Skip to content

Commit b83137c

Browse files
committed
[NFC] TypeCheckProtocol: 'AbstractTypeWitnessKind' is no longer useful
1 parent 26943c5 commit b83137c

File tree

2 files changed

+11
-57
lines changed

2 files changed

+11
-57
lines changed

lib/Sema/TypeCheckProtocol.h

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,26 @@ CheckTypeWitnessResult checkTypeWitness(Type type,
100100
const NormalProtocolConformance *Conf,
101101
SubstOptions options = None);
102102

103-
/// Describes the means of inferring an abstract type witness.
104-
enum class AbstractTypeWitnessKind : uint8_t {
105-
/// The type witness was inferred via a same-type-to-concrete constraint
106-
/// in a protocol requirement signature.
107-
Fixed,
108-
109-
/// The type witness was inferred via a defaulted associated type.
110-
Default,
111-
112-
/// The type witness was inferred to a generic parameter of the
113-
/// conforming type.
114-
GenericParam,
115-
};
116-
117103
/// A type witness inferred without the aid of a specific potential
118104
/// value witness.
119105
class AbstractTypeWitness {
120-
AbstractTypeWitnessKind Kind;
121106
AssociatedTypeDecl *AssocType;
122107
Type TheType;
123108

124-
/// When this is a default type witness, the declaration responsible for it.
125-
/// May not necessarilly match \c AssocType.
109+
/// The defaulted associated type that was used to infer this type witness.
110+
/// Need not necessarilly match \c AssocType, but their names must.
126111
AssociatedTypeDecl *DefaultedAssocType;
127112

128-
AbstractTypeWitness(AbstractTypeWitnessKind Kind,
129-
AssociatedTypeDecl *AssocType, Type TheType,
130-
AssociatedTypeDecl *DefaultedAssocType)
131-
: Kind(Kind), AssocType(AssocType), TheType(TheType),
113+
public:
114+
AbstractTypeWitness(AssociatedTypeDecl *AssocType, Type TheType,
115+
AssociatedTypeDecl *DefaultedAssocType = nullptr)
116+
: AssocType(AssocType), TheType(TheType),
132117
DefaultedAssocType(DefaultedAssocType) {
133118
assert(AssocType && TheType);
119+
assert(!DefaultedAssocType ||
120+
(AssocType->getName() == DefaultedAssocType->getName()));
134121
}
135122

136-
public:
137-
static AbstractTypeWitness forFixed(AssociatedTypeDecl *assocType, Type type);
138-
139-
static AbstractTypeWitness forDefault(AssociatedTypeDecl *assocType,
140-
Type type,
141-
AssociatedTypeDecl *defaultedAssocType);
142-
143-
static AbstractTypeWitness forGenericParam(AssociatedTypeDecl *assocType,
144-
Type type);
145-
146-
public:
147-
AbstractTypeWitnessKind getKind() const { return Kind; }
148-
149123
AssociatedTypeDecl *getAssocType() const { return AssocType; }
150124

151125
Type getType() const { return TheType; }

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,6 @@ STATISTIC(NumDuplicateSolutionStates,
4444

4545
using namespace swift;
4646

47-
AbstractTypeWitness AbstractTypeWitness::forFixed(AssociatedTypeDecl *assocType,
48-
Type type) {
49-
return AbstractTypeWitness(AbstractTypeWitnessKind::Fixed, assocType, type,
50-
nullptr);
51-
}
52-
53-
AbstractTypeWitness
54-
AbstractTypeWitness::forDefault(AssociatedTypeDecl *assocType, Type type,
55-
AssociatedTypeDecl *defaultedAssocType) {
56-
return AbstractTypeWitness(AbstractTypeWitnessKind::Default, assocType, type,
57-
defaultedAssocType);
58-
}
59-
60-
AbstractTypeWitness
61-
AbstractTypeWitness::forGenericParam(AssociatedTypeDecl *assocType, Type type) {
62-
return AbstractTypeWitness(AbstractTypeWitnessKind::GenericParam, assocType,
63-
type, nullptr);
64-
}
65-
6647
void InferredAssociatedTypesByWitness::dump() const {
6748
dump(llvm::errs(), 0);
6849
}
@@ -882,8 +863,7 @@ AssociatedTypeInference::computeDefaultTypeWitness(
882863
if (defaultType->hasError())
883864
return None;
884865

885-
return AbstractTypeWitness::forDefault(assocType, defaultType,
886-
defaultedAssocType);
866+
return AbstractTypeWitness(assocType, defaultType, defaultedAssocType);
887867
}
888868

889869
std::pair<Type, TypeDecl *>
@@ -920,7 +900,7 @@ AssociatedTypeInference::computeAbstractTypeWitness(
920900
// We don't have a type witness for this associated type, so go
921901
// looking for more options.
922902
if (Type concreteType = computeFixedTypeWitness(assocType))
923-
return AbstractTypeWitness::forFixed(assocType, concreteType);
903+
return AbstractTypeWitness(assocType, concreteType);
924904

925905
// If we can form a default type, do so.
926906
if (const auto &typeWitness = computeDefaultTypeWitness(assocType))
@@ -930,7 +910,7 @@ AssociatedTypeInference::computeAbstractTypeWitness(
930910
if (auto genericSig = dc->getGenericSignatureOfContext()) {
931911
for (auto gp : genericSig.getInnermostGenericParams()) {
932912
if (gp->getName() == assocType->getName())
933-
return AbstractTypeWitness::forGenericParam(assocType, gp);
913+
return AbstractTypeWitness(assocType, gp);
934914
}
935915
}
936916

0 commit comments

Comments
 (0)