Skip to content
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

Fixed ICEs with pattern matching in const expression #41055

Merged

Conversation

ryan-scott-dev
Copy link
Contributor

@ryan-scott-dev ryan-scott-dev commented Apr 4, 2017

Fixed 2 ICEs with when pattern matching inside a constant expression.

Both of these ICEs now resolve to an appropriate compiler error.

  1. ICE was caused by a compiler bug to implement discriminant const qualify.

    I removed this intentionally thrown bug and changed it to a FIXME as the unimplemented expression type is handled as a compiler error elsewhere.

  2. ICE was caused during a drop check when checking if a variable lifetime outlives the current scope if there was no parent scope .

    I've changed it to stop checking if there is no parent scope for the current scope. It is valid syntax for a const variable to be assigned a match expression with no enclosing scope.

    The ICE seemed to mainly be used as a defensive check for bugs elsewhere.

Fixes #38199.
Fixes #31577.
Fixes #29093.
Fixes #40012.

@rust-highfive
Copy link
Collaborator

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

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@ryan-scott-dev ryan-scott-dev changed the title Fixed ICEs with pattern matching in const fn. Fixes #38199, fixes #31… Fixed ICEs with pattern matching in const expression Apr 4, 2017
if self.mode != Mode::Fn {
bug!("implement discriminant const qualify");
}
// Discriminants in consts will error elsewhere as an unimplemented expression type
Copy link
Contributor

@arielb1 arielb1 Apr 4, 2017

Choose a reason for hiding this comment

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

You are not calling .not_const() because we report an error for the SwitchInt terminator too? I don't think there is any way of it getting split from its Discriminant now before qualify_consts, but it sounds like we want some other way to avoid duplicate errors.

Maybe have not_const keep a (per-function) HashSet of spans?

Or maybe just not set NOT_CONST and implement Discriminant in trans::mir::consts?

@arielb1
Copy link
Contributor

arielb1 commented Apr 4, 2017

r+ if you make Rvalue::Discriminant a valid const, even if you don't impl it in trans.

@brson
Copy link
Contributor

brson commented Apr 4, 2017

Awesome fixes for old ices @Archytaus!

@ryan-scott-dev
Copy link
Contributor Author

r+ if you make Rvalue::Discriminant a valid const, even if you don't impl it in trans.

@arielb1 To clarify, do you mean making it valid by removing self.add(Qualif::NOT_CONST); and the comments?

I wouldn't mind trying to implement it in trans, but I would be taking my time learning how that part of the compiler works. So I would want to do that in another PR if possible.

@arielb1
Copy link
Contributor

arielb1 commented Apr 6, 2017

@Archytaus

Yup. Remove the self.add(Qualif::NOT_CONST);. We should have MIRI soon enough, so you don't really need to implement it in trans.

@arielb1
Copy link
Contributor

arielb1 commented Apr 8, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Apr 8, 2017

📌 Commit c9932b3 has been approved by arielb1

@bors
Copy link
Contributor

bors commented Apr 8, 2017

⌛ Testing commit c9932b3 with merge a610117...

bors added a commit that referenced this pull request Apr 8, 2017
…, r=arielb1

Fixed ICEs with pattern matching in const expression

Fixed 2 ICEs with when pattern matching inside a constant expression.

Both of these ICEs now resolve to an appropriate compiler error.

1. ICE was caused by a compiler bug to implement discriminant const qualify.

    I removed this intentionally thrown bug and changed it to a FIXME as the unimplemented expression type is handled as a compiler error elsewhere.

2. ICE was caused during a drop check when checking if a variable lifetime outlives the current scope if there was no parent scope .

    I've changed it to stop checking if there is no parent scope for the current scope. It is valid syntax for a const variable to be assigned a match expression with no enclosing scope.

    The ICE seemed to mainly be used as a defensive check for bugs elsewhere.

Fixes #38199.
Fixes #31577.
Fixes #29093.
Fixes #40012.
@bors
Copy link
Contributor

bors commented Apr 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing a610117 to master...

@bors bors merged commit c9932b3 into rust-lang:master Apr 8, 2017
@ryan-scott-dev ryan-scott-dev deleted the compile-fail/const-match-pattern-arm branch April 12, 2017 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants