Skip to content

Commit 65abf96

Browse files
committed
auto merge of #13424 : eddyb/rust/ty-mut-in-store, r=nikomatsakis
Cleans up some remnants of the old mutability system and only allows vector/trait mutability in `VstoreSlice` (`&mut [T]`) and `RegionTraitStore` (`&mut Trait`).
2 parents 1b37afe + ee4c770 commit 65abf96

32 files changed

+490
-563
lines changed

src/librustc/metadata/encoder.rs

-12
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,6 @@ pub fn write_type(ecx: &EncodeContext,
232232
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
233233
}
234234

235-
pub fn write_vstore(ecx: &EncodeContext,
236-
ebml_w: &mut Encoder,
237-
vstore: ty::vstore) {
238-
let ty_str_ctxt = &tyencode::ctxt {
239-
diag: ecx.diag,
240-
ds: def_to_str,
241-
tcx: ecx.tcx,
242-
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)
243-
};
244-
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
245-
}
246-
247235
fn encode_type(ecx: &EncodeContext,
248236
ebml_w: &mut Encoder,
249237
typ: ty::t) {

src/librustc/metadata/tydecode.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,28 @@ fn parse_sigil(st: &mut PState) -> ast::Sigil {
146146
}
147147
}
148148

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

152153
let c = peek(st);
153154
if '0' <= c && c <= '9' {
154155
let n = parse_uint(st);
155156
assert_eq!(next(st), '|');
156-
return ty::vstore_fixed(n);
157+
return ty::VstoreFixed(n);
157158
}
158159

159160
match next(st) {
160-
'~' => ty::vstore_uniq,
161-
'&' => ty::vstore_slice(parse_region(st, conv)),
162-
c => st.tcx.sess.bug(format!("parse_vstore(): bad input '{}'", c))
161+
'~' => ty::VstoreUniq,
162+
'&' => ty::VstoreSlice(parse_region(st, conv), parse_mut(st)),
163+
c => st.tcx.sess.bug(format!("parse_vstore(): bad input '{}'", c))
163164
}
164165
}
165166

166167
fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
167168
match next(st) {
168169
'~' => ty::UniqTraitStore,
169-
'&' => ty::RegionTraitStore(parse_region(st, conv)),
170+
'&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
170171
c => st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'", c))
171172
}
172173
}
@@ -328,10 +329,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
328329
let def = parse_def(st, NominalType, |x,y| conv(x,y));
329330
let substs = parse_substs(st, |x,y| conv(x,y));
330331
let store = parse_trait_store(st, |x,y| conv(x,y));
331-
let mt = parse_mutability(st);
332332
let bounds = parse_bounds(st, |x,y| conv(x,y));
333333
assert_eq!(next(st), ']');
334-
return ty::mk_trait(st.tcx, def, substs, store, mt, bounds.builtin_bounds);
334+
return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
335335
}
336336
'p' => {
337337
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
@@ -351,12 +351,12 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
351351
return ty::mk_rptr(st.tcx, r, mt);
352352
}
353353
'V' => {
354-
let mt = parse_mt(st, |x,y| conv(x,y));
355-
let v = parse_vstore(st, |x,y| conv(x,y));
356-
return ty::mk_vec(st.tcx, mt, v);
354+
let ty = parse_ty(st, |x,y| conv(x,y));
355+
let v = parse_vstore(st, |x,y| conv(x,y), parse_mutability);
356+
return ty::mk_vec(st.tcx, ty, v);
357357
}
358358
'v' => {
359-
let v = parse_vstore(st, |x,y| conv(x,y));
359+
let v = parse_vstore(st, |x,y| conv(x,y), |_| ());
360360
return ty::mk_str(st.tcx, v);
361361
}
362362
'T' => {

src/librustc/metadata/tyencode.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,17 @@ fn enc_bound_region(w: &mut MemWriter, cx: &ctxt, br: ty::BoundRegion) {
204204
}
205205
}
206206

