[5.9 π][Compile Time Constant Extraction] Map types with archetypes out of context, before mangling them for printing. #67696
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.
Cherry-pick of #67692
Matching logic in the ASTPrinter. Otherwise we attempt to mangle types with archetypes in them, which cannot be done, and causes the compiler to crash.
βββ CCC Information βββ
β’ Train: Swift 5.9
β’ Explanation: We have recently made late changes to compile-time metadata extraction from the AST in the compiler, in order to gather additional info about relevant conformances. One such addition is collecting mangled names of conformancesβ properties and compile-time-known type values. Extracting mangled type names of such types has an edge case that the code did not cover, specifically mangling types which contain archetypes (generic type parameters). Upon encountering such types and trying to mangle them, the compiler, unfortunately, crashes during extraction. Earlier we attempted to bypass this by removing mangling of properties altogether, but this was not sufficient to address the overall issue. This change is the general fix which maps archetype-containing types out of their generic context, mapping them to the interface type, before attempting mangling. This is something the code should have been doing all along, as mangling archetypes is impossible.
β’ Scope of Issue: User code with nominal types which conform to the extracted protocols and have properties whose type contains a generic parameter or whose properties are initialized with a type value which is a generic parameter will crash the compiler.
β’ Origination: Recent changes to extraction code to augment it with additional metadata.
β’ Risk: Small. This change causes types which are impossible to mangle to map to their interface type before mangling, removing an otherwise-always-crashing code-path.
β’ main Pull Request URL: #67692
β’ Reviewed By: @slavapestov
β’ Automated Testing: Automated test added to the compiler test suite.
Resolves rdar://113039215