Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwriting typing #3157

Merged
merged 36 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cfe0418
First draft of type checking
anfelor Oct 11, 2024
d0faa26
Check in uniqueness analysis that tags stay the same during overwriting
anfelor Oct 14, 2024
876e636
Report a syntax error on overwriting anything except an allocation
anfelor Oct 14, 2024
f93e692
Merge branch 'overwriting' into overwriting-typing
anfelor Oct 16, 2024
b48eb61
Full type-checking for tuples and records
anfelor Oct 16, 2024
70ead74
Type checking fully implemented
anfelor Oct 17, 2024
345fee9
Clean up type-checking and add ability to overwrite arbitrary express…
anfelor Oct 17, 2024
945fb76
Fix checking of tags
anfelor Oct 17, 2024
c0785a4
Test (labeled) tuples
anfelor Oct 18, 2024
0de2a80
Final tests and allow overwrite of inlined records
anfelor Oct 18, 2024
fbf6e1b
Review suggestion
anfelor Oct 21, 2024
432eade
Review suggestion
anfelor Oct 21, 2024
f984a60
Review feedback: add more tests
anfelor Oct 21, 2024
b261b06
Uniqueness analysis: Change grammar of error message to indicate para…
anfelor Oct 21, 2024
ac401e7
Merge remote-tracking branch 'origin/overwriting-typing' into overwri…
anfelor Oct 21, 2024
2d2ae0b
Review feedback: Fix typo
anfelor Oct 21, 2024
7bf5cf0
Review feedback: add comments and tests
anfelor Oct 21, 2024
3518596
Merge remote-tracking branch 'origin/overwriting-typing' into overwri…
anfelor Oct 21, 2024
a2ca9af
Prevent nested allocations in overwrite
anfelor Oct 21, 2024
399581b
Review feedback: Fix comment and improve readability
anfelor Oct 21, 2024
16d6739
Review feedback: add comments, tests and nicer error messages
anfelor Oct 23, 2024
d385037
Fix nested record bug
anfelor Oct 23, 2024
2d8afdb
Improve code quality
anfelor Oct 23, 2024
288800a
Disallow overwriting of unboxed records
anfelor Oct 23, 2024
eaa0c9f
Review feedback
anfelor Oct 24, 2024
33b3634
Clarify the overwriting state for type_label_exp
goldfirere Oct 25, 2024
fd050dc
Add debugging printers for uniqueness
goldfirere Oct 25, 2024
c29a7bb
Temporarily allow unique mutable fields for better tests of overwriti…
anfelor Oct 30, 2024
3e5023e
New scheme for checking that overwrite does not change tags
anfelor Nov 4, 2024
1f23b9b
Refactor: split up Learned_tags and Overwrites and use match_with_lea…
anfelor Nov 7, 2024
f91955d
Add comment about fold_left1 and zero of semiring
anfelor Nov 7, 2024
db26890
Fix submode error attribution in records
anfelor Nov 8, 2024
cf2a211
Tune errors in tag checker
anfelor Nov 8, 2024
3ca5e8a
Don't record tags that have been overwritten and matched with a learn…
anfelor Nov 8, 2024
7447b62
Review feedback: comments and small improvements
anfelor Nov 26, 2024
5450be3
Review feedback: tune comments
anfelor Nov 27, 2024
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
2 changes: 1 addition & 1 deletion ocaml/file_formats/cmt_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ let iter_on_occurrences
| Texp_object _ | Texp_pack _ | Texp_letop _ | Texp_unreachable
| Texp_list_comprehension _ | Texp_array_comprehension _ | Texp_probe _
| Texp_probe_is_enabled _ | Texp_exclave _
| Texp_open _ | Texp_src_pos -> ());
| Texp_open _ | Texp_src_pos | Texp_overwrite _ | Texp_hole _ -> ());
default_iterator.expr sub e);

(* Remark: some types get iterated over twice due to how constraints are
Expand Down
4 changes: 4 additions & 0 deletions ocaml/lambda/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
]
in
Lconst(Const_block(0, cl))
| Texp_overwrite (_, _) ->
Location.todo_overwrite_not_implemented ~kind:"Translcore" e.exp_loc
| Texp_hole _ ->
Location.todo_overwrite_not_implemented ~kind:"Translcore" e.exp_loc

and pure_module m =
match m.mod_desc with
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ module Exp = struct
let extension ?loc ?attrs a = mk ?loc ?attrs (Pexp_extension a)
let unreachable ?loc ?attrs () = mk ?loc ?attrs Pexp_unreachable
let stack ?loc ?attrs e = mk ?loc ?attrs (Pexp_stack e)
let overwrite ?loc ?attrs x e = mk ?loc ?attrs (Pexp_overwrite (x, e))
let overwrite ?loc ?attrs a b = mk ?loc ?attrs (Pexp_overwrite (a, b))
let hole ?loc ?attrs () = mk ?loc ?attrs Pexp_hole

let case lhs ?guard rhs =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ module Exp:
val extension: ?loc:loc -> ?attrs:attrs -> extension -> expression
val unreachable: ?loc:loc -> ?attrs:attrs -> unit -> expression
val stack : ?loc:loc -> ?attrs:attrs -> expression -> expression
val overwrite : ?loc:loc -> ?attrs:attrs -> lid -> expression -> expression
val overwrite : ?loc:loc -> ?attrs:attrs -> expression -> expression -> expression
val hole : ?loc:loc -> ?attrs:attrs -> unit -> expression

val case: pattern -> ?guard:expression -> expression -> case
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ module E = struct
| Pexp_extension x -> sub.extension sub x
| Pexp_unreachable -> ()
| Pexp_stack e -> sub.expr sub e
| Pexp_overwrite (x, e) -> iter_loc sub x; sub.expr sub e
| Pexp_overwrite (e1, e2) -> sub.expr sub e1; sub.expr sub e2
| Pexp_hole -> ()

let iter_binding_op sub {pbop_op; pbop_pat; pbop_exp; pbop_loc} =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ module E = struct
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pexp_unreachable -> unreachable ~loc ~attrs ()
| Pexp_stack e -> stack ~loc ~attrs (sub.expr sub e)
| Pexp_overwrite (x, e) -> overwrite ~loc ~attrs (map_loc sub x) (sub.expr sub e)
| Pexp_overwrite (e1, e2) -> overwrite ~loc ~attrs (sub.expr sub e1) (sub.expr sub e2)
| Pexp_hole -> hole ~loc ~attrs ()

let map_binding_op sub {pbop_op; pbop_pat; pbop_exp; pbop_loc} =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ let rec add_expr bv exp =
end
| Pexp_extension e -> handle_extension e
| Pexp_stack e -> add_expr bv e
| Pexp_overwrite (x, e) -> add bv x; add_expr bv e
| Pexp_overwrite (e1, e2) -> add_expr bv e1; add_expr bv e2
| Pexp_hole -> ()
| Pexp_unreachable -> ()

Expand Down
4 changes: 2 additions & 2 deletions ocaml/parsing/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,6 @@ let () =
let raise_errorf ?(loc = none) ?(sub = []) =
Format.kdprintf (fun txt -> raise (Error (mkerror loc sub txt)))

let todo_overwrite_not_implemented t =
alert ~kind:"" t "Overwrite not implemented.";
let todo_overwrite_not_implemented ?(kind = "") t =
alert ~kind t "Overwrite not implemented.";
assert false
2 changes: 1 addition & 1 deletion ocaml/parsing/location.mli
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,4 @@ val report_exception: formatter -> exn -> unit
(** Reraise the exception if it is unknown. *)

(** CR uniqueness: remove this *)
val todo_overwrite_not_implemented : t -> 'a
val todo_overwrite_not_implemented : ?kind:string -> t -> 'a
2 changes: 1 addition & 1 deletion ocaml/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ fun_expr:
{ Pexp_try($3, $5), $2 }
| TRY ext_attributes seq_expr WITH error
{ syntax_error() }
| OVERWRITE ext_attributes mkrhs(val_longident) WITH expr
| OVERWRITE ext_attributes seq_expr WITH expr
{ Pexp_overwrite($3, $5), $2 }
| IF ext_attributes seq_expr THEN expr ELSE expr
{ Pexp_ifthenelse($3, $5, Some $7), $2 }
Expand Down
3 changes: 1 addition & 2 deletions ocaml/parsing/parsetree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ and expression_desc =
| Pexp_extension of extension (** [[%id]] *)
| Pexp_unreachable (** [.] *)
| Pexp_stack of expression (** stack_ exp *)
(* CR uniqueness: allow arbitrary expressions instead of identifiers here *)
| Pexp_overwrite of Longident.t loc * expression (** overwrite_ x with exp *)
| Pexp_overwrite of expression * expression (** overwrite_ exp with exp *)
| Pexp_hole (** _ *)

and case =
Expand Down
6 changes: 3 additions & 3 deletions ocaml/parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1117,11 +1117,11 @@ and expression ?(jane_syntax_parens = false) ctxt f x =
(expression ctxt) body
| Pexp_extension e -> extension ctxt f e
| Pexp_unreachable -> pp f "."
| Pexp_overwrite (x, e) ->
| Pexp_overwrite (e1, e2) ->
(* Similar to the case of [Pexp_stack] *)
pp f "@[<hov2>overwrite_@ %a@ with@ %a@]"
longident_loc x
(expression2 reset_ctxt) e
(expression2 reset_ctxt) e1
(expression2 reset_ctxt) e2
| Pexp_hole -> pp f "_"
| _ -> expression1 ctxt f x

Expand Down
7 changes: 4 additions & 3 deletions ocaml/parsing/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,10 @@ and expression i ppf x =
| Pexp_stack e ->
line i ppf "Pexp_stack\n";
expression i ppf e
| Pexp_overwrite (x, e) ->
line i ppf "Pexp_overwrite %a\n" fmt_longident_loc x;
expression i ppf e
| Pexp_overwrite (e1, e2) ->
line i ppf "Pexp_overwrite\n";
expression i ppf e1;
expression i ppf e2;
| Pexp_hole ->
line i ppf "Pexp_hole"

Expand Down
7 changes: 6 additions & 1 deletion ocaml/testsuite/tests/parsetree/source_jane_street.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,11 @@ let overwrite_record = function
let overwrite_record = function
{ a; b } as t -> overwrite_ t with { b = a }

let ret_record () = { a = 1; b = 2 }

let overwrite_record () =
overwrite_ (ret_record ()) with { b = a }

type constructor = C of { a : int; b : int }

let overwrite_constructor = function
Expand All @@ -1059,7 +1064,7 @@ let overwrite_constructor = function
Line 2, characters 19-43:
2 | (a, b) as t -> overwrite_ t with (b, _)
^^^^^^^^^^^^^^^^^^^^^^^^
Alert : Overwrite not implemented.
Alert Translcore: Overwrite not implemented.
Uncaught exception: File "ocaml/parsing/location.ml", line 1106, characters 2-8: Assertion failed

|}]
Loading
Loading