Skip to content

Commit 9148ae3

Browse files
authored
Merge pull request swiftlang#80482 from slavapestov/abstract-conformance-cleanup
AST: Simplify ProtocolConformanceRef operations a little bit
2 parents 7836aff + e475b08 commit 9148ae3

Some content is hidden

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

53 files changed

+228
-437
lines changed

include/swift/AST/GenericEnvironment.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,6 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
325325
/// abstraction level of their associated type requirements.
326326
SILType mapTypeIntoContext(SILModule &M, SILType type) const;
327327

328-
/// Map an interface type's protocol conformance into the corresponding
329-
/// conformance for the contextual type.
330-
static std::pair<Type, ProtocolConformanceRef>
331-
mapConformanceRefIntoContext(GenericEnvironment *genericEnv,
332-
Type conformingType,
333-
ProtocolConformanceRef conformance);
334-
335-
/// Map an interface type's protocol conformance into the corresponding
336-
/// conformance for the contextual type.
337-
std::pair<Type, ProtocolConformanceRef>
338-
mapConformanceRefIntoContext(Type conformingType,
339-
ProtocolConformanceRef conformance) const;
340-
341328
/// Returns a substitution map that sends every generic parameter to its
342329
/// corresponding archetype in this generic environment.
343330
SubstitutionMap getForwardingSubstitutionMap() const;

include/swift/AST/ProtocolAssociations.h

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,6 @@
2323

2424
namespace swift {
2525

26-
/// A type associated with a protocol.
27-
///
28-
/// This struct exists largely so that we can maybe eventually
29-
/// generalize it to an arbitrary path.
30-
class AssociatedType {
31-
AssociatedTypeDecl *Association;
32-
using AssociationInfo = llvm::DenseMapInfo<AssociatedTypeDecl*>;
33-
34-
struct SpecialValue {};
35-
explicit AssociatedType(SpecialValue _, AssociatedTypeDecl *specialValue)
36-
: Association(specialValue) {}
37-
38-
public:
39-
explicit AssociatedType(AssociatedTypeDecl *association)
40-
: Association(association) {
41-
assert(association);
42-
}
43-
44-
ProtocolDecl *getSourceProtocol() const {
45-
return Association->getProtocol();
46-
}
47-
48-
AssociatedTypeDecl *getAssociation() const {
49-
return Association;
50-
}
51-
52-
friend bool operator==(AssociatedType lhs, AssociatedType rhs) {
53-
return lhs.Association == rhs.Association;
54-
}
55-
friend bool operator!=(AssociatedType lhs, AssociatedType rhs) {
56-
return !(lhs == rhs);
57-
}
58-
59-
unsigned getHashValue() const {
60-
return llvm::hash_value(Association);
61-
}
62-
63-
static AssociatedType getEmptyKey() {
64-
return AssociatedType(SpecialValue(), AssociationInfo::getEmptyKey());
65-
}
66-
static AssociatedType getTombstoneKey() {
67-
return AssociatedType(SpecialValue(), AssociationInfo::getTombstoneKey());
68-
}
69-
};
70-
7126
/// A base conformance of a protocol.
7227
class BaseConformance {
7328
ProtocolDecl *Source;
@@ -147,24 +102,6 @@ class AssociatedConformance {
147102
} // end namespace swift
148103

149104
namespace llvm {
150-
template <> struct DenseMapInfo<swift::AssociatedType> {
151-
static inline swift::AssociatedType getEmptyKey() {
152-
return swift::AssociatedType::getEmptyKey();
153-
}
154-
155-
static inline swift::AssociatedType getTombstoneKey() {
156-
return swift::AssociatedType::getTombstoneKey();
157-
}
158-
159-
static unsigned getHashValue(swift::AssociatedType val) {
160-
return val.getHashValue();
161-
}
162-
163-
static bool isEqual(swift::AssociatedType lhs, swift::AssociatedType rhs) {
164-
return lhs == rhs;
165-
}
166-
};
167-
168105
template <> struct DenseMapInfo<swift::AssociatedConformance> {
169106
static inline swift::AssociatedConformance getEmptyKey() {
170107
return swift::AssociatedConformance::getEmptyKey();

include/swift/AST/ProtocolConformance.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
363363
/// Retrieve the protocol conformance for the inherited protocol.
364364
ProtocolConformance *getInheritedConformance(ProtocolDecl *protocol) const;
365365

366-
/// Given a dependent type expressed in terms of the self parameter,
367-
/// map it into the context of this conformance.
368-
Type getAssociatedType(Type assocType) const;
369-
370366
/// Given that the requirement signature of the protocol directly states
371367
/// that the given dependent type must conform to the given protocol,
372368
/// return its associated conformance.

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,38 +185,36 @@ class ProtocolConformanceRef {
185185
ProtocolDecl *getProtocol() const;
186186

187187
/// Apply a substitution to the conforming type.
188-
ProtocolConformanceRef subst(Type origType, SubstitutionMap subMap,
188+
ProtocolConformanceRef subst(SubstitutionMap subMap,
189189
SubstOptions options = std::nullopt) const;
190190

191191
/// Apply a substitution to the conforming type.
192-
ProtocolConformanceRef subst(Type origType, TypeSubstitutionFn subs,
192+
ProtocolConformanceRef subst(TypeSubstitutionFn subs,
193193
LookupConformanceFn conformances,
194194
SubstOptions options = std::nullopt) const;
195195

196196
/// Apply a substitution to the conforming type.
197197
///
198198
/// This function should generally not be used outside of the substitution
199199
/// subsystem.
200-
ProtocolConformanceRef subst(Type origType,
201-
InFlightSubstitution &IFS) const;
200+
ProtocolConformanceRef subst(InFlightSubstitution &IFS) const;
202201

203202
/// Map contextual types to interface types in the conformance.
204203
ProtocolConformanceRef mapConformanceOutOfContext() const;
205204

206205
/// Look up the type witness for an associated type declaration in this
207206
/// conformance.
208-
Type getTypeWitness(Type origType, AssociatedTypeDecl *assocType,
207+
Type getTypeWitness(AssociatedTypeDecl *assocType,
209208
SubstOptions options = std::nullopt) const;
210209

211210
/// Given a dependent type (expressed in terms of this conformance's
212211
/// protocol), follow it from the conforming type.
213-
Type getAssociatedType(Type origType, Type dependentType) const;
212+
Type getAssociatedType(Type dependentType) const;
214213

215214
/// Given a dependent type (expressed in terms of this conformance's
216215
/// protocol) and conformance, follow it from the conforming type.
217216
ProtocolConformanceRef
218-
getAssociatedConformance(Type origType, Type dependentType,
219-
ProtocolDecl *requirement) const;
217+
getAssociatedConformance(Type dependentType, ProtocolDecl *requirement) const;
220218

221219
SWIFT_DEBUG_DUMP;
222220
void dump(llvm::raw_ostream &out, unsigned indent = 0,
@@ -235,15 +233,15 @@ class ProtocolConformanceRef {
235233
return llvm::hash_value(conformance.Union.getOpaqueValue());
236234
}
237235

238-
Type getTypeWitnessByName(Type type, Identifier name) const;
236+
Type getTypeWitnessByName(Identifier name) const;
239237

240238
/// Find a particular named function witness for a type that conforms to
241239
/// the given protocol.
242240
///
243241
/// \param type The conforming type.
244242
///
245243
/// \param name The name of the requirement.
246-
ConcreteDeclRef getWitnessByName(Type type, DeclName name) const;
244+
ConcreteDeclRef getWitnessByName(DeclName name) const;
247245

248246
/// Determine whether this conformance is canonical.
249247
bool isCanonical() const;

include/swift/AST/SubstitutionMap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ class SubstitutionMap {
187187
SubstitutionMap mapIntoTypeExpansionContext(
188188
TypeExpansionContext context) const;
189189

190+
/// Create a substitution map for a protocol conformance.
191+
static SubstitutionMap
192+
getProtocolSubstitutions(ProtocolConformanceRef conformance);
193+
190194
/// Create a substitution map for a protocol conformance.
191195
static SubstitutionMap
192196
getProtocolSubstitutions(ProtocolDecl *protocol,

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5028,7 +5028,7 @@ Type substOpaqueTypesWithUnderlyingTypes(Type type,
50285028
CanType substOpaqueTypesWithUnderlyingTypes(CanType type,
50295029
TypeExpansionContext context);
50305030
ProtocolConformanceRef
5031-
substOpaqueTypesWithUnderlyingTypes(ProtocolConformanceRef ref, Type origType,
5031+
substOpaqueTypesWithUnderlyingTypes(ProtocolConformanceRef ref,
50325032
TypeExpansionContext context);
50335033
namespace Lowering {
50345034
class TypeConverter;

include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
564564
if (Functor.hasLocalArchetypes())
565565
options |= SubstFlags::SubstituteLocalArchetypes;
566566

567-
C = C.subst(Ty, Functor, Functor, options);
567+
C = C.subst(Functor, Functor, options);
568568
if (asImpl().shouldSubstOpaqueArchetypes())
569569
Ty = Ty.subst(Functor, Functor, options);
570570
}
@@ -576,7 +576,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
576576
!context.shouldLookThroughOpaqueTypeArchetypes())
577577
return C;
578578

579-
return substOpaqueTypesWithUnderlyingTypes(C, Ty, context);
579+
return substOpaqueTypesWithUnderlyingTypes(C, context);
580580
}
581581

582582
return C;

include/swift/SIL/SILWitnessVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
100100
// If this is a new associated type (which does not override an
101101
// existing associated type), add it.
102102
if (associatedType->getOverriddenDecls().empty())
103-
asDerived().addAssociatedType(AssociatedType(associatedType));
103+
asDerived().addAssociatedType(associatedType);
104104
}
105105

106106
if (asDerived().shouldVisitRequirementSignatureOnly())

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ ASTContext::getBuiltinInitDecl(NominalTypeDecl *decl,
16781678
}
16791679

16801680
auto *ctx = const_cast<ASTContext *>(this);
1681-
witness = builtinConformance.getWitnessByName(type, initName(*ctx));
1681+
witness = builtinConformance.getWitnessByName(initName(*ctx));
16821682
if (!witness) {
16831683
assert(false && "Missing required witness");
16841684
witness = ConcreteDeclRef();
@@ -6486,7 +6486,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
64866486
*bridgedValueType = type;
64876487

64886488
// Find the Objective-C class type we bridge to.
6489-
Type witnessTy = conformance.getTypeWitnessByName(type, Id_ObjectiveCType);
6489+
Type witnessTy = conformance.getTypeWitnessByName(Id_ObjectiveCType);
64906490
// If Objective-C import is broken, witness type would be a dependent member
64916491
// with `<<error type>>` base.
64926492
return (witnessTy && !witnessTy->hasError()) ? witnessTy : Type();

lib/AST/ActorIsolation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ActorIsolation::forActorInstanceParameter(Expr *actor,
6161
if (auto globalActor = ctx.getProtocol(KnownProtocolKind::GlobalActor)) {
6262
auto conformance = checkConformance(baseType, globalActor);
6363
if (conformance &&
64-
conformance.getWitnessByName(baseType, ctx.Id_shared) == declRef) {
64+
conformance.getWitnessByName(ctx.Id_shared) == declRef) {
6565
return ActorIsolation::forGlobalActor(baseType);
6666
}
6767
}

0 commit comments

Comments
 (0)