Skip to content

Function incorrectly marked as not differentiable #75776

@JaapWijnen

Description

@JaapWijnen

Description

The following code does not compile giving the following error diagnostic:

Function is not differentiable
Differentiated functions in '@inlinable' functions must be marked '@differentiable' or have a public '@derivative'; this is not possible with a closure, make a top-level function instead

This is incorrect however as the function itself is not a closure and is differentiable.

Reproduction

import _Differentiation

public struct Solution2<Thing: Differentiable & FloatingPoint>: Differentiable where Thing.TangentVector == Thing {
    @inlinable
    public static func optimization() -> Thing {
        var initial = Thing.zero
        
        let (_, delta) = valueWithGradient(at: initial, of: simulationWithLoss)
        
        initial.move(by: delta)
        
        return initial
    }
    
    @inlinable
    @differentiable(reverse)
    static func simulationWithLoss(input: Thing) -> Thing {
        return input // implementation
    }
}

Expected behavior

Compile without error

Environment

Apple Swift version 6.0-dev (LLVM 097782ee554d9fe, Swift 60bf038)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    AutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions