Skip to content
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
4 changes: 2 additions & 2 deletions design/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Productions marked * probably deferred to later versions.
```
<typ> ::= type expressions
<id> <typ-args>? constructor
(shared|actor)? { <typ-field>;* } object
actor? { <typ-field>;* } object
[ var? <typ> ] array
? <typ> option
(shared|class)? <typ-params>? <typ> -> <typ> function
Expand Down Expand Up @@ -109,7 +109,7 @@ Productions marked * probably deferred to later versions.
<exp> expression
let <pat> = <exp> immutable
var <id> (: <typ>)? = <exp> mutable
(new|object|actor|shared) <id>? =? { <exp-field>;* } object
(new|object|actor) <id>? =? { <exp-field>;* } object
shared? func <id>? <typ-params>? <pat> (: <typ>)? =? <exp> function
type <id> <typ-params>? = <typ> type
actor? class <id> <typ-params>? <pat> (: <typ>)? =? <exp> class
Expand Down
2 changes: 1 addition & 1 deletion src/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ and control c = match c with
| Type.Promises -> "Promises"

and obj_sort' s = match s with
| Type.Object sh -> Atom ("Object " ^ sharing sh)
| Type.Object -> Atom "Object"
| Type.Actor -> Atom "Actor"

and obj_sort s = obj_sort' s.it
Expand Down
2 changes: 1 addition & 1 deletion src/arrange_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and control c = match c with
| Type.Promises -> "Promises"

and obj_sort s = match s with
| Type.Object sh -> Atom ("Object " ^ sharing sh)
| Type.Object -> Atom "Object"
| Type.Actor -> Atom "Actor"

and func_sort s = match s with
Expand Down
11 changes: 5 additions & 6 deletions src/check_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ and check_typ_field env s typ_field : unit =
(s <> T.Actor || T.is_func (T.promote env.cons typ))
"actor field has non-function type";
check env no_region
(s = T.Object T.Local || T.sub env.cons typ T.Shared)
"shared object or actor field has non-shared type"
(s <> T.Actor || T.sub env.cons typ T.Shared)
"actor field has non-shared type"


and check_typ_binds env typ_binds : T.con list * con_env =
Expand Down Expand Up @@ -656,10 +656,9 @@ and type_exp_field env s (tfs, ve) field : T.field list * val_env =
is_func_exp exp)
"public actor field is not a function";
check env field.at
(if (s <> T.Object T.Local && priv.it = Syntax.Public)
then T.sub env.cons t T.Shared
else true)
"public shared object or actor field has non-shared type";
((s = T.Actor && priv.it = Syntax.Public) ==>
T.sub env.cons t T.Shared)
"public actor field has non-shared type";
let ve' = T.Env.add id.it t ve in
let tfs' =
if priv.it = Syntax.Private
Expand Down
2 changes: 1 addition & 1 deletion src/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3428,7 +3428,7 @@ and compile_exp (env : E.t) exp =
StackRep.unit,
compile_exp_vanilla env e ^^
Var.set_val env name.it
| NewObjE ({ it = Type.Object _ (*sharing*); _}, fs, _) ->
| NewObjE ({ it = Type.Object; _}, fs, _) ->
StackRep.Vanilla,
let fs' = List.map
(fun (name, id) -> (name, fun env -> Var.get_val_ptr env id.it))
Expand Down
2 changes: 1 addition & 1 deletion src/definedness.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let rec exp msgs e : f = match e.it with
let f = close (exp_fields msgs efs) // i.it in
begin match s.it with
| Type.Actor -> eagerify f
| Type.Object _ -> f
| Type.Object -> f
end
| DotE (e, _t, i) -> exp msgs e
| AssignE (e1, e2) -> exps msgs [e1; e2]
Expand Down
2 changes: 1 addition & 1 deletion src/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ and field_to_obj_entry (f : S.exp_field) =

and obj at s class_id self_id es obj_typ =
match s.it with
| Type.Object _ -> build_obj at None s self_id es obj_typ
| Type.Object -> build_obj at None s self_id es obj_typ
| Type.Actor -> I.ActorE (self_id, exp_fields es, obj_typ)

and build_obj at class_id s self_id es obj_typ =
Expand Down
23 changes: 9 additions & 14 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let (@?) it at = {it; at; note = empty_typ_note}
let (@!) it at = {it; at; note = Type.Pre}
let (@=) it at = {it; at; note = None}

let dummy_obj_sort() = ref (Type.Object Type.Local)
let dummy_obj_sort() = ref Type.Object

let dup_var x = VarE (x.it @@ x.at) @? x.at

Expand Down Expand Up @@ -58,8 +58,6 @@ let assign_op lhs rhs_f at =

let share_typ t =
match t.it with
| ObjT ({it = Type.Object Type.Local; _} as s, tfs) ->
{ t with it = ObjT ({s with it = Type.Object Type.Sharable}, tfs)}
| FuncT ({it = Type.Call Type.Local; _} as s, tbs, t1, t2) ->
{ t with it = FuncT ({s with it = Type.Call Type.Sharable}, tbs, t1, t2)}
| _ -> t
Expand All @@ -75,8 +73,6 @@ let share_dec d =

let share_exp e =
match e.it with
| ObjE ({it = Type.Object Type.Local; _} as s, x, efs) ->
ObjE ({s with it = Type.Object Type.Sharable}, x, efs) @? e.at
| DecE (d, ot) ->
DecE (share_dec d, ot) @? e.at
| _ -> e
Expand Down Expand Up @@ -173,13 +169,12 @@ seplist1(X, SEP) :
| VAR { Var @@ at $sloc }

%inline obj_sort :
| NEW { Type.Object Type.Local @@ at $sloc }
| OBJECT { Type.Object Type.Local @@ at $sloc }
| SHARED { Type.Object Type.Sharable @@ at $sloc }
| NEW { Type.Object @@ at $sloc }
| OBJECT { Type.Object @@ at $sloc }
| ACTOR { Type.Actor @@ at $sloc }

%inline obj_sort_opt :
| (* empty *) { Type.Object Type.Local @@ no_region }
| (* empty *) { Type.Object @@ no_region }
| s=obj_sort { s }

%inline shared_opt :
Expand Down Expand Up @@ -208,7 +203,7 @@ typ_nullary :
| LBRACKET m=var_opt t=typ RBRACKET
{ ArrayT(m, t) @! at $sloc }
| tfs=typ_obj
{ ObjT(Type.Object Type.Local @@ at $sloc, tfs) @! at $sloc }
{ ObjT(Type.Object @@ at $sloc, tfs) @! at $sloc }

typ_un :
| t=typ_nullary
Expand All @@ -225,7 +220,7 @@ typ_pre :
{ AsyncT(t) @! at $sloc }
| s=obj_sort tfs=typ_obj
{ let tfs' =
if s.it = Type.Object Type.Local
if s.it = Type.Object
then tfs
else List.map share_typfield tfs
in ObjT(s, tfs') @! at $sloc }
Expand Down Expand Up @@ -443,7 +438,7 @@ exp_nonvar :
| s=obj_sort xf=id_opt EQ? efs=obj_body
{ let anon = if s.it = Type.Actor then "actor" else "object" in
let efs' =
if s.it = Type.Object Type.Local
if s.it = Type.Object
then efs
else List.map share_expfield efs
in ObjE(s, xf anon $sloc, efs') @? at $sloc }
Expand Down Expand Up @@ -539,7 +534,7 @@ dec_nonvar :
| s=obj_sort_opt CLASS xf=id_opt tps=typ_params_opt p=pat_nullary xefs=class_body
{ let x, efs = xefs in
let efs' =
if s.it = Type.Object Type.Local
if s.it = Type.Object
then efs
else List.map share_expfield efs
in
Expand All @@ -557,7 +552,7 @@ dec :
(* TODO(andreas): move to dec_nonvar once other production is gone *)
| s=obj_sort id_opt=id? EQ? efs=obj_body
{ let efs' =
if s.it = Type.Object Type.Local
if s.it = Type.Object
then efs
else List.map share_expfield efs
in
Expand Down
21 changes: 10 additions & 11 deletions src/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
type con = Con.t
type control = Returns | Promises (* Returns a computed value or immediate promise *)
type sharing = Local | Sharable
type obj_sort = Object of sharing | Actor
type obj_sort = Object | Actor
type func_sort = Call of sharing | Construct
type eff = Triv | Await

Expand Down Expand Up @@ -84,7 +84,7 @@ let prim = function
| _ -> raise (Invalid_argument "Type.prim")

let iter_obj t =
Obj (Object Local,
Obj (Object,
[{name = "next"; typ = Func (Call Local, Returns, [], [], [Opt t])}])

let array_obj t =
Expand All @@ -97,8 +97,8 @@ let array_obj t =
let mut t = immut t @
[ {name = "set"; typ = Func (Call Local, Returns, [], [Prim Nat; t], [])} ] in
match t with
| Mut t' -> Obj (Object Local, List.sort compare_field (mut t'))
| t -> Obj (Object Local, List.sort compare_field (immut t))
| Mut t' -> Obj (Object, List.sort compare_field (mut t'))
| t -> Obj (Object, List.sort compare_field (immut t))


(* Shifting *)
Expand Down Expand Up @@ -275,7 +275,7 @@ let as_prim_sub p env t = match promote env t with
let rec as_obj_sub name env t = match promote env t with
| Obj (s, tfs) -> s, tfs
| Array t -> as_obj_sub name env (array_obj t)
| Non -> Object Sharable, [{name; typ = Non}]
| Non -> Object, [{name; typ = Non}]
| _ -> invalid "as_obj_sub"
let as_array_sub env t = match promote env t with
| Array t -> t
Expand Down Expand Up @@ -431,8 +431,9 @@ let rec rel_typ env rel eq t1 t2 =
| Obj (s1, tfs1), Obj (s2, tfs2) ->
s1 = s2 &&
rel_fields env rel eq tfs1 tfs2
| Obj (s, _), Shared when rel != eq ->
s != Object Local
| Obj (s, tfs1), Shared when rel != eq ->
s = Actor ||
rel_fields env rel eq tfs1 (List.map (fun f -> { f with typ = Shared }) tfs1)
| Array t1', Array t2' ->
rel_typ env rel eq t1' t2'
| Array t1', Obj _ when rel != eq ->
Expand Down Expand Up @@ -606,7 +607,7 @@ let rec string_of_typ_nullary vs = function
sprintf "[var %s]" (string_of_typ_nullary vs t)
| Array t ->
sprintf "[%s]" (string_of_typ_nullary vs t)
| Obj (Object Local, fs) ->
| Obj (Object, fs) ->
sprintf "{%s}" (String.concat "; " (List.map (string_of_field vs) fs))
| t -> sprintf "(%s)" (string_of_typ' vs t)

Expand Down Expand Up @@ -644,10 +645,8 @@ and string_of_typ' vs t =
sprintf "?%s" (string_of_typ_nullary vs t)
| Async t ->
sprintf "async %s" (string_of_typ_nullary vs t)
| Obj (Object Sharable, fs) ->
sprintf "shared %s" (string_of_typ_nullary vs (Obj (Object Local, fs)))
| Obj (Actor, fs) ->
sprintf "actor %s" (string_of_typ_nullary vs (Obj (Object Local, fs)))
sprintf "actor %s" (string_of_typ_nullary vs (Obj (Object, fs)))
| Mut t ->
sprintf "var %s" (string_of_typ' vs t)
| t -> string_of_typ_nullary vs t
Expand Down
2 changes: 1 addition & 1 deletion src/type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
type con = Con.t
type control = Returns | Promises (* returns a computed value or immediate promise *)
type sharing = Local | Sharable
type obj_sort = Object of sharing | Actor
type obj_sort = Object | Actor
type func_sort = Call of sharing | Construct
type eff = Triv | Await

Expand Down
8 changes: 4 additions & 4 deletions src/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ and check_typ_field env s typ_field : T.field =
if s = T.Actor && not (T.is_func (T.promote env.cons t)) then
error env typ.at "actor field %s has non-function type\n %s"
id.it (T.string_of_typ_expand env.cons t);
if s <> T.Object T.Local && not (T.sub env.cons t T.Shared) then
error env typ.at "shared object or actor field %s has non-shared type\n %s"
if s = T.Actor && not (T.sub env.cons t T.Shared) then
error env typ.at "actor field %s has non-shared type\n %s"
id.it (T.string_of_typ_expand env.cons t);
{T.name = id.it; typ = t}

Expand Down Expand Up @@ -934,8 +934,8 @@ and infer_exp_field env s (tfs, ve) field : T.field list * val_env =
if not env.pre then begin
if s = T.Actor && priv.it = Public && not (is_func_exp exp) then
error env field.at "public actor field is not a function";
if s <> T.Object T.Local && priv.it = Public && not (T.sub env.cons t T.Shared) then
error env field.at "public shared object or actor field %s has non-shared type\n %s"
if s = T.Actor && priv.it = Public && not (T.sub env.cons t T.Shared) then
error env field.at "public actor field %s has non-shared type\n %s"
(string_of_name name.it) (T.string_of_typ_expand env.cons t)
end;
let ve' = T.Env.add id.it t ve in
Expand Down
44 changes: 36 additions & 8 deletions test/fail/issue103.as
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
// A (non-shared) function is not sharable
func invalid1 (f : shared (() -> Nat) -> ()) {
f (func foo() : Nat = 1)
{
func invalid (f : shared (() -> Nat) -> ()) {
f (func foo() : Nat = 1)
};
};

// An object with function fields is not sharable
func invalid2 (f : shared {foo : () -> Nat} -> ()) {
f (new { foo() : Nat = 1; })
{
func invalid (f : shared {foo : () -> Nat} -> ()) {
f (new { foo() : Nat = 1; })
};
};

// An Object with a mutable field is not sharable
{
func invalid (f : shared {var foo : Nat} -> ()) {
f { new { foo : Nat = 1; } }
};
};

// Cannot return a function in an async
func invalid3 () : (async (() -> Nat)) {
async { func foo() : Nat = 1 }
{
func invalid () : (async (() -> Nat)) {
async { func foo() : Nat = 1 }
};
};
// Cannot return an object with a mutable field in an async
{
func invalid () : (async ({var foo : Nat})) {
async { new { foo : Nat = 1; } }
};
};

// Cannot return an object with function fields in an async
func invalid4 () : (async ({foo : () -> Nat})) {
async { new { foo() : Nat = 1; } }
{
func invalid () : (async ({foo : () -> Nat})) {
async { new { foo() : Nat = 1; } }
};
};

// Cannot return an object with a mutable field in an async
{
func invalid () : (async ({var foo : Nat})) {
async { new { foo : Nat = 1; } }
};
};
14 changes: 13 additions & 1 deletion test/fail/ok/issue103.tc.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
issue103.as:2.27-2.38: type error, shared function has non-shared parameter type
issue103.as:3.28-3.39: type error, shared function has non-shared parameter type
() -> Nat
issue103.as:10.28-10.45: type error, shared function has non-shared parameter type
{foo : () -> Nat}
issue103.as:17.28-17.43: type error, shared function has non-shared parameter type
{foo : var Nat}
issue103.as:24.28-24.39: type error, async type has non-shared parameter type
() -> Nat
issue103.as:30.28-30.45: type error, async type has non-shared parameter type
{foo : var Nat}
issue103.as:37.28-37.47: type error, async type has non-shared parameter type
{foo : () -> Nat}
issue103.as:44.28-44.45: type error, async type has non-shared parameter type
{foo : var Nat}
20 changes: 0 additions & 20 deletions test/run/for.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ async {
assert(i == 11);
};

{
var i = 0;
for (j in await async (range(0, 10))) {
printInt(j);
assert(j == i);
i += 1;
};
assert(i == 11);
};

{
var i = 0;
i := 0;
Expand All @@ -31,16 +21,6 @@ async {
assert(i == 11);
};

{
var i = 0;
for (j in await async (range(0, 10))) {
printInt(j);
assert(j == i);
await (async (i += 1));
};
assert(i == 11);
};

};


Expand Down
2 changes: 1 addition & 1 deletion test/run/ok/for.run-ir.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
012345678910012345678910012345678910012345678910
012345678910012345678910
2 changes: 1 addition & 1 deletion test/run/ok/for.run-low.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
012345678910012345678910012345678910012345678910
012345678910012345678910
2 changes: 1 addition & 1 deletion test/run/ok/for.run.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
012345678910012345678910012345678910012345678910
012345678910012345678910