Skip to content

Commit 368536c

Browse files
committed
[SILGen] Remove subtle identity function call.
Back in 33f4f57 of #28044 fame, non-`CaptureKind::Constant:` uses of `Entry.val` in `SILGenFunction::emitCaptures` were replaced with a use of the newly added lambda `getAddressValue` applied at `Entry.val`. The replacement of `Entry.value` with `getAddressValue(Entry.value)` in the case of `CaptureKind::Box` had no effect. Back then, the reason was that the condition SGM.Types .getTypeLowering( valueType, TypeExpansionContext::noOpaqueTypeArchetypesSubstitution( expansion.getResilienceExpansion())) .isAddressOnly() && !entryValue->getType().isAddress() under which something other than the input was returned would never hold: CaptureKind::Box is used for LValues and those never satisfy `!entryValue->getType().isAddress()`. Since that PR, the getAddressValue lambda has grown. There are two additional aspects to consider: (1) forceCopy, (2) isPack. (1) is not relevant because `false` was being passed for the `CaptureKind::Box` case. (2) can not currently happen because pack lvalues haven't been implemented. But even if they were implemented, the argument passed to the lambda would still need to be an address. The same all holds for the `CaptureKind::ImmutableBox` case which only differs from the `CaptureKind::Box` by a couple of lines.
1 parent e894a34 commit 368536c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
795795
case CaptureKind::Box: {
796796
assert(!isPack);
797797

798-
auto entryValue = getAddressValue(val, /*forceCopy=*/false);
799-
assert(entryValue->getType().isAddress() &&
798+
assert(val->getType().isAddress() &&
800799
"no address for captured var!");
801800
// Boxes of opaque return values stay opaque.
802801
auto minimalLoweredType = SGM.Types.getLoweredRValueType(
803802
TypeExpansionContext::minimal(), type->getCanonicalType());
804803
// If this is a boxed variable, we can use it directly.
805804
if (Entry.box &&
806-
entryValue->getType().getASTType() == minimalLoweredType) {
805+
val->getType().getASTType() == minimalLoweredType) {
807806
auto box = ManagedValue::forBorrowedObjectRValue(Entry.box);
808807
// We can guarantee our own box to the callee.
809808
if (canGuarantee) {
@@ -823,7 +822,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
823822
capturedArgs.push_back(box);
824823

825824
if (captureCanEscape)
826-
escapesToMark.push_back(entryValue);
825+
escapesToMark.push_back(val);
827826
} else {
828827
// Address only 'let' values are passed by box. This isn't great, in
829828
// that a variable captured by multiple closures will be boxed for each
@@ -843,7 +842,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
843842

844843
AllocBoxInst *allocBox = B.createAllocBox(loc, boxTy);
845844
ProjectBoxInst *boxAddress = B.createProjectBox(loc, allocBox, 0);
846-
B.createCopyAddr(loc, entryValue, boxAddress, IsNotTake,
845+
B.createCopyAddr(loc, val, boxAddress, IsNotTake,
847846
IsInitialization);
848847
if (canGuarantee)
849848
capturedArgs.push_back(
@@ -857,15 +856,14 @@ void SILGenFunction::emitCaptures(SILLocation loc,
857856
case CaptureKind::ImmutableBox: {
858857
assert(!isPack);
859858

860-
auto entryValue = getAddressValue(val, /*forceCopy=*/false);
861-
assert(entryValue->getType().isAddress() &&
859+
assert(val->getType().isAddress() &&
862860
"no address for captured var!");
863861
// Boxes of opaque return values stay opaque.
864862
auto minimalLoweredType = SGM.Types.getLoweredRValueType(
865863
TypeExpansionContext::minimal(), type->getCanonicalType());
866864
// If this is a boxed variable, we can use it directly.
867865
if (Entry.box &&
868-
entryValue->getType().getASTType() == minimalLoweredType) {
866+
val->getType().getASTType() == minimalLoweredType) {
869867
// We can guarantee our own box to the callee.
870868
if (canGuarantee) {
871869
capturedArgs.push_back(
@@ -874,7 +872,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
874872
capturedArgs.push_back(emitManagedRetain(loc, Entry.box));
875873
}
876874
if (captureCanEscape)
877-
escapesToMark.push_back(entryValue);
875+
escapesToMark.push_back(val);
878876
} else {
879877
// Address only 'let' values are passed by box. This isn't great, in
880878
// that a variable captured by multiple closures will be boxed for each
@@ -894,7 +892,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
894892

895893
AllocBoxInst *allocBox = B.createAllocBox(loc, boxTy);
896894
ProjectBoxInst *boxAddress = B.createProjectBox(loc, allocBox, 0);
897-
B.createCopyAddr(loc, entryValue, boxAddress, IsNotTake,
895+
B.createCopyAddr(loc, val, boxAddress, IsNotTake,
898896
IsInitialization);
899897
if (canGuarantee)
900898
capturedArgs.push_back(

0 commit comments

Comments
 (0)