Skip to content

codegen_ssa: replace a Result by an Either #143291

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
Jul 5, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jul 1, 2025

Err here clearly does not indicate an "error" of any sort, so the use of Result is confusing. Let's use a sum type that does not come with the baggage of Result.

@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

r? @saethlin

rustbot has assigned @saethlin.
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 Jul 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@workingjubilee
Copy link
Member

r? @scottmcm

@rustbot rustbot assigned scottmcm and unassigned saethlin Jul 1, 2025
@@ -648,9 +649,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
pub fn build(&self) -> OperandRef<'tcx, V> {
let OperandRef { val, layout } = *self;

let unwrap = |r: Result<V, abi::Scalar>| match r {
Ok(v) => v,
Err(_) => bug!("OperandRef::build called while fields are missing {self:?}"),
Copy link
Member

Choose a reason for hiding this comment

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

I'd used an Err here because in build it is an error.

An Either is fine too, so I don't mind doing this, but I'd really rather land #138759 that will conflict with this first, since it's approaching 4 months :/

Copy link
Member Author

Choose a reason for hiding this comment

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

I was mostly looking at the big match in insert_field, which looked like it was... finding errors and removing them? That doesn't look like a Result.

Some actual comments explaining what happens here with that sum type would have helped a lot but, not understanding the code I can't add those unfortunately. Would be great if you could. :)

An Either is fine too, so I don't mind doing this, but I'd really rather land #138759 that will conflict with this first, since it's approaching 4 months :/

Sure, this can wait.

Copy link
Member Author

Choose a reason for hiding this comment

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

#138759 landed, and I rebased :)

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

☔ The latest upstream changes (presumably #138759) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung force-pushed the result-isnt-either branch from 5cea731 to 1628a7c Compare July 5, 2025 07:06
@scottmcm
Copy link
Member

scottmcm commented Jul 5, 2025

Thanks for rebasing! The code change looks good to me
@bors r+

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

📌 Commit 1628a7c has been approved by scottmcm

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 Jul 5, 2025
@bors
Copy link
Collaborator

bors commented Jul 5, 2025

☔ The latest upstream changes (presumably #143473) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 5, 2025
@RalfJung RalfJung force-pushed the result-isnt-either branch from 1628a7c to 3fd85b3 Compare July 5, 2025 13:53
@RalfJung RalfJung force-pushed the result-isnt-either branch from 3fd85b3 to 3cd13f7 Compare July 5, 2025 13:54
@RalfJung
Copy link
Member Author

RalfJung commented Jul 5, 2025

@bors r=scottmcm rollup

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

📌 Commit 3cd13f7 has been approved by scottmcm

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 5, 2025
bors added a commit that referenced this pull request Jul 5, 2025
Rollup of 3 pull requests

Successful merges:

 - #143291 (codegen_ssa: replace a Result by an Either)
 - #143445 (move `va_copy`, `va_arg` and `va_end` to `core::intrinsics`)
 - #143447 ([COMPILETEST-UNTANGLE 4/N] Improve compiletest config documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 5, 2025
Let `rvalue_creates_operand` return true for *all* `Rvalue::Aggregate`s

Draft for now because it's built on Ralf's #143291

Inspired by #138759 (comment) where I noticed that we were nearly at this point, plus the comments I was writing in #143410 that reminded me a type-dependent `true` is fine.

This PR splits the `OperandRef::builder` logic out to a separate type, with the updates needed to handle SIMD as well.  In doing so, that makes the existing `Aggregate` path in `codegen_rvalue_operand` capable of handing SIMD values just fine.

As a result, we no longer need to do layout calculations for aggregate result types when running the analysis to determine which things can be SSA in codegen.
@bors bors merged commit 61bdd11 into rust-lang:master Jul 5, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 5, 2025
rust-timer added a commit that referenced this pull request Jul 5, 2025
Rollup merge of #143291 - RalfJung:result-isnt-either, r=scottmcm

codegen_ssa: replace a Result by an Either

`Err` here clearly does not indicate an "error" of any sort, so the use of `Result` is confusing. Let's use a sum type that does not come with the baggage of `Result`.
@RalfJung RalfJung deleted the result-isnt-either branch July 6, 2025 13:31
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