-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
975: Truncate printing of ClimaCore field types r=charleskawczynski a=charleskawczynski Who wants shorter stack traces? 📒 This PR truncates printing for ClimaCore Field types (which people may know can be pretty long). Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ClimaCore | ||
|
||
function Base.show(io::IO, ::Type{T}) where {T <: ClimaCore.Fields.Field} | ||
values_type(::Type{T}) where {V, T <: ClimaCore.Fields.Field{V}} = V | ||
V = values_type(T) | ||
|
||
_apply!(f, ::T, match_list) where {T} = nothing # sometimes we need this... | ||
function _apply!(f, ::Type{T}, match_list) where {T} | ||
if f(T) | ||
push!(match_list, T) | ||
end | ||
for p in T.parameters | ||
_apply!(f, p, match_list) | ||
end | ||
end | ||
#= | ||
apply(::T) where {T <: Any} | ||
Recursively traverse type `T` and apply | ||
`f` to the types (and type parameters). | ||
Returns a list of matches where `f(T)` is true. | ||
=# | ||
apply(f, ::T) where {T} = apply(f, T) | ||
function apply(f, ::Type{T}) where {T} | ||
match_list = [] | ||
_apply!(f, T, match_list) | ||
return match_list | ||
end | ||
|
||
nts = apply(x -> x <: NamedTuple, eltype(V)) | ||
syms = unique(map(nt -> fieldnames(nt), nts)) | ||
s = join(syms, ",") | ||
print(io, "Field{$s} (trunc disp)") | ||
end |