Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: echo "import _Differentiation" > %t/tmp_preamble
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not recall all all restrictions of internal shell, does one of the following work instead?

cat <(echo "import _Differentiation") tmp.sil > tmp_fixed.sil
(echo "import _Differentiation"; cat tmp.sil) > tmp_fixed.sil

or even

echo "import _Differentiation" | cat - tmp.sil > tmp_fixed.sil

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the <(...) syntax is only supported by BASH and not by internal shell, so that test would fail in Windows CI or shells other than Bash. I think keeping it as two atomic, standard commands is the most robust approach (thanks to @hnrklssn for suggesting this approach in the first place):

// RUN: echo "import _Differentiation" > %t/tmp_fixed.sil
// RUN: cat %t/tmp.sil >> %t/tmp_fixed.sil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@ramonasuncion ramonasuncion Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chiming in here, lit's shell doesn't give you much to work with. You can't use process substitution and you can't use echo if it's piped to another command. At least with the two line approach it keeps things simple.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipes are supported in general, the one limitation is that the built-in version of echo does not support pipes. Another option would be to create a file test/AutoDiff/SIL/import_Differentiation.txt containing import _Differentiation, and use cat %S/import_Differentiation.txt %t/tmp.sil > %t/tmp_fixed.sil. No strong preference from my end though.

// RUN: cat %t/tmp_preamble %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt -sil-print-types %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck %s

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

sil_stage raw

import Swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@

// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: echo "import _Differentiation" > %t/tmp_preamble
// RUN: cat %t/tmp_preamble %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck %s

// IRGen test.

// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=Simplification -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
// NOTE: `%target-cpu`-specific FileCheck lines exist because lowered function types in LLVM IR differ between architectures.

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

sil_stage raw

import Swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.sil -module-name main
// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: echo "import _Differentiation" > %t/tmp_preamble
// RUN: cat %t/tmp_preamble %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck %s

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

sil_stage raw

import Swift
Expand Down
7 changes: 2 additions & 5 deletions test/AutoDiff/SIL/differentiable_function_inst.sil
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@

// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: echo "import _Differentiation" > %t/tmp_preamble
// RUN: cat %t/tmp_preamble %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt -sil-print-types %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck %s --check-prefix=CHECK-SIL

// IRGen test.

// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=CHECK-IRGEN

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

// Would need to update for arm64e.
// UNSUPPORTED: CPU=arm64e

Expand Down
7 changes: 2 additions & 5 deletions test/AutoDiff/SIL/sil_differentiability_witness.sil
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@

// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: echo "import _Differentiation" > %t/tmp_preamble
// RUN: cat %t/tmp_preamble %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck --check-prefix=ROUNDTRIP %s

// IRGen test.

// RUN: %target-swift-frontend -emit-ir %s | %FileCheck --check-prefix=IRGEN %s

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

sil_stage raw

import Builtin
Expand Down