Skip to content

Commit 9b0f61b

Browse files
authored
Merge pull request swiftlang#39512 from slavapestov/rqm-sugared-generic-params
RequirementMachine: Preserve sugared generic params in getSuperclassBound() and getConcreteType()
2 parents 25f7145 + 3f8ef30 commit 9b0f61b

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ Type GenericSignatureImpl::getSuperclassBound(Type type) const {
539539

540540
auto computeViaRQM = [&]() {
541541
auto *machine = getRequirementMachine();
542-
return machine->getSuperclassBound(type);
542+
return machine->getSuperclassBound(type, getGenericParams());
543543
};
544544

545545
auto &ctx = getASTContext();
@@ -772,7 +772,7 @@ Type GenericSignatureImpl::getConcreteType(Type type) const {
772772

773773
auto computeViaRQM = [&]() {
774774
auto *machine = getRequirementMachine();
775-
return machine->getConcreteType(type);
775+
return machine->getConcreteType(type, getGenericParams());
776776
};
777777

778778
auto &ctx = getASTContext();

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ RequirementMachine::getRequiredProtocols(Type depType) const {
139139
return result;
140140
}
141141

142-
Type RequirementMachine::getSuperclassBound(Type depType) const {
142+
Type RequirementMachine::
143+
getSuperclassBound(Type depType,
144+
TypeArrayView<GenericTypeParamType> genericParams) const {
143145
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
144146
/*proto=*/nullptr);
145147
System.simplify(term);
@@ -153,7 +155,7 @@ Type RequirementMachine::getSuperclassBound(Type depType) const {
153155
return Type();
154156

155157
auto &protos = System.getProtocols();
156-
return props->getSuperclassBound({ }, term, protos, Context);
158+
return props->getSuperclassBound(genericParams, term, protos, Context);
157159
}
158160

159161
bool RequirementMachine::isConcreteType(Type depType) const {
@@ -169,7 +171,9 @@ bool RequirementMachine::isConcreteType(Type depType) const {
169171
return props->isConcreteType();
170172
}
171173

172-
Type RequirementMachine::getConcreteType(Type depType) const {
174+
Type RequirementMachine::
175+
getConcreteType(Type depType,
176+
TypeArrayView<GenericTypeParamType> genericParams) const {
173177
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
174178
/*proto=*/nullptr);
175179
System.simplify(term);
@@ -183,7 +187,7 @@ Type RequirementMachine::getConcreteType(Type depType) const {
183187
return Type();
184188

185189
auto &protos = System.getProtocols();
186-
return props->getConcreteType({ }, term, protos, Context);
190+
return props->getConcreteType(genericParams, term, protos, Context);
187191
}
188192

189193
bool RequirementMachine::areSameTypeParameterInContext(Type depType1,

lib/AST/RequirementMachine/RequirementMachine.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ class RequirementMachine final {
9898
LayoutConstraint getLayoutConstraint(Type depType) const;
9999
bool requiresProtocol(Type depType, const ProtocolDecl *proto) const;
100100
GenericSignature::RequiredProtocols getRequiredProtocols(Type depType) const;
101-
Type getSuperclassBound(Type depType) const;
101+
Type getSuperclassBound(Type depType,
102+
TypeArrayView<GenericTypeParamType> genericParams) const;
102103
bool isConcreteType(Type depType) const;
103-
Type getConcreteType(Type depType) const;
104+
Type getConcreteType(Type depType,
105+
TypeArrayView<GenericTypeParamType> genericParams) const;
104106
bool areSameTypeParameterInContext(Type depType1, Type depType2) const;
105107
bool isCanonicalTypeInContext(Type type) const;
106108
Type getCanonicalTypeInContext(Type type,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -emit-module -o %t/Test.swiftmodule -emit-module-interface-path %t/Test.swiftinterface -module-name Test -enable-library-evolution -swift-version 5 %s
3+
// RUN: %FileCheck %s < %t/Test.swiftinterface
4+
5+
public protocol P {
6+
}
7+
8+
public class Foo<T> : P {
9+
public struct Nested {}
10+
}
11+
12+
extension P {
13+
public static func blah1<T>(_: Self) where Self == Foo<T> {}
14+
public static func blah2<T>(_: Self.Nested) where Self == Foo<T> {}
15+
16+
public static func blah3<T>(_: Self) where Self : Foo<T> {}
17+
public static func blah4<T>(_: Self.Nested) where Self : Foo<T> {}
18+
}
19+
20+
// CHECK-LABEL: extension Test.P {
21+
// CHECK-NEXT: public static func blah1<T>(_: Self) where Self == Test.Foo<T>
22+
// CHECK-NEXT: public static func blah2<T>(_: Test.Foo<T>.Nested) where Self == Test.Foo<T>
23+
// CHECK-NEXT: public static func blah3<T>(_: Self) where Self : Test.Foo<T>
24+
// CHECK-NEXT: public static func blah4<T>(_: Test.Foo<T>.Nested) where Self : Test.Foo<T>
25+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)