Conversation
topolarity
approved these changes
Apr 24, 2025
Member
topolarity
left a comment
There was a problem hiding this comment.
Thank you!
I have spent an embarrassing amount of time parsing a method signature to see which foo::Int64 was part of a NamedTuple and which needed to be deleted as part of the arguments
This looks very convenient 👍
Member
Author
|
Good observation! I just tried with named tuples to make sure, it works well: julia> f(x, y; z = 3) = x + y.a + z
f (generic function with 1 method)
julia> f((; k = current_task(), l = 3), (; a = 1, b = "hello"))
ERROR: MethodError: no method matching +(::@NamedTuple{k::Task, l::Int64}, ::Int64)
The function `+` exists, but no method is defined for this combination of argument types.
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:643
+(::BigInt, ::Union{Int16, Int32, Int64, Int8})
@ Base gmp.jl:554
+(::Base.CoreLogging.LogLevel, ::Integer)
@ Base logging/logging.jl:132
...
Stacktrace:
[1] +
@ ./operators.jl:643 [inlined]
[2] f(x::@NamedTuple{k::Task, l::Int64}, y::@NamedTuple{a::Int64, b::String}; z::Int64)
@ Main ./REPL[7]:1
[3] top-level scope
@ REPL[8]:1
[4] top-level scope
@ REPL:1
julia> @code_typed f(x::@NamedTuple{k::Task, l::Int64}, y::@NamedTuple{a::Int64, b::String}; z::Int64)
CodeInfo(
1 ─ nothing::Nothing
│ %2 = builtin Core.getfield(@_2, :z)::Int64
│ nothing::Nothing
│ nothing::Nothing
│ invoke Main.:(var"#f#3")(%2::Int64, @_3::typeof(f), x::@NamedTuple{k::Task, l::Int64}, y::@NamedTuple{a::Int64, b::String})::Union{}
└── unreachable
) => Union{}(now, if only we could step through that |
Member
|
This is a very nice enhancement, thanks! BTW this will really improve JET's usability. julia> using JET, Cthulhu
julia> @report_call sum("julia")
═════ 2 possible errors found ═════
┌ sum(a::String) @ Base ./reduce.jl:553
│┌ sum(a::String; kw::@Kwargs{}) @ Base ./reduce.jl:553
││┌ sum(f::typeof(identity), a::String) @ Base ./reduce.jl:524
│││┌ sum(f::typeof(identity), a::String; kw::@Kwargs{}) @ Base ./reduce.jl:524
││││┌ mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String) @ Base ./reduce.jl:299
│││││┌ mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::@Kwargs{}) @ Base ./reduce.jl:299
││││││┌ mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String) @ Base ./reduce.jl:167
│││││││┌ mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String; init::Base._InitialValue) @ Base ./reduce.jl:167
││││││││┌ mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::String) @ Base ./reduce.jl:36
│││││││││┌ foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::String) @ Base ./reduce.jl:40
││││││││││┌ _foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, init::Base._InitialValue, itr::String) @ Base ./reduce.jl:54
│││││││││││┌ (::Base.BottomRF{typeof(Base.add_sum)})(acc::Char, x::Char) @ Base ./reduce.jl:78
││││││││││││┌ add_sum(x::Char, y::Char) @ Base ./reduce.jl:16
│││││││││││││ no matching method found `+(::Char, ::Char)`: (x::Char + y::Char)
││││││││││││└────────────────────
│││││││││┌ foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::String) @ Base ./reduce.jl:41
││││││││││┌ reduce_empty_iter(op::Base.BottomRF{typeof(Base.add_sum)}, itr::String) @ Base ./reduce.jl:372
│││││││││││┌ reduce_empty_iter(op::Base.BottomRF{typeof(Base.add_sum)}, itr::String, ::Base.HasEltype) @ Base ./reduce.jl:373
││││││││││││┌ reduce_empty(op::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Char}) @ Base ./reduce.jl:349
│││││││││││││┌ reduce_empty(::typeof(Base.add_sum), ::Type{Char}) @ Base ./reduce.jl:342
││││││││││││││┌ reduce_empty(::typeof(+), ::Type{Char}) @ Base ./reduce.jl:335
│││││││││││││││ no matching method found `zero(::Type{Char})`: zero(T::Type{Char})
││││││││││││││└────────────────────
julia> @descend Base. mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::String)
mapfoldl_impl(f::F, op::OP, nt, itr) where {F, OP} @ Base ~/julia/julia/base/reduce.jl:34
... |
aviatesk
approved these changes
Apr 26, 2025
LebedevRI
pushed a commit
to LebedevRI/julia
that referenced
this pull request
May 2, 2025
…on macros (JuliaLang#58222) Continuing the work done at JuliaLang#57909, this PR adds support for the following syntax: ```julia @code_typed f(some_undef_var::Int) # some_undef_var is ignored, only the annotation is used @code_typed f(; x::Int) # same here, the name is used but not the value ``` This should allow us to copy and paste signatures found in stacktraces, such as ```julia julia> f(x; y = 3) = error() f (generic function with 1 method) julia> f(1) ERROR: Stacktrace: [1] error() @ Base ./error.jl:45 [2] f(x::Int64; y::Int64) @ Main ./REPL[40]:1 [3] top-level scope @ REPL[41]:1 julia> asin(-2) ERROR: DomainError with -2.0: asin(x) is not defined for |x| > 1. Stacktrace: [1] asin_domain_error(x::Float64) @ Base.Math ./special/trig.jl:429 [2] asin(x::Float64) @ Base.Math ./special/trig.jl:443 ``` where any function call may be copied and pasted into `@code_typed`, `@edit` etc as is, provided that the function and argument types are defined in the active module (i.e. `Main`). Thanks @topolarity for the idea. --------- Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing the work done at #57909, this PR adds support for the following syntax:
This should allow us to copy and paste signatures found in stacktraces, such as
where any function call may be copied and pasted into
@code_typed,@editetc as is, provided that the function and argument types are defined in the active module (i.e.Main).Thanks @topolarity for the idea.