Skip to content

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

Merged
merged 6 commits into from
Mar 8, 2017

Conversation

slavapestov
Copy link
Contributor

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.

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.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@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());
Copy link
Contributor

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.

Copy link
Contributor Author

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 :-)

@swiftix
Copy link
Contributor

swiftix commented Mar 8, 2017

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()) {
Copy link
Contributor

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.

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - de2f5f7
Test requested by - @slavapestov

@slavapestov
Copy link
Contributor Author

Looks like we hit a non deterministic crasher. I'll make a separate PR to disable it.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov slavapestov merged commit 0dc16d8 into swiftlang:master Mar 8, 2017
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.

3 participants