Repository navigation
Support Ruby implementations without Ractor or RubyVM - #86
Open
sampokuokkanen wants to merge 2 commits into
Open
sampokuokkanen wants to merge 2 commits into
sampokuokkanen wants to merge 2 commits into
Conversation
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.
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
error_highlight uses
RactorandRubyVMunconditionally. On JRuby, which has neither, formatting an error message fails withNameError: uninitialized constant ErrorHighlight::RubyVM, and changing the formatter settings fails with...DefaultFormatter::Ractor.With this change, implementations without them fall back gracefully:
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::AbstractSyntaxTreeis only used when it exists. Other implementations can provide nodes throughThread::Backtrace::Location#syntax_tree(7755b9b); otherwisespotreturnsniland no snippet is shown.TruffleRuby currently patches its bundled copy around the same problem (switching to fiber-local
Thread.currentstorage and skippingNameErrorhighlighting), and could drop those patches with this.