Skip to content

Move mutability from ty_vec and ty_trait to their respective stores. #13424

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

Merged
merged 4 commits into from
Apr 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 0 additions & 12 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,6 @@ pub fn write_type(ecx: &EncodeContext,
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
}

pub fn write_vstore(ecx: &EncodeContext,
ebml_w: &mut Encoder,
vstore: ty::vstore) {
let ty_str_ctxt = &tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)
};
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
}

fn encode_type(ecx: &EncodeContext,
ebml_w: &mut Encoder,
typ: ty::t) {
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,28 @@ fn parse_sigil(st: &mut PState) -> ast::Sigil {
}
}

fn parse_vstore(st: &mut PState, conv: conv_did) -> ty::vstore {
fn parse_vstore<M>(st: &mut PState, conv: conv_did,
parse_mut: |&mut PState| -> M) -> ty::Vstore<M> {
assert_eq!(next(st), '/');

let c = peek(st);
if '0' <= c && c <= '9' {
let n = parse_uint(st);
assert_eq!(next(st), '|');
return ty::vstore_fixed(n);
return ty::VstoreFixed(n);
}

match next(st) {
'~' => ty::vstore_uniq,
'&' => ty::vstore_slice(parse_region(st, conv)),
c => st.tcx.sess.bug(format!("parse_vstore(): bad input '{}'", c))
'~' => ty::VstoreUniq,
'&' => ty::VstoreSlice(parse_region(st, conv), parse_mut(st)),
c => st.tcx.sess.bug(format!("parse_vstore(): bad input '{}'", c))
}
}

fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
match next(st) {
'~' => ty::UniqTraitStore,
'&' => ty::RegionTraitStore(parse_region(st, conv)),
'&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
c => st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'", c))
}
}
Expand Down Expand Up @@ -327,10 +328,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
let def = parse_def(st, NominalType, |x,y| conv(x,y));
let substs = parse_substs(st, |x,y| conv(x,y));
let store = parse_trait_store(st, |x,y| conv(x,y));
let mt = parse_mutability(st);
let bounds = parse_bounds(st, |x,y| conv(x,y));
assert_eq!(next(st), ']');
return ty::mk_trait(st.tcx, def, substs, store, mt, bounds.builtin_bounds);
return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
}
'p' => {
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
Expand All @@ -350,12 +350,12 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_rptr(st.tcx, r, mt);
}
'V' => {
let mt = parse_mt(st, |x,y| conv(x,y));
let v = parse_vstore(st, |x,y| conv(x,y));
return ty::mk_vec(st.tcx, mt, v);
let ty = parse_ty(st, |x,y| conv(x,y));
let v = parse_vstore(st, |x,y| conv(x,y), parse_mutability);
return ty::mk_vec(st.tcx, ty, v);
}
'v' => {
let v = parse_vstore(st, |x,y| conv(x,y));
let v = parse_vstore(st, |x,y| conv(x,y), |_| ());
return ty::mk_str(st.tcx, v);
}
'T' => {
Expand Down
25 changes: 14 additions & 11 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,17 @@ fn enc_bound_region(w: &mut MemWriter, cx: &ctxt, br: ty::BoundRegion) {
}
}

pub fn enc_vstore(w: &mut MemWriter, cx: &ctxt, v: ty::vstore) {
pub fn enc_vstore<M>(w: &mut MemWriter, cx: &ctxt,
v: ty::Vstore<M>,
enc_mut: |&mut MemWriter, M|) {
mywrite!(w, "/");
match v {
ty::vstore_fixed(u) => mywrite!(w, "{}|", u),
ty::vstore_uniq => mywrite!(w, "~"),
ty::vstore_slice(r) => {
ty::VstoreFixed(u) => mywrite!(w, "{}|", u),
ty::VstoreUniq => mywrite!(w, "~"),
ty::VstoreSlice(r, m) => {
mywrite!(w, "&");
enc_region(w, cx, r);
enc_mut(w, m);
}
}
}
Expand All @@ -224,9 +227,10 @@ pub fn enc_trait_ref(w: &mut MemWriter, cx: &ctxt, s: &ty::TraitRef) {
pub fn enc_trait_store(w: &mut MemWriter, cx: &ctxt, s: ty::TraitStore) {
match s {
ty::UniqTraitStore => mywrite!(w, "~"),
ty::RegionTraitStore(re) => {
ty::RegionTraitStore(re, m) => {
mywrite!(w, "&");
enc_region(w, cx, re);
enc_mutability(w, m);
}
}
}
Expand Down Expand Up @@ -266,11 +270,10 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
enc_substs(w, cx, substs);
mywrite!(w, "]");
}
ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, mutability, bounds }) => {
ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, bounds }) => {
mywrite!(w, "x[{}|", (cx.ds)(def_id));
enc_substs(w, cx, substs);
enc_trait_store(w, cx, store);
enc_mutability(w, mutability);
let bounds = ty::ParamBounds {builtin_bounds: bounds,
trait_bounds: Vec::new()};
enc_bounds(w, cx, &bounds);
Expand All @@ -289,14 +292,14 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
enc_region(w, cx, r);
enc_mt(w, cx, mt);
}
ty::ty_vec(mt, v) => {
ty::ty_vec(ty, v) => {
mywrite!(w, "V");
enc_mt(w, cx, mt);
enc_vstore(w, cx, v);
enc_ty(w, cx, ty);
enc_vstore(w, cx, v, enc_mutability);
}
ty::ty_str(v) => {
mywrite!(w, "v");
enc_vstore(w, cx, v);
enc_vstore(w, cx, v, |_, ()| {});
}
ty::ty_closure(ref f) => {
mywrite!(w, "f");
Expand Down
49 changes: 22 additions & 27 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ impl tr for ty::BoundRegion {
}
}

impl tr for ty::TraitStore {
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::TraitStore {
match *self {
ty::RegionTraitStore(r, m) => {
ty::RegionTraitStore(r.tr(xcx), m)
}
ty::UniqTraitStore => ty::UniqTraitStore
}
}
}

// ______________________________________________________________________
// Encoding and decoding of freevar information

Expand Down Expand Up @@ -823,7 +834,6 @@ impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> {

trait ebml_writer_helpers {
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t);
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore);
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]);
fn emit_type_param_def(&mut self,
ecx: &e::EncodeContext,
Expand All @@ -840,10 +850,6 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
self.emit_opaque(|this| Ok(e::write_type(ecx, this, ty)));
}

fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) {
self.emit_opaque(|this| Ok(e::write_vstore(ecx, this, vstore)));
}

fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
self.emit_from_vec(tys, |this, ty| Ok(this.emit_ty(ecx, *ty)));
}
Expand Down Expand Up @@ -903,14 +909,12 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
})
}

ty::AutoObject(sigil, region, m, b, def_id, ref substs) => {
this.emit_enum_variant("AutoObject", 2, 6, |this| {
this.emit_enum_variant_arg(0, |this| sigil.encode(this));
this.emit_enum_variant_arg(1, |this| region.encode(this));
this.emit_enum_variant_arg(2, |this| m.encode(this));
this.emit_enum_variant_arg(3, |this| b.encode(this));
this.emit_enum_variant_arg(4, |this| def_id.encode(this));
this.emit_enum_variant_arg(5, |this| Ok(this.emit_substs(ecx, substs)))
ty::AutoObject(store, b, def_id, ref substs) => {
this.emit_enum_variant("AutoObject", 2, 4, |this| {
this.emit_enum_variant_arg(0, |this| store.encode(this));
this.emit_enum_variant_arg(1, |this| b.encode(this));
this.emit_enum_variant_arg(2, |this| def_id.encode(this));
this.emit_enum_variant_arg(3, |this| Ok(this.emit_substs(ecx, substs)))
})
}
}
Expand Down Expand Up @@ -1279,25 +1283,16 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
ty::AutoDerefRef(auto_deref_ref.tr(xcx))
}
2 => {
let sigil: ast::Sigil =
let store: ty::TraitStore =
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
let region: Option<ty::Region> =
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
let m: ast::Mutability =
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
let b: ty::BuiltinBounds =
this.read_enum_variant_arg(3, |this| Decodable::decode(this)).unwrap();
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
let def_id: ast::DefId =
this.read_enum_variant_arg(4, |this| Decodable::decode(this)).unwrap();
let substs = this.read_enum_variant_arg(5, |this| Ok(this.read_substs(xcx)))
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
let substs = this.read_enum_variant_arg(3, |this| Ok(this.read_substs(xcx)))
.unwrap();

let region = match region {
Some(r) => Some(r.tr(xcx)),
None => None
};

ty::AutoObject(sigil, region, m, b, def_id.tr(xcx), substs)
ty::AutoObject(store.tr(xcx), b, def_id.tr(xcx), substs)
}
_ => fail!("bad enum variant for ty::AutoAdjustment")
})
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
}
not_useful
}
ty::ty_vec(_, ty::vstore_fixed(n)) => {
ty::ty_vec(_, ty::VstoreFixed(n)) => {
is_useful_specialized(cx, m, v, vec(n), n, left_ty)
}
ty::ty_vec(..) => {
Expand Down Expand Up @@ -441,7 +441,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
else if true_found { Some(val(const_bool(false))) }
else { Some(val(const_bool(true))) }
}
ty::ty_vec(_, ty::vstore_fixed(n)) => {
ty::ty_vec(_, ty::VstoreFixed(n)) => {
let mut missing = true;
let mut wrong = false;
for r in m.iter() {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
ty::ty_box(_) => {
n_box += 1;
}
ty::ty_uniq(_) | ty::ty_str(ty::vstore_uniq) |
ty::ty_vec(_, ty::vstore_uniq) |
ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
ty::ty_vec(_, ty::VstoreUniq) |
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
n_uniq += 1;
}
Expand Down Expand Up @@ -1158,7 +1158,7 @@ fn check_unused_result(cx: &Context, s: &ast::Stmt) {
fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
let t = ty::expr_ty(cx.tcx, e);
match ty::get(t).sty {
ty::ty_vec(_, ty::vstore_uniq) => {
ty::ty_vec(_, ty::VstoreUniq) => {
cx.span_lint(DeprecatedOwnedVector, e.span,
"use of deprecated `~[]` vector; replaced by `std::vec::Vec`")
}
Expand Down
25 changes: 12 additions & 13 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,23 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
match ty::get(t).sty {
ty::ty_uniq(_) |
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_vec(_, ty::vstore_uniq) |
ty::ty_str(ty::vstore_uniq) |
ty::ty_vec(_, ty::VstoreUniq) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
Some(deref_ptr(OwnedPtr))
}

ty::ty_rptr(r, mt) |
ty::ty_vec(mt, ty::vstore_slice(r)) => {
ty::ty_rptr(r, mt) => {
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
Some(deref_ptr(BorrowedPtr(kind, r)))
}

ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r), mutability: m, .. }) => {
let kind = ty::BorrowKind::from_mutbl(m);
ty::ty_vec(_, ty::VstoreSlice(r, mutbl)) |
ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r, mutbl), .. }) => {
let kind = ty::BorrowKind::from_mutbl(mutbl);
Some(deref_ptr(BorrowedPtr(kind, r)))
}

ty::ty_str(ty::vstore_slice(r)) |
ty::ty_str(ty::VstoreSlice(r, ())) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
region: r, ..}) => {
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
Expand All @@ -206,8 +205,8 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
Some(deref_interior(InteriorField(PositionalField(0))))
}

ty::ty_vec(_, ty::vstore_fixed(_)) |
ty::ty_str(ty::vstore_fixed(_)) => {
ty::ty_vec(_, ty::VstoreFixed(_)) |
ty::ty_str(ty::VstoreFixed(_)) => {
Some(deref_interior(InteriorElement(element_kind(t))))
}

Expand Down Expand Up @@ -799,7 +798,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
//! the implicit index deref, if any (see above)

let element_ty = match ty::index(base_cmt.ty) {
Some(ref mt) => mt.ty,
Some(ty) => ty,
None => {
self.tcx().sess.span_bug(
elt.span(),
Expand Down Expand Up @@ -882,8 +881,8 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
*/

match ty::get(slice_ty).sty {
ty::ty_vec(slice_mt, ty::vstore_slice(slice_r)) => {
(slice_mt.mutbl, slice_r)
ty::ty_vec(_, ty::VstoreSlice(slice_r, mutbl)) => {
(mutbl, slice_r)
}

ty::ty_rptr(_, ref mt) => {
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,8 @@ fn extract_vec_elems<'a>(
let slice_begin = tvec::pointer_add_byte(bcx, base, slice_byte_offset);
let slice_len_offset = C_uint(bcx.ccx(), elem_count - 1u);
let slice_len = Sub(bcx, len, slice_len_offset);
let slice_ty = ty::mk_vec(bcx.tcx(),
ty::mt {ty: vt.unit_ty, mutbl: ast::MutImmutable},
ty::vstore_slice(ty::ReStatic)
);
let slice_ty = ty::mk_vec(bcx.tcx(), vt.unit_ty,
ty::VstoreSlice(ty::ReStatic, ast::MutImmutable));
let scratch = rvalue_scratch_datum(bcx, slice_ty, "");
Store(bcx, slice_begin,
GEPi(bcx, scratch.val, [0u, abi::slice_elt_base]));
Expand Down Expand Up @@ -1319,7 +1317,7 @@ fn compare_values<'a>(
}

match ty::get(rhs_t).sty {
ty::ty_str(ty::vstore_uniq) => {
ty::ty_str(ty::VstoreUniq) => {
let scratch_lhs = alloca(cx, val_ty(lhs), "__lhs");
Store(cx, lhs, scratch_lhs);
let scratch_rhs = alloca(cx, val_ty(rhs), "__rhs");
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
// FIXME #6750 ~Trait cannot be directly marked as
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) => {
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) => {
unsafe {
llvm::LLVMAddReturnAttribute(llfn, lib::llvm::NoAliasAttribute as c_uint);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
// FIXME #6750 ~Trait cannot be directly marked as
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
unsafe {
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
Expand Down Expand Up @@ -657,10 +657,10 @@ pub fn iter_structural_ty<'r,
}
})
}
ty::ty_str(ty::vstore_fixed(_)) |
ty::ty_vec(_, ty::vstore_fixed(_)) => {
let (base, len) = tvec::get_base_and_byte_len(cx, av, t);
ty::ty_str(ty::VstoreFixed(n)) |
ty::ty_vec(_, ty::VstoreFixed(n)) => {
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
let (base, len) = tvec::get_fixed_base_and_byte_len(cx, av, unit_ty, n);
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
}
ty::ty_tup(ref args) => {
Expand Down
Loading