Actions
Bug #21339
openNamespace: `RubyVM::InstructionSequence.load_iseq` isn't called for the root namespace
Bug #21339: Namespace: `RubyVM::InstructionSequence.load_iseq` isn't called for the root namespace
ruby -v:
ruby 3.5.0dev (2025-05-14T12:41:46Z master b5575a80bc) +PRISM [arm64-darwin24]
Tags:
Description
File.write("/tmp/compile-cache.rb", <<~'RUBY') class << RubyVM::InstructionSequence def load_iseq(path) p [:load_iseq, path] RubyVM::InstructionSequence.compile_file(path) end end RUBY File.write("/tmp/test-file.rb", "") puts "main:" require "/tmp/compile-cache.rb" require "/tmp/test-file.rb" if ENV["RUBY_NAMESPACE"] puts "namespace:" ns = Namespace.new ns.require("/tmp/compile-cache.rb") ns.require("/tmp/test-file.rb") end Expected behavior:
I would expect load_iseq to be invoked both in the root namespace and the user namespace when RUBY_NAMESPACE=1.
Actual behavior:
Somehow it's only invoked in the user namespace:
main: [:compile_cache_setup] [:load_iseq, "/tmp/test-file.rb"] main: [:compile_cache_setup] namespace: [:compile_cache_setup] [:load_iseq, "/tmp/test-file.rb"] But I don't understand why.
Updated by mame (Yusuke Endoh) 6 months ago
It works as expected with --disable=gems.
$ RUBY_NAMESPACE=1 ./local/bin/ruby --disable=gems test.rb ./local/bin/ruby: warning: Namespace is experimental, and the behavior may change in the future! See doc/namespace.md for known issues, etc. main: [:load_iseq, "/tmp/test-file.rb"] namespace: [:load_iseq, "/tmp/test-file.rb"] But it does not by default.
$ RUBY_NAMESPACE=1 ./local/bin/ruby test.rb ./local/bin/ruby: warning: Namespace is experimental, and the behavior may change in the future! See doc/namespace.md for known issues, etc. main: namespace: [:load_iseq, "/tmp/test-file.rb"] The reason seems to be that rubygems's require monkey patch does not work in sub namespace.
# with RUBY_NAMESPACE=1 puts "main:" require "csv" #=> OK if ENV["RUBY_NAMESPACE"] puts "namespace:" ns = Namespace.new # csv is a bundled gem, so rubygems is needed to require it ns.require("csv") #=> cannot load such file -- csv (LoadError) end Thus, there are two problems
- load_iseq does not fire via RubyGems require monkey patch.
- RubyGems require monkey patch does not work in sub namespaces.
Updated by Eregon (Benoit Daloze) 6 months ago
- Related to Bug #21324: Namespace loads RubyGems in root Namespace but it should not added
Updated by Eregon (Benoit Daloze) 6 months ago
Basically dependent or even caused by #21324 then
Updated by hsbt (Hiroshi SHIBATA) 6 months ago
- Tags set to namespace
Actions