@@ -409,32 +409,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
409
409
VarInfo->Scope = getOpScope (VarInfo->Scope );
410
410
}
411
411
412
- ProtocolConformanceRef getOpConformance (Type ty,
413
- ProtocolConformanceRef conformance) {
414
- auto substConf = asImpl ().remapConformance (ty, conformance);
415
-
416
- #ifndef NDEBUG
417
- if (substConf.isInvalid ()) {
418
- llvm::errs () << " Invalid conformance in SIL cloner:\n " ;
419
- Functor.dump (llvm::errs ());
420
- llvm::errs () << " \n conformance:\n " ;
421
- conformance.dump (llvm::errs ());
422
- llvm::errs () << " \n original type:\n " ;
423
- ty.dump (llvm::errs ());
424
- abort ();
425
- }
426
- #endif
427
-
428
- return substConf;
412
+ ProtocolConformanceRef getOpConformance (ProtocolConformanceRef conformance) {
413
+ return asImpl ().remapConformance (conformance);
429
414
}
430
415
431
416
ArrayRef<ProtocolConformanceRef>
432
- getOpConformances (Type ty,
433
- ArrayRef<ProtocolConformanceRef> conformances) {
417
+ getOpConformances (ArrayRef<ProtocolConformanceRef> conformances) {
434
418
SmallVector<ProtocolConformanceRef, 4 > newConformances;
435
419
for (auto conformance : conformances)
436
- newConformances.push_back (getOpConformance (ty, conformance));
437
- return ty-> getASTContext ().AllocateCopy (newConformances);
420
+ newConformances.push_back (getOpConformance (conformance));
421
+ return getBuilder (). getASTContext ().AllocateCopy (newConformances);
438
422
}
439
423
440
424
bool isValueCloned (SILValue OrigValue) const {
@@ -558,28 +542,41 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
558
542
return ty;
559
543
}
560
544
561
- ProtocolConformanceRef remapConformance (Type Ty, ProtocolConformanceRef C) {
562
- if (Functor.SubsMap || Ty->hasLocalArchetype ()) {
545
+ ProtocolConformanceRef remapConformance (ProtocolConformanceRef conformance) {
546
+ auto substConf = conformance;
547
+
548
+ if (Functor.SubsMap || substConf.getType ()->hasLocalArchetype ()) {
563
549
SubstOptions options = SubstFlags::SubstitutePrimaryArchetypes;
564
550
if (Functor.hasLocalArchetypes ())
565
551
options |= SubstFlags::SubstituteLocalArchetypes;
566
552
567
- C = C.subst (Functor, Functor, options);
568
- if (asImpl ().shouldSubstOpaqueArchetypes ())
569
- Ty = Ty.subst (Functor, Functor, options);
553
+ substConf = substConf.subst (Functor, Functor, options);
554
+ }
555
+
556
+ if (substConf.isInvalid ()) {
557
+ llvm::errs () << " Invalid conformance in SIL cloner:\n " ;
558
+ Functor.dump (llvm::errs ());
559
+ llvm::errs () << " \n conformance:\n " ;
560
+ conformance.dump (llvm::errs ());
561
+ llvm::errs () << " \n original conformance:\n " ;
562
+ substConf.dump (llvm::errs ());
563
+ if (Functor.SubsMap ) {
564
+ llvm::errs () << " \n substitution map:\n " ;
565
+ Functor.SubsMap ->dump (llvm::errs ());
566
+ }
567
+ abort ();
570
568
}
571
569
572
570
if (asImpl ().shouldSubstOpaqueArchetypes ()) {
573
571
auto context = getBuilder ().getTypeExpansionContext ();
574
572
575
- if (!Ty->hasOpaqueArchetype () ||
576
- !context.shouldLookThroughOpaqueTypeArchetypes ())
577
- return C;
578
-
579
- return substOpaqueTypesWithUnderlyingTypes (C, context);
573
+ if (substConf.getType ()->hasOpaqueArchetype () &&
574
+ context.shouldLookThroughOpaqueTypeArchetypes ()) {
575
+ return substOpaqueTypesWithUnderlyingTypes (substConf, context);
576
+ }
580
577
}
581
578
582
- return C ;
579
+ return substConf ;
583
580
}
584
581
585
582
SubstitutionMap remapSubstitutionMap (SubstitutionMap Subs) {
@@ -1135,8 +1132,7 @@ SILCloner<ImplClass>::visitAllocExistentialBoxInst(
1135
1132
auto origExistentialType = Inst->getExistentialType ();
1136
1133
auto origFormalType = Inst->getFormalConcreteType ();
1137
1134
1138
- auto conformances = getOpConformances (origFormalType,
1139
- Inst->getConformances ());
1135
+ auto conformances = getOpConformances (Inst->getConformances ());
1140
1136
1141
1137
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1142
1138
recordClonedInstruction (
@@ -2659,29 +2655,28 @@ SILCloner<ImplClass>::visitObjCSuperMethodInst(ObjCSuperMethodInst *Inst) {
2659
2655
template <typename ImplClass>
2660
2656
void
2661
2657
SILCloner<ImplClass>::visitWitnessMethodInst(WitnessMethodInst *Inst) {
2662
- auto lookupType = Inst->getLookupType ();
2663
- auto conformance = getOpConformance (lookupType, Inst->getConformance ());
2664
- auto newLookupType = getOpASTType (lookupType);
2658
+ auto conformance = getOpConformance (Inst->getConformance ());
2659
+ auto lookupType = getOpASTType (Inst->getLookupType ());
2665
2660
2666
2661
if (conformance.isConcrete ()) {
2667
- CanType Ty = conformance.getConcrete ()->getType ()->getCanonicalType ();
2662
+ auto conformingType = conformance.getConcrete ()->getType ()->getCanonicalType ();
2668
2663
2669
- if (Ty != newLookupType ) {
2664
+ if (conformingType != lookupType ) {
2670
2665
assert (
2671
- (Ty ->isExactSuperclassOf (newLookupType ) ||
2666
+ (conformingType ->isExactSuperclassOf (lookupType ) ||
2672
2667
getBuilder ().getModule ().Types .getLoweredRValueType (
2673
- getBuilder ().getTypeExpansionContext (), Ty ) == newLookupType ) &&
2668
+ getBuilder ().getTypeExpansionContext (), conformingType ) == lookupType ) &&
2674
2669
" Should only create upcasts for sub class." );
2675
2670
2676
2671
// We use the super class as the new look up type.
2677
- newLookupType = Ty ;
2672
+ lookupType = conformingType ;
2678
2673
}
2679
2674
}
2680
2675
2681
2676
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2682
2677
recordClonedInstruction (Inst,
2683
2678
getBuilder ().createWitnessMethod (
2684
- getOpLocation (Inst->getLoc ()), newLookupType ,
2679
+ getOpLocation (Inst->getLoc ()), lookupType ,
2685
2680
conformance, Inst->getMember (), getOpType (Inst->getType ())));
2686
2681
}
2687
2682
@@ -2790,8 +2785,7 @@ void
2790
2785
SILCloner<ImplClass>::visitInitExistentialAddrInst(InitExistentialAddrInst *Inst) {
2791
2786
CanType origFormalType = Inst->getFormalConcreteType ();
2792
2787
2793
- auto conformances = getOpConformances (origFormalType,
2794
- Inst->getConformances ());
2788
+ auto conformances = getOpConformances (Inst->getConformances ());
2795
2789
2796
2790
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2797
2791
recordClonedInstruction (
@@ -2806,8 +2800,7 @@ void SILCloner<ImplClass>::visitInitExistentialValueInst(
2806
2800
InitExistentialValueInst *Inst) {
2807
2801
CanType origFormalType = Inst->getFormalConcreteType ();
2808
2802
2809
- auto conformances = getOpConformances (origFormalType,
2810
- Inst->getConformances ());
2803
+ auto conformances = getOpConformances (Inst->getConformances ());
2811
2804
2812
2805
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2813
2806
recordClonedInstruction (
@@ -2821,9 +2814,7 @@ template<typename ImplClass>
2821
2814
void
2822
2815
SILCloner<ImplClass>::
2823
2816
visitInitExistentialMetatypeInst (InitExistentialMetatypeInst *Inst) {
2824
- auto origFormalType = Inst->getFormalErasedObjectType ();
2825
- auto conformances = getOpConformances (origFormalType,
2826
- Inst->getConformances ());
2817
+ auto conformances = getOpConformances (Inst->getConformances ());
2827
2818
2828
2819
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2829
2820
recordClonedInstruction (Inst, getBuilder ().createInitExistentialMetatype (
@@ -2837,8 +2828,7 @@ void
2837
2828
SILCloner<ImplClass>::
2838
2829
visitInitExistentialRefInst (InitExistentialRefInst *Inst) {
2839
2830
CanType origFormalType = Inst->getFormalConcreteType ();
2840
- auto conformances = getOpConformances (origFormalType,
2841
- Inst->getConformances ());
2831
+ auto conformances = getOpConformances (Inst->getConformances ());
2842
2832
2843
2833
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2844
2834
recordClonedInstruction (
0 commit comments