Commit Graph

115 Commits

Author SHA1 Message Date
swift-ci
8e7eae199e Merge remote-tracking branch 'origin/main' into rebranch 2023-02-08 07:33:02 -08:00
Artem Chikin
be3812d686 [Dependency Scanning] Add swift dependency compile arguments required for self-contained commands
- '-o <output_path>'
- '-disable-implicit-swift-modules'
- '-Xcc -fno-implicit-modules' and '-Xcc -fno-implicit-module-maps'
- '-candidate-module-file'

These were previously supplied by the driver. Instead, they will now be ready to be run directly from the dependency scanner's output.
2023-02-07 11:35:11 -07:00
Artem Chikin
c24c81e979 [Dependency Scanning] Adopt new Clang scan-deps C++ API for querying module deps
As introduced in https://reviews.llvm.org/D140176.
2023-02-02 09:13:46 -08:00
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Artem Chikin
12477b7b79 [Dependency Scanning] Refactor the scanner to resolve unqualified module imports
This changes the scanner's behavior to "resolve" a discovered module's dependencies to a set of Module IDs: module name + module kind (swift textual, swift binary, clang, etc.).

The 'ModuleDependencyInfo' objects that are stored in the dependency scanner's cache now carry a set of kind-qualified ModuleIDs for their dependencies, in addition to unqualified imported module names of their dependencies.

Previously, the scanner's internal state would cache a module dependnecy as having its own set of dependencies which were stored as names of imported modules. This led to a design where any time we needed to process the dependency downstream from its discovery (e.g. cycle detection, graph construction), we had to query the ASTContext to resolve this dependency's imports, which shouldn't be necessary. Now, upon discovery, we "resolve" a discovered dependency by executing a lookup for each of its imported module names (this operation happens regardless of this patch) and store a fully-resolved set of dependencies in the dependency module info.

Moreover, looking up a given module dependency by name (via `ASTContext`'s `getModuleDependencies`) would result in iterating over the scanner's module "loaders" and querying each for the module name. The corresponding modules would then check the scanner's cache for a respective discovered module, and if no such module is found the "loader" would search the filesystem.

This meant that in practice, we searched the filesystem on many occasions where we actually had cached the required dependency, as follows:
Suppose we had previously discovered a Clang module "foo" and cached its dependency info.
-> ASTContext.getModuleDependencies("foo")
--> (1) Swift Module "Loader" checks caches for a Swift module "foo" and doesn't find one, so it searches the filesystem for "foo" and fails to find one.
--> (2) Clang Module "Loader" checks caches for a Clang module "foo", finds one and returns it to the client.

This means that we were always searching the filesystem in (1) even if we knew that to be futile.
With this change, queries to `ASTContext`'s `getModuleDependencies` will always check all the caches first, and only delegate to the scanner "loaders" if no cached dependency is found. The loaders are then no longer in the business of checking the cached contents.

To handle cases in the scanner where we must only lookup either a Swift-only module or a Clang-only module, this patch splits 'getModuleDependencies' into an alrady-existing 'getSwiftModuleDependencies' and a newly-added 'getClangModuleDependencies'.
2023-01-05 11:44:06 -08:00
Artem Chikin
1230966e80 [Dependency Scanner] Rename 'ModuleDependenceis' -> 'ModuleDependencyInfo' 2022-12-15 14:18:29 -08:00
Artem Chikin
f39c6385df [Dependency Scanning] Do not disambiguate 'GlobalModuleDependenciesCache' by search path set
This is no longer necessary since the cache is always configured for the current scanning context hash, which includes the search path set.
2022-12-06 14:15:39 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Artem Chikin
dc7cae21d2 [Dependency Scanning] Produce canonical output path for Clang PCMs.
Instead of relying on the client (driver) to perform its own computation of the matching output path.
2022-11-14 13:53:40 -08:00
Artem Chikin
11cd472f14 [Dependency Scanning] Configure the Clang dependency scanner to generate PCM output paths
Using the convention of : <Module_Cache_Path> + "/" + <Module_Name> + "-" + <Context_Hash> + ".pcm"
2022-11-09 09:49:35 -08:00
Artem Chikin
c5bd61bf25 [Dependency Scanning] Adapt 'ClangModuleDependencyScanner' output to clang frontend-only results coming from scan-deps 2022-09-28 09:00:59 -07:00
Jan Svoboda
38686bd402 [importer] Adjust for new dependency scanner API 2022-09-27 15:55:28 -07:00
Artem Chikin
96a82cdf9a [Dependency Scanner] Clean up/Gardening on 'ClangModuleDependencyScanner'
Move clangScanningTool and clangScanningService to be parts of 'ModuleDependenciesCache' state, getting rid of the 'ClangModuleDependenciesCacheImpl', which is no-longer needed since we moved moved to by-name lookup of Clang modules.
2022-09-12 15:10:43 -07:00
Artem Chikin
d8f77c601b [Dependency Scanner] Use Clang scanner's module name query API instead of creating a dummy file 2022-09-12 10:30:19 -07:00
Artem Chikin
03136e06aa [Dependency Scanner] Ensure the Clang dependency scanner working directory matches the invocation.
The Swift compiler does not have a concept of a working directory. It is instead handled by the Swift driver by resolving relative paths according to the driver's working directory argument. On the other hand, Clang does have a concept working directory which may be specified on this Clang invocation with '-working-directory'. If so, it is crucial that we use this directory as an argument to the Clang scanner API. Otherwiswe, we risk having a mismatch between the working directory specified on the scanner's Clang invocation and the one use from the scanner API entry-points, which leads to downstream inconsistencies and errors.
2022-09-09 13:32:14 -07:00
Artem Chikin
6da780e272 [Dependency Scanner] Diagnose failure to find a module
And produce a dependency path from the missing dependency to the main module being scanned.
2022-09-07 15:56:44 -07:00
Steven Wu
9bd2d40084 [ClangImporter] Update to match new DependencyScanningService API
Update ClangImporter to match new DependencyScanningService API from
clang depscan.
2022-08-30 12:49:17 -07:00
Steven Wu
149efac878 Update swift to build against cas-support 2022-06-27 16:44:16 -07:00
Ben Barham
a3f14cc733 [next] Update dependency scanner to inline old API
apple/llvm-project 000a90ab63ce0595d442b3e7e8adc9c0506d2525 removed
`getAdditionalArgsWithoutModulePaths`.
092b2ddf7a swapped to using
`getCommandLineWithoutModulePaths` instead, but this is (almost) all cc1
args used to build the module - which is very different to what was
being looped over previously.

Inline `getAdditionalArgsWithoutModulePaths` instead.

Resolves rdar://94545725.
2022-06-08 14:45:13 -07:00
Ben Barham
092b2ddf7a [next] Update dependency scanner to use new Clang API
apple/llvm-project 000a90ab63ce0595d442b3e7e8adc9c0506d2525 removed
`getAdditionalArgsWithoutModulePaths`. Based on the v2 libclang API, we
should be using `getCommandLineWithoutModulePaths` now.
2022-05-05 16:25:10 -07:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Ben Barham
5e43702ff6 [DepScanner] Do not remove the resource directory path
The clang importer sets the clang resource directory to
`RuntimeResourcePath`/clang (usually "lib/swift/clang", a symbolic link
into "lib/clang/<version>"). This was inadvertently being removed in a
check to remove the clang *executable* path.

Modify that check to only the first argument so the resource directory
is properly passed through.
2021-10-28 15:53:44 +10:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Artem Chikin
a17d5ee012 [Dependency Scanning] Emit path to clang from PCM build command-line
It gets interpreted as just an executable we feed to the linker, since we launch `emit-pcm` actions via `swift-frontend` invocations, not `clang`.
2021-09-30 15:02:25 -07:00
swift-ci
a7839bb80f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-23 14:14:43 -07:00
Artem Chikin
6176657285 [Dependency Scanning] Include initial PCM arguments on Clang module dependency details
Doing so will allow clients to know which Swift-specific PCM arguments are already captured from the scan that first discovered this module.
SwiftDriver, in particular, will be able to use this information to avoid re-scanning a given Clang module if the initial scan was sufficient for all possible sets of PCM arguments on Swift modules that depend on said Clang module.
2021-09-22 11:34:02 -07:00
swift-ci
d12197f488 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-21 08:33:46 -07:00
Artem Chikin
709676c20c [Dependency Scanning] Make GlobalModuleDependenciesCache aware of the current scanning action's target triple
And only resolve cached dependencies that came from scanning actions with the same target triple.

This change means that the `GlobalModuleDependenciesCache` must be configured with a specific target triple for every scannig action, and it will only resolve previously-found dependencies from previous scannig actions using the exact same triple.

Furthermore, the `GlobalModuleDependenciesCache` separately tracks source-file-based module dependencies as those represent main Swift modules of previous scanning actions, and we must be able to resolve those regardless of the target triple.

Resolves rdar://83105455
2021-09-20 11:21:16 -07:00
Evan Wilde
e6c25be684 fix SingleCommandCompilationDatabase references
The SingleCommandCompilationDatabase type was removed from LLVM and the
API's that took it were changed to just take the vector of arguments
instead. This patch updates the calls to `getFullDependencies` to pass
in the argument vector to reflect that change and get things building
again.
2021-09-15 16:35:16 -07:00
Artem Chikin
e64a40451b [Dependency Scanning] Model main module as separate dependency kind: SwiftSource
These kinds of modules differ from `SwiftTextual` modules in that they do not have an interface and have source-files.
It is cleaner to enforce this distinction with types, instead of checking for interface optionality everywhere.
2021-09-15 09:31:20 -07:00
Eric Miotto
fc366f0e96 [rebranch] remove unneeded SingleCommandCompilationDatabase (#38961)
This class will now be provided by LLVM as part of apple/llvm-project#3183
2021-08-20 07:42:13 -07:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07:00
Artem Chikin
6a12dc0070 [Dependency Scanning] Have the scanner cache answer queries relevant to current search paths only.
The dependency scanner's cache persists across different queries and answering a subsequent query's module lookup with a module not in the query's search path is not correct.

For example, suppose we are looking for a Swift module `Foo` with a set of search paths `SP`.
And dependency scanner cache already contains a module `Foo`, for which we found an interface file at location `L`. If `L`∉`SP`, then we cannot re-use the cached entry because we’d be resolving the scanning query to a filesystem location that the current scanning context is not aware of.

Resolves rdar://81175942
2021-07-30 09:53:04 -07:00
Eric Miotto
ad6076a7bc Merge 'origin/main' into rebranch - 2021-07-16
Conflicts:
	lib/IRGen/IRGenFunction.cpp
    Take the changes made in #38386
2021-07-16 07:57:06 -07:00
Artem Chikin
d6f7a017ab [Dependency Scanning] Do not include -target in extraPCMArgs when scanning an interface
https://github.com/apple/swift/pull/37774 (related to rdar://72480261) has made it so that the target of built clang modules (even downstream from Swift interface dependencies) can be consistent with that of the main module. This means that when building transitive Clang dependencies of the main module, they will always have a matching triple to the main module itself (ensured with `-clang-target`). This means we no longer have to report the target triple in the set of `extraPCMArgs` which encode an interface-specific requirement for building its dependencies.
2021-07-15 16:24:37 -07:00
swift_jenkins
992318c128 Merge remote-tracking branch 'origin/main' into next 2021-06-24 16:01:49 -07:00
Ben Barham
28bb2505b0 [ClangImporter] Respect -working-directory in the created VFS
Pass a wrapped VFS down into `clang::createInvocationFromCommandLine` so
that the working directory is set and then used in the underlying Clang
`CompilerInstance`.

Fixes the possibility of differing modules hashes when the same
arguments are used in Clang directly vs from the importer.

Resolves rdar://79376364
2021-06-24 11:07:40 +10:00
Evan Wilde
1cec66e158 Update ContextHash access
The ContextHash is also in the ID of the ModuleDep, so access it through
there.
2021-06-22 11:48:43 -07:00
Evan Wilde
450b78f48d NonPathCommandLine -> getAdditionalArgsWithoutModulePaths()
This value was replaced with a call to 'getNonPathCommandLine()' in
llvm-project commit 2b73565210ef0b3b29e0f067eef150a32adbb967. The API
was later renamed 'getAdditionalArgsWithoutModulePaths()' in
llvm-project commit 77fc4d1feef5f3041f614206447b4461992054bb.
2021-06-22 11:01:37 -07:00
Evan Wilde
96aae72756 Update ModuleName lookup
The ModuleName is now put behind a ModuleID struct called "ID" instead
of on the ModuleDep directly.
2021-06-22 10:53:01 -07:00
Ben Barham
c54c9c7079 [Gardening] Extract basic source info structs from RawComment.h 2021-04-14 10:05:27 +10:00
Keith Smiley
83d76535b7 [NFC] Remove unused ModuleCacheDir variable 2020-11-20 16:19:22 -08:00
Artem Chikin
a09ae48999 [Dependency Scanner] Always add NonPathCommandLine arguments from Clang scan-deps result
When building a set of command-line options required to build a Clang module, also add `NonPathCommandLine` from Clang's `ModuleDeps`. These flags are mandatory in order to build modules discovered by the scanner.

Resolves rdar://70212660
2020-10-13 11:50:23 -07:00
Artem Chikin
f9d6c6a619 [Dependency Scanner] Refactor ModuleDependencies to represent binary-only Swift modules explicitly
This matches the behavior of the current client (`swift-driver`) and reduces ambiguity in how the nodes in the graph are to be treated. Swift dependencies with a textual interface, for example, must be built into a binary module by clients. Swift dependencies without a textual interface, with only a binary module, are to be used directly, without any up-to-date checks.

Note, this is distinct from Swift dependencies that have a textual interface, for which we also detect potential pre-build binary module candidates. Those are still reported in the `details` field of textual Swift dependencies as `prebuiltModuleCandidates`.
2020-10-12 09:56:03 -07:00
Xi Ge
c403b140e1 ClangImporter: refactor ClangImporterOptions to be ASTContext-owned. NFC
We need ClangImporterOptions to be persistent for several scenarios: (1)
when creating a sub-ASTContext to build Swift modules from interfaces; and
(2) when creating a new Clang instance to invoke Clang dependencies scanner.

This change is NFC.
2020-09-01 14:04:22 -07:00
Artem Chikin
02513b1c11 Merge pull request #33671 from artemcm/BatchScannerTargetExtract
[Dependency Scanner] Batch scanner: extract target triple from the PCMArgs for the batch invocation.
2020-08-28 10:16:14 -07:00
Artem Chikin
5afbddb42b [Dependency Scanner] Ensure that Clang dependency scanner instances inherit the creating invocation's extra clang args.
This ensures that when the dependency scanner is invoked with additional clang (`-Xcc`) options, the Clang scanner is correctly configured using these options.
2020-08-27 19:21:53 -07:00
Artem Chikin
863bca87e8 [Dependency Scanner] Prefix Clang dependency scanner search path arguments with -Xcc
Experimentally, this seems to be required for these paths to actually be picked up by the underlying scanner.
2020-08-27 13:17:12 -07:00
Xi Ge
29c7216c6c DependenciesScanner: include search path options in PCM building commands
Unlike Swift modules, building Clang PCMs requires search path options like -F and -I to
look for transitive header includes because in module maps, we can only find top-level headers.

rdar://67589328
2020-08-26 13:19:49 -07:00
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04:00