-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[perf] cache type info for ParamEnv #123058
Conversation
compiler/rustc_middle/src/ty/list.rs
Outdated
let data_ptr = ptr::addr_of!(self.skel.data).cast::<T>(); | ||
// SAFETY: `data_ptr` has the same provenance as `self` and can therefore | ||
// access the `self.len` elements stored at `self.data`. | ||
// Note that we specifically don't reborrow `&self.skel.data`, because that | ||
// would give us a pointer with provenance over 0 bytes. | ||
unsafe { slice::from_raw_parts(data_ptr, self.skel.len) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was UB before.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
[perf] cache type info for ParamEnv This is an attempt to mitigate some of the perf regressions in rust-lang#122553 (comment), but seems worth to test and land separately. r? `@ghost`
💥 Test timed out |
uuh idk what bors is on about, the artifact looks like it got built? Let's try this: ☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
well that worked i guess? |
Finished benchmarking commit (be2a772): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking 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 @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 672.58s -> 671.55s (-0.15%) |
The regression in The regressions in r? @lcnr or compiler |
☔ The latest upstream changes (presumably #123098) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #123327) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler/rustc_middle/src/ty/list.rs
Outdated
#[repr(C)] | ||
pub struct ListWithCachedTypeInfo<T> { | ||
skel: ListWithCachedTypeInfoSkeleton<T>, | ||
opaque: OpaqueListContents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is that moved out of ListSkeleton
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because accessing a field with an extern type tail will always panic, because we don't know the align of the extern type and therefore the padding before the field. So basically if we just put List
as the tail of ListWithCachedTypeInfo
, then any attempt to access the list will panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that does not seem right to me 🤔 it should be totally fine to access an unsized field which contains an extern type as long as you never try to do a place-to-value conversion. I don't think we should ever copy ListSkeleton
to the stack. Which use of ListSkeleton
causes issues if you keep the current setup of having OpaqueListContents
as a field of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm apparently there is a special case if the field with an extern type tail is the only field. Which i guess makes sense since there can't be any padding in that case. If you change the outer type to have some extra data, your example will panic: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=92bafecde22b9fd72a3ddb9d9018bc68
I don't think we should ever copy
ListSkeleton
to the stack
I agree. If my code does that it's not intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments to the *Skeleton
types to hopefully clear this up a bit.
Relevant diff: /~https://github.com/rust-lang/rust/compare/c4f1f7aa586451154c669711abc9c4d9ad9b1075..fcc477fbd0871d8fab045bd7e9524172ab10e51c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after explaining the changes in ty/list.rs
to me 🤔
c4f1f7a
to
2cdccba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 the panic with extern types is annoying, but I understand the issue now.
Looking at this again, we now duplicate the unsafe code for List
which is somewhat intricate and I am a bit worried that it ends up getting out of sync. Could we instead have a single type:
struct RawList<H, T> {
header: H,
length: usize,
data: [T; 0],
opaque: OpaqueListConten,
}
This should avoid both the "extern type alignment" issue and aloows us to remove the code duplication.
Sorry for not thinking of that during the first review round 😅
@bors r+ rollup=never |
☀️ Test successful - checks-actions |
Finished benchmarking commit (087ae97): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.732s -> 668.846s (-0.13%) |
I stumbled across this today while looking at |
There are some functions in the trait solver that use the For example here we disable caching here if the where clauses contain inference variables (which can happen due to canonicalization).
Or here we find out whether inference has happened on the where clauses by resolving the inference variables. This has a shortcut if there are no inference variables.
Before this PR, the
So to find out the type flags or outer binder of the whole The main thing this PR does is add
This way, we can compute e.g.
|
Thanks for the explanation. In this bit:
are the |
Exactly. The flags of the list is the bit-or of all the flags from the clauses and the outer binder of the list is the maximum of the outer binders of the clauses. They are computed when the rust/compiler/rustc_middle/src/ty/context.rs Lines 406 to 412 in 1189851
rust/compiler/rustc_middle/src/ty/flags.rs Lines 38 to 45 in 1189851
|
This is an attempt to mitigate some of the perf regressions in #122553 (comment), but seems worth to test and land separately, since it is mostly unrelated to that PR.