ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
@ 2025-05-10  9:12 fxn (Xavier Noria) via ruby-core
  2025-05-10  9:40 ` [ruby-core:121974] " fxn (Xavier Noria) via ruby-core
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-10  9:12 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been reported by fxn (Xavier Noria).

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:121974] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
@ 2025-05-10  9:40 ` fxn (Xavier Noria) via ruby-core
  2025-05-10  9:50 ` [ruby-core:121975] " fxn (Xavier Noria) via ruby-core
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-10  9:40 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


> I believe this is consistent with the feature

I say so in the sense that objects with the same ID are equal in the namespace.

However, it could be argued that it is not consistent with Ruby. `Object` stores a class object, just after `X = 1` `X` stores a integer.

So, I am doing a method call passing an object, and the method is not receiving the same thing.

So, there is a tension between the feature and this basic aspec of the language, in my view.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113089

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:121975] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
  2025-05-10  9:40 ` [ruby-core:121974] " fxn (Xavier Noria) via ruby-core
@ 2025-05-10  9:50 ` fxn (Xavier Noria) via ruby-core
  2025-05-10 12:20 ` [ruby-core:121985] " Eregon (Benoit Daloze) via ruby-core
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-10  9:50 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


For example, if I instead fo

```ruby
ns = Namespace.new
ns.require_relative 'foo'

c = Class.new
c::X = 1
ns::C.x(c)
```

then `obj::X` resolves as expected in the method.

Method calls somehow seems to be swapping `VALUE`s that correspond to builtin classes on the fly.

Please excuse I am not reading the source code to answer this myself, I do not know enough about CRuby internals to understand the patch and its implications.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113090

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:121985] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
  2025-05-10  9:40 ` [ruby-core:121974] " fxn (Xavier Noria) via ruby-core
  2025-05-10  9:50 ` [ruby-core:121975] " fxn (Xavier Noria) via ruby-core
@ 2025-05-10 12:20 ` Eregon (Benoit Daloze) via ruby-core
  2025-05-11 13:01 ` [ruby-core:122008] " fxn (Xavier Noria) via ruby-core
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-05-10 12:20 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #21322 has been updated by Eregon (Benoit Daloze).


Right, IOW it's the duality between builtin classes and other classes.
Builtin classes' constants, methods, ivar and cvars are all a copy per Namespace (and so potentially differ), even though for all builtin classes they are `equal?` with the corresponding builtin class in all namespaces.

I think that's part of what makes the semantics of Namespace complicated, but as I understand it's also part of the design of Namespace.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113101

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:122008] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
                   ` (2 preceding siblings ...)
  2025-05-10 12:20 ` [ruby-core:121985] " Eregon (Benoit Daloze) via ruby-core
@ 2025-05-11 13:01 ` fxn (Xavier Noria) via ruby-core
  2025-05-11 13:24 ` [ruby-core:122009] " fxn (Xavier Noria) via ruby-core
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-11 13:01 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


@eregon maybe, but the fact is that you pass an object, and the callee receives a different object. This is not consistent with the current language.

Ideas:

* Introduce the concept of "namespace-level root objects", documented to be swapped on the fly or something. Sounds too ad-hoc.
* Restricting method calls to primitive types.
* Disallowing cross-namespace constant access or method calls.

The last one would also fix that the design allows mixing objects from different versions of the same gem.

Implementation details aside, some conceptual solution has to be devised to make this sound.

BTW, my examples are synthetic. But for more practical minds, that `Object` could be an attribute three levels down the object tree from your namespace-level class instance.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113126

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:122009] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
                   ` (3 preceding siblings ...)
  2025-05-11 13:01 ` [ruby-core:122008] " fxn (Xavier Noria) via ruby-core
@ 2025-05-11 13:24 ` fxn (Xavier Noria) via ruby-core
  2025-05-11 15:44 ` [ruby-core:122018] " fxn (Xavier Noria) via ruby-core
  2025-05-13 22:20 ` [ruby-core:122067] " fxn (Xavier Noria) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-11 13:24 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


The third option is more aligned with my intuitive idea of a new entity with new rules. Instead of a container of methods and constants that `::` can work with, you may need a new kind of language-level entity an "isolate", a "cell", a "shield", something.


----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113127

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:122018] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
                   ` (4 preceding siblings ...)
  2025-05-11 13:24 ` [ruby-core:122009] " fxn (Xavier Noria) via ruby-core
@ 2025-05-11 15:44 ` fxn (Xavier Noria) via ruby-core
  2025-05-13 22:20 ` [ruby-core:122067] " fxn (Xavier Noria) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-11 15:44 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


We have followed the discussion in https://bugs.ruby-lang.org/issues/21311.

I may contribute a doc patch to explain the scope to which root object references behave differently in different namespaces.

A consequence of this design is that you will need to mark classes as "namespace-safe".

If your class depends on a core extension, instances of this class cannot be passed across namespaces.

That dependency may not be obvious, could come from a transitive dependency deep in your object tree.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113136

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:122067] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values
  2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
                   ` (5 preceding siblings ...)
  2025-05-11 15:44 ` [ruby-core:122018] " fxn (Xavier Noria) via ruby-core
@ 2025-05-13 22:20 ` fxn (Xavier Noria) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2025-05-13 22:20 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #21322 has been updated by fxn (Xavier Noria).


This ticket was kind of oriented to docs.

I believe the emphasis has to be different and have created https://bugs.ruby-lang.org/issues/21334.

This one can be close if you will.

----------------------------------------
Bug #21322: Namespaces and builtin classes as arguments and return values
https://bugs.ruby-lang.org/issues/21322#change-113219

* Author: fxn (Xavier Noria)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
@tagomoris thanks for the docs under `doc/namespace.md`.

Unless I missed it, I believe there is an edge case related to builtin classes (using the vocabulary there). Consider:

```ruby
# test.rb
ns = Namespace.new
ns.require_relative 'foo'

X = 1
ns::C.x(Object)

# foo.rb
class C
  def self.x(obj)
    obj::X
  end
end
```

`obj::X` raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in `foo.rb`. See what I mean?

I believe, from my tests, that something analogous happens if `ns::C.x` returns (the namespaced) `Object`. In the main namespace, you don't get the object passed up as-is.

I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-05-13 22:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-10  9:12 [ruby-core:121973] [Ruby Bug#21322] Namespaces and builtin classes as arguments and return values fxn (Xavier Noria) via ruby-core
2025-05-10  9:40 ` [ruby-core:121974] " fxn (Xavier Noria) via ruby-core
2025-05-10  9:50 ` [ruby-core:121975] " fxn (Xavier Noria) via ruby-core
2025-05-10 12:20 ` [ruby-core:121985] " Eregon (Benoit Daloze) via ruby-core
2025-05-11 13:01 ` [ruby-core:122008] " fxn (Xavier Noria) via ruby-core
2025-05-11 13:24 ` [ruby-core:122009] " fxn (Xavier Noria) via ruby-core
2025-05-11 15:44 ` [ruby-core:122018] " fxn (Xavier Noria) via ruby-core
2025-05-13 22:20 ` [ruby-core:122067] " fxn (Xavier Noria) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).