Skip to content

don't const eval constants during MIR creation #34657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,19 +700,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
ref sty => bug!("unexpected sty: {:?}", sty)
},
Def::Const(def_id) |
Def::AssociatedConst(def_id) => {
let substs = Some(cx.tcx.node_id_item_substs(expr.id).substs);
let tcx = cx.tcx.global_tcx();
if let Some((e, _)) = const_eval::lookup_const_by_id(tcx, def_id, substs) {
// FIXME ConstVal can't be yet used with adjustments, as they would be lost.
if !cx.tcx.tables.borrow().adjustments.contains_key(&e.id) {
if let Some(v) = cx.try_const_eval_literal(e) {
return ExprKind::Literal { literal: v };
}
}
}
def_id
}
Def::AssociatedConst(def_id) => def_id,

Def::Static(node_id, _) => return ExprKind::StaticRef {
id: node_id,
Expand Down
15 changes: 0 additions & 15 deletions src/librustc_mir/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
}
}

pub fn try_const_eval_literal(&mut self, e: &hir::Expr) -> Option<Literal<'tcx>> {
let hint = const_eval::EvalHint::ExprTypeChecked;
let tcx = self.tcx.global_tcx();
const_eval::eval_const_expr_partial(tcx, e, hint, None).ok().and_then(|v| {
match v {
// All of these contain local IDs, unsuitable for storing in MIR.
ConstVal::Struct(_) | ConstVal::Tuple(_) |
ConstVal::Array(..) | ConstVal::Repeat(..) |
ConstVal::Function(_) => None,

_ => Some(Literal::Value { value: v })
}
})
}

pub fn trait_method(&mut self,
trait_def_id: DefId,
method_name: &str,
Expand Down