Skip to content

Commit 729456a

Browse files
[Caching] Put caching diagnostics into its own DiagnosticGroups
Add explanation and documentation for swift caching diagnostics. rdar://154335823
1 parent d385e8c commit 729456a

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

include/swift/AST/DiagnosticGroups.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ GROUP(StringInterpolationConformance, "string-interpolation-conformance")
7171
GROUP(TemporaryPointers, "temporary-pointers")
7272
GROUP(TrailingClosureMatching, "trailing-closure-matching")
7373
GROUP(UnknownWarningGroup, "unknown-warning-group")
74+
GROUP(CompilationCaching, "compilation-caching")
7475

7576
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS
7677
#include "swift/AST/DefineDiagnosticGroupsMacros.h"

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,30 +509,30 @@ REMARK(matching_output_produced,none,
509509
"produced matching output file '%0' for deterministic check: hash '%1'", (StringRef, StringRef))
510510

511511
// Caching related diagnostics
512-
ERROR(error_caching_no_cas_fs, none,
512+
GROUPED_ERROR(error_caching_no_cas_fs, CompilationCaching, none,
513513
"caching is enabled without CAS file-system options, input is not immutable", ())
514514
ERROR(error_prefix_mapping, none, "cannot create scanner prefix mapping: '%0'", (StringRef))
515515

516516
REMARK(replay_output, none, "replay output file '%0': key '%1'", (StringRef, StringRef))
517517
REMARK(output_cache_miss, none, "cache miss for input file '%0': key '%1'", (StringRef, StringRef))
518518

519519
// CAS related diagnostics
520-
ERROR(error_invalid_cas_id, none, "CAS cannot parse id '%0': %1", (StringRef, StringRef))
521-
ERROR(error_cas, none, "CAS error encountered during %0: %1", (StringRef, StringRef))
522-
ERROR(error_cas_fs_creation, none, "cannot create CAS filesystem: %0", (StringRef))
523-
ERROR(error_cache_key_creation, none, "cannot create cache key for compilation %0: %1", (StringRef, StringRef))
524-
ERROR(error_cas_file_ref, none, "cannot load file %0 from CAS filesystem", (StringRef))
525-
ERROR(error_cas_conflict_options, none, "cannot setup CAS due to conflicting '-cas-*' options", ())
526-
ERROR(error_cas_initialization, none, "CAS cannot be initialized from the specified '-cas-*' options: %0", (StringRef))
527-
ERROR(error_cas_malformed_input, none, "CAS input '%0' is malformed: %1", (StringRef, StringRef))
528-
WARNING(cache_replay_failed, none, "cache replay failed: %0", (StringRef))
529-
530-
ERROR(error_failed_cached_diag, none, "failed to serialize cached diagnostics: %0", (StringRef))
531-
ERROR(error_replay_cached_diag, none, "failed to replay cached diagnostics: %0", (StringRef))
532-
533-
ERROR(error_load_input_from_cas, none, "failed to load input '%0' from CAS", (StringRef))
534-
535-
ERROR(error_wrong_input_num_for_input_file_key, none, "-input-file-key only support one input file", ())
520+
GROUPED_ERROR(error_invalid_cas_id, CompilationCaching, none, "CAS cannot parse id '%0': %1", (StringRef, StringRef))
521+
GROUPED_ERROR(error_cas, CompilationCaching, none, "CAS error encountered during %0: %1", (StringRef, StringRef))
522+
GROUPED_ERROR(error_cas_fs_creation, CompilationCaching, none, "cannot create CAS filesystem: %0", (StringRef))
523+
GROUPED_ERROR(error_cache_key_creation, CompilationCaching, none, "cannot create cache key for compilation %0: %1", (StringRef, StringRef))
524+
GROUPED_ERROR(error_cas_file_ref, CompilationCaching, none, "cannot load file %0 from CAS filesystem", (StringRef))
525+
GROUPED_ERROR(error_cas_conflict_options, CompilationCaching, none, "cannot setup CAS due to conflicting '-cas-*' options", ())
526+
GROUPED_ERROR(error_cas_initialization, CompilationCaching, none, "CAS cannot be initialized from the specified '-cas-*' options: %0", (StringRef))
527+
GROUPED_ERROR(error_cas_malformed_input, CompilationCaching, none, "CAS input '%0' is malformed: %1", (StringRef, StringRef))
528+
GROUPED_WARNING(cache_replay_failed, CompilationCaching, none, "cache replay failed: %0", (StringRef))
529+
530+
GROUPED_ERROR(error_failed_cached_diag, CompilationCaching, none, "failed to serialize cached diagnostics: %0", (StringRef))
531+
GROUPED_ERROR(error_replay_cached_diag, CompilationCaching, none, "failed to replay cached diagnostics: %0", (StringRef))
532+
533+
GROUPED_ERROR(error_load_input_from_cas, CompilationCaching, none, "failed to load input '%0' from CAS", (StringRef))
534+
535+
GROUPED_ERROR(error_wrong_input_num_for_input_file_key, CompilationCaching, none, "-input-file-key only support one input file", ())
536536

537537
// Dependency Verifier Diagnostics
538538
ERROR(missing_member_dependency,none,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Compilation Caching
2+
3+
Compilation caching allows swift compiler to reuse previously compiled outputs if the identical
4+
compilation has been done before.
5+
6+
Swift compilation caching uses a CAS (Content Addressable Storage) to capture all the inputs
7+
during dependency scanning time, and the `swift-frontend` invocation can only access these inputs
8+
to ensure the soundness of the caching.
9+
10+
To enable swift compilation caching, use:
11+
12+
* Explicit module build `-explicit-module-build` is a prerequisite for compilation caching
13+
* `-cache-compile-job` to enable compilation caching
14+
* `-cas-path` specify the path to where CAS storage is
15+
16+
If those options are specified, swift-driver will plan the build using swift dependency scanner.
17+
The planned swift-frontend invocations contain CASIDs that are objects backed by the CAS storage
18+
that provide all the inputs for the compilation. These objects need to be in specific format/schemes
19+
that can be consumed by swift compiler, and any malformed inputs will cause errors during compilation.
20+
21+
The CASIDs in the command-lines should be created by swift-driver, and are not expected to be
22+
constructed by users. If inputs are changed, or the CAS storage is deleted, fallback to swift-driver
23+
command (`swiftc` invocation) to regenerate the `swift-frontend` invocation that contains the
24+
correct options.
25+
26+
To clear the cache, delete the directory pointed by `-cas-path` option. Note the CAS directory should
27+
only be deleted as a whole when not used.

0 commit comments

Comments
 (0)