rustc: use ConstVal::Unevaluated instead of mir::Literal::Item.
This commit is contained in:
parent
74349fa288
commit
57ebd28fdb
8 changed files with 33 additions and 50 deletions
|
|
@ -493,10 +493,6 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for mir::L
|
|||
hasher: &mut StableHasher<W>) {
|
||||
mem::discriminant(self).hash_stable(hcx, hasher);
|
||||
match *self {
|
||||
mir::Literal::Item { def_id, substs } => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::Literal::Value { ref value } => {
|
||||
value.hash_stable(hcx, hasher);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1479,10 +1479,6 @@ newtype_index!(Promoted, "promoted");
|
|||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum Literal<'tcx> {
|
||||
Item {
|
||||
def_id: DefId,
|
||||
substs: &'tcx Substs<'tcx>,
|
||||
},
|
||||
Value {
|
||||
value: &'tcx ty::Const<'tcx>,
|
||||
},
|
||||
|
|
@ -1502,9 +1498,6 @@ impl<'tcx> Debug for Literal<'tcx> {
|
|||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
use self::Literal::*;
|
||||
match *self {
|
||||
Item { def_id, substs } => {
|
||||
ppaux::parameterized(fmt, substs, def_id, &[])
|
||||
}
|
||||
Value { value } => {
|
||||
write!(fmt, "const ")?;
|
||||
fmt_const_val(fmt, &value.val)
|
||||
|
|
@ -2002,17 +1995,16 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
|||
impl<'tcx> TypeFoldable<'tcx> for Literal<'tcx> {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
Literal::Item { def_id, substs } => Literal::Item {
|
||||
def_id,
|
||||
substs: substs.fold_with(folder)
|
||||
Literal::Value { value } => Literal::Value {
|
||||
value: value.fold_with(folder)
|
||||
},
|
||||
_ => self.clone()
|
||||
Literal::Promoted { index } => Literal::Promoted { index }
|
||||
}
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
match *self {
|
||||
Literal::Item { substs, .. } => substs.visit_with(visitor),
|
||||
_ => false
|
||||
Literal::Value { value } => value.visit_with(visitor),
|
||||
Literal::Promoted { .. } => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -724,11 +724,6 @@ macro_rules! make_mir_visitor {
|
|||
literal: & $($mutability)* Literal<'tcx>,
|
||||
location: Location) {
|
||||
match *literal {
|
||||
Literal::Item { ref $($mutability)* def_id,
|
||||
ref $($mutability)* substs } => {
|
||||
self.visit_def_id(def_id, location);
|
||||
self.visit_substs(substs, location);
|
||||
}
|
||||
Literal::Value { ref $($mutability)* value } => {
|
||||
self.visit_const(value, location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -643,9 +643,11 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||
|
||||
Def::Const(def_id) |
|
||||
Def::AssociatedConst(def_id) => ExprKind::Literal {
|
||||
literal: Literal::Item {
|
||||
def_id,
|
||||
substs,
|
||||
literal: Literal::Value {
|
||||
value: cx.tcx.mk_const(ty::Const {
|
||||
val: ConstVal::Unevaluated(def_id, substs),
|
||||
ty: cx.tables().node_id_to_type(expr.hir_id)
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
|||
use rustc::hir;
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
use rustc::traits::{self, Reveal};
|
||||
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
|
||||
use rustc::ty::cast::CastTy;
|
||||
|
|
@ -622,10 +623,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
Operand::Constant(ref constant) => {
|
||||
if let Literal::Item { def_id, substs: _ } = constant.literal {
|
||||
if let Literal::Value {
|
||||
value: &ty::Const { val: ConstVal::Unevaluated(def_id, _), ty }
|
||||
} = constant.literal {
|
||||
// Don't peek inside trait associated constants.
|
||||
if self.tcx.trait_of_item(def_id).is_some() {
|
||||
self.add_type(constant.ty);
|
||||
self.add_type(ty);
|
||||
} else {
|
||||
let (bits, _) = self.tcx.at(constant.span).mir_const_qualif(def_id);
|
||||
|
||||
|
|
@ -635,7 +638,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
// Just in case the type is more specific than
|
||||
// the definition, e.g. impl associated const
|
||||
// with type parameters, take it into account.
|
||||
self.qualif.restrict(constant.ty, self.tcx, self.param_env);
|
||||
self.qualif.restrict(ty, self.tcx, self.param_env);
|
||||
}
|
||||
|
||||
// Let `const fn` transitively have destructors,
|
||||
|
|
|
|||
|
|
@ -235,7 +235,6 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
|
|||
location: Location) {
|
||||
self.record("Literal", literal);
|
||||
self.record(match *literal {
|
||||
Literal::Item { .. } => "Literal::Item",
|
||||
Literal::Value { .. } => "Literal::Value",
|
||||
Literal::Promoted { .. } => "Literal::Promoted",
|
||||
}, literal);
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
|||
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
use rustc::middle::lang_items::{ExchangeMallocFnLangItem};
|
||||
use rustc::traits;
|
||||
use rustc::ty::subst::Substs;
|
||||
|
|
@ -564,24 +565,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||
self.super_rvalue(rvalue, location);
|
||||
}
|
||||
|
||||
fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) {
|
||||
debug!("visiting constant {:?} @ {:?}", *constant, location);
|
||||
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, location: Location) {
|
||||
debug!("visiting const {:?} @ {:?}", *constant, location);
|
||||
|
||||
if let ty::TyFnDef(..) = constant.ty.sty {
|
||||
// function definitions are zero-sized, and only generate
|
||||
// IR when they are called/reified.
|
||||
self.super_constant(constant, location);
|
||||
return
|
||||
}
|
||||
|
||||
if let mir::Literal::Item { def_id, substs } = constant.literal {
|
||||
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
|
||||
let substs = self.scx.tcx().trans_apply_param_substs(self.param_substs,
|
||||
&substs);
|
||||
let instance = monomorphize::resolve(self.scx, def_id, substs);
|
||||
collect_neighbours(self.scx, instance, true, self.output);
|
||||
}
|
||||
|
||||
self.super_constant(constant, location);
|
||||
self.super_const(constant);
|
||||
}
|
||||
|
||||
fn visit_terminator_kind(&mut self,
|
||||
|
|
|
|||
|
|
@ -510,16 +510,17 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
mir::Operand::Constant(ref constant) => {
|
||||
let ty = self.monomorphize(&constant.ty);
|
||||
match constant.literal.clone() {
|
||||
mir::Literal::Item { def_id, substs } => {
|
||||
let substs = self.monomorphize(&substs);
|
||||
MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new())
|
||||
}
|
||||
mir::Literal::Promoted { index } => {
|
||||
let mir = &self.mir.promoted[index];
|
||||
MirConstContext::new(self.ccx, mir, self.substs, IndexVec::new()).trans()
|
||||
}
|
||||
mir::Literal::Value { value } => {
|
||||
Ok(Const::from_constval(self.ccx, &value.val, ty))
|
||||
if let ConstVal::Unevaluated(def_id, substs) = value.val {
|
||||
let substs = self.monomorphize(&substs);
|
||||
MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new())
|
||||
} else {
|
||||
Ok(Const::from_constval(self.ccx, &value.val, ty))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -960,16 +961,17 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
debug!("trans_constant({:?})", constant);
|
||||
let ty = self.monomorphize(&constant.ty);
|
||||
let result = match constant.literal.clone() {
|
||||
mir::Literal::Item { def_id, substs } => {
|
||||
let substs = self.monomorphize(&substs);
|
||||
MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new())
|
||||
}
|
||||
mir::Literal::Promoted { index } => {
|
||||
let mir = &self.mir.promoted[index];
|
||||
MirConstContext::new(bcx.ccx, mir, self.param_substs, IndexVec::new()).trans()
|
||||
}
|
||||
mir::Literal::Value { value } => {
|
||||
Ok(Const::from_constval(bcx.ccx, &value.val, ty))
|
||||
if let ConstVal::Unevaluated(def_id, substs) = value.val {
|
||||
let substs = self.monomorphize(&substs);
|
||||
MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new())
|
||||
} else {
|
||||
Ok(Const::from_constval(bcx.ccx, &value.val, ty))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue