Commit Graph

249 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 429416cabd [CAS] Store the input index along the compiler results
This allows replaying the cached compiler results from an upstream CAS,
if we know the key, without needing access to the caching key input CAS tree.
2026-05-19 11:09:35 -07:00
Steven Wu f494a0b02f [BridgingHeader] auto chaining refinement
This refines how bridging header chaining is done, mainly fixing two
problems:
* On Windows, `#import` statement is not supported. Instead of relying
  on #import to workaround bridging header missing header guard, do a
  simple deduplication in header generation.
* The __has_include check can failed the dependency scanner if the search
  path hits `permission_denied` error. In that case, we cannot rely on
  the clang dependeny scanner to check if the bridging header exists or
  not. Swift dependeny scanner need to know how to reverse mapping and
  check before generating the header.

rdar://175196897
2026-04-27 13:15:11 -07:00
Steven Wu fd8dddc9cd [Caching] Use on-disk path for first-time diagnostic emission with prefix mapping
When CachedDiagnostics emits diagnostics for the first time (cache miss),
the file path shown was the internal prefix-mapped path instead of the real
on-disk path.

Apply remapFilePath when creating the buffer so first-time emission matches
the replay path.

rdar://175263981
2026-04-21 10:26:06 -07:00
Doug Gregor 8713c13bef Centralize computation of the "code generation model" for object code & SIL
For a given function, we might end up emitting it's definition as
object code, serialized SIL, or both. The @export, @inlinable, and
@inline(always) attributes provide control of this behavior at the
declaration level.

Centralize the query function that will look for each of these
attributes and map down to a specific "code generation model", whose 3
options follow the naming from SE-0497: interface, inlinable, and
implementation. Use this one computation to back the queries for
"always emit into client", "never emit into client", and "inlinable"
so we can't get inconsistent results from places that are doing
one-off checks for these attributes.
2026-04-15 13:03:55 -07:00
Saleem Abdulrasool 2b8ee6e5a2 test: disallow llvm-bcanalyzer and use new macro
This ensures that we use the correct llvm-bcanalyzer from the just built
compiler tools.
2026-04-13 16:22:02 -07:00
Steven Wu d2f52f2ab5 Merge pull request #88365 from cachemeifyoucan/eng/PR-swiftdeps-source-file-name
[FineGrainedDeps] Use source path instead of swiftdeps path for sourceFileProvide key
2026-04-09 17:54:11 -07:00
Sam Pyankov 2be1203f7b Merge pull request #88345 from sepy97/SerializeLibraryLevel
Serialize library level into .swiftmodule binary format
2026-04-09 09:40:50 -07:00
Steven Wu 67d331546e [FineGrainedDeps] Use source path instead of swiftdeps path for sourceFileProvide key
The swiftdeps output path is marked CacheInvariant and should not appear
in output content. Use the source file path (SF->getFilename()) instead
of the output path when constructing sourceFileProvide dependency nodes.
2026-04-09 09:13:11 -07:00
Sam Pyankov a09cf04718 Serialize library level into .swiftmodule binary format
Add a LIBRARY_LEVEL record to the .swiftmodule options block so the
declared -library-level value survives across compilations. Without
this, imported modules have to always fell back to a path heuristic
that could only distinguish API vs SPI and never returned IPI.

rdar://174255626
2026-04-08 12:17:32 -07:00
Steven Wu a0635b0cd7 [IncrementalScan][Caching] Validate Swift Binary Module Deps
For swift binary module deps, it's cache key and output are setup during
dependency scanning time. When loading the module dependency from the
incremental cache, need to validate the CAS key and output for swift
binary module both exist in the CAS, otherwise, it needs to be
invalidated so a rescan will re-ingest the binary modules into the CAS.

rdar://173647646
2026-04-07 15:44:17 -07:00
Steven Wu 6aacc38051 Merge pull request #88275 from cachemeifyoucan/eng/PR-173736094
[ConstExtract][Caching] Remap file path in ConstExtract JSON
2026-04-07 15:35:05 -07:00
Steven Wu 5bddf886bb [ConstExtract][Caching] Remap file path in ConstExtract JSON
Fix that the `file` fields in ConstExtract JSON output are all prefix
mapped path when caching and prefix mapping are all enabled. This can
cause the consumers of the output failed to find the source file.

