Skip to content

Commit d13942e

Browse files
committed
Format to canonical form before checking for idempotency test
1 parent e8d70af commit d13942e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ let rewrite_underscore_apply_in_pipe expr =
161161
(fun arg ->
162162
match arg with
163163
| ( lbl,
164-
({pexp_desc = Pexp_ident ({txt = Longident.Lident "__x"} as lid)}
165-
as arg_expr) ) ->
164+
({
165+
pexp_desc = Pexp_ident ({txt = Longident.Lident "__x"} as lid);
166+
} as arg_expr) ) ->
166167
( lbl,
167168
{
168169
arg_expr with

compiler/syntax/src/res_parsetree_viewer.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ val is_single_pipe_expr : Parsetree.expression -> bool
146146
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
147147
val rewrite_underscore_apply : Parsetree.expression -> Parsetree.expression
148148

149-
val rewrite_underscore_apply_in_pipe : Parsetree.expression -> Parsetree.expression
149+
val rewrite_underscore_apply_in_pipe :
150+
Parsetree.expression -> Parsetree.expression
150151

151152
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
152153
val is_underscore_apply_sugar : Parsetree.expression -> bool

scripts/test_syntax.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then
8181
mkdir -p temp/$(dirname $file)
8282
sexpAst1=temp/$file.sexp
8383
sexpAst2=temp/$file.2.sexp
84+
sexpAst3=temp/$file.3.sexp
8485
rescript1=temp/$file.res
8586
rescript2=temp/$file.2.res
8687

@@ -89,14 +90,21 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then
8990
*.resi ) resIntf=-interface ;;
9091
esac
9192

93+
# First pass: original file -> AST1 and text1
9294
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $file > $sexpAst1
9395
$DUNE_BIN_DIR/res_parser $resIntf -print res $file > $rescript1
9496

97+
# Second pass: text1 -> AST2 and text2
9598
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $rescript1 > $sexpAst2
9699
$DUNE_BIN_DIR/res_parser $resIntf -print res $rescript1 > $rescript2
97100

98-
diff --unified $sexpAst1 $sexpAst2
101+
# Third pass: text2 -> AST3 (to check idempotency after normalization)
102+
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $rescript2 > $sexpAst3
103+
104+
# Check AST idempotency: AST2 should equal AST3 (allows AST1 != AST2 for canonicalization)
105+
diff --unified $sexpAst2 $sexpAst3
99106
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
107+
# Check text idempotency: text1 should equal text2
100108
diff --unified $rescript1 $rescript2
101109
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
102110
} & maybeWait

0 commit comments

Comments
 (0)