Add conversion from IntrinsicDef to FnDef

This commit is contained in:
Mohammad Omidvar 2024-05-23 15:35:18 +00:00
parent 56ad5453f6
commit 6743fc7704
2 changed files with 16 additions and 6 deletions

View File

@ -653,6 +653,12 @@ pub fn must_be_overridden(&self) -> bool {
} }
} }
impl From<IntrinsicDef> for FnDef {
fn from(def: IntrinsicDef) -> Self {
FnDef(def.0)
}
}
crate_def! { crate_def! {
pub ClosureDef; pub ClosureDef;
} }

View File

@ -24,11 +24,11 @@
use stable_mir::mir::mono::{Instance, InstanceKind}; use stable_mir::mir::mono::{Instance, InstanceKind};
use stable_mir::mir::visit::{Location, MirVisitor}; use stable_mir::mir::visit::{Location, MirVisitor};
use stable_mir::mir::{LocalDecl, Terminator, TerminatorKind}; use stable_mir::mir::{LocalDecl, Terminator, TerminatorKind};
use stable_mir::ty::{FnDef, GenericArgs, IntrinsicDef, RigidTy, TyKind}; use stable_mir::ty::{FnDef, GenericArgs, RigidTy, TyKind};
use std::assert_matches::assert_matches;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::io::Write; use std::io::Write;
use std::ops::ControlFlow; use std::ops::ControlFlow;
use std::assert_matches::assert_matches;
/// This function tests that we can correctly get type information from binary operations. /// This function tests that we can correctly get type information from binary operations.
fn test_intrinsics() -> ControlFlow<()> { fn test_intrinsics() -> ControlFlow<()> {
@ -41,9 +41,9 @@ fn test_intrinsics() -> ControlFlow<()> {
let calls = visitor.calls; let calls = visitor.calls;
assert_eq!(calls.len(), 3, "Expected 3 calls, but found: {calls:?}"); assert_eq!(calls.len(), 3, "Expected 3 calls, but found: {calls:?}");
for (fn_def, args) in &calls { for (fn_def, args) in calls.into_iter() {
check_instance(&Instance::resolve(*fn_def, &args).unwrap()); check_instance(&Instance::resolve(fn_def, &args).unwrap());
check_def(fn_def.as_intrinsic().unwrap()); check_def(fn_def);
} }
ControlFlow::Continue(()) ControlFlow::Continue(())
@ -68,7 +68,11 @@ fn check_instance(instance: &Instance) {
} }
} }
fn check_def(intrinsic: IntrinsicDef) { fn check_def(fn_def: FnDef) {
assert!(fn_def.is_intrinsic());
let intrinsic = fn_def.as_intrinsic().unwrap();
assert_eq!(fn_def, intrinsic.into());
let name = intrinsic.fn_name(); let name = intrinsic.fn_name();
match name.as_str() { match name.as_str() {
"likely" | "size_of_val" => { "likely" | "size_of_val" => {