Skip to content

Commit 4481a42

Browse files
committed
[GSB] Push potential archetype realization slightly deeper.
Same-type constraints are (still) described in terms of potential archetypes, so push the "realization" operation for potential archetypes down into the function that adds a same-type constraint between type parameters.
1 parent 0f7c822 commit 4481a42

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,11 @@ class GenericSignatureBuilder {
450450
/// \returns true if a new rewrite rule was added, and false otherwise.
451451
bool addSameTypeRewriteRule(CanType type1, CanType type2);
452452

453-
/// \brief Add a new conformance requirement specifying that the given
454-
/// potential archetypes are equivalent.
455-
ConstraintResult addSameTypeRequirementBetweenArchetypes(
456-
PotentialArchetype *T1,
457-
PotentialArchetype *T2,
458-
const RequirementSource *Source);
453+
/// \brief Add a same-type requirement between two types that are known to
454+
/// refer to type parameters.
455+
ConstraintResult addSameTypeRequirementBetweenTypeParameters(
456+
ResolvedType type1, ResolvedType type2,
457+
const RequirementSource *source);
459458

460459
/// \brief Add a new conformance requirement specifying that the given
461460
/// potential archetype is bound to a concrete type.

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,14 +4828,18 @@ void GenericSignatureBuilder::addedNestedType(PotentialArchetype *nestedPA) {
48284828
}
48294829

48304830
ConstraintResult
4831-
GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
4832-
PotentialArchetype *OrigT1,
4833-
PotentialArchetype *OrigT2,
4834-
const RequirementSource *Source)
4831+
GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
4832+
ResolvedType type1, ResolvedType type2,
4833+
const RequirementSource *source)
48354834
{
4835+
// Both sides are type parameters; equate them.
4836+
// FIXME: Realizes potential archetypes far too early.
4837+
auto OrigT1 = type1.realizePotentialArchetype(*this);
4838+
auto OrigT2 = type2.realizePotentialArchetype(*this);
4839+
48364840
// Record the same-type constraint, and bail out if it was already known.
48374841
if (!OrigT1->getOrCreateEquivalenceClass(*this)
4838-
->recordSameTypeConstraint(OrigT1, OrigT2, Source))
4842+
->recordSameTypeConstraint(OrigT1, OrigT2, source))
48394843
return ConstraintResult::Resolved;
48404844

48414845
// Operate on the representatives
@@ -4913,7 +4917,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
49134917
if (t2IsConcrete) {
49144918
if (t1IsConcrete) {
49154919
(void)addSameTypeRequirement(equivClass->concreteType,
4916-
equivClass2->concreteType, Source,
4920+
equivClass2->concreteType, source,
49174921
UnresolvedHandlingKind::GenerateConstraints,
49184922
SameTypeConflictCheckedLater());
49194923
} else {
@@ -5158,15 +5162,9 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirementDirect(
51585162
source.getSource(*this, type1.getDependentType(*this)));
51595163
}
51605164

5161-
// Both sides are type parameters; equate them.
5162-
// FIXME: Realizes potential archetypes far too early.
5163-
auto pa1 = type1.realizePotentialArchetype(*this);
5164-
auto pa2 = type2.realizePotentialArchetype(*this);
5165-
5166-
return addSameTypeRequirementBetweenArchetypes(
5167-
pa1, pa2,
5168-
source.getSource(*this,
5169-
type2.getDependentType(*this)));
5165+
return addSameTypeRequirementBetweenTypeParameters(
5166+
type1, type2,
5167+
source.getSource(*this, type2.getDependentType(*this)));
51705168
}
51715169

51725170
ConstraintResult GenericSignatureBuilder::addInheritedRequirements(

0 commit comments

Comments
 (0)