Skip to content
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

[SR-13046] Non-differentiability diagnostic crash due to invalid source location #55492

Closed
dan-zheng opened this issue Jun 18, 2020 · 1 comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-13046
Radar None
Original Reporter @dan-zheng
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff, CompilerCrash
Assignee None
Priority Medium

md5: a97e210a2a95627bbf78b2041e5b234e

Issue Description:

import _Differentiation

func nondiff(_ f: @differentiable (Float, @noDerivative Float) -> Float) -> Float {
  return derivative(at: 2, 3) { (x, y) in f(x * x, y) }
}
$ swift nondiff.swift
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/danielzheng/swift-dev/llvm-project/llvm/include/llvm/Support/Casting.h, line 264.
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret nondiff.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -target-sdk-version 10.15.4 -module-name nondiff
1.  Swift version 5.3-dev (LLVM 6049ecf8a0, Swift 28fba4f5e6)
2.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Guaranteed Passes } on SIL for nondiff.nondiff)
3.  While running pass #&#8203;51 SILModuleTransform "Differentiation".
4.  While canonicalizing `differentiable_function` SIL node   %17 = differentiable_function [parameters 0 1] [results 0] %16 : $@callee_guaranteed (Float, Float) -> Float // users: %38, %18
5.  While ...in SIL function "@$s7nondiffAAyS3f_SftXFF".
 for 'nondiff(_:)' (at nondiff.swift:3:1)
6.  While processing // differentiability witness for closure #&#8203;1 in nondiff(_:)
sil_differentiability_witness private [parameters 0 1] [results 0] @$s7nondiffAAyS3f_SftXFFS2f_SftcfU_ : $@convention(thin) (Float, Float, @differentiable @noescape @callee_guaranteed (Float, @noDerivative Float) -> Float) -> Float {
}

 on SIL function "@$s7nondiffAAyS3f_SftXFFS2f_SftcfU_".
 for expression at [nondiff.swift:4:31 - line:4:55] RangeText="{ (x, y) in f(x * x, y) "
7.  While generating VJP for SIL function "@$s7nondiffAAyS3f_SftXFFS2f_SftcfU_".
 for expression at [nondiff.swift:4:31 - line:4:55] RangeText="{ (x, y) in f(x * x, y) "
0  swift                    0x0000000111fbd8e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000111fbc868 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x0000000111fbdedd SignalHandler(int) + 285
3  libsystem_platform.dylib 0x00007fff686505fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338764712480
5  libsystem_c.dylib        0x00007fff68526808 abort + 120
6  libsystem_c.dylib        0x00007fff68525ac6 err + 0
7  swift                    0x0000000112488f33 swift::Decl::getLoc(bool) const (.cold.3) + 35
8  swift                    0x000000010ea54b6c swift::Decl::getLoc(bool) const + 188
9  swift                    0x000000010e49d925 swift::SILLocation::getSourceLoc() const + 37
10 swift                    0x000000010df2079a swift::autodiff::getValidLocation(swift::SILValue) + 42
11 swift                    0x000000010e0bdb1b swift::InFlightDiagnostic swift::autodiff::ADContext::emitNondifferentiabilityError<>(swift::SILValue, swift::autodiff::DifferentiationInvoker, swift::Diag<>) + 427
12 swift                    0x000000010df6fa35 swift::autodiff::VJPEmitter::visitApplyInst(swift::ApplyInst*) + 2725

Discovered while upstreaming test/AutoDiff/downstream/forward_mode_diagnostics.swift. This reproducer doesn't crash on tensorflow branch, only master branch.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@BradLarson
Copy link
Collaborator

This seems to produce a proper differentiability diagnostic now:

SR13046.swift:4:31: error: function is not differentiable
  return derivative(at: 2, 3) { (x, y) in f(x * x, y) }
                              ^~~~~~~~~~~~~~~~~~~~~~~~~
SR13046.swift:4:31: note: cannot differentiate with respect to a '@noDerivative' parameter
  return derivative(at: 2, 3) { (x, y) in f(x * x, y) }
                              ^

rather than causing an assertion failure, so I believe it is safe to close this out.

@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants