Skip to content

[AutoDiff] Use auto-generated locations for temporary allocations. #40503

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
Dec 11, 2021
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
10 changes: 6 additions & 4 deletions lib/SILOptimizer/Differentiation/TangentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void TangentBuilder::emitZeroIntoBuffer(SILLocation loc, SILValue buffer,
SILValue TangentBuilder::emitZero(SILLocation loc, CanType type) {
auto silType = getModule().Types.getLoweredLoadableType(
type, TypeExpansionContext::minimal(), getModule());
auto *alloc = createAllocStack(loc, silType);
auto tempAllocLoc = RegularLocation::getAutoGeneratedLocation();
auto *alloc = createAllocStack(tempAllocLoc, silType);
emitZeroIntoBuffer(loc, alloc, IsInitialization);
auto zeroValue = emitLoadValueOperation(
loc, alloc, LoadOwnershipQualifier::Take);
Expand Down Expand Up @@ -176,9 +177,10 @@ SILValue TangentBuilder::emitAdd(SILLocation loc, SILValue lhs, SILValue rhs) {
auto lhsCopy = emitCopyValueOperation(loc, lhs);
auto rhsCopy = emitCopyValueOperation(loc, rhs);
// Allocate buffers for inputs and output.
auto *resultBuf = createAllocStack(loc, type);
auto *lhsBuf = createAllocStack(loc, type);
auto *rhsBuf = createAllocStack(loc, type);
auto tempAllocLoc = RegularLocation::getAutoGeneratedLocation();
auto *resultBuf = createAllocStack(tempAllocLoc, type);
auto *lhsBuf = createAllocStack(tempAllocLoc, type);
auto *rhsBuf = createAllocStack(tempAllocLoc, type);
// Initialize input buffers.
emitStoreValueOperation(loc, lhsCopy, lhsBuf,
StoreOwnershipQualifier::Init);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-build-swift %s
// RUN: %target-swift-frontend -c -g -Xllvm -verify-di-holes=true %s

// SR-15566: Differentiable functions with control flow yield an assertion failure: "location is a VarDecl, but SILDebugVariable is empty"

import _Differentiation

public struct Test: Differentiable {
public var v1: [[Float]]

@differentiable(reverse)
public init(v1: [[Float]]) {
if v1.count != 2 {
fatalError("Mismatched counts")
}
self.v1 = v1
}
}

// Assertion failed: ((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) && "location is a VarDecl, but SILDebugVariable is empty"), function createAllocStack, file SILBuilder.h, line 389.
2 changes: 1 addition & 1 deletion test/AutoDiff/validation-test/array.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
// RUN: %target-run-simple-swift

// REQUIRES: executable_test

Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/validation-test/optional.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
// RUN: %target-run-simple-swift

// REQUIRES: executable_test

Expand Down
4 changes: 2 additions & 2 deletions test/AutoDiff/validation-test/optional_property.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -enable-lexical-borrow-scopes=false -module-name null -o /dev/null 2>&1 %s | %FileCheck %s
// RUN: %target-run-simple-swift
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -module-name null -o /dev/null 2>&1 %s | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: asserts
Expand Down