Skip to content

Commit 5c3ad65

Browse files
slavapestovrjmccall
authored andcommitted
SILGen: Use emitOpenExistentialLValue() when lowering OpenExistentialExprs with lvalue base
1 parent ebdef55 commit 5c3ad65

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,29 +4010,33 @@ void SILGenFunction::emitOpenExistentialExprImpl(
40104010
llvm::function_ref<void(Expr *)> emitSubExpr) {
40114011
Optional<FormalEvaluationScope> writebackScope;
40124012

4013+
Type opaqueValueType = E->getOpaqueValue()->getType()->getRValueType();
4014+
40134015
// Emit the existential value.
4014-
ManagedValue existentialValue;
4016+
SILGenFunction::OpaqueValueState state;
4017+
40154018
AccessKind accessKind;
40164019
if (E->getExistentialValue()->getType()->is<LValueType>()) {
40174020
// Create a writeback scope for the access to the existential lvalue.
40184021
writebackScope.emplace(*this);
40194022

40204023
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};
40254030
} else {
40264031
accessKind = AccessKind::Read;
4027-
existentialValue = emitRValueAsSingleValue(
4028-
E->getExistentialValue(),
4029-
SGFContext::AllowGuaranteedPlusZero);
4030-
}
4032+
auto existentialValue = emitRValueAsSingleValue(
4033+
E->getExistentialValue(),
4034+
SGFContext::AllowGuaranteedPlusZero);
40314035

4032-
Type opaqueValueType = E->getOpaqueValue()->getType()->getRValueType();
4033-
SILGenFunction::OpaqueValueState state = emitOpenExistential(
4036+
state = emitOpenExistential(
40344037
E, existentialValue, E->getOpenedArchetype(),
40354038
getLoweredType(opaqueValueType), accessKind);
4039+
}
40364040

40374041
// Register the opaque value for the projected existential.
40384042
SILGenFunction::OpaqueValueRAII opaqueValueRAII(

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
975975
/// \param openedArchetype The opened existential archetype.
976976
/// \param loweredOpenedType The lowered type of the projection, which in
977977
/// practice will be the openedArchetype, possibly wrapped in a metatype.
978-
SILGenFunction::OpaqueValueState
978+
OpaqueValueState
979979
emitOpenExistential(SILLocation loc,
980980
ManagedValue existentialValue,
981981
ArchetypeType *openedArchetype,

0 commit comments

Comments
 (0)