Skip to content

Commit a375a47

Browse files
authoredJun 6, 2025··
Fix syntax benchmarks (#7539)
1 parent 38414ac commit a375a47

File tree

7 files changed

+675
-715
lines changed

7 files changed

+675
-715
lines changed
 

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ jobs:
364364

365365
- name: Run syntax benchmarks
366366
if: matrix.benchmarks
367-
run: ./_build/install/default/bin/syntax_benchmarks | tee tests/benchmark-output.json
367+
run: |
368+
set -o pipefail
369+
./_build/install/default/bin/syntax_benchmarks | tee tests/benchmark-output.json
368370
369371
# Benchmarking is disabled for now because of inconsistent run times on different runners
370372
#

‎scripts/format.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ shopt -s extglob
44

55
dune build @fmt --auto-promote
66

7-
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
7+
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
88
./cli/rescript.js format $files
99

1010
yarn format

‎scripts/format_check.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ case "$(uname -s)" in
1717
fi
1818

1919
echo "Checking ReScript code formatting..."
20-
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
20+
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
2121
if ./cli/rescript.js format -check $files; then
2222
printf "${successGreen}✅ ReScript code formatting ok.${reset}\n"
2323
else

‎tests/syntax_benchmarks/Benchmark.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ end = struct
160160
let parse_rescript src filename =
161161
let p = Parser.make src filename in
162162
let structure = ResParser.parse_implementation p in
163-
assert (p.diagnostics == []);
163+
if p.diagnostics != [] then (
164+
Res_diagnostics.print_report p.diagnostics src;
165+
assert false);
164166
structure
165167

166168
let data_dir = "tests/syntax_benchmarks/data"

‎tests/syntax_benchmarks/data/Napkinscript.res‎

Lines changed: 435 additions & 422 deletions
Large diffs are not rendered by default.

‎tests/syntax_benchmarks/data/RedBlackTree.res‎

Lines changed: 193 additions & 218 deletions
Large diffs are not rendered by default.

‎tests/syntax_benchmarks/data/RedBlackTreeNoComments.res‎

Lines changed: 39 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ type rec node<'value> = {
1515
type t<'value> = {
1616
mutable size: int,
1717
mutable root: option<node<'value>>,
18-
compare: (. 'value, 'value) => int,
18+
compare: ('value, 'value) => int,
1919
}
2020

2121
let createNode = (~color, ~value, ~height) => {
2222
left: None,
2323
right: None,
2424
parent: None,
2525
sum: 0.,
26-
height: height,
27-
value: value,
28-
color: color,
26+
height,
27+
value,
28+
color,
2929
}
3030

3131
external castNotOption: option<'a> => 'a = "%identity"
@@ -62,10 +62,7 @@ let isLeft = node =>
6262
| Some(parent) => Some(node) === parent.left
6363
}
6464

65-
let leftOrRightSet = (~node, x, value) =>
66-
isLeft(node)
67-
? x.left = value
68-
: x.right = value
65+
let leftOrRightSet = (~node, x, value) => isLeft(node) ? x.left = value : x.right = value
6966

7067
let siblingOf = node =>
7168
if isLeft(node) {
@@ -89,7 +86,7 @@ let rec findNode = (rbt, node, value) =>
8986
switch node {
9087
| None => None
9188
| Some(node) =>
92-
let cmp = rbt.compare(. value, node.value)
89+
let cmp = rbt.compare(value, node.value)
9390
if cmp === 0 {
9491
Some(node)
9592
} else if cmp < 0 {
@@ -159,7 +156,7 @@ let rec findInsert = (rbt, node, nodeToInsert, value) =>
159156
switch node {
160157
| None => None
161158
| Some(node) =>
162-
let cmp = rbt.compare(. value, node.value)
159+
let cmp = rbt.compare(value, node.value)
163160
if cmp === 0 {
164161
Some(node)
165162
} else if cmp < 0 {
@@ -193,14 +190,10 @@ let rec _addLoop = (rbt, currentNode) =>
193190
(grandParentOf(currentNode)->castNotOption).color = Red
194191
_addLoop(rbt, grandParentOf(currentNode)->castNotOption)
195192
} else {
196-
let currentNode = if (
197-
!isLeft(currentNode) && isLeft(currentNode.parent->castNotOption)
198-
) {
193+
let currentNode = if !isLeft(currentNode) && isLeft(currentNode.parent->castNotOption) {
199194
rotateLeft(rbt, currentNode.parent->castNotOption)
200195
currentNode.left->castNotOption
201-
} else if (
202-
isLeft(currentNode) && !isLeft(currentNode.parent->castNotOption)
203-
) {
196+
} else if isLeft(currentNode) && !isLeft(currentNode.parent->castNotOption) {
204197
rotateRight(rbt, currentNode.parent->castNotOption)
205198
currentNode.right->castNotOption
206199
} else {
@@ -253,9 +246,9 @@ let removeNode = (rbt, node) => {
253246
let (successor, isLeaf) = switch successor {
254247
| None =>
255248
let leaf = createNode(~value=%raw("0"), ~color=Black, ~height=0.)
256-
let isLeaf = (. x) => x === leaf
249+
let isLeaf = x => x === leaf
257250
(leaf, isLeaf)
258-
| Some(successor) => (successor, (. _) => false)
251+
| Some(successor) => (successor, _ => false)
259252
}
260253
let nodeParent = nodeToRemove.parent
261254
successor.parent = nodeParent
@@ -300,10 +293,8 @@ let removeNode = (rbt, node) => {
300293
successorParent.color === Black &&
301294
(sibling === None ||
302295
(siblingNN.color === Black &&
303-
(siblingNN.left === None ||
304-
(siblingNN.left->castNotOption).color === Black) &&
305-
(siblingNN.right === None ||
306-
(siblingNN.right->castNotOption).color === Black)))
296+
(siblingNN.left === None || (siblingNN.left->castNotOption).color === Black) &&
297+
(siblingNN.right === None || (siblingNN.right->castNotOption).color === Black)))
307298
) {
308299
if sibling !== None {
309300
siblingNN.color = Red
@@ -313,24 +304,19 @@ let removeNode = (rbt, node) => {
313304
successorParent.color === Red &&
314305
(sibling === None ||
315306
(siblingNN.color === Black &&
316-
(siblingNN.left === None ||
317-
(siblingNN.left->castNotOption).color === Black) &&
318-
(siblingNN.right === None ||
319-
(siblingNN.right->castNotOption).color === Black)))
307+
(siblingNN.left === None || (siblingNN.left->castNotOption).color === Black) &&
308+
(siblingNN.right === None || (siblingNN.right->castNotOption).color === Black)))
320309
) {
321310
if sibling !== None {
322311
siblingNN.color = Red
323312
}
324313
successorParent.color = Black
325314
break.contents = true
326-
} else if (
327-
sibling !== None && (sibling->castNotOption).color === Black
328-
) {
315+
} else if sibling !== None && (sibling->castNotOption).color === Black {
329316
let sibling = sibling->castNotOption
330317
if (
331318
isLeft(successor) &&
332-
(sibling.right === None ||
333-
(sibling.right->castNotOption).color === Black) &&
319+
(sibling.right === None || (sibling.right->castNotOption).color === Black) &&
334320
sibling.left !== None &&
335321
(sibling.left->castNotOption).color === Red
336322
) {
@@ -339,8 +325,7 @@ let removeNode = (rbt, node) => {
339325
rotateRight(rbt, sibling)
340326
} else if (
341327
!isLeft(successor) &&
342-
(sibling.left === None ||
343-
(sibling.left->castNotOption).color === Black) &&
328+
(sibling.left === None || (sibling.left->castNotOption).color === Black) &&
344329
sibling.right !== None &&
345330
(sibling.right->castNotOption).color === Red
346331
) {
@@ -366,7 +351,7 @@ let removeNode = (rbt, node) => {
366351
}
367352
}
368353

369-
if isLeaf(. successor) {
354+
if isLeaf(successor) {
370355
if rbt.root === Some(successor) {
371356
rbt.root = None
372357
}
@@ -390,7 +375,7 @@ let rec findNodeThroughCallback = (rbt, node, cb) =>
390375
switch node {
391376
| None => None
392377
| Some(node) =>
393-
let cmp = cb(. node)
378+
let cmp = cb(node)
394379
if cmp === 0 {
395380
Some(node)
396381
} else if cmp < 0 {
@@ -409,13 +394,11 @@ let removeThroughCallback = (rbt, cb) =>
409394
| None => false
410395
}
411396

412-
let make = (~compare) => {size: 0, root: None, compare: compare}
397+
let make = (~compare) => {size: 0, root: None, compare}
413398

414399
let makeWith = (array, ~compare) => {
415400
let rbt = make(~compare)
416-
array->Js.Array2.forEach(((value, height)) =>
417-
add(rbt, value, ~height)->ignore
418-
)
401+
array->Js.Array2.forEach(((value, height)) => add(rbt, value, ~height)->ignore)
419402
rbt
420403
}
421404

@@ -425,9 +408,9 @@ let rec heightOfInterval = (rbt, node, lhs, rhs) =>
425408
| Some(n) =>
426409
if lhs === None && rhs === None {
427410
n.sum
428-
} else if lhs !== None && rbt.compare(. n.value, lhs->castNotOption) < 0 {
411+
} else if lhs !== None && rbt.compare(n.value, lhs->castNotOption) < 0 {
429412
rbt->heightOfInterval(n.right, lhs, rhs)
430-
} else if rhs !== None && rbt.compare(. n.value, rhs->castNotOption) > 0 {
413+
} else if rhs !== None && rbt.compare(n.value, rhs->castNotOption) > 0 {
431414
rbt->heightOfInterval(n.left, lhs, rhs)
432415
} else {
433416
n.height +.
@@ -436,8 +419,7 @@ let rec heightOfInterval = (rbt, node, lhs, rhs) =>
436419
}
437420
}
438421

439-
let heightOfInterval = (rbt, lhs, rhs) =>
440-
heightOfInterval(rbt, rbt.root, lhs, rhs)
422+
let heightOfInterval = (rbt, lhs, rhs) => heightOfInterval(rbt, rbt.root, lhs, rhs)
441423

442424
let rec firstVisibleNode = (node, top) =>
443425
switch node {
@@ -499,9 +481,7 @@ let rec sumLeftSpine = (node, ~fromRightChild) => {
499481
}
500482
switch node.parent {
501483
| None => leftSpine
502-
| Some(parent) =>
503-
leftSpine +.
504-
parent->sumLeftSpine(~fromRightChild=parent.right === Some(node))
484+
| Some(parent) => leftSpine +. parent->sumLeftSpine(~fromRightChild=parent.right === Some(node))
505485
}
506486
}
507487

@@ -512,11 +492,11 @@ let rec iterate = (~inclusive, firstNode, lastNode, ~callback) =>
512492
| None => ()
513493
| Some(node) =>
514494
if inclusive {
515-
callback(. node)
495+
callback(node)
516496
}
517497
if firstNode !== lastNode {
518498
if !inclusive {
519-
callback(. node)
499+
callback(node)
520500
}
521501
iterate(~inclusive, node->nextNode, lastNode, ~callback)
522502
}
@@ -531,19 +511,13 @@ let rec iterateWithY = (~y=?, ~inclusive, firstNode, lastNode, ~callback) =>
531511
| Some(y) => y
532512
}
533513
if inclusive {
534-
callback(. node, y)
514+
callback(node, y)
535515
}
536516
if firstNode !== lastNode {
537517
if !inclusive {
538-
callback(. node, y)
518+
callback(node, y)
539519
}
540-
iterateWithY(
541-
~y=y +. node.height,
542-
~inclusive,
543-
node->nextNode,
544-
lastNode,
545-
~callback,
546-
)
520+
iterateWithY(~y=y +. node.height, ~inclusive, node->nextNode, lastNode, ~callback)
547521
}
548522
}
549523

@@ -606,38 +580,32 @@ let onChangedVisible = (
606580

607581
let oldLen = old->Js.Array2.length
608582
let oldIter = ref(0)
609-
iterateWithY(~inclusive=true, first, last, (. node, y_) => {
583+
iterateWithY(~inclusive=true, first, last, (node, y_) => {
610584
let y = y_ +. anchorDelta
611585
if y >= 0.0 {
612586
while (
613587
oldIter.contents < oldLen &&
614-
rbt.compare(.
615-
Js.Array2.unsafe_get(old, oldIter.contents),
616-
node.value,
617-
) < 0
588+
rbt.compare(Js.Array2.unsafe_get(old, oldIter.contents), node.value) < 0
618589
) {
619-
disappear(. Js.Array2.unsafe_get(old, oldIter.contents))
590+
disappear(Js.Array2.unsafe_get(old, oldIter.contents))
620591
oldIter.contents = oldIter.contents + 1
621592
}
622593
new->Js.Array2.push(node.value)->ignore
623594
if oldIter.contents < oldLen {
624-
let cmp = rbt.compare(.
625-
Js.Array2.unsafe_get(old, oldIter.contents),
626-
node.value,
627-
)
595+
let cmp = rbt.compare(Js.Array2.unsafe_get(old, oldIter.contents), node.value)
628596
if cmp == 0 {
629-
remained(. node, y)
597+
remained(node, y)
630598
oldIter.contents = oldIter.contents + 1
631599
} else {
632-
appear(. node, y)
600+
appear(node, y)
633601
}
634602
} else {
635-
appear(. node, y)
603+
appear(node, y)
636604
}
637605
}
638606
})
639607
while oldIter.contents < oldLen {
640-
disappear(. Js.Array2.unsafe_get(old, oldIter.contents))
608+
disappear(Js.Array2.unsafe_get(old, oldIter.contents))
641609
oldIter.contents = oldIter.contents + 1
642610
}
643611
}

0 commit comments

Comments
 (0)
Please sign in to comment.