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

[prototype runtime] fails due to cannot load such file -- sorted_set with Ruby 3.0 #590

Open
ybiquitous opened this issue Feb 9, 2021 · 2 comments

Comments

@ybiquitous
Copy link
Contributor

ybiquitous commented Feb 9, 2021

Hello, I find a bug that the rbs prototype runtime Object command fails on Ruby 3.0 (it succeeds on Ruby 2.7).
Please see the reproduction below for details.

Reproduction

Note: I'm using Docker to reduce any environment-specific problems.

Ruby 3.0

rbs prototype runtime Object fails with LoadError:

$ docker run --rm -it rubylang/ruby:3.0.0-focal bash
# gem install rbs:1.0.4
Fetching rbs-1.0.4.gem
Successfully installed rbs-1.0.4
1 gem installed

# rbs prototype runtime Object
/usr/local/lib/ruby/3.0.0/set/sorted_set.rb:4:in `rescue in <top (required)>': The `SortedSet` class has been extracted from the `set` library.You must use the `sorted_set` gem or other alternatives. (RuntimeError)
	from /usr/local/lib/ruby/3.0.0/set/sorted_set.rb:1:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:305:in `const_get'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:305:in `block in generate_constants'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:304:in `each'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:304:in `generate_constants'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:385:in `generate_class'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:45:in `block in decls'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:42:in `each'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:42:in `decls'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/cli.rb:597:in `run_prototype'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/cli.rb:113:in `run'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/exe/rbs:7:in `<top (required)>'
	from /usr/local/bin/rbs:23:in `load'
	from /usr/local/bin/rbs:23:in `<main>'
<internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sorted_set (LoadError)
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/lib/ruby/3.0.0/set/sorted_set.rb:2:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:305:in `const_get'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:305:in `block in generate_constants'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:304:in `each'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:304:in `generate_constants'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:385:in `generate_class'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:45:in `block in decls'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:42:in `each'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/prototype/runtime.rb:42:in `decls'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/cli.rb:597:in `run_prototype'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/lib/rbs/cli.rb:113:in `run'
	from /usr/local/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/exe/rbs:7:in `<top (required)>'
	from /usr/local/bin/rbs:23:in `load'
	from /usr/local/bin/rbs:23:in `<main>'

Ruby 2.7

rbs prototype runtime Object has no problems:

$ docker run --rm -it rubylang/ruby:2.7.2-bionic bash
# gem install rbs:1.0.4
Fetching rbs-1.0.4.gem
Successfully installed rbs-1.0.4
1 gem installed

# rbs prototype runtime Object
class Object < BasicObject
  include PP::ObjectMixin

  include JSON::Ext::Generator::GeneratorMethods::Object

  include Kernel
end

Object::ARGF: ARGF.class

Object::ARGV: Array[untyped]

Object::CROSS_COMPILING: untyped?

Object::ENV: Object

Object::FALSE: bool

Object::NIL: untyped?

Object::RUBY_COPYRIGHT: String

Object::RUBY_DESCRIPTION: String

Object::RUBY_ENGINE: String

Object::RUBY_ENGINE_VERSION: String

Object::RUBY_PATCHLEVEL: Integer

Object::RUBY_PLATFORM: String

Object::RUBY_RELEASE_DATE: String

Object::RUBY_REVISION: String

Object::RUBY_VERSION: String

Object::STDERR: IO

Object::STDIN: IO

Object::STDOUT: IO

Object::TOPLEVEL_BINDING: Binding

Object::TRUE: bool

Environment

  • Ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
  • RBS: rbs 1.0.4
@ybiquitous ybiquitous changed the title [prototype runtime] fails due to cannot load such file -- sorted_set [prototype runtime] fails due to cannot load such file -- sorted_set with Ruby 3.0 Feb 9, 2021
@pocke
Copy link
Member

pocke commented Feb 11, 2021

SortedSet has been removed from set library since Ruby 3.0.0. But the SortedSet constant is still available as an autoload.
https://github.com/ruby/ruby/blob/v3_0_0/lib/set.rb#L692

rbs prototype runtime accesses all constants, so it causes an error.

I think we can suppress the error on const_get.

value = mod.const_get(name)

I got similar errors when I used prototype runtime for Rails gems, because they use autoload. If the error is suppressed, the errors for Rails gems will be also resolved.

@ybiquitous
Copy link
Contributor Author

@pocke Thank you for sharing it! I understand the cause.

It seems a bit weird to me that Object.constants includes SortedSet despite the sorted_set gem is not loaded... 🤔
But I cannot get any good idea to resolve this error. 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants