Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Sep 28, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

nobu and others added 28 commits September 28, 2025 22:15
…al contexts

to fix inconsistent and wrong current namespace detections.

This includes:
* Moving load_path and related things from rb_vm_t to rb_namespace_t to simplify
  accessing those values via namespace (instead of accessing either vm or ns)
* Initializing root_namespace earlier and consolidate builtin_namespace into root_namespace
* Adding VM_FRAME_FLAG_NS_REQUIRE for checkpoints to detect a namespace to load/require files
* Removing implicit refinements in the root namespace which was used to determine
  the namespace to be loaded (replaced by VM_FRAME_FLAG_NS_REQUIRE)
* Removing namespaces from rb_proc_t because its namespace can be identified by lexical context
* Starting to use ep[VM_ENV_DATA_INDEX_SPECVAL] to store the current namespace when
  the frame type is MAGIC_TOP or MAGIC_CLASS (block handlers don't exist in this case)
Calling rb_current_namespace() in rb_namespace_current() means to show
the definition namespace of Namespace.current itself (it's the root always)
but the users' expectation is to show the namespace of the place where
the Namespace.current is called.
* checking all control frames (instead of filtering by VM_FRAME_RUBYFRAME_P)
  because VM_FRAME_FLAG_NS_REQUIRE is set on non-rubyframe
* skip frames of CFUNC in the root namespace for Kernel#require (etc) to avoid
  detecting the root namespace of those frames wrongly
* The current namespace should be based on the Ruby-level location (file, line no in .rb)
  and we can get it by LEP(ep) basically (VM_ENV_FLAG_LOCAL flag is set)
* But the control frame with VM_FRAME_MAGIC_CFUNC is also a LOCAL frame because
  it's a visible Ruby-level frame without block handlers
* So, for the namespace detection, LEP(ep) is not enough and we need to skip CFUNC
  frames to fetch the caller of such frames
…/pop

With this change, the argument code of Namespace#eval cannot refer local
variables around the calling line, but it should not be able to refer
these values. The code is evaluated in the receiver namespace, independently
from the local context.
* Originally, k0kubun added a change to respect namespace in gen_block_given
  d129669
* Just after the change, XrXr proposes a change on master and he says it can fix the problem
  around block_given?, and it has been merged into the master
  #14208
* tagomoris respect the commit on master then will see if it works
* rb_vm_current_namespace() returns main_namespace if it's ready,
  root_namespace otherwise on the top of main_stack.
@pull pull bot locked and limited conversation to collaborators Sep 28, 2025
@pull pull bot added the ⤵️ pull label Sep 28, 2025
@pull pull bot merged commit 9d9390a into turkdevops:master Sep 28, 2025
1 of 2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants