Add GenContext field initializers and SourceFileScope RAII guard#202
Merged
Merged
Conversation
- Default member initializers on all GenContext scalar/pointer fields; a plain "GenContext ctx;" no longer produces indeterminate codegen flags (review doc item A1) - SourceFileScope replaces the 9 hand-rolled sourceFile/mainSourceFileName guard pairs, using the MLIRValueGuard save-and-set constructor (review doc item A2) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 items A1 (partially) and A2 from
docs/MLIRGen-refactoring-review.md:GenContextdefault member initializers.GenContext() = default;left ~15bools and raw pointers indeterminate; every current instance happens to be value-initialized or copied, but a plainGenContext ctx;would compile and produce garbage codegen flags. All scalar/pointer fields now have= false/= nullptrinitializers. (The ownership half of A1 —cleanUps/cleanUpOps/passResult/stateraw-pointer lifetime — is intentionally left for a dedicated PR.)SourceFileScopeRAII guard. Replaces the 9 hand-rolledMLIRValueGuard vgSourceFile / vgFileName+ assignment pairs (3 include/import-loading sites, 6 generic-instantiation sites) with a single class composed of twoMLIRValueGuards using the save-and-set constructor from Refactor theModule handling in MLIRGenImpl #201. A converting constructor handles the include-site variant that interns the UTF-8 file name. Also removes a stray;;at one of the sites.Net −17 lines; no behavior change.
Test plan
tslangrebuilt cleanly (vs2026 debug)SourceFileScopesites (generic function, generic class, generic interface specialization) JIT-runs with expected output5 21 7 x42 15 42 3 1MLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code