Skip to content

expand: Use Option instead of SmallVec<1> where possible. #141273

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 20, 2025

Currently we use SmallVec in various places in expansion where an Option would suffice.

r? @petrochenkov

For most of the AST fragment kinds involved in expansion, we use
`SmallVec<[T; 1]>` for the type produced. This is necessary for things
like items and statements, but for many other things like arms,
variants, and params, we never produce more than one, so an `Option` is
sufficient.

Specifics:
- Numerous `flat_map_foo` methods that currently return a `SmallVec` are
  renamed as `filter_map_foo` and now return an `Option`. (This mirrors
  the existing `filter_map_expr`.)
- Likewise, numerous plural `make_foos` methods that are also renamed as
  singular `make_foo`.
- Also, various AST fragment kinds are renamed from plural to
  singular.
- The `ast_fragments!` macro gets a new `option` kind, to augment the
  existing `one` and `many` kinds.
- `visit_clobber_opt` is added. It's similar to `visit_clobber`.
- In `expect_from_annotables`, it now checks that there aren't any
  excess elements in the iterator.
- The associated type `InvocationCollectorNode::OutputTy` no longer has
  a default value, because it now varies more. It used to mostly be
  `SmallVec`, but not it is sometimes `SmallVec`, sometimes `Option`,
  and sometimes something else.
`mut_visit.rs` has a single mfunction with a `noop_` prefix:
`noop_filter_map_expr`. This commit renames as `walk_filter_map_expr`
which is consistent with other functions in this file.

The commit also removes out-of-date comments that refer to `noop_*`
methods.
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 20, 2025
@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 20, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2025
…<try>

expand: Use `Option` instead of `SmallVec<1>` where possible.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented May 20, 2025

⌛ Trying commit 4360fac with merge 7285814...

@bors
Copy link
Collaborator

bors commented May 20, 2025

☀️ Try build successful - checks-actions
Build commit: 7285814 (728581455a4be10b36b44fac66d04dd9e39cebfe)

@rust-timer

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this May 20, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7285814): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
1.0% [1.0%, 1.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 5
All ❌✅ (primary) -0.9% [-2.8%, 1.0%] 2

Max RSS (memory usage)

Results (primary -4.2%, secondary -1.3%)

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)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
-4.2% [-4.2%, -4.2%] 1
Improvements ✅
(secondary)
-1.7% [-6.9%, -0.4%] 13
All ❌✅ (primary) -4.2% [-4.2%, -4.2%] 1

Cycles

Results (primary -2.8%, secondary 0.7%)

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)
0.7% [0.4%, 1.0%] 7
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-2.8%, -2.8%] 1

Binary size

Results (primary -1.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)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

Bootstrap: 775.977s -> 775.491s (-0.06%)
Artifact size: 365.61 MiB -> 365.29 MiB (-0.09%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 20, 2025
@nnethercote nnethercote marked this pull request as ready for review May 20, 2025 18:21
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 20, 2025
@nnethercote
Copy link
Contributor Author

Looks to be perf-neutral.

@rustbot

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants