Skip to content

Looser check for overflowing_binary_op #91856

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Dec 15, 2021
Merged

Looser check for overflowing_binary_op #91856

merged 5 commits into from
Dec 15, 2021

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Dec 13, 2021

Fix for issue #91636 tight check resulted in ICE, this makes the check a little looser. It seems eq allows comparing of supertype and subtype if lhs = supertype and rhs = subtype but not vice versa, is this intended behavior ?

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 13, 2021
@rust-highfive
Copy link
Contributor

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cjgillot (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 13, 2021
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2021

Higher kinded lifetimes strike again... I think the real fix would be to use the subtyping infra, but that could be rather expensive for such a common op. Although it short circuits on type equality, so it should be cheap most of the time

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 13, 2021

Higher kinded lifetimes strike again... I think the real fix would be to use the subtyping infra, but that could be rather expensive for such a common op. Although it short circuits on type equality, so it should be cheap most of the time

I tried other things to fix this but they broke a lot of stuff 😸 I will look at subtyping infra, thanks!

@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2021

I think something like tcx.at(span).sub(rhs.ty, lhs.ty).is_ok() should work

@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2021

Or maybe check how mir validation does it, tho I fear it just bails out on such lifetimes

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 13, 2021

Or maybe check how mir validation does it, tho I fear it just bails out on such lifetimes

I think because of coercion mir gives up. As I posted in the issue if I use println! program compiles but there are bunch of MIR errors.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2021

OK, I guess if the subtyping check works here, we should make mir validation use it, too?

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 13, 2021

Again for such a small case wouldn't adding an extra layer of subtyping check make it slow ? 😕

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 13, 2021

I think something like tcx.at(span).sub(rhs.ty, lhs.ty).is_ok() should work

Also tcx.at(span) doesn't have sub method did you meant infcx ?

@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2021

Oh... I did... yea... spawning an infcx is serious overkill...

OK, let's keep the PR as it is, doing the real check is too expensive for CTFE

@RalfJung that ok with you?

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned cjgillot Dec 13, 2021
@RalfJung
Copy link
Member

OK, I guess if the subtyping check works here, we should make mir validation use it, too?

I think MIR validation currently doesn't check much about operators (unary and binary alike), so that sounds like a separate PR to me.

@@ -330,7 +330,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
_ if left.layout.ty.is_any_ptr() => {
// The RHS type must be the same *or an integer type* (for `Offset`).
Copy link
Member

Choose a reason for hiding this comment

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

Please update this comment, adding a link to #91636.

@RalfJung
Copy link
Member

Yeah I am fine with this change. I proposed it. :)

@ouz-a could you add #91636 (comment) add a regression test? Other than that and the comment nit I raised, this looks good to me!

@ouz-a
Copy link
Contributor Author

ouz-a commented Dec 13, 2021

Going to update the comment and add a regression test. Thanks!

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 14, 2021

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 14, 2021

📌 Commit b85762f has been approved by oli-obk

@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 Dec 14, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Dec 14, 2021

@bors rollup

@@ -328,9 +328,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.binary_int_op(bin_op, l, left.layout, r, right.layout)
}
_ if left.layout.ty.is_any_ptr() => {
// The RHS type must be the same *or an integer type* (for `Offset`).
// The RHS type must be a `pointer` *or an integer type* (for `Offset`).
// (This is workaround for the issue #91636)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// (This is workaround for the issue #91636)
// (Even when both sides are pointers, their type might differ, see issue #91636)

@RalfJung
Copy link
Member

Comment nit
@bors r-

@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 Dec 14, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Dec 14, 2021

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 14, 2021

📌 Commit a5054e3 has been approved by oli-obk

@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 Dec 14, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#89825 (Make split_inclusive() on an empty slice yield an empty output)
 - rust-lang#91239 (regression test for issue 87490)
 - rust-lang#91597 (Recover on invalid operators `<>` and `<=>`)
 - rust-lang#91774 (Fix typo for MutVisitor)
 - rust-lang#91786 (Return an error when `eval_rvalue_with_identities` fails)
 - rust-lang#91798 (Avoid suggest adding `self` in visibility spec)
 - rust-lang#91856 (Looser check for overflowing_binary_op)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bae9270 into rust-lang:master Dec 15, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 15, 2021
bors added a commit to rust-lang/miri that referenced this pull request Dec 15, 2021
add regression test

Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
bors added a commit to rust-lang/miri that referenced this pull request Dec 15, 2021
add regression test

Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
bors added a commit to rust-lang/miri that referenced this pull request Dec 15, 2021
add regression test

Adds a regression test for rust-lang/rust#91636 (which was fixed by rust-lang/rust#91856)
# for free to join this conversation on GitHub. Already have an account? # 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.

8 participants