Commit f244ad9
committed
RFC: errorshow: simplify printing of keyword argument types using a new 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.1 parent 1cc10a6 commit f244ad9
2 files changed
+46
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
498 | 505 | | |
499 | 506 | | |
500 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1057 | 1057 | | |
1058 | 1058 | | |
1059 | 1059 | | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
1060 | 1076 | | |
1061 | 1077 | | |
1062 | 1078 | | |
1063 | 1079 | | |
| 1080 | + | |
1064 | 1081 | | |
1065 | 1082 | | |
1066 | 1083 | | |
| |||
1094 | 1111 | | |
1095 | 1112 | | |
1096 | 1113 | | |
1097 | | - | |
1098 | 1114 | | |
1099 | 1115 | | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
1111 | | - | |
| 1116 | + | |
1112 | 1117 | | |
1113 | 1118 | | |
1114 | 1119 | | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
1115 | 1125 | | |
1116 | 1126 | | |
1117 | 1127 | | |
1118 | 1128 | | |
1119 | 1129 | | |
1120 | 1130 | | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1121 | 1147 | | |
1122 | 1148 | | |
1123 | 1149 | | |
| |||
0 commit comments