Skip to content

Commit f429712

Browse files
committed
[GSB] Track all same-type constraint requirement sources.
As we've been doing with other kinds of constraints, track *all* of the requirement sources for deriving same-type constraints within the equivalence class, then remove self-derived constraints at the end. There is no checking for duplicated same-type constraints yet.
1 parent 0be028a commit f429712

File tree

2 files changed

+186
-124
lines changed

2 files changed

+186
-124
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 21 additions & 11 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
@@ -476,6 +482,12 @@ class GenericSignatureBuilder {
476482
ArrayRef<GenericTypeParamType *> genericParams,
477483
PotentialArchetype *pa);
478484

485+
/// Check same-type constraints within the equivalence class of the
486+
/// given potential archetype.
487+
void checkSameTypeConstraints(
488+
ArrayRef<GenericTypeParamType *> genericParams,
489+
PotentialArchetype *pa);
490+
479491
public:
480492
/// \brief Resolve the given type to the potential archetype it names.
481493
///
@@ -1025,11 +1037,6 @@ class GenericSignatureBuilder::PotentialArchetype {
10251037
mutable llvm::PointerUnion<PotentialArchetype *, EquivalenceClass *>
10261038
representativeOrEquivClass;
10271039

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-
10331040
/// \brief The layout constraint of this archetype, if specified.
10341041
LayoutConstraint Layout;
10351042

@@ -1301,12 +1308,15 @@ class GenericSignatureBuilder::PotentialArchetype {
13011308
const RequirementSource *source);
13021309

13031310
/// 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());
1311+
ArrayRef<Constraint<PotentialArchetype *>> getSameTypeConstraints() const {
1312+
if (auto equivClass = getEquivalenceClassIfPresent()) {
1313+
auto known = equivClass->sameTypeConstraints.find(
1314+
const_cast<PotentialArchetype *>(this));
1315+
if (known == equivClass->sameTypeConstraints.end()) return { };
1316+
return known->second;
1317+
}
1318+
1319+
return { };
13101320
}
13111321

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

0 commit comments

Comments
 (0)