Skip to content

Commit

Permalink
incremental: migrate diagnostics
Browse files Browse the repository at this point in the history
Migrate the `rustc_incremental` crate's diagnostics to translatable
diagnostic structs.

Signed-off-by: David Wood <david.wood@huawei.com>
  • Loading branch information
davidtwco committed Aug 22, 2022
1 parent e6a3632 commit 3becaaf
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 253 deletions.
106 changes: 106 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/incremental.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name}
incremental_missing_depnode = missing `DepNode` variant
incremental_missing_if_this_changed = no `#[rustc_if_this_changed]` annotation detected
incremental_no_path = no path from `{$source}` to `{$target}`
incremental_ok = OK
incremental_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified
incremental_missing_query_depgraph = found CGU-reuse attribute but `-Zquery-dep-graph` was not specified
incremental_malformed_cgu_name =
found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case).
incremental_no_module_named = no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
incremental_field_associated_value_expected = associated value expected for `{$name}`
incremental_no_field = no field `{$name}`
incremental_assertion_auto = `except` specified DepNodes that can not be affected for \"{$name}\": \"{$e}\"
incremental_undefined_clean_dirty_assertions_item = clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}
incremental_undefined_clean_dirty_assertions = clean/dirty auto-assertions not yet defined for {$kind}
incremental_repeated_depnode_label = dep-node label `{$label}` is repeated
incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized
incremental_not_dirty = `{$dep_node_str}` should be dirty but is not
incremental_not_clean = `{$dep_node_str}` should be clean but is not
incremental_not_loaded = `{$dep_node_str}` should have been loaded from disk but it was not
incremental_unknown_item = unknown item `{$name}`
incremental_no_cfg = no cfg attribute
incremental_associated_value_expected_for = associated value expected for `{$ident}`
incremental_associated_value_expected = expected an associated value
incremental_unchecked_clean = found unchecked `#[rustc_clean]` attribute
incremental_delete_old = unable to delete old {$name} at `{$path}`: {$err}
incremental_create_new = failed to create {$name} at `{$path}`: {$err}
incremental_write_new = failed to write {$name} to `{$path}`: {$err}
incremental_canonicalize_path = incremental compilation: error canonicalizing path `{$path}`: {$err}
incremental_create_incr_comp_dir = could not create incremental compilation {$tag} directory `{$path}`: {$err}
incremental_create_lock = incremental compilation: could not create session directory lock file: {$lock_err}
.lock_unsupported = the filesystem for the incremental path at {$session_dir} does not appear to support locking, consider changing the incremental path to a filesystem that supports locking or disable incremental compilation
.cargo_help_1 = incremental compilation can be disabled by setting the environment variable CARGO_INCREMENTAL=0 (see https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)
.cargo_help_2 = the entire build directory can be changed to a different filesystem by setting the environment variable CARGO_TARGET_DIR to a different path (see https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir)
incremental_delete_lock = error deleting lock file for incremental compilation session directory `{$path}`: {$err}
incremental_hard_link_failed =
hard linking files in the incremental compilation cache failed. copying files instead. consider moving the cache directory to a file system which supports hard linking in session dir `{$path}`
incremental_delete_partial = failed to delete partly initialized session dir `{$path}`: {$err}
incremental_delete_full = error deleting incremental compilation session directory `{$path}`: {$err}
incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}
incremental_invalid_gc_failed =
failed to garbage collect invalid incremental compilation session directory `{$path}`: {$err}
incremental_finalized_gc_failed =
failed to garbage collect finalized incremental compilation session directory `{$path}`: {$err}
incremental_session_gc_failed =
failed to garbage collect incremental compilation session directory `{$path}`: {$err}
incremental_assert_not_loaded =
we asserted that the incremental cache should not be loaded, but it was loaded
incremental_assert_loaded =
we asserted that an existing incremental cache directory should be successfully loaded, but it was not
incremental_delete_incompatible =
failed to delete invalidated or incompatible incremental compilation session directory contents `{$path}`: {$err}
incremental_load_dep_graph = could not load dep-graph from `{$path}`: {$err}
incremental_decode_incr_cache = could not decode incremental cache: {$err}
incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err}
incremental_move_dep_graph = failed to move dependency graph from `{$from}` to `{$to}`: {$err}
incremental_create_dep_graph = failed to create dependency graph at `{$path}`: {$err}
incremental_copy_workproduct_to_cache = error copying object file `{$from}` to incremental directory as `{$to}`: {$err}
incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fluent_messages! {
builtin_macros => "../locales/en-US/builtin_macros.ftl",
const_eval => "../locales/en-US/const_eval.ftl",
expand => "../locales/en-US/expand.ftl",
incremental => "../locales/en-US/incremental.ftl",
interface => "../locales/en-US/interface.ftl",
lint => "../locales/en-US/lint.ftl",
parser => "../locales/en-US/parser.ftl",
Expand Down
40 changes: 17 additions & 23 deletions compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! fn baz() { foo(); }
//! ```

use crate::errors;
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
Expand Down Expand Up @@ -133,12 +134,10 @@ impl<'tcx> IfThisChanged<'tcx> {
Some(n) => {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n,
Err(()) => {
self.tcx.sess.span_fatal(
attr.span,
&format!("unrecognized DepNode variant {:?}", n),
);
}
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
span: attr.span,
name: n,
}),
}
}
};
Expand All @@ -149,16 +148,14 @@ impl<'tcx> IfThisChanged<'tcx> {
Some(n) => {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n,
Err(()) => {
self.tcx.sess.span_fatal(
attr.span,
&format!("unrecognized DepNode variant {:?}", n),
);
}
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
span: attr.span,
name: n,
}),
}
}
None => {
self.tcx.sess.span_fatal(attr.span, "missing DepNode variant");
self.tcx.sess.emit_fatal(errors::MissingDepNode { span: attr.span });
}
};
self.then_this_would_need.push((
Expand Down Expand Up @@ -204,7 +201,7 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
// Return early here so as not to construct the query, which is not cheap.
if if_this_changed.is_empty() {
for &(target_span, _, _, _) in then_this_would_need {
tcx.sess.span_err(target_span, "no `#[rustc_if_this_changed]` annotation detected");
tcx.sess.emit_err(errors::MissingIfThisChanged { span: target_span });
}
return;
}
Expand All @@ -213,16 +210,13 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
let dependents = query.transitive_predecessors(source_dep_node);
for &(target_span, ref target_pass, _, ref target_dep_node) in then_this_would_need {
if !dependents.contains(&target_dep_node) {
tcx.sess.span_err(
target_span,
&format!(
"no path from `{}` to `{}`",
tcx.def_path_str(source_def_id),
target_pass
),
);
tcx.sess.emit_err(errors::NoPath {
span: target_span,
source: tcx.def_path_str(source_def_id),
target: *target_pass,
});
} else {
tcx.sess.span_err(target_span, "OK");
tcx.sess.emit_err(errors::Ok { span: target_span });
}
}
}
Expand Down
50 changes: 21 additions & 29 deletions compiler/rustc_incremental/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! allows for doing a more fine-grained check to see if pre- or post-lto data
//! was re-used.

use crate::errors;
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::LOCAL_CRATE;
Expand Down Expand Up @@ -66,21 +67,17 @@ impl<'tcx> AssertModuleSource<'tcx> {
sym::post_dash_lto => (CguReuse::PostLto, ComparisonKind::Exact),
sym::any => (CguReuse::PreLto, ComparisonKind::AtLeast),
other => {
self.tcx.sess.span_fatal(
attr.span,
&format!("unknown cgu-reuse-kind `{}` specified", other),
);
self.tcx
.sess
.emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other });
}
}
} else {
return;
};

