← Back to Pull requests

`rustc_builtin_macros` cleanup, part 8 #163485

Merged
cyrgani merged 33 files (1057 lines) on Oct 21, 2026 19:45 UTC
View on GitHub
cyrgani cyrgani commented on Sep 29, 2026 12:47 UTC
Author

<!-- homu-ignore:start -->
View all comments
<!-- homu-ignore:end -->

This PR is roughly split into three parts:

  • The first few commits add helpers to ExtCtxt to both construct some common AST elements in an easier way. They also change some Ident arguments to Symbol to avoid the annoying call-site pattern of repeating the span (cx.some_method(span, Ident::new(name, span), ...)).

  • The next few commits focus on the derive infrastructure cleanup a bit.

  • The further following commits make Path construction faster and remove the new_path remnant of the old local path version.
  • Previous PR: https://github.com/rust-lang/rust/pull/163389

    r? @nnethercote

    Diff: 1057 lines (+448 / -609) across 33 files Reviewer: petrochenkov Review duration: 32098m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.72) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 1057 lines diff across 33 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 5 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    24 items
    jieyouxu jieyouxu commented on Sep 29, 2026 13:01 UTC
    Contributor

    @bors try @rust-timer queue

    rust-timer rust-timer commented on Sep 29, 2026 13:01 UTC
    Contributor

    Awaiting bors try build completion.

    @rustbot label: +S-waiting-on-perf

    <!-- rust-timer: temporary -->

    rust-bors[bot] rust-bors[bot] commented on Sep 29, 2026 13:01 UTC
    Bot

    :hourglass: Trying commit 7eace5560c6201cf8c59cbeeb4a799335f9f08a3 with merge 0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617…

    To cancel the try build, run the command @bors try cancel.

    Workflow: https://github.com/rust-lang/rust/actions/runs/36572142525

    petrochenkov petrochenkov commented on code on Sep 29, 2026 13:02 UTC
    Code Review
    compiler/rustc_expand/src/base.rs:1
    @@ -689,7 +689,7 @@ pub enum SyntaxExtensionKind {
         ),
     
         /// An AST-based function-like macro.
    -    LegacyBang(
    +    BuiltinBang(

        AstBang(
    

    "Built-in" is not the defining property of these macros, we could easily have token-based built-in macros (IIRC quote! is already built-in but token based).
    The defining property is that these macros are AST-based rather than token-based (just like the comments on them say).

    View changes since the review

    rust-bors[bot] rust-bors[bot] commented on Sep 29, 2026 14:04 UTC
    Bot

    :sunny: Try build successful (CI)
    Build commit: 0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617 (0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617)
    Base parent: b46c90c5619a16a0c7e4d0f4e9e1ad4db4cf106e (b46c90c5619a16a0c7e4d0f4e9e1ad4db4cf106e)

    <!-- homu: {"type":"TryBuildCompleted","merge_sha":"0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617"} -->

    rust-timer rust-timer commented on Sep 29, 2026 14:04 UTC
    Contributor

    Queued 0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617 with parent b46c90c5619a16a0c7e4d0f4e9e1ad4db4cf106e, future comparison URL.
    There is currently 1 preceding artifact in the queue.
    It will probably take at least ~1.3 hours until the benchmark run finishes.
    <!-- rust-timer: temporary -->

    rust-timer rust-timer commented on Sep 29, 2026 16:15 UTC
    Contributor

    Finished benchmarking commit (0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617): comparison URL.

    Overall result: ✅ improvements - no action needed

    Benchmarking 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 count


    Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

    | | mean | range | count |
    |:----------------------------------:|:-----:|:--------------:|:-----:|
    | Regressions ❌ <br /> (primary) | - | - | 0 |
    | Regressions ❌ <br /> (secondary) | - | - | 0 |
    | Improvements ✅ <br /> (primary) | - | - | 0 |
    | Improvements ✅ <br /> (secondary) | -0.2% | [-0.3%, -0.2%] | 7 |
    | All ❌✅ (primary) | - | - | 0 |

    Max RSS (memory usage)


    <details>
    <summary>Results (primary 0.7%, secondary 2.1%)</summary>

    A less reliable metric. May be of interest, but not used to determine the overall result above.

    | | mean | range | count |
    |:----------------------------------:|:-----:|:--------------:|:-----:|
    | Regressions ❌ <br /> (primary) | 2.2% | [2.2%, 2.2%] | 1 |
    | Regressions ❌ <br /> (secondary) | 3.6% | [3.4%, 3.8%] | 3 |
    | Improvements ✅ <br /> (primary) | -0.9% | [-0.9%, -0.9%] | 1 |
    | Improvements ✅ <br /> (secondary) | -2.3% | [-2.3%, -2.3%] | 1 |
    | All ❌✅ (primary) | 0.7% | [-0.9%, 2.2%] | 2 |
    </details>

    Cycles


    This perf run didn't have relevant results for this metric.

    Binary size


    This perf run didn't have relevant results for this metric.

    Bootstrap: 491.711s -> 491.207s (-0.10%)
    Artifact size: 406.38 MiB -> 406.39 MiB (0.00%)

    rust-bors[bot] rust-bors[bot] commented on Oct 08, 2026 00:15 UTC
    Bot

    :umbrella: The latest upstream changes (presumably #163957) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

    rustbot rustbot commented on Oct 09, 2026 12:24 UTC
    Contributor

    Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

    cc @ZuseZ4

    cyrgani cyrgani commented on code on Oct 09, 2026 13:07 UTC
    Code Review
    compiler/rustc_builtin_macros/src/deriving/generic/mod.rs:1
    @@ -194,7 +194,7 @@ use thin_vec::{ThinVec, thin_vec};
     use crate::util::path_std;
     use crate::{deriving, diagnostics};
     
    -pub(crate) struct TraitDef<'a> {
    +pub(crate) struct TraitDef<> {

    oh, it looks like rustfmt skips formatting a struct with a default field entirely

    View changes since the review

    nnethercote nnethercote commented on code on Oct 16, 2026 14:06 UTC
    Code Review
    compiler/rustc_expand/src/build.rs:1
    @@ -26,6 +26,9 @@ impl<'a> ExtCtxt<'a> {
         pub fn path_ident(&self, span: Span, id: Ident) -> ast::Path {
             self.path(span, vec![id])
         }
    +    pub fn path_sym(&self, span: Span, name: Symbol) -> ast::Path {

    I think path_name and ty_name would be better, more consistent with other functions.

    nnethercote nnethercote commented on code on Oct 16, 2026 14:08 UTC
    Code Review
    compiler/rustc_builtin_macros/src/alloc_error_handler.rs:1
    @@ -62,21 +62,22 @@ pub(crate) fn expand(
     // }
     fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span) -> Stmt {
         let ty_usize = cx.ty_sym(span, sym::usize);
    -    let size = Ident::new(sym::size, span);
    -    let align = Ident::new(sym::align, span);
     
         let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
         let layout_new = cx.expr_path(cx.path(span, layout_new));
         let layout = cx.expr_call(
             span,
             layout_new,
    -        thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)],
    +        thin_vec![cx.expr_ident_sym(span, sym::size), cx.expr_ident_sym(span, sym::align)],

    Pre-existing: expr_name would be better than expr_ident_sym.

    nnethercote nnethercote commented on code on Oct 16, 2026 14:09 UTC
    Code Review
    compiler/rustc_expand/src/build.rs:1
    @@ -494,17 +494,17 @@ impl<'a> ExtCtxt<'a> {
         pub fn pat_wild(&self, span: Span) -> ast::Pat {
             self.pat(span, PatKind::Wild)
         }
    -    pub fn pat_ident(&self, span: Span, ident: Ident) -> ast::Pat {
    -        self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE)
    +    pub fn pat_ident(&self, span: Span, name: Symbol) -> ast::Pat {

    This should be pat_name.

    nnethercote nnethercote commented on Oct 16, 2026 14:19 UTC
    Reviewer

    I think leaving path_std! and pathvec! seems fine, though perhaps the latter should be renamed path_vec!.

    I don't have strong opinions about the substructure change, though the extra error messages are annoying.

    View changes since this review

    nnethercote nnethercote commented on Oct 16, 2026 14:20 UTC
    Contributor

    @petrochenkov: do you have opinions about the first commit ("rename Legacy macro kinds to Ast")?

    petrochenkov petrochenkov commented on Oct 16, 2026 14:36 UTC
    Contributor

    @petrochenkov: do you have opinions about the first commit ("rename Legacy macro kinds to Ast")?

    Yes :D https://github.com/rust-lang/rust/pull/163485#discussion_r4133751506

    cyrgani cyrgani commented on Oct 20, 2026 21:21 UTC
    Author

    I added a commit that uses name instead of ident where appropriate and removed the two commits for the path macros and the broader use of Substructure for now.
    @rustbot ready

    nnethercote nnethercote commented on Oct 21, 2026 08:18 UTC
    Contributor

    Thanks!

    @bors r+

    rust-bors[bot] rust-bors[bot] commented on Oct 21, 2026 08:18 UTC
    Bot

    :pushpin: Commit a85d97ff42f3048aad98208fc5cff08fd71e4237 has been approved by nnethercote

    It is now in the queue for this repository.

    :evergreen_tree: The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

    Reason for tree closure: spurious failures

    rust-bors[bot] rust-bors[bot] commented on Oct 21, 2026 16:22 UTC
    Bot

    :hourglass: Testing commit a85d97ff42f3048aad98208fc5cff08fd71e4237 with merge ae9d6d54d9a8b689a58dc467c8ba9d633bd4fa9d...

    Workflow: https://github.com/rust-lang/rust/actions/runs/39634220880

    JonathanBrouwer JonathanBrouwer commented on Oct 21, 2026 16:35 UTC
    Contributor

    @bors yield

    rust-bors[bot] rust-bors[bot] commented on Oct 21, 2026 16:36 UTC
    Bot

    Auto build was cancelled. Cancelled workflows:

  • https://github.com/rust-lang/rust/actions/runs/39634220880
  • The next pull request likely to be tested is https://github.com/rust-lang/rust/pull/164699.

    rust-timer rust-timer commented on Oct 22, 2026 04:01 UTC
    Contributor

    [!NOTE]

    This PR was benchmarked as part of triage of its containing rollup: [triage URL](/rust-lang/rust/pull/164699#issuecomment-6332214855).

    Finished benchmarking commit (6351b4b7b719d6f1a1636be9e2b27a1788e4934a): comparison URL.

    Overall result: ✅ improvements - no action needed

    @rustbot label: -perf-regression

    Instruction count


    Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

    | | mean | range | count |
    |:----------------------------------:|:-----:|:--------------:|:-----:|
    | Regressions ❌ <br /> (primary) | - | - | 0 |
    | Regressions ❌ <br /> (secondary) | - | - | 0 |
    | Improvements ✅ <br /> (primary) | -0.1% | [-0.1%, -0.1%] | 2 |
    | Improvements ✅ <br /> (secondary) | -0.2% | [-0.3%, -0.1%] | 11 |
    | All ❌✅ (primary) | -0.1% | [-0.1%, -0.1%] | 2 |

    Max RSS (memory usage)


    <details>
    <summary>Results (secondary -2.3%)</summary>

    A less reliable metric. May be of interest, but not used to determine the overall result above.

    | | mean | range | count |
    |:----------------------------------:|:-----:|:--------------:|:-----:|
    | Regressions ❌ <br /> (primary) | - | - | 0 |
    | Regressions ❌ <br /> (secondary) | - | - | 0 |
    | Improvements ✅ <br /> (primary) | - | - | 0 |
    | Improvements ✅ <br /> (secondary) | -2.3% | [-2.4%, -2.2%] | 2 |
    | All ❌✅ (primary) | - | - | 0 |
    </details>

    Cycles


    This perf run didn't have relevant results for this metric.

    Binary size


    This perf run didn't have relevant results for this metric.

    Artifact size: 406.57 MiB -> 406.49 MiB (-0.02%)

    Reviewers
    Assignees
    cyrgani cyrgani
    Labels
    risk: low confidence: 90.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.6% · Lower = rushed or shallow review
    90.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.7% · Safe to merge
    6.7%
    Repository