Now the JSON file is correct updated with the correct source file
location when caching is on. This allows both un-prefix-mapped source
location and relocatable source file location. As a bonus, now CAS
stores the compact version of the JSON file to save space without
affecting the pretty formatted final output file.

rdar://173736094
2026-04-02 10:15:54 -07:00
Steven Wu 38cf5f87f4 [DependencyScan][Caching] Do not mix CAS instance
Make sure the CAS instances are not mixed during dependency scanning,
especially when used from libSwiftScan C APIs.

For clang scanning service and file system, it should always be created
from the global CAS instance.

For CAS instance inside the swift instance when performing dependency
scanning, it reuse the CAS instance from global as well if that is
already initialized.

rdar://173703843
2026-04-01 11:46:17 -07:00
Saleem Abdulrasool e394b67f75 test: correct %plugin definition
This is a host property, not a target property. When cross-testing a
Unix-like environment on Windows, we find that we load the plugin from
the wrong location. Correct the definition to use the toolchain host as
the basis for the decision.
2026-03-25 08:38:52 -07:00
Steven Wu 22b01f3aa1 Merge pull request #87944 from cachemeifyoucan/eng/PR-172870182 2026-03-20 20:46:26 -07:00
Argyrios Kyrtzidis 2c4988d6f9 Merge pull request #87981 from akyrtzi/akyrtzi/pr/swiftscan-casfsbuilder-apis
[CAS][SwiftScan] Introduce APIs for creating a CASFS root
2026-03-20 16:45:40 -07:00
Argyrios Kyrtzidis b0537d7a7b [CAS][SwiftScan] Introduce APIs for creating a CASFS root
These are APIs that are wrapping `llvm::cas::CASFSBuilder`
2026-03-20 10:58:11 -07:00
Steven Wu 8d1e4c4988 [BridgingHeader] Improve bridging header scanning to fix corner cases
Improve bridging header chaining when prefix mapping is used so it
matches the behavior of non-prefix-map and non-caching builds.
This also fixes a corner case where the same bridging header is used
by different modules in the dependency chain, preventing it from being
imported twice.

The improvements are:
* Fully utilize the clang scanner prefix mapping option, which can
  restore prefix-mapped paths during scanning to find the real file on
  the file system. This allows the generated bridging header to always
  reference the header path without worrying about introducing path
  dependencies.
* Move the header existence check from a file system access in the
  Swift scanner to a `__has_include` check in the clang scanner. This
  allows direct header import even when the header path is previously
  prefix mapped.
* Use `#import` to chain bridging headers so the same header will not
  be imported twice.

rdar://172870182
2026-03-19 16:42:19 -07:00
Steven Wu 357f58b65f [Macro][Caching] Improve macro plugin verification
In order to achieve sound caching, plugin loader double checks the
plugin loaded is the same as what dependency scanner sees during
compilation. However, user can pass a non-existing macro plugin to the
compiler and that should trigger a warning during compilation. Improve
the plugin verification to handle the case where the plugin is passed
but missing on the file system.

rdar://172930632
2026-03-19 14:30:41 -07:00
Steven Wu b25df1566d [TEST-ONLY] Fix CAS/swift-scan-test
Don't diff `stat` output, which might be different due to last access
time. Using `getmtime` script to compare mtime only to make sure the
output is not updated.