if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
self.tcx.sess.span_fatal(
attr.span,
"found CGU-reuse attribute but `-Zquery-dep-graph` was not specified",
);
self.tcx.sess.emit_fatal(errors::MissingQueryDepGraph { span: attr.span });
}

if !self.check_config(attr) {
Expand All @@ -92,13 +89,11 @@ impl<'tcx> AssertModuleSource<'tcx> {
let crate_name = self.tcx.crate_name(LOCAL_CRATE).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);
self.tcx.sess.emit_fatal(errors::MalformedCguName {
span: attr.span,
user_path,
crate_name,
});
}

// Split of the "special suffix" if there is one.
Expand All @@ -125,15 +120,12 @@ impl<'tcx> AssertModuleSource<'tcx> {
let mut cgu_names: Vec<&str> =
self.available_cgus.iter().map(|cgu| cgu.as_str()).collect();
cgu_names.sort();
self.tcx.sess.span_err(
attr.span,
&format!(
"no module named `{}` (mangled: {}). Available modules: {}",
user_path,
cgu_name,
cgu_names.join(", ")
),
);
self.tcx.sess.emit_err(errors::NoModuleNamed {
span: attr.span,
user_path,
cgu_name,
cgu_names: cgu_names.join(", "),
});
}

self.tcx.sess.cgu_reuse_tracker.set_expectation(
Expand All @@ -151,15 +143,15 @@ impl<'tcx> AssertModuleSource<'tcx> {
if let Some(value) = item.value_str() {
return value;
} else {
self.tcx.sess.span_fatal(
item.span(),
&format!("associated value expected for `{}`", name),
);
self.tcx.sess.emit_fatal(errors::FieldAssociatedValueExpected {
span: item.span(),
name,
});
}
}
}

self.tcx.sess.span_fatal(attr.span, &format!("no field `{}`", name));
self.tcx.sess.emit_fatal(errors::NoField { span: attr.span, name });
}

/// Scan for a `cfg="foo"` attribute and check whether we have a
Expand Down
Loading

0 comments on commit 3becaaf

Please sign in to comment.