[project @ 2001-07-25 07:42:23 by simonpj]
authorsimonpj <unknown>
Wed, 25 Jul 2001 07:42:23 +0000 (07:42 +0000)
committersimonpj <unknown>
Wed, 25 Jul 2001 07:42:23 +0000 (07:42 +0000)
---------------------------------------
Fix a grevious dict-inlining infelicity
---------------------------------------

This commit fixes an infelicity that must have been there
for a long time.  The problem was that dictionary functions
(arising from instance declarations) were treated as GlobalIds,
and hence no taken account of when doing free variable and dependency
analysis.    As a result, the specialiser was messing up dependency
order, so the program was considerably more complex than it should
be by the time it got to the strictness analyser.

Net result:
PrelRead.$sreduce :: Integer -> Integer -> (Integer,Integer)
didn't get detected as strict.

Easily fixed, by making DictFunIds into LocalIds (albeit exported ones).

ghc/compiler/basicTypes/MkId.lhs

index 0d5bcec..761eef8 100644 (file)
@@ -66,6 +66,7 @@ import DataCon                ( DataCon,
                          splitProductType
                        )
 import Id              ( idType, mkGlobalId, mkVanillaGlobal, mkSysLocal,
+                         mkLocalIdWithInfo, setIdNoDiscard,
                          mkTemplateLocals, mkTemplateLocalsNum,
                          mkTemplateLocal, idNewStrictness, idName
                        )
@@ -665,7 +666,19 @@ mkDictFunId :: Name                -- Name to use for the dict fun;
            -> Id
 
 mkDictFunId dfun_name clas inst_tyvars inst_tys dfun_theta
-  = mkVanillaGlobal dfun_name dfun_ty noCafNoTyGenIdInfo
+  = setIdNoDiscard (mkLocalIdWithInfo dfun_name dfun_ty noCafNoTyGenIdInfo)
+       -- NB: It's important that dict funs are *local* Ids
+       -- This ensures that they are taken to account by free-variable finding
+       -- and dependency analysis (e.g. CoreFVs.exprFreeVars).  
+       -- In particular, if they are globals, the
+       -- specialiser floats dict uses above their defns, which prevents
+       -- good simplifications happening.
+       --
+       -- It's OK for them to be locals, because we form the instance-env to
+       -- pass on to the next module (md_insts) in CoreTidy, afer tdying
+       -- and globalising the top-level Ids.
+       --
+       -- BUT Make sure it's an exported Id (setIdNoDiscard) so that it's not dropped!
   where
     dfun_ty = mkSigmaTy inst_tyvars dfun_theta (mkDictTy clas inst_tys)