Commit Graph

75 Commits

Author SHA1 Message Date
Saleem Abdulrasool
9c85fbc8da AST,DependencyScan,IRGen,Serialization,Tooling: track library style (#78777)
Track if the dependency is static or dynamic. This is in preparation for
helping rename the static library to differentiate it from import
libraries.
2025-02-06 13:22:56 -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
477ba0dd97 [Dependency Scanning] Remove references to per-triple PCM variant compilation 2025-01-29 11:32:07 -08:00
Artem Chikin
41e471288a [Dependency Scanning] Deprecate/Remove batch scanning capability
Batch dependency scanning was added as a mechanism to support multiple compilation contexts within a single module dependency graph.
The Swift compiler and the Explicitly-built modules model has long since abandoned this approach and this code has long been stale. It is time to remove it and its associated C API.
2025-01-28 15:30:39 -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
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
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
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
3947fa9e16 [Dependency Scanning] Add libSwiftScan entrypoint to query binary module dependencies' header inputs' module dependencies 2024-03-28 11:06:55 -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
Artem Chikin
d2a8e32bc5 [Dependency Scanning] Collect emitted diagnostics per-scan-query 2024-02-27 14:51:54 -08:00
Steven Wu
46e0f7ae19 [libSwiftScan][Caching] Add APIs to manage CAS size
Add new APIs to manage ondisk storage size used by CAS.

rdar://121944849
2024-01-30 15:30:01 -08:00
Steven Wu
76bde39ee7 [Caching] Encoding cache key for input file with index instead of path
Avoid path encoding difference (for example, real_path vs. path from
symlink) by eliminating the path from cache key. Cache key is now
encoded with the index of the input file from all the input files from
the command-line, reguardless if those inputs will produce output or
not. This is to ensure stable ordering even the batching is different.

Add a new cache computation API that is preferred for using input index
directly. Old API for cache key is deprecated but still updated to
fallback to real_path comparsion if needed.

As a result of swift scan API change, rename the feature in JSON file to
avoid version confusion between swift-driver and libSwiftScan.

rdar://119387650
2023-12-18 14:06:00 -08:00
Steven Wu
d02df13445 [libSwiftScan][Caching] Add async download API
Add a new async download API from CASID. This helps build system better
schedule the job/remove duplicated downloads, than using an opaque
cached_output handle.
2023-11-16 15:11:17 -08:00
Steven Wu
034c15ce54 [Caching] Add new CacheReplay APIs to libSwiftScan
Add new APIs libSwiftScan that can be used for cache query and cache
replay. This enables swift-driver or build system to query the cache and
replay the compilation results without invocation swift-frontend for
better scheduling.
2023-11-03 15:59:56 -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
6c3097657a [Caching] Change swift cache key computation
Update swift cache key computation mechanism from one cache key per
output, to one cache key per primary input file (for all outputs that
associated with that input).

The new schema allows fewer cache lookups while still preserving most of
the flexibility for batch mode and incremental mode.
2023-10-13 09:15:22 -07:00
Steven Wu
0f53e7db46 [SwiftScan][Caching] Add support for plugin CAS for caching
Teach libSwiftScan about plugin CAS and add API to create plugin CAS to
use for dependency scanning and cas operations.
2023-09-06 10:36:23 -07:00
Steven Wu
e66d8b6efb [SwiftScan] Fix a typo in SwiftScan C header
Fix a typo in SwiftScan C Header.
2023-07-14 16:27:24 -07:00
Artem Chikin
92d9e61d1a [Dependency Scanning] Emit header dependencies of binary Swift module dependencies in output and provide libSwiftScan API to query it 2023-06-12 15:01:41 -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
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
Rintaro Ishizaki
761cbb0ade [Macros] Add a library to make simple executable plugins for testing
Add `_swiftMockPlugin` library.
Usage:
  #include "swift/swift-c/MockPlugin/MockPlugin.h"

  MOCK_PLUGIN([
    {"expect": {...},
     "response: {...}}
  ])
2023-02-26 12:17:24 -08:00
Artem Chikin
1b4bc33e68 [libSwiftScan] Add V2 target info query API that takes compiler executable path as parameter
This new version takes the path to the compiler executable as a parameter, in order for libSwiftScan to compute compiler-relative portions of runtimeLibraryPaths, runtimeResourcePath. V1, without knowing the path to the compiler executable, produced incomplete sets of these paths.
2023-01-23 09:39:46 -08:00
Artem Chikin
5ac9d5b35f [Dependency Scanning] Provide libSwiftScan API to dispose of a string ref
Previously no API returned a raw 'swiftscan_string_ref_t' directly so this was not needed.
However, 'swiftscan_compiler_target_info_query' returns a string directly, which the clients need to clean up.
2023-01-18 16:33:06 -08:00
Artem Chikin
3db767843e [Dependency Scanning] Record whether discovered binary Swift modules are frameworks
Part of rdar://102824777
2022-12-13 10:44:37 -08:00
Robert Widmann
2d07f382c5 Delete _InternalSwiftSyntaxParser And Its Build Infrastructure
This is the start of the removal of the C++ implementation of libSyntax
in favor of the new Swift Parser and Swift Syntax libraries. Now that
the Swift Parser has switched the SwiftSyntaxParser library over to
being a thin wrapper around the Swift Parser, there is no longer any
reason we need to retain any libSyntax infrastructure in the swift
compiler.

As a first step, delete the infrastructure that builds
lib_InternalSwiftSyntaxParser and convert any scripts that mention
it to instead mention the static mirror libraries. The --swiftsyntax
build-script flag has been retained and will now just execute the
SwiftSyntax and Swift Parser builds with the just-built tools.
2022-11-02 10:35:29 -07:00
Artem Chikin
606151683c [Dependency Scanner] Add API to query emitted diagnostics during a scan 2022-09-08 09:20:15 -07:00
Artem Chikin
c2190aefc0 [SwiftStaticMirror] Create API to query an opaque associated type's same-type requirements 2022-07-08 13:20:05 -07:00
Artem Chikin
3aad9fad9d [SwiftStaticMirror] Create API to query an opaque associated type's protocol requirements 2022-07-05 11:47:58 -07:00
Alex Hoppen
6f7e792637 [SwiftSyntax] Add an API to enable or disable bare slash regex literals from SwiftSyntax
This adds C functions that can be called from SwiftSyntax to enable or disable bare slash regex parsing.

It also adds a function to set the Swift language version - while this is not of top priority at the moment it will become important once we introduce a new language mode again.

rdar://93750821
2022-05-24 09:58:41 +02:00
Artem Chikin
02e15882d4 [Static Mirror] Add entry-points for querying field type information for properties and enum cases 2022-03-04 16:05:08 -08:00
Artem Chikin
e376af58f5 Refactor gathering of field type info from a binary into two steps: collect and output.
The collect step can then be used for other tools, such as the `BinaryScanningTool`.
2022-03-04 14:41:07 -08:00
Artem Chikin
62e07dc339 [Static Mirror] Refactor gathering of associated types from a binary and add SwiftStaticMirror entry-point for it. 2022-03-02 16:28:12 -08:00
Kim de Vos
da22c80d92 Update year in header 2022-02-18 13:34:46 +01:00
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
Artem Chikin
458eccca5f [LibSwiftScan] Add entry-points for querying protocol conformances from the static mirror
This commit adds new entry-points to `libSwiftScan` that operate on the new BinaryScanningTool, which reads out Swift type information from object files, starting with a query of all protocol conformances.
2022-02-02 11:56:17 -08: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
Alex Hoppen
4d4b2b3967 [SwiftSyntax] Include stdint.h from SwiftSyntaxCDataTypes.h 2021-10-14 15:24:13 +02:00
Alex Hoppen
9841d1c5df Merge pull request #39441 from ahoppen/pr/split-swiftsyntax-c-data-types
[SyntaxParser] Split definition of C data types into separate file
2021-09-29 20:12:26 +02:00
Alex Hoppen
b147dfac55 [SyntaxParser] Split definition of C data types into separate file
To split the SwiftSyntax library into two modules – `SwiftSyntax` with no dependency on `_InternalSwiftSyntaxParser.dylib` and `SwiftSyntaxParser` which generates a `SwiftSyntax` tree using `_InternalSwiftSyntaxParser.dylib` – we need to copy the definition of the C types into the SwiftSyntax repository. To make sure the two match, move the duplicated types into their own file. That way, we can compare them in SwiftSyntax’s build script and thus make sure their definitions are the same.
2021-09-24 14:10:49 +02: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
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
Xi Ge
e12148ae13 libSwiftScanner: add an API to invoke compiler in process 2021-07-13 14:56:19 -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
Alex Hoppen
a48713717e [libSyntax] Store range in token_data in C lib parse actions
We don't actually need the range for layout nodes, so just store it
for token nodes. This will also make deferred node handling easier
later on, because we don't need to keep track of layout node ranges.
2021-03-08 18:40:42 +01:00
Alex Hoppen
dd9e831ba7 [libSyntax] Explicitly pass source file length to c parse actions
Previously, the passed in source file was implicitly terminated by the
first null character. The source file might, however, contain a null
character in the middle and we shouldn't stop parsing at it.
2021-03-04 22:20:11 +01:00
Artem Chikin
b3259eaac0 Make string_set_dispose method a part of public API.
It is not a distinct result returned by `swiftscan_compiler_supported_arguments_query` and `swiftscan_compiler_supported_features_query`, not owned by any other type, so it must be disposed of by the clients.
2021-02-10 10:54:05 -08:00