Skip to content

Add 0..=isize::MAX range metadata to size loads from vtables #105446

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

Merged
merged 2 commits into from
Dec 19, 2022

Conversation

erikdesjardins
Copy link
Contributor

This is the (much belated) size counterpart to #91569.

Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often.

Miri detects this UB already:

if size >= self.tcx.data_layout.obj_size_bound() {
throw_ub!(InvalidVtableSize);
}

(In fact Miri goes further, assuming a 48-bit address space on 64-bit platforms, but I don't think we can assume that in an optimization.)

@rustbot
Copy link
Collaborator

rustbot commented Dec 8, 2022

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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. labels Dec 8, 2022
@nikic
Copy link
Contributor

nikic commented Dec 8, 2022

@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 Dec 8, 2022
@bors
Copy link
Collaborator

bors commented Dec 8, 2022

⌛ Trying commit a99e97a with merge 1e9be934e289bcfe6465db23c6e5cdbd94078d7c...

@bors
Copy link
Collaborator

bors commented Dec 8, 2022

☀️ Try build successful - checks-actions
Build commit: 1e9be934e289bcfe6465db23c6e5cdbd94078d7c (1e9be934e289bcfe6465db23c6e5cdbd94078d7c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1e9be934e289bcfe6465db23c6e5cdbd94078d7c): comparison URL.

Overall result: no relevant changes - no action needed

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.

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

Instruction count

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

Max RSS (memory usage)

Results

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

Cycles

Results

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)
1.0% [0.9%, 1.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.0% [0.9%, 1.2%] 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 8, 2022
@petrochenkov
Copy link
Contributor

r? @nikic

@rustbot rustbot assigned nikic and unassigned petrochenkov Dec 18, 2022
@nikic
Copy link
Contributor

nikic commented Dec 18, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 18, 2022

📌 Commit e01d944 has been approved by nikic

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 18, 2022
@bors
Copy link
Collaborator

bors commented Dec 18, 2022

⌛ Testing commit e01d944 with merge 2b094b1...

@bors
Copy link
Collaborator

bors commented Dec 19, 2022

☀️ Test successful - checks-actions
Approved by: nikic
Pushing 2b094b1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 19, 2022
@bors bors merged commit 2b094b1 into rust-lang:master Dec 19, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 19, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2b094b1): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

Max RSS (memory usage)

Results

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)
1.8% [1.2%, 2.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 3
All ❌✅ (primary) - - 0

Cycles

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

@erikdesjardins erikdesjardins deleted the vt-size branch December 19, 2022 15:50
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Add 0..=isize::MAX range metadata to size loads from vtables

This is the (much belated) size counterpart to rust-lang#91569.

Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often.

Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121
(In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants