Skip to content

Commit dbe8760

Browse files
committed
Merge commit 'jyasskin/work'
Conflicts: src/rt/rust_dom.cpp src/rt/rust_upcall.cpp
2 parents 75e46cc + b713405 commit dbe8760

File tree

17 files changed

+155
-103
lines changed

17 files changed

+155
-103
lines changed

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

src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
472472
i32-sub.rs \
473473
i8-incr.rs \
474474
import.rs \
475-
inner-module.rs \
476475
integral-indexing.rs \
477476
int-lib.rs \
478477
iter-range.rs \

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 ";";

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)

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

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, _, _)

src/boot/me/layout.ml

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

src/boot/me/trans.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,10 +2141,12 @@ let trans_visitor
21412141
((*initializing*)_:bool)
21422142
(dst:Ast.lval)
21432143
(domain:Ast.domain)
2144+
(name:string)
21442145
(fn_lval:Ast.lval)
21452146
(args:Ast.atom array)
21462147
: unit =
21472148
let (task_cell, _) = trans_lval_init dst in
2149+
let runtime_name = trans_static_string name in
21482150
let (fptr_operand, fn_ty) = trans_callee fn_lval in
21492151
(*let fn_ty_params = [| |] in*)
21502152
let _ =
@@ -2178,7 +2180,7 @@ let trans_visitor
21782180
match domain with
21792181
Ast.DOMAIN_thread ->
21802182
begin
2181-
trans_upcall "upcall_new_thread" new_task [| |];
2183+
trans_upcall "upcall_new_thread" new_task [| runtime_name |];
21822184
copy_fn_args false true (CLONE_all new_task) call;
21832185
trans_upcall "upcall_start_thread" task_cell
21842186
[|
@@ -2190,7 +2192,7 @@ let trans_visitor
21902192
end
21912193
| _ ->
21922194
begin
2193-
trans_upcall "upcall_new_task" new_task [| |];
2195+
trans_upcall "upcall_new_task" new_task [| runtime_name |];
21942196
copy_fn_args false true (CLONE_chan new_task) call;
21952197
trans_upcall "upcall_start_task" task_cell
21962198
[|
@@ -4529,8 +4531,9 @@ let trans_visitor
45294531
| Ast.STMT_send (chan,src) ->
45304532
trans_send chan src
45314533

4532-
| Ast.STMT_spawn (dst, domain, plv, args) ->
4533-
trans_spawn (maybe_init stmt.id "spawn" dst) dst domain plv args
4534+
| Ast.STMT_spawn (dst, domain, name, plv, args) ->
4535+
trans_spawn (maybe_init stmt.id "spawn" dst) dst
4536+
domain name plv args
45344537

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

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

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, _, _)

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

src/rt/rust.cpp

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

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

0 commit comments

Comments
 (0)