Skip to content
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

delegation: Implement list delegation #123413

Merged
merged 1 commit into from
May 15, 2024
Merged

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Apr 3, 2024

reuse prefix::{a, b, c};

Using design described in rust-lang/rfcs#3530 (comment) (the lists are desugared at macro expansion time).
List delegations are expanded eagerly when encountered, similarly to #[cfg]s, and not enqueued for later resolution/expansion like regular macros or glob delegation (#124135).

Part of #118212.

@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2024

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 3, 2024
@fmease
Copy link
Member

fmease commented Apr 12, 2024

Wait, this conflicts with #122500, which one should I review first?

@petrochenkov
Copy link
Contributor Author

@fmease
Any order should be fine.

@bors

This comment was marked as resolved.

@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2024

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@petrochenkov petrochenkov changed the title delegation: Implement multi-item delegation delegation: Implement list delegation Apr 19, 2024
@petrochenkov
Copy link
Contributor Author

petrochenkov commented Apr 19, 2024

Based on the experience of implementing glob delegation in #124135, I changed the implementation here from using DelegationKind to using a new ItemKind for delegation lists, which is treated similarly to ItemKind::MacCall.
It requires touching more code, but the result is clearer.
(I also found missing pretty-printing this way, and fixed it.)

@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov force-pushed the delegmulti2 branch 2 times, most recently from bf178ca to c60d449 Compare April 24, 2024 16:33
@petrochenkov
Copy link
Contributor Author

@fmease
I rebased and changed the treatment of DelegationMac in expand.rs to be more similar to other macros.

@bors

This comment was marked as resolved.

@fmease fmease added the F-fn_delegation `#![feature(fn_delegation)]` label May 14, 2024
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay 😞

r=me after rebase & with suggestions & questions addressed.

compiler/rustc_ast/src/mut_visit.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/item.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/item.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_lowering/src/item.rs Outdated Show resolved Hide resolved
}
if let Some(suffixes) = suffixes {
self.word("::");
self.word("{");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor, not blocking) could maybe use one of ibox, cbox

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this for some later time.

compiler/rustc_ast_pretty/src/pprust/state/item.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_pretty/src/pprust/state/item.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/expand.rs Show resolved Hide resolved
compiler/rustc_parse/src/parser/item.rs Show resolved Hide resolved
tests/ui/delegation/list.rs Outdated Show resolved Hide resolved
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2024
```rust
reuse prefix::{a, b, c}
```
@petrochenkov
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 14, 2024
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fmease
Copy link
Member

fmease commented May 15, 2024

@bors r+

@bors
Copy link
Contributor

bors commented May 15, 2024

📌 Commit c30b410 has been approved by fmease

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 15, 2024
@bors
Copy link
Contributor

bors commented May 15, 2024

⌛ Testing commit c30b410 with merge 3cb0030...

@bors
Copy link
Contributor

bors commented May 15, 2024

☀️ Test successful - checks-actions
Approved by: fmease
Pushing 3cb0030 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 15, 2024
@bors bors merged commit 3cb0030 into rust-lang:master May 15, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 15, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3cb0030): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.5%, -0.4%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 678.182s -> 679.399s (0.18%)
Artifact size: 316.22 MiB -> 316.22 MiB (-0.00%)

