swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.59k stars 10.36k forks source link

Calling a function with a `isolated any Actor = #isolation` parameter from a non-isolated context crashes the compiler #74358

Open tgoyne opened 5 months ago

tgoyne commented 5 months ago

Description

Calling the nonisolated function gives the expected error "'nil' is not compatible with expected argument type 'any Actor'" (which probably needs to be special-cased to be a more helpful error?), but calling the isolated function crashes the compiler instead.

Reproduction

func nonisolated(_isolation: any Actor = #isolation) {}
func isolated(_isolation: isolated any Actor = #isolation) {}
Task {
    nonisolated() // error: 'nil' is not compatible with expected argument type 'any Actor'
    isolated() // compiler crash
}

Stack dump

0.  Program arguments: /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret foo.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -color-diagnostics -new-driver-path /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name foo -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins
1.  Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
2.  Compiling with effective version 5.10
3.  While evaluating request TypeCheckSourceFileRequest(source_file "foo.swift")
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000105c32cd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105c30f44 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105c332d8 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x00000001806af584 _sigtramp + 56
4  swift-frontend           0x000000010192f060 (anonymous namespace)::ActorIsolationChecker::checkApply(swift::ApplyExpr*) + 1908
5  swift-frontend           0x000000010192bd78 (anonymous namespace)::ActorIsolationChecker::walkToExprPre(swift::Expr*) + 1784
6  swift-frontend           0x0000000101d20218 (anonymous namespace)::Traversal::visit(swift::Stmt*) + 2748
7  swift-frontend           0x0000000101d1d920 (anonymous namespace)::Traversal::visitClosureExpr(swift::ClosureExpr*) + 296
8  swift-frontend           0x0000000101d1ca14 (anonymous namespace)::Traversal::visit(swift::Expr*) + 452
9  swift-frontend           0x0000000101d1d02c (anonymous namespace)::Traversal::visitDynamicMemberRefExpr(swift::DynamicMemberRefExpr*) + 84
10 swift-frontend           0x0000000101d1cb10 (anonymous namespace)::Traversal::visit(swift::Expr*) + 704
11 swift-frontend           0x0000000101d227c4 (anonymous namespace)::Traversal::visit(swift::ArgumentList*) + 288
12 swift-frontend           0x0000000101d1f384 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 196
13 swift-frontend           0x0000000101d1c8a8 (anonymous namespace)::Traversal::visit(swift::Expr*) + 88
14 swift-frontend           0x0000000101d20120 (anonymous namespace)::Traversal::visit(swift::Stmt*) + 2500
15 swift-frontend           0x000000010191fd3c swift::checkTopLevelActorIsolation(swift::TopLevelCodeDecl*) + 344
16 swift-frontend           0x0000000101a2e4dc swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 256
17 swift-frontend           0x0000000101a7ba08 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 696
18 swift-frontend           0x0000000101a83098 swift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()>(swift::TypeCheckSourceFileRequest const&, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()) + 616
19 swift-frontend           0x0000000101a7b734 swift::performTypeChecking(swift::SourceFile&) + 328
20 swift-frontend           0x00000001009d3ca8 swift::CompilerInstance::performSema() + 332
21 swift-frontend           0x0000000100612280 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 40
22 swift-frontend           0x0000000100601938 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2904
23 swift-frontend           0x00000001005ff438 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4752
24 swift-frontend           0x00000001005852d8 swift::mainEntry(int, char const**) + 2812
25 dyld                     0x00000001802f60e0 start + 2360
[1]    4157 segmentation fault  DEVELOPER_DIR=/Applications/Xcode-16.0.0-beta.app swift foo.swift

Expected behavior

A helpful error message (or at least a not very helpful error message like the nonisolated case).

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Target: arm64-apple-macosx14.0

Additional information

No response

Nelyus commented 5 days ago

I got a very similar issue today


0.  Program arguments: /Applications/Xcode-16.1.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend […]
1.  Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
2.  Compiling with effective version 5.10
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/pmb/Projets/lacaisse/working/LCAKit/Sources/LCAEpson/EpsonPrinterInfo.swift")
4.  While evaluating request TypeCheckFunctionBodyRequest(LCAEpson.(file).EpsonPrinterInfo.connect(complete:)@/Users/pmb/Projets/lacaisse/working/LCAKit/Sources/LCAEpson/EpsonPrinterInfo.swift:44:17)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010648e9ac llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010648cc00 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010648ef78 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019d630184 _sigtramp + 56
4  swift-frontend           0x00000001021a007c (anonymous namespace)::ActorIsolationChecker::checkApply(swift::ApplyExpr*) + 2032
5  swift-frontend           0x00000001021a007c (anonymous namespace)::ActorIsolationChecker::checkApply(swift::ApplyExpr*) + 2032
6  swift-frontend           0x000000010219caf4 (anonymous namespace)::ActorIsolationChecker::walkToExprPre(swift::Expr*) + 1872
7  swift-frontend           0x0000000102592d9c (anonymous namespace)::Traversal::visitDynamicMemberRefExpr(swift::DynamicMemberRefExpr*) + 48
8  swift-frontend           0x0000000102592718 (anonymous namespace)::Traversal::visit(swift::Expr*) + 308
9  swift-frontend           0x0000000102592dc0 (anonymous namespace)::Traversal::visitDynamicMemberRefExpr(swift::DynamicMemberRefExpr*) + 84
10 swift-frontend           0x0000000102592754 (anonymous namespace)::Traversal::visit(swift::Expr*) + 368
11 swift-frontend           0x0000000102597988 (anonymous namespace)::Traversal::visit(swift::Decl*) + 2964
12 swift-frontend           0x00000001025923f4 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 324
13 swift-frontend           0x0000000102595f24 (anonymous namespace)::Traversal::visit(swift::Stmt*) + 2612
14 swift-frontend           0x0000000102595a64 (anonymous namespace)::Traversal::visit(swift::Stmt*) + 1396
15 swift-frontend           0x000000010259600c (anonymous namespace)::Traversal::visit(swift::Stmt*) + 2844
16 swift-frontend           0x00000001025936b4 (anonymous namespace)::Traversal::visitClosureExpr(swift::ClosureExpr*) + 296
17 swift-frontend           0x00000001025927a8 (anonymous namespace)::Traversal::visit(swift::Expr*) + 452
18 swift-frontend           0x0000000102592dc0 (anonymous namespace)::Traversal::visitDynamicMemberRefExpr(swift::DynamicMemberRefExpr*) + 84
19 swift-frontend           0x00000001025928a4 (anonymous namespace)::Traversal::visit(swift::Expr*) + 704
20 swift-frontend           0x0000000102598580 (anonymous namespace)::Traversal::visit(swift::ArgumentList*) + 288
21 swift-frontend           0x0000000102595118 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 196
22 swift-frontend           0x000000010259263c (anonymous namespace)::Traversal::visit(swift::Expr*) + 88
23 swift-frontend           0x0000000102595eb4 (anonymous namespace)::Traversal::visit(swift::Stmt*) + 2500
24 swift-frontend           0x0000000102190da0 swift::checkFunctionActorIsolation(swift::AbstractFunctionDecl*) + 544
25 swift-frontend           0x00000001022a16fc swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 2268
26 swift-frontend           0x00000001026b1fd4 swift::TypeCheckFunctionBodyRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()>(swift::TypeCheckFunctionBodyRequest const&, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()) + 636
27 swift-frontend           0x0000000102620b44 swift::AbstractFunctionDecl::getTypecheckedBody() const + 160
28 swift-frontend           0x00000001022ef3dc swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 868
29 swift-frontend           0x00000001022f6970 swift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()>(swift::TypeCheckSourceFileRequest const&, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()) + 620
30 swift-frontend           0x00000001022ef05c swift::performTypeChecking(swift::SourceFile&) + 328
31 swift-frontend           0x000000010120cce0 swift::CompilerInstance::performSema() + 260
32 swift-frontend           0x0000000100e3a0dc performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1532
33 swift-frontend           0x0000000100e38ea0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
34 swift-frontend           0x0000000100dbff64 swift::mainEntry(int, char const**) + 3680
35 dyld                     0x000000019d278274 start + 2840