Skip to content

Commit

Permalink
Revert "basically revert #4611"
Browse files Browse the repository at this point in the history
This reverts commit 13d9d57.
  • Loading branch information
ggreif committed Jul 27, 2024
1 parent 83d4c27 commit 026172c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/ir_def/check_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ and type_exp_field env s f : T.field =
with Not_found -> error env f.at "field typing for %s not found" name
in
assert (t <> T.Pre);
let t = T.(match f.note with Mut _ -> t | _ -> as_immut t) in
check_sub env f.at t f.note;
if not (T.is_typ t) then begin
check env f.at ((s = T.Actor) ==> T.is_shared_func t)
Expand Down
11 changes: 7 additions & 4 deletions src/ir_def/construct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,7 @@ let unreachableE () =
loopE (unitE ())

let objE sort typ_flds flds =
let rec go ds fields fld_tys flds =
match flds with
let rec go ds fields fld_tys = function
| [] ->
blockE
(List.rev ds)
Expand All @@ -765,13 +764,17 @@ let objE sort typ_flds flds =
((List.map (fun (id,c) -> (id, T.Typ c)) typ_flds)
@ fld_tys)))
| (lab, exp)::flds ->
let v = fresh_var lab (typ exp) in
let v, addv = match exp.it with
| VarE v -> var v (typ exp), fun _ ds -> ds
| _ ->
let v = fresh_var lab (typ exp) in
v, fun exp ds -> letD v exp :: ds in
let field = {
it = {name = lab; var = id_of_var v};
at = no_region;
note = typ exp
} in
go ((letD v exp)::ds) (field::fields) ((lab, typ exp)::fld_tys) flds
go (addv exp ds) (field::fields) ((lab, typ exp)::fld_tys) flds
in
go [] [] [] flds

Expand Down
6 changes: 5 additions & 1 deletion src/ir_interpreter/interpret_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,11 @@ and interpret_fields env fs =
let ve =
List.fold_left
(fun ve (f : field) ->
V.Env.disjoint_add f.it.name (Lib.Promise.value (find f.it.var env.vals)) ve
let v = match f.note, Lib.Promise.value (find f.it.var env.vals) with
| T.Mut _, v -> v
| _, V.Mut v -> !v (* immutable field, read mutable box *)
| _, v -> v in
V.Env.disjoint_add f.it.name v ve
) V.Env.empty fs in
V.Obj ve

Expand Down
13 changes: 8 additions & 5 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -600,17 +600,19 @@ and exp_field obj_typ ef =
let id' = fresh_var id.it typ in
let d = varD id' (exp e) in
let f = { it = I.{ name = id.it; var = id_of_var id' }; at = no_region; note = typ } in
(d, f)
(Some d, f)
| S.Const ->
let typ = match T.lookup_val_field_opt id.it fts with
| Some typ -> typ
| None -> e.note.S.note_typ
in
assert (not (T.is_mut typ));
let id' = fresh_var id.it typ in
let d = letD id' (exp e) in
let e = exp e in
let id', d_opt = match e.it with
| I.VarE v -> var v typ, None
| _ -> let id' = fresh_var id.it typ in id', Some (letD id' e) in
let f = { it = I.{ name = id.it; var = id_of_var id' }; at = no_region; note = typ } in
(d, f)
(d_opt, f)

and obj obj_typ efs bases =
let open List in
Expand Down Expand Up @@ -642,7 +644,8 @@ and obj obj_typ efs bases =
let ds, fs = map (exp_field obj_typ) efs |> split in
let ds', fs' = concat_map gap (T.as_obj obj_typ |> snd) |> split in
let obj_e = newObjE T.Object (append fs fs') obj_typ in
I.BlockE(append base_decs (append ds ds'), obj_e)
let decs = append base_decs (append (filter_map (fun o -> o) ds) ds') in
(blockE decs obj_e).it

and typ_binds tbs = List.map typ_bind tbs

Expand Down

0 comments on commit 026172c

Please sign in to comment.