Skip to content

Commit 763b58e

Browse files
authored
Merge pull request #6665 from slavapestov/scalability-fix-and-cleanups
Scalability fix and cleanups
2 parents 466d000 + 6c75bf8 commit 763b58e

27 files changed

+241
-188
lines changed

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,17 @@ ProjectBoxInst *getOrCreateProjectBox(AllocBoxInst *ABI, unsigned Index);
137137
/// if possible.
138138
void replaceDeadApply(ApplySite Old, ValueBase *New);
139139

140-
/// \brief Return true if the substitution map contains a
141-
/// substitution that is an unbound generic type.
142-
bool hasUnboundGenericTypes(const TypeSubstitutionMap &SubsMap);
140+
/// \brief Return true if the substitution map contains replacement types
141+
/// that are dependent on the type parameters of the caller.
142+
bool hasTypeParameterTypes(SubstitutionMap &SubsMap);
143143

144-
/// Return true if the substitution list contains a substitution
145-
/// that is an unbound generic.
146-
bool hasUnboundGenericTypes(ArrayRef<Substitution> Subs);
144+
/// \brief Return true if the substitution list contains replacement types
145+
/// that are dependent on the type parameters of the caller.
146+
bool hasArchetypes(ArrayRef<Substitution> Subs);
147147

148148
/// \brief Return true if the substitution map contains a
149149
/// substitution that refers to the dynamic Self type.
150-
bool hasDynamicSelfTypes(const TypeSubstitutionMap &SubsMap);
151-
152-
/// \brief Return true if the substitution list contains a
153-
/// substitution that refers to the dynamic Self type.
154-
bool hasDynamicSelfTypes(ArrayRef<Substitution> Subs);
150+
bool hasDynamicSelfTypes(const SubstitutionMap &SubsMap);
155151

156152
/// \brief Return true if any call inside the given function may bind dynamic
157153
/// 'Self' to a generic argument of the callee.

