ruby / rbs

Type Signature for Ruby
Other
1.94k stars 212 forks source link

RubyVM usage #348

Open eregon opened 4 years ago

eregon commented 4 years ago

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

soutaro commented 4 years ago

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.)

eregon commented 4 years ago

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)

soutaro commented 4 years ago

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 commented 4 years ago

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

eregon commented 4 years ago

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 commented 4 years ago

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

soutaro commented 4 years ago

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

eregon commented 2 years ago

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