Skip to content

Commit

Permalink
rename option
Browse files Browse the repository at this point in the history
Signed-off-by: alanechang <alanechang@janestreet.com>
  • Loading branch information
alanechang committed Nov 7, 2023
1 parent 98b4ec6 commit df7ba4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
34 changes: 17 additions & 17 deletions lib/Normalize_std_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let sort_attributes : attributes -> attributes =
List.sort ~compare:Poly.compare

let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
~local_rewrite_occurred =
~ignore_local_annot_differences =
let open Ast_helper in
(* remove locations *)
let location _ _ = Location.none in
Expand Down Expand Up @@ -124,7 +124,7 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
else atrs
in
let atrs =
if local_rewrite_occurred then
if ignore_local_annot_differences then
List.filter atrs ~f:(fun a -> not (is_local_jane_syntax a))
else atrs
in
Expand Down Expand Up @@ -155,7 +155,7 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
| Pexp_apply
( {pexp_desc= Pexp_extension ({txt= extension_name; _}, PStr []); _}
, [(Nolabel, sbody)] )
when (local_rewrite_occurred || erase_jane_syntax)
when (ignore_local_annot_differences || erase_jane_syntax)
&& ( Conf.is_jane_street_local_annotation conf "local"
~test:extension_name
|| Conf.is_jane_street_local_annotation conf "exclave"
Expand All @@ -166,7 +166,7 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
let pat (m : Ast_mapper.mapper) pat =
let pat = {pat with ppat_loc_stack= []} in
let pat =
if local_rewrite_occurred || erase_jane_syntax then
if ignore_local_annot_differences || erase_jane_syntax then
{ pat with
ppat_attributes=
erase_legacy_jane_street_local_annotations conf
Expand Down Expand Up @@ -196,7 +196,7 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
let typ (m : Ast_mapper.mapper) typ =
let typ = {typ with ptyp_loc_stack= []} in
let typ =
if local_rewrite_occurred || erase_jane_syntax then
if ignore_local_annot_differences || erase_jane_syntax then
{ typ with
ptyp_attributes=
erase_legacy_jane_street_local_annotations conf
Expand Down Expand Up @@ -243,7 +243,7 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
in
let label_declaration (m : Ast_mapper.mapper) ld =
let ld =
if local_rewrite_occurred || erase_jane_syntax then
if ignore_local_annot_differences || erase_jane_syntax then
{ ld with
pld_attributes=
erase_legacy_jane_street_local_annotations conf ld.pld_attributes
Expand All @@ -266,17 +266,17 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax
; label_declaration }

let ast fragment ~ignore_doc_comments ~erase_jane_syntax
~local_rewrite_occurred c =
~ignore_local_annot_differences c =
map fragment
(make_mapper c ~ignore_doc_comments ~erase_jane_syntax
~local_rewrite_occurred )
~ignore_local_annot_differences )

let equal fragment ~ignore_doc_comments ~erase_jane_syntax
~local_rewrite_occurred c ~old:ast1 ~new_:ast2 =
~ignore_local_annot_differences c ~old:ast1 ~new_:ast2 =
let map = ast fragment c ~ignore_doc_comments in
equal fragment
(map ~erase_jane_syntax ~local_rewrite_occurred ast1)
(map ~erase_jane_syntax:false ~local_rewrite_occurred ast2)
(map ~erase_jane_syntax ~ignore_local_annot_differences ast1)
(map ~erase_jane_syntax:false ~ignore_local_annot_differences ast2)

let ast = ast ~ignore_doc_comments:false

Expand Down Expand Up @@ -307,22 +307,22 @@ let docstrings (type a) (fragment : a t) s =
let (_ : a) = map fragment (make_docstring_mapper docstrings) s in
!docstrings

let docstring conf ~erase_jane_syntax ~local_rewrite_occurred =
let docstring conf ~erase_jane_syntax ~ignore_local_annot_differences =
let mapper =
make_mapper conf ~ignore_doc_comments:false ~erase_jane_syntax
~local_rewrite_occurred
~ignore_local_annot_differences
in
let normalize_code = normalize_code conf mapper in
docstring conf ~normalize_code

let moved_docstrings fragment ~erase_jane_syntax ~local_rewrite_occurred c
~old:s1 ~new_:s2 =
let moved_docstrings fragment ~erase_jane_syntax
~ignore_local_annot_differences c ~old:s1 ~new_:s2 =
let d1 = docstrings fragment s1 in
let d2 = docstrings fragment s2 in
let equal ~old:(_, x) ~new_:(_, y) =
String.equal
(docstring c x ~erase_jane_syntax ~local_rewrite_occurred)
(docstring c y ~erase_jane_syntax ~local_rewrite_occurred:false)
(docstring c x ~erase_jane_syntax ~ignore_local_annot_differences)
(docstring c y ~erase_jane_syntax ~ignore_local_annot_differences:false)
in
let cmt_kind = `Doc_comment in
let cmt (loc, x) = Cmt.create_docstring x loc in
Expand Down
6 changes: 3 additions & 3 deletions lib/Normalize_std_ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
val ast :
'a Std_ast.t
-> erase_jane_syntax:bool
-> local_rewrite_occurred:bool
-> ignore_local_annot_differences:bool
-> Conf.t
-> 'a
-> 'a
Expand All @@ -23,7 +23,7 @@ val equal :
'a Std_ast.t
-> ignore_doc_comments:bool
-> erase_jane_syntax:bool
-> local_rewrite_occurred:bool
-> ignore_local_annot_differences:bool
-> Conf.t
-> old:'a
-> new_:'a
Expand All @@ -36,7 +36,7 @@ val equal :
val moved_docstrings :
'a Std_ast.t
-> erase_jane_syntax:bool
-> local_rewrite_occurred:bool
-> ignore_local_annot_differences:bool
-> Conf.t
-> old:'a
-> new_:'a
Expand Down
18 changes: 9 additions & 9 deletions lib/Translation_unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,18 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
in
(* Ast not preserved ? *)
let erase_jane_syntax = Erase_jane_syntax.should_erase () in
let local_rewrite_occurred =
let ignore_local_annot_differences =
Erase_jane_syntax.local_rewrite_occurred ()
in
if i = 1 && local_rewrite_occurred then
if i = 1 && ignore_local_annot_differences then
Format.eprintf
"Warning: Legacy local annotation rewrite occurred. AST \
normalization will ignore local syntax differences.\n" ;
( if
(not
(Normalize_std_ast.equal std_fg conf ~old:std_t.ast
~new_:std_t_new.ast ~erase_jane_syntax
~local_rewrite_occurred
~ignore_local_annot_differences
~ignore_doc_comments:(not conf.opr_opts.comment_check.v) ) )
&& not
(Normalize_extended_ast.equal fg conf t.ast t_new.ast
Expand All @@ -344,12 +344,12 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
let old_ast =
dump_ast std_fg ~suffix:".old"
(Normalize_std_ast.ast std_fg ~erase_jane_syntax
~local_rewrite_occurred conf std_t.ast )
~ignore_local_annot_differences conf std_t.ast )
in
let new_ast =
dump_ast std_fg ~suffix:".new"
(Normalize_std_ast.ast std_fg ~erase_jane_syntax:false
~local_rewrite_occurred conf std_t_new.ast )
~ignore_local_annot_differences conf std_t_new.ast )
in
let args ~suffix =
[ ("output file", dump_formatted ~suffix fmted)
Expand All @@ -360,12 +360,12 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
in
if
Normalize_std_ast.equal std_fg ~ignore_doc_comments:true
~erase_jane_syntax ~local_rewrite_occurred conf ~old:std_t.ast
~new_:std_t_new.ast
~erase_jane_syntax ~ignore_local_annot_differences conf
~old:std_t.ast ~new_:std_t_new.ast
then
let docstrings =
Normalize_std_ast.moved_docstrings std_fg ~erase_jane_syntax
~local_rewrite_occurred conf ~old:std_t.ast
~ignore_local_annot_differences conf ~old:std_t.ast
~new_:std_t_new.ast
in
let args = args ~suffix:".unequal-docs" in
Expand All @@ -378,7 +378,7 @@ let format (type a b) (fg : a Extended_ast.t) (std_fg : b Std_ast.t)
else
dump_ast std_fg ~suffix:""
(Normalize_std_ast.ast std_fg ~erase_jane_syntax
~local_rewrite_occurred conf std_t_new.ast )
~ignore_local_annot_differences conf std_t_new.ast )
|> function
| Some file ->
if i = 1 then Format.eprintf "[DEBUG] AST structure: %s\n" file
Expand Down

0 comments on commit df7ba4d

Please sign in to comment.