* [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
@ 2025-05-01 7:43 mame (Yusuke Endoh) via ruby-core
2025-05-01 19:15 ` [ruby-core:121795] " tenderlovemaking (Aaron Patterson) via ruby-core
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-05-01 7:43 UTC (permalink / raw)
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #21298 has been reported by mame (Yusuke Endoh).
----------------------------------------
Bug #21298: `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
https://bugs.ruby-lang.org/issues/21298
* Author: mame (Yusuke Endoh)
* Status: Open
* Assignee: tenderlovemaking (Aaron Patterson)
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
`ObjectSpace.allocation_class_path` is an API that returns the class of `self` in the context where an object was allocated. However, due to recent optimizations in `Class#new` (#21254), the return value now changes depending on whether `TracePoint` is enabled.
```ruby
require "objspace"
class Foo
def test
obj = Object.new
ObjectSpace.allocation_class_path(obj)
end
end
ObjectSpace.trace_object_allocations_start
p Foo.new.test #=> 3.4.2: "Class", master: "Foo"
```
Previously, this returned `"Class"` (from the `Class#new` call frame), but in the master branch, the result is now `"Foo"` because that frame is gone.
I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
```ruby
p Foo.new.test #=> master: "Foo"
TracePoint.new {}.enable do
p Foo.new.test #=> master: "Class", expected: "Foo"
end
```
This makes behavior dependent on whether `TracePoint` is enabled, which can lead to confusion.
@ko1 @tenderlovemaking Can we make `ObjectSpace.allocation_class_path` consistently return the class from the `.new` call context, regardless of the `TracePoint` state?
---
I am facing a failure of the following test when code coverage (which uses `TracePoint`) is enabled:
https://github.com/ruby/ruby/blob/e8ad728209ee22136e61054fea74096b49088b8a/test/objspace/test_objspace.rb#L206
As a short-term workaround, I'm considering commenting out this test.
--
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] 5+ messages in thread
* [ruby-core:121795] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
2025-05-01 7:43 [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state mame (Yusuke Endoh) via ruby-core
@ 2025-05-01 19:15 ` tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-01 19:30 ` [ruby-core:121796] " tenderlovemaking (Aaron Patterson) via ruby-core
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: tenderlovemaking (Aaron Patterson) via ruby-core @ 2025-05-01 19:15 UTC (permalink / raw)
To: ruby-core; +Cc: tenderlovemaking (Aaron Patterson)
Issue #21298 has been updated by tenderlovemaking (Aaron Patterson).
mame (Yusuke Endoh) wrote:
> I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
Yes, we can keep the behavior consistent. I would rather keep the behavior consistent, but some TracePoint tests were expecting the frame so I tried to maintain backwards compatibility.
I sent a PR to make the behavior consistent [here](https://github.com/ruby/ruby/pull/13232).
----------------------------------------
Bug #21298: `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
https://bugs.ruby-lang.org/issues/21298#change-112860
* Author: mame (Yusuke Endoh)
* Status: Open
* Assignee: tenderlovemaking (Aaron Patterson)
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
`ObjectSpace.allocation_class_path` is an API that returns the class of `self` in the context where an object was allocated. However, due to recent optimizations in `Class#new` (#21254), the return value now changes depending on whether `TracePoint` is enabled.
```ruby
require "objspace"
class Foo
def test
obj = Object.new
ObjectSpace.allocation_class_path(obj)
end
end
ObjectSpace.trace_object_allocations_start
p Foo.new.test #=> 3.4.2: "Class", master: "Foo"
```
Previously, this returned `"Class"` (from the `Class#new` call frame), but in the master branch, the result is now `"Foo"` because that frame is gone.
I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
```ruby
p Foo.new.test #=> master: "Foo"
TracePoint.new {}.enable do
p Foo.new.test #=> master: "Class", expected: "Foo"
end
```
This makes behavior dependent on whether `TracePoint` is enabled, which can lead to confusion.
@ko1 @tenderlovemaking Can we make `ObjectSpace.allocation_class_path` consistently return the class from the `.new` call context, regardless of the `TracePoint` state?
---
I am facing a failure of the following test when code coverage (which uses `TracePoint`) is enabled:
https://github.com/ruby/ruby/blob/e8ad728209ee22136e61054fea74096b49088b8a/test/objspace/test_objspace.rb#L206
As a short-term workaround, I'm considering commenting out this test.
--
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] 5+ messages in thread
* [ruby-core:121796] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
2025-05-01 7:43 [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state mame (Yusuke Endoh) via ruby-core
2025-05-01 19:15 ` [ruby-core:121795] " tenderlovemaking (Aaron Patterson) via ruby-core
@ 2025-05-01 19:30 ` tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-02 0:14 ` [ruby-core:121797] " mame (Yusuke Endoh) via ruby-core
2025-05-05 5:27 ` [ruby-core:121827] " ktsj (Kazuki Tsujimoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: tenderlovemaking (Aaron Patterson) via ruby-core @ 2025-05-01 19:30 UTC (permalink / raw)
To: ruby-core; +Cc: tenderlovemaking (Aaron Patterson)
Issue #21298 has been updated by tenderlovemaking (Aaron Patterson).
I remember the problem now. `power_assert` expects to find the `Class#new` frame: https://github.com/ruby/ruby/actions/runs/14781787226/job/41502113192?pr=13232
I want to make the behavior consistent, but I'm not sure what to do about `power_assert`
----------------------------------------
Bug #21298: `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
https://bugs.ruby-lang.org/issues/21298#change-112861
* Author: mame (Yusuke Endoh)
* Status: Open
* Assignee: tenderlovemaking (Aaron Patterson)
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
`ObjectSpace.allocation_class_path` is an API that returns the class of `self` in the context where an object was allocated. However, due to recent optimizations in `Class#new` (#21254), the return value now changes depending on whether `TracePoint` is enabled.
```ruby
require "objspace"
class Foo
def test
obj = Object.new
ObjectSpace.allocation_class_path(obj)
end
end
ObjectSpace.trace_object_allocations_start
p Foo.new.test #=> 3.4.2: "Class", master: "Foo"
```
Previously, this returned `"Class"` (from the `Class#new` call frame), but in the master branch, the result is now `"Foo"` because that frame is gone.
I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
```ruby
p Foo.new.test #=> master: "Foo"
TracePoint.new {}.enable do
p Foo.new.test #=> master: "Class", expected: "Foo"
end
```
This makes behavior dependent on whether `TracePoint` is enabled, which can lead to confusion.
@ko1 @tenderlovemaking Can we make `ObjectSpace.allocation_class_path` consistently return the class from the `.new` call context, regardless of the `TracePoint` state?
---
I am facing a failure of the following test when code coverage (which uses `TracePoint`) is enabled:
https://github.com/ruby/ruby/blob/e8ad728209ee22136e61054fea74096b49088b8a/test/objspace/test_objspace.rb#L206
As a short-term workaround, I'm considering commenting out this test.
--
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] 5+ messages in thread
* [ruby-core:121797] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
2025-05-01 7:43 [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state mame (Yusuke Endoh) via ruby-core
2025-05-01 19:15 ` [ruby-core:121795] " tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-01 19:30 ` [ruby-core:121796] " tenderlovemaking (Aaron Patterson) via ruby-core
@ 2025-05-02 0:14 ` mame (Yusuke Endoh) via ruby-core
2025-05-05 5:27 ` [ruby-core:121827] " ktsj (Kazuki Tsujimoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-05-02 0:14 UTC (permalink / raw)
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #21298 has been updated by mame (Yusuke Endoh).
@tenderlovemaking Oh thank you!
@ktsj Would it be possible for `power_assert` to avoid depending on `Class#new` being present in the stack trace?
----------------------------------------
Bug #21298: `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
https://bugs.ruby-lang.org/issues/21298#change-112863
* Author: mame (Yusuke Endoh)
* Status: Open
* Assignee: tenderlovemaking (Aaron Patterson)
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
`ObjectSpace.allocation_class_path` is an API that returns the class of `self` in the context where an object was allocated. However, due to recent optimizations in `Class#new` (#21254), the return value now changes depending on whether `TracePoint` is enabled.
```ruby
require "objspace"
class Foo
def test
obj = Object.new
ObjectSpace.allocation_class_path(obj)
end
end
ObjectSpace.trace_object_allocations_start
p Foo.new.test #=> 3.4.2: "Class", master: "Foo"
```
Previously, this returned `"Class"` (from the `Class#new` call frame), but in the master branch, the result is now `"Foo"` because that frame is gone.
I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
```ruby
p Foo.new.test #=> master: "Foo"
TracePoint.new {}.enable do
p Foo.new.test #=> master: "Class", expected: "Foo"
end
```
This makes behavior dependent on whether `TracePoint` is enabled, which can lead to confusion.
@ko1 @tenderlovemaking Can we make `ObjectSpace.allocation_class_path` consistently return the class from the `.new` call context, regardless of the `TracePoint` state?
---
I am facing a failure of the following test when code coverage (which uses `TracePoint`) is enabled:
https://github.com/ruby/ruby/blob/e8ad728209ee22136e61054fea74096b49088b8a/test/objspace/test_objspace.rb#L206
As a short-term workaround, I'm considering commenting out this test.
--
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] 5+ messages in thread
* [ruby-core:121827] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
2025-05-01 7:43 [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state mame (Yusuke Endoh) via ruby-core
` (2 preceding siblings ...)
2025-05-02 0:14 ` [ruby-core:121797] " mame (Yusuke Endoh) via ruby-core
@ 2025-05-05 5:27 ` ktsj (Kazuki Tsujimoto) via ruby-core
3 siblings, 0 replies; 5+ messages in thread
From: ktsj (Kazuki Tsujimoto) via ruby-core @ 2025-05-05 5:27 UTC (permalink / raw)
To: ruby-core; +Cc: ktsj (Kazuki Tsujimoto)
Issue #21298 has been updated by ktsj (Kazuki Tsujimoto).
> Would it be possible for power_assert to avoid depending on Class#new being present in the stack trace?
I updated power_assert.
https://github.com/ruby/power_assert/pull/56
Now, it should work.
----------------------------------------
Bug #21298: `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state
https://bugs.ruby-lang.org/issues/21298#change-112890
* Author: mame (Yusuke Endoh)
* Status: Open
* Assignee: tenderlovemaking (Aaron Patterson)
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
`ObjectSpace.allocation_class_path` is an API that returns the class of `self` in the context where an object was allocated. However, due to recent optimizations in `Class#new` (#21254), the return value now changes depending on whether `TracePoint` is enabled.
```ruby
require "objspace"
class Foo
def test
obj = Object.new
ObjectSpace.allocation_class_path(obj)
end
end
ObjectSpace.trace_object_allocations_start
p Foo.new.test #=> 3.4.2: "Class", master: "Foo"
```
Previously, this returned `"Class"` (from the `Class#new` call frame), but in the master branch, the result is now `"Foo"` because that frame is gone.
I am ok for the incompatibility itself because I find the new behavior more intuitive and useful. However, there's an inconsistency: the optimization is disabled when `TracePoint` is enabled, causing the result to revert to the old behavior.
```ruby
p Foo.new.test #=> master: "Foo"
TracePoint.new {}.enable do
p Foo.new.test #=> master: "Class", expected: "Foo"
end
```
This makes behavior dependent on whether `TracePoint` is enabled, which can lead to confusion.
@ko1 @tenderlovemaking Can we make `ObjectSpace.allocation_class_path` consistently return the class from the `.new` call context, regardless of the `TracePoint` state?
---
I am facing a failure of the following test when code coverage (which uses `TracePoint`) is enabled:
https://github.com/ruby/ruby/blob/e8ad728209ee22136e61054fea74096b49088b8a/test/objspace/test_objspace.rb#L206
As a short-term workaround, I'm considering commenting out this test.
--
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] 5+ messages in thread
end of thread, other threads:[~2025-05-05 5:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-01 7:43 [ruby-core:121791] [Ruby Bug#21298] `ObjectSpace.allocation_class_path` returns inconsistent results depending on `TracePoint` state mame (Yusuke Endoh) via ruby-core
2025-05-01 19:15 ` [ruby-core:121795] " tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-01 19:30 ` [ruby-core:121796] " tenderlovemaking (Aaron Patterson) via ruby-core
2025-05-02 0:14 ` [ruby-core:121797] " mame (Yusuke Endoh) via ruby-core
2025-05-05 5:27 ` [ruby-core:121827] " ktsj (Kazuki Tsujimoto) 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).