@@ -57,6 +57,16 @@ struct SubstitutionMapWithLocalArchetypes {
57
57
58
58
return ProtocolConformanceRef (proto);
59
59
}
60
+
61
+ void dump (llvm::raw_ostream &out) const {
62
+ if (SubsMap)
63
+ SubsMap->dump (out);
64
+ for (auto pair : LocalArchetypeSubs) {
65
+ out << " ---\n " ;
66
+ pair.first ->dump (out);
67
+ pair.second ->dump (out);
68
+ }
69
+ }
60
70
};
61
71
62
72
// / SILCloner - Abstract SIL visitor which knows how to clone instructions and
@@ -231,8 +241,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
231
241
for (auto substConf : substSubs.getConformances ()) {
232
242
if (substConf.isInvalid ()) {
233
243
llvm::errs () << " Invalid conformance in SIL cloner:\n " ;
234
- if (Functor.SubsMap )
235
- Functor.SubsMap ->dump (llvm::errs ());
244
+ Functor.dump (llvm::errs ());
236
245
llvm::errs () << " \n substitution map:\n " ;
237
246
Subs.dump (llvm::errs ());
238
247
llvm::errs () << " \n " ;
@@ -363,11 +372,10 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
363
372
#ifndef NDEBUG
364
373
if (substConf.isInvalid ()) {
365
374
llvm::errs () << " Invalid conformance in SIL cloner:\n " ;
366
- if (Functor.SubsMap )
367
- Functor.SubsMap ->dump (llvm::errs ());
375
+ Functor.dump (llvm::errs ());
368
376
llvm::errs () << " \n conformance:\n " ;
369
377
conformance.dump (llvm::errs ());
370
- llvm::errs () << " original type:\n " ;
378
+ llvm::errs () << " \n original type:\n " ;
371
379
ty.dump (llvm::errs ());
372
380
abort ();
373
381
}
@@ -460,8 +468,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
460
468
461
469
SILType remapType (SILType Ty) {
462
470
if (Functor.SubsMap || Ty.hasLocalArchetype ()) {
471
+ SubstOptions options (std::nullopt );
472
+ if (!Functor.LocalArchetypeSubs .empty ())
473
+ options |= SubstFlags::SubstituteLocalArchetypes;
474
+
463
475
Ty = Ty.subst (Builder.getModule (), Functor, Functor,
464
- CanGenericSignature ());
476
+ CanGenericSignature (), options );
465
477
}
466
478
467
479
if (asImpl ().shouldSubstOpaqueArchetypes ()) {
@@ -480,8 +492,13 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
480
492
}
481
493
482
494
CanType remapASTType (CanType ty) {
483
- if (Functor.SubsMap || ty->hasLocalArchetype ())
484
- ty = ty.subst (Functor, Functor)->getCanonicalType ();
495
+ if (Functor.SubsMap || ty->hasLocalArchetype ()) {
496
+ SubstOptions options (std::nullopt );
497
+ if (!Functor.LocalArchetypeSubs .empty ())
498
+ options |= SubstFlags::SubstituteLocalArchetypes;
499
+
500
+ ty = ty.subst (Functor, Functor, options)->getCanonicalType ();
501
+ }
485
502
486
503
if (asImpl ().shouldSubstOpaqueArchetypes ()) {
487
504
auto context = getBuilder ().getTypeExpansionContext ();
@@ -500,9 +517,13 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
500
517
501
518
ProtocolConformanceRef remapConformance (Type Ty, ProtocolConformanceRef C) {
502
519
if (Functor.SubsMap || Ty->hasLocalArchetype ()) {
503
- C = C.subst (Ty, Functor, Functor);
520
+ SubstOptions options (std::nullopt );
521
+ if (!Functor.LocalArchetypeSubs .empty ())
522
+ options |= SubstFlags::SubstituteLocalArchetypes;
523
+
524
+ C = C.subst (Ty, Functor, Functor, options);
504
525
if (asImpl ().shouldSubstOpaqueArchetypes ())
505
- Ty = Ty.subst (Functor, Functor);
526
+ Ty = Ty.subst (Functor, Functor, options );
506
527
}
507
528
508
529
if (asImpl ().shouldSubstOpaqueArchetypes ()) {
@@ -520,8 +541,13 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
520
541
521
542
SubstitutionMap remapSubstitutionMap (SubstitutionMap Subs) {
522
543
// If we have local archetypes to substitute, do so now.
523
- if (Subs.getRecursiveProperties ().hasLocalArchetype () || Functor.SubsMap )
524
- Subs = Subs.subst (Functor, Functor);
544
+ if (Subs.getRecursiveProperties ().hasLocalArchetype () || Functor.SubsMap ) {
545
+ SubstOptions options (std::nullopt );
546
+ if (!Functor.LocalArchetypeSubs .empty ())
547
+ options |= SubstFlags::SubstituteLocalArchetypes;
548
+
549
+ Subs = Subs.subst (Functor, Functor, options);
550
+ }
525
551
526
552
if (asImpl ().shouldSubstOpaqueArchetypes ()) {
527
553
auto context = getBuilder ().getTypeExpansionContext ();
0 commit comments