71 Commits

Author SHA1 Message Date
Artem Chikin
d24e15812b Build libSwiftStaticMirror as a standalone library with minimal required dependencies.
This separates it from `libSwiftScan` and allows us to build this library without building much of the rest of the compiler.

Also refactor `utils/build-parser-lib` into `utils/build-tooling-libs` which builds both SwiftSyntaxParser and SwiftStaticMirror.
2022-02-09 12:28:21 -08:00
Alex Hoppen
63c31033fc [Frontend] Load standard libarary in CompilerInstance::setup
Instead of checking that the stdlib can be loaded in a variety of places, check it when setting up the compiler instance. This required a couple more checks to avoid loading the stdlib in cases where it’s not needed.

To be able to differentiate stdlib loading failures from other setup errors, make `CompilerInstance::setup` return an error message on failure via an inout parameter. Consume that error on the call side, replacing a previous, more generic error message, adding error handling where appropriate or ignoring the error message, depending on the context.
2021-12-13 15:32:08 +01:00
Artem Chikin
40a1b321f5 Add libSwiftScan entry-point to query target info.
This provides the library with functionality to answer `-print-target-info` queries in place of calls to `swift-frontend`.
2021-11-12 11:01:45 -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
5440e2febe [DependencyScanning] Loading the scanner cache returns true on failure.
The code made the opposite assumption.
2021-06-03 16:49:27 -07:00
Artem Chikin
7e2c8e97fc [Dependency Scanning] Add ability for -scan-dependencies action to serialize and deserialize dependency scanner cache from a .moddepcache file.
Using the serialization format added in https://github.com/apple/swift/pull/37585.

- Add load/save code for the `-scan-dependencies` code-path.
- Add `libSwiftDriver` entry-points to load/store the cache of a given scanner instance.
2021-06-01 14:45:50 -07:00
Artem Chikin
e1b3ad8b10 [Dependency Scanning] Reset LLVM option occurences for each libSwiftScan query
We must reset option occurences on each individual query because when an instance of the scanning tool is re-used in different contexts/different scans, we will be creating multiple compilation instances and re-parsing various (potentially-repeating) arguments.

Resolves rdar://75247030
2021-04-14 16:40:09 -07:00
Artem Chikin
39483f0a91 [Dependency Scanning] Cache compiler instance/module depenency cache used for batched versioned-PCM scans. 2021-01-07 09:08:21 -08:00
Artem Chikin
41a09a4092 [Dependency Scanning] Establish object ownership convention by using a Foundation-style ownership signals naming scheme across the API surface.
Foundation-style ownership signals documentation:
https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-CJBEJBHH
2021-01-07 09:08:21 -08:00
Artem Chikin
f91c8a8574 [Dependency Scanning] Refactor string implementation to always malloc and tie lifetime to owning object. 2021-01-07 09:08:21 -08:00
Artem Chikin
cff741b60f [Dependency Scanning] Make the prescan dependency scan result (import set) an opaque structure 2021-01-07 09:08:20 -08:00
Artem Chikin
409de733f7 [Dependency Scanning] Make the overall dependency scan result (inter-module dependency graph) an opaque structure 2021-01-07 09:08:20 -08:00
Artem Chikin
fcf943370e [Dependency Scanning] Change C API prefix to: swiftscan from ds and adopt query method naming scheme of:
`<prefix>_<object>_<action>`
2021-01-07 09:08:20 -08:00
Artem Chikin
2ad960083a [Dependency Scanning] Use an opaque type for dependency module details with API query functions for individual fields 2021-01-07 09:08:20 -08:00
Artem Chikin
75b8a0ea44 [Dependency Scanning] Add entry-point to DependencyScanningTool and the corresponding C API for an import prescan operation 2021-01-07 09:08:20 -08:00
Artem Chikin
75a8cfa048 [Dependency Scanning] Add a C API layer for dependency scanning tool, scanning actions, and scan results.
Adds a C API layer consisting of:
- Data structures used to represent in-memory result of dependency scanning
- Opaque dependency scanner tool (C wrapper for `DependencyScanningTool`)

Refactors `ScanDependencies.cpp` to produce dependency scanning result in the form of the above binary format.
2021-01-07 09:08:20 -08:00
Artem Chikin
082fc48b25 [Dependency Scanning] Refactor dependency scanner to return an in-memory format as a result
This commit refactors ScanDependencies.cpp to split the functionality into two functional groups:
- Scan execution code that performs the mechanics of the scan and produces an in-memory result
- Dependency scanner entry-points used when the scanning action is invoked as a `swift-frontend` execution mode
This commit also adds the aforementioned in-memory dependency scanning result in `FullDependencies.h`, modeled after the InterModuleDependencyGraph representation in swift-driver
2021-01-07 09:08:20 -08:00
Artem Chikin
dad14358fb [Dependency Scanning] Factor out import prescan into separate utility 2021-01-07 09:08:20 -08:00
Artem Chikin
aabcb22df1 Rename SwiftScan directory into DependencyScan 2021-01-07 09:08:20 -08:00