Skip to content

Commit

Permalink
5.3 effect syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
hhugo authored and NathanReb committed Jan 13, 2025
1 parent f06c16e commit 0a1fbc5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions astlib/migrate_502_503.ml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ and copy_pattern_desc :
(copy_loc (fun x -> Option.map (fun x -> x) x) x0)
| Ast_502.Parsetree.Ppat_exception x0 ->
Ast_503.Parsetree.Ppat_exception (copy_pattern x0)
| Ast_502.Parsetree.Ppat_extension (
{txt = "ppxlib.effect_syntax"; _},
PPat ({ ppat_desc = Ppat_tuple [e; c ]; _}, None)) ->
Ast_503.Parsetree.Ppat_effect (copy_pattern e, copy_pattern c)
| Ast_502.Parsetree.Ppat_extension x0 ->
Ast_503.Parsetree.Ppat_extension (copy_extension x0)
| Ast_502.Parsetree.Ppat_open (x0, x1) ->
Expand Down
14 changes: 9 additions & 5 deletions astlib/migrate_503_502.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ open Stdlib0
module From = Ast_503
module To = Ast_502

let migration_error loc missing_feature =
Location.raise_errorf ~loc
"migration error: %s is not supported before OCaml 5.03" missing_feature

let rec copy_toplevel_phrase :
Ast_503.Parsetree.toplevel_phrase -> Ast_502.Parsetree.toplevel_phrase =
function
Expand Down Expand Up @@ -330,7 +326,15 @@ and copy_pattern_desc loc :
(copy_loc (fun x -> Option.map (fun x -> x) x) x0)
| Ast_503.Parsetree.Ppat_exception x0 ->
Ast_502.Parsetree.Ppat_exception (copy_pattern x0)
| Ast_503.Parsetree.Ppat_effect _ -> migration_error loc "effect pattern"
| Ast_503.Parsetree.Ppat_effect (e,c) ->
Ast_502.Parsetree.Ppat_extension (
Location.{txt = "ppxlib.effect_syntax"; loc = Location.none},
Ast_502.Parsetree.PPat (
{ppat_desc = Ppat_tuple [copy_pattern e; copy_pattern c];
ppat_attributes = [];
ppat_loc_stack = [];
ppat_loc = Location.none},
None))
| Ast_503.Parsetree.Ppat_extension x0 ->
Ast_502.Parsetree.Ppat_extension (copy_extension x0)
| Ast_503.Parsetree.Ppat_open (x0, x1) ->
Expand Down
9 changes: 4 additions & 5 deletions test/503_migrations/preserve-effect-downward/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ If we run the driver on the following source file:
it should successfully roundtrip to 5.2 and print the source code unchanged:
$ ./driver.exe test.ml -o test.pp.ml
File "test.ml", line 4, characters 2-23:
4 | | effect Random_bits, k -> Effect.Deep.continue k (Random.bits ())
^^^^^^^^^^^^^^^^^^^^^
Error: migration error: effect pattern is not supported before OCaml 5.03
[1]
let handler f =
match f () with
| x -> x
| effect Random_bits, k -> Effect.Deep.continue k (Random.bits ())

0 comments on commit 0a1fbc5

Please sign in to comment.