Skip to content
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

Rollup of 8 pull requests #105308

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
34de257
PERs are homogeneous
RalfJung Nov 25, 2022
71fd3ab
Don't update submodules for `x setup`
jyn514 Nov 26, 2022
86251da
Refactor `setup_config_toml` into a function
jyn514 Nov 26, 2022
b771d90
Revamp the order `setup` executes
jyn514 Nov 26, 2022
ab89c17
Ensure required submodules at the same time as updating existing subm…
jyn514 Nov 26, 2022
51ac2af
interpret: clobber return place when calling function
RalfJung Dec 3, 2022
3b4cbe9
add test for self-referential future
RalfJung Dec 3, 2022
3fa692c
for now, do not do fake reads on non-Unpin mutable references
RalfJung Dec 3, 2022
faec289
Auto merge of #2713 - RalfJung:not-unpin-fake-read, r=RalfJung
bors Dec 3, 2022
35c00a9
suggest parenthesis around ExprWithBlock BinOp ExprWithBlock
Dec 3, 2022
c808d0b
more comments
Dec 3, 2022
6cc86db
Add small comment explaining what `method-margins.goml` test is about
GuillaumeGomez Dec 4, 2022
5811057
fix dupe word typos
Rageking8 Dec 5, 2022
16a9fdf
Preparing for merge from rustc
RalfJung Dec 5, 2022
7481ba7
Merge from rustc
RalfJung Dec 5, 2022
552b63c
Auto merge of #2715 - RalfJung:rustup, r=RalfJung
bors Dec 5, 2022
9ad58d0
Rollup merge of #104912 - RalfJung:per, r=Mark-Simulacrum
matthiaskrgr Dec 5, 2022
3a25327
Rollup merge of #104952 - jyn514:setup, r=Mark-Simulacrum
matthiaskrgr Dec 5, 2022
5c0e0ce
Rollup merge of #104953 - jyn514:fewer-submodule-updates, r=Mark-Simu…
matthiaskrgr Dec 5, 2022
9539059
Rollup merge of #105207 - RalfJung:interpret-clobber-return, r=oli-obk
matthiaskrgr Dec 5, 2022
9a438dc
Rollup merge of #105223 - lukas-code:(ExprWithBlock), r=petrochenkov
matthiaskrgr Dec 5, 2022
1847671
Rollup merge of #105256 - GuillaumeGomez:comment-method-margins, r=no…
matthiaskrgr Dec 5, 2022
4c0166f
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
matthiaskrgr Dec 5, 2022
2a030bb
Rollup merge of #105301 - RalfJung:miri, r=oli-obk
matthiaskrgr Dec 5, 2022
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
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cef44f53034eac46be3a0e3eec7b2b3d4ef5140b
203c8765ea33c65d888febe0e8219c4bb11b0d89
23 changes: 14 additions & 9 deletions src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ pub struct Stacks {
/// new pointer.
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
enum RefKind {
/// `&mut` and `Box`.
/// `Box`.
Box,
/// `&mut`.
Unique { two_phase: bool },
/// `&` with or without interior mutability.
Shared,
Expand All @@ -56,6 +58,7 @@ enum RefKind {
impl fmt::Display for RefKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RefKind::Box => write!(f, "Box"),
RefKind::Unique { two_phase: false } => write!(f, "unique reference"),
RefKind::Unique { two_phase: true } => write!(f, "unique reference (two-phase)"),
RefKind::Shared => write!(f, "shared reference"),
Expand Down Expand Up @@ -654,15 +657,17 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
let (perm, access) = match kind {
RefKind::Unique { two_phase } => {
// Permission is Unique only if the type is `Unpin` and this is not twophase
let perm = if !two_phase && place.layout.ty.is_unpin(*this.tcx, this.param_env()) {
Permission::Unique
if !two_phase && place.layout.ty.is_unpin(*this.tcx, this.param_env()) {
(Permission::Unique, Some(AccessKind::Write))
} else {
Permission::SharedReadWrite
};
// We do an access for all full borrows, even if `!Unpin`.
let access = if !two_phase { Some(AccessKind::Write) } else { None };
(perm, access)
// FIXME: We emit `dereferenceable` for `!Unpin` mutable references, so we
// should do fake accesses here. But then we run into
// <https://github.com/rust-lang/unsafe-code-guidelines/issues/381>, so for now
// we don't do that.
(Permission::SharedReadWrite, None)
}
}
RefKind::Box => (Permission::Unique, Some(AccessKind::Write)),
RefKind::Raw { mutable: true } => {
// Creating a raw ptr does not count as an access
(Permission::SharedReadWrite, None)
Expand Down Expand Up @@ -853,7 +858,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// Boxes get a weak protectors, since they may be deallocated.
self.retag_place(
place,
RefKind::Unique { two_phase: false },
RefKind::Box,
self.retag_cause,
/*protector*/
(self.kind == RetagKind::FnEntry).then_some(ProtectorKind::WeakProtector),
Expand Down

This file was deleted.

This file was deleted.

102 changes: 102 additions & 0 deletions src/tools/miri/tests/pass/stacked-borrows/future-self-referential.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#![feature(pin_macro)]

use std::future::*;
use std::marker::PhantomPinned;
use std::pin::*;
use std::ptr;
use std::task::*;

struct Delay {
delay: usize,
}

impl Delay {
fn new(delay: usize) -> Self {
Delay { delay }
}
}

impl Future for Delay {
type Output = ();
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
if self.delay > 0 {
self.delay -= 1;
Poll::Pending
} else {
Poll::Ready(())
}
}
}

async fn do_stuff() {
(&mut Delay::new(1)).await;
}

// Same thing implemented by hand
struct DoStuff {
state: usize,
delay: Delay,
delay_ref: *mut Delay,
_marker: PhantomPinned,
}

impl DoStuff {
fn new() -> Self {
DoStuff {
state: 0,
delay: Delay::new(1),
delay_ref: ptr::null_mut(),
_marker: PhantomPinned,
}
}
}

impl Future for DoStuff {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
unsafe {
let this = self.get_unchecked_mut();
match this.state {
0 => {
// Set up self-ref.
this.delay_ref = &mut this.delay;
// Move to next state.
this.state = 1;
Poll::Pending
}
1 => {
let delay = &mut *this.delay_ref;
Pin::new_unchecked(delay).poll(cx)
}
_ => unreachable!(),
}
}
}
}

fn run_fut<T>(fut: impl Future<Output = T>) -> T {
use std::sync::Arc;

struct MyWaker;
impl Wake for MyWaker {
fn wake(self: Arc<Self>) {
unimplemented!()
}
}

let waker = Waker::from(Arc::new(MyWaker));
let mut context = Context::from_waker(&waker);

let mut pinned = pin!(fut);
loop {
match pinned.as_mut().poll(&mut context) {
Poll::Pending => continue,
Poll::Ready(v) => return v,
}
}
}

fn main() {
run_fut(do_stuff());
run_fut(DoStuff::new());
}