Adjust imports to librustc::mir::interpret

This commit is contained in:
Oliver Schneider 2017-09-18 16:18:23 +02:00
parent df5e122eda
commit ea35192d7c
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
21 changed files with 209 additions and 102 deletions

20
src/Cargo.lock generated
View file

@ -174,6 +174,11 @@ dependencies = [
"filetime 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "byteorder"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "cargo" name = "cargo"
version = "0.23.0" version = "0.23.0"
@ -888,6 +893,14 @@ name = "log"
version = "0.3.8" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log_settings"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "lzma-sys" name = "lzma-sys"
version = "0.1.9" version = "0.1.9"
@ -1430,13 +1443,18 @@ name = "rustc"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"arena 0.0.0", "arena 0.0.0",
"backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"fmt_macros 0.0.0", "fmt_macros 0.0.0",
"graphviz 0.0.0", "graphviz 0.0.0",
"jobserver 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "jobserver 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_back 0.0.0", "rustc_back 0.0.0",
"rustc_const_math 0.0.0", "rustc_const_math 0.0.0",
"rustc_data_structures 0.0.0", "rustc_data_structures 0.0.0",
@ -2489,6 +2507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989" "checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"
"checksum bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f382711e76b9de6c744cc00d0497baba02fb00a787f088c879f01d09468e32" "checksum bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f382711e76b9de6c744cc00d0497baba02fb00a787f088c879f01d09468e32"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7db2f146208d7e0fbee761b09cd65a7f51ccc38705d4e7262dad4d73b12a76b1" "checksum cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7db2f146208d7e0fbee761b09cd65a7f51ccc38705d4e7262dad4d73b12a76b1"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2" "checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2"
@ -2547,6 +2566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0db4ec23611747ef772db1c4d650f8bd762f07b461727ec998f953c614024b75" "checksum libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0db4ec23611747ef772db1c4d650f8bd762f07b461727ec998f953c614024b75"
"checksum libz-sys 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "44ebbc760fd2d2f4d93de09a0e13d97e057612052e871da9985cedcb451e6bd5" "checksum libz-sys 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "44ebbc760fd2d2f4d93de09a0e13d97e057612052e871da9985cedcb451e6bd5"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6"
"checksum lzma-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c1b93b78f89e8737dac81837fc8f5521ac162abcba902e1a3db949d55346d1da" "checksum lzma-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c1b93b78f89e8737dac81837fc8f5521ac162abcba902e1a3db949d55346d1da"
"checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" "checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527"

View file

@ -23,6 +23,12 @@ rustc_errors = { path = "../librustc_errors" }
serialize = { path = "../libserialize" } serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" } syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" } syntax_pos = { path = "../libsyntax_pos" }
log_settings = "0.1.1"
lazy_static = "0.2.8"
regex = "0.2.2"
backtrace = "0.3.3"
byteorder = { version = "1.1", features = ["i128"]}
# Note that these dependencies are a lie, they're just here to get linkage to # Note that these dependencies are a lie, they're just here to get linkage to
# work. # work.

View file

@ -54,6 +54,7 @@
#![feature(specialization)] #![feature(specialization)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(trace_macros)] #![feature(trace_macros)]
#![feature(catch_expr)]
#![feature(test)] #![feature(test)]
#![cfg_attr(stage0, feature(const_fn))] #![cfg_attr(stage0, feature(const_fn))]
@ -82,6 +83,13 @@ extern crate jobserver;
extern crate serialize as rustc_serialize; // used by deriving extern crate serialize as rustc_serialize; // used by deriving
extern crate log_settings;
extern crate byteorder;
#[macro_use]
extern crate lazy_static;
extern crate regex;
extern crate backtrace;
// Note that librustc doesn't actually depend on these crates, see the note in // Note that librustc doesn't actually depend on these crates, see the note in
// `Cargo.toml` for this crate about why these are here. // `Cargo.toml` for this crate about why these are here.
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]

View file

@ -1,4 +1,4 @@
use rustc::ty::{self, Ty}; use ty::{self, Ty};
use syntax::ast::{FloatTy, IntTy, UintTy}; use syntax::ast::{FloatTy, IntTy, UintTy};
use super::{PrimVal, EvalContext, EvalResult, MemoryPointer, PointerArithmetic, Machine}; use super::{PrimVal, EvalContext, EvalResult, MemoryPointer, PointerArithmetic, Machine};
@ -72,7 +72,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
negative: bool, negative: bool,
) -> EvalResult<'tcx, PrimVal> { ) -> EvalResult<'tcx, PrimVal> {
trace!("cast_from_int: {}, {}, {}", v, ty, negative); trace!("cast_from_int: {}, {}, {}", v, ty, negative);
use rustc::ty::TypeVariants::*; use ty::TypeVariants::*;
match ty.sty { match ty.sty {
// Casts to bool are not permitted by rustc, no need to handle them here. // Casts to bool are not permitted by rustc, no need to handle them here.
TyInt(ty) => Ok(PrimVal::Bytes(self.int_to_int(v as i128, ty))), TyInt(ty) => Ok(PrimVal::Bytes(self.int_to_int(v as i128, ty))),
@ -94,7 +94,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
fn cast_from_float(&self, val: f64, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> { fn cast_from_float(&self, val: f64, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
use rustc::ty::TypeVariants::*; use ty::TypeVariants::*;
match ty.sty { match ty.sty {
// Casting negative floats to unsigned integers yields zero. // Casting negative floats to unsigned integers yields zero.
TyUint(_) if val < 0.0 => self.cast_from_int(0, ty, false), TyUint(_) if val < 0.0 => self.cast_from_int(0, ty, false),
@ -109,7 +109,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
fn cast_from_ptr(&self, ptr: MemoryPointer, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> { fn cast_from_ptr(&self, ptr: MemoryPointer, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
use rustc::ty::TypeVariants::*; use ty::TypeVariants::*;
match ty.sty { match ty.sty {
// Casting to a reference or fn pointer is not permitted by rustc, no need to support it here. // Casting to a reference or fn pointer is not permitted by rustc, no need to support it here.
TyRawPtr(_) | TyRawPtr(_) |

View file

@ -1,6 +1,6 @@
use rustc::traits::Reveal; use traits::Reveal;
use rustc::ty::{self, TyCtxt, Ty, Instance, layout}; use ty::{self, TyCtxt, Ty, Instance, layout};
use rustc::mir; use mir;
use syntax::ast::Mutability; use syntax::ast::Mutability;
use syntax::codemap::Span; use syntax::codemap::Span;
@ -83,7 +83,7 @@ pub fn eval_body_as_integer<'a, 'tcx>(
let (prim, ty) = eval_body_as_primval(tcx, instance)?; let (prim, ty) = eval_body_as_primval(tcx, instance)?;
let prim = prim.to_bytes()?; let prim = prim.to_bytes()?;
use syntax::ast::{IntTy, UintTy}; use syntax::ast::{IntTy, UintTy};
use rustc::ty::TypeVariants::*; use ty::TypeVariants::*;
use rustc_const_math::{ConstIsize, ConstUsize}; use rustc_const_math::{ConstIsize, ConstUsize};
Ok(match ty.sty { Ok(match ty.sty {
TyInt(IntTy::I8) => ConstInt::I8(prim as i128 as i8), TyInt(IntTy::I8) => ConstInt::I8(prim as i128 as i8),

View file

@ -1,8 +1,8 @@
use std::error::Error; use std::error::Error;
use std::{fmt, env}; use std::{fmt, env};
use rustc::mir; use mir;
use rustc::ty::{FnSig, Ty, layout}; use ty::{FnSig, Ty, layout};
use super::{ use super::{
MemoryPointer, Lock, AccessKind MemoryPointer, Lock, AccessKind

View file

@ -1,15 +1,15 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fmt::Write; use std::fmt::Write;
use rustc::hir::def_id::DefId; use hir::def_id::DefId;
use rustc::hir::map::definitions::DefPathData; use hir::map::definitions::DefPathData;
use rustc::middle::const_val::ConstVal; use middle::const_val::ConstVal;
use rustc::middle::region; use middle::region;
use rustc::mir; use mir;
use rustc::traits::Reveal; use traits::Reveal;
use rustc::ty::layout::{self, Layout, Size, Align, HasDataLayout}; use ty::layout::{self, Layout, Size, Align, HasDataLayout};
use rustc::ty::subst::{Subst, Substs, Kind}; use ty::subst::{Subst, Substs, Kind};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use syntax::codemap::{self, DUMMY_SP}; use syntax::codemap::{self, DUMMY_SP};
use syntax::ast::Mutability; use syntax::ast::Mutability;
@ -227,7 +227,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
pub(super) fn const_to_value(&mut self, const_val: &ConstVal<'tcx>) -> EvalResult<'tcx, Value> { pub(super) fn const_to_value(&mut self, const_val: &ConstVal<'tcx>) -> EvalResult<'tcx, Value> {
use rustc::middle::const_val::ConstVal::*; use middle::const_val::ConstVal::*;
let primval = match *const_val { let primval = match *const_val {
Integral(const_int) => PrimVal::Bytes(const_int.to_u128_unchecked()), Integral(const_int) => PrimVal::Bytes(const_int.to_u128_unchecked()),
@ -467,7 +467,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
/// Return the set of locals that have a storage annotation anywhere /// Return the set of locals that have a storage annotation anywhere
fn collect_storage_annotations<'tcx>(mir: &'tcx mir::Mir<'tcx>) -> HashSet<mir::Local> { fn collect_storage_annotations<'tcx>(mir: &'tcx mir::Mir<'tcx>) -> HashSet<mir::Local> {
use rustc::mir::StatementKind::*; use mir::StatementKind::*;
let mut set = HashSet::new(); let mut set = HashSet::new();
for block in mir.basic_blocks() { for block in mir.basic_blocks() {
@ -634,7 +634,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let dest_ty = self.lvalue_ty(lvalue); let dest_ty = self.lvalue_ty(lvalue);
let dest_layout = self.type_layout(dest_ty)?; let dest_layout = self.type_layout(dest_ty)?;
use rustc::mir::Rvalue::*; use mir::Rvalue::*;
match *rvalue { match *rvalue {
Use(ref operand) => { Use(ref operand) => {
let value = self.eval_operand(operand)?.value; let value = self.eval_operand(operand)?.value;
@ -692,7 +692,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
Aggregate(ref kind, ref operands) => { Aggregate(ref kind, ref operands) => {
self.inc_step_counter_and_check_limit(operands.len() as u64)?; self.inc_step_counter_and_check_limit(operands.len() as u64)?;
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *dest_layout { match *dest_layout {
Univariant { ref variant, .. } => { Univariant { ref variant, .. } => {
self.write_maybe_aligned_mut(!variant.packed, |ecx| { self.write_maybe_aligned_mut(!variant.packed, |ecx| {
@ -893,7 +893,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
Cast(kind, ref operand, cast_ty) => { Cast(kind, ref operand, cast_ty) => {
debug_assert_eq!(self.monomorphize(cast_ty, self.substs()), dest_ty); debug_assert_eq!(self.monomorphize(cast_ty, self.substs()), dest_ty);
use rustc::mir::CastKind::*; use mir::CastKind::*;
match kind { match kind {
Unsize => { Unsize => {
let src = self.eval_operand(operand)?; let src = self.eval_operand(operand)?;
@ -1122,7 +1122,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
packed: false, packed: false,
}), }),
ty::TyAdt(adt_def, substs) if adt_def.is_enum() => { ty::TyAdt(adt_def, substs) if adt_def.is_enum() => {
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *self.type_layout(ty)? { match *self.type_layout(ty)? {
RawNullablePointer { nndiscr, .. } => Ok(TyAndPacked { RawNullablePointer { nndiscr, .. } => Ok(TyAndPacked {
ty: adt_def.variants[nndiscr as usize].fields[field_index].ty( ty: adt_def.variants[nndiscr as usize].fields[field_index].ty(
@ -1161,7 +1161,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
ty::TyAdt(adt_def, substs) => { ty::TyAdt(adt_def, substs) => {
let variant_def = adt_def.struct_variant(); let variant_def = adt_def.struct_variant();
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *self.type_layout(ty)? { match *self.type_layout(ty)? {
UntaggedUnion { ref variants } => Ok(TyAndPacked { UntaggedUnion { ref variants } => Ok(TyAndPacked {
ty: variant_def.fields[field_index].ty(self.tcx, substs), ty: variant_def.fields[field_index].ty(self.tcx, substs),
@ -1214,7 +1214,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
// Also see lvalue_field in lvalue.rs, which handles more cases but needs an actual value at the given type // Also see lvalue_field in lvalue.rs, which handles more cases but needs an actual value at the given type
let layout = self.type_layout(ty)?; let layout = self.type_layout(ty)?;
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *layout { match *layout {
Univariant { ref variant, .. } => Ok(variant.offsets[field_index]), Univariant { ref variant, .. } => Ok(variant.offsets[field_index]),
FatPointer { .. } => { FatPointer { .. } => {
@ -1239,7 +1239,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
pub fn get_field_count(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, u64> { pub fn get_field_count(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, u64> {
let layout = self.type_layout(ty)?; let layout = self.type_layout(ty)?;
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *layout { match *layout {
Univariant { ref variant, .. } => Ok(variant.offsets.len() as u64), Univariant { ref variant, .. } => Ok(variant.offsets.len() as u64),
FatPointer { .. } => Ok(2), FatPointer { .. } => Ok(2),
@ -1277,7 +1277,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
pub fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, ValTy<'tcx>> { pub fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, ValTy<'tcx>> {
use rustc::mir::Operand::*; use mir::Operand::*;
match *op { match *op {
Consume(ref lvalue) => { Consume(ref lvalue) => {
Ok(ValTy { Ok(ValTy {
@ -1287,7 +1287,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
}, },
Constant(ref constant) => { Constant(ref constant) => {
use rustc::mir::Literal; use mir::Literal;
let mir::Constant { ref literal, .. } = **constant; let mir::Constant { ref literal, .. } = **constant;
let value = match *literal { let value = match *literal {
Literal::Value { ref value } => self.const_to_value(&value.val)?, Literal::Value { ref value } => self.const_to_value(&value.val)?,
@ -1314,7 +1314,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
adt_ptr: MemoryPointer, adt_ptr: MemoryPointer,
adt_ty: Ty<'tcx>, adt_ty: Ty<'tcx>,
) -> EvalResult<'tcx, u128> { ) -> EvalResult<'tcx, u128> {
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
let adt_layout = self.type_layout(adt_ty)?; let adt_layout = self.type_layout(adt_ty)?;
//trace!("read_discriminant_value {:#?}", adt_layout); //trace!("read_discriminant_value {:#?}", adt_layout);
@ -1418,7 +1418,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
pub fn is_packed(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, bool> { pub fn is_packed(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, bool> {
let layout = self.type_layout(ty)?; let layout = self.type_layout(ty)?;
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
Ok(match *layout { Ok(match *layout {
Univariant { ref variant, .. } => variant.packed, Univariant { ref variant, .. } => variant.packed,
@ -1719,7 +1719,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
ty::TyAdt(def, _) if def.is_box() => PrimValKind::Ptr, ty::TyAdt(def, _) if def.is_box() => PrimValKind::Ptr,
ty::TyAdt(def, substs) => { ty::TyAdt(def, substs) => {
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
match *self.type_layout(ty)? { match *self.type_layout(ty)? {
CEnum { discr, signed, .. } => { CEnum { discr, signed, .. } => {
let size = discr.size().bytes(); let size = discr.size().bytes();
@ -1731,7 +1731,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
RawNullablePointer { value, .. } => { RawNullablePointer { value, .. } => {
use rustc::ty::layout::Primitive::*; use ty::layout::Primitive::*;
match value { match value {
// TODO(solson): Does signedness matter here? What should the sign be? // TODO(solson): Does signedness matter here? What should the sign be?
Int(int) => PrimValKind::from_uint_size(int.size().bytes()), Int(int) => PrimValKind::from_uint_size(int.size().bytes()),
@ -1867,7 +1867,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
if def.is_box() { if def.is_box() {
return self.read_ptr(ptr, ty.boxed_ty()).map(Some); return self.read_ptr(ptr, ty.boxed_ty()).map(Some);
} }
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
if let CEnum { discr, signed, .. } = *self.type_layout(ty)? { if let CEnum { discr, signed, .. } = *self.type_layout(ty)? {
let size = discr.size().bytes(); let size = discr.size().bytes();
self.memory.read_primval(ptr, size, signed)? self.memory.read_primval(ptr, size, signed)?
@ -2225,7 +2225,7 @@ pub(super) trait IntegerExt {
impl IntegerExt for layout::Integer { impl IntegerExt for layout::Integer {
fn size(self) -> Size { fn size(self) -> Size {
use rustc::ty::layout::Integer::*; use ty::layout::Integer::*;
match self { match self {
I1 | I8 => Size::from_bits(8), I1 | I8 => Size::from_bits(8),
I16 => Size::from_bits(16), I16 => Size::from_bits(16),
@ -2416,19 +2416,19 @@ fn resolve_associated_item<'a, 'tcx>(
// Now that we know which impl is being used, we can dispatch to // Now that we know which impl is being used, we can dispatch to
// the actual function: // the actual function:
match vtbl { match vtbl {
::rustc::traits::VtableImpl(impl_data) => { ::traits::VtableImpl(impl_data) => {
let (def_id, substs) = let (def_id, substs) =
::rustc::traits::find_associated_item(tcx, trait_item, rcvr_substs, &impl_data); ::traits::find_associated_item(tcx, trait_item, rcvr_substs, &impl_data);
let substs = tcx.erase_regions(&substs); let substs = tcx.erase_regions(&substs);
ty::Instance::new(def_id, substs) ty::Instance::new(def_id, substs)
} }
::rustc::traits::VtableGenerator(closure_data) => { ::traits::VtableGenerator(closure_data) => {
ty::Instance { ty::Instance {
def: ty::InstanceDef::Item(closure_data.closure_def_id), def: ty::InstanceDef::Item(closure_data.closure_def_id),
substs: closure_data.substs.substs substs: closure_data.substs.substs
} }
} }
::rustc::traits::VtableClosure(closure_data) => { ::traits::VtableClosure(closure_data) => {
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap(); let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
resolve_closure( resolve_closure(
tcx, tcx,
@ -2437,20 +2437,20 @@ fn resolve_associated_item<'a, 'tcx>(
trait_closure_kind, trait_closure_kind,
) )
} }
::rustc::traits::VtableFnPointer(ref data) => { ::traits::VtableFnPointer(ref data) => {
ty::Instance { ty::Instance {
def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty), def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty),
substs: rcvr_substs, substs: rcvr_substs,
} }
} }
::rustc::traits::VtableObject(ref data) => { ::traits::VtableObject(ref data) => {
let index = tcx.get_vtable_index_of_object_method(data, def_id); let index = tcx.get_vtable_index_of_object_method(data, def_id);
ty::Instance { ty::Instance {
def: ty::InstanceDef::Virtual(def_id, index), def: ty::InstanceDef::Virtual(def_id, index),
substs: rcvr_substs, substs: rcvr_substs,
} }
} }
::rustc::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items().clone_trait() => { ::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items().clone_trait() => {
ty::Instance { ty::Instance {
def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()), def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()),
substs: rcvr_substs substs: rcvr_substs
@ -2477,7 +2477,7 @@ pub fn apply_param_substs<'a, 'tcx, T>(
value: &T, value: &T,
) -> T ) -> T
where where
T: ::rustc::infer::TransNormalize<'tcx>, T: ::infer::TransNormalize<'tcx>,
{ {
debug!( debug!(
"apply_param_substs(param_substs={:?}, value={:?})", "apply_param_substs(param_substs={:?}, value={:?})",
@ -2504,7 +2504,7 @@ impl<'a, 'tcx> AssociatedTypeNormalizer<'a, 'tcx> {
} }
} }
impl<'a, 'tcx> ::rustc::ty::fold::TypeFolder<'tcx, 'tcx> for AssociatedTypeNormalizer<'a, 'tcx> { impl<'a, 'tcx> ::ty::fold::TypeFolder<'tcx, 'tcx> for AssociatedTypeNormalizer<'a, 'tcx> {
fn tcx<'c>(&'c self) -> TyCtxt<'c, 'tcx, 'tcx> { fn tcx<'c>(&'c self) -> TyCtxt<'c, 'tcx, 'tcx> {
self.tcx self.tcx
} }
@ -2528,7 +2528,7 @@ pub fn resolve_drop_in_place<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
) -> ty::Instance<'tcx> { ) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(::rustc::middle::lang_items::DropInPlaceFnLangItem); let def_id = tcx.require_lang_item(::middle::lang_items::DropInPlaceFnLangItem);
let substs = tcx.intern_substs(&[Kind::from(ty)]); let substs = tcx.intern_substs(&[Kind::from(ty)]);
resolve(tcx, def_id, substs) resolve(tcx, def_id, substs)
} }

View file

@ -1,6 +1,6 @@
use rustc::mir; use mir;
use rustc::ty::layout::{Size, Align}; use ty::layout::{Size, Align};
use rustc::ty::{self, Ty}; use ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use super::{EvalResult, EvalContext, MemoryPointer, PrimVal, Value, Pointer, Machine, PtrAndAlign, ValTy}; use super::{EvalResult, EvalContext, MemoryPointer, PrimVal, Value, Pointer, Machine, PtrAndAlign, ValTy};
@ -101,7 +101,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
&mut self, &mut self,
lvalue: &mir::Lvalue<'tcx>, lvalue: &mir::Lvalue<'tcx>,
) -> EvalResult<'tcx, Option<Value>> { ) -> EvalResult<'tcx, Option<Value>> {
use rustc::mir::Lvalue::*; use mir::Lvalue::*;
match *lvalue { match *lvalue {
// Might allow this in the future, right now there's no way to do this from Rust code anyway // Might allow this in the future, right now there's no way to do this from Rust code anyway
Local(mir::RETURN_POINTER) => err!(ReadFromReturnPointer), Local(mir::RETURN_POINTER) => err!(ReadFromReturnPointer),
@ -126,7 +126,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
&mut self, &mut self,
proj: &mir::LvalueProjection<'tcx>, proj: &mir::LvalueProjection<'tcx>,
) -> EvalResult<'tcx, Option<Value>> { ) -> EvalResult<'tcx, Option<Value>> {
use rustc::mir::ProjectionElem::*; use mir::ProjectionElem::*;
let base = match self.try_read_lvalue(&proj.base)? { let base = match self.try_read_lvalue(&proj.base)? {
Some(base) => base, Some(base) => base,
None => return Ok(None), None => return Ok(None),
@ -181,7 +181,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
pub fn eval_lvalue(&mut self, mir_lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue> { pub fn eval_lvalue(&mut self, mir_lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue> {
use rustc::mir::Lvalue::*; use mir::Lvalue::*;
let lvalue = match *mir_lvalue { let lvalue = match *mir_lvalue {
Local(mir::RETURN_POINTER) => self.frame().return_lvalue, Local(mir::RETURN_POINTER) => self.frame().return_lvalue,
Local(local) => Lvalue::Local { Local(local) => Lvalue::Local {
@ -222,7 +222,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
base_ty: Ty<'tcx>, base_ty: Ty<'tcx>,
field_ty: Ty<'tcx>, field_ty: Ty<'tcx>,
) -> EvalResult<'tcx, Lvalue> { ) -> EvalResult<'tcx, Lvalue> {
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
let base_layout = self.type_layout(base_ty)?; let base_layout = self.type_layout(base_ty)?;
let field_index = field.index(); let field_index = field.index();
@ -404,7 +404,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
base_ty: Ty<'tcx>, base_ty: Ty<'tcx>,
proj_elem: &mir::ProjectionElem<'tcx, mir::Local, Ty<'tcx>>, proj_elem: &mir::ProjectionElem<'tcx, mir::Local, Ty<'tcx>>,
) -> EvalResult<'tcx, Lvalue> { ) -> EvalResult<'tcx, Lvalue> {
use rustc::mir::ProjectionElem::*; use mir::ProjectionElem::*;
let (ptr, extra) = match *proj_elem { let (ptr, extra) = match *proj_elem {
Field(field, field_ty) => { Field(field, field_ty) => {
return self.lvalue_field(base, field, base_ty, field_ty); return self.lvalue_field(base, field, base_ty, field_ty);
@ -416,7 +416,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let base = self.force_allocation(base)?; let base = self.force_allocation(base)?;
let (base_ptr, base_extra) = base.to_ptr_extra_aligned(); let (base_ptr, base_extra) = base.to_ptr_extra_aligned();
use rustc::ty::layout::Layout::*; use ty::layout::Layout::*;
let extra = match *base_layout { let extra = match *base_layout {
General { .. } => LvalueExtra::DowncastVariant(variant), General { .. } => LvalueExtra::DowncastVariant(variant),
RawNullablePointer { .. } | RawNullablePointer { .. } |

View file

@ -4,7 +4,7 @@
use super::{EvalResult, EvalContext, Lvalue, PrimVal, ValTy}; use super::{EvalResult, EvalContext, Lvalue, PrimVal, ValTy};
use rustc::{mir, ty}; use {mir, ty};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ast::Mutability; use syntax::ast::Mutability;

View file

@ -3,10 +3,10 @@ use std::collections::{btree_map, BTreeMap, HashMap, HashSet, VecDeque};
use std::{fmt, iter, ptr, mem, io}; use std::{fmt, iter, ptr, mem, io};
use std::cell::Cell; use std::cell::Cell;
use rustc::ty::Instance; use ty::Instance;
use rustc::ty::layout::{self, TargetDataLayout, HasDataLayout}; use ty::layout::{self, TargetDataLayout, HasDataLayout};
use syntax::ast::Mutability; use syntax::ast::Mutability;
use rustc::middle::region; use middle::region;
use super::{EvalResult, EvalErrorKind, PrimVal, Pointer, EvalContext, DynamicLifetime, Machine, use super::{EvalResult, EvalErrorKind, PrimVal, Pointer, EvalContext, DynamicLifetime, Machine,
RangeMap, AbsLvalue}; RangeMap, AbsLvalue};

View file

@ -2,7 +2,7 @@
#[macro_export] #[macro_export]
macro_rules! err { macro_rules! err {
($($tt:tt)*) => { Err($crate::interpret::EvalErrorKind::$($tt)*.into()) }; ($($tt:tt)*) => { Err($crate::mir::interpret::EvalErrorKind::$($tt)*.into()) };
} }
mod cast; mod cast;

View file

@ -1,5 +1,5 @@
use rustc::mir; use mir;
use rustc::ty::Ty; use ty::Ty;
use rustc_const_math::ConstFloat; use rustc_const_math::ConstFloat;
use syntax::ast::FloatTy; use syntax::ast::FloatTy;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -116,7 +116,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
right: PrimVal, right: PrimVal,
right_ty: Ty<'tcx>, right_ty: Ty<'tcx>,
) -> EvalResult<'tcx, (PrimVal, bool)> { ) -> EvalResult<'tcx, (PrimVal, bool)> {
use rustc::mir::BinOp::*; use mir::BinOp::*;
use super::PrimValKind::*; use super::PrimValKind::*;
let left_kind = self.ty_to_primval_kind(left_ty)?; let left_kind = self.ty_to_primval_kind(left_ty)?;
@ -229,7 +229,7 @@ pub fn unary_op<'tcx>(
val: PrimVal, val: PrimVal,
val_kind: PrimValKind, val_kind: PrimValKind,
) -> EvalResult<'tcx, PrimVal> { ) -> EvalResult<'tcx, PrimVal> {
use rustc::mir::UnOp::*; use mir::UnOp::*;
use super::PrimValKind::*; use super::PrimValKind::*;
let bytes = val.to_bytes()?; let bytes = val.to_bytes()?;

View file

@ -2,15 +2,15 @@
//! //!
//! The main entry point is the `step` method. //! The main entry point is the `step` method.
use rustc::hir::def_id::DefId; use hir::def_id::DefId;
use rustc::hir; use hir;
use rustc::mir::visit::{Visitor, LvalueContext}; use mir::visit::{Visitor, LvalueContext};
use rustc::mir; use mir;
use rustc::traits::Reveal; use traits::Reveal;
use rustc::ty; use ty;
use rustc::ty::layout::Layout; use ty::layout::Layout;
use rustc::ty::subst::Substs; use ty::subst::Substs;
use rustc::middle::const_val::ConstVal; use middle::const_val::ConstVal;
use super::{EvalResult, EvalContext, StackPopCleanup, PtrAndAlign, GlobalId, Lvalue, use super::{EvalResult, EvalContext, StackPopCleanup, PtrAndAlign, GlobalId, Lvalue,
MemoryKind, Machine, PrimVal}; MemoryKind, Machine, PrimVal};
@ -91,7 +91,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> { fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> {
trace!("{:?}", stmt); trace!("{:?}", stmt);
use rustc::mir::StatementKind::*; use mir::StatementKind::*;
// Some statements (e.g. box) push new stack frames. We have to record the stack frame number // Some statements (e.g. box) push new stack frames. We have to record the stack frame number
// *before* executing the statement. // *before* executing the statement.

View file

@ -1,8 +1,8 @@
use rustc::mir::BasicBlock; use mir::BasicBlock;
use rustc::ty::{self, Ty}; use ty::{self, Ty};
use syntax::codemap::Span; use syntax::codemap::Span;
use interpret::{EvalResult, EvalContext, Lvalue, LvalueExtra, PrimVal, Value, use mir::interpret::{EvalResult, EvalContext, Lvalue, LvalueExtra, PrimVal, Value,
Machine, ValTy}; Machine, ValTy};
impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {

View file

@ -1,6 +1,6 @@
use rustc::mir; use mir;
use rustc::ty::{self, TypeVariants}; use ty::{self, TypeVariants};
use rustc::ty::layout::Layout; use ty::layout::Layout;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::abi::Abi; use syntax::abi::Abi;
@ -21,7 +21,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
&mut self, &mut self,
terminator: &mir::Terminator<'tcx>, terminator: &mir::Terminator<'tcx>,
) -> EvalResult<'tcx> { ) -> EvalResult<'tcx> {
use rustc::mir::TerminatorKind::*; use mir::TerminatorKind::*;
match terminator.kind { match terminator.kind {
Return => { Return => {
self.dump_local(self.frame().return_lvalue); self.dump_local(self.frame().return_lvalue);
@ -137,7 +137,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
if expected == cond_val { if expected == cond_val {
self.goto_block(target); self.goto_block(target);
} else { } else {
use rustc::mir::AssertMessage::*; use mir::AssertMessage::*;
return match *msg { return match *msg {
BoundsCheck { ref len, ref index } => { BoundsCheck { ref len, ref index } => {
let span = terminator.source_info.span; let span = terminator.source_info.span;

View file

@ -1,7 +1,7 @@
use rustc::traits::{self, Reveal}; use traits::{self, Reveal};
use rustc::hir::def_id::DefId; use hir::def_id::DefId;
use rustc::ty::subst::Substs; use ty::subst::Substs;
use rustc::ty::{self, Ty}; use ty::{self, Ty};
use syntax::codemap::DUMMY_SP; use syntax::codemap::DUMMY_SP;
use syntax::ast::{self, Mutability}; use syntax::ast::{self, Mutability};
@ -54,7 +54,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let align = self.type_align(trait_ref.self_ty())?; let align = self.type_align(trait_ref.self_ty())?;
let ptr_size = self.memory.pointer_size(); let ptr_size = self.memory.pointer_size();
let methods = ::rustc::traits::get_vtable_methods(self.tcx, trait_ref); let methods = ::traits::get_vtable_methods(self.tcx, trait_ref);
let vtable = self.memory.allocate( let vtable = self.memory.allocate(
ptr_size * (3 + methods.count() as u64), ptr_size * (3 + methods.count() as u64),
ptr_size, ptr_size,
@ -70,7 +70,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let align_ptr = vtable.offset(ptr_size * 2, &self)?; let align_ptr = vtable.offset(ptr_size * 2, &self)?;
self.memory.write_ptr_sized_unsigned(align_ptr, PrimVal::Bytes(align as u128))?; self.memory.write_ptr_sized_unsigned(align_ptr, PrimVal::Bytes(align as u128))?;
for (i, method) in ::rustc::traits::get_vtable_methods(self.tcx, trait_ref).enumerate() { for (i, method) in ::traits::get_vtable_methods(self.tcx, trait_ref).enumerate() {
if let Some((def_id, substs)) = method { if let Some((def_id, substs)) = method {
let instance = eval_context::resolve(self.tcx, def_id, substs); let instance = eval_context::resolve(self.tcx, def_id, substs);
let fn_ptr = self.memory.create_fn_alloc(instance); let fn_ptr = self.memory.create_fn_alloc(instance);

View file

@ -1,12 +1,12 @@
use rustc::hir::{self, Mutability}; use hir::{self, Mutability};
use rustc::hir::Mutability::*; use hir::Mutability::*;
use rustc::mir::{self, ValidationOp, ValidationOperand}; use mir::{self, ValidationOp, ValidationOperand};
use rustc::ty::{self, Ty, TypeFoldable, TyCtxt}; use ty::{self, Ty, TypeFoldable, TyCtxt};
use rustc::ty::subst::{Substs, Subst}; use ty::subst::{Substs, Subst};
use rustc::traits; use traits;
use rustc::infer::InferCtxt; use infer::InferCtxt;
use rustc::traits::Reveal; use traits::Reveal;
use rustc::middle::region; use middle::region;
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use super::{EvalError, EvalResult, EvalErrorKind, EvalContext, DynamicLifetime, AccessKind, Value, use super::{EvalError, EvalResult, EvalErrorKind, EvalContext, DynamicLifetime, AccessKind, Value,
@ -383,9 +383,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
mut query: ValidationQuery<'tcx>, mut query: ValidationQuery<'tcx>,
mode: ValidationMode, mode: ValidationMode,
) -> EvalResult<'tcx> { ) -> EvalResult<'tcx> {
use rustc::ty::TypeVariants::*; use ty::TypeVariants::*;
use rustc::ty::RegionKind::*; use ty::RegionKind::*;
use rustc::ty::AdtKind; use ty::AdtKind;
// No point releasing shared stuff. // No point releasing shared stuff.
if !mode.acquiring() && query.mutbl == MutImmutable { if !mode.acquiring() && query.mutbl == MutImmutable {

View file

@ -1,6 +1,6 @@
#![allow(unknown_lints)] #![allow(unknown_lints)]
use rustc::ty::layout::HasDataLayout; use ty::layout::HasDataLayout;
use super::{EvalResult, Memory, MemoryPointer, HasMemory, PointerArithmetic, Machine, PtrAndAlign}; use super::{EvalResult, Memory, MemoryPointer, HasMemory, PointerArithmetic, Machine, PtrAndAlign};

View file

@ -42,6 +42,7 @@ pub mod tcx;
pub mod visit; pub mod visit;
pub mod transform; pub mod transform;
pub mod traversal; pub mod traversal;
pub mod interpret;
macro_rules! newtype_index { macro_rules! newtype_index {
($name:ident, $debug_name:expr) => ( ($name:ident, $debug_name:expr) => (

View file

@ -791,5 +791,76 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} else { } else {
tcx.extern_const_body(def_id).body tcx.extern_const_body(def_id).body
}; };
ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value)
let instance = ty::Instance::new(def_id, substs);
let miri_result = ::rustc::interpret::eval_body_as_primval(tcx, instance);
let old_result = ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value);
match (miri_result, old_result) {
(Err(err), Ok(ok)) => {
warn!("miri fails to eval {:?} to {:?} with error {:?}", key, ok, err);
Ok(ok)
},
(Ok(ok), Err(err)) => {
info!("miri can eval {:?} to {:?}, while old ctfe fails with {:?}", key, ok, err);
Err(err)
},
(Err(_), Err(err)) => Err(err),
(Ok((miri_val, miri_ty)), Ok(ctfe)) => {
use rustc::ty::TypeVariants::*;
use rustc::interpret::PrimVal;
match (miri_val, &miri_ty.sty, ctfe.val) {
(PrimVal::Undef, _, _) => {
warn!("miri produced an undef, while old ctfe produced {:?}", ctfe);
},
(PrimVal::Ptr(_), _, _) => {
warn!("miri produced a pointer, which isn't implemented yet");
},
(PrimVal::Bytes(b), &TyInt(int_ty), ConstVal::Integral(ci)) => {
let c = ConstInt::new_signed_truncating(b as i128,
int_ty,
tcx.sess.target.isize_ty);
if c != ci {
warn!("miri evaluated to {}, but ctfe yielded {}", b as i128, ci);
}
}
(PrimVal::Bytes(b), &TyUint(int_ty), ConstVal::Integral(ci)) => {
let c = ConstInt::new_unsigned_truncating(b, int_ty, tcx.sess.target.usize_ty);
if c != ci {
warn!("miri evaluated to {}, but ctfe yielded {}", b, ci);
}
}
(PrimVal::Bytes(bits), &TyFloat(ty), ConstVal::Float(cf)) => {
let f = ConstFloat { bits, ty };
if f != cf {
warn!("miri evaluated to {}, but ctfe yielded {}", f, cf);
}
}
(PrimVal::Bytes(bits), &TyBool, ConstVal::Bool(b)) => {
if bits == 0 && b {
warn!("miri evaluated to {}, but ctfe yielded {}", bits == 0, b);
} else if bits == 1 && !b {
warn!("miri evaluated to {}, but ctfe yielded {}", bits == 1, b);
} else {
warn!("miri evaluated to {}, but expected a bool {}", bits, b);
}
}
(PrimVal::Bytes(bits), &TyChar, ConstVal::Char(c)) => {
if let Some(cm) = ::std::char::from_u32(bits as u32) {
if cm != c {
warn!("miri evaluated to {:?}, but expected {:?}", cm, c);
}
} else {
warn!("miri evaluated to {}, but expected a char {:?}", bits, c);
}
}
_ => {
info!("can't check whether miri's {:?} ({}) makes sense when ctfe yields {:?}",
miri_val,
miri_ty,
ctfe)
}
}
Ok(ctfe)
}
}
} }

View file

@ -66,6 +66,7 @@ fn filter_dirs(path: &Path) -> bool {
"src/tools/rust-installer", "src/tools/rust-installer",
"src/tools/rustfmt", "src/tools/rustfmt",
"src/tools/miri", "src/tools/miri",
"src/librustc/mir/interpret",
]; ];
skip.iter().any(|p| path.ends_with(p)) skip.iter().any(|p| path.ends_with(p))
} }