Skip to content

Commit bd0625f

Browse files
committed
[GSB] Flatten list of same-type requirements.
Equivalence classes stored their same-type constraints in a MapVector keyed on the source potential archetype, which allowed traversal along the paths of the graph. However, this capability isn't required, because we end up walking all of the edges each time. Flatten the list of same-type constraints to a single vector, eliminating constraint duplication between the source and the target out-edge lists. This cuts down on the number of same-type constraints we record by 50%, but performance gains are limited (6% of stdlib type-checking time) because most of the time these same-type constraints were skipped anyway.
1 parent d1206e4 commit bd0625f

File tree

3 files changed

+126
-191
lines changed

3 files changed

+126
-191
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ class GenericSignatureBuilder {
120120
llvm::MapVector<ProtocolDecl *, std::vector<Constraint<ProtocolDecl *>>>
121121
conformsTo;
122122

123-
/// Same-type constraints between each potential archetype and any other
124-
/// archetype in its equivalence class.
125-
llvm::MapVector<PotentialArchetype *,
126-
std::vector<Constraint<PotentialArchetype *>>>
127-
sameTypeConstraints;
123+
/// Same-type constraints within this equivalence class.
124+
std::vector<Constraint<PotentialArchetype *>> sameTypeConstraints;
128125

129126
/// Concrete type to which this equivalence class is equal.
130127
///
@@ -1669,18 +1666,6 @@ class GenericSignatureBuilder::PotentialArchetype {
16691666
/// potential archetype computations.
16701667
PotentialArchetype *getArchetypeAnchor(GenericSignatureBuilder &builder);
16711668

1672-
/// Retrieve the same-type constraints.
1673-
ArrayRef<Constraint<PotentialArchetype *>> getSameTypeConstraints() const {
1674-
if (auto equivClass = getEquivalenceClassIfPresent()) {
1675-
auto known = equivClass->sameTypeConstraints.find(
1676-
const_cast<PotentialArchetype *>(this));
1677-
if (known == equivClass->sameTypeConstraints.end()) return { };
1678-
return known->second;
1679-
}
1680-
1681-
return { };
1682-
}
1683-
16841669
/// \brief Retrieve (or create) a nested type that is the current best
16851670
/// nested archetype anchor (locally) with the given name.
16861671
///

0 commit comments

Comments
 (0)