Permalink
Browse files

Remove bind. Issue #2189

  • Loading branch information...
brson committed Jun 20, 2012
1 parent bcd3942 commit 4dcf84e4f4a9a54254fd426609ad9f1ccffae3b9
Showing with 384 additions and 806 deletions.
  1. +1 −44 doc/rust.md
  2. +0 −13 doc/tutorial.md
  3. +2 −2 src/cargo/cargo.rs
  4. +1 −1 src/compiletest/runtest.rs
  5. +16 −16 src/fuzzer/fuzzer.rs
  6. +2 −2 src/libcore/comm.rs
  7. +1 −1 src/libcore/extfmt.rs
  8. +1 −1 src/libstd/bitv.rs
  9. +1 −1 src/libstd/c_vec.rs
  10. +1 −1 src/libstd/deque.rs
  11. +4 −4 src/libstd/test.rs
  12. +1 −1 src/libstd/treemap.rs
  13. +0 −1 src/libsyntax/ast.rs
  14. +5 −5 src/libsyntax/ext/auto_serialize.rs
  15. +4 −4 src/libsyntax/ext/expand.rs
  16. +3 −1 src/libsyntax/ext/fmt.rs
  17. +4 −4 src/libsyntax/ext/qquote.rs
  18. +29 −21 src/libsyntax/ext/simplext.rs
  19. +14 −18 src/libsyntax/fold.rs
  20. +3 −2 src/libsyntax/parse.rs
  21. +3 −24 src/libsyntax/parse/parser.rs
  22. +0 −1 src/libsyntax/parse/token.rs
  23. +3 −21 src/libsyntax/print/pprust.rs
  24. +43 −38 src/libsyntax/visit.rs
  25. +5 −2 src/rustc/back/rpath.rs
  26. +2 −2 src/rustc/back/upcall.rs
  27. +59 −47 src/rustc/driver/driver.rs
  28. +1 −1 src/rustc/driver/rustc.rs
  29. +6 −6 src/rustc/front/config.rs
  30. +3 −3 src/rustc/front/test.rs
  31. +2 −2 src/rustc/metadata/creader.rs
  32. +2 −2 src/rustc/metadata/decoder.rs
  33. +3 −3 src/rustc/metadata/encoder.rs
  34. +1 −1 src/rustc/metadata/tydecode.rs
  35. +5 −5 src/rustc/middle/astencode.rs
  36. +1 −1 src/rustc/middle/borrowck/categorization.rs
  37. +2 −2 src/rustc/middle/check_alt.rs
  38. +4 −2 src/rustc/middle/check_const.rs
  39. +0 −3 src/rustc/middle/kind.rs
  40. +2 −12 src/rustc/middle/liveness.rs
  41. +23 −20 src/rustc/middle/resolve.rs
  42. +1 −1 src/rustc/middle/trans/alt.rs
  43. +10 −11 src/rustc/middle/trans/base.rs
  44. +0 −8 src/rustc/middle/trans/closure.rs
  45. +5 −5 src/rustc/middle/trans/common.rs
  46. +1 −1 src/rustc/middle/trans/type_use.rs
  47. +6 −6 src/rustc/middle/tstate/annotate.rs
  48. +1 −1 src/rustc/middle/tstate/auxiliary.rs
  49. +1 −1 src/rustc/middle/tstate/bitvectors.rs
  50. +3 −1 src/rustc/middle/tstate/ck.rs
  51. +6 −4 src/rustc/middle/tstate/collect_locals.rs
  52. +3 −19 src/rustc/middle/tstate/pre_post_conditions.rs
  53. +0 −15 src/rustc/middle/tstate/states.rs
  54. +1 −58 src/rustc/middle/typeck/check.rs
  55. +1 −1 src/rustc/middle/typeck/check/alt.rs
  56. +2 −2 src/rustc/middle/typeck/collect.rs
  57. +1 −1 src/rustc/util/common.rs
  58. +3 −1 src/rustdoc/prune_unexported_pass.rs
  59. +3 −3 src/rustdoc/reexport_pass.rs
  60. +1 −1 src/test/bench/sudoku.rs
  61. +4 −4 src/test/bench/task-perf-word-count-generic.rs
  62. +2 −2 src/test/bench/task-perf-word-count.rs
  63. +0 −4 src/test/compile-fail/auto-deref-bind.rs
  64. +0 −10 src/test/compile-fail/bind-stack-closure.rs
  65. +0 −7 src/test/compile-fail/crust-no-bind.rs
  66. +0 −8 src/test/compile-fail/fn-bare-bind.rs
  67. +1 −1 src/test/compile-fail/liveness-uninit-after-item.rs
  68. +1 −1 src/test/compile-fail/tstate-unsat-after-item.rs
  69. +0 −9 src/test/compile-fail/unsafe-fn-used-in-bind.rs
  70. +2 −1 src/test/run-fail/unwind-closure.rs
  71. +27 −27 src/test/run-pass/auto_serialize.rs
  72. +0 −5 src/test/run-pass/bind-exterior.rs
  73. +0 −16 src/test/run-pass/bind-generic.rs
  74. +0 −11 src/test/run-pass/bind-interior.rs
  75. +0 −20 src/test/run-pass/bind-methods.rs
  76. +0 −21 src/test/run-pass/bind-native-fn.rs
  77. +0 −10 src/test/run-pass/bind-native.rs
  78. +0 −7 src/test/run-pass/bind-parameterized-args-2.rs
  79. +0 −7 src/test/run-pass/bind-parameterized-args.rs
  80. +0 −11 src/test/run-pass/bind-thunk.rs
  81. +0 −11 src/test/run-pass/bind-trivial.rs
  82. +1 −1 src/test/run-pass/block-fn-coerce.rs
  83. +2 −2 src/test/run-pass/cycle-collection2.rs
  84. +2 −2 src/test/run-pass/cycle-collection4.rs
  85. +2 −2 src/test/run-pass/cycle-collection5.rs
  86. +0 −5 src/test/run-pass/drop-bind-thunk-args.rs
  87. +0 −5 src/test/run-pass/drop-parametric-closure-with-bound-box.rs
  88. +1 −1 src/test/run-pass/empty-tag.rs
  89. +1 −2 src/test/run-pass/expr-alt-generic-box1.rs
  90. +1 −2 src/test/run-pass/expr-alt-generic-box2.rs
  91. +1 −2 src/test/run-pass/expr-alt-generic-unique1.rs
  92. +1 −2 src/test/run-pass/expr-alt-generic-unique2.rs
  93. +2 −4 src/test/run-pass/expr-alt-generic.rs
  94. +1 −2 src/test/run-pass/expr-block-generic-box1.rs
  95. +1 −2 src/test/run-pass/expr-block-generic-box2.rs
  96. +1 −2 src/test/run-pass/expr-block-generic-unique1.rs
  97. +1 −2 src/test/run-pass/expr-block-generic-unique2.rs
  98. +2 −4 src/test/run-pass/expr-block-generic.rs
  99. +1 −2 src/test/run-pass/expr-if-generic-box1.rs
  100. +1 −2 src/test/run-pass/expr-if-generic-box2.rs
  101. +2 −4 src/test/run-pass/expr-if-generic.rs
  102. +2 −2 src/test/run-pass/fixed-point-bind-box.rs
  103. +2 −2 src/test/run-pass/fixed-point-bind-unique.rs
  104. +0 −10 src/test/run-pass/fn-bare-bind-generic.rs
  105. +0 −9 src/test/run-pass/fn-bare-bind.rs
  106. +0 −2 src/test/run-pass/fun-call-variants.rs
  107. +0 −10 src/test/run-pass/generic-bind-2.rs
  108. +0 −17 src/test/run-pass/generic-bind.rs
  109. +1 −1 src/test/run-pass/hashmap-memory.rs
  110. +0 −4 src/test/run-pass/issue-1899.rs
  111. +3 −3 src/test/run-pass/issue-2185.rs
  112. +1 −1 src/test/run-pass/issue-333.rs
  113. +0 −11 src/test/run-pass/issue-898.rs
  114. +0 −8 src/test/run-pass/rebind-fn.rs
  115. +1 −1 src/test/run-pass/unchecked-predicates.rs
  116. +1 −1 src/test/run-pass/weird-exprs.rs
View
@@ -980,7 +980,7 @@ fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
pure fn pure_length<T>(ls: list<T>) -> uint {
fn count<T>(_t: T, &&u: uint) -> uint { u + 1u }
unchecked {
- pure_foldl(ls, 0u, count(_, _))
+ pure_foldl(ls, 0u, count)
}
}
~~~~
@@ -1941,49 +1941,6 @@ An example of a call expression:
let x: int = add(1, 2);
~~~~
-
-### Bind expressions
-
-A _bind expression_ constructs a new function from an existing function.^[The
-`bind` expression is analogous to the `bind` expression in the Sather
-language.] The new function has zero or more of its arguments *bound* into a
-new, hidden boxed tuple that holds the bindings. For each concrete argument
-passed in the `bind` expression, the corresponding parameter in the existing
-function is *omitted* as a parameter of the new function. For each argument
-passed the placeholder symbol `_` in the `bind` expression, the corresponding
-parameter of the existing function is *retained* as a parameter of the new
-function.
-
-Any subsequent invocation of the new function with residual arguments causes
-invocation of the existing function with the combination of bound arguments
-and residual arguments that was specified during the binding.
-
-An example of a `bind` expression:
-
-~~~~{.xfail-test}
-fn add(x: int, y: int) -> int {
- ret x + y;
-}
-type single_param_fn = fn(int) -> int;
-
-let add4: single_param_fn = bind add(4, _);
-
-let add5: single_param_fn = bind add(_, 5);
-
-assert (add(4,5) == add4(5));
-assert (add(4,5) == add5(4));
-
-~~~~
-
-A `bind` expression generally stores a copy of the bound arguments in a
-hidden, boxed tuple, owned by the resulting first-class function. For each
-bound slot in the bound function's signature, space is allocated in the hidden
-tuple and populated with a copy of the bound value.
-
-A `bind` expression is an alternative way of constructing a shared function
-closure; the [`fn@` expression](#shared-function-expressions) form is another
-way.
-
### Shared function expressions
*TODO*.
View
@@ -903,19 +903,6 @@ argument to every element of a vector, producing a new vector.
Even when a closure takes no parameters, you must still write the bars
for the parameter list, as in `{|| ...}`.
-## Binding
-
-Partial application is done using the `bind` keyword in Rust.
-
-~~~~
-let findx = bind str::find_char(_, 'x');
-~~~~
-
-Binding a function produces a boxed closure (`fn@` type) in which some
-of the arguments to the bound function have already been provided.
-`findx` will be a function taking a single string argument, and
-returning the position where the letter `x` occurs.
-
## Iteration
Functions taking closures provide a good way to define non-trivial
View
@@ -328,8 +328,8 @@ fn load_crate(filename: str) -> option<crate> {
mut deps: []
};
let v = visit::mk_simple_visitor(@{
- visit_view_item: bind goto_view_item(e, _),
- visit_item: bind goto_item(e, _),
+ visit_view_item: {|a|goto_view_item(e, a)},
+ visit_item: {|a|goto_item(e, a)},
with *visit::default_simple_visitor()
});
@@ -325,7 +325,7 @@ fn compose_and_run_compiler(
let abs_ab = path::connect(config.aux_base, rel_ab);
let aux_args =
make_compile_args(config, props, ["--lib"] + extra_link_args,
- bind make_lib_name(_, _, testfile), abs_ab);
+ {|a,b|make_lib_name(a, b, testfile)}, abs_ab);
let auxres = compose_and_run(config, abs_ab, aux_args, [],
config.compile_lib_path, option::none);
if auxres.status != 0 {
View
@@ -139,8 +139,8 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
let exprs = @mut [];
let tys = @mut [];
let v = visit::mk_simple_visitor(@{
- visit_expr: bind stash_expr_if(safe_to_steal_expr, exprs, _, tm),
- visit_ty: bind stash_ty_if(safe_to_steal_ty, tys, _, tm)
+ visit_expr: {|a|stash_expr_if(safe_to_steal_expr, exprs, a, tm)},
+ visit_ty: {|a|stash_ty_if(safe_to_steal_ty, tys, a, tm)}
with *visit::default_simple_visitor()
});
visit::visit_crate(crate, (), v);
@@ -188,8 +188,8 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint,
}
}
let afp =
- @{fold_expr: fold::wrap(bind fold_expr_rep(j, i,
- newexpr.node, _, _, tm))
+ @{fold_expr: fold::wrap({|a,b|
+ fold_expr_rep(j, i, newexpr.node, a, b, tm)})
with *fold::default_ast_fold()};
let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -211,7 +211,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty,
} else { fold::noop_fold_ty(original, fld) }
}
let afp =
- @{fold_ty: fold::wrap(bind fold_ty_rep(j, i, newty.node, _, _, tm))
+ @{fold_ty: fold::wrap({|a,b|fold_ty_rep(j, i, newty.node, a, b, tm)})
with *fold::default_ast_fold()};
let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -235,7 +235,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
filename: str, cx: context) {
let stolen = steal(crate, cx.mode);
let extra_exprs = vec::filter(common_exprs(),
- bind safe_to_use_expr(_, cx.mode));
+ {|a|safe_to_use_expr(a, cx.mode)});
check_variants_T(crate, codemap, filename, "expr",
extra_exprs + stolen.exprs, pprust::expr_to_str,
replace_expr_in_crate, cx);
@@ -268,13 +268,13 @@ fn check_variants_T<T: copy>(
// testing the string for stability is easier and ok for now.
let handler = diagnostic::mk_handler(none);
let str3 =
- @as_str(bind pprust::print_crate(
+ @as_str({|a|pprust::print_crate(
codemap,
diagnostic::mk_span_handler(handler, codemap),
crate2,
filename,
- io::str_reader(""), _,
- pprust::no_ann()));
+ io::str_reader(""), a,
+ pprust::no_ann())});
alt cx.mode {
tm_converge {
check_roundtrip_convergence(str3, 1u);
@@ -421,12 +421,12 @@ fn parse_and_print(code: @str) -> str {
let crate = parse::parse_crate_from_source_str(
filename, code, [], sess);
io::with_str_reader(*code) { |rdr|
- as_str(bind pprust::print_crate(sess.cm,
+ as_str({|a|pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
filename,
- rdr, _,
- pprust::no_ann()))
+ rdr, a,
+ pprust::no_ann())})
}
}
@@ -439,7 +439,7 @@ fn has_raw_pointers(c: ast::crate) -> bool {
}
}
let v =
- visit::mk_simple_visitor(@{visit_ty: bind visit_ty(has_rp, _)
+ visit::mk_simple_visitor(@{visit_ty: {|a|visit_ty(has_rp, a)}
with *visit::default_simple_visitor()});
visit::visit_crate(c, (), v);
ret *has_rp;
@@ -565,12 +565,12 @@ fn check_variants(files: [str], cx: context) {
s, [], sess);
io::with_str_reader(*s) { |rdr|
#error("%s",
- as_str(bind pprust::print_crate(sess.cm,
+ as_str({|a|pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
file,
- rdr, _,
- pprust::no_ann())));
+ rdr, a,
+ pprust::no_ann())}));
}
check_variants_of_ast(*crate, sess.cm, file, cx);
}
View
@@ -177,11 +177,11 @@ fn peek<T: send>(p: port<T>) -> bool { peek_(***p) }
#[doc(hidden)]
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
- as_raw_port(ch, recv_(_))
+ as_raw_port(ch, {|x|recv_(x)})
}
fn peek_chan<T: send>(ch: comm::chan<T>) -> bool {
- as_raw_port(ch, peek_(_))
+ as_raw_port(ch, {|x|peek_(x)})
}
#[doc = "Receive on a raw port pointer"]
View
@@ -174,7 +174,7 @@ mod ct {
let curr: [flag] = [f];
ret {flags: curr + rest, next: j};
}
- let more = bind more_(_, s, i, lim);
+ let more = {|x|more_(x, s, i, lim)};
let f = s[i];
ret if f == '-' as u8 {
more(flag_left_justify)
View
@@ -185,7 +185,7 @@ Converts the bitvector to a vector of uint with the same length.
Each uint in the resulting vector has either value 0u or 1u.
"]
fn to_vec(v: bitv) -> [uint] {
- let sub = bind init_to_vec(v, _);
+ let sub = {|x|init_to_vec(v, x)};
ret vec::from_fn::<uint>(v.nbits, sub);
}
View
@@ -136,7 +136,7 @@ mod tests {
assert mem as int != 0;
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
- bind free(mem)) };
+ {||free(mem)}) };
}
#[test]
View
@@ -292,7 +292,7 @@ mod tests {
two(17, 42));
#debug("*** test parameterized: taggypar<int>");
- let eq4: eqfn<taggypar<int>> = bind taggypareq::<int>(_, _);
+ let eq4: eqfn<taggypar<int>> = {|x,y|taggypareq::<int>(x, y)};
test_parameterized::<taggypar<int>>(eq4, onepar::<int>(1),
twopar::<int>(1, 2),
threepar::<int>(1, 2, 3),
View
@@ -162,7 +162,7 @@ fn run_tests_console(opts: test_opts,
mut ignored: 0u,
mut failures: []};
- run_tests(opts, tests, bind callback(_, st));
+ run_tests(opts, tests, {|x|callback(x, st)});
assert (st.passed + st.failed + st.ignored == st.total);
let success = st.failed == 0u;
@@ -349,7 +349,7 @@ fn filter_tests(opts: test_opts,
} else { ret option::none; }
}
- let filter = bind filter_fn(_, filter_str);
+ let filter = {|x|filter_fn(x, filter_str)};
vec::filter_map(filtered, filter)
};
@@ -367,7 +367,7 @@ fn filter_tests(opts: test_opts,
} else { ret option::none; }
};
- vec::filter_map(filtered, bind filter(_))
+ vec::filter_map(filtered, {|x|filter(x)})
};
// Sort the tests alphabetically
@@ -376,7 +376,7 @@ fn filter_tests(opts: test_opts,
fn lteq(t1: test_desc, t2: test_desc) -> bool {
str::le(t1.name, t2.name)
}
- sort::merge_sort(bind lteq(_, _), filtered)
+ sort::merge_sort({|x,y|lteq(x, y)}, filtered)
};
ret filtered;
View
@@ -125,7 +125,7 @@ mod tests {
fn t(n: @mut int, &&k: int, &&_v: ()) {
assert (*n == k); *n += 1;
}
- traverse(m, bind t(n, _, _));
+ traverse(m, {|x,y|t(n, x, y)});
}
#[test]
View
@@ -300,7 +300,6 @@ enum expr_ {
expr_rec([field], option<@expr>),
expr_call(@expr, [@expr], bool), // True iff last argument is a block
expr_tup([@expr]),
- expr_bind(@expr, [option<@expr>]),
expr_binary(binop, @expr, @expr),
expr_unary(unop, @expr),
expr_lit(@lit),
@@ -267,7 +267,7 @@ impl helpers for ext_ctxt {
}
let fld = fold::make_fold(@{
- new_span: repl_sp(_, ast_util::dummy_sp(), span)
+ new_span: {|a|repl_sp(a, ast_util::dummy_sp(), span)}
with *fold::default_ast_fold()
});
@@ -757,8 +757,8 @@ fn ty_fns(cx: ext_ctxt, name: ast::ident, ty: @ast::ty, tps: [ast::ty_param])
let span = ty.span;
[
- mk_ser_fn(cx, span, name, tps, ser_ty(_, _, ty, _, _)),
- mk_deser_fn(cx, span, name, tps, deser_ty(_, _, ty, _))
+ mk_ser_fn(cx, span, name, tps, {|a,b,c,d|ser_ty(a, b, ty, c, d)}),
+ mk_deser_fn(cx, span, name, tps, {|a,b,c|deser_ty(a, b, ty, c)})
]
}
@@ -860,8 +860,8 @@ fn enum_fns(cx: ext_ctxt, e_name: ast::ident, e_span: span,
-> [@ast::item] {
[
mk_ser_fn(cx, e_span, e_name, tps,
- ser_enum(_, _, e_name, e_span, variants, _, _)),
+ {|a,b,c,d|ser_enum(a, b, e_name, e_span, variants, c, d)}),
mk_deser_fn(cx, e_span, e_name, tps,
- deser_enum(_, _, e_name, e_span, variants, _))
+ {|a,b,c|deser_enum(a, b, e_name, e_span, variants, c)})
]
}
@@ -130,10 +130,10 @@ fn expand_crate(parse_sess: parse::parse_sess,
let afp = default_ast_fold();
let cx: ext_ctxt = mk_ctxt(parse_sess, cfg);
let f_pre =
- @{fold_expr: bind expand_expr(exts, cx, _, _, _, afp.fold_expr),
- fold_mod: bind expand_mod_items(exts, cx, _, _, afp.fold_mod),
- fold_item: bind expand_item(cx, _, _, afp.fold_item),
- new_span: bind new_span(cx, _)
+ @{fold_expr: {|a,b,c|expand_expr(exts, cx, a, b, c, afp.fold_expr)},
+ fold_mod: {|a,b|expand_mod_items(exts, cx, a, b, afp.fold_mod)},
+ fold_item: {|a,b|expand_item(cx, a, b, afp.fold_item)},
+ new_span: {|a|new_span(cx, a)}
with *afp};
let f = make_fold(f_pre);
let cm = parse_expr_from_source_str("<core-macros>",
View
@@ -23,7 +23,9 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! {
cx.span_fatal(sp, msg);
}
- let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
+ let parse_fmt_err = fn@(s: str) -> ! {
+ parse_fmt_err_(cx, fmtspan, s)
+ };
let pieces = parse_fmt_string(fmt, parse_fmt_err);
ret pieces_to_expr(cx, sp, pieces, args);
}
@@ -274,10 +274,10 @@ fn replace<T>(node: T, repls: [fragment], ff: fn (ast_fold, T) -> T)
-> T
{
let aft = default_ast_fold();
- let f_pre = @{fold_expr: bind replace_expr(repls, _, _, _,
- aft.fold_expr),
- fold_ty: bind replace_ty(repls, _, _, _,
- aft.fold_ty)
+ let f_pre = @{fold_expr: {|a,b,c|replace_expr(repls, a, b, c,
+ aft.fold_expr)},
+ fold_ty: {|a,b,c|replace_ty(repls, a, b, c,
+ aft.fold_ty)}
with *aft};
ret ff(make_fold(f_pre), node);
}
Oops, something went wrong.

0 comments on commit 4dcf84e

Please sign in to comment.