Commit Graph

115 Commits

Author SHA1 Message Date
Artem Chikin
04015fef77 [Dependency Scanning] Adopt new clang scanner API to place stable modules into an SDK-specific module cache 2025-03-19 10:43:42 -06: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
809dbf0994 [Dependency Scanning] Keep track of whether a given Swift 'import' statement is '@_exported' 2025-02-26 15:52:46 -08:00
Qiongsi Wu
69e88b176a Removing unused functions. 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
8055c1d17c Initial commit of InterfaceModuleNameExpander implmentation. All tests pass, and the unused vfs overlay is optimized. 2025-02-12 20:19:36 -08:00
Steven Wu
ca749de113 [Dependency Scanning] Support loading scanner cache state for caching
Teach scanner cache loader to validate the CAS contents when validating
dependency graph loaded.
2025-02-05 14:24:35 -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
acb4e847f5 [Dependency Scanning] Add functionality to validate contents of a loaded scanner cache state
Checking each module dependency info if it is up-to-date with respect to when the cache contents were serialized in a prior scan.

- Add a timestamp field to the serialization format for the dependency scanner cache
- Add a flag "-validate-prior-dependency-scan-cache" which, when combined with "-load-dependency-scan-cache" will have the scanner prune dependencies from the deserialized cache which have inputs that are newer than the prior scan itself

With the above in-place, the scan otherwise proceeds as-is, getting cache hits for entries still valid since the prior scan.
2025-02-03 10:33:43 -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
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
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
a46e33143a [Dependency Scanning] Modernize and revive the module dependencies cache serialization format
This format has gotten stale and been not in use for many months. This commit restores primary functionality of the format.
2025-01-06 09:09:27 -08:00
Artem Chikin
9055a401a3 [Dependency Scanner] Refactor the global scanning service to no longer maintain scanner cache state
Instead, each scan's 'ModuleDependenciesCache' will hold all of the data corresponding to discovered module dependencies.

The initial design presumed the possibility of sharing a global scanning cache amongs different scanner invocations, possibly even different concurrent scanner invocations.

This change also deprecates two libSwiftScan entry-points: 'swiftscan_scanner_cache_load' and 'swiftscan_scanner_cache_serialize'. They never ended up getting used, and since this code has been largely stale, we are confident they have not otherwise had users, and they do not fit with this design.

A follow-up change will re-introduce moduele dependency cache serialization on a per-query basis and bring the binary format up-to-date.
2024-12-04 11:13:05 -08: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
cd07d532af [CAS] Use IncludeTreeFileList instead of full CASFS for caching
Use IncludeTreeFileList instead of full feature CASFS for swift
dependency filesystem. This allows smaller CAS based VFS that is smaller
and faster. This is enabled by the CAS enabled compilation does not
need to iterate file system.

rdar://136787368
2024-09-30 16:01:33 -07:00
Steven Wu
c7775733cf [ScanDependencies] Re-structure the dependency resolver
Rewrite part of the dependency scanner into a class so it is easier to
keep track of the global states and avoid redundent work. This allows
folding the pruning unused VFS job into the same loop and reduce a lot
of repeated dependency cache updates.
2024-09-25 09:43:25 -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
Steven Wu
fcdc29500f [DependencyScanner] Drop macro search path if not needed
When scanning swift modules and constructing their build commands, there
is no need to pass any external plugin search paths if there are no macro
dependencies for the module.

rdar://135221984
2024-09-03 15:15:20 -07:00
Steven Wu
fd6707e312 [Caching] CASFS need to include blocklist
There are blocklist items can affect code-generation, thus the
block-list needs to be included in the CASFS for compilation.

rdar://134593841
2024-08-26 11:49:42 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Xi Ge
98f4ad840a DependenciesScanner: report user module version for textual Swift interfaces 2024-08-06 15:45:45 -07:00
Xi Ge
b4d64bde55 DependencyScanner: report user module version in dependency scanning results for binary Swift modules 2024-08-06 11:43:53 -07:00
Steven Wu
9967e58624 [DependencyScanner] Use mutex to protect all accesses to contextCacheMap
Rather than only protecting the insertion and non-const access to
`ContextSpecificCacheMap` in ScanningService, extend the mutex
protection to all accesses. Even a 'const' lookup in the cache map is
not thread safe because the `StringMap` could be in the process of being
rehashed.

rdar://127205953
2024-07-31 13:17:04 -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
da10a02231 [Macro] Fix bugs in macro dependency scanning
Fix few issues from previous implementation from explicit module build
with macros and accurate macro dependency scanning in
https://github.com/swiftlang/swift/pull/73421.

First, there is a crash when propagating the macro dependencies. It
turns out that the current macro plugin implementation doesn't need the
downstream users to know about the plugin search path from the upstream
dependencies.

Secondly, fix a bug that the swiftinterface that has macro usage won't
build because the build command doesn't inherit the plugin search path
option.

Finally, add JSON output for macro dependencies so it is easier to
debug the macro dependencies.

rdar://131214106
2024-07-09 10:37:27 -07:00
Artem Chikin
2464f87f8f [Dependency Scanning] Resolve cross-import overlays relative to defining interface for prebuilt binary Swift dependencies
When the dependency scanner picks a pre-built binary module candidate for a given dependency, it needs to be able to attempt to resolve its cross-import overlays relative to the textual interface that the binary module was built from. For example, if a collection of binary modules are located in, and resolved as dependencies from, a pre-built module directory, the scanner must lookup their corresponding cross-import overlays relative to the defining interface as read out from the binary module's MODULE_INTERFACE_PATH. https://github.com/swiftlang/swift/pull/70817 ensures that binary modules serialize the path to their defining textual interface.

