]> git.lizzy.rs Git - rust.git/commitdiff
Rustup to rustc 1.29.0-nightly (866a71325 2018-07-29)
authorbjorn3 <bjorn3@users.noreply.github.com>
Mon, 30 Jul 2018 14:57:40 +0000 (16:57 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Mon, 30 Jul 2018 14:57:40 +0000 (16:57 +0200)
Cargo.toml
src/abi.rs
src/base.rs
src/common.rs
src/constant.rs
src/lib.rs
src/pretty_clif.rs

index dc4f2d93fafc48cf088ce416b720b085fe8f291f..651fba4133ac78245e2771341acf0916cfbfe784 100644 (file)
@@ -1,7 +1,10 @@
+cargo-features = ["edition"]
+
 [package]
 name = "rustc_codegen_cranelift"
 version = "0.1.0"
 authors = ["bjorn3 <bjorn3@users.noreply.github.com>"]
+edition = "2018"
 
 [lib]
 crate-type = ["dylib"]
index 70af157e47c340ecddf2f2651addd5ea185f11f4..144ba167c5196366465adf0b236a8ce441d11a01 100644 (file)
@@ -3,7 +3,7 @@
 use rustc::hir;
 use rustc_target::spec::abi::Abi;
 
-use prelude::*;
+use crate::prelude::*;
 
 pub fn cton_sig_from_fn_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_ty: Ty<'tcx>) -> Signature {
     let sig = ty_fn_sig(tcx, fn_ty);
@@ -250,12 +250,12 @@ pub fn codegen_call<'a, 'tcx: 'a>(
     args: &[Operand<'tcx>],
     destination: &Option<(Place<'tcx>, BasicBlock)>,
 ) {
-    let func = ::base::trans_operand(fx, func);
+    let func = trans_operand(fx, func);
     let fn_ty = func.layout().ty;
     let sig = ty_fn_sig(fx.tcx, fn_ty);
 
     let return_place = if let Some((place, _)) = destination {
-        Some(::base::trans_place(fx, place))
+        Some(trans_place(fx, place))
     } else {
         None
     };
@@ -263,8 +263,8 @@ pub fn codegen_call<'a, 'tcx: 'a>(
     // Unpack arguments tuple for closures
     let args = if sig.abi == Abi::RustCall {
         assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
-        let self_arg = ::base::trans_operand(fx, &args[0]);
-        let pack_arg = ::base::trans_operand(fx, &args[1]);
+        let self_arg = trans_operand(fx, &args[0]);
+        let pack_arg = trans_operand(fx, &args[1]);
         let mut args = Vec::new();
         args.push(self_arg);
         match pack_arg.layout().ty.sty {
@@ -281,7 +281,7 @@ pub fn codegen_call<'a, 'tcx: 'a>(
         args
             .into_iter()
             .map(|arg| {
-                ::base::trans_operand(fx, arg)
+                trans_operand(fx, arg)
             })
             .collect::<Vec<_>>()
     };
@@ -319,7 +319,7 @@ pub fn codegen_call<'a, 'tcx: 'a>(
                 }
                 "discriminant_value" => {
                     assert_eq!(args.len(), 1);
-                    let discr = ::base::trans_get_discriminant(fx, args[0], ret.layout());
+                    let discr = crate::base::trans_get_discriminant(fx, args[0], ret.layout());
                     ret.write_cvalue(fx, discr);
                 }
                 "size_of" => {
@@ -351,10 +351,10 @@ pub fn codegen_call<'a, 'tcx: 'a>(
                     };
                     let res = match ret.layout().ty.sty {
                         TypeVariants::TyUint(_) => {
-                            ::base::trans_int_binop(fx, bin_op, args[0], args[1], ret.layout().ty, false, false)
+                            crate::base::trans_int_binop(fx, bin_op, args[0], args[1], ret.layout().ty, false, false)
                         }
                         TypeVariants::TyInt(_) => {
-                            ::base::trans_int_binop(fx, bin_op, args[0], args[1], ret.layout().ty, true, false)
+                            crate::base::trans_int_binop(fx, bin_op, args[0], args[1], ret.layout().ty, true, false)
                         }
                         _ => panic!(),
                     };
index 104b948f148435aa6fb813f96bfbc4a3d2022f12..dbb562e4e5ae7dde4e930800ffe85ee38079dfbf 100644 (file)
@@ -1,4 +1,4 @@
-use prelude::*;
+use crate::prelude::*;
 
 pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend>, context: &mut Context, mono_item: MonoItem<'tcx>) {
     let tcx = cx.tcx;
@@ -33,7 +33,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend
 
                 let mut f = Function::with_name_signature(ExternalName::user(0, func_id.index() as u32), sig);
 
-                let comments = match ::base::trans_fn(cx, &mut f, inst){
+                let comments = match trans_fn(cx, &mut f, inst){
                     Ok(comments) => comments,
                     Err(err) => {
                         tcx.sess.err(&err);
@@ -41,7 +41,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend
                     }
                 };
 
-                let mut writer = ::pretty_clif::CommentWriter(comments);
+                let mut writer = crate::pretty_clif::CommentWriter(comments);
                 let mut cton = String::new();
                 ::cranelift::codegen::write::decorate_function(&mut writer, &mut cton, &f, None).unwrap();
                 tcx.sess.warn(&cton);
@@ -99,7 +99,7 @@ pub fn trans_fn<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend>, f: &
     };
     let fx = &mut fx;
 
-    ::abi::codegen_fn_prelude(fx, start_ebb);
+    crate::abi::codegen_fn_prelude(fx, start_ebb);
 
     fx.bcx.ins().jump(*fx.ebb_map.get(&START_BLOCK).unwrap(), &[]);
 
@@ -143,13 +143,13 @@ pub fn trans_fn<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend>, f: &
                     let ebb = fx.get_ebb(targets[i]);
                     jt_data.set_entry(*value as usize, ebb);
                 }
-                let mut jump_table = fx.bcx.create_jump_table(jt_data);
+                let jump_table = fx.bcx.create_jump_table(jt_data);
                 fx.bcx.ins().br_table(discr, jump_table);
                 let otherwise_ebb = fx.get_ebb(targets[targets.len() - 1]);
                 fx.bcx.ins().jump(otherwise_ebb, &[]);
             }
             TerminatorKind::Call { func, args, destination, cleanup: _ } => {
-                ::abi::codegen_call(fx, func, args, destination);
+                crate::abi::codegen_call(fx, func, args, destination);
             }
             TerminatorKind::Resume | TerminatorKind::Abort | TerminatorKind::Unreachable => {
                 fx.bcx.ins().trap(TrapCode::User(!0));
@@ -319,13 +319,13 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: &
                         (TypeVariants::TyUint(_), TypeVariants::TyInt(_)) |
                         (TypeVariants::TyUint(_), TypeVariants::TyUint(_)) => {
                             let from = operand.load_value(fx);
-                            let res = ::common::cton_intcast(fx, from, from_ty, to_ty, false);
+                            let res = crate::common::cton_intcast(fx, from, from_ty, to_ty, false);
                             lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
                         }
                         (TypeVariants::TyInt(_), TypeVariants::TyInt(_)) |
                         (TypeVariants::TyInt(_), TypeVariants::TyUint(_)) => {
                             let from = operand.load_value(fx);
-                            let res = ::common::cton_intcast(fx, from, from_ty, to_ty, true);
+                            let res = crate::common::cton_intcast(fx, from, from_ty, to_ty, true);
                             lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
                         }
                         _ => return Err(format!("rval misc {:?} {:?}", operand, to_ty)),
@@ -602,6 +602,7 @@ fn trans_ptr_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, l
 pub fn trans_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, place: &Place<'tcx>) -> CPlace<'tcx> {
     match place {
         Place::Local(local) => fx.get_local_place(*local),
+        Place::Promoted(promoted) => crate::constant::trans_promoted(fx, promoted.0),
         Place::Static(static_) => unimplemented!("static place {:?} ty {:?}", static_.def_id, static_.ty),
         Place::Projection(projection) => {
             let base = trans_place(fx, &projection.base);
@@ -632,7 +633,7 @@ pub fn trans_operand<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx>, operand: &Operand<
             cplace.to_cvalue(fx)
         },
         Operand::Constant(const_) => {
-            ::constant::trans_constant(fx, const_)
+            crate::constant::trans_constant(fx, const_)
         }
     }
 }
index ba84b2d64611af4101a638b5bc5ccb72bcbfe21f..2ef9d1d6772cce3a301fd9be18ea2767fe4763e4 100644 (file)
@@ -4,7 +4,7 @@
 
 use cranelift_module::{Module, FuncId, DataId};
 
-use prelude::*;
+use crate::prelude::*;
 
 pub type CurrentBackend = ::cranelift_simplejit::SimpleJITBackend;
 
@@ -313,7 +313,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         writeln!(f, "{:?}", self.local_map)?;
 
         let mut clif = String::new();
-        let mut writer = ::pretty_clif::CommentWriter(self.comments.clone());
+        let mut writer = crate::pretty_clif::CommentWriter(self.comments.clone());
         ::cranelift::codegen::write::decorate_function(
             &mut writer,
             &mut clif,
index 60fe341927135570842ac365cd088ead4b7b954f..5520a77bad3594993cb6f677a5bb2013d45ebf18 100644 (file)
@@ -1,21 +1,30 @@
-use prelude::*;
+use crate::prelude::*;
+use rustc::ty::Const;
 use rustc::mir::interpret::{ConstValue, GlobalId, AllocId, read_target_uint};
 use rustc_mir::interpret::{CompileTimeEvaluator, Memory, MemoryKind};
 use cranelift_module::*;
 
-pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &Constant<'tcx>) -> CValue<'tcx> {
-    let const_val = match const_.literal {
-        Literal::Value { value } => fx.monomorphize(&value),
-        Literal::Promoted { index } => fx
-            .tcx
-            .const_eval(ParamEnv::reveal_all().and(GlobalId {
-                instance: fx.instance,
-                promoted: Some(index),
-            }))
-            .unwrap(),
-    };
-
-    let const_ = match const_val.val {
+pub fn trans_promoted<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, promoted: Promoted) -> CPlace<'tcx> {
+    let const_ = fx
+        .tcx
+        .const_eval(ParamEnv::reveal_all().and(GlobalId {
+            instance: fx.instance,
+            promoted: Some(promoted),
+        }))
+        .unwrap();
+
+    let const_ = force_eval_const(fx, const_);
+    trans_const_place(fx, const_)
+}
+
+pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, constant: &Constant<'tcx>) -> CValue<'tcx> {
+    let const_ = fx.monomorphize(&constant.literal);
+    let const_ = force_eval_const(fx, const_);
+    trans_const_value(fx, const_)
+}
+
+fn force_eval_const<'a, 'tcx: 'a>(fx: &FunctionCx<'a, 'tcx>, const_: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
+    match const_.val {
         ConstValue::Unevaluated(def_id, ref substs) => {
             let param_env = ParamEnv::reveal_all();
             let instance = Instance::resolve(fx.tcx, param_env, def_id, substs).unwrap();
@@ -25,11 +34,11 @@ pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &Cons
             };
             fx.tcx.const_eval(param_env.and(cid)).unwrap()
         },
-        _ => const_val,
-    };
-
-    fx.tcx.sess.warn(&format!("const_val: {:?} const_: {:?}", const_val, const_));
+        _ => const_,
+    }
+}
 
