Skip to content

Support Ruby implementations without Ractor or RubyVM - #86

Merged
mame merged 2 commits into
ruby:masterfrom
sampokuokkanen:support-without-ractor-rubyvm
Dec 2, 2026
Merged

mame merged 2 commits into
ruby:masterfrom
sampokuokkanen:support-without-ractor-rubyvm

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

error_highlight uses Ractor and RubyVM unconditionally. On JRuby, which has neither, formatting an error message fails with NameError: uninitialized constant ErrorHighlight::RubyVM, and changing the formatter settings fails with ...DefaultFormatter::Ractor.

With this change, implementations without them fall back gracefully:

  • Without Ractor, the formatter settings live in module instance variables. They're shared across threads like Ractor-local storage, so a formatter set at boot still applies in worker threads. I picked instance variables over a Hash because JRuby serializes concurrent ivar updates but doesn't make Hash thread-safe (https://github.com/jruby/jruby/wiki/Concurrency-in-jruby).
  • RubyVM::AbstractSyntaxTree is only used when it exists. Other implementations can provide nodes through Thread::Backtrace::Location#syntax_tree (7755b9b); otherwise spot returns nil and no snippet is shown.

TruffleRuby currently patches its bundled copy around the same problem (switching to fiber-local Thread.current storage and skipping NameError highlighting), and could drop those patches with this.

This is the first part of #72.

sampokuokkanen and others added 2 commits December 2, 2026 12:46
error_highlight referenced Ractor and RubyVM unconditionally. On JRuby,
which defines neither, formatting an error message fails with
`NameError: uninitialized constant ErrorHighlight::RubyVM`, and changing
the formatter settings fails with `NameError: uninitialized constant
ErrorHighlight::DefaultFormatter::Ractor`.

* When Ractor is not available, store the formatter settings in module
  instance variables. Like Ractor-local storage, they are shared by all
  threads. Unlike Hash, which is not thread-safe on JRuby, concurrent
  instance variable updates are serialized
  (https://github.com/jruby/jruby/wiki/Concurrency-in-jruby), so threads
  that format errors concurrently cannot corrupt the settings. Both
  storages are behind a private ErrorHighlight::LocalSettings module.
* Only consult RubyVM::AbstractSyntaxTree when it is defined. Other
  implementations can provide nodes through
  Thread::Backtrace::Location#syntax_tree; without it, spot returns nil.
* Guard the RubyVM references in the tests, and test the settings with
  Ractor hidden so that the non-Ractor storage also runs on CRuby.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruby loads error_highlight at boot unless it is disabled, so the child
process loaded it before the script hid Ractor and took the Ractor branch.
It only passed where RUBYOPT had --disable-error_highlight, and failed in
CI, where bundle exec also adds -rbundler/setup to RUBYOPT. Run the child
with --disable-gems and without RUBYOPT.
@mame
mame force-pushed the support-without-ractor-rubyvm branch from 17936d4 to 25e9e60 Compare December 2, 2026 03:46

@mame mame left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mame
mame merged commit aedccc6 into ruby:master Dec 2, 2026
9 checks passed
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.

2 participants