rbs icon indicating copy to clipboard operation
rbs copied to clipboard

RubyVM usage

Open eregon opened this issue 5 years ago • 8 comments

Hello, it seems that currently rbs uses RubyVM::AbstractSyntaxTree in a couple places: https://github.com/ruby/rbs/search?q=RubyVM&unscoped_q=RubyVM

However, RubyVM by design is MRI-only and is expected to not exist as a constant on alternative Ruby implementations (documentation).

Do you plan to address this somehow? If AbstractSyntaxTree is needed by rbs then I think it's time to move it somewhere outside of RubyVM.

For instance, when running on TruffleRuby:

% rbs prototype rb lib/person.rb lib/email.rb lib/phone.rb
/Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/prototype/rb.rb:55:in `const_missing': uninitialized constant RBS::Prototype::RB::RubyVM (NameError)
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/prototype/rb.rb:55:in `parse'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/cli.rb:629:in `block in run_prototype_file'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/cli.rb:628:in `each'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/cli.rb:628:in `run_prototype_file'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/cli.rb:526:in `run_prototype'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/lib/rbs/cli.rb:92:in `run'
	from /Users/bfish/Documents/truffleruby-ws/truffleruby/mxbuild/truffleruby-native/jre/languages/ruby/lib/gems/gems/rbs-0.7.0/exe/rbs:7:in `<top (required)>'
	from <internal:core> core/kernel.rb:395:in `load'
	from <internal:core> core/kernel.rb:395:in `load'
	from /Users/bfish/.rbenv/versions/tr-native/bin/rbs:23:in `<main>'

cc @bjfish

Relates to https://github.com/oracle/truffleruby/issues/1671

eregon avatar Jul 30 '20 16:07 eregon

Good point!

I decided to use RubyVM::AbstractSyntaxTree because it's included MRuby and doesn't require additional dependencies. One option would be to make prototype commands an external library and uses parser gem (or something else if exists.)

soutaro avatar Jul 31 '20 06:07 soutaro

because it's included MRuby

You mean CRuby, right? I think MRuby doesn't have RubyVM.

One option would be to make prototype commands an external library and uses parser gem (or something else if exists.)

Right, I think that would make sense.

I think moving and stabilizing AbstractSyntaxTree would also be valuable, it seems a few gems decided to use RubyVM::AbstractSyntaxTree but do not realize this is making the gem not portable across Ruby implementations, and using something experimental and unstable. (Just moving under ExperimentalFeatures would also be an option if not making it stable at the same time)

eregon avatar Jul 31 '20 09:07 eregon

Oh sorry, I mixed CRuby and MRI...

It's great to me too if AbstractSyntaxTree is stable and portable.

I think showing a better error message and exit gracefully is the first step we can do now.

soutaro avatar Jul 31 '20 14:07 soutaro

I don't think printing error messages is the best solution for this. Contributions for improvement are welcome.

soutaro avatar Aug 01 '20 10:08 soutaro

Could we leave the issue opened? The error message is an improvement but the original issue is still there: rbs prototype only works on CRuby.

eregon avatar Aug 01 '20 12:08 eregon

I posted a comment related to this on the RubyVM::AbstractSyntaxTree on the CRuby tracker: https://bugs.ruby-lang.org/issues/14844#note-25

eregon avatar Aug 01 '20 13:08 eregon

Okay. Reopening this issue. (I don't think I have bandwidth to do this for a while, but someone else would have!)

soutaro avatar Aug 01 '20 14:08 soutaro

FYI, a report about this on the truffleruby tracker: https://github.com/oracle/truffleruby/issues/2691

eregon avatar Jul 16 '22 09:07 eregon