@@ -129,53 +129,6 @@ void PropertyBag::dump(llvm::raw_ostream &out) const {
129
129
out << " }" ;
130
130
}
131
131
132
- // / Concrete type terms are written in terms of generic parameter types that
133
- // / have a depth of 0, and an index into an array of substitution terms.
134
- // /
135
- // / See RewriteSystemBuilder::getConcreteSubstitutionSchema().
136
- static unsigned getGenericParamIndex (Type type) {
137
- auto *paramTy = type->castTo <GenericTypeParamType>();
138
- assert (paramTy->getDepth () == 0 );
139
- return paramTy->getIndex ();
140
- }
141
-
142
- // / Reverses the transformation performed by
143
- // / RewriteSystemBuilder::getConcreteSubstitutionSchema().
144
- static Type getTypeFromSubstitutionSchema (Type schema,
145
- ArrayRef<Term> substitutions,
146
- TypeArrayView<GenericTypeParamType> genericParams,
147
- const MutableTerm &prefix,
148
- const ProtocolGraph &protos,
149
- RewriteContext &ctx) {
150
- assert (!schema->isTypeParameter () && " Must have a concrete type here" );
151
-
152
- if (!schema->hasTypeParameter ())
153
- return schema;
154
-
155
- return schema.transformRec ([&](Type t) -> Optional<Type> {
156
- if (t->is <GenericTypeParamType>()) {
157
- auto index = getGenericParamIndex (t);
158
- auto substitution = substitutions[index];
159
-
160
- // Prepend the prefix of the lookup key to the substitution.
161
- if (prefix.empty ()) {
162
- // Skip creation of a new MutableTerm in the case where the
163
- // prefix is empty.
164
- return ctx.getTypeForTerm (substitution, genericParams, protos);
165
- } else {
166
- // Otherwise build a new term by appending the substitution
167
- // to the prefix.
168
- MutableTerm result (prefix);
169
- result.append (substitution);
170
- return ctx.getTypeForTerm (result, genericParams, protos);
171
- }
172
- }
173
-
174
- assert (!t->isTypeParameter ());
175
- return None;
176
- });
177
- }
178
-
179
132
// / Given a term \p lookupTerm whose suffix must equal this property bag's
180
133
// / key, return a new term with that suffix stripped off. Will be empty if
181
134
// / \p lookupTerm exactly equals the key.
@@ -205,10 +158,10 @@ Type PropertyBag::getSuperclassBound(
205
158
const ProtocolGraph &protos,
206
159
RewriteContext &ctx) const {
207
160
MutableTerm prefix = getPrefixAfterStrippingKey (lookupTerm);
208
- return getTypeFromSubstitutionSchema (Superclass->getSuperclass (),
209
- Superclass->getSubstitutions (),
210
- genericParams, prefix,
211
- protos, ctx );
161
+ return ctx. getTypeFromSubstitutionSchema (Superclass->getSuperclass (),
162
+ Superclass->getSubstitutions (),
163
+ genericParams, prefix,
164
+ protos );
212
165
}
213
166
214
167
// / Get the concrete type of the term represented by this property bag.
@@ -226,70 +179,10 @@ Type PropertyBag::getConcreteType(
226
179
const ProtocolGraph &protos,
227
180
RewriteContext &ctx) const {
228
181
MutableTerm prefix = getPrefixAfterStrippingKey (lookupTerm);
229
- return getTypeFromSubstitutionSchema (ConcreteType->getConcreteType (),
230
- ConcreteType->getSubstitutions (),
231
- genericParams, prefix,
232
- protos, ctx);
233
- }
234
-
235
- // / Computes the term corresponding to a member type access on a substitution.
236
- // /
237
- // / The type witness is a type parameter of the form τ_0_n.X.Y.Z,
238
- // / where 'n' is an index into the substitution array.
239
- // /
240
- // / If the nth entry in the array is S, this will produce S.X.Y.Z.
241
- // /
242
- // / There is a special behavior if the substitution is a term consisting of a
243
- // / single protocol symbol [P]. If the innermost associated type in
244
- // / \p typeWitness is [Q:Foo], the result will be [P:Foo], not [P].[Q:Foo] or
245
- // / [Q:Foo].
246
- static MutableTerm getRelativeTermForType (CanType typeWitness,
247
- ArrayRef<Term> substitutions,
248
- RewriteContext &ctx) {
249
- MutableTerm result;
250
-
251
- // Get the substitution S corresponding to τ_0_n.
252
- unsigned index = getGenericParamIndex (typeWitness->getRootGenericParam ());
253
- result = MutableTerm (substitutions[index]);
254
-
255
- // If the substitution is a term consisting of a single protocol symbol
256
- // [P], save P for later.
257
- const ProtocolDecl *proto = nullptr ;
258
- if (result.size () == 1 &&
259
- result[0 ].getKind () == Symbol::Kind::Protocol) {
260
- proto = result[0 ].getProtocol ();
261
- }
262
-
263
- // Collect zero or more member type names in reverse order.
264
- SmallVector<Symbol, 3 > symbols;
265
- while (auto memberType = dyn_cast<DependentMemberType>(typeWitness)) {
266
- typeWitness = memberType.getBase ();
267
-
268
- auto *assocType = memberType->getAssocType ();
269
- assert (assocType != nullptr &&
270
- " Conformance checking should not produce unresolved member types" );
271
-
272
- // If the substitution is a term consisting of a single protocol symbol [P],
273
- // produce [P:Foo] instead of [P].[Q:Foo] or [Q:Foo].
274
- const auto *thisProto = assocType->getProtocol ();
275
- if (proto && isa<GenericTypeParamType>(typeWitness)) {
276
- thisProto = proto;
277
-
278
- assert (result.size () == 1 );
279
- assert (result[0 ].getKind () == Symbol::Kind::Protocol);
280
- assert (result[0 ].getProtocol () == proto);
281
- result = MutableTerm ();
282
- }
283
-
284
- symbols.push_back (Symbol::forAssociatedType (thisProto,
285
- assocType->getName (), ctx));
286
- }
287
-
288
- // Add the member type names.
289
- for (auto iter = symbols.rbegin (), end = symbols.rend (); iter != end; ++iter)
290
- result.add (*iter);
291
-
292
- return result;
182
+ return ctx.getTypeFromSubstitutionSchema (ConcreteType->getConcreteType (),
183
+ ConcreteType->getSubstitutions (),
184
+ genericParams, prefix,
185
+ protos);
293
186
}
294
187
295
188
// / This method takes a concrete type that was derived from a concrete type
@@ -327,7 +220,7 @@ remapConcreteSubstitutionSchema(CanType concreteType,
327
220
if (!t->isTypeParameter ())
328
221
return None;
329
222
330
- auto term = getRelativeTermForType (CanType (t), substitutions, ctx );
223
+ auto term = ctx. getRelativeTermForType (CanType (t), substitutions);
331
224
332
225
unsigned newIndex = result.size ();
333
226
result.push_back (Term::get (term, ctx));
@@ -368,10 +261,10 @@ namespace {
368
261
369
262
if (firstAbstract && secondAbstract) {
370
263
// Both sides are type parameters; add a same-type requirement.
371
- auto lhsTerm = getRelativeTermForType (CanType (firstType),
372
- lhsSubstitutions, ctx );
373
- auto rhsTerm = getRelativeTermForType (CanType (secondType),
374
- rhsSubstitutions, ctx );
264
+ auto lhsTerm = ctx. getRelativeTermForType (CanType (firstType),
265
+ lhsSubstitutions );
266
+ auto rhsTerm = ctx. getRelativeTermForType (CanType (secondType),
267
+ rhsSubstitutions );
375
268
if (lhsTerm != rhsTerm) {
376
269
if (debug) {
377
270
llvm::dbgs () << " %% Induced rule " << lhsTerm
@@ -385,8 +278,8 @@ namespace {
385
278
if (firstAbstract && !secondAbstract) {
386
279
// A type parameter is equated with a concrete type; add a concrete
387
280
// type requirement.
388
- auto subjectTerm = getRelativeTermForType (CanType (firstType),
389
- lhsSubstitutions, ctx );
281
+ auto subjectTerm = ctx. getRelativeTermForType (CanType (firstType),
282
+ lhsSubstitutions );
390
283
391
284
SmallVector<Term, 3 > result;
392
285
auto concreteType = remapConcreteSubstitutionSchema (CanType (secondType),
@@ -407,8 +300,8 @@ namespace {
407
300
if (!firstAbstract && secondAbstract) {
408
301
// A concrete type is equated with a type parameter; add a concrete
409
302
// type requirement.
410
- auto subjectTerm = getRelativeTermForType (CanType (secondType),
411
- rhsSubstitutions, ctx );
303
+ auto subjectTerm = ctx. getRelativeTermForType (CanType (secondType),
304
+ rhsSubstitutions );
412
305
413
306
SmallVector<Term, 3 > result;
414
307
auto concreteType = remapConcreteSubstitutionSchema (CanType (firstType),
@@ -915,8 +808,8 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
915
808
if (!t->isTypeParameter ())
916
809
return None;
917
810
918
- auto term = getRelativeTermForType (t->getCanonicalType (),
919
- substitutions, Context );
811
+ auto term = Context. getRelativeTermForType (t->getCanonicalType (),
812
+ substitutions );
920
813
System.simplify (term);
921
814
return Context.getTypeForTerm (term, { }, Protos);
922
815
}));
@@ -998,7 +891,7 @@ MutableTerm PropertyMap::computeConstraintTermForTypeWitness(
998
891
// where 'n' is an index into the substitution array.
999
892
//
1000
893
// Add a rule T => S.X.Y...Z, where S is the nth substitution term.
1001
- return getRelativeTermForType (typeWitness, substitutions, Context );
894
+ return Context. getRelativeTermForType (typeWitness, substitutions);
1002
895
}
1003
896
1004
897
// The type witness is a concrete type.
0 commit comments