Repository navigation
-Z simulate-remapped-rust-src-base is not fully simulating remap-debuginfo = true #97682
Description
Activity
Thanks for reporting! Totally agree with your suggestions, I'm going to open a PR to disable that UI test later.
- addedA-testsuiteArea: The testsuite used to check the correctness of rustcArea: The testsuite used to check the correctness of rustcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.C-bugCategory: This is a bug.Category: This is a bug.
on Jun 5, 2022 - removedA-testsuiteArea: The testsuite used to check the correctness of rustcArea: The testsuite used to check the correctness of rustc
on Jun 5, 2022 - changed the title
[-]./x.py test src/test/ui now fails with remap-debuginfo = true[/-][+]`-Z simulate-remapped-rust-src-base` is not working as expected with `remap-debuginfo = true`[/+]on Jun 5, 2022 Opened #97750, and retitled this issue as the issue is not limited to UI test, I think.
I couldn't figure where in the source code remap-debuginfo is set for CI builders
remap-debuginfois set when the builder deploys dist artifacts.Found the cause of the mismatch between
remap-debuginfo = trueandremap-debuginfo = false!When
-Z simulate-remapped-rust-src-baseis passed to the compiler, when loading the standard library'srlib/rmetafile paths are remapped on the fly, reproducing the same behavior ofremap-debuginfo = true. This is correct.rust/compiler/rustc_metadata/src/rmeta/decoder.rs
Lines 1578 to 1601 in 9a74608
// If this file is under $sysroot/lib/rustlib/src/ but has not been remapped // during rust bootstrapping by `remap-debuginfo = true`, and the user // wish to simulate that behaviour by -Z simulate-remapped-rust-src-base, // then we change `name` to a similar state as if the rust was bootstrapped // with `remap-debuginfo = true`. // This is useful for testing so that tests about the effects of // `try_to_translate_virtual_to_real` don't have to worry about how the // compiler is bootstrapped. if let Some(virtual_dir) = &sess.opts.debugging_opts.simulate_remapped_rust_src_base { if let Some(real_dir) = &sess.opts.real_rust_source_base_dir { if let rustc_span::FileName::Real(ref mut old_name) = name { if let rustc_span::RealFileName::LocalPath(local) = old_name { if let Ok(rest) = local.strip_prefix(real_dir) { *old_name = rustc_span::RealFileName::Remapped { local_path: None, virtual_name: virtual_dir.join(rest), }; } } } } } The problem is, below in the same file, another piece of code tries to determine the local path of a remapped path if available:
rust/compiler/rustc_metadata/src/rmeta/decoder.rs
Lines 1479 to 1556 in 9a74608
// Translate the virtual `/rustc/$hash` prefix back to a real directory // that should hold actual sources, where possible. // // NOTE: if you update this, you might need to also update bootstrap's code for generating // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`. let virtual_rust_source_base_dir = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR") .map(Path::new) .filter(|_| { // Only spend time on further checks if we have what to translate *to*. sess.opts.real_rust_source_base_dir.is_some() }) .filter(|virtual_dir| { // Don't translate away `/rustc/$hash` if we're still remapping to it, // since that means we're still building `std`/`rustc` that need it, // and we don't want the real path to leak into codegen/debuginfo. !sess.opts.remap_path_prefix.iter().any(|(_from, to)| to == virtual_dir) }); let try_to_translate_virtual_to_real = |name: &mut rustc_span::FileName| { debug!( "try_to_translate_virtual_to_real(name={:?}): \ virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}", name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir, ); if let Some(virtual_dir) = virtual_rust_source_base_dir { if let Some(real_dir) = &sess.opts.real_rust_source_base_dir { if let rustc_span::FileName::Real(old_name) = name { if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } = old_name { if let Ok(rest) = virtual_name.strip_prefix(virtual_dir) { let virtual_name = virtual_name.clone(); // The std library crates are in // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we // detect crates from the std libs and handle them specially. const STD_LIBS: &[&str] = &[ "core", "alloc", "std", "test", "term", "unwind", "proc_macro", "panic_abort", "panic_unwind", "profiler_builtins", "rtstartup", "rustc-std-workspace-core", "rustc-std-workspace-alloc", "rustc-std-workspace-std", "backtrace", ]; let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l)); let new_path = if is_std_lib { real_dir.join("library").join(rest) } else { real_dir.join(rest) }; debug!( "try_to_translate_virtual_to_real: `{}` -> `{}`", virtual_name.display(), new_path.display(), ); let new_name = rustc_span::RealFileName::Remapped { local_path: Some(new_path), virtual_name, }; *old_name = new_name; } } } } } }; That code is not correct, as it only looks at the prefix set by bootstrap when
remap-debuginfo = true, not at the simulated prefix added with the-Zflag. This is the cause of the mismatch in behavior, and that code should be updated to also check for the simulated prefix (as the purpose of that-Zflag is to fully simulateremap-debuginfo = true).This also explains the difference @japaric identified depending on whether the
rust-srccomponent was installed: when it's not installed the second piece of code is skipped, as there is no local path to determine, causing the consistent behavior.- added a commit that references this issue
on Jun 6, 2022 - changed the title
[-]`-Z simulate-remapped-rust-src-base` is not working as expected with `remap-debuginfo = true`[/-][+]`-Z simulate-remapped-rust-src-base` is not fully simulating `remap-debuginfo = true`[/+]on Jun 6, 2022
alternative title:
-Z simulate-remapped-rust-src-baseis not working as expected withremap-debuginfo = trueHello! We are running the compiler test with a compiler configured with
remap-debuginfo = trueand after a recent PR merge we observed that thesrc/test/uitest suite is no longer passing. After looking into the issue I think a (test only?)-Zcompiler flag may not be working as intended. Details below and apologies for not using one of the issue templates!Observations
./x.py test src/test/uiworked fine before PR #97504 withremap-debuginfo = trueset inconfig.toml./x.py test src/test/uistopped working after #97504 was merged.more concretely, the UI test
issue-71363added in PR #97504 fails. the error message looks like the one that was reported by CI in the original PR #89268. see rust-log-analyzerdisabling
remap-debuginfomakes testissue-71363and the test suite pass:Hypotheses
-Z simulate-remapped-rust-src-baseis not working as intended withremap-debuginfo = true.AIUI, the goal of
-Z simulate-remapped-rust-src-base=/rustc/xyzis to make it as if there was norust-srccomponent installed but it's not working when the compiler is built withremap-debuginfo = true. This can be observed in the above test failure: the location oftrait Erroris reported. It can also be observed on nightly (shown below):only removing the
rust-srccomponent makes thatpub traitnote disappear.issue-71363is not being exercised withremap-debuginfo = truein CIPR #97504 rebased PR #89268 but added
// only-x86_64-unknown-linux-gnu. with that change theissue-71363test is run in theauto (x86_64-gnu, ubuntu-20.04-xl)builder which is configured with the default ofremap-debuginfo = false. (see temporary logs)I couldn't figure where in the source code
remap-debuginfois set for CI builders but for exampleauto (dist-x86_64-linux, ubuntu-20.04-xl)is configured withremap-debuginfo = true(see temporary logs) but that builder does not run thesrc/test/uitests.OTOH,
auto (dist-i586-gnu-i586-i686-musl, ubuntu-20.04-xl)is configured withremap-debuginfo = true(see temporary logs) and does run thesrc/test/uitests. However, it will not runissue-71363(see temp logs) because the test has a// only-x86_64-unknown-linux-gnudirective. Thisdist-i586builder is the one that failed in the original PR #89268 (again, see rust-log-analyzer); that original PR did not have the// only-directive.Conclusions
-Z simulate-remapped-rust-src-baseis not working as intended withremap-debuginfo = true.issue-71363is a hazard because it will fail if theremap-debuginfoconfiguration of the CI builders is tweaked in the futureSuggestions
I would suggest:
issue-71363needs-test. note that the actual issue is already fixed-Z simulate-remapped-rust-src-base(or re-purporse this issue for that)issue-71363once (3) is sorted outcc @JohnTitor (author of PR #97504)