X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcRnTypes.lhs;h=746a30bab3f13cb4b1c13a40cfcf68e20b0412a5;hp=cbc443f10031da48824e684f915eea495ba7f172;hb=90686adf9d3dc7a09a51853df051bc4ea472d840;hpb=63489d40bdee972656ff115ab2309b809c0e39fc diff --git a/compiler/typecheck/TcRnTypes.lhs b/compiler/typecheck/TcRnTypes.lhs index cbc443f..746a30b 100644 --- a/compiler/typecheck/TcRnTypes.lhs +++ b/compiler/typecheck/TcRnTypes.lhs @@ -22,7 +22,7 @@ module TcRnTypes( -- Template Haskell ThStage(..), topStage, topAnnStage, topSpliceStage, - ThLevel, impLevel, topLevel, + ThLevel, impLevel, outerLevel, thLevel, -- Arrows ArrowCtxt(NoArrowCtxt), newArrowScope, escapeArrowScope, @@ -233,7 +233,11 @@ data TcGblEnv tcg_rn_imports :: [LImportDecl Name], -- Keep the renamed imports regardless. They are not -- voluminous and are needed if you want to report unused imports + tcg_used_rdrnames :: TcRef (Set RdrName), + -- The set of used *imported* (not locally-defined) RdrNames + -- Used only to report unused import declarations + tcg_rn_decls :: Maybe (HsGroup Name), -- ^ Renamed decls, maybe. @Nothing@ <=> Don't retain renamed -- decls. @@ -247,8 +251,12 @@ data TcGblEnv tcg_fords :: [LForeignDecl Id], -- ...Foreign import & exports tcg_doc_hdr :: Maybe LHsDocString, -- ^ Maybe Haddock header docs - tcg_hpc :: AnyHpcUsage -- ^ @True@ if any part of the prog uses hpc - -- instrumentation. + tcg_hpc :: AnyHpcUsage, -- ^ @True@ if any part of the + -- prog uses hpc instrumentation. + + tcg_main :: Maybe Name -- ^ The Name of the main + -- function, if this module is + -- the main module. } data RecFieldEnv @@ -382,37 +390,55 @@ pass it inwards. -} --------------------------- --- Template Haskell levels +-- Template Haskell stages and levels --------------------------- +data ThStage -- See Note [Template Haskell state diagram] in TcSplice + = Splice -- Top-level splicing + -- This code will be run *at compile time*; + -- the result replaces the splice + -- Binding level = 0 + + | Comp -- Ordinary Haskell code + -- Binding level = 1 + + | Brack -- Inside brackets + ThStage -- Binding level = level(stage) + 1 + (TcRef [PendingSplice]) -- Accumulate pending splices here + (TcRef LIE) -- and type constraints here + +topStage, topAnnStage, topSpliceStage :: ThStage +topStage = Comp +topAnnStage = Splice +topSpliceStage = Splice + +instance Outputable ThStage where + ppr Splice = text "Splice" + ppr Comp = text "Comp" + ppr (Brack s _ _) = text "Brack" <> parens (ppr s) + type ThLevel = Int - -- Indicates how many levels of brackets we are inside - -- (always >= 0) + -- See Note [Template Haskell levels] in TcSplice -- Incremented when going inside a bracket, -- decremented when going inside a splice -- NB: ThLevel is one greater than the 'n' in Fig 2 of the -- original "Template meta-programming for Haskell" paper -impLevel, topLevel :: ThLevel -topLevel = 1 -- Things defined at top level of this module +impLevel, outerLevel :: ThLevel impLevel = 0 -- Imported things; they can be used inside a top level splice +outerLevel = 1 -- Things defined outside brackets +-- NB: Things at level 0 are not *necessarily* imported. +-- eg $( \b -> ... ) here b is bound at level 0 -- -- For example: -- f = ... -- g1 = $(map ...) is OK -- g2 = $(f ...) is not OK; because we havn't compiled f yet - -data ThStage - = Comp ThLevel -- Ordinary compiling, usually at level topLevel but annotations use a lower level - | Splice ThLevel -- Inside a splice - | Brack ThLevel -- Inside brackets; - (TcRef [PendingSplice]) -- accumulate pending splices here - (TcRef LIE) -- and type constraints here -topStage, topAnnStage, topSpliceStage :: ThStage -topStage = Comp topLevel -topAnnStage = Comp (topLevel - 1) -topSpliceStage = Splice (topLevel - 1) -- Stage for the body of a top-level splice +thLevel :: ThStage -> ThLevel +thLevel Splice = 0 +thLevel Comp = 1 +thLevel (Brack s _ _) = thLevel s + 1 --------------------------- -- Arrow-notation context