Commit Graph

25 Commits

Author SHA1 Message Date
Steven Wu
226552bf23 [Caching] Improve diagnostics around swift caching
Improve diagnostics message for swift caching build by trying to emit
the diagnostics early when there is more context to differentiate the
different kind of problems.

After the improvement, CAS Error should be more closer to when there is
functional problem with the CAS, rather than mixing in other kinds of
problem (like scanning dependency failures) when operating with a CAS.

rdar://145676736
2025-05-01 10:36:42 -07:00
Steven Wu
3d38d0dd56 [Caching][Macro] Make macro plugin options cacheable
Currently, the macro plugin options are included as cache key and the
absolute path of the plugin executable and library will affect cache
hit, even the plugin itself is identical.

Using the new option `-resolved-plugin-validation` flag, the macro
plugin paths are remapped just like the other paths during dependency
scanning. `swift-frontend` will unmap to its original path during the
compilation, make sure the content hasn't changed, and load the plugin.
It also hands few other corner cases for macro plugins:

* Make sure the plugin options in the swift module is prefix mapped.
* Make sure the remarks of the macro loading is not cached, as the
  mesasge includes the absolute path of the plugin, and is not
  cacheable.

rdar://148465899
2025-04-10 12:10:00 -07:00
Doug Gregor
e88f8995e1 [Diagnostics] Eliminate educational notes in favor of diagnostic groups
We've been converging the implementations of educational notes and
diagnostic groups, where both provide category information in
diagnostics (e.g., `[#StrictMemorySafety]`) and corresponding
short-form documentation files. The diagnostic group model is more
useful in a few ways:

* It provides warnings-as-errors control for warnings in the group
* It is easier to associate a diagnostic with a group with
GROUPED_ERROR/GROUPED_WARNING than it is to have a separate diagnostic
ID -> mapping.
* It is easier to see our progress on diagnostic-group coverage
* It provides an easy name to use for diagnostic purposes.

Collapse the educational-notes infrastructure into diagnostic groups,
migrating all of the existing educational notes into new groups.
Simplify the code paths that dealt with multiple educational notes to
have a single, possibly-missing "category documentation URL", which is
how we're treating this.
2025-03-29 15:40:35 -07:00
Steven Wu
0613fca744 [Caching] Fix a bug when emitting diagnostics from nested macros
Fix a bug when emitting cached diagnostics from nested macros. When
building a new source manager for cached diagnostics, there is a bug
when creating mapping between FileIDs between two different source
managers. If the newly created file in source manager requires another
file to be mapped, e.g. when emitting a diagnostic from nested macros,
the returning FileID can be updated by the second request before
returning. Fix the bug by making sure two different FileIDs are returned
in this case.

rdar://144810862
2025-02-13 13:46:50 -08:00
Steven Wu
ca87615b4a [CAS] Allow empty filename for diagnostics location
Fix a bug that an empty filename for diagnostics can trigger an error
in the cached diagnostics. The empty filename can be a virtual file
synthesized, for example, to hold an implicit attribute from clang
importer.

The cached diagnostics can correctly handle such filename now and
cached/replay those diagnostics.

rdar://141961161
2025-01-02 13:18:43 -08:00
swift-ci
ec2edb72f0 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-09 14:44:21 -07:00
Steven Wu
1d402d2d62 [CachedDiagnostics] Optimize in case no diagnostics is emitted
When no diagnostics is emitted from the compilation, just use an empty
object as cached diagnostics. That is an optimization for storage to
avoid emitting some supporting file to recreate source manager when not
needed, also save a bit time from emitting YAML file.

rdar://128426132
2024-10-09 09:17:01 -07:00
Ben Barham
2715d0e9d6 Merge branch 'main' into 20240710-main-to-rebranch
Conflicts:
  - `test/Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-itanium.swift`
    previously fixed on rebranch, now fixed on main (slightly differently).
2024-07-10 20:42:09 -07:00
Steven Wu
30737eb396 [Caching] Support swift style diagnostics for swift caching
Add support for swift style diagnostics for swift caching. This includes
pre-populate the GeneratedSourceInfo with macro name so it doesn't need
to infer from an ASTNode, which the caching mechanism cannot preserve.

Still leave the default diagnostic style to LLVM style because replaying
swift style diagnostics is still very slow and including parsing source
file using swift-syntax.

rdar://128615572
2024-07-08 16:15:44 -07:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
swift-ci
6950a31397 Merge remote-tracking branch 'origin/main' into rebranch 2024-06-03 09:33:41 -07:00
Steven Wu
c132f74c3c [Caching] Don't rely on FileSystem when replaying diagnostics
Stop relying on file system to provide source buffer for diagnostics
when replying. This avoids initializing CASFS which is quite expensive.
Now cached diagnostics contains CASID for the file buffer so it can
initialize its own source manager without relying on the underlying file
system.

rdar://128423393
2024-05-31 14:51:26 -07:00
Ben Barham
cacfd3e3ae Rename llvm::support::endianness to llvm::endianness
LLVM is gearing up to move to `std::endianness` and as part of that has
moved `llvm::support::endianness` to `llvm::endianness`
(bbdbcd83e6702f314d147a680247058a899ba261). Rename our uses.
2024-04-08 08:58:58 -07:00
Steven Wu
4e246dfdfd [Caching] Fix stack-use-after-scope in CachedDiagnostics
Fix a stack-use-after-scope in the CachedDiagnostics when the
DiagnosticInfo entry that is getting deserialized has ChildDiagnostics.

There are some fields in the DiagnosticInfo are not owned by the
DiagnosticsInfo itself. While the callback during the deserialization
ensures those fields are still alive for the top level DiagnosticInfo
when it gets used, it is not true for any child diagnostics info inside.

rdar://123846525
2024-03-08 11:01:15 -08:00
Steven Wu
3986937e03 [Caching][NFC] Restructure CASOption in swift. NFC
Clean up how CASOptions are kept and passed inside swift to make the
code more readable. Also avoid a copy of CAS configuration in
ClangImporter.
2024-02-11 14:08:09 -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
30cfa3deb2 [Caching] Re-associate diagnostics cache key with InputFile
Change how cached diagnostics are stored inside the CAS. It used to be
stored as a standalone entry for a frontend invocation in the cache and
now it is switched to be associated with input files, stored together
with other outputs like object files, etc.

This enables cleaner Cache Replay APIs and future cached diagnostics
that can be splitted up by file contribution.
2023-10-30 16:02:19 -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
c8bc08107c Merge pull request #68684 from cachemeifyoucan/eng/PR-path-remapping
[CompilerCaching] Path Remapping for canonicalization
2023-10-04 12:57:27 -07:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
Steven Wu
5be305e839 [CompilerCaching] Teach CachedDiagnostics to replay with prefix map
Teach CachedDiagnosticsProcessor to replay diagnostics for all consumers
with a different path using a path prefix map. This allows diagnostics
to be replayed for the actual path on disk after the scanner
canonicalized the path for compilation.
2023-09-26 12:36:43 -07:00
Steven Wu
b78b569450 [CAS] Consolidate compile cache flags
Rename `-enable-cas` to `-compile-cache-job` to align with clang option
names and promote that to a new driver only flag.

Few other additions to driver flag for caching behaviors:
* `-compile-cache-remarks`: now cache hit/miss remarks are guarded behind
  this flag
* `-compile-cache-skip`: skip replaying from the cache. Useful as a
  debugging tool to do the compilation using CAS inputs even the output
  is a hit from the cache.
2023-06-26 10:34:27 -07:00
Steven Wu
1b70ba1ce2 Fix CachingDiagnosticsProcessor when replay by FileSpecificDiagConsumer
When using a FileSpecificDiagConsumer, the source file that doesn't have
any diagnostics need to exist in the source manager for the consumer to
be successfully created.
2023-06-12 13:22:10 -07:00
Steven Wu
d3891a86ba [CAS] Add caching diagnostic processor
Add a CachedDiagnosticsProcessor that is a DiagConsumer can capture all
the diagnostics during a compilation, serialized them into CAS with a
format that can be replayed without re-compiling.
2023-04-27 13:36:49 -07:00