Skip to content

Commit 4e20c52

Browse files
authored
Unrolled build for #149716
Rollup merge of #149716 - RalfJung:miri, r=RalfJung miri subtree update Subtree update of `miri` to rust-lang/miri@56a3765. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents ba86c04 + 5339794 commit 4e20c52

File tree

82 files changed

+2323
-810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2323
-810
lines changed

src/tools/miri/.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
os: ubuntu-24.04-arm
3232
multiarch: armhf
3333
gcc_cross: arm-linux-gnueabihf
34-
- host_target: riscv64gc-unknown-linux-gnu
35-
os: ubuntu-latest
36-
multiarch: riscv64
37-
gcc_cross: riscv64-linux-gnu
38-
qemu: true
3934
# Ubuntu mirrors are not reliable enough for these architectures
4035
# (see <https://bugs.launchpad.net/ubuntu/+bug/2130309>).
36+
# - host_target: riscv64gc-unknown-linux-gnu
37+
# os: ubuntu-latest
38+
# multiarch: riscv64
39+
# gcc_cross: riscv64-linux-gnu
40+
# qemu: true
4141
# - host_target: s390x-unknown-linux-gnu
4242
# os: ubuntu-latest
4343
# multiarch: s390x

src/tools/miri/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ Definite bugs found:
624624
* [Mockall reading uninitialized memory when mocking `std::io::Read::read`, even if all expectations are satisfied](https://github.com/asomers/mockall/issues/647) (caught by Miri running Tokio's test suite)
625625
* [`ReentrantLock` not correctly dealing with reuse of addresses for TLS storage of different threads](https://github.com/rust-lang/rust/pull/141248)
626626
* [Rare Deadlock in the thread (un)parking example code](https://github.com/rust-lang/rust/issues/145816)
627+
* [`winit` registering a global constructor with the wrong ABI on Windows](https://github.com/rust-windowing/winit/issues/4435)
627628

628629
Violations of [Stacked Borrows] found that are likely bugs (but Stacked Borrows is currently just an experiment):
629630

src/tools/miri/etc/rust_analyzer_helix.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ overrideCommand = [
2828
"./miri",
2929
"check",
3030
"--no-default-features",
31+
"-Zunstable-options",
32+
"--compile-time-deps",
3133
"--message-format=json",
3234
]

src/tools/miri/etc/rust_analyzer_vscode.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"./miri",
2323
"check",
2424
"--no-default-features",
25+
"-Zunstable-options",
26+
"--compile-time-deps",
2527
"--message-format=json",
2628
],
2729
}

src/tools/miri/etc/rust_analyzer_zed.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"./miri",
3232
"check",
3333
"--no-default-features",
34+
"-Zunstable-options",
35+
"--compile-time-deps",
3436
"--message-format=json"
3537
]
3638
}

src/tools/miri/rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1eb0657f78777f0b4d6bcc49c126d5d35212cae5
1+
36b2369c91d32c2659887ed6fe3d570640f44fd2

src/tools/miri/src/bin/miri.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,13 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
272272
}
273273
}
274274

275-
struct MiriBeRustCompilerCalls {
276-
target_crate: bool,
277-
}
275+
/// This compiler produces rlibs that are meant for later consumption by Miri.
276+
struct MiriDepCompilerCalls;
278277

279-
impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
278+
impl rustc_driver::Callbacks for MiriDepCompilerCalls {
280279
#[allow(rustc::potential_query_instability)] // rustc_codegen_ssa (where this code is copied from) also allows this lint
281280
fn config(&mut self, config: &mut Config) {
282-
if !self.target_crate {
283-
// For a host crate, we fully behave like rustc.
284-
return;
285-
}
286-
// For a target crate, we emit an rlib that Miri can later consume.
281+
// We don't need actual codegen, we just emit an rlib that Miri can later consume.
287282
config.make_codegen_backend = Some(Box::new(make_miri_codegen_backend));
288283

289284
// Avoid warnings about unsupported crate types. However, only do that we we are *not* being
@@ -367,16 +362,12 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
367362
_: &rustc_interface::interface::Compiler,
368363
tcx: TyCtxt<'tcx>,
369364
) -> Compilation {
370-
if self.target_crate {
371-
// cargo-miri has patched the compiler flags to make these into check-only builds,
372-
// but we are still emulating regular rustc builds, which would perform post-mono
373-
// const-eval during collection. So let's also do that here, even if we might be
374-
// running with `--emit=metadata`. In particular this is needed to make
375-
// `compile_fail` doc tests trigger post-mono errors.
376-
// In general `collect_and_partition_mono_items` is not safe to call in check-only
377-
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
378-
let _ = tcx.collect_and_partition_mono_items(());
379-
}
365+
// While the dummy codegen backend doesn't do any codegen, we are still emulating
366+
// regular rustc builds, which would perform post-mono const-eval during collection.
367+
// So let's also do that here. In particular this is needed to make `compile_fail`
368+
// doc tests trigger post-mono errors.
369+
let _ = tcx.collect_and_partition_mono_items(());
370+
380371
Compilation::Continue
381372
}
382373
}
@@ -457,32 +448,28 @@ fn main() {
457448

458449
// If the environment asks us to actually be rustc, then do that.
459450
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
451+
if crate_kind == "host" {
452+
// For host crates like proc macros and build scripts, we are an entirely normal rustc.
453+
// These eventually produce actual binaries and never run in Miri.
454+
match rustc_driver::main() {
455+
// Empty match proves this function will never return.
456+
}
457+
} else if crate_kind != "target" {
458+
panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}")
459+
};
460+
460461
// Earliest rustc setup.
461462
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
462463
rustc_driver::init_rustc_env_logger(&early_dcx);
463464

464-
let target_crate = if crate_kind == "target" {
465-
true
466-
} else if crate_kind == "host" {
467-
false
468-
} else {
469-
panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}")
470-
};
471-
472465
let mut args = args;
473-
// Don't insert `MIRI_DEFAULT_ARGS`, in particular, `--cfg=miri`, if we are building
474-
// a "host" crate. That may cause procedural macros (and probably build scripts) to
475-
// depend on Miri-only symbols, such as `miri_resolve_frame`:
476-
// https://github.com/rust-lang/miri/issues/1760
477-
if target_crate {
478-
// Splice in the default arguments after the program name.
479-
// Some options have different defaults in Miri than in plain rustc; apply those by making
480-
// them the first arguments after the binary name (but later arguments can overwrite them).
481-
args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string));
482-
}
466+
// Splice in the default arguments after the program name.
467+
// Some options have different defaults in Miri than in plain rustc; apply those by making
468+
// them the first arguments after the binary name (but later arguments can overwrite them).
469+
args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string));
483470

484471
// We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments.
485-
run_compiler_and_exit(&args, &mut MiriBeRustCompilerCalls { target_crate })
472+
run_compiler_and_exit(&args, &mut MiriDepCompilerCalls)
486473
}
487474

488475
// Add an ICE bug report hook.

src/tools/miri/src/borrow_tracker/tree_borrows/diagnostics.rs

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ struct DisplayFmtPadding {
488488
indent_middle: S,
489489
/// Indentation for the last child.
490490
indent_last: S,
491+
/// Replaces `join_last` for a wildcard root.
492+
wildcard_root: S,
491493
}
492494
/// How to show whether a location has been accessed
493495
///
@@ -561,6 +563,11 @@ impl DisplayFmt {
561563
})
562564
.unwrap_or("")
563565
}
566+
567+
/// Print extra text if the tag is exposed.
568+
fn print_exposed(&self, exposed: bool) -> S {
569+
if exposed { " (exposed)" } else { "" }
570+
}
564571
}
565572

566573
/// Track the indentation of the tree.
@@ -607,23 +614,21 @@ fn char_repeat(c: char, n: usize) -> String {
607614
struct DisplayRepr {
608615
tag: BorTag,
609616
name: Option<String>,
617+
exposed: bool,
610618
rperm: Vec<Option<LocationState>>,
611619
children: Vec<DisplayRepr>,
612620
}
613621

614622
impl DisplayRepr {
615-
fn from(tree: &Tree, show_unnamed: bool) -> Option<Self> {
623+
fn from(tree: &Tree, root: UniIndex, show_unnamed: bool) -> Option<Self> {
616624
let mut v = Vec::new();
617-
extraction_aux(tree, tree.root, show_unnamed, &mut v);
625+
extraction_aux(tree, root, show_unnamed, &mut v);
618626
let Some(root) = v.pop() else {
619627
if show_unnamed {
620628
unreachable!(
621629
"This allocation contains no tags, not even a root. This should not happen."
622630
);
623631
}
624-
eprintln!(
625-
"This allocation does not contain named tags. Use `miri_print_borrow_state(_, true)` to also print unnamed tags."
626-
);
627632
return None;
628633
};
629634
assert!(v.is_empty());
@@ -637,6 +642,7 @@ impl DisplayRepr {
637642
) {
638643
let node = tree.nodes.get(idx).unwrap();
639644
let name = node.debug_info.name.clone();
645+
let exposed = node.is_exposed;
640646
let children_sorted = {
641647
let mut children = node.children.iter().cloned().collect::<Vec<_>>();
642648
children.sort_by_key(|idx| tree.nodes.get(*idx).unwrap().tag);
@@ -661,12 +667,13 @@ impl DisplayRepr {
661667
for child_idx in children_sorted {
662668
extraction_aux(tree, child_idx, show_unnamed, &mut children);
663669
}
664-
acc.push(DisplayRepr { tag: node.tag, name, rperm, children });
670+
acc.push(DisplayRepr { tag: node.tag, name, rperm, children, exposed });
665671
}
666672
}
667673
}
668674
fn print(
669-
&self,
675+
main_root: &Option<DisplayRepr>,
676+
wildcard_subtrees: &[DisplayRepr],
670677
fmt: &DisplayFmt,
671678
indenter: &mut DisplayIndent,
672679
protected_tags: &FxHashMap<BorTag, ProtectorKind>,
@@ -703,15 +710,41 @@ impl DisplayRepr {
703710
block.push(s);
704711
}
705712
// This is the actual work
706-
print_aux(
707-
self,
708-
&range_padding,
709-
fmt,
710-
indenter,
711-
protected_tags,
712-
true, /* root _is_ the last child */
713-
&mut block,
714-
);
713+
if let Some(root) = main_root {
714+
print_aux(
715+
root,
716+
&range_padding,
717+
fmt,
718+
indenter,
719+
protected_tags,
720+
true, /* root _is_ the last child */
721+
false, /* not a wildcard_root*/
722+
&mut block,
723+
);
724+
}
725+
for tree in wildcard_subtrees.iter() {
726+
let mut gap_line = String::new();
727+
gap_line.push_str(fmt.perm.open);
728+
for (i, &pad) in range_padding.iter().enumerate() {
729+
if i > 0 {
730+
gap_line.push_str(fmt.perm.sep);
731+
}
732+
gap_line.push_str(&format!("{}{}", char_repeat(' ', pad), " "));
733+
}
734+
gap_line.push_str(fmt.perm.close);
735+
block.push(gap_line);
736+
737+
print_aux(
738+
tree,
739+
&range_padding,
740+
fmt,
741+
indenter,
742+
protected_tags,
743+
true, /* root _is_ the last child */
744+
true, /* wildcard_root*/
745+
&mut block,
746+
);
747+
}
715748
// Then it's just prettifying it with a border of dashes.
716749
{
717750
let wr = &fmt.wrapper;
@@ -741,6 +774,7 @@ impl DisplayRepr {
741774
indent: &mut DisplayIndent,
742775
protected_tags: &FxHashMap<BorTag, ProtectorKind>,
743776
is_last_child: bool,
777+
is_wildcard_root: bool,
744778
acc: &mut Vec<String>,
745779
) {
746780
let mut line = String::new();
@@ -760,7 +794,9 @@ impl DisplayRepr {
760794
indent.write(&mut line);
761795
{
762796
// padding
763-
line.push_str(if is_last_child {
797+
line.push_str(if is_wildcard_root {
798+
fmt.padding.wildcard_root
799+
} else if is_last_child {
764800
fmt.padding.join_last
765801
} else {
766802
fmt.padding.join_middle
@@ -777,12 +813,22 @@ impl DisplayRepr {
777813
line.push_str(&fmt.print_tag(tree.tag, &tree.name));
778814
let protector = protected_tags.get(&tree.tag);
779815
line.push_str(fmt.print_protector(protector));
816+
line.push_str(fmt.print_exposed(tree.exposed));
780817
// Push the line to the accumulator then recurse.
781818
acc.push(line);
782819
let nb_children = tree.children.len();
783820
for (i, child) in tree.children.iter().enumerate() {
784821
indent.increment(fmt, is_last_child);
785-
print_aux(child, padding, fmt, indent, protected_tags, i + 1 == nb_children, acc);
822+
print_aux(
823+
child,
824+
padding,
825+
fmt,
826+
indent,
827+
protected_tags,
828+
/* is_last_child */ i + 1 == nb_children,
829+
/* is_wildcard_root */ false,
830+
acc,
831+
);
786832
indent.decrement(fmt);
787833
}
788834
}
@@ -803,6 +849,7 @@ const DEFAULT_FORMATTER: DisplayFmt = DisplayFmt {
803849
indent_last: " ",
804850
join_haschild: "┬",
805851
join_default: "─",
852+
wildcard_root: "*",
806853
},
807854
accessed: DisplayFmtAccess { yes: " ", no: "?", meh: "-" },
808855
};
@@ -816,15 +863,27 @@ impl<'tcx> Tree {
816863
) -> InterpResult<'tcx> {
817864
let mut indenter = DisplayIndent::new();
818865
let ranges = self.locations.iter_all().map(|(range, _loc)| range).collect::<Vec<_>>();
819-
if let Some(repr) = DisplayRepr::from(self, show_unnamed) {
820-
repr.print(
821-
&DEFAULT_FORMATTER,
822-
&mut indenter,
823-
protected_tags,
824-
ranges,
825-
/* print warning message about tags not shown */ !show_unnamed,
866+
let main_tree = DisplayRepr::from(self, self.roots[0], show_unnamed);
867+
let wildcard_subtrees = self.roots[1..]
868+
.iter()
869+
.filter_map(|root| DisplayRepr::from(self, *root, show_unnamed))
870+
.collect::<Vec<_>>();
871+
872+
if main_tree.is_none() && wildcard_subtrees.is_empty() {
873+
eprintln!(
874+
"This allocation does not contain named tags. Use `miri_print_borrow_state(_, true)` to also print unnamed tags."
826875
);
827876
}
877+
878+
DisplayRepr::print(
879+
&main_tree,
880+
wildcard_subtrees.as_slice(),
881+
&DEFAULT_FORMATTER,
882+
&mut indenter,
883+
protected_tags,
884+
ranges,
885+
/* print warning message about tags not shown */ !show_unnamed,
886+
);
828887
interp_ok(())
829888
}
830889
}

0 commit comments

Comments
 (0)