Skip to content

Honor fallbackAfterTimeout: false when inferring a file's target - #2791

Open
setouchi-h wants to merge 2 commits into
swiftlang:mainfrom
setouchi-h:respect-fallback-after-timeout-for-target-inference
Open

setouchi-h wants to merge 2 commits into
swiftlang:mainfrom
setouchi-h:respect-fallback-after-timeout-for-target-inference

Conversation

@setouchi-h

@setouchi-h setouchi-h commented Oct 8, 2026 •

Copy link
Copy Markdown

buildSettingsInferredFromMainFile first infers the document's target and then asks the build server for the build
settings in that target. The second step honors fallbackAfterTimeout, but since #2322 the first step always runs
with a buildSettingsTimeout and returns fallback settings when it fires, even if the caller passed
fallbackAfterTimeout: false.

This bit me in swiftlang/swift-syntax#3460: SwiftSourceKitPluginTests.testCompletionImportDepth failed on Windows CI (https://ci-external.swift.org/job/swift-syntax-PR-windows/4967/) because buildTarget/sources took 5s instead of a
few milliseconds, so code completion ran with -sdk-only fallback arguments. workspace/_sourceKitOptions with
allowFallbackSettings: false and the other callers that pass fallbackAfterTimeout: false have the same problem.

Await canonicalTarget(for:) directly if fallbackAfterTimeout is false, which is what we did before #2322. The
fallbackAfterTimeout: true path and the handling of files the build server doesn't know about are unchanged. The new test fails without the fix and passes with it.

The second commit fixes a typo in the allowFallbackSettings docs, which described the false case but said true.

`buildSettingsInferredFromMainFile` infers the document's target before it
asks the build server for the build settings in that target. Since swiftlang#2322
the target inference is wrapped in `withTimeoutResult` and returns fallback
build settings when `buildTarget/sources` takes longer than
`buildSettingsTimeout`, even if the caller passed
`fallbackAfterTimeout: false`. Only the second step honored the flag.

This showed up in swiftlang/swift-syntax#3460, where
`SwiftSourceKitPluginTests.testCompletionImportDepth` failed on Windows CI
because `buildTarget/sources` took 5s and the test ended up with `-sdk`-only
fallback arguments. The same applies to `workspace/_sourceKitOptions` with
`allowFallbackSettings: false`, `OnDiskDocumentManager` and the
`compileCommand(for:fallbackAfterTimeout: false)` calls in
`SwiftLanguageService`.

Await `canonicalTarget(for:)` directly when `fallbackAfterTimeout` is
false, which is what we did before swiftlang#2322. The `fallbackAfterTimeout: true`
path and the handling of files the build server doesn't know about are
unchanged.
The second sentence of the `allowFallbackSettings` docs described the
`false` case but said `true`.
@setouchi-h
setouchi-h force-pushed the respect-fallback-after-timeout-for-target-inference branch from 88bad83 to 06154ea Compare October 8, 2026 08:21
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.

1 participant