Commit Graph

125 Commits

Author SHA1 Message Date
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
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
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
Steven Wu
0e8d794ec8 [Dependency Scanning] Scan embedded header content if file doesn't exist
Fallback to scan embedded header content when the bridging header path
encoded in the swift binary module doesn't exit on the disk.

rdar://144261730
2025-02-06 09:28:11 -08:00
Steven Wu
9d59044bb1 [BrdigingHeader] Auto bridging header chaining
Add ability to automatically chaining the bridging headers discovered from all
dependencies module when doing swift caching build. This will eliminate all
implicit bridging header imports from the build and make the bridging header
importing behavior much more reliable, while keep the compatibility at maximum.

For example, if the current module A depends on module B and C, and both B and
C are binary modules that uses bridging header, when building module A,
dependency scanner will construct a new header that chains three bridging
headers together with the option to build a PCH from it. This will make all
importing errors more obvious while improving the performance.
2025-02-05 09:41:04 -08:00
Artem Chikin
477ba0dd97 [Dependency Scanning] Remove references to per-triple PCM variant compilation 2025-01-29 11:32:07 -08:00
Artem Chikin
41e471288a [Dependency Scanning] Deprecate/Remove batch scanning capability
Batch dependency scanning was added as a mechanism to support multiple compilation contexts within a single module dependency graph.
The Swift compiler and the Explicitly-built modules model has long since abandoned this approach and this code has long been stale. It is time to remove it and its associated C API.
2025-01-28 15:30:39 -08:00
Artem Chikin
ae98eae9d5 [Dependency Scanning] Synchronize on updating Swift dependency lookup results in-parallel
Resolves rdar://142978967
2025-01-23 10:26:13 -08:00
Artem Chikin
7049c5bfea [Dependency Scanning] Introduce a new constructor for dummy source modules
Instead of passing in a bunch of dummy/empty data.
2025-01-06 09:09:32 -08:00
Artem Chikin
48387eed55 [Dependency Scanning] Keep track of how many filesystem module lookups the dependency scanner performs on a given scan 2025-01-06 09:09:32 -08:00
Artem Chikin
25d32fc7a3 [Dependency Scanning] Add import statement source locations to the dependency scanner cache serialization format 2025-01-06 09:09:32 -08:00
Artem Chikin
6fdb788b7e [Dependency Scanning] Add Link Libraries to the dependency scanner cache serialization format 2025-01-06 09:09:31 -08:00
Artem Chikin
717002d405 [Dependency Scanning] Copy the set of already-seen clang modules before parallel Clang identifier query
This set, belonging to 'ModuleDependenciesCache', is only updated in a critical section behind a lock in the scanner. However, it is queried unsynchronized inside the Clang scanner itself. If an update causes a re-hash to happen, chaose can ensue with concurrent lookups.

Since this set only affects the produced set of results from teh Clang scanning query, we should simply pass in an immutable copy to scanning queries and rely on downstream de-duplication of scanning results.

With this, we can avoid passing in the reference to `ModuleDependenciesCache` to the 'scanFilesystemFor*ModuleDependency' altogether.

Resolves rdar://139414443
2024-11-07 14:08:58 -08:00
Artem Chikin
8e3a6207b9 Merge pull request #76915 from artemcm/AsyncScanExperiment
[Dependency Scanning] Parallelize Clang module queries
2024-11-05 10:04:31 -08:00
Meghana Gupta
1985b6cceb [NFC] Add SerializationOptions to ASTContext 2024-10-31 13:40:56 -07:00
Artem Chikin
0f50693aa5 [Dependency Scanning] Parallelize Clang module queries
This change refactors the top-level dependency scanning flow to follow the following procedure:

Scan():
1. From the source target under scan, query all imported module identifiers for a *Swift* module. Leave unresolved identifiers unresolved. Proceed transitively to build a *Swift* module dependency graph.
2. Take every unresolved import identifier in the graph from (1) and, assuming that it must be a Clang module, dispatch all of them to be queried in-parallel by the scanner's worker pool.
3. Resolve bridging header Clang module dpendencies
4. Resolve all Swift overlay dependencies, relying on all Clang modules collected in (2) and (3)
5. For the source target under scan, use all of the above discovered module dependencies to resolve all cross-import overlay dependencies
2024-10-30 11:10:10 -07:00
Steven Wu
fffe2cea19 Merge pull request #76591 from cachemeifyoucan/eng/PR-swift-macro-dep-tracking
[Macro][Dependencies] Properly model macro dependencies in the scanner
2024-09-25 09:41:45 -07:00
Steven Wu
5a6f6e1d4d [NFC][ScanDependency] Remove some ununsed code
Clean up some code that no longer used.
2024-09-24 16:29:21 -07:00
Steven Wu
e0541b0357 [Macro][Dependencies] Properly model macro dependencies in the scanner
Add function to handle all macro dependencies kinds in the scanner,
including taking care of the macro definitions in the module interface
for its client to use. The change involves:
  * Encode the macro definition inside the binary module
  * Resolve macro modules in the dependencies scanners, including those
    declared inside the dependency modules.
  * Propagate the macro defined from the direct dependencies to track
    all the potentially available modules inside a module compilation.
