Skip to content

Commit 710621c

Browse files
committed
GSB: Remove checkConformanceConstraints()
1 parent a10c5ed commit 710621c

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,6 @@ class GenericSignatureBuilder {
723723
TypeArrayView<GenericTypeParamType> genericParams,
724724
EquivalenceClass *equivClass);
725725

726-
/// Check conformance constraints within the equivalence class of the
727-
/// given potential archetype.
728-
void checkConformanceConstraints(
729-
TypeArrayView<GenericTypeParamType> genericParams,
730-
EquivalenceClass *equivClass);
731-
732726
/// Check same-type constraints within the equivalence class of the
733727
/// given potential archetype.
734728
void checkSameTypeConstraints(

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,7 @@ static void concretizeNestedTypeFromConcreteParent(
28282828
assert(parentEquiv->conformsTo.count(proto) > 0 &&
28292829
"No conformance requirement");
28302830
const RequirementSource *parentConcreteSource = nullptr;
2831+
28312832
for (const auto &constraint : parentEquiv->conformsTo.find(proto)->second) {
28322833
if (!isSuperclassConstrained) {
28332834
if (constraint.source->kind == RequirementSource::Concrete) {
@@ -5796,16 +5797,24 @@ static void expandSameTypeConstraints(GenericSignatureBuilder &builder,
57965797
bool alreadyFound = false;
57975798
const RequirementSource *conformsSource = nullptr;
57985799
for (const auto &constraint : conforms.second) {
5799-
if (constraint.source->getAffectedType()->isEqual(dependentType)) {
5800+
bool derivedViaConcrete = false;
5801+
5802+
auto *minimal = constraint.source->getMinimalConformanceSource(
5803+
builder, constraint.getSubjectDependentType({ }), proto,
5804+
derivedViaConcrete);
5805+
5806+
if (minimal == nullptr || derivedViaConcrete)
5807+
continue;
5808+
5809+
if (minimal->getAffectedType()->isEqual(dependentType)) {
58005810
alreadyFound = true;
58015811
break;
58025812
}
58035813

58045814
// Capture the source for later use, skipping
58055815
if (!conformsSource &&
5806-
constraint.source->kind
5807-
!= RequirementSource::RequirementSignatureSelf)
5808-
conformsSource = constraint.source;
5816+
minimal->kind != RequirementSource::RequirementSignatureSelf)
5817+
conformsSource = minimal;
58095818
}
58105819

58115820
if (alreadyFound) continue;
@@ -6382,9 +6391,7 @@ GenericSignatureBuilder::finalize(TypeArrayView<GenericTypeParamType> genericPar
63826391
equivClass.recursiveSuperclassType = true;
63836392
}
63846393
}
6385-
6386-
checkConformanceConstraints(genericParams, &equivClass);
6387-
};
6394+
}
63886395

63896396
if (!Impl->ExplicitSameTypeRequirements.empty()) {
63906397
// FIXME: Expand all conformance requirements. This is expensive :(
@@ -6855,18 +6862,6 @@ static bool isRedundantlyInheritableObjCProtocol(
68556862
return true;
68566863
}
68576864

6858-
void GenericSignatureBuilder::checkConformanceConstraints(
6859-
TypeArrayView<GenericTypeParamType> genericParams,
6860-
EquivalenceClass *equivClass) {
6861-
for (auto &entry : equivClass->conformsTo) {
6862-
// Remove self-derived constraints.
6863-
assert(!entry.second.empty() && "No constraints to work with?");
6864-
6865-
// Remove any self-derived constraints.
6866-
removeSelfDerived(*this, entry.second, entry.first);
6867-
}
6868-
}
6869-
68706865
void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
68716866
for (const auto &req : Impl->ExplicitRequirements) {
68726867
auto *source = req.getSource();

test/Generics/sr14580.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s
3+
4+
public protocol ScalarProtocol: ScalarMultiplicative where Self == Scalar {
5+
}
6+
7+
public protocol ScalarMultiplicative {
8+
associatedtype Scalar: ScalarProtocol
9+
}
10+
11+
public protocol MapReduceArithmetic: ScalarMultiplicative, Collection where Element: ScalarMultiplicative {}
12+
13+
public protocol Tensor: MapReduceArithmetic where Element == Scalar {
14+
}
15+
16+
// FIXME: The same-type requirement canonicalization still produces bugus results here, but
17+
// at least we don't crash.
18+
19+
// CHECK-LABEL: Requirement signature: <Self where Self : Tensor, Self == Self.Float16Components.Model, Self.Element == Double, Self.Float16Components : ColorComponents, Self.Float32Components : ColorComponents, Self.Float16Components.Element == Double, Self.Float16Components.Model == Self.Float32Components.Model, Self.Float32Components.Element == Double, Self.Float32Components.Indices == Self.Float32Components.Indices.SubSequence, Self.Float32Components.SubSequence == Self.Float32Components.SubSequence.SubSequence, Self.Float32Components.Indices.Indices == Self.Float32Components.Indices.Indices.SubSequence, Self.Float32Components.SubSequence.Indices == Self.Float32Components.SubSequence.Indices.SubSequence, Self.Float32Components.SubSequence.Indices.Indices == Self.Float32Components.SubSequence.Indices.Indices.SubSequence>
20+
public protocol ColorModel: Tensor where Scalar == Double {
21+
associatedtype Float16Components: ColorComponents where Float16Components.Model == Self, Float16Components.Scalar == Double
22+
associatedtype Float32Components: ColorComponents where Float32Components.Model == Self, Float32Components.Scalar == Double
23+
}
24+
25+
public protocol ColorComponents: Tensor {
26+
associatedtype Model: ColorModel
27+
}
28+
29+
extension Double : ScalarMultiplicative {}
30+
extension Double : ScalarProtocol {
31+
public typealias Scalar = Self
32+
}

0 commit comments

Comments
 (0)