From 856acbf66d21a20bd115f11c55c7abecd1f4c92e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 23 Sep 2011 18:50:00 -0700 Subject: [PATCH] Vectors containing pinned kinds become pinned Otherwise they could be copied --- src/comp/metadata/encoder.rs | 2 +- src/comp/middle/ty.rs | 11 ++++------- src/comp/syntax/ext/simplext.rs | 2 +- src/comp/syntax/parse/parser.rs | 18 ++++++++++-------- src/lib/either.rs | 6 +++--- src/lib/vec.rs | 2 +- .../run-pass/alloca-from-derived-tydesc.rs | 2 +- src/test/run-pass/ivec-add.rs | 2 +- src/test/run-pass/vec-push.rs | 2 +- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index 154f623eacb5..bf43b158be72 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -385,7 +385,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) -> // Path and definition ID indexing -fn create_index(index: [entry], hash_fn: fn(T) -> uint) -> +fn create_index<@T>(index: [entry], hash_fn: fn(T) -> uint) -> [@[entry]] { let buckets: [@mutable [entry]] = []; for each i: uint in uint::range(0u, 256u) { buckets += [@mutable []]; } diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 190b974f72ae..a013359f3b0d 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -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); } diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index c6b6056bbc46..528b2cdc7565 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -104,7 +104,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> } } -fn option_flatten_map(f: fn(T) -> option::t, v: [T]) -> +fn option_flatten_map(f: fn(T) -> option::t, v: [T]) -> option::t<[U]> { let res = []; for elem: T in v { diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index a39189861753..ba01d4e4a1e1 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -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(sep: option::t, f: fn(parser) -> T, - p: parser) -> [T] { +fn parse_seq_to_before_gt<@T>(sep: option::t, + 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(sep: option::t, f: fn(parser) -> T, ret v; } -fn parse_seq_to_gt(sep: option::t, f: fn(parser) -> T, +fn parse_seq_to_gt<@T>(sep: option::t, 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(sep: option::t, f: fn(parser) -> T, ret v; } -fn parse_seq_lt_gt(sep: option::t, f: fn(parser) -> T, +fn parse_seq_lt_gt<@T>(sep: option::t, 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(sep: option::t, f: fn(parser) -> T, ret spanned(lo, hi, result); } -fn parse_seq_to_end(ket: token::token, sep: option::t, +fn parse_seq_to_end<@T>(ket: token::token, sep: option::t, 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(ket: token::token, sep: option::t, - f: fn(parser) -> T, p: parser) -> [T] { +fn parse_seq_to_before_end<@T>(ket: token::token, + sep: option::t, + 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(ket: token::token, sep: option::t, } -fn parse_seq(bra: token::token, ket: token::token, +fn parse_seq<@T>(bra: token::token, ket: token::token, sep: option::t, f: fn(parser) -> T, p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); diff --git a/src/lib/either.rs b/src/lib/either.rs index 143f0cabe92d..d20b124a9682 100644 --- a/src/lib/either.rs +++ b/src/lib/either.rs @@ -10,7 +10,7 @@ fn either(eithers: [t]) -> [T] { +fn lefts<@T, U>(eithers: [t]) -> [T] { let result: [T] = []; for elt: t in eithers { alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } } @@ -18,7 +18,7 @@ fn lefts(eithers: [t]) -> [T] { ret result; } -fn rights(eithers: [t]) -> [U] { +fn rights(eithers: [t]) -> [U] { let result: [U] = []; for elt: t in eithers { alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } } @@ -26,7 +26,7 @@ fn rights(eithers: [t]) -> [U] { ret result; } -fn partition(eithers: [t]) -> {lefts: [T], rights: [U]} { +fn partition<@T, @U>(eithers: [t]) -> {lefts: [T], rights: [U]} { let lefts: [T] = []; let rights: [U] = []; for elt: t in eithers { diff --git a/src/lib/vec.rs b/src/lib/vec.rs index fef91259b500..84bd02e3689f 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -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(ptr: *T, elts: uint) -> [T] { + fn from_buf<@T>(ptr: *T, elts: uint) -> [T] { ret rustrt::vec_from_buf_shared(ptr, elts); } diff --git a/src/test/run-pass/alloca-from-derived-tydesc.rs b/src/test/run-pass/alloca-from-derived-tydesc.rs index 6077bbf6723b..57e319357384 100644 --- a/src/test/run-pass/alloca-from-derived-tydesc.rs +++ b/src/test/run-pass/alloca-from-derived-tydesc.rs @@ -2,6 +2,6 @@ tag option { some(T); none; } type r = {mutable v: [option]}; -fn f() -> [T] { ret []; } +fn f<@T>() -> [T] { ret []; } fn main() { let r: r = {mutable v: []}; r.v = f(); } diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs index f9378b213177..e13b2557b09c 100644 --- a/src/test/run-pass/ivec-add.rs +++ b/src/test/run-pass/ivec-add.rs @@ -1,4 +1,4 @@ -fn double(a: T) -> [T] { ret [a] + [a]; } +fn double<@T>(a: T) -> [T] { ret [a] + [a]; } fn double_int(a: int) -> [int] { ret [a] + [a]; } diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index 0e0d828bf63d..bb7b6805f148 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -1,5 +1,5 @@ -fn push(&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); }