@@ -409,32 +409,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
409409 VarInfo->Scope = getOpScope (VarInfo->Scope );
410410 }
411411
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);
429414 }
430415
431416 ArrayRef<ProtocolConformanceRef>
432- getOpConformances (Type ty,
433- ArrayRef<ProtocolConformanceRef> conformances) {
417+ getOpConformances (ArrayRef<ProtocolConformanceRef> conformances) {
434418 SmallVector<ProtocolConformanceRef, 4 > newConformances;
435419 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);
438422 }
439423
440424 bool isValueCloned (SILValue OrigValue) const {
@@ -558,28 +542,35 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
558542 return ty;
559543 }
560544
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 ()) {
563549 SubstOptions options = SubstFlags::SubstitutePrimaryArchetypes;
564550 if (Functor.hasLocalArchetypes ())
565551 options |= SubstFlags::SubstituteLocalArchetypes;
566552
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 substituted conformance in SIL cloner:\n " ;
558+ Functor.dump (llvm::errs ());
559+ llvm::errs () << " \n original conformance:\n " ;
560+ conformance.dump (llvm::errs ());
561+ abort ();
570562 }
571563
572564 if (asImpl ().shouldSubstOpaqueArchetypes ()) {
573565 auto context = getBuilder ().getTypeExpansionContext ();
574566
575- if (!Ty->hasOpaqueArchetype () ||
576- !context.shouldLookThroughOpaqueTypeArchetypes ())
577- return C;
578-
579- return substOpaqueTypesWithUnderlyingTypes (C, context);
567+ if (substConf.getType ()->hasOpaqueArchetype () &&
568+ context.shouldLookThroughOpaqueTypeArchetypes ()) {
569+ return substOpaqueTypesWithUnderlyingTypes (substConf, context);
570+ }
580571 }
581572
582- return C ;
573+ return substConf ;
583574 }
584575
585576 SubstitutionMap remapSubstitutionMap (SubstitutionMap Subs) {
@@ -599,11 +590,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
599590 !context.shouldLookThroughOpaqueTypeArchetypes ())
600591 return Subs;
601592
602- ReplaceOpaqueTypesWithUnderlyingTypes replacer (
603- context.getContext (), context.getResilienceExpansion (),
604- context.isWholeModuleContext ());
605- return Subs.subst (replacer, replacer,
606- SubstFlags::SubstituteOpaqueArchetypes);
593+ return Subs.mapIntoTypeExpansionContext (context);
607594 }
608595
609596 return Subs;
@@ -1135,8 +1122,7 @@ SILCloner<ImplClass>::visitAllocExistentialBoxInst(
11351122 auto origExistentialType = Inst->getExistentialType ();
11361123 auto origFormalType = Inst->getFormalConcreteType ();
11371124
1138- auto conformances = getOpConformances (origFormalType,
1139- Inst->getConformances ());
1125+ auto conformances = getOpConformances (Inst->getConformances ());
11401126
11411127 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
11421128 recordClonedInstruction (
@@ -2659,29 +2645,28 @@ SILCloner<ImplClass>::visitObjCSuperMethodInst(ObjCSuperMethodInst *Inst) {
26592645template <typename ImplClass>
26602646void
26612647SILCloner<ImplClass>::visitWitnessMethodInst(WitnessMethodInst *Inst) {
2662- auto lookupType = Inst->getLookupType ();
2663- auto conformance = getOpConformance (lookupType, Inst->getConformance ());
2664- auto newLookupType = getOpASTType (lookupType);
2648+ auto conformance = getOpConformance (Inst->getConformance ());
2649+ auto lookupType = getOpASTType (Inst->getLookupType ());
26652650
26662651 if (conformance.isConcrete ()) {
2667- CanType Ty = conformance.getConcrete ()->getType ()->getCanonicalType ();
2652+ auto conformingType = conformance.getConcrete ()->getType ()->getCanonicalType ();
26682653
2669- if (Ty != newLookupType ) {
2654+ if (conformingType != lookupType ) {
26702655 assert (
2671- (Ty ->isExactSuperclassOf (newLookupType ) ||
2656+ (conformingType ->isExactSuperclassOf (lookupType ) ||
26722657 getBuilder ().getModule ().Types .getLoweredRValueType (
2673- getBuilder ().getTypeExpansionContext (), Ty ) == newLookupType ) &&
2658+ getBuilder ().getTypeExpansionContext (), conformingType ) == lookupType ) &&
26742659 " Should only create upcasts for sub class." );
26752660
26762661 // We use the super class as the new look up type.
2677- newLookupType = Ty ;
2662+ lookupType = conformingType ;
26782663 }
26792664 }
26802665
26812666 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
26822667 recordClonedInstruction (Inst,
26832668 getBuilder ().createWitnessMethod (
2684- getOpLocation (Inst->getLoc ()), newLookupType ,
2669+ getOpLocation (Inst->getLoc ()), lookupType ,
26852670 conformance, Inst->getMember (), getOpType (Inst->getType ())));
26862671}
26872672
@@ -2790,8 +2775,7 @@ void
27902775SILCloner<ImplClass>::visitInitExistentialAddrInst(InitExistentialAddrInst *Inst) {
27912776 CanType origFormalType = Inst->getFormalConcreteType ();
27922777
2793- auto conformances = getOpConformances (origFormalType,
2794- Inst->getConformances ());
2778+ auto conformances = getOpConformances (Inst->getConformances ());
27952779
27962780 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
27972781 recordClonedInstruction (
@@ -2806,8 +2790,7 @@ void SILCloner<ImplClass>::visitInitExistentialValueInst(
28062790 InitExistentialValueInst *Inst) {
28072791 CanType origFormalType = Inst->getFormalConcreteType ();
28082792
2809- auto conformances = getOpConformances (origFormalType,
2810- Inst->getConformances ());
2793+ auto conformances = getOpConformances (Inst->getConformances ());
28112794
28122795 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
28132796 recordClonedInstruction (
@@ -2821,9 +2804,7 @@ template<typename ImplClass>
28212804void
28222805SILCloner<ImplClass>::
28232806visitInitExistentialMetatypeInst (InitExistentialMetatypeInst *Inst) {
2824- auto origFormalType = Inst->getFormalErasedObjectType ();
2825- auto conformances = getOpConformances (origFormalType,
2826- Inst->getConformances ());
2807+ auto conformances = getOpConformances (Inst->getConformances ());
28272808
28282809 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
28292810 recordClonedInstruction (Inst, getBuilder ().createInitExistentialMetatype (
@@ -2837,8 +2818,7 @@ void
28372818SILCloner<ImplClass>::
28382819visitInitExistentialRefInst (InitExistentialRefInst *Inst) {
28392820 CanType origFormalType = Inst->getFormalConcreteType ();
2840- auto conformances = getOpConformances (origFormalType,
2841- Inst->getConformances ());
2821+ auto conformances = getOpConformances (Inst->getConformances ());
28422822
28432823 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
28442824 recordClonedInstruction (
0 commit comments