Skip to content

Commit c87d3a1

Browse files
committed
---
yaml --- r: 475 b: refs/heads/master c: b713405 h: refs/heads/master i: 473: d31223b 471: 15a0cae v: v3
1 parent 8794b7d commit c87d3a1

File tree

17 files changed

+152
-96
lines changed

17 files changed

+152
-96
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: df75a968c56935cca1c1482a8703eca82c607c62
2+
refs/heads/master: b71340552fa0caa870877f87a1273e8d4c91efe6

trunk/doc/rust.texi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,12 +2822,15 @@ x.y = z + 2;
28222822
@c * Ref.Stmt.Spawn:: Statements creating new tasks.
28232823
@cindex Spawn statement
28242824

2825-
A @code{spawn} statement consists of keyword @code{spawn}, followed by a
2826-
normal @emph{call} statement (@pxref{Ref.Stmt.Call}). A @code{spawn}
2827-
statement causes the runtime to construct a new task executing the called
2828-
function. The called function is referred to as the @dfn{entry function} for
2829-
the spawned task, and its arguments are copied from the spawning task to the
2830-
spawned task before the spawned task begins execution.
2825+
A @code{spawn} statement consists of keyword @code{spawn}, followed by
2826+
an optional literal string naming the new task and then a normal
2827+
@emph{call} statement (@pxref{Ref.Stmt.Call}). A @code{spawn}
2828+
statement causes the runtime to construct a new task executing the
2829+
called function with the given name. The called function is referred
2830+
to as the @dfn{entry function} for the spawned task, and its arguments
2831+
are copied from the spawning task to the spawned task before the
2832+
spawned task begins execution. If no explicit name is present, the
2833+
task is implicitly named with the string of the call statement.
28312834

28322835
Functions taking alias-slot arguments, or returning non-nil values, cannot be
28332836
spawned. Iterators cannot be spawned.
@@ -2843,6 +2846,7 @@ fn helper(chan[u8] out) @{
28432846
28442847
let port[u8] out;
28452848
let task p = spawn helper(chan(out));
2849+
let task p2 = spawn "my_helper" helper(chan(out));
28462850
// let task run, do other things.
28472851
auto result <- out;
28482852

trunk/src/boot/fe/ast.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ and tup_input = (mutability * atom)
199199
and stmt' =
200200

201201
(* lval-assigning stmts. *)
202-
STMT_spawn of (lval * domain * lval * (atom array))
202+
STMT_spawn of (lval * domain * string * lval * (atom array))
203203
| STMT_new_rec of (lval * (rec_input array) * lval option)
204204
| STMT_new_tup of (lval * (tup_input array))
205205
| STMT_new_vec of (lval * mutability * atom array)
@@ -936,10 +936,11 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
936936
fmt ff ";"
937937
end
938938

939-
| STMT_spawn (dst, domain, fn, args) ->
939+
| STMT_spawn (dst, domain, name, fn, args) ->
940940
fmt_lval ff dst;
941941
fmt ff " = spawn ";
942942
fmt_domain ff domain;
943+
fmt_str ff ("\"" ^ name ^ "\"");
943944
fmt_lval ff fn;
944945
fmt_atoms ff args;
945946
fmt ff ";";

trunk/src/boot/fe/pexp.ml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Parser;;
1818

1919
type pexp' =
2020
PEXP_call of (pexp * pexp array)
21-
| PEXP_spawn of (Ast.domain * pexp)
21+
| PEXP_spawn of (Ast.domain * string * pexp)
2222
| PEXP_bind of (pexp * pexp option array)
2323
| PEXP_rec of ((Ast.ident * Ast.mutability * pexp) array * pexp option)
2424
| PEXP_tup of ((Ast.mutability * pexp) array)
@@ -558,9 +558,27 @@ and parse_bottom_pexp (ps:pstate) : pexp =
558558
THREAD -> bump ps; Ast.DOMAIN_thread
559559
| _ -> Ast.DOMAIN_local
560560
in
561-
let pexp = ctxt "spawn [domain] pexp: init call" parse_pexp ps in
561+
(* Spawns either have an explicit literal string for the spawned
562+
task's name, or the task is named as the entry call
563+
expression. *)
564+
let explicit_name =
565+
match peek ps with
566+
LIT_STR s -> bump ps; Some s
567+
| _ -> None
568+
in
569+
let pexp =
570+
ctxt "spawn [domain] [name] pexp: init call" parse_pexp ps
571+
in
562572
let bpos = lexpos ps in
563-
span ps apos bpos (PEXP_spawn (domain, pexp))
573+
let name =
574+
match explicit_name with
575+
Some s -> s
576+
(* FIXME: string_of_span returns a string like
577+
"./driver.rs:10:16 - 11:52", not the actual text at those
578+
characters *)
579+
| None -> Session.string_of_span { lo = apos; hi = bpos }
580+
in
581+
span ps apos bpos (PEXP_spawn (domain, name, pexp))
564582

565583
| BIND ->
566584
let apos = lexpos ps in
@@ -1183,15 +1201,16 @@ and desugar_expr_init
11831201
let bind_stmt = ss (Ast.STMT_bind (dst_lval, fn_lval, arg_atoms)) in
11841202
ac [ fn_stmts; arg_stmts; [| bind_stmt |] ]
11851203

1186-
| PEXP_spawn (domain, sub) ->
1204+
| PEXP_spawn (domain, name, sub) ->
11871205
begin
11881206
match sub.node with
11891207
PEXP_call (fn, args) ->
11901208
let (fn_stmts, fn_atom) = desugar_expr_atom ps fn in
11911209
let (arg_stmts, arg_atoms) = desugar_expr_atoms ps args in
11921210
let fn_lval = atom_lval ps fn_atom in
11931211
let spawn_stmt =
1194-
ss (Ast.STMT_spawn (dst_lval, domain, fn_lval, arg_atoms))
1212+
ss (Ast.STMT_spawn
1213+
(dst_lval, domain, name, fn_lval, arg_atoms))
11951214
in
11961215
ac [ fn_stmts; arg_stmts; [| spawn_stmt |] ]
11971216
| _ -> raise (err "non-call spawn" ps)

trunk/src/boot/me/alias.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let alias_analysis_visitor
5959
* survive 'into' a sub-block (those formed during iteration)
6060
* need to be handled in this module. *)
6161
Ast.STMT_call (dst, callee, args)
62-
| Ast.STMT_spawn (dst, _, callee, args)
62+
| Ast.STMT_spawn (dst, _, _, callee, args)
6363
-> alias_call_args dst callee args
6464

6565
| Ast.STMT_send (_, src) -> alias src

trunk/src/boot/me/effect.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let mutability_checking_visitor
6262
match s.node with
6363
Ast.STMT_copy (lv_dst, _)
6464
| Ast.STMT_call (lv_dst, _, _)
65-
| Ast.STMT_spawn (lv_dst, _, _, _)
65+
| Ast.STMT_spawn (lv_dst, _, _, _, _)
6666
| Ast.STMT_recv (lv_dst, _)
6767
| Ast.STMT_bind (lv_dst, _, _)
6868
| Ast.STMT_new_rec (lv_dst, _, _)

trunk/src/boot/me/layout.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ let layout_visitor
400400
let callees =
401401
match s.node with
402402
Ast.STMT_call (_, lv, _)
403-
| Ast.STMT_spawn (_, _, lv, _) -> [| lv |]
403+
| Ast.STMT_spawn (_, _, _, lv, _) -> [| lv |]
404404
| Ast.STMT_check (_, calls) -> Array.map (fun (lv, _) -> lv) calls
405405
| _ -> [| |]
406406
in

