Skip to content
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

Don't transmute &List<GenericArg> <-> &List<Ty> #110496

Merged
merged 3 commits into from
Apr 19, 2023

Conversation

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented Apr 18, 2023

In #93505 we allowed safely transmuting between &List<GenericArg<'_>> and &List<Ty<'_>>. This was possible because GenericArg is a tagged pointer and the tag for types is 0b00, such that a GenericArg with a type inside has the same layout as Ty.

While this was meant as an optimization, it doesn't look like it was actually any perf or max-rss win (see #94799 (comment), #94841, #110496 (comment)).

Additionally the way it was done is quite fragile — unsafe code was not properly documented or contained in a module, types were not marked as repr(C) (making the transmutes possibly unsound). All of this makes the code maintenance harder and blocks other possible optimizations (as an example I've found out about these transmutes when my change caused them to sigsegv compiler).

Thus, I think we can safely (pun intended) remove those transmutes, making maintenance easier, optimizations possible, code less cursed, etc.

r? @compiler-errors

@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 Apr 18, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@WaffleLapkin
Copy link
Member 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 Apr 18, 2023
@bors
Copy link
Contributor

bors commented Apr 18, 2023

⌛ Trying commit 10ec03c with merge 6156b93350a5f3c622e7eec405ce70b7f72da35f...

@compiler-errors compiler-errors changed the title 🏳️‍⚧️sound Don't transmute &List<GenericArg> <-> &List<Ty> Apr 18, 2023
@compiler-errors
Copy link
Member

(sorry, i like the title but it has nothing to do with what the pr's actually doing, so i changed it 😅)

@WaffleLapkin WaffleLapkin marked this pull request as draft April 18, 2023 18:20
@bors
Copy link
Contributor

bors commented Apr 18, 2023

☀️ Try build successful - checks-actions
Build commit: 6156b93350a5f3c622e7eec405ce70b7f72da35f (6156b93350a5f3c622e7eec405ce70b7f72da35f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6156b93350a5f3c622e7eec405ce70b7f72da35f): comparison URL.

Overall result: ✅ improvements - 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 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)
-2.0% [-2.8%, -0.7%] 3
Improvements ✅
(secondary)
-5.2% [-7.4%, -0.3%] 5
All ❌✅ (primary) -2.0% [-2.8%, -0.7%] 3

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)
1.9% [1.9%, 1.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-3.3%, -0.5%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-3.3%, 1.9%] 5

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)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.2% [-9.0%, -3.1%] 3
All ❌✅ (primary) - - 0

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 18, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Apr 18, 2023

cool, r=me

Seems from the PR that seldom in practice do we ever need to interconvert between SubstsRef and List<Ty>, and it seems not worth the complication or additional unsafe transmutes in the compiler.

@WaffleLapkin
Copy link
Member Author

what

@WaffleLapkin
Copy link
Member Author

Well, that's cool with me, I'll cleanup & r=errs tomorrow.

@compiler-errors
Copy link
Member

cc #94799 (comment)
cc #93505
cc #94841

Seems like it may have already been understood that this transmute wasn't really saving much perf in reality. Seems like max-rss isn't affected either. Lgtm.

@WaffleLapkin WaffleLapkin marked this pull request as ready for review April 19, 2023 08:37
@WaffleLapkin
Copy link
Member Author

@bors r=compiler-errors rollup-

@bors
Copy link
Contributor

bors commented Apr 19, 2023

📌 Commit 10ec03c has been approved by compiler-errors

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 Apr 19, 2023
@WaffleLapkin

This comment was marked as resolved.

@WaffleLapkin
Copy link
Member Author

@bors rollup=never

@bors
Copy link
Contributor

bors commented Apr 19, 2023

⌛ Testing commit 10ec03c with merge df0d9b4...

@bors
Copy link
Contributor

bors commented Apr 19, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing df0d9b4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 19, 2023
@bors bors merged commit df0d9b4 into rust-lang:master Apr 19, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 19, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (df0d9b4): comparison URL.

Overall result: ❌✅ regressions and 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)
3.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.5% [-1.5%, -1.5%] 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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.9%] 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)
- - 0
Regressions ❌
(secondary)
4.4% [4.4%, 4.4%] 2
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-2.8%, -2.8%] 1

@WaffleLapkin WaffleLapkin deleted the 🏳️‍⚧️sound branch April 20, 2023 12:59
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 20, 2023
…nsmutes, r=compiler-errors

Remove an unused `&[Ty]` <-> `&[GenericArg]`

Missed this one in rust-lang#110496, oops.

r? `@compiler-errors`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Apr 22, 2023
…errors

Stable hash tag (discriminant) of `GenericArg`

This is a continuation of my quest of removing `transmute` if generic args and types (rust-lang#110496, rust-lang#110599).

r? `@compiler-errors`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Apr 23, 2023
Don't transmute `&List<GenericArg>` <-> `&List<Ty>`

In #93505 we allowed safely transmuting between `&List<GenericArg<'_>>` and `&List<Ty<'_>>`. This was possible because `GenericArg` is a tagged pointer and the tag for types is `0b00`, such that a `GenericArg` with a type inside has the same layout as `Ty`.

While this was meant as an optimization, it doesn't look like it was actually any perf or max-rss win (see rust-lang/rust#94799 (comment), rust-lang/rust#94841, rust-lang/rust#110496 (comment)).

Additionally the way it was done is quite fragile — `unsafe` code was not properly documented or contained in a module, types were not marked as `repr(C)` (making the transmutes possibly unsound). All of this makes the code maintenance harder and blocks other possible optimizations (as an example I've found out about these `transmutes` when my change caused them to sigsegv compiler).

Thus, I think we can safely (pun intended) remove those transmutes, making maintenance easier, optimizations possible, code less cursed, etc.

r? `@compiler-errors`
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.

5 participants