Open kateinoigakukun opened 9 months ago
I tried to enable swiftasynccall
calling convention in LLVM with Wasm, but got assertion hit below:
swift-frontend: /home/katei/ghq/work.katei.dev/swift-source/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:138: llvm::ilist_iterator::reference llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::MachineInstr, true, true, void>, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options<llvm::MachineInstr, true, true, void>, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend -frontend -c /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Actor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncLet.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/CheckedContinuation.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Errors.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Executor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/ExecutorAssertions.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncCompactMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncDropFirstSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncDropWhileSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncFilterSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncFlatMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncIteratorProtocol.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncPrefixSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncPrefixWhileSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingCompactMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingDropWhileSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingFilterSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingFlatMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingMapSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingPrefixWhileSequence.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/GlobalActor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/GlobalConcurrentExecutor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/MainActor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/PartialAsyncTask.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/SourceCompatibilityShims.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Task.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Task+TaskExecutor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskCancellation.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskGroup.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskGroup+TaskExecutor.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/DiscardingTaskGroup.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskLocal.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskSleep.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncStreamBuffer.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncStream.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/AsyncThrowingStream.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/_DequeBuffer.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/_DequeBufferHeader.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/_DequeSlot.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/_UnsafeWrappedBuffer.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Compatibility.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Storage.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+UnsafeHandle.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Codable.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Collection.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+CustomDebugStringConvertible.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+CustomReflectable.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+CustomStringConvertible.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Equatable.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+ExpressibleByArrayLiteral.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Extras.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Hashable.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/Deque+Testing.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Deque/UnsafeMutableBufferPointer+Utilities.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/Clock.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/ContinuousClock.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/SuspendingClock.swift /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/TaskSleepDuration.swift -supplementary-output-file-map /tmp/TemporaryDirectory.RrRsAc/supplementaryOutputs-1 -disable-objc-attr-requires-foundation-module -target wasm32-unknown-wasi -disable-objc-interop -sdk /home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasi-sysroot -I /home/katei/ghq/work.katei.dev/swift-source/swift/stdlib/public/Concurrency/InternalShims -I /home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasmstdlib-linux-x86_64/lib/swift/wasi -color-diagnostics -warn-implicit-overrides -enable-library-evolution -module-cache-path /home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasmstdlib-linux-x86_64/module-cache -module-link-name swift_Concurrency -parse-stdlib -static -swift-version 5 -O -diagnostic-style swift -library-level api -D SWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -D SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY -D SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE -D SWIFT_THREADING_NONE -D SWIFT_ENABLE_REFLECTION -require-explicit-availability=ignore -assume-single-threaded -enforce-exclusivity=unchecked -disable-autolinking-runtime-compatibility-concurrency -disable-objc-interop -enable-ossa-modules -enable-lexical-lifetimes=false -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -prespecialize-generic-metadata -define-availability "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -define-availability "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" -define-availability "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" -define-availability "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" -define-availability "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" -define-availability "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" -define-availability "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" -define-availability "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" -define-availability "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" -define-availability "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4" -define-availability "SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0" -define-availability "SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4" -define-availability "SwiftStdlib 5.11:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -target-min-inlining-version min -enable-experimental-feature OptionalIsolatedParameters -resource-dir /home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasmstdlib-linux-x86_64/lib/swift -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -Xcc -mtail-call -module-name _Concurrency -plugin-path /home/katei/ghq/work.katei.dev/swift-source/install/usr/lib/swift/host/plugins -plugin-path /home/katei/ghq/work.katei.dev/swift-source/install/usr/local/lib/swift/host/plugins -parse-as-library -o /home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasmstdlib-linux-x86_64/stdlib/public/Concurrency/WASI/wasm32/_Concurrency.o -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements
1. Swift version 5.11-dev (LLVM 35482cf965aa5ab, Swift e0fda801d757229)
2. Compiling with the current language version
3. Running pass 'Function Pass Manager' on module '/home/katei/ghq/work.katei.dev/swift-source/build/buildbot_linux/wasmstdlib-linux-x86_64/stdlib/public/Concurrency/WASI/wasm32/_Concurrency.o'.
4. Running pass 'WebAssembly Instruction Selection' on function '@"$ss15ContinuousClockV3nowAB7InstantVvg"'
#0 0x000055bee29ae567 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x7a41567)
#1 0x000055bee29ac29e llvm::sys::RunSignalHandlers() (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x7a3f29e)
#2 0x000055bee29aebef SignalHandler(int) Signals.cpp:0:0
#3 0x00007f4b1f1fb420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f4b1d47800b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f4b1d457859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007f4b1d457729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007f4b1d457729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007f4b1d468fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x000055bedf87d1c9 llvm::findSplitPointForStackProtector(llvm::MachineBasicBlock*, llvm::TargetInstrInfo const&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x49101c9)
#10 0x000055bedec7d257 llvm::SelectionDAGISel::FinishBasicBlock() (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x3d10257)
#11 0x000055bedec784e5 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x3d0b4e5)
#12 0x000055bedec74ca7 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x3d07ca7)
#13 0x000055bedf9d8c67 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x4a6bc67)
#14 0x000055bee2626373 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x76b9373)
#15 0x000055bee262ea71 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x76c1a71)
#16 0x000055bee2626b54 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x76b9b54)
#17 0x000055bedc0dc492 swift::compileAndWriteLLVM(llvm::Module*, llvm::TargetMachine*, swift::IRGenOptions const&, swift::UnifiedStatsReporter*, swift::DiagnosticEngine&, llvm::raw_pwrite_stream&, llvm::sys::SmartMutex<false>*, llvm::raw_pwrite_stream*) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x116f492)
#18 0x000055bedc0db635 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, llvm::vfs::OutputBackend&, swift::UnifiedStatsReporter*) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0x116e635)
#19 0x000055bedbcb3110 generateCode(swift::CompilerInstance&, llvm::StringRef, llvm::Module*, llvm::GlobalVariable*) FrontendTool.cpp:0:0
#20 0x000055bedbcad942 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
#21 0x000055bedbcac7ca swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0xd3f7ca)
#22 0x000055bedbcc2d99 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#23 0x000055bedbcb01a5 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#24 0x000055bedbcae81d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0xd4181d)
#25 0x000055bedbaa6b67 swift::mainEntry(int, char const**) (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0xb39b67)
#26 0x00007f4b1d459083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055bedbaa4e4e _start (/home/katei/ghq/work.katei.dev/swift-source/install/usr/bin/swift-frontend+0xb37e4e)
The main problem here is Wasm's call is split into two CALL_PARAMS and CALL_RESULTS, and SSP tries to insert check code among them
Safari TP 202 shipped tail-call support https://developer.apple.com/documentation/safari-technology-preview-release-notes/stp-release-202
Currently, we are using simple recursive call for coroutine lowering in CoroSplit LLVM pass. However, it limits number of suspension chains due to the limitation of number of call frames.
In theory, with tail-call feature, which is now in standardizing phase, we can use
swiftasynccall
calling convention andmusttail call
to ensure the call is tail-called, and it will remove the limitation of the length of suspension chain.Blockers