Skip to content

Tolerate spurious emit-module in singleFileCompile on all non-Darwin hosts - #1849

Merged
jakepetroules merged 1 commit into
swiftlang:mainfrom
jakepetroules:fix-singlefilecompile-emit-module-flake
Oct 7, 2026
Merged

jakepetroules merged 1 commit into
swiftlang:mainfrom
jakepetroules:fix-singlefilecompile-emit-module-flake

Conversation

@jakepetroules

Copy link
Copy Markdown
Collaborator

BuildCommandTests.singleFileCompile has been nondeterministically failing on non-Darwin hosts with:

found unexpected task matching conditions '[]', found: Task(forTarget: aLibrary, ruleInfo: ["SwiftEmitModule", "normal", "x86_64", "Emitting module for aLibrary"])

Root cause

  • Building only CFile.o legitimately depends on the target's swift-generated-headers gate, because a C file may include aLibrary-Swift.h. So the Swift driver is re-planned and decides whether the emit-module job is up to date.
  • With no compile jobs needed, the driver skips emit-module only if every Swift source is strictly older than the oldest emit-module output (FirstWaveComputer.computeCanSkipEmitModuleTasks).
  • On non-Darwin platforms, swift-driver truncates modification times to whole seconds. When SwiftFile.swift and the first build's module outputs are written in the same second (they're about 120ms apart in this test), they compare equal, so emit-module is re-run.

I confirmed this on Linux by instrumenting the driver: the test failed in exactly the runs where the source and outputs shared a whole-second timestamp, and passed when they straddled a second boundary. macOS keeps nanosecond precision and never hits it.

Change

The existing workaround only checked runDestination == .linux, so the test was still flaky on FreeBSD (e.g. in CI for #638). This applies it to every non-macOS host and replaces the "needs to be investigated" FIXME with the explanation.

The underlying fix is swiftlang/swift-driver#2228. With that change, this test passed 15/15 runs on Linux with the workaround disabled, versus failing roughly two thirds of the time before. The workaround can be removed once CI picks up a driver with that fix.

…hosts

The C file compile depends on the target's Swift generated headers, so the
Swift driver is re-planned and decides whether emit-module is up to date by
checking that every source is strictly older than every emit-module output.
swift-driver truncates modification times to whole seconds on non-Darwin
platforms, so when SwiftFile.swift and the module outputs from the first
build are written within the same second, emit-module is re-run.

The existing workaround only applied to Linux, so the test was still flaky
on FreeBSD. Apply it to every non-macOS host, and document the root cause
in place of the FIXME. The underlying driver fix is
swiftlang/swift-driver#2228.
@jakepetroules

Copy link
Copy Markdown
Collaborator Author

@swift-ci test

@jakepetroules
jakepetroules enabled auto-merge (rebase) October 7, 2026 18:17
@mhrawdon

mhrawdon commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@swift-ci test macOS

1 similar comment
@jakepetroules

Copy link
Copy Markdown
Collaborator Author

@swift-ci test macOS

@jakepetroules
jakepetroules merged commit 080a733 into swiftlang:main Oct 7, 2026
37 of 41 checks passed
@jakepetroules
jakepetroules deleted the fix-singlefilecompile-emit-module-flake branch October 7, 2026 22:40
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.

2 participants