Skip to content

Make GenContext cleanup pointers non-owning#204

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-ownership
Jul 11, 2026
Merged

Make GenContext cleanup pointers non-owning#204
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-ownership

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Implements the ownership half of item A1 from docs/MLIRGen-refactoring-review.md.

GenContext held raw owning pointers (cleanUps, cleanUpOps, passResult, state) freed manually via clean()/cleanState(), while the struct is copied ~48× and copies share those pointers — a leak on any early-return path and a latent double-delete if clean() ever ran through two copies.

  • The two setup sites now stack-allocate the objects — the discovery run (SmallVectors + PassResult + state in mlirGenFunctionEntry's discovery block) and the per-function state counter — and GenContext only 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 dummy funcOp — but no longer frees memory; it clears the borrowed lists and detaches. cleanState() is removed entirely.
  • Removed the stale no-op clean() call and commented-out allocations in mlirDiscoverAllDependencies (that context never allocated cleanup lists nor set funcOp, 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

🤖 Generated with Claude Code

@ASDAlexander77 ASDAlexander77 merged commit 6ea52da into main Jul 11, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/gencontext-ownership branch July 11, 2026 22:00
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.

1 participant