Skip to content

Commit cd3ada5

Browse files
authored
getInterfaceType() always returns a type (#28210)
getInterfaceType() always returns a type
2 parents 71df606 + a7fb2d3 commit cd3ada5

15 files changed

+52
-97
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,26 +2526,26 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25262526
[&]{
25272527
Printer.printName(decl->getName(), getTypeMemberPrintNameContext(decl));
25282528
});
2529-
if (auto type = decl->getInterfaceType()) {
2530-
Printer << ": ";
2531-
TypeLoc tyLoc;
2532-
if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr())
2533-
tyLoc = TypeLoc(repr, type);
2534-
else
2535-
tyLoc = TypeLoc::withoutLoc(type);
25362529

2537-
Printer.printDeclResultTypePre(decl, tyLoc);
2530+
auto type = decl->getInterfaceType();
2531+
Printer << ": ";
2532+
TypeLoc tyLoc;
2533+
if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr())
2534+
tyLoc = TypeLoc(repr, type);
2535+
else
2536+
tyLoc = TypeLoc::withoutLoc(type);
25382537

2539-
// HACK: When printing result types for vars with opaque result types,
2540-
// always print them using the `some` keyword instead of printing
2541-
// the full stable reference.
2542-
llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2543-
x(Options.OpaqueReturnTypePrinting,
2544-
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2538+
Printer.printDeclResultTypePre(decl, tyLoc);
25452539

2546-
printTypeLocForImplicitlyUnwrappedOptional(
2547-
tyLoc, decl->isImplicitlyUnwrappedOptional());
2548-
}
2540+
// HACK: When printing result types for vars with opaque result types,
2541+
// always print them using the `some` keyword instead of printing
2542+
// the full stable reference.
2543+
llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2544+
x(Options.OpaqueReturnTypePrinting,
2545+
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2546+
2547+
printTypeLocForImplicitlyUnwrappedOptional(
2548+
tyLoc, decl->isImplicitlyUnwrappedOptional());
25492549

25502550
printAccessors(decl);
25512551
}
@@ -2674,18 +2674,13 @@ void PrintAST::printFunctionParameters(AbstractFunctionDecl *AFD) {
26742674
auto curTy = AFD->getInterfaceType();
26752675

26762676
// Skip over the implicit 'self'.
2677-
if (AFD->hasImplicitSelfDecl()) {
2678-
if (curTy)
2679-
if (auto funTy = curTy->getAs<AnyFunctionType>())
2680-
curTy = funTy->getResult();
2681-
}
2677+
if (AFD->hasImplicitSelfDecl())
2678+
if (auto funTy = curTy->getAs<AnyFunctionType>())
2679+
curTy = funTy->getResult();
26822680

26832681
ArrayRef<AnyFunctionType::Param> parameterListTypes;
2684-
if (curTy) {
2685-
if (auto funTy = curTy->getAs<AnyFunctionType>()) {
2686-
parameterListTypes = funTy->getParams();
2687-
}
2688-
}
2682+
if (auto funTy = curTy->getAs<AnyFunctionType>())
2683+
parameterListTypes = funTy->getParams();
26892684

26902685
printParameterList(BodyParams, parameterListTypes,
26912686
AFD->argumentNameIsAPIByDefault());
@@ -2878,15 +2873,14 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) {
28782873

28792874

28802875
auto params = ArrayRef<AnyFunctionType::Param>();
2881-
if (auto type = elt->getInterfaceType()) {
2882-
if (!elt->isInvalid()) {
2883-
// Walk to the params of the associated values.
2884-
// (EnumMetaType) -> (AssocValues) -> Enum
2885-
params = type->castTo<AnyFunctionType>()
2886-
->getResult()
2887-
->castTo<AnyFunctionType>()
2888-
->getParams();
2889-
}
2876+
if (!elt->isInvalid()) {
2877+
// Walk to the params of the associated values.
2878+
// (EnumMetaType) -> (AssocValues) -> Enum
2879+
auto type = elt->getInterfaceType();
2880+
params = type->castTo<AnyFunctionType>()
2881+
->getResult()
2882+
->castTo<AnyFunctionType>()
2883+
->getParams();
28902884
}
28912885

28922886
// @escaping is not valid in enum element position, even though the
@@ -2977,11 +2971,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
29772971
}, [&] { // Parameters
29782972
printGenericDeclGenericParams(decl);
29792973
auto params = ArrayRef<AnyFunctionType::Param>();
2980-
if (auto type = decl->getInterfaceType()) {
2981-
if (!decl->isInvalid()) {
2982-
// Walk to the params of the subscript's indices.
2983-
params = type->castTo<AnyFunctionType>()->getParams();
2984-
}
2974+
if (!decl->isInvalid()) {
2975+
// Walk to the params of the subscript's indices.
2976+
auto type = decl->getInterfaceType();
2977+
params = type->castTo<AnyFunctionType>()->getParams();
29852978
}
29862979
printParameterList(decl->getIndices(), params,
29872980
/*isAPINameByDefault*/false);

lib/AST/Decl.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,11 +3431,7 @@ Type TypeDecl::getDeclaredInterfaceType() const {
34313431
selfTy, const_cast<AssociatedTypeDecl *>(ATD));
34323432
}
34333433

3434-
Type interfaceType = getInterfaceType();
3435-
if (!interfaceType)
3436-
return ErrorType::get(getASTContext());
3437-
3438-
return interfaceType->getMetatypeInstanceType();
3434+
return getInterfaceType()->getMetatypeInstanceType();
34393435
}
34403436

34413437
int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
@@ -4776,10 +4772,6 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value,
47764772

47774773
auto type = value->getInterfaceType();
47784774

4779-
// FIXME: Deal with broken recursion.
4780-
if (!type)
4781-
return SelfReferenceKind::None();
4782-
47834775
// Skip invalid declarations.
47844776
if (type->hasError())
47854777
return SelfReferenceKind::None();

lib/AST/USRGeneration.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
242242
}
243243

