-tcImportDecl name
- = do {
- -- Make sure the interface is loaded
- ; let { nd_doc = ptext SLIT("Need decl for") <+> ppr name }
- ; traceIf (nd_doc <+> char '{') -- Brace matches the later message
- ; loadHomeInterface nd_doc name
-
- -- Get the real name of the thing, with a correct nameParent field.
- -- Before the interface is loaded, we may have a non-committal 'Nothing'
- -- in the namePareent field (made up by IfaceEnv.lookupOrig), but
- -- loading the interface updates the name cache.
- -- We need the right nameParent field in getThing
- ; real_name <- lookupOrig (nameModuleName name) (nameOccName name)
-
- -- Get the decl out of the EPS
- ; main_thing <- ASSERT( real_name == name ) -- Unique should not change!
- getThing real_name
-
- -- Record the import in the type env,
- -- slurp any rules it allows in
- ; recordImportOf main_thing
-
- ; let { extra | getName main_thing == real_name = empty
- | otherwise = brackets (ptext SLIT("when seeking") <+> ppr real_name) }
- ; traceIf (ptext SLIT(" ...imported decl for") <+> ppr main_thing <+> extra <+> char '}')
-
-
- -- Look up the wanted Name in the type envt; it might be
- -- one of the subordinate members of the input thing
- ; if real_name == getName main_thing
- then return main_thing
- else do
- { eps <- getEps
- ; return (expectJust "tcImportDecl" $
- lookupTypeEnv (eps_PTE eps) real_name) }}
-
-recordImportOf :: TyThing -> IfG ()
--- Update the EPS to record the import of the Thing
--- (a) augment the type environment; this is done even for wired-in
--- things, so that we don't go through this rigmarole a second time
--- (b) slurp in any rules to maintain the invariant that any rule
--- whose gates are all in the type envt, is in eps_rule_base
-
-recordImportOf thing
- = do { new_things <- updateEps (\ eps ->
- let { new_things = thing : implicitTyThings thing
- ; new_type_env = extendTypeEnvList (eps_PTE eps) new_things
- -- NB: opportunity for a very subtle loop here!
- -- If working out what the implicitTyThings are involves poking
- -- any of the fork'd thunks in 'thing', then here's what happens
- -- * recordImportOf succeed, extending type-env with a thunk
- -- * the next guy to pull on type-env forces the thunk
- -- * which pokes the suspended forks
- -- * which, to execute, need to consult type-env (to check
- -- entirely unrelated types, perhaps)
- }
- in (eps { eps_PTE = new_type_env }, new_things)
- )
- ; traceIf (text "tcImport: extend type env" <+> ppr new_things)
- }
-
-getThing :: Name -> IfG TyThing
--- Find and typecheck the thing; the Name might be a "subordinate name"
--- of the "main thing" (e.g. the constructor of a data type declaration)
--- The Thing we return is the parent "main thing"
-
-getThing name