Skip to content

Read the instructions array patterns use from persisted IR - #9837

Open
sferik wants to merge 1 commit into
jruby:masterfrom
sferik:ir-persist-int-temp
Open

sferik wants to merge 1 commit into
jruby:masterfrom
sferik:ir-persist-int-temp

Conversation

@sferik

@sferik sferik commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #9834.

Loading a jrubyc-compiled file that uses an array pattern, like [1] in [1], failed with a NullPointerException while reading the persisted IR. The first problem was in TemporaryLocalVariable.decode, which had no case for INT, so the TemporaryIntVariables that array patterns use for the length, rest count and indexes decoded as null and the reader lost its place.

Fixing that turned up the next one: IRReaderStream couldn't read b_int, int_math or as_fixnum either. All three instruction classes already had a decode method, but nothing called them. And IntegerMathInstr never wrote its two operands, so it couldn't have been read back regardless. It now writes them in the order its decode reads them.

I checked the reader's switch against every operation. The other ones it doesn't handle either have no decode method at all or are only added by optimization passes, so I left them alone.

The new spec runs array patterns, including a rest pattern that exercises int_math, in all four compile modes, and the persistence mode fails without this change. I also compiled several pattern forms with jrubyc, including rest and find patterns, and they now load and give the same results as CRuby.

@sferik
sferik force-pushed the ir-persist-int-temp branch from 7c86f75 to 0103757 Compare October 20, 2026 02:21
Array patterns compile to instructions that IRReaderStream couldn't
read back: TemporaryIntVariable operands, b_int, int_math and
as_fixnum. Each class already had a decode method, but the reader's
switches never called them, so loading a jrubyc-compiled file with an
array pattern failed with a NullPointerException.

IntegerMathInstr also didn't write its operands, so it couldn't have
been read back even with a reader case. It now writes them in the order
its decode method reads them.

Fixes jruby#9834
@sferik
sferik force-pushed the ir-persist-int-temp branch from 0103757 to dfb2a7e Compare October 20, 2026 02:53
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.

jrubyc-compiled code with an array pattern fails to load (NullPointerException reading persisted IR)

1 participant