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

RFC: "quiet" types for easier-to-read stack traces #48444

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented Jan 28, 2023

It is fairly common to define types with parameters whose only use is specialization (of code and memory layout), and printing those parameters everywhere can cause excessive noise. One motivating example is https://github.com/SciML/OrdinaryDiffEq.jl/blob/2eb73bed76c31248113fa8f3f05ff2f84448651a/src/integrators/type.jl#L80. The proposed feature here is to put Experimental.@quietparams in a struct declaration, and then printing instances and types within stacktraces will omit parameters, e.g.

julia> struct Foo{A,B,C}
       a::A
       b::B
       c::C
       Base.Experimental.@quietparams
       end

julia> map(error, [Foo((1,2),4,5)])
ERROR: Foo((1, 2), 4, 5)
Stacktrace:
 [1] error(s::Foo{...})
   @ Base ./error.jl:44

In the case of ODEIntegrator, each type can be multiple screens full of text and it is causing quite a problem.

@JeffBezanson JeffBezanson added the display and printing Aesthetics and correctness of printed representations of objects. label Jan 28, 2023
@Keno
Copy link
Member

Keno commented Jan 28, 2023

Why does this need a flag in the datatype rather than just having a macro that overrides is_quiet_type for the type in question?

@jw3126
Copy link
Contributor

jw3126 commented Jan 29, 2023

Could this be spelled:

struct Foo{A,B,C}
       a::A
       b::B
       c::C
end
Base.Experimental.@quietparams Foo

That would for instance allow silencing types you don't own in a debugging session.

@pablosanjose
Copy link
Contributor

This sounds useful.
Feature request: could one choose to silence some parameters and not others?

@timholy
Copy link
Member

timholy commented Jan 31, 2023

In case it affects thinking on this issue: I think our issues with type-printing go beyond this special case. Someday I'm planning on investigating whether all parameters in stack traces can initially be printed in "folded" form. Now that we have err we can revisit the stacktrace interactively, so printing in folded form is no longer truly lossy for deep debugging. These plans also vaguely include an interactive REPL mode for incrementally unfolding those parameters. To me this seems like a more comprehensive solution, and thus we might not need to add special language features for special cases that may fairly soon become redundant.

If someone gets excited about this and wants to beat me to the punch, that would be wonderful. But if that doesn't happen, it's on my (long) TODO list.

@antoine-levitt
Copy link
Contributor

FWIW, as a data point in this line of thinking, I've been using https://github.com/BioTurboNick/AbbreviatedStackTraces.jl in the "minimal" mode (one line per frame, with only the function name, without arguments) for a while now, and I very rarely have found the need to have the types of the arguments (or even the argument names).

@vtjnash
Copy link
Member

vtjnash commented Jan 31, 2023

I sort of like Tim's idea, where the REPL (with limited=true IOContext) skips showing the type details, but that logs and other non-interactive contexts continue to show all parameters, and err can access the whole content. This PR otherwise feels mildly hostile to developers, since I can no longer take a user's stacktrace and replicate it in Cthulhu from an arbitrary point to simulate what it was doing wrong.

@JeffBezanson
Copy link
Member Author

I agree it would be much better to have stacktraces in the REPL let you interactively expand type parameters.

@timholy
Copy link
Member

timholy commented Feb 7, 2023

We already have FoldingTrees' TreeMenu, how hard can it be? (Famous last words...)

@KristofferC
Copy link
Member

KristofferC commented Mar 21, 2023

Here are two reasonable paths forward (in mu mind):

  1. Do something specific for stacktraces (or maybe just limited=true IO. For example, just hide types parameters in stacktraces by default and have err show them with some opt in for showing type parameters by default. I don't think any interactive unfolding of type parameters are needed, either you want to see them or you don't.

  2. Do something like showargtype as Tim mentioned in Making stacktraces shorter (reducing the number of frames) #49044 (reply in thread). This would allow package authors to more precisely define how their type should be printed "conveniently". It is up to callers to decide whether to use show or showargtype. However, if everyone (including Base) starts using showargtype it would surely be just as vulnerable to invalidations? But at least things like string interpolation don't add backedges to it.

@timholy
Copy link
Member

timholy commented Mar 24, 2023

I'm going to be traveling all next week with very little availability, but if anyone wants to run with this, I just pushed a big head start: https://github.com/timholy/TypeTreesIO.jl. The idea is that whether we print abbreviated type info or have a full UI for folding parameters, it's probably best to have a tree organization of the information that could be printed. For example, if we want to print with a target of no more than 80 characters in the signature, it's probably best to use a homogeneous depth for all arguments and then print anything that's omitted as ....

Feel free to do whatever with that. Contact me by email, discourse, or slack if you're known to me and want an invitation to the repo.

@storopoli
Copy link
Contributor

We are getting lots of feedback from Pumas new users.
Even the advanced coders are overwhelmed by the huge stack traces they get.
So I think that something like this would great benefit not only these users but others as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. DO NOT MERGE Do not merge this PR!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants