Commit Graph

28 Commits

Author SHA1 Message Date
Artem Chikin
44a8f99d19 [DependencyScanning] Count target variant, clang target, and sdk versions as components of scanning context hash
Resolves rdar://103093122
2022-12-09 09:24:44 -08:00
Artem Chikin
9f62b19058 [Dependency Scanning] Use persistent dependency scanning filesystem in the Swift dependency scanner
Adopts Clang's 'DependencyScanningWorkerFilesystem' for use by the scanner, with the persistent
scanner instance keeping a 'DependencyScanningFilesystemSharedCache'.
2022-12-08 11:41:20 -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
Artem Chikin
990b95e9d8 [Dependency Scanning] Key into a global (shared) dependency scanning cache via context hash
Introduces a concept of a dependency scanning action context hash, which is used to select an instance of a global dependency scanning cache which gets re-used across dependency scanning actions.
2022-12-06 08:26:28 -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
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
b426757eda [Dependency Scanning] Share the Clang Dependency Scanning service among scanner invocations.
It was recently moved to the ModuleDependenciesCache. This is undesireable, instead this should live in the GlobalModuleDependenciesCache so that we benefit from the filesystem caching it performs across diferent scanning actions.
2022-09-29 16:06:56 -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
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
Artem Chikin
eebebd9a55 [Dependency Scanning] Do not persist cached Clang module dependencies between scans.
This change tweaks the 'GlobalModuleDependenciesCache', which persists across scanner invocations with the same 'DependencyScanningTool' to no longer cache discovered Clang modules.

Doing so felt like a premature optimization, and we should instead attempt to share as much state as possible by keeping around the actual Clang scanner's state, which performs its own caching. Caching discovered dependencies both in the Clang scanner instance, and in our own cache is much more error-prone - the Clang scanner has a richer context for what is okay and not okay to cache/re-use.

Instead, we still cache discovered Clang dependencies *within* a given scan, since those are discovered using a common Clang scanner instance and should be safe to keep for the duration of the scan.

This change should make it simpler to pin down the core functionality and correctness of the scanner.
Once we turn our attention to the scanner's performance, we can revisit this strategy and optimize the caching behaviour.
2022-08-29 15:40:59 -07:00
Artem Chikin
9fcd202918 [Dependency Scanning] Do not add underlying Clang moduel to persistent (global) scanner cache
When we are building a Swift module which has an underlying Clang module, and which generates an ObjC interface ('-Swift.h'), the mechanism for building the latter involves a VFS redirect of its modulemap to one that does not yet have the generated Swift code, because it must be built before the Swift portion is built because the Swift portion depends on it. This means that the invocation to build this module is different to one used by the clients which depend on this module.

To avoid the subsequent client scans from re-using the partial (VFS-redirected) module, ensure that we do not store dependency info of the underlying Clang module into the global scanner cache. This will cause subsequent client scans to re-scan for this module, and find the fully-resolved modulemap without a VFS redirect.

Resolves rdar://88309064
2022-08-26 10:31:01 -07:00
Ellie Shin
5da881256f Module aliasing: Use real module names with -scan-dependencies
Resolves rdar://85991587
2021-12-02 15:45:30 -08: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
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
Artem Chikin
9429136112 [Dependency Scanning] Split the ModuleDependencyCache into two: current scan cache & global.
This change causes the cache to be layered with a local "cache" that wraps the global cache, which will serve as the source of truth. The local cache persists only for the duration of a given scanning action, and has a store of references to dependencies resolved as a part of the current scanning action only, while the global cache is the one that persists across scanning actions (e.g. in `DependencyScanningTool`) and stores actual module dependency info values.

Only the local cache can answer dependency lookup queries, checking current scanning action results first, before falling back to querying the global cache, with queries disambiguated by the current scannning action's search paths, ensuring we never resolve a dependency lookup query with a module info that could not be found in the current action's search paths.

This change is required because search-path disambiguation can lead to false-negatives: for example, the Clang dependency scanner may find modules relative to the compiler's path that are not on the compiler's direct search paths. While such false-negative query responses should be functionally safe, we rely on the current scanning action's results being always-present-in-the-cache for the scanner's functionality. This layering ensures that the cache use-sites remain unchanged and that we get both: preserved global state which can be queried disambiguated with the search path details, and an always-consistent local (current action) cache state.
2021-08-06 09:13:42 -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
Artem Chikin
14229f13b0 [Dependency Scanning] Add a binary serialization format for the Inter-Module Dependencies Cache
- Adds serialization format based on the LLVM Bitcode File Format (https://llvm.org/docs/BitCodeFormat.html).
- Adds Serialization and Deserialization code.
2021-05-21 14:31:00 -07:00
Artem Chikin
3221734e7b Merge pull request #34244 from artemcm/RefactorScannerBinaryDependencies
[Dependency Scanner] Refactor ModuleDependencies to represent binary-only Swift modules explicitly
2020-10-12 17:03:25 -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
Brent Royal-Gordon
d02b34cccc [NFC] Add conveniences to clean up import code 2020-10-09 18:59:19 -07:00
Artem Chikin
965ca698d5 Add in-source rationale for why Placeholder dependencies are needed. 2020-07-28 11:34:27 -07:00
Artem Chikin
746e89b252 Rename external dependencies to placeholder dependencies. 2020-07-27 09:24:36 -07:00
Artem Chikin
b5af62f93f Add new dependency kind (swiftExternal) to model external dependencies. 2020-07-27 09:24:35 -07:00
Xi Ge
056f00322d DependenciesScanner: refactor cross import overlay resolver to a standalone function. NFC
This change facilitates resolving cross-import overlays from transitive dependencies.
2020-07-23 17:47:47 -07:00
Saleem Abdulrasool
09975d1253 sprinkle llvm_unreachable for covered switches (NFC)
Annotate the covered switches with `llvm_unreachable` to avoid the MSVC
warning which does not recognise the covered switches.  This allows us
to avoid a spew of warnings.
2020-05-07 11:05:35 -07:00
Michael Forster
4852210fd5 More StringRef->std::string conversion fixes 2020-04-29 17:40:51 +02:00
Doug Gregor
d6484c8280 [Dependency scanning] Scan and record bridging header dependencies.
When there is a bridging header associated with the module, scan and record
its dependencies. Note them in a separate structure to capture the specific
dependencies of the bridging header.
2020-04-24 12:58:45 -07:00
Doug Gregor
33cdd61835 Fast dependency scanning for Swift
Implement a new "fast" dependency scanning option,
`-scan-dependencies`, in the Swift frontend that determines all
of the source file and module dependencies for a given set of
Swift sources. It covers four forms of modules:

1) Swift (serialized) module files, by reading the module header
2) Swift interface files, by parsing the source code to find imports
3) Swift source modules, by parsing the source code to find imports
4) Clang modules, using Clang's fast dependency scanning tool

A single `-scan-dependencies` operation maps out the full
dependency graph for the given Swift source files, including all
of the Swift and Clang modules that may need to be built, such
that all of the work can be scheduled up front by the Swift
driver or any other build system that understands this
option. The dependency graph is emitted as JSON, which can be
consumed by these other tools.
2020-04-24 12:58:41 -07:00