Skip to content

Commit 45fc0bc

Browse files
committed
Sema: Replace some calls to getDeclaredType() with getDeclaredInterfaceType()
1 parent 94c6bff commit 45fc0bc

22 files changed

+117
-99
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,7 +3594,10 @@ namespace {
35943594
ctx.Diags.diagnose(SourceLoc(), diag::broken_bool);
35953595
}
35963596

3597-
cs.setType(isSomeExpr, boolDecl ? boolDecl->getDeclaredType() : Type());
3597+
cs.setType(isSomeExpr,
3598+
boolDecl
3599+
? boolDecl->getDeclaredInterfaceType()
3600+
: Type());
35983601
return isSomeExpr;
35993602
}
36003603

@@ -8068,7 +8071,7 @@ static Optional<SolutionApplicationTarget> applySolutionToForEachStmt(
80688071
if (forEachStmtInfo.whereExpr) {
80698072
auto *boolDecl = dc->getASTContext().getBoolDecl();
80708073
assert(boolDecl);
8071-
Type boolType = boolDecl->getDeclaredType();
8074+
Type boolType = boolDecl->getDeclaredInterfaceType();
80728075
assert(boolType);
80738076

80748077
SolutionApplicationTarget whereTarget(
@@ -8269,7 +8272,7 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
82698272
return None;
82708273

82718274
// FIXME: Feels like we could leverage existing code more.
8272-
Type boolType = cs.getASTContext().getBoolDecl()->getDeclaredType();
8275+
Type boolType = cs.getASTContext().getBoolDecl()->getDeclaredInterfaceType();
82738276
guardExpr = solution.coerceToType(
82748277
guardExpr, boolType, cs.getConstraintLocator(info.guardExpr));
82758278
if (!guardExpr)

lib/Sema/CSGen.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ namespace {
11591159
TVO_PrefersSubtypeBinding |
11601160
TVO_CanBindToNoEscape);
11611161
CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
1162-
protocol->getDeclaredType(),
1162+
protocol->getDeclaredInterfaceType(),
11631163
CS.getConstraintLocator(expr));
11641164
return tv;
11651165
}
@@ -1184,7 +1184,7 @@ namespace {
11841184
TVO_PrefersSubtypeBinding |
11851185
TVO_CanBindToNoEscape);
11861186
CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
1187-
interpolationProto->getDeclaredType(),
1187+
interpolationProto->getDeclaredInterfaceType(),
11881188
locator);
11891189

11901190
if (auto appendingExpr = expr->getAppendingExpr()) {
@@ -1222,7 +1222,7 @@ namespace {
12221222
return nullptr;
12231223

12241224
auto unsafeRawPointer = ctx.getUnsafeRawPointerDecl();
1225-
return unsafeRawPointer->getDeclaredType();
1225+
return unsafeRawPointer->getDeclaredInterfaceType();
12261226
}
12271227

12281228
default:
@@ -1257,7 +1257,7 @@ namespace {
12571257
TVO_CanBindToHole);
12581258

12591259
CS.addConstraint(ConstraintKind::LiteralConformsTo, witnessType,
1260-
protocol->getDeclaredType(), exprLoc);
1260+
protocol->getDeclaredInterfaceType(), exprLoc);
12611261

