]> git.lizzy.rs Git - rust.git/commitdiff
Revert "librustc: Make monomorphic newtype structs work cross-crate"
authorGraydon Hoare <graydon@mozilla.com>
Tue, 12 Feb 2013 17:02:17 +0000 (09:02 -0800)
committerGraydon Hoare <graydon@mozilla.com>
Tue, 12 Feb 2013 17:02:17 +0000 (09:02 -0800)
This reverts commit a8f039a085c7d7622899b7a4d1bebfe2d7621165.

src/librustc/metadata/common.rs
src/librustc/metadata/csearch.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/resolve.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/reachable.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/coherence.rs
src/test/auxiliary/newtype_struct_xc.rs [deleted file]
src/test/run-pass/newtype-struct-xc.rs [deleted file]

index 62bfdf4c3aa1bd102194c52d475b930318728028..37c19e80600b7f9ddaf4d6debb68afc17cfb6bc1 100644 (file)
@@ -153,7 +153,5 @@ pub enum astencode_tag { // Reserves 0x50 -- 0x6f
 pub const tag_lang_items_item_id: uint = 0x74;
 pub const tag_lang_items_item_node_id: uint = 0x75;
 
-pub const tag_item_unnamed_field: uint = 0x76;
-
 pub type link_meta = {name: @str, vers: @str, extras_hash: @str};
 
index fa82e6c92c098ffdd78b47dff59fa5517c30e203..2cb5cfbddd73015a52fa878d740232ab2f866c24 100644 (file)
@@ -166,9 +166,8 @@ pub fn get_item_attrs(cstore: @mut cstore::CStore,
     decoder::get_item_attrs(cdata, def_id.node, f)
 }
 
-pub fn get_struct_fields(cstore: @mut cstore::CStore,
-                         def: ast::def_id)
-                      -> ~[ty::field_ty] {
+pub fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
+    let cstore = tcx.cstore;
     let cdata = cstore::get_crate_data(cstore, def.crate);
     decoder::get_struct_fields(cstore.intr, cdata, def.node)
 }
index 14dda96228206e7a21e9841fbbf822a72813a1be..67498ad5aafe6425babdac100d3b1202bbdac88f 100644 (file)
@@ -42,7 +42,7 @@
 use syntax::ast_map;
 use syntax::attr;
 use syntax::diagnostic::span_handler;
-use syntax::parse::token::{ident_interner, special_idents};
+use syntax::parse::token::ident_interner;
 use syntax::print::pprust;
 use syntax::{ast, ast_util};
 use syntax::codemap;
@@ -231,9 +231,7 @@ pub fn item_type(item_id: ast::def_id, item: ebml::Doc,
     let t = doc_type(item, tcx, cdata);
     if family_names_type(item_family(item)) {
         ty::mk_with_id(tcx, t, item_id)
-    } else {
-        t
-    }
+    } else { t }
 }
 
 fn item_impl_traits(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] {
@@ -663,12 +661,11 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
     rslt
 }
 
-pub fn get_impls_for_mod(intr: @ident_interner,
-                         cdata: cmd,
-                         m_id: ast::node_id,
-                         name: Option<ast::ident>,
-                         get_cdata: &fn(ast::crate_num) -> cmd)
+pub fn get_impls_for_mod(intr: @ident_interner, cdata: cmd,
+                         m_id: ast::node_id, name: Option<ast::ident>,
+                         get_cdata: fn(ast::crate_num) -> cmd)
                       -> @~[@_impl] {
+
     let data = cdata.data;
     let mod_item = lookup_item(m_id, data);
     let mut result = ~[];
@@ -890,15 +887,6 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
             });
         }
     }
-    for reader::tagged_docs(item, tag_item_unnamed_field) |an_item| {
-        let did = item_def_id(an_item, cdata);
-        result.push(ty::field_ty {
-            ident: special_idents::unnamed_field,
-            id: did,
-            vis: ast::inherited,
-            mutability: ast::struct_immutable,
-        });
-    }
     result
 }
 
index e6dcf17f34c98d68c0c0deb3d10ea509df26dde2..fcc1a4e806dffeefcc309557eba8f0a23b692a90 100644 (file)
@@ -46,7 +46,6 @@
 use syntax::ast_util::*;
 use syntax::attr;
 use syntax::diagnostic::span_handler;
