Fix #23239: give the nested tempinst a chance of instantiation#23346
Open
gulugulubing wants to merge 5 commits into
Open
Fix #23239: give the nested tempinst a chance of instantiation#23346gulugulubing wants to merge 5 commits into
gulugulubing wants to merge 5 commits into
Conversation
Contributor
Author
|
It looks break the phobo, marked as draft first. |
Contributor
Author
|
It looks good now, by moving the fix logic to needsCodegen(). The previous approach modified minst during semantic analysis, which could interfere with module-level template instantiation order and break Phobos builds. |
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.
Try to fix #23239:
The instance relationship was not immediately clear to me, so I used an LLM to help draw this graph:
The root cause:
touch!intis only instantiated once, insidestatic assert. StaticAssert::semantic2() sets sc.minst = null before evaluating the condition, so touch!int gets minst = null (speculative). Later when Tmpl!() is used at runtime and gets swapped to a root instance, the nested touch!int is left behind with minst = null, and needsCodegen() skips it entirely — including its static this().The fix: after the swap makes Tmpl!() a root instance, scan the root module's members for any speculative TemplateInstances whose enclosing chain resolves to the newly-rooted instance. There is no direct backlink from TemplateDeclaration to TemplateInstance, so we filter candidates by checking nested.tempdecl.isInstantiated(). Once found, set nested.minst = root.