Resolves rdar://130778577
2024-07-03 10:05:54 -07:00
Steven Wu
4125e8c3cd [ScanDependencies] Get accurate macro dependency
Build an accurate macro dependency for swift caching. Specifically, do
not include not used macro plugins into the dependency, which might
cause false negatives for cache hits.

This also builds the foundation for future improvement when dependency
scanning will determine the macro plugin to load and swift-frontend do
not need to redo the work.

rdar://127116512
2024-06-27 10:45:14 -07:00
artemcm
d70863501e [Dependency Scanning] Collect and report each module dependency's Link Libraries 2024-06-05 10:59:41 -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
Artem Chikin
eb1c0e71d8 [Dependency Scanning] Add required additional C++ interop overlay module queries 2024-05-20 10:23:10 -07:00
Steven Wu
cf8187a4fe [ScanDependency] Pass crossimport overlay file to swift-frontend
Teach dependency scanner to pass cross import overlay file to
swift-frontend for main module compilation. This allows swift-frontend
not to repeat the file system search for overlay files when loading
modules.

This also fixes the issue when caching is enabled, the cross import
doesn't work when the first module is a clang module because the module
built with caching using clang include tree does not preserve
DefinitionLoc which is used to inferred the modulemap location for cross
import overlay search.

rdar://127844120
2024-05-14 15:24:35 -07:00
Artem Chikin
a4f72c3078 Revert "Revert "[Dependency Scanning] Use a standalone DependencyScanningFilesystemon the scanner, sharing a common status cache from Clang's dependency service cache"" 2024-05-01 09:45:12 -07:00
Artem Chikin
983a95c199 Revert "[Dependency Scanning] Use a standalone DependencyScanningFilesystemon the scanner, sharing a common status cache from Clang's dependency service cache" 2024-04-24 15:08:49 -07:00
Artem Chikin
1804a8486e [Dependency Scanning] Use a standalone DependencyScanningFilesystem on the scanner, sharing a common status cache from Clang's dependency service cache 2024-04-09 13:36:46 -07:00
Steven Wu
0e12f2042e [ScanDependency] Move binary module validation into scanner
Improve swift dependency scanner by validating and selecting dependency
module into scanner. This provides benefits that:
* Build system does not need to schedule interface compilation task if
  the candidate module is picked, it can just use the candidate module
  directly.
* There is no need for forwarding module in the explicit module build.
  Since the build system is coordinating the build, there is no need for
  the forwarding module in the module cache to avoid duplicated work,
* This also correctly supports all the module loading modes in the
  dependency scanner.

This is achieved by only adding validate and up-to-date binary module as
the candidate module for swift interface module dependency. This allows
caching build to construct the correct dependency in the CAS. If there
is a candidate module for the interface module, dependency scanner will
return a binary module dependency in the dependency graph.

The legacy behavior is mostly preserved with a hidden frontend flag
`-no-scanner-module-validation`, while the scanner output is mostly
interchangeable with new scanner behavior with `prefer-interface` module
loading mode except the candidate module will not be returned.

rdar://123711823
2024-04-05 07:52:14 -07:00
Steven Wu
cdd1ac91a8 [Caching] Support CrossImport modules for caching build
Add support for cross import modules by ingesting swiftoverlay files for
the cross import into CAS file system.

The long-term better fix will be just passing the cross import
information from scanner to swift-frontend so frontend doesn't need to
read overlay files again to figure out the cross import module.

rdar://123839248
2024-03-11 14:55:22 -07:00
Artem Chikin
bfa8c0ee4f [Dependency Scanning] Scan header inputs of binary Swift moduel dependencies
Otherwise they may have module dependencies of their own which will not be detected by the scanner and included in the list of explicit inputs for compilation.
2024-03-06 11:02:35 -08:00
Ben Langmuir
576cc8cee1 [Caching] Use clang to prefix-map -fmodule-file-cache-key paths
When prefix mapping paths that are used in clang, ensure we are
consistently using the same prefix mapper from clang. This prevents
mismatches that could cause modules to fail to load.

rdar://123324072
2024-02-28 13:44:28 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Artem Chikin
f45db99c04 [Dependency Scanning] Improve the cycle-detection diagnostic for Swift overlay dependencies
Add tracing of the underlying Clang module for an overlay dependency if said overlay dependency forms a cycle
2024-02-08 08:54:14 -08:00
Artem Chikin
ff63a900aa [Dependency Scanning] Remove 'overlaySharedFilesystemCacheForCompilation' from the scanner. It overlays a non-thread-safe filesystem on shared compilation instances and is no longer valid with parallel scanning. 2023-12-04 12:34:41 -08:00
Artem Chikin
9c58b9f5f5 [Dependency Scanning] Detect and ignore (and warn about) tautological imports
This matches the current behavior in `ImportResolution`. The change refactors an existing utility function to do this check from `UnboundImport` to a common utility used now also in the scanner.
2023-11-01 06:46:42 -07:00
Artem Chikin
9615729d0b [Dependency Scanning] Handle binary module dependencies' Swift overlay dependencies
The code, previously, only properly handled such dependencies being a distinct category for Swift source and Swift textual dependency infos. Swift binary module dependencies must handle this similarly and this change adds the missing support for them. Recent refactor of the scanner also means that now Swift binary dependencies with Swift overlay dependencies may crash the scanner, and this change resolves this as well.

Resolves rdar://117088840
2023-10-18 09:46:34 -07:00
Steven Wu
c8bc08107c Merge pull request #68684 from cachemeifyoucan/eng/PR-path-remapping
[CompilerCaching] Path Remapping for canonicalization
2023-10-04 12:57:27 -07:00