lib/AST/ASTVerifier.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,17 +1249,17 @@ struct ASTNodeBase {};
12491249
Out << "\n";
12501250
abort();
12511251
}
1252-
CanType InputExprTy = E->getArg()->getType()->getCanonicalType();
1253-
CanType ResultExprTy = E->getType()->getCanonicalType();
1254-
if (ResultExprTy != FT->getResult()->getCanonicalType()) {
1252+
Type InputExprTy = E->getArg()->getType();
1253+
Type ResultExprTy = E->getType();
1254+
if (!ResultExprTy->isEqual(FT->getResult())) {
12551255
Out << "result of ApplyExpr does not match result type of callee:";
12561256
E->getType().print(Out);
12571257
Out << " vs. ";
12581258
FT->getResult()->print(Out);
12591259
Out << "\n";
12601260
abort();
12611261
}
1262-
if (InputExprTy != FT->getInput()->getCanonicalType()) {
1262+
if (!InputExprTy->isEqual(FT->getInput())) {
12631263
TupleType *TT = FT->getInput()->getAs<TupleType>();
12641264
if (isa<SelfApplyExpr>(E)) {
12651265
Type InputExprObjectTy;
@@ -1274,8 +1274,7 @@ struct ASTNodeBase {};
12741274
checkSameOrSubType(InputExprObjectTy, FunctionInputObjectTy,
12751275
"object argument and 'self' parameter");
12761276
} else if (!TT || TT->getNumElements() != 1 ||
1277-
TT->getElement(0).getType()->getCanonicalType()
1278-
!= InputExprTy) {
1277+
!TT->getElement(0).getType()->isEqual(InputExprTy)) {
12791278
Out << "Argument type does not match parameter type in ApplyExpr:"
12801279
"\nArgument type: ";
12811280
E->getArg()->getType().print(Out);
@@ -1892,8 +1891,7 @@ struct ASTNodeBase {};
18921891
return;
18931892
}
18941893

1895-
if (type->getCanonicalType() !=
1896-
conformance.getConcrete()->getType()->getCanonicalType()) {
1894+
if (!type->isEqual(conformance.getConcrete()->getType())) {
18971895
Out << "conforming type does not match conformance\n";
18981896
Out << "conforming type:\n";
18991897
type.dump(Out, 2);
@@ -2518,7 +2516,7 @@ struct ASTNodeBase {};
25182516
}
25192517

25202518
void checkSameType(Type T0, Type T1, const char *what) {
2521-
if (T0->getCanonicalType() == T1->getCanonicalType())
2519+
if (T0->isEqual(T1))
25222520
return;
25232521

25242522
Out << "different types for " << what << ": ";
@@ -2568,7 +2566,7 @@ struct ASTNodeBase {};
25682566
}
25692567

25702568
void checkSameOrSubType(Type T0, Type T1, const char *what) {
2571-
if (T0->getCanonicalType() == T1->getCanonicalType())
2569+
if (T0->isEqual(T1))
25722570
return;
25732571

25742572
// Protocol subtyping.

lib/AST/Availability.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class AvailabilityInferenceTypeWalker : public TypeWalker {
188188
AvailabilityInferenceTypeWalker(ASTContext &AC) : AC(AC) {}
189189

190190
Action walkToTypePre(Type ty) override {
191-
if (auto *nominalDecl = ty->getCanonicalType()->getAnyNominal()) {
191+
if (auto *nominalDecl = ty->getAnyNominal()) {
192192
AvailabilityInfo.intersectWith(
193193
AvailabilityInference::availableRange(nominalDecl, AC));
194194
}

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static void formatDiagnosticArgument(StringRef Modifier,
391391
showAKA = false;
392392

393393
// Don't show generic type parameters.
394-
if (showAKA && type->getCanonicalType()->hasTypeParameter())
394+
if (showAKA && type->hasTypeParameter())
395395
showAKA = false;
396396

397397
if (showAKA)

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ Type GenericSignature::getRepresentative(Type type, ModuleDecl &mod) {
466466
if (rep->isConcreteType()) return rep->getConcreteType();
467467
if (pa == rep) {
468468
assert(rep->getDependentType(getGenericParams(), /*allowUnresolved*/ false)
469-
->getCanonicalType() == type->getCanonicalType());
469+
->isEqual(type));
470470
return type;
471471
}
472472
return rep->getDependentType(getGenericParams(), /*allowUnresolved*/ false);

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ SpecializedProtocolConformance::getTypeWitnessSubstAndDecl(
414414
assert((conforms ||
415415
specializedType->isTypeVariableOrMember() ||
416416
specializedType->isTypeParameter() ||
417-
specializedType->hasError() ||
418-
specializedType->getCanonicalType()->hasError()) &&
417+
specializedType->hasError()) &&
419418
"Improperly checked substitution");
420419
conformances.push_back(conforms ? *conforms
421420
: ProtocolConformanceRef(proto));

lib/AST/Substitution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool Substitution::operator==(const Substitution &other) const {
2929
// The archetypes may be missing, but we can compare them directly
3030
// because archetypes are always canonical.
3131
return
32-
Replacement->getCanonicalType() == other.Replacement->getCanonicalType() &&
32+
Replacement->isEqual(other.Replacement) &&
3333
Conformance.equals(other.Conformance);
3434
}
3535

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,18 +3708,17 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37083708
// We can only say .foo where foo is a static member of the contextual
37093709
// type and has the same type (or if the member is a function, then the
37103710
// same result type) as the contextual type.
3711-
auto contextCanT = T->getCanonicalType();
37123711
FilteredDeclConsumer consumer(*this, [=](ValueDecl *VD, DeclVisibilityKind reason) {
37133712
if (!VD->hasInterfaceType()) {
37143713
TypeResolver->resolveDeclSignature(VD);
37153714
if (!VD->hasInterfaceType())
37163715
return false;
37173716
}
37183717

3719-
auto T = VD->getInterfaceType();
3720-
while (auto FT = T->getAs<AnyFunctionType>())
3721-
T = FT->getResult();
3722-
return T->getCanonicalType() == contextCanT;
3718+
auto declTy = VD->getInterfaceType();
3719+
while (auto FT = declTy->getAs<AnyFunctionType>())
3720+
declTy = FT->getResult();
3721+
return declTy->isEqual(T);
37233722
});
37243723

37253724
auto baseType = MetatypeType::get(T);

lib/IDE/TypeReconstruction.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,10 @@ static void VisitNodeConstructor(
945945

946946
const AnyFunctionType *type_func =
947947
type_result._types.front()->getAs<AnyFunctionType>();
948-
if (identifier_func->getResult()->getCanonicalType() ==
949-
type_func->getResult()->getCanonicalType() &&
950-
identifier_func->getInput()->getCanonicalType() ==
951-
type_func->getInput()->getCanonicalType()) {
948+
if (identifier_func->getResult()->isEqual(
949+
type_func->getResult()) &&
950+
identifier_func->getInput()->isEqual(
951+
type_func->getInput())) {
952952
result._module = kind_type_result._module;
953953
result._decls.push_back(kind_type_result._decls[i]);
954954
result._types.push_back(
@@ -1481,8 +1481,8 @@ static void VisitNodeSetterGetter(
14811481
const AnyFunctionType *type_func =
14821482
type_result._types.front()->getAs<AnyFunctionType>();
14831483

1484-
CanType type_result_type = type_func->getResult()->getCanonicalType();
1485-
CanType type_input_type = type_func->getInput()->getCanonicalType();
1484+
Type type_result_type = type_func->getResult();
1485+
Type type_input_type = type_func->getInput();
14861486

14871487
FuncDecl *identifier_func = nullptr;
14881488

@@ -1520,14 +1520,12 @@ static void VisitNodeSetterGetter(
15201520
const AnyFunctionType *identifier_uncurried_result =
15211521
identifier_func_type->getResult()->getAs<AnyFunctionType>();
15221522
if (identifier_uncurried_result) {
1523-
CanType identifier_result_type =
1524-
identifier_uncurried_result->getResult()
1525-
->getCanonicalType();
1526-
CanType identifier_input_type =
1527-
identifier_uncurried_result->getInput()
1528-
->getCanonicalType();
1529-
if (identifier_result_type == type_result_type &&
1530-
identifier_input_type == type_input_type) {
1523+
Type identifier_result_type =
1524+
identifier_uncurried_result->getResult();
1525+
Type identifier_input_type =
1526+
identifier_uncurried_result->getInput();
1527+
if (identifier_result_type->isEqual(type_result_type) &&
1528+
identifier_input_type->isEqual(type_input_type)) {
15311529
break;
15321530
}
15331531
}

lib/SILOptimizer/IPO/UsePrespecialized.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,9 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
9494
if (!SpecType)
9595
continue;
9696

97-
// Bail if any generic types parameters of the concrete type
98-
// are unbound.
99-
if (SpecType->hasArchetype())
100-
continue;
101-
102-
// Bail if any generic types parameters of the concrete type
103-
// are unbound.
104-
if (hasUnboundGenericTypes(Subs))
97+
// Bail any callee generic type parameters are dependent on the generic
98+
// parameters of the caller.
99+
if (SpecType->hasArchetype() || hasArchetypes(Subs))
105100
continue;
106101

107102
// Create a name of the specialization.

0 commit comments

Comments
 (0)