@@ -591,10 +591,26 @@ namespace {
591
591
" base for open existential component must be an existential" );
592
592
assert (base.getType ().isAddress () &&
593
593
" base value of open-existential component was not an address?" );
594
+ SILValue addr;
594
595
595
- SILValue addr = SGF.B .createOpenExistentialAddr (
596
+ auto rep = base.getType ().getPreferredExistentialRepresentation (SGF.SGM .M );
597
+ switch (rep) {
598
+ case ExistentialRepresentation::Opaque:
599
+ addr = SGF.B .createOpenExistentialAddr (
596
600
loc, base.getValue (), getTypeOfRValue ().getAddressType (),
597
601
getOpenedExistentialAccessFor (accessKind));
602
+ break ;
603
+ case ExistentialRepresentation::Boxed: {
604
+ auto &TL = SGF.getTypeLowering (base.getType ());
605
+ auto error = SGF.emitLoad (loc, base.getValue (), TL,
606
+ SGFContext (), IsNotTake);
607
+ addr = SGF.B .createOpenExistentialBox (
608
+ loc, error.getValue (), getTypeOfRValue ().getAddressType ());
609
+ break ;
610
+ }
611
+ default :
612
+ llvm_unreachable (" Bad existential representation for address-only type" );
613
+ }
598
614
599
615
SGF.setArchetypeOpeningSite (cast<ArchetypeType>(getSubstFormalType ()),
600
616
addr);
@@ -1999,9 +2015,11 @@ LValue SILGenLValue::visitOpaqueValueExpr(OpaqueValueExpr *e,
1999
2015
openedExistentials.erase (known);
2000
2016
2001
2017
// Do formal evaluation of the underlying existential lvalue.
2002
- LValue lv = visitRec (opened->getExistentialValue (), accessKind);
2003
- lv.add <OpenOpaqueExistentialComponent>(
2004
- cast<ArchetypeType>(opened->getOpenedArchetype ()->getCanonicalType ()));
2018
+ auto lv = visitRec (opened->getExistentialValue (), accessKind);
2019
+ lv = SGF.emitOpenExistentialLValue (
2020
+ opened, std::move (lv),
2021
+ CanArchetypeType (opened->getOpenedArchetype ()),
2022
+ accessKind);
2005
2023
return lv;
2006
2024
}
2007
2025
@@ -2907,7 +2925,8 @@ SILGenFunction::emitOpenExistentialLValue(SILLocation loc,
2907
2925
auto rep = lv.getTypeOfRValue ()
2908
2926
.getPreferredExistentialRepresentation (SGM.M );
2909
2927
switch (rep) {
2910
- case ExistentialRepresentation::Opaque: {
2928
+ case ExistentialRepresentation::Opaque:
2929
+ case ExistentialRepresentation::Boxed: {
2911
2930
lv.add <OpenOpaqueExistentialComponent>(openedArchetype);
2912
2931
break ;
2913
2932
}
0 commit comments