Repository navigation
perf(resolve): match names first under recursive imports - #1192
Closed
devin-ai-integration[bot] wants to merge 9 commits into
Closed
devin-ai-integration[bot] wants to merge 9 commits into
devin-ai-integration[bot] wants to merge 9 commits into
Conversation
A lookup of one name through import X::** listed every element below X and ran the KerML 7.2.5.4 hiding checks on each. The enumeration now takes a selector: by name it tries each namespace's own members and the index entries bound to the name, descends only into members that may be namespaces, and applies the visibility, re-export and hiding checks to those alone. Full listings keep the selector empty and are unchanged. Also: a settled per-symbol memo for derived short names, a per-generation FQN cache on the index, and a map-free elementList for small lists. Co-Authored-By: jason.han <[email protected]>
…cursive-import-matching
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
HuiJun
marked this pull request as ready for review
October 16, 2026 05:03
A derived short name (KerML 8.2.3.3) is the declared short name of the feature a naming chain ends at, so a scope's chains are resolved for a name only when some declaration the index knows has that short name (Index.ShortNamed, read as a segment), and only when the scope has derived-named members at all. The derived-short-name memo is neither read nor written while a filter condition resolves unfiltered or an import all lifts the visibility boundary. Co-Authored-By: jason.han <[email protected]>
…cursive-import-matching
…ed ones The index walks only named symbols' scopes, so a short name declared under an unnamed owner or in a body-local scope is in no index entry; the derived-short- name gate now also consults the set of short names declared anywhere in the scope's document, collected once per root scope. Co-Authored-By: jason.han <[email protected]>
Co-Authored-By: jason.han <[email protected]>
Asking Index.ShortNamed before resolving a scope's naming chains recorded a segment read, and a recorded document whose analysis took that read turned stale as soon as another document re-exported its names, so it was hydrated (TestWorkspacePortLintReadsRecordedDefinitions). The chains are resolved only for scopes that have derived-named members, which needs no read of its own. Co-Authored-By: jason.han <[email protected]>
namespaceChildren listed every index child of the target before narrowing the list to the name asked for; the narrowed lookup is now the only one. Co-Authored-By: jason.han <[email protected]>
Co-Authored-By: jason.han <[email protected]>
Contributor
Author
|
Closing: on current develop the subtest this change targeted ( |
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.
What and why
Since the hiding of colliding imported memberships (KerML 7.2.5.4) landed, a lookup of one name through
import X::**enumerated every element belowXand ran the per-element hiding checks (admitsUnderName,reexportedUnder,hiddenOnRoute,withoutHiddenMembers) on each of them before comparing names. On models built from recursive imports (the OMGVehicle Exampleinexamples/pilot-corpora/sysml-examples) name resolution became about sixty percent slower, and thetests/modelrace shard sits near its timeout.The enumeration in
internal/semantic/resolve/filter.gonow takes amemberSelect:named: a lookup lists, per visited namespace, only the members bound to the name — the scope'sLookupLocalAllplus derived short names (shortNamedMembers), the child imports asked for the same name, and the index entries bound to it (declared name, short name, or a derived short name for an entry the index alone holds). The hiding, re-export and visibility checks run on those alone.namespaces: the recursive descent lists only the members that can be namespaces (own members or imports, or index entries under their name; never a body-local scope) and checks only those, so a namespace that is hidden or not admitted still hides its subtree as before.ImportedElements, completion, theDuplicate of imported member nameaudit and the distinguishability warnings are unchanged.Around it, none changing an answer:
derivedShortNamememoizes a settled answer per symbol (journaled to the symbol's document frame), skipped while a naming chain under way cut it short, while the lookup was cut by an import cycle, and while a filter condition resolves unfiltered or animport alllifts the visibility boundary.Index.ShortNamedwas tried and dropped: its segment read made a recorded document's analysis stale as soon as another document re-exported its names, so the record was hydrated (TestWorkspacePortLintReadsRecordedDefinitions).Index.GetFQNcaches the built FQN per symbol for the index generation (FQNOfwas ~27% of all allocation: the string was rebuilt for every namespace a lookup visited).elementListdedups by a linear scan until it holds sixteen keys, then indexes.memberCache.fqnjoins the lazily filled cachesTestSnapshotIndexMatchesFreshLoadskips when comparing a decoded snapshot with a fresh load.Specification basis
No behaviour change. KerML 7.2.5.4 / 8.3.2.4.3 hiding of indistinguishable imported memberships (declared and derived short names, KerML 8.2.3.3) is applied exactly as before, to the candidates instead of to the whole subtree;
Resolver.InConditionis untouched.tests/resolvegainsTestDerivedShortNameFromADeclarationUnderAnUnnamedOwner: a redefinition borrowing a short name declared under an anonymous part, which no index entry holds.How it was verified
Measured on one machine (8 cores),
go test -count=1 -run 'TestInterfaceRecordDifferentialCorpora/sysml-examples' ./tests/model, back to back (wall):-race0af9fcb36)6b81872(before #1155, #1158 and the day's merges)e00ce72(with #1158)On current develop the costs this change removes no longer show in the profile (subtree enumeration per lookup, derived-short-name chains: under 1 s), but the subtest's time is now dominated by
Model.generalizationTarget(41 s of 160 s CPU, throughcollectContributorsandgeneralsOf) and by the captured collision sets of #1158 (importedCollisions→capturing→collectImported, 28 s, mostly import-target resolution andmetadataBodyOwnerending in generalization resolution), so the end-to-end number does not move there. The-racecolumn was taken in one sequence on the earlier develop.Passing:
internal/semantic/...,internal/check/...,internal/workspace/...,internal/frontend/...,tests/resolve,tests/export,tests/migrate,tests/parser,make lint, andtests/modelTestIncrementalEqualsFresh,TestSnapshotIndexMatchesFreshLoad,TestInterfaceRecordDifferential$,TestPackagesImportingEachOtherInACycleAnalysePromptly.Checklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/26443c7e5db24d5c99c23cd94846f6a0
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/26443c7e5db24d5c99c23cd94846f6a0?variant=devin
Requested by: @HuiJun