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

FromBuilder should remove intermediate renames #215

Open
julianhyde opened this issue Jan 15, 2024 · 1 comment
Open

FromBuilder should remove intermediate renames #215

julianhyde opened this issue Jan 15, 2024 · 1 comment

Comments

@julianhyde
Copy link
Collaborator

FromBuilder should remove intermediate renames. Consider

from i in [1, 2],
  j in [3, 4],
  k in [5, 6]
yield {a = j, b = i}
where a + b = 5

This can be converted to

from i in [1, 2],
  j in [3, 4],
  k in [5, 6]
where j + i = 5
yield {a = j, b = i}

The yield {a = j, b = i} is removed; all occurrences of a after the yield are replaced with i, and all occurrences of b are replaced with j.

A final yield is added to ensure that the from expression still has type {a:int, b:int} list.

The variable k is dead after the yield, and must not be used. (Do we need to add a new subclass of Core.FromStep to kill variables?)

@julianhyde
Copy link
Collaborator Author

Another optimization:

from d in dept join loc in [d.loc] yield loc

should become

from d in dept join yield d.loc

The singleton join loc in [d.loc] should be seen as a project, yield {d, d.loc}, and therefore it can be merged with the following yield loc.

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

1 participant