Skip to content

Conversation

@slavapestov
Copy link
Contributor

I noticed that SIL had three copy and pasted implementations of the algorithm for replacing opened existential archetypes with concrete types. This optimization comes up if inlining produces an existential value formed from a concrete type which is then immediately opened; we can eliminate the existential archetype in that case. However, this bit of copy and paste predated the introduction of generalized existentials, so it did not handle member types at all. This is a potential landmine if it ends up being used in more places in SIL.

This PR factors out one of the duplicate copies into a new "official" ReplaceExistentialArchetypesWithConcreteTypes, analogous to the transformer used for opaque archetypes. The new version is more complicated but it handles existential archetypes in full generality now. The other duplicate copy was a special case of an existing utility in SILCloner, and the third one was dead.

Let's use transformRec() instead of subst() here since we want to
leave DependentMemberTypes unchanged. This avoids an assertion
failure with the upcoming change to InFlightSubstitution::lookupConformance().
The special handling of DynamicSelfType should no longer be necessary
so I'm removing it.
This replaces the oddly-named mapIntoTypeExpansionContext() method
on SubstitutionMap itself in favor of a global function, just like
the ones that take Type and ProtocolConformanceRef.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov enabled auto-merge April 29, 2025 17:58
@slavapestov
Copy link
Contributor Author

swiftlang/llvm-project#10587
@swift-ci Please smoke test macOS

@slavapestov slavapestov merged commit 6b4710e into swiftlang:main Apr 30, 2025
5 checks passed
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