ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint
@ 2025-04-18  7:29 st0012 (Stan Lo) via ruby-core
  2025-04-26 18:25 ` [ruby-core:121738] " Eregon (Benoit Daloze) via ruby-core
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: st0012 (Stan Lo) via ruby-core @ 2025-04-18  7:29 UTC (permalink / raw)
  To: ruby-core; +Cc: st0012 (Stan Lo)

Issue #21272 has been reported by st0012 (Stan Lo).

----------------------------------------
Bug #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272

* Author: st0012 (Stan Lo)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:121738] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
@ 2025-04-26 18:25 ` Eregon (Benoit Daloze) via ruby-core
  2026-02-08  4:03 ` [ruby-core:124713] " cfis (Charlie Savage) via ruby-core
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-04-26 18:25 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


In my view, `Baz = Class.new` doesn't really "Start a class or module definition." it creates a class but there is no definition of it, no body.
Though `Baz = Class.new { ... }` would arguably start a definition/body, but then so would `Baz.class_exec { ... }` and that seems less reasonable to catch with a :class TracePoint.

I think unless there is a good motivating example to change behavior (which could be incompatible), it's better to just document it better, so I'd suggest opening a PR to document it better.

----------------------------------------
Bug #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-112793

* Author: st0012 (Stan Lo)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124713] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
  2025-04-26 18:25 ` [ruby-core:121738] " Eregon (Benoit Daloze) via ruby-core
@ 2026-02-08  4:03 ` cfis (Charlie Savage) via ruby-core
  2026-02-08 11:30 ` [ruby-core:124715] " Eregon (Benoit Daloze) via ruby-core
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2026-02-08  4:03 UTC (permalink / raw)
  To: ruby-core; +Cc: cfis (Charlie Savage)

Issue #21272 has been updated by cfis (Charlie Savage).


This is a difference in Ruby 4.0, all previous versions of Ruby send out a Class.new event. You can see this in the ruby-prof test suite which now has lots of new failures. For example this test now fails:




----------------------------------------
Bug #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116309

* Author: st0012 (Stan Lo)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124715] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
  2025-04-26 18:25 ` [ruby-core:121738] " Eregon (Benoit Daloze) via ruby-core
  2026-02-08  4:03 ` [ruby-core:124713] " cfis (Charlie Savage) via ruby-core
