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

errorshow: simplify printing of keyword argument types using a new macro format #49959

Merged
merged 10 commits into from
May 31, 2023

Commits on May 31, 2023

  1. 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.
    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    60d0d89 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    439d0da View commit details
    Browse the repository at this point in the history
  3. use the @Kwargs syntax only when printing kwmethod signature within…

    … stack trace view
    
    And add tests.
    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    2e5a493 View commit details
    Browse the repository at this point in the history
  4. add news entry

    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    a864dc2 View commit details
    Browse the repository at this point in the history
  5. more type stability

    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    ecb276c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    400a6bc View commit details
    Browse the repository at this point in the history
  7. 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.
    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    d3c734a View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    e8e5990 View commit details
    Browse the repository at this point in the history
  9. add test for @Kwargs

    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    3adafca View commit details
    Browse the repository at this point in the history
  10. clean up test/errorshow.jl

    aviatesk committed May 31, 2023
    Configuration menu
    Copy the full SHA
    4a00980 View commit details
    Browse the repository at this point in the history