Skip to content

getInterfaceType() always returns a type #28210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 34 additions & 41 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrintOptions::OpaqueReturnTypePrintingMode>
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<PrintOptions::OpaqueReturnTypePrintingMode>
x(Options.OpaqueReturnTypePrinting,
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);

printTypeLocForImplicitlyUnwrappedOptional(
tyLoc, decl->isImplicitlyUnwrappedOptional());

printAccessors(decl);
}
Expand Down Expand Up @@ -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<AnyFunctionType>())
curTy = funTy->getResult();
}
if (AFD->hasImplicitSelfDecl())
if (auto funTy = curTy->getAs<AnyFunctionType>())
curTy = funTy->getResult();

ArrayRef<AnyFunctionType::Param> parameterListTypes;
if (curTy) {
if (auto funTy = curTy->getAs<AnyFunctionType>()) {
parameterListTypes = funTy->getParams();
}
}
if (auto funTy = curTy->getAs<AnyFunctionType>())
parameterListTypes = funTy->getParams();

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


auto params = ArrayRef<AnyFunctionType::Param>();
if (auto type = elt->getInterfaceType()) {
if (!elt->isInvalid()) {
// Walk to the params of the associated values.
// (EnumMetaType) -> (AssocValues) -> Enum
params = type->castTo<AnyFunctionType>()
->getResult()
->castTo<AnyFunctionType>()
->getParams();
}
if (!elt->isInvalid()) {
// Walk to the params of the associated values.
// (EnumMetaType) -> (AssocValues) -> Enum
auto type = elt->getInterfaceType();
params = type->castTo<AnyFunctionType>()
->getResult()
->castTo<AnyFunctionType>()
->getParams();
}

// @escaping is not valid in enum element position, even though the
Expand Down Expand Up @@ -2977,11 +2971,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
}, [&] { // Parameters
printGenericDeclGenericParams(decl);
auto params = ArrayRef<AnyFunctionType::Param>();
if (auto type = decl->getInterfaceType()) {
if (!decl->isInvalid()) {
// Walk to the params of the subscript's indices.
params = type->castTo<AnyFunctionType>()->getParams();
}
if (!decl->isInvalid()) {
// Walk to the params of the subscript's indices.
auto type = decl->getInterfaceType();
params = type->castTo<AnyFunctionType>()->getParams();
}
printParameterList(decl->getIndices(), params,
/*isAPINameByDefault*/false);
Expand Down
10 changes: 1 addition & 9 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3426,11 +3426,7 @@ Type TypeDecl::getDeclaredInterfaceType() const {
selfTy, const_cast<AssociatedTypeDecl *>(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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions lib/IDE/ExprContextAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ static void collectPossibleCalleesByQualifiedLookup(
if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD))
continue;
Type declaredMemberType = VD->getInterfaceType();
if (!declaredMemberType) {
continue;
}
if (!declaredMemberType->is<AnyFunctionType>())
continue;
if (VD->getDeclContext()->isTypeContext()) {
Expand Down
8 changes: 0 additions & 8 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/CalleeCandidateInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3939,11 +3939,8 @@ bool swift::isMemberOperator(FuncDecl *decl, Type type) {
// Check the parameters for a reference to 'Self'.
bool isProtocol = selfNominal && isa<ProtocolDecl>(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()) {
Expand Down
10 changes: 4 additions & 6 deletions lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/Sema/TypeCheckDeclOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckPropertyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
}
assert(isa<CaseStmt>(initialCaseVarDecl->getParentPatternStmt()));

if (vd->getInterfaceType() && initialCaseVarDecl->getType() &&
Copy link
Contributor

@CodaFi CodaFi Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VarDecl::getType() also computes the interface type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, even more cleanup

!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());
Expand Down
7 changes: 2 additions & 5 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down