Repository navigation
Releases
v0.14.0
What's Changed
- ci: move the Go pin from 1.27.1 to 1.27.2 by @tannevaled in #53
- ci: install qemu-user, not the virtual qemu-user-static (Ubuntu 26.04) by @tannevaled in #56
- chore(deps): update dependency go to v1.27.3 by @tannevaled in #55
- token: a non-ASCII uppercase letter starts a CONSTANT, not a local by @tannevaled in #58
Full Changelog: v0.13.1...v0.14.0
v0.13.1 — an END block records no splat, instead of claiming one at index 0
Patch, as gorelease -base v0.13.0 reports: no exported API changed.
One line, and a Go zero value that means something
END { } desugars to at_exit { }, and the Block it built left SplatIndex
at Go's zero value. Zero is a perfectly good index, and this field's "no
splat" value is -1:
SplatIndex int // index of the top-level *splat param in Params, or -1So the block announced a *splat parameter at position 0 with no parameters to
hold it.
Nothing here crashed, which is why it lasted
A parser does not run what it builds, so the whole cost landed in a consumer.
go-embedded-ruby's compiler believed the claim and emitted a rest-binding that
read past an empty environment:
$ echo 'END { puts "E" }' > p.rb && rbgo p.rb
panic: runtime error: slice bounds out of range [:1] with capacity 0
$ echo $?
2An uncontained Go panic from ordinary Ruby — END has been in the language
since 1.0 — which for an embedder takes the host process down rather than
returning an error. Verified end to end with a replace directive: with this
one line, END, main + END, and BEGIN + main + END all match
MRI 4.0.7 byte for byte.
The guard, which is the part worth having
Two of the three &ast.Block literals in parser.go already set SplatIndex —
the two that build their value from parsed parameters. The one that forgot
is the one with no parameters to parse, and that is the shape any future
desugaring will have.
So the new test is an invariant, not a case: it parses a corpus and asserts,
over every Block in every tree, that SplatIndex is -1 or a valid index into
Params. It walks by reflection rather than a type switch, so a node added later
is covered without anyone remembering to extend the walker — not remembering is
the failure it exists to catch — and it fails when the walk finds no Block at
all, since a walk that read nothing looks exactly like a tree with no defects.
Both tests were checked in the reverse direction: reverting the one-line fix
turns both red.
Upgrading
go get github.com/go-ruby-parser/parser@v0.13.1
No API change. Any consumer that compiles a Block's parameters should take it:
the defect is invisible in the AST and only appears when something lowers it.
v0.13.0 — nested source is an error, not a crash
Bounds expression recursion, so deeply nested source is a parse error instead of taking the process down.
What it fixes
Deeply nested source overflowed the Go stack, which is a fatal error: rather than a panic: — recover() never sees it, so neither this package's own recover in Parse nor an embedder's could contain it, and the process died. x = + f(×50000, about 150 KB of source, was enough.
It matters beyond this repository because go-embedded-ruby/ruby calls Parse as the first statement of its public Run, so a host that merely compiles untrusted Ruby was exposed without ever executing it. Tracked as #48.
Behaviour change
Parse now returns parse error at line N: nesting of 32769 is too deep past the limit. Previously it either succeeded (up to ~45 000 levels) or killed the process. No exported API changed — the package still exports Parse alone — which is why this is a minor and not a major.
The limit sits between two measured bounds:
| nesting | counter units | |
|---|---|---|
deepest shape MRI 4.0.5 accepts (ruby -c → "Syntax OK") |
9 500 | 19 000 |
| the limit | — | 32 768 |
| deepest observed safe here | 45 000 | 90 000 |
1.7× above the first, 2.7× below the second. So nothing MRI accepts is newly rejected, and nothing reaches the Go stack's real ceiling.
Two things the measurement settled
Where to count. No single function sees every production: instrumenting four candidates at nesting 1000 showed parsePrimary reaching 1 (not 1001) for f { … }, and parseExprOrAssign reaching 2 for a ternary chain. The four productions that actually overflow route through parseExprOrAssign, ternary through parseTernary, so both carry the count. An assignment chain (y = ×N) recurses through parseExprOrAssign alone — which is why deleting its check as apparently-dead code would have left y = ×300000, 1.2 MB of source, with no guard at all.
The counter measures frames, not brackets, and the two differ by exactly 2× for bracket productions. A first revision set the limit to 16384 believing it counted brackets; that capped nesting at 8192 and rejected a shape MRI accepts. A limit that is too low is as much a defect as no limit, just a quieter one, and the suite pins both ends for that reason.
Why a frame count and not a byte budget
Go offers no portable stack-pointer read, and a saved stack address is useless as a baseline: the runtime copies a goroutine's stack when it grows, leaving the value stale by the relocation delta. MRI can budget bytes; we cannot. The honest consequence, recorded in the source, is that a production costing far more stack per frame than any probed would reach the real ceiling first.
For the dependent
go-embedded-ruby/ruby pins this module and needs a go.mod bump to pick the fix up; go-embedded-ruby/ruby#768 tracks the VM-side sibling of this defect.
🤖 Generated with Claude Code
v0.12.0
v0.11.1
v0.11.0
v0.10.0 — unary plus dispatches #+@
One behavioural fix, in the parser rather than in any consumer.
Unary plus dispatches #+@, except on a numeric literal (#45)
arg: tUPLUS arg calls call_uni_op(p, $2, idUPlus) (parse.y-ruby_4_0:3962), so unary plus is a method send. The parser elided it entirely.
MRI's rule is narrower than "always fold" or "always dispatch", and the exception is lexical — measured on ruby 4.0.5 with Integer#+@, Float#+@ and String#+@ each redefined:
+1, +1.5 |
the literal; nothing dispatched |
+"lit", +n, +(1), +(1 + 1) |
dispatched |
Only a plus directly before a numeric literal token is absorbed. A parenthesised literal is not, and neither is a variable holding a number.
Why it surfaced now. The elision was invisible while every string literal was mutable. Under # frozen_string_literal: true, +"..." is the ordinary way to ask a frozen literal for a mutable copy, and eliding the operator handed back the frozen literal:
# frozen_string_literal: true
buf = +"start"
buf << "-more" # ruby: "start-more" with the elision: FrozenErrorFor consumers
ast.UnaryExpr now carries Op: "+@" for the dispatching form — the method name to send, so it cannot be confused with binary +, the same convention ~ already uses. A consumer that treats an unknown unary Op as a method name needs no change; one that assumed unary plus never produced a node will now see one.
Measured through go-embedded-ruby/ruby with a local replace: all rows match ruby 4.0.5 byte for byte, precedence is unchanged (+2**3 is 8, +1.abs is 1), and its conformance sweep moves core/string/uplus_spec.rb 2 → 3 with core/string/uminus_spec.rb unmoved as the control. A consumer that freezes compiled bytecode will see its drift check fire, since the compiler now emits a send where it emitted nothing.
v0.9.0 — HashLit.Braced and Call.Paren
Two bits of written form that the AST was discarding. Both are additive fields with a false zero value, so every existing consumer compiles and behaves exactly as before; only a consumer that reads them changes.
HashLit.Braced (#42, closes #40)
f({k: 1}) and f(k: 1) produced the same node, so nothing downstream could tell a positional Hash from keywords.
The field mirrors MRI, which carries the same bit in the same place: primary: tLBRACE assoc_list '}' sets RNODE_HASH($$)->nd_brace = TRUE, while rb_node_hash_new leaves it 0 for hashes the grammar assembles, and aryset_check reads it back for exactly this question.
As in MRI it is not conditional on being an argument — x = {a: 1} is Braced too. A { that opens a block never reaches the hash-literal production, so obj.m {} builds no HashLit to misread.
Call.Paren (#43, closes #41)
foo and foo() produced the same node, so nothing downstream could tell MRI's VCALL from its FCALL — a difference that is observable: nope raises NameError, nope() raises NoMethodError.
Paren is written form and nothing else: true for an empty list foo(), false for puts 1, obj.m, and a[0] (brackets are not parentheses).
Deciding VCALL takes more than this one bit. foo! and foo? are FCALLs without parentheses (primary: tFID), and a literal block makes an FCALL too. The full rule, documented on the field:
Recv == nil && !Paren && len(Args) == 0 && Block == nil &&
name is a plain identifier (no trailing ! or ?)Notes
Both fields were derived from parse.y and checked against the running ruby 4.0.5 oracle. One case is worth knowing: the value-omitted shorthand {x:} is a VCALL under --parser=parse.y and an FCALL under Prism, which is the default on a +PRISM build. These changes follow parse.y.