Skip to content

Commit 2125074

Browse files
committed
rustc: update docs & propagate @[]/@str removal more.
Various functions can now be made specific to ~[], or just non-managed vectors.
1 parent c8947c1 commit 2125074

File tree

11 files changed

+57
-128
lines changed

11 files changed

+57
-128
lines changed

doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,7 @@ Such a definite-sized vector type is a first-class type, since its size is known
31153115
A vector without such a size is said to be of _indefinite_ size,
31163116
and is therefore not a _first-class_ type.
31173117
An indefinite-size vector can only be instantiated through a pointer type,
3118-
such as `&[T]`, `@[T]` or `~[T]`.
3118+
such as `&[T]` or `~[T]`.
31193119
The kind of a vector type depends on the kind of its element type,
31203120
as with other simple structural types.
31213121

src/librustc/middle/borrowck/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,6 @@ pub struct BorrowStats {
194194
//
195195
// Note that there is no entry with derefs:3---the type of that expression
196196
// is T, which is not a box.
197-
//
198-
// Note that implicit dereferences also occur with indexing of `@[]`,
199-
// `@str`, etc. The same rules apply. So, for example, given a
200-
// variable `x` of type `@[@[...]]`, if I have an instance of the
201-
// expression `x[0]` which is then auto-slice'd, there would be two
202-
// potential entries in the root map, both with the id of the `x[0]`
203-
// expression. The entry with `derefs==0` refers to the deref of `x`
204-
// used as part of evaluating `x[0]`. The entry with `derefs==1`
205-
// refers to the deref of the `x[0]` that occurs as part of the
206-
// auto-slice.
207197
#[deriving(Eq, IterBytes)]
208198
pub struct root_map_key {
209199
id: ast::NodeId,

src/librustc/middle/trans/_match.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,6 @@ fn match_datum(bcx: &Block,
10321032

10331033
fn extract_vec_elems<'a>(
10341034
bcx: &'a Block<'a>,
1035-
pat_span: Span,
10361035
pat_id: ast::NodeId,
10371036
elem_count: uint,
10381037
slice: Option<uint>,
@@ -1041,7 +1040,7 @@ fn extract_vec_elems<'a>(
10411040
-> ExtractedBlock<'a> {
10421041
let _icx = push_ctxt("match::extract_vec_elems");
10431042
let vec_datum = match_datum(bcx, val, pat_id);
1044-
let (bcx, base, len) = vec_datum.get_vec_base_and_len(bcx, pat_span, pat_id, 0);
1043+
let (base, len) = vec_datum.get_vec_base_and_len(bcx);
10451044
let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id));
10461045

10471046
let mut elems = vec::from_fn(elem_count, |i| {
@@ -1512,13 +1511,11 @@ fn compile_submatch_continue<'r,
15121511
vals.slice(col + 1u, vals.len()));
15131512
let ccx = bcx.fcx.ccx;
15141513
let mut pat_id = 0;
1515-
let mut pat_span = DUMMY_SP;
15161514
for br in m.iter() {
15171515
// Find a real id (we're adding placeholder wildcard patterns, but
15181516
// each column is guaranteed to have at least one real pattern)
15191517
if pat_id == 0 {
15201518
pat_id = br.pats[col].id;
1521-
pat_span = br.pats[col].span;
15221519
}
15231520
}
15241521

@@ -1767,7 +1764,7 @@ fn compile_submatch_continue<'r,
17671764
vec_len_ge(i) => (n + 1u, Some(i)),
17681765
vec_len_eq => (n, None)
17691766
};
1770-
let args = extract_vec_elems(opt_cx, pat_span, pat_id, n,
1767+
let args = extract_vec_elems(opt_cx, pat_id, n,
17711768
slice, val, test_val);
17721769
size = args.vals.len();
17731770
unpacked = args.vals.clone();

src/librustc/middle/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn malloc_raw_dyn<'a>(
360360
None);
361361
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
362362
} else {
363-
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
363+
// we treat ~fn as @ here, which isn't ideal
364364
let langcall = match heap {
365365
heap_managed => {
366366
require_alloc_fn(bcx, t, MallocFnLangItem)

src/librustc/middle/trans/controlflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn trans_fail_expr<'a>(
334334
unpack_datum!(bcx, expr::trans_to_lvalue(bcx, arg_expr, "fail"));
335335

336336
if ty::type_is_str(arg_datum.ty) {
337-
let (lldata, _) = arg_datum.get_vec_base_and_len_no_root(bcx);
337+
let (lldata, _) = arg_datum.get_vec_base_and_len(bcx);
338338
return trans_fail_value(bcx, sp_opt, lldata);
339339
} else if bcx.unreachable.get() || ty::type_is_bot(arg_datum.ty) {
340340
return bcx;

src/librustc/middle/trans/datum.rs

+2-43
Original file line numberDiff line numberDiff line change
@@ -528,49 +528,8 @@ impl Datum<Lvalue> {
528528
}
529529
}
530530

531-
pub fn get_vec_base_and_byte_len<'a>(
532-
&self,
533-
mut bcx: &'a Block<'a>,
534-
span: Span,
535-
expr_id: ast::NodeId,
536-
derefs: uint)
537-
-> (&'a Block<'a>, ValueRef, ValueRef) {
538-
//! Converts a vector into the slice pair. Performs rooting
539-
//! and write guards checks.
540-
541-
// only imp't for @[] and @str, but harmless
542-
bcx = write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs);
543-
let (base, len) = self.get_vec_base_and_byte_len_no_root(bcx);
544-
(bcx, base, len)
545-
}
546-
547-
pub fn get_vec_base_and_byte_len_no_root(&self, bcx: &Block)
548-
-> (ValueRef, ValueRef) {
549-
//! Converts a vector into the slice pair. Des not root
550-
//! nor perform write guard checks.
551-
552-
tvec::get_base_and_byte_len(bcx, self.val, self.ty)
553-
}
554-
555-
pub fn get_vec_base_and_len<'a>(&self,
556-
mut bcx: &'a Block<'a>,
557-
span: Span,
558-
expr_id: ast::NodeId,
559-
derefs: uint)
560-
-> (&'a Block<'a>, ValueRef, ValueRef) {
561-
//! Converts a vector into the slice pair. Performs rooting
562-
//! and write guards checks.
563-
564-
// only imp't for @[] and @str, but harmless
565-
bcx = write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs);
566-
let (base, len) = self.get_vec_base_and_len_no_root(bcx);
567-
(bcx, base, len)
568-
}
569-
570-
pub fn get_vec_base_and_len_no_root<'a>(&self, bcx: &'a Block<'a>)
571-
-> (ValueRef, ValueRef) {
572-
//! Converts a vector into the slice pair. Des not root
573-
//! nor perform write guard checks.
531+
pub fn get_vec_base_and_len<'a>(&self, bcx: &'a Block<'a>) -> (ValueRef, ValueRef) {
532+
//! Converts a vector into the slice pair.
574533
575534
tvec::get_base_and_len(bcx, self.val, self.ty)
576535
}

