Commit Graph

107 Commits

Author SHA1 Message Date
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
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
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
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
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
Steven Wu
2a18922c4b [Caching] Move per-query CAS state out of the SwiftDependencyScanningService
Move per-query state out of ScanningService. There is still a check to
make sure the CASOptions are matching between queries because of the
requirement on clang scanner. Otherwise, the scanning service should
contain no per-query information anymore.

Resolves: https://github.com/swiftlang/swift/issues/82490
2025-06-26 17:03:27 -07:00
Artem Chikin
39c096c388 [Dependency Scanning] Refactor 'ModuleDependenciesCache' to not hold a reference to the global 'SwiftDependencyScanningService'
While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkard layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.
2025-06-23 13:39:43 -07:00
Artem Chikin
68883a1014 [Dependency Scanning] Refactor Swift Scanner loader to be standalone
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
2025-06-23 13:39:36 -07:00
Artem Chikin
5eb85acad5 Merge pull request #82031 from artemcm/RemovePlaceholdersInDepScanner
[Dependency Scanning] Remove obsolete placeholder module concept
2025-06-18 12:40:30 -07:00
Artem Chikin
a78ee29692 [Dependency Scanning] Remove obsolete placeholder module concept
This was used a long time ago for a design of a scanner which could rely on the client to specify that some modules *will be* present at a given location but are not yet during the scan. We have long ago determined that the scanner must have all modules available to it at the time of scan for soundness. This code has been stale for a couple of years and it is time to simplify things a bit by deleting it.
2025-06-12 08:32:25 -07:00
Artem Chikin
6816922dd4 [Dependency Scanning] Keep track of each imported module's access control
Adds an access control field for each imported module identified. When multiple imports of the same module are found, this keeps track of the most "open" access specifier.
2025-06-12 06:56:30 -07:00
Artem Chikin
d4abba10a5 Add a new diagnostic group and documentation for the module-not-found failure which specifies that a missing module dependency can be found on a search path serialized in another Swift binary module dependency. 2025-06-04 16:57:01 -07:00
Artem Chikin
90f2fba2ae [Dependency Scanning] On failure to locate a module, attempt to diagnose if binary dependencies contain search paths with this module.
Unlike with implicitly-built modules (prior to Swift 6 mode), explicitly-built modules require that all search paths be specified explicitly and no longer inherit search paths serialized into discovered Swift binary modules. This behavior was never intentional and is considered a bug. This change adds a diagnostic note to a scan failure: for each binary Swift module dependency, the scanner will attempt to execute a dependency scanning query for each serialized search path inside that module. If such diagnostic query returns a result, a diagnostic will be emitted to inform the user that the dependency may be found in the search path configuration of another Swift binary module dependency, specifying which search path contains the "missing" module, and stating that such search paths are not automatically inherited by the current compilation.
2025-06-04 16:55:37 -07:00
Artem Chikin
4fb4945ab9 Merge pull request #81908 from artemcm/FixImplicitBuildCXXInteropCycle
[C++Interop] Do not query C++ Standard Library Swift overlays when building Swift modules which were built without C++ interop
2025-06-02 23:26:27 -07:00
Artem Chikin
5b501ad2c5 Hard-code the 'Darwin' module as having been built without C++ interop
Textual interfaces for 'Darwin' built with recent compilers specify that it is built witout C++ interop enabled. However, to ensure compatibility with versions of the 'Darwin' module built with older compilers, we hard-code this fact. This is required to break the module cycle that occurs when building the 'Darwin' module with C++ interop enabled, where the underlying 'Darwin' clang module depends on C++ standard library for which the compiler brings in the 'CxxStdlib' Swift overlay, which depends on 'Darwin'.
2025-06-02 14:16:57 -07:00
Artem Chikin
bb6967bcb9 Merge pull request #81850 from artemcm/BridgeHeaderScanDiagnostics
[Dependency Scanning] Bridge diagnostics emitted during bridging header scanning
2025-05-30 18:36:16 -07:00
Artem Chikin
8ec341eac4 [Dependency Scanning] Bridge diagnostics emitted during bridging header scanning
Instead of simply dumping them to stderr.

Resolves rdar://151993075
2025-05-30 13:50:37 -07:00
Artem Chikin
a9e0a58b46 [Dependency Scanning] Add ClangImporter's mandatory path remaps to dependency scanning query filesystem
On creation, 'ClangImporter' adds overlay modulemap files for non-modular platform libraries (e.g. glibc, libstdc++), which allows Swift code to import and use those libraries.

This change adds the same filesystem overlay to dependency scanning queries by applying them to the filesystem instantiated for each depndency scanning worker. Without these overlays EBM builds cannot discover and use non-modular system libraries on non-Darwin platforms.

Resolves rdar://151780437
2025-05-29 13:33:36 -07:00
Artem Chikin
c4fcee0875 [Dependency Scanning][C++ Interop] Remap lookup of Clang module 'CxxStdlib' to 'std'
Otherwise querying this clang module, e.g. from the corresponding Swift overlay's underlying module import, will fail, since no such module exists.

Resolves rdar://151718115
2025-05-21 09:54:28 -07:00
Steven Wu
1506a0d495 [Caching] Remove capture clang extra files
After removing the CASFS implementation for clang modules, there is no
need to capture clang extra file that sets up the VFS for the clang
modules since all content imported by ClangImporter is dependency
scanned and available via include-tree. This saves more ClangImporter
instance when caching is enabled.

Update the test to check that clang content found via `-Xcc` VFS options
can currently work without capture the headermaps and vfs overlays.
2025-05-14 09:35:03 -07:00
Artem Chikin
8ab726c2be Merge pull request #81361 from artemcm/DepScanFewerClangs
[Dependency Scanning][Refactor] Reduce the number of `ClangImporter` instances used by the scanner
2025-05-12 09:57:38 -07:00
Artem Chikin
d1adc24bbc Merge pull request #81415 from artemcm/CXXInteropDarwinCycleFix
[Dependency Scanning][C++Interop] Do not query `CxxStdlib` Swift overlay for textual modules which were not built with c++interop
2025-05-12 09:08:37 -07:00
Artem Chikin
94898aabf5 [Dependency Scanning][C++Interop] Do not query 'CxxStdlib' Swift overlay for textual modules which were not built with c++interop
When we discover a textual module dependency which is a module which was not originally built from source using C++ interop (specifying '-formal-cxx-interoperability-mode=off'), avoid looking up the C++ standard library Swift overlay for it. This is required for the case of the 'Darwin' module, for example, which includes headers which map to C++ stdlib headers when the compiler is operating in C++ interop mode, but the C++ standard library Swift overlay module itself depends on 'Darwin', which results in a cycle. To resolve such situations, we can rely on the fact that Swift textual interfaces of modules which were not built with C++ interop must be able to build without importing the C++ standard library Swift overlay, so we avoid specifying it as a dependency for such modules.

The primary source module, as well as Swift textual module dependencies which *were* built with C++ interop will continue getting a direct depedency of the 'CxxStdlib' Swift module.

Resolves rdar://150222155
2025-05-09 13:00:14 -07:00
Artem Chikin
80c71fd3a9 [Dependency Scanning] Reduce number of module loaders instantiated for textual interface scanning sub-instance 2025-05-09 10:23:00 -07:00
Artem Chikin
8cd193fc08 [Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
2025-05-07 16:43:45 -07:00
Artem Chikin
4b26a3d10a [Dependency Scanning] Emit a detailed error diagnostic on Clang module variant discovery
In expectation, this should never happen. Such a situation means that within the same scanning action, Clang Dependency Scanner has produced two different variants of the same module. This is not supposed to happen, but we are currently hunting down the rare cases where it does, seemingly due to differences in Clang Scanner direct by-name queries and transitive header lookup queries.
2025-05-06 08:55:57 -07:00
Steven Wu
3d38d0dd56 [Caching][Macro] Make macro plugin options cacheable
Currently, the macro plugin options are included as cache key and the
absolute path of the plugin executable and library will affect cache
hit, even the plugin itself is identical.

Using the new option `-resolved-plugin-validation` flag, the macro
plugin paths are remapped just like the other paths during dependency
scanning. `swift-frontend` will unmap to its original path during the
compilation, make sure the content hasn't changed, and load the plugin.
It also hands few other corner cases for macro plugins:

* Make sure the plugin options in the swift module is prefix mapped.
* Make sure the remarks of the macro loading is not cached, as the
  mesasge includes the absolute path of the plugin, and is not
  cacheable.

rdar://148465899
2025-04-10 12:10:00 -07:00
Artem Chikin
88dec5199e [Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
With '-sdk-module-cache-path', Swift textual interfaces found in the SDK will be built into a separate SDK-specific module cache.
Clang modules are not yet affected by this change, pending addition of the required API.
2025-03-19 09:17:04 -06:00
Artem Chikin
148fb369fe [Dependency Scanning] Unique collected cross-import overlay files with a set
Resolves rdar://146141228
2025-03-05 15:13:07 -08:00
Artem Chikin
38dc2101d4 [Dependency Scanning] Add missing 'isExported' argument 2025-03-03 12:59:23 -08:00