Implement forced keywords (k#) - #161775
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement forced keywords (`k#`)
This comment has been minimized.
This comment has been minimized.
| /// Traits for function pointers and items | ||
| (unstable, fn_static, "CURRENT_RUSTC_VERSION", Some(148768)), | ||
| /// Allows using forced keywords `k#fn`. | ||
| (unstable, forced_keywords, "CURRENT_RUSTC_VERSION", Some(153839)), |
There was a problem hiding this comment.
I've intentionally not marked it internal even though this feature is only backed by a T-compiler MCP and not by a T-lang RFC or in-tree experiment:
I would find it a bit weird if we (in a hypothetical future) told users to "please try out" "k#only bounds" or "&k#own types & exprs" (features that would obviously be non-internal) but they'd have to enable an internal feature in tandem (could be perceived as off-putting).
However, I'm okay with switching it to incomplete or even internal if requested.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (4eb8eac): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -3.0%, secondary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.1%, secondary -1.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 477.576s -> 469.017s (-1.79%) |
This comment has been minimized.
This comment has been minimized.
9e590de to
1de8681
Compare
k#)k#)
|
Ready for review. Caution Only review the commits created after ------------------------- BRANCH SEPARATOR -------------------------. Best reviewed commit by commit. |
|
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4
cc @rust-lang/rust-analyzer |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I've addressed all of your suggestions & added a new commit that drops the abstraction-layer-breaking check from the lexer (can be squashed away). @rustbot review |
|
@bors squash |
This comment has been minimized.
This comment has been minimized.
* Implement forced keywords * Allow any identifier to be forced as a keyword even if not reserved
|
🔨 2 commits were squashed into abcef06. |
628d0f7 to
abcef06
Compare
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing d080e7d (parent) -> 2269776 (this PR) Test differencesShow 37 test diffsStage 1
Stage 2
Additionally, 16 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 22697761c6a01e8d12adcd91e4a5bc755596767a --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (2269776): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.8%, secondary 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.2%, secondary -3.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 488.289s -> 489.806s (0.31%) |
Implement forced keywords (`k#`) Part of rust-lang/rust#153839. CC @dianne Introduces a new token kind to Rust >=2021 that looks like `k#ident` and that is called *forced keyword (identifier)*. This is gated behind a new unstable feature called `forced_keywords`. This is backed by [compiler MCP 945](rust-lang/compiler-team#945). ~~The `ident` in `k#ident` *must* be a keyword (from any edition) or a weak/contextual keyword for the token to be valid.~~ The `ident` in `k#ident` needn't be a keyword to be lexically valid (CC rust-lang/rust#161775 (comment)). --- What **won't** be done in this PR: 1. implementing forced keyword lifetimes (`'k#static`) 2. migrating away from built-in syntax `builtin # $ident($($tt)*)` / introducing `k#`-exclusive (weak) keywords * that'll be done in PR rust-lang/rust#162232 instead 3. allowing the user to force edition-dependent & context-dependent keywords to be keywords * re. edition-dependent: forcing them to be keywords even in editions where they're usually not a (strong) keyword (today, that only affects `gen` anyway IINM) * re. context-dependent: E.g., `union` is only "active" if it's followed by a non-reserved identifier and under this PR the same rules apply to `k#union` even though that's not necessary; changing it would result in better diagnostics (e.g., for `k#union struct {}`: `` error: expected item, found `k#union` `` => `` expected identifier, found keyword `struct` ``) and maybe also allow for disambiguation for other context-dependent keywords 4. extending the `proc_macro::Ident` API to allow users to programmatically create forced keywords (might never be added) <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
|
perf triage: This improvement looks real, but it didn't show up before merge. Do we know where this could come from? |
View all comments
Part of #153839. CC @dianne
Introduces a new token kind to Rust >=2021 that looks like
k#identand that is called forced keyword (identifier). This is gated behind a new unstable feature calledforced_keywords. This is backed by compiler MCP 945.TheTheidentink#identmust be a keyword (from any edition) or a weak/contextual keyword for the token to be valid.identink#identneedn't be a keyword to be lexically valid (CC #161775 (comment)).What won't be done in this PR:
'k#static)builtin # $ident($($tt)*)/ introducingk#-exclusive (weak) keywordsbuiltin #withk##162232 insteadgenanyway IINM)unionis only "active" if it's followed by a non-reserved identifier and under this PR the same rules apply tok#unioneven though that's not necessary; changing it would result in better diagnostics (e.g., fork#union struct {}:error: expected item, found `k#union`=>expected identifier, found keyword `struct`) and maybe also allow for disambiguation for other context-dependent keywordsproc_macro::IdentAPI to allow users to programmatically create forced keywords (might never be added)(No LLM was or will be used by me during the entire creation process of this PR)