diff options
| author | bors <bors@rust-lang.org> | 2018-07-13 22:06:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-13 22:06:38 +0000 |
| commit | a14a361c2c80fdcd0270766e0bd57104e608988e (patch) | |
| tree | b99e7d5c2a0ea280dd37ed069907b86e3ca05af9 /src/librustc_incremental | |
| parent | 254f8796b729810846e2b97620032ecaf103db33 (diff) | |
| parent | e045a6cd8c0235a26ef11e6cd9a13ebd817f1265 (diff) | |
Auto merge of #52266 - michaelwoerister:incr-thinlto-preliminaries, r=alexcrichton
Preliminary work for incremental ThinLTO. Since implementing incremental ThinLTO is a bit more involved than I initially thought, I'm splitting out some of the things that already work. This PR (1) adds a way accessing some ThinLTO information in `rustc` and (2) does some cleanup around CGU/object file naming (which makes things quite a bit nicer). This is probably best reviewed one commit at a time.
Diffstat (limited to 'src/librustc_incremental')
| -rw-r--r-- | src/librustc_incremental/assert_module_sources.rs | 53 | ||||
| -rw-r--r-- | src/librustc_incremental/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_incremental/persist/mod.rs | 1 |
3 files changed, 47 insertions, 8 deletions
diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index df8e0f056af..f6e9ee7b225 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -27,11 +27,11 @@ //! the HIR doesn't change as a result of the annotations, which might //! perturb the reuse results. +use rustc::hir::def_id::LOCAL_CRATE; use rustc::dep_graph::{DepNode, DepConstructor}; use rustc::mir::mono::CodegenUnit; use rustc::ty::TyCtxt; use syntax::ast; -use syntax_pos::symbol::Symbol; use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED}; const MODULE: &'static str = "module"; @@ -72,12 +72,37 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> { return; } - let mname = self.field(attr, MODULE); - let mangled_cgu_name = CodegenUnit::mangle_name(&mname.as_str()); - let mangled_cgu_name = Symbol::intern(&mangled_cgu_name).as_interned_str(); + let user_path = self.field(attr, MODULE).as_str().to_string(); + let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string(); + + if !user_path.starts_with(&crate_name) { + let msg = format!("Found malformed codegen unit name `{}`. \ + Codegen units names must always start with the name of the \ + crate (`{}` in this case).", user_path, crate_name); + self.tcx.sess.span_fatal(attr.span, &msg); + } + + // Split of the "special suffix" if there is one. + let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind(".") { + (&user_path[..index], Some(&user_path[index + 1 ..])) + } else { + (&user_path[..], None) + }; + + let mut cgu_path_components = user_path.split("-").collect::<Vec<_>>(); + + // Remove the crate name + assert_eq!(cgu_path_components.remove(0), crate_name); + + let cgu_name = CodegenUnit::build_cgu_name(self.tcx, + LOCAL_CRATE, + cgu_path_components, + cgu_special_suffix); + + debug!("mapping '{}' to cgu name '{}'", self.field(attr, MODULE), cgu_name); let dep_node = DepNode::new(self.tcx, - DepConstructor::CompileCodegenUnit(mangled_cgu_name)); + DepConstructor::CompileCodegenUnit(cgu_name)); if let Some(loaded_from_cache) = self.tcx.dep_graph.was_loaded_from_cache(&dep_node) { match (disposition, loaded_from_cache) { @@ -85,13 +110,13 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> { self.tcx.sess.span_err( attr.span, &format!("expected module named `{}` to be Reused but is Codegened", - mname)); + user_path)); } (Disposition::Codegened, true) => { self.tcx.sess.span_err( attr.span, &format!("expected module named `{}` to be Codegened but is Reused", - mname)); + user_path)); } (Disposition::Reused, true) | (Disposition::Codegened, false) => { @@ -99,7 +124,19 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> { } } } else { - self.tcx.sess.span_err(attr.span, &format!("no module named `{}`", mname)); + let available_cgus = self.tcx + .collect_and_partition_mono_items(LOCAL_CRATE) + .1 + .iter() + .map(|cgu| format!("{}", cgu.name())) + .collect::<Vec<String>>() + .join(", "); + + self.tcx.sess.span_err(attr.span, + &format!("no module named `{}` (mangled: {}).\nAvailable modules: {}", + user_path, + cgu_name, + available_cgus)); } } diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index 2ef88041d33..10efa1a2870 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -44,6 +44,7 @@ pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir; pub use persist::save_dep_graph; pub use persist::save_work_product_index; pub use persist::in_incr_comp_dir; +pub use persist::in_incr_comp_dir_sess; pub use persist::prepare_session_directory; pub use persist::finalize_session_directory; pub use persist::delete_workproduct_files; diff --git a/src/librustc_incremental/persist/mod.rs b/src/librustc_incremental/persist/mod.rs index e1f00db56d5..17d36ba3fa7 100644 --- a/src/librustc_incremental/persist/mod.rs +++ b/src/librustc_incremental/persist/mod.rs @@ -23,6 +23,7 @@ mod file_format; pub use self::fs::finalize_session_directory; pub use self::fs::garbage_collect_session_directories; pub use self::fs::in_incr_comp_dir; +pub use self::fs::in_incr_comp_dir_sess; pub use self::fs::prepare_session_directory; pub use self::load::dep_graph_tcx_init; pub use self::load::load_dep_graph; |
