Skip to content

Emit the discovery pass into a throwaway module (§4a)#213

Merged
ASDAlexander77 merged 2 commits into
mainfrom
refactor/discovery-throwaway-module
Jul 12, 2026
Merged

Emit the discovery pass into a throwaway module (§4a)#213
ASDAlexander77 merged 2 commits into
mainfrom
refactor/discovery-throwaway-module

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Implements §4a from docs/MLIRGen-refactoring-review.md: the discovery (dummyRun) pass now generates into a fresh detached ModuleOp via a DiscoveryModuleScope RAII guard (composed of MLIRValueGuard<ModuleOp> + OpBuilder::InsertionGuard, same pattern as TempModuleScope from #201; the throwaway module is erased on scope exit).

This replaces the snapshot-and-erase mechanism (preExistingOps set + 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:

  • JIT: 339/339 passed (39 s) — including all test-jit-shared-export-import-* tests that exercise nested include/discovery
  • AOT: 342/342 passed (115 s) — compile + link + run per test
  • All 9 JIT smoke tests identical; MLIRGenTests.exe 12/12
  • Also checked: plain local-file import under --emit=jit --no-default-lib fails identically on baseline main (Symbols not found), i.e. pre-existing and unrelated to this change

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits July 12, 2026 18:56
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 ASDAlexander77 merged commit f0bf983 into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/discovery-throwaway-module branch July 12, 2026 18:15
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>
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