244244
auto declIFaceTy = D->getInterfaceType();
245-
if (!declIFaceTy)
246-
return std::string();
247245

248246
// Invalid code.
249247
if (declIFaceTy.findIf([](Type t) -> bool {

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ static void collectPossibleCalleesByQualifiedLookup(
288288
if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD))
289289
continue;
290290
Type declaredMemberType = VD->getInterfaceType();
291-
if (!declaredMemberType) {
292-
continue;
293-
}
294291
if (!declaredMemberType->is<AnyFunctionType>())
295292
continue;
296293
if (VD->getDeclContext()->isTypeContext()) {

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5274,10 +5274,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
52745274
return;
52755275
}
52765276

5277-
// FIXME: Deal with broken recursion
5278-
if (!decl->hasInterfaceType())
5279-
return;
5280-
52815277
// Dig out the instance type and figure out what members of the instance type
52825278
// we are going to see.
52835279
auto baseTy = candidate.getBaseType();
@@ -5649,10 +5645,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
56495645
return result;
56505646
}
56515647

5652-
// FIXME: Deal with broken recursion
5653-
if (!cand->hasInterfaceType())
5654-
continue;
5655-
56565648
result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false,
56575649
/*isUnwrappedOptional=*/false),
56585650
MemberLookupResult::UR_Inaccessible);

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
602602
auto ctors = TypeChecker::lookupConstructors(
603603
CS.DC, instanceType, NameLookupFlags::IgnoreAccessControl);
604604
for (auto ctor : ctors) {
605-
if (ctor.getValueDecl()->getInterfaceType())
606-
candidates.push_back({ ctor.getValueDecl(), 1 });
605+
candidates.push_back({ ctor.getValueDecl(), 1 });
607606
}
608607
}
609608

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
14711471

