Skip to content

Miri subtree update #116508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cfbcc0e
add test for a function ABI mismatch due to target features
RalfJung Oct 2, 2023
43d1042
Auto merge of #3099 - RalfJung:abi-target-feature, r=RalfJung
bors Oct 2, 2023
91ef03b
Fix typos `*ucom` → `ucom*`
eduardosm Oct 3, 2023
3e21c1f
wording tweaks
RalfJung Oct 3, 2023
4f73d3f
Auto merge of #3102 - eduardosm:typos, r=RalfJung
bors Oct 3, 2023
31a5755
auto-detect no_std where possible
RalfJung Oct 4, 2023
7d065db
miri-script: print which sysroot target we are building
RalfJung Oct 4, 2023
40c928e
Auto merge of #3105 - RalfJung:sysroot-target, r=RalfJung
bors Oct 4, 2023
6ed502d
Auto merge of #3000 - RalfJung:no_std, r=oli-obk
bors Oct 5, 2023
5178ae6
Tree Borrows: do not create new tags as 'Active'
RalfJung Oct 5, 2023
ff3e990
Auto merge of #3106 - RalfJung:tree-borrows-initial, r=RalfJung
bors Oct 5, 2023
95c4590
Update miri dependencies
eduardosm Oct 5, 2023
f49d325
Update cargo-miri dependencies
eduardosm Oct 5, 2023
bbebfa7
Update miri-script dependencies
eduardosm Oct 5, 2023
11afb99
Update test dependencies
eduardosm Oct 5, 2023
1a6ab01
Auto merge of #3107 - eduardosm:update-deps, r=RalfJung
bors Oct 5, 2023
dff7d5a
Move getentropy handling to a shared location for foreign item implem…
BlackHoleFox Oct 1, 2023
f9003c0
Auto merge of #3098 - BlackHoleFox:apple-entropy, r=RalfJung
bors Oct 6, 2023
bc8d4df
refactor dlsym: dispatch symbols via the normal shim mechanism
RalfJung Oct 6, 2023
099311b
make some things on foreign_items private
RalfJung Oct 6, 2023
16cde06
allow dyn_sym in the files where they are defined; remove unreachable…
RalfJung Oct 6, 2023
4135408
Auto merge of #3108 - RalfJung:dlsym, r=RalfJung
bors Oct 6, 2023
03a03e2
add a direct dlsym test
RalfJung Oct 6, 2023
4587c7c
Auto merge of #3109 - RalfJung:dlsym, r=RalfJung
bors Oct 6, 2023
bf1356e
Fix problems of Reserved -> Frozen
Vanille-N Sep 20, 2023
e1e880e
Do not use host floats in `simd_{ceil,floor,round,trunc}`
eduardosm Oct 6, 2023
3c511bb
Auto merge of #3067 - Vanille-N:spurious-incremental, r=RalfJung
bors Oct 6, 2023
375ff3e
Auto merge of #3110 - eduardosm:rounding-without-host-floats, r=RalfJung
bors Oct 6, 2023
ea56007
Preparing for merge from rustc
RalfJung Oct 6, 2023
100ea2b
Merge from rustc
RalfJung Oct 6, 2023
3b08930
Auto merge of #3112 - RalfJung:rustup, r=RalfJung
bors Oct 6, 2023
d322243
Preparing for merge from rustc
Oct 7, 2023
722736a
Merge from rustc
Oct 7, 2023
1c42857
Auto merge of #3113 - rust-lang:rustup-2023-10-07, r=saethlin
bors Oct 7, 2023
5aecfe4
update lockfile
RalfJung Oct 7, 2023
a04b7a3
allow option-ext as a tool dependency (MPL licensed)
RalfJung Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/tools/miri/src/borrow_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ pub struct FrameState {
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
/// tag, to identify which call is responsible for protecting the tag.
/// See `Stack::item_popped` for more explanation.
/// Tree Borrows also needs to know which allocation these tags
/// belong to so that it can perform a read through them immediately before
/// the frame gets popped.
///
/// This will contain one tag per reference passed to the function, so
/// a size of 2 is enough for the vast majority of functions.
pub protected_tags: SmallVec<[BorTag; 2]>,
pub protected_tags: SmallVec<[(AllocId, BorTag); 2]>,
}

impl VisitTags for FrameState {
Expand Down Expand Up @@ -208,7 +211,7 @@ impl GlobalStateInner {
}

pub fn end_call(&mut self, frame: &machine::FrameExtra<'_>) {
for tag in &frame
for (_, tag) in &frame
.borrow_tracker
.as_ref()
.expect("we should have borrow tracking data")
Expand Down Expand Up @@ -453,6 +456,19 @@ impl AllocState {
AllocState::TreeBorrows(tb) => tb.borrow_mut().remove_unreachable_tags(tags),
}
}

/// Tree Borrows needs to be told when a tag stops being protected.
pub fn release_protector<'tcx>(
&self,
machine: &MiriMachine<'_, 'tcx>,
global: &GlobalState,
tag: BorTag,
) -> InterpResult<'tcx> {
match self {
AllocState::StackedBorrows(_sb) => Ok(()),
AllocState::TreeBorrows(tb) => tb.borrow_mut().release_protector(machine, global, tag),
}
}
}

impl VisitTags for AllocState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
ProtectorKind::WeakProtector => "weakly protected",
ProtectorKind::StrongProtector => "strongly protected",
};
let item_tag = item.tag();
let call_id = self
.machine
.threads
Expand All @@ -444,7 +445,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
.map(|frame| {
frame.extra.borrow_tracker.as_ref().expect("we should have borrow tracking data")
})
.find(|frame| frame.protected_tags.contains(&item.tag()))
.find(|frame| frame.protected_tags.iter().any(|(_, tag)| tag == &item_tag))
.map(|frame| frame.call_id)
.unwrap(); // FIXME: Surely we should find something, but a panic seems wrong here?
match self.operation {
Expand Down
8 changes: 7 additions & 1 deletion src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,13 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'

if let Some(protect) = new_perm.protector() {
// See comment in `Stack::item_invalidated` for why we store the tag twice.
this.frame_mut().extra.borrow_tracker.as_mut().unwrap().protected_tags.push(new_tag);
this.frame_mut()
.extra
.borrow_tracker
.as_mut()
.unwrap()
.protected_tags
.push((alloc_id, new_tag));
this.machine
.borrow_tracker
.as_mut()
Expand Down
21 changes: 18 additions & 3 deletions src/tools/miri/src/borrow_tracker/tree_borrows/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum AccessCause {
Explicit(AccessKind),
Reborrow,
Dealloc,
FnExit,
}

impl fmt::Display for AccessCause {
Expand All @@ -27,6 +28,7 @@ impl fmt::Display for AccessCause {
Self::Explicit(kind) => write!(f, "{kind}"),
Self::Reborrow => write!(f, "reborrow"),
Self::Dealloc => write!(f, "deallocation"),
Self::FnExit => write!(f, "protector release"),
}
}
}
Expand All @@ -38,6 +40,7 @@ impl AccessCause {
Self::Explicit(kind) => format!("{rel} {kind}"),
Self::Reborrow => format!("reborrow (acting as a {rel} read access)"),
Self::Dealloc => format!("deallocation (acting as a {rel} write access)"),
Self::FnExit => format!("protector release (acting as a {rel} read access)"),
}
}
}
Expand All @@ -52,7 +55,9 @@ pub struct Event {
/// Relative position of the tag to the one used for the access.
pub is_foreign: bool,
/// User-visible range of the access.
pub access_range: AllocRange,
/// `None` means that this is an implicit access to the entire allocation
/// (used for the implicit read on protector release).
pub access_range: Option<AllocRange>,
/// The transition recorded by this event only occured on a subrange of
/// `access_range`: a single access on `access_range` triggers several events,
/// each with their own mutually disjoint `transition_range`. No-op transitions
Expand Down Expand Up @@ -123,7 +128,17 @@ impl HistoryData {
// NOTE: `transition_range` is explicitly absent from the error message, it has no significance
// to the user. The meaningful one is `access_range`.
let access = access_cause.print_as_access(is_foreign);
self.events.push((Some(span.data()), format!("{this} later transitioned to {endpoint} due to a {access} at offsets {access_range:?}", endpoint = transition.endpoint())));
let access_range_text = match access_range {
Some(r) => format!("at offsets {r:?}"),
None => format!("on every location previously accessed by this tag"),
};
self.events.push((
Some(span.data()),
format!(
"{this} later transitioned to {endpoint} due to a {access} {access_range_text}",
endpoint = transition.endpoint()
),
));
self.events
.push((None, format!("this transition corresponds to {}", transition.summary())));
}
Expand Down Expand Up @@ -745,7 +760,7 @@ const DEFAULT_FORMATTER: DisplayFmt = DisplayFmt {
bot: '─',
warning_text: "Warning: this tree is indicative only. Some tags may have been hidden.",
},
perm: DisplayFmtPermission { open: "|", sep: "|", close: "|", uninit: "---", range_sep: ".." },
perm: DisplayFmtPermission { open: "|", sep: "|", close: "|", uninit: "----", range_sep: ".." },
padding: DisplayFmtPadding {
join_middle: "├",
join_last: "└",
Expand Down
57 changes: 37 additions & 20 deletions src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use log::trace;

use rustc_target::abi::{Abi, Align, Size};

use crate::borrow_tracker::{AccessKind, GlobalStateInner, ProtectorKind, RetagFields};
use crate::borrow_tracker::{
AccessKind, GlobalState, GlobalStateInner, ProtectorKind, RetagFields,
};
use rustc_middle::{
mir::{Mutability, RetagKind},
ty::{
Expand Down Expand Up @@ -70,7 +72,7 @@ impl<'tcx> Tree {
self.perform_access(
access_kind,
tag,
range,
Some(range),
global,
span,
diagnostics::AccessCause::Explicit(access_kind),
Expand Down Expand Up @@ -99,6 +101,29 @@ impl<'tcx> Tree {
pub fn expose_tag(&mut self, _tag: BorTag) {
// TODO
}

/// A tag just lost its protector.
///
/// This emits a special kind of access that is only applied
/// to initialized locations, as a protection against other
/// tags not having been made aware of the existence of this
/// protector.
pub fn release_protector(
&mut self,
machine: &MiriMachine<'_, 'tcx>,
global: &GlobalState,
tag: BorTag,
) -> InterpResult<'tcx> {
let span = machine.current_span();
self.perform_access(
AccessKind::Read,
tag,
None, // no specified range because it occurs on the entire allocation
global,
span,
diagnostics::AccessCause::FnExit,
)
}
}

/// Policy for a new borrow.
Expand Down Expand Up @@ -248,7 +273,13 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
// We register the protection in two different places.
// This makes creating a protector slower, but checking whether a tag
// is protected faster.
this.frame_mut().extra.borrow_tracker.as_mut().unwrap().protected_tags.push(new_tag);
this.frame_mut()
.extra
.borrow_tracker
.as_mut()
.unwrap()
.protected_tags
.push((alloc_id, new_tag));
this.machine
.borrow_tracker
.as_mut()
Expand All @@ -275,7 +306,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
tree_borrows.perform_access(
AccessKind::Read,
orig_tag,
range,
Some(range),
this.machine.borrow_tracker.as_ref().unwrap(),
this.machine.current_span(),
diagnostics::AccessCause::Reborrow,
Expand All @@ -287,21 +318,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
// Also inform the data race model (but only if any bytes are actually affected).
if range.size.bytes() > 0 {
if let Some(data_race) = alloc_extra.data_race.as_ref() {
// We sometimes need to make it a write, since not all retags commute with reads!
// FIXME: Is that truly the semantics we want? Some optimizations are likely to be
// very unhappy without this. We'd tsill ge some UB just by picking a suitable
// interleaving, but wether UB happens can depend on whether a write occurs in the
// future...
let is_write = new_perm.initial_state.is_active()
|| (new_perm.initial_state.is_reserved(None) && new_perm.protector.is_some());
if is_write {
// Need to get mutable access to alloc_extra.
// (Cannot always do this as we can do read-only reborrowing on read-only allocations.)
let (alloc_extra, machine) = this.get_alloc_extra_mut(alloc_id)?;
alloc_extra.data_race.as_mut().unwrap().write(alloc_id, range, machine)?;
} else {
data_race.read(alloc_id, range, &this.machine)?;
}
data_race.read(alloc_id, range, &this.machine)?;
}
}

Expand Down Expand Up @@ -532,7 +549,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// if converting this alloc_id from a global to a local one
// uncovers a non-supported `extern static`.
let alloc_extra = this.get_alloc_extra(alloc_id)?;
trace!("Stacked Borrows tag {tag:?} exposed in {alloc_id:?}");
trace!("Tree Borrows tag {tag:?} exposed in {alloc_id:?}");
alloc_extra.borrow_tracker_tb().borrow_mut().expose_tag(tag);
}
AllocKind::Function | AllocKind::VTable | AllocKind::Dead => {
Expand Down
Loading