Skip to content

Commit

Permalink
Enhance test and fix arguments list
Browse files Browse the repository at this point in the history
Add a comma between function arguments
  • Loading branch information
celinval committed Oct 28, 2024
1 parent bb08f56 commit 3b2c906
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/stable_mir/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ impl Debug for Place {

pub(crate) fn function_body<W: Write>(writer: &mut W, body: &Body, name: &str) -> io::Result<()> {
write!(writer, "fn {name}(")?;
body.arg_locals()
.iter()
.enumerate()
.try_for_each(|(index, local)| write!(writer, "_{}: {}", index + 1, local.ty))?;
let mut sep = "";
body.arg_locals().iter().enumerate().try_for_each(|(index, local)| {
write!(writer, "{}_{}: {}", sep, index + 1, local.ty)?;
sep = ", ";
io::Result::Ok(())
})?;
write!(writer, ")")?;

let return_local = body.ret_local();
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/stable-mir-print/operands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ pub fn operands(val: u8) {
let size_of = std::mem::size_of_val(&length);
assert_eq!(length, size_of);
}

pub struct Dummy { c: char, i: i32 }

pub enum Ctors {
Unit,
StructLike { d: Dummy },
TupLike(bool),
}

pub fn more_operands() -> [Ctors; 3] {
let dummy = Dummy { c: 'a', i: i32::MIN };
let unit = Ctors::Unit;
let struct_like = Ctors::StructLike { d: dummy };
let tup_like = Ctors::TupLike(false);
[unit, struct_like, tup_like]
}

pub fn closures(x: bool, z: bool) -> impl FnOnce(bool) -> bool {
move |y: bool| { (x ^ y) || z }
}
66 changes: 66 additions & 0 deletions tests/ui/stable-mir-print/operands.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,69 @@ fn operands::{constant#0}() -> usize {
return;
}
}
fn more_operands() -> [Ctors; 3] {
let mut _0: [Ctors; 3];
let _1: Dummy;
let _2: Ctors;
let _3: Ctors;
let _4: Ctors;
debug dummy => _1;
debug unit => _2;
debug struct_like => _3;
debug tup_like => _4;
bb0: {
_1 = Dummy('a', core::num::<impl i32>::MIN);
_2 = Ctors::Unit;
_3 = Ctors::StructLike(move _1);
_4 = Ctors::TupLike(false);
_0 = [move _2, move _3, move _4];
return;
}
}
fn more_operands::{constant#0}() -> usize {
let mut _0: usize;
bb0: {
_0 = 3_usize;
return;
}
}
fn closures(_1: bool, _2: bool) -> {closure@$DIR/operands.rs:44:5: 44:19} {
let mut _0: {closure@$DIR/operands.rs:44:5: 44:19};
debug x => _1;
debug z => _2;
bb0: {
_0 = {closure@Span { id: 105, repr: "$DIR/operands.rs:44:5: 44:19" }}(_1, _2);
return;
}
}
fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:44:5: 44:19}, _2: bool) -> bool {
let mut _0: bool;
let mut _3: bool;
let mut _4: bool;
debug y => _2;
debug x => (_1.0: bool);
debug z => (_1.1: bool);
bb0: {
_4 = (_1.0: bool);
_3 = BitXor(move _4, _2);
switchInt(move _3) -> [0: bb2, otherwise: bb1];
}
bb1: {
_0 = true;
goto -> bb3;
}
bb2: {
_0 = (_1.1: bool);
goto -> bb3;
}
bb3: {
return;
}
}
fn Ctors::TupLike(_1: bool) -> Ctors {
let mut _0: Ctors;
bb0: {
_0 = Ctors::TupLike(move _1);
return;
}
}

0 comments on commit 3b2c906

Please sign in to comment.