Skip to content

Conversation

@emirariemir
Copy link

Refactored AutoDiff test files that contains REQUIRES: shell by replacing the line:

// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil

with echo and cat commands:

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

to make it compatible with LLVM Lit internal shell.

Partially address #84407

…_type.swift file

Convert `sed` command with `echo` and `cat` commands to achieve the same logic for compatibility with LLVM Lit internal shell.
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.
@emirariemir emirariemir requested a review from asl as a code owner December 4, 2025 19:04
// 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.

@ramonasuncion
Copy link
Member

LGTM!

@ramonasuncion
Copy link
Member

ramonasuncion commented Dec 4, 2025

? @swift-ci please smoke test

@ramonasuncion
Copy link
Member

The bot clocked out for the day. 🪫🪫🪫

@hnrklssn
Copy link
Member

hnrklssn commented Dec 5, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Member

hnrklssn commented Dec 5, 2025

The bot clocked out for the day. 🪫🪫🪫

magic touch ;)

@emirariemir
Copy link
Author

Oh no, Windows platform test failed 😭 ! I cannot see the cause in details, it says:

No problems were identified. If you know why this problem occurred, please add a suitable Cause for it.

How do I identify the problem that makes the test fail?

@hnrklssn
Copy link
Member

hnrklssn commented Dec 5, 2025

Oh no, Windows platform test failed 😭 ! I cannot see the cause in details, it says:

No problems were identified. If you know why this problem occurred, please add a suitable Cause for it.

How do I identify the problem that makes the test fail?

These two tests failed:


Failed Tests (2):
  Swift(windows-x86_64) :: AutoDiff/SIL/differentiability_witness_function_inst.sil
  Swift(windows-x86_64) :: AutoDiff/SIL/sil_differentiability_witness.sil

If you click on the failed CI bot, and then go to "View as plain text" you can see the build and test log (where the above excerpt is from). I'm on the phone so I can't really see what the actual issue was, but if you cmd+f for those paths you should find the test output for them. Let me know if you need more help, I can take a look tomorrow. Normally when only Windows fails it's related to either newlines or path separators being different.

@emirariemir
Copy link
Author

If you click on the failed CI bot, and then go to "View as plain text" you can see the build and test log (where the above excerpt is from).

Thanks so much for the explanation! I’ll check the logs and try to fix it. If I run into issues, I’ll reach out again.

@hnrklssn
Copy link
Member

hnrklssn commented Dec 5, 2025

It looks like // IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] doesn't match @fooWJrSUUpSr = external dllimport global %swift.differentiability_witness, align 8 because of the extra dllimport on Windows. These tests were not running on Windows previously, since REQUIRES: shell is never fulfilled on Windows, so we'll have to make some small adjustments. Something like // IRGEN: @fooWJrSUUpSr = external {{(dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] should fix it.

@asl
Copy link
Contributor

asl commented Dec 5, 2025

It looks like // IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] doesn't match @fooWJrSUUpSr = external dllimport global %swift.differentiability_witness, align 8 because of the extra dllimport on Windows. These tests were not running on Windows previously, since REQUIRES: shell is never fulfilled on Windows, so we'll have to make some small adjustments. Something like // IRGEN: @fooWJrSUUpSr = external {{(dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] should fix it.

Yeah, this is what normally done in tests. Or just ignore everything between external and global, e.g.

// IRGEN: @fooWJrSUUpSr = external {{.*}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]]

@emirariemir
Copy link
Author

It looks like // IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] doesn't match @fooWJrSUUpSr = external dllimport global %swift.differentiability_witness, align 8 because of the extra dllimport on Windows. These tests were not running on Windows previously, since REQUIRES: shell is never fulfilled on Windows, so we'll have to make some small adjustments. Something like // IRGEN: @fooWJrSUUpSr = external {{(dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] should fix it.

Yeah, this is what normally done in tests. Or just ignore everything between external and global, e.g.

// IRGEN: @fooWJrSUUpSr = external {{.*}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+

Thanks for the explanation! I also checked the other failing test file, AutoDiff/SIL/sil_differentiability_witness.sil, and it looks like there is a similar Windows-specific mismatch there as well. The check // IRGEN-LABEL: @externalFn1WJrSpSr ={{( protected)?}} global { ptr, ptr } { ... does not match the Windows IR: @externalFn1WJrSpSr = dllexport global { ptr, ptr } ....

I believe this could be fixed in a similar way by allowing dllexport explicitly:

// IRGEN-LABEL: @externalFn1WJrSpSr ={{( dllexport)?( protected)?}} global { ptr, ptr } {...

But as @asl mentioned, it could also be fixed by ignoring everything between = and global:

// IRGEN-LABEL: @externalFn1WJrSpSr ={{.*}}global { ptr, ptr } {

But I couldn't figure out which is the best way to approach this. Allowing only the known platform differences seems safer to me, since a fully generic {{.*}} might hide unexpected attribute regressions. I am not sure if that could be a case so thats why I need further guidance before I proceed.

…ndows 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.
@emirariemir
Copy link
Author

It looks like // IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] doesn't match @fooWJrSUUpSr = external dllimport global %swift.differentiability_witness, align 8 because of the extra dllimport on Windows. These tests were not running on Windows previously, since REQUIRES: shell is never fulfilled on Windows, so we'll have to make some small adjustments. Something like // IRGEN: @fooWJrSUUpSr = external {{(dllimport)?}} global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]] should fix it.

I’ve updated the failing tests by adding optional dllimport and dllexport handling to the relevant FileCheck patterns, following the approach suggested by @hnrklssn. The changes are now up to date and ready for another review.

If you’d prefer {{.*}} approach, I can switch to that as well — happy to adjust based on feedback.

@hnrklssn
Copy link
Member

hnrklssn commented Dec 7, 2025

@swift-ci please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants