Skip to content

Commit

Permalink
let create_ref take a mutability, and leave it to step.rs to interpre…
Browse files Browse the repository at this point in the history
…t mir::BorrowKind
  • Loading branch information
RalfJung committed Oct 29, 2018
1 parent f2f0f1a commit 3545dae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,17 @@ where

/// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
/// This is the inverse of `ref_to_mplace`.
/// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
pub fn create_ref(
&mut self,
place: MPlaceTy<'tcx, M::PointerTag>,
borrow_kind: Option<mir::BorrowKind>,
mutbl: Option<hir::Mutability>,
) -> EvalResult<'tcx, Value<M::PointerTag>> {
// Pointer tag tracking might want to adjust the tag
let place = if M::ENABLE_PTR_TRACKING_HOOKS {
let (size, _) = self.size_and_align_of_mplace(place)?
// for extern types, just cover what we can
.unwrap_or_else(|| place.layout.size_and_align());
let mutbl = match borrow_kind {
Some(mir::BorrowKind::Mut { .. }) |
Some(mir::BorrowKind::Unique) =>
Some(hir::MutMutable),
Some(_) => Some(hir::MutImmutable),
None => None,
};
M::tag_reference(self, *place, place.layout.ty, size, mutbl)?
} else {
*place
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_mir/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! The main entry point is the `step` method.

use rustc::mir;
use rustc::{hir, mir};
use rustc::ty::layout::LayoutOf;
use rustc::mir::interpret::{EvalResult, Scalar, PointerArithmetic};

Expand Down Expand Up @@ -250,7 +250,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
Ref(_, borrow_kind, ref place) => {
let src = self.eval_place(place)?;
let val = self.force_allocation(src)?;
let val = self.create_ref(val, Some(borrow_kind))?;
let mutbl = match borrow_kind {
mir::BorrowKind::Mut { .. } |
mir::BorrowKind::Unique =>
hir::MutMutable,
mir::BorrowKind::Shared |
mir::BorrowKind::Shallow =>
hir::MutImmutable,
};
let val = self.create_ref(val, Some(mutbl))?;
self.write_value(val, dest)?;
}

Expand Down

0 comments on commit 3545dae

Please sign in to comment.