[POC] {cwd} placeholder in --remap-path-prefix#157405
Draft
ashi009 wants to merge 1 commit into
Draft
Conversation
Collaborator
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @chenyukang (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:
|
This comment has been minimized.
This comment has been minimized.
Proof-of-concept for an alternative to the incremental-cache invalidation caused
by remapping the current working directory. Validates feasibility ahead of a
Major Change Proposal; not meant to merge as-is.
Today `-Zremap-cwd-prefix=V` resolves the absolute cwd at parse time and stores
it in `remap_path_prefix` (`[TRACKED_NO_CRATE_HASH]`), so the working directory
enters the incremental command-line hash and a build from a different directory
(e.g. a sandbox) purges the cache even though the remapped output is identical.
This lets a `--remap-path-prefix` FROM contain a `{cwd}` placeholder. The FROM is
stored verbatim (so `{cwd}` the placeholder and `{{cwd}}` the escaped literal stay
distinct in storage, with no new type needed), and the placeholder is expanded to
the working directory only when the `FilePathMapping` is built. The stored value
is therefore stable across build directories and keeps the incremental cache
valid. `-Zremap-cwd-prefix=V` becomes exactly sugar for
`--remap-path-prefix={cwd}=V`, providing a path to sunset it.
`{cwd}` uses `format!`-style escaping (`{{`/`}}`). Open questions for the MCP:
unknown-placeholder handling (kept literal here), the precise escaping rules, and
the relationship to remap-path-scope and RFC 3127. Adding placeholder semantics to
a stable flag is a stable-surface change and needs sign-off.
7190bc6 to
761963b
Compare
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.
Warning
Proof-of-concept, do not merge. Validates feasibility + CI ahead of a Major Change Proposal, since it adds placeholder semantics to the stable
--remap-path-prefixflag. Companion to #157348 (the minimal, unstable-only fix that can land now).Idea
Let a
--remap-path-prefixFROM contain a{cwd}placeholder:The FROM is stored verbatim in
remap_path_prefix, and the placeholder is expanded to the working directory only when theFilePathMappingis built (apply time). So:{cwd}/sub), not the absolute cwd → its dependency hash is stable across build directories → the incremental cache survives (fixes the cwd half of no-op remap_path_prefix change invalidates incremental cache #132132).{cwd}(placeholder) and{{cwd}}(escaped literal) distinct in storage, so a plainPathBufis sufficient.-Zremap-cwd-prefix=Vis reimplemented as exactly sugar for--remap-path-prefix={cwd}=V, giving a path to sunset that unstable flag.Escaping
format!-style: a path component{cwd}is the placeholder;{{/}}are literal{/}, so a literal{cwd}directory is written{{cwd}}.Why
{cwd}(vs<cwd>,%cwd%,\(cwd))format!syntax — native to Rust, self-escaping ({{/}}), doesn't look path-like.<cwd>/\(cwd): shell redirection / backslash issues (\is the Windows path separator).%cwd%: collides with cmd.exe%VAR%(%CD%).(Hand-typed it's quoted like any tool-level token; build systems pass argv with no shell, so it arrives verbatim.)
Open questions for the MCP
{cwd},{{/}}here).--remap-path-scope; relationship to RFC 3127.Tests
{cwd}/substored-verbatim + applied; escaped{{cwd}}stays literal;-Zremap-cwd-prefix→{cwd}equivalence.r? compiler