]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/cstore.rs
Only retain external static symbols across LTO
[rust.git] / src / librustc / middle / cstore.rs
index 27745a85935abf00d8c6668ca8da7b61754c81b3..c2c23f6a0325094242c829c98012e6fe715cc62e 100644 (file)
@@ -29,6 +29,7 @@
 use middle::ty::{self, Ty, VariantKind};
 use middle::def_id::{DefId, DefIndex};
 use mir::repr::Mir;
+use mir::mir_map::MirMap;
 use session::Session;
 use session::search_paths::PathKind;
 use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
@@ -186,8 +187,7 @@ fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
     fn is_defaulted_trait(&self, did: DefId) -> bool;
     fn is_impl(&self, did: DefId) -> bool;
     fn is_default_impl(&self, impl_did: DefId) -> bool;
-    fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
-    fn is_static(&self, did: DefId) -> bool;
+    fn is_extern_item(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
     fn is_static_method(&self, did: DefId) -> bool;
     fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
     fn is_typedef(&self, did: DefId) -> bool;
@@ -223,6 +223,8 @@ fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
                           -> FoundAst<'tcx>;
     fn maybe_get_item_mir(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
                           -> Option<Mir<'tcx>>;
+    fn is_item_mir_available(&self, def: DefId) -> bool;
+
     // This is basically a 1-based range of ints, which is a little
     // silly - I may fix that.
     fn crates(&self) -> Vec<ast::CrateNum>;
@@ -242,7 +244,7 @@ fn encode_metadata(&self,
                        item_symbols: &RefCell<NodeMap<String>>,
                        link_meta: &LinkMeta,
                        reachable: &NodeSet,
-                       mir_map: &NodeMap<Mir<'tcx>>,
+                       mir_map: &MirMap<'tcx>,
                        krate: &hir::Crate) -> Vec<u8>;
     fn metadata_encoding_version(&self) -> &[u8];
 }
@@ -267,24 +269,28 @@ pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
 
 // FIXME: find a better place for this?
 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
-    let say = |s: &str| {
-        match (sp, sess) {
-            (_, None) => panic!("{}", s),
-            (Some(sp), Some(sess)) => sess.span_err(sp, s),
-            (None, Some(sess)) => sess.err(s),
+    let mut err_count = 0;
+    {
+        let mut say = |s: &str| {
+            match (sp, sess) {
+                (_, None) => panic!("{}", s),
+                (Some(sp), Some(sess)) => sess.span_err(sp, s),
+                (None, Some(sess)) => sess.err(s),
+            }
+            err_count += 1;
+        };
+        if s.is_empty() {
+            say("crate name must not be empty");
+        }
+        for c in s.chars() {
+            if c.is_alphanumeric() { continue }
+            if c == '_'  { continue }
+            say(&format!("invalid character `{}` in crate name: `{}`", c, s));
         }
-    };
-    if s.is_empty() {
-        say("crate name must not be empty");
-    }
-    for c in s.chars() {
-        if c.is_alphanumeric() { continue }
-        if c == '_'  { continue }
-        say(&format!("invalid character `{}` in crate name: `{}`", c, s));
     }
-    match sess {
-        Some(sess) => sess.abort_if_errors(),
-        None => {}
+
+    if err_count > 0 {
+        sess.unwrap().abort_if_errors();
     }
 }
 
@@ -350,8 +356,7 @@ fn is_const_fn(&self, did: DefId) -> bool { unimplemented!() }
     fn is_defaulted_trait(&self, did: DefId) -> bool { unimplemented!() }
     fn is_impl(&self, did: DefId) -> bool { unimplemented!() }
     fn is_default_impl(&self, impl_did: DefId) -> bool { unimplemented!() }
-    fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool { unimplemented!() }
-    fn is_static(&self, did: DefId) -> bool { unimplemented!() }
+    fn is_extern_item(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool { unimplemented!() }
     fn is_static_method(&self, did: DefId) -> bool { unimplemented!() }
     fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
     fn is_typedef(&self, did: DefId) -> bool { unimplemented!() }
@@ -397,6 +402,9 @@ fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
                           -> FoundAst<'tcx> { unimplemented!() }
     fn maybe_get_item_mir(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
                           -> Option<Mir<'tcx>> { unimplemented!() }
+    fn is_item_mir_available(&self, def: DefId) -> bool {
+        unimplemented!()
+    }
 
     // This is basically a 1-based range of ints, which is a little
     // silly - I may fix that.
@@ -419,7 +427,7 @@ fn encode_metadata(&self,
                        item_symbols: &RefCell<NodeMap<String>>,
                        link_meta: &LinkMeta,
                        reachable: &NodeSet,
-                       mir_map: &NodeMap<Mir<'tcx>>,
+                       mir_map: &MirMap<'tcx>,
                        krate: &hir::Crate) -> Vec<u8> { vec![] }
     fn metadata_encoding_version(&self) -> &[u8] { unimplemented!() }
 }