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

Rollup of 8 pull requests #57823

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
763392c
Fix memory leak in P::filter_map
ishitatsuyuki Jan 16, 2019
13dc584
Merge visitors in AST validation
Zoxc Jan 18, 2019
eb5a253
When using value after move, point at span of local
estebank Jan 3, 2019
74a2cd0
Add test for #34721
estebank Jan 3, 2019
97bc38e
break eagerly from loop
estebank Jan 4, 2019
802d8c5
Point at type argument suggesting adding `Copy` constraint
estebank Jan 6, 2019
09006d8
review comments
estebank Jan 18, 2019
a5d4aed
Address some comments
Zoxc Jan 19, 2019
2200fd3
Add default rust logo for documentation
GuillaumeGomez Jan 12, 2019
98d4f33
const_eval: Predetermine the layout of all locals when pushing a stac…
dotdash Jan 16, 2019
b5d167f
Add default favicon for documentation
GuillaumeGomez Jan 12, 2019
3ecbe1e
Add regression test for #54582
estebank Jan 21, 2019
45a95b5
Use structured suggestion in stead of notes
estebank Jan 21, 2019
58b0200
Add powerpc64-unknown-freebsd
Jan 21, 2019
68ea7e4
Rollup merge of #57294 - estebank:point-copy-less, r=nikomatsakis
Centril Jan 21, 2019
db720ec
Rollup merge of #57552 - GuillaumeGomez:default-images, r=QuietMisdre…
Centril Jan 21, 2019
d29a1bc
Rollup merge of #57667 - ishitatsuyuki:p-leak, r=nnethercote
Centril Jan 21, 2019
d87385f
Rollup merge of #57677 - dotdash:locals, r=michaelwoerister
Centril Jan 21, 2019
45e6a2b
Rollup merge of #57730 - Zoxc:combined-ast-validator, r=cramertj
Centril Jan 21, 2019
a311372
Rollup merge of #57791 - estebank:issue-54582, r=zackmdavis
Centril Jan 21, 2019
c5dfb30
Rollup merge of #57795 - estebank:did-you-mean, r=zackmdavis
Centril Jan 21, 2019
39b92c1
Rollup merge of #57809 - MikaelUrankar:powerpc64-unknown-freebsd, r=n…
Centril Jan 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,38 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let place = &self.move_data.move_paths[mpi].place;

let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
let note_msg = match self.describe_place_with_options(
place,
IncludingDowncast(true),
) {
Some(name) => format!("`{}`", name),
let opt_name = self.describe_place_with_options(place, IncludingDowncast(true));
let note_msg = match opt_name {
Some(ref name) => format!("`{}`", name),
None => "value".to_owned(),
};

err.note(&format!(
"move occurs because {} has type `{}`, \
which does not implement the `Copy` trait",
note_msg, ty
));
if let ty::TyKind::Param(param_ty) = ty.sty {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id);
let def_id = generics.type_param(&param_ty, tcx).def_id;
if let Some(sp) = tcx.hir().span_if_local(def_id) {
err.span_label(
sp,
"consider adding a `Copy` constraint to this type argument",
);
}
}
if let Place::Local(local) = place {
let decl = &self.mir.local_decls[*local];
err.span_label(
decl.source_info.span,
format!(
"move occurs because {} has type `{}`, \
which does not implement the `Copy` trait",
note_msg, ty,
));
} else {
err.note(&format!(
"move occurs because {} has type `{}`, \
which does not implement the `Copy` trait",
note_msg, ty
));
}
}