12621262
// The arguments are required to be argument-convertible to the
12631263
// idealized parameter type of the initializer, which generally
@@ -1815,7 +1815,7 @@ namespace {
18151815
contextualArrayElementType = *arrayElementType;
18161816

18171817
CS.addConstraint(ConstraintKind::LiteralConformsTo, contextualType,
1818-
arrayProto->getDeclaredType(),
1818+
arrayProto->getDeclaredInterfaceType(),
18191819
locator);
18201820

18211821
unsigned index = 0;
@@ -1885,7 +1885,7 @@ namespace {
18851885

18861886
// The array must be an array literal type.
18871887
CS.addConstraint(ConstraintKind::LiteralConformsTo, arrayTy,
1888-
arrayProto->getDeclaredType(),
1888+
arrayProto->getDeclaredInterfaceType(),
18891889
locator);
18901890

18911891
// Its subexpression should be convertible to a tuple (T.Element...).
@@ -1950,7 +1950,7 @@ namespace {
19501950
Type contextualDictionaryElementType = TupleType::get(tupleElts, C);
19511951

19521952
CS.addConstraint(ConstraintKind::LiteralConformsTo, contextualType,
1953-
dictionaryProto->getDeclaredType(),
1953+
dictionaryProto->getDeclaredInterfaceType(),
19541954
locator);
19551955

19561956
unsigned index = 0;
@@ -1971,7 +1971,7 @@ namespace {
19711971

19721972
// The dictionary must be a dictionary literal type.
19731973
CS.addConstraint(ConstraintKind::LiteralConformsTo, dictionaryTy,
1974-
dictionaryProto->getDeclaredType(),
1974+
dictionaryProto->getDeclaredInterfaceType(),
19751975
locator);
19761976

19771977

@@ -2481,7 +2481,7 @@ namespace {
24812481
}
24822482

24832483
case PatternKind::Bool:
2484-
return setType(CS.getASTContext().getBoolDecl()->getDeclaredType());
2484+
return setType(CS.getASTContext().getBoolDecl()->getDeclaredInterfaceType());
24852485

24862486
case PatternKind::EnumElement: {
24872487
auto enumPattern = cast<EnumElementPattern>(pattern);
@@ -2701,7 +2701,7 @@ namespace {
27012701
// Okay, now it should be safe to coerce the pattern.
27022702
// Pull the top-level pattern back out.
27032703
pattern = LabelItem.getPattern();
2704-
Type exnType = CS.getASTContext().getErrorDecl()->getDeclaredType();
2704+
Type exnType = CS.getASTContext().getErrorDecl()->getDeclaredInterfaceType();
27052705

27062706
if (!exnType)
27072707
return false;
@@ -2978,7 +2978,7 @@ namespace {
29782978

29792979
CS.addConstraint(
29802980
ConstraintKind::Conversion, CS.getType(expr->getCondExpr()),
2981-
boolDecl->getDeclaredType(),
2981+
boolDecl->getDeclaredInterfaceType(),
29822982
CS.getConstraintLocator(expr, ConstraintLocator::Condition));
29832983

29842984
// The branches must be convertible to a common type.
@@ -3130,7 +3130,7 @@ namespace {
31303130
return Type();
31313131
}
31323132

3133-
return boolDecl->getDeclaredType();
3133+
return boolDecl->getDeclaredInterfaceType();
31343134
}
31353135

31363136
Type visitDiscardAssignmentExpr(DiscardAssignmentExpr *expr) {
@@ -3307,7 +3307,7 @@ namespace {
33073307
}
33083308

33093309
Type visitEnumIsCaseExpr(EnumIsCaseExpr *expr) {
3310-
return CS.getASTContext().getBoolDecl()->getDeclaredType();
3310+
return CS.getASTContext().getBoolDecl()->getDeclaredInterfaceType();
33113311
}
33123312

33133313
Type visitLazyInitializerExpr(LazyInitializerExpr *expr) {
@@ -3947,7 +3947,8 @@ generateForEachStmtConstraints(
39473947
cs.addConstraint(ConstraintKind::Conversion, cs.getType(sequence),
39483948
sequenceType, locator);
39493949
cs.addConstraint(ConstraintKind::ConformsTo, sequenceType,
3950-
sequenceProto->getDeclaredType(), contextualLocator);
3950+
sequenceProto->getDeclaredInterfaceType(),
3951+
contextualLocator);
39513952

39523953
// Check the element pattern.
39533954
ASTContext &ctx = cs.getASTContext();
@@ -4008,7 +4009,7 @@ generateForEachStmtConstraints(
40084009
if (!boolDecl)
40094010
return None;
40104011

4011-
Type boolType = boolDecl->getDeclaredType();
4012+
Type boolType = boolDecl->getDeclaredInterfaceType();
40124013
if (!boolType)
40134014
return None;
40144015

@@ -4194,7 +4195,7 @@ bool ConstraintSystem::generateConstraints(StmtCondition condition,
41944195
return true;
41954196
}
41964197

4197-
Type boolTy = boolDecl->getDeclaredType();
4198+
Type boolTy = boolDecl->getDeclaredInterfaceType();
41984199
for (const auto &condElement : condition) {
41994200
switch (condElement.getKind()) {
42004201
case StmtConditionElement::CK_Availability:

lib/Sema/CSRanking.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,15 @@ bool CompareDeclSpecializationRequest::evaluate(
567567
case SelfTypeRelationship::ConformsTo:
568568
assert(conformance);
569569
cs.addConstraint(ConstraintKind::ConformsTo, selfTy1,
570-
cast<ProtocolDecl>(outerDC2)->getDeclaredType(), locator);
570+
cast<ProtocolDecl>(outerDC2)->getDeclaredInterfaceType(),
571+
locator);
571572
break;
572573

573574
case SelfTypeRelationship::ConformedToBy:
574575
assert(conformance);
575576
cs.addConstraint(ConstraintKind::ConformsTo, selfTy2,
576-
cast<ProtocolDecl>(outerDC1)->getDeclaredType(), locator);
577+
cast<ProtocolDecl>(outerDC1)->getDeclaredInterfaceType(),
578+
locator);
577579
break;
578580
}
579581

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,7 +5501,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
55015501
// If we're supposed to generate constraints, do so.
55025502
if (flags.contains(TMF_GenerateConstraints)) {
55035503
addUnsolvedConstraint(
5504-
Constraint::create(*this, kind, type, protocol->getDeclaredType(),
5504+
Constraint::create(*this, kind, type,
5505+
protocol->getDeclaredInterfaceType(),
55055506
getConstraintLocator(locator)));
55065507
return SolutionKind::Solved;
55075508
}
@@ -5558,7 +5559,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
55585559
if (!shouldAttemptFixes())
55595560
return SolutionKind::Error;
55605561

5561-
auto protocolTy = protocol->getDeclaredType();
5562+
auto protocolTy = protocol->getDeclaredInterfaceType();
55625563

55635564
// If this conformance has been fixed already, let's just consider this done.
55645565
if (isFixedRequirement(getConstraintLocator(locator), protocolTy))
@@ -7196,9 +7197,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
71967197
auto result =
71977198
baseTy->is<MetatypeType>()
71987199
? solveWithNewBaseOrName(ExistentialMetatypeType::get(
7199-
proto->getDeclaredType()),
7200+
proto->getDeclaredInterfaceType()),
72007201
member)
7201-
: solveWithNewBaseOrName(proto->getDeclaredType(),
7202+
: solveWithNewBaseOrName(proto->getDeclaredInterfaceType(),
72027203
member);
72037204
if (result == SolutionKind::Solved)
72047205
return recordFix(
@@ -8963,7 +8964,7 @@ getDynamicCallableMethods(Type type, ConstraintSystem &CS,
89638964
if (auto archetype = dyn_cast<ArchetypeType>(canType)) {
89648965
SmallVector<Type, 2> componentTypes;
89658966
for (auto protocolDecl : archetype->getConformsTo())
8966-
componentTypes.push_back(protocolDecl->getDeclaredType());
8967+
componentTypes.push_back(protocolDecl->getDeclaredInterfaceType());
89678968
if (auto superclass = archetype->getSuperclass())
89688969
componentTypes.push_back(superclass);
89698970
return calculateForComponentTypes(componentTypes);
@@ -9159,15 +9160,15 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(
91599160
auto arrayLitProto =
91609161
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral);
91619162
addConstraint(ConstraintKind::ConformsTo, tvParam,
9162-
arrayLitProto->getDeclaredType(), locator);
9163+
arrayLitProto->getDeclaredInterfaceType(), locator);
91639164
auto elementAssocType = arrayLitProto->getAssociatedType(
91649165
ctx.Id_ArrayLiteralElement);
91659166
argumentType = DependentMemberType::get(tvParam, elementAssocType);
91669167
} else {
91679168
auto dictLitProto =
91689169
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
91699170
addConstraint(ConstraintKind::ConformsTo, tvParam,
9170-
dictLitProto->getDeclaredType(), locator);
9171+
dictLitProto->getDeclaredInterfaceType(), locator);
91719172
auto valueAssocType = dictLitProto->getAssociatedType(ctx.Id_Value);
91729173
argumentType = DependentMemberType::get(tvParam, valueAssocType);
91739174
}
@@ -9639,7 +9640,8 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
96399640
TVO_CanBindToNoEscape);
96409641

96419642
addConstraint(ConstraintKind::ConformsTo, tv,
9642-
hashableProtocol->getDeclaredType(), constraintLocator);
9643+
hashableProtocol->getDeclaredInterfaceType(),
9644+
constraintLocator);
96439645

96449646
return matchTypes(type1, tv, ConstraintKind::Conversion, subflags,
96459647
locator);

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ synthesizeStubBody(AbstractFunctionDecl *fn, void *) {
323323
}
324324

325325
auto *staticStringDecl = ctx.getStaticStringDecl();
326-
auto staticStringType = staticStringDecl->getDeclaredType();
326+
auto staticStringType = staticStringDecl->getDeclaredInterfaceType();
327327
auto staticStringInit = ctx.getStringBuiltinInitDecl(staticStringDecl);
328328

329329
auto *uintDecl = ctx.getUIntDecl();
330-
auto uintType = uintDecl->getDeclaredType();
330+
auto uintType = uintDecl->getDeclaredInterfaceType();
331331
auto uintInit = ctx.getIntBuiltinInitDecl(uintDecl);
332332

333333
// Create a call to Swift._unimplementedInitializer

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ void ConstraintSystem::bindOverloadType(
22022202
return;
22032203

22042204
addConstraint(ConstraintKind::LiteralConformsTo, argType,
2205-
stringLiteral->getDeclaredType(), locator);
2205+
stringLiteral->getDeclaredInterfaceType(), locator);
22062206

22072207
// If this is used inside of the keypath expression, we need to make
22082208
// sure that argument is Hashable.
@@ -2355,7 +2355,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
23552355
argType->getASTContext(), choice.getDecl()->getLoc(),
23562356
KnownProtocolKind::Hashable)) {
23572357
addConstraint(ConstraintKind::ConformsTo, argType,
2358-
hashable->getDeclaredType(),
2358+
hashable->getDeclaredInterfaceType(),
23592359
getConstraintLocator(
23602360
locator, LocatorPathElt::TupleElement(index)));
23612361
}
@@ -4672,7 +4672,7 @@ SolutionApplicationTarget SolutionApplicationTarget::forForEachStmt(
46724672
bool bindPatternVarsOneWay) {
46734673
SolutionApplicationTarget target(
46744674
stmt->getSequence(), dc, CTP_ForEachStmt,
4675-
sequenceProto->getDeclaredType(), /*isDiscarded=*/false);
4675+
sequenceProto->getDeclaredInterfaceType(), /*isDiscarded=*/false);
46764676
target.expression.pattern = stmt->getPattern();
46774677
target.expression.bindPatternVarsOneWay =
46784678
bindPatternVarsOneWay || (stmt->getWhere() != nullptr);

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
314314
// We want to look through all the var declarations of this type to create
315315
// enum cases based on those var names.
316316
auto *codingKeyProto = C.getProtocol(KnownProtocolKind::CodingKey);
317-
auto *codingKeyType = codingKeyProto->getDeclaredType();
317+
auto codingKeyType = codingKeyProto->getDeclaredInterfaceType();
318318
TypeLoc protoTypeLoc[1] = {TypeLoc::withoutLoc(codingKeyType)};
319319
MutableArrayRef<TypeLoc> inherited = C.AllocateCopy(protoTypeLoc);
320320

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ deriveRawValueInit(AbstractFunctionDecl *initDecl, void *) {
7878
auto *rawValueDecl = new (C) ParamDecl(
7979
SourceLoc(), SourceLoc(), C.Id_rawValue,
8080
SourceLoc(), C.Id_rawValue, parentDC);
81-
rawValueDecl->setInterfaceType(C.getIntDecl()->getDeclaredType());
81+
rawValueDecl->setInterfaceType(C.getIntDecl()->getDeclaredInterfaceType());
8282
rawValueDecl->setSpecifier(ParamSpecifier::Default);
8383
rawValueDecl->setImplicit();
8484
auto *paramList = ParameterList::createWithoutLoc(rawValueDecl);
@@ -362,7 +362,7 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
362362
auto name = requirement->getBaseName();
363363
if (name == Context.Id_stringValue) {
364364
// Synthesize `var stringValue: String { get }`
365-
auto stringType = Context.getStringDecl()->getDeclaredType();
365+
auto stringType = Context.getStringDecl()->getDeclaredInterfaceType();
366366
auto synth = [rawType, stringType](AbstractFunctionDecl *getterDecl) {
367367
if (rawType && rawType->isEqual(stringType)) {
368368
// enum SomeStringEnum : String {
@@ -393,7 +393,7 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
393393

394394
} else if (name == Context.Id_intValue) {
395395
// Synthesize `var intValue: Int? { get }`
396-
auto intType = Context.getIntDecl()->getDeclaredType();
396+
auto intType = Context.getIntDecl()->getDeclaredInterfaceType();
397397
auto optionalIntType = OptionalType::get(intType);
398398

399399
auto synth = [rawType, intType](AbstractFunctionDecl *getterDecl) {
@@ -422,7 +422,7 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
422422
if (argumentNames.size() == 1) {
423423
if (argumentNames[0] == Context.Id_stringValue) {
424424
// Derive `init?(stringValue:)`
425-
auto stringType = Context.getStringDecl()->getDeclaredType();
425+
auto stringType = Context.getStringDecl()->getDeclaredInterfaceType();
426426
auto synth = [rawType, stringType](AbstractFunctionDecl *initDecl) {
427427
if (rawType && rawType->isEqual(stringType)) {
428428
// enum SomeStringEnum : String {
@@ -455,7 +455,7 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
455455
return deriveInitDecl(*this, stringType, Context.Id_stringValue, synth);
456456
} else if (argumentNames[0] == Context.Id_intValue) {
457457
// Synthesize `init?(intValue:)`
458-
auto intType = Context.getIntDecl()->getDeclaredType();
458+
auto intType = Context.getIntDecl()->getDeclaredInterfaceType();
459459
auto synthesizer = [rawType, intType](AbstractFunctionDecl *initDecl) {
460460
if (rawType && rawType->isEqual(intType)) {
461461
// enum SomeIntEnum : Int {

lib/Sema/DerivedConformanceComparable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ deriveComparable_lt(
244244
getParamDecl("b")
245245
});
246246

247-
auto boolTy = C.getBoolDecl()->getDeclaredType();
247+
auto boolTy = C.getBoolDecl()->getDeclaredInterfaceType();
248248

249249
Identifier generatedIdentifier;
250250
if (parentDC->getParentModule()->isResilient()) {
@@ -271,7 +271,7 @@ deriveComparable_lt(
271271
// Add the @_implements(Comparable, < (_:_:)) attribute
272272
if (generatedIdentifier != C.Id_LessThanOperator) {
273273
auto comparable = C.getProtocol(KnownProtocolKind::Comparable);
274-
auto comparableType = comparable->getDeclaredType();
274+
auto comparableType = comparable->getDeclaredInterfaceType();
275275
auto comparableTypeExpr = TypeExpr::createImplicit(comparableType, C);
276276
SmallVector<Identifier, 2> argumentLabels = { Identifier(), Identifier() };
277277
auto comparableDeclName = DeclName(C, DeclBaseName(C.Id_LessThanOperator),
@@ -354,7 +354,7 @@ void DerivedConformance::tryDiagnoseFailedComparableDerivation(
354354
ctx.Diags.diagnose(rawTypeLoc,
355355
diag::comparable_synthesis_raw_value_not_allowed,
356356
rawType, nominal->getDeclaredInterfaceType(),
357-
comparableProto->getDeclaredType());
357+
comparableProto->getDeclaredInterfaceType());
358358
}
359359
}
360360
}

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ getOrSynthesizeTangentVectorStruct(DerivedConformance &derived, Identifier id) {
621621

622622
// Otherwise, synthesize a new struct.
623623
auto *diffableProto = C.getProtocol(KnownProtocolKind::Differentiable);
624-
auto diffableType = TypeLoc::withoutLoc(diffableProto->getDeclaredType());
624+
auto diffableType = TypeLoc::withoutLoc(diffableProto->getDeclaredInterfaceType());
625625
auto *addArithProto = C.getProtocol(KnownProtocolKind::AdditiveArithmetic);
626-
auto addArithType = TypeLoc::withoutLoc(addArithProto->getDeclaredType());
626+
auto addArithType = TypeLoc::withoutLoc(addArithProto->getDeclaredInterfaceType());
627627

628628
// By definition, `TangentVector` must conform to `Differentiable` and
629629
// `AdditiveArithmetic`.

0 commit comments

Comments
 (0)