Skip to content

[AutoDiff] Fix PullbackCloner tangent value category mismatch crash #33514

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
Aug 18, 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
1 change: 1 addition & 0 deletions lib/SIL/IR/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ static CanSILFunctionType getAutoDiffDifferentialType(
// result's convention is indirect.
if (tl.isAddressOnly() && !isIndirectFormalResult(origResConv)) {
switch (origResConv) {
case ResultConvention::Unowned:
case ResultConvention::Owned:
return ResultConvention::Indirect;
default:
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Differentiation/PullbackCloner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ bool PullbackCloner::Implementation::runForSemanticMemberGetter() {

// Switch based on the base tangent struct's value category.
// TODO(TF-1255): Simplify using unified adjoint value data structure.
switch (tangentVectorSILTy.getCategory()) {
switch (getTangentValueCategory(origSelf)) {
case SILValueCategory::Object: {
auto adjResult = getAdjointValue(origEntry, origResult);
switch (adjResult.getKind()) {
Expand Down Expand Up @@ -2455,7 +2455,7 @@ bool PullbackCloner::Implementation::runForSemanticMemberGetter() {
if (field == tanField) {
// Switch based on the property's value category.
// TODO(TF-1255): Simplify using unified adjoint value data structure.
switch (origResult->getType().getCategory()) {
switch (getTangentValueCategory(origResult)) {
case SILValueCategory::Object: {
auto adjResult = getAdjointValue(origEntry, origResult);
auto adjResultValue = materializeAdjointDirect(adjResult, pbLoc);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-build-swift %s
// REQUIRES: asserts

// SR-13411: Semantic member getter pullback generation crash due to tangent value category mismatch

import _Differentiation

struct Dense: Differentiable {
@differentiable
var bias: Float?
}