From 6743fc7704d28a0be61643b1cada2fd31be132b5 Mon Sep 17 00:00:00 2001 From: Mohammad Omidvar Date: Thu, 23 May 2024 15:35:18 +0000 Subject: [PATCH] Add conversion from IntrinsicDef to FnDef --- compiler/stable_mir/src/ty.rs | 6 ++++++ tests/ui-fulldeps/stable-mir/check_intrinsics.rs | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index ab4deac9fd7..ebfc6e026eb 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -653,6 +653,12 @@ pub fn must_be_overridden(&self) -> bool { } } +impl From for FnDef { + fn from(def: IntrinsicDef) -> Self { + FnDef(def.0) + } +} + crate_def! { pub ClosureDef; } diff --git a/tests/ui-fulldeps/stable-mir/check_intrinsics.rs b/tests/ui-fulldeps/stable-mir/check_intrinsics.rs index a9c1f64f812..7e247ce0c75 100644 --- a/tests/ui-fulldeps/stable-mir/check_intrinsics.rs +++ b/tests/ui-fulldeps/stable-mir/check_intrinsics.rs @@ -24,11 +24,11 @@ use stable_mir::mir::mono::{Instance, InstanceKind}; use stable_mir::mir::visit::{Location, MirVisitor}; 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::io::Write; use std::ops::ControlFlow; -use std::assert_matches::assert_matches; /// This function tests that we can correctly get type information from binary operations. fn test_intrinsics() -> ControlFlow<()> { @@ -41,9 +41,9 @@ fn test_intrinsics() -> ControlFlow<()> { let calls = visitor.calls; assert_eq!(calls.len(), 3, "Expected 3 calls, but found: {calls:?}"); - for (fn_def, args) in &calls { - check_instance(&Instance::resolve(*fn_def, &args).unwrap()); - check_def(fn_def.as_intrinsic().unwrap()); + for (fn_def, args) in calls.into_iter() { + check_instance(&Instance::resolve(fn_def, &args).unwrap()); + check_def(fn_def); } 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(); match name.as_str() { "likely" | "size_of_val" => {