diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-18 12:39:20 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-18 12:49:01 +0100 |
| commit | f6491bb42636f4c43f3cbb48fdb98ddd749e6e5d (patch) | |
| tree | c22607ada38b85ce4fadda6cf89998f6684a4964 /src/comp | |
| parent | 8f8ebb550cf7e641d7dedd56e08efd4f0e15afab (diff) | |
| download | rust-f6491bb42636f4c43f3cbb48fdb98ddd749e6e5d.tar.gz rust-f6491bb42636f4c43f3cbb48fdb98ddd749e6e5d.zip | |
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
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/front/attr.rs | 2 | ||||
| -rw-r--r-- | src/comp/front/test.rs | 4 | ||||
| -rw-r--r-- | src/comp/metadata/encoder.rs | 2 | ||||
| -rw-r--r-- | src/comp/metadata/tydecode.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/ast_map.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 65 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 9 | ||||
| -rw-r--r-- | src/comp/syntax/util/interner.rs | 6 | ||||
| -rw-r--r-- | src/comp/util/common.rs | 4 | ||||
| -rw-r--r-- | src/comp/util/filesearch.rs | 2 |
13 files changed, 57 insertions, 63 deletions
diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index cb7b652a256..0c3fac3b46f 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -199,7 +199,7 @@ fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) { } } -fn span<T>(item: T) -> ast::spanned<T> { +fn span<copy T>(item: T) -> ast::spanned<T> { ret {node: item, span: ast_util::dummy_sp()}; } diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index 6bb6651294f..95c592eeada 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -196,7 +196,9 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item { ret @item; } -fn nospan<T>(t: T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; } +fn nospan<copy T>(t: T) -> ast::spanned<T> { + ret {node: t, span: dummy_sp()}; +} fn mk_tests(cx: test_ctxt) -> @ast::item { let ret_ty = mk_test_desc_vec_ty(cx); diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index bee96f53f0d..8eb0ea64e49 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -389,7 +389,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<copy T>(index: [entry<T>], hash_fn: fn(T) -> uint) -> [@[entry<T>]] { let buckets: [@mutable [entry<T>]] = []; uint::range(0u, 256u) {|_i| buckets += [@mutable []]; }; diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs index 8e71ff86f56..9034e5bb261 100644 --- a/src/comp/metadata/tydecode.rs +++ b/src/comp/metadata/tydecode.rs @@ -150,7 +150,7 @@ fn parse_ty_constr_arg(st: @pstate, sd: str_def) -> } } -fn parse_constr<T>(st: @pstate, sd: str_def, pser: arg_parser<T>) -> +fn parse_constr<copy T>(st: @pstate, sd: str_def, pser: arg_parser<T>) -> @ty::constr_general<T> { let sp = ast_util::dummy_sp(); // FIXME: use a real span let args: [@sp_constr_arg<T>] = []; diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index 240e14749e9..af4a5272246 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -74,7 +74,7 @@ fn map_expr(cx: ctx, ex: @expr) { cx.map.insert(ex.id, node_expr(ex)); } -fn new_smallintmap_int_adapter<V>() -> std::map::hashmap<int, V> { +fn new_smallintmap_int_adapter<copy V>() -> std::map::hashmap<int, V> { let key_idx = fn (&&key: int) -> uint { key as uint }; let idx_key = fn (idx: uint) -> int { idx as int }; ret new_smallintmap_adapter(key_idx, idx_key); @@ -85,11 +85,11 @@ fn new_smallintmap_int_adapter<V>() -> std::map::hashmap<int, V> { // the entire codebase adapting all the callsites to the different // interface. // FIXME: hashmap and smallintmap should support the same interface. -fn new_smallintmap_adapter<K, V>(key_idx: fn(K) -> uint, - idx_key: fn(uint) -> K) +fn new_smallintmap_adapter<copy K, copy V>(key_idx: fn(K) -> uint, + idx_key: fn(uint) -> K) -> std::map::hashmap<K, V> { - obj adapter<shar K, shar V>(map: smallintmap::smallintmap<V>, + obj adapter<copy K, copy V>(map: smallintmap::smallintmap<V>, key_idx: fn(K) -> uint, idx_key: fn(uint) -> K) { diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index b5164b54c6c..9733d6e53fa 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -23,9 +23,7 @@ type def_id = {crate: crate_num, node: node_id}; const local_crate: crate_num = 0; -tag plicit<T> { explicit(T); implicit(T); } - -type ty_param = {ident: ident, kind: plicit<kind>}; +type ty_param = {ident: ident, kind: kind}; tag def { def_fn(def_id, purity); diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 6091b24ac1b..2af904bdef0 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -2,7 +2,9 @@ import std::{str, option}; import codemap::span; import ast::*; -fn respan<T>(sp: span, t: T) -> spanned<T> { ret {node: t, span: sp}; } +fn respan<copy T>(sp: span, t: T) -> spanned<T> { + ret {node: t, span: sp}; +} /* assuming that we're not in macro expansion */ fn mk_sp(lo: uint, hi: uint) -> span { @@ -186,7 +188,7 @@ fn eq_def_id(&&a: def_id, &&b: def_id) -> bool { a == b } -fn new_def_id_hash<T>() -> std::map::hashmap<def_id, T> { +fn new_def_id_hash<copy T>() -> std::map::hashmap<def_id, T> { std::map::mk_hashmap(hash_def_id, eq_def_id) } @@ -228,9 +230,7 @@ fn ret_by_ref(style: ret_style) -> bool { } } -fn ty_param_kind(tp: ty_param) -> kind { - alt tp.kind { ast::implicit(x) | ast::explicit(x) { x } } -} +fn ty_param_kind(tp: ty_param) -> kind { tp.kind } // Local Variables: // mode: rust diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 252dd33a1f1..dd66c1bef92 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -103,7 +103,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<copy T, copy U>(f: fn@(T) -> option::t<U>, 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 d33bd89d5d8..2f6257f1064 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -219,7 +219,7 @@ fn expect_gt(p: parser) { } } -fn spanned<T>(lo: uint, hi: uint, node: T) -> spanned<T> { +fn spanned<copy T>(lo: uint, hi: uint, node: T) -> spanned<T> { ret {node: node, span: ast_util::mk_sp(lo, hi)}; } @@ -394,8 +394,8 @@ fn parse_constr_in_type(p: parser) -> @ast::ty_constr { } -fn parse_constrs<T>(pser: block(parser) -> @ast::constr_general<T>, - p: parser) -> +fn parse_constrs<copy T>(pser: block(parser) -> @ast::constr_general<T>, + p: parser) -> [@ast::constr_general<T>] { let constrs: [@ast::constr_general<T>] = []; while true { @@ -595,9 +595,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: block(parser) -> T, - p: parser) -> [T] { +fn parse_seq_to_before_gt<copy T>(sep: option::t<token::token>, + f: block(parser) -> T, + p: parser) -> [T] { let first = true; let v = []; 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>, ret v; } -fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: block(parser) -> T, - p: parser) -> [T] { +fn parse_seq_to_gt<copy T>(sep: option::t<token::token>, + f: block(parser) -> T, p: parser) -> [T] { let v = parse_seq_to_before_gt(sep, f, p); expect_gt(p); ret v; } -fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: block(parser) -> T, - p: parser) -> spanned<[T]> { +fn parse_seq_lt_gt<copy T>(sep: option::t<token::token>, + f: block(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, token::LT); 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, ret spanned(lo, hi, result); } -fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>, - f: block(parser) -> T, p: parser) -> [T] { +fn parse_seq_to_end<copy T>(ket: token::token, sep: option::t<token::token>, + f: block(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: block(parser) -> T, p: parser) -> [T] { +fn parse_seq_to_before_end<copy T>(ket: token::token, + sep: option::t<token::token>, + f: block(parser) -> T, p: parser) -> [T] { let first: bool = true; let v: [T] = []; while p.peek() != ket { @@ -653,9 +654,9 @@ fn parse_seq_to_before_end<T>(ket: token::token, } -fn parse_seq<T>(bra: token::token, ket: token::token, - sep: option::t<token::token>, f: block(parser) -> T, - p: parser) -> spanned<[T]> { +fn parse_seq<copy T>(bra: token::token, ket: token::token, + sep: option::t<token::token>, f: block(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, bra); 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 { ret spanned(lo, hi, bloc); } -fn parse_ty_param(p: parser, def: ast::kind) -> ast::ty_param { - // Accept both old and new kind names for now. FIXME remove this - let k = if eat_word(p, "send") | eat_word(p, "uniq") - { ast::explicit(ast::kind_sendable) } - else if eat_word(p, "copy") | eat_word(p, "shar") - { ast::explicit(ast::kind_copyable) } - else if eat_word(p, "nocopy") | eat_word(p, "pin") - { ast::explicit(ast::kind_noncopyable) } - else { ast::implicit(def) }; +fn parse_ty_param(p: parser) -> ast::ty_param { + let k = if eat_word(p, "send") { ast::kind_sendable } + else if eat_word(p, "copy") { ast::kind_copyable } + else { ast::kind_noncopyable }; ret {ident: parse_ident(p), kind: k}; } -fn parse_ty_params(p: parser, def: ast::kind) -> [ast::ty_param] { +fn parse_ty_params(p: parser) -> [ast::ty_param] { let ty_params: [ast::ty_param] = []; if p.peek() == token::LT { p.bump(); - ty_params = parse_seq_to_gt(some(token::COMMA), - {|p| parse_ty_param(p, def)}, p); + ty_params = parse_seq_to_gt(some(token::COMMA), parse_ty_param, p); } ret ty_params; } @@ -1811,7 +1806,7 @@ fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity, fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} { let id = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_copyable); + let ty_params = parse_ty_params(p); ret {ident: id, tps: ty_params}; } @@ -1864,7 +1859,7 @@ fn parse_method(p: parser) -> @ast::method { fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_copyable); + let ty_params = parse_ty_params(p); let fields: ast::spanned<[ast::obj_field]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_obj_field, p); @@ -1881,7 +1876,7 @@ fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_noncopyable); + let ty_params = parse_ty_params(p); expect(p, token::LPAREN); let arg_ident = parse_value_ident(p); expect(p, token::COLON); @@ -2045,7 +2040,7 @@ fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} { fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { let t = parse_type_decl(p); - let tps = parse_ty_params(p, ast::kind_noncopyable); + let tps = parse_ty_params(p); expect(p, token::EQ); let ty = parse_ty(p, false); let hi = p.get_hi_pos(); @@ -2056,7 +2051,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); - let ty_params = parse_ty_params(p, ast::kind_noncopyable); + let ty_params = parse_ty_params(p); let variants: [ast::variant] = []; // Newtype syntax if p.peek() == token::EQ { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index dc09187e062..bf87410b885 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1167,12 +1167,11 @@ fn print_arg_mode(s: ps, m: ast::mode) { } } -fn print_kind(s: ps, kind: ast::plicit<ast::kind>) { +fn print_kind(s: ps, kind: ast::kind) { alt kind { - ast::explicit(ast::kind_sendable.) { word_nbsp(s, "send"); } - ast::explicit(ast::kind_copyable.) { word_nbsp(s, "copy"); } - ast::explicit(ast::kind_noncopyable.) { word_nbsp(s, "nocopy"); } - ast::implicit(_) {} + ast::kind_sendable. { word_nbsp(s, "send"); } + ast::kind_copyable. { word_nbsp(s, "copy"); } + ast::kind_noncopyable. {} } } diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs index c814f168a4a..6993eeee35e 100644 --- a/src/comp/syntax/util/interner.rs +++ b/src/comp/syntax/util/interner.rs @@ -11,12 +11,12 @@ type interner<T> = hasher: hashfn<T>, eqer: eqfn<T>}; -fn mk<T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { +fn mk<copy T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { let m = map::mk_hashmap::<T, uint>(hasher, eqer); ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; } -fn intern<T>(itr: interner<T>, val: T) -> uint { +fn intern<copy T>(itr: interner<T>, val: T) -> uint { alt itr.map.find(val) { some(idx) { ret idx; } none. { @@ -31,7 +31,7 @@ fn intern<T>(itr: interner<T>, val: T) -> uint { // |get| isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. -pure fn get<T>(itr: interner<T>, idx: uint) -> T { +pure fn get<copy T>(itr: interner<T>, idx: uint) -> T { unchecked { itr.vect[idx] } diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index b20f0c59f01..22c344e6200 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -21,7 +21,7 @@ fn hash_def(d: ast::def_id) -> uint { ret h; } -fn new_def_hash<V>() -> std::map::hashmap<ast::def_id, V> { +fn new_def_hash<copy V>() -> std::map::hashmap<ast::def_id, V> { let hasher: std::map::hashfn<ast::def_id> = hash_def; let eqer: std::map::eqfn<ast::def_id> = def_eq; 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 { } } -fn ranges_overlap<T>(a1: T, a2: T, b1: T, b2: T) -> bool { +fn ranges_overlap<copy T>(a1: T, a2: T, b1: T, b2: T) -> bool { let min1 = min(a1, a2); let max1 = max(a1, a2); let min2 = min(b1, b2); diff --git a/src/comp/util/filesearch.rs b/src/comp/util/filesearch.rs index 5e51f6c6840..bd9735034e3 100644 --- a/src/comp/util/filesearch.rs +++ b/src/comp/util/filesearch.rs @@ -55,7 +55,7 @@ fn mk_filesearch(maybe_sysroot: option::t<fs::path>, } // FIXME #1001: This can't be an obj method -fn search<T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> { +fn search<copy T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> { for lib_search_path in filesearch.lib_search_paths() { log #fmt["searching %s", lib_search_path]; for path in fs::list_dir(lib_search_path) { |
