Skip to content

Compiler Error with consuming Modifier on Actor Method in Swift 5.9 #68072

@mehmeteminkartal

Description

@mehmeteminkartal

Description
An unexpected compiler error is observed when using the consuming modifier within an actor method. The provided actor code seems to trigger a compiler malfunction. This even crashes the swift language server so pasting this code on vscode (where the swift extension is installed) will make it freak out.

Code sample:

actor User {
    var name: String = "Test"

    consuming func read() {
        print(name)
    }
}

func a() async {
    let newUser = User()

    await newUser.read()
}

The command output is below

mehmet@mehmetlinux:~/swiftbugtest$ swift run
warning: 'swiftbugtest': warning: direct reference to protected function `$sSJ12isWhitespaceSbvg' in `/home/mehmet/swift-5.9/usr/bin/../lib/swift/linux/libswiftCore.so' may break pointer equality
Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
warning: direct reference to protected function `$sSJ12isWhitespaceSbvg' in `/home/mehmet/swift-5.9/usr/bin/../lib/swift/linux/libswiftCore.so' may break pointer equality
Begin Error in Function: '$s12swiftbugtest1ayyYaF'
Found outside of lifetime use?!
Value:   %7 = copy_value %5 : $User                      // users: %11, %9, %8
Consuming User:   %11 = apply %8(%7) : $@convention(method) (@owned User) -> ()
Non Consuming User:   end_borrow %9 : $User                           // id: %13
Block: bb0

End Error in Function: '$s12swiftbugtest1ayyYaF'
Found ownership error?!
triggering standard assertion failure routine
UNREACHABLE executed at /home/build-user/swift/lib/SIL/Verifier/LinearLifetimeCheckerPrivate.h:211!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/mehmet/swift-5.9/usr/bin/swift-frontend -frontend -c -primary-file /home/mehmet/swiftbugtest/Sources/main.swift -emit-dependencies-path /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug/swiftbugtest.build/main.d -emit-reference-dependencies-path /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug/swiftbugtest.build/main.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /home/mehmet/swift-5.9/usr/bin/swift-driver -entry-point-function-name swiftbugtest_main -empty-abi-descriptor -resource-dir /home/mehmet/swift-5.9/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fPIC -module-name swiftbugtest -package-name swiftbugtest -plugin-path /home/mehmet/swift-5.9/usr/lib/swift/host/plugins -plugin-path /home/mehmet/swift-5.9/usr/local/lib/swift/host/plugins -o /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug/swiftbugtest.build/main.swift.o -index-store-path /home/mehmet/swiftbugtest/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.      Swift version 5.9-dev (LLVM 71b6f8f40249d4a, Swift 0027fac736e2385)
2.      Compiling with the current language version
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/home/mehmet/swiftbugtest/Sources/main.swift")
4.      While silgen emitFunction SIL function "@$s12swiftbugtest1ayyYaF".
 for 'a()' (at /home/mehmet/swiftbugtest/Sources/main.swift:11:1)
5.      While verifying SIL function "@$s12swiftbugtest1ayyYaF".
 for 'a()' (at /home/mehmet/swiftbugtest/Sources/main.swift:11:1)
 #0 0x0000000006bbfa73 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x6bbfa73)
 #1 0x0000000006bbd68e llvm::sys::RunSignalHandlers() (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x6bbd68e)
 #2 0x0000000006bbfddf SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fa76b43c4b0 (/lib/x86_64-linux-gnu/libc.so.6+0x3c4b0)
 #4 0x00007fa76b490ffb __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007fa76b490ffb __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007fa76b490ffb pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007fa76b43c406 raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007fa76b42287c abort ./stdlib/abort.c:81:7
 #9 0x0000000006adb321 (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x6adb321)
#10 0x00000000018a93ae swift::LinearLifetimeChecker::ErrorBuilder::handleError(llvm::function_ref<void ()>&&, bool) const crtstuff.c:0:0
#11 0x00000000018a5d8f swift::LinearLifetimeChecker::checkValueImpl(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&, llvm::Optional<llvm::function_ref<void (swift::SILBasicBlock*)>>, llvm::Optional<llvm::function_ref<void (swift::Operand*)>>) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x18a5d8f)
#12 0x00000000018a73c7 swift::LinearLifetimeChecker::checkValue(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x18a73c7)
#13 0x00000000018ac1f4 swift::SILValueOwnershipChecker::check() (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x18ac1f4)
#14 0x00000000018ae756 verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) SILOwnershipVerifier.cpp:0:0
#15 0x00000000018ae5ea swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x18ae5ea)
#16 0x00000000018d6e6e (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) SILVerifier.cpp:0:0
#17 0x00000000018d9958 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) SILVerifier.cpp:0:0
#18 0x00000000018c2e23 swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) SILVerifier.cpp:0:0
#19 0x00000000018b9dfb (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#20 0x00000000018b7eca (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) SILVerifier.cpp:0:0
#21 0x00000000018b00fa swift::SILFunction::verify(bool, bool, bool) const (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x18b00fa)
#22 0x0000000000d53d1b swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) crtstuff.c:0:0
#23 0x0000000000d52b47 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) crtstuff.c:0:0
#24 0x0000000000d55120 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef) SILGen.cpp:0:0
#25 0x0000000000d50d94 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) crtstuff.c:0:0
#26 0x0000000000d57ff8 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0xd57ff8)
#27 0x0000000000e3b71f swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) crtstuff.c:0:0
#28 0x0000000000d5c9ca llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) crtstuff.c:0:0
#29 0x0000000000d59c09 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0xd59c09)
#30 0x000000000066508d swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x66508d)
#31 0x000000000067b2d9 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#32 0x0000000000668332 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x668332)
#33 0x00000000004c4b51 swift::mainEntry(int, char const**) (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x4c4b51)
#34 0x00007fa76b423a90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#35 0x00007fa76b423b49 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007fa76b423b49 __libc_start_main ./csu/../csu/libc-start.c:347:5
#37 0x00000000004c429e _start (/home/mehmet/swift-5.9/usr/bin/swift-frontend+0x4c429e)

Steps to reproduce

  • Create a new swift package using swift package init --type=executable
  • Replace the main.swift with the given contents
  • run swift run from the package directory

Expected behavior
The compiler should not crash

Environment

  • Swift version 5.9-dev (LLVM 71b6f8f40249d4a, Swift 0027fac)
  • Target: x86_64-unknown-linux-gnu
uname -a
Linux mehmetlinux 6.2.0-27-generic #28-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 12 22:39:51 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
lsb_release
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:        23.04
Codename:       lunar

The bug is also observed on the swift main branch (tested using the trunk docker image)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    SIL ownershipArea → compiler → SIL: SIL ownershipassertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions