Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,389
    • Issues 4,389
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 373
    • Merge Requests 373
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18711

Closed
Open
Opened Sep 18, 2020 by Ben Gamari@bgamari🐢Maintainer

More intelligent recompilation for Typed Template Haskell splices

Currently GHC is extremely eager to recompile modules that use Template Haskell. Specifically, if I have:

module A where
-- stuff...
-- EOF


{-# LANGUAGE TemplateHaskell #-}
module B where
import A
-- other stuff containing splices...
-- EOF

Due to B's LANGUAGE TemplateHaskell pragma, any change to A will result in the recompilation of B, even if A's fingerprint didn't change.

While this may be somewhat justified in the case of untyped Template Haskell (where code generation decisions can "depend" upon declarations that aren't present in the final generated code), we can be far smarter if B only contains Typed Template Haskell splices. Specifically, I believe we could use the "normal" recompilation check with a slightly augmented usages set containing the declarations present in the body of the module's splices in addition to the usual usages mentioned in the expanded HsSyn.

I believe this wouldn't be too hard to implement. We would simply need to pass the set of home module names used by Typed TH splices forward from the type-checker (where we expand typed TH splices) to the desugarer. This would likely just take the form of a field in TcGblEnv of the type:

data SpliceSummary
    = NoSplices
      -- ^ no splices, therefore no usages
    | HasOnlyTypedTHSplices { used_names :: NameSet }
      -- ^ the module contained *only* typed TH splices, mentioning the given names
    | HasUntypedTHSplices
      -- ^ the module contained at least on untyped TH splice, therefore there is no
      -- reason to even try tracking typed TH usages

Ultimately GHC.HsToCore.Usage.mkUsedNames would inspect this when building its usage information. The check in GHC.Driver.Make.enableCodeGenForTH would also need to be narrowed.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#18711