Skip to content

Commit de5a959

Browse files
cknittclaude
andcommitted
Do not check the Flow parser's AST for dead code
Without the AST mapper, which read every field to rebuild nodes, most fields of flow_ast.ml are only written: make dead-code reported 435 record labels and 54 modules of them, and nothing else in the Flow parser. The parser fills in the whole AST and the compiler reads only what it needs to classify %raw code, so that file is suppressed like the frozen parsetree0.ml; the rest of the Flow parser stays checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gLDo8mBJKpNE25WAwT Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 194c023 commit de5a959

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎compiler/flow_parser/README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
This directory contains the OCaml Flow parser used by the ReScript compiler.
44
It is a pruned fork: Flow's parser has moved to Rust, so there are no further
55
OCaml releases to sync with, and code ReScript does not use is removed like
6-
dead code anywhere else in the repository (`make dead-code` covers it).
6+
dead code anywhere else in the repository (`make dead-code` covers it, except
7+
the AST in `parser/flow_ast.ml`).
78

89
- Upstream repository: https://github.com/facebook/flow
910
- Flow parser version: `0.320.0`
@@ -40,7 +41,12 @@ printers (`[@@deriving show]`), the file-key variants (ReScript parses only
4041
strings), error variants that are never raised, and AST fields that the parser
4142
fills in but nothing reads (template literal quasi values, tolerated-syntax
4243
records, JSX text and fragment locations, comment `on_newline`, accessibility
43-
comments).
44+
comments). The AST mapper classes that moved trailing comments between nodes
45+
(`Flow_ast_mapper` and its subclasses in `Comment_attachment`) are gone too:
46+
ReScript never reads trailing comments, and creating the classes was most of
47+
the compiler's startup work. They were also what read every AST field, so most
48+
fields of `flow_ast.ml` are now only written; `make dead-code` does not check
49+
that file.
4450

4551
Vendored sources are excluded from the repository-wide OCamlformat check so
4652
that they keep Flow's formatting.

‎scripts/dead_code.sh‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ trap 'rm -rf "$root"' EXIT
2424
ln -s "$PWD/_build/default" "$root/native"
2525
ln -s "$PWD/_build_playground/default" "$root/playground"
2626

27-
# Not reported: compiler/ml/parsetree0.ml is the frozen AST of PPXs, which
28-
# build the constructors the compiler itself never builds; it must not change.
27+
# Not reported:
28+
# - compiler/ml/parsetree0.ml is the frozen AST of PPXs, which build the
29+
# constructors the compiler itself never builds; it must not change.
30+
# - compiler/flow_parser/parser/flow_ast.ml is the vendored Flow parser's AST:
31+
# the parser fills in every field, the compiler reads only the few it needs
32+
# to classify %raw code.
2933
"$reanalyze" -dce-cmt "$root" \
30-
-suppress compiler/ml/parsetree0.ml \
34+
-suppress compiler/ml/parsetree0.ml,compiler/flow_parser/parser/flow_ast.ml \
3135
-set-exit-code

0 commit comments

Comments
 (0)