Skip to content

Commit

Permalink
Add names to tasks and domains. These can either be an explicit liter…
Browse files Browse the repository at this point in the history
…al string

after the "spawn" keyword, or implicitly the call expression used to start the
spawn.
  • Loading branch information
jyasskin committed Aug 9, 2010
1 parent df75a96 commit b713405
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 95 deletions.
16 changes: 10 additions & 6 deletions doc/rust.texi
Expand Up @@ -2822,12 +2822,15 @@ x.y = z + 2;
@c * Ref.Stmt.Spawn:: Statements creating new tasks.
@cindex Spawn statement

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

Functions taking alias-slot arguments, or returning non-nil values, cannot be
spawned. Iterators cannot be spawned.
Expand All @@ -2843,6 +2846,7 @@ fn helper(chan[u8] out) @{
let port[u8] out;
let task p = spawn helper(chan(out));
let task p2 = spawn "my_helper" helper(chan(out));
// let task run, do other things.
auto result <- out;
Expand Down
5 changes: 3 additions & 2 deletions src/boot/fe/ast.ml
Expand Up @@ -199,7 +199,7 @@ and tup_input = (mutability * atom)
and stmt' =

(* lval-assigning stmts. *)
STMT_spawn of (lval * domain * lval * (atom array))
STMT_spawn of (lval * domain * string * lval * (atom array))
| STMT_new_rec of (lval * (rec_input array) * lval option)
| STMT_new_tup of (lval * (tup_input array))
| STMT_new_vec of (lval * mutability * atom array)
Expand Down Expand Up @@ -936,10 +936,11 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
fmt ff ";"
end

| STMT_spawn (dst, domain, fn, args) ->
| STMT_spawn (dst, domain, name, fn, args) ->
fmt_lval ff dst;
fmt ff " = spawn ";
fmt_domain ff domain;
fmt_str ff ("\"" ^ name ^ "\"");
fmt_lval ff fn;
fmt_atoms ff args;
fmt ff ";";
Expand Down
29 changes: 24 additions & 5 deletions src/boot/fe/pexp.ml
Expand Up @@ -18,7 +18,7 @@ open Parser;;

type pexp' =
PEXP_call of (pexp * pexp array)
| PEXP_spawn of (Ast.domain * pexp)
| PEXP_spawn of (Ast.domain * string * pexp)
| PEXP_bind of (pexp * pexp option array)
| PEXP_rec of ((Ast.ident * Ast.mutability * pexp) array * pexp option)
| PEXP_tup of ((Ast.mutability * pexp) array)
Expand Down Expand Up @@ -558,9 +558,27 @@ and parse_bottom_pexp (ps:pstate) : pexp =
THREAD -> bump ps; Ast.DOMAIN_thread
| _ -> Ast.DOMAIN_local
in
let pexp = ctxt "spawn [domain] pexp: init call" parse_pexp ps in
(* Spawns either have an explicit literal string for the spawned
task's name, or the task is named as the entry call
expression. *)
let explicit_name =
match peek ps with
LIT_STR s -> bump ps; Some s
| _ -> None
in
let pexp =
ctxt "spawn [domain] [name] pexp: init call" parse_pexp ps
in
let bpos = lexpos ps in
span ps apos bpos (PEXP_spawn (domain, pexp))
let name =
match explicit_name with
Some s -> s
(* FIXME: string_of_span returns a string like
"./driver.rs:10:16 - 11:52", not the actual text at those
characters *)
| None -> Session.string_of_span { lo = apos; hi = bpos }
in
span ps apos bpos (PEXP_spawn (domain, name, pexp))

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

| PEXP_spawn (domain, sub) ->
| PEXP_spawn (domain, name, sub) ->
begin
match sub.node with
PEXP_call (fn, args) ->
let (fn_stmts, fn_atom) = desugar_expr_atom ps fn in
let (arg_stmts, arg_atoms) = desugar_expr_atoms ps args in
let fn_lval = atom_lval ps fn_atom in
let spawn_stmt =
ss (Ast.STMT_spawn (dst_lval, domain, fn_lval, arg_atoms))
ss (Ast.STMT_spawn
(dst_lval, domain, name, fn_lval, arg_atoms))
in
ac [ fn_stmts; arg_stmts; [| spawn_stmt |] ]
| _ -> raise (err "non-call spawn" ps)
Expand Down
2 changes: 1 addition & 1 deletion src/boot/me/alias.ml
Expand Up @@ -59,7 +59,7 @@ let alias_analysis_visitor
* survive 'into' a sub-block (those formed during iteration)
* need to be handled in this module. *)
Ast.STMT_call (dst, callee, args)
| Ast.STMT_spawn (dst, _, callee, args)
| Ast.STMT_spawn (dst, _, _, callee, args)
-> alias_call_args dst callee args

| Ast.STMT_send (_, src) -> alias src
Expand Down
2 changes: 1 addition & 1 deletion src/boot/me/effect.ml
Expand Up @@ -62,7 +62,7 @@ let mutability_checking_visitor
match s.node with
Ast.STMT_copy (lv_dst, _)
| Ast.STMT_call (lv_dst, _, _)
| Ast.STMT_spawn (lv_dst, _, _, _)
| Ast.STMT_spawn (lv_dst, _, _, _, _)
| Ast.STMT_recv (lv_dst, _)
| Ast.STMT_bind (lv_dst, _, _)
| Ast.STMT_new_rec (lv_dst, _, _)
Expand Down
2 changes: 1 addition & 1 deletion src/boot/me/layout.ml
Expand Up @@ -400,7 +400,7 @@ let layout_visitor
let callees =
match s.node with
Ast.STMT_call (_, lv, _)
| Ast.STMT_spawn (_, _, lv, _) -> [| lv |]
| Ast.STMT_spawn (_, _, _, lv, _) -> [| lv |]
| Ast.STMT_check (_, calls) -> Array.map (fun (lv, _) -> lv) calls
| _ -> [| |]
in
Expand Down
11 changes: 7 additions & 4 deletions src/boot/me/trans.ml
Expand Up @@ -2128,10 +2128,12 @@ let trans_visitor
((*initializing*)_:bool)
(dst:Ast.lval)
(domain:Ast.domain)
(name:string)
(fn_lval:Ast.lval)
(args:Ast.atom array)
: unit =
let (task_cell, _) = trans_lval_init dst in
let runtime_name = trans_static_string name in
let (fptr_operand, fn_ty) = trans_callee fn_lval in
(*let fn_ty_params = [| |] in*)
let _ =
Expand Down Expand Up @@ -2165,7 +2167,7 @@ let trans_visitor
match domain with
Ast.DOMAIN_thread ->
begin
trans_upcall "upcall_new_thread" new_task [| |];
trans_upcall "upcall_new_thread" new_task [| runtime_name |];
copy_fn_args false true (CLONE_all new_task) call;
trans_upcall "upcall_start_thread" task_cell
[|
Expand All @@ -2177,7 +2179,7 @@ let trans_visitor
end
| _ ->
begin
trans_upcall "upcall_new_task" new_task [| |];
trans_upcall "upcall_new_task" new_task [| runtime_name |];
copy_fn_args false true (CLONE_chan new_task) call;
trans_upcall "upcall_start_task" task_cell
[|
Expand Down Expand Up @@ -4496,8 +4498,9 @@ let trans_visitor
| Ast.STMT_send (chan,src) ->
trans_send chan src

| Ast.STMT_spawn (dst, domain, plv, args) ->
trans_spawn (maybe_init stmt.id "spawn" dst) dst domain plv args
| Ast.STMT_spawn (dst, domain, name, plv, args) ->
trans_spawn (maybe_init stmt.id "spawn" dst) dst
domain name plv args

| Ast.STMT_recv (dst, chan) ->
trans_recv (maybe_init stmt.id "recv" dst) dst chan
Expand Down
2 changes: 1 addition & 1 deletion src/boot/me/type.ml
Expand Up @@ -692,7 +692,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
and check_stmt (stmt:Ast.stmt) : unit =
check_ret stmt;
match stmt.Common.node with
Ast.STMT_spawn (dst, _, callee, args) ->
Ast.STMT_spawn (dst, _, _, callee, args) ->
infer_lval Ast.TY_task dst;
demand Ast.TY_nil (check_fn callee args)

Expand Down
4 changes: 2 additions & 2 deletions src/boot/me/typestate.ml
Expand Up @@ -664,7 +664,7 @@ let condition_assigning_visitor
let precond = Array.append dst_init src_init in
raise_pre_post_cond s.id precond;

| Ast.STMT_spawn (dst, _, lv, args)
| Ast.STMT_spawn (dst, _, _, lv, args)
| Ast.STMT_call (dst, lv, args) ->
raise_dst_init_precond_if_writing_through s.id dst;
visit_callable_pre s.id (lval_slots cx dst) lv args
Expand Down Expand Up @@ -1350,7 +1350,7 @@ let lifecycle_visitor
match s.node with
Ast.STMT_copy (lv_dst, _)
| Ast.STMT_call (lv_dst, _, _)
| Ast.STMT_spawn (lv_dst, _, _, _)
| Ast.STMT_spawn (lv_dst, _, _, _, _)
| Ast.STMT_recv (lv_dst, _)
| Ast.STMT_bind (lv_dst, _, _)
| Ast.STMT_new_rec (lv_dst, _, _)
Expand Down
2 changes: 1 addition & 1 deletion src/boot/me/walk.ml
Expand Up @@ -451,7 +451,7 @@ and walk_stmt
walk_lval v f;
Array.iter (walk_opt_atom v) az

| Ast.STMT_spawn (dst,_,p,az) ->
| Ast.STMT_spawn (dst,_,_,p,az) ->
walk_lval v dst;
walk_lval v p;
Array.iter (walk_atom v) az
Expand Down
2 changes: 1 addition & 1 deletion src/rt/rust.cpp
Expand Up @@ -182,7 +182,7 @@ rust_start(uintptr_t main_fn, rust_crate const *crate, int argc, char **argv)
int ret;
{
rust_srv srv;
rust_dom dom(&srv, crate);
rust_dom dom(&srv, crate, "main");
command_line_args args(dom, argc, argv);

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

0 comments on commit b713405

Please sign in to comment.