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

Update to latest rustc #27

Merged
merged 9 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
921 changes: 481 additions & 440 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ edition = "2018"
[dependencies]
regex = "1.3"
lazy_static = "1.4.0"
rocket = "0.4.5"
rocket_codegen = "0.4.5"
miri = { git = "https://github.com/rust-lang/miri.git", rev = "c641fbde0223cde9fae67de3cc4892998a21cec0" }
rocket = "0.4.7"
# This is the version of miri for the nightly in the rust-toolchain file. This might be superfluous
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved
miri = { git = "https://github.com/rust-lang/miri.git", rev = "ea86335318fd06ec964d9a86b187995bda1b6c7d" }

log = "0.4"
env_logger = "0.7"

serde = "1.0"
serde_derive = "1.0"
serde = {version="1.0", features=["derive"]}
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
serde_json = "1.0"

open = "1.4.0"
Expand All @@ -30,7 +29,7 @@ cgraph = { git = "https://github.com/oli-obk/cgraph.git", rev = "b65e460ee323b31
rental = "0.5.5"

# Uncomment to use local checkout of miri
# [patch."https://github.com/solson/miri.git"]
# [patch."https://github.com/rust-lang/miri.git"]
# miri = { path = "../miri" }

[features]
Expand Down
4 changes: 3 additions & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
nightly-2020-07-26
[toolchain]
channel = "nightly-2021-02-26"
components = ["miri", "rustc-dev", "llvm-tools-preview"]
134 changes: 47 additions & 87 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#![feature(never_type)]
#![allow(unused_attributes)]
#![recursion_limit = "5000"]
#![warn(rust_2018_idioms)]

extern crate rustc_ast;
extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_hir;
extern crate rustc_index;
Expand All @@ -13,30 +12,12 @@ extern crate rustc_middle;
extern crate rustc_mir;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_type_ir;

extern crate lazy_static;
extern crate regex;
#[macro_use]
extern crate rental;
extern crate miri;
#[macro_use]
extern crate rocket;

extern crate env_logger;
extern crate log;
extern crate log_settings;

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

extern crate open;
extern crate promising_future;
extern crate syntect;
#[macro_use]
extern crate horrorshow;
extern crate cgraph;
extern crate rental;

mod render;
mod step;
Expand All @@ -58,19 +39,19 @@ use rocket::response::status::BadRequest;
use rocket::response::NamedFile;
use rocket::State;

use miri::AllocId;
use serde::Deserialize;

use crate::step::BreakpointTree;

fn should_hide_stmt(stmt: &mir::Statement) -> bool {
fn should_hide_stmt(stmt: &mir::Statement<'_>) -> bool {
use rustc_middle::mir::StatementKind::*;
match stmt.kind {
StorageLive(_) | StorageDead(_) | Nop => true,
_ => false,
}
}

type InterpCx<'tcx> = miri::InterpCx<'tcx, 'tcx, miri::Evaluator<'tcx, 'tcx>>;
type InterpCx<'tcx> = miri::MiriEvalContext<'tcx, 'tcx>;

pub struct PrirodaContext<'a, 'tcx: 'a> {
ecx: InterpCx<'tcx>,
Expand Down Expand Up @@ -137,26 +118,31 @@ fn create_ecx<'mir, 'tcx>(tcx: TyCtxt<'tcx>) -> InterpCx<'tcx> {
tracked_call_id: None,
validate: true,
stacked_borrows: false,
check_alignment: false,
// Guesses
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
check_alignment: miri::AlignmentCheck::None,
track_raw: false,
data_race_detector: false,
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
// This is the default, might be better off setting it to 0.0
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
cmpxchg_weak_failure_rate: 0.8,
},
)
.unwrap()
.0
}

pub struct PrirodaSender(
Mutex<::std::sync::mpsc::Sender<Box<dyn FnOnce(&mut PrirodaContext) + Send>>>,
Mutex<::std::sync::mpsc::Sender<Box<dyn FnOnce(&mut PrirodaContext<'_, '_>) + Send>>>,
);

impl PrirodaSender {
fn do_work<'r, T, F>(&self, f: F) -> Result<T, Html<String>>
where
T: rocket::response::Responder<'r> + Send + 'static,
F: FnOnce(&mut PrirodaContext) -> T + Send + 'static,
F: FnOnce(&mut PrirodaContext<'_, '_>) -> T + Send + 'static,
{
let (future, promise) = future_promise();
let sender = self.0.lock().unwrap_or_else(|err| err.into_inner());
match sender.send(Box::new(move |pcx: &mut PrirodaContext| {
match sender.send(Box::new(move |pcx: &mut PrirodaContext<'_, '_>| {
promise.set(f(pcx));
})) {
Ok(()) => match future.value() {
Expand All @@ -174,34 +160,9 @@ impl PrirodaSender {
}
}

macro action_route($name:ident : $route:expr, |$pcx:ident $(,$arg:ident : $arg_ty:ty)*| $body:block) {
#[get($route)]
pub fn $name(
sender: rocket::State<crate::PrirodaSender>
$(,$arg:$arg_ty)*
) -> crate::RResult<rocket::response::Flash<rocket::response::Redirect>> {
sender.do_work(move |$pcx| {
rocket::response::Flash::success(rocket::response::Redirect::to("/"), (||$body)())
})
}
}

macro view_route($name:ident : $route:expr, |$pcx:ident $(,$arg:ident : $arg_ty:ty)*| $body:block) {
#[get($route)]
pub fn $name(
sender: rocket::State<crate::PrirodaSender>
$(,$arg:$arg_ty)*
) -> crate::RResult<Html<String>> {
sender.do_work(move |pcx| {
let $pcx = &*pcx;
(||$body)()
})
}
}

#[get("/please_panic")]
#[allow(unreachable_code)]
fn please_panic(sender: State<PrirodaSender>) -> RResult<()> {
fn please_panic(sender: State<'_, PrirodaSender>) -> RResult<()> {
sender.do_work(|_pcx| {
panic!("You requested a panic");
})
Expand Down Expand Up @@ -242,7 +203,7 @@ fn resources(path: PathBuf) -> Result<Content<&'static str>, std::io::Error> {
}

#[get("/step_count")]
fn step_count(sender: State<PrirodaSender>) -> RResult<String> {
fn step_count(sender: State<'_, PrirodaSender>) -> RResult<String> {
sender.do_work(|pcx| format!("{}", pcx.step_count))
}

Expand Down Expand Up @@ -288,7 +249,7 @@ fn find_sysroot() -> String {
}

fn main() {
init_logger();
rustc_driver::init_rustc_env_logger();
let mut args: Vec<String> = std::env::args().collect();

let sysroot_flag = String::from("--sysroot");
Expand Down Expand Up @@ -326,7 +287,7 @@ fn main() {
receiver: Arc<
Mutex<
std::sync::mpsc::Receiver<
Box<dyn FnOnce(&mut PrirodaContext) + Send>,
Box<dyn FnOnce(&mut PrirodaContext<'_, '_>) + Send>,
>,
>,
>,
Expand Down Expand Up @@ -382,16 +343,15 @@ fn main() {
}
}

rustc_driver::run_compiler(
rustc_driver::RunCompiler::new(
&*args,
&mut PrirodaCompilerCalls {
step_count,
config,
receiver,
},
None,
None,
)
.run()
});
})
.join();
Expand All @@ -403,29 +363,29 @@ fn main() {
handle.join().unwrap();
}

fn init_logger() {
const NSPACES: usize = 40;
let format = |_fmt: &mut _, record: &log::Record| {
// prepend spaces to indent the final string
let indentation = log_settings::settings().indentation;
println!(
"{lvl}:{module}{depth:2}{indent:<indentation$} {text}",
lvl = record.level(),
module = record.module_path().unwrap_or(""),
depth = indentation / NSPACES,
indentation = indentation % NSPACES,
indent = "",
text = record.args()
);
Ok(())
};

let mut builder = env_logger::Builder::new();
builder.format(format).filter(None, log::LevelFilter::Info);

if std::env::var("MIRI_LOG").is_ok() {
builder.parse_filters(&std::env::var("MIRI_LOG").unwrap());
}

builder.init();
}
// fn init_logger() {
// const NSPACES: usize = 40;
// let format = |_fmt: &mut _, record: &log::Record| {
// // prepend spaces to indent the final string
// let indentation = log_settings::settings().indentation;
// println!(
// "{lvl}:{module}{depth:2}{indent:<indentation$} {text}",
// lvl = record.level(),
// module = record.module_path().unwrap_or(""),
// depth = indentation / NSPACES,
// indentation = indentation % NSPACES,
// indent = "",
// text = record.args()
// );
// Ok(())
// };

// let mut builder = env_logger::Builder::new();
// builder.format(format).filter(None, log::LevelFilter::Info);

// if std::env::var("MIRI_LOG").is_ok() {
// builder.parse_filters(&std::env::var("MIRI_LOG").unwrap());
// }

// builder.init();
// }
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 16 additions & 12 deletions src/render/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
// except according to those terms.

use crate::step::LocalBreakpoints;
use miri::{Frame, FrameData, Tag};
use miri::{FrameData, Tag};
use rustc_middle::mir::*;
use rustc_mir::interpret::Frame;
use std::fmt::{self, Debug, Write};

pub fn render_html<'tcx>(frame: &Frame<Tag, FrameData>, breakpoints: LocalBreakpoints) -> String {
pub fn render_html<'tcx>(
frame: &Frame<'_, '_, Tag, FrameData<'_>>,
breakpoints: LocalBreakpoints<'_>,
) -> String {
let mut rendered = String::new();

render_mir_svg(&frame.body, breakpoints, &mut rendered, None).unwrap();

let (block, statement_index) = if let Some(location) = frame.loc {
let (block, statement_index) = if let Some(location) = frame.current_loc().ok() {
(location.block, location.statement_index)
} else {
rendered.push_str("<div style='color: red;'>Unwinding</div>");
Expand Down Expand Up @@ -47,7 +51,7 @@ pub fn render_html<'tcx>(frame: &Frame<Tag, FrameData>, breakpoints: LocalBreakp
use rustc_middle::mir::TerminatorKind::*;
match blck.terminator().kind {
Goto { target } => (vec![target], None),
SwitchInt { ref targets, .. } => (targets.to_vec(), None),
SwitchInt { ref targets, .. } => (targets.all_targets().to_owned(), None),
Drop { target, unwind, .. } | DropAndReplace { target, unwind, .. } => {
(vec![target], unwind)
}
Expand Down Expand Up @@ -120,8 +124,8 @@ pub fn render_html<'tcx>(frame: &Frame<Tag, FrameData>, breakpoints: LocalBreakp

/// Write a graphviz DOT graph of a list of MIRs.
pub fn render_mir_svg<W: Write>(
mir: &Body,
breakpoints: LocalBreakpoints,
mir: &Body<'_>,
breakpoints: LocalBreakpoints<'_>,
w: &mut W,
promoted: Option<usize>,
) -> fmt::Result {
Expand Down Expand Up @@ -158,8 +162,8 @@ pub fn render_mir_svg<W: Write>(
/// `LabelText::HtmlStr` from libgraphviz.)
fn write_node_label<W: Write>(
block: BasicBlock,
mir: &Body,
breakpoints: LocalBreakpoints,
mir: &Body<'_>,
breakpoints: LocalBreakpoints<'_>,
promoted: Option<usize>,
w: &mut W,
) -> fmt::Result {
Expand Down Expand Up @@ -215,8 +219,8 @@ fn write_node_label<W: Write>(
/// Write a graphviz DOT node for the given basic block.
fn write_node<W: Write>(
block: BasicBlock,
mir: &Body,
breakpoints: LocalBreakpoints,
mir: &Body<'_>,
breakpoints: LocalBreakpoints<'_>,
promoted: Option<usize>,
w: &mut W,
) -> fmt::Result {
Expand All @@ -232,7 +236,7 @@ fn write_node<W: Write>(
}

/// Write graphviz DOT edges with labels between the given basic block and all of its successors.
fn write_edges<W: Write>(source: BasicBlock, mir: &Body, w: &mut W) -> fmt::Result {
fn write_edges<W: Write>(source: BasicBlock, mir: &Body<'_>, w: &mut W) -> fmt::Result {
let terminator = mir[source].terminator();
let labels = terminator.kind.fmt_successor_labels();

Expand Down Expand Up @@ -261,6 +265,6 @@ fn escape<T: Debug>(t: &T) -> String {
escape_html(&format!("{:?}", t)).into_owned()
}

fn escape_html(s: &str) -> ::std::borrow::Cow<str> {
fn escape_html(s: &str) -> ::std::borrow::Cow<'_, str> {
::rocket::http::RawStr::from_str(s).html_escape()
}
Loading