207-
pub fn enc_vstore(w: &mut MemWriter, cx: &ctxt, v: ty::vstore) {
207+
pub fn enc_vstore<M>(w: &mut MemWriter, cx: &ctxt,
208+
v: ty::Vstore<M>,
209+
enc_mut: |&mut MemWriter, M|) {
208210
mywrite!(w, "/");
209211
match v {
210-
ty::vstore_fixed(u) => mywrite!(w, "{}|", u),
211-
ty::vstore_uniq => mywrite!(w, "~"),
212-
ty::vstore_slice(r) => {
212+
ty::VstoreFixed(u) => mywrite!(w, "{}|", u),
213+
ty::VstoreUniq => mywrite!(w, "~"),
214+
ty::VstoreSlice(r, m) => {
213215
mywrite!(w, "&");
214216
enc_region(w, cx, r);
217+
enc_mut(w, m);
215218
}
216219
}
217220
}
@@ -224,9 +227,10 @@ pub fn enc_trait_ref(w: &mut MemWriter, cx: &ctxt, s: &ty::TraitRef) {
224227
pub fn enc_trait_store(w: &mut MemWriter, cx: &ctxt, s: ty::TraitStore) {
225228
match s {
226229
ty::UniqTraitStore => mywrite!(w, "~"),
227-
ty::RegionTraitStore(re) => {
230+
ty::RegionTraitStore(re, m) => {
228231
mywrite!(w, "&");
229232
enc_region(w, cx, re);
233+
enc_mutability(w, m);
230234
}
231235
}
232236
}
@@ -266,11 +270,10 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
266270
enc_substs(w, cx, substs);
267271
mywrite!(w, "]");
268272
}
269-
ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, mutability, bounds }) => {
273+
ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, bounds }) => {
270274
mywrite!(w, "x[{}|", (cx.ds)(def_id));
271275
enc_substs(w, cx, substs);
272276
enc_trait_store(w, cx, store);
273-
enc_mutability(w, mutability);
274277
let bounds = ty::ParamBounds {builtin_bounds: bounds,
275278
trait_bounds: Vec::new()};
276279
enc_bounds(w, cx, &bounds);
@@ -289,14 +292,14 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
289292
enc_region(w, cx, r);
290293
enc_mt(w, cx, mt);
291294
}
292-
ty::ty_vec(mt, v) => {
295+
ty::ty_vec(ty, v) => {
293296
mywrite!(w, "V");
294-
enc_mt(w, cx, mt);
295-
enc_vstore(w, cx, v);
297+
enc_ty(w, cx, ty);
298+
enc_vstore(w, cx, v, enc_mutability);
296299
}
297300
ty::ty_str(v) => {
298301
mywrite!(w, "v");
299-
enc_vstore(w, cx, v);
302+
enc_vstore(w, cx, v, |_, ()| {});
300303
}
301304
ty::ty_closure(ref f) => {
302305
mywrite!(w, "f");

src/librustc/middle/astencode.rs

+22-27
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ impl tr for ty::BoundRegion {
514514
}
515515
}
516516

517+
impl tr for ty::TraitStore {
518+
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::TraitStore {
519+
match *self {
520+
ty::RegionTraitStore(r, m) => {
521+
ty::RegionTraitStore(r.tr(xcx), m)
522+
}
523+
ty::UniqTraitStore => ty::UniqTraitStore
524+
}
525+
}
526+
}
527+
517528
// ______________________________________________________________________
518529
// Encoding and decoding of freevar information
519530

@@ -824,7 +835,6 @@ impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> {
824835

825836
trait ebml_writer_helpers {
826837
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t);
827-
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore);
828838
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]);
829839
fn emit_type_param_def(&mut self,
830840
ecx: &e::EncodeContext,
@@ -841,10 +851,6 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
841851
self.emit_opaque(|this| Ok(e::write_type(ecx, this, ty)));
842852
}
843853

844-
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) {
845-
self.emit_opaque(|this| Ok(e::write_vstore(ecx, this, vstore)));
846-
}
847-
848854
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
849855
self.emit_from_vec(tys, |this, ty| Ok(this.emit_ty(ecx, *ty)));
850856
}
@@ -904,14 +910,12 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
904910
})
905911
}
906912

907-
ty::AutoObject(sigil, region, m, b, def_id, ref substs) => {
908-
this.emit_enum_variant("AutoObject", 2, 6, |this| {
909-
this.emit_enum_variant_arg(0, |this| sigil.encode(this));
910-
this.emit_enum_variant_arg(1, |this| region.encode(this));
911-
this.emit_enum_variant_arg(2, |this| m.encode(this));
912-
this.emit_enum_variant_arg(3, |this| b.encode(this));
913-
this.emit_enum_variant_arg(4, |this| def_id.encode(this));
914-
this.emit_enum_variant_arg(5, |this| Ok(this.emit_substs(ecx, substs)))
913+
ty::AutoObject(store, b, def_id, ref substs) => {
914+
this.emit_enum_variant("AutoObject", 2, 4, |this| {
915+
this.emit_enum_variant_arg(0, |this| store.encode(this));
916+
this.emit_enum_variant_arg(1, |this| b.encode(this));
917+
this.emit_enum_variant_arg(2, |this| def_id.encode(this));
918+
this.emit_enum_variant_arg(3, |this| Ok(this.emit_substs(ecx, substs)))
915919
})
916920
}
917921
}
@@ -1280,25 +1284,16 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
12801284
ty::AutoDerefRef(auto_deref_ref.tr(xcx))
12811285
}
12821286
2 => {
1283-
let sigil: ast::Sigil =
1287+
let store: ty::TraitStore =
12841288
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
1285-
let region: Option<ty::Region> =
1286-
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
1287-
let m: ast::Mutability =
1288-
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
12891289
let b: ty::BuiltinBounds =
1290-
this.read_enum_variant_arg(3, |this| Decodable::decode(this)).unwrap();
1290+
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
12911291
let def_id: ast::DefId =
1292-
this.read_enum_variant_arg(4, |this| Decodable::decode(this)).unwrap();
1293-
let substs = this.read_enum_variant_arg(5, |this| Ok(this.read_substs(xcx)))
1292+
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
1293+
let substs = this.read_enum_variant_arg(3, |this| Ok(this.read_substs(xcx)))
12941294
.unwrap();
12951295

1296-
let region = match region {
1297-
Some(r) => Some(r.tr(xcx)),
1298-
None => None
1299-
};
1300-
1301-
ty::AutoObject(sigil, region, m, b, def_id.tr(xcx), substs)
1296+
ty::AutoObject(store.tr(xcx), b, def_id.tr(xcx), substs)
13021297
}
13031298
_ => fail!("bad enum variant for ty::AutoAdjustment")
13041299
})

