Skip to content

[5.9] MoveOnlyChecker: Look through convert_function of nonescaping closures. #66823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,11 @@ static bool findNonEscapingPartialApplyUses(PartialApplyInst *pai,
//
// We have this separately from the other look through sections so that
// we can make it clearer what we are doing here.
isa<PartialApplyInst>(user)) {
isa<PartialApplyInst>(user) ||
// Likewise with convert_function. Any valid function conversion that
// doesn't prevent stack promotion of the closure must retain the
// invariants on its transitive uses.
isa<ConvertFunctionInst>(user)) {
for (auto *use : cast<SingleValueInstruction>(user)->getUses())
worklist.push_back(use);
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-swift-frontend -emit-sil -verify %s

// rdar://111060678

protocol P {
func doStuff() throws
}

struct A: ~Copyable {
let b = B()

consuming func f(_ p: some P) throws -> B {
// Passing the closure here undergoes a SIL-level function conversion
// from the concrete type `() -> Void` to `<T> () throws -> T`.
try b.takeClosure {
try b.takeP(p)
}
return B()
}
}

struct B {
func takeClosure<T>(_ f: () throws -> T) throws -> T { try f() }
func takeP(_: some P) throws {}
}