Skip to content

[AutoDiff] Revisit differentiation of struct instruction with aggregate adjoint value. #25234

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
Jun 4, 2019
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
7 changes: 5 additions & 2 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4541,8 +4541,11 @@ class AdjointEmitter final : public SILInstructionVisitor<AdjointEmitter> {
break;
}
case AdjointValueKind::Aggregate: {
llvm_unreachable("Unhandled. Are you trying to differentiate a "
"memberwise initializer?");
// Note: All user-called initializations go through the calls to the
// initializer, and synthesized initializers only have one level of struct
// formation which will not result into any aggregate adjoint valeus.
llvm_unreachable("Aggregate adjoint values should not occur for `struct` "
"instructions");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/AutoDiff/simple_math.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ SimpleMathTests.test("StructMemberwiseInitializer") {

let 𝛁foo = pullback(at: Float(4), in: { input -> Foo in
let foo = Foo(stored: input)
return foo + foo
let foo2 = foo + foo
return Foo(stored: foo2.stored)
})(Foo.TangentVector(stored: 1))
expectEqual(2, 𝛁foo)

Expand Down