Skip to content

Commit f6491bb

Browse files
committed
Update stdlib, compiler, and tests to new kind system
This involved adding 'copy' to more generics than I hoped, but an experiment with making it implicit showed that that way lies madness -- unless enforced, you will not remember to mark functions that don't copy as not requiring copyable kind. Issue #1177
1 parent 8f8ebb5 commit f6491bb

File tree

94 files changed

+314
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+314
-476
lines changed

src/comp/front/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) {
199199
}
200200
}
201201

202-
fn span<T>(item: T) -> ast::spanned<T> {
202+
fn span<copy T>(item: T) -> ast::spanned<T> {
203203
ret {node: item, span: ast_util::dummy_sp()};
204204
}
205205

src/comp/front/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
196196
ret @item;
197197
}
198198

199-
fn nospan<T>(t: T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; }
199+
fn nospan<copy T>(t: T) -> ast::spanned<T> {
200+
ret {node: t, span: dummy_sp()};
201+
}
200202

201203
fn mk_tests(cx: test_ctxt) -> @ast::item {
202204
let ret_ty = mk_test_desc_vec_ty(cx);

src/comp/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) ->
389389

390390
// Path and definition ID indexing
391391

392-
fn create_index<T>(index: [entry<T>], hash_fn: fn(T) -> uint) ->
392+
fn create_index<copy T>(index: [entry<T>], hash_fn: fn(T) -> uint) ->
393393
[@[entry<T>]] {
394394
let buckets: [@mutable [entry<T>]] = [];
395395
uint::range(0u, 256u) {|_i| buckets += [@mutable []]; };

src/comp/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn parse_ty_constr_arg(st: @pstate, sd: str_def) ->
150150
}
151151
}
152152

