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

Nesting let expressions may reveal potential bugs #10

Open
gregr opened this issue Sep 14, 2017 · 2 comments
Open

Nesting let expressions may reveal potential bugs #10

gregr opened this issue Sep 14, 2017 · 2 comments

Comments

@gregr
Copy link

gregr commented Sep 14, 2017

Hi, Ilya, thanks for sc-mini! I just finished reading the paper and the source, and noticed some things that didn't make sense to me, which may be unintended. By the way, this issue probably isn't a big deal since let expressions don't seem intended for use in the source language, and so won't appear in nested positions.

I noticed a few places where the handling of let expressions would cause problems if they appeared in nested positions (currently, they are only placed in outer positions during decomposition).

Based on how it's used, vnames should be extracting free variables, so should subtract the let parameter from the names retrieved from the body:

vnames' (Let (_, e1) e2) = vnames' e1 ++ vnames' e2

I don't think you really want to substitute v' for v in e2' here, since v could legitimately be free in e2'. You really want the behavior you'd get from first substituting the argument for the let-bound parameter in both e2 and e2', then computing the renaming. A more efficient way of getting this would be to prime the renaming with [(v, v')] to ensure that other occurrences of v on the left, indicating that renaming v to anything else should fail; then removing this renaming since v is not actually a free variable in e2:

renaming' (Let (v, e1) e2, Let (v', e1') e2') = renaming' (e1, e1') ++ renaming' (e2, e2' // [(v, Var v')])

@ilya-klyuchnikov
Copy link
Owner

ilya-klyuchnikov commented Sep 14, 2017 via email

@gregr
Copy link
Author

gregr commented Sep 14, 2017

Nope, that's it. Since it's fresh in my mind, just wanted to point out a few of the more subtle places that, if fixed (along with other less subtle changes), could make it possible to include let expressions in the source language too. It's the kind of code where, if you revisit it after several years, it might be hard to remember where things could go wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants