Skip to content

Commit 7811dc7

Browse files
authored
Merge pull request #8239 from DougGregor/all-same-type-constraints
2 parents d123343 + 0f4c14b commit 7811dc7

File tree

2 files changed

+194
-156
lines changed

2 files changed

+194
-156
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ class GenericSignatureBuilder {
104104
llvm::MapVector<ProtocolDecl *, std::vector<Constraint<ProtocolDecl *>>>
105105
conformsTo;
106106

107+
/// Same-type constraints between each potential archetype and any other
108+
/// archetype in its equivalence class.
109+
llvm::MapVector<PotentialArchetype *,
110+
std::vector<Constraint<PotentialArchetype *>>>
111+
sameTypeConstraints;
112+
107113
/// Concrete type to which this equivalence class is equal.
108114
///
109115
/// This is the semantic concrete type; the constraints as written
@@ -163,14 +169,6 @@ class GenericSignatureBuilder {
163169
GenericSignatureBuilder(const GenericSignatureBuilder &) = delete;
164170
GenericSignatureBuilder &operator=(const GenericSignatureBuilder &) = delete;
165171

166-
/// Update an existing constraint source reference when another constraint
167-
/// source was found to produce the same constraint. Only the better
168-
/// constraint source will be kept.
169-
///
170-
/// \returns true if the new constraint source was better, false otherwise.
171-
bool updateRequirementSource(const RequirementSource *&existingSource,
172-
const RequirementSource *newSource);
173-
174172
/// Retrieve the constraint source conformance for the superclass constraint
175173
/// of the given potential archetype (if present) to the given protocol.
176174
///
@@ -458,15 +456,15 @@ class GenericSignatureBuilder {
458456
Diag<Type, T> redundancyDiag,
459457
Diag<bool, Type, T> otherNoteDiag);
460458

461-
/// Check for redundant concrete type constraints within the equivalence
459+
/// Check the concrete type constraints within the equivalence
462460
/// class of the given potential archetype.
463-
void checkRedundantConcreteTypeConstraints(
461+
void checkConcreteTypeConstraints(
464462
ArrayRef<GenericTypeParamType *> genericParams,
465463
PotentialArchetype *pa);
466464

467-
/// Check for redundant superclass constraints within the equivalence
465+
/// Check the superclass constraints within the equivalence
468466
/// class of the given potential archetype.
469-
void checkRedundantSuperclassConstraints(
467+
void checkSuperclassConstraints(
470468
ArrayRef<GenericTypeParamType *> genericParams,
471469
PotentialArchetype *pa);
472470

@@ -476,6 +474,12 @@ class GenericSignatureBuilder {
476474
ArrayRef<GenericTypeParamType *> genericParams,
477475
PotentialArchetype *pa);
478476

477+
/// Check same-type constraints within the equivalence class of the
478+
/// given potential archetype.
479+
void checkSameTypeConstraints(
480+
ArrayRef<GenericTypeParamType *> genericParams,
481+
PotentialArchetype *pa);
482+
479483
public:
480484
/// \brief Resolve the given type to the potential archetype it names.
481485
///
@@ -1025,11 +1029,6 @@ class GenericSignatureBuilder::PotentialArchetype {
10251029
mutable llvm::PointerUnion<PotentialArchetype *, EquivalenceClass *>
10261030
representativeOrEquivClass;
10271031

1028-
/// Same-type constraints between this potential archetype and any other
1029-
/// archetype in its equivalence class.
1030-
llvm::MapVector<PotentialArchetype *, const RequirementSource *>
1031-
SameTypeConstraints;
1032-
10331032
/// \brief The layout constraint of this archetype, if specified.
10341033
LayoutConstraint Layout;
10351034

@@ -1301,12 +1300,15 @@ class GenericSignatureBuilder::PotentialArchetype {
13011300
const RequirementSource *source);
13021301

13031302
/// Retrieve the same-type constraints.
1304-
llvm::iterator_range<
1305-
std::vector<std::pair<PotentialArchetype *, const RequirementSource *>>
1306-
::const_iterator>
1307-
getSameTypeConstraints() const {
1308-
return llvm::make_range(SameTypeConstraints.begin(),
1309-
SameTypeConstraints.end());
1303+
ArrayRef<Constraint<PotentialArchetype *>> getSameTypeConstraints() const {
1304+
if (auto equivClass = getEquivalenceClassIfPresent()) {
1305+
auto known = equivClass->sameTypeConstraints.find(
1306+
const_cast<PotentialArchetype *>(this));
1307+
if (known == equivClass->sameTypeConstraints.end()) return { };
1308+
return known->second;
1309+
}
1310+
1311+
return { };
13101312
}
13111313

13121314
/// \brief Retrieve (or create) a nested type with the given name.

0 commit comments

Comments
 (0)