Skip to content

Commit 9d5b175

Browse files
Merge pull request #67846 from nate-chandler/nfc/20230809/1/silgen-closure-simplification
[SILGen] Remove subtle identity function call.
2 parents c6387fd + 368536c commit 9d5b175

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -797,18 +797,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
797797
case CaptureKind::Box: {
798798
assert(!isPack);
799799

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!");
804802
// Boxes of opaque return values stay opaque.
805803
auto minimalLoweredType = SGM.Types.getLoweredRValueType(
806804
TypeExpansionContext::minimal(), type->getCanonicalType());
807805
// If this is a boxed variable, we can use it directly.
808806
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) {
812808
auto box = ManagedValue::forBorrowedObjectRValue(Entry.box);
813809
// We can guarantee our own box to the callee.
814810
if (canGuarantee) {
@@ -817,6 +813,8 @@ void SILGenFunction::emitCaptures(SILLocation loc,
817813
box = box.copy(*this, loc);
818814
}
819815

816+
// If our captured value is a box with a moveonlywrapped type inside,
817+
// unwrap it.
820818
if (box.getType().isBoxedMoveOnlyWrappedType(&F)) {
821819
CleanupCloner cloner(*this, box);
822820
box = cloner.clone(
@@ -826,7 +824,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
826824
capturedArgs.push_back(box);
827825

828826
if (captureCanEscape)
829-
escapesToMark.push_back(entryValue);
827+
escapesToMark.push_back(val);
830828
} else {
831829
// Address only 'let' values are passed by box. This isn't great, in
832830
// that a variable captured by multiple closures will be boxed for each
@@ -840,12 +838,13 @@ void SILGenFunction::emitCaptures(SILLocation loc,
840838
// in-place.
841839
// TODO: Use immutable box for immutable captures.
842840
auto boxTy = SGM.Types.getContextBoxTypeForCapture(
843-
vd, minimalLoweredType, FunctionDC->getGenericEnvironmentOfContext(),
841+
vd, minimalLoweredType,
842+
FunctionDC->getGenericEnvironmentOfContext(),
844843
/*mutable*/ true);
845844

846845
AllocBoxInst *allocBox = B.createAllocBox(loc, boxTy);
847846
ProjectBoxInst *boxAddress = B.createProjectBox(loc, allocBox, 0);
848-
B.createCopyAddr(loc, entryValue, boxAddress, IsNotTake,
847+
B.createCopyAddr(loc, val, boxAddress, IsNotTake,
849848
IsInitialization);
850849
if (canGuarantee)
851850
capturedArgs.push_back(
@@ -859,17 +858,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
859858
case CaptureKind::ImmutableBox: {
860859
assert(!isPack);
861860

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() &&
866862
"no address for captured var!");
867863
// Boxes of opaque return values stay opaque.
868864
auto minimalLoweredType = SGM.Types.getLoweredRValueType(
869865
TypeExpansionContext::minimal(), type->getCanonicalType());
870866
// If this is a boxed variable, we can use it directly.
871867
if (Entry.box &&
872-
entryValue->getType().getASTType() == minimalLoweredType) {
868+
val->getType().getASTType() == minimalLoweredType) {
873869
// We can guarantee our own box to the callee.
874870
if (canGuarantee) {
875871
capturedArgs.push_back(
@@ -878,7 +874,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
878874
capturedArgs.push_back(emitManagedRetain(loc, Entry.box));
879875
}
880876
if (captureCanEscape)
881-
escapesToMark.push_back(entryValue);
877+
escapesToMark.push_back(val);
882878
} else {
883879
// Address only 'let' values are passed by box. This isn't great, in
884880
// that a variable captured by multiple closures will be boxed for each
@@ -898,7 +894,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
898894

899895
AllocBoxInst *allocBox = B.createAllocBox(loc, boxTy);
900896
ProjectBoxInst *boxAddress = B.createProjectBox(loc, allocBox, 0);
901-
B.createCopyAddr(loc, entryValue, boxAddress, IsNotTake,
897+
B.createCopyAddr(loc, val, boxAddress, IsNotTake,
902898
IsInitialization);
903899
if (canGuarantee)
904900
capturedArgs.push_back(

0 commit comments

Comments
 (0)