Remove RestrictionSet

Now that RestrictionSet is no longer being used for anything meaningful,
it can be removed, along with any other associated functions and
RestrictionSet fields of other types.
This commit is contained in:
Cameron Zwarich 2014-06-16 15:40:20 -07:00
parent 9934759195
commit 59309e0d9b
3 changed files with 17 additions and 98 deletions

View file

@ -259,7 +259,7 @@ impl<'a> GatherLoanCtxt<'a> {
// loan is safe.
let restr = restrictions::compute_restrictions(
self.bccx, borrow_span, cause,
cmt.clone(), loan_region, self.restriction_set(req_kind));
cmt.clone(), loan_region);
// Create the loan record (if needed).
let loan = match restr {
@ -390,21 +390,6 @@ impl<'a> GatherLoanCtxt<'a> {
}
}
fn restriction_set(&self, req_kind: ty::BorrowKind) -> RestrictionSet {
match req_kind {
// If borrowing data as immutable, no mutation allowed:
ty::ImmBorrow => RESTR_MUTATE,
// If borrowing data as mutable, no mutation nor other
// borrows allowed:
ty::MutBorrow => RESTR_MUTATE | RESTR_FREEZE,
// If borrowing data as unique imm, no mutation nor other
// borrows allowed:
ty::UniqueImmBorrow => RESTR_MUTATE | RESTR_FREEZE,
}
}
pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) {
//! For mutable loans of content whose mutability derives
//! from a local variable, mark the mutability decl as necessary.

View file

@ -30,8 +30,7 @@ pub fn compute_restrictions(bccx: &BorrowckCtxt,
span: Span,
cause: euv::LoanCause,
cmt: mc::cmt,
loan_region: ty::Region,
restr: RestrictionSet) -> RestrictionResult {
loan_region: ty::Region) -> RestrictionResult {
let ctxt = RestrictionsContext {
bccx: bccx,
span: span,
@ -39,7 +38,7 @@ pub fn compute_restrictions(bccx: &BorrowckCtxt,
loan_region: loan_region,
};
ctxt.restrict(cmt, restr)
ctxt.restrict(cmt)
}
///////////////////////////////////////////////////////////////////////////
@ -54,11 +53,8 @@ struct RestrictionsContext<'a> {
impl<'a> RestrictionsContext<'a> {
fn restrict(&self,
cmt: mc::cmt,
restrictions: RestrictionSet) -> RestrictionResult {
debug!("restrict(cmt={}, restrictions={})",
cmt.repr(self.bccx.tcx),
restrictions.repr(self.bccx.tcx));
cmt: mc::cmt) -> RestrictionResult {
debug!("restrict(cmt={})", cmt.repr(self.bccx.tcx));
match cmt.cat.clone() {
mc::cat_rvalue(..) => {
@ -75,19 +71,14 @@ impl<'a> RestrictionsContext<'a> {
mc::cat_upvar(ty::UpvarId {var_id: local_id, ..}, _) => {
// R-Variable
let lp = Rc::new(LpVar(local_id));
SafeIf(lp.clone(), vec!(Restriction {
loan_path: lp,
set: restrictions
}))
SafeIf(lp.clone(), vec!(Restriction { loan_path: lp }))
}
mc::cat_downcast(cmt_base) => {
// When we borrow the interior of an enum, we have to
// ensure the enum itself is not mutated, because that
// could cause the type of the memory to change.
self.restrict(
cmt_base,
restrictions | RESTR_MUTATE)
self.restrict(cmt_base)
}
mc::cat_interior(cmt_base, i) => {
@ -96,8 +87,8 @@ impl<'a> RestrictionsContext<'a> {
// Overwriting the base would not change the type of
// the memory, so no additional restrictions are
// needed.
let result = self.restrict(cmt_base, restrictions);
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
let result = self.restrict(cmt_base);
self.extend(result, cmt.mutbl, LpInterior(i))
}
mc::cat_deref(cmt_base, _, pk @ mc::OwnedPtr) |
@ -112,10 +103,8 @@ impl<'a> RestrictionsContext<'a> {
// 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);
self.extend(result, cmt.mutbl, LpDeref(pk), restrictions)
let result = self.restrict(cmt_base);
self.extend(result, cmt.mutbl, LpDeref(pk))
}
mc::cat_copied_upvar(..) | // FIXME(#2152) allow mutation of upvars
@ -152,8 +141,8 @@ impl<'a> RestrictionsContext<'a> {
return Safe;
}
let result = self.restrict(cmt_base, restrictions);
self.extend(result, cmt.mutbl, LpDeref(pk), restrictions)
let result = self.restrict(cmt_base);
self.extend(result, cmt.mutbl, LpDeref(pk))
}
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
@ -162,7 +151,7 @@ impl<'a> RestrictionsContext<'a> {
}
mc::cat_discr(cmt_base, _) => {
self.restrict(cmt_base, restrictions)
self.restrict(cmt_base)
}
}
}
@ -170,16 +159,12 @@ impl<'a> RestrictionsContext<'a> {
fn extend(&self,
result: RestrictionResult,
mc: mc::MutabilityCategory,
elem: LoanPathElem,
restrictions: RestrictionSet) -> RestrictionResult {
elem: LoanPathElem) -> RestrictionResult {
match result {
Safe => Safe,
SafeIf(base_lp, mut base_vec) => {
let lp = Rc::new(LpExtend(base_lp, mc, elem));
base_vec.push(Restriction {
loan_path: lp.clone(),
set: restrictions
});
base_vec.push(Restriction { loan_path: lp.clone() });
SafeIf(lp, base_vec)
}
}

View file

@ -21,7 +21,6 @@ use middle::ty;
use util::ppaux::{note_and_explain_region, Repr, UserString};
use std::cell::{Cell};
use std::ops::{BitOr, BitAnd};
use std::rc::Rc;
use std::gc::{Gc, GC};
use std::string::String;
@ -250,56 +249,8 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
}
}
///////////////////////////////////////////////////////////////////////////
// Restrictions
//
// Borrowing an lvalue often results in *restrictions* that limit what
// can be done with this lvalue during the scope of the loan:
//
// - `RESTR_MUTATE`: The lvalue may not be modified or `&mut` borrowed.
// - `RESTR_FREEZE`: `&` borrows of the lvalue are forbidden.
//
// In addition, no value which is restricted may be moved. Therefore,
// restrictions are meaningful even if the RestrictionSet is empty,
// because the restriction against moves is implied.
pub struct Restriction {
loan_path: Rc<LoanPath>,
set: RestrictionSet
}
#[deriving(PartialEq)]
pub struct RestrictionSet {
bits: u32
}
#[allow(dead_code)] // potentially useful
pub static RESTR_EMPTY: RestrictionSet = RestrictionSet {bits: 0b0000};
pub static RESTR_MUTATE: RestrictionSet = RestrictionSet {bits: 0b0001};
pub static RESTR_FREEZE: RestrictionSet = RestrictionSet {bits: 0b0010};
impl RestrictionSet {
pub fn intersects(&self, restr: RestrictionSet) -> bool {
(self.bits & restr.bits) != 0
}
}
impl BitOr<RestrictionSet,RestrictionSet> for RestrictionSet {
fn bitor(&self, rhs: &RestrictionSet) -> RestrictionSet {
RestrictionSet {bits: self.bits | rhs.bits}
}
}
impl BitAnd<RestrictionSet,RestrictionSet> for RestrictionSet {
fn bitand(&self, rhs: &RestrictionSet) -> RestrictionSet {
RestrictionSet {bits: self.bits & rhs.bits}
}
}
impl Repr for RestrictionSet {
fn repr(&self, _tcx: &ty::ctxt) -> String {
format!("RestrictionSet(0x{:x})", self.bits as uint)
}
}
///////////////////////////////////////////////////////////////////////////
@ -832,9 +783,7 @@ impl Repr for Loan {
impl Repr for Restriction {
fn repr(&self, tcx: &ty::ctxt) -> String {
(format!("Restriction({}, {:x})",
self.loan_path.repr(tcx),
self.set.bits as uint)).to_string()
(format!("Restriction({})", self.loan_path.repr(tcx))).to_string()
}
}