Wibble to SetLevels.abstractVars
authorsimonpj@microsoft.com <unknown>
Fri, 18 Jan 2008 17:17:54 +0000 (17:17 +0000)
committersimonpj@microsoft.com <unknown>
Fri, 18 Jan 2008 17:17:54 +0000 (17:17 +0000)
I've gotten this wrong more than once.  Hopefully this has it nailed.
The issue is that in float-out we must abstract over the correct
variables.

compiler/simplCore/FloatOut.lhs
compiler/simplCore/SetLevels.lhs

index 7cac08d..e6e8b7a 100644 (file)
@@ -322,7 +322,7 @@ floatExpr lvl (Note InlineMe expr)  -- Other than SCCs
        -- them into floating_defns (which would mean testing for
        -- inlineCtxt  at every let)
     (fs, [], Note InlineMe (install floating_defns expr')) }
        -- them into floating_defns (which would mean testing for
        -- inlineCtxt  at every let)
     (fs, [], Note InlineMe (install floating_defns expr')) }
-       -- See Note [FloatOut inside INLINE]
+       -- See Note [FloatOut inside INLINE] in SetLevels
        -- I'm guessing that floating_dens should be empty
 
 floatExpr lvl (Note note expr) -- Other than SCCs
        -- I'm guessing that floating_dens should be empty
 
 floatExpr lvl (Note note expr) -- Other than SCCs
index 020ed71..8be8dd6 100644 (file)
@@ -669,8 +669,8 @@ type LevelEnv = (FloatOutSwitches,
        -- We also use these envs when making a variable polymorphic
        -- because we want to float it out past a big lambda.
        --
        -- We also use these envs when making a variable polymorphic
        -- because we want to float it out past a big lambda.
        --
-       -- The SubstEnv and IdEnv always implement the same mapping, but the
-       -- SubstEnv maps to CoreExpr and the IdEnv to LevelledExpr
+       -- The Subst and IdEnv always implement the same mapping, but the
+       -- Subst maps to CoreExpr and the IdEnv to LevelledExpr
        -- Since the range is always a variable or type application,
        -- there is never any difference between the two, but sadly
        -- the types differ.  The SubstEnv is used when substituting in
        -- Since the range is always a variable or type application,
        -- there is never any difference between the two, but sadly
        -- the types differ.  The SubstEnv is used when substituting in
@@ -774,9 +774,11 @@ abstractVars :: Level -> LevelEnv -> VarSet -> [Var]
        -- These are the ones we are going to abstract out
 abstractVars dest_lvl (_, lvl_env, _, id_env) fvs
   = map zap $ uniq $ sortLe le 
        -- These are the ones we are going to abstract out
 abstractVars dest_lvl (_, lvl_env, _, id_env) fvs
   = map zap $ uniq $ sortLe le 
-    [var | fv <- varSetElems fvs
-        , var <- absVarsOf id_env fv
-        , abstract_me var]
+       [var | fv <- varSetElems fvs
+            , var <- absVarsOf id_env fv
+            , abstract_me var ]
+       -- NB: it's important to call abstract_me only on the OutIds the
+       -- come from absVarsOf (not on fv, which is an InId)
   where
        -- Sort the variables so the true type variables come first;
        -- the tyvars scope over Ids and coercion vars
   where
        -- Sort the variables so the true type variables come first;
        -- the tyvars scope over Ids and coercion vars