Skip to content
Merged
2 changes: 1 addition & 1 deletion src/libfourcc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->

let s = match expr.node {
// expression is a literal
ast::ExprLit(lit) => match lit.node {
ast::ExprLit(ref lit) => match lit.node {
// string literal
ast::LitStr(ref s, _) => {
if s.get().char_len() != 4 {
Expand Down
13 changes: 4 additions & 9 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
time(time_passes, "effect checking", (), |_|
middle::effect::check_crate(&ty_cx, krate));

let middle::moves::MoveMaps {moves_map, moved_variables_set,
capture_map} =
let middle::moves::MoveMaps {moves_map, capture_map} =
time(time_passes, "compute moves", (), |_|
middle::moves::compute_moves(&ty_cx, krate));

Expand All @@ -359,14 +358,11 @@ pub fn phase_3_run_analysis_passes(sess: Session,
time(time_passes, "liveness checking", (), |_|
middle::liveness::check_crate(&ty_cx, &capture_map, krate));

let root_map =
time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(&ty_cx, &moves_map,
&moved_variables_set,
&capture_map, krate));
time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(&ty_cx, &moves_map,
&capture_map, krate));

drop(moves_map);
drop(moved_variables_set);

time(time_passes, "kind checking", (), |_|
kind::check_crate(&ty_cx, krate));
Expand All @@ -391,7 +387,6 @@ pub fn phase_3_run_analysis_passes(sess: Session,
exported_items: exported_items,
public_items: public_items,
maps: astencode::Maps {
root_map: root_map,
capture_map: RefCell::new(capture_map)
},
reachable: reachable_map
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use writer = serialize::ebml::writer;

// Auxiliary maps of things to be encoded
pub struct Maps {
pub root_map: middle::borrowck::root_map,
pub capture_map: RefCell<middle::moves::CaptureMap>,
}

Expand Down
120 changes: 2 additions & 118 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ struct GuaranteeLifetimeContext<'a> {
}

impl<'a> GuaranteeLifetimeContext<'a> {
fn tcx(&self) -> &'a ty::ctxt {
self.bccx.tcx
}

fn check(&self, cmt: &mc::cmt, discr_scope: Option<ast::NodeId>) -> R {
//! Main routine. Walks down `cmt` until we find the "guarantor".
Expand All @@ -90,29 +87,10 @@ impl<'a> GuaranteeLifetimeContext<'a> {
Ok(())
}

mc::cat_deref(ref base, derefs, mc::GcPtr) => {
let base_scope = self.scope(base);

// L-Deref-Managed-Imm-User-Root
let omit_root =
self.bccx.is_subregion_of(self.loan_region, base_scope) &&
self.is_rvalue_or_immutable(base) &&
!self.is_moved(base);

if !omit_root {
// L-Deref-Managed-Imm-Compiler-Root
// L-Deref-Managed-Mut-Compiler-Root
self.check_root(cmt, base, derefs, discr_scope)
} else {
debug!("omitting root, base={}, base_scope={:?}",
base.repr(self.tcx()), base_scope);
Ok(())
}
}

mc::cat_downcast(ref base) |
mc::cat_deref(ref base, _, mc::OwnedPtr) | // L-Deref-Send
mc::cat_interior(ref base, _) => { // L-Field
mc::cat_interior(ref base, _) | // L-Field
mc::cat_deref(ref base, _, mc::GcPtr) => {
self.check(base, discr_scope)
}

Expand Down Expand Up @@ -174,74 +152,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
}
}

fn is_rvalue_or_immutable(&self,
cmt: &mc::cmt) -> bool {
//! We can omit the root on an `@T` value if the location
//! that holds the box is either (1) an rvalue, in which case
//! it is in a non-user-accessible temporary, or (2) an immutable
//! lvalue.

cmt.mutbl.is_immutable() || match cmt.guarantor().cat {
mc::cat_rvalue(..) => true,
_ => false
}
}

fn check_root(&self,
cmt_deref: &mc::cmt,
cmt_base: &mc::cmt,
derefs: uint,
discr_scope: Option<ast::NodeId>) -> R {
debug!("check_root(cmt_deref={}, cmt_base={}, derefs={:?}, \
discr_scope={:?})",
cmt_deref.repr(self.tcx()),
cmt_base.repr(self.tcx()),
derefs,
discr_scope);

// Make sure that the loan does not exceed the maximum time
// that we can root the value, dynamically.
let root_region = ty::ReScope(self.root_scope_id);
if !self.bccx.is_subregion_of(self.loan_region, root_region) {
return Err(self.report_error(
err_out_of_root_scope(root_region, self.loan_region)));
}

// Extract the scope id that indicates how long the rooting is required
let root_scope = match self.loan_region {
ty::ReScope(id) => id,
_ => {
// the check above should fail for anything is not ReScope
self.bccx.tcx.sess.span_bug(
cmt_base.span,
format!("cannot issue root for scope region: {:?}",
self.loan_region));
}
};

// If inside of a match arm, expand the rooting to the entire
// match. See the detailed discussion in `check()` above.
let root_scope = match discr_scope {
None => root_scope,
Some(id) => {
if self.bccx.is_subscope_of(root_scope, id) {
id
} else {
root_scope
}
}
};

// Add a record of what is required
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
let root_info = RootInfo {scope: root_scope};

self.bccx.root_map.borrow_mut().insert(rm_key, root_info);

debug!("root_key: {:?} root_info: {:?}", rm_key, root_info);
Ok(())
}

fn check_scope(&self, max_scope: ty::Region) -> R {
//! Reports an error if `loan_region` is larger than `valid_scope`

Expand All @@ -252,32 +162,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
}
}

fn is_moved(&self, cmt: &mc::cmt) -> bool {
//! True if `cmt` is something that is potentially moved
//! out of the current stack frame.

match cmt.guarantor().cat {
mc::cat_local(id) |
mc::cat_arg(id) => {
self.bccx.moved_variables_set.contains(&id)
}
mc::cat_rvalue(..) |
mc::cat_static_item |
mc::cat_copied_upvar(..) |
mc::cat_deref(..) |
mc::cat_upvar(..) => {
false
}
ref r @ mc::cat_downcast(..) |
ref r @ mc::cat_interior(..) |
ref r @ mc::cat_discr(..) => {
self.tcx().sess.span_bug(
cmt.span,
format!("illegal guarantor category: {:?}", r));
}
}
}

fn scope(&self, cmt: &mc::cmt) -> ty::Region {
//! Returns the maximal region scope for the which the
//! lvalue `cmt` is guaranteed to be valid without any
Expand Down
13 changes: 7 additions & 6 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,18 @@ impl<'a> RestrictionsContext<'a> {
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
}

mc::cat_deref(cmt_base, _, pk @ mc::OwnedPtr) => {
mc::cat_deref(cmt_base, _, pk @ mc::OwnedPtr) |
mc::cat_deref(cmt_base, _, pk @ mc::GcPtr) => {
// R-Deref-Send-Pointer
//
// When we borrow the interior of an owned pointer, we
// cannot permit the base to be mutated, because that
// would cause the unique pointer to be freed.
//
// For a managed pointer, the rules are basically the
// same, because this could be the last ref.
// Eventually we should make these non-special and
// just rely on Deref<T> implementation.
let result = self.restrict(
cmt_base,
restrictions | RESTR_MUTATE);
Expand Down Expand Up @@ -134,11 +140,6 @@ impl<'a> RestrictionsContext<'a> {
Safe
}

mc::cat_deref(_, _, mc::GcPtr) => {
// R-Deref-Imm-Managed
Safe
}

mc::cat_deref(cmt_base, _, pk @ mc::BorrowedPtr(ty::MutBorrow, lt)) => {
// R-Deref-Mut-Borrowed
if !self.bccx.is_subregion_of(self.loan_region, lt) {
Expand Down
Loading