+fn trans_const_value<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &'tcx Const<'tcx>) -> CValue<'tcx> {
     let ty = fx.monomorphize(&const_.ty);
     let layout = fx.layout_of(ty);
     match ty.sty {
@@ -50,24 +59,30 @@ pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &Cons
             CValue::Func(func_ref, layout)
         }
         _ => {
-            if true {
-                // TODO: cranelift-module api seems to be used wrong,
-                // thus causing panics for some consts, so this disables it
-                return CValue::ByRef(fx.bcx.ins().iconst(types::I64, 0), layout);
-            }
-            let mut memory = Memory::<CompileTimeEvaluator>::new(fx.tcx.at(DUMMY_SP), ());
-            let alloc = fx.tcx.const_value_to_allocation(const_);
-            //println!("const value: {:?} allocation: {:?}", value, alloc);
-            let alloc_id = memory.allocate_value(alloc.clone(), MemoryKind::Stack).unwrap();
-            let data_id = get_global_for_alloc_id(fx, &memory, alloc_id);
-            let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
-            // TODO: does global_value return a ptr of a val?
-            let global_ptr = fx.bcx.ins().global_value(types::I64, local_data_id);
-            CValue::ByRef(global_ptr, layout)
+            trans_const_place(fx, const_).to_cvalue(fx)
         }
     }
 }
 
+fn trans_const_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &'tcx Const<'tcx>) -> CPlace<'tcx> {
+    let ty = fx.monomorphize(&const_.ty);
+    let layout = fx.layout_of(ty);
+    if true {
+        // TODO: cranelift-module api seems to be used wrong,
+        // thus causing panics for some consts, so this disables it
+        return CPlace::Addr(fx.bcx.ins().iconst(types::I64, 0), layout);
+    }
+    let mut memory = Memory::<CompileTimeEvaluator>::new(fx.tcx.at(DUMMY_SP), ());
+    let alloc = fx.tcx.const_value_to_allocation(const_);
+    //println!("const value: {:?} allocation: {:?}", value, alloc);
+    let alloc_id = memory.allocate_value(alloc.clone(), MemoryKind::Stack).unwrap();
+    let data_id = get_global_for_alloc_id(fx, &memory, alloc_id);
+    let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+    // TODO: does global_value return a ptr of a val?
+    let global_ptr = fx.bcx.ins().global_value(types::I64, local_data_id);
+    CPlace::Addr(global_ptr, layout)
+}
+
 // If ret.1 is true, then the global didn't exist before
 fn define_global_for_alloc_id(fx: &mut FunctionCx, alloc_id: AllocId, todo: &mut HashMap<AllocId, DataId>) -> (DataId, bool) {
     use std::collections::hash_map::Entry;
index c26b7cd19473fb1a317e53c3466cd16e209dfe8f..e69c1625f3fb75eb544f2e1ac1c82877ffa64384 100644 (file)
@@ -76,14 +76,15 @@ mod prelude {
     pub use cranelift_module::{Module, Backend, DataContext, FuncId, DataId, Linkage, Writability};
     pub use cranelift_simplejit::{SimpleJITBuilder, SimpleJITBackend};
 
-    pub use abi::*;
-    pub use common::Variable;
-    pub use common::*;
+    pub use crate::abi::*;
+    pub use crate::common::Variable;
+    pub use crate::common::*;
+    pub use crate::base::{trans_operand, trans_place};
 
-    pub use CodegenCx;
+    pub use crate::CodegenCx;
 }
 
-use prelude::*;
+use crate::prelude::*;
 
 pub struct CodegenCx<'a, 'tcx: 'a, B: Backend + 'a> {
     pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -279,7 +280,7 @@ fn codegen_crate<'a, 'tcx>(
                 .unwrap()
         );
 
-        Box::new(::OngoingCodegen {
+        Box::new(OngoingCodegen {
             product: translated_module.finish(),
             metadata: metadata.raw_data,
             crate_name: tcx.crate_name(LOCAL_CRATE),
index 5c38f8af11924f1b0e580711ed7bcd822b97165c..51c170375613e62048d3d536954987b270d23dfb 100644 (file)
@@ -4,7 +4,7 @@
 
 use cranelift::codegen::write::{FuncWriter, PlainWriter};
 
-use prelude::*;
+use crate::prelude::*;
 
 pub struct CommentWriter(pub HashMap<Inst, String>);