icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.03k stars 95 forks source link

Xcode 14.3 / Swift 5.8 compiler crash in CFlowExt.swift #238

Closed darronschall closed 1 year ago

darronschall commented 1 year ago

I'm unable to upgrade a KMM project to Xcode 14.3 / Swift 5.8 using MOKO-MVVM's CFlowExt SwiftUI helper.

This is likely a Swift compiler bug. Xcode 14.2 / Swift 5.7 works just fine, but the Swift 5.8 compiler throws the following stack trace:

1.  Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
2.  Compiling with the current language version
3.  While evaluating request IRGenRequest(IR Generation for file "/Users/darron/Development/example-kmm/iosApp/iosApp/mokoMvvmFlowSwiftUI/CFlowExt.swift")
4.  While emitting IR SIL function "@$sxSgIegg_AAIeyBy_RlzC5InputQy_Rsz7Combine10SubscriberR_s5NeverO7FailureRt_r0_lTR".
 for <<debugloc at "<compiler-generated>":0:0>>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           0x0000000109ef3300 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109ef22e4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109ef3910 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001815e82a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001815b9cec pthread_kill + 288
5  libsystem_c.dylib        0x00000001814f22c8 abort + 180
6  swift-frontend           0x000000010651f24c swift::GenericSignatureImpl::getDependentUpperBounds(swift::Type) const + 1392
7  swift-frontend           0x0000000106625afc swift::ArchetypeType::getExistentialType() const + 192
8  swift-frontend           0x00000001052981a8 void llvm::function_ref<void (swift::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::addPseudogenericFulfillments()::$_11>(long, swift::GenericRequirement) + 304
9  swift-frontend           0x000000010529c544 void llvm::function_ref<void (swift::GenericTypeParamType*, bool)>::callback_fn<swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&)::$_0>(long, swift::GenericTypeParamType*, bool) + 44
10 swift-frontend           0x000000010651c4bc swift::GenericSignatureImpl::forEachParam(llvm::function_ref<void (swift::GenericTypeParamType*, bool)>) const + 756
11 swift-frontend           0x000000010528e8c4 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&) + 1044
12 swift-frontend           0x00000001052974c0 (anonymous namespace)::PolymorphicConvention::PolymorphicConvention(swift::irgen::IRGenModule&, swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 188
13 swift-frontend           0x000000010529478c swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::EntryPointArgumentEmission&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 76
14 swift-frontend           0x0000000105334da0 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 5996
15 swift-frontend           0x00000001051c2048 swift::irgen::IRGenerator::emitLazyDefinitions() + 2664
16 swift-frontend           0x00000001052ea824 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 11448
17 swift-frontend           0x0000000105333368 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
18 swift-frontend           0x00000001052fbca0 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 832
19 swift-frontend           0x00000001052ed9b0 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 236
20 swift-frontend           0x0000000104de6f30 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) + 228
21 swift-frontend           0x0000000104de17a0 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1684
22 swift-frontend           0x0000000104de4520 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1856
23 swift-frontend           0x0000000104de2944 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4308
24 swift-frontend           0x0000000104da768c swift::mainEntry(int, char const**) + 4116
25 dyld                     0x000000018128fe50 start + 2544
zsh: abort       -c          -primary-file  -primary-file  -primary-file  -primary-file

I've narrowed the crash down to the CFlowSubscription class. That is, if I comment the class out and do not reference it in CFlowPublisher's receive, then the compiler doesn't crash anymore. But, I haven't been able to determine a workaround yet to bring the functionality back.

Has anyone else run into this, or is it just me?

darronschall commented 1 year ago

I was able to workaround the Swift 5.8 compiler crash by making both CFlowPublisher and CFlowSubscription no longer generic and instead pinning Output to AnyObject. This requires casting the cFlow from createPublisher via cFlow as! CFlow<AnyObject> since we lose the generic T, but that's OK and should always succeed because T has to be constrained to AnyObject anyway.

I'll submit a PR for further discussion.

darronschall commented 1 year ago

FYI, I logged the Swift 5.8 compiler crash against the Swift project at https://github.com/apple/swift/issues/65331