Open BradLarson opened 2 years ago
This reproducer can be narrowed down further. I don't think it's about whether the function is differentiable, because the reproducer works with [Float]
. In that case, the function would be differentiable, but it would still crash.
import _Differentiation
@differentiable(reverse)
func readAll(from root: Float) -> [Float] {
// [Int] can be any array type. It can also be initialized outside of the
// function.
return [Int]().map { _ in root }
}
The crash appeared between the 2021-01-27 and 2021-04-18 snapshots. On 2021-01-27, there seems to be a pre-existing bug that triggered before this one. To reproduce it on that toolchain, you must change @differentiable(reverse)
to @differentiable
.
On the 2020-07-22 toolchain, it fails gracefully when using [Int]()
, saying it can't be differentiated because of unsupported control flow. Changing to [Float]()
doesn't eliminate the error, so maybe this reproducer is non-differentiable in all forms. Thus, it could be about emitting a proper diagnostic for non-differentiable functions.
Still causes a crash on the 05/24 toolchain. Stack dump looks different.
Assertion failed: (index >= (getNumIndirectSILResults() + getNumIndirectSILErrorResults()) && index <= getNumSILArguments()), function getParamInfoForSILArg, file SILFunctionConventions.h, line 444.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/kshitij/workspace/scratch/test.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -color-diagnostics -O -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/kshitij/workspace/scratch -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/lib/swift -module-name test -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a.xctoolchain/usr/local/lib/swift/host/plugins -enable-default-cmo -o /var/folders/5h/9l25ljkd47qct1zm4g4_dxz00000gq/T/TemporaryDirectory.0Bb8Yc/test-1.o
1. Apple Swift version 6.0-dev (LLVM b66077aefd3be08, Swift 84d36181a762913)
2. Compiling with effective version 5.10
3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for test)
4. While running pass #145 SILModuleTransform "Differentiation".
5. While processing // differentiability witness for TestKeyPaths.readAll(from:)
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] <Root, Value where Root : Differentiable, Value : Differentiable> @$s4test12TestKeyPathsV7readAll4fromSayq_Gx_tF : $@convention(method) <Root, Value> (@in_guaranteed Root, @guaranteed TestKeyPaths<Root, Value>) -> @owned Array<Value> {
}
on SIL function "@$s4test12TestKeyPathsV7readAll4fromSayq_Gx_tF".
for 'readAll(from:)' (at /Users/kshitij/workspace/scratch/test.swift:12:12)
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 0x0000000109d9d600 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000109d9bdcc llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000109d9dc48 SignalHandler(int) + 304
3 libsystem_platform.dylib 0x00000001a3286a24 _sigtramp + 56
4 libsystem_pthread.dylib 0x00000001a3257c28 pthread_kill + 288
5 libsystem_c.dylib 0x00000001a3165ae8 abort + 180
6 libsystem_c.dylib 0x00000001a3164e44 err + 0
7 swift-frontend 0x0000000109edb124 swift::SILFunctionConventions::getParamInfoForSILArg(unsigned int) const (.cold.3) + 0
8 swift-frontend 0x0000000105030b24 swift::SILFunctionConventions::getParamInfoForSILArg(unsigned int) const + 180
9 swift-frontend 0x00000001050f7c98 swift::autodiff::LinearMapInfo::getLinearMapType(swift::autodiff::ADContext&, swift::FullApplySite) + 476
10 swift-frontend 0x00000001050f6770 swift::autodiff::LinearMapInfo::generateDifferentiationDataStructures(swift::autodiff::ADContext&, swift::SILFunction*) + 1008
11 swift-frontend 0x00000001050f6eec swift::autodiff::LinearMapInfo::LinearMapInfo(swift::autodiff::ADContext&, swift::AutoDiffLinearMapKind, swift::SILFunction*, swift::SILFunction*, swift::AutoDiffConfig const&, swift::DifferentiableActivityInfo const&, swift::SILLoopInfo*) + 148
12 swift-frontend 0x0000000105117de4 swift::autodiff::VJPCloner::Implementation::Implementation(swift::autodiff::VJPCloner&, swift::autodiff::ADContext&, swift::SILDifferentiabilityWitness*, swift::SILFunction*, swift::autodiff::DifferentiationInvoker) + 616
13 swift-frontend 0x0000000105118ea0 swift::autodiff::VJPCloner::VJPCloner(swift::autodiff::ADContext&, swift::SILDifferentiabilityWitness*, swift::SILFunction*, swift::autodiff::DifferentiationInvoker) + 92
14 swift-frontend 0x00000001052752a4 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 6020
15 swift-frontend 0x0000000105273130 (anonymous namespace)::Differentiation::run() + 1060
16 swift-frontend 0x0000000105316a80 swift::SILPassManager::runModulePass(unsigned int) + 856
17 swift-frontend 0x0000000105318e40 swift::SILPassManager::execute() + 624
18 swift-frontend 0x00000001053136f8 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
19 swift-frontend 0x0000000105313678 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
20 swift-frontend 0x000000010534f07c swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
21 swift-frontend 0x000000010532f2e4 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
22 swift-frontend 0x00000001053138d4 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
23 swift-frontend 0x000000010533186c swift::runSILDiagnosticPasses(swift::SILModule&) + 192
24 swift-frontend 0x0000000104b73fa8 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68
25 swift-frontend 0x0000000104938b44 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*) + 796
26 swift-frontend 0x0000000104938258 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
27 swift-frontend 0x00000001049494cc withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
28 swift-frontend 0x000000010493a868 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
29 swift-frontend 0x00000001049397d4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
30 swift-frontend 0x00000001047549cc swift::mainEntry(int, char const**) + 3096
31 dyld 0x00000001a2efff28 start + 2236
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, AutoDiff | |Assignee | None | |Priority | Medium | md5: ae84dcea4936a75e0d58dcc65a61c26eIssue Description:
The following simple file involving differentiation through a map function that uses keypaths triggers an assertion failure of "Assertion failed: (!NodePtr->isKnownSentinel()), function operator*, file ilist_iterator.h, line 138.":
To reproduce, place the above in a file and run `swiftc file.swift` to hit the assertion failure. This is present in current nightly snapshots and is not a recent regression.
My guess is that we're missing a diagnostic stating that the above isn't differentiable, in a similar manner to the missing diagnostic in SR-15201.
This is the full text of the assertion failure: