Skip to content

Commit

Permalink
librustc: Remove &const and *const from the language.
Browse files Browse the repository at this point in the history
They are still present as part of the borrow check.
  • Loading branch information
pcwalton committed Aug 28, 2013
1 parent 58d6eb5 commit 5c35047
Show file tree
Hide file tree
Showing 48 changed files with 306 additions and 457 deletions.
4 changes: 2 additions & 2 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub mod rustrt {

#[link_name = "rustrt"]
extern {
pub fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;

pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
Expand Down
9 changes: 3 additions & 6 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,9 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
fn get_mutability(ch: u8) -> ast::mutability {
match ch as char {
'i' => { ast::m_imm }
'm' => { ast::m_mutbl }
'c' => { ast::m_const }
_ => {
fail!("unknown mutability character: `%c`", ch as char)
}
'i' => ast::m_imm,
'm' => ast::m_mutbl,
_ => fail!("unknown mutability character: `%c`", ch as char),
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
fn encode_mutability(ebml_w: &writer::Encoder,
m: ast::mutability) {
match m {
m_imm => {
ebml_w.writer.write(&[ 'i' as u8 ]);
}
m_mutbl => {
ebml_w.writer.write(&[ 'm' as u8 ]);
}
m_const => {
ebml_w.writer.write(&[ 'c' as u8 ]);
}
m_imm => ebml_w.writer.write(&[ 'i' as u8 ]),
m_mutbl => ebml_w.writer.write(&[ 'm' as u8 ]),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
fn parse_mutability(st: &mut PState) -> ast::mutability {
match peek(st) {
'm' => { next(st); ast::m_mutbl }
'?' => { next(st); ast::m_const }
_ => { ast::m_imm }
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn enc_mutability(w: @io::Writer, mt: ast::mutability) {
match mt {
m_imm => (),
m_mutbl => w.write_char('m'),
m_const => w.write_char('?')
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use mc = middle::mem_categorization;
use middle::borrowck::*;
use middle::moves;
use middle::ty;
use syntax::ast::{m_mutbl, m_imm, m_const};
use syntax::ast::m_mutbl;
use syntax::ast;
use syntax::ast_util;
use syntax::codemap::span;
Expand Down Expand Up @@ -220,9 +220,9 @@ impl<'self> CheckLoanCtxt<'self> {

// Restrictions that would cause the new loan to be illegal:
let illegal_if = match loan2.mutbl {
m_mutbl => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
m_imm => RESTR_ALIAS | RESTR_FREEZE,
m_const => RESTR_ALIAS,
MutableMutability => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
ImmutableMutability => RESTR_ALIAS | RESTR_FREEZE,
ConstMutability => RESTR_ALIAS,
};
debug!("illegal_if=%?", illegal_if);

Expand All @@ -231,7 +231,7 @@ impl<'self> CheckLoanCtxt<'self> {
if restr.loan_path != loan2.loan_path { loop; }

match (new_loan.mutbl, old_loan.mutbl) {
(m_mutbl, m_mutbl) => {
(MutableMutability, MutableMutability) => {
self.bccx.span_err(
new_loan.span,
fmt!("cannot borrow `%s` as mutable \
Expand Down Expand Up @@ -582,16 +582,18 @@ impl<'self> CheckLoanCtxt<'self> {
// Otherwise stop iterating
LpExtend(_, mc::McDeclared, _) |
LpExtend(_, mc::McImmutable, _) |
LpExtend(_, mc::McReadOnly, _) |
LpVar(_) => {
return true;
}
}

// Check for a non-const loan of `loan_path`
let cont = do this.each_in_scope_loan(expr.id) |loan| {
if loan.loan_path == loan_path && loan.mutbl != m_const {
this.report_illegal_mutation(expr, full_loan_path, loan);
if loan.loan_path == loan_path &&
loan.mutbl != ConstMutability {
this.report_illegal_mutation(expr,
full_loan_path,
loan);
false
} else {
true
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use middle::borrowck::*;
use mc = middle::mem_categorization;
use middle::ty;
use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast::{m_imm, m_mutbl};
use syntax::ast;
use syntax::codemap::span;
use util::ppaux::{note_and_explain_region};
Expand All @@ -26,7 +26,7 @@ pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
span: span,
cmt: mc::cmt,
loan_region: ty::Region,
loan_mutbl: ast::mutability) {
loan_mutbl: LoanMutability) {
debug!("guarantee_lifetime(cmt=%s, loan_region=%s)",
cmt.repr(bccx.tcx), loan_region.repr(bccx.tcx));
let ctxt = GuaranteeLifetimeContext {bccx: bccx,
Expand Down Expand Up @@ -54,7 +54,7 @@ struct GuaranteeLifetimeContext {

span: span,
loan_region: ty::Region,
loan_mutbl: ast::mutability,
loan_mutbl: LoanMutability,
cmt_original: mc::cmt
}

Expand Down Expand Up @@ -235,11 +235,11 @@ impl GuaranteeLifetimeContext {
// we need to dynamically mark it to prevent incompatible
// borrows from happening later.
let opt_dyna = match ptr_mutbl {
m_imm | m_const => None,
m_imm => None,
m_mutbl => {
match self.loan_mutbl {
m_mutbl => Some(DynaMut),
m_imm | m_const => Some(DynaImm)
MutableMutability => Some(DynaMut),
ImmutableMutability | ConstMutability => Some(DynaImm)
}
}
};
Expand Down
82 changes: 48 additions & 34 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use middle::ty;
use util::common::indenter;
use util::ppaux::{Repr};

use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast;
use syntax::ast_util::id_range;
use syntax::codemap::span;
Expand Down Expand Up @@ -237,7 +236,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
// make sure that the thing we are pointing out stays valid
// for the lifetime `scope_r` of the resulting ptr:
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
this.guarantee_valid(ex.id,
ex.span,
base_cmt,
LoanMutability::from_ast_mutability(mutbl),
scope_r);
visit::walk_expr(v, ex, this);
}

Expand Down Expand Up @@ -278,7 +281,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
// adjustments).
let scope_r = ty::re_scope(ex.id);
let arg_cmt = this.bccx.cat_expr(arg);
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
this.guarantee_valid(arg.id,
arg.span,
arg_cmt,
ImmutableMutability,
scope_r);
visit::walk_expr(v, ex, this);
}

Expand Down Expand Up @@ -357,26 +364,30 @@ impl GatherLoanCtxt {

match *autoref {
ty::AutoPtr(r, m) => {
let loan_mutability =
LoanMutability::from_ast_mutability(m);
self.guarantee_valid(expr.id,
expr.span,
cmt,
m,
loan_mutability,
r)
}
ty::AutoBorrowVec(r, m) | ty::AutoBorrowVecRef(r, m) => {
let cmt_index = mcx.cat_index(expr, cmt, autoderefs+1);
let loan_mutability =
LoanMutability::from_ast_mutability(m);
self.guarantee_valid(expr.id,
expr.span,
cmt_index,
m,
loan_mutability,
r)
}
ty::AutoBorrowFn(r) => {
let cmt_deref = mcx.cat_deref_fn_or_obj(expr, cmt, 0);
self.guarantee_valid(expr.id,
expr.span,
cmt_deref,
m_imm,
ImmutableMutability,
r)
}
ty::AutoBorrowObj(r, m) => {
Expand All @@ -402,7 +413,7 @@ impl GatherLoanCtxt {
borrow_id: ast::NodeId,
borrow_span: span,
cmt: mc::cmt,
req_mutbl: ast::mutability,
req_mutbl: LoanMutability,
loan_region: ty::Region) {
debug!("guarantee_valid(borrow_id=%?, cmt=%s, \
req_mutbl=%?, loan_region=%?)",
Expand Down Expand Up @@ -473,7 +484,7 @@ impl GatherLoanCtxt {
let kill_scope = self.compute_kill_scope(loan_scope, loan_path);
debug!("kill_scope = %?", kill_scope);

if req_mutbl == m_mutbl {
if req_mutbl == MutableMutability {
self.mark_loan_path_as_mutated(loan_path);
}

Expand Down Expand Up @@ -516,7 +527,7 @@ impl GatherLoanCtxt {
// index: all_loans.len(),
// loan_path: loan_path,
// cmt: cmt,
// mutbl: m_const,
// mutbl: ConstMutability,
// gen_scope: borrow_id,
// kill_scope: kill_scope,
// span: borrow_span,
Expand All @@ -527,29 +538,20 @@ impl GatherLoanCtxt {
fn check_mutability(bccx: @BorrowckCtxt,
borrow_span: span,
cmt: mc::cmt,
req_mutbl: ast::mutability) {
req_mutbl: LoanMutability) {
//! Implements the M-* rules in doc.rs.
match req_mutbl {
m_const => {
ConstMutability => {
// Data of any mutability can be lent as const.
}

m_imm => {
match cmt.mutbl {
mc::McImmutable | mc::McDeclared | mc::McInherited => {
// both imm and mut data can be lent as imm;
// for mutable data, this is a freeze
}
mc::McReadOnly => {
bccx.report(BckError {span: borrow_span,
cmt: cmt,
code: err_mutbl(req_mutbl)});
}
}
ImmutableMutability => {
// both imm and mut data can be lent as imm;
// for mutable data, this is a freeze
}

m_mutbl => {
MutableMutability => {
// Only mutable data can be lent as mutable.
if !cmt.mutbl.is_mutable() {
bccx.report(BckError {span: borrow_span,
Expand All @@ -561,12 +563,14 @@ impl GatherLoanCtxt {
}
}

pub fn restriction_set(&self, req_mutbl: ast::mutability)
pub fn restriction_set(&self, req_mutbl: LoanMutability)
-> RestrictionSet {
match req_mutbl {
m_const => RESTR_EMPTY,
m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
m_mutbl => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
ConstMutability => RESTR_EMPTY,
ImmutableMutability => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
MutableMutability => {
RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
}
}
}

Expand All @@ -582,8 +586,8 @@ impl GatherLoanCtxt {
self.mark_loan_path_as_mutated(base);
}
LpExtend(_, mc::McDeclared, _) |
LpExtend(_, mc::McImmutable, _) |
LpExtend(_, mc::McReadOnly, _) => {
LpExtend(_, mc::McImmutable, _) => {
// Nothing to do.
}
}
}
Expand Down Expand Up @@ -701,8 +705,13 @@ impl GatherLoanCtxt {
}
}
};
self.guarantee_valid(pat.id, pat.span,
cmt_discr, mutbl, scope_r);
let loan_mutability =
LoanMutability::from_ast_mutability(mutbl);
self.guarantee_valid(pat.id,
pat.span,
cmt_discr,
loan_mutability,
scope_r);
}
ast::bind_infer => {
// No borrows here, but there may be moves
Expand All @@ -725,6 +734,8 @@ impl GatherLoanCtxt {
self.vec_slice_info(slice_pat, slice_ty);
let mcx = self.bccx.mc_ctxt();
let cmt_index = mcx.cat_index(slice_pat, cmt, 0);
let slice_loan_mutability =
LoanMutability::from_ast_mutability(slice_mutbl);

// Note: We declare here that the borrow occurs upon
// entering the `[...]` pattern. This implies that
Expand All @@ -743,8 +754,11 @@ impl GatherLoanCtxt {
// trans do the right thing, and it would only work
// for `~` vectors. It seems simpler to just require
// that people call `vec.pop()` or `vec.unshift()`.
self.guarantee_valid(pat.id, pat.span,
cmt_index, slice_mutbl, slice_r);
self.guarantee_valid(pat.id,
pat.span,
cmt_index,
slice_loan_mutability,
slice_r);
}

_ => {}
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::vec;
use middle::borrowck::*;
use mc = middle::mem_categorization;
use middle::ty;
use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast::{m_imm, m_mutbl};
use syntax::codemap::span;

pub enum RestrictionResult {
Expand Down Expand Up @@ -121,13 +121,6 @@ impl RestrictionsContext {
Safe
}

mc::cat_deref(_, _, mc::region_ptr(m_const, _)) |
mc::cat_deref(_, _, mc::gc_ptr(m_const)) => {
// R-Deref-Freeze-Borrowed
self.check_no_mutability_control(cmt, restrictions);
Safe
}

mc::cat_deref(cmt_base, _, pk @ mc::gc_ptr(m_mutbl)) => {
// R-Deref-Managed-Borrowed
//
Expand Down
Loading

0 comments on commit 5c35047

Please sign in to comment.