Skip to content

Rustup #368

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 46 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2671cf3
Update to some cleanups in rustc
oli-obk Dec 15, 2017
a23e587
stop using Instance::def_ty
arielb1 Dec 17, 2017
5147655
Merge branch 'master' into def_ty
oli-obk Dec 19, 2017
30496f5
update compiletest dependency
dwrensha Dec 31, 2017
03aa876
pass typecheck
dwrensha Jan 2, 2018
cabdc55
update log deps
dwrensha Jan 6, 2018
33af320
update for rust/47205
dwrensha Jan 15, 2018
d289c0f
partially deal with rust/46479
dwrensha Jan 15, 2018
753da67
Rustup
bjorn3 Jan 14, 2018
a3a01ba
Add stack guard shim
bjorn3 Mar 17, 2018
cd89e56
Get the tests one step further
oli-obk Mar 18, 2018
6a85104
Use elem align as src align in copy intrinsic
bjorn3 Mar 19, 2018
680bcf8
Hack: copy init_static from rustc CompileTimeEvaluator to try to fix …
bjorn3 Mar 19, 2018
878d666
Maybe prevent marking statics as immutable
bjorn3 Mar 19, 2018
f55d077
Fix init_static
bjorn3 Mar 23, 2018
ac42af3
travis: cache build dir
bjorn3 Mar 23, 2018
a6cdd8a
Fix it
bjorn3 Mar 23, 2018
e09a996
Fix some more tests with some unsafe code
bjorn3 Apr 4, 2018
73658c4
Remove unsafe code
bjorn3 Apr 7, 2018
7bd20f1
Some cleanups
bjorn3 Apr 7, 2018
9d186d9
Update Cargo.lock and some improvements
bjorn3 Apr 7, 2018
95a8771
Fixup various things needed to get miri working on rustc
oli-obk Apr 13, 2018
d4f30aa
Fix alignment issue
bjorn3 Mar 18, 2018
4ecbcc5
Dont claim to have marked static initialized
bjorn3 Mar 19, 2018
3f1b2bd
Mirror function rename in rustc
oli-obk Apr 13, 2018
f48fed7
Rustup
oli-obk Apr 17, 2018
ba1c88a
Rustup to rustc 1.27.0-nightly (79252ff4e 2018-04-29)
bjorn3 May 1, 2018
ee2a3a1
Merge pull request #367 from bjorn3/rustup2
oli-obk May 1, 2018
3dba298
Fixed build for latest nightly
alexreg May 1, 2018
76573ba
Merge pull request #370 from alexreg/nightly-fix
oli-obk May 1, 2018
9156953
Minor fix to get build working
alexreg May 3, 2018
3d8c7a8
Fixed build for latest nightly
alexreg May 3, 2018
b0d3dae
Rustup
oli-obk May 7, 2018
6bc35f7
Fix allocator api and temporarily disable validation_op
bjorn3 May 7, 2018
42ab135
Merge branch 'rustup' into alloc_fix
oli-obk May 7, 2018
860e2b8
Dedup tag reading
oli-obk May 7, 2018
0eb3c18
Use a deterministic method for executing the start lang item
oli-obk May 7, 2018
7c45bfc
Merge branch 'rustup' into nightly-fix
oli-obk May 7, 2018
696dda8
Merge pull request #372 from alexreg/nightly-fix
oli-obk May 7, 2018
3ffc237
Merge pull request #373 from bjorn3/alloc_fix
oli-obk May 7, 2018
0a88698
Hide some warnings/Fix build
oli-obk May 7, 2018
6653bb3
Implement missing intrinsic
oli-obk May 7, 2018
e0e1bd7
Pointers must be valid, even pointers to zsts
oli-obk May 7, 2018
ce7605c
Fix some bad conversions on 32 bit emulation
oli-obk May 9, 2018
a4fdcd2
Disable cargo miri test for now
oli-obk May 9, 2018
c05d570
Update the rustc_tests crate
oli-obk May 9, 2018
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: rust
cache: cargo
rust:
- nightly
before_script:
Expand All @@ -23,7 +24,7 @@ script:
# Test cargo miri
cd cargo-miri-test &&
cargo miri &&
cargo miri test &&
#cargo miri test &&
cd ..
- |
# and run all tests with full mir
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ path = "miri/lib.rs"

[dependencies]
byteorder = { version = "1.1", features = ["i128"]}
cargo_metadata = { version = "0.2", optional = true }
cargo_metadata = { version = "0.5", optional = true }
regex = "0.2.2"
lazy_static = "1.0"
env_logger = "0.5.0-rc.1"
log = "0.4"

[features]
cargo_miri = ["cargo_metadata"]

[dev-dependencies]
compiletest_rs = { version = "0.3.3", features = ["tmp"] }
compiletest_rs = { version = "0.3.4", features = ["tmp"] }
4 changes: 3 additions & 1 deletion miri/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ fn main() {

let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
let sys_root = if let Ok(sysroot) = ::std::env::var("MIRI_SYSROOT") {
sysroot
} else if let (Some(home), Some(toolchain)) = (home, toolchain) {
format!("{}/toolchains/{}", home, toolchain)
} else {
option_env!("RUST_SYSROOT")
Expand Down
115 changes: 46 additions & 69 deletions miri/bin/miri.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![feature(rustc_private, i128_type)]
#![feature(rustc_private)]

extern crate getopts;
extern crate miri;
extern crate rustc;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_trans_utils;
extern crate env_logger;
extern crate log_settings;
extern crate syntax;
Expand All @@ -17,11 +18,16 @@ use rustc_driver::driver::{CompileState, CompileController};
use rustc::session::config::{self, Input, ErrorOutputType};
use rustc::hir::{self, itemlikevisit};
use rustc::ty::TyCtxt;
use syntax::ast::{self, MetaItemKind, NestedMetaItemKind};
use rustc_trans_utils::trans_crate::TransCrate;
use syntax::ast;
use std::path::PathBuf;

struct MiriCompilerCalls {
default: RustcDefaultCalls,
/// Whether to begin interpretation at the start_fn lang item or not
///
/// If false, the interpretation begins at the `main` function
start_fn: bool,
}

impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
Expand Down Expand Up @@ -61,14 +67,15 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
}
fn late_callback(
&mut self,
trans: &TransCrate,
matches: &getopts::Matches,
sess: &Session,
cstore: &CrateStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
) -> Compilation {
self.default.late_callback(matches, sess, cstore, input, odir, ofile)
self.default.late_callback(trans, matches, sess, cstore, input, odir, ofile)
}
fn build_controller(
&mut self,
Expand All @@ -77,7 +84,8 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
) -> CompileController<'a> {
let mut control = self.default.build_controller(sess, matches);
control.after_hir_lowering.callback = Box::new(after_hir_lowering);
control.after_analysis.callback = Box::new(after_analysis);
let start_fn = self.start_fn;
control.after_analysis.callback = Box::new(move |state| after_analysis(state, start_fn));
if sess.target.target != sess.host {
// only fully compile targets on the host. linking will fail for cross-compilation.
control.after_analysis.stop = Compilation::Stop;
Expand All @@ -94,135 +102,92 @@ fn after_hir_lowering(state: &mut CompileState) {
state.session.plugin_attributes.borrow_mut().push(attr);
}

fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>, use_start_fn: bool) {
state.session.abort_if_errors();

let tcx = state.tcx.unwrap();
let limits = resource_limits_from_attributes(state);

if std::env::args().any(|arg| arg == "--test") {
struct Visitor<'a, 'tcx: 'a>(
miri::ResourceLimits,
TyCtxt<'a, 'tcx, 'tcx>,
&'a CompileState<'a, 'tcx>
);
impl<'a, 'tcx: 'a, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'a, 'tcx> {
fn visit_item(&mut self, i: &'hir hir::Item) {
if let hir::Item_::ItemFn(_, _, _, _, _, body_id) = i.node {
if i.attrs.iter().any(|attr| {
attr.name().map_or(false, |n| n == "test")
attr.name() == "test"
})
{
let did = self.1.hir.body_owner_def_id(body_id);
let did = self.0.hir.body_owner_def_id(body_id);
println!(
"running test: {}",
self.1.def_path_debug_str(did),
self.0.def_path_debug_str(did),
);
miri::eval_main(self.1, did, None, self.0);
self.2.session.abort_if_errors();
miri::eval_main(self.0, did, None);
self.1.session.abort_if_errors();
}
}
}
fn visit_trait_item(&mut self, _trait_item: &'hir hir::TraitItem) {}
fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {}
}
state.hir_crate.unwrap().visit_all_item_likes(
&mut Visitor(limits, tcx, state),
&mut Visitor(tcx, state),
);
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
} else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() {
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
let start_wrapper = tcx.lang_items().start_fn().and_then(|start_fn| {
if tcx.is_mir_available(start_fn) {
if use_start_fn {
Some(start_fn)
} else {
None
}
});
miri::eval_main(tcx, entry_def_id, start_wrapper, limits);
miri::eval_main(tcx, entry_def_id, start_wrapper);

state.session.abort_if_errors();
} else {
println!("no main function found, assuming auxiliary build");
}
}

fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits {
let mut limits = miri::ResourceLimits::default();
let krate = state.hir_crate.as_ref().unwrap();
let err_msg = "miri attributes need to be in the form `miri(key = value)`";
let extract_int = |lit: &syntax::ast::Lit| -> u128 {
match lit.node {
syntax::ast::LitKind::Int(i, _) => i,
_ => {
state.session.span_fatal(
lit.span,
"expected an integer literal",
)
}
}
};

for attr in krate.attrs.iter().filter(|a| {
a.name().map_or(false, |n| n == "miri")
})
{
if let Some(items) = attr.meta_item_list() {
for item in items {
if let NestedMetaItemKind::MetaItem(ref inner) = item.node {
if let MetaItemKind::NameValue(ref value) = inner.node {
match &inner.name().as_str()[..] {
"memory_size" => limits.memory_size = extract_int(value) as u64,
"step_limit" => limits.step_limit = extract_int(value) as u64,
"stack_limit" => limits.stack_limit = extract_int(value) as usize,
_ => state.session.span_err(item.span, "unknown miri attribute"),
}
} else {
state.session.span_err(inner.span, err_msg);
}
} else {
state.session.span_err(item.span, err_msg);
}
}
} else {
state.session.span_err(attr.span, err_msg);
}
}
limits
}

fn init_logger() {
let format = |record: &log::LogRecord| {
if record.level() == log::LogLevel::Trace {
let format = |formatter: &mut env_logger::fmt::Formatter, record: &log::Record| {
use std::io::Write;
if record.level() == log::Level::Trace {
// prepend frame number
let indentation = log_settings::settings().indentation;
format!(
writeln!(
formatter,
"{indentation}:{lvl}:{module}: {text}",
lvl = record.level(),
module = record.location().module_path(),
module = record.module_path().unwrap_or("<unknown module>"),
indentation = indentation,
text = record.args(),
)
} else {
format!(
writeln!(
formatter,
"{lvl}:{module}: {text}",
lvl = record.level(),
module = record.location().module_path(),
module = record.module_path().unwrap_or("<unknown_module>"),
text = record.args(),
)
}
};

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

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

builder.init().unwrap();
builder.init();
}

fn find_sysroot() -> String {
Expand All @@ -246,6 +211,7 @@ fn find_sysroot() -> String {
}

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

Expand All @@ -255,10 +221,21 @@ fn main() {
args.push(find_sysroot());
}

let mut start_fn = false;
args.retain(|arg| {
if arg == "-Zmiri-start-fn" {
start_fn = true;
false
} else {
true
}
});

// Make sure we always have all the MIR (e.g. for auxilary builds in unit tests).
args.push("-Zalways-encode-mir".to_owned());

rustc_driver::run_compiler(&args, &mut MiriCompilerCalls {
default: RustcDefaultCalls,
start_fn,
}, None, None);
}
Loading