Skip to content

Commit 9904d6c

Browse files
committed
SILGen: Establish an addressability scope for closure captures.
This allows a captured variable to serve as the root of an addressable dependency. Fixes the compiler crash in rdar://150479326.
1 parent 7387f85 commit 9904d6c

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,8 @@ SILGenFunction::getLocalVariableAddressableBuffer(VarDecl *decl,
25422542
SILValue reabstraction, allocStack, storeBorrow;
25432543
{
25442544
SavedInsertionPointRAII save(B);
2545+
ASSERT(AddressableBuffers.find(decl) != AddressableBuffers.end()
2546+
&& "local variable did not have an addressability scope set");
25452547
auto insertPoint = AddressableBuffers[decl].insertPoint;
25462548
B.setInsertionPoint(insertPoint);
25472549
auto allocStackTy = fullyAbstractedTy;

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
543543

544544
PreparedAddressableBuffer(SILInstruction *insertPoint)
545545
: insertPoint(insertPoint)
546-
{}
546+
{
547+
ASSERT(insertPoint && "null insertion point provided");
548+
}
547549

548550
PreparedAddressableBuffer(PreparedAddressableBuffer &&other)
549551
: insertPoint(other.insertPoint)

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ static void emitCaptureArguments(SILGenFunction &SGF,
14061406
}
14071407

14081408
SGF.VarLocs[VD] = SILGenFunction::VarLoc(arg, enforcement, box);
1409+
SGF.enterLocalVariableAddressableBufferScope(VD);
14091410
SILDebugVariable DbgVar(VD->isLet(), ArgNo);
14101411
if (auto *AllocStack = dyn_cast<AllocStackInst>(arg)) {
14111412
AllocStack->setArgNo(ArgNo);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-emit-silgen -verify -enable-experimental-feature LifetimeDependence -enable-experimental-feature AddressableTypes %s
2+
3+
// REQUIRES: swift_feature_LifetimeDependence
4+
// REQUIRES: swift_feature_AddressableTypes
5+
6+
@_addressableForDependencies
7+
struct Owner {
8+
@lifetime(borrow self)
9+
func reference() -> Reference { fatalError() }
10+
}
11+
12+
struct Reference: ~Escapable {
13+
@lifetime(immortal)
14+
init() { fatalError() }
15+
16+
func use() {}
17+
}
18+
19+
func closure(_: () -> Void) {}
20+
21+
func dependencyThroughClosure(from owner: borrowing Owner) {
22+
closure { owner.reference().use() }
23+
}

test/Sema/Inputs/lifetime_depend_infer.swiftinterface

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,12 @@ public struct NoncopyableSelfAccessors : ~Copyable & ~Escapable {
253253
_modify
254254
}
255255

256-
// FIXME: rdar://150073405 ([SILGen] support synthesized _modify on top of borrowed getters with library evolution)
257-
/*
258256
public var neComputedBorrow: lifetime_depend_infer.NE {
259257
@lifetime(borrow self)
260258
get
261259
@lifetime(&self)
262260
set
263261
}
264-
*/
265262

266263
public var neYieldedBorrow: lifetime_depend_infer.NE {
267264
@lifetime(borrow self)

0 commit comments

Comments
 (0)