Skip to content

Add parsetree support for wildcards in simple expressions - #300

Closed
dra27 wants to merge 130 commits into
trunkfrom
upstream-Pexp_hole
Closed

dra27 wants to merge 130 commits into
trunkfrom
upstream-Pexp_hole

Conversation

@dra27

@dra27 dra27 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

This PR first extends the parser to recognise syntax errors specifically related to invalid uses of _ in more places. It then converts these illegal _ to a new parsetree node, moving the error handling for encountering them to the type checker. The value of this change is that ppxes can both transform parsetrees which include the new node, and also use the OCaml parser to parse attribute and extension point payloads which include them.

The names Pexp_hole and Pmod_hole originate from ocaml/merlin#1242 where they were temporarily part of Merlin's AST before being replaced with extensions in ocaml/merlin#1503 in order to remain compatible with ppx infrastructure. Pexp_hole returned in a (highly experimental) feature in oxcaml/oxcaml#3310 which introduced it to the (OxCaml) compiler. Although the feature in OxCaml remains incomplete, we have found the node to be very useful in ppxes, and the parsing was extended in oxcaml/oxcaml#4956 entirely with ppx use in mind. We think the node is a useful addition to the parsetree, even without a language feature that directly requires it. We haven't used Pmod_hole in ppxes, but the intention is that having both Pexp_hole and Pmod_hole in the AST means that Merlin can use it as well (see OxCaml's Merlin changes in oxcaml/oxcaml#6960).

The PR itself is five fairly straightforward commits, which are worth reviewing separately:

  • The first two add a parse-errors test which shows the existing fun_expr uses of _ displaying the existing "unexpected wildcard" parsing error, and all the additional simple_expr and module_expr points where a standard "syntax error" is displayed
  • The third commit (essentially taking the grammar changes of Parse Pexp_hole as a simple expression oxcaml/oxcaml#4956, without the parsetree node), extends the handling of _ to simple_expr, which can be seen in the parse-errors test output
  • The fourth commit then creates the parse tree node for Pexp_hole, removing the hack from the parser and instead converting the error to come directly from the type checker
  • The fifth commit does the same for Pmod_hole

There are various subtleties (visible in the reference files) to do with _ and ~/? corner cases. For information, the original work predates LLM-use - Claude's responsibility in this PR was rebasing the work from OxCaml, refactoring the work to be a syntax change, then a parsetree change, and adding the tests to demonstrate the effects.

Repository owner deleted a comment from github-actions Bot Jul 30, 2026
dra27 and others added 11 commits August 4, 2026 08:05
Switch the required autoconf to 2.72
runtime: Fix sigaltstack call with musl on certain Intel CPUs
Istackoffset allocated only n bytes, but slot_offset places outgoing
stack arguments at SP + reserved_stack_space + n, so a call with more
than 8 integer arguments overflowed into the caller's frame. Add
reserved_stack_space to the allocation (and release it on deallocation).
Previously we used r31 which is also the frame pointer register for
PPC64 so we move it to r23 (which is unused) and can use it as a frame
pointer register later on. Using r31 also lines up with C frame
pointer usage.
Without this patch, the openSUSE ocaml package builds would unpredictably
vary in hard to reproduce ways.

.depend makes root-directory targets (ocamldoc, the debugger, ...) depend
on otherlibs/str/str.cmi and otherlibs/unix/unix.cmi. Nothing stopped the
generic %.cmi rule of the root Makefile from building those itself, so
under make -j they were compiled either from the root directory or by
"make -C otherlibs", whichever got there first.

The two compilations do not agree on the source path they record in the
.cmi ("otherlibs/str/str.mli" vs "str.mli"), which changes the interface
digest. Since that digest is embedded in every .cmi/.cmt/.cmx/.cma/.cmxa
of every unit that (transitively) uses Str or Unix, a large part of the
installed tree ended up differing from one build to the next, including
ocamldoc, ocamldebug and all of otherlibs/{str,unix,systhreads}.

Give both files an empty recipe depending on otherlibraries, so the
generic rule no longer applies and "make -C otherlibs" is always the one
that compiles them.

And same for the .cmx variant.
@dra27 dra27 changed the title Upstream Pexp_hole Add parsetree support for wildcards in simple expressions Aug 6, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dra27-js
dra27-js force-pushed the upstream-Pexp_hole branch 2 times, most recently from 008e295 to 07d22b8 Compare August 6, 2026 13:29
hannesm and others added 20 commits September 10, 2026 12:52
add OSEC advisory reference
contributing: mention possibility to RFC; flatter alt contrib list
…pt-stream

Runtime events corrupt stream fix
Fixes ocaml#14151
…ds-direct

Add runtime events for direct major allocations and GC ramp-up
ocaml#14898: lambda/Translcore, do not trust GADT equations introduced by a partial match
…uctions-from-hacking

remove instructions for `opam custom-install`
The expansiveness check should consider effect cases
Weak.get_copy: copying continuations is unsafe, so don't copy them.
@dra27
dra27 force-pushed the upstream-Pexp_hole branch from 7c94e0d to 7fef74c Compare September 14, 2026 10:12
dra27 and others added 2 commits September 14, 2026 12:17
Record the current behaviour of the wildcard `_` appearing in expression
positions:
- `~_:` and `?_:` already lex as labels named `_`
- where a general expression can start, the parser recognizes `_` via
  an ad hoc rule in order to report a specific syntax error;
- where only a simple expression is allowed (function-argument
  positions), "_" is a plain syntax error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dra27
dra27 force-pushed the upstream-Pexp_hole branch 2 times, most recently from e5377da to c756769 Compare September 14, 2026 13:56
dra27 and others added 2 commits September 14, 2026 15:08
Parse `_` as Pexp_hole in simple_expr and as Pmod_hole in module_expr

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dra27
dra27 force-pushed the upstream-Pexp_hole branch from c756769 to a93cc68 Compare September 14, 2026 14:09
@dra27 dra27 closed this Sep 14, 2026
@dra27
dra27 deleted the upstream-Pexp_hole branch September 14, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.