-use syntax::parse::token::special_idents;
 use syntax::print::pprust;
 use syntax::{ast_util, visit};
 use syntax;
@@ -329,7 +328,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
     // Encode info about all the module children.
     for md.items.each |item| {
         match item.node {
-            item_impl(*) => {
+            item_impl(*) | item_struct(*) => {
                 let (ident, did) = (item.ident, item.id);
                 debug!("(encoding info for module) ... encoding impl %s \
                         (%?/%?)",
@@ -433,28 +432,25 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
      /* We encode both private and public fields -- need to include
         private fields to get the offsets right */
     for fields.each |field| {
-        let (nm, mt, vis) = match field.node.kind {
-            named_field(nm, mt, vis) => (nm, mt, vis),
-            unnamed_field => (
-                special_idents::unnamed_field,
-                struct_immutable,
-                inherited
-            )
-        };
-
-        let id = field.node.id;
-        index.push({val: id, pos: ebml_w.writer.tell()});
-        global_index.push({val: id, pos: ebml_w.writer.tell()});
-        ebml_w.start_tag(tag_items_data_item);
-        debug!("encode_info_for_struct: doing %s %d",
-               tcx.sess.str_of(nm), id);
-        encode_visibility(ebml_w, vis);
-        encode_name(ecx, ebml_w, nm);
-        encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
-        encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
-        encode_mutability(ebml_w, mt);
-        encode_def_id(ebml_w, local_def(id));
-        ebml_w.end_tag();
+        match field.node.kind {
+            named_field(nm, mt, vis) => {
+                let id = field.node.id;
+                index.push({val: id, pos: ebml_w.writer.tell()});
+                global_index.push({val: id,
+                                    pos: ebml_w.writer.tell()});
+                ebml_w.start_tag(tag_items_data_item);
+                debug!("encode_info_for_struct: doing %s %d",
+                       tcx.sess.str_of(nm), id);
+                encode_visibility(ebml_w, vis);
+                encode_name(ecx, ebml_w, nm);
+                encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
+                encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
+                encode_mutability(ebml_w, mt);
+                encode_def_id(ebml_w, local_def(id));
+                ebml_w.end_tag();
+            }
+            unnamed_field => {}
+        }
     }
     /*bad*/copy *index
 }
@@ -677,24 +673,7 @@ fn add_to_index_(item: @item, ebml_w: writer::Encoder,
         encode_def_id(ebml_w, local_def(item.id));
         encode_family(ebml_w, 'S');
         encode_type_param_bounds(ebml_w, ecx, tps);
-
-        // If this is a tuple- or enum-like struct, encode the type of the
-        // constructor. Otherwise, encode the type of the struct.
-        if struct_def.fields.len() > 0 &&
-                struct_def.fields[0].node.kind == ast::unnamed_field {
-            // Tuple- or enum-like struct.
-            let ctor_id = match struct_def.ctor_id {
-                Some(ctor_id) => ctor_id,
-                None => ecx.tcx.sess.bug(~"struct def didn't have ctor id"),
-            };
-            encode_type(ecx, ebml_w, node_id_to_type(tcx, ctor_id));
-
-            // Also encode the symbol.
-            encode_symbol(ecx, ebml_w, ctor_id);
-        } else {
-            encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
-        }
-
+        encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
         encode_name(ecx, ebml_w, item.ident);
         encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
         encode_region_param(ecx, ebml_w, item);
@@ -718,11 +697,7 @@ fn add_to_index_(item: @item, ebml_w: writer::Encoder,
                    encode_def_id(ebml_w, local_def(f.node.id));
                    ebml_w.end_tag();
                 }
-                unnamed_field => {
-                    ebml_w.start_tag(tag_item_unnamed_field);
-                    encode_def_id(ebml_w, local_def(f.node.id));
-                    ebml_w.end_tag();
-                }
+                unnamed_field => {}
             }
         }
 
index 14e27f328d1e90ef98364db46d9c00b642e28e57..ba550dbbde8ed62b266fb685d3ae743e6acd52f1 100644 (file)
@@ -13,8 +13,7 @@
 use driver::session;
 use driver::session::Session;
 use metadata::csearch::{each_path, get_method_names_if_trait};
-use metadata::csearch::{get_static_methods_if_impl, get_struct_fields};
-use metadata::csearch::{get_type_name_if_impl};
+use metadata::csearch::{get_static_methods_if_impl, get_type_name_if_impl};
 use metadata::cstore::find_use_stmt_cnum;
 use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
 use middle::lang_items::LanguageItems;
@@ -1660,14 +1659,6 @@ trait method '%s'",
                     crate) building type %s",
                    final_ident);
             child_name_bindings.define_type(Public, def, dummy_sp());
-
-            // Define the struct constructor if this is a tuple-like struct.
-            let fields = get_struct_fields(self.session.cstore, def_id);
-            if fields.len() != 0 &&
-                    fields[0].ident == special_idents::unnamed_field {
-                child_name_bindings.define_value(Public, def, dummy_sp());
-            }
-
             self.structs.insert(def_id, ());
           }
           def_self(*) | def_arg(*) | def_local(*) |
@@ -1754,12 +1745,10 @@ fn build_reduced_graph_for_external_crate(root: @Module) {
                                        OverwriteDuplicates,
                                        dummy_sp());
 
-                    self.handle_external_def(def,
-                                             modules,
+                    self.handle_external_def(def, modules,
                                              child_name_bindings,
                                              self.session.str_of(final_ident),
-                                             final_ident,
-                                             new_parent);
+                                             final_ident, new_parent);
                 }
                 dl_impl(def) => {
                     // We only process static methods of impls here.
index c61ff7d5e0267d3b7f96eb719e87f4470ab794a9..ced47bb5681b16fb366008be3e770e891515562e 100644 (file)
@@ -1905,13 +1905,8 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt,
         }
     };
 
-    let fcx = new_fn_ctxt_w_id(ccx,
-                               ~[],
-                               llfndecl,
-                               ctor_id,
-                               None,
-                               param_substs,
-                               None);
+    let fcx = new_fn_ctxt_w_id(ccx, ~[], llfndecl, ctor_id, None,
+                               param_substs, None);
 
     // XXX: Bad copy.
     let raw_llargs = create_llargs_for_fn_args(fcx, no_self, copy fn_args);
index bf417e9a5f4f9744d5944266ba93a2b94e98e4bd..f77aa33407d105d6a475bb49c4e2aa9f0f620927 100644 (file)
@@ -122,9 +122,6 @@ fn traverse_public_item(cx: ctx, item: @item) {
         }
       }
       item_struct(struct_def, tps) => {
-        for struct_def.ctor_id.each |&ctor_id| {
-            cx.rmap.insert(ctor_id, ());
-        }
         do option::iter(&struct_def.dtor) |dtor| {
             cx.rmap.insert(dtor.node.id, ());
             if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs)
index 136a2f055651fbf0212444d17d53c7df8c3e5b80..4350c62af6fc3155e1ca92a4cb2ab64723b718c4 100644 (file)
@@ -4011,7 +4011,7 @@ pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
     }
         }
   else {
-        return csearch::get_struct_fields(cx.sess.cstore, did);
+        return csearch::get_struct_fields(cx, did);
     }
 }
 
index fdf936f7aec622b49779edec29153ab4f103d9e7..5e51c216093009e943e42110f8c32e807c599b2e 100644 (file)
@@ -828,7 +828,7 @@ fn add_impls_for_module(impls_seen: HashMap<def_id,()>,
         let implementations = get_impls_for_mod(crate_store,
                                                 module_def_id,
                                                 None);
-        for implementations.each |implementation| {
+        for (*implementations).each |implementation| {
             debug!("coherence: adding impl from external crate: %s",
                    ty::item_path_str(self.crate_context.tcx,
                                      implementation.did));
diff --git a/src/test/auxiliary/newtype_struct_xc.rs b/src/test/auxiliary/newtype_struct_xc.rs
deleted file mode 100644 (file)
index 90036e0..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#[crate_type="lib"];
-
-pub struct Au(int);
-
diff --git a/src/test/run-pass/newtype-struct-xc.rs b/src/test/run-pass/newtype-struct-xc.rs
deleted file mode 100644 (file)
index 8b15d73..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// xfail-fast
-// aux-build:newtype_struct_xc.rs
-
-extern mod newtype_struct_xc;
-
-fn main() {
-    let _ = newtype_struct_xc::Au(2);
-}
-