Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Stubs for visiting MIR nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Herman Venter committed Dec 7, 2018
1 parent 8fdb938 commit 71c0a7e
Show file tree
Hide file tree
Showing 7 changed files with 625 additions and 41 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions documentation/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@ sources.

## Testing

For now we test mirai by running it on itself, by doing `cargo build` in the mirai directory while setting the
`RUSTC_WRAPPER` environment variable to `mirai`.
Testing is done via `cargo test`. We favor integration tests over unit tests and require every pull request to have 100%
test coverage. The code coverage tool (`cargo tarpaulin`) is still buggy, so this may not always be possible, but all
exceptions should be called out and explained in the pull request test plan.

For the time being (see issue #10), we provide a separate test method in integration_tests.rs for each test input in
the [tests/run-pass](https://github.com/facebookexperimental/MIRAI/blob/master/tests/run-pass) directory.
11 changes: 7 additions & 4 deletions src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_metadata::cstore::CStore;
use std::path::PathBuf;
use syntax::{ast, errors};
use visitors;
use visitors::MirVisitor;

/// Private state used to implement the callbacks.
pub struct MiraiCallbacks {
Expand Down Expand Up @@ -139,8 +140,10 @@ impl<'a> CompilerCalls<'a> for MiraiCallbacks {
/// interpretation of all of the functions that will end up in the compiler output.
fn after_analysis(state: &mut driver::CompileState) {
let tcx = state.tcx.unwrap();
state
.hir_crate
.unwrap()
.visit_all_item_likes(&mut visitors::CrateVisitor { tcx, state });
for def_id in tcx.body_owners() {
// By this time all analyses have been carried out, so it should be safe to borrow this now.
let mir = tcx.optimized_mir(def_id);

This comment has been minimized.

Copy link
@fpoli

fpoli Dec 14, 2018

If you want to extract aliasing information from the types I suggest to use validated_mir instead of optimized_mir, because some type guarantees are not respected in the latter. For example, mutable borrows can be copied in optimized MIR: rust-lang/rust#46420 (as pointed out in https://users.rust-lang.org/t/why-the-borrow-checker-runs-on-validated-and-not-optimized-mir/15775).

This comment has been minimized.

Copy link
@hermanventer

hermanventer Dec 14, 2018

Contributor

Good point. At this stage, however, it is not clear to me that the optimizer will break the Abstract Interpreter, because it will accurately track the state inside a body. The only help it should need is to ensure that parameters that point to mutable state will not be aliased. Nevertheless, I will keep this in mind. It seems that it should be an easy enough change to make if the need for it become apparent in the future.

let mir_visitor = visitors::MirTestVisitor { tcx, def_id, mir };
mir_visitor.visit_body();
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
// While pretty bad, it is a lot less bad than having to write our own compiler, so here goes.
#![feature(rustc_private)]
#![feature(box_syntax)]
#![feature(extern_crate_item_prelude)]

extern crate getopts;
extern crate rustc;
extern crate rustc_codegen_utils;
extern crate rustc_driver;
extern crate rustc_metadata;
extern crate syntax;
extern crate syntax_pos;

#[macro_use]
extern crate log;
Expand Down
Loading

0 comments on commit 71c0a7e

Please sign in to comment.