Make GenContext cleanup pointers non-owning#204
Merged
Conversation
…nd improve memory management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the ownership half of item A1 from
docs/MLIRGen-refactoring-review.md.GenContextheld raw owning pointers (cleanUps,cleanUpOps,passResult,state) freed manually viaclean()/cleanState(), while the struct is copied ~48× and copies share those pointers — a leak on any early-return path and a latent double-delete ifclean()ever ran through two copies.SmallVectors +PassResult+stateinmlirGenFunctionEntry's discovery block) and the per-functionstatecounter — andGenContextonly borrows pointers to them. Declaration order guarantees the owners outlive every context copy in the call subtree.GenContext::clean()keeps its real job — erasing IR collected during a dummy run and the dummyfuncOp— but no longer frees memory; it clears the borrowed lists and detaches.cleanState()is removed entirely.clean()call and commented-out allocations inmlirDiscoverAllDependencies(that context never allocated cleanup lists nor setfuncOp, so the call did nothing).Net effect: memory lifetime is structural (stack unwinding), while the three explicit
clean()calls remain for their IR-erasure side effect only.Test plan
tslangrebuilt cleanly (vs2026 debug)PassResult) and closure capture (outerVariables) — JIT output3 42as expected42 15 42 3 1,5 21 7 x, and the utility-type/spread/push suite)MLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code