Add regression test

This commit is contained in:
Oli Scherer 2024-06-07 13:22:25 +00:00
parent 72cbb8bd94
commit 9461852363

View File

@ -33,7 +33,7 @@ fn test_stable_mir() -> ControlFlow<()> {
// Get all items and split generic vs monomorphic items.
let (generic, mono): (Vec<_>, Vec<_>) =
items.into_iter().partition(|item| item.requires_monomorphization());
assert_eq!(mono.len(), 3, "Expected 2 mono functions and one constant");
assert_eq!(mono.len(), 4, "Expected 2 mono functions and one constant");
assert_eq!(generic.len(), 2, "Expected 2 generic functions");
// For all monomorphic items, get the correspondent instances.
@ -57,8 +57,9 @@ fn test_body(body: mir::Body) {
for term in body.blocks.iter().map(|bb| &bb.terminator) {
match &term.kind {
Call { func, .. } => {
let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { unreachable!
() };
let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else {
unreachable!()
};
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
let instance = Instance::resolve(def, &args).unwrap();
let mangled_name = instance.mangled_name();
@ -102,6 +103,9 @@ fn generate_input(path: &str) -> std::io::Result<()> {
write!(
file,
r#"
struct Foo(());
pub fn ty_param<T>(t: &T) -> T where T: Clone {{
t.clone()
}}
@ -116,6 +120,7 @@ pub fn ty_param<T>(t: &T) -> T where T: Clone {{
}}
pub fn monomorphic() {{
Foo(());
let v = vec![10];
let dup = ty_param(&v);
assert_eq!(v, dup);