-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mir tycheck aggregate rvalues #13
Mir tycheck aggregate rvalues #13
Conversation
} | ||
} | ||
|
||
#[allow(dead_code)] |
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.
why dead_code
?
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.
I was writing check_rvalue
before I was using it and was trying to check the types. This is cleaned up in the latest commit.
let tcx = self.tcx(); | ||
match rv { | ||
Rvalue::Aggregate(ref ak, ref ops) => { | ||
match **ak { |
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.
Nit: you no longer need match **ak
, thanks to #[feature(match_default_bindings)]
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.
In the latest commit I still need to because this is a &Box
rather than &&
.
fn check_rvalue(&mut self, mir: &Mir<'tcx>, rv: &Rvalue<'tcx>, location: Location) { | ||
let tcx = self.tcx(); | ||
match rv { | ||
Rvalue::Aggregate(ref ak, ref ops) => { |
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.
Nit: ref
ought to be the default; we're matching on a reference
field_ty | ||
} else { | ||
// TODO(nashenas88) log span_mirbug terr?? | ||
continue; |
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.
Yes, I think span_mirbug
is appropriate here.
Operand::Constant(c) => c.ty, | ||
}; | ||
if let Err(_terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) { | ||
// TODO(nashenas88) log span_mirbug terr?? |
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.
Also here, span_mirbug
seems good.
let mut x = 22; | ||
let wrapper = Wrap { w: &mut x }; | ||
//~^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506] | ||
//~^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503] |
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.
Huh ,do we get errors here too? These seem bogus...
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.
These are actually ignored by the test. I accidentally left them in from the run before I added in revisions. It seems with revisions only comments beginning with a revision tag are looked at. These are gone in the latest commit.
x += 1; //[ast]~ ERROR cannot assign to `x` because it is borrowed [E0506] | ||
//[mir]~^ ERROR cannot assign to `x` because it is borrowed (Ast) [E0506] | ||
//[mir]~^^ ERROR cannot assign to `x` because it is borrowed (Mir) [E0506] | ||
//[mir]~^^^ ERROR cannot use `x` because it was mutably borrowed (Mir) [E0503] |
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.
But these seem correct.
|
||
#![allow(unused_assignments)] | ||
|
||
struct Wrap<'a> { w: &'a mut u32 } |
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.
Let's rename this test to compile-fail/nll/reference-carried-through-struct-field.rs
. Not sure what the best naming scheme is here, but at least in the nll
directory would be good.
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.
Left some requests for changes.
Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx), | ||
Operand::Constant(c) => c.ty, | ||
}; | ||
if let Err(terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) { |
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.
This line causes the follow error to occur during compilation:
Compiling core v0.0.0 (file:///home/paulf/rust2/src/libcore)
error: internal compiler error: broken MIR in NodeId(258966) (str::pattern::CharSearcher::{{constructor}}(_1,)): <str::pattern::CharEqPattern<char> as str::pattern::Pattern>::Searcher is not a subtype of str::pattern::CharEqSearcher<'_, _>: Sorts(ExpectedFound { expected: str::pattern::CharEqSearcher<'_, _>, found: <str::pattern::CharEqPattern<char> as str::pattern::Pattern>::Searcher })
--> src/libcore/str/pattern.rs:418:1
|
418 | pub struct CharSearcher<'a>(<CharEqPattern<char> as Pattern<'a>>::Searcher);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
Do I need to do additional work to get the types to match or is this a legitimate bug?
This is a fix for rust-lang#45889. |
}; | ||
let op_ty = match op { | ||
Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx), | ||
Operand::Consume(lv) => { | ||
self.normalize(&lv.ty(mir, tcx), location).to_ty(tcx) |
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.
Very interesting. It's not obvious to me why this is necessary, though it doesn't seem bad per se.
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.
OK, I see, it's needed only in the "shim MIR" that we construct -- e.g., the MIR that we build for the constructor of a type like struct Foo(X)
. In that code (librustc_mir/shim.rs
), we are not presently normalizing associated types as I would expect.
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.
I think we'll leave it like this but open a FIXME.
I limited normalizing of operand types to when we are within an ADT constructor. Interestingly, when running the tests, I found a problem in the type-checking of unions. I am now rebuilding so I can't readily reproduce it yet. |
|
Problem seems to be that for unions we don't remember the correct field number. If you look at the MIR, you'll see it assigns to field 0 of the union ( |
We do it very explicitly on purpose though. cc @petrochenkov -- can you shed any light on why we are mapping all union field indices to |
Ah, I see now -- there is the |
Pushed a fix for unions. Running tests now, but it's looking good. I expect to merge shortly, then I think I need to rebase the |
Merged! |
sync with rust-lang/rust
@nikomatsakis I still have a couple TODO comments left in there. What should I do for those error cases? Should I just place
span_mirbug
macro calls there like the other functions do?