Commit Graph

151 Commits

Author SHA1 Message Date
Steven Wu
af6270ce6a Merge pull request #87208 from cachemeifyoucan/eng/PR-170007480
[ExplicitModule] Teach scanner emit loaded module trace
2026-02-19 15:25:59 -08:00
Qiongsi Wu
bfc8a842a7 [DependencyScanning] Reenable Clang Module Dependency Scanning through the Shared Clang Compiler Instance (#87319)
This PR enables the lookup using shared compiler instance since
https://github.com/llvm/llvm-project/pull/178542 (and
https://github.com/swiftlang/llvm-project/pull/12245) fixed the
incorrect diagnostics coming from the shared compiler instance.

Fixes rdar://136303612.
2026-02-19 13:36:31 -08:00
Steven Wu
7fdf642819 [ExplicitModule] Teach scanner emit loaded module trace
During explicit module build, teach dependency scanner to emit the
module trace file instead of each following compile job command. This
reduces the duplicated info, and allows supporting fully cached build
that only loads module from CAS thus cannot produce the path to the
original module file on disk.

rdar://170007480
2026-02-18 09:10:08 -08:00
Steven Wu
17d969924c [SDKInfo] Fix SDKInfo loading to use correct VFS
Partially revert https://github.com/swiftlang/swift/pull/86309. Keep the
SDKInfo parsing in the ASTContext separately from the search path
configuration. This allows the availablity checking to load SDKSettings
from the correct VFS.

rdar://169886913
2026-02-09 15:03:53 -08:00
Hiroshi Yamauchi
36be4d294e Remove Clang CASFS (#86973) 2026-02-05 19:32:08 -08:00
Steven Wu
1852967fcf [Caching] Support -const-gather-protocols-file correctly
Previously, const-values output is not supported correctly as it is not
captured correctly as a dependency. The load of the input JSON file is
loaded via file system directly, that can cause issues like:
* False cache hit when the file is changed
* Cannot be prefix mapped to allow distributed caching

Try to support the input file by:
* Correctly capture the input
* Create a new driver flag `-const-gather-protocols-list` that can do
  path remapping correctly in swift-driver

rdar://169109358
2026-01-30 13:14:33 -08:00
Artem Chikin
966874a68e Merge pull request #86091 from artemcm/RemoveRedundantNegativeSwiftLookups
[Dependency Scanning] Add caching of unsuccessful Swift dependency lookups
2026-01-26 18:06:59 +00:00
Qiongsi Wu
8a7fbc5ecf [Dependency Scanning] Use clang dependency scanning tool's old by-name lookup API (#86733)
https://github.com/swiftlang/swift/pull/85555 taught Swift to use a
shared clang compiler instance that is initialized once and reused for
multiple by-name lookups. This unfortunately led to a few internal
project build failures.

This PR reverts back to use clang dependency scanning tool's old by-name
lookup APIs while we investigate the failures.

rdar://168709914
2026-01-23 14:24:29 -08:00
Artem Chikin
ad3d2d8aa5 Add caching of unsuccessful Swift dependency lookups
Use it to avoid unnecessary re-queries of Swift dependencies during a given scanning action.

Refactor 'hasSwiftDependency' API into 'hasQueriedSwiftDependency' to instead report whether or not the cache has recorded a prior lookup of a given Swift dependency.
2026-01-22 12:19:27 +00:00
Ian Anderson
60f2c405d0 Merge pull request #86309 from ian-twilightcoder/system-prefix
[Frontend][Darwin] Use the system prefix from SDK when constructing the default search paths
2026-01-10 00:03:58 -08:00
Artem Chikin
9c97a6fc3a Merge pull request #86101 from artemcm/RemoveDuplicateClangLookups
[Dependency Scanning] Re-use cached queried Clang dependency info in subsequent scanning stages
2026-01-09 20:15:07 -08:00
Ian Anderson
48ab4b0595 [Frontend][Darwin] Use the system prefix from SDK when constructing the default search paths
Some Darwin platforms like DriverKit use a system prefix on all of their search paths. Even though DriverKit isn't supported, add support to get the system prefix from SDKSettings when constructing the default search paths.

This requires the DarwinSDKInfo to be gotten earlier in CompilerInvocation, pass that down to ASTContext through CompilerInstance.

-platform-availability-inheritance-map-path is no longer needed to support visionOS in tests, remove that and its supporting code that gets an alternative DarwinSDKInfo.

rdar://166277280
2026-01-09 12:41:32 -08:00
Steven Wu
d7fa48629e Merge pull request #86390 from cachemeifyoucan/eng/PR-167760262
[DependencyScanner] Fix non-deterministic failures
2026-01-09 08:26:06 -08:00
Steven Wu
6b3b6608b6 Merge pull request #86363 from cachemeifyoucan/eng/PR-167707148
[Caching][DependencyScan] Fix main module header chaining
2026-01-08 14:46:15 -08:00
Steven Wu
a9aa57ee0b Reapply "[DependencyScan] Correct setup clang VFS for dependency scanning"
This reverts commit e60ae24052 and fix
non-deterministic failures introduced by the commit.

Fix two issues when attempting to testing parallel scanning using
`swift-scan-test` tools:
* Make sure the BumpPtrAllocator in ScanningService is thread-safe so
  there are no race condition when a new slab is allocated.
* Make sure the output of `swift-scan-test` only written from one
  thread. This prevents some race conditions when writing to the same
  raw_fd_ostream.

rdar://167760262
2026-01-08 14:14:22 -08:00
Steven Wu
e60ae24052 Revert "[DependencyScan] Correct setup clang VFS for dependency scanning"
This reverts commit e0e69f7ac0. This
causes flaky tests ScanDependencies/scanner_api_working_dir.swift.

rdar://167742034
2026-01-08 08:14:23 -08:00
Steven Wu
7b4c2f37e5 [Caching][DependencyScan] Fix main module header chaining
Fix a programming mistake when chaining bridging header for the main
module. Main module never has the binary module, thus it always need to
chain the bridging header content directly without falling back to
embedded binary module. Previously, the scanner was wrongly error out
because it failed to locate the binary module for main module.

rdar://167707148
2026-01-07 20:55:00 -08:00
Steven Wu
e0e69f7ac0 [DependencyScan] Correct setup clang VFS for dependency scanning
Currently, dependency scanner is not reporting the redirecting files
that are baked inside swift-frontend for platform support. This causes
dependency scanner returns virtual path for those files, and
swift-driver/build-system will not be able to correct validate the files
on incremental build, causing incremental build to be almost clean
builds.

This behavior issue is caused by the dependency scanning file system
layer inside clang dependency scanner that caches stats. If the
redirecting files are created underneath the layer, the real path is
lost. This fixes the issue by moving the redirecting files above the
caching layer using `-ivfsoverlay` option.

In addition to that, this commit also unifies how clang importer and
clang dependency scanner initiate the VFS, making the logic much
simpler.
2026-01-07 10:00:25 -08:00
Artem Chikin
195bc1e6d6 [Dependency Scanning] Re-use cached queried Clang dependency info in subsequent scanning stages
Dependency Scanning is recursive over discovered Swift module overlays and cross-import overlays. In the main 'resolveImportedModuleDependencies' routine, after all Swift and Clang dependencies of the main module are discovered, the scanner looks up Swift overlays for discovered Clang modules. For each such Swift overlay, the scanner will then proceed to call 'resolveImportedModuleDependencies' on the overlay module.

On these subsequent recursive calls to 'resolveImportedModuleDependencies', Clang dependency resolution will re-query all imports of the overlay module which do not resolve to Swift modules, even if they had been queried previously in a parent invocation. This change adds the ability to re-use previously-queried-and-cached Clang module dependency information by having the dependency cache also store the set of visible modules which resulted from each by-name lookup.
2026-01-05 11:42:51 -08:00
Qiongsi Wu
954c8a28d0 [DependencyScanning] Perform Clang Module By-Name Dependency Query Using a Shared Clang Compiler Instance (#85555)
<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

This PR teaches Swift to take advantage of the new clang dependency
scanning API to use a single clang compiler instance per dependency
scanning worker to perform by-name queries.

rdar://136303612
2026-01-02 20:57:14 -08:00
Artem Chikin
dad62f8017 Merge pull request #86079 from artemcm/DependencyScanningMetrics
[Dependency Scanning] Add tracking of the number of dependency queries and emit them as remarks
2025-12-17 17:55:44 -08:00
Artem Chikin
7017034d20 [Dependency Scanning] Add tracking of the number of dependency queries and emit them as remarks
This change adds collection of three metrics to the scanner:
- number of Swift module lookups
- number of named Clang module lookups
- recorded number of Clang modules which were imported into a Swift module by name

It introduces '-Rdependency-scan', which acts as a super-set flag to the existing '-Rdependency-scan-cache' and adds emission of the above metrics as remarks when this flag is enabled. Followup changes will add further remarks about dependency scanner progress.
2025-12-17 12:50:33 -08:00
Artem Chikin
e68bcb802c Merge pull request #86077 from artemcm/DepScan-QuerySwiftOverlaysInBulk
[Dependency Scanning] Query Swift overlay dependencies in parallel
2025-12-16 17:32:52 -08:00
Artem Chikin
dea8d67a0d [Dependency Scanning] Query Swift overlay dependencies in parallel
In 'resolveSwiftOverlayDependencies', instead of calling into 'resolveImportedModuleDependencies' for every newly-discovered Swift overlay dependency, gather all collecected overlay dependencies under one umbrella dummy query module and execute a single call into 'resolveImportedModuleDependencies' which will cover all of them.

With this change, we not only lookup all the various Swift module overlays' imports in parallel, but also all of their aggregate respective Clang dependencies are queried in one shot as well.
2025-12-15 15:34:02 -08:00
Hiroshi Yamauchi
b1058c8952 Fix the swiftCxxStdlib link with explicit module build on Windows (#85904)
We currently support static linking swiftCxxStdlib only on Windows. When
C++ interop is enabled but swiftCxxStdlib isn't actually used or only
when its underlying std module is used, we incorrectly emitted the
dynamic version of the lib name and caused the link error. This change
fixes it by always adding it to the dependency.

Issue https://github.com/swiftlang/swift/issues/85876
2025-12-15 14:07:07 -08:00
Artem Chikin
7b00603077 [Dependency Scanning] Do not re-query a given clang module identifier more than once
During parallel clang module dependency resolution, an unintended side-effect of https://github.com/swiftlang/swift/pull/84929 is that we stopped uniquing the module identifiers we query to the Clang dependency scanner.

This change ensures we do not query the same identifier more than once.

Resolves rdar://165133617
2025-12-04 14:33:37 -08:00
Hiroshi Yamauchi
a96b57de17 Fix direct clang cc1 emit-pcm commands with vfs overlay on Windows (#85325)
Explicit module builds currently fail on Windows because
direct-clang-cc1-module-build emit-pcm commands take overlaid system
module map files as inputs but miss the clang VFS overlay. This change
adds the overlay and fixes explicit module builds on Windows.
2025-11-12 21:03:15 -08:00
Artem Chikin
1584287b73 [Dependency Scanning] Have 'ModuleDependnecyScanner' hold a reference to a dependency cache, instead of passing it around 2025-10-21 12:29:31 -07:00
Artem Chikin
f7d008e7ab Merge pull request #84929 from artemcm/RevertRevertOnDemandBridging
[Dependency Scanning] Refactor batch clang dependency query to preserve only partial results
2025-10-21 03:40:13 -04:00
Artem Chikin
8335a038bf [Dependency Scanning] Refactor batch clang dependency query to preserve only partial results
Previously, with the change to bridge Clang dependency scanning results on-demand, the scanner would execute Clang dependency scanning queries for each unresolved import, in parallel, and aggregate all of the results to post-process (including on-demand bridging) later. As a consequence of that change, all of the Clang scanner queries' results ('TranslationUnitDeps') got aggregated during a scan and had their lifetimes extended until a later point when they got processed and added to the scanner's cache.

This change refactors the Clang dependency scanner invocation to, upon query completion, accumulate only the 'ModuleDeps' nodes which have not been registered by a prior scan, discarding the rest of the 'TranslationUnitDeps' graph. The arrgegated 'ModuleDeps' objects are still bridged on-demand downstream.

This change further splits up the 'resolveAllClangModuleDependencies' method's functionality to improve readability and maintainability, into:
- 'gatherUnresolvedImports' method which collects all of collected Swift dependents' imports which did not get resolved to Swift dependencies
- 'performParallelClangModuleLookup' which actually executes the parallel queries and includes the new logic described above
- 'cacheComputedClangModuleLookupResults' method which takes the result of the parallel Clang scanner query and records in in the Swift scanner cache
- 'reQueryMissedModulesFromCache' method which covers the scenario where Clang scanner query returned no result because either the dependency can only be found transitively, or the query is for a dependency previously-queried.
2025-10-20 13:33:51 -07:00
Steven Wu
bd2b3c7aeb [Caching] Allow prefix mapping on legacy layout file
To support distributed caching for targets that need to use legacy
layout file, the path of legacy layout needs to be remapped.

Current handling of the legacy layout file is to ingest all layout files
to the CAS FileSystem as part of the compiler resource files. But it
cannot convey remapped legacy layout file path to the swift-frontend
when distributed caching is enabled. In order to properly support path
remapping, the legacy layout file is ingested on demand (thus it doesn't
need to be ingested for module compilation), and the remapped path is
communicated to swift-front via frontend flag.

rdar://162793678
2025-10-17 15:53:52 -07:00
Steven Wu
1beef99ba1 [CAS] Update swift CAS file system usage after llvm-project change
Update swift compiler to go with llvm CAS update to decouple CAS file
system from VFS that breaks layering violation.
2025-10-16 10:14:00 -07:00
Artem Chikin
70341f4802 Merge pull request #84942 from artemcm/DowngradeIncompatBinModDepToWarning
[Dependency Scanning] Warn, instead of fail, when a Swift dependency query only finds modules built for incompatible target
2025-10-16 01:26:09 -04:00
Artem Chikin
d699e2fc49 [Dependency Scanning] Warn, instead of fail, when a Swift dependency query only finds modules built for incompatible target
We have adopters who are relying on directly importing the underlying Clang module in the presence of incompatible Swift modules.

Resolves rdar://162549210
2025-10-15 16:58:50 -07:00
Steven Wu
88b719d7fc [Caching] Adjust the bridging header chaining rule
Adjust the rule for how bridging header chaining is performed to
increase compatibilities with existing project configuration.

Previously in #84442, bridging header chaining was done via content
concatenation, rather than `#include` via absolute path, to enable prefix
mapping to drop references to absolute path. This triggers an
incompatibility since the directory of the header file is also
considered as part of the search path when resolve the include
directives in the file. Simple concatenation will result in some
`#include` can no longer be resolved.

Now relax the rule to do header content concatenation only when prefix
map is used. This will keep the breakage minimal, and the breakage can
always be fixed by additional include paths when turning on prefix
mapping.

In the future, we should move towards internal bridging header
implementation to avoid the need of chaining completely.

rdar://161854282
2025-10-03 16:34:51 -07:00
Steven Wu
818d0a026f Merge pull request #84658 from cachemeifyoucan/eng/PR-161835182
[Caching] Fix -access-note-path when using caching
2025-10-02 20:26:47 -07:00
Steven Wu
a1a67997b7 [Caching] Fix -access-note-path when using caching
Make sure to capture access-note when building with swift caching.

rdar://161835182
2025-10-02 12:09:14 -07:00
swift-ci
d5a03fa0e4 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-26 22:36:42 -07:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
swift-ci
6cf902227a Merge remote-tracking branch 'origin/main' into rebranch 2025-09-25 15:15:11 -07:00
Steven Wu
d579027c02 Merge pull request #84442 from cachemeifyoucan/eng/PR-issue-84088
[Caching] Allow prefix mapping for generated bridging header
2025-09-25 15:10:29 -07:00
Steven Wu
b7329f4ea7 [Caching] Allow prefix mapping for generated bridging header
To allow prefix mapping of the bridging header to achieve cache hit when
source files are located in different location, the generated chained
bridging header should not include absolute paths of the headers. Fix
the problem by concat the chained bridging header together.

Fixes: https://github.com/swiftlang/swift/issues/84088
2025-09-24 10:14:10 -07:00
swift-ci
bf0e4bb4d1 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-23 15:58:43 -07:00
Artem Chikin
e9a75193c0 [Dependency Scanning] Avoid querying Swift Overlay for underlying module
Avoid Swift Overlay lookup for the underlying clang module of a known Swift module.
i.e. When computing set of Swift Overlay dependencies for module 'A', which depends on a Clang module 'A', ensure we don't lookup Swift module 'A' itself here - this can lead to bizarre interactions where the source module under scan is queried as a dependency of itself.

Resolves rdar://159706486
2025-09-23 10:05:53 -07:00
swift-ci
0d2c4ca9be Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 10:29:21 -07:00
Artem Chikin
926fc78b4c Merge pull request #84191 from artemcm/InMemoryDepScanSerializedDiagnostics
[Dependency Scanning] Configure a serialized diagnostics consumer for in-memory scans
2025-09-15 11:54:44 -04:00
Artem Chikin
c82048559a [Dependency Scanning] Configure a thread-safe serialized diagnostics consumer for in-memory scans
This change introduces a thread-safe version of the 'SerializedDiagnosticConsumer' and refactors scanning compilation instance creation code to ensure this consumer gets added when the scanner query configuration command-line includes '-serialized-diagnostics-path' option.
2025-09-11 09:50:24 -07:00
swift-ci
fc70acc130 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-10 14:58:45 -07:00
Artem Chikin
44688083ae Merge pull request #83841 from artemcm/ReEnableVisibleOnlyModuleOverlayDeps
[Dependency Scanning] Re-enable querying Swift Overlays only for visible Clang modules
2025-09-10 17:40:50 -04:00
Anthony Latsis
e1450e011e Manually merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
*	utils/build_swift/build_swift/defaults.py
2025-09-04 14:07:50 +01:00