Skip to content

Commit 37898d0

Browse files
committed
WIP: rework direct mode documentation some more
Most importantly, group similar things together. Also improve some of the wording and (TODO) Also TODO: "provisional fix for [nothing]"
1 parent 755dfe7 commit 37898d0

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

docs/Local.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,44 @@ The local storage only supports a single sccache server at a time. Multiple conc
88

99
## Preprocessor cache mode
1010

11-
This is inspired by [ccache's direct mode](https://ccache.dev/manual/3.7.9.html#_the_direct_mode) and works roughly the same. It allows to skip the preprocessor for cached results when compiling C/C++.
11+
This is inspired by [ccache's direct mode](https://ccache.dev/manual/3.7.9.html#_the_direct_mode) and works roughly the same.
12+
It adds a cache that allows to skip preprocessing when compiling C/C++. This can make it much faster to return compilation results
13+
from cache since preprocessing is a major expense for these.
1214

13-
[preprocessor cache] mode is controlled by a configuration option which is true by default, as well as additional conditions described below.
15+
Preprocessor cache mode is controlled by a configuration option which is true by default, as well as additional conditions described below.
1416

15-
In non-preprocessor cache mode, sccache's compilation pipeline for one C/C++ source file is inputs → preprocessing → cache lookup → (return outputs if cached / compilation otherwise). In preprocessor cache mode, the compilation pipeline is inputs → cache lookup → (return outputs if cached / preprocessing → compilation otherwise). This can make it much faster to return compilation outputs from cache.
17+
To ensure that the cached preprocessor results for a source file correspond to the un-preprocessed inputs, sccache needs
18+
to remember, among other things, all files included by the source file. sccache also needs to recognize
19+
when "external factors" may change the results, such as system time if the `__TIME__` macro is used
20+
in a source file. How conservative sccache is about some of these external factors is configurable, see below.
1621

17-
To ensure that the cached outputs for a source file correspond to the un-preprocessed inputs, [sccache] needs to remember, among other things, all files included by that source file (i.e. the complete set of inputs). To quote ccache's documentation:
22+
Preprocessor cache mode will be disabled in any of the following cases:
1823

19-
> There is a catch with the [preprocessor cache] mode: header files that were used by the compiler are recorded, but header files that were not used, but would have been used if they existed, are not. So, when [sccache] checks if a result can be taken from the cache, it currently can’t check if the existence of a new header file should invalidate the result. In practice, the [preprocessor cache] mode is safe to use in the vast majority of cases.
24+
- The configuration option is false
25+
- Using distributed compilation (provisional fix for )
26+
- Not using GCC or Clang with local storage (only implemented for these)
27+
- The modification time of one of the header files is too new (avoids a race condition)
28+
- A compiler option not supported by preprocessor cache mode is used
29+
- Certain strings such as `__TIME__` are present in the source code, indicating that the preprocessor result may change based on external factors
2030

21-
Preprocessor cache mode will be disabled if any of the following holds:
31+
The preprocessor cache may silently produce stale results in any of the following cases:
2232

23-
- the configuration option is false
24-
- not using GCC or Clang with local storage (only implemented for these)
25-
- the modification time of one of the include files is too new (this avoids a race condition)
26-
- a compiler option not supported by [preprocessor cache] mode is used; this is usually because the compilation has inputs or outputs which [sccache] does not model well enough
27-
- the string `__TIME__` is present in the source code
33+
- When a source file was compiled and its results were cached, a header file would have been included if it existed, but it did
34+
not exist at the time. sccache does not know about such files, so it cannot invalidate the result if the header file later exists.
35+
- A macro such as `__TIME__` is used in the source code and `ignore_time_macros` is enabled
36+
- There are other external factors influencing the preprocessing result that sccache does not know about
2837

2938
Configuration options and their default values:
3039

31-
- `use_preprocessor_cache_mode`: `true`. Whether to use [preprocessor cache] mode. This can be overridden for an sccache invocation by setting the environment variable `SCCACHE_DIRECT` to `true`/`on`/`1` or `false`/`off`/`0`).
40+
- `use_preprocessor_cache_mode`: `true`. Whether to use preprocessor cache mode. This can be overridden for an sccache invocation by setting the environment variable `SCCACHE_DIRECT` to `true`/`on`/`1` or `false`/`off`/`0`).
3241
- `file_stat_matches`: `false`. If false, only compare header files by hashing their contents. If true, will use size + ctime + mtime to check whether a file has changed. See other flags below for more control over this behavior.
3342
- `use_ctime_for_stat`: `true`. If true, uses the ctime (file status change on UNIX, creation time on Windows) to check that a file has/hasn't changed. Can be useful to disable when backdating modification times in a controlled manner.
3443

35-
- `ignore_time_macros`: `false`. If true, ignore `__DATE__`, `__TIME__` and `__TIMESTAMP__` being present in the source code. Will speed up preprocessor cache mode, but can result in false positives.
44+
- `ignore_time_macros`: `false`. If true, ignore `__DATE__`, `__TIME__` and `__TIMESTAMP__` being present in the source code. Will speed up preprocessor cache mode, but can produce stale results.
3645

3746
- `skip_system_headers`: `false`. If true, preprocessor cache mode will not cache system headers, only add them to the hash.
3847

39-
- `hash_working_directory`: `true`. If true, will add the current working directory in the hash to distinguish two compilations from different directories.
48+
- `hash_working_directory`: `true`. If true, will add the current working directory to the hash to distinguish two compilations from different directories.
4049

4150
See where to write the config in [the configuration doc](Configuration.md).
4251

0 commit comments

Comments
 (0)