Project

General

Profile

Actions

Bug #21339

open

Namespace: `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

Added by byroot (Jean Boussier) 6 months ago. Updated 6 months ago.

Status:
Assigned
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-05-14T12:41:46Z master b5575a80bc) +PRISM [arm64-darwin24]
[ruby-core:122098]

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.


Related issues 1 (1 open0 closed)

Updated by mame (Yusuke Endoh) 6 months ago Actions #1 [ruby-core:122112]

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 Actions #2

  • Related to Bug #21324: Namespace loads RubyGems in root Namespace but it should not added

Updated by Eregon (Benoit Daloze) 6 months ago Actions #3 [ruby-core:122117]

Basically dependent or even caused by #21324 then

Updated by hsbt (Hiroshi SHIBATA) 6 months ago Actions #4

  • Tags set to namespace
Actions

Also available in: PDF Atom