src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
279279
}
280280
not_useful
281281
}
282-
ty::ty_vec(_, ty::vstore_fixed(n)) => {
282+
ty::ty_vec(_, ty::VstoreFixed(n)) => {
283283
is_useful_specialized(cx, m, v, vec(n), n, left_ty)
284284
}
285285
ty::ty_vec(..) => {
@@ -441,7 +441,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
441441
else if true_found { Some(val(const_bool(false))) }
442442
else { Some(val(const_bool(true))) }
443443
}
444-
ty::ty_vec(_, ty::vstore_fixed(n)) => {
444+
ty::ty_vec(_, ty::VstoreFixed(n)) => {
445445
let mut missing = true;
446446
let mut wrong = false;
447447
for r in m.iter() {

src/librustc/middle/lint.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
917917
ty::ty_box(_) => {
918918
n_box += 1;
919919
}
920-
ty::ty_uniq(_) | ty::ty_str(ty::vstore_uniq) |
921-
ty::ty_vec(_, ty::vstore_uniq) |
920+
ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
921+
ty::ty_vec(_, ty::VstoreUniq) |
922922
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
923923
n_uniq += 1;
924924
}
@@ -1158,7 +1158,7 @@ fn check_unused_result(cx: &Context, s: &ast::Stmt) {
11581158
fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
11591159
let t = ty::expr_ty(cx.tcx, e);
11601160
match ty::get(t).sty {
1161-
ty::ty_vec(_, ty::vstore_uniq) => {
1161+
ty::ty_vec(_, ty::VstoreUniq) => {
11621162
cx.span_lint(DeprecatedOwnedVector, e.span,
11631163
"use of deprecated `~[]` vector; replaced by `std::vec::Vec`")
11641164
}

src/librustc/middle/mem_categorization.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,23 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
170170
match ty::get(t).sty {
171171
ty::ty_uniq(_) |
172172
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
173-
ty::ty_vec(_, ty::vstore_uniq) |
174-
ty::ty_str(ty::vstore_uniq) |
173+
ty::ty_vec(_, ty::VstoreUniq) |
174+
ty::ty_str(ty::VstoreUniq) |
175175
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
176176
Some(deref_ptr(OwnedPtr))
177177
}
178178

179-
ty::ty_rptr(r, mt) |
180-
ty::ty_vec(mt, ty::vstore_slice(r)) => {
179+
ty::ty_rptr(r, mt) => {
181180
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
182181
Some(deref_ptr(BorrowedPtr(kind, r)))
183182
}
184-
185-
ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r), mutability: m, .. }) => {
186-
let kind = ty::BorrowKind::from_mutbl(m);
183+
ty::ty_vec(_, ty::VstoreSlice(r, mutbl)) |
184+
ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r, mutbl), .. }) => {
185+
let kind = ty::BorrowKind::from_mutbl(mutbl);
187186
Some(deref_ptr(BorrowedPtr(kind, r)))
188187
}
189188

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

209-
ty::ty_vec(_, ty::vstore_fixed(_)) |
210-
ty::ty_str(ty::vstore_fixed(_)) => {
208+
ty::ty_vec(_, ty::VstoreFixed(_)) |
209+
ty::ty_str(ty::VstoreFixed(_)) => {
211210
Some(deref_interior(InteriorElement(element_kind(t))))
212211
}
213212

@@ -799,7 +798,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
799798
//! the implicit index deref, if any (see above)
800799
801800
let element_ty = match ty::index(base_cmt.ty) {
802-
Some(ref mt) => mt.ty,
801+
Some(ty) => ty,
803802
None => {
804803
self.tcx().sess.span_bug(
805804
elt.span(),
@@ -882,8 +881,8 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
882881
*/
883882

884883
match ty::get(slice_ty).sty {
885-
ty::ty_vec(slice_mt, ty::vstore_slice(slice_r)) => {
886-
(slice_mt.mutbl, slice_r)
884+
ty::ty_vec(_, ty::VstoreSlice(slice_r, mutbl)) => {
885+
(mutbl, slice_r)
887886
}
888887

889888
ty::ty_rptr(_, ref mt) => {

src/librustc/middle/trans/_match.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,8 @@ fn extract_vec_elems<'a>(
11091109
let slice_begin = tvec::pointer_add_byte(bcx, base, slice_byte_offset);
11101110
let slice_len_offset = C_uint(bcx.ccx(), elem_count - 1u);
11111111
let slice_len = Sub(bcx, len, slice_len_offset);
1112-
let slice_ty = ty::mk_vec(bcx.tcx(),
1113-
ty::mt {ty: vt.unit_ty, mutbl: ast::MutImmutable},
1114-
ty::vstore_slice(ty::ReStatic)
1115-
);
1112+
let slice_ty = ty::mk_vec(bcx.tcx(), vt.unit_ty,
1113+
ty::VstoreSlice(ty::ReStatic, ast::MutImmutable));
11161114
let scratch = rvalue_scratch_datum(bcx, slice_ty, "");
11171115
Store(bcx, slice_begin,
11181116
GEPi(bcx, scratch.val, [0u, abi::slice_elt_base]));
@@ -1319,7 +1317,7 @@ fn compare_values<'a>(
13191317
}
13201318

13211319
match ty::get(rhs_t).sty {
1322-
ty::ty_str(ty::vstore_uniq) => {
1320+
ty::ty_str(ty::VstoreUniq) => {
13231321
let scratch_lhs = alloca(cx, val_ty(lhs), "__lhs");
13241322
Store(cx, lhs, scratch_lhs);
13251323
let scratch_rhs = alloca(cx, val_ty(rhs), "__rhs");

src/librustc/middle/trans/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
188188
// FIXME #6750 ~Trait cannot be directly marked as
189189
// noalias because the actual object pointer is nested.
190190
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
191-
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) => {
191+
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) => {
192192
unsafe {
193193
llvm::LLVMAddReturnAttribute(llfn, lib::llvm::NoAliasAttribute as c_uint);
194194
}
@@ -259,7 +259,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
259259
// FIXME #6750 ~Trait cannot be directly marked as
260260
// noalias because the actual object pointer is nested.
261261
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
262-
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
262+
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) |
263263
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
264264
unsafe {
265265
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
@@ -657,10 +657,10 @@ pub fn iter_structural_ty<'r,
657657
}
658658
})
659659
}
660-
ty::ty_str(ty::vstore_fixed(_)) |
661-
ty::ty_vec(_, ty::vstore_fixed(_)) => {
662-
let (base, len) = tvec::get_base_and_byte_len(cx, av, t);
660+
ty::ty_str(ty::VstoreFixed(n)) |
661+
ty::ty_vec(_, ty::VstoreFixed(n)) => {
663662
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
663+
let (base, len) = tvec::get_fixed_base_and_byte_len(cx, av, unit_ty, n);
664664
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
665665
}
666666
ty::ty_tup(ref args) => {

0 commit comments

Comments
 (0)