Skip to content

Commit d0c7eb6

Browse files
authored
Merge pull request swiftlang#24694 from slavapestov/random-ast-cleanups
More preliminary cleanups for 'Used Conformances' removal
2 parents 0d82f1e + 37412c2 commit d0c7eb6

File tree

15 files changed

+50
-121
lines changed

15 files changed

+50
-121
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,6 +5323,8 @@ class ParamDecl : public VarDecl {
53235323

53245324
SourceRange getSourceRange() const;
53255325

5326+
AnyFunctionType::Param toFunctionParam(Type type = Type()) const;
5327+
53265328
// Implement isa/cast/dyncast/etc.
53275329
static bool classof(const Decl *D) {
53285330
return D->getKind() == DeclKind::Param;

include/swift/AST/ParameterList.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ class alignas(ParamDecl *) ParameterList final :
127127
/// based on the interface types of the parameters in this list.
128128
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params) const;
129129

130-
/// Return a list of function parameters for this parameter list,
131-
/// based on types provided by a callback.
132-
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params,
133-
llvm::function_ref<Type(ParamDecl *)> getType) const;
134-
135-
136130
/// Return the full source range of this parameter.
137131
SourceRange getSourceRange() const;
138132
SourceLoc getStartLoc() const { return getSourceRange().Start; }

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class ProtocolConformanceRef {
138138
static Type
139139
getTypeWitnessByName(Type type,
140140
ProtocolConformanceRef conformance,
141-
Identifier name,
142-
LazyResolver *resolver);
141+
Identifier name);
143142

144143
/// Determine whether this conformance is canonical.
145144
bool isCanonical() const;
@@ -154,11 +153,6 @@ class ProtocolConformanceRef {
154153
/// Get any additional requirements that are required for this conformance to
155154
/// be satisfied.
156155
ArrayRef<Requirement> getConditionalRequirements() const;
157-
158-
/// If this is a conformance reference for a protocol that inherits other
159-
/// protocols, get a reference to the related conformance for the inherited
160-
/// protocol.
161-
ProtocolConformanceRef getInheritedConformanceRef(ProtocolDecl *base) const;
162156
};
163157

164158
} // end namespace swift

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4225,13 +4225,8 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
42254225
*bridgedValueType = type;
42264226

42274227
// Find the Objective-C class type we bridge to.
4228-
if (conformance->isConcrete()) {
4229-
return ProtocolConformanceRef::getTypeWitnessByName(
4230-
type, *conformance, Id_ObjectiveCType,
4231-
getLazyResolver());
4232-
} else {
4233-
return type->castTo<ArchetypeType>()->getNestedType(Id_ObjectiveCType);
4234-
}
4228+
return ProtocolConformanceRef::getTypeWitnessByName(
4229+
type, *conformance, Id_ObjectiveCType);
42354230
}
42364231

42374232
// Do we conform to Error?

lib/AST/Decl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5673,6 +5673,21 @@ Type ParamDecl::getVarargBaseTy(Type VarArgT) {
56735673
return T;
56745674
}
56755675

5676+
AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
5677+
if (!type)
5678+
type = getInterfaceType();
5679+
5680+
if (isVariadic())
5681+
type = ParamDecl::getVarargBaseTy(type);
5682+
5683+
auto label = getArgumentName();
5684+
auto flags = ParameterTypeFlags::fromParameterType(type,
5685+
isVariadic(),
5686+
isAutoClosure(),
5687+
getValueOwnership());
5688+
return AnyFunctionType::Param(type, label, flags);
5689+
}
5690+
56765691
void ParamDecl::setDefaultValue(Expr *E) {
56775692
if (!DefaultValueAndFlags.getPointer()) {
56785693
if (!E) return;

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,13 +2057,6 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20572057
!= proto->getParentModule())
20582058
continue;
20592059

2060-
// Resolve the signature of this type.
2061-
if (!type->hasInterfaceType()) {
2062-
type->getASTContext().getLazyResolver()->resolveDeclSignature(type);
2063-
if (!type->hasInterfaceType())
2064-
continue;
2065-
}
2066-
20672060
concreteDecls.push_back(type);
20682061
continue;
20692062
}

