Skip to content

[SR-14235] [AutoDiff] Cross-file differentiation error: derivative configuration not registered for @derivative attribute  #55170

@dan-zheng

Description

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

md5: 1c36955f37f690185a211308ac4034a9

Issue Description:

// a.swift
@differentiable
func crossFileDerivativeAttr<T: DifferentiableTensorProtocol>(
  _ input: T
) -> T {
  return input.identityDerivativeAttr()
}
import _Differentiation

protocol DifferentiableTensorProtocol: Differentiable {}

extension DifferentiableTensorProtocol {
  func identityDerivativeAttr() -> Self { self }

  // Test cross-file `@derivative` attribute.
  @derivative(of: identityDerivativeAttr)
  func vjpIdentityDerivativeAttr() -> (
    value: Self, pullback: (TangentVector) -> TangentVector
  ) {
    fatalError()
  }
}

The error occurs because AbstractFunctionDecl::getDerivativeConfigurations is not sufficiently requestified to type-check @derivative attributes in other files.

$ swiftc a.swift b.swift
a.swift:20:16: error: expression is not differentiable
  return input.identityDerivativeAttr()
               ^
a:20:16: note: cannot differentiate functions that have not been marked '@differentiable' and that are defined in other files
  return input.identityDerivativeAttr()
               ^

Metadata

Metadata

Assignees

Labels

AutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfmultiple filesFlag: An issue whose reproduction requires multiple filesserializationArea → compiler: Serialization & deserializationtype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions