Skip to content

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

Description

@saelo

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions