summaryrefslogtreecommitdiffstats
path: root/tests/ui-fulldeps/stable-mir/crate-info.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui-fulldeps/stable-mir/crate-info.rs')
-rw-r--r--tests/ui-fulldeps/stable-mir/crate-info.rs129
1 files changed, 71 insertions, 58 deletions
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs
index ce4ee3c24..ed6b786f5 100644
--- a/tests/ui-fulldeps/stable-mir/crate-info.rs
+++ b/tests/ui-fulldeps/stable-mir/crate-info.rs
@@ -4,6 +4,7 @@
// ignore-stage1
// ignore-cross-compile
// ignore-remote
+// ignore-windows-gnu mingw has troubles with linking https://github.com/rust-lang/rust/pull/116837
// edition: 2021
#![feature(rustc_private)]
@@ -12,14 +13,17 @@
extern crate rustc_hir;
extern crate rustc_middle;
+#[macro_use]
extern crate rustc_smir;
+extern crate rustc_driver;
+extern crate rustc_interface;
extern crate stable_mir;
use rustc_hir::def::DefKind;
use rustc_middle::ty::TyCtxt;
use rustc_smir::rustc_internal;
-
-use stable_mir::fold::Foldable;
+use stable_mir::mir::mono::Instance;
+use stable_mir::ty::{RigidTy, TyKind};
use std::assert_matches::assert_matches;
use std::io::Write;
use std::ops::ControlFlow;
@@ -38,59 +42,59 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
let items = stable_mir::all_local_items();
assert!(get_item(&items, (DefKind::Fn, "foo::bar")).is_some());
- // Find the `std` crate.
- assert!(stable_mir::find_crate("std").is_some());
+ // Find the `std` crate and assert that there is only one of it.
+ assert!(stable_mir::find_crates("std").len() == 1);
let bar = get_item(&items, (DefKind::Fn, "bar")).unwrap();
let body = bar.body();
- assert_eq!(body.locals.len(), 2);
+ assert_eq!(body.locals().len(), 2);
assert_eq!(body.blocks.len(), 1);
let block = &body.blocks[0];
assert_eq!(block.statements.len(), 1);
- match &block.statements[0] {
- stable_mir::mir::Statement::Assign(..) => {}
+ match &block.statements[0].kind {
+ stable_mir::mir::StatementKind::Assign(..) => {}
other => panic!("{other:?}"),
}
- match &block.terminator {
- stable_mir::mir::Terminator::Return => {}
+ match &block.terminator.kind {
+ stable_mir::mir::TerminatorKind::Return => {}
other => panic!("{other:?}"),
}
let foo_bar = get_item(&items, (DefKind::Fn, "foo_bar")).unwrap();
let body = foo_bar.body();
- assert_eq!(body.locals.len(), 7);
+ assert_eq!(body.locals().len(), 5);
assert_eq!(body.blocks.len(), 4);
let block = &body.blocks[0];
- match &block.terminator {
- stable_mir::mir::Terminator::Call { .. } => {}
+ match &block.terminator.kind {
+ stable_mir::mir::TerminatorKind::Call { .. } => {}
other => panic!("{other:?}"),
}
let types = get_item(&items, (DefKind::Fn, "types")).unwrap();
let body = types.body();
- assert_eq!(body.locals.len(), 6);
+ assert_eq!(body.locals().len(), 6);
assert_matches!(
- body.locals[0].kind(),
+ body.locals()[0].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
);
assert_matches!(
- body.locals[1].kind(),
+ body.locals()[1].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
);
assert_matches!(
- body.locals[2].kind(),
+ body.locals()[2].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
);
assert_matches!(
- body.locals[3].kind(),
+ body.locals()[3].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
);
assert_matches!(
- body.locals[4].kind(),
+ body.locals()[4].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
);
assert_matches!(
- body.locals[5].kind(),
+ body.locals()[5].ty.kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
stable_mir::ty::FloatTy::F64
))
@@ -100,8 +104,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
let body = drop.body();
assert_eq!(body.blocks.len(), 2);
let block = &body.blocks[0];
- match &block.terminator {
- stable_mir::mir::Terminator::Drop { .. } => {}
+ match &block.terminator.kind {
+ stable_mir::mir::TerminatorKind::Drop { .. } => {}
other => panic!("{other:?}"),
}
@@ -109,47 +113,25 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
let body = assert.body();
assert_eq!(body.blocks.len(), 2);
let block = &body.blocks[0];
- match &block.terminator {
- stable_mir::mir::Terminator::Assert { .. } => {}
+ match &block.terminator.kind {
+ stable_mir::mir::TerminatorKind::Assert { .. } => {}
other => panic!("{other:?}"),
}
let monomorphic = get_item(&items, (DefKind::Fn, "monomorphic")).unwrap();
- for block in monomorphic.body().blocks {
- match &block.terminator {
- stable_mir::mir::Terminator::Call { func, .. } => match func {
- stable_mir::mir::Operand::Constant(c) => match &c.literal.literal {
- stable_mir::ty::ConstantKind::Allocated(alloc) => {
- assert!(alloc.bytes.is_empty());
- match c.literal.ty.kind() {
- stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::FnDef(
- def,
- mut args,
- )) => {
- let func = def.body();
- match func.locals[1]
- .fold(&mut args)
- .continue_value()
- .unwrap()
- .kind()
- {
- stable_mir::ty::TyKind::RigidTy(
- stable_mir::ty::RigidTy::Uint(_),
- ) => {}
- stable_mir::ty::TyKind::RigidTy(
- stable_mir::ty::RigidTy::Tuple(_),
- ) => {}
- other => panic!("{other:?}"),
- }
- }
- other => panic!("{other:?}"),
- }
- }
+ let instance = Instance::try_from(monomorphic.clone()).unwrap();
+ for block in instance.body().blocks {
+ match &block.terminator.kind {
+ stable_mir::mir::TerminatorKind::Call { func, .. } => {
+ let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
+ let RigidTy::FnDef(def, args) = ty else { unreachable!() };
+ let next_func = Instance::resolve(def, &args).unwrap();
+ match next_func.body().locals()[1].ty.kind() {
+ TyKind::RigidTy(RigidTy::Uint(_)) | TyKind::RigidTy(RigidTy::Tuple(_)) => {}
other => panic!("{other:?}"),
- },
- other => panic!("{other:?}"),
- },
- stable_mir::mir::Terminator::Return => {}
+ }
+ }
+ stable_mir::mir::TerminatorKind::Return => {}
other => panic!("{other:?}"),
}
}
@@ -158,6 +140,29 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
// Ensure we don't panic trying to get the body of a constant.
foo_const.body();
+ let locals_fn = get_item(&items, (DefKind::Fn, "locals")).unwrap();
+ let body = locals_fn.body();
+ assert_eq!(body.locals().len(), 4);
+ assert_matches!(
+ body.ret_local().ty.kind(),
+ stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
+ );
+ assert_eq!(body.arg_locals().len(), 2);
+ assert_matches!(
+ body.arg_locals()[0].ty.kind(),
+ stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
+ );
+ assert_matches!(
+ body.arg_locals()[1].ty.kind(),
+ stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
+ );
+ assert_eq!(body.inner_locals().len(), 1);
+ // If conditions have an extra inner local to hold their results
+ assert_matches!(
+ body.inner_locals()[0].ty.kind(),
+ stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
+ );
+
ControlFlow::Continue(())
}
@@ -185,7 +190,7 @@ fn main() {
CRATE_NAME.to_string(),
path.to_string(),
];
- rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap();
+ run!(args, tcx, test_stable_mir(tcx)).unwrap();
}
fn generate_input(path: &str) -> std::io::Result<()> {
@@ -229,6 +234,14 @@ fn generate_input(path: &str) -> std::io::Result<()> {
pub fn assert(x: i32) -> i32 {{
x + 1
+ }}
+
+ pub fn locals(a: i32, _: u64) -> char {{
+ if a > 5 {{
+ 'a'
+ }} else {{
+ 'b'
+ }}
}}"#
)?;
Ok(())