Skip to content

Conversation

camsteffen
Copy link
Contributor

@camsteffen camsteffen commented Jul 28, 2025

Changes impl_trait_header to panic on inherent impls intstead of returning None. A few downstream functions are split into option and non-option returning functions. This gets rid of a lot of unwraps where we know we have a trait impl, while there are still some cases where the Option is helpful.

Summary of changes to tcx methods:

  • impl_is_of_trait (new)
  • impl_trait_header -> impl_trait_header/impl_opt_trait_header
  • impl_trait_ref -> impl_trait_ref/impl_opt_trait_ref
  • trait_id_of_impl -> impl_trait_id/impl_opt_trait_id

@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

r? @jackh726

rustbot has assigned @jackh726.
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 A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

HIR ty lowering was modified

cc @fmease

@rust-log-analyzer

This comment has been minimized.

@lqd
Copy link
Member

lqd commented Jul 28, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jul 28, 2025
Limit impl_trait_header query to only trait impls
@rust-bors
Copy link

rust-bors bot commented Jul 28, 2025

⌛ Trying commit c4b4025 with merge a9207a1

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 28, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 28, 2025

💔 Test failed (CI). Failed jobs:

@camsteffen camsteffen force-pushed the impl-trait-header-option branch from c4b4025 to 35dbd1a Compare July 28, 2025 22:35
@camsteffen
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-bors
Copy link

rust-bors bot commented Jul 28, 2025

@camsteffen: 🔑 Insufficient privileges: not in try users

@rust-timer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@lqd
Copy link
Member

lqd commented Jul 29, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jul 29, 2025
Limit impl_trait_header query to only trait impls
@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

⌛ Trying commit 35dbd1a with merge 60b45cb

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

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

☀️ Try build successful (CI)
Build commit: 60b45cb (60b45cbaa7a7f0ea8340063c9bbac4ed081c245a, parent: cdccba87bf9ad5d87c1417eeb8fa52a4b614bbf9)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (60b45cb): comparison URL.

Overall result: ❌✅ regressions and improvements - BENCHMARK(S) FAILED

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

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

❗ ❗ ❗ ❗ ❗
Warning ⚠️: The following benchmark(s) failed to build:

  • eza-0.21.2
  • externs
  • include-blob
  • clap_derive-4.5.32
  • serde-1.0.219
  • wg-grammar
  • syn-2.0.101
  • unify-linearly
  • ucd
  • serde_derive-1.0.219
  • cranelift-codegen-0.119.0
  • regression-31157
  • diesel-2.2.10
  • bitmaps-3.2.1
  • hyper-1.6.0
  • ripgrep-14.1.1
  • tuple-stress
  • match-stress
  • ctfe-stress-5
  • derive
  • deeply-nested-multi
  • helloworld
  • unicode-normalization-0.1.24
  • wf-projection-stress-65510
  • coercions
  • stm32f4-0.15.1
  • issue-58319
  • html5ever-0.31.0
  • projection-caching
  • token-stream-stress
  • tt-muncher
  • serde-1.0.219-threads4
  • large-workspace
  • nalgebra-0.33.0
  • many-assoc-items
  • issue-46449
  • image-0.25.6
  • cargo-0.87.1
  • typenum-1.18.0
  • unused-warnings
  • await-call-tree
  • regex-automata-0.4.8
  • issue-88862
  • deep-vector
  • libc-0.2.172

❗ ❗ ❗ ❗ ❗

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)
2.4% [0.2%, 3.7%] 9
Regressions ❌
(secondary)
0.5% [0.4%, 0.5%] 3
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) 2.1% [-0.2%, 3.7%] 10

Max RSS (memory usage)

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

Cycles

Results (secondary -2.6%)

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)
-2.6% [-3.1%, -2.3%] 5
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 469.046s -> 466.887s (-0.46%)
Artifact size: 376.81 MiB -> 376.87 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 29, 2025
@camsteffen
Copy link
Contributor Author

camsteffen commented Jul 29, 2025

Y'all think that's funny? 😤

Fixed the rustdoc issues from above.

@camsteffen camsteffen force-pushed the impl-trait-header-option branch from c6eaf7f to 19fcf89 Compare October 13, 2025 20:19
@camsteffen
Copy link
Contributor Author

