Commit Graph

327 Commits

Author SHA1 Message Date
Artem Chikin
dbf15f9c09 [6.2][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 12:32:10 -07:00
Artem Chikin
8cec61e50d Merge pull request #82779 from artemcm/62_DepScanImportAccessControl
[6.2 🍒][Dependency Scanning] Keep track of each imported module's access control
2025-07-07 10:53:00 -07:00
Artem Chikin
dc91d088c2 Merge pull request #82772 from artemcm/62_FixDepScanCxxStdlibLookup
[6.2 🍒][Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
2025-07-07 10:52:38 -07:00
Artem Chikin
716331e77a [Dependency Scanning] Add libSwiftScan API and JSON output for source import information 2025-07-03 11:12:55 -07:00
Artem Chikin
1c9b864738 [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-07-03 11:12:46 -07:00
Artem Chikin
01e5d4433f [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-03 09:20:29 -07:00
Artem Chikin
2f07a98aec [Dependency Scanning] On cycle via overlay, fix Clang dependency path reconstruction
The code should consider *only* clang module dependencies, instead of all dependencies.
2025-07-02 12:16:06 -07:00
Artem Chikin
e37071bcd4 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-05 10:24:56 -07:00
Artem Chikin
e67be5ad7a [Dependency Scanning] Serialized Swift binary module serialized search paths 2025-06-05 10:24:50 -07:00
Artem Chikin
5dc42ffb0c [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-05 10:24:43 -07:00
Artem Chikin
784a506374 Merge pull request #81912 from artemcm/FixImplicitBuildCXXInteropCycle_62
[6.2 🍒][C++Interop] Do not query C++ Standard Library Swift overlays when building Swift modules which were built without C++ interop
2025-06-02 23:59:38 -07:00
Artem Chikin
5749ef3c14 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:17:53 -07:00
Artem Chikin
f24016f197 [Dependency Scanning] Bridge diagnostics emitted during bridging header scanning
Instead of simply dumping them to stderr.

Resolves rdar://151993075
2025-05-30 13:53:07 -07:00
Artem Chikin
ca59242429 [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:35:14 -07:00
Steven Wu
28360605e7 Merge pull request #81720 from cachemeifyoucan/eng/PR-release-148752988-151339073-151395300
[6.2][Caching] Swift Caching Dependency Scanning Improvements
2025-05-28 11:44:00 -07:00
Steven Wu
ed4e035f97 [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.

(cherry picked from commit 1506a0d495)
2025-05-22 11:13:52 -07:00
Steven Wu
559734c6d0 [Caching] Remove CASFS clang module implemenation
Remove the CASFS based clang module implemenation as it is not longer
used.

(cherry picked from commit 3c81c1ca9f)
2025-05-22 11:13:36 -07:00
Steven Wu
4670acf7f9 [Caching] Reduce the number of cas ID passed on frontend commandline
Using IncludeTree::FileList to concat the include tree file systems that
are passed on the command-line. This significantly reduce the
command-line size, and also makes the cache key computation a lot
faster.

rdar://148752988
(cherry picked from commit 201e4faea7)
2025-05-22 11:12:31 -07:00
Artem Chikin
93da5b4797 [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:56:56 -07:00
Artem Chikin
f8f749b07f Merge pull request #81416 from artemcm/CXXInteropDarwinCycleFix-62 2025-05-15 05:49:39 -07:00
Artem Chikin
eae522b206 [Dependency Scanning] Reduce number of module loaders instantiated for textual interface scanning sub-instance 2025-05-12 10:01:51 -07:00
Artem Chikin
fc23c6b460 [Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
2025-05-12 10:01:45 -07:00
Artem Chikin
7be7ab1e2b [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:59 -07:00
Steven Wu
8e30d7f7c7 Merge pull request #81245 from cachemeifyoucan/eng/PR-145676736-release 2025-05-08 18:21:43 -07:00
Artem Chikin
8e1bc70454 Merge pull request #81337 from artemcm/DepScanVariantError-62
[6.2 🍒][Dependency Scanning] Emit a detailed error diagnostic on Clang module variant discovery
2025-05-07 21:12:31 -07:00
Artem Chikin
7f950ff180 [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 10:14:14 -07:00
Artem Chikin
d355233cbd [Dependency Scanning][libSwiftScan] Deprecate scanner-global diagnostic collection
All clients are expected to have switched to the per-scan-query diagnostics using 'swiftscan_dependency_graph_get_diagnostics'
2025-05-05 10:43:45 -07:00
Artem Chikin
f830a207b2 [Dependency Scanning] Always use a locking diagnostic consumer
Since we enabled parallel dependency scanning by-default, each individual scan needs a diagnostic consumer that is safe to use across many threads. Deprecate the 'Locking' sub-class, making its behavior the default in the base class.
2025-05-05 10:43:40 -07:00
Artem Chikin
28289e9d94 [Dependency Scanning][Serialization] Do not serialize auxiliary files
The field is only used to store information to be used in finalize stage, in caching builds. When loading scan results from the cache, the entries are finalized already and have the file info encoded in CASIDs already.

Resolves rdar://150307865
2025-05-02 10:02:50 -07:00
Artem Chikin
025c086077 [Dependency Scanning] Miscellaneous fixes to import statement info serialization
- Deserialization of binary module dependencies was still relying on stale code (e.g. 'currentModuleImports', 'currentOptionalModuleImports') from serialized import strings, instead of the now in-use import infos.
- Imports without a source location (e.g. implicit imports of stdlib) were not getting serialized at all
- Optional import arrays were not being written out at all
2025-05-02 09:52:27 -07:00
Steven Wu
edb94fb2fb [Caching] Improve diagnostics around swift caching
Improve diagnostics message for swift caching build by trying to emit
the diagnostics early when there is more context to differentiate the
different kind of problems.

After the improvement, CAS Error should be more closer to when there is
functional problem with the CAS, rather than mixing in other kinds of
problem (like scanning dependency failures) when operating with a CAS.

rdar://145676736
(cherry picked from commit 226552bf23)
2025-05-01 16:59:43 -07:00
Artem Chikin
f0518f64ec [Dependency Scanning] Add a field of source-imported dependencies
For the main source module, provide info on which dependencies are directly imported into the user program, explicitly ('import' statement) or implicitly (e.g. stdlib). Thist list does not include Swift overlay dependencies, cross-import dependencies, bridging header dependencies.
2025-04-30 10:17:45 -07:00
Steven Wu
f96b81975a [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
(cherry picked from commit 3d38d0dd56)
2025-04-10 16:52:15 -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
Steven Wu
6de939156d [ExplicitModule] Propagate deterministic check to explicit modules
Make `-enable-deterministic-check` a driver option and teach dependency
scanner to propagate the option to explicit module build commmands. This
allows to the option to check every build output from the compiler is
deterministic.
2025-03-17 14:58:11 -07: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
Qiongsi Wu
3271c193aa [Dependency Scanning] Remove Unnecessary Code that Computes Module Output Path (#79752)
https://github.com/swiftlang/swift/pull/79297 implemented current working directory pruning but left some unnecessary code
that computes Swift interface module output path prematurely. This PR removes the code that computes the output path too 
early. The `ExplicitModuleDependencyResolver` now adds the path to the command line after it can correctly compute it. 

Context: https://github.com/swiftlang/swift/pull/79297/files#r1955314542
2025-03-04 08:44:25 -08:00
Artem Chikin
38dc2101d4 [Dependency Scanning] Add missing 'isExported' argument 2025-03-03 12:59:23 -08:00
Artem Chikin
6f0bc1ede1 [Dependency Scanning] Remove hard failure mode (crash) during cross-import resolution 2025-02-28 13:02:54 -08:00
Artem Chikin
0555764bb4 [Dependency Scanning] Refine cross-import overlay detection algorithm
The algorithm already performs pairwise checks on module dependencies brought into compilation per-source-file. Previously, the algorithm considered the entire sub-graph of a given source file. Actual source compiles do not consider the full transitive module dependency set for cross-import-overlay lookup, but rather only directly-imported modules in a given source file, and '@_exported import' Swift transitive dependencies.

This change adds tracking of whether a given import statement is 'exported' to the dependency scanner and then refines the cross-import overlay lookup logic to only consider transitive modules that are exported by directly-imported dependencies.
2025-02-27 15:48:11 -08:00
Artem Chikin
809dbf0994 [Dependency Scanning] Keep track of whether a given Swift 'import' statement is '@_exported' 2025-02-26 15:52:46 -08:00
Artem Chikin
14dd14d1a4 Merge pull request #79550 from artemcm/EBM_CrossImportsPerSourceFile
[Dependency Scanning] Perform cross-import overlay resolution per source-file
2025-02-25 20:36:33 -08:00
Artem Chikin
214fe59139 [Dependency Scanning] Perform cross-import overlay resolution per source-file
Previous implementation took the entire transitive dependency set and cross-referenced all of its members to determine which ones introduce requried cross-import overlays. That implementation differed from the cross-import overlay loading logic during source compilation, where a corrsponding cross-import overlay module is only requested if the two constituent modules are reachable via direct 'import's from *the same source file*. Meaning the dependency scanner before this change would report cross-import overlay dependencies which never got loaded by the corresponding client source compile.

This change implements a new implementation of cross-import overlay discovery which first computes sub-graphs of module dependencies directly reachable by 'import's for each source file of the module under scan and then performs pairwise cross-import overlay query per each such sub-graph.

Resolves rdar://145157171
2025-02-25 13:40:23 -08:00
Artem Chikin
e0359f7988 Merge pull request #79297 from qiongsiwu/upstream_rehash_after_vfs_overlay_prune
[Dependency Scanning] Update Swift Interface Module's Output Path after `vfs` Pruning
2025-02-14 09:03:36 -08:00
Qiongsi Wu
23e863dc7a Address code review: adding a test for -experimental-clang-importer-direct-cc1-scan and renaming a function. 2025-02-13 14:02:53 -08:00
Ryan Mansfield
bf0aae4afe Fix missing-field-initializers warning. 2025-02-13 09:41:25 -05:00
Qiongsi Wu
b7b27955bd Addressing code review. Removed the helper class, hence we do not need to manage any states. 2025-02-12 20:19:39 -08:00
Qiongsi Wu
9a5a83ad60 Modify ModuleDependencyInfo so we can set swift interface module output paths consistently and avoid const_casts. 2025-02-12 20:19:39 -08:00
Qiongsi Wu
1ce69497ff Address code review comments. 2025-02-12 20:19:39 -08:00
Qiongsi Wu
15726fc45d Adding a test. 2025-02-12 20:19:39 -08:00