Skip to content

Commit 09b6b74

Browse files
authored
Merge pull request swiftlang#33234 from slavapestov/get-declared-type-cleanup
Replace trivial calls to getDeclaredType() with getDeclaredInterfaceType()
2 parents 0ef465f + cd79b54 commit 09b6b74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+212
-180
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,6 +2986,11 @@ class TypeAliasDecl : public GenericTypeDecl {
29862986
Type getCachedUnderlyingType() const { return UnderlyingTy.getType(); }
29872987

29882988
/// For generic typealiases, return the unbound generic type.
2989+
///
2990+
/// Since UnboundGenericType is on its way out, so is this method. Try to
2991+
/// avoid introducing new callers if possible. Instead of passing around
2992+
/// an UnboundGenericType, considering passing around the Decl itself
2993+
/// instead.
29892994
UnboundGenericType *getUnboundGenericType() const;
29902995

29912996
/// Retrieve a sugared interface type containing the structure of the interface
@@ -3372,6 +3377,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33723377

33733378
/// getDeclaredType - Retrieve the type declared by this entity, without
33743379
/// any generic parameters bound if this is a generic type.
3380+
///
3381+
/// Since UnboundGenericType is on its way out, so is this method. Try to
3382+
/// avoid introducing new callers if possible. Instead of passing around
3383+
/// an UnboundGenericType, considering passing around the Decl itself
3384+
/// instead.
33753385
Type getDeclaredType() const;
33763386

33773387
/// getDeclaredInterfaceType - Retrieve the type declared by this entity, with
@@ -4300,11 +4310,6 @@ class ProtocolDecl final : public NominalTypeDecl {
43004310
/// protocol.
43014311
bool inheritsFrom(const ProtocolDecl *Super) const;
43024312

4303-
ProtocolType *getDeclaredType() const {
4304-
return reinterpret_cast<ProtocolType *>(
4305-
NominalTypeDecl::getDeclaredType().getPointer());
4306-
}
4307-
43084313
SourceLoc getStartLoc() const { return ProtocolLoc; }
43094314
SourceRange getSourceRange() const {
43104315
return SourceRange(ProtocolLoc, getBraces().End);

include/swift/AST/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,8 @@ END_CAN_TYPE_WRAPPER(TupleType, Type)
21792179

21802180
/// UnboundGenericType - Represents a generic type where the type arguments have
21812181
/// not yet been resolved.
2182+
///
2183+
/// This type is on its way out. Try to avoid introducing new usages.
21822184
class UnboundGenericType : public AnyGenericType,
21832185
public llvm::FoldingSetNode {
21842186
private:

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ FuncDecl *ASTContext::getSequenceMakeIterator() const {
772772

773773
CanType ASTContext::getExceptionType() const {
774774
if (auto exn = getErrorDecl()) {
775-
return exn->getDeclaredType()->getCanonicalType();
775+
return exn->getDeclaredInterfaceType()->getCanonicalType();
776776
} else {
777777
// Use Builtin.NativeObject just as a stand-in.
778778
return TheNativeObjectType;
@@ -864,7 +864,7 @@ CanType ASTContext::getNeverType() const {
864864
auto neverDecl = getNeverDecl();
865865
if (!neverDecl)
866866
return CanType();
867-
return neverDecl->getDeclaredType()->getCanonicalType();
867+
return neverDecl->getDeclaredInterfaceType()->getCanonicalType();
868868
}
869869

870870
#define KNOWN_OBJC_TYPE_DECL(MODULE, NAME, DECLTYPE) \
@@ -1073,7 +1073,7 @@ ASTContext::getBuiltinInitDecl(NominalTypeDecl *decl,
10731073
if (witness)
10741074
return witness;
10751075

1076-
auto type = decl->getDeclaredType();
1076+
auto type = decl->getDeclaredInterfaceType();
10771077
auto builtinProtocol = getProtocol(builtinProtocolKind);
10781078
auto builtinConformance = getStdlibModule()->lookupConformance(
10791079
type, builtinProtocol);
@@ -1102,12 +1102,12 @@ FuncDecl *getBinaryComparisonOperatorIntDecl(const ASTContext &C, StringRef op,
11021102
if (!C.getIntDecl() || !C.getBoolDecl())
11031103
return nullptr;
11041104

1105-
auto intType = C.getIntDecl()->getDeclaredType();
1105+
auto intType = C.getIntDecl()->getDeclaredInterfaceType();
11061106
auto isIntParam = [&](AnyFunctionType::Param param) {
11071107
return (!param.isVariadic() && !param.isInOut() &&
11081108
param.getPlainType()->isEqual(intType));
11091109
};
1110-
auto boolType = C.getBoolDecl()->getDeclaredType();
1110+
auto boolType = C.getBoolDecl()->getDeclaredInterfaceType();
11111111
auto decl = lookupOperatorFunc(C, op, intType,
11121112
[=](FunctionType *type) {
11131113
// Check for the signature: (Int, Int) -> Bool
@@ -4264,7 +4264,7 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
42644264
if (auto objcBridgeable
42654265
= getProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
42664266
auto conformance = dc->getParentModule()->lookupConformance(
4267-
nominal->getDeclaredType(), objcBridgeable);
4267+
nominal->getDeclaredInterfaceType(), objcBridgeable);
42684268
if (conformance) {
42694269
result =
42704270
ForeignRepresentationInfo::forBridged(conformance.getConcrete());

lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Type ASTBuilder::createNominalType(GenericTypeDecl *decl, Type parent) {
153153
bool isImported = nominalDecl->hasClangNode() ||
154154
nominalDecl->getAttrs().hasAttribute<ClangImporterSynthesizedTypeAttr>();
155155
if (isImported && !nominalDecl->isGenericContext())
156-
return nominalDecl->getDeclaredType();
156+
return nominalDecl->getDeclaredInterfaceType();
157157

158158
// Validate the parent type.
159159
if (!validateParentType(nominalDecl, parent))
@@ -572,7 +572,7 @@ Type ASTBuilder::createProtocolCompositionType(
572572
bool isClassBound) {
573573
std::vector<Type> members;
574574
for (auto protocol : protocols)
575-
members.push_back(protocol->getDeclaredType());
575+
members.push_back(protocol->getDeclaredInterfaceType());
576576
if (superclass && superclass->getClassOrBoundGenericClass())
577577
members.push_back(superclass);
578578
return ProtocolCompositionType::get(Ctx, members, isClassBound);

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,7 +4102,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41024102
case SILFunctionType::Representation::WitnessMethod:
41034103
Printer << "witness_method: ";
41044104
printTypeDeclName(
4105-
witnessMethodConformance.getRequirement()->getDeclaredType());
4105+
witnessMethodConformance.getRequirement()->getDeclaredType()
4106+
->castTo<ProtocolType>());
41064107
break;
41074108
case SILFunctionType::Representation::Closure:
41084109
Printer << "closure";
@@ -5045,7 +5046,7 @@ swift::getInheritedForPrinting(const Decl *decl, const PrintOptions &options,
50455046
isa<EnumDecl>(decl) &&
50465047
cast<EnumDecl>(decl)->hasRawType())
50475048
continue;
5048-
Results.push_back(TypeLoc::withoutLoc(proto->getDeclaredType()));
5049+
Results.push_back(TypeLoc::withoutLoc(proto->getDeclaredInterfaceType()));
50495050
}
50505051
}
50515052
}

lib/AST/ASTVerifier.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ class Verifier : public ASTWalker {
10401040
case StmtConditionElement::CK_Boolean: {
10411041
auto *E = elt.getBoolean();
10421042
if (shouldVerifyChecked(E))
1043-
checkSameType(E->getType(), Ctx.getBoolDecl()->getDeclaredType(),
1043+
checkSameType(E->getType(),
1044+
Ctx.getBoolDecl()->getDeclaredInterfaceType(),
10441045
"condition type");
10451046
break;
10461047
}
@@ -1633,7 +1634,8 @@ class Verifier : public ASTWalker {
16331634
abort();
16341635
}
16351636

1636-
checkSameType(E->getType(), anyHashableDecl->getDeclaredType(),
1637+
checkSameType(E->getType(),
1638+
anyHashableDecl->getDeclaredInterfaceType(),
16371639
"AnyHashableErasureExpr and the standard AnyHashable type");
16381640

16391641
if (E->getConformance().getRequirement() != hashableDecl) {
@@ -3355,7 +3357,7 @@ class Verifier : public ASTWalker {
33553357

33563358
Type checkExceptionTypeExists(const char *where) {
33573359
auto exn = Ctx.getErrorDecl();
3358-
if (exn) return exn->getDeclaredType();
3360+
if (exn) return exn->getDeclaredInterfaceType();
33593361

33603362
Out << "exception type does not exist in " << where << "\n";
33613363
abort();

lib/AST/AutoDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ GenericSignature autodiff::getConstrainedDerivativeGenericSignature(
282282
// Require differentiability parameters to conform to `Differentiable`.
283283
auto paramType = originalFnTy->getParameters()[paramIdx].getInterfaceType();
284284
Requirement req(RequirementKind::Conformance, paramType,
285-
diffableProto->getDeclaredType());
285+
diffableProto->getDeclaredInterfaceType());
286286
requirements.push_back(req);
287287
if (isTranspose) {
288288
// Require linearity parameters to additionally satisfy

lib/AST/Builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ namespace {
496496
void addConformanceRequirement(const G &generator, ProtocolDecl *proto) {
497497
Requirement req(RequirementKind::Conformance,
498498
generator.build(*this),
499-
proto->getDeclaredType());
499+
proto->getDeclaredInterfaceType());
500500
addedRequirements.push_back(req);
501501
}
502502

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5068,7 +5068,7 @@ class GenericSignatureBuilder::InferRequirementsWalker : public TypeWalker {
50685068
if (differentiableProtocol && fnTy->isDifferentiable()) {
50695069
auto addConformanceConstraint = [&](Type type, ProtocolDecl *protocol) {
50705070
Requirement req(RequirementKind::Conformance, type,
5071-
protocol->getDeclaredType());
5071+
protocol->getDeclaredInterfaceType());
50725072
Builder.addRequirement(req, source, nullptr);
50735073
};
50745074
auto addSameTypeConstraint = [&](Type firstType,

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ GenericParamListRequest::evaluate(Evaluator &evaluator, GenericContext *value) c
23232323
// Protocol extensions need an inheritance clause due to how name lookup
23242324
// is implemented.
23252325
if (auto *proto = ext->getExtendedProtocolDecl()) {
2326-
auto protoType = proto->getDeclaredType();
2326+
auto protoType = proto->getDeclaredInterfaceType();
23272327
TypeLoc selfInherited[1] = { TypeLoc::withoutLoc(protoType) };
23282328
genericParams->getParams().front()->setInherited(
23292329
ctx.AllocateCopy(selfInherited));
@@ -2343,7 +2343,7 @@ GenericParamListRequest::evaluate(Evaluator &evaluator, GenericContext *value) c
23432343
auto selfId = ctx.Id_Self;
23442344
auto selfDecl = new (ctx) GenericTypeParamDecl(
23452345
proto, selfId, SourceLoc(), /*depth=*/0, /*index=*/0);
2346-
auto protoType = proto->getDeclaredType();
2346+
auto protoType = proto->getDeclaredInterfaceType();
23472347
TypeLoc selfInherited[1] = { TypeLoc::withoutLoc(protoType) };
23482348
selfDecl->setInherited(ctx.AllocateCopy(selfInherited));
23492349
selfDecl->setImplicit();

0 commit comments

Comments
 (0)