Commit Graph

94 Commits

Author SHA1 Message Date
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
Artem Chikin
04eb35b7e3 [Dependency Scanning] Only optionally try to resolve imports of 'Foo.Private' submodules to 'Foo_Private' top-level modules. Such a module may not actually exist and the user did in fact mean a submodule, in which case we do not want to error out during the scan 2023-09-28 12:52:46 -07:00
Steven Wu
7b89afbb6e [DepScan] Teach dependency scanner to remap path for canonicalization
Allow DependencyScanner to canonicalize path using a prefix map. When
option `-scanner-prefix-map` option is used, dependency scanner will
remap all the input paths in following:
* all the paths in the CAS file system or clang include tree
* all the paths related to input on the command-line returned by scanner

This allows all the input paths to be canonicalized so cache key can be
computed reguardless of the exact on disk path.

The sourceFile field is not remapped so build system can track the exact
file as on the local file system.
2023-09-26 12:36:43 -07:00
Artem Chikin
b4dfb6baa1 [Dependency Scanning] Implement parallel imported module resolution
'ModuleDependencyScanner' maintains a Thread Pool along with a pool of workers
which are capable of executing a filesystem lookup of a named module dependency.
When resolving imports of a given Swift module, each import's resolution
operation can be issued asunchronously.
2023-09-22 14:11:26 -07:00
Artem Chikin
6e3f896962 [Dependency Scanning] Refactor primary scan operations into 'ModuleDependencyScanner' class
From being a scattered collection of 'static' methods in ScanDependencies.cpp
and member methods of ASTContext. This makes 'ScanDependencies.cpp' much easier
to read, and abstracts the actual scanning logic away to a place with common
state which will make it easier to reason about in the future.
2023-09-22 14:09:45 -07:00
Artem Chikin
52da0b02fa [Dependency Scanning] Attempt to lookup optional transitive dependencies of binary module dependencies. Instead of simply pretending they do not exist, do a best-effort lookup 2023-09-14 10:33:18 -07:00
Artem Chikin
475fc6a74d [Dependency Scanning] Avoid adding a cross-import-overlay dependency when
scanning the cross-import overlay module itself.

Resolves rdar://114265603
2023-08-22 16:39:19 -07:00
Artem Chikin
4610a83bdf [Dependency Scanning] Remove Swift Overlay dependencies from the set of direct
dependencies

It is valuable for clients to be able to distinguish which dependencies of a
Swift module originated from 'import' statements, and which ones are implicit
dependency Swift overlays of imported Clang modules.
2023-08-17 11:38:09 -07:00
Artem Chikin
6ef79c4ba0 [Dependency Scanning] Specify Explicit Module output path to the scanner explicitly
Instead of the code querying the compiler's built-in Clang instance, refactor the
dependency scanner to explicitly keep track of module output path. It is still
set according to '-module-cache-path' as it has been prior to this change, but
now the scanner can use a different module cache for scanning PCMs, as specified
with '-clang-scanner-module-cache-path', without affecting module output path.

Resolves rdar://113222853
2023-08-10 11:11:05 -07:00
Artem Chikin
0c6f212cd5 [Dependency Scanning] Add Clang modules from scan-deps queries to the set of
"already seen" modules, to pass down to subsequent queries.
2023-08-09 09:16:46 -07:00
Steven Wu
5fb778b7d2 [DependencyScan] Prevent command-line flags added again on re-scan
Add a flag `finalized` to indicate that a module entry in the dependency
cache is finalized and no longer needs to be updated. This prevents the
command-line flags from dependency inputs get added multiple times on
re-scan with the same service.

While during normal compilation, adding the same command-line flags
multiple times are fine, it is bad for caching builds as a new
compilation cache key needs to be computed every time.
2023-07-11 13:46:03 -07:00
Steven Wu
c470c81b9c Merge pull request #66940 from cachemeifyoucan/eng/PR-dep-sharing-serivce-issue
[CAS][DependencyScanning] Don't keep a shared state of common file deps
2023-06-30 11:56:14 -07:00
Steven Wu
bed01ade89 [CAS][DependencyScanning] Don't keep a shared state of common file deps
Unlike `swift-frontend -scan-dependencies` option, when dependency
scanner is used as a library by swift driver, the SwiftScanningService
is shared for multiple driver invocations. It can't keep states (like
common file dependencies) that can change from one invocation to
another.

Instead, the clang/SDK file dependencies are computed from each driver
invocations to avoid out-of-date information when scanning service is
reused.

The test case for a shared Service will be added to swift-driver repo
since there is no tool to test it within swift compiler.
2023-06-27 09:50:26 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Steven Wu
744e01ea47 [CAS] Allow SwiftDependencyScanningService be shared
When the CASOptions are the same, SwiftDependencyScanningService can be
shared with multiple swift driver invocation for scanning.
2023-06-26 10:34:26 -07:00
Artem Chikin
b974d97879 [Dependency Scanning] Record header dependencies of Binary Swift module dependencies
These are meant to capture paths to the PCH files that a given module was built with.
2023-06-12 14:56:28 -04:00
Steven Wu
b1f99b8e93 [CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS.

This allows swift compilation caching using CAS.
2023-06-12 10:55:53 -07:00
Artem Chikin
78b4391e0d [Dependency Scannning] Handle special case import of Clang Private "submodules"
There is a special case that already exists in 'ClangImporter' for implicit module loading:
Import of a "submodule" named "Foo.Private" is treated as a top-level module named "Foo_Private".
Clang has special support for this.

Resolves rdar://108287140
2023-05-25 14:00:28 -07:00
Artem Chikin
5ca91786ec [Dependency Scanning] Break out Swift overlay dependencies into separate output category
Instead of being a part of 'directDependencies' on a module dependency info, make them a separate array of dependency IDs for Swift Source and Textual modules.

This will allow clients to still distinguish direct module dependencies imported from a given module, versus dependencies added because direct/transitive Clang module dependencies have Swift overlays.

This change does *not* remove overlay dependencies from 'directDependencies' yet, just adds them as a separate field on the module details info. A followup change will remove overlay and bridging header dependencies from 'directDependencies' once the clients have had a chance to adopt to this change.
2023-05-19 14:47:43 -07:00
Artem Chikin
10fb324d1f [Dependency Scanning] Keep track of which direct dependencies are '@testable' for a Source dependency 2023-04-17 13:37:08 -07:00
Artem Chikin
e0eeb6339b [Dependency Scanning] Teach dependency scanner to resolve optional dependencies of a module 2023-04-17 13:36:53 -07:00