-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace - with _ in fluent slugs to improve developer workflows #100377
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
123d562
to
02ff933
Compare
cc @davidtwco |
I think this change is fine, we really should be using underscores for grep-ability. |
r? @davidtwco |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with this change - I don't anticipate any issues with an all-_
slug scheme and it increases uniformity.
Looks like you need to fix src/test/run-make/translation
which relies on overriding one of the built-in slugs.
// `typeck-foo-bar` => `foo_bar` (in `typeck.ftl`) | ||
// `const-eval-baz` => `baz` (in `const_eval.ftl`) | ||
let snake_name = Ident::new( | ||
if name.contains('-') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you submit a PR to the dev guide documenting this and updating the examples there too? Please ping me on it :)
(this can be after this lands, just so that it happens)
This comment has been minimized.
This comment has been minimized.
Is it possible to mix - and _ in a slug? If so, would it make sense to make it |
Thanks @davidtwco and @compiler-errors for the positive feedback! @deltragon from a technical point of view, it's possible, yes. And at least both in Kate and in VS Codium The only allowed chars for fluent message identifiers are ones for which |
02ff933
to
cc5dab1
Compare
I don't have a strong opinion on this - either would be fine with me. I guess I'd prefer that if we do have mixed |
6eb5ab4
to
ddc1941
Compare
@bors r+ |
📌 Commit ddc194171118535d473ff7195b4e4e1763d86abd has been approved by It is now in the queue for this repository. |
Due to changes by rust-lang/rust#100377
Due to changes by rust-lang/rust#100377
Due to changes by rust-lang/rust#100377
This comment was marked as resolved.
This comment was marked as resolved.
Having to replace - with _ (and vice versa) makes the slugs less greppable and thus constitutes a contributor roadblock. Result of running this repeatedly up until reaching a fixpoint: find compiler/rustc_error_messages/locales/en-US/ -type f -exec sed -i 's/\(.+\)-\(.*\)=/\1_\2=/' {} \; Plus some fixes to update usages of slugs leading with -.
ddc1941
to
66e4ddb
Compare
For the most part, the macro actually worked with _ slugs, but the prefix_something -> prefix::something conversion was not implemented. We don't want to accept - slugs for consistency reasons. We thus error if a name is found with - inside. This ensures a consistent style.
66e4ddb
to
ca16a8d
Compare
@rustbot ready |
Can someone add r=davidtwco? I've just rebased it. Thanks. |
@bors r+ |
Replace - with _ in fluent slugs to improve developer workflows This is a proposal to smoothen the compiler contribution experience in the face of the move to fluent. ## Context The fluent project has introduced a layer of abstraction to compiler errors. Previously, people would write down error messages directly in the same file the code was located to emit them. Now, there is a slug that connects the code in the compiler to the error message in the ftl file. You can look at 7ef610c to see an example of the changes: Old: ```Rust let msg = format!( "bounds on `{}` are most likely incorrect, consider instead \ using `{}` to detect whether a type can be trivially dropped", predicate, cx.tcx.def_path_str(needs_drop) ); lint.build(&msg).emit(); ``` New (Rust side): ```Rust lint.build(fluent::lint::drop_trait_constraints) .set_arg("predicate", predicate) .set_arg("needs_drop", cx.tcx.def_path_str(needs_drop)) .emit(); ``` New (Fluent side): ```fluent lint-drop-trait-constraints = bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped ``` You will note that in the ftl file, the slug is slightly different from the slug in the Rust file: The ftl slug uses `-` (e.g. `lint-drop-trait-constraints`) while the rust slug uses `::` and `_` (e.g. `lint::drop_trait_constraints`). This choice was probably done due to: * Rust not accepting `-` in identifiers (as it is an operator) * fluent not supporting the `:` character in slug names (parse error upon attempts) * all official fluent documentation using `-` instead of `_` ## The problem The two different types of slugs, one with `-`, and one with `_`, cause difficulties for contributors. Imagine you don't have perfect knowledge of where stuff is in the compiler (i would say this is most people), and you encounter an error for which you think there is something you could improve that is not just a rewording. So you want to find out where in the compiler's code that error is being emitted. The best way is via grepping. 1. you grep for the message in the compiler's source code. You discover the ftl file and find out the slug for that error. 2. That slug however contains `-` instead of `_`, so you have to manually translate the `-`'s into `_`s, and furthermore either remove the leading module name, or replace the first `-` with a `::`. 3. you do a second grep to get to the emitting location in the compiler's code. This translation difficulty in step 2 appears also in the other direction when you want to figure out what some code in the compiler is doing and use error messages to help your understanding. Comments and variable names are way less exposed to users so [are more likely going to lie](rust-lang@cc3c5d2) than error messages. I think that at least the `-`→`_` translation which makes up most of step 2 can be removed at low cost. ## The solution If you look closely, the practice of fluent to use `-` is only a stylistic choice and it is not enforced by fluent implementations, neither the playground nor the one the rust compiler uses, that slugs may not contain `_`. Thus, we can in fact migrate the ftl side to `_`. So now we'll have slugs like `lint_drop_trait_constraints` on the ftl side. You only have to do one replacement now to get to the Rust slug: remove the first `_` and place a `::` in its stead. I would argue that this change is in fact useful as it allows you to control whether you want to look at the rust side of things or the ftl side of things via changing the query string only: with an increased number of translations checked into the repository, grepping for raw slugs will return the slug in many ftl files, so an explicit step to look for the source code is always useful. In the other direction (rust to fluent), you don't need a translation at all any more, as you can just take the final piece of the slug (e.g. `drop_trait_constraints`) and grep for that. The PR also adds enforcement to forbid usage of `_` in slug names. Internal slug names (those leading with a `-`) are exempt from that enforcement. As another workflow that benefits from this change, people who add new errors don't have to do that `-` conversion either. | Before/After | Fluent slug | Rust slug (no change) | |--|--|--| | Before | `lint-drop-trait-constraints` | `lint::drop_trait_constraints`| | After | `lint_drop_trait_constraints` | `lint::drop_trait_constraints`| Note that I've suggested this previously in the translation thread on zulip. I think it's important to think about non-translator contribution impact of fluent. I have certainly plans for more improvements, but this is a good first step. `@rustbot` label A-diagnostics
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#100031 (improve "try ignoring the field" diagnostic) - rust-lang#100325 (Rustdoc-Json: Don't remove impls for items imported from private modules) - rust-lang#100377 (Replace - with _ in fluent slugs to improve developer workflows) - rust-lang#100458 (Adjust span of fn argument declaration) - rust-lang#100514 (Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls) - rust-lang#100528 (Support 1st group of RISC-V Bitmanip backend target features) - rust-lang#100559 (Parser simplifications) - rust-lang#100568 (Fix STD build for ESP-IDF) - rust-lang#100582 ([rustdoc] Fix handling of stripped enum variant in JSON output format) - rust-lang#100586 (Reland changes replacing num_cpus with available_parallelism ) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Due to changes by rust-lang/rust#100377
Due to changes by rust-lang/rust#100377
Due to changes by rust-lang/rust#100377
This is a proposal to smoothen the compiler contribution experience in the face of the move to fluent.
Context
The fluent project has introduced a layer of abstraction to compiler errors. Previously, people would write down error messages directly in the same file the code was located to emit them. Now, there is a slug that connects the code in the compiler to the error message in the ftl file.
You can look at 7ef610c to see an example of the changes:
Old:
New (Rust side):
New (Fluent side):
You will note that in the ftl file, the slug is slightly different from the slug in the Rust file: The ftl slug uses
-
(e.g.lint-drop-trait-constraints
) while the rust slug uses::
and_
(e.g.lint::drop_trait_constraints
). This choice was probably done due to:-
in identifiers (as it is an operator):
character in slug names (parse error upon attempts)-
instead of_
The problem
The two different types of slugs, one with
-
, and one with_
, cause difficulties for contributors. Imagine you don't have perfect knowledge of where stuff is in the compiler (i would say this is most people), and you encounter an error for which you think there is something you could improve that is not just a rewording.So you want to find out where in the compiler's code that error is being emitted. The best way is via grepping.
-
instead of_
, so you have to manually translate the-
's into_
s, and furthermore either remove the leading module name, or replace the first-
with a::
.This translation difficulty in step 2 appears also in the other direction when you want to figure out what some code in the compiler is doing and use error messages to help your understanding. Comments and variable names are way less exposed to users so are more likely going to lie than error messages.
I think that at least the
-
→_
translation which makes up most of step 2 can be removed at low cost.The solution
If you look closely, the practice of fluent to use
-
is only a stylistic choice and it is not enforced by fluent implementations, neither the playground nor the one the rust compiler uses, that slugs may not contain_
. Thus, we can in fact migrate the ftl side to_
. So now we'll have slugs likelint_drop_trait_constraints
on the ftl side. You only have to do one replacement now to get to the Rust slug: remove the first_
and place a::
in its stead. I would argue that this change is in fact useful as it allows you to control whether you want to look at the rust side of things or the ftl side of things via changing the query string only: with an increased number of translations checked into the repository, grepping for raw slugs will return the slug in many ftl files, so an explicit step to look for the source code is always useful. In the other direction (rust to fluent), you don't need a translation at all any more, as you can just take the final piece of the slug (e.g.drop_trait_constraints
) and grep for that. The PR also adds enforcement to forbid usage of_
in slug names. Internal slug names (those leading with a-
) are exempt from that enforcement.As another workflow that benefits from this change, people who add new errors don't have to do that
-
conversion either.lint-drop-trait-constraints
lint::drop_trait_constraints
lint_drop_trait_constraints
lint::drop_trait_constraints
Note that I've suggested this previously in the translation thread on zulip. I think it's important to think about non-translator contribution impact of fluent. I have certainly plans for more improvements, but this is a good first step.
@rustbot label A-diagnostics