@@ -449,29 +449,90 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
449
449
SILLocation remapLocation (SILLocation Loc) { return Loc; }
450
450
const SILDebugScope *remapScope (const SILDebugScope *DS) { return DS; }
451
451
452
+ bool shouldSubstOpaqueArchetypes () const { return false ; }
453
+
452
454
SILType remapType (SILType Ty) {
453
455
if (Functor.SubsMap || Ty.hasLocalArchetype ()) {
454
456
Ty = Ty.subst (Builder.getModule (), Functor, Functor,
455
457
CanGenericSignature ());
456
458
}
457
459
460
+ if (asImpl ().shouldSubstOpaqueArchetypes ()) {
461
+ auto context = getBuilder ().getTypeExpansionContext ();
462
+
463
+ if (!Ty.hasOpaqueArchetype () ||
464
+ !context.shouldLookThroughOpaqueTypeArchetypes ())
465
+ return Ty;
466
+
467
+ // Remap types containing opaque result types in the current context.
468
+ Ty = getBuilder ().getTypeLowering (Ty).getLoweredType ().getCategoryType (
469
+ Ty.getCategory ());
470
+ }
471
+
458
472
return Ty;
459
473
}
460
474
461
475
CanType remapASTType (CanType ty) {
462
476
if (Functor.SubsMap || ty->hasLocalArchetype ())
463
477
ty = ty.subst (Functor, Functor)->getCanonicalType ();
464
478
479
+ if (asImpl ().shouldSubstOpaqueArchetypes ()) {
480
+ auto context = getBuilder ().getTypeExpansionContext ();
481
+
482
+ if (!ty->hasOpaqueArchetype () ||
483
+ !context.shouldLookThroughOpaqueTypeArchetypes ())
484
+ return ty;
485
+
486
+ // Remap types containing opaque result types in the current context.
487
+ return substOpaqueTypesWithUnderlyingTypes (ty, context,
488
+ /* allowLoweredTypes=*/ false );
489
+ }
490
+
465
491
return ty;
466
492
}
467
493
468
494
ProtocolConformanceRef remapConformance (Type Ty, ProtocolConformanceRef C) {
469
- if (Functor.SubsMap || Ty->hasLocalArchetype ())
495
+ if (Functor.SubsMap || Ty->hasLocalArchetype ()) {
470
496
C = C.subst (Ty, Functor, Functor);
497
+ if (asImpl ().shouldSubstOpaqueArchetypes ())
498
+ Ty = Ty.subst (Functor, Functor);
499
+ }
500
+
501
+ if (asImpl ().shouldSubstOpaqueArchetypes ()) {
502
+ auto context = getBuilder ().getTypeExpansionContext ();
503
+
504
+ if (!Ty->hasOpaqueArchetype () ||
505
+ !context.shouldLookThroughOpaqueTypeArchetypes ())
506
+ return C;
507
+
508
+ return substOpaqueTypesWithUnderlyingTypes (C, Ty, context);
509
+ }
471
510
472
511
return C;
473
512
}
474
513
514
+ SubstitutionMap remapSubstitutionMap (SubstitutionMap Subs) {
515
+ // If we have local archetypes to substitute, do so now.
516
+ if (Subs.hasLocalArchetypes () || Functor.SubsMap )
517
+ Subs = Subs.subst (Functor, Functor);
518
+
519
+ if (asImpl ().shouldSubstOpaqueArchetypes ()) {
520
+ auto context = getBuilder ().getTypeExpansionContext ();
521
+
522
+ if (!Subs.hasOpaqueArchetypes () ||
523
+ !context.shouldLookThroughOpaqueTypeArchetypes ())
524
+ return Subs;
525
+
526
+ ReplaceOpaqueTypesWithUnderlyingTypes replacer (
527
+ context.getContext (), context.getResilienceExpansion (),
528
+ context.isWholeModuleContext ());
529
+ return Subs.subst (replacer, replacer,
530
+ SubstFlags::SubstituteOpaqueArchetypes);
531
+ }
532
+
533
+ return Subs;
534
+ }
535
+
475
536
// / Get the value that takes the place of the given `Value` within the cloned
476
537
// / region. The given value must already have been mapped by this cloner.
477
538
SILValue getMappedValue (SILValue Value);
@@ -481,14 +542,6 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
481
542
SILBasicBlock *remapBasicBlock (SILBasicBlock *BB);
482
543
void postProcess (SILInstruction *Orig, SILInstruction *Cloned);
483
544
484
- SubstitutionMap remapSubstitutionMap (SubstitutionMap Subs) {
485
- // If we have local archetypes to substitute, do so now.
486
- if (Subs.hasLocalArchetypes () || Functor.SubsMap )
487
- Subs = Subs.subst (Functor, Functor);
488
-
489
- return Subs;
490
- }
491
-
492
545
// / This is called by either of the top-level visitors, cloneReachableBlocks
493
546
// / or cloneSILFunction, after all other visitors are have been called.
494
547
0 commit comments