if let Some((_, mut old_err)) = self.move_error_reported
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn mk_eval_cx_inner<'a, 'mir, 'tcx>(
ecx.stack.push(interpret::Frame {
block: mir::START_BLOCK,
locals: IndexVec::new(),
local_layouts: IndexVec::new(),
instance,
span,
mir,
Expand Down
19 changes: 14 additions & 5 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cell::Cell;
use std::fmt::Write;
use std::mem;

Expand Down Expand Up @@ -76,6 +77,7 @@ pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> {
/// `None` represents a local that is currently dead, while a live local
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
pub locals: IndexVec<mir::Local, LocalValue<Tag>>,
pub local_layouts: IndexVec<mir::Local, Cell<Option<TyLayout<'tcx>>>>,

////////////////////////////////////////////////////////////////////////////////
// Current position within the function
Expand Down Expand Up @@ -290,9 +292,15 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
local: mir::Local
) -> EvalResult<'tcx, TyLayout<'tcx>> {
let local_ty = frame.mir.local_decls[local].ty;
let local_ty = self.monomorphize(local_ty, frame.instance.substs);
self.layout_of(local_ty)
let cell = &frame.local_layouts[local];
if cell.get().is_none() {
let local_ty = frame.mir.local_decls[local].ty;
let local_ty = self.monomorphize(local_ty, frame.instance.substs);
let layout = self.layout_of(local_ty)?;
cell.set(Some(layout));
}

Ok(cell.get().unwrap())
}

pub fn str_to_immediate(&mut self, s: &str) -> EvalResult<'tcx, Immediate<M::PointerTag>> {
Expand Down Expand Up @@ -426,6 +434,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
// empty local array, we fill it in below, after we are inside the stack frame and
// all methods actually know about the frame
locals: IndexVec::new(),
local_layouts: IndexVec::from_elem_n(Default::default(), mir.local_decls.len()),
span,
instance,
stmt: 0,
Expand Down Expand Up @@ -464,11 +473,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
},
}
// Finally, properly initialize all those that still have the dummy value
for (local, decl) in locals.iter_mut().zip(mir.local_decls.iter()) {
for (idx, local) in locals.iter_enumerated_mut() {
match *local {
LocalValue::Live(_) => {
// This needs to be peoperly initialized.
let layout = self.layout_of(self.monomorphize(decl.ty, instance.substs))?;
let layout = self.layout_of_local(self.frame(), idx)?;
*local = LocalValue::Live(self.uninit_operand(layout)?);
}
LocalValue::Dead => {
Expand Down
18 changes: 6 additions & 12 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,36 +457,30 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
}

/// This is used by [priroda](https://github.com/oli-obk/priroda) to get an OpTy from a local
///
/// When you know the layout of the local in advance, you can pass it as last argument
pub fn access_local(
fn access_local(
&self,
frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
local: mir::Local,
layout: Option<TyLayout<'tcx>>,
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
assert_ne!(local, mir::RETURN_PLACE);
let op = *frame.locals[local].access()?;
let layout = from_known_layout(layout,
|| self.layout_of_local(frame, local))?;
let layout = self.layout_of_local(frame, local)?;
Ok(OpTy { op, layout })
}

// Evaluate a place with the goal of reading from it. This lets us sometimes
// avoid allocations. If you already know the layout, you can pass it in
// to avoid looking it up again.
// avoid allocations.
fn eval_place_to_op(
&self,
mir_place: &mir::Place<'tcx>,
layout: Option<TyLayout<'tcx>>,
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Place::*;
let op = match *mir_place {
Local(mir::RETURN_PLACE) => return err!(ReadFromReturnPointer),
Local(local) => self.access_local(self.frame(), local, layout)?,
Local(local) => self.access_local(self.frame(), local)?,

Projection(ref proj) => {
let op = self.eval_place_to_op(&proj.base, None)?;
let op = self.eval_place_to_op(&proj.base)?;
self.operand_projection(op, &proj.elem)?
}

Expand All @@ -510,7 +504,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
// FIXME: do some more logic on `move` to invalidate the old location
Copy(ref place) |
Move(ref place) =>
self.eval_place_to_op(place, layout)?,
self.eval_place_to_op(place)?,

Constant(ref constant) => {
let layout = from_known_layout(layout, || {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/interpret/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,14 @@ struct FrameSnapshot<'a, 'tcx: 'a> {
stmt: usize,
}

impl_stable_hash_for!(impl<'tcx, 'mir: 'tcx> for struct Frame<'mir, 'tcx> {
impl_stable_hash_for!(impl<'mir, 'tcx: 'mir> for struct Frame<'mir, 'tcx> {
mir,
instance,
span,
return_to_block,
return_place -> (return_place.as_ref().map(|r| &**r)),
locals,
local_layouts -> _,
block,
stmt,
extra,
Expand All @@ -339,6 +340,7 @@ impl<'a, 'mir, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a Frame<'mir, 'tcx>
return_to_block,
return_place,
locals,
local_layouts: _,
block,
stmt,
extra: _,
Expand Down
Loading