-
Notifications
You must be signed in to change notification settings - Fork 10.5k
More SubstitutionList => SubstitutionMap cleanups #7969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ASTContext::getSpecializedConformance() already copies the substitutions, so remove some AllocateCopy() calls. Also, add a new overload taking a SubstitutionMap instead. This allows removing some gatherAllSubstitutions() calls, which have an allocation inside them. Finally, remove the now-unused ModuleDecl parameter from ProtocolConformance::subst() and make it public.
Extract this from Substitution::subst(), which is going away.
This will replace Substitution::subst().
…Cloner This also fixes a latent bug; we were substituting opened existentials inside the replacement type of a Substitution, but not inside the conformances.
I want to get rid of Substitution entirely, and now we have the right abstractions to do everything with SubstitutionMap.
@swift-ci Please test |
@swiftix Please take a look. |
@@ -351,6 +349,11 @@ bool SILPerformanceInliner::isProfitableToInline(FullApplySite AI, | |||
int BaseBenefit = RemovedCallBenefit; | |||
|
|||
SubstitutionMap CalleeSubstMap; | |||
if (IsGeneric) { | |||
CalleeSubstMap = Callee->getGenericEnvironment() | |||
->getSubstitutionMap(AI.getSubstitutions()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slavapestov please construct this map only on demand. There is no need to always create it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the new representation is done, going from a list to a map will be O(1), and going from a map to a list will just be a memcpy :-)
I like that we can now perform substitutions on the whole SubstitutionMap and on conformances. This is very useful. |
auto newConformance = | ||
conformance.subst(ty, | ||
[&](SubstitutableType *t) -> Type { | ||
if (t->isOpenedExistential()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use llvm's early return style here. if (!t-> isOpenedExistential()) return t;
This will reduce the indentation.
Build failed |
Looks like we hit a non deterministic crasher. I'll make a separate PR to disable it. |
@swift-ci Please smoke test macOS |
The goal here is to eliminate a few calls to TypeBase::gatherAllSubstitutions() and entirely kill off Substitution::subst(), dealing with the fallout along the way.
The main improvement is that we now have public APIs to substitute conformances, as well as a SubstitutionMap::subst() that substitutes all replacement types. Also, some unnecessary allocations in the permanent arena are now eliminated.