@@ -3256,11 +3256,26 @@ instance HoistableB b => HoistableB (WithAttrB a b) where
3256
3256
3257
3257
-- === extra data structures ===
3258
3258
3259
- -- A map from names in some scope to values that do not contain names. This is
3260
- -- not trying to enforce completeness -- a name in the scope can fail to be in
3261
- -- the map.
3262
-
3263
- -- Hoisting the map removes entries that are no longer in scope.
3259
+ -- A map from names in some scope to values that may contain names
3260
+ -- from the same scope. This is not trying to enforce completeness --
3261
+ -- a name in the scope can fail to be in the map.
3262
+
3263
+ -- Hoisting the map removes entries for names that are no longer in
3264
+ -- scope, and then attempts to hoist the remaining values.
3265
+
3266
+ -- This structure is useful for bottom-up code traversals. Once one
3267
+ -- has traversed some term in scope n, one may be carrying information
3268
+ -- associated with (some of) the free variables of the term. These
3269
+ -- free variables are necessarily in the scope n, though they need by
3270
+ -- no means be all the names in the scope n (that's what a Subst is
3271
+ -- for). But, if the traversal is alpha-invariant, it cannot be
3272
+ -- carrying any information about names bound within the term, only
3273
+ -- the free ones.
3274
+ --
3275
+ -- Further, if the information being carried is E-kinded, the names
3276
+ -- therein should be resolvable in the same scope n, since those are
3277
+ -- the only names that are given meaning by the context of the term
3278
+ -- being traversed.
3264
3279
3265
3280
newtype NameMapE (c :: C ) (e :: E ) (n :: S ) = UnsafeNameMapE (RawNameMap (e n ))
3266
3281
deriving (Eq , Semigroup , Monoid , Store )
@@ -3330,6 +3345,9 @@ instance RenameE e => RenameE (NameMapE c e) where
3330
3345
instance HoistableE e => HoistableE (NameMapE c e ) where
3331
3346
freeVarsE = undefined
3332
3347
3348
+ -- A small short-cut: When the information in a NameMapE does not, in
3349
+ -- fact, reference any names, hoisting the entries cannot fail.
3350
+
3333
3351
type NameMap (c :: C ) (a :: * ) = NameMapE c (LiftE a )
3334
3352
3335
3353
hoistNameMap :: (BindsNames b , Show a )
0 commit comments