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

Experiment with JavaScriptLifter inlining heuristic that tries to avoid additional brackets #491

Open
saelo opened this issue Dec 31, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@saelo
Copy link
Collaborator

saelo commented Dec 31, 2024

Currently, the JavaScriptLifter is fairly "greedy" about its inlining decisions and mostly inlines expressions whenever possible:

  1. There is a single use of the produced value (or if the expression is pure)
  2. There is no other effectful operation between the operation that produced the expression and the operation using the value (otherwise, inlining would change the semantics of the program)

However, this can lead to somewhat hard to read code. For example things such as

print((new X).a);

or

("1234").foobar();

Currently we manually try to avoid some of these patterns, for example by forcing the constructor value to be an identifier for a construct call. However it could be the case that a simple heuristic would also work here instead of a manual "denylist": we avoid inlining if we would require additional brackets (such as in the examples above). Maybe for arithmetic operations we allow adding brackets, but forbid them for other expressions and instead force the creation of a new variable. Ideally, we would design the new algorithm in a way that also allows us to remove the somewhat awkward logic for expression un-inlining.

I think it would be worth experimenting with such a heuristic to see how the generated samples look like.

@saelo saelo added the enhancement New feature or request label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant