Remove unimplemented!() from BinOp::ty() function
To reduce redundancy, we now internalize the BinOp instead of duplicating the `ty()` function body.
This commit is contained in:
parent
ea40fa210b
commit
0a4f4a3e29
5 changed files with 196 additions and 39 deletions
|
@ -10,7 +10,7 @@ use rustc_span::Symbol;
|
|||
use stable_mir::abi::Layout;
|
||||
use stable_mir::mir::alloc::AllocId;
|
||||
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
||||
use stable_mir::mir::{Mutability, Place, ProjectionElem, Safety};
|
||||
use stable_mir::mir::{BinOp, Mutability, Place, ProjectionElem, Safety};
|
||||
use stable_mir::ty::{
|
||||
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
|
||||
DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
|
||||
|
@ -535,6 +535,38 @@ impl RustcInternal for ProjectionElem {
|
|||
}
|
||||
}
|
||||
|
||||
impl RustcInternal for BinOp {
|
||||
type T<'tcx> = rustc_middle::mir::BinOp;
|
||||
|
||||
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
||||
match self {
|
||||
BinOp::Add => rustc_middle::mir::BinOp::Add,
|
||||
BinOp::AddUnchecked => rustc_middle::mir::BinOp::AddUnchecked,
|
||||
BinOp::Sub => rustc_middle::mir::BinOp::Sub,
|
||||
BinOp::SubUnchecked => rustc_middle::mir::BinOp::SubUnchecked,
|
||||
BinOp::Mul => rustc_middle::mir::BinOp::Mul,
|
||||
BinOp::MulUnchecked => rustc_middle::mir::BinOp::MulUnchecked,
|
||||
BinOp::Div => rustc_middle::mir::BinOp::Div,
|
||||
BinOp::Rem => rustc_middle::mir::BinOp::Rem,
|
||||
BinOp::BitXor => rustc_middle::mir::BinOp::BitXor,
|
||||
BinOp::BitAnd => rustc_middle::mir::BinOp::BitAnd,
|
||||
BinOp::BitOr => rustc_middle::mir::BinOp::BitOr,
|
||||
BinOp::Shl => rustc_middle::mir::BinOp::Shl,
|
||||
BinOp::ShlUnchecked => rustc_middle::mir::BinOp::ShlUnchecked,
|
||||
BinOp::Shr => rustc_middle::mir::BinOp::Shr,
|
||||
BinOp::ShrUnchecked => rustc_middle::mir::BinOp::ShrUnchecked,
|
||||
BinOp::Eq => rustc_middle::mir::BinOp::Eq,
|
||||
BinOp::Lt => rustc_middle::mir::BinOp::Lt,
|
||||
BinOp::Le => rustc_middle::mir::BinOp::Le,
|
||||
BinOp::Ne => rustc_middle::mir::BinOp::Ne,
|
||||
BinOp::Ge => rustc_middle::mir::BinOp::Ge,
|
||||
BinOp::Gt => rustc_middle::mir::BinOp::Gt,
|
||||
BinOp::Cmp => rustc_middle::mir::BinOp::Cmp,
|
||||
BinOp::Offset => rustc_middle::mir::BinOp::Offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> RustcInternal for &T
|
||||
where
|
||||
T: RustcInternal,
|
||||
|
|
|
@ -19,7 +19,7 @@ use stable_mir::abi::{FnAbi, Layout, LayoutShape};
|
|||
use stable_mir::compiler_interface::Context;
|
||||
use stable_mir::mir::alloc::GlobalAlloc;
|
||||
use stable_mir::mir::mono::{InstanceDef, StaticDef};
|
||||
use stable_mir::mir::{Body, Place};
|
||||
use stable_mir::mir::{BinOp, Body, Place};
|
||||
use stable_mir::target::{MachineInfo, MachineSize};
|
||||
use stable_mir::ty::{
|
||||
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef,
|
||||
|
@ -668,6 +668,15 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let tcx = tables.tcx;
|
||||
format!("{:?}", place.internal(&mut *tables, tcx))
|
||||
}
|
||||
|
||||
fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let tcx = tables.tcx;
|
||||
let rhs_internal = rhs.internal(&mut *tables, tcx);
|
||||
let lhs_internal = lhs.internal(&mut *tables, tcx);
|
||||
let ty = bin_op.internal(&mut *tables, tcx).ty(tcx, rhs_internal, lhs_internal);
|
||||
ty.stable(&mut *tables)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TablesWrapper<'tcx>(pub RefCell<Tables<'tcx>>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue