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-12559] @derivative attribute type-checking crash with -parse-stdlib #55003

Closed
dan-zheng opened this issue Apr 10, 2020 · 1 comment
Closed
Assignees
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-12559
Radar None
Original Reporter @dan-zheng
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff, CompilerCrash
Assignee @dan-zheng
Priority Medium

md5: c6f00eaea2463753ead497751f503bc3

Issue Description:

import _Differentiation

struct AnyDerivative: Differentiable {
  init<T>(_ base: T) {}

  @derivative(of: init)
  static func _vjpInit<T: Differentiable>(
    _ base: T
  ) -> (value: AnyDerivative, pullback: (AnyDerivative) -> T.TangentVector) {
    fatalError()
  }

  typealias TangentVector = AnyDerivative
}

This program is not valid, but the compiler shouldn't crash nonetheless.

$ swiftc -parse-stdlib anyd3.swift
Assertion failed: (resultTan && "Original result has no tangent space?"), function getAutoDiffDerivativeFunctionLinearMapType, file /Users/danielzheng/swift-merge/swift/lib/AST/Type.cpp, line 5190.
Stack dump:

1.  Swift version 5.3-dev (LLVM 33154ab6f1, Swift 42a4748532)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "anyd3.swift")
3.  While type-checking 'AnyDerivative' (at anyd3.swift:3:1)
4.  While type-checking '_vjpInit(_:)' (at anyd3.swift:7:3)
0  swift                    0x000000010749b0b5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010749a068 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010749b6ac SignalHandler(int) + 268
3  libsystem_platform.dylib 0x00007fff6deebb5d _sigtramp + 29
4  libsystem_platform.dylib 0x00000000000056d0 _sigtramp + 18446603338671823760
5  libsystem_c.dylib        0x00007fff6dda56a6 abort + 127
6  libsystem_c.dylib        0x00007fff6dd6e20d basename_r + 0
7  swift                    0x00000001079ae5b3 swift::AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(swift::IndexSubset*, swift::AutoDiffLinearMapKind, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, bool) (.cold.2) + 35
8  swift                    0x00000001040aa41b swift::AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(swift::IndexSubset*, swift::AutoDiffLinearMapKind, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, bool) + 1451
9  swift                    0x0000000103c05f26 swift::ASTVisitor<(anonymous namespace)::AttributeChecker, void, void, void, void, void, void>::visit(swift::DeclAttribute*) + 40022

The crash occurs because checking for a Differentiable conformance during type-checking is not sufficient, we must also check for an invalid associated type:

(lldb) p valueResultConf.dump()
(normal_conformance type=AnyDerivative protocol=Differentiable
  (assoc_type req=TangentVector type=<<error type>>))

I tried to find a reproducer that doesn't use -parse-stdlib but failed. Fixing this issue at least resolves a potential stdlib crasher.

@dan-zheng
Copy link
Collaborator Author

Done in #30936

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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

2 participants