Project

General

Profile

Actions

Bug #21334

closed

Namespaces and object reference sharing

Added by fxn (Xavier Noria) about 12 hours ago. Updated about 10 hours ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:122066]

Description

Implications related to builtin classes and modules

As we know, when a namespace is created, builtin classes in the namespace are as in the root one. This applies to all references to them, explicit or implicit.

This is at the core of the current implementation and semantics of namespaces.

However, the feature also allow object references to cross namespaces. For example, via method calls:

ns::Foo.m(ref)

And this has implications that do not seem good to me. Examples:

  1. If ref has an HTTP client in an attribute, that depends on a parser gem, which depends on a string utils gem, that adds blank? to String, that call is broken because the transitive code at some point may perhaps hit a blank? call, and the user has no way to tell.

  2. If ref is a reference created by a gem managed by Zeitwerk (there are hundreds), the call is broken too. When m uses ref, it might need to lazy load something, and that won't work because the Kernel#require and Module#const_added decorations are gone within the namespace.

Please, note whether a gem loads with Zeitwerk or not is transparent to the user of the gem, by design. How do gems load their code is a private matter that is not, and should not be, documented. So the user does not know.

Implications related to different gem versions

In the example above, ref could be an instance of an object that corresponds to v2.0 of a gem, and perhaps the code under the namespace has a transitive dependency on v1.0. Mixing such references seems like a receipt for a good amount of Paracetamol.

Proposal

This is all so brittle, that I would like to ask for a fundamental reconsideration of cross-namespace object reference passing.

The rules are consistent within a namespace, problem is opening that up to cross-namespace communication.

Maybe redefine communication across namespaces in a very restrictive way that make these issues by design. Maybe remove cross-namespace communication in this manner altogether. Or some other option people can think of.

Actions

Also available in: Atom PDF

Like2
Like0Like0Like1Like1Like0Like0