Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
464 commits
Select commit Hold shift + click to select a range
944b47f
Update RALPH_TODO.md with detailed category breakdown
jfrolich Feb 2, 2026
52f483f
Fix ppx/react tests: recursive components, ref types, @as attrs
jfrolich Feb 2, 2026
436c185
Fix ML printer formatting for sig/struct blocks and module types
jfrolich Feb 2, 2026
506f67d
Fix ML printer: add attributes for Psig_modtype and fix inline record…
jfrolich Feb 2, 2026
da12aad
Fix ML printer: type extensions and exception inline record formatting
jfrolich Feb 2, 2026
500718c
Fix ML printer: type defs on newlines, module attrs, empty functors
jfrolich Feb 2, 2026
8596bf1
Fix ML printer: top-level signature items on separate lines
jfrolich Feb 2, 2026
8112c13
Fix ML printer: module alias syntax (= instead of :)
jfrolich Feb 2, 2026
2bbec5c
Fix ML printer: add HOV box for val/external in signatures
jfrolich Feb 2, 2026
ee90c04
Fix variant constructor inline record spacing
jfrolich Feb 2, 2026
0b2924c
Fix with type constraint printing in ML printer
jfrolich Feb 2, 2026
59acfb7
Fix optional record field printing and field attributes
jfrolich Feb 2, 2026
daf1dfa
Print locally abstract types inline in value bindings
jfrolich Feb 2, 2026
2402f8a
Print attributes on arrow type arguments
jfrolich Feb 2, 2026
9e40b55
Update RALPH_TODO.md with current status (340/506)
jfrolich Feb 2, 2026
018e4e0
Print arity markers on each Pexp_fun in uncurried mode
jfrolich Feb 2, 2026
6e18962
Add parens around arrow types in arrow type arguments
jfrolich Feb 2, 2026
e69838b
Print constrained module binding sugar and fix trailing space
jfrolich Feb 2, 2026
aa81870
Print type parameter variance annotations
jfrolich Feb 2, 2026
ed821f6
Print private on open type (Ptype_open)
jfrolich Feb 2, 2026
27867a4
Fix extension payload printing to use print_payload function
jfrolich Feb 2, 2026
618fcde
Include parsing/ directory in AST parity tests
jfrolich Feb 2, 2026
0fea63b
Fix attribute placement in module types with 'with' constraints
jfrolich Feb 2, 2026
7b7705e
Fix package type constraint printing to use 'and' for subsequent cons…
jfrolich Feb 2, 2026
d65c676
Fix record field semicolon spacing when field has attributes
jfrolich Feb 2, 2026
11d2ab6
Exclude files where both parsers fail from parity test
jfrolich Feb 2, 2026
bae816a
Fix ML printer for Psig_recmodule and Psig_type
jfrolich Feb 2, 2026
49fb0d0
Print type constraints in type declarations
jfrolich Feb 2, 2026
9a85b7a
Update RALPH_TODO.md with current status and root cause analysis
jfrolich Feb 2, 2026
e68a671
Update RALPH_TODO.md with detailed analysis of remaining failures
jfrolich Feb 2, 2026
172b026
Fix recursive module binding and type declaration parsing
jfrolich Feb 2, 2026
3e1ddf2
Update RALPH_TODO.md: 349/506 tests passing (68%)
jfrolich Feb 2, 2026
a2c6e5e
Fix module functor sugar and module application printing
jfrolich Feb 2, 2026
4e44d6c
Fix unit functor printing: functor () -> instead of functor (*) ->
jfrolich Feb 2, 2026
68bfe9e
Update RALPH_TODO.md: 350/506 tests passing (69%)
jfrolich Feb 2, 2026
465c700
Fix multiple parser parity issues
jfrolich Feb 2, 2026
4bfedc1
Fix ML printer: complete list literals are simple expressions
jfrolich Feb 2, 2026
4b9d8fa
Implement full JSX printing in ML printer
jfrolich Feb 2, 2026
8b96ae1
Update RALPH_TODO.md: 351/506 tests passing (69%)
jfrolich Feb 2, 2026
d1e39cd
Fix ML printer: record pattern punning only for simple Lident fields
jfrolich Feb 2, 2026
1ed63da
Update RALPH_TODO.md: 352/506 tests passing (69.6%)
jfrolich Feb 2, 2026
c6cbab8
Fix ML printer: include res.await attribute in printed output
jfrolich Feb 2, 2026
77e9b61
Fix ML printer: avoid double parens in await expressions
jfrolich Feb 2, 2026
bed86db
Fix ML printer: add spaces between JSX children
jfrolich Feb 2, 2026
6da5e38
Update RALPH_TODO.md with recent fixes
jfrolich Feb 2, 2026
b1bf72a
Fix multiple parser parity issues
jfrolich Feb 2, 2026
e1c36b1
Fix constrained pattern printing in value bindings
jfrolich Feb 2, 2026
f5986e1
Fix constructor attribute printing in type declarations
jfrolich Feb 2, 2026
510c8d6
Fix cons pattern parens in constraint patterns
jfrolich Feb 2, 2026
b206281
Add trailing space after Ppat_unpack pattern
jfrolich Feb 2, 2026
d1b2249
Add Pexp_send to simple expressions and document Pexp_field
jfrolich Feb 2, 2026
352a01b
Update RALPH_TODO.md: 355/506 tests passing (70%)
jfrolich Feb 2, 2026
13a0015
Add Pexp_jsx_element to is_simple_expression
jfrolich Feb 2, 2026
7880cb5
Update RALPH_TODO.md with detailed failure analysis
jfrolich Feb 2, 2026
ca140bb
Fix ML printer expression tier hierarchy (expression2 vs simple_expr)
jfrolich Feb 2, 2026
665deb8
Fix letexception spacing in ML printer
jfrolich Feb 2, 2026
daa9253
Fix ML printer Unicode escaping and margin width
jfrolich Feb 2, 2026
6dad490
Add HOV box with break hints to Ptyp_arrow for line wrapping
jfrolich Feb 2, 2026
aacc5d7
Add consecutive statements/expressions error checking
jfrolich Feb 2, 2026
cf59241
Update RALPH_TODO.md: 361/506 tests passing (71%)
jfrolich Feb 2, 2026
a1f62d9
Fix escape_string to iterate over chars not bytes
jfrolich Feb 2, 2026
fc9b4f3
Add mk_loc_spanning_preserve_ghost for sequence ghost locations
jfrolich Feb 2, 2026
3b2997f
Use simple_expr for record field values in ML printer
jfrolich Feb 2, 2026
879dc1b
ML printer: add pipe context for match cases and use simple_expr for …
jfrolich Feb 2, 2026
df322f1
Fix label_declaration location for constructor records
jfrolich Feb 2, 2026
fc6eadc
Fix parenthesized module expression location
jfrolich Feb 2, 2026
df079e3
ML printer: wrap alias types in parens when used as arrow arguments
jfrolich Feb 2, 2026
c9f2a49
Update RALPH_TODO.md with recent ML printer fixes
jfrolich Feb 2, 2026
c751a2d
Fix unit pattern and alias locations in for loops
jfrolich Feb 2, 2026
debc5e7
Fix module type location to exclude leading attributes
jfrolich Feb 2, 2026
faea6ac
Add polyvariant type error generation for error recovery mode
jfrolich Feb 2, 2026
0645106
Update RALPH_TODO.md with recent polyvariant error fix
jfrolich Feb 2, 2026
dc6011c
Update RALPH_TODO.md with current analysis of remaining failures
jfrolich Feb 2, 2026
f2cdd52
Fix polyvariant error recovery: generate two type holes for `[]` and …
jfrolich Feb 2, 2026
f47f7d7
Update RALPH_TODO.md with current parity status
jfrolich Feb 2, 2026
dd39408
Update RALPH_TODO.md with error investigation findings
jfrolich Feb 2, 2026
704a1d1
Use Grammar enum in DiagnosticCategory for context-aware error messages
jfrolich Feb 2, 2026
ce8db4a
Fix DiagnosticCategory to use Grammar enum consistently
jfrolich Feb 2, 2026
274217a
Implement context-aware error messages using breadcrumbs
jfrolich Feb 2, 2026
bbbcee3
Fix error location spans in expect_with_grammar
jfrolich Feb 2, 2026
ceafab2
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
36f6318
Fix empty record printing in ML printer
jfrolich Feb 2, 2026
6f3bcac
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
3244a0d
Fix item_attribute and polyvariant line-breaking in ML printer
jfrolich Feb 2, 2026
f91e76a
Fix remaining sexp-locs parity differences
jfrolich Feb 2, 2026
d94cc4b
Add specific error messages for dangling attrs/mutable in record fields
jfrolich Feb 2, 2026
d09de73
Add error recovery for = instead of : in record field declarations
jfrolich Feb 2, 2026
7557ae4
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
a09b4b9
Add critical note about Format module being 1:1 port from OCaml
jfrolich Feb 2, 2026
f5709cb
Fix error reporting to match OCaml's region-based silencing
jfrolich Feb 2, 2026
0140f96
Add begin_region/end_region to type and module parsing
jfrolich Feb 2, 2026
05d6e51
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
2a3d6cf
Add begin_region/end_region to switch and try case parsing
jfrolich Feb 2, 2026
8b7a2b7
Add skip_tokens_and_maybe_retry for better error recovery
jfrolich Feb 2, 2026
faeedd3
Propagate scanner diagnostics to parser
jfrolich Feb 2, 2026
ad66b4c
Add error for empty exotic identifiers
jfrolich Feb 2, 2026
44dbc99
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
1258de9
Move parse_newline_or_semicolon_structure inside structure item branches
jfrolich Feb 2, 2026
caf757e
Add parse_newline_or_semicolon_signature for signature item parsing
jfrolich Feb 2, 2026
54c2b6a
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
2d1929b
Add PatternMatchCase and Pattern breadcrumbs for switch/try cases
jfrolich Feb 2, 2026
5e6a557
Use expect() for catch token to get correct error message
jfrolich Feb 2, 2026
47108f4
Add sigitemhole recovery and attribute_without_node error
jfrolich Feb 2, 2026
1a61ae5
Update RALPH_TODO.md with current status
jfrolich Feb 2, 2026
2354b82
Add infinite loop warning to RALPH instructions
jfrolich Feb 2, 2026
1c4090c
Add timeout to parity tests, fix is_atomic_expr_start
jfrolich Feb 2, 2026
40c92c4
Fix infinite loop in signature parsing for unexpected tokens
jfrolich Feb 3, 2026
b6465ab
Fix stack overflow crashes in parser for malformed input
jfrolich Feb 3, 2026
863a728
Fix type definition parsing: emit error when Bar precedes Equal
jfrolich Feb 3, 2026
f9d228a
Fix type name parsing: use Lident diagnostic for uppercase names
jfrolich Feb 3, 2026
09b1899
Fix type extension parsing: emit error for uppercase final segment
jfrolich Feb 3, 2026
e8f69bb
Fix exotic identifier error location to start at backslash
jfrolich Feb 3, 2026
8204afd
Fix type name parsing: use Unexpected diagnostic for EOF token
jfrolich Feb 3, 2026
b96073d
Update RALPH_TODO.md with recent fixes
jfrolich Feb 3, 2026
2084cd2
Add skip_tokens_and_maybe_retry to type expression parsing
jfrolich Feb 3, 2026
c75a9ca
Add MinusGreater error recovery in arrow type parsing
jfrolich Feb 3, 2026
dc39774
Add grammar context to expect(Colon) for type hints
jfrolich Feb 3, 2026
4506ff9
Update RALPH_TODO.md with recent error recovery fixes
jfrolich Feb 3, 2026
5c90f1d
Add empty switch case error: "Pattern matching needs at least one case"
jfrolich Feb 3, 2026
d6db02e
Add error for numeric polymorphic variants with suffix
jfrolich Feb 3, 2026
b57dc63
Treat _ as error in expressions but allow in function arguments
jfrolich Feb 3, 2026
d8a28d4
Update RALPH_TODO.md with recent fixes (394 -> 397 tests)
jfrolich Feb 3, 2026
8eab677
Fix single-element tuple error locations and add error to patterns/types
jfrolich Feb 3, 2026
3a8e6d0
Add missing tilde error for labeled parameters and fix Lident diagnostic
jfrolich Feb 3, 2026
8b74705
Add parse_ident helper and fix type variable error messages
jfrolich Feb 3, 2026
7de3cb0
Update RALPH_TODO.md with recent fixes
jfrolich Feb 3, 2026
e50b5da
Fix type declaration error recovery to create placeholder type
jfrolich Feb 3, 2026
5f81ce0
Update RALPH_TODO.md: 400/506 tests passing (79%)
jfrolich Feb 3, 2026
8b9a2d4
Add special error messages for old |> and [|...|] syntax
jfrolich Feb 3, 2026
435f4d2
Fix pattern error recovery to use skip_tokens_and_maybe_retry
jfrolich Feb 3, 2026
56be182
Fix if-expression error recovery with proper regions and breadcrumbs
jfrolich Feb 3, 2026
675b12d
Add spread pattern error messages for array and record patterns
jfrolich Feb 3, 2026
ca4c093
Update RALPH_TODO.md: 404/506 tests passing (79%)
jfrolich Feb 3, 2026
49299ea
Add 'Did you mean ==?' error for = used as binary operator
jfrolich Feb 3, 2026
037411b
Add string interpolation error in pattern matching
jfrolich Feb 3, 2026
85c69ff
Update RALPH_TODO.md with recent fixes
jfrolich Feb 3, 2026
fc835a9
Add error messages for `let?` in signatures and `let? rec`
jfrolich Feb 3, 2026
d232a1e
Add error for second record spread in record expressions
jfrolich Feb 3, 2026
2d6c91c
Add missing tilde error for labeled type parameters
jfrolich Feb 3, 2026
cb8b017
Update RALPH_TODO.md with recent fixes
jfrolich Feb 3, 2026
a43973c
Add dict spread error message
jfrolich Feb 3, 2026
0873bf9
Update RALPH_TODO.md with current status
jfrolich Feb 3, 2026
0158ce6
Add type definition in function error message
jfrolich Feb 3, 2026
41e6202
Add external missing JS value name error
jfrolich Feb 3, 2026
b2e70d3
Use exprhole instead of unit for empty block bodies
jfrolich Feb 3, 2026
174bc03
Fix empty inline record parsing and exprhole for empty blocks
jfrolich Feb 3, 2026
f8a42f6
Add keyword field error handling for record fields
jfrolich Feb 3, 2026
3ec8caf
Fix value path error recovery for trailing dot
jfrolich Feb 3, 2026
5720298
Add ExprSetField breadcrumb for record field mutation
jfrolich Feb 3, 2026
82eac1c
Update RALPH_TODO.md with current status
jfrolich Feb 3, 2026
341b0cf
Use Lident diagnostic in parse_lident functions
jfrolich Feb 3, 2026
71a8a95
Update RALPH_TODO.md with Lident diagnostic fix
jfrolich Feb 3, 2026
77bf025
Fix exotic identifier handling to match OCaml
jfrolich Feb 3, 2026
ac210ed
Fix scanner to preserve start_pos when skipping bad characters
jfrolich Feb 3, 2026
8230d98
Fix error location span in parse_atomic_expr to match OCaml
jfrolich Feb 3, 2026
01c07e8
Update RALPH_TODO.md with session progress
jfrolich Feb 3, 2026
0d9f547
Fix template literal pattern parsing for string interpolation errors
jfrolich Feb 3, 2026
dbd0226
Fix semicolon spacing in inline record constructor fields
jfrolich Feb 3, 2026
4a5c3d8
Update RALPH_TODO.md with current status
jfrolich Feb 3, 2026
c1c4f29
Add proper comma error handling in parameter and argument lists
jfrolich Feb 3, 2026
dd07893
Update RALPH_TODO.md with comma error handling fix
jfrolich Feb 3, 2026
9d23eae
Update RALPH_TODO.md with current failure analysis
jfrolich Feb 3, 2026
b175dd2
Fix record/braced expression disambiguation for ident-ident case
jfrolich Feb 3, 2026
58f18d9
Add break hints to ML printer external/val declarations
jfrolich Feb 3, 2026
c8f220c
Fix Format module size calculation and for-loop box structure
jfrolich Feb 3, 2026
2e75c49
Fix Format module fits comparison and Pstr_eval box wrapping
jfrolich Feb 3, 2026
6a3559f
Improve formatter and ML printer for closer OCaml parity
jfrolich Feb 3, 2026
30aceb6
Fix fun/let/module expression formatting for 4 more test passes (432/…
jfrolich Feb 3, 2026
b818178
Fix pattern/expression construct & variant printing with simple_patte…
jfrolich Feb 3, 2026
497ab44
Implement structural box (Pp_box) and fix box types for closer OCaml …
jfrolich Feb 3, 2026
082f2a4
Refine structural box: content newlines force cuts, fix is_new_line
jfrolich Feb 3, 2026
a11e8b1
Fix attribute printing to use single cut before all attributes
jfrolich Feb 3, 2026
23f2bec
Add proper label_exp punning for fun expression parameters
jfrolich Feb 3, 2026
1ab28be
Fix GADT constructor syntax to use : args -> return_type format
jfrolich Feb 3, 2026
a6ac8d7
Add core_type1 for constructor args and print_record_declaration helper
jfrolich Feb 3, 2026
fc306f0
Implement sequence flattening for Pexp_sequence printing
jfrolich Feb 3, 2026
01c143a
Fix when clause formatting in match/try cases
jfrolich Feb 3, 2026
54f9aae
Fix list element printing to use expression(under_semi) not semi_context
jfrolich Feb 3, 2026
0189220
Move type declaration item attributes outside the box
jfrolich Feb 3, 2026
c259897
Fix formatter fit check and struct inner box type
jfrolich Feb 3, 2026
ca49a3c
Fix record declaration printing and formatter boundary check
jfrolich Feb 3, 2026
de574d1
Remove extra parens from Pexp_newtype printing
jfrolich Feb 3, 2026
a896e16
Treat forced newlines inside nested boxes as size 0
jfrolich Feb 3, 2026
7d708a3
Make forced newlines always have size 0 for box measurement
jfrolich Feb 3, 2026
975c03b
Fix typext wildcard param and recursive module and-bindings
jfrolich Feb 3, 2026
7ade7a8
Fix string column tracking to match OCaml's Format behavior
jfrolich Feb 3, 2026
515bcd9
Fix if/try expression formatting with break hints
jfrolich Feb 3, 2026
5e65d52
Fix extension, unpack, and await break hints
jfrolich Feb 3, 2026
c3bdedc
Fix Pstr_include and Psig_include to use HOV(2) box with break hints
jfrolich Feb 3, 2026
ccc5034
Fix break size computation to match OCaml's Format module
jfrolich Feb 3, 2026
f08298a
Add pp_max_indent cap to formatter (68, matching OCaml)
jfrolich Feb 3, 2026
4e27c18
Add pp_force_break_line and fits_stack to formatter
jfrolich Feb 3, 2026
0b666bc
Fix width computation in formatter to match OCaml's Format module
jfrolich Feb 3, 2026
5a1e744
Fix else branch to use under_semi context for expression printing
jfrolich Feb 3, 2026
181c926
Fix array under_semi and pattern_is_simple for attributed patterns
jfrolich Feb 3, 2026
0825c4f
Add locally abstract type sugar detection in printer
jfrolich Feb 3, 2026
fc9d65d
Fix box fits check to match OCaml's scan model
jfrolich Feb 3, 2026
69810c8
Implement OCaml Format scan-based algorithm in Rust formatter
jfrolich Feb 3, 2026
6fc2dde
Fix break placement in ML printer to match OCaml format strings
jfrolich Feb 3, 2026
70d68ba
Use breaks instead of literal spaces for type/constructor separators
jfrolich Feb 3, 2026
307b422
Use breaks in Pexp_newtype, Pexp_pack, Ppat_unpack to match OCaml for…
jfrolich Feb 3, 2026
6b38647
Use breaks in Pmod_functor, Pmod_constraint to match OCaml format str…
jfrolich Feb 3, 2026
5d36b1b
Use breaks in Ptyp_poly, Ptyp_package, Pmty_functor to match OCaml fo…
jfrolich Feb 3, 2026
a66454a
Add Box(2) wrapping for core_type fallthrough and Ptyp_alias breaks
jfrolich Feb 3, 2026
6a7982b
Use breaks in Ptyp_constr separators and Ptyp_object HOV boxes
jfrolich Feb 3, 2026
d768a3e
Use correct box type and separator for Pmod_structure
jfrolich Feb 3, 2026
10cb209
Use proper boxes and breaks for record expressions/patterns and tuple…
jfrolich Feb 3, 2026
5717fed
Add Box(2) and breaks to Ppat_constraint and Ppat_array
jfrolich Feb 3, 2026
9a724df
Add Box(2) and breaks to Ppat_alias
jfrolich Feb 3, 2026
b51f570
Use breaks in recmodule, letmodule, letexception, open expressions
jfrolich Feb 3, 2026
53def16
Remove f.cut() before pattern attributes to match OCaml
jfrolich Feb 3, 2026
e40aee4
Add Box(2) wrapping in payload PStr/Pstr_eval to match OCaml
jfrolich Feb 3, 2026
e09e1da
Add ifthenelse context and fix attribute ordering in ML printer contexts
jfrolich Feb 3, 2026
caa88ff
Add break_long_line to code frame for error context wrapping
jfrolich Feb 3, 2026
84bdcd9
Add record field = vs : error messages and labelled argument : vs = e…
jfrolich Feb 3, 2026
9a6032e
Add attribute-without-node error for structure items and Structure br…
jfrolich Feb 3, 2026
7ea024f
Add type parameter angle bracket error for parenthesized type args
jfrolich Feb 3, 2026
d441f07
Add parse_lident recovery in expr.rs to match OCaml behavior
jfrolich Feb 3, 2026
fcf3a0b
Skip trailing | before ] in array expr for old [|...|] syntax recovery
jfrolich Feb 3, 2026
5883163
Restrict tagged template literals to identifier tags only
jfrolich Feb 3, 2026
2dc87ae
Add parse_lident recovery to pattern.rs for alias parsing
jfrolich Feb 3, 2026
951a80a
Add missing comma detection in comma-delimited type lists
jfrolich Feb 3, 2026
dd6fc2e
Fix unterminated template literal to exclude trailing char
jfrolich Feb 3, 2026
77789fe
Add forbidden inline record declaration error in type expressions
jfrolich Feb 3, 2026
82cba51
Add StringFieldDeclarations breadcrumb in parse_object_fields
jfrolich Feb 3, 2026
06abef7
Add over_parse_constrained_or_coerced_or_arrow_expression for constra…
jfrolich Feb 3, 2026
40a30b6
Add if-let expression parsing with experimental error message
jfrolich Feb 3, 2026
bc89211
Add PrintCtx to ML printer for context-dependent parenthesization
jfrolich Feb 3, 2026
6eca64b
Thread PrintCtx through print_expression_simple and related functions
jfrolich Feb 3, 2026
00a6129
Fix spread lookahead in constructor args to scan for string fields
jfrolich Feb 3, 2026
09f1d91
Add JSX-specific error messages for parity with OCaml
jfrolich Feb 3, 2026
9281c82
Add HOV(2) box around Pexp_send to match OCaml pprintast formatting
jfrolich Feb 3, 2026
ec0bfde
Remove over-aggressive JSX disambiguation in binary expression loop
jfrolich Feb 3, 2026
805a020
Improve JSX closing tag handling to match OCaml's three-way check
jfrolich Feb 3, 2026
aaaf4df
Fix JSX error recovery: breadcrumbs, prop recovery, trailing hyphen/dot
jfrolich Feb 3, 2026
ee665b4
Add Forwardslash regex rescanning and fix is_expr_start/is_atomic_exp…
jfrolich Feb 3, 2026
d48c622
Fix region-aware error suppression for old-style type params
jfrolich Feb 3, 2026
845b9c7
Match OCaml parse_tag_spec fallback for poly variant row fields
jfrolich Feb 3, 2026
b179177
Fix test script: compare grammar test output regardless of exit code
jfrolich Feb 3, 2026
d6b9b8d
Add ExprBlock breadcrumb to block body parsing
jfrolich Feb 3, 2026
68e2971
Match OCaml: use parse_pattern for switch case patterns, allow arrows…
jfrolich Feb 3, 2026
1b44f46
Improve switch case empty body error recovery to match OCaml
jfrolich Feb 3, 2026
e06222d
Rewrite list and record pattern parsing to match OCaml's spread handling
jfrolich Feb 3, 2026
9997d56
Fix record pattern spread error ordering to match OCaml
jfrolich Feb 3, 2026
6ae8b98
Check is_argument_start before parsing call args to match OCaml
jfrolich Feb 3, 2026
e2de7e0
Match OCaml's parse_type_constructor_arg_region to skip < in type args
jfrolich Feb 3, 2026
fb79b38
Move locally abstract type parsing out of parse_atomic_typ_expr
jfrolich Feb 3, 2026
ce1fa3d
Match OCaml's parse_value_path quirk for Uident type names (504→505)
jfrolich Feb 3, 2026
500115a
Thread inline record extraction through type parser (505→506, 100% pa…
jfrolich Feb 3, 2026
f56ed5c
Fix 12 idempotency test parse failures (regex, JSX, and Unicode handl…
jfrolich Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 148 additions & 63 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The Makefile’s targets build on each other in this order:

## ⚠️ Critical Guidelines & Common Pitfalls

- **COMMIT YOUR CHANGES** - After completing ANY meaningful work (bug fix, feature, refactor, parity improvement), you MUST commit immediately. Do not leave work uncommitted. Do not move on to the next task without committing first. This is the most important rule.

- **We are NOT bound by OCaml compatibility** - The ReScript compiler originated as a fork of the OCaml compiler, but we maintain our own AST and can make breaking changes. Focus on what's best for ReScript's JavaScript compilation target.

- **Never modify `parsetree0.ml`** - Existing PPX (parser extensions) rely on this frozen v0 version. When changing `parsetree.ml`, always update the mapping modules `ast_mapper_from0.ml` and `ast_mapper_to0.ml` to maintain PPX compatibility while allowing the main parsetree to evolve
Expand All @@ -74,6 +76,14 @@ The Makefile’s targets build on each other in this order:

- **Handle concurrent agent work gracefully** - If compilation fails due to errors in code you didn't touch, another agent may be actively working on that part of the codebase. Do NOT modify their files and NEVER use `git stash`. Simply wait 30 seconds and retry the build. Repeat this until compilation succeeds—the other agent will fix their changes shortly.

- **Do NOT revert large changes** - If a task impacts a large amount of code, do NOT revert and give up. Complete the large task as requested. The user is aware it's a big change and expects you to follow through.

- **Do NOT switch tasks when things get hard** - If you're working on a difficult task, do NOT abandon it to work on something easier. Complete the current task FIRST, then move on to the next one. Switching tasks loses valuable context and leaves work incomplete.

- **Embrace complexity - everything must be done** - Do not shy away from complex tasks or defer them hoping for an easier path. Every item on the task list must eventually be completed, so you might as well dig in now. Complex problems don't get easier by avoiding them—they just stay unsolved. Tackle the hard parts head-on with full attention. The satisfaction of solving a difficult problem far outweighs the temporary comfort of picking low-hanging fruit.

- **ALWAYS commit before moving on** - Before starting a new task, before investigating a problem, before taking a break: COMMIT. Use `git add <files> && git commit -m "description"`. No exceptions.

## Compiler Architecture

### Compilation Pipeline
Expand Down Expand Up @@ -642,81 +652,41 @@ When the Rust printer output differs from OCaml, common issues include:

### AST Parity Test Suite

The AST parity test suite (`scripts/test_parser_ast_parity.sh`) comprehensively compares the Rust and OCaml parser outputs across multiple dimensions:

**Tests performed:**
1. **sexp parity** - AST structure matches between OCaml and Rust
2. **sexp-locs parity** - AST structure + locations match
3. **sexp0-locs parity** - parsetree→parsetree0→sexp output matches (single-trip)
4. **Roundtrip structure parity** - After parsetree→parsetree0→parsetree, both parsers produce same AST
5. **Roundtrip location parity** - Locations preserved correctly through parsetree0 conversion
6. **Binary parity** - Marshalled parsetree0 is byte-identical (critical for PPX compatibility)

#### Running the AST Parity Tests
**This is the primary test for verifying Rust compiler parity with OCaml.**

```bash
# Run all tests (default: 16 parallel jobs)
./scripts/test_parser_ast_parity.sh

# Test a single file (fastest for iteration)
./scripts/test_parser_ast_parity.sh tests/syntax_tests/data/printer/expr/apply.res

# Test files matching a pattern
./scripts/test_parser_ast_parity.sh "printer/expr"

# Quick mode - stop on first failure
./scripts/test_parser_ast_parity.sh --quick

# Verbose mode - show each file being tested
./scripts/test_parser_ast_parity.sh -v tests/syntax_tests/data/printer/expr/apply.res

# Adjust parallelism
./scripts/test_parser_ast_parity.sh -j8
# See detailed usage information
./scripts/test_parser_ast_parity.sh --info
```

#### Regression Tracking
**⚠️ Use `--binary-only` for most testing to save resources:**

The parity test suite tracks regressions using baseline files in `tests/parity_baselines/`. Each test type has its own baseline:

- `sexp_locs.txt` - Files passing sexp-locs parity
- `binary.txt` - Files passing binary parity
- `sexp0_locs.txt` - Files passing sexp0-locs parity
- `binary0.txt` - Files passing binary0 parity
- `roundtrip_structure.txt` - Files passing roundtrip structure parity
- `roundtrip_locs.txt` - Files passing roundtrip location parity

**How it works:**
1. When a file passes a test, it's added to the corresponding baseline (append-only)
2. On subsequent runs, if a file that's in the baseline fails, it's flagged as a **regression**
3. Regressions are reported prominently and cause the test to fail

**Why this matters:**
- Prevents accidentally breaking files that were already working
- Makes it easy to see which files regressed after a change
- Baselines grow monotonically as parity improves
- Committed to git so regressions are caught in CI/PRs
```bash
# Test only bsc-ast output - USE THIS FOR ITERATION
./scripts/test_parser_ast_parity.sh --binary-only

**When you see a regression:**
1. The output will clearly list which files regressed for each test type
2. Fix the regression before moving on - don't let parity decrease
3. The baseline files should never be manually edited to remove entries
# Test a single file in binary-only mode (fastest)
./scripts/test_parser_ast_parity.sh -b tests/syntax_tests/data/printer/expr/apply.res

#### Quick Iteration Workflow
# Stop on first failure
./scripts/test_parser_ast_parity.sh -b --quick
```

When fixing parity issues, use single-file mode for fast feedback:
Since AST (sexp) parity is already achieved, you only need to run the full test suite occasionally to verify nothing regressed. The `--binary-only` flag skips sexp tests, binary0, and roundtrip tests—only testing the production `bsc -bs-ast` output:

```bash
# 1. Find a failing file from the test output
# 2. Test just that file
./scripts/test_parser_ast_parity.sh tests/syntax_tests/data/printer/expr/apply.res
# Full test suite - run occasionally, not on every change
./scripts/test_parser_ast_parity.sh
```

# 3. Make changes to Rust parser
# 4. Rebuild
cargo build --manifest-path compiler-rust/Cargo.toml --release
The test suite compares:
- **bsc-ast** - Full `bsc -bs-ast` output (production format with dependency extraction)
- **binary0** - Marshalled parsetree0 (byte-identical for PPX tools)
- **sexp-locs** - Parser AST with locations (readable diffs for debugging)
- **sexp0-locs** - Parsetree0 sexp output
- **roundtrip** - parsetree → parsetree0 → parsetree conversion

# 5. Re-test the single file
./scripts/test_parser_ast_parity.sh tests/syntax_tests/data/printer/expr/apply.res
```
**Regression tracking**: Files that pass are added to baselines in `tests/parity_baselines/`. If a passing file starts failing, it's flagged as a regression and the test fails. This ensures parity can only increase.

#### Known sexp-locs Parity Issues (5 files remaining at 99.5%)

Expand Down Expand Up @@ -748,3 +718,118 @@ The following files have known location parity differences that require more com
- **Explicit contexts** - `CompilationContext`, `TypeContext` passed through pipeline
- **Arena-per-compilation** - Type arenas owned by `TypeContext`, not shared
- **No `static mut`** - All mutable state in explicit contexts

### Binary AST Parity (Completed for Current Parsetree)

**Status:** ✅ Current parsetree format (the active AST format) has 100% binary parity.

The binary AST format uses OCaml's Marshal serialization, which includes back-references for shared objects. When OCaml creates two references to the same memory object, Marshal writes a shared reference (CODE_SHARED8/16/32) instead of duplicating the data.

**What's working:**
- Current parsetree binary: 100% parity (1049/1049 files identical)
- sexp-locs: 100% parity (1049/1049 files identical)

**parsetree0 / binary0 - NOT A PRIORITY:**

⚠️ **Do not work on parsetree0 or binary0 parity at this time.** These involve the frozen PPX-compatible format and will be addressed later. The code must still compile, but parity differences are expected and acceptable for now.

- binary0 has 985 differing files (this is fine)
- roundtrip (parsetree→parsetree0→parsetree) has differences (this is fine)

**Key implementation points:**

- **ParseArena** (`compiler-rust/src/parse_arena.rs`): Arena for positions and locations. Same `PosIdx`/`LocIdx` = same object for marshalling purposes.
- The "none" position/location are pre-allocated at index 0

- **Marshal writer** (`compiler-rust/src/binary_ast/marshal.rs`): Tables for sharing:
- `position_idx_table`: Maps `PosIdx` to object counter for arena-based position sharing
- `location_idx_table`: Maps `LocIdx` to object counter for arena-based location sharing

**Testing:**

```bash
# Run full parity test suite
./scripts/test_parser_ast_parity.sh

# Test a single file for quick iteration
./scripts/test_parser_ast_parity.sh tests/syntax_tests/data/printer/expr/apply.res

# Compare binary output directly
./_build/install/default/bin/res_parser -print binary FILE > /tmp/ocaml.bin
./compiler-rust/target/release/res_parser_rust -print binary FILE > /tmp/rust.bin
diff <(xxd /tmp/ocaml.bin) <(xxd /tmp/rust.bin)
```

**Debugging tips:**

- When binary differs, look at the hex dump: shared references show up as `04 XX` (CODE_SHARED8), `05 XX XX` (CODE_SHARED16)
- The offset after the opcode is the "distance back" in object counter terms
- If Rust has more bytes, it's likely not sharing something OCaml shares
- If Rust has fewer bytes, it's likely sharing something OCaml doesn't share
- Add debug prints in `marshal.rs` to trace object counter values

**Understanding OCaml's value sharing (critical for parity):**

OCaml's Marshal format uses **pointer identity** for sharing. When two AST nodes reference the same memory object (same pointer), Marshal writes a shared reference instead of duplicating the data. This is NOT about string interning or content equality—it's about whether the OCaml code constructs a NEW value or passes an EXISTING value by reference.

**⚠️ CRITICAL: Explicit sharing, NOT automatic interning**

The Rust implementation must **explicitly mirror OCaml's allocation patterns**. Do NOT try to automatically intern or deduplicate values based on content. Instead:

1. **Study the OCaml code** to understand when it passes a reference vs. constructs a new value
2. **Explicitly share** in Rust when OCaml passes the same reference (use the same arena index)
3. **Explicitly allocate new** in Rust when OCaml constructs a new value (push a new arena entry)

This means the Rust parser code must be structured to match OCaml's data flow:
- If OCaml binds a value to a variable and passes that variable to multiple places, Rust should do the same with an arena index
- If OCaml constructs a new record/value at each use site, Rust should push a new arena entry each time

**Do NOT use content-based deduplication** (e.g., "if we've seen this string before, reuse the index"). OCaml doesn't do this—it uses pointer identity from the actual code flow. The only way to achieve parity is to replicate the exact same allocation patterns.

**⚠️ STRING SHARING: Use StrIdx, NOT content-based interning**

For strings in the AST (identifiers, labels, file names), use `StrIdx` arena indices to control sharing:
- **Same StrIdx = same object** - Will be shared in marshal output via back-references
- **Different StrIdx = different objects** - Even if content is identical, will NOT be shared
- **Do NOT intern strings automatically** - Don't use hash-based deduplication in the marshal writer
- **Pass StrIdx by reference** - When OCaml passes the same string reference, use the same StrIdx in Rust

Example: For punned labeled arguments like `~compare`, the label and identifier should use the SAME `StrIdx` because OCaml reuses the same string pointer. Create the StrIdx once and pass it to both the `ArgLabel` and the `Longident`.

To achieve binary parity, you MUST study the OCaml sources (tokenizer, parser, marshaller) to understand:
1. **When does OCaml construct NEW values?** - Look for `{...}` record literals, `::` cons operations, function calls that return new allocations
2. **When does OCaml pass EXISTING values by reference?** - Look for variables being passed directly, pattern match bindings that propagate references

Examples of what to look for in OCaml:
```ocaml
(* NEW allocation - each call creates a fresh string *)
let lid = Longident.Lident name in ...

(* SAME reference - passing the same variable *)
let loc = start_pos in
{ pexp_loc = loc; ... } (* loc is the SAME object as start_pos *)

(* NEW allocation - record literal creates new record *)
{ txt = s; loc = l } (* This is always a new allocation *)
```

The Rust implementation must replicate these EXACT allocation patterns using the arena:
- When OCaml creates a new value, Rust should push a new entry to the arena
- When OCaml passes the same value, Rust should reuse the same arena index
- The arena index becomes the "pointer identity" for marshalling purposes

**Do NOT assume values are always interned.** Some values may be shared in certain contexts but not others, depending on how the OCaml code flows. Always trace the exact code path in the OCaml implementation.

**⚠️ CORE PRINCIPLE: Replicate OCaml's memory allocation, not content**

OCaml constructs new values OR passes by reference. The Marshal implementation shares values according to how they were allocated by memory management—NOT based on content equality. We do NOT need content-based interning because that's not how OCaml works. Instead:

1. **Study the OCaml source code** - Look at how values are constructed and passed. If a value is bound to a variable and that variable is passed to multiple places, those are all the same reference.

2. **Create an arena for types that need sharing** - If the OCaml code shares values of a particular type (e.g., `Location.t`, `Longident.t`), ensure we have an arena for that type in `ParseArena`.

3. **Pass by arena index, not by value** - When the OCaml code passes a reference, use the same arena index in Rust. Do NOT push a new value into the arena—reuse the existing index.

4. **Push new values only when OCaml allocates** - When OCaml constructs a fresh value (record literal, function call returning new allocation), push a new entry to the arena.

If we do this consistently—replicating OCaml's exact allocation and reference patterns—the binary AST WILL match byte-for-byte.
64 changes: 64 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
# Claude Code Instructions

Please read and follow the instructions in [AGENTS.md](./AGENTS.md).

## ⚠️ CRITICAL: COMMIT YOUR CHANGES

**You MUST commit after completing any meaningful work.** This is non-negotiable.

### When to commit:
- ✅ After fixing a bug or issue
- ✅ After implementing a feature or part of a feature
- ✅ After refactoring code
- ✅ After improving parity (even 1 more test passing)
- ✅ Before switching to a different task
- ✅ Before investigating a problem (commit WIP first)
- ✅ At natural stopping points

### How to commit:
```bash
# Stage specific files (preferred)
git add path/to/changed/files

# Commit with descriptive message
git commit -m "$(cat <<'EOF'
Short description of what changed

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
```

**DO NOT** leave work uncommitted. If you made changes, commit them.

## CRITICAL: Document Your Learnings

**When you discover something useful, ALWAYS add it to CLAUDE.md or AGENTS.md.**

This includes:
- Commands that work (or don't work)
- Solutions to problems you encountered
- Gotchas or edge cases you discovered
- Debugging techniques that helped
- Patterns that solved an issue

**Don't let knowledge be lost.** If you figured something out the hard way, document it so you (or another agent) don't have to figure it out again.

## CRITICAL: Protect Uncommitted Work

**NEVER revert or discard uncommitted changes.** This has caused lost work multiple times.

When you have uncommitted changes and encounter issues:

1. **ALWAYS commit work-in-progress first** before any troubleshooting:
```bash
git add -A && git commit -m "WIP: [description of current state]"
```

2. **NEVER run these commands when there are uncommitted changes:**
- `git checkout -- <file>`
- `git checkout HEAD -- <path>`
- `git restore <file>`
- `git reset --hard`
- `git stash` (unless you immediately `git stash pop`)

3. **Make small, frequent commits** - every meaningful change should be committed, even if incomplete. Use "WIP:" prefix for work-in-progress commits.

4. **If tests fail or there are regressions**, commit the current state first, THEN investigate. You can always revert a commit, but you cannot recover uncommitted changes.
Loading