14721472
// Retrieve the interface type.
14731473
auto type = decl->getInterfaceType();
1474-
if (!type || type->hasError()) {
1474+
if (type->hasError()) {
14751475
return Type();
14761476
}
14771477

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,11 +3935,8 @@ bool swift::isMemberOperator(FuncDecl *decl, Type type) {
39353935
// Check the parameters for a reference to 'Self'.
39363936
bool isProtocol = selfNominal && isa<ProtocolDecl>(selfNominal);
39373937
for (auto param : *decl->getParameters()) {
3938-
auto paramType = param->getInterfaceType();
3939-
if (!paramType) break;
3940-
39413938
// Look through a metatype reference, if there is one.
3942-
paramType = paramType->getMetatypeInstanceType();
3939+
auto paramType = param->getInterfaceType()->getMetatypeInstanceType();
39433940

39443941
auto nominal = paramType->getAnyNominal();
39453942
if (type.isNull()) {

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,10 @@ static void diagnoseFunctionParamNotRepresentable(
225225
AFD->diagnose(diag::objc_invalid_on_func_param_type,
226226
ParamIndex + 1, getObjCDiagnosticAttrKind(Reason));
227227
}
228-
if (Type ParamTy = P->getType()) {
229-
SourceRange SR;
230-
if (auto typeRepr = P->getTypeRepr())
231-
SR = typeRepr->getSourceRange();
232-
diagnoseTypeNotRepresentableInObjC(AFD, ParamTy, SR);
233-
}
228+
SourceRange SR;
229+
if (auto typeRepr = P->getTypeRepr())
230+
SR = typeRepr->getSourceRange();
231+
diagnoseTypeNotRepresentableInObjC(AFD, P->getType(), SR);
234232
describeObjCReason(AFD, Reason);
235233
}
236234

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,6 @@ diagnoseMismatchedOptionals(const ValueDecl *member,
287287
Type paramTy = decl->getType();
288288
Type parentParamTy = parentDecl->getType();
289289

290-
if (!paramTy || !parentParamTy)
291-
return;
292-
293290
auto *repr = decl->getTypeRepr();
294291
if (!repr)
295292
return;

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,10 +1488,7 @@ void TypeChecker::coerceParameterListToType(ParameterList *P, ClosureExpr *CE,
14881488
if (param->isInvalid())
14891489
return true;
14901490

1491-
if (auto type = param->getType())
1492-
return !isValidType(type);
1493-
1494-
return true;
1491+
return !isValidType(param->getType());
14951492
};
14961493

14971494
auto handleParameter = [&](ParamDecl *param, Type ty, bool forceMutable) {

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
546546

547547
// Compute the type of the property to plug in to the wrapper type.
548548
Type propertyType = var->getType();
549-
if (!propertyType || propertyType->hasError())
549+
if (propertyType->hasError())
550550
return Type();
551551

552552
using namespace constraints;

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11631163
}
11641164
assert(isa<CaseStmt>(initialCaseVarDecl->getParentPatternStmt()));
11651165

1166-
if (vd->getInterfaceType() && initialCaseVarDecl->getType() &&
1167-
!initialCaseVarDecl->isInvalid() &&
1166+
if (!initialCaseVarDecl->isInvalid() &&
11681167
!vd->getType()->isEqual(initialCaseVarDecl->getType())) {
11691168
getASTContext().Diags.diagnose(vd->getLoc(), diag::type_mismatch_multiple_pattern_list,
11701169
vd->getType(), initialCaseVarDecl->getType());

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,11 +1122,8 @@ static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
11221122
return true;
11231123

11241124
// If we're expecting a type, make sure this decl has the expected type.
1125-
if (canTy) {
1126-
auto ifaceTy = value->getInterfaceType();
1127-
if (!ifaceTy || !ifaceTy->isEqual(canTy))
1128-
return true;
1129-
}
1125+
if (canTy && !value->getInterfaceType()->isEqual(canTy))
1126+
return true;
11301127

11311128
if (value->isStatic() != isStatic)
11321129
return true;

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,11 @@ static bool passCursorInfoForDecl(SourceFile* SF,
778778
unsigned USREnd = SS.size();
779779

780780
unsigned TypenameBegin = SS.size();
781-
if (auto vdType = VD->getInterfaceType()) {
782-
llvm::raw_svector_ostream OS(SS);
783-
PrintOptions Options;
784-
Options.PrintTypeAliasUnderlyingType = true;
785-
vdType.print(OS, Options);
786-
}
781+
llvm::raw_svector_ostream OS(SS);
782+
PrintOptions Options;
783+
Options.PrintTypeAliasUnderlyingType = true;
784+
VD->getInterfaceType().print(OS, Options);
785+
787786
unsigned TypenameEnd = SS.size();
788787

789788
unsigned MangledTypeStart = SS.size();

0 commit comments

Comments
 (0)