Skip to content

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented May 30, 2025

See #t-compiler/help > Span pointing to wrong file location (`rustc-dev` component).

The path remapping and unremapping for compiler sources (distributed via rustc-dev dist component) is broken because bootstrap currently remaps all sources unconditionally (if remapping is enabled) to the /rustc/{hash} form. However, the rustc-dev dist component (compiler sources) and rust-src dist component (library sources) unpacks differently:

  • rust-src unpacks sources to a path like $sysroot/lib/rustlib/src/rust, whereas
  • rustc-dev unpacks sources to a path like $sysroot/lib/rustlib/rustc-src/rust1,

meaning that the compiler need to unremap them differently. But the same remapping means that the compiler has no way to distinguish between compiler and non-compiler (esp. standard library) sources. To remedy this, this PR adopts the approach of:

  • remapping compiler sources (corresponding to rustc-dev dist component) with /rustc-dev/{hash} (this is RemapScheme::Compiler), and
  • remapping non-compiler sources (corresponding to rust-src dist component or other non-compiler sources) with /rustc/{hash} (this is RemapScheme::NonCompiler).

A different remapping allows the compiler to reverse the remapping differently.

This PR implements the bootstrap side. A follow-up compiler-side change is needed to implement the unremapping change to address the reported issue completely.

This PR introduces another env var CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR that is made available to the compiler when building compiler sources to know what the remap scheme for rustc-dev (RemapScheme::Compiler) is. Compiler sources are built with the compiler remapping scheme.

As far as I know, this change should not introduce new regressions, because the compiler source unremapping (through rustc-dev) is already broken.

Footnotes

  1. (Notice the src vs rustc-src difference.)

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label May 30, 2025
@jieyouxu jieyouxu added the A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. label May 30, 2025
@Urgau
Copy link
Member

Urgau commented May 30, 2025

We'll also need in the compiler a different compile-time environment variable, like is currently done for /rustc/<sha> with CFG_VIRTUAL_RUST_SOURCE_BASE_DIR, otherwise we will not be able to differentiate between the two.

Be aware that both environment variables need to be set when compiling the compiler.

@jieyouxu jieyouxu changed the title [WIP] Remap compiler vs non-compiler sources differently Remap compiler vs non-compiler sources differently (bootstrap side) May 31, 2025
@jieyouxu jieyouxu marked this pull request as ready for review May 31, 2025 13:08
@rustbot
Copy link
Collaborator

rustbot commented May 31, 2025

r? @albertlarsan68

rustbot has assigned @albertlarsan68.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2025
@jieyouxu

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2025
@jieyouxu

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2025
- Map compiler sources (corresponding to `rustc-dev` dist component)
  with `/rustc-dev/{hash}`.
- Map non-compiler sources (corresponding to `rust-src` dist component
  or other non-compiler sources) with `/rustc/{hash}`.

This allows the compiler to have the possibility of opportunistically
reverse the mapping. This is because

- `rust-src` unpacks sources to a path like
  `$sysroot/lib/rustlib/src/rust`, whereas
- `rustc-dev` unpacks sources to a path like
  `$sysroot/lib/rustlib/rustc-src/rust`

(Notice the `src` vs `rustc-src` difference.)
@jieyouxu
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 31, 2025
@Urgau
Copy link
Member

Urgau commented May 31, 2025

The changes looks good to me. Thanks you.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jun 8, 2025

r? bootstrap

@rustbot rustbot assigned Kobzol and unassigned albertlarsan68 Jun 8, 2025
@Kobzol
Copy link
Member

Kobzol commented Jun 9, 2025

Thanks for introducing the enum and the comments, it's now much clearer what's going on.

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 9, 2025

📌 Commit 8976a6e has been approved by Kobzol

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 9, 2025
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 9, 2025
bors added a commit that referenced this pull request Jun 9, 2025
Rollup of 6 pull requests

Successful merges:

 - #141751 (Remap compiler vs non-compiler sources differently (bootstrap side))
 - #142160 (Only allow `bootstrap` cfg in rustc & related)
 - #142191 (early return in trait detection for non-trait item)
 - #142211 (Do not checkout GCC submodule for the tidy job)
 - #142218 (CI: rfl: move job forward to Linux v6.16-rc1)
 - #142224 (Avoid a gratuitous 10s wait in a stress test)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 45cf4fb into rust-lang:master Jun 9, 2025
9 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 9, 2025
rust-timer added a commit that referenced this pull request Jun 9, 2025
Rollup merge of #141751 - jieyouxu:remap, r=Kobzol

Remap compiler vs non-compiler sources differently (bootstrap side)

See [#t-compiler/help > Span pointing to wrong file location (&#96;rustc-dev&#96; component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

The path remapping and unremapping for compiler sources (distributed via `rustc-dev` dist component) is broken because bootstrap currently remaps all sources unconditionally (if remapping is enabled) to the `/rustc/{hash}` form. However, the `rustc-dev` dist component (compiler sources) and `rust-src` dist component (library sources) unpacks differently:

- `rust-src` unpacks sources to a path like `$sysroot/lib/rustlib/src/rust`, whereas
- `rustc-dev` unpacks sources to a path like `$sysroot/lib/rustlib/rustc-src/rust`[^note],

meaning that the compiler need to unremap them differently. But the same remapping means that the compiler has no way to distinguish between compiler and non-compiler (esp. standard library) sources. To remedy this, this PR adopts the approach of:

- remapping compiler sources (corresponding to `rustc-dev` dist component) with `/rustc-dev/{hash}` (this is `RemapScheme::Compiler`), and
- remapping non-compiler sources (corresponding to `rust-src` dist component or other non-compiler sources) with `/rustc/{hash}` (this is `RemapScheme::NonCompiler`).

A different remapping allows the compiler to reverse the remapping differently.

This PR implements the bootstrap side. A follow-up compiler-side change is needed to implement the unremapping change to address the reported issue completely.

This PR introduces another env var `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` that is made available to the compiler when building compiler sources to know what the remap scheme for `rustc-dev` (`RemapScheme::Compiler`) is. Compiler sources are built with the compiler remapping scheme.

As far as I know, this change should not introduce new regressions, because the compiler source unremapping (through `rustc-dev`) is already broken.

[^note]: (Notice the `src` vs `rustc-src` difference.)
@jieyouxu jieyouxu deleted the remap branch June 9, 2025 12:06
fmease added a commit to fmease/rust that referenced this pull request Jun 14, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc `@samueltardieu`
r? `@jieyouxu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 15, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc ``@samueltardieu``
r? ``@jieyouxu``
rust-bors bot added a commit that referenced this pull request Jun 15, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to #141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from #141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc `@samueltardieu`
r? `@jieyouxu`

try-job: x86_64-gnu-llvm-20-3
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 17, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc `@samueltardieu`
r? `@jieyouxu`
Urgau added a commit to Urgau/rust that referenced this pull request Jun 18, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc ``@samueltardieu``
r? ``@jieyouxu``
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 19, 2025
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang/rust#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang/rust#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc ``@samueltardieu``
r? ``@jieyouxu``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants