Commit Graph

380 Commits

Author SHA1 Message Date
Steven Wu
ee09790748 Update swift compiler after clang gmodule CAS build update
Fix swift compiler build and test to work with new clang gmodule build
with CAS, which encodes references to clang PCMs as CASIDs.
2025-10-28 11:35:44 -07:00
Artem Chikin
9102c65102 Merge pull request #84938 from artemcm/ShareCacheRefInScanner
[Dependency Scanning] Have `ModuleDependnecyScanner` hold a reference to a dependency cache, instead of passing it around
2025-10-23 19:51:49 -04: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
Adrian Prantl
c91211a5d2 Serialize explicit module dependencies in swift module files
For clients, such as the debugger, who do not have access the full
output of the dependency scanner, it is a huger performance and
correctness improvement if each explicitly built Swift module not just
serialized all its Clang .pcm dependencies (via the serialized Clang
compiler invocation) but also its direct Swift module dependencies.

This patch changes the Swift module format to store the absolute path
or cas cache key for each dependency in the INPUT block, and makes
sure the deserialization makes these available to the ESML.

rdar://150969755
2025-10-21 09:08:58 -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
50c0dd844f [Dependency Scanning] Refactor 'createScanQueryContext' to directly return an error 2025-09-12 15:50:40 -07: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
Artem Chikin
1cd1193e6c [Dependency Scanning] Give each scanner worker a unique Diagnostic Engine
Otherwise, when multiple workers encounter a diagnostic simultaneously we can encounter races which lead to corrupted diagnostic data or crashes

Resolves rdar://159598539
2025-09-03 13:52:44 -07:00
Artem Chikin
986e6057f5 [Dependency Scanning] Re-enable querying Swift Overlays only for visible Clang modules
This change re-enables the new semantic of looking up Swift Overlay modules only for "visible" clang modules.
We have investigated the failures we were seeing with this change enabled and addressed them with project-side fixes.
2025-08-20 16:14:42 -07:00
swift-ci
d27620fc73 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-20 10:19:17 -07:00
Anthony Latsis
44c480e83b Mnually merge main -> rebranch
Conflicts:
* `lib/ClangImporter/ClangModuleDependencyScanner.cpp`:
  https://github.com/swiftlang/swift/commit/5e09125
*	`utils/build.ps1`: https://github.com/swiftlang/swift/pull/83523
2025-08-19 21:51:34 +01:00
Steven Wu
b18e865b0a [Caching] Fix typecheck swiftinterface with prefix map
SwiftVerifyEmittedModuleInterface job is configured to be built within
the SubInvocation and it needs to inherit the caching replay prefix map
in order to load macro plugin library correctly.

rdar://158692095
2025-08-19 10:28:20 -07:00
Artem Chikin
89b43dccf3 Merge pull request #83600 from artemcm/NoRedundantClangDepBridging
[Dependency Scanning] Bridge Clang dependency scanner results on-demand
2025-08-18 09:36:27 -07:00
Artem Chikin
b14cbbb039 [Dependency Scanning] Add serialization of optional imports to the JSON output
And to the corresponding graph data structure the output gets generated from
2025-08-15 16:11:13 -07:00
Artem Chikin
9f0083c7c0 [Dependency Scanning] Refactor Clang dependency bridging into a 'ModuleDependencyScanner' utility
This moves the functionality of 'bridgeClangModuleDependency' into a utility in the main scanner class because it relies on various objects whose lifetime is already tied to the scanner itself.
2025-08-15 15:40:41 -07:00
Artem Chikin
5015ba683a [Dependency Scanning] Bridge Clang dependency scanner results on-demand
Instead of always bridging all of the discovered modules of all of the queries, only do so for modules which are not already cached
2025-08-15 14:55:42 -07:00
Artem Chikin
bc30953c15 [Dependency Scanning] Fix optional import statement serialization logic
Previously, serialization of optional import statement node arrays erroneously used the node layout of a non-optional import node array while maintaining a separate index for these arrays which got serialized into each module's info node. This meant it got serialized out in a sequence of non-optional import arrays, and as a result, the consumer deserialized them as such, which broke ordering of which arrays of import nodes belong which module, causing mismatches between a module's actual import set and the import which got deserialized for it.

This change fixes the optional import serialization routine to use the purpose-made separate layout which gets read out according to the separate optional import array index.
2025-08-15 14:23:43 -07:00
Artem Chikin
f7bc37410e Merge pull request #83532 from artemcm/AdjustDarwinCxxInteropCycleHack
[Dependency Scanning][C++ Interop] Avoid `CxxStdlib` overlay lookup for binary Swift dependencies which were not built with C++ interop
2025-08-13 15:29:14 -07:00
Artem Chikin
56a6c14ba0 [Dependency Scanning] Reduce the amount of copying of collections of module IDs
Previously, frequently-used methods like 'getAllDependencies' and 'getAllClangDependencies' had to aggregate (copy) multiple collections stored in a 'ModuleDependencyInfo' into a new result array to present to the client. These methods have been refactored to instead return an iterable joined view of the constituent collections.
2025-08-11 12:18:56 -07:00
Artem Chikin
77a61a242f [Dependency Scanning][C++ Interop] Avoid 'CxxStdlib' overlay lookup for binary Swift dependencies which were not built with C++ interop
In addition to skipping it on textual Swift module dependencies which were built without C++ interop enabled, also skip it over similarly on binary Swift dependencies
2025-08-07 10:41:00 -07:00
Artem Chikin
06c55d0463 [Dependency Scanning] Revert Swift overlay lookup using "visible" Clang modules only
We have identified scenarios where this is insufficient and compilation still relies on the presence of certain overlay modules this excludes. Reverting to prior lookup logic while we investigate.

Resolves rdar://157519278
2025-08-05 15:24:06 -07:00
Artem Chikin
27305d6ccc [Dependency Scanning] Ensure all direct Clang module imports from Swift modules are always queried by-name to the Clang dependency scanner
This is required in order to always have computed the set of visible Clang modules for each Swift module in the graph. Otherwise when some Clang module gets cached as a transitive dependency from a query and is later looked up as a direct dependency, there will not be any computed visible modules set.
2025-07-23 10:02:52 -07:00
Artem Chikin
242585dcba [Dependency Scanning] Restrict Swift overlay lookup to "visible" Clang modules only
Previously Swift overlay lookup was performed for every directly and transitively-imported Clang module.

https://github.com/llvm/llvm-project/pull/147969 introduced the concept of "visible" Clang modules from a given named Clang dependency scanner query which closely maps to the set of modules for which Swift will attempt to load a Swift overlay. This change switches overlay querying to apply only to the set of such visible modules.

Resolves rdar://144797648
2025-07-23 09:25:26 -07:00
Artem Chikin
23678690b2 [Dependency Scanner] Adapt to API change on Clang's 'DependencyScanningTool::getModuleDependencies' 2025-07-23 09:25:24 -07:00
Artem Chikin
e08b78226c [Dependency Scanning] Consider '-swift-module-file' inputs when looking for dependencies
Previously this flag was only used to pass explicit dependencies to compilation tasks. This change adds support for the dependency scanner to also consider these inputs when resolving dependencies.

Resolves https://github.com/swiftlang/swift-driver/issues/1951
2025-07-18 09:48:02 -07:00
Artem Chikin
8961d8da9a [Dependency Scanning] Diagnose an error when only finding incompatible Swift binary modules
When querying a Swift module, the scanner now also keeps track of all discovered candidate binary modules which are not compatible with current compilation.

- If a Swift dependency is successfully resolved to a compatible binary module or a textual interface, a warning is emitted for every incompatible binary Swift module discovered along the way.
- If a Swift dependency is not resolved, but incompatible module candidates were found, an error is emitted - while it is likely that the scan would fail downstream, it is also possible that an underlying Clang module dependency (with the same name) is successfuly resolved and the Swift lookup failure is ignored, which is still going to lead to failures most of the time if the client code assumes the presence of the Swift overlay module in this scenario.

This change refactors common error reporting by the scanner into a 'ModuleDependencyIssueReporter' class, which also keeps track of all diagnosed failed lookups to avoid repeating diagnostics.
2025-07-07 11:11:34 -07:00
Artem Chikin
d499b14cb3 Merge pull request #82751 from artemcm/FixDepScanCxxStdlibLookup
[Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
2025-07-07 10:52:28 -07:00
Artem Chikin
b889976dc9 Merge pull request #82695 from artemcm/DepScanCycleShadow
[Dependency Scanning] Emit a note if a dependency cycle is between the source target and another Swift module with the same name
2025-07-07 10:52:14 -07:00
Artem Chikin
ec0ab18d70 [Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
A prior change ensured that we forego this query when looking up Swift overlays for a textual interface which was built without C++ interop. This change introduced a bug where it also caused us to skip this lookup for the main source module. This commit resolves that by preserving the fix above but also ensuring we perform the lookup for the main source module under scan.
2025-07-02 15:50:27 -07:00
Artem Chikin
0d3def55df [Dependency Scanning] Emit a note if a dependency cycle is between the source target and another Swift module with the same name
The note will point the user to where the "other" module with the same name is located and mention whether it is an SDK module. This is nice to have in various circumstances where developers attempt to define a module with the same name as a Swift module that already exists on their search paths, for example in the SDK.
2025-07-01 13:38:45 -07:00