Create StableMir replacer for SMirCalls
This commit is contained in:
parent
cedbe5c715
commit
c2fe0bf253
5 changed files with 54 additions and 33 deletions
|
@ -6,11 +6,15 @@
|
|||
use std::fmt::Debug;
|
||||
use std::string::ToString;
|
||||
|
||||
use crate::rustc_internal;
|
||||
use crate::{
|
||||
rustc_smir::Tables,
|
||||
stable_mir::{self, with},
|
||||
};
|
||||
use rustc_driver::{Callbacks, Compilation, RunCompiler};
|
||||
use rustc_interface::{interface, Queries};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::EarlyErrorHandler;
|
||||
pub use rustc_span::def_id::{CrateNum, DefId};
|
||||
|
||||
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
|
||||
|
@ -163,3 +167,40 @@ pub type Opaque = impl Debug + ToString + Clone;
|
|||
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
|
||||
format!("{value:?}")
|
||||
}
|
||||
|
||||
pub struct StableMir {
|
||||
args: Vec<String>,
|
||||
callback: fn(TyCtxt<'_>),
|
||||
}
|
||||
|
||||
impl StableMir {
|
||||
/// Creates a new `StableMir` instance, with given test_function and arguments.
|
||||
pub fn new(args: Vec<String>, callback: fn(TyCtxt<'_>)) -> Self {
|
||||
StableMir { args, callback }
|
||||
}
|
||||
|
||||
/// Runs the compiler against given target and tests it with `test_function`
|
||||
pub fn run(&mut self) {
|
||||
rustc_driver::catch_fatal_errors(|| {
|
||||
RunCompiler::new(&self.args.clone(), self).run().unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl Callbacks for StableMir {
|
||||
/// Called after analysis. Return value instructs the compiler whether to
|
||||
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
||||
fn after_analysis<'tcx>(
|
||||
&mut self,
|
||||
_handler: &EarlyErrorHandler,
|
||||
_compiler: &interface::Compiler,
|
||||
queries: &'tcx Queries<'tcx>,
|
||||
) -> Compilation {
|
||||
queries.global_ctxt().unwrap().enter(|tcx| {
|
||||
rustc_internal::run(tcx, || (self.callback)(tcx));
|
||||
});
|
||||
// No need to keep going.
|
||||
Compilation::Stop
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@
|
|||
|
||||
use std::cell::Cell;
|
||||
|
||||
use crate::rustc_smir::Tables;
|
||||
|
||||
use self::ty::{
|
||||
GenericDef, Generics, ImplDef, ImplTrait, PredicateKind, Span, TraitDecl, TraitDef, Ty, TyKind,
|
||||
};
|
||||
use crate::rustc_smir::Tables;
|
||||
|
||||
pub mod mir;
|
||||
pub mod ty;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue