Repository navigation
A discovery module skips an import discovered already; its globals are put back - #773
Merged
Merged
Conversation
…e put back theModule receives each import once (emittedFiles), but every discovery module that reached an import generated it again, and was then thrown away: powder_sandbox's checks.ts generated its imports 211 times, nearly all of them into discovery modules. In a discovery module (discoveryDepth > 0) an import whose discovery has run already (discoveredImports) is no longer generated. What discovery resolves against it is in the compile's maps, except fullNameGlobalsMap, which is scoped to each module: generating an import registers its globals there, a class's .rtti among them, and without it testing a `C | null` for truth failed with "Class member '.rtti' can't be found". So the first generation of each file (an import, or a file one references) records the globals it registered and the files it reached (importUnits), and a skipped import's are put back, with those of every file it reached. A file this module emitted already is there with its globals. A referenced file is first generated here, and recorded: a module's references are emitted by its discovery's dummy run, so an import nested in it never generated them. An import that reached a library or an import cycle is generated each time, as before. checks.ts --di -O0 -mm=gc: 2.68 s -> 2.10 s; -O3 -mm=rc 3.29 -> 2.60 s; powder_sandbox_nri 2.45 -> 1.59 s. LLVM IR of checks, powder_sandbox_nri and simulation is identical to main's. New test import-chain-rtti-skipped (compile, -shared, -jit -shared, -jit): the program reads the .rtti of a class two imports down that its discovery module skips; without the globals put back the compile and JIT variants fail. Co-Authored-By: Claude Opus 5.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.
Problem
After #772 every import is parsed once, but it is still generated 211 times for powder_sandbox's
checks.ts(0.67 s of codegen, where once each would be about 0.07 s).theModulereceives each import only once, becauseemittedFilesguards it. Nearly all the other generations go into discovery modules, which are thrown away when discovery ends.Fix (
MLIRGenModule.cpp,MLIRGenImpl.h,MLIRGenVariables.cpp)In a discovery module (
discoveryDepth > 0), an import that has already been discovered (discoveredImports) is no longer generated.fullNameGlobalsMap, which is scoped to each module. Generating an import registers its globals there, including each class's.rtti. Without them, testing aC | nullfor truth (p && p.read()) failed with "Class member '.rtti' can't be found". powder_sandbox'ssimulation.tshit this.importUnits..d.tsthat has not been recorded is generated, and recorded, right then. A module's references are emitted by its discovery's dummy run, so an import nested inside it never generates them.mlirGenImportSharedLib,libraryHoldingModule, a library's__decls) or an import cycle is generated every time, as before.theModulestill generates every import.Results
checks.ts--di -O0 -mm=gcchecks.ts-O3 -mm=rcpowder_sandbox_nri.ts--di -O0 -mm=gcsimulation.ts--di -O0 -mm=gcThe LLVM IR of
checks,powder_sandbox_nriandsimulationis identical to main's, after normalizing generated numeric ids. Compiled 10 times with each binary, checks.ts gave the same IR every time.Tests
import-chain-rtti-skipped(compile,-shared,-jit -shared,-jit), intslang/test/tester/import-chain/rtti_*.ts. The program reads the.rttiof a class two imports down, in a module its discovery skips. With the globals not put back, the compile and-jitvariants fail with the error above. The-sharedvariants reach the module through the library, so it is never skipped there.ctest -C Releaseon Windows: 6655/6655 passed.Next
In discovery,
nri_interop.d.ts, which most powder_sandbox files reference, is still generated about 20 times (0.26 s). Skipping it the same way would be a separate change.🤖 Generated with Claude Code