@@ -463,9 +463,7 @@ ManagedValue SILGenFunction::emitExistentialErasure(
463
463
if (nsErrorType->isExactSuperclassOf (concreteFormalType, nullptr )) {
464
464
ManagedValue nsError = F (SGFContext ());
465
465
if (nsErrorType != concreteFormalType) {
466
- nsError = ManagedValue (B.createUpcast (loc, nsError.getValue (),
467
- getLoweredType (nsErrorType)),
468
- nsError.getCleanup ());
466
+ nsError = B.createUpcast (loc, nsError, getLoweredType (nsErrorType));
469
467
}
470
468
return emitBridgedToNativeError (loc, nsError);
471
469
}
@@ -490,16 +488,15 @@ ManagedValue SILGenFunction::emitExistentialErasure(
490
488
}
491
489
}
492
490
493
- auto nativeError = F (SGFContext ());
491
+ ManagedValue nativeError = F (SGFContext ());
494
492
495
493
FormalEvaluationScope writebackScope (*this );
496
- auto nsError =
497
- emitRValueForPropertyLoad (loc, nativeError, concreteFormalType,
498
- /* super*/ false , nsErrorVar,
499
- nsErrorVarSubstitutions,
500
- AccessSemantics::Ordinary, nsErrorType,
501
- SGFContext ())
502
- .getAsSingleValue (*this , loc);
494
+ ManagedValue nsError =
495
+ emitRValueForPropertyLoad (
496
+ loc, nativeError, concreteFormalType,
497
+ /* super*/ false , nsErrorVar, nsErrorVarSubstitutions,
498
+ AccessSemantics::Ordinary, nsErrorType, SGFContext ())
499
+ .getAsSingleValue (*this , loc);
503
500
504
501
return emitBridgedToNativeError (loc, nsError);
505
502
}
@@ -557,14 +554,11 @@ ManagedValue SILGenFunction::emitExistentialErasure(
557
554
// layering reasons, so perform an unchecked cast down to NSError.
558
555
SILType anyObjectTy =
559
556
potentialNSError.getType ().getAnyOptionalObjectType ();
560
- SILValue nsError = isPresentBB->createPHIArgument (
561
- anyObjectTy, ValueOwnershipKind::Owned);
557
+ ManagedValue nsError = B.createOwnedPHIArgument (anyObjectTy);
562
558
nsError = B.createUncheckedRefCast (loc, nsError,
563
559
getLoweredType (nsErrorType));
564
560
565
- branchArg = emitBridgedToNativeError (loc,
566
- emitManagedRValueWithCleanup (nsError))
567
- .forward (*this );
561
+ branchArg = emitBridgedToNativeError (loc, nsError).forward (*this );
568
562
}
569
563
B.createBranch (loc, contBB, branchArg);
570
564
@@ -616,12 +610,8 @@ ManagedValue SILGenFunction::emitExistentialErasure(
616
610
assert (existentialTL.isLoadable ());
617
611
618
612
ManagedValue sub = F (SGFContext ());
619
- SILValue v = B.createInitExistentialRef (loc,
620
- existentialTL.getLoweredType (),
621
- concreteFormalType,
622
- sub.getValue (),
623
- conformances);
624
- return ManagedValue (v, sub.getCleanup ());
613
+ return B.createInitExistentialRef (loc, existentialTL.getLoweredType (),
614
+ concreteFormalType, sub, conformances);
625
615
}
626
616
case ExistentialRepresentation::Boxed: {
627
617
// Allocate the existential.
@@ -660,13 +650,10 @@ ManagedValue SILGenFunction::emitExistentialErasure(
660
650
ProtocolConformanceRef buf[] = {
661
651
*anyObjectConformance,
662
652
};
663
-
664
- auto asAnyObject = B.createInitExistentialRef (loc,
665
- SILType::getPrimitiveObjectType (anyObjectTy),
666
- concreteFormalType,
667
- concreteValue.getValue (),
668
- getASTContext ().AllocateCopy (buf));
669
- return ManagedValue (asAnyObject, concreteValue.getCleanup ());
653
+
654
+ return B.createInitExistentialRef (
655
+ loc, SILType::getPrimitiveObjectType (anyObjectTy), concreteFormalType,
656
+ concreteValue, getASTContext ().AllocateCopy (buf));
670
657
};
671
658
672
659
auto concreteTLPtr = &concreteTL;
0 commit comments