Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix de Bruijn indices in LetRecs #2227

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Juvix/Compiler/Core/Transformation/LambdaLetRecLifting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ lambdaLiftNode aboveBl top =
]
declareTopSyms

let -- TODO it can probably be simplified
shiftHelper :: Node -> NonEmpty (Node, Binder) -> Node
let shiftHelper :: Node -> NonEmpty (Node, Binder) -> Node
shiftHelper b = goShift 0
where
goShift :: Int -> NonEmpty (Node, Binder) -> Node
Expand All @@ -171,7 +170,7 @@ lambdaLiftNode aboveBl top =
| otherwise -> impossible
(y : ys) -> mkLet mempty bnd' (shift k x) (goShift (k + 1) (y :| ys))
where
bnd' = over binderType (shift k . subsCalls) bnd
bnd' = over binderType (shift k) bnd
let res :: Node
res = shiftHelper body' (nonEmpty' (zipExact letItems letRecBinders'))
return (Recur res)
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Translation/FromInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ goLet l = goClauses (toList (l ^. Internal.letClauses))
pragmas = map (^. Internal.funDefPragmas) lfuns
tys' <- mapM goType tys
localAddNames names $ do
vals' <- sequence [mkFunBody ty f | (ty, f) <- zipExact tys' lfuns]
vals' <- sequence [mkFunBody (shift (length names) ty) f | (ty, f) <- zipExact tys' lfuns]
let items = nonEmpty' (zipWith3Exact (\ty n v -> LetItem (Binder (n ^. nameText) (Just $ n ^. nameLoc) ty) v) tys' names vals')
rest <- goClauses cs
return (mkLetRec (setInfoPragmas pragmas mempty) items rest)
Expand Down