Skip to content

[AutoDiff] Pullbacks w/ loops can segfault #68392

Closed
@jkshtj

Description

@jkshtj

Description
Recently we fixed an issue in the Autodiff runtime due to which PBs w/ loops used to leak memory. A fix for the issue was merged in #67944. While validating the fix on our internal test suite we uncovered another memory related bug (a double free) because of which certain pullbacks w/ loops can segfault.

Below is a minimal reproducer for the issue.

import _Differentiation

@differentiable(reverse) func B(x: Float) -> Float {
    var y = x + 1
    for _ in 0 ..< 1 {}
    return y
}

func f() {
    let (_, pb) = valueWithPullback(at: 1.0, of: B)
    pb(21.0)
}

f()

Running the above program leads to a segfault.

Expected Behavior
The program should not segfault and pullback of B should be runnable multiple times.

Metadata

Metadata

Assignees

Labels

AutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.run-time crashBug → crash: Swift code crashed during executionruntimeThe Swift Runtimeswift 5.9

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions