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

v: fix redundant emission of left expression in in infix expressions #22763

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

HectorPeeters
Copy link
Contributor

@HectorPeeters HectorPeeters commented Nov 4, 2024

This PR fixes the issue addressed in #22758. It prevents the left expression of an in infix expression from being emitted multiple times. This occurs in the following code example:

x() in [12, 13]

This gets optimized into:

x() == 12 || x() == 13

In this case this optimization is incorrect.

The fix I implemented checks if the left expression is an ast.Ident. However, I'm unsure if there is side effect information present in the compiler. Having this information available would allow this optimization to be applied in more situations.

Huly®: V_0.6-21210

@spytheman
Copy link
Member

However, I'm unsure if there is side effect information present in the compiler.

There is not yet afaik.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 2dd6587 into vlang:master Nov 5, 2024
71 checks passed
@medvednikov
Copy link
Member

This kills the allocation optimization though and now x() in [12, 13] will result in an allocation for [12, 13]?

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

Successfully merging this pull request may close these issues.

3 participants