Remove all non-CTFE stuff from the miri repository

parent ed674f7c
target
/doc
tex/*/out
*.dot
*.mir
*.rs.bk
language: rust
rust:
- nightly
before_script:
- export PATH=$HOME/.local/bin:$PATH
- rustup target add i686-unknown-linux-gnu
- rustup target add i686-pc-windows-gnu
- rustup target add i686-pc-windows-msvc
- rustup component add rust-src
- cargo install --git https://github.com/japaric/xargo.git
- export RUST_SYSROOT=$HOME/rust
script:
- set -e
- |
# get ourselves a MIR-ful libstd
xargo/build.sh
- |
# Test plain miri
cargo build --locked --release --all-features &&
cargo test --locked --release --all-features --all &&
cargo install --locked --all-features
- |
# Test cargo miri
cd cargo-miri-test &&
cargo miri &&
cargo miri test &&
cd ..
- |
# and run all tests with full mir
MIRI_SYSROOT=~/.xargo/HOST cargo test --locked --release
- |
# test that the rustc_tests binary compiles
cd rustc_tests &&
cargo build --locked --release &&
cd ..
notifications:
email:
on_success: never
branches:
only:
- master
env:
global:
- RUST_TEST_NOCAPTURE=1
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
This diff is collapsed.
[package]
authors = ["Scott Olson <scott@solson.me>"]
description = "An experimental interpreter for Rust MIR."
license = "MIT/Apache-2.0"
name = "miri"
repository = "https://github.com/solson/miri"
version = "0.1.0"
build = "build.rs"
[[bin]]
doc = false
name = "miri"
path = "miri/bin/miri.rs"
[[bin]]
doc = false
name = "cargo-miri"
path = "miri/bin/cargo-miri.rs"
required-features = ["cargo_miri"]
[lib]
path = "miri/lib.rs"
[dependencies]
byteorder = { version = "1.1", features = ["i128"]}
env_logger = "0.4.3"
log = "0.3.6"
log_settings = "0.1.1"
cargo_metadata = { version = "0.2", optional = true }
rustc_miri = { path = "src/librustc_mir" }
[features]
cargo_miri = ["cargo_metadata"]
[dev-dependencies]
compiletest_rs = { version = "0.3", features = ["tmp"] }
[workspace]
exclude = ["xargo", "cargo-miri-test", "rustc_tests"]
This diff is collapsed.
Copyright (c) 2016 The Miri Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
# Miri [[slides](https://solson.me/miri-slides.pdf)] [[report](https://solson.me/miri-report.pdf)] [![Build Status](https://travis-ci.org/solson/miri.svg?branch=master)](https://travis-ci.org/solson/miri) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/solson/miri?svg=true)](https://ci.appveyor.com/project/solson63299/miri)
An experimental interpreter for [Rust][rust]'s [mid-level intermediate
representation][mir] (MIR). This project began as part of my work for the
undergraduate research course at the [University of Saskatchewan][usask].
## Installing Rust
I recommend that you install [rustup][rustup] and then use it to install the
current Rust nightly version:
```sh
rustup update nightly
```
You should also make `nightly` the default version for your Miri directory by
running the following command while you're in it. If you don't do this, you can
run the later `cargo` commands by using `cargo +nightly` instead.
```sh
rustup override add nightly
```
## Building Miri
```sh
cargo build
```
If Miri fails to build, it's likely because a change in the latest nightly
compiler broke it. You could try an older nightly with `rustup update
nightly-<date>` where `<date>` is a few days or weeks ago, e.g. `2016-05-20` for
May 20th. Otherwise, you could notify me in an issue or on IRC. Or, if you know
how to fix it, you could send a PR. :smile:
## Running tests
```sh
cargo run --bin miri tests/run-pass/vecs.rs # Or whatever test you like.
```
## Debugging
You can get detailed, statement-by-statement traces by setting the `MIRI_LOG`
environment variable to `trace`. These traces are indented based on call stack
depth. You can get a much less verbose set of information with other logging
levels such as `warn`.
## Running miri on your own project('s test suite)
Install miri as a cargo subcommand with `cargo install --debug`.
Then, inside your own project, use `cargo +nightly miri` to run your project, if it is
a bin project, or run `cargo +nightly miri test` to run all tests in your project
through miri.
## Running miri with full libstd
Per default libstd does not contain the MIR of non-polymorphic functions. When
miri hits a call to such a function, execution terminates. To fix this, it is
possible to compile libstd with full MIR:
```sh
rustup component add rust-src
cargo install xargo
cd xargo/
RUSTFLAGS='-Zalways-encode-mir' xargo build
```
Now you can run miri against the libstd compiled by xargo:
```sh
MIRI_SYSROOT=~/.xargo/HOST cargo run --bin miri tests/run-pass-fullmir/vecs.rs
```
Notice that you will have to re-run the last step of the preparations above when
your toolchain changes (e.g., when you update the nightly).
## Contributing and getting help
Check out the issues on this GitHub repository for some ideas. There's lots that
needs to be done that I haven't documented in the issues yet, however. For more
ideas or help with running or hacking on Miri, you can contact me (`scott`) on
Mozilla IRC in any of the Rust IRC channels (`#rust`, `#rust-offtopic`, etc).
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT) at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.
[rust]: https://www.rust-lang.org/
[mir]: https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md
[usask]: https://www.usask.ca/
[rustup]: https://www.rustup.rs
environment:
global:
PROJECT_NAME: miri
matrix:
- TARGET: i686-pc-windows-msvc
MSYS2_BITS: 32
- TARGET: x86_64-pc-windows-msvc
MSYS2_BITS: 64
# branches to build
branches:
# whitelist
only:
- master
install:
- set PATH=C:\Program Files\Git\mingw64\bin;%PATH%
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin;C:\Users\appveyor\.rustup\toolchains\nightly-%TARGET%\bin
- if defined MSYS2_BITS set PATH=%PATH%;C:\msys64\mingw%MSYS2_BITS%\bin
- rustc -V
- cargo -V
- rustup component add rust-src
- cargo install --git https://github.com/japaric/xargo.git
- cd xargo
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-validate=1
- xargo build
- set RUSTFLAGS=
- cd ..
build: false
test_script:
- set RUST_BACKTRACE=1
- cargo build --locked --release
- cargo test --locked --release
notifications:
- provider: Email
on_build_success: false
#![feature(test, rustc_private)]
extern crate test;
use test::Bencher;
mod helpers;
use helpers::*;
#[bench]
fn fib(bencher: &mut Bencher) {
bencher.iter(|| { fibonacci_helper::main(); })
}
#[bench]
fn fib_miri(bencher: &mut Bencher) {
miri_helper::run("fibonacci_helper", bencher);
}
#[bench]
fn fib_iter(bencher: &mut Bencher) {
bencher.iter(|| { fibonacci_helper_iterative::main(); })
}
#[bench]
fn fib_iter_miri(bencher: &mut Bencher) {
miri_helper::run("fibonacci_helper_iterative", bencher);
}
#[inline(never)]
pub fn main() {
assert_eq!(fib(10), 55);
}
fn fib(n: usize) -> usize {
if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) }
}
#[inline(never)]
pub fn main() {
assert_eq!(fib(10), 55);
}
fn fib(n: usize) -> usize {
let mut a = 0;
let mut b = 1;
for _ in 0..n {
let c = a;
a = b;
b = c + b;
}
a
}
extern crate getopts;
extern crate miri;
extern crate rustc;
extern crate rustc_driver;
extern crate test;
use self::miri::eval_main;
use self::rustc::session::Session;
use self::rustc_driver::{driver, CompilerCalls, Compilation};
use std::cell::RefCell;
use std::rc::Rc;
use test::Bencher;
pub struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
fn find_sysroot() -> String {
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
match (home, toolchain) {
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
_ => {
option_env!("RUST_SYSROOT")
.expect(
"need to specify RUST_SYSROOT env var or use rustup or multirust",
)
.to_owned()
}
}
}
pub fn run(filename: &str, bencher: &mut Bencher) {
let args = &[
"miri".to_string(),
format!("benches/helpers/{}.rs", filename),
"--sysroot".to_string(),
find_sysroot(),
];
let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
rustc_driver::run_compiler(args, compiler_calls, None, None);
}
impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
fn build_controller(
&mut self,
_: &Session,
_: &getopts::Matches,
) -> driver::CompileController<'a> {
let mut control: driver::CompileController<'a> = driver::CompileController::basic();
let bencher = self.0.clone();
control.after_analysis.stop = Compilation::Stop;
control.after_analysis.callback = Box::new(move |state| {
state.session.abort_if_errors();
let tcx = state.tcx.unwrap();
let (entry_node_id, _) = state.session.entry_fn.borrow().expect(
"no main or start function found",
);
let entry_def_id = tcx.map.local_def_id(entry_node_id);
let memory_size = 100 * 1024 * 1024; // 100MB
let step_limit = 1000_000;
let stack_limit = 100;
bencher.borrow_mut().iter(|| {
eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit);
});
state.session.abort_if_errors();
});
control
}
}
// This module gets included in multiple crates, and they each only use part of it.
#![allow(dead_code)]
pub mod fibonacci_helper;
pub mod fibonacci_helper_iterative;
pub mod miri_helper;
pub mod smoke_helper;
fn main() {
let data: [u8; 1024] = [42; 1024];
assert_eq!(data.len(), 1024);
}
fn main() {
let mut data: [u8; 1024] = unsafe { std::mem::uninitialized() };
for i in 0..data.len() {
unsafe { std::ptr::write(&mut data[i], 0); }
}
assert_eq!(data.len(), 1024);
}
#[inline(never)]
pub fn main() {}
#![feature(test, rustc_private)]
extern crate test;
use test::Bencher;
mod helpers;
use helpers::*;
#[bench]
fn repeat(bencher: &mut Bencher) {
miri_helper::run("repeat", bencher);
}
#[bench]
fn repeat_manual(bencher: &mut Bencher) {
miri_helper::run("repeat_manual", bencher);
}
#![feature(test, rustc_private)]
extern crate test;
use test::Bencher;
mod helpers;
use helpers::*;
#[bench]
fn noop(bencher: &mut Bencher) {
bencher.iter(|| { smoke_helper::main(); })
}
/*
// really slow
#[bench]
fn noop_miri_full(bencher: &mut Bencher) {
let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
bencher.iter(|| {
let mut process = std::process::Command::new("target/release/miri");
process.arg("benches/smoke_helper.rs")
.arg("--sysroot").arg(&path);
let output = process.output().unwrap();
if !output.status.success() {
println!("{}", String::from_utf8(output.stdout).unwrap());
println!("{}", String::from_utf8(output.stderr).unwrap());
panic!("failed to run miri");
}
})
}
*/
#[bench]
fn noop_miri_interpreter(bencher: &mut Bencher) {
miri_helper::run("smoke_helper", bencher);
}
use std::env;
fn main() {
// Forward the profile to the main compilation
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
// Don't rebuild miri even if nothing changed
println!("cargo:rerun-if-changed=build.rs");
}
[root]
name = "cargo-miri-test"
version = "0.1.0"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
[package]
name = "cargo-miri-test"
version = "0.1.0"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
[dependencies]
byteorder = "1.0"
\ No newline at end of file
extern crate byteorder;
use byteorder::{BigEndian, ByteOrder};
fn main() {
let buf = &[1,2,3,4];
let n = <BigEndian as ByteOrder>::read_u32(buf);
assert_eq!(n, 0x01020304);
}
#[test]
fn bar() {
assert_eq!(4, 4);
}
extern crate cargo_metadata;
use std::path::{PathBuf, Path};
use std::io::Write;
use std::process::Command;
const CARGO_MIRI_HELP: &str = r#"Interprets bin crates
Usage:
cargo miri [options] [--] [<opts>...]
Common options: