Skip to content

Add default to TypeFoldable::fold_with - #159584

Open
camsteffen wants to merge 1 commit into
rust-lang:mainfrom
camsteffen:fold-with-default
Open

Add default to TypeFoldable::fold_with#159584
camsteffen wants to merge 1 commit into
rust-lang:mainfrom
camsteffen:fold-with-default

Conversation

@camsteffen

@camsteffen camsteffen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

View all comments

TypeFoldable::fold_with delegates to TypeFoldable::try_fold_with with an infallible error type.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 20, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 20, 2026
@rustbot

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@fmease fmease assigned fmease and unassigned dingxiangfei2009 Aug 23, 2026

@fmease fmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the wait! Could you rebase, then I'll issue a perf run? Otherwise looks good, amazing reduction in LOC!

Edit: I'll just rebase for you.

View changes since this review

/// infallible folders. Do not override this method, to ensure coherence
/// with `try_super_fold_with`.
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self;
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you test #[inline] on it locally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't test locally. Added #[inline] here and also to the new struct methods. Wanna try another perf run?

/// the behavior in sync across functions.
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self;
#[inline]
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {

@fmease fmease Aug 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Ideally we would mark this final but unfortunately this crate needs to be able to compile on stable, too. We could make it conditional on feature="nightly" using an identity macro but at this point we should just give up I guess.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and did this the naive way. Doesn't seem like too much copy-paste?

/// infallible folders. Do not override this method, to ensure coherence
/// with `try_super_fold_with`.
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self;
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {

@fmease fmease Aug 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(similarly)

@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 Aug 23, 2026
@fmease
fmease force-pushed the fold-with-default branch from a915f8c to 12bd193 Compare August 23, 2026 22:01
@rustbot

This comment has been minimized.

@fmease

fmease commented Aug 23, 2026

Copy link
Copy Markdown
Member

@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 Aug 23, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 23, 2026
Add default to `TypeFoldable::fold_with`
@rust-bors

rust-bors Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 72fafa6 (72fafa63ba64b0a54986aa53d3b2508074285e19)
Base parent: fb6531d (fb6531d550e0075b9eb9a51464f404805eec87d9)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (72fafa6): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@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 ❌
(primary)
0.6% [0.6%, 0.6%] 1
Regressions ❌
(secondary)
0.3% [0.2%, 0.6%] 32
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.4%, 0.6%] 4

Max RSS (memory usage)

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

Cycles

Results (primary 7.2%, secondary 8.1%)

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

mean range count
Regressions ❌
(primary)
7.2% [5.9%, 8.4%] 2
Regressions ❌
(secondary)
12.0% [2.0%, 18.4%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) 7.2% [5.9%, 8.4%] 2

Binary size

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

Bootstrap: 469.882s -> 474.787s (1.04%)
Artifact size: 400.35 MiB -> 400.33 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 23, 2026
@camsteffen
camsteffen force-pushed the fold-with-default branch 2 times, most recently from 80eb019 to 14eda03 Compare August 25, 2026 22:16
Comment thread compiler/rustc_type_ir/src/fold.rs Outdated
@@ -94,7 +94,19 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> + Clone {
///
/// Same as [`TypeFoldable::try_fold_with`], but not fallible. Make sure to keep
/// the behavior in sync across functions.

@camsteffen camsteffen Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I should probably delete this sentence.

View changes since the review

Comment thread compiler/rustc_type_ir/src/fold.rs Outdated
/// the behavior in sync across functions.
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self;
#[inline]
#[cfg(feature = "nightly")] // for `final`

@fmease fmease Aug 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's not sufficient unfortunately. final like all recent unstable syntax is gated pre-expansion, meaning this will still lead to a feature gate error if feature = "nightly" is not set.

Since we're now building+testing (a subset of?) rust-analyzer in CI (which uses the stable version of this crate), this should also manifest itself as a CI failure soon IINM.

In https://github.com/rust-lang/rust/pull/159584/changes#r3838787968 I did indeed mean "identity macro" (cf. first part of #154045's description).

View changes since the review

@fmease

fmease commented Aug 25, 2026

Copy link
Copy Markdown
Member

@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 Aug 25, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
Add default to `TypeFoldable::fold_with`
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ca257ee (ca257eeeac9753a2e07ff38cbe1e2e8204a7c4f4)
Base parent: 787af2b (787af2b8c80638c51a4fc8e44f84e6891f243ec7)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ca257ee): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@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 ❌
(primary)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
0.6% [0.2%, 1.2%] 12
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.3%, 0.4%] 3

Max RSS (memory usage)

Results (primary 3.3%, secondary -2.0%)

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

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

Cycles

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

Binary size

Results (secondary -0.0%)

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

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

Bootstrap: 474.247s -> 477.756s (0.74%)
Artifact size: 402.66 MiB -> 402.68 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 26, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

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.

@rust-bors

rust-bors Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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