Skip to content

Swift 5.9 compiler crash on Linux when compile a generic distributed actor with type constraints #68517

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

Closed
ser-0xff opened this issue Sep 14, 2023 · 9 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software distributed Feature → concurrency: distributed actor generics Feature: generic declarations and types IRGen LLVM IR generation

Comments

@ser-0xff
Copy link

ser-0xff commented Sep 14, 2023

Description
Compiler crashes if compile a following code:

protocol StorableKey {
    static var isInteger: Bool { get }
}

distributed actor TestActor<Object> where Object: Transferable & Identifiable, Object.ID: StorableKey {
    public typealias ActorSystem = DistributedSystem

    public init(in actorSystem: ActorSystem) {
        self.actorSystem = actorSystem
    }

    public distributed func handleObject(_ object: Object) async throws {
        print("\(object)")
    }
}

Steps to reproduce

The source code which crash the compiler is in the GitHub repo, can be reproduced as:

git clone https://github.com/ordo-one/package-distributed-system.git
cd package-distributed-system
git checkout swift-compiler-crash
swift test

Compilation fails with following error:

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Term verification failed
Initial term:    τ_0_0.[Identifiable:ID]
Erased term:     τ_0_0.ID
Simplified term: τ_0_0.ID

Requirement machine for <τ_0_0, τ_1_0 where τ_1_0 : DistributedTargetInvocationDecoder>
Rewrite system: {
- [DistributedTargetInvocationDecoder].[DistributedTargetInvocationDecoder] => [DistributedTargetInvocationDecoder] [permanent]
- [DistributedTargetInvocationDecoder].SerializationRequirement => [DistributedTargetInvocationDecoder:SerializationRequirement] [permanent]
- [DistributedTargetInvocationDecoder].[DistributedTargetInvocationDecoder:SerializationRequirement] => [DistributedTargetInvocationDecoder:SerializationRequirement]
- τ_1_0.[DistributedTargetInvocationDecoder] => τ_1_0 [explicit]
- τ_1_0.SerializationRequirement => τ_1_0.[DistributedTargetInvocationDecoder:SerializationRequirement]
}
}
Property map: {
  [DistributedTargetInvocationDecoder] => { conforms_to: [DistributedTargetInvocationDecoder] }
  τ_1_0 => { conforms_to: [DistributedTargetInvocationDecoder] }
}
Conformance paths: {
}
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend -frontend -c -primary-file /home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/CompilerCrash.swift /home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/DistributedSystemTests.swift /home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/FrostflakeInitializer.swift /home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/GenericDistributedActor.swift /home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/TransferableConformanceTests.swift -emit-dependencies-path /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/DistributedSystemTests.build/CompilerCrash.d -emit-reference-dependencies-path /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/DistributedSystemTests.build/CompilerCrash.swiftdeps -target aarch64-unknown-linux-gnu -Xllvm -aarch64-use-tbi -disable-objc-interop -I /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/CNIOLLHTTP.build/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIOLLHTTP/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIOWindows/include/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIOWindows/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/CNIOLinux.build/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIOLinux/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/CNIODarwin.build/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIODarwin/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/CNIOAtomics.build/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-nio/Sources/CNIOAtomics/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/swift-atomics/Sources/_AtomicsShims/include -Xcc -fmodule-map-file=/home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/_PauseShims.build/module.modulemap -Xcc -I -Xcc /home/ubuntu/package-distributed-system/.build/checkouts/package-concurrency-helpers/Sources/_PauseShims/include -Xcc -fPIC -module-name DistributedSystemTests -plugin-path /home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/lib/swift/host/plugins -plugin-path /home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/local/lib/swift/host/plugins -parse-as-library -o /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/DistributedSystemTests.build/CompilerCrash.swift.o -index-store-path /home/ubuntu/package-distributed-system/.build/aarch64-unknown-linux-gnu/debug/index/store -index-system-modules
1.	Swift version 5.9-dev (LLVM 3708b80be7731a7, Swift aaafc31485ff571)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/home/ubuntu/package-distributed-system/Tests/DistributedSystemTests/CompilerCrash.swift")
4.	While emitting IR SIL function "@$s22DistributedSystemTests9TestActorC12handleObjectyyxYaKFTE".
 for 'handleObject(_:)' (in module 'DistributedSystemTests')
 #0 0x0000aaaae86d7038 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x6a87038)
 #1 0x0000aaaae86d5028 llvm::sys::RunSignalHandlers() (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x6a85028)
 #2 0x0000aaaae86d7454 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffff8b6a67dc (linux-vdso.so.1+0x7dc)
 #4 0x0000ffff89d9f200 __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x0000ffff89d5a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x0000ffff89d47130 abort ./stdlib/./stdlib/abort.c:81:7
 #7 0x0000aaaae433e3bc swift::rewriting::RequirementMachine::getReducedShape(swift::Type, llvm::ArrayRef<swift::GenericTypeParamType*>) const (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x26ee3bc)
 #8 0x0000aaaae433e810 swift::rewriting::RequirementMachine::getRequiredProtocols(swift::Type) const (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x26ee810)
 #9 0x0000aaaae3002378 swift::irgen::FulfillmentMap::searchWitnessTable(swift::irgen::IRGenModule&, swift::CanType, swift::ProtocolDecl*, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x13b2378)
#10 0x0000aaaae3001d6c swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x13b1d6c)
#11 0x0000aaaae2f6b390 void (anonymous namespace)::PolymorphicConvention::considerNewTypeSource<unsigned int>(swift::irgen::IsExact_t, swift::irgen::MetadataSource::Kind, swift::CanType, unsigned int) GenProto.cpp:0:0
#12 0x0000aaaae2f6a628 (anonymous namespace)::PolymorphicConvention::considerParameter(swift::SILParameterInfo, unsigned int, bool) GenProto.cpp:0:0
#13 0x0000aaaae2f5f464 (anonymous namespace)::PolymorphicConvention::PolymorphicConvention(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, bool) GenProto.cpp:0:0
#14 0x0000aaaae2f68890 swift::irgen::expandPolymorphicSignature(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::SmallVectorImpl<llvm::Type*>&, llvm::SmallVectorImpl<swift::irgen::PolymorphicSignatureExpandedTypeSource>*) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x1318890)
#15 0x0000aaaae2e4dfa4 swift::irgen::(anonymous namespace)::SignatureExpansion::expandAsyncEntryType() GenCall.cpp:0:0
#16 0x0000aaaae2e4bea4 swift::irgen::(anonymous namespace)::SignatureExpansion::expandFunctionType(swift::irgen::SignatureExpansionABIDetails*) GenCall.cpp:0:0
#17 0x0000aaaae2e4bad8 swift::irgen::Signature::getUncached(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::FunctionPointerKind, bool) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x11fbad8)
#18 0x0000aaaae2efcd38 (anonymous namespace)::FuncSignatureInfo::getSignature(swift::irgen::IRGenModule&) const GenFunc.cpp:0:0
#19 0x0000aaaae2efc910 swift::irgen::IRGenModule::getSignature(swift::CanTypeWrapper<swift::SILFunctionType>) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x12ac910)
#20 0x0000aaaae3012ce8 swift::irgen::IRGenModule::getAddrOfDistributedTargetAccessor(swift::SILFunction*, swift::ForDefinition_t) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x13c2ce8)
#21 0x0000aaaae301382c swift::irgen::IRGenModule::emitDistributedTargetAccessor(swift::SILFunction*) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x13c382c)
#22 0x0000aaaae2fce914 (anonymous namespace)::IRGenSILFunction::emitSILFunction() IRGenSIL.cpp:0:0
#23 0x0000aaaae2fcdf64 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x137df64)
#24 0x0000aaaae2ea5174 swift::irgen::IRGenerator::emitGlobalTopLevel(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x1255174)
#25 0x0000aaaae2d724b8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x11224b8)
#26 0x0000aaaae2dc5a48 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::integer_sequence<unsigned long, 0ul>) const crtstuff.c:0:0
#27 0x0000aaaae2d814bc llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) crtstuff.c:0:0
#28 0x0000aaaae2d74a00 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0x1124a00)
#29 0x0000aaaae2a33e44 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >) FrontendTool.cpp:0:0
#30 0x0000aaaae2a30128 performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#31 0x0000aaaae2a2f1b8 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0xddf1b8)
#32 0x0000aaaae2a41208 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#33 0x0000aaaae2a31b3c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#34 0x0000aaaae2a30acc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0xde0acc)
#35 0x0000aaaae28a4874 swift::mainEntry(int, char const**) (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0xc54874)
#36 0x0000ffff89d473fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#37 0x0000ffff89d474cc call_init ./csu/../csu/libc-start.c:128:20
#38 0x0000ffff89d474cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#39 0x0000aaaae28a3570 _start (/home/ubuntu/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a-ubuntu22.04-aarch64/usr/bin/swift-frontend+0xc53570)
[584/595] Linking TestService
error: fatalError

