]> git.lizzy.rs Git - rust.git/commitdiff
Let the translation item collector make a distinction between drop-glue kinds
authorMichael Woerister <michaelwoerister@posteo.net>
Thu, 21 Apr 2016 19:36:57 +0000 (15:36 -0400)
committerMichael Woerister <michaelwoerister@posteo.net>
Thu, 28 Apr 2016 18:36:34 +0000 (14:36 -0400)
src/librustc_trans/collector.rs
src/librustc_trans/glue.rs
src/librustc_trans/partitioning.rs
src/test/codegen-units/item-collection/generic-drop-glue.rs
src/test/codegen-units/item-collection/non-generic-drop-glue.rs
src/test/codegen-units/item-collection/transitive-drop-glue.rs
src/test/codegen-units/item-collection/tuple-drop-glue.rs
src/test/codegen-units/partitioning/extern-drop-glue.rs
src/test/codegen-units/partitioning/local-drop-glue.rs

index e8437393625dbe37fb4bf9638bcd40c294ef3a8f..3dbcd8c05be3eb03c77d2edf1431c0dd471c8c1d 100644 (file)
 use context::CrateContext;
 use common::{fulfill_obligation, normalize_and_test_predicates,
                     type_is_sized};
-use glue;
+use glue::{self, DropGlueKind};
 use llvm;
 use meth;
 use monomorphize::{self, Instance};
@@ -227,7 +227,7 @@ pub enum TransItemCollectionMode {
 
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 pub enum TransItem<'tcx> {
-    DropGlue(Ty<'tcx>),
+    DropGlue(DropGlueKind<'tcx>),
     Fn(Instance<'tcx>),
     Static(NodeId)
 }
@@ -326,7 +326,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
             let def_id = ccx.tcx().map.local_def_id(node_id);
             let ty = ccx.tcx().lookup_item_type(def_id).ty;
             let ty = glue::get_drop_glue_type(ccx, ty);
-            neighbors.push(TransItem::DropGlue(ty));
+            neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
             recursion_depth_reset = None;
         }
         TransItem::Fn(instance) => {
@@ -485,7 +485,7 @@ fn visit_lvalue(&mut self,
                                                       &ty);
             let ty = self.ccx.tcx().erase_regions(&ty);
             let ty = glue::get_drop_glue_type(self.ccx, ty);
-            self.output.push(TransItem::DropGlue(ty));
+            self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
         }
 
         self.super_lvalue(lvalue, context);
@@ -575,9 +575,17 @@ fn can_have_local_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 }
 
 fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-                                      ty: ty::Ty<'tcx>,
-                                      output: &mut Vec<TransItem<'tcx>>)
-{
+                                      dg: DropGlueKind<'tcx>,
+                                      output: &mut Vec<TransItem<'tcx>>) {
+    let ty = match dg {
+        DropGlueKind::Ty(ty) => ty,
+        DropGlueKind::TyContents(_) => {
+            // We already collected the neighbors of this item via the
+            // DropGlueKind::Ty variant.
+            return
+        }
+    };
+
     debug!("find_drop_glue_neighbors: {}", type_to_string(ccx, ty));
 
     // Make sure the exchange_free_fn() lang-item gets translated if
@@ -634,6 +642,10 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                                   &Substs::empty());
             output.push(trans_item);
         }
+
+        // This type has a Drop implementation, we'll need the contents-only
+        // version of the glue too.
+        output.push(TransItem::DropGlue(DropGlueKind::TyContents(ty)));
     }
 
     // Finally add the types of nested values
@@ -661,7 +673,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                 let field_type = glue::get_drop_glue_type(ccx, field_type);
 
                 if glue::type_needs_drop(ccx.tcx(), field_type) {
-                    output.push(TransItem::DropGlue(field_type));
+                    output.push(TransItem::DropGlue(DropGlueKind::Ty(field_type)));
                 }
             }
         }
@@ -669,7 +681,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             for upvar_ty in &substs.upvar_tys {
                 let upvar_ty = glue::get_drop_glue_type(ccx, upvar_ty);
                 if glue::type_needs_drop(ccx.tcx(), upvar_ty) {
-                    output.push(TransItem::DropGlue(upvar_ty));
+                    output.push(TransItem::DropGlue(DropGlueKind::Ty(upvar_ty)));
                 }
             }
         }
@@ -677,14 +689,14 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         ty::TyArray(inner_type, _) => {
             let inner_type = glue::get_drop_glue_type(ccx, inner_type);
             if glue::type_needs_drop(ccx.tcx(), inner_type) {
-                output.push(TransItem::DropGlue(inner_type));
+                output.push(TransItem::DropGlue(DropGlueKind::Ty(inner_type)));
             }
         }
         ty::TyTuple(ref args) => {
             for arg in args {
                 let arg = glue::get_drop_glue_type(ccx, arg);
                 if glue::type_needs_drop(ccx.tcx(), arg) {
-                    output.push(TransItem::DropGlue(arg));
+                    output.push(TransItem::DropGlue(DropGlueKind::Ty(arg)));
                 }
             }
         }
@@ -1000,7 +1012,7 @@ fn visit_item(&mut self, item: &'v hir::Item) {
                                                 self.ccx.tcx().map.local_def_id(item.id)));
 
                         let ty = glue::get_drop_glue_type(self.ccx, ty);
-                        self.output.push(TransItem::DropGlue(ty));
+                        self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
                     }
                 }
             }
@@ -1413,10 +1425,13 @@ pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
         let hir_map = &ccx.tcx().map;
 
         return match *self {
-            TransItem::DropGlue(t) => {
+            TransItem::DropGlue(dg) => {
                 let mut s = String::with_capacity(32);
-                s.push_str("drop-glue ");
-                push_unique_type_name(ccx, t, &mut s);
+                match dg {
+                    DropGlueKind::Ty(_) => s.push_str("drop-glue "),
+                    DropGlueKind::TyContents(_) => s.push_str("drop-glue-contents "),
+                };
+                push_unique_type_name(ccx, dg.ty(), &mut s);
                 s
             }
             TransItem::Fn(instance) => {
@@ -1442,8 +1457,8 @@ fn to_string_internal<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 
     fn to_raw_string(&self) -> String {
         match *self {
-            TransItem::DropGlue(t) => {
-                format!("DropGlue({})", t as *const _ as usize)
+            TransItem::DropGlue(dg) => {
+                format!("DropGlue({})", dg.ty() as *const _ as usize)
             }
             TransItem::Fn(instance) => {
                 format!("Fn({:?}, {})",
index 39ea25619eed01de7e355f03eeeb3fc70522be64..06761a7016add15a5dbd03da7d12a13c456a8e53 100644 (file)
@@ -98,7 +98,7 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     // Even if there is no dtor for t, there might be one deeper down and we
     // might need to pass in the vtable ptr.
     if !type_is_sized(tcx, t) {
-        return t
+        return ccx.tcx().erase_regions(&t);
     }
 
     // FIXME (#22815): note that type_needs_drop conservatively
@@ -121,10 +121,10 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             if llsize_of_alloc(ccx, llty) == 0 {
                 tcx.types.i8
             } else {
-                t
+                ccx.tcx().erase_regions(&t)
             }
         }
-        _ => t
+        _ => ccx.tcx().erase_regions(&t)
     }
 }
 
@@ -215,11 +215,11 @@ pub enum DropGlueKind<'tcx> {
 }
 
 impl<'tcx> DropGlueKind<'tcx> {
-    fn ty(&self) -> Ty<'tcx> {
+    pub fn ty(&self) -> Ty<'tcx> {
         match *self { DropGlueKind::Ty(t) | DropGlueKind::TyContents(t) => t }
     }
 
-    fn map_ty<F>(&self, mut f: F) -> DropGlueKind<'tcx> where F: FnMut(Ty<'tcx>) -> Ty<'tcx>
+    pub fn map_ty<F>(&self, mut f: F) -> DropGlueKind<'tcx> where F: FnMut(Ty<'tcx>) -> Ty<'tcx>
     {
         match *self {
             DropGlueKind::Ty(t) => DropGlueKind::Ty(f(t)),
@@ -487,14 +487,13 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
 
 fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueKind<'tcx>)
                               -> Block<'blk, 'tcx> {
-    let t = g.ty();
-
     if collector::collecting_debug_information(bcx.ccx()) {
         bcx.ccx()
-           .record_translation_item_as_generated(TransItem::DropGlue(bcx.tcx()
-                                                                        .erase_regions(&t)));
+           .record_translation_item_as_generated(TransItem::DropGlue(g));
     }
 
+    let t = g.ty();
+
     let skip_dtor = match g { DropGlueKind::Ty(_) => false, DropGlueKind::TyContents(_) => true };
     // NB: v0 is an *alias* of type t here, not a direct value.
     let _icx = push_ctxt("make_drop_glue");
index f2198c0e490f618f2a090a24f9c2298a5e861f97..d482814961fbc726d4a7036d3db3bfb91d75bf01 100644 (file)
@@ -304,7 +304,7 @@ fn characteristic_def_id_of_trans_item<'tcx>(tcx: &TyCtxt<'tcx>,
 
             Some(instance.def)
         }
-        TransItem::DropGlue(t) => characteristic_def_id_of_type(t),
+        TransItem::DropGlue(dg) => characteristic_def_id_of_type(dg.ty()),
         TransItem::Static(node_id) => Some(tcx.map.local_def_id(node_id)),
     }
 }
index 476c84044e68656390521693be220ecbab4c461e..6da8154540574f9cc73616d7fa7520bc26a5f2f6 100644 (file)
@@ -46,19 +46,22 @@ enum EnumNoDrop<T1, T2> {
 
 struct NonGenericWithDrop(i32);
 //~ TRANS_ITEM drop-glue generic_drop_glue::NonGenericWithDrop[0]
+//~ TRANS_ITEM drop-glue-contents generic_drop_glue::NonGenericWithDrop[0]
 
 impl Drop for NonGenericWithDrop {
+    //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
     fn drop(&mut self) {}
-//~ TRANS_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
 }
 
 //~ TRANS_ITEM fn generic_drop_glue::main[0]
 fn main() {
     //~ TRANS_ITEM drop-glue generic_drop_glue::StructWithDrop[0]<i8, char>
+    //~ TRANS_ITEM drop-glue-contents generic_drop_glue::StructWithDrop[0]<i8, char>
     //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<i8, char>
     let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
 
     //~ TRANS_ITEM drop-glue generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
+    //~ TRANS_ITEM drop-glue-contents generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
     //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
     let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
 
@@ -71,6 +74,7 @@ fn main() {
     let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
 
     //~ TRANS_ITEM drop-glue generic_drop_glue::EnumWithDrop[0]<i32, i64>
+    //~ TRANS_ITEM drop-glue-contents generic_drop_glue::EnumWithDrop[0]<i32, i64>
     //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<i32, i64>
     let _ = match EnumWithDrop::A::<i32, i64>(0) {
         EnumWithDrop::A(x) => x,
@@ -78,6 +82,7 @@ fn main() {
     };
 
     //~ TRANS_ITEM drop-glue generic_drop_glue::EnumWithDrop[0]<f64, f32>
+    //~ TRANS_ITEM drop-glue-contents generic_drop_glue::EnumWithDrop[0]<f64, f32>
     //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<f64, f32>
     let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
         EnumWithDrop::A(x) => x,
index bd8b0c605aecf8b96a48a468c35acb04a57de1ff..91be81a0b8996ab81dd806deef1a102cec6e8d5b 100644 (file)
@@ -14,6 +14,7 @@
 #![deny(dead_code)]
 
 //~ TRANS_ITEM drop-glue non_generic_drop_glue::StructWithDrop[0]
+//~ TRANS_ITEM drop-glue-contents non_generic_drop_glue::StructWithDrop[0]
 struct StructWithDrop {
     x: i32
 }
@@ -28,6 +29,7 @@ struct StructNoDrop {
 }
 
 //~ TRANS_ITEM drop-glue non_generic_drop_glue::EnumWithDrop[0]
+//~ TRANS_ITEM drop-glue-contents non_generic_drop_glue::EnumWithDrop[0]
 enum EnumWithDrop {
     A(i32)
 }
index 21bb29199a685715ba4832ed0b35e071c6610c78..81a7059fe209f4c7099fd167c600b97bc91270b0 100644 (file)
@@ -18,6 +18,7 @@
 //~ TRANS_ITEM drop-glue transitive_drop_glue::Intermediate[0]
 struct Intermediate(Leaf);
 //~ TRANS_ITEM drop-glue transitive_drop_glue::Leaf[0]
+//~ TRANS_ITEM drop-glue-contents transitive_drop_glue::Leaf[0]
 struct Leaf;
 
 impl Drop for Leaf {
@@ -25,11 +26,8 @@ impl Drop for Leaf {
     fn drop(&mut self) {}
 }
 
-//~ TRANS_ITEM drop-glue transitive_drop_glue::Root[0]
 struct RootGen<T>(IntermediateGen<T>);
-//~ TRANS_ITEM drop-glue transitive_drop_glue::Root[0]
 struct IntermediateGen<T>(LeafGen<T>);
-//~ TRANS_ITEM drop-glue transitive_drop_glue::Root[0]
 struct LeafGen<T>(T);
 
 impl<T> Drop for LeafGen<T> {
@@ -44,12 +42,14 @@ fn main() {
     //~ TRANS_ITEM drop-glue transitive_drop_glue::RootGen[0]<u32>
     //~ TRANS_ITEM drop-glue transitive_drop_glue::IntermediateGen[0]<u32>
     //~ TRANS_ITEM drop-glue transitive_drop_glue::LeafGen[0]<u32>
+    //~ TRANS_ITEM drop-glue-contents transitive_drop_glue::LeafGen[0]<u32>
     //~ TRANS_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<u32>
     let _ = RootGen(IntermediateGen(LeafGen(0u32)));
 
     //~ TRANS_ITEM drop-glue transitive_drop_glue::RootGen[0]<i16>
     //~ TRANS_ITEM drop-glue transitive_drop_glue::IntermediateGen[0]<i16>
     //~ TRANS_ITEM drop-glue transitive_drop_glue::LeafGen[0]<i16>
+    //~ TRANS_ITEM drop-glue-contents transitive_drop_glue::LeafGen[0]<i16>
     //~ TRANS_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<i16>
     let _ = RootGen(IntermediateGen(LeafGen(0i16)));
 }
index 1bc235de88e1f603c33b3222ddb6b496b0d97081..ef4bc1dca594cc6174d0aa355841df65cbb2e987 100644 (file)
@@ -14,6 +14,7 @@
 #![deny(dead_code)]
 
 //~ TRANS_ITEM drop-glue tuple_drop_glue::Dropped[0]
+//~ TRANS_ITEM drop-glue-contents tuple_drop_glue::Dropped[0]
 struct Dropped;
 
 impl Drop for Dropped {
index ddf5f461aef0943bf20c7ccb452f0041fa0311cf..bd57a09fadd349eb992078508ce455110d2b05e2 100644 (file)
@@ -18,6 +18,7 @@
 extern crate cgu_extern_drop_glue;
 
 //~ TRANS_ITEM drop-glue cgu_extern_drop_glue::Struct[0] @@ extern_drop_glue[OnceODR] extern_drop_glue-mod1[OnceODR]
+//~ TRANS_ITEM drop-glue-contents cgu_extern_drop_glue::Struct[0] @@ extern_drop_glue[OnceODR] extern_drop_glue-mod1[OnceODR]
 
 struct LocalStruct(cgu_extern_drop_glue::Struct);
 
@@ -40,4 +41,3 @@ fn user()
         let _ = LocalStruct(cgu_extern_drop_glue::Struct(0));
     }
 }
-
index 0c500bb64f8db928878bc99e48d3005438aa4a69..a42a34a0766b71fb2b1dd2ef063b1e1a266708f7 100644 (file)
@@ -15,6 +15,7 @@
 #![crate_type="lib"]
 
 //~ TRANS_ITEM drop-glue local_drop_glue::Struct[0] @@ local_drop_glue[OnceODR] local_drop_glue-mod1[OnceODR]
+//~ TRANS_ITEM drop-glue-contents local_drop_glue::Struct[0] @@ local_drop_glue[OnceODR] local_drop_glue-mod1[OnceODR]
 struct Struct {
     _a: u32
 }