Consolidate the parsetree printers
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Refactorisation
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- ocaml
- Domaine
- compilers
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
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.
- Langage dominant
- OCaml
- Étoiles
- 7.5k
- Forks
- 484
- Merge moyen
- 20 h 27 min
- PR mergées (30 j)
- 120
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rescript-lang/rescript
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
rescript-lang/rescript#8833 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonPeut-être pris @cknitt l’a pris il y a 2 jours. Ouverte
Difficulté 4/5 1-2 jours Accessibilité débutants 35/100
rescript-lang/rescript#8825 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
rescript-lang/rescript#8806 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 Une demi-journée Accessibilité débutants 58/100
rescript-lang/rescript#8757 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 40/100
rescript-lang/rescript#8753 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rescript-lang/rescript
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
limitlessprojects/Go-Hybrid#50 ·
Les mainteneurs répondent en général sous 1 jour
-
Drawing: a reserved word as a view or sheet name says "is not a name" instead of "is reserved"Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
bmander/geomsolver#316 ·
Les mainteneurs répondent en général sous 1 jour
-
text as float loses precisionOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
NationalSecurityAgency/ghidra#9884 ·
Les mainteneurs répondent en général sous 2 jours
-
crash generated by fuzzer mlir
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
llvm/llvm-project#231844 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour