Skip to content

Commit 161c674

Browse files
committed
Add Assume custom MIR.
1 parent ef71f10 commit 161c674

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
2020
@call(mir_storage_dead, args) => {
2121
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
2222
},
23+
@call(mir_assume, args) => {
24+
let op = self.parse_operand(args[0])?;
25+
Ok(StatementKind::Intrinsic(Box::new(NonDivergingIntrinsic::Assume(op))))
26+
},
2327
@call(mir_deinit, args) => {
2428
Ok(StatementKind::Deinit(Box::new(self.parse_place(args[0])?)))
2529
},

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ symbols! {
10271027
minnumf32,
10281028
minnumf64,
10291029
mips_target_feature,
1030+
mir_assume,
10301031
mir_basic_block,
10311032
mir_call,
10321033
mir_cast_transmute,

library/core/src/intrinsics/mir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ define!("mir_unwind_resume",
357357

358358
define!("mir_storage_live", fn StorageLive<T>(local: T));
359359
define!("mir_storage_dead", fn StorageDead<T>(local: T));
360+
#[cfg(not(bootstrap))]
361+
define!("mir_assume", fn Assume(operand: bool));
360362
define!("mir_deinit", fn Deinit<T>(place: T));
361363
define!("mir_checked", fn Checked<T>(binop: T) -> (T, bool));
362364
define!("mir_len", fn Len<T>(place: T) -> usize);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// MIR for `assume_constant` after built
2+
3+
fn assume_constant() -> () {
4+
let mut _0: ();
5+
6+
bb0: {
7+
assume(const true);
8+
return;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// MIR for `assume_local` after built
2+
3+
fn assume_local(_1: bool) -> () {
4+
let mut _0: ();
5+
6+
bb0: {
7+
assume(_1);
8+
return;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// MIR for `assume_place` after built
2+
3+
fn assume_place(_1: (bool, u8)) -> () {
4+
let mut _0: ();
5+
6+
bb0: {
7+
assume((_1.0: bool));
8+
return;
9+
}
10+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// skip-filecheck
2+
#![feature(custom_mir, core_intrinsics)]
3+
4+
extern crate core;
5+
use core::intrinsics::mir::*;
6+
7+
// EMIT_MIR assume.assume_local.built.after.mir
8+
#[custom_mir(dialect = "built")]
9+
fn assume_local(x: bool) {
10+
mir!(
11+
{
12+
Assume(x);
13+
Return()
14+
}
15+
)
16+
}
17+
18+
// EMIT_MIR assume.assume_place.built.after.mir
19+
#[custom_mir(dialect = "built")]
20+
fn assume_place(p: (bool, u8)) {
21+
mir!(
22+
{
23+
Assume(p.0);
24+
Return()
25+
}
26+
)
27+
}
28+
29+
// EMIT_MIR assume.assume_constant.built.after.mir
30+
#[custom_mir(dialect = "built")]
31+
fn assume_constant() {
32+
mir!(
33+
{
34+
Assume(true);
35+
Return()
36+
}
37+
)
38+
}
39+
40+
fn main() {
41+
assume_local(true);
42+
assume_place((true, 50));
43+
assume_constant();
44+
}

0 commit comments

Comments
 (0)