1
Fork 0

Auto merge of #103042 - davidtwco:translation-distributed-ftl, r=oli-obk

errors: generate typed identifiers in each crate

Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter.

There are advantages and disadvantages to this change..

#### Advantages
- Changing a diagnostic now only recompiles the crate for that diagnostic and those crates that depend on it, rather than `rustc_error_messages` and all crates thereafter.
- This approach can be used to support first-party crates that want to supply translatable diagnostics (e.g. `rust-lang/thorin` in https://github.com/rust-lang/rust/pull/102612#discussion_r985372582, cc `@JhonnyBillM)`
- We can extend this a little so that tools built using rustc internals (like clippy or rustdoc) can add their own diagnostic resources (much more easily than those resources needing to be available to `rustc_error_messages`)

#### Disadvantages
- Crates can only refer to the diagnostic messages defined in the current crate (or those from dependencies), rather than all diagnostic messages.
- `rustc_driver` (or some other crate we create for this purpose) has to directly depend on *everything* that has error messages.
  - It already transitively depended on all these crates.

#### Pending work
- [x] I don't know how to make `rustc_codegen_gcc`'s translated diagnostics work with this approach - because `rustc_driver` can't depend on that crate and so can't get its resources to provide to the diagnostic emission. I don't really know how the alternative codegen backends are actually wired up to the compiler at all.
- [x] Update `triagebot.toml` to track the moved FTL files.

r? `@compiler-errors`
cc #100717
This commit is contained in:
bors 2023-02-22 15:14:22 +00:00
commit b869e84e58
156 changed files with 1786 additions and 1454 deletions

View file

@ -0,0 +1,56 @@
interface_ferris_identifier =
Ferris cannot be used as an identifier
.suggestion = try using their name instead
interface_emoji_identifier =
identifiers cannot contain emoji: `{$ident}`
interface_mixed_bin_crate =
cannot mix `bin` crate type with others
interface_mixed_proc_macro_crate =
cannot mix `proc-macro` crate type with others
interface_proc_macro_doc_without_arg =
Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
.warn = The generated documentation may be incorrect
interface_error_writing_dependencies =
error writing dependencies to `{$path}`: {$error}
interface_input_file_would_be_overwritten =
the input file "{$path}" would be overwritten by the generated executable
interface_generated_file_conflicts_with_directory =
the generated executable for the input file "{$input_path}" conflicts with the existing directory "{$dir_path}"
interface_temps_dir_error =
failed to find or create the directory specified by `--temps-dir`
interface_out_dir_error =
failed to find or create the directory specified by `--out-dir`
interface_cant_emit_mir =
could not emit MIR: {$error}
interface_rustc_error_fatal =
fatal error triggered by #[rustc_error]
interface_rustc_error_unexpected_annotation =
unexpected annotation used with `#[rustc_error(...)]!
interface_failed_writing_file =
failed to write file {$path}: {$error}"
interface_proc_macro_crate_panic_abort =
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
interface_unsupported_crate_type_for_target =
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
interface_multiple_output_types_adaption =
due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
interface_ignoring_extra_filename = ignoring -C extra-filename flag due to -o flag
interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag

View file

@ -222,6 +222,7 @@ pub struct Config {
pub output_dir: Option<PathBuf>,
pub output_file: Option<PathBuf>,
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
pub locale_resources: &'static [&'static str],
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
@ -267,6 +268,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
config.opts,
config.crate_cfg,
config.crate_check_cfg,
config.locale_resources,
config.file_loader,
CompilerIO {
input: config.input,

View file

@ -12,6 +12,9 @@
#[macro_use]
extern crate tracing;
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_macros::fluent_messages;
mod callbacks;
mod errors;
pub mod interface;
@ -27,3 +30,5 @@ pub use queries::Queries;
#[cfg(test)]
mod tests;
fluent_messages! { "../locales/en-US.ftl" }

View file

@ -50,7 +50,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
output_file: None,
temps_dir,
};
let sess = build_session(sessopts, io, None, registry, Default::default(), None, None);
let sess = build_session(sessopts, io, None, registry, vec![], Default::default(), None, None);
(sess, cfg)
}

View file

@ -59,6 +59,7 @@ pub fn create_session(
sopts: config::Options,
cfg: FxHashSet<(String, Option<String>)>,
check_cfg: CheckCfg,
locale_resources: &'static [&'static str],
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
io: CompilerIO,
lint_caps: FxHashMap<lint::LintId, lint::Level>,
@ -89,11 +90,15 @@ pub fn create_session(
}
};
let mut locale_resources = Vec::from(locale_resources);
locale_resources.push(codegen_backend.locale_resource());
let mut sess = session::build_session(
sopts,
io,
bundle,
descriptions,
locale_resources,
lint_caps,
file_loader,
target_override,