-typecheckIface :: ModIface -> IfG ModDetails
--- Used when we decide not to recompile, but intead to use the
--- interface to construct the type environment for the module
-typecheckIface iface
- = initIfaceLcl (moduleName (mi_module iface)) $
- do { ty_things <- mapM (tcIfaceDecl . snd) (mi_decls iface)
- ; rules <- mapM tcIfaceRule (mi_rules iface)
+typecheckIface :: HscEnv
+ -> ModIface -- Get the decls from here
+ -> IO ModDetails
+typecheckIface hsc_env iface@(ModIface { mi_module = mod, mi_decls = ver_decls,
+ mi_rules = rules, mi_insts = dfuns })
+ = initIfaceTc hsc_env iface $ \ tc_env_var -> do
+ { -- Typecheck the decls
+ names <- mappM (lookupOrig (moduleName mod) . ifName) decls
+ ; ty_things <- fixM (\ rec_ty_things -> do
+ { writeMutVar tc_env_var (mkNameEnv (names `zipLazy` rec_ty_things))
+ -- This only makes available the "main" things,
+ -- but that's enough for the strictly-checked part
+ ; mapM tcIfaceDecl decls })
+
+ -- Now augment the type envt with all the implicit things
+ -- These will be needed when type-checking the unfoldings for
+ -- the IfaceIds, but this is done lazily, so writing the thing
+ -- now is sufficient
+ ; let { add_implicits main_thing = main_thing : implicitTyThings main_thing
+ ; type_env = mkTypeEnv (concatMap add_implicits ty_things) }
+ ; writeMutVar tc_env_var type_env
+
+ -- Now do those rules and instances