Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated TracePoint #1943

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions core/trace_point.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# `:script_compiled`
# : new Ruby code compiled (with `eval`, `load` or `require`)
#
class TracePoint < Object
class TracePoint
# <!--
# rdoc-file=trace_point.rb
# - TracePoint.new(*events) { |obj| block } -> obj
Expand Down Expand Up @@ -110,7 +110,7 @@ class TracePoint < Object
#
# Access from other threads is also forbidden.
#
def initialize: (*Symbol events) { (TracePoint tp) -> void } -> void
def self.new: (*_ToSym events) { (instance tp) -> void } -> instance
sampersand marked this conversation as resolved.
Show resolved Hide resolved

# <!--
# rdoc-file=trace_point.rb
Expand Down Expand Up @@ -172,7 +172,7 @@ class TracePoint < Object
# (note that we needed to filter out calls by itself from :line handler,
# otherwise it will call itself infinitely).
#
def self.allow_reentry: () { () -> void } -> void
def self.allow_reentry: [T] () { (nil) -> T } -> T
sampersand marked this conversation as resolved.
Show resolved Hide resolved

# <!--
# rdoc-file=trace_point.rb
Expand All @@ -199,7 +199,7 @@ class TracePoint < Object
#
# trace.enabled? #=> true
#
def self.trace: (*Symbol events) { (TracePoint tp) -> void } -> TracePoint
def self.trace: (*_ToSym events) { (instance tp) -> void } -> instance

# <!--
# rdoc-file=trace_point.rb
Expand All @@ -218,7 +218,7 @@ class TracePoint < Object
# -->
# Return the called name of the method being called
#
def callee_id: () -> Symbol
def callee_id: () -> Symbol?

# <!--
# rdoc-file=trace_point.rb
Expand Down Expand Up @@ -257,7 +257,7 @@ class TracePoint < Object
# C.foo
# end
#
def defined_class: () -> Module
def defined_class: () -> (Class | Module)?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though Class | Module is technically Module, i think this is much clearer for the end-user

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Give the type a try.


# <!--
# rdoc-file=trace_point.rb
Expand Down Expand Up @@ -293,7 +293,7 @@ class TracePoint < Object
# #=> RuntimeError: access from outside
#
def disable: () -> bool
| () { () -> void } -> void
| [T] () { () -> T } -> T

# <!--
# rdoc-file=trace_point.rb
Expand Down Expand Up @@ -352,8 +352,8 @@ class TracePoint < Object
# trace.enable { p tp.lineno }
# #=> RuntimeError: access from outside
#
def enable: (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) -> bool
| [R] (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) { () -> R } -> R
def enable: (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) -> bool
| [T] (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) { () -> T } -> T
sampersand marked this conversation as resolved.
Show resolved Hide resolved

# <!--
# rdoc-file=trace_point.rb
Expand Down Expand Up @@ -395,7 +395,7 @@ class TracePoint < Object
# -->
# Return the name at the definition of the method being called
#
def method_id: () -> Symbol
def method_id: () -> Symbol?

# <!--
# rdoc-file=trace_point.rb
Expand All @@ -412,7 +412,7 @@ class TracePoint < Object
# Return the parameters definition of the method or block that the current hook
# belongs to. Format is the same as for Method#parameters
#
def parameters: () -> ::Array[[ :req | :opt | :rest | :keyreq | :key | :keyrest | :block, Symbol ] | [ :rest | :keyrest ]]
def parameters: () -> Method::param_types?

# <!--
# rdoc-file=trace_point.rb
Expand All @@ -421,7 +421,7 @@ class TracePoint < Object
# Value from exception raised on the `:raise` event, or rescued on the `:rescue`
# event.
#
def raised_exception: () -> untyped
def raised_exception: () -> Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the case of other events than :raise nor :rescue?

Suggested change
def raised_exception: () -> Exception
def raised_exception: () -> Exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call raised_exception and there's no exception, it raises an error:

$ ruby -e 'TracePoint.trace(:line) { p _1.raised_exception }; p 1'
<internal:trace_point>:402:in `raised_exception': not supported by this event (RuntimeError)
	from -e:1:in `block in <main>'
	from -e:1:in `<main>'


# <!--
# rdoc-file=trace_point.rb
Expand Down
Loading