diff --git a/README.md b/README.md index 323c771ff90..5bd2173a1cb 100644 --- a/README.md +++ b/README.md @@ -187,9 +187,6 @@ and open the path printed on the last line of that command. * Async types: like futures/promises - `async T` -* Class types: the identity of a class (essentially, a modref) - - `class` - * Like types: structural expansions of nominal types - `like T` diff --git a/design/Syntax.md b/design/Syntax.md index d60646ba5db..d5cd42fa70f 100644 --- a/design/Syntax.md +++ b/design/Syntax.md @@ -10,7 +10,7 @@ Productions marked * probably deferred to later versions. (shared|actor)? { ;* } object [ var? ] array ? option - (shared|class)? ? -> function + shared ? -> function async future ( (( :)? ),* ) tuple Any top diff --git a/src/arrange.ml b/src/arrange.ml index 4d658d0d1d0..d2bc40e16c0 100644 --- a/src/arrange.ml +++ b/src/arrange.ml @@ -111,10 +111,6 @@ and obj_sort' s = match s with and obj_sort s = obj_sort' s.it -and func_sort s = match s.it with - | Type.Call sh -> Atom ("Call " ^ sharing sh) - | Type.Construct -> Atom "Construct" - and mut m = match m.it with | Const -> Atom "Const" | Var -> Atom "Var" @@ -141,7 +137,7 @@ and typ t = match t.it with | ArrayT (m, t) -> "ArrayT" $$ [mut m; typ t] | OptT t -> "OptT" $$ [typ t] | TupT ts -> "TupT" $$ List.map typ ts - | FuncT (s, tbs, at, rt) -> "FuncT" $$ [func_sort s] @ List.map typ_bind tbs @ [ typ at; typ rt] + | FuncT (s, tbs, at, rt) -> "FuncT" $$ [Atom (sharing s.it)] @ List.map typ_bind tbs @ [ typ at; typ rt] | AsyncT t -> "AsyncT" $$ [typ t] | ParT t -> "ParT" $$ [typ t] diff --git a/src/arrange_type.ml b/src/arrange_type.ml index 6740fea0ebe..fa1b4d5271d 100644 --- a/src/arrange_type.ml +++ b/src/arrange_type.ml @@ -6,23 +6,19 @@ let ($$) head inner = Node (head, inner) let id i = Atom i.it -let rec sharing sh = match sh with +let sharing sh = match sh with | Type.Local -> "Local" | Type.Sharable -> "Sharable" -and control c = match c with +let control c = match c with | Type.Returns -> "Returns" | Type.Promises -> "Promises" -and obj_sort s = match s with +let obj_sort s = match s with | Type.Object sh -> Atom ("Object " ^ sharing sh) | Type.Actor -> Atom "Actor" -and func_sort s = match s with - | Type.Call sh -> Atom ("Call " ^ sharing sh) - | Type.Construct -> Atom "Construct" - -and prim p = match p with +let prim p = match p with | Null -> Atom "Null" | Bool -> Atom "Bool" | Nat -> Atom "Nat" @@ -35,7 +31,7 @@ and prim p = match p with | Char -> Atom "Char" | Text -> Atom "Text" -and con c = Atom (Con.to_string c) +let con c = Atom (Con.to_string c) let rec typ (t:Type.typ) = match t with | Var (s, i) -> "Var" $$ [Atom s; Atom (string_of_int i)] @@ -45,10 +41,9 @@ let rec typ (t:Type.typ) = match t with | Array t -> "Array" $$ [typ t] | Opt t -> "Opt" $$ [typ t] | Tup ts -> "Tup" $$ List.map typ ts - | Func (s, c, tbs, at, rt) -> "Func" $$ [func_sort s; Atom (control c)] @ List.map typ_bind tbs @ [ "" $$ (List.map typ at); "" $$ (List.map typ rt)] + | Func (s, c, tbs, at, rt) -> "Func" $$ [Atom (sharing s); Atom (control c)] @ List.map typ_bind tbs @ [ "" $$ (List.map typ at); "" $$ (List.map typ rt)] | Async t -> "Async" $$ [typ t] | Mut t -> "Mut" $$ [typ t] - | Class -> Atom "Class" | Shared -> Atom "Shared" | Any -> Atom "Any" | Non -> Atom "Non" diff --git a/src/async.ml b/src/async.ml index 28a1fe9e65c..5938bbfd8b9 100644 --- a/src/async.ml +++ b/src/async.ml @@ -19,21 +19,23 @@ let unary typ = [typ] let nary typ = T.as_seq typ -let replyT as_seq typ = T.Func(T.Call T.Sharable, T.Returns, [], as_seq typ, []) +let replyT as_seq typ = T.Func(T.Sharable, T.Returns, [], as_seq typ, []) -let fullfillT as_seq typ = T.Func(T.Call T.Local, T.Returns, [], as_seq typ, []) +let fullfillT as_seq typ = T.Func(T.Local, T.Returns, [], as_seq typ, []) let t_async as_seq t = - T.Func (T.Call T.Local, T.Returns, [], [T.Func(T.Call T.Local, T.Returns, [],as_seq t,[])], []) + T.Func (T.Local, T.Returns, [], [T.Func(T.Local, T.Returns, [],as_seq t,[])], []) let new_async_ret as_seq t = [t_async as_seq t;fullfillT as_seq t] let new_asyncT = - T.Func(T.Call T.Local,T.Returns, - [ { var = "T"; - bound = T.Shared } ], - [], - new_async_ret unary (T.Var ("T", 0))) + T.Func ( + T.Local, + T.Returns, + [ { var = "T"; bound = T.Shared } ], + [], + new_async_ret unary (T.Var ("T", 0)) + ) let new_asyncE = idE ("@new_async"@@no_region) new_asyncT @@ -92,7 +94,7 @@ let letEta e scope = let isAwaitableFunc exp = match typ exp with - | T.Func (T.Call T.Sharable,T.Promises,_,_,[T.Async _]) -> true + | T.Func (T.Sharable,T.Promises,_,_,[T.Async _]) -> true | _ -> false let extendTup ts t2 = ts @ [t2] @@ -137,7 +139,7 @@ let rec t_typ (t:T.typ) = | Func (s, c, tbs, t1, t2) -> begin match s with - | T.Call T.Sharable -> + | T.Sharable -> begin match t2 with | [] -> @@ -156,7 +158,6 @@ let rec t_typ (t:T.typ) = | Async t -> t_async nary (t_typ t) | Obj (s, fs) -> Obj (s, List.map t_field fs) | Mut t -> Mut (t_typ t) - | Class -> Class | Shared -> Shared | Any -> Any | Non -> Non @@ -235,7 +236,7 @@ and t_exp' (exp:exp) = | t -> assert false in let k = fresh_id contT in let v1 = fresh_id t1 in - let post = fresh_id (T.Func(T.Call T.Sharable,T.Returns,[],[],[])) in + let post = fresh_id (T.Func(T.Sharable,T.Returns,[],[],[])) in let u = fresh_id T.unit in let ((nary_async,nary_reply),def) = new_nary_async_reply t1 in (blockE [letP (tupP [varP nary_async; varP nary_reply]) def; @@ -247,7 +248,7 @@ and t_exp' (exp:exp) = | CallE (cc,exp1, typs, exp2) when isAwaitableFunc exp1 -> let ts1,t2 = match typ exp1 with - | T.Func (T.Call T.Sharable,T.Promises,tbs,ts1,[T.Async t2]) -> + | T.Func (T.Sharable,T.Promises,tbs,ts1,[T.Async t2]) -> List.map t_typ ts1, t_typ t2 | _ -> assert(false) in @@ -315,10 +316,9 @@ and t_dec' dec' = let s = cc.Value.sort in begin match s with - | T.Construct - | T.Call T.Local -> + | T.Local -> FuncD (cc, id, t_typ_binds typbinds, t_pat pat, t_typ typT, t_exp exp) - | T.Call T.Sharable -> + | T.Sharable -> begin match typ exp with | T.Tup [] -> diff --git a/src/awaitopt.ml b/src/awaitopt.ml index 404dc2f1a8c..a44c79be4ff 100644 --- a/src/awaitopt.ml +++ b/src/awaitopt.ml @@ -284,7 +284,7 @@ and c_loop_some context k e1 e2 = and c_for context k pat e1 e2 = let v1 = fresh_id (typ e1) in - let next_typ = (T.Func(T.Call T.Local, T.Returns, [], [], [T.Opt pat.note])) in + let next_typ = (T.Func(T.Local, T.Returns, [], [], [T.Opt pat.note])) in let dotnext v = dotE v nextN next_typ -*- unitE in let loop = fresh_id (contT T.unit) in let v2 = fresh_id T.unit in diff --git a/src/check_ir.ml b/src/check_ir.ml index dad25f85ebf..d4a3f2472b3 100644 --- a/src/check_ir.ml +++ b/src/check_ir.ml @@ -142,7 +142,6 @@ let rec check_typ env typ : unit = | T.Any -> () | T.Non -> () | T.Shared -> () - | T.Class -> () | T.Prim _ -> () | T.Array typ -> check_typ env typ @@ -164,7 +163,7 @@ let rec check_typ env typ : unit = error env no_region "promising function with non-async result type \n %s" (T.string_of_typ_expand env'.cons t2) end; - if sort = T.Call T.Sharable then begin + if sort = T.Sharable then begin let t1 = T.seq ts1 in check_sub env' no_region t1 T.Shared; match ts2 with @@ -723,7 +722,7 @@ and check_dec env dec = let env' = adjoin_typs env ce in let ve = check_pat_exhaustive env' pat in check_typ env' t2; - check ((cc.Value.sort = T.Call T.Sharable && Type.is_async t2) + check ((cc.Value.sort = T.Sharable && Type.is_async t2) ==> isAsyncE exp) "shared function with async type has non-async body"; let env'' = @@ -790,7 +789,7 @@ and gather_dec env scope dec : scope = | _ -> T.as_seq t2 in let c = match func_sort, t2 with - | T.Call T.Sharable, (T.Async _) -> T.Promises (* TBR: do we want this for T.Local too? *) + | T.Sharable, (T.Async _) -> T.Promises (* TBR: do we want this for T.Local too? *) | _ -> T.Returns in let ts = List.map (fun typbind -> typbind.it.T.bound) typ_binds in diff --git a/src/compile.ml b/src/compile.ml index 5b5e04d5def..8a8ad22c173 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -941,7 +941,7 @@ module AllocHow = struct | VarD _ -> map_of_set LocalMut d (* Messages cannot be static *) - | FuncD (cc, _, _, _, _, _) when cc.Value.sort = Type.Call Type.Sharable -> + | FuncD (cc, _, _, _, _, _) when cc.Value.sort = Type.Sharable -> map_of_set LocalImmut d (* Static functions *) | FuncD _ when is_static env how0 f -> @@ -1128,7 +1128,6 @@ module Object = struct in the await-translation of objects, and get rid of this indirection. *) - (* First word: Class pointer (0x1, an invalid pointer, when none) *) let header_size = Int32.add Tagged.header_size 1l (* Number of object fields *) @@ -2803,7 +2802,7 @@ module FuncDec = struct (* Compile a closure declaration (has free variables) *) let dec_closure pre_env cc h name captured mk_pat mk_body at = - let is_local = cc.Value.sort <> Type.Call Type.Sharable in + let is_local = cc.Value.sort <> Type.Sharable in let (set_li, get_li) = new_local pre_env (name.it ^ "_clos") in let (pre_env1, alloc_code0) = AllocHow.add_how pre_env name.it h in @@ -2893,7 +2892,7 @@ module FuncDec = struct Var.set_val env name.it) let dec pre_env how name cc captured mk_pat mk_body at = - let is_local = cc.Value.sort <> Type.Call Type.Sharable in + let is_local = cc.Value.sort <> Type.Sharable in if not is_local && E.mode pre_env <> DfinityMode then @@ -3351,7 +3350,7 @@ and compile_exp (env : E.t) exp = compile_unboxed_zero ^^ (* A dummy closure *) compile_exp_as env (StackRep.of_arity cc.Value.n_args) e2 ^^ (* the args *) G.i (Call (nr fi)) - | None, (Type.Call Type.Local | Type.Construct) -> + | None, Type.Local -> let (set_clos, get_clos) = new_local env "clos" in compile_exp_vanilla env e1 ^^ set_clos ^^ @@ -3359,7 +3358,7 @@ and compile_exp (env : E.t) exp = compile_exp_as env (StackRep.of_arity cc.Value.n_args) e2 ^^ get_clos ^^ Closure.call_closure env cc - | None, Type.Call Type.Sharable -> + | None, Type.Sharable -> let (set_funcref, get_funcref) = new_local env "funcref" in compile_exp_as env StackRep.UnboxedReference e1 ^^ set_funcref ^^ diff --git a/src/construct.ml b/src/construct.ml index 6b435a60268..f0d00e51cb7 100644 --- a/src/construct.ml +++ b/src/construct.ml @@ -279,7 +279,7 @@ let funcD f x exp = match f.it, x.it with | VarE _, VarE _ -> let sharing, t1, t2 = match typ f with - | T.Func(T.Call sharing, _, _, ts1, ts2) -> sharing, T.seq ts1, T.seq ts2 + | T.Func(sharing, _, _, ts1, ts2) -> sharing, T.seq ts1, T.seq ts2 | _ -> assert false in let cc = Value.call_conv_of_typ (typ f) in { it = FuncD (cc, @@ -298,7 +298,7 @@ let funcD f x exp = let nary_funcD f xs exp = match f.it, typ f with | VarE _, - T.Func(T.Call sharing,_,_,_,ts2) -> + T.Func(sharing,_,_,_,ts2) -> let cc = Value.call_conv_of_typ (typ f) in let t2 = T.seq ts2 in { it = FuncD (cc, @@ -317,8 +317,8 @@ let nary_funcD f xs exp = let answerT = T.unit -let contT typ = T.Func (T.Call T.Local, T.Returns, [], T.as_seq typ, []) -let cpsT typ = T.Func (T.Call T.Local, T.Returns, [], [contT typ], []) +let contT typ = T.Func (T.Local, T.Returns, [], T.as_seq typ, []) +let cpsT typ = T.Func (T.Local, T.Returns, [], [contT typ], []) let fresh_cont typ = fresh_id (contT typ) @@ -343,7 +343,7 @@ let (-->) x exp = match x.it with | VarE _ -> let f = idE ("$lambda" @@ no_region) - (T.Func (T.Call T.Local, T.Returns, [], T.as_seq (typ x), T.as_seq (typ exp))) + (T.Func (T.Local, T.Returns, [], T.as_seq (typ x), T.as_seq (typ exp))) in decE (funcD f x exp) | _ -> failwith "Impossible: -->" @@ -351,7 +351,7 @@ let (-->) x exp = (* n-ary local lambda *) let (-->*) xs exp = let f = idE ("$lambda" @@ no_region) - (T.Func (T.Call T.Local, T.Returns, [], + (T.Func (T.Local, T.Returns, [], List.map typ xs, T.as_seq (typ exp))) in decE (nary_funcD f xs exp) @@ -359,7 +359,7 @@ let (-->*) xs exp = (* n-ary shared lambda *) let (-@>*) xs exp = let f = idE ("$lambda" @@ no_region) - (T.Func (T.Call T.Sharable, T.Returns, [], + (T.Func (T.Sharable, T.Returns, [], List.map typ xs, T.as_seq (typ exp))) in decE (nary_funcD f xs exp) @@ -387,8 +387,8 @@ let ( -*- ) exp1 exp2 = *) let prim_async typ = - primE "@async" (T.Func (T.Call T.Local, T.Returns, [], [cpsT typ], [T.Async typ])) + primE "@async" (T.Func (T.Local, T.Returns, [], [cpsT typ], [T.Async typ])) let prim_await typ = - primE "@await" (T.Func (T.Call T.Local, T.Returns, [], [T.Async typ; contT typ], [])) + primE "@await" (T.Func (T.Local, T.Returns, [], [T.Async typ; contT typ], [])) diff --git a/src/interpret.ml b/src/interpret.ml index ea99966f5e8..a29eb38a2df 100644 --- a/src/interpret.ml +++ b/src/interpret.ml @@ -149,7 +149,7 @@ let actor_msg id f v (k : V.value V.cont) = let make_unit_message id v = let call_conv, f = V.as_func v in match call_conv with - | {V.sort = T.Call T.Sharable; V.n_res = 0; _} -> + | {V.sort = T.Sharable; V.n_res = 0; _} -> Value.message_func call_conv.V.n_args (fun v k -> actor_msg id f v (fun _ -> ()); k V.unit @@ -161,7 +161,7 @@ let make_unit_message id v = let make_async_message id v = let call_conv, f = V.as_func v in match call_conv with - | {V.sort = T.Call T.Sharable; V.control = T.Promises; V.n_res = 1; _} -> + | {V.sort = T.Sharable; V.control = T.Promises; V.n_res = 1; _} -> Value.async_func call_conv.V.n_args (fun v k -> let async = make_async () in actor_msg id f v (fun v_async -> diff --git a/src/interpret_ir.ml b/src/interpret_ir.ml index 615a9c82431..4e585674442 100644 --- a/src/interpret_ir.ml +++ b/src/interpret_ir.ml @@ -149,7 +149,7 @@ let actor_msg id f v (k : V.value V.cont) = let make_unit_message id v = let call_conv, f = V.as_func v in match call_conv with - | {V.sort = T.Call T.Sharable; V.n_res = 0; _} -> + | {V.sort = T.Sharable; V.n_res = 0; _} -> Value.message_func call_conv.V.n_args (fun v k -> actor_msg id f v (fun _ -> ()); k V.unit @@ -162,7 +162,7 @@ let make_async_message id v = assert (not !Flags.async_lowering); let call_conv, f = V.as_func v in match call_conv with - | {V.sort = T.Call T.Sharable; V.control = T.Promises; V.n_res = 1; _} -> + | {V.sort = T.Sharable; V.control = T.Promises; V.n_res = 1; _} -> Value.async_func call_conv.V.n_args (fun v k -> let async = make_async () in actor_msg id f v (fun v_async -> @@ -640,8 +640,7 @@ and interpret_dec env dec (k : V.value V.cont) = let v = V.Func (V.call_conv_of_typ dec.note.Syntax.note_typ, f) in let v = match cc.Value.sort with - | T.Call T.Sharable -> - make_message id dec.note.Syntax.note_typ v + | T.Sharable -> make_message id dec.note.Syntax.note_typ v | _-> v in define_id env id v; diff --git a/src/parser.mly b/src/parser.mly index 6f1d3ab6993..294e1cd3cd9 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -60,8 +60,8 @@ 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)} + | FuncT ({it = Type.Local; _} as s, tbs, t1, t2) -> + { t with it = FuncT ({s with it = Type.Sharable}, tbs, t1, t2)} | _ -> t let share_typfield tf = @@ -187,9 +187,8 @@ seplist1(X, SEP) : | SHARED { Type.Sharable @@ at $sloc } %inline func_sort_opt : - | (* empty *) { Type.Call Type.Local @@ no_region } - | SHARED { Type.Call Type.Sharable @@ at $sloc } - | CLASS { Type.Construct @@ at $sloc } + | (* empty *) { Type.Local @@ no_region } + | SHARED { Type.Sharable @@ at $sloc } (* Types *) @@ -251,7 +250,7 @@ typ_field : | mut=var_opt x=id COLON t=typ { {id = x; typ = t; mut} @@ at $sloc } | x=id tps=typ_params_opt t1=typ_nullary t2=return_typ - { let t = FuncT(Type.Call Type.Local @@ no_region, tps, t1, t2) + { let t = FuncT(Type.Local @@ no_region, tps, t1, t2) @! span x.at t2.at in {id = x; typ = t; mut = Const @@ no_region} @@ at $sloc } diff --git a/src/prelude.ml b/src/prelude.ml index daa56a1dea7..2d01a864e1f 100644 --- a/src/prelude.ml +++ b/src/prelude.ml @@ -3,7 +3,6 @@ let prelude = type Any = prim "Any"; type None = prim "None"; type Shared = prim "Shared"; -type Class = prim "Class"; type Null = prim "Null"; type Bool = prim "Bool"; type Nat = prim "Nat"; diff --git a/src/syntax.ml b/src/syntax.ml index e84db43b9f9..eab511f8aad 100644 --- a/src/syntax.ml +++ b/src/syntax.ml @@ -19,7 +19,6 @@ let string_of_name (Name s ) = s type sharing = Type.sharing Source.phrase type obj_sort = Type.obj_sort Source.phrase -type func_sort = Type.func_sort Source.phrase type mut = mut' Source.phrase and mut' = Const | Var @@ -32,7 +31,7 @@ and typ' = | ArrayT of mut * typ (* array *) | OptT of typ (* option *) | TupT of typ list (* tuple *) - | FuncT of func_sort * typ_bind list * typ * typ (* function *) + | FuncT of sharing * typ_bind list * typ * typ (* function *) | AsyncT of typ (* future *) | ParT of typ (* parentheses, used to control function arity only *) (* diff --git a/src/tailcall.ml b/src/tailcall.ml index 327715e16db..35f4df59122 100644 --- a/src/tailcall.ml +++ b/src/tailcall.ml @@ -195,7 +195,7 @@ and dec' env d = let env = bind env i None in (fun env1 -> VarD(i,exp env1 e)), env - | FuncD ({ Value.sort = Call Local; _} as cc, id, tbs, p, typT, exp0) -> + | FuncD ({ Value.sort = Local; _} as cc, id, tbs, p, typT, exp0) -> let env = bind env id None in (fun env1 -> let temp = fresh_id (Mut p.note) in diff --git a/src/type.ml b/src/type.ml index c290ddc726f..33bb6a837f4 100644 --- a/src/type.ml +++ b/src/type.ml @@ -4,7 +4,6 @@ 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 func_sort = Call of sharing | Construct type eff = Triv | Await type prim = @@ -29,11 +28,10 @@ and typ = | Array of typ (* array *) | Opt of typ (* option *) | Tup of typ list (* tuple *) - | Func of func_sort * control * + | Func of sharing * control * bind list * typ list * typ list (* function *) | Async of typ (* future *) | Mut of typ (* mutable type *) - | Class (* class *) | Shared (* sharable *) | Any (* top *) | Non (* bottom *) @@ -85,17 +83,17 @@ let prim = function let iter_obj t = Obj (Object Local, - [{name = "next"; typ = Func (Call Local, Returns, [], [], [Opt t])}]) + [{name = "next"; typ = Func (Local, Returns, [], [], [Opt t])}]) let array_obj t = let immut t = - [ {name = "get"; typ = Func (Call Local, Returns, [], [Prim Nat], [t])}; - {name = "len"; typ = Func (Call Local, Returns, [], [], [Prim Nat])}; - {name = "keys"; typ = Func (Call Local, Returns, [], [], [iter_obj (Prim Nat)])}; - {name = "vals"; typ = Func (Call Local, Returns, [], [], [iter_obj t])}; + [ {name = "get"; typ = Func (Local, Returns, [], [Prim Nat], [t])}; + {name = "len"; typ = Func (Local, Returns, [], [], [Prim Nat])}; + {name = "keys"; typ = Func (Local, Returns, [], [], [iter_obj (Prim Nat)])}; + {name = "vals"; typ = Func (Local, Returns, [], [], [iter_obj t])}; ] in let mut t = immut t @ - [ {name = "set"; typ = Func (Call Local, Returns, [], [Prim Nat; t], [])} ] in + [ {name = "set"; typ = Func (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)) @@ -117,7 +115,6 @@ let rec shift i n t = | Async t -> Async (shift i n t) | Obj (s, fs) -> Obj (s, List.map (shift_field n i) fs) | Mut t -> Mut (shift i n t) - | Class -> Class | Shared -> Shared | Any -> Any | Non -> Non @@ -152,7 +149,6 @@ let rec subst sigma t = | Async t -> Async (subst sigma t) | Obj (s, fs) -> Obj (s, List.map (subst_field sigma) fs) | Mut t -> Mut (subst sigma t) - | Class -> Class | Shared -> Shared | Any -> Any | Non -> Non @@ -192,7 +188,6 @@ let rec open' i ts t = | Async t -> Async (open' i ts t) | Obj (s, fs) -> Obj (s, List.map (open_field i ts) fs) | Mut t -> Mut (open' i ts t) - | Class -> Class | Shared -> Shared | Any -> Any | Non -> Non @@ -327,7 +322,7 @@ let rec span env = function | Prim Word16 -> Some 0x10000 | Prim (Word32 | Word64 | Char) -> None (* for all practical purpuses *) | Obj _ | Tup _ | Async _ -> Some 1 - | Array _ | Func _ | Class | Shared | Any -> None + | Array _ | Func _ | Shared | Any -> None | Opt _ -> Some 2 | Mut t -> span env t | Non -> Some 0 @@ -338,7 +333,7 @@ let rec span env = function exception Unavoidable of con let rec avoid' env env' = function - | (Prim _ | Var _ | Any | Non | Shared | Class | Pre) as t -> t + | (Prim _ | Var _ | Any | Non | Shared | Pre) as t -> t | Con (c, ts) -> (match Con.Env.find_opt c env' with | Some (Abs _) -> raise (Unavoidable c) @@ -450,23 +445,14 @@ let rec rel_typ env rel eq t1 t2 = | Tup ts1, Shared -> rel_list rel_typ env rel eq ts1 (List.map (fun _ -> Shared) ts1) | Func (s1, c1, tbs1, t11, t12), Func (s2, c2, tbs2, t21, t22) -> - (* TODO: not all classes should be sharable *) - c1 = c2 && - (s1 = s2 || rel != eq && s1 = Construct) && + c1 = c2 && s1 = s2 && (match rel_binds env rel eq tbs1 tbs2 with | Some (ts, env') -> rel_list rel_typ env' rel eq (List.map (open_ ts) t21) (List.map (open_ ts) t11) && rel_list rel_typ env' rel eq (List.map (open_ ts) t12) (List.map (open_ ts) t22) | None -> false ) - | Func (Construct, _, _, _, _), Class when rel != eq -> - true - | Func (s1, _, _, _, _), Shared when rel != eq -> - (* TODO: not all classes should be sharable *) - s1 <> Call Local - | Class, Class -> - true - | Class, Shared -> + | Func (Sharable, _, _, _, _), Shared when rel != eq -> true | Shared, Shared -> true @@ -582,16 +568,11 @@ let string_of_sharing = function | Local -> "" | Sharable -> "shared " -let string_of_func_sort = function - | Call sh -> string_of_sharing sh - | Construct -> "class " - let rec string_of_typ_nullary vs = function | Pre -> "???" | Any -> "Any" | Non -> "Non" | Shared -> "Shared" - | Class -> "Class" | Prim p -> string_of_prim p | Var (s, i) -> (try string_of_var (List.nth vs i) with _ -> assert false) | Con (c, []) -> string_of_con vs c @@ -632,13 +613,13 @@ and string_of_cod c vs ts = and string_of_typ' vs t = match t with | Func (s, c, [], ts1, ts2) -> - sprintf "%s%s -> %s" (string_of_func_sort s) + sprintf "%s%s -> %s" (string_of_sharing s) (string_of_dom vs ts1) (string_of_cod c vs ts2) | Func (s, c, tbs, ts1, ts2) -> let vs' = names_of_binds vs tbs in sprintf "%s%s%s -> %s" - (string_of_func_sort s) (string_of_binds (vs' @ vs) vs' tbs) + (string_of_sharing s) (string_of_binds (vs' @ vs) vs' tbs) (string_of_dom (vs' @ vs) ts1) (string_of_cod c (vs' @ vs) ts2) | Opt t -> sprintf "?%s" (string_of_typ_nullary vs t) @@ -696,7 +677,7 @@ let rec string_of_typ_expand env t = | Abs _ -> s | Def _ -> match normalize env t with - | Prim _ | Any | Non | Class -> s + | Prim _ | Any | Non -> s | t' -> s ^ " = " ^ string_of_typ_expand env t' ) | _ -> s diff --git a/src/type.mli b/src/type.mli index d26ebb50719..884ac714070 100644 --- a/src/type.mli +++ b/src/type.mli @@ -4,7 +4,6 @@ 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 func_sort = Call of sharing | Construct type eff = Triv | Await type prim = @@ -29,11 +28,10 @@ and typ = | Array of typ (* array *) | Opt of typ (* option *) | Tup of typ list (* tuple *) - | Func of func_sort * control * + | Func of sharing * control * bind list * typ list * typ list (* function *) | Async of typ (* future *) | Mut of typ (* mutable type *) - | Class (* class *) | Shared (* sharable *) | Any (* top *) | Non (* bottom *) @@ -88,7 +86,7 @@ val as_opt : typ -> typ val as_tup : typ -> typ list val as_unit : typ -> unit val as_pair : typ -> typ * typ -val as_func : typ -> func_sort * control * bind list * typ list * typ list +val as_func : typ -> sharing * control * bind list * typ list * typ list val as_async : typ -> typ val as_mut : typ -> typ val as_immut : typ -> typ @@ -144,7 +142,7 @@ module Env : Env.S with type key = string (* Pretty printing *) val string_of_prim : prim -> string -val string_of_func_sort: func_sort -> string +val string_of_sharing: sharing -> string val string_of_typ : typ -> string val string_of_kind : kind -> string val strings_of_kind : kind -> string * string * string diff --git a/src/typing.ml b/src/typing.ml index a24b08695e6..ad59595bef7 100644 --- a/src/typing.ml +++ b/src/typing.ml @@ -150,7 +150,6 @@ and check_typ' env typ : T.typ = | PrimT "Any" -> T.Any | PrimT "None" -> T.Non | PrimT "Shared" -> T.Shared - | PrimT "Class" -> T.Class | PrimT s -> (try T.Prim (T.prim s) with Invalid_argument _ -> error env typ.at "unknown primitive type" @@ -168,7 +167,7 @@ and check_typ' env typ : T.typ = let ts1 = List.map (check_typ env') typs1 in let ts2 = List.map (check_typ env') typs2 in let c = match typs2 with [{it = AsyncT _; _}] -> T.Promises | _ -> T.Returns in - if sort.it = T.Call T.Sharable then begin + if sort.it = T.Sharable then begin let t1 = T.seq ts1 in if not (T.sub env'.cons t1 T.Shared) then error env typ1.at "shared function has non-shared parameter type\n %s" @@ -1098,7 +1097,7 @@ and gather_dec_typdecs env scope dec : scope = match dec.it with | ClassD (id, _, _ , _, _, _, _) -> let t2 = T.Con (c, List.map (fun c' -> T.Con (c', [])) cs) in - T.Env.add id.it (T.Func (T.Construct, T.Returns, pre_tbs, [T.Pre], [t2])) scope.val_env + T.Env.add id.it (T.Func (T.Local, T.Returns, pre_tbs, [T.Pre], [t2])) scope.val_env | _ -> scope.val_env in let te' = T.Env.add con_id.it c scope.typ_env in let ce' = Con.Env.add c pre_k scope.con_env in @@ -1204,7 +1203,7 @@ and infer_dec_valdecs env dec : val_env = in let tbs = List.map2 (fun c t -> {T.var = Con.name c; bound = T.close cs t}) cs ts in T.Env.singleton id.it - (T.Func (T.Call sort.it, c, tbs, List.map (T.close cs) ts1, List.map (T.close cs) ts2)) + (T.Func (sort.it, c, tbs, List.map (T.close cs) ts1, List.map (T.close cs) ts2)) | TypD _ -> T.Env.empty | ClassD (id, con_id, typ_binds, sort, pat, self_id, fields) -> @@ -1215,7 +1214,7 @@ and infer_dec_valdecs env dec : val_env = let ts1 = match pat.it with TupP _ -> T.as_seq t1 | _ -> [t1] in let t2 = T.Con (c, List.map (fun c -> T.Con (c, [])) cs) in let tbs = List.map2 (fun c t -> {T.var = Con.name c; bound = T.close cs t}) cs ts in - T.Env.singleton id.it (T.Func (T.Construct, T.Returns, tbs, List.map (T.close cs) ts1, [T.close cs t2])) + T.Env.singleton id.it (T.Func (T.Local, T.Returns, tbs, List.map (T.close cs) ts1, [T.close cs t2])) (* Programs *) diff --git a/src/value.ml b/src/value.ml index ff11663f4fc..6bd6e7b060d 100644 --- a/src/value.ml +++ b/src/value.ml @@ -190,7 +190,7 @@ end type unicode = int type call_conv = { - sort: Type.func_sort; + sort: Type.sharing; control : Type.control; n_args : int; n_res : int; @@ -230,9 +230,9 @@ and 'a cont = 'a -> unit (* Smart constructors *) -let local_cc n m = { sort = T.Call T.Local; control = T.Returns; n_args = n; n_res = m} -let message_cc n = { sort = T.Call T.Sharable; control = T.Returns; n_args = n; n_res = 0} -let async_cc n = { sort = T.Call T.Sharable; control = T.Promises; n_args = n; n_res = 1} +let local_cc n m = { sort = T.Local; control = T.Returns; n_args = n; n_res = m} +let message_cc n = { sort = T.Sharable; control = T.Returns; n_args = n; n_res = 0} +let async_cc n = { sort = T.Sharable; control = T.Promises; n_args = n; n_res = 1} let local_func n m f = Func (local_cc n m, f) let message_func n f = Func (message_cc n, f) @@ -395,7 +395,7 @@ let string_of_def d = string_of_def' !Flags.print_depth d let string_of_call_conv {sort;control;n_args;n_res} = sprintf "(%s %i %s %i)" - (T.string_of_func_sort sort) + (T.string_of_sharing sort) n_args (match control with | T.Returns -> "->" diff --git a/src/value.mli b/src/value.mli index ccfd0a40234..c0362d0f063 100644 --- a/src/value.mli +++ b/src/value.mli @@ -60,7 +60,7 @@ module Env : Env.S with type key = string type unicode = int type call_conv = { - sort: Type.func_sort; + sort: Type.sharing; control : Type.control; n_args : int; n_res : int;