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

Fix index variable leak when forall body is empty #25915

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented Sep 9, 2024

Closes #25893, reverts #25894.

I was happy to find logic that notes down loop index variables as something that needs to be auto-destroyed in a scope. However, while stepping through in the debugger, I noticed that the cleanup only happens "per statement", which means that loops with empty bodies over iterators do not have their bounds cleaned up:

[x in myiter()] ;; // does not clean up var

One of the reasons was that an "anchor statement" was needed to know where to put all the auto-destroys. This PR fixes the problem by detecting the situation (empty block statement but need to clean up variables), inserting a dummy noop, and using that as anchor.

Reviewed by @jabraham17 -- thanks!

Testing

  • paratest

compiler/resolution/AutoDestroyScope.h Outdated Show resolved Hide resolved
Signed-off-by: Danila Fedorin <[email protected]>
@DanilaFe DanilaFe merged commit 4a3d344 into chapel-lang:main Sep 9, 2024
7 checks passed
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.

[Bug]: ignoring the yielded values from an interator results in leaked memory
2 participants