Vectors containing pinned kinds become pinned
Otherwise they could be copied
This commit is contained in:
parent
e5d5682065
commit
856acbf66d
9 changed files with 23 additions and 24 deletions
|
|
@ -385,7 +385,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) ->
|
|||
|
||||
// Path and definition ID indexing
|
||||
|
||||
fn create_index<T>(index: [entry<T>], hash_fn: fn(T) -> uint) ->
|
||||
fn create_index<@T>(index: [entry<T>], hash_fn: fn(T) -> uint) ->
|
||||
[@[entry<T>]] {
|
||||
let buckets: [@mutable [entry<T>]] = [];
|
||||
for each i: uint in uint::range(0u, 256u) { buckets += [@mutable []]; }
|
||||
|
|
|
|||
|
|
@ -1019,17 +1019,14 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
|
|||
ty_box(mt) {
|
||||
result = ast::kind_shared;
|
||||
}
|
||||
// Pointers and unique boxes / vecs raise pinned to shared,
|
||||
// otherwise pass through their pointee kind.
|
||||
ty_ptr(tm) | ty_vec(tm) {
|
||||
// Pointers raise pinned to shared.
|
||||
ty_ptr(tm) {
|
||||
let k = type_kind(cx, tm.ty);
|
||||
if k == ast::kind_pinned { k = ast::kind_shared; }
|
||||
result = kind::lower_kind(result, k);
|
||||
}
|
||||
// Unique boxes pass through their pointee kind. FIXME: Shouldn't
|
||||
// pointers and vecs do this too to avoid copying vectors of pinned
|
||||
// things?
|
||||
ty_uniq(tm) {
|
||||
// Unique containers pass through their pointee kind.
|
||||
ty_vec(tm) | ty_uniq(tm) {
|
||||
let k = type_kind(cx, tm.ty);
|
||||
result = kind::lower_kind(result, k);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn option_flatten_map<T, U>(f: fn(T) -> option::t<U>, v: [T]) ->
|
||||
fn option_flatten_map<T, @U>(f: fn(T) -> option::t<U>, v: [T]) ->
|
||||
option::t<[U]> {
|
||||
let res = [];
|
||||
for elem: T in v {
|
||||
|
|
|
|||
|
|
@ -609,8 +609,9 @@ fn parse_fn_block_arg(p: parser) -> ast::arg {
|
|||
ret {mode: m, ty: t, ident: i, id: p.get_id()};
|
||||
}
|
||||
|
||||
fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
||||
p: parser) -> [T] {
|
||||
fn parse_seq_to_before_gt<@T>(sep: option::t<token::token>,
|
||||
f: fn(parser) -> T,
|
||||
p: parser) -> [T] {
|
||||
let first = true;
|
||||
let v = [];
|
||||
while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) &&
|
||||
|
|
@ -625,7 +626,7 @@ fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
||||
fn parse_seq_to_gt<@T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
||||
p: parser) -> [T] {
|
||||
let v = parse_seq_to_before_gt(sep, f, p);
|
||||
expect_gt(p);
|
||||
|
|
@ -633,7 +634,7 @@ fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
||||
fn parse_seq_lt_gt<@T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
||||
p: parser) -> spanned<[T]> {
|
||||
let lo = p.get_lo_pos();
|
||||
expect(p, token::LT);
|
||||
|
|
@ -643,15 +644,16 @@ fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T,
|
|||
ret spanned(lo, hi, result);
|
||||
}
|
||||
|
||||
fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>,
|
||||
fn parse_seq_to_end<@T>(ket: token::token, sep: option::t<token::token>,
|
||||
f: fn(parser) -> T, p: parser) -> [T] {
|
||||
let val = parse_seq_to_before_end(ket, sep, f, p);
|
||||
p.bump();
|
||||
ret val;
|
||||
}
|
||||
|
||||
fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>,
|
||||
f: fn(parser) -> T, p: parser) -> [T] {
|
||||
fn parse_seq_to_before_end<@T>(ket: token::token,
|
||||
sep: option::t<token::token>,
|
||||
f: fn(parser) -> T, p: parser) -> [T] {
|
||||
let first: bool = true;
|
||||
let v: [T] = [];
|
||||
while p.peek() != ket {
|
||||
|
|
@ -665,7 +667,7 @@ fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>,
|
|||
}
|
||||
|
||||
|
||||
fn parse_seq<T>(bra: token::token, ket: token::token,
|
||||
fn parse_seq<@T>(bra: token::token, ket: token::token,
|
||||
sep: option::t<token::token>, f: fn(parser) -> T, p: parser)
|
||||
-> spanned<[T]> {
|
||||
let lo = p.get_lo_pos();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ fn either<T, U,
|
|||
alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
|
||||
}
|
||||
|
||||
fn lefts<T, U>(eithers: [t<T, U>]) -> [T] {
|
||||
fn lefts<@T, U>(eithers: [t<T, U>]) -> [T] {
|
||||
let result: [T] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } }
|
||||
|
|
@ -18,7 +18,7 @@ fn lefts<T, U>(eithers: [t<T, U>]) -> [T] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn rights<T, U>(eithers: [t<T, U>]) -> [U] {
|
||||
fn rights<T, @U>(eithers: [t<T, U>]) -> [U] {
|
||||
let result: [U] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } }
|
||||
|
|
@ -26,7 +26,7 @@ fn rights<T, U>(eithers: [t<T, U>]) -> [U] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn partition<T, U>(eithers: [t<T, U>]) -> {lefts: [T], rights: [U]} {
|
||||
fn partition<@T, @U>(eithers: [t<T, U>]) -> {lefts: [T], rights: [U]} {
|
||||
let lefts: [T] = [];
|
||||
let rights: [U] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ iter iter2<@T>(v: [T]) -> (uint, T) {
|
|||
mod unsafe {
|
||||
type vec_repr = {mutable fill: uint, mutable alloc: uint, data: u8};
|
||||
|
||||
fn from_buf<T>(ptr: *T, elts: uint) -> [T] {
|
||||
fn from_buf<@T>(ptr: *T, elts: uint) -> [T] {
|
||||
ret rustrt::vec_from_buf_shared(ptr, elts);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ tag option<T> { some(T); none; }
|
|||
|
||||
type r<T> = {mutable v: [option<T>]};
|
||||
|
||||
fn f<T>() -> [T] { ret []; }
|
||||
fn f<@T>() -> [T] { ret []; }
|
||||
|
||||
fn main() { let r: r<int> = {mutable v: []}; r.v = f(); }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn double<T>(a: T) -> [T] { ret [a] + [a]; }
|
||||
fn double<@T>(a: T) -> [T] { ret [a] + [a]; }
|
||||
|
||||
fn double_int(a: int) -> [int] { ret [a] + [a]; }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
|
||||
fn push<T>(&v: [mutable? T], t: T) { v += [t]; }
|
||||
fn push<@T>(&v: [mutable? T], t: T) { v += [t]; }
|
||||
|
||||
fn main() { let v = [1, 2, 3]; push(v, 1); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue