Skip to content

Commit fed48cc

Browse files
committed
auto merge of #10132 : pcwalton/rust/proc, r=pcwalton
the feature gate for `once fn` if used with the `~` sigil. r? @brson
2 parents 52f42f1 + 7e77bf1 commit fed48cc

29 files changed

+252
-72
lines changed

src/compiletest/procsrv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn run(lib_path: &str,
4848
input: Option<~str>) -> Result {
4949

5050
let env = env + target_env(lib_path, prog);
51-
let mut proc = run::Process::new(prog, args, run::ProcessOptions {
51+
let mut process = run::Process::new(prog, args, run::ProcessOptions {
5252
env: Some(env),
5353
dir: None,
5454
in_fd: None,
@@ -57,9 +57,9 @@ pub fn run(lib_path: &str,
5757
});
5858

5959
for input in input.iter() {
60-
proc.input().write(input.as_bytes());
60+
process.input().write(input.as_bytes());
6161
}
62-
let output = proc.finish_with_output();
62+
let output = process.finish_with_output();
6363

6464
Result {
6565
status: output.status,

src/librustc/front/feature_gate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ impl Visitor<()> for Context {
132132

133133
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
134134
match t.node {
135-
ast::ty_closure(closure) if closure.onceness == ast::Once => {
135+
ast::ty_closure(closure) if closure.onceness == ast::Once &&
136+
closure.sigil != ast::OwnedSigil => {
136137
self.gate_feature("once_fns", t.span,
137138
"once functions are \
138139
experimental and likely to be removed");

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'self> CheckLoanCtxt<'self> {
656656

657657
fn check_move_out_from_expr(&self, expr: @ast::Expr) {
658658
match expr.node {
659-
ast::ExprFnBlock(*) => {
659+
ast::ExprFnBlock(*) | ast::ExprProc(*) => {
660660
// moves due to capture clauses are checked
661661
// in `check_loans_in_fn`, so that we can
662662
// give a better error message

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
307307
this.pop_repeating_id(body.id);
308308
}
309309

310-
ast::ExprFnBlock(*) => {
310+
ast::ExprFnBlock(*) | ast::ExprProc(*) => {
311311
gather_moves::gather_captures(this.bccx, this.move_data, ex);
312312
visit::walk_expr(this, ex, ());
313313
}

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ impl CFGBuilder {
409409
ast::ExprInlineAsm(*) |
410410
ast::ExprSelf |
411411
ast::ExprFnBlock(*) |
412+
ast::ExprProc(*) |
412413
ast::ExprLit(*) |
413414
ast::ExprPath(*) => {
414415
self.straightline(expr, pred, [])

src/librustc/middle/check_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Visitor<Context> for CheckLoopVisitor {
4949
ExprLoop(ref b, _) => {
5050
self.visit_block(b, Context { in_loop: true,.. cx });
5151
}
52-
ExprFnBlock(_, ref b) => {
52+
ExprFnBlock(_, ref b) | ExprProc(_, ref b) => {
5353
self.visit_block(b, Context { in_loop: false, can_ret: false });
5454
}
5555
ExprBreak(_) => {

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
431431
self.merge_with_entry_set(expr.id, in_out);
432432

433433
match expr.node {
434-
ast::ExprFnBlock(ref decl, ref body) => {
434+
ast::ExprFnBlock(ref decl, ref body) |
435+
ast::ExprProc(ref decl, ref body) => {
435436
if self.dfcx.oper.walk_closures() {
436437
// In the absence of once fns, we must assume that
437438
// every function body will execute more than

src/librustc/middle/freevars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Visitor<int> for CollectFreevarsVisitor {
4747
fn visit_expr(&mut self, expr:@ast::Expr, depth:int) {
4848

4949
match expr.node {
50-
ast::ExprFnBlock(*) => {
50+
ast::ExprFnBlock(*) | ast::ExprProc(*) => {
5151
visit::walk_expr(self, expr, depth + 1)
5252
}
5353
ast::ExprPath(*) | ast::ExprSelf => {

src/librustc/middle/liveness.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: @Expr, this: @mut IrMaps) {
485485
}
486486
visit::walk_expr(v, expr, this);
487487
}
488-
ExprFnBlock(*) => {
488+
ExprFnBlock(*) | ExprProc(*) => {
489489
// Interesting control flow (for loops can contain labeled
490490
// breaks or continues)
491491
this.add_live_node_for_node(expr.id, ExprNode(expr.span));
@@ -1023,8 +1023,8 @@ impl Liveness {
10231023
self.propagate_through_expr(e, succ)
10241024
}
10251025

1026-
ExprFnBlock(_, ref blk) => {
1027-
debug!("{} is an expr_fn_block",
1026+
ExprFnBlock(_, ref blk) | ExprProc(_, ref blk) => {
1027+
debug!("{} is an ExprFnBlock or ExprProc",
10281028
expr_to_str(expr, self.tcx.sess.intr()));
10291029

10301030
/*
@@ -1498,7 +1498,8 @@ fn check_expr(this: &mut Liveness, expr: @Expr) {
14981498
ExprCast(*) | ExprUnary(*) | ExprRet(*) | ExprBreak(*) |
14991499
ExprAgain(*) | ExprLit(_) | ExprBlock(*) |
15001500
ExprMac(*) | ExprAddrOf(*) | ExprStruct(*) | ExprRepeat(*) |
1501-
ExprParen(*) | ExprFnBlock(*) | ExprPath(*) | ExprSelf(*) => {
1501+
ExprParen(*) | ExprFnBlock(*) | ExprProc(*) | ExprPath(*) |
1502+
ExprSelf(*) => {
15021503
visit::walk_expr(this, expr, ());
15031504
}
15041505
ExprForLoop(*) => fail!("non-desugared expr_for_loop")

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl mem_categorization_ctxt {
424424

425425
ast::ExprAddrOf(*) | ast::ExprCall(*) |
426426
ast::ExprAssign(*) | ast::ExprAssignOp(*) |
427-
ast::ExprFnBlock(*) | ast::ExprRet(*) |
427+
ast::ExprFnBlock(*) | ast::ExprProc(*) | ast::ExprRet(*) |
428428
ast::ExprDoBody(*) | ast::ExprUnary(*) |
429429
ast::ExprMethodCall(*) | ast::ExprCast(*) | ast::ExprVstore(*) |
430430
ast::ExprVec(*) | ast::ExprTup(*) | ast::ExprIf(*) |

src/librustc/middle/moves.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ impl VisitContext {
555555
self.use_expr(base, comp_mode);
556556
}
557557

558-
ExprFnBlock(ref decl, ref body) => {
558+
ExprFnBlock(ref decl, ref body) |
559+
ExprProc(ref decl, ref body) => {
559560
for a in decl.inputs.iter() {
560561
self.use_pat(a.pat);
561562
}

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5043,7 +5043,8 @@ impl Resolver {
50435043
visit::walk_expr(self, expr, ());
50445044
}
50455045

5046-
ExprFnBlock(ref fn_decl, ref block) => {
5046+
ExprFnBlock(ref fn_decl, ref block) |
5047+
ExprProc(ref fn_decl, ref block) => {
50475048
self.resolve_function(FunctionRibKind(expr.id, block.id),
50485049
Some(fn_decl),
50495050
NoTypeParameters,

src/librustc/middle/trans/debuginfo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
569569
}
570570
ast_map::node_expr(ref expr) => {
571571
match expr.node {
572-
ast::ExprFnBlock(ref fn_decl, ref top_level_block) => {
572+
ast::ExprFnBlock(ref fn_decl, ref top_level_block) |
573+
ast::ExprProc(ref fn_decl, ref top_level_block) => {
573574
let name = format!("fn{}", token::gensym("fn"));
574575
let name = token::str_to_ident(name);
575576
(name, fn_decl,
@@ -2579,7 +2580,8 @@ fn populate_scope_map(cx: &mut CrateContext,
25792580
}
25802581
}
25812582

2582-
ast::ExprFnBlock(ast::fn_decl { inputs: ref inputs, _ }, ref block) => {
2583+
ast::ExprFnBlock(ast::fn_decl { inputs: ref inputs, _ }, ref block) |
2584+
ast::ExprProc(ast::fn_decl { inputs: ref inputs, _ }, ref block) => {
25832585
do with_new_scope(cx, block.span, scope_stack, scope_map) |cx,
25842586
scope_stack,
25852587
scope_map| {

src/librustc/middle/trans/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,11 @@ fn trans_rvalue_dps_unadjusted(bcx: @mut Block, expr: &ast::Expr,
717717
ast::ExprVec(*) | ast::ExprRepeat(*) => {
718718
return tvec::trans_fixed_vstore(bcx, expr, expr, dest);
719719
}
720-
ast::ExprFnBlock(ref decl, ref body) => {
720+
ast::ExprFnBlock(ref decl, ref body) |
721+
ast::ExprProc(ref decl, ref body) => {
721722
let expr_ty = expr_ty(bcx, expr);
722723
let sigil = ty::ty_closure_sigil(expr_ty);
723-
debug!("translating fn_block {} with type {}",
724+
debug!("translating block function {} with type {}",
724725
expr_to_str(expr, tcx.sess.intr()),
725726
expr_ty.repr(tcx));
726727
return closure::trans_expr_fn(bcx, sigil, decl, body,

src/librustc/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,7 @@ pub fn expr_kind(tcx: ctxt,
32633263
ast::ExprIf(*) |
32643264
ast::ExprMatch(*) |
32653265
ast::ExprFnBlock(*) |
3266+
ast::ExprProc(*) |
32663267
ast::ExprDoBody(*) |
32673268
ast::ExprBlock(*) |
32683269
ast::ExprRepeat(*) |

src/librustc/middle/typeck/check/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14081408
for (i, arg) in args.iter().enumerate() {
14091409
let is_block = match arg.node {
14101410
ast::ExprFnBlock(*) |
1411+
ast::ExprProc(*) |
14111412
ast::ExprDoBody(*) => true,
14121413
_ => false
14131414
};
@@ -2592,6 +2593,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
25922593
check_expr_fn(fcx, expr, None,
25932594
decl, body, Vanilla, expected);
25942595
}
2596+
ast::ExprProc(ref decl, ref body) => {
2597+
check_expr_fn(fcx,
2598+
expr,
2599+
Some(ast::OwnedSigil),
2600+
decl,
2601+
body,
2602+
Vanilla,
2603+
expected);
2604+
}
25952605
ast::ExprDoBody(b) => {
25962606
let expected_sty = unpack_expected(fcx,
25972607
expected,

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn visit_expr(rcx: &mut Rcx, expr: @ast::Expr) {
427427
visit::walk_expr(rcx, expr, ());
428428
}
429429

430-
ast::ExprFnBlock(*) => {
430+
ast::ExprFnBlock(*) | ast::ExprProc(*) => {
431431
check_expr_fn_block(rcx, expr);
432432
}
433433

@@ -457,7 +457,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
457457
expr: @ast::Expr) {
458458
let tcx = rcx.fcx.tcx();
459459
match expr.node {
460-
ast::ExprFnBlock(_, ref body) => {
460+
ast::ExprFnBlock(_, ref body) | ast::ExprProc(_, ref body) => {
461461
let function_type = rcx.resolve_node_type(expr.id);
462462
match ty::get(function_type).sty {
463463
ty::ty_closure(
@@ -1027,6 +1027,7 @@ pub mod guarantor {
10271027
ast::ExprIf(*) |
10281028
ast::ExprMatch(*) |
10291029
ast::ExprFnBlock(*) |
1030+
ast::ExprProc(*) |
10301031
ast::ExprDoBody(*) |
10311032
ast::ExprBlock(*) |
10321033
ast::ExprRepeat(*) |

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn visit_expr(e: @ast::Expr, wbcx: &mut WbCtxt) {
245245
}
246246

247247
match e.node {
248-
ast::ExprFnBlock(ref decl, _) => {
248+
ast::ExprFnBlock(ref decl, _) | ast::ExprProc(ref decl, _) => {
249249
for input in decl.inputs.iter() {
250250
let _ = resolve_type_vars_for_node(wbcx, e.span, input.id);
251251
}

src/librustc/util/ppaux.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
337337
}
338338
fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str
339339
{
340-
let mut s = cty.sigil.to_str();
340+
let is_proc =
341+
(cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
342+
343+
let mut s = if is_proc {
344+
~""
345+
} else {
346+
cty.sigil.to_str()
347+
};
341348

342349
match (cty.sigil, cty.region) {
343350
(ast::ManagedSigil, ty::re_static) |
@@ -356,15 +363,19 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
356363
}
357364
};
358365

359-
match cty.onceness {
360-
ast::Many => {}
361-
ast::Once => {
362-
s.push_str(cty.onceness.to_str());
363-
s.push_char(' ');
364-
}
365-
};
366+
if is_proc {
367+
s.push_str("proc");
368+
} else {
369+
match cty.onceness {
370+
ast::Many => {}
371+
ast::Once => {
372+
s.push_str(cty.onceness.to_str());
373+
s.push_char(' ');
374+
}
375+
};
366376

367-
s.push_str("fn");
377+
s.push_str("fn");
378+
}
368379

369380
if !cty.bounds.is_empty() {
370381
s.push_str(":");

src/libstd/rt/io/native/process.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -649,23 +649,25 @@ fn waitpid(pid: pid_t) -> int {
649649

650650
unsafe {
651651

652-
let proc = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, FALSE, pid as DWORD);
653-
if proc.is_null() {
652+
let process = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
653+
FALSE,
654+
pid as DWORD);
655+
if process.is_null() {
654656
fail!("failure in OpenProcess: {}", os::last_os_error());
655657
}
656658

657659
loop {
658660
let mut status = 0;
659-
if GetExitCodeProcess(proc, &mut status) == FALSE {
660-
CloseHandle(proc);
661+
if GetExitCodeProcess(process, &mut status) == FALSE {
662+
CloseHandle(process);
661663
fail!("failure in GetExitCodeProcess: {}", os::last_os_error());
662664
}
663665
if status != STILL_ACTIVE {
664-
CloseHandle(proc);
666+
CloseHandle(process);
665667
return status as int;
666668
}
667-
if WaitForSingleObject(proc, INFINITE) == WAIT_FAILED {
668-
CloseHandle(proc);
669+
if WaitForSingleObject(process, INFINITE) == WAIT_FAILED {
670+
CloseHandle(process);
669671
fail!("failure in WaitForSingleObject: {}", os::last_os_error());
670672
}
671673
}

src/libstd/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ mod tests {
413413
let pipe_out = os::pipe();
414414
let pipe_err = os::pipe();
415415
416-
let mut proc = run::Process::new("cat", [], run::ProcessOptions {
416+
let mut process = run::Process::new("cat", [], run::ProcessOptions {
417417
dir: None,
418418
env: None,
419419
in_fd: Some(pipe_in.input),
@@ -430,7 +430,7 @@ mod tests {
430430
}
431431
let actual = readclose(pipe_out.input);
432432
readclose(pipe_err.input);
433-
proc.finish();
433+
process.finish();
434434
435435
assert_eq!(~"test", actual);
436436
}

src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ pub enum Expr_ {
537537
ExprLoop(Block, Option<Ident>),
538538
ExprMatch(@Expr, ~[Arm]),
539539
ExprFnBlock(fn_decl, Block),
540+
ExprProc(fn_decl, Block),
540541
ExprDoBody(@Expr),
541542
ExprBlock(Block),
542543

src/libsyntax/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
786786
folder.fold_block(body)
787787
)
788788
}
789+
ExprProc(ref decl, ref body) => {
790+
ExprProc(fold_fn_decl(decl, folder), folder.fold_block(body))
791+
}
789792
ExprBlock(ref blk) => ExprBlock(folder.fold_block(blk)),
790793
ExprAssign(el, er) => {
791794
ExprAssign(folder.fold_expr(el), folder.fold_expr(er))

0 commit comments

Comments
 (0)