Skip to content

[CSSimplify] Allow conversion from caller isolated to parameter isola… #80329

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
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
15 changes: 15 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,21 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
SmallVector<AnyFunctionType::Param, 8> func2Params;
func2Params.append(func2->getParams().begin(), func2->getParams().end());

// Support conversion from `@execution(caller)` to a function type
// with an isolated parameter.
if (subKind == ConstraintKind::Subtype &&
func1->getIsolation().isNonIsolatedCaller() &&
func2->getIsolation().isParameter()) {
// `@execution(caller)` function gets an implicit isolation parameter
// introduced during SILGen and thunk is going to forward an isolation
// from the caller to it.
// Let's remove the isolated parameter from consideration, function
// types have to match on everything else.
llvm::erase_if(func2Params, [](const AnyFunctionType::Param &param) {
return param.isIsolated();
});
}

// Add a very narrow exception to SE-0110 by allowing functions that
// take multiple arguments to be passed as an argument in places
// that expect a function that takes a single tuple (of the same
Expand Down
17 changes: 16 additions & 1 deletion test/Concurrency/attr_execution/conversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,26 @@ func testUpcast(arr: [@execution(caller) () async -> Void]) {
}

// Isolated parameter
func testParameterIsolation(fn: @escaping (isolated (any Actor)?) async -> Void) {
func testParameterIsolation(fn: @escaping (isolated (any Actor)?) async -> Void, caller: @escaping @execution(caller) (String) async -> Void) {
let _: @execution(caller) () async -> Void = fn
// expected-error@-1 {{cannot convert value of type '(isolated (any Actor)?) async -> Void' to specified type '@execution(caller) () async -> Void'}}
let _: @execution(concurrent) () async -> Void = fn
// expected-error@-1 {{cannot convert value of type '(isolated (any Actor)?) async -> Void' to specified type '() async -> Void'}}

let _: (isolated (any Actor)?) async -> Void = callerTest // Ok
let _: (isolated (any Actor)?) -> Void = callerTest
// expected-error@-1 {{invalid conversion from 'async' function of type '@execution(caller) () async -> ()' to synchronous function type '(isolated (any Actor)?) -> Void'}}
let _: (isolated (any Actor)?) async -> Void = concurrentTest
// expected-error@-1 {{cannot convert value of type '() async -> ()' to specified type '(isolated (any Actor)?) async -> Void'}}
let _: (isolated (any Actor)?, Int) async -> Void = callerTest
// expected-error@-1 {{cannot convert value of type '@execution(caller) () async -> ()' to specified type '(isolated (any Actor)?, Int) async -> Void'}}

let _: (String, isolated any Actor) async -> Void = caller // Ok
let _: (isolated (any Actor)?, String) async -> Void = caller // Ok

let _: (Int, isolated any Actor) async -> Void = { @execution(caller) x in } // Ok
let _: (Int, isolated any Actor) async -> Void = { @execution(caller) (x: Int) in } // Ok
let _: (isolated any Actor, Int, String) async -> Void = { @execution(caller) (x: Int, _: String) in } // Ok
}

// Non-conversion situations
Expand Down