diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index af61b5e16c02b..683bd769098ee 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -2526,26 +2526,26 @@ void PrintAST::visitVarDecl(VarDecl *decl) { [&]{ Printer.printName(decl->getName(), getTypeMemberPrintNameContext(decl)); }); - if (auto type = decl->getInterfaceType()) { - Printer << ": "; - TypeLoc tyLoc; - if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr()) - tyLoc = TypeLoc(repr, type); - else - tyLoc = TypeLoc::withoutLoc(type); - Printer.printDeclResultTypePre(decl, tyLoc); + auto type = decl->getInterfaceType(); + Printer << ": "; + TypeLoc tyLoc; + if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr()) + tyLoc = TypeLoc(repr, type); + else + tyLoc = TypeLoc::withoutLoc(type); - // HACK: When printing result types for vars with opaque result types, - // always print them using the `some` keyword instead of printing - // the full stable reference. - llvm::SaveAndRestore - x(Options.OpaqueReturnTypePrinting, - PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword); + Printer.printDeclResultTypePre(decl, tyLoc); - printTypeLocForImplicitlyUnwrappedOptional( - tyLoc, decl->isImplicitlyUnwrappedOptional()); - } + // HACK: When printing result types for vars with opaque result types, + // always print them using the `some` keyword instead of printing + // the full stable reference. + llvm::SaveAndRestore + x(Options.OpaqueReturnTypePrinting, + PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword); + + printTypeLocForImplicitlyUnwrappedOptional( + tyLoc, decl->isImplicitlyUnwrappedOptional()); printAccessors(decl); } @@ -2674,18 +2674,13 @@ void PrintAST::printFunctionParameters(AbstractFunctionDecl *AFD) { auto curTy = AFD->getInterfaceType(); // Skip over the implicit 'self'. - if (AFD->hasImplicitSelfDecl()) { - if (curTy) - if (auto funTy = curTy->getAs()) - curTy = funTy->getResult(); - } + if (AFD->hasImplicitSelfDecl()) + if (auto funTy = curTy->getAs()) + curTy = funTy->getResult(); ArrayRef parameterListTypes; - if (curTy) { - if (auto funTy = curTy->getAs()) { - parameterListTypes = funTy->getParams(); - } - } + if (auto funTy = curTy->getAs()) + parameterListTypes = funTy->getParams(); printParameterList(BodyParams, parameterListTypes, AFD->argumentNameIsAPIByDefault()); @@ -2878,15 +2873,14 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) { auto params = ArrayRef(); - if (auto type = elt->getInterfaceType()) { - if (!elt->isInvalid()) { - // Walk to the params of the associated values. - // (EnumMetaType) -> (AssocValues) -> Enum - params = type->castTo() - ->getResult() - ->castTo() - ->getParams(); - } + if (!elt->isInvalid()) { + // Walk to the params of the associated values. + // (EnumMetaType) -> (AssocValues) -> Enum + auto type = elt->getInterfaceType(); + params = type->castTo() + ->getResult() + ->castTo() + ->getParams(); } // @escaping is not valid in enum element position, even though the @@ -2977,11 +2971,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) { }, [&] { // Parameters printGenericDeclGenericParams(decl); auto params = ArrayRef(); - if (auto type = decl->getInterfaceType()) { - if (!decl->isInvalid()) { - // Walk to the params of the subscript's indices. - params = type->castTo()->getParams(); - } + if (!decl->isInvalid()) { + // Walk to the params of the subscript's indices. + auto type = decl->getInterfaceType(); + params = type->castTo()->getParams(); } printParameterList(decl->getIndices(), params, /*isAPINameByDefault*/false); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index a59f780d6945e..40519d24b6659 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3426,11 +3426,7 @@ Type TypeDecl::getDeclaredInterfaceType() const { selfTy, const_cast(ATD)); } - Type interfaceType = getInterfaceType(); - if (!interfaceType) - return ErrorType::get(getASTContext()); - - return interfaceType->getMetatypeInstanceType(); + return getInterfaceType()->getMetatypeInstanceType(); } int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) { @@ -4771,10 +4767,6 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value, auto type = value->getInterfaceType(); - // FIXME: Deal with broken recursion. - if (!type) - return SelfReferenceKind::None(); - // Skip invalid declarations. if (type->hasError()) return SelfReferenceKind::None(); diff --git a/lib/AST/USRGeneration.cpp b/lib/AST/USRGeneration.cpp index cf9d7895f71b9..db298ab702686 100644 --- a/lib/AST/USRGeneration.cpp +++ b/lib/AST/USRGeneration.cpp @@ -242,8 +242,6 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator, } auto declIFaceTy = D->getInterfaceType(); - if (!declIFaceTy) - return std::string(); // Invalid code. if (declIFaceTy.findIf([](Type t) -> bool { diff --git a/lib/IDE/ExprContextAnalysis.cpp b/lib/IDE/ExprContextAnalysis.cpp index 44320e0517381..f5ee2b6db3377 100644 --- a/lib/IDE/ExprContextAnalysis.cpp +++ b/lib/IDE/ExprContextAnalysis.cpp @@ -288,9 +288,6 @@ static void collectPossibleCalleesByQualifiedLookup( if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD)) continue; Type declaredMemberType = VD->getInterfaceType(); - if (!declaredMemberType) { - continue; - } if (!declaredMemberType->is()) continue; if (VD->getDeclContext()->isTypeContext()) { diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index d40a5a05ad1b6..85bd58b9d617c 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -5274,10 +5274,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, return; } - // FIXME: Deal with broken recursion - if (!decl->hasInterfaceType()) - return; - // Dig out the instance type and figure out what members of the instance type // we are going to see. auto baseTy = candidate.getBaseType(); @@ -5649,10 +5645,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, return result; } - // FIXME: Deal with broken recursion - if (!cand->hasInterfaceType()) - continue; - result.addUnviable(getOverloadChoice(cand, /*isBridged=*/false, /*isUnwrappedOptional=*/false), MemberLookupResult::UR_Inaccessible); diff --git a/lib/Sema/CalleeCandidateInfo.cpp b/lib/Sema/CalleeCandidateInfo.cpp index bfd548925d3dd..67b5127efac82 100644 --- a/lib/Sema/CalleeCandidateInfo.cpp +++ b/lib/Sema/CalleeCandidateInfo.cpp @@ -602,8 +602,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn, auto ctors = TypeChecker::lookupConstructors( CS.DC, instanceType, NameLookupFlags::IgnoreAccessControl); for (auto ctor : ctors) { - if (ctor.getValueDecl()->getInterfaceType()) - candidates.push_back({ ctor.getValueDecl(), 1 }); + candidates.push_back({ ctor.getValueDecl(), 1 }); } } diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index eadd085b89378..a9dca5bcfae22 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -1470,7 +1470,7 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload, // Retrieve the interface type. auto type = decl->getInterfaceType(); - if (!type || type->hasError()) { + if (type->hasError()) { return Type(); } diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 213f1c4a3fc63..9a230feec7380 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -3939,11 +3939,8 @@ bool swift::isMemberOperator(FuncDecl *decl, Type type) { // Check the parameters for a reference to 'Self'. bool isProtocol = selfNominal && isa(selfNominal); for (auto param : *decl->getParameters()) { - auto paramType = param->getInterfaceType(); - if (!paramType) break; - // Look through a metatype reference, if there is one. - paramType = paramType->getMetatypeInstanceType(); + auto paramType = param->getInterfaceType()->getMetatypeInstanceType(); auto nominal = paramType->getAnyNominal(); if (type.isNull()) { diff --git a/lib/Sema/TypeCheckDeclObjC.cpp b/lib/Sema/TypeCheckDeclObjC.cpp index 8d769cd58e648..59eccfb70903b 100644 --- a/lib/Sema/TypeCheckDeclObjC.cpp +++ b/lib/Sema/TypeCheckDeclObjC.cpp @@ -225,12 +225,10 @@ static void diagnoseFunctionParamNotRepresentable( AFD->diagnose(diag::objc_invalid_on_func_param_type, ParamIndex + 1, getObjCDiagnosticAttrKind(Reason)); } - if (Type ParamTy = P->getType()) { - SourceRange SR; - if (auto typeRepr = P->getTypeRepr()) - SR = typeRepr->getSourceRange(); - diagnoseTypeNotRepresentableInObjC(AFD, ParamTy, SR); - } + SourceRange SR; + if (auto typeRepr = P->getTypeRepr()) + SR = typeRepr->getSourceRange(); + diagnoseTypeNotRepresentableInObjC(AFD, P->getType(), SR); describeObjCReason(AFD, Reason); } diff --git a/lib/Sema/TypeCheckDeclOverride.cpp b/lib/Sema/TypeCheckDeclOverride.cpp index 157a8ccf5891d..631aa8f859989 100644 --- a/lib/Sema/TypeCheckDeclOverride.cpp +++ b/lib/Sema/TypeCheckDeclOverride.cpp @@ -282,9 +282,6 @@ diagnoseMismatchedOptionals(const ValueDecl *member, Type paramTy = decl->getType(); Type parentParamTy = parentDecl->getType(); - if (!paramTy || !parentParamTy) - return; - auto *repr = decl->getTypeRepr(); if (!repr) return; diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp index 521f5edec0953..7740c3db2b7d3 100644 --- a/lib/Sema/TypeCheckPattern.cpp +++ b/lib/Sema/TypeCheckPattern.cpp @@ -1488,10 +1488,7 @@ void TypeChecker::coerceParameterListToType(ParameterList *P, ClosureExpr *CE, if (param->isInvalid()) return true; - if (auto type = param->getType()) - return !isValidType(type); - - return true; + return !isValidType(param->getType()); }; auto handleParameter = [&](ParamDecl *param, Type ty, bool forceMutable) { diff --git a/lib/Sema/TypeCheckPropertyWrapper.cpp b/lib/Sema/TypeCheckPropertyWrapper.cpp index 4f0644c980370..e59c97d2117c2 100644 --- a/lib/Sema/TypeCheckPropertyWrapper.cpp +++ b/lib/Sema/TypeCheckPropertyWrapper.cpp @@ -546,7 +546,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate( // Compute the type of the property to plug in to the wrapper type. Type propertyType = var->getType(); - if (!propertyType || propertyType->hasError()) + if (propertyType->hasError()) return Type(); using namespace constraints; diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index da0a60faca8d9..b2d7608258e54 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -1166,8 +1166,7 @@ class StmtChecker : public StmtVisitor { } assert(isa(initialCaseVarDecl->getParentPatternStmt())); - if (vd->getInterfaceType() && initialCaseVarDecl->getType() && - !initialCaseVarDecl->isInvalid() && + if (!initialCaseVarDecl->isInvalid() && !vd->getType()->isEqual(initialCaseVarDecl->getType())) { getASTContext().Diags.diagnose(vd->getLoc(), diag::type_mismatch_multiple_pattern_list, vd->getType(), initialCaseVarDecl->getType()); diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 8e71fccdd34c3..d7f6d8d6e91f4 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -1122,11 +1122,8 @@ static void filterValues(Type expectedTy, ModuleDecl *expectedModule, return true; // If we're expecting a type, make sure this decl has the expected type. - if (canTy) { - auto ifaceTy = value->getInterfaceType(); - if (!ifaceTy || !ifaceTy->isEqual(canTy)) - return true; - } + if (canTy && !value->getInterfaceType()->isEqual(canTy)) + return true; if (value->isStatic() != isStatic) return true; diff --git a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp index 74e8ee8c05978..4fb215165d9c5 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp @@ -778,12 +778,11 @@ static bool passCursorInfoForDecl(SourceFile* SF, unsigned USREnd = SS.size(); unsigned TypenameBegin = SS.size(); - if (auto vdType = VD->getInterfaceType()) { - llvm::raw_svector_ostream OS(SS); - PrintOptions Options; - Options.PrintTypeAliasUnderlyingType = true; - vdType.print(OS, Options); - } + llvm::raw_svector_ostream OS(SS); + PrintOptions Options; + Options.PrintTypeAliasUnderlyingType = true; + VD->getInterfaceType().print(OS, Options); + unsigned TypenameEnd = SS.size(); unsigned MangledTypeStart = SS.size();