rdar://172853933
2026-03-18 13:27:04 -07:00
Steven Wu a0451cc33a Merge pull request #87922 from cachemeifyoucan/replay-cache-hit-config
[Caching] Do not update file if the same when cache replay
2026-03-18 09:09:28 -07:00
Steven Wu 3ba1ba45d4 Merge pull request #87892 from cachemeifyoucan/eng/PR-172693314
[DependencyScan] Propagate module library level through dependency scanner for CAS builds
2026-03-18 09:08:27 -07:00
Steven Wu b9700aa6cc [Caching] Do not update file if the same when cache replay
Make sure cache replay matches the same behavior as normal compilation
that the output is not written (timestamp preserved) when replaying
cache hits. This make sure the downstream dependencies are not
invalidated on a cache hit but the output doesn't change.
2026-03-17 16:59:21 -07:00
Steven Wu 34d52cfe1a [DependencyScan] Propagate module library level through dependency scanner for CAS builds
Compute and propagate the library level (api/spi/ipi) of each module
dependency through the dependency scanner so that the compiler can
correctly enforce private module import diagnostics in CAS mode, where
path-based SPI detection fails because CAS abstracts file paths to
content IDs.

Swift modules:
- Detect library level from the module interface path using
  libraryLevelFromPath() during scanning, for both textual (.swiftinterface)
  and binary (.swiftmodule) Swift modules.

Clang modules:
- Expose ModuleMapIsPrivate from clang::Module in ModuleDeps via the
  dependency scanning infrastructure.
- Set library level for clang modules in bridgeClangModuleDependency()
  using ModuleMapIsPrivate (catches module.private.modulemap in any
  SDK location) and libraryLevelFromPath() on the module map file
  (catches modules under PrivateFrameworks directories).

The library level is:
- Stored in ModuleDependencyInfo and serialized in the module dependency
  cache (format version bumped to v8).
- Exposed through the swiftscan C API via a new
  swiftscan_module_info_get_library_level() function (API minor version
  bumped to 3).
- Emitted in the dependency scanner JSON output as "libraryLevel" for
  all module kinds (Swift textual, Swift binary, Clang, and main module).
- Parsed from the explicit module map JSON by ExplicitModuleMapParser
  for both Swift (ExplicitSwiftModuleInputInfo) and Clang
  (ExplicitClangModuleInputInfo) modules.
- Looked up in ModuleLibraryLevelRequest via
  ASTContext::getExplicitModuleLibraryLevel(name, isClang), which
  consults the appropriate map (Swift or Clang) based on module kind.

rdar://172693314

Assisted-By: Claude
2026-03-17 11:04:18 -07:00
Ben Langmuir 11312f84de [cas] Introduce a frontend option to write CAS hash to an xattr
With the new option, when doing caching we write the hash that we already
computed for the main output file to an extended attribute (xattr) on the file.
This is equivalent to clang's -fwrite-output-hash-xattr option.

The format of the xattr is
name: com.apple.clang.cas_output_hash
data:
* Null-terminated hash schema name, e.g. llvm.builtin.v2[BLAKE3].
* Hash length (4 bytes, little-endian).
* Hash bytes

rdar://171185394
2026-03-16 15:06:33 -07:00
Steven Wu 083029a112 [DebugInfo][Caching] Using CASID for bridging header PCH
Fix the debug info emitted for bridging header PCH when compilation
caching is used. This includes:
* Bridging header should have the correct dwo_name that uses CASID
* The search_path for PCH should be the cache key that can load the PCH
  just like other modules.
2026-03-12 17:16:16 -07:00
Steven Wu 4493089aeb [Caching] Support Profile build
Fix build using profile data by setting up profiling data correctly
through the VFS layer.

rdar://172295490
2026-03-12 08:53:16 -07:00
Adrian Prantl 8ef2d49796 Merge pull request #87296 from cachemeifyoucan/eng/PR-169110002
[Caching] Support -debug-module-path type of debug info
2026-03-06 18:05:36 -08:00
Steven Wu fb7e6af60e [Caching] Fix a module build regression in #86881
Fix a module build regression in PR86881 that causes an increase of
swift interface compilation tasks due to including the
const-gather-protocol list files into the build dependencies for
swiftinterface files. This causes targets cannot sharing module
dependencies.

This make sures the CASFS system only captures the const-gather-protocol
list in the tasks for main module, not for any of its module
dependencies.

rdar://171506799
2026-03-03 08:58:13 -08:00
Steven Wu c496931403 [Caching] Support -debug-module-path type of debug info
Add flag `-debug-module-cache-key` and flag `-debug-module-self-key` to
support embedded swift module output in the debug info via CASID.

rdar://169110002
2026-02-27 09:42:05 -08:00
Steven Wu 489436ffab [Modules] Don't search for cross import when building explicit modules
Do not search for cross import when building swiftinterfaces. This is
uncessary because:
* The cross import modules are explicitly listed in the interface file
  thus there is no need to walk the file system to discover more
  cross imports.
* All cross imports are discovered by scanner already and the
  dependencies are passed to the interface building job. There is no
  need to search file system to find the module to consume.

This reduces the work needed when building interface and fix a bug that
the file system walk when caching is enabled can cause build failures on
windows platform.
2026-02-21 13:35:34 -08:00
Ryan Mansfield f07c1a1b82 Merge pull request #87284 from rjmansfield/se-0441-alias-swap
Swap the alias relationship between -language-mode and -swift-version.
2026-02-20 18:14:44 -05:00
Steven Wu af6270ce6a Merge pull request #87208 from cachemeifyoucan/eng/PR-170007480
[ExplicitModule] Teach scanner emit loaded module trace
2026-02-19 15:25:59 -08:00
Ryan Mansfield ae78773ad8 Swap the alias relationship between -language-mode and -swift-version.
As specified in SE-0441, -language-mode should appear in help output
while -swift-version should be the hidden alias.

Related to swiftlang/swift-driver#1894
2026-02-18 16:06:08 -05:00
Steven Wu 7fdf642819 [ExplicitModule] Teach scanner emit loaded module trace
During explicit module build, teach dependency scanner to emit the
module trace file instead of each following compile job command. This
reduces the duplicated info, and allows supporting fully cached build
that only loads module from CAS thus cannot produce the path to the
original module file on disk.

rdar://170007480
2026-02-18 09:10:08 -08:00
Hunter Baker a4f20039b7 Rename SwiftSyntax experimental SPI to ExperimentalLanguageFeatures to unify naming
Replaces the other ExperimentalLanguageFeature (non-plural) SPI usages with the plural version. Also removes the `@_spi` flag from BodyMacroWithControlFlow as body macros are no longer an experimental feature. This is liked to a PR on swift-syntax: https://github.com/swiftlang/swift-syntax/pull/3272
2026-02-16 17:41:59 -05:00
Steven Wu 17d969924c [SDKInfo] Fix SDKInfo loading to use correct VFS
Partially revert https://github.com/swiftlang/swift/pull/86309. Keep the
SDKInfo parsing in the ASTContext separately from the search path
configuration. This allows the availablity checking to load SDKSettings
from the correct VFS.

rdar://169886913
2026-02-09 15:03:53 -08:00
Steven Wu 1852967fcf [Caching] Support -const-gather-protocols-file correctly
Previously, const-values output is not supported correctly as it is not
captured correctly as a dependency. The load of the input JSON file is
loaded via file system directly, that can cause issues like:
* False cache hit when the file is changed
* Cannot be prefix mapped to allow distributed caching

Try to support the input file by:
* Correctly capture the input
* Create a new driver flag `-const-gather-protocols-list` that can do
  path remapping correctly in swift-driver

rdar://169109358
2026-01-30 13:14:33 -08:00
Ian Anderson fc628a8bfb [test][NFC] Add more keys to test SDKSettings files
Every time DarwinSDKInfo reads a new key out of SDKSettings, a boatload of test SDKSettings files need to be updated across several repositories and forks and branches. It’s tedious to be careful to update those with real values so that the tests are properly regression testing older SDKs. It’s important to be careful so that the tests are accurate, e.g. to prevent the scenario where DarwinSDKInfo starts reading a new key out of SDKSettings and assumes that it’s always available everywhere, when in reality it was only added a few releases ago and will break with older SDKs. If the test SDKSettings files continue to be updated ad hoc, it’s going to be really easy to copy/paste a default value everywhere, and then clients will see incorrect behaviors with the real SDKs, or even compiler crashes if the key is unconditionally read. Preemptively add all of the maybe-possibly-compiler relevant keys to the test SDKSettings files from the real SDKs so that the test files are an accurate representation and shouldn't need to be touched in the future. Where the test SDKSettings have intentionally doctored data, add a Comments key explaining what is changed from the real SDK, and alter the SDK name with a tag indicating the change.

rdar://168700857
2026-01-23 02:19:36 -08:00
Steven Wu c5189de182 [ScanDependency] Fix canImport when versioned checks all eval to false
Fix a corner case when following conditions are met in a single module:
* Module A is imported in the current module
* There exists a versioned `canImport` check for a module A
* All `canImport` check within the module evaluated to false

If all above conditions are met, swift-frontend will not received the
version number from scanner, and it will be confused if version is
either not available (thus a warning, and treat as true), or condition
is not met (eval to false).

Now make sure if when scanner tries to resolve `canImport`, it will
record all instances that a module can be imported, or a version of the
module is found.

rdar://167784812
2026-01-12 15:57:52 -08:00
Steven Wu 1df1e2f781 Merge pull request #86398 from cachemeifyoucan/eng/PR-167640539
[TEST-ONLY] Disable flaky test on FreeBSD
2026-01-09 18:38:01 -08:00
Steven Wu 69b36e99e5 [TEST-ONLY] Disable flaky test on FreeBSD
Disable CAS/include-tree-cxx.swift test on FreeBSD.

rdar://167640539
2026-01-08 15:27:07 -08:00
Steven Wu 6b3b6608b6 Merge pull request #86363 from cachemeifyoucan/eng/PR-167707148
[Caching][DependencyScan] Fix main module header chaining
2026-01-08 14:46:15 -08:00
Ian Anderson c0d0d73c4f [Test][Darwin] Add CanonicalName and SupportedTargets to all applicable SDKSettings
clang will start looking at CanonicalName and SupportedTargets soon, and error if those aren't as expected in the shipping SDKs. Pre-emptively add those to the test SDKSettings.

rdar://166277280
2026-01-07 23:59:29 -08:00
Steven Wu 7b4c2f37e5 [Caching][DependencyScan] Fix main module header chaining
Fix a programming mistake when chaining bridging header for the main
module. Main module never has the binary module, thus it always need to
chain the bridging header content directly without falling back to
embedded binary module. Previously, the scanner was wrongly error out
because it failed to locate the binary module for main module.

rdar://167707148
2026-01-07 20:55:00 -08:00
Steven Wu 36e1f62119 [DebugInfo] CAS built swift TU should have CASID as dwo_name for PCM
When using compilation caching, make sure the debug info emitted in the
swift TU references PCM files via CASID instead of file path. This
allows dsymutil and lldb to load clang modules correctly from CAS,
instead of relying on file system to load the file.

rdar://167054494
2025-12-22 16:53:49 -08:00
Saleem Abdulrasool 4d4b82a641 Merge pull request #85978 from compnerd/cas-support
test: enable CAS tests on Windows
2025-12-18 08:08:53 -08:00
Saleem Abdulrasool 0ee389bd16 Merge pull request #86090 from compnerd/remapping
test: disable CAS.path_remap on Windows
2025-12-17 20:33:27 -08:00
Artem Chikin dad62f8017 Merge pull request #86079 from artemcm/DependencyScanningMetrics
[Dependency Scanning] Add tracking of the number of dependency queries and emit them as remarks
2025-12-17 17:55:44 -08:00
Artem Chikin 7017034d20 [Dependency Scanning] Add tracking of the number of dependency queries and emit them as remarks
This change adds collection of three metrics to the scanner:
- number of Swift module lookups
- number of named Clang module lookups
- recorded number of Clang modules which were imported into a Swift module by name

It introduces '-Rdependency-scan', which acts as a super-set flag to the existing '-Rdependency-scan-cache' and adds emission of the above metrics as remarks when this flag is enabled. Followup changes will add further remarks about dependency scanner progress.
2025-12-17 12:50:33 -08:00