Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prism::VERSION can't be referred by non-main Ractor #3422

Closed
wanabe opened this issue Jan 18, 2025 · 0 comments · Fixed by #3424
Closed

Prism::VERSION can't be referred by non-main Ractor #3422

wanabe opened this issue Jan 18, 2025 · 0 comments · Fixed by #3424

Comments

@wanabe
Copy link

wanabe commented Jan 18, 2025

Hello,

I found that Prism::VERSION can't be referred by non-main Ractor.

$ ruby -rprism -e 'Ractor.new do Prism::VERSION end.take'
-e:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
#<Thread:0x00007f1b5a5704c8 run> terminated with exception (report_on_exception is true):
-e:1:in 'block in <main>': can not access non-shareable objects in constant Prism::VERSION by non-main Ractor. (Ractor::IsolationError)
<internal:ractor>:711:in 'Ractor#take': thrown by remote Ractor. (Ractor::RemoteError)
        from -e:1:in '<main>'
-e:1:in 'block in <main>': can not access non-shareable objects in constant Prism::VERSION by non-main Ractor. (Ractor::IsolationError)

This prevents error_highlight from working properly on non-main Ractor.

$ echo 'Ractor.new do unknown rescue $!.detailed_message end; sleep 0.1' > /tmp/a.rb; ruby /tmp/a.rb
/tmp/a.rb:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
#<Thread:0x00007f9d37061f18 run> terminated with exception (report_on_exception is true):
/home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:88:in 'ErrorHighlight.prism_find': can not access non-shareable objects in constant Prism::VERSION by non-main Ractor. (Ractor::IsolationError)
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:65:in 'ErrorHighlight.spot'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:6:in 'ErrorHighlight::CoreExt#generate_snippet'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:14:in 'ErrorHighlight::CoreExt#detailed_message'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/did_you_mean/core_ext/name_error.rb:24:in 'DidYouMean::Correctable#detailed_message'
        from /tmp/a.rb:1:in 'block in <main>'
<internal:ast>:96:in 'RubyVM::AbstractSyntaxTree.of': cannot get AST for ISEQ compiled by prism (RuntimeError)
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:59:in 'ErrorHighlight.spot'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:6:in 'ErrorHighlight::CoreExt#generate_snippet'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:14:in 'ErrorHighlight::CoreExt#detailed_message'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/did_you_mean/core_ext/name_error.rb:24:in 'DidYouMean::Correctable#detailed_message'
        from /tmp/a.rb:1:in 'block in <main>'
/home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:88:in 'ErrorHighlight.prism_find': can not access non-shareable objects in constant Prism::VERSION by non-main Ractor. (Ractor::IsolationError)
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:65:in 'ErrorHighlight.spot'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:6:in 'ErrorHighlight::CoreExt#generate_snippet'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:14:in 'ErrorHighlight::CoreExt#detailed_message'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/did_you_mean/core_ext/name_error.rb:11:in 'DidYouMean::Correctable#detailed_message'
        from /tmp/a.rb:1:in 'block in <main>'
<internal:ast>:96:in 'RubyVM::AbstractSyntaxTree.of': cannot get AST for ISEQ compiled by prism (RuntimeError)
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/base.rb:59:in 'ErrorHighlight.spot'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:6:in 'ErrorHighlight::CoreExt#generate_snippet'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/error_highlight/core_ext.rb:14:in 'ErrorHighlight::CoreExt#detailed_message'
        from /home/wanabe/.rbenv/versions/master/lib/ruby/3.5.0+0/did_you_mean/core_ext/name_error.rb:11:in 'DidYouMean::Correctable#detailed_message'
        from /tmp/a.rb:1:in 'block in <main>'

It is not impossible to solve this problem by calling Ractor.make_shareable or String#freeze by user program.
However, if the library can solve the problem, it would be more appreciated. (Perhaps similar to ruby/io-console#82)
Thank you to read.

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 a pull request may close this issue.

1 participant