Skip to content

Commit da13c50

Browse files
committed
First pass on splitting stratum and opacity off of effects. WIP.
1 parent ccd6296 commit da13c50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+288
-215
lines changed

doc/rust.texi

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,12 @@ The keywords are:
667667
@tab @code{export}
668668
@tab @code{let}
669669
@tab @code{auto}
670-
@item @code{io}
671-
@tab @code{state}
670+
@item @code{state}
671+
@tab @code{gc}
672+
@tab @code{abs}
673+
@item @code{auth}
674+
@tab @code{impure}
672675
@tab @code{unsafe}
673-
@tab @code{auth}
674-
@tab @code{with}
675676
@item @code{bind}
676677
@tab @code{type}
677678
@tab @code{true}
@@ -705,8 +706,8 @@ The keywords are:
705706
@item @code{task}
706707
@tab @code{port}
707708
@tab @code{chan}
708-
@tab @code{flush}
709709
@tab @code{spawn}
710+
@tab @code{with}
710711
@item @code{if}
711712
@tab @code{else}
712713
@tab @code{alt}
@@ -1473,7 +1474,6 @@ operating-system processes.
14731474
@cindex Message passing
14741475
@cindex Send statement
14751476
@cindex Receive statement
1476-
@cindex Flush statement
14771477

14781478
With the exception of @emph{unsafe} constructs, Rust tasks are isolated from
14791479
interfering with one another's memory directly. Instead of manipulating shared
@@ -1515,11 +1515,7 @@ task. If too many messages are queued for transmission from a single sending
15151515
task, without being received by a receiving task, the sending task may exceed
15161516
its memory budget, which causes a run-time signal. To help control this
15171517
possibility, a semi-synchronous send operation is possible, which blocks until
1518-
there is room in the existing queue and then executes an asynchronous send. A
1519-
full @code{flush} operation is also available, which blocks until a channel's
1520-
queue is @emph{empty}. A @code{flush} does @emph{not} guarantee that a message
1521-
has been @emph{received} by any particular recipient when the sending task is
1522-
unblocked. @xref{Ref.Stmt.Flush}.
1518+
there is room in the existing queue and then executes an asynchronous send.
15231519

15241520
The asynchronous message-send operator is @code{<+}. The semi-synchronous
15251521
message-send operator is @code{<|}. @xref{Ref.Stmt.Send}. The message-receive
@@ -2550,7 +2546,6 @@ actions.
25502546
* Ref.Stmt.Copy:: Statement for copying a value.
25512547
* Ref.Stmt.Spawn:: Statements for creating new tasks.
25522548
* Ref.Stmt.Send:: Statements for sending a value into a channel.
2553-
* Ref.Stmt.Flush:: Statement for flushing a channel queue.
25542549
* Ref.Stmt.Recv:: Statement for receiving a value from a channel.
25552550
* Ref.Stmt.Call:: Statement for calling a function.
25562551
* Ref.Stmt.Bind:: Statement for binding arguments to functions.
@@ -2933,24 +2928,6 @@ chan[str] c = @dots{};
29332928
c <| "hello, world";
29342929
@end example
29352930

2936-
@node Ref.Stmt.Flush
2937-
@subsection Ref.Stmt.Flush
2938-
@c * Ref.Stmt.Flush:: Statement for flushing a channel queue.
2939-
@cindex Flush statement
2940-
@cindex Communication
2941-
2942-
A @code{flush} statement takes a channel and blocks the flushing task until
2943-
the channel's queue has emptied. It can be used to implement a more precise
2944-
form of flow-control than with the send operators alone.
2945-
2946-
An example of the @code{flush} statement:
2947-
@example
2948-
chan[str] c = @dots{};
2949-
c <| "hello, world";
2950-
flush c;
2951-
@end example
2952-
2953-
29542931
@node Ref.Stmt.Recv
29552932
@subsection Ref.Stmt.Recv
29562933
@c * Ref.Stmt.Recv:: Statement for receiving a value from a channel.
@@ -3359,8 +3336,8 @@ statement following the @code{alt} when the case block completes.
33593336
@cindex Multiplexing
33603337