Expected behavior
Tests compiles without errors.

Environment

  • Swift version 5.9-dev (LLVM 3708b80be7731a7, Swift aaafc31)
    Target: aarch64-unknown-linux-gnu
  • Linux linux-dev 5.15.0-78-generic Fix spelling of “file” #85-Ubuntu SMP Fri Jul 7 15:29:30 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Seems it is a regression, works properly with latest 5.8

@ser-0xff ser-0xff added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 14, 2023
@hassila
Copy link

hassila commented Sep 14, 2023

@ser-0xff this worked with 5.8 and is a regression, right?

@ser-0xff
Copy link
Author

Yes, it works properly with 5.8

@xedin xedin added distributed Feature → concurrency: distributed actor IRGen LLVM IR generation crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types and removed triage needed This issue needs more specific labels labels Sep 14, 2023
@xedin
Copy link
Contributor

xedin commented Sep 14, 2023

cc @slavapestov

@ser-0xff
Copy link
Author

ser-0xff commented Sep 28, 2023

Hi!
If it make sense...
We tried it once more with the 5.9 officially released:

Swift version 5.9 (swift-5.9-RELEASE)
Target: aarch64-unknown-linux-gnu

and it works.
Is it expected?

@slavapestov
Copy link
Contributor

@ktoso I believe you had a fix already?

@ktoso
Copy link
Contributor

ktoso commented Sep 29, 2023

Sorry I was traveling last week and took me a moment to recover.

I was just investigating today and have not fixed anything here yet, though can confirm that the 5.9 works correctly.
I can't get it to fail in a test case either so far.

This is pretty weird and I'm trying to pinpoint where it regressed and...

The 5.9 tag is from 2023-09-08, but... all the snapshots I'm checking are crashing:

root@d5549540a8d7:/code/package-distributed-system# cat ../checks
5.9-DEVELOPMENT-SNAPSHOT-2023-08-05-a: broken
5.9-DEVELOPMENT-SNAPSHOT-2023-08-07-a: broken
5.9: OK // 08-09
5.9-DEVELOPMENT-SNAPSHOT-2023-09-13-a: broken
5.9-DEVELOPMENT-SNAPSHOT-2023-07-22-a: broken
5.9-DEVELOPMENT-SNAPSHOT-2023-09-27-a: broken
5.8.1: OK
5.8.0: OK
5.8-DEVELOPMENT-SNAPSHOT-2023-03-17-a: broken

including the "latest" 5.8 snapshot... but stable releases work (?!), so this is very weird.

I guess we're doing something wrong and will try to just read the code... but it's incredibly weird why it's not wrong in any stable release...? While tags leading up to those releases are broken in the same way (as posted in this thread).

@ktoso
Copy link
Contributor

ktoso commented Sep 29, 2023

OH... wait what if we just don't run the verifier on stable releases or something like that? 🤔 That's an idea... checking...

edit1: Yeah I just noticed the diagnostic in RequirementMachine::verify is surrounded with a #ifndef NDEBUG, so yeah I suspect that might be it... Not quite; the code triggers but does not fail on main...

edit2: Okey reproducing this in test suite and looking for fix.

@ktoso
Copy link
Contributor

ktoso commented Sep 29, 2023

Yup, fixed: #68859

It'll affect only nightlies, but it's good to have it on 5.10 and main 👍

Thanks for reporting @ser-0xff @hassila !

@ser-0xff
Copy link
Author

Works fine with latest 5.9, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software distributed Feature → concurrency: distributed actor generics Feature: generic declarations and types IRGen LLVM IR generation
Projects
None yet
5 participants