Skip to content

Commit 1a8a5d0

Browse files
committed
SMIR: Allow users to pick if compilation continues
Currently we stop compilation, but some users might want to keep going. This is needed for us to test against rustc tests. Other tools, such as Kani, also implements parts of their logic as a backend so it is important for compilation to continue.
1 parent 3b01f65 commit 1a8a5d0

File tree

1 file changed

+20
-8
lines changed
  • compiler/rustc_smir/src/rustc_internal

1 file changed

+20
-8
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ where
196196
{
197197
args: Vec<String>,
198198
callback: fn(TyCtxt<'_>) -> T,
199+
after_analysis: Compilation,
199200
result: Option<T>,
200201
}
201202

@@ -205,16 +206,27 @@ where
205206
{
206207
/// Creates a new `StableMir` instance, with given test_function and arguments.
207208
pub fn new(args: Vec<String>, callback: fn(TyCtxt<'_>) -> T) -> Self {
208-
StableMir { args, callback, result: None }
209+
StableMir { args, callback, result: None, after_analysis: Compilation::Stop }
210+
}
211+
212+
/// Configure object to stop compilation after callback is called.
213+
pub fn stop_compilation(&mut self) -> &mut Self {
214+
self.after_analysis = Compilation::Stop;
215+
self
216+
}
217+
218+
/// Configure object to continue compilation after callback is called.
219+
pub fn continue_compilation(&mut self) -> &mut Self {
220+
self.after_analysis = Compilation::Continue;
221+
self
209222
}
210223

211224
/// Runs the compiler against given target and tests it with `test_function`
212-
pub fn run(mut self) -> Result<T, CompilerError> {
213-
let compiler_result = rustc_driver::catch_fatal_errors(|| {
214-
RunCompiler::new(&self.args.clone(), &mut self).run()
215-
});
225+
pub fn run(&mut self) -> Result<T, CompilerError> {
226+
let compiler_result =
227+
rustc_driver::catch_fatal_errors(|| RunCompiler::new(&self.args.clone(), self).run());
216228
match compiler_result {
217-
Ok(Ok(())) => Ok(self.result.unwrap()),
229+
Ok(Ok(())) => Ok(self.result.take().unwrap()),
218230
Ok(Err(_)) => Err(CompilerError::CompilationFailed),
219231
Err(_) => Err(CompilerError::ICE),
220232
}
@@ -238,7 +250,7 @@ where
238250
self.result = Some((self.callback)(tcx));
239251
});
240252
});
241-
// No need to keep going.
242-
Compilation::Stop
253+
// Let users define if they want to stop compilation.
254+
self.after_analysis
243255
}
244256
}

0 commit comments

Comments
 (0)