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

wrap is read as a variable when compiling `with' blocks #664

Open
developedby opened this issue Aug 7, 2024 · 0 comments · May be fixed by #665
Open

wrap is read as a variable when compiling `with' blocks #664

developedby opened this issue Aug 7, 2024 · 0 comments · May be fixed by #665
Assignees
Labels
bug Something isn't working compilation Compilation of terms and functions to HVM

Comments

@developedby
Copy link
Member

Reproducing the behavior

This excerpt:

def main():
  with IO:
    x <- wrap(1)
    return wrap(wrap(2))

Should be desugaring to

(main) = (IO/bind (IO/wrap 1) λa (a λ* (IO/wrap (IO/wrap 2))))

Instead it desugars into

(main) = (IO/bind (IO/wrap 1) λa (a λb let {c d} = b; λ* (c (d 2)) IO/wrap))

wrap is seen as a free variable, so it gets applied in a deferred way as well as duplicated if it's used more than once.

We need to first substitute the wrap and only then desugar the bind.

System Settings

Bend commit 270f39c

Additional context

No response

@developedby developedby added bug Something isn't working compilation Compilation of terms and functions to HVM labels Aug 7, 2024
@developedby developedby self-assigned this Aug 7, 2024
@developedby developedby linked a pull request Aug 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compilation Compilation of terms and functions to HVM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant