Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #42 moving join and yield into stdlib #185

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/boot/fe/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ and stmt' =

(* structural and misc stmts. *)
| STMT_fail
| STMT_yield
| STMT_join of lval
| STMT_send of (lval * lval)
| STMT_log of atom
| STMT_note of atom
Expand Down Expand Up @@ -1471,7 +1469,6 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
fmt ff ";"

| STMT_fail -> fmt ff "fail;"
| STMT_yield -> fmt ff "yield;"

| STMT_send (chan, v) ->
fmt_lval ff chan;
Expand All @@ -1485,11 +1482,6 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
fmt_lval ff port;
fmt ff ";";

| STMT_join t ->
fmt ff "join ";
fmt_lval ff t;
fmt ff ";"

| STMT_new_box (lv, mutability, at) ->
fmt_lval ff lv;
fmt ff " = @@";
Expand Down
13 changes: 0 additions & 13 deletions src/boot/fe/item.ml
Original file line number Diff line number Diff line change
Expand Up @@ -585,25 +585,12 @@ and parse_stmts_including_none (ps:pstate) : Ast.stmt array =
in
Array.concat [[| span ps apos bpos (Ast.STMT_decl decl) |]; stmts]

| YIELD ->
bump ps;
expect ps SEMI;
let bpos = lexpos ps in
[| span ps apos bpos Ast.STMT_yield |]

| FAIL ->
bump ps;
expect ps SEMI;
let bpos = lexpos ps in
[| span ps apos bpos Ast.STMT_fail |]

| JOIN ->
bump ps;
let (stmts, lval) = ctxt "stmts: task expr" parse_lval ps in
expect ps SEMI;
spans ps stmts apos (Ast.STMT_join lval)


| STATE | GC
| IMPURE | UNSAFE
| ABS | NATIVE
Expand Down
2 changes: 0 additions & 2 deletions src/boot/fe/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
("cont", CONT);
("spawn", SPAWN);
("thread", THREAD);
("yield", YIELD);
("join", JOIN);

("bool", BOOL);

Expand Down
4 changes: 0 additions & 4 deletions src/boot/fe/token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ type token =
| SPAWN
| BIND
| THREAD
| YIELD
| JOIN

(* Literals *)
| LIT_INT of int64
Expand Down Expand Up @@ -272,8 +270,6 @@ let rec string_of_tok t =
| SPAWN -> "spawn"
| BIND -> "bind"
| THREAD -> "thread"
| YIELD -> "yield"
| JOIN -> "join"

(* Literals *)
| LIT_INT i -> Int64.to_string i
Expand Down
9 changes: 0 additions & 9 deletions src/boot/me/trans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2796,9 +2796,6 @@ let trans_visitor
imm (Int64.of_int line)
|];

and trans_join (task:Ast.lval) : unit =
trans_void_upcall "upcall_join" [| trans_atom (Ast.ATOM_lval task) |]

and trans_send (chan:Ast.lval) (src:Ast.lval) : unit =
let (src_cell, src_ty) = trans_lval src in
begin
Expand Down Expand Up @@ -5309,15 +5306,9 @@ let trans_visitor
| Ast.STMT_check_expr e ->
trans_check_expr stmt.id e

| Ast.STMT_yield ->
trans_yield ()

| Ast.STMT_fail ->
trans_fail ()

| Ast.STMT_join task ->
trans_join task

| Ast.STMT_send (chan,src) ->
trans_send chan src

Expand Down
8 changes: 2 additions & 6 deletions src/boot/me/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,7 @@ let check_block (cx:Semant.ctxt) : (fn_ctx -> Ast.block -> unit) =
let check_ret (stmt:Ast.stmt) : unit =
fn_ctx.fnctx_just_saw_ret <-
match stmt.Common.node with
Ast.STMT_ret _ | Ast.STMT_be _ | Ast.STMT_fail
| Ast.STMT_yield -> true
Ast.STMT_ret _ | Ast.STMT_be _ | Ast.STMT_fail -> true
| _ -> false
in

