Skip to content

Overload show(io, mime, x) instead of show(io, x) for pretty-printing. #179

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

Closed
wants to merge 1 commit into from

Conversation

fredrikekre
Copy link
Contributor

I think the three-arg method is recommended for pretty-printing. Otherwise the pretty-printing leaks out in e.g. error messages.

@timholy
Copy link
Member

timholy commented Mar 18, 2019

If you can fix CI, I approve. Thanks!

@fredrikekre
Copy link
Contributor Author

The failures are doctest failures, and those make me think this is not a good change, since two-arg show is used when printing containers. For example the breakpoint example will turn from

julia> frame, bp = @interpret sum([1,2,5])
(Frame for sum(a::AbstractArray) in Base at reducedim.jl:645
c 1 645      1 ─      nothing
  2 645  645 │   %2 = (Base.#sum#538)(Colon(), #self#, a)
  3 645      └──      return %2
a = [1, 2, 5], breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:645, line 645))

to

julia> frame, bp = @interpret sum([1,2,5])
(Frame(JuliaInterpreter.FrameCode(sum(a::AbstractArray) in Base at reducedim.jl:648, CodeInfo(
1 ─      nothing
│   @ reducedim.jl:648 within `sum'
│   %2 = ($(QuoteNode(Base.#sum#558)))($(QuoteNode(Colon())), #self#, a)
└──      return %2
), Union{Compiled, Core.TypeMapEntry}[#undef, #undef, #undef], JuliaInterpreter.BreakpointState[JuliaInterpreter.BreakpointState(true, ##slotfunction#373), #undef, #undef], BitSet([2]), false), JuliaInterpreter.FrameData(Union{Nothing, Some{Any}}[Some(sum), Some([1, 2, 5])], Any[#undef, #undef, #undef], Any[], Int64[], Base.RefValue{Any}(nothing), Dict(:a => 2,Symbol("#self#") => 1), Any[]), 1, nothing, nothing), BreakpointRef(JuliaInterpreter.FrameCode(sum(a::AbstractArray) in Base at reducedim.jl:648, CodeInfo(
1 ─      nothing
│   @ reducedim.jl:648 within `sum'
│   %2 = ($(QuoteNode(Base.#sum#558)))($(QuoteNode(Colon())), #self#, a)
└──      return %2
), Union{Compiled, Core.TypeMapEntry}[#undef, #undef, #undef], JuliaInterpreter.BreakpointState[JuliaInterpreter.BreakpointState(true, ##slotfunction#373), #undef, #undef], BitSet([2]), false), 1, nothing))

because there is a tuple returned. The examples can of course be updated to display them separately like so:

julia> frame, bp = @interpret sum([1,2,5]);

julia> frame
Frame for sum(a::AbstractArray) in Base at reducedim.jl:648
c 1 648  1 ─      nothing
  2 648  │   @ reducedim.jl:648 within `sum'
  3 648  │   %2 = (Base.#sum#558)(Colon(), #self#, a)
Variable([1, 2, 5], :a, false)

julia> bp
breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:648, line 648)

I don't really know what is "correct", but from JuliaLang/julia#30757 (comment) it sounds like three-arg should be used for pretty-printing. Also, with the PR as is, the fact that both Method and CodeInfo pretty-prints with two-arg makes things look weird anyway.

@fredrikekre
Copy link
Contributor Author

Actually, the docs for show say that

The default MIME type is MIME"text/plain". There is a fallback definition for text/plain output that calls show with 2 arguments. Therefore, this case should be handled by defining a 2-argument show(io::IO, x::MyType) method.

which contradicts the link from the previous post.

@KristofferC
Copy link
Member

Think we just ignore this for now.

@fredrikekre fredrikekre deleted the fe/show branch August 16, 2019 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants