Skip to content

Commit 4e50e4e

Browse files
authored
Remove some unnecessary mapTypeIntoContext calls from CSGen. (#11743)
These helpers are all about trying to decide if a particular overload is "favored", but the answer won't change if a local archetype is actually the type we're looking for, so there's no advantage to using contextual types over interface types. On top of that, the calls to mapTypeIntoContext are forcing the deserialization of several generic environments that would have otherwise been left untouched, resulting in unnecessary calls to the generic signature builder. This isn't a recent change, but we're seeing strain around the generic signature builder and complex constraints in the standard library anyway, so we'll take wins where we can get them. Discovered as part of the performance investigation in rdar://problem/33984386.
1 parent dd38ace commit 4e50e4e

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,6 @@ namespace {
644644
auto overloadChoice = favoredConstraints[0]->getOverloadChoice();
645645
auto overloadType = overloadChoice.getDecl()->getInterfaceType();
646646
auto resultType = overloadType->getAs<AnyFunctionType>()->getResult();
647-
resultType = overloadChoice.getDecl()->getInnermostDeclContext()
648-
->mapTypeIntoContext(resultType);
649647
CS.setFavoredType(expr, resultType.getPointer());
650648
}
651649

@@ -731,10 +729,8 @@ namespace {
731729
fnTy = fnTy->getResult()->castTo<AnyFunctionType>();
732730
}
733731

734-
Type paramTy = value->getInnermostDeclContext()
735-
->mapTypeIntoContext(fnTy->getInput());
736-
auto resultTy = value->getInnermostDeclContext()
737-
->mapTypeIntoContext(fnTy->getResult());
732+
Type paramTy = fnTy->getInput();
733+
auto resultTy = fnTy->getResult();
738734
auto contextualTy = CS.getContextualType(expr);
739735

740736
return isFavoredParamAndArg(
@@ -808,9 +804,6 @@ namespace {
808804
}
809805
}
810806
Type paramTy = fnTy->getInput();
811-
paramTy = value->getInnermostDeclContext()
812-
->mapTypeIntoContext(paramTy);
813-
814807
return favoredTy->isEqual(paramTy);
815808
};
816809

@@ -895,17 +888,15 @@ namespace {
895888
fnTy = fnTy->getResult()->castTo<AnyFunctionType>();
896889
}
897890

898-
Type paramTy = value->getInnermostDeclContext()
899-
->mapTypeIntoContext(fnTy->getInput());
891+
Type paramTy = fnTy->getInput();
900892
auto paramTupleTy = paramTy->getAs<TupleType>();
901893
if (!paramTupleTy || paramTupleTy->getNumElements() != 2)
902894
return false;
903895

904896
auto firstParamTy = paramTupleTy->getElement(0).getType();
905897
auto secondParamTy = paramTupleTy->getElement(1).getType();
906898

907-
auto resultTy = value->getInnermostDeclContext()
908-
->mapTypeIntoContext(fnTy->getResult());
899+
auto resultTy = fnTy->getResult();
909900
auto contextualTy = CS.getContextualType(expr);
910901

911902
return

0 commit comments

Comments
 (0)