Skip to content

Commit f7bc907

Browse files
committed
[GSB] Provide a root potential archetype for nested-type-name-match sources.
1 parent 40a813b commit f7bc907

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class GenericSignatureBuilder::RequirementSource : public llvm::FoldingSetNode {
622622

623623
/// Retrieve a requirement source for nested type name matches.
624624
static const RequirementSource *forNestedTypeNameMatch(
625-
GenericSignatureBuilder &builder);
625+
PotentialArchetype *root);
626626

627627
/// A requirement source that describes that a requirement comes from a
628628
/// requirement of the given protocol described by the parent.

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ const RequirementSource *RequirementSource::forRequirementSignature(
284284
}
285285

286286
const RequirementSource *RequirementSource::forNestedTypeNameMatch(
287-
GenericSignatureBuilder &builder) {
287+
PotentialArchetype *root) {
288+
auto &builder = *root->getBuilder();
289+
// FIXME: Store the root
288290
REQUIREMENT_SOURCE_FACTORY_BODY_NOSTORAGE(NestedTypeNameMatch, nullptr);
289291
}
290292

@@ -724,7 +726,8 @@ bool GenericSignatureBuilder::PotentialArchetype::addConformance(
724726
// and make it equivalent to the first potential archetype we encountered.
725727
auto otherPA = new PotentialArchetype(this, assocType);
726728
known->second.push_back(otherPA);
727-
auto sameNamedSource = RequirementSource::forNestedTypeNameMatch(builder);
729+
auto sameNamedSource = RequirementSource::forNestedTypeNameMatch(
730+
known->second.front());
728731
builder.addSameTypeRequirement(known->second.front(), otherPA,
729732
sameNamedSource);
730733

@@ -980,9 +983,6 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
980983
if (rep != this)
981984
repNested = rep->getNestedType(nestedName, builder);
982985

983-
auto sameNestedTypeSource =
984-
RequirementSource::forNestedTypeNameMatch(builder);
985-
986986
// Attempt to resolve this nested type to an associated type
987987
// of one of the protocols to which the parent potential
988988
// archetype conforms.
@@ -1048,9 +1048,11 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
10481048
ProtocolConformanceRef(proto));
10491049
type = type.subst(subMap, SubstFlags::UseErrorType);
10501050

1051-
builder.addSameTypeRequirement(ResolvedType::forNewTypeAlias(pa),
1052-
builder.resolve(type),
1053-
sameNestedTypeSource, diagnoseMismatch);
1051+
builder.addSameTypeRequirement(
1052+
ResolvedType::forNewTypeAlias(pa),
1053+
builder.resolve(type),
1054+
RequirementSource::forNestedTypeNameMatch(pa),
1055+
diagnoseMismatch);
10541056
} else
10551057
continue;
10561058

@@ -1063,14 +1065,18 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
10631065

10641066
// Produce a same-type constraint between the two same-named
10651067
// potential archetypes.
1066-
builder.addSameTypeRequirement(pa, nested.front(), sameNestedTypeSource,
1067-
diagnoseMismatch);
1068+
builder.addSameTypeRequirement(
1069+
pa, nested.front(),
1070+
RequirementSource::forNestedTypeNameMatch(pa),
1071+
diagnoseMismatch);
10681072
} else {
10691073
nested.push_back(pa);
10701074

10711075
if (repNested) {
1072-
builder.addSameTypeRequirement(pa, repNested, sameNestedTypeSource,
1073-
diagnoseMismatch);
1076+
builder.addSameTypeRequirement(
1077+
pa, repNested,
1078+
RequirementSource::forNestedTypeNameMatch(pa),
1079+
diagnoseMismatch);
10741080
}
10751081
}
10761082

@@ -1097,7 +1103,8 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
10971103
if (isConcreteType()) {
10981104
for (auto equivT : rep->getEquivalenceClassMembers()) {
10991105
concretizeNestedTypeFromConcreteParent(
1100-
equivT, sameNestedTypeSource, nestedPA, builder,
1106+
equivT, RequirementSource::forNestedTypeNameMatch(nestedPA),
1107+
nestedPA, builder,
11011108
[&](ProtocolDecl *proto) -> ProtocolConformanceRef {
11021109
auto depTy = nestedPA->getDependentType({},
11031110
/*allowUnresolved=*/true)
@@ -1936,13 +1943,13 @@ bool GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
19361943
}
19371944

19381945
// Recursively merge the associated types of T2 into T1.
1939-
auto sameNestedTypeSource = RequirementSource::forNestedTypeNameMatch(*this);
19401946
for (auto equivT2 : equivClass2Members) {
19411947
for (auto T2Nested : equivT2->NestedTypes) {
19421948
auto T1Nested = T1->getNestedType(T2Nested.first, *this);
1943-
if (addSameTypeRequirement(T1Nested, T2Nested.second.front(),
1944-
sameNestedTypeSource,
1945-
[&](Type type1, Type type2) {
1949+
if (addSameTypeRequirement(
1950+
T1Nested, T2Nested.second.front(),
1951+
RequirementSource::forNestedTypeNameMatch(T1Nested),
1952+
[&](Type type1, Type type2) {
19461953
Diags.diagnose(Source->getLoc(),
19471954
diag::requires_same_type_conflict,
19481955
T1Nested->isGenericParam(),
@@ -2695,7 +2702,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
26952702
*this);
26962703
addSameTypeRequirement(
26972704
pa, replacement,
2698-
RequirementSource::forNestedTypeNameMatch(*this));
2705+
RequirementSource::forNestedTypeNameMatch(pa));
26992706
});
27002707
}
27012708
}

0 commit comments

Comments
 (0)