diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2018-07-10 19:16:22 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2018-08-15 13:47:39 +0200 |
| commit | 2d2cd21f95a01f776ab6248fe24a8d033b147b28 (patch) | |
| tree | b4ae7e199b72673d1a214b7092faeddbac687571 /src/librustc_incremental/assert_module_sources.rs | |
| parent | 81cfaad030435aae447d73c66123b3df856c09cb (diff) | |
| download | rust-2d2cd21f95a01f776ab6248fe24a8d033b147b28.tar.gz rust-2d2cd21f95a01f776ab6248fe24a8d033b147b28.zip | |
Clean up CodegenUnit name generation.
Diffstat (limited to 'src/librustc_incremental/assert_module_sources.rs')
| -rw-r--r-- | src/librustc_incremental/assert_module_sources.rs | 53 |
1 files changed, 45 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)); } } |
