From 3764fe3f2a7d04d99d7c69137b7a7724a6546bcb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 4 Sep 2012 14:12:14 -0700 Subject: [PATCH] std: Camel case list --- src/libstd/arena.rs | 10 +-- src/libstd/list.rs | 86 +++++++++---------- src/libstd/std.rc | 1 - src/rustc/middle/borrowck.rs | 2 +- src/rustc/middle/resolve.rs | 2 +- src/rustc/middle/trans/type_use.rs | 8 +- src/rustc/middle/typeck.rs | 2 +- src/rustc/middle/typeck/check.rs | 10 +-- src/rustc/middle/typeck/check/regionmanip.rs | 2 +- .../typeck/infer/region_var_bindings.rs | 2 +- src/rustc/middle/typeck/infer/sub.rs | 4 +- src/test/bench/task-perf-alloc-unwind.rs | 34 ++++---- .../log-knows-the-names-of-variants-in-std.rs | 2 +- src/test/run-pass/non-boolean-pure-fns.rs | 12 +-- 14 files changed, 88 insertions(+), 89 deletions(-) diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 7037752cc26..b59ec38b352 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -24,7 +24,7 @@ export Arena, arena_with_size; -use list::{list, cons, nil}; +use list::{List, Cons, Nil}; use unsafe::reinterpret_cast; use sys::TypeDesc; use libc::size_t; @@ -53,7 +53,7 @@ struct Arena { // access the head. priv mut head: Chunk; priv mut pod_head: Chunk; - priv mut chunks: @list; + priv mut chunks: @List; drop { unsafe { destroy_chunk(self.head); @@ -73,7 +73,7 @@ fn chunk(size: uint, is_pod: bool) -> Chunk { fn arena_with_size(initial_size: uint) -> Arena { return Arena {mut head: chunk(initial_size, false), mut pod_head: chunk(initial_size, true), - mut chunks: @nil}; + mut chunks: @Nil}; } fn Arena() -> Arena { @@ -134,7 +134,7 @@ impl &Arena { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.pod_head.data); let new_min_chunk_size = uint::max(n_bytes, chunk_size); - self.chunks = @cons(copy self.pod_head, self.chunks); + self.chunks = @Cons(copy self.pod_head, self.chunks); self.pod_head = chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true); @@ -176,7 +176,7 @@ impl &Arena { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.head.data); let new_min_chunk_size = uint::max(n_bytes, chunk_size); - self.chunks = @cons(copy self.head, self.chunks); + self.chunks = @Cons(copy self.head, self.chunks); self.head = chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false); diff --git a/src/libstd/list.rs b/src/libstd/list.rs index e73152cf1ac..ff4f20e7be7 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -7,14 +7,14 @@ use core::option; use option::*; use option::{Some, None}; -enum list { - cons(T, @list), - nil, +enum List { + Cons(T, @List), + Nil, } -/// Create a list from a vector -fn from_vec(v: &[T]) -> @list { - vec::foldr(v, @nil::, |h, t| @cons(h, t)) +/// Cregate a list from a vector +fn from_vec(v: &[T]) -> @List { + vec::foldr(v, @Nil::, |h, t| @Cons(h, t)) } /** @@ -30,7 +30,7 @@ fn from_vec(v: &[T]) -> @list { * * z - The initial value * * f - The function to apply */ -fn foldl(+z: T, ls: @list, f: fn((&T), (&U)) -> T) -> T { +fn foldl(+z: T, ls: @List, f: fn((&T), (&U)) -> T) -> T { let mut accum: T = z; do iter(ls) |elt| { accum = f(&accum, &elt);} accum @@ -43,21 +43,21 @@ fn foldl(+z: T, ls: @list, f: fn((&T), (&U)) -> T) -> T { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -fn find(ls: @list, f: fn((&T)) -> bool) -> Option { +fn find(ls: @List, f: fn((&T)) -> bool) -> Option { let mut ls = ls; loop { ls = match *ls { - cons(hd, tl) => { + Cons(hd, tl) => { if f(&hd) { return Some(hd); } tl } - nil => return None + Nil => return None } }; } /// Returns true if a list contains an element with the given value -fn has(ls: @list, +elt: T) -> bool { +fn has(ls: @List, +elt: T) -> bool { for each(ls) |e| { if e == elt { return true; } } @@ -65,49 +65,49 @@ fn has(ls: @list, +elt: T) -> bool { } /// Returns true if the list is empty -pure fn is_empty(ls: @list) -> bool { +pure fn is_empty(ls: @List) -> bool { match *ls { - nil => true, + Nil => true, _ => false } } /// Returns true if the list is not empty -pure fn is_not_empty(ls: @list) -> bool { +pure fn is_not_empty(ls: @List) -> bool { return !is_empty(ls); } /// Returns the length of a list -fn len(ls: @list) -> uint { +fn len(ls: @List) -> uint { let mut count = 0u; iter(ls, |_e| count += 1u); count } /// Returns all but the first element of a list -pure fn tail(ls: @list) -> @list { +pure fn tail(ls: @List) -> @List { match *ls { - cons(_, tl) => return tl, - nil => fail ~"list empty" + Cons(_, tl) => return tl, + Nil => fail ~"list empty" } } /// Returns the first element of a list -pure fn head(ls: @list) -> T { +pure fn head(ls: @List) -> T { match *ls { - cons(hd, _) => hd, + Cons(hd, _) => hd, // makes me sad _ => fail ~"head invoked on empty list" } } /// Appends one list to another -pure fn append(l: @list, m: @list) -> @list { +pure fn append(l: @List, m: @List) -> @List { match *l { - nil => return m, - cons(x, xs) => { + Nil => return m, + Cons(x, xs) => { let rest = append(xs, m); - return @cons(x, rest); + return @Cons(x, rest); } } } @@ -121,45 +121,45 @@ pure fn push(ll: &mut @list, +vv: T) { */ /// Iterate over a list -fn iter(l: @list, f: fn(T)) { +fn iter(l: @List, f: fn(T)) { let mut cur = l; loop { cur = match *cur { - cons(hd, tl) => { + Cons(hd, tl) => { f(hd); tl } - nil => break + Nil => break } } } /// Iterate over a list -fn each(l: @list, f: fn(T) -> bool) { +fn each(l: @List, f: fn(T) -> bool) { let mut cur = l; loop { cur = match *cur { - cons(hd, tl) => { + Cons(hd, tl) => { if !f(hd) { return; } tl } - nil => break + Nil => break } } } -impl list : Eq { - pure fn eq(&&other: list) -> bool { +impl List : Eq { + pure fn eq(&&other: List) -> bool { match self { - cons(e0a, e1a) => { + Cons(e0a, e1a) => { match other { - cons(e0b, e1b) => e0a == e0b && e1a == e1b, + Cons(e0b, e1b) => e0a == e0b && e1a == e1b, _ => false } } - nil => { + Nil => { match other { - nil => true, + Nil => true, _ => false } } @@ -172,7 +172,7 @@ mod tests { #[test] fn test_is_empty() { - let empty : @list::list = from_vec(~[]); + let empty : @list::List = from_vec(~[]); let full1 = from_vec(~[1]); let full2 = from_vec(~['r', 'u']); @@ -200,15 +200,15 @@ mod tests { #[test] fn test_from_vec_empty() { - let empty : @list::list = from_vec(~[]); - assert (empty == @list::nil::); + let empty : @list::List = from_vec(~[]); + assert (empty == @list::Nil::); } #[test] fn test_foldl() { fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); } let l = from_vec(~[0, 1, 2, 3, 4]); - let empty = @list::nil::; + let empty = @list::Nil::; assert (list::foldl(0u, l, add) == 10u); assert (list::foldl(0u, empty, add) == 0u); } @@ -233,7 +233,7 @@ mod tests { fn test_find_fail() { fn match_(_i: &int) -> bool { return false; } let l = from_vec(~[0, 1, 2]); - let empty = @list::nil::; + let empty = @list::Nil::; assert (list::find(l, match_) == option::None::); assert (list::find(empty, match_) == option::None::); } @@ -241,7 +241,7 @@ mod tests { #[test] fn test_has() { let l = from_vec(~[5, 8, 6]); - let empty = @list::nil::; + let empty = @list::Nil::; assert (list::has(l, 5)); assert (!list::has(l, 7)); assert (list::has(l, 8)); @@ -251,7 +251,7 @@ mod tests { #[test] fn test_len() { let l = from_vec(~[0, 1, 2]); - let empty = @list::nil::; + let empty = @list::Nil::; assert (list::len(l) == 3u); assert (list::len(empty) == 0u); } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 2b60d4cc4be..dd7bba8d1f1 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -61,7 +61,6 @@ mod comm; mod bitv; mod deque; mod fun_treemap; -#[allow(non_camel_case_types)] // XXX mod list; #[allow(non_camel_case_types)] // XXX mod map; diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs index c5679351941..18df37373b1 100644 --- a/src/rustc/middle/borrowck.rs +++ b/src/rustc/middle/borrowck.rs @@ -223,7 +223,7 @@ use syntax::codemap::span; use util::ppaux::{ty_to_str, region_to_str, explain_region}; use std::map::{int_hash, hashmap, set}; use std::list; -use std::list::{list, cons, nil}; +use std::list::{List, Cons, Nil}; use result::{Result, Ok, Err}; use syntax::print::pprust; use util::common::indenter; diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 25fbe1b99ad..7745d7b9eef 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -59,7 +59,7 @@ use str::{connect, split_str}; use vec::pop; use syntax::parse::token::ident_interner; -use std::list::{cons, list, nil}; +use std::list::{Cons, List, Nil}; use std::map::{hashmap, int_hash, uint_hash}; use str_eq = str::eq; diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index 3a09b2f0fdc..faf01781289 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -19,7 +19,7 @@ use std::map::hashmap; use std::list; -use std::list::{list, cons, nil}; +use std::list::{List, Cons, Nil}; use driver::session::session; use metadata::csearch; use syntax::ast::*, syntax::ast_util, syntax::visit; @@ -122,14 +122,14 @@ fn type_needs(cx: ctx, use: uint, ty: ty::t) { // Optimization -- don't descend type if all params already have this use for vec::each_mut(cx.uses) |u| { if *u & use != use { - type_needs_inner(cx, use, ty, @nil); + type_needs_inner(cx, use, ty, @Nil); return; } } } fn type_needs_inner(cx: ctx, use: uint, ty: ty::t, - enums_seen: @list) { + enums_seen: @List) { do ty::maybe_walk_ty(ty) |ty| { if ty::type_has_params(ty) { match ty::get(ty).struct { @@ -143,7 +143,7 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t, | ty::ty_trait(_, _, _) => false, ty::ty_enum(did, substs) => { if option::is_none(list::find(enums_seen, |id| *id == did)) { - let seen = @cons(did, enums_seen); + let seen = @Cons(did, enums_seen); for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { for vec::each(v.args) |aty| { let t = ty::subst(cx.ccx.tcx, &substs, aty); diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 9a838d4bc24..dc484f581e7 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -64,7 +64,7 @@ use util::ppaux::{ty_to_str, tys_to_str, region_to_str, bound_region_to_str, vstore_to_str}; use util::common::{indent, indenter}; use std::list; -use list::{list, nil, cons}; +use list::{List, Nil, Cons}; export check_crate; export infer; diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index b56a8efa606..dd8ac61dd46 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -157,7 +157,7 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t, indirect_ret_ty: None, purity: ast::pure_fn, mut region_lb: region_bnd, - in_scope_regions: @nil, + in_scope_regions: @Nil, inh: blank_inherited(ccx), ccx: ccx } @@ -165,7 +165,7 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t, // a list of mapping from in-scope-region-names ("isr") to the // corresponding ty::region -type isr_alist = @list<(ty::bound_region, ty::region)>; +type isr_alist = @List<(ty::bound_region, ty::region)>; trait get_and_find_region { fn get(br: ty::bound_region) -> ty::region; @@ -225,7 +225,7 @@ fn check_fn(ccx: @crate_ctxt, // the node_id of the body block. let {isr, self_info, fn_ty} = { - let old_isr = option::map_default(old_fcx, @nil, + let old_isr = option::map_default(old_fcx, @Nil, |fcx| fcx.in_scope_regions); replace_bound_regions_in_fn_ty(tcx, old_isr, self_info, fn_ty, |br| ty::re_free(body.node.id, br)) @@ -917,7 +917,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, match structure_of(fcx, sp, in_fty) { ty::ty_fn(ref fn_ty) => { replace_bound_regions_in_fn_ty( - fcx.ccx.tcx, @nil, None, fn_ty, + fcx.ccx.tcx, @Nil, None, fn_ty, |_br| fcx.infcx().next_region_var(sp, call_expr_id)).fn_ty } @@ -1237,7 +1237,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, Some(ty::ty_fn(ref fn_ty)) => { let {fn_ty, _} = replace_bound_regions_in_fn_ty( - tcx, @nil, None, fn_ty, + tcx, @Nil, None, fn_ty, |br| ty::re_bound(ty::br_cap_avoid(expr.id, @br))); (Some({inputs:fn_ty.inputs, output:fn_ty.output}), diff --git a/src/rustc/middle/typeck/check/regionmanip.rs b/src/rustc/middle/typeck/check/regionmanip.rs index b0dd57890a9..2acdfbf8b74 100644 --- a/src/rustc/middle/typeck/check/regionmanip.rs +++ b/src/rustc/middle/typeck/check/regionmanip.rs @@ -103,7 +103,7 @@ fn replace_bound_regions_in_fn_ty( ty::re_bound(br) => { match isr.find(br) { Some(_) => isr, - None => @cons((br, to_r(br)), isr) + None => @Cons((br, to_r(br)), isr) } } } diff --git a/src/rustc/middle/typeck/infer/region_var_bindings.rs b/src/rustc/middle/typeck/infer/region_var_bindings.rs index c0714294491..ff0afdb4816 100644 --- a/src/rustc/middle/typeck/infer/region_var_bindings.rs +++ b/src/rustc/middle/typeck/infer/region_var_bindings.rs @@ -310,7 +310,7 @@ use result::Result; use result::{Ok, Err}; use std::map::{hashmap, uint_hash}; use std::cell::{Cell, empty_cell}; -use std::list::{list, nil, cons}; +use std::list::{List, Nil, Cons}; use ty::{region, region_vid, hash_region}; use region::is_subregion_of; diff --git a/src/rustc/middle/typeck/infer/sub.rs b/src/rustc/middle/typeck/infer/sub.rs index 2363c2a8251..bb36473dc3d 100644 --- a/src/rustc/middle/typeck/infer/sub.rs +++ b/src/rustc/middle/typeck/infer/sub.rs @@ -133,7 +133,7 @@ impl Sub: combine { // First, we instantiate each bound region in the subtype with a fresh // region variable. let {fn_ty: a_fn_ty, _} = { - do replace_bound_regions_in_fn_ty(self.infcx.tcx, @nil, + do replace_bound_regions_in_fn_ty(self.infcx.tcx, @Nil, None, a) |br| { // N.B.: The name of the bound region doesn't have // anything to do with the region variable that's created @@ -153,7 +153,7 @@ impl Sub: combine { // Second, we instantiate each bound region in the supertype with a // fresh concrete region. let {fn_ty: b_fn_ty, _} = { - do replace_bound_regions_in_fn_ty(self.infcx.tcx, @nil, + do replace_bound_regions_in_fn_ty(self.infcx.tcx, @Nil, None, b) |br| { // FIXME: eventually re_skolemized (issue #2263) ty::re_bound(br) diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 2f020d6cdfd..c64fd4bc89c 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -2,7 +2,7 @@ use std; -import std::list::{list, cons, nil}; +import std::list::{List, Cons, Nil}; import std::time::precise_time_s; fn main() { @@ -25,7 +25,7 @@ fn run(repeat: int, depth: int) { } } -type nillist = list<()>; +type nillist = List<()>; // Filled with things that have to be unwound enum st { @@ -56,13 +56,13 @@ fn recurse_or_fail(depth: int, st: Option) { let st = match st { None => { st_({ - box: @nil, - unique: ~nil, - fn_box: fn@() -> @nillist { @nil::<()> }, - fn_unique: fn~() -> ~nillist { ~nil::<()> }, - tuple: (@nil, ~nil), - vec: ~[@nil], - res: r(@nil) + box: @Nil, + unique: ~Nil, + fn_box: fn@() -> @nillist { @Nil::<()> }, + fn_unique: fn~() -> ~nillist { ~Nil::<()> }, + tuple: (@Nil, ~Nil), + vec: ~[@Nil], + res: r(@Nil) }) } Some(st) => { @@ -70,14 +70,14 @@ fn recurse_or_fail(depth: int, st: Option) { let fn_unique = st.fn_unique; st_({ - box: @cons((), st.box), - unique: ~cons((), @*st.unique), - fn_box: fn@() -> @nillist { @cons((), fn_box()) }, - fn_unique: fn~() -> ~nillist { ~cons((), @*fn_unique()) }, - tuple: (@cons((), st.tuple.first()), - ~cons((), @*st.tuple.second())), - vec: st.vec + ~[@cons((), st.vec.last())], - res: r(@cons((), st.res._l)) + box: @Cons((), st.box), + unique: ~Cons((), @*st.unique), + fn_box: fn@() -> @nillist { @Cons((), fn_box()) }, + fn_unique: fn~() -> ~nillist { ~Cons((), @*fn_unique()) }, + tuple: (@Cons((), st.tuple.first()), + ~Cons((), @*st.tuple.second())), + vec: st.vec + ~[@Cons((), st.vec.last())], + res: r(@Cons((), st.res._l)) }) } }; diff --git a/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs b/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs index 6fa9461a227..de9541a3c06 100644 --- a/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs +++ b/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs @@ -12,7 +12,7 @@ fn check_log(exp: ~str, v: T) { fn main() { let x = list::from_vec(~[a(22u), b(~"hi")]); - let exp = ~"@cons(a(22), @cons(b(~\"hi\"), @nil))"; + let exp = ~"@Cons(a(22), @Cons(b(~\"hi\"), @Nil))"; assert fmt!("%?", x) == exp; check_log(exp, x); } diff --git a/src/test/run-pass/non-boolean-pure-fns.rs b/src/test/run-pass/non-boolean-pure-fns.rs index 5a86d54c77f..a2f1775c734 100644 --- a/src/test/run-pass/non-boolean-pure-fns.rs +++ b/src/test/run-pass/non-boolean-pure-fns.rs @@ -2,21 +2,21 @@ use std; import std::list::*; -pure fn pure_length_go(ls: @list, acc: uint) -> uint { - match *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } } +pure fn pure_length_go(ls: @List, acc: uint) -> uint { + match *ls { nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } } } -pure fn pure_length(ls: @list) -> uint { pure_length_go(ls, 0u) } +pure fn pure_length(ls: @List) -> uint { pure_length_go(ls, 0u) } -pure fn nonempty_list(ls: @list) -> bool { pure_length(ls) > 0u } +pure fn nonempty_list(ls: @List) -> bool { pure_length(ls) > 0u } -fn safe_head(ls: @list) -> T { +fn safe_head(ls: @List) -> T { assert is_not_empty(ls); return head(ls); } fn main() { - let mylist = @cons(@1u, @nil); + let mylist = @Cons(@1u, @Nil); assert (nonempty_list(mylist)); assert (*safe_head(mylist) == 1u); }