Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`. Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all. However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish... ``@oli-obk`` any ideas?
This commit is contained in:
commit
208f6ed95c
76 changed files with 461 additions and 493 deletions
|
@ -14,8 +14,8 @@ use crate::stable_mir::ty::{
|
|||
};
|
||||
use crate::stable_mir::{self, CompilerError, Context};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{alloc_range, AllocId};
|
||||
use rustc_middle::mir::{self, ConstantKind};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
|
||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_span::ErrorGuaranteed;
|
||||
|
@ -539,14 +539,14 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for mir::Constant<'tcx> {
|
||||
impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
|
||||
type T = stable_mir::mir::Constant;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
stable_mir::mir::Constant {
|
||||
span: self.span.stable(tables),
|
||||
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
|
||||
literal: self.literal.stable(tables),
|
||||
literal: self.const_.stable(tables),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1247,13 +1247,13 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
|
||||
impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> {
|
||||
type T = stable_mir::ty::Const;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
match *self {
|
||||
ConstantKind::Ty(c) => c.stable(tables),
|
||||
ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
|
||||
mir::Const::Ty(c) => c.stable(tables),
|
||||
mir::Const::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
|
||||
literal: stable_mir::ty::ConstantKind::Unevaluated(
|
||||
stable_mir::ty::UnevaluatedConst {
|
||||
def: tables.const_def(unev_const.def),
|
||||
|
@ -1263,7 +1263,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
|
|||
),
|
||||
ty: tables.intern_ty(ty),
|
||||
},
|
||||
ConstantKind::Val(val, ty) => stable_mir::ty::Const {
|
||||
mir::Const::Val(val, ty) => stable_mir::ty::Const {
|
||||
literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
|
||||
ty, val, tables,
|
||||
)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue