tecosaur / About.jl

Mirror of https://code.tecosaur.net/tec/About.jl
Mozilla Public License 2.0
119 stars 6 forks source link

about gives up with stacktrace for non-definite types #33

Open devel-chm opened 2 weeks ago

devel-chm commented 2 weeks ago

It would be more useful if about could report what it can rather than stopping with a stack trace/error and skipping the rest.

For example, if I have a type like this

julia> struct AA
              a::Int16
              b::Int32
              c::Vector{Int32}   # size(c) is given by b
          end

and I try about(AA) I get the following

julia> about(AA)
Concrete (padded) DataType defined in Main, 16B
  AA <: Any

Struct with 3 fields:
ERROR: Type Array does not have a definite size.
Stacktrace:
  [1] sizeof(x::Type)
    @ Base .\essentials.jl:631
  [2] (::About.var"#11#12"{DataType})(i::Int64)
    @ About C:\Software\dot_julia\packages\About\52iMk\src\types.jl:22
  [3] iterate
    @ .\generator.jl:47 [inlined]
  [4] collect_to!
    @ .\array.jl:892 [inlined]
  [5] collect_to_with_first!
    @ .\array.jl:870 [inlined]
  [6] _collect(c::UnitRange{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base .\array.jl:864
  [7] collect_similar
    @ .\array.jl:763 [inlined]
  [8] map
    @ .\abstractarray.jl:3285 [inlined]
  [9] structinfo
    @ C:\Software\dot_julia\packages\About\52iMk\src\types.jl:13 [inlined]
[10] about(io::Base.TTY, type::Type)
    @ About C:\Software\dot_julia\packages\About\52iMk\src\types.jl:63
[11] about(x::Type)
    @ About C:\Software\dot_julia\packages\About\52iMk\src\About.jl:201
[12] top-level scope
    @ REPL[38]:1
Some type information was truncated. Use `show(err)` to see complete types.

I would prefer a report more like this (I've made c an SVector so the full context would be visible without the stack trace:

julia> using StaticArrays
julia> struct AA
             a::Int16
             b::Int32
             c::SVector{5,Int32}
          end

julia> about(AA)
Concrete (padded) DataType defined in Main, 28B
  AA <: Any

Struct with 3 fields:
• a  Int16
• b  Int32
• c  SVector{5, Int32}

 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    2B+2B      4B                           20B

where c is reported as a Vector{Int32} along with an indication that the size is not definite. The byte size could be the pointer/ref size in the struct.