trunk/src/boot/me/trans.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,10 +2128,12 @@ let trans_visitor
21282128
((*initializing*)_:bool)
21292129
(dst:Ast.lval)
21302130
(domain:Ast.domain)
2131+
(name:string)
21312132
(fn_lval:Ast.lval)
21322133
(args:Ast.atom array)
21332134
: unit =
21342135
let (task_cell, _) = trans_lval_init dst in
2136+
let runtime_name = trans_static_string name in
21352137
let (fptr_operand, fn_ty) = trans_callee fn_lval in
21362138
(*let fn_ty_params = [| |] in*)
21372139
let _ =
@@ -2165,7 +2167,7 @@ let trans_visitor
21652167
match domain with
21662168
Ast.DOMAIN_thread ->
21672169
begin
2168-
trans_upcall "upcall_new_thread" new_task [| |];
2170+
trans_upcall "upcall_new_thread" new_task [| runtime_name |];
21692171
copy_fn_args false true (CLONE_all new_task) call;
21702172
trans_upcall "upcall_start_thread" task_cell
21712173
[|
@@ -2177,7 +2179,7 @@ let trans_visitor
21772179
end
21782180
| _ ->
21792181
begin
2180-
trans_upcall "upcall_new_task" new_task [| |];
2182+
trans_upcall "upcall_new_task" new_task [| runtime_name |];
21812183
copy_fn_args false true (CLONE_chan new_task) call;
21822184
trans_upcall "upcall_start_task" task_cell
21832185
[|
@@ -4496,8 +4498,9 @@ let trans_visitor
44964498
| Ast.STMT_send (chan,src) ->
44974499
trans_send chan src
44984500

4499-
| Ast.STMT_spawn (dst, domain, plv, args) ->
4500-
trans_spawn (maybe_init stmt.id "spawn" dst) dst domain plv args
4501+
| Ast.STMT_spawn (dst, domain, name, plv, args) ->
4502+
trans_spawn (maybe_init stmt.id "spawn" dst) dst
4503+
domain name plv args
45014504

45024505
| Ast.STMT_recv (dst, chan) ->
45034506
trans_recv (maybe_init stmt.id "recv" dst) dst chan

trunk/src/boot/me/type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
692692
and check_stmt (stmt:Ast.stmt) : unit =
693693
check_ret stmt;
694694
match stmt.Common.node with
695-
Ast.STMT_spawn (dst, _, callee, args) ->
695+
Ast.STMT_spawn (dst, _, _, callee, args) ->
696696
infer_lval Ast.TY_task dst;
697697
demand Ast.TY_nil (check_fn callee args)
698698

trunk/src/boot/me/typestate.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ let condition_assigning_visitor
664664
let precond = Array.append dst_init src_init in
665665
raise_pre_post_cond s.id precond;
666666

667-
| Ast.STMT_spawn (dst, _, lv, args)
667+
| Ast.STMT_spawn (dst, _, _, lv, args)
668668
| Ast.STMT_call (dst, lv, args) ->
669669
raise_dst_init_precond_if_writing_through s.id dst;
670670
visit_callable_pre s.id (lval_slots cx dst) lv args
@@ -1350,7 +1350,7 @@ let lifecycle_visitor
13501350
match s.node with
13511351
Ast.STMT_copy (lv_dst, _)
13521352
| Ast.STMT_call (lv_dst, _, _)
1353-
| Ast.STMT_spawn (lv_dst, _, _, _)
1353+
| Ast.STMT_spawn (lv_dst, _, _, _, _)
13541354
| Ast.STMT_recv (lv_dst, _)
13551355
| Ast.STMT_bind (lv_dst, _, _)
13561356
| Ast.STMT_new_rec (lv_dst, _, _)

trunk/src/boot/me/walk.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ and walk_stmt
451451
walk_lval v f;
452452
Array.iter (walk_opt_atom v) az
453453

454-
| Ast.STMT_spawn (dst,_,p,az) ->
454+
| Ast.STMT_spawn (dst,_,_,p,az) ->
455455
walk_lval v dst;
456456
walk_lval v p;
457457
Array.iter (walk_atom v) az

trunk/src/rt/rust.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ rust_start(uintptr_t main_fn, rust_crate const *crate, int argc, char **argv)
182182
int ret;
183183
{
184184
rust_srv srv;
185-
rust_dom dom(&srv, crate);
185+
rust_dom dom(&srv, crate, "main");
186186
command_line_args args(dom, argc, argv);
187187

188188
dom.log(rust_log::DOM, "startup: %d args", args.argc);

0 commit comments

Comments
 (0)