-
-ifaceDeclSubBndrs (IfaceData {ifCons = cons}) = foldr ((++) . conDeclBndrs) []
- (visibleIfConDecls cons)
-ifaceDeclSubBndrs other = []
-
-conDeclBndrs (IfaceConDecl con_occ _ _ _ _ _ fields)
- = fields ++
- [con_occ, mkDataConWrapperOcc con_occ, mkDataConWorkerOcc con_occ]
-
-
------------------------------------------------------
--- Loading instance decls
------------------------------------------------------
-
-loadInsts :: Module -> InstPool -> [IfaceInst] -> IfL InstPool
-loadInsts mod (Pool pool n_in n_out) decls
- = do { new_pool <- foldlM (loadInstDecl (moduleName mod)) pool decls
- ; returnM (Pool new_pool
- (n_in + length decls)
- n_out) }
-
-loadInstDecl mod pool decl@(IfaceInst {ifInstHead = inst_ty})
- = do {
- -- Find out what type constructors and classes are "gates" for the
- -- instance declaration. If all these "gates" are slurped in then
- -- we should slurp the instance decl too.
- --
- -- We *don't* want to count names in the context part as gates, though.
- -- For example:
- -- instance Foo a => Baz (T a) where ...
- --
- -- Here the gates are Baz and T, but *not* Foo.
- --
- -- HOWEVER: functional dependencies make things more complicated
- -- class C a b | a->b where ...
- -- instance C Foo Baz where ...
- -- Here, the gates are really only C and Foo, *not* Baz.
- -- That is, if C and Foo are visible, even if Baz isn't, we must
- -- slurp the decl.
- --
- -- Rather than take fundeps into account "properly", we just slurp
- -- if C is visible and *any one* of the Names in the types
- -- This is a slightly brutal approximation, but most instance decls
- -- are regular H98 ones and it's perfect for them.
- --
- -- NOTICE that we rename the type before extracting its free
- -- variables. The free-variable finder for a renamed HsType
- -- does the Right Thing for built-in syntax like [] and (,).
- let { (cls_ext, tc_exts) = ifaceInstGates inst_ty }
- ; cls <- lookupIfaceExt cls_ext
- ; tcs <- mapM lookupIfaceTc tc_exts
- ; let { new_pool = extendNameEnv_C combine pool cls [(tcs, (mod,decl))]
- ; combine old _ = (tcs,(mod,decl)) : old }
- ; returnM new_pool
- }
-
------------------------------------------------------
--- Loading Rules
------------------------------------------------------
-
-loadRules :: Bool -- Don't load pragmas into the decl pool
- -> Module -> RulePool -> [IfaceRule] -> IfL RulePool
-loadRules ignore_prags mod pool@(Pool rule_pool n_in n_out) rules
- | ignore_prags = returnM pool
- | otherwise
- = do { new_pool <- foldlM (loadRule (moduleName mod)) rule_pool rules
- ; returnM (Pool new_pool (n_in + length rules) n_out) }
-
-loadRule :: ModuleName -> RulePoolContents -> IfaceRule -> IfL RulePoolContents
--- "Gate" the rule simply by a crude notion of the free vars of
--- the LHS. It can be crude, because having too few free vars is safe.
-loadRule mod_name pool decl@(IfaceRule {ifRuleHead = fn, ifRuleArgs = args})
- = do { names <- mapM lookupIfaceExt (fn : arg_fvs)
- ; returnM (addRuleToPool pool (mod_name, decl) names) }
+ dcww_occ | is_newtype = mkDataConWrapperOcc dc_occ -- Newtypes have wrapper but no worker
+ | otherwise = mkDataConWorkerOcc dc_occ -- Otherwise worker but no wrapper
+ is_newtype = n_sigs + n_ctxt == 1 -- Sigh
+
+ifaceDeclSubBndrs (IfaceData {ifCons = IfAbstractTyCon})
+ = []
+-- Newtype
+ifaceDeclSubBndrs (IfaceData {ifCons = IfNewTyCon (IfVanillaCon { ifConOcc = con_occ,
+ ifConFields = fields})})
+ = fields ++ [con_occ, mkDataConWrapperOcc con_occ]
+ -- Wrapper, no worker; see MkId.mkDataConIds
+
+ifaceDeclSubBndrs (IfaceData {ifCons = IfDataTyCon cons})
+ = nub (concatMap fld_occs cons) -- Eliminate duplicate fields
+ ++ concatMap dc_occs cons