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

show_method_table error #49403

Closed
vtjnash opened this issue Apr 18, 2023 · 4 comments · Fixed by #52354
Closed

show_method_table error #49403

vtjnash opened this issue Apr 18, 2023 · 4 comments · Fixed by #52354
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:regression Regression in behavior compared to a previous version

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 18, 2023

#45069 seems to assume that mt[1] value is meaningful (though it seems probably never true), and crashes if is isn't

julia> @time methods(Base.Broadcast.BroadcastStyle, Tuple{Type{<:Any}})
  0.004502 seconds (2.26 k allocations: 75.891 KiB)
# 45 methods for type constructor:Error showing value of type Base.MethodList:
ERROR: "BroadcastStyle" is not defined in module RecursiveArrayTools
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] which(m::Module, s::Symbol)
    @ Base ./reflection.jl:1632
  [3] show_method_table(io::IOContext{Base.TTY}, ms::Base.MethodList, max::Int64, header::Bool)
    @ Base ./methodshow.jl:303
  [4] show_method_table
    @ ./methodshow.jl:289 [inlined]
  [5] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, ms::Base.MethodList)
    @ Base ./methodshow.jl:349
  [6] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:271
  [7] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:552
  [8] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:259
  [9] display(d::REPL.REPLDisplay, x::Any)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:276
 [10] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [11] #invokelatest#2
    @ ./essentials.jl:863 [inlined]
 [12] invokelatest
    @ ./essentials.jl:860 [inlined]
 [13] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:300
 [14] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:282
 [15] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:552
 [16] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:280
 [17] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:894
 [18] #invokelatest#2
    @ ./essentials.jl:863 [inlined]
 [19] invokelatest
    @ ./essentials.jl:860 [inlined]
 [20] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2648
 [21] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/julia/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1295
 [22] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:514
@vtjnash vtjnash added kind:regression Regression in behavior compared to a previous version domain:display and printing Aesthetics and correctness of printed representations of objects. labels Apr 18, 2023
@fredrikekre
Copy link
Member

Looks like a duplicate if #49382

@ararslan
Copy link
Member

ararslan commented Nov 6, 2023

Duplicate of #49382

@ararslan ararslan marked this as a duplicate of #49382 Nov 6, 2023
@persinammon
Copy link

persinammon commented Nov 20, 2023

Hi, I'm learning from this issue. I could not find the reference to mt[1], what is it? Is it clear what the underlying error is?

@ararslan
Copy link
Member

Hi @persinammon! I believe by mt[1], @vtjnash is actually referring to ms.ms[1] as in this line of the linked PR. Here, ms is a MethodList and its .ms field is an array of Methods, and the code is assuming that the location of the first method in that array is meaningful.

Taking the OpaqueClosure example from #52043:

julia> ms = methods(Core.OpaqueClosure);  # suppress output with ; to avoid the error

julia> ms.ms[1]
Core.OpaqueClosure(ir::Core.Compiler.IRCode, env...; nargs, isva, rt)
     @ Base.Experimental opaque_closure.jl:58

julia> (ms.ms[1].module, ms.ms[1].name)
(Base.Experimental, :OpaqueClosure)

julia> isdefined(ms.ms[1].module, ms.ms[1].name)
false

Since OpaqueClosure isn't defined in Base.Experimental, the call to which as in the linked PR errors.

ararslan added a commit that referenced this issue Nov 30, 2023
When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

To fix this, we can look through the available methods and choose the
first in which the type is defined in the method's module, falling back
to the method table's module otherwise.

Fixes #49382
Fixes #49403
Fixes #52043
ararslan added a commit that referenced this issue Dec 21, 2023
When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
ararslan added a commit that referenced this issue Dec 22, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
ararslan added a commit that referenced this issue Dec 22, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
(cherry picked from commit 40bc64c)
KristofferC pushed a commit that referenced this issue Dec 23, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
(cherry picked from commit 40bc64c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants