Skip to content

Extract an arguments struct for Builder::then_else_break - #121928

Merged
bors merged 1 commit into
rust-lang:masterfrom
Zalathar:then-else-args
Mar 5, 2024
Merged

Extract an arguments struct for Builder::then_else_break#121928
bors merged 1 commit into
rust-lang:masterfrom
Zalathar:then-else-args

Conversation

@Zalathar

Copy link
Copy Markdown
Member

Most of this method's arguments are usually or always forwarded as-is to recursive invocations.

Wrapping them in a dedicated struct allows us to document each struct field, and lets us use struct-update syntax to indicate which arguments are being modified when making a recursive call.


While trying to understand the lowering of if expressions, I found it difficult to keep track of the half-dozen arguments passed through to every call to then_else_break. I tried switching over to an arguments struct, and I found that it really helps to make sense of what each argument does, and how each call is modifying the arguments.

I have some further ideas for how to streamline these recursive calls, but I've kept those out of this PR so that it's a pure refactoring with no behavioural changes.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @lcnr

rustbot has assigned @lcnr.
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

@rustbotrustbot 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 Mar 3, 2024
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in match lowering

cc @Nadrieril

@Zalathar

Copy link
Copy Markdown
MemberAuthor

All of the new comments are based on my own understanding, so they could certainly use a second opinion from someone more familiar with this code.

Comment threadcompiler/rustc_mir_build/src/build/matches/mod.rs Outdated
@Nadrieril

Copy link
Copy Markdown
Member

I have one comment, otherwise I think this is a net improvement in code legibility, thank you!

r? @Nadrieril

@rustbotrustbot assigned Nadrieril and unassigned lcnrMar 3, 2024
@Zalathar

Copy link
Copy Markdown
MemberAuthor

Updated to address feedback (diff).

Now all of the external callers are unchanged, except for some extra comments. The arguments struct is purely an internal detail of then_else_break_inner.

Comment threadcompiler/rustc_mir_build/src/build/expr/into.rs
Most of this method's arguments are usually or always forwarded as-is to
recursive invocations.
Wrapping them in a dedicated struct allows us to document each struct field,
and lets us use struct-update syntax to indicate which arguments are being
modified when making a recursive call.
@Nadrieril

Copy link
Copy Markdown
Member

Thank you!

@bors r+ rollup=always

@bors

bors commented Mar 4, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 4146136 has been approved by Nadrieril

It is now in the queue for this repository.

@borsbors 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 Mar 4, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 4, 2024
Extract an arguments struct for `Builder::then_else_break`
Most of this method's arguments are usually or always forwarded as-is to recursive invocations.
Wrapping them in a dedicated struct allows us to document each struct field, and lets us use struct-update syntax to indicate which arguments are being modified when making a recursive call.
---
While trying to understand the lowering of `if` expressions, I found it difficult to keep track of the half-dozen arguments passed through to every call to `then_else_break`. I tried switching over to an arguments struct, and I found that it really helps to make sense of what each argument does, and how each call is modifying the arguments.
I have some further ideas for how to streamline these recursive calls, but I've kept those out of this PR so that it's a pure refactoring with no behavioural changes.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2024
…llaumeGomez
Rollup of 9 pull requests
Successful merges:
- rust-lang#120976 (constify a couple thread_local statics)
- rust-lang#121576 (Convert the rest of the visitors to use `VisitorResult`)
- rust-lang#121826 (Use root obligation on E0277 for some cases)
- rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`)
- rust-lang#121958 (Fix redundant import errors for preload extern crate)
- rust-lang#121959 (Removing absolute path in proc-macro)
- rust-lang#121968 (Don't run test_get_os_named_thread on win7)
- rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.)
- rust-lang#121978 (Fix duplicated path in the "not found dylib" error)
r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 4, 2024
Extract an arguments struct for `Builder::then_else_break`
Most of this method's arguments are usually or always forwarded as-is to recursive invocations.
Wrapping them in a dedicated struct allows us to document each struct field, and lets us use struct-update syntax to indicate which arguments are being modified when making a recursive call.
---
While trying to understand the lowering of `if` expressions, I found it difficult to keep track of the half-dozen arguments passed through to every call to `then_else_break`. I tried switching over to an arguments struct, and I found that it really helps to make sense of what each argument does, and how each call is modifying the arguments.
I have some further ideas for how to streamline these recursive calls, but I've kept those out of this PR so that it's a pure refactoring with no behavioural changes.
This was referenced Mar 4, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2024
…iaskrgr
Rollup of 10 pull requests
Successful merges:
- rust-lang#120976 (constify a couple thread_local statics)
- rust-lang#121683 (Fix LVI tests after frame pointers are enabled by default)
- rust-lang#121703 (Add a way to add constructors for `rustc_type_ir` types)
- rust-lang#121732 (Improve assert_matches! documentation)
- rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`)
- rust-lang#121939 (Small enhancement to description of From trait)
- rust-lang#121968 (Don't run test_get_os_named_thread on win7)
- rust-lang#121969 (`ParseSess` cleanups)
- rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.)
- rust-lang#121994 (Update platform-support.md with supported musl version)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2024
…iaskrgr
Rollup of 10 pull requests
Successful merges:
- rust-lang#120976 (constify a couple thread_local statics)
- rust-lang#121683 (Fix LVI tests after frame pointers are enabled by default)
- rust-lang#121703 (Add a way to add constructors for `rustc_type_ir` types)
- rust-lang#121732 (Improve assert_matches! documentation)
- rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`)
- rust-lang#121939 (Small enhancement to description of From trait)
- rust-lang#121968 (Don't run test_get_os_named_thread on win7)
- rust-lang#121969 (`ParseSess` cleanups)
- rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.)
- rust-lang#121994 (Update platform-support.md with supported musl version)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 58a0f64 into rust-lang:masterMar 5, 2024
@rustbotrustbot added this to the 1.78.0 milestone Mar 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2024
Rollup merge of rust-lang#121928 - Zalathar:then-else-args, r=Nadrieril
Extract an arguments struct for `Builder::then_else_break`
Most of this method's arguments are usually or always forwarded as-is to recursive invocations.
Wrapping them in a dedicated struct allows us to document each struct field, and lets us use struct-update syntax to indicate which arguments are being modified when making a recursive call.
---
While trying to understand the lowering of `if` expressions, I found it difficult to keep track of the half-dozen arguments passed through to every call to `then_else_break`. I tried switching over to an arguments struct, and I found that it really helps to make sense of what each argument does, and how each call is modifying the arguments.
I have some further ideas for how to streamline these recursive calls, but I've kept those out of this PR so that it's a pure refactoring with no behavioural changes.
@Zalathar
Zalathar deleted the then-else-args branch March 5, 2024 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@Zalathar@rustbot@Nadrieril@bors@lcnr