]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/dependency_format.rs
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / librustc / middle / dependency_format.rs
index 125e9285b52b5fca5fcf1b2a8384ffa97eba2f7f..aac6f1edc051da6fe085ebf06848cc85fd2581c0 100644 (file)
@@ -65,8 +65,8 @@
 
 use session;
 use session::config;
-use metadata::cstore;
-use metadata::csearch;
+use middle::cstore::CrateStore;
+use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
 use util::nodemap::FnvHashMap;
 
 /// A list of dependencies for a certain crate type.
@@ -123,12 +123,12 @@ fn calculate_type(sess: &session::Session,
                 Some(v) => return v,
                 None => {}
             }
-            sess.cstore.iter_crate_data(|cnum, data| {
-                let src = sess.cstore.get_used_crate_source(cnum).unwrap();
-                if src.rlib.is_some() { return }
+            for cnum in sess.cstore.crates() {
+                let src = sess.cstore.used_crate_source(cnum);
+                if src.rlib.is_some() { continue }
                 sess.err(&format!("dependency `{}` not found in rlib format",
-                                 data.name));
-            });
+                                  sess.cstore.crate_name(cnum)));
+            }
             return Vec::new();
         }
 
@@ -151,25 +151,27 @@ fn calculate_type(sess: &session::Session,
     // Sweep all crates for found dylibs. Add all dylibs, as well as their
     // dependencies, ensuring there are no conflicts. The only valid case for a
     // dependency to be relied upon twice is for both cases to rely on a dylib.
-    sess.cstore.iter_crate_data(|cnum, data| {
-        let src = sess.cstore.get_used_crate_source(cnum).unwrap();
+    for cnum in sess.cstore.crates() {
+        let name = sess.cstore.crate_name(cnum);
+        let src = sess.cstore.used_crate_source(cnum);
         if src.dylib.is_some() {
-            info!("adding dylib: {}", data.name);
-            add_library(sess, cnum, cstore::RequireDynamic, &mut formats);
-            let deps = csearch::get_dylib_dependency_formats(&sess.cstore, cnum);
+            info!("adding dylib: {}", name);
+            add_library(sess, cnum, RequireDynamic, &mut formats);
+            let deps = sess.cstore.dylib_dependency_formats(cnum);
             for &(depnum, style) in &deps {
                 info!("adding {:?}: {}", style,
-                      sess.cstore.get_crate_data(depnum).name.clone());
+                      sess.cstore.crate_name(depnum));
                 add_library(sess, depnum, style, &mut formats);
             }
         }
-    });
+    }
 
     // Collect what we've got so far in the return vector.
-    let mut ret = (1..sess.cstore.next_crate_num()).map(|i| {
-        match formats.get(&i) {
-            Some(&cstore::RequireDynamic) => Linkage::Dynamic,
-            Some(&cstore::RequireStatic) => Linkage::IncludedFromDylib,
+    let last_crate = sess.cstore.crates().len() as ast::CrateNum;
+    let mut ret = (1..last_crate+1).map(|cnum| {
+        match formats.get(&cnum) {
+            Some(&RequireDynamic) => Linkage::Dynamic,
+            Some(&RequireStatic) => Linkage::IncludedFromDylib,
             None => Linkage::NotLinked,
         }
     }).collect::<Vec<_>>();
@@ -179,17 +181,17 @@ fn calculate_type(sess: &session::Session,
     //
     // If the crate hasn't been included yet and it's not actually required
     // (e.g. it's an allocator) then we skip it here as well.
-    sess.cstore.iter_crate_data(|cnum, data| {
-        let src = sess.cstore.get_used_crate_source(cnum).unwrap();
+    for cnum in sess.cstore.crates() {
+        let src = sess.cstore.used_crate_source(cnum);
         if src.dylib.is_none() &&
            !formats.contains_key(&cnum) &&
-           data.explicitly_linked.get() {
+           sess.cstore.is_explicitly_linked(cnum) {
             assert!(src.rlib.is_some());
-            info!("adding staticlib: {}", data.name);
-            add_library(sess, cnum, cstore::RequireStatic, &mut formats);
+            info!("adding staticlib: {}", sess.cstore.crate_name(cnum));
+            add_library(sess, cnum, RequireStatic, &mut formats);
             ret[cnum as usize - 1] = Linkage::Static;
         }
-    });
+    }
 
     // We've gotten this far because we're emitting some form of a final
     // artifact which means that we're going to need an allocator of some form.
@@ -205,7 +207,7 @@ fn calculate_type(sess: &session::Session,
     // making sure that everything is available in the requested format.
     for (cnum, kind) in ret.iter().enumerate() {
         let cnum = (cnum + 1) as ast::CrateNum;
-        let src = sess.cstore.get_used_crate_source(cnum).unwrap();
+        let src = sess.cstore.used_crate_source(cnum);
         match *kind {
             Linkage::NotLinked |
             Linkage::IncludedFromDylib => {}
@@ -216,10 +218,10 @@ fn calculate_type(sess: &session::Session,
                     Linkage::Static => "rlib",
                     _ => "dylib",
                 };
-                let data = sess.cstore.get_crate_data(cnum);
+                let name = sess.cstore.crate_name(cnum);
                 sess.err(&format!("crate `{}` required to be available in {}, \
                                   but it was not available in this form",
-                                 data.name, kind));
+                                  name, kind));
             }
         }
     }
@@ -229,8 +231,8 @@ fn calculate_type(sess: &session::Session,
 
 fn add_library(sess: &session::Session,
                cnum: ast::CrateNum,
-               link: cstore::LinkagePreference,
-               m: &mut FnvHashMap<ast::CrateNum, cstore::LinkagePreference>) {
+               link: LinkagePreference,
+               m: &mut FnvHashMap<ast::CrateNum, LinkagePreference>) {
     match m.get(&cnum) {
         Some(&link2) => {
             // If the linkages differ, then we'd have two copies of the library
@@ -240,12 +242,12 @@ fn add_library(sess: &session::Session,
             //
             // This error is probably a little obscure, but I imagine that it
             // can be refined over time.
-            if link2 != link || link == cstore::RequireStatic {
-                let data = sess.cstore.get_crate_data(cnum);
-                sess.err(&format!("cannot satisfy dependencies so `{}` only \
-                                   shows up once", data.name));
-                sess.help("having upstream crates all available in one format \
-                           will likely make this go away");
+            if link2 != link || link == RequireStatic {
+                sess.struct_err(&format!("cannot satisfy dependencies so `{}` only \
+                                          shows up once", sess.cstore.crate_name(cnum)))
+                    .help("having upstream crates all available in one format \
+                           will likely make this go away")
+                    .emit();
             }
         }
         None => { m.insert(cnum, link); }
@@ -253,15 +255,16 @@ fn add_library(sess: &session::Session,
 }
 
 fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
-    let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
+    let crates = sess.cstore.used_crates(RequireStatic);
     if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
         return None
     }
 
     // All crates are available in an rlib format, so we're just going to link
     // everything in explicitly so long as it's actually required.
-    let mut ret = (1..sess.cstore.next_crate_num()).map(|cnum| {
-        if sess.cstore.get_crate_data(cnum).explicitly_linked.get() {
+    let last_crate = sess.cstore.crates().len() as ast::CrateNum;
+    let mut ret = (1..last_crate+1).map(|cnum| {
+        if sess.cstore.is_explicitly_linked(cnum) {
             Linkage::Static
         } else {
             Linkage::NotLinked
@@ -288,7 +291,7 @@ fn activate_allocator(sess: &session::Session, list: &mut DependencyList) {
     let mut allocator_found = false;
     for (i, slot) in list.iter().enumerate() {
         let cnum = (i + 1) as ast::CrateNum;
-        if !sess.cstore.get_crate_data(cnum).is_allocator() {
+        if !sess.cstore.is_allocator(cnum) {
             continue
         }
         if let Linkage::NotLinked = *slot {
@@ -314,18 +317,18 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
     let mut allocator = None;
     for (i, linkage) in list.iter().enumerate() {
         let cnum = (i + 1) as ast::CrateNum;
-        let data = sess.cstore.get_crate_data(cnum);
-        if !data.is_allocator() {
+        if !sess.cstore.is_allocator(cnum) {
             continue
         }
         if let Linkage::NotLinked = *linkage {
             continue
         }
         if let Some(prev_alloc) = allocator {
-            let prev = sess.cstore.get_crate_data(prev_alloc);
+            let prev_name = sess.cstore.crate_name(prev_alloc);
+            let cur_name = sess.cstore.crate_name(cnum);
             sess.err(&format!("cannot link together two \
                                allocators: {} and {}",
-                              prev.name(), data.name()));
+                              prev_name, cur_name));
         }
         allocator = Some(cnum);
     }