Emit the discovery pass into a throwaway module (§4a)#213
Merged
Conversation
Discovery now emits into a dedicated DiscoveryModuleScope module that is erased wholesale on scope exit, so its cleanup is structurally unable to disturb content already generated in the real module (nested discovery via 'import' of a local source file during SourceGeneration). Replaces the preExistingOps snapshot-and-selective-erase mechanism. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Jul 12, 2026
…eview doc 2) (#214) NamespaceInfo::functionMap cached raw mlir_ts::FuncOp handles; since the discovery pass emits into a throwaway module (#213), any handle registered during discovery is guaranteed to dangle once the module is erased - consumers survived only because they read the (context-owned) type early. The map now stores FunctionEntry { symbol name, function type }, which is all any consumer used; the one site that needs a live op (generic-instantiation short-circuit) resolves it through theModule.lookupSymbol with a short/full-name fallback. 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 §4a from
docs/MLIRGen-refactoring-review.md: the discovery (dummyRun) pass now generates into a fresh detachedModuleOpvia aDiscoveryModuleScopeRAII guard (composed ofMLIRValueGuard<ModuleOp>+OpBuilder::InsertionGuard, same pattern asTempModuleScopefrom #201; the throwaway module is erased on scope exit).This replaces the snapshot-and-erase mechanism (
preExistingOpsset + selective op erasure) — discovery cleanup is now structurally unable to touch real module content, closing the bug class behind the old nested-import "op 'console.log' does not reference a valid function" crash for good.Test plan
This is the change the review doc flagged as needing real suite coverage, so beyond the usual smokes it got the full ctest suite:
test-jit-shared-export-import-*tests that exercise nested include/discoveryMLIRGenTests.exe12/12importunder--emit=jit --no-default-libfails identically on baseline main (Symbols not found), i.e. pre-existing and unrelated to this change🤖 Generated with Claude Code