@@ -4010,29 +4010,33 @@ void SILGenFunction::emitOpenExistentialExprImpl(
4010
4010
llvm::function_ref<void (Expr *)> emitSubExpr) {
4011
4011
Optional<FormalEvaluationScope> writebackScope;
4012
4012
4013
+ Type opaqueValueType = E->getOpaqueValue ()->getType ()->getRValueType ();
4014
+
4013
4015
// Emit the existential value.
4014
- ManagedValue existentialValue;
4016
+ SILGenFunction::OpaqueValueState state;
4017
+
4015
4018
AccessKind accessKind;
4016
4019
if (E->getExistentialValue ()->getType ()->is <LValueType>()) {
4017
4020
// Create a writeback scope for the access to the existential lvalue.
4018
4021
writebackScope.emplace (*this );
4019
4022
4020
4023
accessKind = E->getExistentialValue ()->getLValueAccessKind ();
4021
- existentialValue = emitAddressOfLValue (
4022
- E->getExistentialValue (),
4023
- emitLValue (E->getExistentialValue (), accessKind),
4024
- accessKind);
4024
+ auto lv = emitLValue (E->getExistentialValue (), accessKind);
4025
+ lv = emitOpenExistentialLValue (E, std::move (lv),
4026
+ CanArchetypeType (E->getOpenedArchetype ()),
4027
+ accessKind);
4028
+ auto addr = emitAddressOfLValue (E, std::move (lv), accessKind);
4029
+ state = {addr, false , false };
4025
4030
} else {
4026
4031
accessKind = AccessKind::Read;
4027
- existentialValue = emitRValueAsSingleValue (
4028
- E->getExistentialValue (),
4029
- SGFContext::AllowGuaranteedPlusZero);
4030
- }
4032
+ auto existentialValue = emitRValueAsSingleValue (
4033
+ E->getExistentialValue (),
4034
+ SGFContext::AllowGuaranteedPlusZero);
4031
4035
4032
- Type opaqueValueType = E->getOpaqueValue ()->getType ()->getRValueType ();
4033
- SILGenFunction::OpaqueValueState state = emitOpenExistential (
4036
+ state = emitOpenExistential (
4034
4037
E, existentialValue, E->getOpenedArchetype (),
4035
4038
getLoweredType (opaqueValueType), accessKind);
4039
+ }
4036
4040
4037
4041
// Register the opaque value for the projected existential.
4038
4042
SILGenFunction::OpaqueValueRAII opaqueValueRAII (
0 commit comments