Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
be5e40a
modified Ir.ml and desugar.ml to preserve types
crusso Jan 4, 2019
e9d5dbb
tidy
crusso Jan 7, 2019
e1e93b8
use semantic, not syntactic types in IR
crusso Jan 7, 2019
f44d211
remove inst type from syntax (now redundant)
crusso Jan 8, 2019
cb4cd53
update tests to reflect new arrange output
crusso Jan 8, 2019
535449c
simplify note on typ_bind to typ from Con.t ref
crusso Jan 8, 2019
d828378
simplify pat annotations to typ from note_typ
crusso Jan 8, 2019
e96576b
simply annotation on types to typ from typ_note
crusso Jan 8, 2019
a6292f3
simplify annotation on types to typ from typ_note
crusso Jan 8, 2019
ef0710b
Merge branch 'claudio/check-ir' of github.com:dfinity-lab/actorscript…
crusso Jan 8, 2019
f87144e
check_ir.ml: WIP: checking of types (only)
crusso Jan 9, 2019
064ba0f
WIP: almost working check-ir
crusso Jan 10, 2019
6ac59b1
desugar ClassD into TypD and FuncD; fix intial env in call oo check IR
crusso Jan 11, 2019
38c3849
ironing out bugs
crusso Jan 12, 2019
cbc74ed
fix async lowering to also lower (new) type and kind annotations on …
crusso Jan 14, 2019
cda0233
rename typbind to typ_bind, conid to con_id
crusso Jan 14, 2019
efcecd1
check IR.ActorE and NewObj properly
crusso Jan 15, 2019
190303b
add element type annotation to Ir.ArrayE and fix broken annotations i…
crusso Jan 21, 2019
137a4b6
annoted blocks with type after avoidance to enable checking of ir
crusso Jan 21, 2019
62fd1c8
updated tests to reflect new type annotations
crusso Jan 21, 2019
79535db
remove typ_env from IR scope; replace note_typ assigment with type eq…
crusso Jan 22, 2019
cc70ebe
annotate DotE with obj_sort to simplify desugaring (in next commit)
crusso Jan 22, 2019
d64ff0b
remove con_env from desugar.ml, now that DotE is sort annotated
crusso Jan 22, 2019
7408f0f
use Type.compare_field, not lexicographic compare, for ordering field…
crusso Jan 22, 2019
50306df
trivial code fixes
crusso Jan 23, 2019
82eea3f
remove unfold_obj in favour of Type.promote
crusso Jan 23, 2019
394e023
WIP, simplify check_ir to do less inference using annotations (or, in…
crusso Jan 24, 2019
b0814dc
ir checker: remove redundant pat code
crusso Jan 24, 2019
e443d67
restore checks on FuncD and DecD
crusso Jan 24, 2019
3c93dc8
gather block scope in a single pass; remove commented out code
crusso Jan 24, 2019
b2ded26
more checking, less inference, cleanup
crusso Jan 24, 2019
9d2d880
remove pre field from env
crusso Jan 24, 2019
b900265
check_ir: fail on first error, no recovery
crusso Jan 24, 2019
f1e81e4
add check for async body, remove check_lit
crusso Jan 24, 2019
be09e7a
spacing
crusso Jan 24, 2019
f5b5256
clean up desugarer a little
crusso Jan 24, 2019
8a6e2ca
add IR effect inference and checking of effects in check-ir; eventual…
crusso Jan 24, 2019
6bfcefd
restored ir-checking that was masking failing build
crusso Jan 25, 2019
fc05eb9
WIP; rewrite check_ir to avoid inference
crusso Jan 26, 2019
ff32768
cleanup
crusso Jan 26, 2019
53245d9
remove infer_pat*; replace by check_pat*; rename other infer_ to type_
crusso Jan 26, 2019
8f6c193
revise typing.ml to (re) annotate rvalues with dereferenced type; sim…
crusso Jan 26, 2019
1e5001f
address joachim's comments and refactor some remaining error as checks
crusso Jan 30, 2019
47ad813
refactor <~
crusso Jan 30, 2019
7b15375
add comments to T.Non <: ... cases
crusso Jan 30, 2019
8e27294
merge with master
crusso Jan 30, 2019
775a3af
merge fixes
crusso Jan 30, 2019
bb62813
more selective desugaring of literal objects in declarations (fix for…
crusso Jan 31, 2019
9630ae0
Merge branch 'master' into fix/issue129
crusso Jan 31, 2019
c593086
add newline
crusso Jan 31, 2019
6faddf2
untabify
crusso Feb 1, 2019
d972270
really untabify
crusso Feb 1, 2019
06e38ca
spaceing
crusso Feb 1, 2019
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
12 changes: 6 additions & 6 deletions src/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module I = Ir
module T = Type

(* TODO: clean me up when IrOps available, especially build_obj *)

(* Combinators used in the desguaring *)

let bool_lit b : Ir.exp =
Expand Down Expand Up @@ -162,8 +162,8 @@ let
| d::ds ->
match d.it with
| S.ClassD(_,con_id,_,_,_,_,_) ->
let (c,k) = match con_id.note with Some p -> p | _ -> assert false in
let typD = {it = I.TypD (c,k);
let (c, k) = match con_id.note with Some p -> p | _ -> assert false in
let typD = {it = I.TypD (c, k);
at = d.at;
note = {S.note_typ = T.unit; S.note_eff = T.Triv}}
in
Expand All @@ -177,8 +177,8 @@ let
let cc = Value.call_conv_of_typ n.S.note_typ in
I.FuncD (cc, i, typ_binds tbs, pat p, ty.note, exp e)
| S.TypD (con_id, typ_bind, t) ->
let (c,k) = Lib.Option.value con_id.note in
I.TypD (c,k)
let (c, k) = Lib.Option.value con_id.note in
I.TypD (c, k)
| S.ClassD (fun_id, typ_id, tbs, s, p, self_id, es) ->
let cc = Value.call_conv_of_typ n.S.note_typ in
let inst = List.map
Expand All @@ -191,7 +191,7 @@ let
match n.S.note_typ with
| T.Func(s,c,bds,dom,[rng]) ->
assert(List.length inst = List.length bds);
T.open_ inst rng
T.open_ inst rng
| _ -> assert false
in
I.FuncD (cc, fun_id, typ_binds tbs, pat p, obj_typ, (* TBR *)
Expand Down
33 changes: 21 additions & 12 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ let (@=) it at = {it; at; note = None}
let dummy_obj_sort() = ref (Type.Object Type.Local)

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

let anon sort at = "anon-" ^ sort ^ "-" ^ string_of_pos at.left

let name_exp e =
match e.it with
| VarE x -> [], e, dup_var x
| _ ->
let x = ("anon-val-" ^ string_of_pos (e.at.left)) @@ e.at in
let x = anon "val" e.at @@ e.at in
[LetD (VarP x @! x.at, e) @? e.at], dup_var x, dup_var x

let assign_op lhs rhs_f at =
Expand Down Expand Up @@ -164,8 +167,7 @@ seplist1(X, SEP) :
| id=ID
{ fun _ _ -> id @@ at $sloc }
| (* empty *)
{ fun sort sloc ->
("anon-" ^ sort ^ "-" ^ string_of_pos (at sloc).left) @@ at sloc }
{ fun sort sloc -> anon sort (at sloc) @@ at sloc }

%inline var_opt :
| (* empty *) { Const @@ no_region }
Expand Down Expand Up @@ -456,9 +458,9 @@ exp :
{ e }
| d=dec_var
{ DecE(d, ref Type.Pre) @? at $sloc }
case :


case :
| CASE p=pat_nullary e=exp
{ {pat = p; exp = e} @@ at $sloc }

Expand Down Expand Up @@ -558,15 +560,22 @@ dec :
| e=exp_nondec
{ ExpD e @? at $sloc }
(* TODO(andreas): move to dec_nonvar once other production is gone *)
| s=obj_sort xf=id_opt EQ? efs=obj_body
{ let anon = if s.it = Type.Actor then "actor" else "object" in
let efs' =
| s=obj_sort id_opt=id? EQ? efs=obj_body
{ let efs' =
if s.it = Type.Object Type.Local
then efs
else List.map share_expfield efs
in
let p = VarP(xf anon $sloc) @! at $sloc in
LetD(p, ObjE(s, xf anon $sloc, efs') @? at $sloc) @? at $sloc }
let r = at $sloc in
(* desugar anonymous objects to ExpD, named ones to LetD. *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing desugaring in the Parser causes confusing type error messages if the type checker wants to pretty print expressions, i.e. code that is different from what the user wrote.
I know it is tedious to have a large source AST that needs to be typechecked, but it is the proper thing to do. Desguaring should happen in, well, desguar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with trivial desugarings like this being done in the parser. Don't think we want to print ASTs in error messages anyway, that's what source locations are for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But even if we don’t print actual AST fragments, there is still a risk to say “in a let-binding at …” where there isn’t a let binding there, but rather an object declaration.

But not a big deal and we have more important things to do, so I will not press this issue.

match id_opt with
| None ->
let sort = if s.it = Type.Actor then "actor" else "object" in
let x = anon sort r @@ r in
ExpD(ObjE(s, x, efs') @? r) @? r
| Some x ->
let p = VarP x @! r in
LetD(p, ObjE(s, x, efs') @? r) @? r }

func_dec :
| tps=typ_params_opt p=pat_nullary rt=return_typ? fb=func_body
Expand All @@ -592,7 +601,7 @@ obj_body :

class_body :
| EQ xf=id_opt efs=obj_body { xf "object" $sloc, efs }
| efs=obj_body { ("anon-object-" ^ string_of_pos (at $sloc).left) @@ at $sloc, efs }
| efs=obj_body { anon "object" (at $sloc) @@ at $sloc, efs }


(* Programs *)
Expand Down
7 changes: 2 additions & 5 deletions src/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,8 @@ and check_dec env t dec =
(* TBR: special-case unit? *)
if not (T.eq env.cons t T.unit || T.sub env.cons t' t) then
local_error env dec.at "expression of type\n %s\ncannot produce expected type\n %s"
(T.string_of_typ_expand env.cons t)
(T.string_of_typ_expand env.cons t')

(T.string_of_typ_expand env.cons t)
(*
and print_ce =
Con.Env.iter (fun c k ->
Expand Down Expand Up @@ -1167,8 +1166,7 @@ and infer_dec_typdecs env dec : con_env =
let tbs = List.map2 (fun c t -> {T.var = Con.name c; bound = T.close cs t}) cs ts in
let k = T.Abs (tbs, T.close cs t) in
id.note <- Some (c, k);
Con.Env.singleton c (T.Abs (tbs, T.close cs t))

Con.Env.singleton c k

(* Pass 4: collect value identifiers *)
and gather_block_valdecs env decs : val_env =
Expand All @@ -1185,7 +1183,6 @@ and gather_dec_valdecs env ve dec : val_env =
error env dec.at "duplicate definition for %s in block" id.it;
T.Env.add id.it T.Pre ve


(* Pass 5: infer value types *)
and infer_block_valdecs env decs : val_env =
let _, ve =
Expand Down
14 changes: 14 additions & 0 deletions test/run/issue129.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// status.as
type Status = {
failed_ : Nat;
passed_ : Nat;
pending_ : Nat;
};

let appendStatus = func (x : Status, y : Status) : Status {
new {
failed_ = x.failed_ + y.failed_;
passed_ = x.passed_ + y.passed_;
pending_ = x.pending_ + y.pending_;
};
};