unhygienic expansion and unintended normalization in refmt
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 10.3k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
Consider:
let f = (x, p) => p(x);
let g = (a, b) => a + b;
let ___x = 42;
Js.log(7->f(g(_, ___x))); /* output 49 */
Now, change ___x to __x:
let f = (x, p) => p(x);
let g = (a, b) => a + b;
let __x = 42;
Js.log(7->f(g(_, __x))); /* output 14 */
The reason is that 7->f(g(_, __x)) is rewritten to 7->f(__x => g(__x, __x)) in the compiler. This causes an unintended variable capture akin to what we can see from unhygienic macros.
A related bug is that refmt normalizes 7->f(g(_, foo)) to 7->f(__x => g(__x, foo)). I argue that it should not do this. Even if the compiler is now correct, that is, it generates a fresh identifier that avoids unintended variable capture, outputting the generated identifier to users doesn't seem to be a good normalization. Furthermore, it doesn't look good aesthetically (although this might be subjective).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the compiler rewrite of partial application and the refmt normalization described in the issue. Reproduce both ___x and __x examples, then verify that expansion avoids unintended variable capture and that refmt does not expose an unnecessary generated identifier.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100