Expand Down Expand Up @@ -1118,10 +1117,7 @@ let check_block (cx:Semant.ctxt) : (fn_ctx -> Ast.block -> unit) =
| Ast.STMT_alt_port _ -> () (* TODO *)

(* always well-typed *)
| Ast.STMT_fail | Ast.STMT_yield
| Ast.STMT_break | Ast.STMT_cont -> ()

| Ast.STMT_join lval -> infer_lval Ast.TY_task lval
| Ast.STMT_fail | Ast.STMT_break | Ast.STMT_cont -> ()

| Ast.STMT_send (chan, value) ->
let value_ty = demand_chan (check_lval chan) in
Expand Down
4 changes: 0 additions & 4 deletions src/boot/me/typestate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,6 @@ let condition_assigning_visitor
let precond = slot_inits (atom_slots cx at) in
raise_pre_post_cond s.id precond

| Ast.STMT_join lval ->
let precond = slot_inits (lval_slots cx lval) in
raise_pre_post_cond s.id precond

| Ast.STMT_log atom ->
let precond = slot_inits (atom_slots cx atom) in
raise_pre_post_cond s.id precond
Expand Down
5 changes: 1 addition & 4 deletions src/boot/me/walk.ml
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,9 @@ and walk_stmt
| Ast.STMT_decl (Ast.DECL_slot (_, slot)) ->
walk_slot_identified v slot

| Ast.STMT_break | Ast.STMT_cont | Ast.STMT_yield | Ast.STMT_fail ->
| Ast.STMT_break | Ast.STMT_cont | Ast.STMT_fail ->
()

| Ast.STMT_join task ->
walk_lval v task

| Ast.STMT_send (dst,src) ->
walk_lval v dst;
walk_lval v src
Expand Down
2 changes: 0 additions & 2 deletions src/comp/front/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ fn new_reader(stdio_reader rdr, str filename) -> reader
keywords.insert("log", token.LOG);
keywords.insert("spawn", token.SPAWN);
keywords.insert("thread", token.THREAD);
keywords.insert("yield", token.YIELD);
keywords.insert("join", token.JOIN);

keywords.insert("bool", token.BOOL);

