From 5f5dd1f806e60719afa6860bede6320abc64beef Mon Sep 17 00:00:00 2001 From: Philip Turner Date: Fri, 17 Jun 2022 17:57:17 -0700 Subject: [PATCH 1/2] Add S4TF crasher test --- .../59467-failed-to-reconstruct-type.swift | 24 +++++++++++++++++++ .../59467-failed-to-reconstruct-type.swift | 19 +++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift create mode 100644 test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift diff --git a/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift b/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift new file mode 100644 index 0000000000000..44f2c3484d061 --- /dev/null +++ b/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift @@ -0,0 +1,24 @@ +// RUN: %target-swift-frontend -emit-ir -g -primary-file %s %S/Inputs/59467-failed-to-reconstruct-type.swift -module-name TensorFlow + +import _Differentiation + +@_semantics("autodiff.nonvarying") +func withoutDerivative() -> Tensor { + fatalError() +} + +func BatchNorm_doInference( + _ input: Tensor +) -> Tensor { + withoutDerivative() +} + +@differentiable(reverse) +func BatchNorm_callAsFunction(_ input: Tensor) -> Tensor { + BatchNorm_doInference(input) +} + +@differentiable(reverse) +func LayerNorm_callAsFunction(_ input: Tensor) -> Tensor { + rsqrt(input) +} diff --git a/test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift b/test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift new file mode 100644 index 0000000000000..debe867f37f59 --- /dev/null +++ b/test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift @@ -0,0 +1,19 @@ +import _Differentiation + +struct Tensor: Differentiable {} + +// `Tensor` could be defined in this test case's primary file and the crash +// would still happen. All that matters is that `LayerNorm_callAsFunction` and +// `rsqrt` are defined in separate files. + +@differentiable(reverse) +func rsqrt( _ x: Tensor) -> Tensor { + fatalError() +} + +@derivative(of: rsqrt) +func _vjpRsqrt(_ x: Tensor) -> ( + value: Tensor, pullback: (Tensor.TangentVector) -> (Tensor.TangentVector) +) { + fatalError() +} From 3fa5623c489028adfcf02186208fc4419d552c17 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Tue, 19 Jul 2022 20:07:05 +0200 Subject: [PATCH 2/2] Unbreak the test --- .../59467-failed-to-reconstruct-type.swift | 2 +- ...type.swift => 59467-failed-to-reconstruct-type-second.swift} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/AutoDiff/compiler_crashers_fixed/Inputs/{59467-failed-to-reconstruct-type.swift => 59467-failed-to-reconstruct-type-second.swift} (100%) diff --git a/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift b/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift index 44f2c3484d061..87109b56a4155 100644 --- a/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift +++ b/test/AutoDiff/compiler_crashers_fixed/59467-failed-to-reconstruct-type.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir -g -primary-file %s %S/Inputs/59467-failed-to-reconstruct-type.swift -module-name TensorFlow +// RUN: %target-swift-frontend -emit-ir -g -primary-file %s %S/Inputs/59467-failed-to-reconstruct-type-second.swift -module-name TensorFlow import _Differentiation diff --git a/test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift b/test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type-second.swift similarity index 100% rename from test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type.swift rename to test/AutoDiff/compiler_crashers_fixed/Inputs/59467-failed-to-reconstruct-type-second.swift