@@ -2773,12 +2773,13 @@ static SILValue emitMetatypeOfDelegatingInitExclusivelyBorrowedSelf(
2773
2773
auto *vd = cast<ParamDecl>(dre->getDecl ());
2774
2774
ManagedValue selfValue;
2775
2775
2776
+ Scope S (SGF, loc);
2777
+ Optional<FormalEvaluationScope> FES;
2776
2778
// If we have not exclusively borrowed self, we need to do so now.
2777
2779
if (SGF.SelfInitDelegationState == SILGenFunction::WillExclusiveBorrowSelf) {
2778
2780
// We need to use a full scope here to ensure that any underlying
2779
2781
// "normal cleanup" borrows are cleaned up.
2780
- Scope S (SGF, loc);
2781
- selfValue = S.popPreservingValue (SGF.emitRValueAsSingleValue (dre));
2782
+ selfValue = SGF.emitRValueAsSingleValue (dre);
2782
2783
} else {
2783
2784
// If we already exclusively borrowed self, then we need to emit self
2784
2785
// using formal evaluation primitives.
@@ -2788,6 +2789,7 @@ static SILValue emitMetatypeOfDelegatingInitExclusivelyBorrowedSelf(
2788
2789
// This needs to be inlined since there is a Formal Evaluation Scope
2789
2790
// in emitRValueForDecl that causing any borrow for this LValue to be
2790
2791
// popped too soon.
2792
+ FES.emplace (SGF);
2791
2793
selfValue =
2792
2794
SGF.emitLValueForDecl (dre, vd, dre->getType ()->getCanonicalType (),
2793
2795
AccessKind::Read, dre->getAccessSemantics ());
@@ -2796,9 +2798,7 @@ static SILValue emitMetatypeOfDelegatingInitExclusivelyBorrowedSelf(
2796
2798
selfValue.getLValueAddress (), ctx)
2797
2799
.getAsSingleValue (SGF, loc);
2798
2800
}
2799
- assert (selfValue && !selfValue.hasCleanup ());
2800
2801
2801
- // Check if we need to perform a conversion here.
2802
2802
return SGF.B .createValueMetatype (loc, metaTy, selfValue.getValue ());
2803
2803
}
2804
2804
@@ -2814,7 +2814,6 @@ SILValue SILGenFunction::emitMetatypeOfValue(SILLocation loc, Expr *baseExpr) {
2814
2814
SGFContext::AllowImmediatePlusZero).getValue ();
2815
2815
return B.createExistentialMetatype (loc, metaTy, base);
2816
2816
}
2817
-
2818
2817
SILType metaTy = getLoweredLoadableType (CanMetatypeType::get (baseTy));
2819
2818
// If the lowered metatype has a thick representation, we need to derive it
2820
2819
// dynamically from the instance.
@@ -2836,7 +2835,6 @@ SILValue SILGenFunction::emitMetatypeOfValue(SILLocation loc, Expr *baseExpr) {
2836
2835
return S.popPreservingValue (B.createValueMetatype (loc, metaTy, base))
2837
2836
.getValue ();
2838
2837
}
2839
-
2840
2838
// Otherwise, ignore the base and return the static thin metatype.
2841
2839
emitIgnoredExpr (baseExpr);
2842
2840
return B.createMetatype (loc, metaTy);
0 commit comments