@ 2026-02-08 11:30 ` Eregon (Benoit Daloze) via ruby-core
  2026-02-08 11:30 ` [ruby-core:124716] [Ruby Feature#21272] " Eregon (Benoit Daloze) via ruby-core
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2026-02-08 11:30 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


cfis (Charlie Savage) wrote in #note-2:
> This is a difference in Ruby 4.0. Previous versions of Ruby sent out a Class.new event.

No they did not as far as I can see. Even Ruby 2.0.0 does not emit a `:class` tracepoint for `Class.new`:
```
$ ruby -ve 'TracePoint.trace(:class) { puts "class tp" }; p 1; class Foo; end; p 2; Class.new {}'
ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux]
1
class tp
2
$ ruby -ve 'TracePoint.trace(:class) { puts "class tp" }; p 1; class Foo; end; p 2; Class.new {}'
ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]
1
class tp
2
```

----------------------------------------
Bug #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116311

* Author: st0012 (Stan Lo)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124716] [Ruby Feature#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
                   ` (2 preceding siblings ...)
  2026-02-08 11:30 ` [ruby-core:124715] " Eregon (Benoit Daloze) via ruby-core
@ 2026-02-08 11:30 ` Eregon (Benoit Daloze) via ruby-core
  2026-02-08 11:34 ` [ruby-core:124717] " Eregon (Benoit Daloze) via ruby-core
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2026-02-08 11:30 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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

Tracker changed from Bug to Feature
Backport deleted (3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN)

Changing this to a feature request.

----------------------------------------
Feature #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116312

* Author: st0012 (Stan Lo)
* Status: Open
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124717] [Ruby Feature#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
                   ` (3 preceding siblings ...)
  2026-02-08 11:30 ` [ruby-core:124716] [Ruby Feature#21272] " Eregon (Benoit Daloze) via ruby-core
@ 2026-02-08 11:34 ` Eregon (Benoit Daloze) via ruby-core
  2026-02-09  4:04 ` [ruby-core:124722] " cfis (Charlie Savage) via ruby-core
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2026-02-08 11:34 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


@cfis I think you're thinking about `:call` TracePoints, that's unrelated to this issue and that did change in 4.0, see #21254 and #21298.

----------------------------------------
Feature #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116313

* Author: st0012 (Stan Lo)
* Status: Open
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124722] [Ruby Feature#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
                   ` (4 preceding siblings ...)
  2026-02-08 11:34 ` [ruby-core:124717] " Eregon (Benoit Daloze) via ruby-core
@ 2026-02-09  4:04 ` cfis (Charlie Savage) via ruby-core
  2026-02-09  8:28 ` [ruby-core:124729] " cfis (Charlie Savage) via ruby-core
  2026-02-09  9:33 ` [ruby-core:124730] " Eregon (Benoit Daloze) via ruby-core
  7 siblings, 0 replies; 9+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2026-02-09  4:04 UTC (permalink / raw)
  To: ruby-core; +Cc: cfis (Charlie Savage)

Issue #21272 has been updated by cfis (Charlie Savage).


@Eregon - Ah, you are right. Thanks for the pointers to the other issues. Reading them I can see that Class.new is eliminated but I also see this note:

> Before inlining, ObjectSpace would report the allocation class path and method id as Class#new which isn't very helpful. With the inlining patch, we can see that the object is allocated in Foo#test.

It seems like tracepoint doesn't report anything anymore though? Should I move my questions to those tickets? Thanks!

----------------------------------------
Feature #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116320

* Author: st0012 (Stan Lo)
* Status: Open
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124729] [Ruby Feature#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
                   ` (5 preceding siblings ...)
  2026-02-09  4:04 ` [ruby-core:124722] " cfis (Charlie Savage) via ruby-core
@ 2026-02-09  8:28 ` cfis (Charlie Savage) via ruby-core
  2026-02-09  9:33 ` [ruby-core:124730] " Eregon (Benoit Daloze) via ruby-core
  7 siblings, 0 replies; 9+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2026-02-09  8:28 UTC (permalink / raw)
  To: ruby-core; +Cc: cfis (Charlie Savage)

Issue #21272 has been updated by cfis (Charlie Savage).


Ok, I see, now its `Array#initialize` (or some such). That looks like a nice change, will update ruby-prof.

----------------------------------------
Feature #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116331

* Author: st0012 (Stan Lo)
* Status: Open
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

* [ruby-core:124730] [Ruby Feature#21272] Class.new doesn't trigger :class TracePoint
  2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
                   ` (6 preceding siblings ...)
  2026-02-09  8:28 ` [ruby-core:124729] " cfis (Charlie Savage) via ruby-core
@ 2026-02-09  9:33 ` Eregon (Benoit Daloze) via ruby-core
  7 siblings, 0 replies; 9+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2026-02-09  9:33 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


cfis (Charlie Savage) wrote in #note-6:
> Should I move my questions to those tickets?

Yes, or file a new ticket with a reproduction.

----------------------------------------
Feature #21272: Class.new doesn't trigger :class TracePoint
https://bugs.ruby-lang.org/issues/21272#change-116332

* Author: st0012 (Stan Lo)
* Status: Open
----------------------------------------
According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events):

> To filter what is traced, you can pass any of the following as events:
> 
> :class
> Start a class or module definition.

I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case.

Should we either support `Class.new`, or clarify the behaviour in documentation?

### Reproduction

```rb
TracePoint.trace(:class) do |tp|
  puts "Class created at line: #{tp.lineno}"
end

class Foo; end # Triggers the tracepoint

Baz = Class.new # Doesn't trigger the tracepoint

# ruby test.rb
# Class created at line: 5
```




-- 
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] 9+ messages in thread

end of thread, other threads:[~2026-02-09  9:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18  7:29 [ruby-core:121683] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint st0012 (Stan Lo) via ruby-core
2025-04-26 18:25 ` [ruby-core:121738] " Eregon (Benoit Daloze) via ruby-core
2026-02-08  4:03 ` [ruby-core:124713] " cfis (Charlie Savage) via ruby-core
2026-02-08 11:30 ` [ruby-core:124715] " Eregon (Benoit Daloze) via ruby-core
2026-02-08 11:30 ` [ruby-core:124716] [Ruby Feature#21272] " Eregon (Benoit Daloze) via ruby-core
2026-02-08 11:34 ` [ruby-core:124717] " Eregon (Benoit Daloze) via ruby-core
2026-02-09  4:04 ` [ruby-core:124722] " cfis (Charlie Savage) via ruby-core
2026-02-09  8:28 ` [ruby-core:124729] " cfis (Charlie Savage) via ruby-core
2026-02-09  9:33 ` [ruby-core:124730] " Eregon (Benoit Daloze) 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).