2024-09-19 16:41:53 -07:00
Artem Chikin
e7a76653aa [Dependency Scanning] Enable parallel dependency scanning by-default 2024-08-01 14:26:05 -07:00
Artem Chikin
5dd4977b0f Revert "[Dependency Scanning] Use a standalone DependencyScanningFilesystem on the scanner, sharing a common status cache from Clang's dependency service cache"
This reverts commit 1804a8486e.
2024-07-29 11:58:59 -07:00
Steven Wu
2bc4080116 [ExplicitModule] Include -Xcc -D into module hash
The decision to exclude `-Xcc -D` options from swift module hash
actually doesn't help to solve the problem. It wouldn't reduce the
module variants (or the number of swiftmodule build commands) because
the command-line also encodes all the clang PCM dependencies that do get
affected by `-Xcc` flags.

To avoid the false sharing and the nondeterministic build products,
include most of the `-Xcc` flags, except include search path, into swift
module hash.

rdar://132046247
2024-07-23 14:57:44 -07:00
Steven Wu
b51436ed6c [CrossImport][PrefixMap] Make sure overlay file is remapped if used
When dependency scanner construct the overlay file path for the
swift-frontend invocation, make sure the path is remapped if prefix map
is used.

rdar://131940130
2024-07-17 12:10:30 -07:00
Steven Wu
156b0a9b47 Merge pull request #75133 from cachemeifyoucan/eng/PR-131408266
[Modules] Avoid false swift module sharing
2024-07-11 09:36:23 -07:00
Steven Wu
a32dd9539b [Modules] Avoid false swift module sharing
When the swiftmodule is built with different clang importer arguments,
they can have the same module hash, causing them to be wrongly re-used even
they contains different interfaces. Add ReducedExtraArgs to the module hash to
disambiguate them.

However, some Xcc arguments, most commonly `-D` options do not affect the
swiftmodule being generated. Do not pass `-Xcc -DARGS` to swift
interface compilation to reduce the amount of module variants in the
build.

rdar://131408266
2024-07-10 14:48:12 -07:00
Artem Chikin
4b7bf3a59d [Dependency Scanning] Emit diagnostics from compilation instance initialization 2024-07-10 10:34:40 -07:00
Artem Chikin
643fb60a3e [Dependency Scanning] Respect the Language Option for cross-import overlay enablement 2024-06-27 10:04:08 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Steven Wu
026fcd24fe [ScanDependency][canImport] Improve canImport handling in explicit build
Teach dependency scanner to report all the module canImport check result
to swift-frontend, so swift-frontend doesn't need to parse swiftmodule
or parse TBD file to determine the versions. This ensures dependency
scanner and swift-frontend will have the same resolution for all
canImport checks.

This also fixes two related issues:
* Previously, in order to get consistant results between scanner and
  frontend, scanner will request building the module in canImport check
  even it is not imported later. This slightly alters the definition of
  the canImport to only succeed when the module can be found AND be
  built. This also can affect the auto-link in such cases.
* For caching build, the location of the clang module is abstracted away
  so swift-frontend cannot locate the TBD file to resolve
  underlyingVersion.

rdar://128067152
2024-05-31 15:36:55 -07:00
artemcm
9aeadd0507 [Dependency Scanning] Specify Source Locations For Missing Module Dependencies
This change modifies the dependency scanner to keep track of source locations of each encountered 'import' statement, in order to be able to emit diagnostics with source locations if an import failed to resolve.

- Keep track of each 'import' statement's source buffer, line number, and column number when adding it. The dependency scanner utilizes separate compilation instances, and therefore separate Source Managers for scanning `import` statements of user sources and textual interfaces of Swift dependencies. Since import resolution may happen in the main scanner compilation instance while the `import` itself was found by an interface-scanning sub-instance, we cannot simply hold on to the import's `SourceLoc`.
- Add libSwiftScan API for diagnostics to carry above source locations to clients.
2024-05-21 13:12:09 -07:00
Artem Chikin
31337dd004 Merge pull request #69706 from artemcm/DepScanCPPInterop
[Explicit Module Builds] C++ Interoperability mode fixes
2024-05-20 20:29:17 -04:00