-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
errorshow: simplify printing of keyword argument types using a new macro format #49959
Merged
Commits on May 31, 2023
-
RFC: errorshow: simplify printing of keyword argument types using a n…
…ew macro format In Julia, keyword arguments are represented as `Base.Pairs` objects. However, the object type often appears unnecessarily complex, especially when printed in a stack trace. This commit aims to simplify the printing of stack traces that involve keyword method calls, while still allowing us to reconstruct the actual method signature types from the printed signature types. The approach is similar to #49117: this commit introduces a new macro called `Base.@Kwargs`. It follows the same syntax as `@NamedTuple` and returns a `Base.Pairs` type that is used for keyword method calls. We use this syntax when printing keyword argument types. Here's an example of a stack trace: ```diff diff --git a/b.jl b/a.jl index 91dd6f0464..b804ae4be5 100644 --- a/b.jl +++ b/a.jl @@ -22,12 +22,11 @@ Stacktrace: @ Base ./reduce.jl:44 [inlined] [6] mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String; init::Int64) @ Base ./reduce.jl:175 [inlined] - [7] mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::Base.Pairs{…}) + [7] mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:307 [inlined] - [8] sum(f::typeof(identity), a::String; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, @NamedTuple{init::Int64}}) + [8] sum(f::typeof(identity), a::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:535 [inlined] - [9] sum(a::String; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, @NamedTuple{init::Int64}}) + [9] sum(a::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:564 [inlined] [10] top-level scope ``` Feel free to share any comments or suggestions. If this idea seems acceptable, I will add test cases and also address any broken test cases.
Configuration menu - View commit details
-
Copy full SHA for 60d0d89 - Browse repository at this point
Copy the full SHA 60d0d89View commit details -
Configuration menu - View commit details
-
Copy full SHA for 439d0da - Browse repository at this point
Copy the full SHA 439d0daView commit details -
use the
@Kwargs
syntax only when printing kwmethod signature within…… stack trace view And add tests.
Configuration menu - View commit details
-
Copy full SHA for 2e5a493 - Browse repository at this point
Copy the full SHA 2e5a493View commit details -
Configuration menu - View commit details
-
Copy full SHA for a864dc2 - Browse repository at this point
Copy the full SHA a864dc2View commit details -
Configuration menu - View commit details
-
Copy full SHA for ecb276c - Browse repository at this point
Copy the full SHA ecb276cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 400a6bc - Browse repository at this point
Copy the full SHA 400a6bcView commit details -
enable the type-repr simplification unconditionally in the stack trace
Since keyword pairs can appear within positional arguments, it can be confusing if we print the same type with different representations.
Configuration menu - View commit details
-
Copy full SHA for d3c734a - Browse repository at this point
Copy the full SHA d3c734aView commit details -
Configuration menu - View commit details
-
Copy full SHA for e8e5990 - Browse repository at this point
Copy the full SHA e8e5990View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3adafca - Browse repository at this point
Copy the full SHA 3adafcaView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4a00980 - Browse repository at this point
Copy the full SHA 4a00980View commit details
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.