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

Change the return type of Ty::kind from &TyKind to TyKind. #126069

Closed
wants to merge 1 commit into from

Conversation

nnethercote
Copy link
Contributor

This is valid because TyKind impls Copy, and makes Ty consistent with Predicate and Region, both of which have kind methods that return a non-reference.

The change removes more than one thousand & and * sigils, while requiring the addition of just five! It's clearly moving with the grain of the existing code.

Almost all of the removed sigils fit one of the following three patterns.

  • Remove the dereference in the match expression:

    match *ty.kind() { ... } ->
    match ty.kind() { ... }

  • Remove the dereference in the match pattern:

    match ty.kind() { &ty::Foo(foo) => { ... foo ... } ->
    match ty.kind() { ty::Foo(foo) => { ... foo ... }

  • Remove the derefernce in the match arm:

    match ty.kind() { ty::Foo(foo) => { ... *foo ... } ->
    match ty.kind() { ty::Foo(foo) => { ... foo ... }

A couple of other methods had their signatures changed.

  • TypeErrCtxt::cmp_fn_sig: & removed from two args.
  • EncodableWithShorthand::variant: & removed from return type.

r? @ghost

@rustbot rustbot added 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Jun 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in match lowering

cc @Nadrieril

The Miri subtree was changed

cc @rust-lang/miri

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Some changes occurred in match checking

cc @Nadrieril

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in exhaustiveness checking

cc @Nadrieril

HIR ty lowering was modified

cc @fmease

Some changes occurred in compiler/rustc_sanitizers

cc @rust-lang/project-exploit-mitigations, @rcvalle

Some changes occurred in need_type_info.rs

cc @lcnr

@nnethercote nnethercote marked this pull request as draft June 6, 2024 10:17
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Jun 6, 2024

this needs perf. I remember trying this previously and getting a performance regression

@lcnr lcnr changed the title Change the return type of Ty::kind from TyKind to &TyKind. Change the return type of Ty::kind from &TyKind to TyKind. Jun 6, 2024
@RalfJung
Copy link
Member

RalfJung commented Jun 6, 2024

The commit message still describes the change the wrong way around (lcnr fixed it in the PR title). I got quite confused due to that when reading the notification email. :)

@nnethercote
Copy link
Contributor Author

I really wish it was possible to mark a PR as a draft while creating it and not notifying everybody until it's in a non-draft state.

@lcnr
Copy link
Contributor

lcnr commented Jun 6, 2024

I really wish it was possible to mark a PR as a draft while creating it and not notifying everybody until it's in a non-draft state.

That should be possible 🤔 or do you mean something else?

image

@nnethercote
Copy link
Contributor 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 Jun 6, 2024
@bors
Copy link
Contributor

bors commented Jun 6, 2024

⌛ Trying commit 25e854a with merge b3b9397...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 6, 2024
Change the return type of `Ty::kind` from `&TyKind` to `TyKind`.

This is valid because `TyKind` impls `Copy`, and makes `Ty` consistent with `Predicate` and `Region`, both of which have `kind` methods that return a non-reference.

The change removes more than one thousand `&` and `*` sigils, while requiring the addition of just five! It's clearly moving with the grain of the existing code.

Almost all of the removed sigils fit one of the following three patterns.

- Remove the dereference in the match expression:

    `match *ty.kind() { ... }` ->
    `match ty.kind() { ... }`

- Remove the dereference in the match pattern:

    `match ty.kind() { &ty::Foo(foo) => { ... foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

- Remove the derefernce in the match arm:

    `match ty.kind() { ty::Foo(foo) => { ... *foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

A couple of other methods had their signatures changed.
- `TypeErrCtxt::cmp_fn_sig`: `&` removed from two args.
- `EncodableWithShorthand::variant`: `&` removed from return type.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Jun 6, 2024

☀️ Try build successful - checks-actions
Build commit: b3b9397 (b3b93972dc3a27bf8b67074e3e737a4a686bd669)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b3b9397): comparison URL.

Overall result: ❌ regressions - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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.4% [0.2%, 0.9%] 45
Regressions ❌
(secondary)
0.7% [0.4%, 1.2%] 36
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.2%, 0.9%] 45

Max RSS (memory usage)

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

Cycles

Results (secondary 3.2%)

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)
3.2% [3.1%, 3.4%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 672.761s -> 673.707s (0.14%)
Artifact size: 319.40 MiB -> 319.45 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 Jun 6, 2024
@mati865
Copy link
Contributor

mati865 commented Jun 6, 2024

I really wish it was possible to mark a PR as a draft while creating it and not notifying everybody until it's in a non-draft state.

That should be possible 🤔 or do you mean something else?

I think you can create easily make draft PR but rustbot won't distinguish it from "ready PR", or at least that used to be the case.

@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2024

going through my list of assigned PRs today.

@rustbot author

@rustbot rustbot 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 14, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

This is valid because `TyKind` impls `Copy`, and makes `Ty` consistent
with `Predicate` and `Region`, both of which have `kind` methods that
return a non-reference.

The change removes more than one thousand `&` and `*` sigils, while
requiring the addition of just five! It's clearly moving with the grain
of the existing code.

Almost all of the removed sigils fit one of the following three
patterns.

- Remove the dereference in the match expression:

    `match *ty.kind() { ... }` ->
    `match ty.kind() { ... }`

- Remove the dereference in the match pattern:

    `match ty.kind() { &ty::Foo(foo) => { ... foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

- Remove the derefernce in the match arm:

    `match ty.kind() { ty::Foo(foo) => { ... *foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

A couple of other methods had their signatures changed.
- `TypeErrCtxt::cmp_fn_sig`: `&` removed from two args.
- `EncodableWithShorthand::variant`: `&` removed from return type.
@nnethercote
Copy link
Contributor 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 Aug 14, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 14, 2024
Change the return type of `Ty::kind` from `&TyKind` to `TyKind`.

This is valid because `TyKind` impls `Copy`, and makes `Ty` consistent with `Predicate` and `Region`, both of which have `kind` methods that return a non-reference.

The change removes more than one thousand `&` and `*` sigils, while requiring the addition of just five! It's clearly moving with the grain of the existing code.

Almost all of the removed sigils fit one of the following three patterns.

- Remove the dereference in the match expression:

    `match *ty.kind() { ... }` ->
    `match ty.kind() { ... }`

- Remove the dereference in the match pattern:

    `match ty.kind() { &ty::Foo(foo) => { ... foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

- Remove the derefernce in the match arm:

    `match ty.kind() { ty::Foo(foo) => { ... *foo ... }` ->
    `match ty.kind() { ty::Foo(foo) => { ... foo ... }`

A couple of other methods had their signatures changed.
- `TypeErrCtxt::cmp_fn_sig`: `&` removed from two args.
- `EncodableWithShorthand::variant`: `&` removed from return type.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Aug 14, 2024

⌛ Trying commit bd3667d with merge 342c2c0...

@bors
Copy link
Contributor

bors commented Aug 14, 2024

☀️ Try build successful - checks-actions
Build commit: 342c2c0 (342c2c0d4f0bb38271cf24e102ffd76bc2e9bca5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (342c2c0): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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.5% [0.3%, 0.7%] 45
Regressions ❌
(secondary)
0.9% [0.3%, 1.9%] 50
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.2%] 12
All ❌✅ (primary) 0.5% [0.3%, 0.7%] 45

Max RSS (memory usage)

Results (secondary -3.1%)

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

Cycles

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

Binary size

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

Bootstrap: 751.474s -> 753.088s (0.21%)
Artifact size: 341.45 MiB -> 341.40 MiB (-0.01%)

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

I had hoped that shrinking TyKind in #128812 might have helped with the regression, but it didn't make much difference. I have filed #129110 to add a comment so that nobody else spends time trying this again in the future.

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Aug 16, 2024
…, r=jieyouxu

Add a comment explaining the return type of `Ty::kind`.

At least we'll get a useful comment out of rust-lang#126069 :)

r? `@lcnr`
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Aug 16, 2024
…, r=jieyouxu

Add a comment explaining the return type of `Ty::kind`.

At least we'll get a useful comment out of rust-lang#126069 :)

r? ``@lcnr``
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Aug 16, 2024
…, r=jieyouxu

Add a comment explaining the return type of `Ty::kind`.

At least we'll get a useful comment out of rust-lang#126069 :)

r? ```@lcnr```
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Aug 16, 2024
…, r=jieyouxu

Add a comment explaining the return type of `Ty::kind`.

At least we'll get a useful comment out of rust-lang#126069 :)

r? ````@lcnr````
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 16, 2024
Rollup merge of rust-lang#129110 - nnethercote:Ty-kind-ret-ty-comment, r=jieyouxu

Add a comment explaining the return type of `Ty::kind`.

At least we'll get a useful comment out of rust-lang#126069 :)

r? ````@lcnr````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants