Consolidate the parsetree printers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- ocaml
- Domain
- compilers
Research direction
Start with compiler/ml/printast.ml, compiler/syntax/src/res_ast_debugger.ml, compiler/ml/pprintast.ml, and the roundtrip test in scripts/test_syntax.sh. Trace the printer call sites and parser fixture snapshots named in the issue, then check how bsc -dsource handles PPX and builtin rewrites. Done means removing the redundant printers and comparisons while keeping the listed print modes, fixtures, and tests working.
Written by the indexing model from the issue text.
Description
The compiler has three printers for the parsetree, and each one matches over every node. Every new node (recently Pexp_dict, Ppat_dict, Pexp_ternary, Pmod_await, Ppat_variant_spread) has to be added to all three, on top of the parsetree, the v0 mappers and the formatter.
| Printer | Size | Output | Used by |
|---|---|---|---|
compiler/ml/printast.ml |
827 lines | tree with source locations | bsc -dparsetree, res_parser -print ast, the playground's parsetree view, ounit_parser_recovery_tests |
Sexp_ast in compiler/syntax/src/res_ast_debugger.ml |
~1,040 lines | S-expression without locations, except the offsets of explicit braces (see below) | res_parser -print sexp, used by the formatter roundtrip test |
compiler/ml/pprintast.ml |
1,471 lines | OCaml syntax | res_parser -print ml (expected output for the parser fixtures in tests/syntax_tests/data/parsing), bsc -dsource, a few ounit tests |
Sexp_ast is redundant. The roundtrip test in scripts/test_syntax.sh formats a file twice and checks two things:
- the two formatted texts are equal;
- the ASTs parsed from them are equal (as sexp).
The parser is deterministic, so the AST check holds whenever the text check does. The original file's AST can't usefully be compared with the formatted one, because the formatter changes the AST on purpose, e.g. it removes braces in switch cases.
Sexp_ast prints no locations, with one exception: since #8678 it prints the character offsets of explicit braces (braces_loc of Pexp_braces). That was not intended and nothing depends on it. It should not be carried into any other printer or test.
Pprintast is a leftover from OCaml. ReScript has no other use for printing its AST as OCaml code.
Proposal
- Remove
Sexp_ast,-print sexpand the redundant AST comparison from the roundtrip test. - Snapshot the parser fixtures with
Printastinstead of-print ml. - Make
bsc -dsourceprint the parsetree after PPX and builtin rewrites with the ReScript printer instead of OCaml syntax. - Move
Pprintast.string_of_int_as_char(used byprintlambda.mlandparmatch.ml), then removePprintastandres_driver_ml_printer.ml.
That removes about 2,500 lines, and new parsetree nodes need one printer case instead of three. -print comments and -print doc in res_ast_debugger.ml, Printtyped and Printlambda are not affected.
Compatibility: res_parser isn't shipped in the npm packages, so -print sexp and -print ml are internal. bsc -dsource is a debugging flag. Its output switches from OCaml-like to ReScript syntax.
- Dominant language
- OCaml
- Stars
- 7.5k
- Forks
- 484
- Avg merge
- 18h 19m
- Merged PRs (30d)
- 116
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rescript-lang/rescript
-
Build-test fixtures that no longer test what they claimPossibly taken @cknitt claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rescript-lang/rescript#8827 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
rescript-lang/rescript#8833 · 1 reaction ·
Maintainers usually reply within 1 day
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonPossibly taken @cknitt claimed this 1 day ago. Open
Difficulty 4/5 1-2 days Newbie friendliness 35/100
rescript-lang/rescript#8825 ·
Maintainers usually reply within 1 day
-
Formatter drops comments in dict patterns, variant spread patterns and dict literal spreadsPossibly taken @cknitt claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
rescript-lang/rescript#8820 ·
Maintainers usually reply within 1 day
-
JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)Possibly taken @cknitt claimed this 1 day ago. Open
Difficulty 4/5 1-2 days Newbie friendliness 25/100
rescript-lang/rescript#8813 ·
Maintainers usually reply within 1 day
All issues in rescript-lang/rescript
Similar issues
-
[llvm-cov] `export -format=lcov` writes the folded side of a branch as an untaken `BRDA` recordOpentools:llvm-cov
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
llvm/llvm-project#231521 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
bug format I/O medium priority rt_lib
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
lane:method-table todo:ticket
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Re-importing a cached module re-reads its files once per import path (very slow on Windows / in the LSP)Possibly taken @bfren claimed this today. Openstatus:needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nushell/nushell#19226 · 1 comment ·
Maintainers usually reply within 1 day