153-
fn parse_constr<T>(st: @pstate, sd: str_def, pser: arg_parser<T>) ->
153+
fn parse_constr<copy T>(st: @pstate, sd: str_def, pser: arg_parser<T>) ->
154154
@ty::constr_general<T> {
155155
let sp = ast_util::dummy_sp(); // FIXME: use a real span
156156
let args: [@sp_constr_arg<T>] = [];

src/comp/middle/ast_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn map_expr(cx: ctx, ex: @expr) {
7474
cx.map.insert(ex.id, node_expr(ex));
7575
}
7676

77-
fn new_smallintmap_int_adapter<V>() -> std::map::hashmap<int, V> {
77+
fn new_smallintmap_int_adapter<copy V>() -> std::map::hashmap<int, V> {
7878
let key_idx = fn (&&key: int) -> uint { key as uint };
7979
let idx_key = fn (idx: uint) -> int { idx as int };
8080
ret new_smallintmap_adapter(key_idx, idx_key);
@@ -85,11 +85,11 @@ fn new_smallintmap_int_adapter<V>() -> std::map::hashmap<int, V> {
8585
// the entire codebase adapting all the callsites to the different
8686
// interface.
8787
// FIXME: hashmap and smallintmap should support the same interface.
88-
fn new_smallintmap_adapter<K, V>(key_idx: fn(K) -> uint,
89-
idx_key: fn(uint) -> K)
88+
fn new_smallintmap_adapter<copy K, copy V>(key_idx: fn(K) -> uint,
89+
idx_key: fn(uint) -> K)
9090
-> std::map::hashmap<K, V> {
9191

92-
obj adapter<shar K, shar V>(map: smallintmap::smallintmap<V>,
92+
obj adapter<copy K, copy V>(map: smallintmap::smallintmap<V>,
9393
key_idx: fn(K) -> uint,
9494
idx_key: fn(uint) -> K) {
9595

src/comp/syntax/ast.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ type def_id = {crate: crate_num, node: node_id};
2323

2424
const local_crate: crate_num = 0;
2525

26-
tag plicit<T> { explicit(T); implicit(T); }
27-
28-
type ty_param = {ident: ident, kind: plicit<kind>};
26+
type ty_param = {ident: ident, kind: kind};
2927

3028
tag def {
3129
def_fn(def_id, purity);

src/comp/syntax/ast_util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import std::{str, option};
22
import codemap::span;
33
import ast::*;
44

5-
fn respan<T>(sp: span, t: T) -> spanned<T> { ret {node: t, span: sp}; }
5+
fn respan<copy T>(sp: span, t: T) -> spanned<T> {
6+
ret {node: t, span: sp};
7+
}
68

79
/* assuming that we're not in macro expansion */
810
fn mk_sp(lo: uint, hi: uint) -> span {
@@ -186,7 +188,7 @@ fn eq_def_id(&&a: def_id, &&b: def_id) -> bool {
186188
a == b
187189
}
188190

189-
fn new_def_id_hash<T>() -> std::map::hashmap<def_id, T> {
191+
fn new_def_id_hash<copy T>() -> std::map::hashmap<def_id, T> {
190192
std::map::mk_hashmap(hash_def_id, eq_def_id)
191193
}
192194

@@ -228,9 +230,7 @@ fn ret_by_ref(style: ret_style) -> bool {
228230
}
229231
}
230232

231-
fn ty_param_kind(tp: ty_param) -> kind {
232-
alt tp.kind { ast::implicit(x) | ast::explicit(x) { x } }
233-
}
233+
fn ty_param_kind(tp: ty_param) -> kind { tp.kind }
234234

235235
// Local Variables:
236236
// mode: rust

src/comp/syntax/ext/simplext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) ->
103103
}
104104
}
105105

106-
fn option_flatten_map<T, U>(f: fn@(T) -> option::t<U>, v: [T]) ->
106+
fn option_flatten_map<copy T, copy U>(f: fn@(T) -> option::t<U>, v: [T]) ->
107107
option::t<[U]> {
108108
let res = [];
109109
for elem: T in v {

src/comp/syntax/parse/parser.rs

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn expect_gt(p: parser) {
219219
}
220220
}
221221

222-
fn spanned<T>(lo: uint, hi: uint, node: T) -> spanned<T> {
222+
fn spanned<copy T>(lo: uint, hi: uint, node: T) -> spanned<T> {
223223
ret {node: node, span: ast_util::mk_sp(lo, hi)};
224224
}
225225

@@ -394,8 +394,8 @@ fn parse_constr_in_type(p: parser) -> @ast::ty_constr {
394394
}
395395

396396

397-
fn parse_constrs<T>(pser: block(parser) -> @ast::constr_general<T>,
398-
p: parser) ->
397+
fn parse_constrs<copy T>(pser: block(parser) -> @ast::constr_general<T>,
398+
p: parser) ->
399399
[@ast::constr_general<T>] {
400400
let constrs: [@ast::constr_general<T>] = [];
401401
while true {
@@ -595,9 +595,9 @@ fn parse_fn_block_arg(p: parser) -> ast::arg {
595595
ret {mode: m, ty: t, ident: i, id: p.get_id()};
596596
}
597597

598-
fn parse_seq_to_before_gt<T>(sep: option::t<token::token>,
599-
f: block(parser) -> T,
600-
p: parser) -> [T] {
598+
fn parse_seq_to_before_gt<copy T>(sep: option::t<token::token>,
599+
f: block(parser) -> T,
600+
p: parser) -> [T] {
601601
let first = true;
602602
let v = [];
603603
while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) &&
@@ -612,16 +612,17 @@ fn parse_seq_to_before_gt<T>(sep: option::t<token::token>,
612612
ret v;
613613
}
614614

615-
fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: block(parser) -> T,
616-
p: parser) -> [T] {
615+
fn parse_seq_to_gt<copy T>(sep: option::t<token::token>,
616+
f: block(parser) -> T, p: parser) -> [T] {
617617
let v = parse_seq_to_before_gt(sep, f, p);
618618
expect_gt(p);
619619

620620
ret v;
621621
}
622622

623-
fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: block(parser) -> T,
624-
p: parser) -> spanned<[T]> {
623+
fn parse_seq_lt_gt<copy T>(sep: option::t<token::token>,
624+
f: block(parser) -> T,
625+
p: parser) -> spanned<[T]> {
625626
let lo = p.get_lo_pos();
626627
expect(p, token::LT);
627628
let result = parse_seq_to_before_gt::<T>(sep, f, p);
@@ -630,16 +631,16 @@ fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: block(parser) -> T,
630631
ret spanned(lo, hi, result);
631632
}
632633

633-
fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>,
634-
f: block(parser) -> T, p: parser) -> [T] {
634+
fn parse_seq_to_end<copy T>(ket: token::token, sep: option::t<token::token>,
635+
f: block(parser) -> T, p: parser) -> [T] {
635636
let val = parse_seq_to_before_end(ket, sep, f, p);
636637
p.bump();
637638
ret val;
638639
}
639640

640-
fn parse_seq_to_before_end<T>(ket: token::token,
641-
sep: option::t<token::token>,
642-
f: block(parser) -> T, p: parser) -> [T] {
641+
fn parse_seq_to_before_end<copy T>(ket: token::token,
642+
sep: option::t<token::token>,
643+
f: block(parser) -> T, p: parser) -> [T] {
643644
let first: bool = true;
644645
let v: [T] = [];
645646
while p.peek() != ket {
@@ -653,9 +654,9 @@ fn parse_seq_to_before_end<T>(ket: token::token,
653654
}
654655

655656

656-
fn parse_seq<T>(bra: token::token, ket: token::token,
657-
sep: option::t<token::token>, f: block(parser) -> T,
658-
p: parser) -> spanned<[T]> {
657+
fn parse_seq<copy T>(bra: token::token, ket: token::token,
658+
sep: option::t<token::token>, f: block(parser) -> T,
659+
p: parser) -> spanned<[T]> {
659660
let lo = p.get_lo_pos();
660661
expect(p, bra);
661662
let result = parse_seq_to_before_end::<T>(ket, sep, f, p);
@@ -1741,24 +1742,18 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
17411742
ret spanned(lo, hi, bloc);
17421743
}
17431744

1744-
fn parse_ty_param(p: parser, def: ast::kind) -> ast::ty_param {
1745-
// Accept both old and new kind names for now. FIXME remove this
1746-
let k = if eat_word(p, "send") | eat_word(p, "uniq")
1747-
{ ast::explicit(ast::kind_sendable) }
1748-
else if eat_word(p, "copy") | eat_word(p, "shar")
1749-
{ ast::explicit(ast::kind_copyable) }
1750-
else if eat_word(p, "nocopy") | eat_word(p, "pin")
1751-
{ ast::explicit(ast::kind_noncopyable) }
1752-
else { ast::implicit(def) };
1745+
fn parse_ty_param(p: parser) -> ast::ty_param {
1746+
let k = if eat_word(p, "send") { ast::kind_sendable }
1747+
else if eat_word(p, "copy") { ast::kind_copyable }
1748+
else { ast::kind_noncopyable };
17531749
ret {ident: parse_ident(p), kind: k};
17541750
}
17551751

1756-
fn parse_ty_params(p: parser, def: ast::kind) -> [ast::ty_param] {
1752+
fn parse_ty_params(p: parser) -> [ast::ty_param] {
17571753
let ty_params: [ast::ty_param] = [];
17581754
if p.peek() == token::LT {
17591755
p.bump();
1760-
ty_params = parse_seq_to_gt(some(token::COMMA),
1761-
{|p| parse_ty_param(p, def)}, p);
1756+
ty_params = parse_seq_to_gt(some(token::COMMA), parse_ty_param, p);
17621757
}
17631758
ret ty_params;
17641759
}
@@ -1811,7 +1806,7 @@ fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity,
18111806

18121807
fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} {
18131808
let id = parse_value_ident(p);
1814-
let ty_params = parse_ty_params(p, ast::kind_copyable);
1809+
let ty_params = parse_ty_params(p);
18151810
ret {ident: id, tps: ty_params};
18161811
}
18171812

@@ -1864,7 +1859,7 @@ fn parse_method(p: parser) -> @ast::method {
18641859
fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item {
18651860
let lo = p.get_last_lo_pos();
18661861
let ident = parse_value_ident(p);
1867-
let ty_params = parse_ty_params(p, ast::kind_copyable);
1862+
let ty_params = parse_ty_params(p);
18681863
let fields: ast::spanned<[ast::obj_field]> =
18691864
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
18701865
parse_obj_field, p);
@@ -1881,7 +1876,7 @@ fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item {
18811876
fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
18821877
let lo = p.get_last_lo_pos();
18831878
let ident = parse_value_ident(p);
1884-
let ty_params = parse_ty_params(p, ast::kind_noncopyable);
1879+
let ty_params = parse_ty_params(p);
18851880
expect(p, token::LPAREN);
18861881
let arg_ident = parse_value_ident(p);
18871882
expect(p, token::COLON);
@@ -2045,7 +2040,7 @@ fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} {
20452040

20462041
fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
20472042
let t = parse_type_decl(p);
2048-
let tps = parse_ty_params(p, ast::kind_noncopyable);
2043+
let tps = parse_ty_params(p);
20492044
expect(p, token::EQ);
20502045
let ty = parse_ty(p, false);
20512046
let hi = p.get_hi_pos();
@@ -2056,7 +2051,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
20562051
fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
20572052
let lo = p.get_last_lo_pos();
20582053
let id = parse_ident(p);
2059-
let ty_params = parse_ty_params(p, ast::kind_noncopyable);
2054+
let ty_params = parse_ty_params(p);
20602055
let variants: [ast::variant] = [];
20612056
// Newtype syntax
20622057
if p.peek() == token::EQ {

src/comp/syntax/print/pprust.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,12 +1167,11 @@ fn print_arg_mode(s: ps, m: ast::mode) {
11671167
}
11681168
}
11691169
1170-
fn print_kind(s: ps, kind: ast::plicit<ast::kind>) {
1170+
fn print_kind(s: ps, kind: ast::kind) {
11711171
alt kind {
1172-
ast::explicit(ast::kind_sendable.) { word_nbsp(s, "send"); }
1173-
ast::explicit(ast::kind_copyable.) { word_nbsp(s, "copy"); }
1174-
ast::explicit(ast::kind_noncopyable.) { word_nbsp(s, "nocopy"); }
1175-
ast::implicit(_) {}
1172+
ast::kind_sendable. { word_nbsp(s, "send"); }
1173+
ast::kind_copyable. { word_nbsp(s, "copy"); }
1174+
ast::kind_noncopyable. {}
11761175
}
11771176
}
11781177

src/comp/syntax/util/interner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ type interner<T> =
1111
hasher: hashfn<T>,
1212
eqer: eqfn<T>};
1313

14-
fn mk<T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> {
14+
fn mk<copy T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> {
1515
let m = map::mk_hashmap::<T, uint>(hasher, eqer);
1616
ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer};
1717
}
1818

19-
fn intern<T>(itr: interner<T>, val: T) -> uint {
19+
fn intern<copy T>(itr: interner<T>, val: T) -> uint {
2020
alt itr.map.find(val) {
2121
some(idx) { ret idx; }
2222
none. {
@@ -31,7 +31,7 @@ fn intern<T>(itr: interner<T>, val: T) -> uint {
3131
// |get| isn't "pure" in the traditional sense, because it can go from
3232
// failing to returning a value as items are interned. But for typestate,
3333
// where we first check a pred and then rely on it, ceasing to fail is ok.
34-
pure fn get<T>(itr: interner<T>, idx: uint) -> T {
34+
pure fn get<copy T>(itr: interner<T>, idx: uint) -> T {
3535
unchecked {
3636
itr.vect[idx]
3737
}

src/comp/util/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn hash_def(d: ast::def_id) -> uint {
2121
ret h;
2222
}
2323

24-
fn new_def_hash<V>() -> std::map::hashmap<ast::def_id, V> {
24+
fn new_def_hash<copy V>() -> std::map::hashmap<ast::def_id, V> {
2525
let hasher: std::map::hashfn<ast::def_id> = hash_def;
2626
let eqer: std::map::eqfn<ast::def_id> = def_eq;
2727
ret std::map::mk_hashmap::<ast::def_id, V>(hasher, eqer);
@@ -162,7 +162,7 @@ fn lit_in_range(l: @ast::lit, m1: @ast::lit, m2: @ast::lit) -> bool {
162162
}
163163
}
164164

165-
fn ranges_overlap<T>(a1: T, a2: T, b1: T, b2: T) -> bool {
165+
fn ranges_overlap<copy T>(a1: T, a2: T, b1: T, b2: T) -> bool {
166166
let min1 = min(a1, a2);
167167
let max1 = max(a1, a2);
168168
let min2 = min(b1, b2);

src/comp/util/filesearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn mk_filesearch(maybe_sysroot: option::t<fs::path>,
5555
}
5656

5757
// FIXME #1001: This can't be an obj method
58-
fn search<T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> {
58+
fn search<copy T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> {
5959
for lib_search_path in filesearch.lib_search_paths() {
6060
log #fmt["searching %s", lib_search_path];
6161
for path in fs::list_dir(lib_search_path) {

src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
224224
check_variants_T(crate, codemap, filename, "ty", stolen.tys, pprust::ty_to_str, replace_ty_in_crate, cx);
225225
}
226226

227-
fn check_variants_T<T>(
227+
fn check_variants_T<copy T>(
228228
crate: ast::crate,
229229
codemap: codemap::codemap,
230230
filename: str,

0 commit comments

Comments
 (0)