@@ -4047,29 +4047,33 @@ void SILGenFunction::emitOpenExistentialExprImpl(
4047
4047
llvm::function_ref<void (Expr *)> emitSubExpr) {
4048
4048
Optional<FormalEvaluationScope> writebackScope;
4049
4049
4050
+ Type opaqueValueType = E->getOpaqueValue ()->getType ()->getRValueType ();
4051
+
4050
4052
// Emit the existential value.
4051
- ManagedValue existentialValue;
4053
+ SILGenFunction::OpaqueValueState state;
4054
+
4052
4055
AccessKind accessKind;
4053
4056
if (E->getExistentialValue ()->getType ()->is <LValueType>()) {
4054
4057
// Create a writeback scope for the access to the existential lvalue.
4055
4058
writebackScope.emplace (*this );
4056
4059
4057
4060
accessKind = E->getExistentialValue ()->getLValueAccessKind ();
4058
- existentialValue = emitAddressOfLValue (
4059
- E->getExistentialValue (),
4060
- emitLValue (E->getExistentialValue (), accessKind),
4061
- accessKind);
4061
+ auto lv = emitLValue (E->getExistentialValue (), accessKind);
4062
+ lv = emitOpenExistentialLValue (E, std::move (lv),
4063
+ CanArchetypeType (E->getOpenedArchetype ()),
4064
+ accessKind);
4065
+ auto addr = emitAddressOfLValue (E, std::move (lv), accessKind);
4066
+ state = {addr, false , false };
4062
4067
} else {
4063
4068
accessKind = AccessKind::Read;
4064
- existentialValue = emitRValueAsSingleValue (
4065
- E->getExistentialValue (),
4066
- SGFContext::AllowGuaranteedPlusZero);
4067
- }
4069
+ auto existentialValue = emitRValueAsSingleValue (
4070
+ E->getExistentialValue (),
4071
+ SGFContext::AllowGuaranteedPlusZero);
4068
4072
4069
- Type opaqueValueType = E->getOpaqueValue ()->getType ()->getRValueType ();
4070
- SILGenFunction::OpaqueValueState state = emitOpenExistential (
4073
+ state = emitOpenExistential (
4071
4074
E, existentialValue, E->getOpenedArchetype (),
4072
4075
getLoweredType (opaqueValueType), accessKind);
4076
+ }
4073
4077
4074
4078
// Register the opaque value for the projected existential.
4075
4079
SILGenFunction::OpaqueValueRAII opaqueValueRAII (
0 commit comments