Skip to content

Conversation

@rwardd
Copy link
Contributor

@rwardd rwardd commented Jan 1, 2026

Adds tests to check the output of the different ways of writing Option::or

Fixes #124533

@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 Jan 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2026

Mark-Simulacrum is not on the review rotation at the moment.
They may take a while to respond.

@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2026

r? @Mark-Simulacrum

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

@rwardd rwardd force-pushed the rwardd/option_or_codegen_tests branch from 1612a70 to 80acf74 Compare January 1, 2026 11:58
@scottmcm
Copy link
Member

scottmcm commented Jan 1, 2026

r? scottmcm

@rustbot rustbot assigned scottmcm and unassigned Mark-Simulacrum Jan 1, 2026
Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Thanks for picking up this work!

Looking mostly good; I left some comments. The DAG one I do feel reasonably strongly about. The others think about and feel free to push back if you think otherwise.

View changes since this review

@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 Jan 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rwardd
Copy link
Contributor Author

rwardd commented Jan 2, 2026

The DAG one I do feel reasonably strongly about. The o

Thank you very much for the valuable feedback - I agree with all the comments, and have attempted to address and implement all of it. I have two further questions:

  1. If/when this PR gets approved, are you happy if the same style is followed to build out the Option::and and Result::{and, or} tests? E.g., have multiple functions for the different forms of the operation, and test them against the three types (u8, [u8; 1], NonZero<u8>) as was done in this PR?

  2. Is there value in writing tests for larger types (e.g. u64, [u64; 1] ...)? I am cognisant of keeping tests minimal as stated in the Best Practices section, and don't want to inflate the tests if they are superfluous.

Thanks again!

@rwardd
Copy link
Contributor Author

rwardd commented Jan 2, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 2, 2026
@scottmcm
Copy link
Member

scottmcm commented Jan 2, 2026

  1. Yes, this same style makes sense to me.
  2. Unless there's a particular reason to think they'll do something different, I'd prefer fewer tests overall. LLVM support arbitrary-sized integer types (even i40 and such), which means it's usually pretty reliable at not doing something different just because it's a wider integer type. If you play around and notice a difference that's interesting, then sure, but hopefully the "what's the BackendRepr variant of the option" coverage is getting the interesting differences and thus different widths (or floats, or ...) aren't interesting enough to bother testing separately. (Unless, of course, someone finds an issue about them.)

Comment on lines 124 to 128
pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> {
// CHECK: start:
// CHECK-NEXT: [[NOT_A:%.*]] = icmp eq i8 %0, 0
// CHECK-NEXT: select i1 [[NOT_A]], i8 %optb, i8 %0
// ret i8
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding these! Nice to see the argument names and such too, since it's short so that's not a big deal.

But that ret on its own isn't actually checking anything. How about, instead,

Suggested change
pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> {
// CHECK: start:
// CHECK-NEXT: [[NOT_A:%.*]] = icmp eq i8 %0, 0
// CHECK-NEXT: select i1 [[NOT_A]], i8 %optb, i8 %0
// ret i8
pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> {
// CHECK: start:
// CHECK: [[NOT_A:%.+]] = icmp eq i8 %0, 0
// CHECK: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %0
// CHECK: ret i8 [[R]]

Since naming the values means that we're not concerned about other things showing up in the middle, and thus don't need to use the -NEXT that the ones looking at just the instructions do.

Copy link
Member

Choose a reason for hiding this comment

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

(And of course ditto the others below)

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Another round of suggestions 🙃

The most important one is about the un-CHECKed ret comments, but ponder the others as well.

Thanks for making the previous updates! Hopefully these are the last things I'll think of.

View changes since this review

@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 Jan 2, 2026
@rwardd
Copy link
Contributor Author

rwardd commented Jan 3, 2026

@rustbot ready

Thank you very much again for feedback (and patience!). I've implemented all the suggestions (specifically ensuring all ret comments are actually CHECKed), and gone ahead and extended some of the existing CHECKs to be more explicit with argument naming and return values.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different ways of writing Option::or codegen differently

5 participants