Skip to content

In rustc_mir_transform, iterate over index newtypes instead of ints #139674

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 1 commit into from
Apr 14, 2025

Conversation

yotamofek
Copy link
Contributor

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 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 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk oli-obk changed the title In rustc_mir_tranform, iterator over index newtypes instead of ints In rustc_mir_transform, iterator over index newtypes instead of ints Apr 11, 2025
@jieyouxu

This comment was marked as resolved.

@rustbot rustbot assigned nnethercote and unassigned jieyouxu Apr 11, 2025
@yotamofek yotamofek changed the title In rustc_mir_transform, iterator over index newtypes instead of ints In rustc_mir_transform, iterate over index newtypes instead of ints Apr 11, 2025
@@ -1339,13 +1333,10 @@ fn create_coroutine_resume_function<'tcx>(

make_coroutine_state_argument_indirect(tcx, body);

match transform.coroutine_kind {
Copy link
Member

Choose a reason for hiding this comment

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

Change this back to a match and make it exhaustive, please.

!matches IMO makes it much easier to forget adding a variant in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this? It can be be even more exhaustive (i.e. on Movability and CoroutineSource)

Copy link
Member

Choose a reason for hiding this comment

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

This is good enough

@@ -1057,7 +1057,7 @@ fn insert_switch<'tcx>(
let blocks = body.basic_blocks_mut().iter_mut();

for target in blocks.flat_map(|b| b.terminator_mut().successors_mut()) {
Copy link
Member

Choose a reason for hiding this comment

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

can this be changed into a count?

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 loops over a bunch of BasicBlocks and increments each one, so something like *target += blocks.flat_map(..).count() would mean something completely different.
Unless I misunderstood you?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I'm blind, lol. I thought we were incrementing a counter, not incrementing a per-bb index.

@yotamofek yotamofek force-pushed the pr/mir_transform/index-iterators branch from 197dcb5 to c36e8fc Compare April 12, 2025 11:54
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 13, 2025

📌 Commit c36e8fc 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 13, 2025
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 13, 2025
…terators, r=compiler-errors

In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 13, 2025
…terators, r=compiler-errors

In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2025
…enton

Rollup of 12 pull requests

Successful merges:

 - rust-lang#138744 (Add methods to TCP and UDP sockets to modify hop limit (refresh of rust-lang#94678))
 - rust-lang#138962 (Expect an array when expected and acutal types are both arrays during cast)
 - rust-lang#139001 (add `naked_functions_rustic_abi` feature gate)
 - rust-lang#139379 (Use delayed bug for normalization errors in drop elaboration)
 - rust-lang#139582 (Various coercion cleanups)
 - rust-lang#139628 (Suggest remove redundant `$()?` around `vis`)
 - rust-lang#139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`)
 - rust-lang#139666 (cleanup `mir_borrowck`)
 - rust-lang#139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints)
 - rust-lang#139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout)
 - rust-lang#139722 (Move some things to rustc_type_ir)
 - rust-lang#139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 13, 2025
…terators, r=compiler-errors

In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2025
Rollup of 11 pull requests

Successful merges:

 - rust-lang#137043 (Initial `UnsafePinned` implementation [Part 1: Libs])
 - rust-lang#138962 (Expect an array when expected and acutal types are both arrays during cast)
 - rust-lang#139001 (add `naked_functions_rustic_abi` feature gate)
 - rust-lang#139379 (Use delayed bug for normalization errors in drop elaboration)
 - rust-lang#139582 (Various coercion cleanups)
 - rust-lang#139628 (Suggest remove redundant `$()?` around `vis`)
 - rust-lang#139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`)
 - rust-lang#139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file})
 - rust-lang#139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints)
 - rust-lang#139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test)
 - rust-lang#139741 (fix smir's run! doc and import)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#137043 (Initial `UnsafePinned` implementation [Part 1: Libs])
 - rust-lang#138962 (Expect an array when expected and acutal types are both arrays during cast)
 - rust-lang#139001 (add `naked_functions_rustic_abi` feature gate)
 - rust-lang#139379 (Use delayed bug for normalization errors in drop elaboration)
 - rust-lang#139582 (Various coercion cleanups)
 - rust-lang#139628 (Suggest remove redundant `$()?` around `vis`)
 - rust-lang#139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`)
 - rust-lang#139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints)
 - rust-lang#139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test)
 - rust-lang#139741 (fix smir's run! doc and import)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1b6fcd9 into rust-lang:master Apr 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2025
Rollup merge of rust-lang#139674 - yotamofek:pr/mir_transform/index-iterators, r=compiler-errors

In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
@yotamofek yotamofek deleted the pr/mir_transform/index-iterators branch April 14, 2025 16:21
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 14, 2025
…li-obk

Use `newtype_index!`-generated types more idiomatically

Continuation of sorts of rust-lang#139674
Shouldn't affect anything, just makes some code simpler
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 15, 2025
…li-obk

Use `newtype_index!`-generated types more idiomatically

Continuation of sorts of rust-lang#139674
Shouldn't affect anything, just makes some code simpler
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 15, 2025
Rollup merge of rust-lang#139811 - yotamofek:pr/newtype_cleanups, r=oli-obk

Use `newtype_index!`-generated types more idiomatically

Continuation of sorts of rust-lang#139674
Shouldn't affect anything, just makes some code simpler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants