Skip to content

Commit 5908d42

Browse files
authored
Merge pull request #71903 from jckarter/borrowing-switch-load-borrow-elimination-barrier
MoveOnlyAddressChecker: Treat opaque accesses consistently in CopiedLoadBorrowEliminationVisitor.
2 parents ccc6b2b + d671f2a commit 5908d42

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,7 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
17261726
// Begin a new binding scope, which is popped when the next innermost debug
17271727
// scope ends. The cleanup location loc isn't the perfect source location
17281728
// but it's close enough.
1729-
B.getSILGenFunction().enterDebugScope(loc,
1730-
/*isBindingScope=*/true);
1729+
B.getSILGenFunction().enterDebugScope(loc, /*isBindingScope=*/true);
17311730
InitializationPtr initialization =
17321731
emitPatternBindingInitialization(elt.getPattern(), FalseDest);
17331732

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,19 @@ struct CopiedLoadBorrowEliminationState {
15731573
}
15741574
};
15751575

1576+
static bool shouldVisitAsEndPointUse(Operand *op) {
1577+
// If an access is static and marked as "no nested conflict", we use that
1578+
// in switch codegen to mark an opaque sub-access that move-only checking
1579+
// should not look through.
1580+
if (auto ba = dyn_cast<BeginAccessInst>(op->getUser())) {
1581+
if (ba->getEnforcement() == SILAccessEnforcement::Static
1582+
&& ba->hasNoNestedConflict()) {
1583+
return true;
1584+
}
1585+
}
1586+
return false;
1587+
}
1588+
15761589
/// An early transform that we run to convert any load_borrow that are copied
15771590
/// directly or that have any subelement that is copied to a load [copy]. This
15781591
/// lets the rest of the optimization handle these as appropriate.
@@ -1583,6 +1596,10 @@ struct CopiedLoadBorrowEliminationVisitor
15831596
CopiedLoadBorrowEliminationVisitor(CopiedLoadBorrowEliminationState &state)
15841597
: state(state) {}
15851598

1599+
bool visitTransitiveUseAsEndPointUse(Operand *op) {
1600+
return shouldVisitAsEndPointUse(op);
1601+
}
1602+
15861603
bool visitUse(Operand *op) {
15871604
LLVM_DEBUG(llvm::dbgs() << "CopiedLBElim visiting ";
15881605
llvm::dbgs() << " User: " << *op->getUser());
@@ -1978,16 +1995,7 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
19781995
} // end anonymous namespace
19791996

19801997
bool GatherUsesVisitor::visitTransitiveUseAsEndPointUse(Operand *op) {
1981-
// If an access is static and marked as "no nested conflict", we use that
1982-
// in switch codegen to mark an opaque sub-access that move-only checking
1983-
// should not look through.
1984-
if (auto ba = dyn_cast<BeginAccessInst>(op->getUser())) {
1985-
if (ba->getEnforcement() == SILAccessEnforcement::Static
1986-
&& ba->hasNoNestedConflict()) {
1987-
return true;
1988-
}
1989-
}
1990-
return false;
1998+
return shouldVisitAsEndPointUse(op);
19911999
}
19922000

19932001
// Filter out recognized uses that do not write to memory.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -enable-experimental-feature BorrowingSwitch -enable-experimental-feature NoncopyableGenerics -emit-sil -verify %s
2+
3+
struct Box<Wrapped: ~Copyable>: ~Copyable {
4+
init(_ element: consuming Wrapped) { }
5+
}
6+
7+
struct Tree<Element>: ~Copyable {
8+
struct Node: ~Copyable { }
9+
10+
enum Branch: ~Copyable {
11+
case empty
12+
case more(Box<Node>)
13+
}
14+
var root: Branch = .empty
15+
}
16+
17+
extension Tree {
18+
mutating func insert(_ element: consuming Element) {
19+
root =
20+
switch root {
21+
case .empty:
22+
.more(Box(Node()))
23+
case .more:
24+
fatalError()
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)