-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
turn on MIR construction unconditionally #28748
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
Oh, I meant to remove the "reachable" flags for matches. I can do that easily enough. |
done. |
#[stable(feature = "rust1", since = "1.0.0")] | ||
fn eq(&self, other: &ConstVal) -> bool { | ||
match (self, other) { | ||
(&Float(v1), &Float(v2)) => (v1.is_nan() && v2.is_nan()) || (v1 == v2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is v1.is_nan() && v2.is_nan()
really what you mean, as opposed to transmute<f64, u64>(v1) == transmute<f64, u64>(v2)
?
Hmm, interesting question. It's probably better to be more conservative, I agree. |
🎊 |
@alexcrichton huh, that confetti-ball renders looks more like an angry stormcloud to me. I was like "what did I do to make alex angry now?" |
😈 |
Hmm, on a checkout from yesterday, the #[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[repr(usize)]
pub enum E { A = 0, B = 1 }
impl E {
pub fn foo(x: usize) -> Self {
use self::E::{A, B};
const E_A: usize = A as usize;
const E_B: usize = B as usize;
match x {
E_A => A,
E_B => B,
_ => panic!("no match"),
}
}
} results in ICE:
The crater run you did, I assume it wasn't including the |
(The reason that I point this out on this ticket is just to warn that we do not seem to have been testing this pattern internally, if Update: and in fact the commit messages for the commit series on this PR gives me some hope that this problem is in fact addressed somewhere here, since this PR does something with respect to the handling of patterns and const-evaluation. Update 2: @nikomatsakis I will actually build rust with this PR locally and check whether it indeed does fix the test case I listed above. |
@pnkfelix that test case works on this branch. I did indeed revamp how constants are handled to just reuse more of the compiler's existing machinery. |
Note: -Z always build Mir is only used currently when bootstrapping, not
|
☔ The latest upstream changes (presumably #28742) made this pull request unmergeable. Please resolve the merge conflicts. |
9adce8d
to
c84f284
Compare
@nikomatsakis okay I've finished reviewing. Looks fine, assuming you squash some of the later commits into the appropriate earlier commits (i.e. the removal of the So r=me once that's done. |
various annoying edge cases
c84f284
to
5261441
Compare
and track which arms are reached (though in fact we don't make use of this right now -- we might later if we absorb the checking of patterns into MIR, as I would like)
if they represent the same constant; otherwise the match algorithm goes into infinite recursion when a pattern contains `NaN`
5261441
to
7e1e830
Compare
@bors r=pnkfelix |
📌 Commit 7e1e830 has been approved by |
I had to fix a few things. Notable changes: 1. I removed the MIR support for constants, instead falling back to the existing `ConstVal`. I still think we ought to reform how we handle constants, but it's not clear to me that the approach I was taking is correct, and anyway I think we ought to do it separately. 2. I adjusted how we handle bindings in matches: we now *declare* all the bindings up front, rather than doing it as we encounter them. This is not only simpler, since we don't have to check if a binding has already been declared, it avoids ICEs if any of the arms turn out to be unreachable. 3. I do MIR construction *after* `check_match`, because it detects various broken cases. I'd like for `check_match` to be subsumed by MIR construction, but we can do that as a separate PR (if indeed it makes sense). I did a crater run and found no regressions in the wild: https://gist.github.com/nikomatsakis/0038f90e10c8ad00f2f8
I had to fix a few things. Notable changes:
ConstVal
. I still think we ought to reform how we handle constants, but it's not clear to me that the approach I was taking is correct, and anyway I think we ought to do it separately.check_match
, because it detects various broken cases. I'd like forcheck_match
to be subsumed by MIR construction, but we can do that as a separate PR (if indeed it makes sense).I did a crater run and found no regressions in the wild: https://gist.github.com/nikomatsakis/0038f90e10c8ad00f2f8