Project

General

Profile

Actions

Misc #21881

open

Split the root box into the (newer) root box and the source of copied user boxes

Misc #21881: Split the root box into the (newer) root box and the source of copied user boxes

Added by tagomoris (Satoshi Tagomori) 7 days ago. Updated 6 days ago.

Status:
Open
[ruby-dev:<unknown>]
Tags:

Description

Proposal

This ticket proposes to:

  • have a new box type: the "source" box, used as the source of copied boxes when user boxes are created
  • split the "source" box from the root box just before loading "prelude.rb" and "gem_prelude.rb"
  • load "prelude.rb" and "gem_prelude.rb" in the root box after the "source" box creation
  • load "prelude.rb" and "gem_prelude.rb" in user boxes in the last step of those creation

After this change, user boxes will be created very cleanly, without any side effects of codes that ran in the root box.

The boxes in the runtime (technically, it starts only with the "source", then the "root" will be split from the "source"):

[While runtime initialization]
- source (box_id=-1)

[Just before loading prelude]
- source (-1)
- root (0)

[After loading prelude]
- source (-1)
- root (0)
- main (1, copied from -1)

This idea is discussed here but I'm changing the names (root/builtin -> source/root) because the name and idea of the root box is known by Ruby users.

Definition changes

Currently (in Ruby 4.0), the prime classext (concatenated to RClass) is for the root box, and other optional classexts are for user boxes.
After this change, the prime classext is for the source box. Even the root box also uses optional classexts.

Motivation

The issues #21324 and #21830. RubyGems uses tons of .rb files and it loads/requires the files originally passed to Kernel#require or Kernel#load.
Before this change, files are correctly loaded into the caller (user) box using an heuristic rule about the current/loading box.
But the above change uses a more solid/non-heuristic rule to determine the current box, and as the result of it, RubyGems wrongly loads scripts into the root box.

The solution is to load RubyGems in each user box. But the root box also needs to load RubyGems, and if user boxes are copied from the root box, user boxes can't load its own RubyGems.
(A new mechanism to forcibly overwrite existing definitions is another option, but it looks too risky to introduce such new feature only for loading RubyGems in the root box.)

So, the stored idea comes up again. Having the "source" box cleanly separated from the root box can solve this situation.

Actions

Also available in: PDF Atom