@rustbot ready -S-blocked

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Oct 13, 2025
@rust-lang rust-lang deleted a comment from rust-bors bot Oct 13, 2025
@rust-lang rust-lang deleted a comment from bors Oct 13, 2025
@fmease
Copy link
Member

fmease commented Oct 13, 2025

@bors2 delegate=try

@rust-bors
Copy link

rust-bors bot commented Oct 13, 2025

✌️ @camsteffen, you can now perform try builds on this pull request!

You can now post @bors2 try to start a try build.

@rust-lang rust-lang deleted a comment from rust-bors bot Oct 13, 2025
@rust-lang rust-lang deleted a comment from rust-bors bot Oct 13, 2025
@fmease
Copy link
Member

fmease commented Oct 13, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 13, 2025
Limit impl_trait_header query to only trait impls
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 13, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 13, 2025

☀️ Try build successful (CI)
Build commit: f97840c (f97840c763a3db50d44f28bf0073d58787a62f3b, parent: ed1d94311e7ed53eabb5667ef577802d88d1aaee)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f97840c): comparison URL.

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

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@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.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
0.1% [0.0%, 0.2%] 14
Improvements ✅
(primary)
-0.5% [-0.8%, -0.2%] 17
Improvements ✅
(secondary)
-1.8% [-2.6%, -0.1%] 4
All ❌✅ (primary) -0.5% [-0.8%, 0.2%] 18

Max RSS (memory usage)

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

Cycles

Results (secondary -4.3%)

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)
-4.3% [-5.7%, -3.4%] 4
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 473.894s -> 472.442s (-0.31%)
Artifact size: 388.15 MiB -> 388.12 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 14, 2025
@camsteffen
Copy link
Contributor Author

Yay! Consistent wins for rustc and some smaller regressions for doc. I think the doc regressions can be won back by continuing with more refactors to avoid the def_kind lookups, but I think that can be a follow-up and this is worth landing as is.

There are one or two things here that could be split out into smaller chunks if that is preferred but I'll leave it to the reviewer.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

didn't quite look into clippy yet, but a few nits

I quite like this change and think it's a nice improvement

I do feel like it would have been nice to initially simply rename the query to opt_impl_trait_ref and change impl_trait_ref to simply call that query and unwrap so that this change can be separately reviewed and merged.

View changes since this review

// Note: this cannot come from an inherent impl,
// because the first probing succeeded.
CandidateSource::Impl(def) => self.tcx.trait_id_of_impl(def),
CandidateSource::Impl(def) => self.tcx.impl_opt_trait_id(def),
Copy link
Contributor

Choose a reason for hiding this comment

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

given the note, this could just be impl_trait_id, should it nor?

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 wasn't totally sure but I'll give it a try.

CandidateSource::Trait(def_id) => def_id != info.def_id,
CandidateSource::Impl(def_id) => {
self.tcx.trait_id_of_impl(def_id) != Some(info.def_id)
self.tcx.impl_opt_trait_id(def_id) != Some(info.def_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this change from non-optional to optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trait_id_of_impl is optional. I'm not sure if it's safe to be non-optional.

}

fn trait_ref(&mut self) -> &mut Self {
self.in_primary_interface = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

... we set this to true here and don't reset it to false after... is this a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed odd to me too. I'm not really sure but several functions above this one do the same. self is unused after this function is called so I think I've preserved behavior.

Comment on lines 1706 to 1709
check.ty();
if of_trait {
check.trait_ref();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this pattern could be something like check.impl_header(of_trait) given that it's being repeated multiple times here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The patterns is repeated once but it's a different function being called. But I could do that to preserve the chaining?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a commit with this.

@lcnr lcnr assigned lcnr and unassigned jackh726 Oct 14, 2025
@camsteffen
Copy link
Contributor Author

camsteffen commented Oct 14, 2025

Replied and added some fixup commits that can be squashed.

I do feel like it would have been nice to initially simply rename the query to opt_impl_trait_ref and change impl_trait_ref to simply call that query and unwrap so that this change can be separately reviewed and merged.

Yeah that's fair. I did kinda do that with separate commits except I lumped in some changes to not use opt along with the rename. It seemed silly to do a simple rename that would leave opt().unwrap() so I guess I fixed those with the rename and then decided I may as well throw in more changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants