@@ -797,18 +797,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
797
797
case CaptureKind::Box: {
798
798
assert (!isPack);
799
799
800
- auto entryValue = getAddressValue (val, /* forceCopy=*/ false );
801
- // LValues are captured as both the box owning the value and the
802
- // address of the value.
803
- assert (entryValue->getType ().isAddress () && " no address for captured var!" );
800
+ assert (val->getType ().isAddress () &&
801
+ " no address for captured var!" );
804
802
// Boxes of opaque return values stay opaque.
805
803
auto minimalLoweredType = SGM.Types .getLoweredRValueType (
806
804
TypeExpansionContext::minimal (), type->getCanonicalType ());
807
805
// If this is a boxed variable, we can use it directly.
808
806
if (Entry.box &&
809
- entryValue->getType ().getASTType () == minimalLoweredType) {
810
- // If our captured value is a box with a moveonlywrapped type inside,
811
- // unwrap it.
807
+ val->getType ().getASTType () == minimalLoweredType) {
812
808
auto box = ManagedValue::forBorrowedObjectRValue (Entry.box );
813
809
// We can guarantee our own box to the callee.
814
810
if (canGuarantee) {
@@ -817,6 +813,8 @@ void SILGenFunction::emitCaptures(SILLocation loc,
817
813
box = box.copy (*this , loc);
818
814
}
819
815
816
+ // If our captured value is a box with a moveonlywrapped type inside,
817
+ // unwrap it.
820
818
if (box.getType ().isBoxedMoveOnlyWrappedType (&F)) {
821
819
CleanupCloner cloner (*this , box);
822
820
box = cloner.clone (
@@ -826,7 +824,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
826
824
capturedArgs.push_back (box);
827
825
828
826
if (captureCanEscape)
829
- escapesToMark.push_back (entryValue );
827
+ escapesToMark.push_back (val );
830
828
} else {
831
829
// Address only 'let' values are passed by box. This isn't great, in
832
830
// that a variable captured by multiple closures will be boxed for each
@@ -840,12 +838,13 @@ void SILGenFunction::emitCaptures(SILLocation loc,
840
838
// in-place.
841
839
// TODO: Use immutable box for immutable captures.
842
840
auto boxTy = SGM.Types .getContextBoxTypeForCapture (
843
- vd, minimalLoweredType, FunctionDC->getGenericEnvironmentOfContext (),
841
+ vd, minimalLoweredType,
842
+ FunctionDC->getGenericEnvironmentOfContext (),
844
843
/* mutable*/ true );
845
844
846
845
AllocBoxInst *allocBox = B.createAllocBox (loc, boxTy);
847
846
ProjectBoxInst *boxAddress = B.createProjectBox (loc, allocBox, 0 );
848
- B.createCopyAddr (loc, entryValue , boxAddress, IsNotTake,
847
+ B.createCopyAddr (loc, val , boxAddress, IsNotTake,
849
848
IsInitialization);
850
849
if (canGuarantee)
851
850
capturedArgs.push_back (
@@ -859,17 +858,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
859
858
case CaptureKind::ImmutableBox: {
860
859
assert (!isPack);
861
860
862
- auto entryValue = getAddressValue (val, /* forceCopy=*/ false );
863
- // LValues are captured as both the box owning the value and the
864
- // address of the value.
865
- assert (entryValue->getType ().isAddress () &&
861
+ assert (val->getType ().isAddress () &&
866
862
" no address for captured var!" );
867
863
// Boxes of opaque return values stay opaque.
868
864
auto minimalLoweredType = SGM.Types .getLoweredRValueType (
869
865
TypeExpansionContext::minimal (), type->getCanonicalType ());
870
866
// If this is a boxed variable, we can use it directly.
871
867
if (Entry.box &&
872
- entryValue ->getType ().getASTType () == minimalLoweredType) {
868
+ val ->getType ().getASTType () == minimalLoweredType) {
873
869
// We can guarantee our own box to the callee.
874
870
if (canGuarantee) {
875
871
capturedArgs.push_back (
@@ -878,7 +874,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
878
874
capturedArgs.push_back (emitManagedRetain (loc, Entry.box ));
879
875
}
880
876
if (captureCanEscape)
881
- escapesToMark.push_back (entryValue );
877
+ escapesToMark.push_back (val );
882
878
} else {
883
879
// Address only 'let' values are passed by box. This isn't great, in
884
880
// that a variable captured by multiple closures will be boxed for each
@@ -898,7 +894,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
898
894
899
895
AllocBoxInst *allocBox = B.createAllocBox (loc, boxTy);
900
896
ProjectBoxInst *boxAddress = B.createProjectBox (loc, allocBox, 0 );
901
- B.createCopyAddr (loc, entryValue , boxAddress, IsNotTake,
897
+ B.createCopyAddr (loc, val , boxAddress, IsNotTake,
902
898
IsInitialization);
903
899
if (canGuarantee)
904
900
capturedArgs.push_back (
0 commit comments