lib/AST/Parameter.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,8 @@ ParameterList *ParameterList::clone(const ASTContext &C,
8989

9090
void ParameterList::getParams(
9191
SmallVectorImpl<AnyFunctionType::Param> &params) const {
92-
getParams(params,
93-
[](ParamDecl *decl) { return decl->getInterfaceType(); });
94-
}
95-
96-
void ParameterList::getParams(
97-
SmallVectorImpl<AnyFunctionType::Param> &params,
98-
llvm::function_ref<Type(ParamDecl *)> getType) const {
99-
if (size() == 0)
100-
return;
101-
102-
for (auto P : *this) {
103-
auto type = getType(P);
104-
105-
if (P->isVariadic())
106-
type = ParamDecl::getVarargBaseTy(type);
107-
108-
auto label = P->getArgumentName();
109-
auto flags = ParameterTypeFlags::fromParameterType(type,
110-
P->isVariadic(),
111-
P->isAutoClosure(),
112-
P->getValueOwnership());
113-
params.emplace_back(type, label, flags);
114-
}
92+
for (auto P : *this)
93+
params.push_back(P->toFunctionParam());
11594
}
11695

11796

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ ProtocolConformanceRef::subst(Type origType,
144144
Type
145145
ProtocolConformanceRef::getTypeWitnessByName(Type type,
146146
ProtocolConformanceRef conformance,
147-
Identifier name,
148-
LazyResolver *resolver) {
147+
Identifier name) {
149148
assert(!conformance.isInvalid());
150149

151150
// Find the named requirement.
151+
ProtocolDecl *proto = conformance.getRequirement();
152152
AssociatedTypeDecl *assocType = nullptr;
153-
auto members = conformance.getRequirement()->lookupDirect(name);
153+
auto members = proto->lookupDirect(name);
154154
for (auto member : members) {
155155
assocType = dyn_cast<AssociatedTypeDecl>(member);
156156
if (assocType)
@@ -161,21 +161,8 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
161161
if (!assocType)
162162
return nullptr;
163163

164-
if (conformance.isAbstract()) {
165-
// For an archetype, retrieve the nested type with the appropriate
166-
// name. There are no conformance tables.
167-
if (auto archetype = type->getAs<ArchetypeType>()) {
168-
return archetype->getNestedType(name);
169-
}
170-
171-
return DependentMemberType::get(type, assocType);
172-
}
173-
174-
auto concrete = conformance.getConcrete();
175-
if (!concrete->hasTypeWitness(assocType, resolver)) {
176-
return nullptr;
177-
}
178-
return concrete->getTypeWitness(assocType, resolver);
164+
return assocType->getDeclaredInterfaceType().subst(
165+
SubstitutionMap::getProtocolSubstitutions(proto, type, conformance));
179166
}
180167

181168
void *ProtocolConformance::operator new(size_t bytes, ASTContext &context,
@@ -500,37 +487,6 @@ ProtocolConformanceRef::getConditionalRequirements() const {
500487
return {};
501488
}
502489

503-
ProtocolConformanceRef
504-
ProtocolConformanceRef::getInheritedConformanceRef(ProtocolDecl *base) const {
505-
if (isAbstract()) {
506-
assert(getRequirement()->inheritsFrom(base));
507-
return ProtocolConformanceRef(base);
508-
}
509-
510-
auto concrete = getConcrete();
511-
auto proto = concrete->getProtocol();
512-
auto path =
513-
proto->getGenericSignature()->getConformanceAccessPath(
514-
proto->getSelfInterfaceType(), base);
515-
ProtocolConformanceRef result = *this;
516-
Type resultType = concrete->getType();
517-
bool first = true;
518-
for (const auto &step : path) {
519-
if (first) {
520-
assert(step.first->isEqual(proto->getSelfInterfaceType()));
521-
assert(step.second == proto);
522-
first = false;
523-
continue;
524-
}
525-
526-
result =
527-
result.getAssociatedConformance(resultType, step.first, step.second);
528-
resultType = result.getAssociatedType(resultType, step.first);
529-
}
530-
531-
return result;
532-
}
533-
534490
void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
535491
const {
536492
switch (CRState) {

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
13801380
Type objcType = ProtocolConformanceRef::getTypeWitnessByName(
13811381
nominal->getDeclaredType(),
13821382
ProtocolConformanceRef(conformance),
1383-
ctx.Id_ObjectiveCType,
1384-
nullptr);
1383+
ctx.Id_ObjectiveCType);
13851384
if (!objcType) return nullptr;
13861385

13871386
// Dig out the Objective-C class.

lib/SIL/Bridging.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
225225
Type bridgedTy =
226226
ProtocolConformanceRef::getTypeWitnessByName(
227227
t, ProtocolConformanceRef(conformance),
228-
M.getASTContext().Id_ObjectiveCType,
229-
M.getASTContext().getLazyResolver());
228+
M.getASTContext().Id_ObjectiveCType);
230229
assert(bridgedTy && "Missing _ObjectiveCType witness?");
231230
if (purpose == BridgedTypePurpose::ForResult && clangTy)
232231
bridgedTy = OptionalType::get(bridgedTy);

0 commit comments

Comments
 (0)