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

Fix roundtrip check to support 5.1 <-> 5.2 migrations #519

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ details.

### Other changes

- Fix `deriving_inline` round-trip check so that it works with 5.01 <-> 5.02
migrations (#519, @NathanReb)

0.33.0 (2024-07-22)
-------------------

Expand Down
6 changes: 6 additions & 0 deletions astlib/astlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ module Location = Location
module Longident = Longident
module Parse = Parse
module Pprintast = Pprintast
module Compiler_pprintast = struct
include Ocaml_common.Pprintast

let structure_item fmt t = structure fmt [t]
let signature_item fmt t = signature fmt [t]
end

let init_error_reporting_style_using_env_vars () =
(*IF_AT_LEAST 408 Ocaml_common.Compmisc.read_clflags_from_env () *)
Expand Down
16 changes: 12 additions & 4 deletions src/code_matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ end

module Make (M : sig
type t
type compiler_t

val get_loc : t -> Location.t
val end_marker : (t, unit) Attribute.Floating.t
Expand All @@ -33,8 +34,9 @@ module Make (M : sig
end

val parse : Lexing.lexbuf -> t list
val pp : Format.formatter -> t -> unit
val to_sexp : t -> Sexp.t
val to_compiler : t -> compiler_t
val pp_compiler : Format.formatter -> compiler_t -> unit
end) =
struct
let extract_prefix ~pos l =
Expand Down Expand Up @@ -131,7 +133,9 @@ struct
let y = remove_loc y in
if Poly.( <> ) x y then (
let round_trip =
remove_loc (parse_string (Format.asprintf "%a@." M.pp x))
let compiler_x = M.to_compiler x in
NathanReb marked this conversation as resolved.
Show resolved Hide resolved
remove_loc
(parse_string (Format.asprintf "%a@." M.pp_compiler compiler_x))
in
if Poly.( <> ) x round_trip then
Location.raise_errorf ~loc
Expand All @@ -151,6 +155,7 @@ end
(*$*)
module Str = Make (struct
type t = structure_item
type compiler_t = Ppxlib_ast.Compiler_version.Ast.Parsetree.structure_item

let get_loc x = x.pstr_loc
let end_marker = end_marker_str
Expand All @@ -160,13 +165,15 @@ module Str = Make (struct
end

let parse = Parse.implementation
let pp = Pprintast.structure_item
let to_sexp = Ast_traverse.sexp_of#structure_item
let to_compiler = Ppxlib_ast.Selected_ast.To_ocaml.copy_structure_item
let pp_compiler = Astlib.Compiler_pprintast.structure_item
end)

(*$ str_to_sig _last_text_block *)
module Sig = Make (struct
type t = signature_item
type compiler_t = Ppxlib_ast.Compiler_version.Ast.Parsetree.signature_item

let get_loc x = x.psig_loc
let end_marker = end_marker_sig
Expand All @@ -176,8 +183,9 @@ module Sig = Make (struct
end

let parse = Parse.interface
let pp = Pprintast.signature_item
let to_sexp = Ast_traverse.sexp_of#signature_item
let to_compiler = Ppxlib_ast.Selected_ast.To_ocaml.copy_signature_item
let pp_compiler = Astlib.Compiler_pprintast.signature_item
end)

(*$*)
Expand Down
Loading