src/librustc/middle/trans/expr.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
202202
unpack_datum!(bcx, auto_ref(bcx, datum, expr))
203203
}
204204
Some(AutoBorrowVec(..)) => {
205-
unpack_datum!(bcx, auto_slice(bcx, adj.autoderefs,
206-
expr, datum))
205+
unpack_datum!(bcx, auto_slice(bcx, expr, datum))
207206
}
208207
Some(AutoBorrowVecRef(..)) => {
209-
unpack_datum!(bcx, auto_slice_and_ref(bcx, adj.autoderefs,
210-
expr, datum))
208+
unpack_datum!(bcx, auto_slice_and_ref(bcx, expr, datum))
211209
}
212210
Some(AutoBorrowFn(..)) => {
213211
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span,
@@ -271,7 +269,6 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
271269

272270
fn auto_slice<'a>(
273271
bcx: &'a Block<'a>,
274-
autoderefs: uint,
275272
expr: &ast::Expr,
276273
datum: Datum<Expr>)
277274
-> DatumBlock<'a, Expr> {
@@ -290,8 +287,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
290287
let datum = unpack_datum!(
291288
bcx, datum.to_lvalue_datum(bcx, "auto_slice", expr.id));
292289

293-
let (bcx, base, len) =
294-
datum.get_vec_base_and_len(bcx, expr.span, expr.id, autoderefs+1);
290+
let (base, len) = datum.get_vec_base_and_len(bcx);
295291

296292
// this type may have a different region/mutability than the
297293
// real one, but it will have the same runtime representation
@@ -323,11 +319,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
323319

324320
fn auto_slice_and_ref<'a>(
325321
bcx: &'a Block<'a>,
326-
autoderefs: uint,
327322
expr: &ast::Expr,
328323
datum: Datum<Expr>)
329324
-> DatumBlock<'a, Expr> {
330-
let DatumBlock { bcx, datum } = auto_slice(bcx, autoderefs, expr, datum);
325+
let DatumBlock { bcx, datum } = auto_slice(bcx, expr, datum);
331326
auto_ref(bcx, datum, expr)
332327
}
333328

