about summary refs log tree commit diff
path: root/compiler/stable_mir/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-29 03:55:21 +0000
committerbors <bors@rust-lang.org>2024-05-29 03:55:21 +0000
commit751691271d76b8435559200b84d1947c2bd735bd (patch)
tree43c1b958190e9e2b87cea232e2f3ac27df9ecaa8 /compiler/stable_mir/src
parentda159eb331b27df528185c616b394bb0e1d2a4bd (diff)
parent4c1228276b15c50b991d052d9fc682cc62f90881 (diff)
downloadrust-751691271d76b8435559200b84d1947c2bd735bd.tar.gz
rust-751691271d76b8435559200b84d1947c2bd735bd.zip
Auto merge of #125691 - jieyouxu:rollup-0i3wrc4, r=jieyouxu
Rollup of 8 pull requests

Successful merges:

 - #124251 (Add an intrinsic for `ptr::metadata`)
 - #124320 (Add `--print=check-cfg` to get the expected configs)
 - #125226 (Make more of the test suite run on Mac Catalyst)
 - #125381 (Silence some resolve errors when there have been glob import errors)
 - #125633 (miri: avoid making a full copy of all new allocations)
 - #125638 (Rewrite `lto-smoke`, `simple-rlib` and `mixing-deps` `run-make` tests in `rmake.rs` format)
 - #125639 (Support `./x doc run-make-support --open`)
 - #125664 (Tweak relations to no longer rely on `TypeTrace`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/stable_mir/src')
-rw-r--r--compiler/stable_mir/src/compiler_interface.rs5
-rw-r--r--compiler/stable_mir/src/mir/body.rs14
2 files changed, 17 insertions, 2 deletions
diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs
index 4dd64228bba..858ce5301d8 100644
--- a/compiler/stable_mir/src/compiler_interface.rs
+++ b/compiler/stable_mir/src/compiler_interface.rs
@@ -8,7 +8,7 @@ use std::cell::Cell;
 use crate::abi::{FnAbi, Layout, LayoutShape};
 use crate::mir::alloc::{AllocId, GlobalAlloc};
 use crate::mir::mono::{Instance, InstanceDef, StaticDef};
-use crate::mir::{BinOp, Body, Place};
+use crate::mir::{BinOp, Body, Place, UnOp};
 use crate::target::MachineInfo;
 use crate::ty::{
     AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef,
@@ -226,6 +226,9 @@ pub trait Context {
 
     /// Get the resulting type of binary operation.
     fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty;
+
+    /// Get the resulting type of unary operation.
+    fn unop_ty(&self, un_op: UnOp, arg: Ty) -> Ty;
 }
 
 // A thread local variable that stores a pointer to the tables mapping between TyCtxt
diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs
index a1432acf93c..4c779ae96a8 100644
--- a/compiler/stable_mir/src/mir/body.rs
+++ b/compiler/stable_mir/src/mir/body.rs
@@ -346,6 +346,15 @@ impl BinOp {
 pub enum UnOp {
     Not,
     Neg,
+    PtrMetadata,
+}
+
+impl UnOp {
+    /// Return the type of this operation for the given input Ty.
+    /// This function does not perform type checking, and it currently doesn't handle SIMD.
+    pub fn ty(&self, arg_ty: Ty) -> Ty {
+        with(|ctx| ctx.unop_ty(*self, arg_ty))
+    }
 }
 
 #[derive(Clone, Debug, Eq, PartialEq)]
@@ -580,7 +589,10 @@ impl Rvalue {
                 let ty = op.ty(lhs_ty, rhs_ty);
                 Ok(Ty::new_tuple(&[ty, Ty::bool_ty()]))
             }
-            Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, operand) => operand.ty(locals),
+            Rvalue::UnaryOp(op, operand) => {
+                let arg_ty = operand.ty(locals)?;
+                Ok(op.ty(arg_ty))
+            }
             Rvalue::Discriminant(place) => {
                 let place_ty = place.ty(locals)?;
                 place_ty