@@ -204,23 +204,30 @@ static MutableTerm getRelativeTermForType(CanType typeWitness,
204
204
return result;
205
205
}
206
206
207
- // / Given a concrete type that is a structural sub-component of a concrete
208
- // / type produced by RewriteSystemBuilder::getConcreteSubstitutionSchema(),
209
- // / collect the subset of referenced substitutions and renumber the generic
210
- // / parameters in the type.
207
+ // / This method takes a concrete type that was derived from a concrete type
208
+ // / produced by RewriteSystemBuilder::getConcreteSubstitutionSchema(),
209
+ // / either by extracting a structural sub-component or performing a (Swift AST)
210
+ // / substitution using subst(). It returns a new concrete substitution schema
211
+ // / and a new list of substitution terms.
211
212
// /
212
213
// / For example, suppose we start with the concrete type
213
214
// /
214
215
// / Dictionary<τ_0_0, Array<τ_0_1>> with substitutions {X.Y, Z}
215
216
// /
216
217
// / We can extract out the structural sub-component Array<τ_0_1>. If we wish
217
- // / to turn this into a new concrete substitution schema, we call this method
218
- // / with Array<τ_0_1> and the original substitutions {X.Y, Z}. This will
219
- // / return the type Array<τ_0_0> and the substitutions {Z}.
220
- CanType
218
+ // / to build a new concrete substitution schema, we call this method with
219
+ // / Array<τ_0_1> and the original substitutions {X.Y, Z}. This will produce
220
+ // / the new schema Array<τ_0_0> with substitutions {Z}.
221
+ // /
222
+ // / As another example, consider we start with the schema Bar<τ_0_0> with
223
+ // / original substitutions {X.Y}, and perform a Swift AST subst() to get
224
+ // / Foo<τ_0_0.A.B>. We can then call this method with Foo<τ_0_0.A.B> and
225
+ // / the original substitutions {X.Y} to produce the new schema Foo<τ_0_0>
226
+ // / with substitutions {X.Y.A.B}.
227
+ static CanType
221
228
remapConcreteSubstitutionSchema (CanType concreteType,
222
229
ArrayRef<Term> substitutions,
223
- ASTContext &ctx,
230
+ RewriteContext &ctx,
224
231
SmallVectorImpl<Term> &result) {
225
232
assert (!concreteType->isTypeParameter () && " Must have a concrete type here" );
226
233
@@ -229,16 +236,16 @@ remapConcreteSubstitutionSchema(CanType concreteType,
229
236
230
237
return CanType (concreteType.transformRec (
231
238
[&](Type t) -> Optional<Type> {
232
- assert (!t->is <DependentMemberType>());
233
-
234
- if (!t->is <GenericTypeParamType>())
239
+ if (!t->isTypeParameter ())
235
240
return None;
236
241
237
- unsigned oldIndex = getGenericParamIndex (t);
242
+ auto term = getRelativeTermForType (CanType (t), substitutions, ctx);
243
+
238
244
unsigned newIndex = result.size ();
239
- result.push_back (substitutions[oldIndex] );
245
+ result.push_back (Term::get (term, ctx) );
240
246
241
- return CanGenericTypeParamType::get (/* depth=*/ 0 , newIndex, ctx);
247
+ return CanGenericTypeParamType::get (/* depth=*/ 0 , newIndex,
248
+ ctx.getASTContext ());
242
249
}));
243
250
}
244
251
@@ -326,8 +333,7 @@ static Atom unifyConcreteTypes(
326
333
SmallVector<Term, 3 > result;
327
334
auto concreteType = remapConcreteSubstitutionSchema (CanType (secondType),
328
335
rhsSubstitutions,
329
- ctx.getASTContext (),
330
- result);
336
+ ctx, result);
331
337
332
338
MutableTerm constraintTerm (subjectTerm);
333
339
constraintTerm.add (Atom::forConcreteType (concreteType, result, ctx));
@@ -350,8 +356,7 @@ static Atom unifyConcreteTypes(
350
356
SmallVector<Term, 3 > result;
351
357
auto concreteType = remapConcreteSubstitutionSchema (CanType (firstType),
352
358
lhsSubstitutions,
353
- ctx.getASTContext (),
354
- result);
359
+ ctx, result);
355
360
356
361
MutableTerm constraintTerm (subjectTerm);
357
362
constraintTerm.add (Atom::forConcreteType (concreteType, result, ctx));
@@ -676,12 +681,10 @@ void EquivalenceClassMap::concretizeNestedTypesFromConcreteParent(
676
681
// The type witness is a concrete type.
677
682
constraintType = subjectType;
678
683
679
- // FIXME: Handle dependent member types here
680
684
SmallVector<Term, 3 > result;
681
685
auto typeWitnessSchema =
682
686
remapConcreteSubstitutionSchema (typeWitness, substitutions,
683
- Context.getASTContext (),
684
- result);
687
+ Context, result);
685
688
686
689
// Add a rule T.[P:A].[concrete: Foo.A] => T.[P:A].
687
690
constraintType.add (
0 commit comments