@@ -522,8 +517,7 @@ fn trans_datum_unadjusted<'a>(bcx: &'a Block<'a>,
522517
ast::ExprVstore(contents, ast::ExprVstoreUniq) => {
523518
fcx.push_ast_cleanup_scope(contents.id);
524519
let datum = unpack_datum!(
525-
bcx, tvec::trans_uniq_or_managed_vstore(bcx, heap_exchange,
526-
expr, contents));
520+
bcx, tvec::trans_uniq_vstore(bcx, expr, contents));
527521
bcx = fcx.pop_and_trans_ast_cleanup_scope(bcx, contents.id);
528522
DatumBlock(bcx, datum)
529523
}
@@ -626,8 +620,7 @@ fn trans_index<'a>(bcx: &'a Block<'a>,
626620
let vt = tvec::vec_types(bcx, base_datum.ty);
627621
base::maybe_name_value(bcx.ccx(), vt.llunit_size, "unit_sz");
628622

629-
let (bcx, base, len) =
630-
base_datum.get_vec_base_and_len(bcx, index_expr.span, index_expr.id, 0);
623+
let (base, len) = base_datum.get_vec_base_and_len(bcx);
631624

632625
debug!("trans_index: base {}", bcx.val_to_str(base));
633626
debug!("trans_index: len {}", bcx.val_to_str(len));

src/librustc/middle/trans/tvec.rs

+37-46
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ pub fn alloc_uniq_raw<'a>(
110110
alloc_raw(bcx, unit_ty, fill, alloc, heap_exchange)
111111
}
112112

113-
pub fn alloc_vec<'a>(
113+
pub fn alloc_uniq_vec<'a>(
114114
bcx: &'a Block<'a>,
115115
unit_ty: ty::t,
116-
elts: uint,
117-
heap: heap)
116+
elts: uint)
118117
-> Result<'a> {
119118
let _icx = push_ctxt("tvec::alloc_uniq");
120119
let ccx = bcx.ccx();
@@ -125,7 +124,7 @@ pub fn alloc_vec<'a>(
125124
let alloc = if elts < 4u { Mul(bcx, C_int(ccx, 4), unit_sz) }
126125
else { fill };
127126
let Result {bcx: bcx, val: vptr} =
128-
alloc_raw(bcx, unit_ty, fill, alloc, heap);
127+
alloc_raw(bcx, unit_ty, fill, alloc, heap_exchange);
129128
return rslt(bcx, vptr);
130129
}
131130

@@ -302,70 +301,62 @@ pub fn trans_lit_str<'a>(
302301
}
303302

304303

305-
pub fn trans_uniq_or_managed_vstore<'a>(bcx: &'a Block<'a>,
306-
heap: heap,
307-
vstore_expr: &ast::Expr,
308-
content_expr: &ast::Expr)
309-
-> DatumBlock<'a, Expr> {
304+
pub fn trans_uniq_vstore<'a>(bcx: &'a Block<'a>,
305+
vstore_expr: &ast::Expr,
306+
content_expr: &ast::Expr)
307+
-> DatumBlock<'a, Expr> {
310308
/*!
311-
* @[...] or ~[...] (also @"..." or ~"...") allocate boxes in the
312-
* appropriate heap and write the array elements into them.
309+
* ~[...] and ~"..." allocate boxes in the exchange heap and write
310+
* the array elements into them.
313311
*/
314312

315-
debug!("trans_uniq_or_managed_vstore(vstore_expr={}, heap={:?})",
316-
bcx.expr_to_str(vstore_expr), heap);
313+
debug!("trans_uniq_vstore(vstore_expr={})", bcx.expr_to_str(vstore_expr));
317314
let fcx = bcx.fcx;
318315

319316
// Handle ~"".
320-
match heap {
321-
heap_exchange => {
322-
match content_expr.node {
323-
ast::ExprLit(lit) => {
324-
match lit.node {
325-
ast::LitStr(ref s, _) => {
326-
let llptrval = C_cstr(bcx.ccx(), (*s).clone());
327-
let llptrval = PointerCast(bcx,
328-
llptrval,
329-
Type::i8p());
330-
let llsizeval = C_uint(bcx.ccx(), s.get().len());
331-
let typ = ty::mk_str(bcx.tcx(), ty::vstore_uniq);
332-
let lldestval = rvalue_scratch_datum(bcx,
333-
typ,
334-
"");
335-
let alloc_fn = langcall(bcx,
336-
Some(lit.span),
337-
"",
338-
StrDupUniqFnLangItem);
339-
let bcx = callee::trans_lang_call(
340-
bcx,
341-
alloc_fn,
342-
[ llptrval, llsizeval ],
343-
Some(expr::SaveIn(lldestval.val))).bcx;
344-
return DatumBlock(bcx, lldestval).to_expr_datumblock();
345-
}
346-
_ => {}
347-
}
317+
match content_expr.node {
318+
ast::ExprLit(lit) => {
319+
match lit.node {
320+
ast::LitStr(ref s, _) => {
321+
let llptrval = C_cstr(bcx.ccx(), (*s).clone());
322+
let llptrval = PointerCast(bcx,
323+
llptrval,
324+
Type::i8p());
325+
let llsizeval = C_uint(bcx.ccx(), s.get().len());
326+
let typ = ty::mk_str(bcx.tcx(), ty::vstore_uniq);
327+
let lldestval = rvalue_scratch_datum(bcx,
328+
typ,
329+
"");
330+
let alloc_fn = langcall(bcx,
331+
Some(lit.span),
332+
"",
333+
StrDupUniqFnLangItem);
334+
let bcx = callee::trans_lang_call(
335+
bcx,
336+
alloc_fn,
337+
[ llptrval, llsizeval ],
338+
Some(expr::SaveIn(lldestval.val))).bcx;
339+
return DatumBlock(bcx, lldestval).to_expr_datumblock();
348340
}
349341
_ => {}
350342
}
351343
}
352-
heap_exchange_closure => fail!("vectors use exchange_alloc"),
353-
heap_managed => {}
344+
_ => {}
354345
}
355346

356347
let vt = vec_types_from_expr(bcx, vstore_expr);
357348
let count = elements_required(bcx, content_expr);
358349

359-
let Result {bcx, val} = alloc_vec(bcx, vt.unit_ty, count, heap);
350+
let Result {bcx, val} = alloc_uniq_vec(bcx, vt.unit_ty, count);
360351

361352
// Create a temporary scope lest execution should fail while
362353
// constructing the vector.
363354
let temp_scope = fcx.push_custom_cleanup_scope();
364-
fcx.schedule_free_value(cleanup::CustomScope(temp_scope), val, heap);
355+
fcx.schedule_free_value(cleanup::CustomScope(temp_scope), val, heap_exchange);
365356

366357
let dataptr = get_dataptr(bcx, val);
367358

368-
debug!("alloc_vec() returned val={}, dataptr={}",
359+
debug!("alloc_uniq_vec() returned val={}, dataptr={}",
369360
bcx.val_to_str(val), bcx.val_to_str(dataptr));
370361

371362
let bcx = write_content(bcx, &vt, vstore_expr,

src/librustc/middle/trans/write_guard.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fn root<'a, K:KindOps>(datum: &Datum<K>,
4646
_span: Span,
4747
root_key: root_map_key,
4848
root_info: RootInfo) -> &'a Block<'a> {
49-
//! In some cases, borrowck will decide that an @T/@[]/@str
50-
//! value must be rooted for the program to be safe. In that
51-
//! case, we will call this function, which will stash a copy
52-
//! away until we exit the scope `scope_id`.
49+
//! In some cases, borrowck will decide that an @T value must be
50+
//! rooted for the program to be safe. In that case, we will call
51+
//! this function, which will stash a copy away until we exit the
52+
//! scope `scope_id`.
5353
5454
debug!("write_guard::root(root_key={:?}, root_info={:?}, datum={:?})",
5555
root_key, root_info, datum.to_str(bcx.ccx()));
@@ -62,4 +62,3 @@ fn root<'a, K:KindOps>(datum: &Datum<K>,
6262
cleanup::AstScope(root_info.scope), (),
6363
|(), bcx, llval| datum.shallow_copy_and_take(bcx, llval)).bcx
6464
}
65-

src/librustc/middle/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ pub enum AutoRef {
226226
/// Convert from T to &T
227227
AutoPtr(Region, ast::Mutability),
228228

229-
/// Convert from @[]/~[]/&[] to &[] (or str)
229+
/// Convert from ~[]/&[] to &[] (or str)
230230
AutoBorrowVec(Region, ast::Mutability),
231231

232-
/// Convert from @[]/~[]/&[] to &&[] (or str)
232+
/// Convert from ~[]/&[] to &&[] (or str)
233233
AutoBorrowVecRef(Region, ast::Mutability),
234234

235235
/// Convert from @fn()/~fn()/|| to ||

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ impl Parser {
12911291
}
12921292

12931293
// other things are parsed as @/~ + a type. Note that constructs like
1294-
// @[] and @str will be resolved during typeck to slices and so forth,
1294+
// ~[] and ~str will be resolved during typeck to slices and so forth,
12951295
// rather than boxed ptrs. But the special casing of str/vec is not
12961296
// reflected in the AST type.
12971297
if sigil == OwnedSigil {

0 commit comments

Comments
 (0)