33613338
The simplest form of @code{alt} statement is the a @emph{communication}
3362-
@code{alt}. The cases of a communication @code{alt}'s arms are send, receive
3363-
and flush statements. @xref{Ref.Task.Comm}.
3339+
@code{alt}. The cases of a communication @code{alt}'s arms are send and
3340+
receive statements. @xref{Ref.Task.Comm}.
33643341

33653342
To execute a communication @code{alt}, the runtime checks all of the ports and
33663343
channels involved in the arms of the statement to see if any @code{case} can
@@ -3679,3 +3656,11 @@ to the task's domain; if the queue grows too big, the task will fail.
36793656
@printindex cp
36803657

36813658
@bye
3659+
3660+
@c Local Variables:
3661+
@c mode: texinfo
3662+
@c fill-column: 78;
3663+
@c indent-tabs-mode: nil
3664+
@c buffer-file-coding-system: utf-8-unix
3665+
@c compile-command: "make -k 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
3666+
@c End:

src/boot/fe/ast.ml

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@ type slot_key =
2929
*)
3030

3131
type effect =
32-
PURE
33-
| IO
34-
| STATE
35-
| UNSAFE
32+
EFF_pure
33+
| EFF_impure
34+
| EFF_unsafe
35+
;;
36+
37+
type stratum =
38+
STRAT_value
39+
| STRAT_state
40+
| STRAT_gc
41+
;;
42+
43+
type opacity =
44+
OPA_transparent
45+
| OPA_abstract
3646
;;
3747

3848
type mutability =
@@ -702,19 +712,56 @@ and fmt_effect
702712
(effect:effect)
703713
: unit =
704714
match effect with
705-
PURE -> ()
706-
| IO -> fmt ff "io"
707-
| STATE -> fmt ff "state"
708-
| UNSAFE -> fmt ff "unsafe"
715+
EFF_pure -> ()
716+
| EFF_impure -> fmt ff "impure"
717+
| EFF_unsafe -> fmt ff "unsafe"
718+
719+
and fmt_effect_qual
720+
(ff:Format.formatter)
721+
(e:effect)
722+
: unit =
723+
fmt_effect ff e;
724+
if e <> EFF_pure then fmt ff " ";
725+
726+
and fmt_stratum
727+
(ff:Format.formatter)
728+
(strat:stratum)
729+
: unit =
730+
match strat with
731+
STRAT_value -> ()
732+
| STRAT_state -> fmt ff "state"
733+
| STRAT_gc -> fmt ff "gc"
734+
735+
and fmt_stratum_qual
736+
(ff:Format.formatter)
737+
(s:stratum)
738+
: unit =
739+
fmt_stratum ff s;
740+
if s <> STRAT_value then fmt ff " ";
741+
742+
and fmt_opacity
743+
(ff:Format.formatter)
744+
(opa:opacity)
745+
: unit =
746+
match opa with
747+
OPA_transparent -> ()
748+
| OPA_abstract -> fmt ff "abs"
749+
750+
and fmt_opacity_qual
751+
(ff:Format.formatter)
752+
(op:opacity)
753+
: unit =
754+
fmt_opacity ff op;
755+
if op <> OPA_transparent then fmt ff " ";
756+
709757

710758
and fmt_ty_fn
711759
(ff:Format.formatter)
712760
(ident_and_params:(ident * ty_param array) option)
713761
(tf:ty_fn)
714762
: unit =
715763
let (tsig, ta) = tf in
716-
fmt_effect ff ta.fn_effect;
717-
if ta.fn_effect <> PURE then fmt ff " ";
764+
fmt_effect_qual ff ta.fn_effect;
718765
fmt ff "%s" (if ta.fn_is_iter then "iter" else "fn");
719766
begin
720767
match ident_and_params with
@@ -763,8 +810,7 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit =
763810
fmt_ident_tys ff entries;
764811
fmt ff "@]"
765812

766-
| TY_param (i, e) -> (fmt_effect ff e;
767-
if e <> PURE then fmt ff " ";
813+
| TY_param (i, e) -> (fmt_effect_qual ff e;
768814
fmt ff "<p#%d>" i)
769815
| TY_native oid -> fmt ff "<native#%d>" (int_of_opaque oid)
770816
| TY_named n -> fmt_name ff n
@@ -789,8 +835,7 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit =
789835

790836
| TY_obj (effect, fns) ->
791837
fmt_obox ff;
792-
fmt_effect ff effect;
793-
if effect <> PURE then fmt ff " ";
838+
fmt_effect_qual ff effect;
794839
fmt ff "obj ";
795840
fmt_obr ff;
796841
Hashtbl.iter
@@ -1584,8 +1629,7 @@ and fmt_slice (ff:Format.formatter) (slice:slice) : unit =
15841629

15851630
and fmt_decl_param (ff:Format.formatter) (param:ty_param) : unit =
15861631
let (ident, (i, e)) = param in
1587-
fmt_effect ff e;
1588-
if e <> PURE then fmt ff " ";
1632+
fmt_effect_qual ff e;
15891633
fmt_ident ff ident;
15901634
fmt ff "=<p#%d>" i
15911635

@@ -1608,10 +1652,6 @@ and fmt_ident_and_params
16081652
fmt_ident ff id;
16091653
fmt_decl_params ff params
16101654

1611-
and fmt_effect_qual (ff:Format.formatter) (e:effect) : unit =
1612-
fmt_effect ff e;
1613-
if e <> PURE then fmt ff " ";
1614-
16151655
and fmt_fn
16161656
(ff:Format.formatter)
16171657
(id:ident)

src/boot/fe/cexp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ and parse_cexp (ps:pstate) : cexp =
181181
fun (ident, item) ->
182182
htab_put items ident item
183183
end
184-
(Item.parse_mod_item_from_signature ps)
184+
(Item.parse_native_mod_item_from_signature ps)
185185
in
186186
ignore (bracketed_zero_or_more
187187
LBRACE RBRACE None get_item ps);

src/boot/fe/fuzz.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let rec generate_mod_item (mis:mod_items) (cx:ctxt) : unit =
104104
match Random.int 2 with
105105
0 ->
106106
let ty = generate_ty cx in
107-
let eff = PURE in
107+
let eff = Ast.EFF_pure in
108108
decl (MOD_ITEM_type (eff, ty))
109109
| _ ->
110110
let mis' = Hashtbl.create 0 in

src/boot/fe/item.ml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ and parse_stmts (ps:pstate) : Ast.stmt array =
154154
if (Array.length arr) == 0 then
155155
raise (err "statement does nothing" ps);
156156
arr
157-
158-
159157

160158
(*
161159
* We have no way to parse a single Ast.stmt; any incoming syntactic statement
@@ -605,7 +603,11 @@ and parse_stmts_including_none (ps:pstate) : Ast.stmt array =
605603
expect ps SEMI;
606604
spans ps stmts apos (Ast.STMT_join lval)
607605

608-
| IO | STATE | UNSAFE | MOD | OBJ | TAG | TYPE | FN | USE | NATIVE ->
606+
607+
| STATE | GC
608+
| IMPURE | UNSAFE
609+
| ABS | NATIVE
610+
| MOD | OBJ | TAG | TYPE | FN | USE ->
609611
let items = ctxt "stmt: decl" parse_mod_item ps in
610612
let bpos = lexpos ps in
611613
Array.map
@@ -689,6 +691,8 @@ and parse_stmts_including_none (ps:pstate) : Ast.stmt array =
689691

690692
and parse_ty_param (iref:int ref) (ps:pstate) : Ast.ty_param identified =
691693
let apos = lexpos ps in
694+
let _ = Pexp.parse_opacity ps in
695+
let _ = Pexp.parse_stratum ps in
692696
let e = Pexp.parse_effect ps in
693697
let ident = Pexp.parse_ident ps in
694698
let i = !iref in
@@ -851,7 +855,7 @@ and parse_obj_item
851855
do
852856
let apos = lexpos ps in
853857
match peek ps with
854-
IO | STATE | UNSAFE | FN | ITER ->
858+
IMPURE | UNSAFE | FN | ITER ->
855859
let effect = Pexp.parse_effect ps in
856860
let is_iter = (peek ps) = ITER in
857861
bump ps;
@@ -986,7 +990,10 @@ and parse_mod_item (ps:pstate)
986990

987991
match peek ps with
988992

989-
IO | STATE | UNSAFE | TYPE | OBJ | TAG | FN | ITER ->
993+
STATE | GC | IMPURE | UNSAFE | ABS
994+
| TYPE | OBJ | TAG | FN | ITER ->
995+
let _ = Pexp.parse_opacity ps in
996+
let _ = Pexp.parse_stratum ps in
990997
let effect = Pexp.parse_effect ps in
991998
begin
992999
match peek ps with
@@ -1044,7 +1051,7 @@ and parse_mod_item (ps:pstate)
10441051
expect ps MOD;
10451052
let ident = Pexp.parse_ident ps in
10461053
let path = parse_lib_name ident in
1047-
let items = parse_mod_items_from_signature ps in
1054+
let items = parse_native_mod_items_from_signature ps in
10481055
let bpos = lexpos ps in
10491056
let rlib = REQUIRED_LIB_c { required_libname = path;
10501057
required_prefix = ps.pstate_depth }
@@ -1056,7 +1063,7 @@ and parse_mod_item (ps:pstate)
10561063
end
10571064
| _ -> raise (unexpected ps)
10581065

1059-
and parse_mod_items_header_from_signature (ps:pstate) : Ast.mod_view =
1066+
and parse_native_mod_header_from_signature (ps:pstate) : Ast.mod_view =
10601067
let exports = Hashtbl.create 0 in
10611068
while (peek ps = EXPORT)
10621069
do
@@ -1068,36 +1075,36 @@ and parse_mod_items_header_from_signature (ps:pstate) : Ast.mod_view =
10681075
then htab_put exports Ast.EXPORT_all_decls ();
10691076
{empty_view with Ast.view_exports = exports}
10701077

1071-
and parse_mod_items_from_signature
1078+
and parse_native_mod_items_from_signature
10721079
(ps:pstate)
10731080
: (Ast.mod_view * Ast.mod_items) =
10741081
expect ps LBRACE;
1075-
let view = parse_mod_items_header_from_signature ps in
1082+
let view = parse_native_mod_header_from_signature ps in
10761083
let items = Hashtbl.create 0 in
10771084
while not (peek ps = RBRACE)
10781085
do
10791086
Array.iter
10801087
(fun (ident, item) ->
10811088
htab_put items ident item)
10821089
(ctxt "mod items from sig: mod item"
1083-
parse_mod_item_from_signature ps)
1090+
parse_native_mod_item_from_signature ps)
10841091
done;
10851092
expect ps RBRACE;
10861093
(view,items)
10871094

1088-
and parse_mod_item_from_signature (ps:pstate)
1095+
and parse_native_mod_item_from_signature (ps:pstate)
10891096
: (Ast.ident * Ast.mod_item) array =
10901097
let apos = lexpos ps in
10911098
match peek ps with
10921099
MOD ->
10931100
bump ps;
10941101
let (ident, params) = parse_ident_and_params ps "mod signature" in
1095-
let items = parse_mod_items_from_signature ps in
1102+
let items = parse_native_mod_items_from_signature ps in
10961103
let bpos = lexpos ps in
10971104
[| (ident,
10981105
span ps apos bpos (decl params (Ast.MOD_ITEM_mod items))) |]
10991106

1100-
| IO | STATE | UNSAFE | FN | ITER ->
1107+
| IMPURE | UNSAFE | FN | ITER ->
11011108
let effect = Pexp.parse_effect ps in
11021109
let is_iter = (peek ps) = ITER in
11031110
bump ps;
@@ -1142,7 +1149,7 @@ and parse_mod_item_from_signature (ps:pstate)
11421149
expect ps SEMI;
11431150
let bpos = lexpos ps in
11441151
[| (ident, span ps apos bpos
1145-
(decl params (Ast.MOD_ITEM_type (Ast.UNSAFE, t)))) |]
1152+
(decl params (Ast.MOD_ITEM_type (Ast.EFF_unsafe, t)))) |]
11461153

11471154
| _ -> raise (unexpected ps)
11481155

src/boot/fe/lexer.mll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@
9595
("claim", CLAIM);
9696
("prove", PROVE);
9797

98-
("io", IO);
98+
("abs", ABS);
99+
99100
("state", STATE);
101+
("gc", GC);
102+
103+
("impure", IMPURE);
100104
("unsafe", UNSAFE);
101105

102106
("native", NATIVE);

0 commit comments

Comments
 (0)