From 5e44c0441717894779563dd7bfb77ac35c313ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Ar=C4=B1?= Date: Thu, 4 Dec 2025 21:24:21 +0300 Subject: [PATCH 1/4] [Test][AutoDiff] Replace sed with echo/cat in sil_differentiability_witness.sil file --- test/AutoDiff/SIL/sil_differentiability_witness.sil | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/AutoDiff/SIL/sil_differentiability_witness.sil b/test/AutoDiff/SIL/sil_differentiability_witness.sil index b050775c91c4a..95fc45fa9d6df 100644 --- a/test/AutoDiff/SIL/sil_differentiability_witness.sil +++ b/test/AutoDiff/SIL/sil_differentiability_witness.sil @@ -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 From 8f5d318bb9d47dff206d40992f9f4c1fbbc3aa20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Ar=C4=B1?= Date: Thu, 4 Dec 2025 21:39:08 +0300 Subject: [PATCH 2/4] [Test][AutoDiff] Replace sed with echo/cat in differentiable_function_type.swift file Convert `sed` command with `echo` and `cat` commands to achieve the same logic for compatibility with LLVM Lit internal shell. --- .../SIL/Serialization/differentiable_function_type.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/AutoDiff/SIL/Serialization/differentiable_function_type.swift b/test/AutoDiff/SIL/Serialization/differentiable_function_type.swift index dc467d0d6a599..26b5025f98bf6 100644 --- a/test/AutoDiff/SIL/Serialization/differentiable_function_type.swift +++ b/test/AutoDiff/SIL/Serialization/differentiable_function_type.swift @@ -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 +// 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 From 30451f9e7706dae77925a46474f9ec837f863cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Ar=C4=B1?= Date: Thu, 4 Dec 2025 21:56:06 +0300 Subject: [PATCH 3/4] [Test][AutoDiff] Replace sed with echo/cat for Lit shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert the existing `sed` commands in `AutoDiff` test files that use `REQUIRES: shell` into equivalent logic using `echo` and `cat` for compatibility with LLVM Lit’s internal shell. --- .../SIL/differentiability_witness_function_inst.sil | 7 ++----- .../differentiability_witness_function_inst_transpose.sil | 7 ++----- test/AutoDiff/SIL/differentiable_function_inst.sil | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/test/AutoDiff/SIL/differentiability_witness_function_inst.sil b/test/AutoDiff/SIL/differentiability_witness_function_inst.sil index 0e702cd253122..6def26b0ae409 100644 --- a/test/AutoDiff/SIL/differentiability_witness_function_inst.sil +++ b/test/AutoDiff/SIL/differentiability_witness_function_inst.sil @@ -10,7 +10,8 @@ // 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. @@ -18,10 +19,6 @@ // 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 diff --git a/test/AutoDiff/SIL/differentiability_witness_function_inst_transpose.sil b/test/AutoDiff/SIL/differentiability_witness_function_inst_transpose.sil index b085dc031bcbf..768ebac69e74f 100644 --- a/test/AutoDiff/SIL/differentiability_witness_function_inst_transpose.sil +++ b/test/AutoDiff/SIL/differentiability_witness_function_inst_transpose.sil @@ -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 diff --git a/test/AutoDiff/SIL/differentiable_function_inst.sil b/test/AutoDiff/SIL/differentiable_function_inst.sil index c990cf3a0ac62..31d3e7cf8b764 100644 --- a/test/AutoDiff/SIL/differentiable_function_inst.sil +++ b/test/AutoDiff/SIL/differentiable_function_inst.sil @@ -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 From 6e934eca9bbe40c24cfdabe909dab70fbebf577b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Ar=C4=B1?= Date: Sun, 7 Dec 2025 12:58:17 +0300 Subject: [PATCH 4/4] [Test][AutoDiff] Make differentiability witness checks tolerant of Windows dllimport and dllexport This change updates the affected `IRGEN` and `IRGEN-LABEL` checks to explicitly allow optional `dllimport` and `dllexport` attributes using regex patterns, while keeping the rest of the checks strict. --- .../differentiability_witness_function_inst.sil | 14 +++++++------- .../AutoDiff/SIL/sil_differentiability_witness.sil | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/AutoDiff/SIL/differentiability_witness_function_inst.sil b/test/AutoDiff/SIL/differentiability_witness_function_inst.sil index 6def26b0ae409..4900ccaa780a9 100644 --- a/test/AutoDiff/SIL/differentiability_witness_function_inst.sil +++ b/test/AutoDiff/SIL/differentiability_witness_function_inst.sil @@ -80,13 +80,13 @@ bb0: // CHECK: {{%.*}} = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 // CHECK: } -// IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] -// IRGEN: @fooWJrSSUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] -// IRGEN: @barWJrSUUpSUr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] -// IRGEN: @barWJrSSUpSSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] -// IRGEN: @generic16_Differentiation14DifferentiableRzlWJrSUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] -// IRGEN: @generics18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlWJrSSpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] -// IRGEN: @generic16_Differentiation14DifferentiableRz13TangentVector{{.*}}WJrSSpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @fooWJrSUUpSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] +// IRGEN: @fooWJrSSUpSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @barWJrSUUpSUr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @barWJrSSUpSSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @generic16_Differentiation14DifferentiableRzlWJrSUpSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @generics18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlWJrSSpSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] +// IRGEN: @generic16_Differentiation14DifferentiableRz13TangentVector{{.*}}WJrSSpSr = external{{( dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT]] // IRGEN-LABEL: define {{.*}} @test_derivative_witnesses() diff --git a/test/AutoDiff/SIL/sil_differentiability_witness.sil b/test/AutoDiff/SIL/sil_differentiability_witness.sil index 95fc45fa9d6df..2890089974f39 100644 --- a/test/AutoDiff/SIL/sil_differentiability_witness.sil +++ b/test/AutoDiff/SIL/sil_differentiability_witness.sil @@ -51,7 +51,7 @@ sil_differentiability_witness [reverse] [parameters 0] [results 0] @externalFn1 // ROUNDTRIP: vjp: @AD__externalFn1__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) // ROUNDTRIP: } -// IRGEN-LABEL: @externalFn1WJrSpSr ={{( protected)?}} global { ptr, ptr } { +// IRGEN-LABEL: @externalFn1WJrSpSr ={{( dllexport)?( protected)?}} global { ptr, ptr } { // IRGEN-SAME: @AD__externalFn1__jvp_src_0_wrt_0 // IRGEN-SAME: @AD__externalFn1__vjp_src_0_wrt_0 // IRGEN-SAME: } @@ -75,7 +75,7 @@ sil_differentiability_witness [reverse] [parameters 0] [results 0] @externalFn2 // ROUNDTRIP: vjp: @AD__externalFn2__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) // ROUNDTRIP: } -// IRGEN-LABEL: @externalFn2WJrSpSr ={{( protected)?}} global { ptr, ptr } { +// IRGEN-LABEL: @externalFn2WJrSpSr ={{( dllexport)?( protected)?}} global { ptr, ptr } { // IRGEN-SAME: @AD__externalFn2__jvp_src_0_wrt_0 // IRGEN-SAME: @AD__externalFn2__vjp_src_0_wrt_0 // IRGEN-SAME: } @@ -122,7 +122,7 @@ sil_differentiability_witness [reverse] [parameters 0] [results 0] @foo : $@conv // ROUNDTRIP: vjp: @AD__foo__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) // ROUNDTRIP: } -// IRGEN-LABEL: @fooWJrSpSr ={{( protected)?}} global { ptr, ptr } { +// IRGEN-LABEL: @fooWJrSpSr ={{( dllexport)?( protected)?}} global { ptr, ptr } { // IRGEN-SAME: @AD__foo__jvp_src_0_wrt_0 // IRGEN-SAME: @AD__foo__vjp_src_0_wrt_0 // IRGEN-SAME: }