Skip to content

[AutoDiff] Fix forward-mode differentiation ownership verification failure. #33898

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

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/SILOptimizer/Differentiation/LinearMapInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,6 @@ bool LinearMapInfo::shouldDifferentiateInstruction(SILInstruction *inst) {
isa<EndBorrowInst>(inst) || isa<DeallocationInst>(inst) ||
isa<DestroyValueInst>(inst) || isa<DestroyAddrInst>(inst))
return true;
// Should differentiate any instruction that creates an SSA copy of an
// active operand.
if (isa<CopyValueInst>(inst))
return true;
Comment on lines -540 to -543
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I tried to track down the origin of this code. I found it was added by this commit, though it existed in a different form prior to the commit.

I think this special-case for copy_value was just an oversight/latent error.

}
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions test/AutoDiff/validation-test/forward_mode_simple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1389,4 +1389,15 @@ ForwardModeTests.test("ApplyNonActiveIndirectResult") {
expectEqual(1.0, derivative(at: 2, in: applyNonactiveArgumentActiveIndirectResult))
}

ForwardModeTests.test("SR-13530") {
// SR-13530: Test "leaked owned value" ownership verification failure related
// to differential generation for `copy_value` instruction.
@differentiable
func SR_13530(_ x: NonresilientTracked<Float>) -> NonresilientTracked<Float> {
precondition(x >= 0)
return x
}
expectEqual(1, derivative(at: 2, in: SR_13530))
}

runAllTests()