Skip to content

Optimize offset_from_unsigned result bounds - #161063

Closed
SomeFlyingThing wants to merge 4 commits into
rust-lang:mainfrom
SomeFlyingThing:agent/offset-from-unsigned-bound
Closed

Optimize offset_from_unsigned result bounds#161063
SomeFlyingThing wants to merge 4 commits into
rust-lang:mainfrom
SomeFlyingThing:agent/offset-from-unsigned-bound

Conversation

@SomeFlyingThing

Copy link
Copy Markdown
Contributor

Hint that result cannot be larger than isize max

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 13, 2026
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 18 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jieyouxu

Copy link
Copy Markdown
Member

r? libs

@rustbot rustbot assigned clarfonthey and unassigned jieyouxu Aug 14, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

Seems reasonable. For lack of any niche-type APIs that represent this, it should be okay to add this assumption.

@bors r+

@rust-bors

rust-bors Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7dbde06 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Aug 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 14, 2026
…unsigned-bound, r=clarfonthey

Optimize offset_from_unsigned result bounds

Hint that result cannot be larger than isize max
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 14, 2026
…unsigned-bound, r=clarfonthey

Optimize offset_from_unsigned result bounds

Hint that result cannot be larger than isize max
@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #161089 (comment)

@bors try jobs=test-various

@rust-bors rust-bors Bot 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 Aug 14, 2026
@rust-bors

rust-bors Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#161092), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
…und, r=<try>

Optimize offset_from_unsigned result bounds


try-job: test-various
@rust-bors

rust-bors Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

💔 Test for f4b1164 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@clarfonthey

Copy link
Copy Markdown
Contributor

Not sure if spurious, will have to take a closer look later.

@clarfonthey

Copy link
Copy Markdown
Contributor

@rustbot review

@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 Aug 21, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

Finally getting back to this, confused why it passed CI in the PR but not on the rollup, but this is indeed a real issue. Running locally I also have a failure for the test that failed, tests/codegen-llvm/lib-optimizations/append-elements.rs.

So, @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 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

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

@nikic

nikic commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

cc @scottmcm because this seems like a bad idea for all the usual reasons.

@hanna-kruppe

Copy link
Copy Markdown
Contributor

In addition to all the reasons why adding assume and similar hints is usually a bad idea, I gotta ask @SomeFlyingThing -- did you use an LLM in creating this PR and/or #161071? As pointed out before in #160737 we don't generally accept LLM-assisted PRs without prior approval from reviewers, especially not for soundness-relevant changes.

@clarfonthey

Copy link
Copy Markdown
Contributor

So, given existing discussion and the breakage, I'm going to close this. Will list the various points separately.

First, per the repo's LLM policy we do at minimum require disclosure of LLM usage, and it appears you have submitted a few PRs post this policy being merged without disclosure despite LLM usage. (Evident by the agent/ branch name.) While this is not a formal moderation warning (I'm not a moderator), I want to make sure you know what the policy is going forward. In general, LLM-assisted PRs require prior approval from reviewers, and we rely on disclosure to enforce this.

Second, we do want to have a higher bar for approval on changes that just blanket-apply assert_unchecked in places, since it is not always a unilateral improvement; while it may increase performance in some places, it may overburden the optimizer in other places and make things worse. I was a bit overzealous in approving this since we didn't fully verify that this was a complete improvement despite the one codegen test.

Third, also just going on the second point, we generally prefer that performance improvements are based in benchmarks or other real data that indicates the improvement, not just guesses on invariants. So, rather than finding invariants that the optimizer cannot assume, we want to show cases where that non-assumption is leading to noticeably worse code.

So, with that said, I'm closing this for now.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 25, 2026
@scottmcm

Copy link
Copy Markdown
Member

Also see #123598 where I tried doing this previously -- notably inside the intrinsic which I think is better than in the rust code -- but it still was red in perf.

(The 64-bit only restriction here made me particularly skeptical, too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants