diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-10-27 22:02:18 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-10-27 22:02:18 +0100 |
commit | 4acecc1099caefc2bd2fbe252d30d52ead2c74be (patch) | |
tree | c32d4ae3fd7269df5543c0b8fe3cbbce87b1ce28 /src/AST/Count.hs | |
parent | 8d15d92bb9a0472e096ff714e45b10cf16134a30 (diff) |
WIP preserve only subset of D0 bindings in dual (...)
The point of this is to ensure that when an expression occurs in a
Build, then the parts of D0 that are only there to make sharing work out
for D1 are not laboriously taped in an array and preserved for D2, only
for D2 to ignore them.
However, while the subtape machinery is a good first step, this is not
everything: the current Build translation makes a Build for the
(elementwise) tape and separately a build for the primal. Because the
primal _does_ generally need the subtaped-away stuff, we can't just not
tape those.
TODO: figure out how to resolve this / what the next step is.
Diffstat (limited to 'src/AST/Count.hs')
-rw-r--r-- | src/AST/Count.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/AST/Count.hs b/src/AST/Count.hs index 31720a5..a928743 100644 --- a/src/AST/Count.hs +++ b/src/AST/Count.hs @@ -150,12 +150,12 @@ deleteUnused (_ `SCons` env) (OccPush occenv (Occ _ count)) k = unsafeWeakenWithSubenv :: Subenv env env' -> Expr x env t -> Expr x env' t unsafeWeakenWithSubenv = \sub -> - subst (\x t i -> case sinkWithSubenv i sub of + subst (\x t i -> case sinkViaSubenv i sub of Just i' -> EVar x t i' Nothing -> error "unsafeWeakenWithSubenv: Index occurred that was subenv'd away") where - sinkWithSubenv :: Idx env t -> Subenv env env' -> Maybe (Idx env' t) - sinkWithSubenv IZ (SEYes _) = Just IZ - sinkWithSubenv IZ (SENo _) = Nothing - sinkWithSubenv (IS i) (SEYes sub) = IS <$> sinkWithSubenv i sub - sinkWithSubenv (IS i) (SENo sub) = sinkWithSubenv i sub + sinkViaSubenv :: Idx env t -> Subenv env env' -> Maybe (Idx env' t) + sinkViaSubenv IZ (SEYes _) = Just IZ + sinkViaSubenv IZ (SENo _) = Nothing + sinkViaSubenv (IS i) (SEYes sub) = IS <$> sinkViaSubenv i sub + sinkViaSubenv (IS i) (SENo sub) = sinkViaSubenv i sub |