Don't track cwd for -Zremap-cwd-prefix in incremental compilation#157348
Draft
ashi009 wants to merge 1 commit into
Draft
Don't track cwd for -Zremap-cwd-prefix in incremental compilation#157348ashi009 wants to merge 1 commit into
-Zremap-cwd-prefix in incremental compilation#157348ashi009 wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
b094991 to
b9c4f73
Compare
This comment has been minimized.
This comment has been minimized.
b96a8fc to
273c1cb
Compare
This comment has been minimized.
This comment has been minimized.
273c1cb to
6d0225c
Compare
This comment has been minimized.
This comment has been minimized.
ae39a0c to
eb85a15
Compare
This comment has been minimized.
This comment has been minimized.
eb85a15 to
5789e68
Compare
`-Zremap-cwd-prefix=<to>` was applied inside `parse_remap_path_prefix`, which resolved `std::env::current_dir()` and pushed `(cwd, to)` onto `remap_path_prefix`. That option is `[TRACKED_NO_CRATE_HASH]`, so the absolute working directory entered the incremental command-line-args hash, and building the same sources from a different directory (e.g. a Bazel sandbox, whose path contains a per-action counter) purged the whole incremental cache even though the remapped output is identical (rust-lang#132132). `--remap-path-prefix` and `-Zremap-cwd-prefix` already have separate options (`remap_path_prefix` and `remap_cwd_prefix`). Keep each option holding exactly its own flag, and apply `-Zremap-cwd-prefix` in `file_path_mapping` — i.e. when building the (untracked) applied `FilePathMapping` — rather than when parsing/tracking options. The absolute cwd then lives only in the runtime mapping, never in a tracked field. Output is unchanged (the cwd entry is still appended last). Tracking stays sound: the cwd's effect is tracked via `remap_cwd_prefix` (the target prefix baked into output) and `working_dir` (whose `RealFileName` hash includes the real path only when it was not fully remapped, i.e. exactly when the cwd can leak into output). The stable `--remap-path-prefix` flag is unchanged in data and in tracking. A unit test guards against the cwd being merged back into `remap_path_prefix`. Addresses the cwd half of rust-lang#132132.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-Zremap-cwd-prefix=<to>defeats incremental compilation whenever the build directory changes (Bazel sandboxes, CI checkouts with per-build paths), even though the remapped output is identical:Root cause
-Zremap-cwd-prefixand--remap-path-prefixhave two separate options (remap_cwd_prefixandremap_path_prefix), butparse_remap_path_prefixmerges them: it resolvesstd::env::current_dir()and pushes(cwd, to)ontoremap_path_prefix, which is[TRACKED_NO_CRATE_HASH]. The absolute cwd thus entersdep_tracking_hash(false)(compared inrustc_incremental::persist::load), so the same build from a different directory purges the whole incremental session. This is the cwd half of #132132.Fix: apply the cwd prefix where the mapping is built, not where options are tracked
Keep each option holding exactly its own flag, and apply
-Zremap-cwd-prefixinfile_path_mapping— i.e. while building the (untracked) appliedFilePathMapping— instead of inparse_remap_path_prefix. The absolute cwd then lives only in the runtime mapping and never in a tracked option.Behaviour-preserving for output: the applied mapping is identical (the cwd entry is still appended last), so all emitted paths (debuginfo, diagnostics, metadata) are unchanged.
Sound for tracking: the cwd's effect is still tracked, by the two options that should carry it —
remap_cwd_prefix([TRACKED]) — the target prefix baked into output;working_dir([TRACKED]) — andRealFileName's hash already includes the real local path only when the path was not fully remapped (was_fully_remapped()=scopes.is_all()):So under a restrictive
-Zremap-path-scope(where the cwd can still leak into output) the real cwd stays tracked viaworking_dir; under full remapping (where it cannot leak) it is correctly ignored. Dropping the cwd fromremap_path_prefix's hash is therefore sound in every scope.The stable
--remap-path-prefixflag is entirely unchanged in data and in tracking. No SVH/crate-hash change (remap_path_prefixisTRACKED_NO_CRATE_HASH). One file, +32/-17, no new types and no special-case hashing.Status
rustcend-to-end (root cause confirmed empirically under a Bazel sandbox; reasoning above). Needs atests/run-maketest: same crate built from two directories sharing one-Cincrementaldir with-Zremap-cwd-prefix=.→ expect reuse; plus a restricted-Zremap-path-scopevariant → expect a rebuild (proving theworking_dirguard).r? compiler