celinval added a commit to celinval/rust-dev that referenced this pull request Jun 4, 2024
Update Rust toolchain from nightly-2024-05-15 to nightly-2024-05-16
without any other source changes.
This is an automatically generated pull request. If any of the CI checks
fail, manual intervention is required. In such a case, review the
changes at https://github.com/rust-lang/rust from
rust-lang@8387315
up to
rust-lang@1871252.
The log for this commit range is:
rust-lang@1871252fc8 Auto merge of
rust-lang#125164 - fmease:rollup-s5vwzlg, r=fmease
rust-lang@734a109998 Rollup merge of
rust-lang#125159 - fmease:allow-unauth-labels-l-pg-z, r=jieyouxu
rust-lang@601e5d199f Rollup merge of
rust-lang#125154 - FractalFir:fnabi_doc, r=compiler-errors
rust-lang@09156291e5 Rollup merge of
rust-lang#125146 - Oneirical:panic-impl, r=jieyouxu
rust-lang@80f991e09b Rollup merge of
rust-lang#125142 - GuillaumeGomez:migrate-rustdoc-themes, r=jieyouxu
rust-lang@c5b17ec9d2 Rollup merge of
rust-lang#125003 - RalfJung:aligned_alloc, r=cuviper
rust-lang@257d222e4b Improved the
documentation of the FnAbi struct
rust-lang@72a48fc68c Allow
unauthenticated users to modify `L-*`, `PG-*` and `-Z*` labels
rust-lang@b21b74b5e6 Auto merge of
rust-lang#125134 - compiler-errors:negative-traits-are-not-notable, r=fmease
rust-lang@a7484d2e49 fix tidy
rust-lang@cae17ff42b rewrite
panic-impl-transitive
rust-lang@ade234d574 Auto merge of
rust-lang#125144 - fmease:rollup-4uft293, r=fmease
rust-lang@8d38f2fb11 Rollup merge of
rust-lang#125137 - RalfJung:mir-sh, r=scottmcm
rust-lang@2659ff3882 Rollup merge of
rust-lang#125104 - Oneirical:test6, r=jieyouxu
rust-lang@4f7d9d4ad8 Rollup merge of
rust-lang#125038 - ivan-shrimp:checked_sub, r=joboet
rust-lang@2804d4223b Rollup merge of
rust-lang#125027 - Oneirical:c-test-with-remove, r=jieyouxu
rust-lang@2e70bea168 Rollup merge of
rust-lang#124975 - lu-zero:move_file, r=clubby789
rust-lang@3873a74f8a Rollup merge of
rust-lang#124307 - reitermarkus:escape-debug-size-hint-inline, r=joboet
rust-lang@3cb0030fe9 Auto merge of
rust-lang#123413 - petrochenkov:delegmulti2, r=fmease
rust-lang@c765480efe Migrate
`run-make/rustdoc-themes` to new rmake
rust-lang@c87ae947eb Add new `htmldocck`
function to `run-make-support`
rust-lang@a71c3ffce9 Auto merge of
rust-lang#125032 - compiler-errors:crash-dump-dir, r=onur-ozkan
rust-lang@0afd50e852 MIR operators:
clarify Shl/Shr handling of negative offsets
rust-lang@44fa5fd39a Auto merge of
rust-lang#125136 - matthiaskrgr:rollup-ljm15m3, r=matthiaskrgr
rust-lang@5f1a120ee5 Rollup merge of
rust-lang#125135 - chenyukang:yukang-fix-116502, r=compiler-errors
rust-lang@f7c2934420 Rollup merge of
rust-lang#125132 - mejrs:diag, r=compiler-errors
rust-lang@a8ff937b07 Rollup merge of
rust-lang#125108 - Zalathar:info-bitmap-bytes, r=nnethercote
rust-lang@03ff673dcc Rollup merge of
rust-lang#124990 - fmease:expand-weak-aliases-within-cts, r=compiler-errors
rust-lang@75895f59b0 Fix the dedup error
because of spans from suggestion
rust-lang@9e7aff7945 Auto merge of
rust-lang#125031 - Oneirical:dynamic-libs, r=jieyouxu
rust-lang@8994840f7e rustdoc: Negative
impls are not notable
rust-lang@91a3f04a3f fix the test
rust-lang@0160bff4b1 Auto merge of
rust-lang#125084 - Jules-Bertholet:fix-125058, r=Nadrieril
rust-lang@c30b41012d delegation:
Implement list delegation
rust-lang@18d7411719 Add
`on_unimplemented" typo suggestions
rust-lang@81f7e54962 Port issue-11908 to
rmake
rust-lang@1f61cc3078 port
no-cdylib-as-rdylib test
rust-lang@b1e5e5161a remove cxx_flags
rust-lang@1f5837ae25 rewrite
c-link-to-rust-staticlib
rust-lang@5cc020d3df avoid using
aligned_alloc; posix_memalign is better-behaved
rust-lang@c81be68fb4 coverage: Remove
confusing comments from `CoverageKind`
rust-lang@bfadc3a9b9 coverage:
`CoverageIdsInfo::mcdc_bitmap_bytes` is never needed
rust-lang@fe8f66e4bc `rustc_hir_typeck`:
Account for `skipped_ref_pats` in `expr_use_visitor`
rust-lang@4db00fe229 Use an helper to
move the files
rust-lang@7fde7308bf reverse condition in
`uN::checked_sub`
rust-lang@848f3c2c6e Make crashes dump
mir to build dir
rust-lang@35a5be2833 Also expand weak
alias tys inside consts inside `expand_weak_alias_tys`
rust-lang@4edf12d33e Improve escape
methods.
rust-lang@16981ba406 Avoid panicking
branch in `EscapeIterInner`.
rust-lang@e3fc97be2b Inline
`EscapeDebug::size_hint`.

Co-authored-by: celinval <[email protected]>
Co-authored-by: Zyad Hassan <[email protected]>
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Jun 19, 2024
delegation: Implement glob delegation

Support delegating to all trait methods in one go.
Overriding globs with explicit definitions is also supported.

The implementation is generally based on the design from rust-lang/rfcs#3530 (comment), but unlike with list delegation in rust-lang#123413 we cannot expand glob delegation eagerly.
We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob.

Glob delegation is only allowed in impls, and can only point to traits.
Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity.

Part of rust-lang#118212.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Jun 19, 2024
delegation: Implement glob delegation

Support delegating to all trait methods in one go.
Overriding globs with explicit definitions is also supported.

The implementation is generally based on the design from rust-lang/rfcs#3530 (comment), but unlike with list delegation in rust-lang#123413 we cannot expand glob delegation eagerly.
We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob.

Glob delegation is only allowed in impls, and can only point to traits.
Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity.

Part of rust-lang#118212.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 19, 2024
Rollup merge of rust-lang#124135 - petrochenkov:deleglob, r=fmease

delegation: Implement glob delegation

Support delegating to all trait methods in one go.
Overriding globs with explicit definitions is also supported.

The implementation is generally based on the design from rust-lang/rfcs#3530 (comment), but unlike with list delegation in rust-lang#123413 we cannot expand glob delegation eagerly.
We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob.

Glob delegation is only allowed in impls, and can only point to traits.
Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity.

Part of rust-lang#118212.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-fn_delegation `#![feature(fn_delegation)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants