]> git.lizzy.rs Git - rust.git/commitdiff
[MIR] Implement calling of closures and add missing monomorphization when translating...
authorMichael Woerister <michaelwoerister@posteo.net>
Tue, 5 Jan 2016 17:29:50 +0000 (12:29 -0500)
committerMichael Woerister <michaelwoerister@posteo.net>
Tue, 5 Jan 2016 17:50:46 +0000 (12:50 -0500)
src/librustc_trans/trans/mir/constant.rs
src/librustc_trans/trans/mir/did.rs

index 12839df87b159d4ce86e55535ada1679986caa67..0f4a0407298c8da5a071226262017d4321fb7786 100644 (file)
@@ -89,8 +89,10 @@ pub fn trans_constant(&mut self,
     {
         let ty = bcx.monomorphize(&constant.ty);
         match constant.literal {
-            mir::Literal::Item { def_id, kind, substs } =>
-                self.trans_item_ref(bcx, ty, kind, substs, def_id),
+            mir::Literal::Item { def_id, kind, substs } => {
+                let substs = bcx.tcx().mk_substs(bcx.monomorphize(&substs));
+                self.trans_item_ref(bcx, ty, kind, substs, def_id)
+            }
             mir::Literal::Value { ref value } => {
                 self.trans_constval(bcx, value, ty)
             }
index d4a7a7c8b48ff3234be80857dfae5c084e39d550..737c3dace2efe138e3d8b5fa0d6a2e2db5c4ec90 100644 (file)
@@ -21,6 +21,7 @@
 use rustc::mir::repr::ItemKind;
 use trans::common::{Block, fulfill_obligation};
 use trans::base;
+use trans::closure;
 use trans::expr;
 use trans::monomorphize;
 use trans::meth;
@@ -38,6 +39,9 @@ pub fn trans_item_ref(&mut self,
                           substs: &'tcx Substs<'tcx>,
                           did: DefId)
                           -> OperandRef<'tcx> {
+        debug!("trans_item_ref(ty={:?}, kind={:?}, substs={:?}, did={})",
+            ty, kind, substs, bcx.tcx().item_path_str(did));
+
         match kind {
             ItemKind::Function => self.trans_fn_ref(bcx, ty, substs, did),
             ItemKind::Method => match bcx.tcx().impl_or_trait_item(did).container() {
@@ -68,6 +72,9 @@ pub fn trans_fn_ref(&mut self,
                         substs: &'tcx Substs<'tcx>,
                         did: DefId)
                         -> OperandRef<'tcx> {
+        debug!("trans_fn_ref(ty={:?}, substs={:?}, did={})",
+            ty, substs, bcx.tcx().item_path_str(did));
+
         let did = inline::maybe_instantiate_inline(bcx.ccx(), did);
 
         if !substs.types.is_empty() || is_named_tuple_constructor(bcx.tcx(), did) {
@@ -101,9 +108,14 @@ pub fn trans_static_method(&mut self,
                                trait_id: DefId,
                                substs: &'tcx Substs<'tcx>)
                                -> OperandRef<'tcx> {
+        debug!("trans_static_method(ty={:?}, method={}, trait={}, substs={:?})",
+                ty,
+                bcx.tcx().item_path_str(method_id),
+                bcx.tcx().item_path_str(trait_id),
+                substs);
+
         let ccx = bcx.ccx();
         let tcx = bcx.tcx();
-        let mname = tcx.item_name(method_id);
         let subst::SeparateVecsPerParamSpace {
             types: rcvr_type,
             selfs: rcvr_self,
@@ -118,6 +130,9 @@ pub fn trans_static_method(&mut self,
         match vtbl {
             traits::VtableImpl(traits::VtableImplData { impl_def_id, substs: imp_substs, .. }) => {
                 assert!(!imp_substs.types.needs_infer());
+
+                let mname = tcx.item_name(method_id);
+
                 let subst::SeparateVecsPerParamSpace {
                     types: impl_type,
                     selfs: impl_self,
@@ -130,6 +145,17 @@ pub fn trans_static_method(&mut self,
                 let mthsubsts = tcx.mk_substs(mth.substs);
                 self.trans_fn_ref(bcx, ty, mthsubsts, mth.method.def_id)
             },
+            traits::VtableClosure(data) => {
+                let trait_closure_kind = bcx.tcx().lang_items.fn_trait_kind(trait_id).unwrap();
+                let llfn = closure::trans_closure_method(bcx.ccx(),
+                                                         data.closure_def_id,
+                                                         data.substs,
+                                                         trait_closure_kind);
+                OperandRef {
+                    ty: ty,
+                    val: OperandValue::Immediate(llfn)
+                }
+            },
             traits::VtableObject(ref data) => {
                 let idx = traits::get_vtable_index_of_object_method(tcx, data, method_id);
                 OperandRef::from_rvalue_datum(