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

Mir tycheck aggregate rvalues #13

Conversation

Nashenas88
Copy link

@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?

@Nashenas88 Nashenas88 changed the title Mir tycheck aggregate rvalues for nll master Mir tycheck aggregate rvalues Nov 11, 2017
}
}

#[allow(dead_code)]
Copy link
Owner

Choose a reason for hiding this comment

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

why dead_code?

Copy link
Author

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 {
Copy link
Owner

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)]

Copy link
Author

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) => {
Copy link
Owner

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;
Copy link
Owner

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??
Copy link
Owner

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]
Copy link
Owner

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...

Copy link
Author

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]
Copy link
Owner

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 }
Copy link
Owner

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.

Copy link
Owner

@nikomatsakis nikomatsakis left a 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()) {
Copy link
Author

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?

@Nashenas88
Copy link
Author

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)
Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Owner

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.

@nikomatsakis
Copy link
Owner

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.

@nikomatsakis
Copy link
Owner

lunch-box. rustc --stage1 union-packed.rs  -Zdump-mir=all
error: internal compiler error: broken MIR in NodeId(61) (U { a: _1 }): [u8; 3] is not a subtype of u16: Sorts(ExpectedFound { expected: u16, found: [u8; 3] })
  --> union-packed.rs:39:15
   |
39 | const CU: U = U { b: [0, 0, 0] };
   |               ^^^^^^^^^^^^^^^^^^

@nikomatsakis
Copy link
Owner

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 (a) but in fact we are initializing with field 1. This seems bogus to me.

@nikomatsakis
Copy link
Owner

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 0? It seems like we're losing important information from the MIR (what interpretation the user assigned to).

@nikomatsakis
Copy link
Owner

Ah, I see now -- there is the active_field_index which stores the field we wanted.

@nikomatsakis
Copy link
Owner

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 nll-master branch.

@nikomatsakis nikomatsakis merged commit ad44d7e into nikomatsakis:nll-master Nov 12, 2017
@nikomatsakis
Copy link
Owner

Merged!

@Nashenas88 Nashenas88 deleted the mir-tycheck-aggregate-rvalues-for-nll-master branch November 12, 2017 14:20
nikomatsakis pushed a commit that referenced this pull request Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants