Skip to content

Commit ff40f10

Browse files
committed
RequirementMachine: Allow RequirementMachine::isConcreteType() and ::getCanonicalTypeInContext() to be used with protocol connected components
1 parent 4446f2a commit ff40f10

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ getSuperclassBound(Type depType,
156156
return props->getSuperclassBound(genericParams, term, Map);
157157
}
158158

159-
bool RequirementMachine::isConcreteType(Type depType) const {
159+
/// Unlike the other queries, we have occasion to call this on a requirement
160+
/// machine for a protocol connected component as well as a top-level
161+
/// generic signature, so plumb through the protocol to use for the root
162+
/// `Self` generic parameter here.
163+
bool RequirementMachine::isConcreteType(Type depType,
164+
const ProtocolDecl *proto) const {
160165
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
161-
/*proto=*/nullptr);
166+
proto);
162167
System.simplify(term);
163168
verify(term);
164169

@@ -169,11 +174,16 @@ bool RequirementMachine::isConcreteType(Type depType) const {
169174
return props->isConcreteType();
170175
}
171176

177+
/// Unlike the other queries, we have occasion to call this on a requirement
178+
/// machine for a protocol connected component as well as a top-level
179+
/// generic signature, so plumb through the protocol to use for the root
180+
/// `Self` generic parameter here.
172181
Type RequirementMachine::
173182
getConcreteType(Type depType,
174-
TypeArrayView<GenericTypeParamType> genericParams) const {
183+
TypeArrayView<GenericTypeParamType> genericParams,
184+
const ProtocolDecl *proto) const {
175185
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
176-
/*proto=*/nullptr);
186+
proto);
177187
System.simplify(term);
178188
verify(term);
179189

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ RequirementMachine::initWithProtocolWrittenRequirements(
172172
SmallVector<StructuralRequirement, 4>> protos) {
173173
FrontendStatsTracer tracer(Stats, "build-rewrite-system");
174174

175+
// For RequirementMachine::verify() when called by generic signature queries;
176+
// We have a single valid generic parameter at depth 0, index 0.
177+
Params.push_back(component[0]->getSelfInterfaceType()->getCanonicalType());
178+
175179
if (Dump) {
176180
llvm::dbgs() << "Adding protocols";
177181
for (auto *proto : component) {

lib/AST/RequirementMachine/RequirementMachine.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ class RequirementMachine final {
142142
GenericSignature::RequiredProtocols getRequiredProtocols(Type depType) const;
143143
Type getSuperclassBound(Type depType,
144144
TypeArrayView<GenericTypeParamType> genericParams) const;
145-
bool isConcreteType(Type depType) const;
145+
bool isConcreteType(Type depType,
146+
const ProtocolDecl *proto=nullptr) const;
146147
Type getConcreteType(Type depType,
147-
TypeArrayView<GenericTypeParamType> genericParams) const;
148+
TypeArrayView<GenericTypeParamType> genericParams,
149+
const ProtocolDecl *proto=nullptr) const;
148150
bool areSameTypeParameterInContext(Type depType1, Type depType2) const;
149151
bool isCanonicalTypeInContext(Type type) const;
150152
Type getCanonicalTypeInContext(Type type,

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ RequirementMachine::computeMinimalProtocolRequirements() {
119119

120120
assert(protos.size() > 0 &&
121121
"Not a protocol connected component rewrite system");
122-
assert(Params.empty() &&
123-
"Not a protocol connected component rewrite system");
124122

125123
System.minimizeRewriteSystem();
126124

0 commit comments

Comments
 (0)