From 0ac4901ac5b438725e466f8f4ac8b9b13f266942 Mon Sep 17 00:00:00 2001 From: Daniil Kovalev Date: Wed, 20 Nov 2024 22:19:11 +0300 Subject: [PATCH] [AutoDiff][test] Use true and false literals instead of `1 == 1` and `1 == 0` After introducing BooleanLiteralFolding mandatory pass in c89df9ec985244ff5109b0a7852c086e39d8e5eb, true and false literals in some tests were changed to `1 == 1` and `1 == 0` with a comment that literals caused crash. At this point, using literals no longer causes crashes, so switch back to using true and false in such cases. --- ...8660-conflicting-debug-info-inlining.swift | 3 +-- ...mutating-functions-with-control-flow.swift | 3 +-- .../address_only_tangentvector.swift | 3 +-- .../validation-test/control_flow.swift | 22 +++++++------------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift b/test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift index a7fed3c2b502b..0ea0792a3baab 100644 --- a/test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift +++ b/test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift @@ -55,8 +55,7 @@ struct MyModel: Differentiable { property2 = localVar // `false` may instead be any expression that returns a `Bool`. - // TODO: cannot use literal `false` because it crashes - if 1 == 0 { + if false { localVar = member3 } } diff --git a/test/AutoDiff/compiler_crashers_fixed/issue-58123-mutating-functions-with-control-flow.swift b/test/AutoDiff/compiler_crashers_fixed/issue-58123-mutating-functions-with-control-flow.swift index bc7f6f5050594..98ee93a59acf6 100644 --- a/test/AutoDiff/compiler_crashers_fixed/issue-58123-mutating-functions-with-control-flow.swift +++ b/test/AutoDiff/compiler_crashers_fixed/issue-58123-mutating-functions-with-control-flow.swift @@ -62,8 +62,7 @@ struct BatchNorm: Layer { // Crash requires conformance to `Layer` @differentiable(reverse) func callAsFunction(_ input: Tensor) -> Tensor { var offset = self.offset - // TODO: cannot use literal `true` because it crashes - if 1 == 1 { // Crash requires `if true` + if true { // Crash requires `if true` offset += offset // Using `offset = offset + offset` stops the crash } return offset diff --git a/test/AutoDiff/validation-test/address_only_tangentvector.swift b/test/AutoDiff/validation-test/address_only_tangentvector.swift index e7c6ad1f60cf6..e62570ade1ff5 100644 --- a/test/AutoDiff/validation-test/address_only_tangentvector.swift +++ b/test/AutoDiff/validation-test/address_only_tangentvector.swift @@ -43,8 +43,7 @@ AddressOnlyTangentVectorTests.test("LoadableClassAddressOnlyTangentVector") { @differentiable(reverse) func conditional(_ s: LoadableClass) -> T { var tuple = (s, (s, s)) - // TODO: cannot use literal `false` because it crashes - if 1 == 0 {} + if false {} return tuple.1.0.stored } expectEqual(.init(stored: 1), gradient(at: LoadableClass(10), of: conditional)) diff --git a/test/AutoDiff/validation-test/control_flow.swift b/test/AutoDiff/validation-test/control_flow.swift index 915049b0a5236..e4a13f00481c4 100644 --- a/test/AutoDiff/validation-test/control_flow.swift +++ b/test/AutoDiff/validation-test/control_flow.swift @@ -66,12 +66,10 @@ ControlFlowTests.test("Conditionals") { func cond4_var(_ x: Float) -> Float { var outer = x - // TODO: cannot use literal `true` because it crashes - outerIf: if 1 == 1 { + outerIf: if true { var inner = outer inner = inner * x - // TODO: cannot use literal `false` because it crashes - if 1 == 0 { + if false { break outerIf } outer = inner @@ -388,9 +386,8 @@ ControlFlowTests.test("NestedConditionals") { @differentiable(reverse, wrt: self) // wrt only self is important func callAsFunction(_ input: Float) -> Float { var x = input - // TODO: cannot use literal `true` because it crashes - if 1 == 1 { - if 1 == 1 { + if true { + if true { // Function application below should make `self` have non-zero // derivative. x = x * w @@ -408,9 +405,8 @@ ControlFlowTests.test("NestedConditionals") { @differentiable(reverse, wrt: x) func TF_781(_ x: Float, _ y: Float) -> Float { var result = y - // TODO: cannot use literal `true` because it crashes - if 1 == 1 { - if 1 == 1 { + if true { + if true { result = result * x } } @@ -795,8 +791,7 @@ ControlFlowTests.test("ThrowingCalls") { func testComplexControlFlow(_ x: Float) -> Float { rethrowing({}) for _ in 0..(_ x: T) -> T { rethrowing({}) for _ in 0..<10 { - // TODO: cannot use literal `true` because it crashes - if 1 == 1 { + if true { rethrowing({}) } rethrowing({}) // non-active `try_apply`