Skip to content

Commit

Permalink
Add examples to docstrings (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Aug 17, 2024
1 parent 6a6c12d commit 9615c0d
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ export ascend
Evaluates the arguments to the function or macro call, determines their
types, and calls [`descend_code_typed`](@ref) on the resulting expression.
See [`Cthulhu.CONFIG`](@ref) for options and their defaults.
# Examples
```julia
julia> @descend_code_typed sin(1)
[...]
julia> @descend_code_typed optimize=false sin(1)
[...]
```
"""
macro descend_code_typed(ex0...)
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :descend_code_typed, ex0)
Expand All @@ -126,6 +136,22 @@ end
Evaluates the arguments to the function or macro call, determines their
types, and calls [`descend_code_warntype`](@ref) on the resulting expression.
See [`Cthulhu.CONFIG`](@ref) for options and their defaults.
# Examples
```julia
julia> function foo()
T = rand() > 0.5 ? Int64 : Float64
sin(rand(T))
end
foo (generic function with 1 method)
julia> @descend_code_warntype foo()
[...]
julia> @descend_code_warntype hide_type_stable=true foo()
[...]
```
"""
macro descend_code_warntype(ex0...)
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :descend_code_warntype, ex0)
Expand All @@ -136,6 +162,16 @@ end
Evaluates the arguments to the function or macro call, determines their
types, and calls [`descend`](@ref) on the resulting expression.
See [`Cthulhu.CONFIG`](@ref) for options and their defaults.
# Examples
```julia
julia> @descend sin(1)
[...]
julia> @descend iswarn=false foo()
[...]
```
"""
macro descend(ex0...)
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :descend, ex0)
Expand All @@ -150,6 +186,7 @@ end
Given a function and a tuple-type, interactively explore the output of
`code_typed` by descending into `invoke` statements. Type enter to select an
`invoke` to descend into, select `↩` to ascend, and press `q` or `control-c` to quit.
See [`Cthulhu.CONFIG`](@ref) for `kwargs` and their defaults.
# Usage:
```julia
Expand All @@ -164,7 +201,7 @@ julia> descend_code_typed(Tuple{typeof(sin), Int})
julia> descend_code_typed() do
T = rand() > 0.5 ? Int64 : Float64
sin(rand(T)
sin(rand(T))
end
[...]
```
Expand All @@ -181,6 +218,7 @@ descend_code_typed(@nospecialize(args...); kwargs...) =
Given a function and a tuple-type, interactively explore the output of
`code_warntype` by descending into `invoke` statements. Type enter to select an
`invoke` to descend into, select `↩` to ascend, and press `q` or `control-c` to quit.
See [`Cthulhu.CONFIG`](@ref) for `kwargs` and their defaults.
# Usage:
```julia
Expand All @@ -195,7 +233,7 @@ julia> descend_code_warntype(Tuple{typeof(sin), Int})
julia> descend_code_warntype() do
T = rand() > 0.5 ? Int64 : Float64
sin(rand(T)
sin(rand(T))
end
[...]
```
Expand Down Expand Up @@ -245,6 +283,7 @@ default_terminal() = REPL.LineEdit.terminal(Base.active_repl)
Given a function and a tuple-type, interactively explore the source code of functions
annotated with inferred types by descending into `invoke` statements. Type enter to select an
`invoke` to descend into, select `↩` to ascend, and press `q` or `control-c` to quit.
See [`Cthulhu.CONFIG`](@ref) for `kwargs` and their defaults.
# Usage:
```julia
Expand All @@ -259,7 +298,7 @@ julia> descend(Tuple{typeof(sin), Int})
julia> descend() do
T = rand() > 0.5 ? Int64 : Float64
sin(rand(T)
sin(rand(T))
end
[...]
```
Expand Down

2 comments on commit 9615c0d

@timholy
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/113330

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.14.0 -m "<description of version>" 9615c0d08ac69b3eeeec2a4521d7a8011d7bdafe
git push origin v2.14.0

Please sign in to comment.