Expand Down
4 changes: 0 additions & 4 deletions src/comp/front/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ tag token {
SPAWN;
BIND;
THREAD;
YIELD;
JOIN;

/* Literals */
LIT_INT(int);
Expand Down Expand Up @@ -284,8 +282,6 @@ fn to_str(token t) -> str {
case (SPAWN) { ret "spawn"; }
case (BIND) { ret "bind"; }
case (THREAD) { ret "thread"; }
case (YIELD) { ret "yield"; }
case (JOIN) { ret "join"; }

/* Literals */
case (LIT_INT(?i)) { ret _int.to_str(i, 10u); }
Expand Down
10 changes: 10 additions & 0 deletions src/lib/_task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
native "rust" mod rustrt {
fn task_sleep(uint time_in_us);
fn task_yield();
fn task_join(task t);
}

/**
Expand All @@ -11,6 +13,14 @@ fn sleep(uint time_in_us) {
ret rustrt.task_sleep(time_in_us);
}

fn join(task t) {
ret rustrt.task_join(t);
}

fn yield() {
ret rustrt.task_yield();
}

// Local Variables:
// mode: rust;
// fill-column: 78;
Expand Down
15 changes: 15 additions & 0 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ task_sleep(rust_task *task, size_t time_in_us) {
upcall_sleep(task, time_in_us);
}

extern "C" CDECL void upcall_yield(rust_task *task);

extern "C" CDECL void
task_yield(rust_task *task) {
upcall_yield(task);
}

extern "C" CDECL void
upcall_join(rust_task *task, maybe_proxy<rust_task> *target);

extern "C" CDECL void
task_join(rust_task *task, maybe_proxy<rust_task> *target) {
upcall_join(task, target);
}

/* Debug builtins for std.dbg. */

static void
Expand Down
5 changes: 4 additions & 1 deletion src/test/run-pass/clone-with-exterior.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.join;

fn f(@rec(int a, int b) x) {
check (x.a == 10);
check (x.b == 12);
Expand All @@ -6,5 +9,5 @@ fn f(@rec(int a, int b) x) {
fn main() {
let @rec(int a, int b) z = rec(a=10, b=12);
let task p = spawn thread f(z);
join p;
join(p);
}
5 changes: 4 additions & 1 deletion src/test/run-pass/obj-dtor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.yield;

obj worker(chan[int] c) {
drop {
log "in dtor";
Expand All @@ -16,7 +19,7 @@ impure fn do_work(chan[int] c) {
// Deadlock-condition not handled properly yet, need to avoid
// exiting the child early.
c <| 11;
yield;
yield();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/spawn-fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// -*- rust -*-
use std;
import std._task.yield;

fn x(str s, int n) {
log s;
Expand All @@ -13,6 +15,6 @@ fn main() {
while (i > 0) {
i = i - 1;
log "parent sleeping";
yield;
yield();
}
}
5 changes: 4 additions & 1 deletion src/test/run-pass/spawn-module-qualified.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std;
import std._task.join;

fn main() {
auto x = spawn m.child(10);
join x;
join(x);
}
mod m {
fn child(int i) {
Expand Down
5 changes: 4 additions & 1 deletion src/test/run-pass/task-comm-1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task;

fn main() -> () {
test00();
}
Expand All @@ -8,6 +11,6 @@ fn start() {

fn test00() {
let task t = spawn thread start();
join t;
_task.join(t);
log "Completing.";
}
5 changes: 4 additions & 1 deletion src/test/run-pass/task-comm-10.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.yield;

io fn start(chan[chan[str]] c) {
let port[str] p = port();
c <| chan(p);
Expand All @@ -11,5 +14,5 @@ io fn main() {
auto c <- p;
c <| "A";
c <| "B";
yield;
yield();
}
2 changes: 1 addition & 1 deletion src/test/run-pass/task-comm-12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn test00() {
_task.sleep(10000u);

// Try joining tasks that have already finished.
join t;
_task.join(t);

log "Joined Task.";
}
2 changes: 1 addition & 1 deletion src/test/run-pass/task-comm-13-thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn main() -> () {
log "Check that we don't deadlock.";
let port[int] p = port();
let task a = spawn thread "start" start(chan(p), 0, 10);
join a;
_task.join(a);
log "Joined Task";
}
2 changes: 1 addition & 1 deletion src/test/run-pass/task-comm-13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn main() -> () {
log "Check that we don't deadlock.";
let port[int] p = port();
let task a = spawn "start" start(chan(p), 0, 10);
join a;
_task.join(a);
log "Joined Task";
}
5 changes: 4 additions & 1 deletion src/test/run-pass/task-comm-2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.join;

fn main() -> () {
log "===== SPAWNING and JOINING TASKS =====";
test00(false);
Expand Down Expand Up @@ -29,7 +32,7 @@ fn test00(bool create_threads) {
}

for (task t in tasks) {
join t;
join(t);
}

log "Joined all task.";
Expand Down
5 changes: 4 additions & 1 deletion src/test/run-pass/task-comm-3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.join;

io fn main() -> () {
log "===== WITHOUT THREADS =====";
test00(false);
Expand Down Expand Up @@ -52,7 +55,7 @@ io fn test00(bool is_multithreaded) {

// Join spawned tasks...
for (task t in tasks) {
join t;
join(t);
}

log "Completed: Final number is: ";
Expand Down
11 changes: 7 additions & 4 deletions src/test/run-pass/task-comm-7.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std;
import std._task.join;

impure fn main() -> () {
test00();
}
Expand Down Expand Up @@ -34,10 +37,10 @@ impure fn test00() {
i += 1;
}

join t0;
join t1;
join t2;
join t3;
join(t0);
join(t1);
join(t2);
join(t3);

check (sum == (((number_of_messages * 4) *
((number_of_messages * 4) - 1)) / 2));
Expand Down
Loading