rust/compiler
Dylan DPC dc9f6f3243
Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors
translation: eager translation

Part of #100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context.

- **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`.
- **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure.
- **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages
(messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation.
- **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`.
- **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic.
- **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move.

  This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg`
anyway.

  However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as:

      let diag = { /* create diagnostic */ };

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          format!("{}", __binding_0),
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.emit();

  For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first.

  Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition.

  By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added.

      let diag = { /* create diagnostic */ };

      let __code_0 = format!("{}", __binding_0);
      /* + other formatting */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          __code_0,
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.emit();

- **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem.

r? ```@compiler-errors```
2022-10-12 22:13:23 +05:30
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011 2022-10-12 03:46:16 +00:00
rustc_ast_lowering Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors 2022-10-12 22:13:23 +05:30
rustc_ast_passes errors: AddToDiagnostic::add_to_diagnostic_with 2022-10-10 14:20:16 +01:00
rustc_ast_pretty Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
rustc_attr Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_borrowck Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk 2022-10-12 11:11:24 +05:30
rustc_builtin_macros Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
rustc_codegen_cranelift Remove mir::CastKind::Misc 2022-10-06 15:32:41 +03:00
rustc_codegen_gcc Remove type argument of array_alloca and rename to byte_array_alloca 2022-10-02 13:42:14 +00:00
rustc_codegen_llvm Rollup merge of #102725 - nnethercote:rm-Z-time, r=davidtwco 2022-10-06 16:29:45 +02:00
rustc_codegen_ssa Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors 2022-10-12 22:13:23 +05:30
rustc_const_eval Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk 2022-10-08 14:38:18 +02:00
rustc_data_structures Rollup merge of #102725 - nnethercote:rm-Z-time, r=davidtwco 2022-10-06 16:29:45 +02:00
rustc_driver Remove -Ztime option. 2022-10-06 15:49:44 +11:00
rustc_error_codes Cleanup some error code explanations 2022-10-03 08:53:06 +02:00
rustc_error_messages Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors 2022-10-12 22:13:23 +05:30
rustc_errors Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors 2022-10-12 22:13:23 +05:30
rustc_expand Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011 2022-10-12 03:46:16 +00:00
rustc_feature Stabilize half_open_range_patterns 2022-10-08 11:00:13 +02:00
rustc_fs_util
rustc_graphviz
rustc_hir rustc_hir: Less error-prone methods for accessing PartialRes resolution 2022-10-11 09:04:52 +04:00
rustc_hir_analysis Rollup merge of #102890 - camsteffen:adt-sized-representability, r=cjgillot 2022-10-12 11:11:26 +05:30
rustc_hir_pretty Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki 2022-10-10 00:09:42 +09:00
rustc_incremental Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki 2022-10-10 00:09:42 +09:00
rustc_index Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_infer errors: AddToDiagnostic::add_to_diagnostic_with 2022-10-10 14:20:16 +01:00
rustc_interface Move lifetime resolution module to rustc_hir_analysis. 2022-10-10 17:40:52 +00:00
rustc_lexer Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_lint errors: AddToDiagnostic::add_to_diagnostic_with 2022-10-10 14:20:16 +01:00
rustc_lint_defs Auto merge of #100720 - camsteffen:representable, r=cjgillot 2022-10-08 11:53:25 +00:00
rustc_llvm Avoid LLVM-deprecated Optional::hasValue 2022-09-26 16:51:18 -07:00
rustc_log
rustc_macros macros: simplify field ordering in diag derive 2022-10-10 14:20:16 +01:00
rustc_metadata Rewrite representability 2022-10-07 09:33:46 -05:00
rustc_middle Rollup merge of #102890 - camsteffen:adt-sized-representability, r=cjgillot 2022-10-12 11:11:26 +05:30
rustc_mir_build Rollup merge of #102853 - cjgillot:skip-opaque-cast, r=jackh726 2022-10-10 13:43:42 +05:30
rustc_mir_dataflow Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk 2022-10-08 14:38:18 +02:00
rustc_mir_transform Rollup merge of #102778 - nbdd0121:mir, r=tmiasko 2022-10-08 14:38:19 +02:00
rustc_monomorphize Auto merge of #99324 - reez12g:issue-99144, r=jyn514 2022-10-06 03:01:57 +00:00
rustc_parse Auto merge of #102896 - matthiaskrgr:rollup-jg5xawz, r=matthiaskrgr 2022-10-11 00:36:26 +00:00
rustc_parse_format Fix span of byte-escaped left format args brace 2022-09-28 13:47:17 -07:00
rustc_passes Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, r=davidtwco 2022-10-12 11:11:23 +05:30
rustc_plugin_impl Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
rustc_privacy ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
rustc_query_impl Rewrite representability 2022-10-07 09:33:46 -05:00
rustc_query_system query_system: finish migration 2022-10-10 14:20:16 +01:00
rustc_resolve Rollup merge of #102913 - SparrowLii:import-candidate, r=compiler-errors 2022-10-12 11:11:26 +05:30
rustc_save_analysis ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
rustc_serialize remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
rustc_session errors: add emit_note/create_note 2022-10-07 13:19:27 -06:00
rustc_smir
rustc_span Rollup merge of #102860 - GuillaumeGomez:missing-docs-FileNameDisplayPreference, r=nagisa 2022-10-10 10:23:05 +09:00
rustc_symbol_mangling Auto merge of #99324 - reez12g:issue-99144, r=jyn514 2022-10-06 03:01:57 +00:00
rustc_target rustc_target: Refactor internal linker flavors 2022-10-06 13:41:12 +04:00
rustc_trait_selection Auto merge of #102896 - matthiaskrgr:rollup-jg5xawz, r=matthiaskrgr 2022-10-11 00:36:26 +00:00
rustc_traits Change InferCtxtBuilder from enter to build 2022-10-07 07:10:40 -05:00
rustc_transmute Remove TypeckResults from InferCtxt 2022-10-07 07:06:19 -05:00
rustc_ty_utils Check representability in adt_sized_constraint 2022-10-10 14:36:12 -05:00
rustc_type_ir Remove from compiler/ crates 2022-09-29 16:49:04 +09:00