@@ -3256,11 +3256,26 @@ instance HoistableB b => HoistableB (WithAttrB a b) where
32563256
32573257-- === extra data structures ===
32583258
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.
32643279
32653280newtype NameMapE (c :: C ) (e :: E ) (n :: S ) = UnsafeNameMapE (RawNameMap (e n ))
32663281 deriving (Eq , Semigroup , Monoid , Store )
@@ -3330,6 +3345,9 @@ instance RenameE e => RenameE (NameMapE c e) where
33303345instance HoistableE e => HoistableE (NameMapE c e ) where
33313346 freeVarsE = undefined
33323347
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+
33333351type NameMap (c :: C ) (a :: * ) = NameMapE c (LiftE a )
33343352
33353353hoistNameMap :: (BindsNames b , Show a )
0 commit comments