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 fails with TypeConstructor #5497

Closed
stevengj opened this issue Jan 24, 2014 · 9 comments
Closed

show fails with TypeConstructor #5497

stevengj opened this issue Jan 24, 2014 · 9 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@stevengj
Copy link
Member

This afternoon, @StefanKarpinski and @loladiro and I hit a bug. If you type methods(+) in the REPL, you get:

ERROR: type TypeConstructor has no field name
 in show at show.jl:66
 in argtype_decl at methodshow.jl:18
 in arg_decl_parts at methodshow.jl:30
 in show at methodshow.jl:36
 in show_method_table at methodshow.jl:61
 in show at methodshow.jl:74
 in anonymous at show.jl:869
 in showlimited at show.jl:868
 in writemime at repl.jl:2
 in display at multimedia.jl:118
 in display at multimedia.jl:120
 in display at multimedia.jl:152

The problem seems to be that show(x::DataType) expects x.name.name to exist, but TypeConstructor (x.name?) does not have this field. (I'm actually not even sure what TypeConstructor is; I can't get it to show up reliably except via methods(+).)

I did a git bisect, and it claims the problem showed up in commit 2c2d165, but this seems kinda random to me.

@StefanKarpinski
Copy link
Member

Sure enough, reverting that changes fixes the issue, but why is that method even getting called at all?

@stevengj
Copy link
Member Author

show is getting called by string to convert some type to a string for display. But the weird thing is that I don't see how it is being called for a MIME type.

@stevengj
Copy link
Member Author

The weird thing is that the TypeConstructor exception is being thrown for the display of the +(DiagonalMatrix, Matrix) method, which has nothing to do with MIME types. It's barfing on string(Matrix), I think, but only in this context.

My current theory is that we are seeing a random side effect of some other bug in Julia.

@StefanKarpinski
Copy link
Member

Yeah, that's why I'm hesitating to just revert that change – I think this is exposing some other breakage.

@carlobaldassi
Copy link
Member

I found out that the bug is intermittent, things sometimes work when restarting julia. However, reverting that commit makes it disappear for some reason.

Also, this can be reproduced as simply as this:

julia> g(a::Matrix) = 1
g (generic function with 1 method)

julia> methods(g)
# 1 method for generic function "g":
gEvaluation succeeded, but an error occurred while showing value of type MethodTable:
ERROR: type TypeConstructor has no field name
 in show at show.jl:66
 in argtype_decl at methodshow.jl:18
 in arg_decl_parts at methodshow.jl:30
 in show at methodshow.jl:36
 in show_method_table at methodshow.jl:61
 in show at methodshow.jl:74
 in anonymous at show.jl:869
 in showlimited at show.jl:868
 in writemime at repl.jl:2
 in display at multimedia.jl:118
 in display at multimedia.jl:120
 in display at multimedia.jl:152

More data: say we have put the TypeConstructor into a variable xs:

julia> xs = g.env.defs.sig[1]
Array{T,2}

julia> typeof(xs)
TypeConstructor

the bug shows up when calling show with a IOBuffer as a first argument, but not on STDIO, even though they should call the same method:

julia> s = IOBuffer(Array(Uint8,0), true, true)
IOBuffer([],true,true,true,false,0,9223372036854775807,1)

julia> @which show(s, xs)
show(io::IO,x::TypeConstructor) at show.jl:60
julia> @which show(STDOUT, xs)
show(io::IO,x::TypeConstructor) at show.jl:60
julia> show(STDOUT, xs)
Array{T,2}
julia> show(s, xs)
ERROR: type TypeConstructor has no field name
 in show at show.jl:66

The called method should just do this:

show(io::IO, x::TypeConstructor) = show(io, x.body)

but when this is called directly, it always works:

julia> show(STDOUT, xs.body)
Array{T,2}
julia> show(s, xs.body)

julia> takebuf_string(s)
"Array{T,2}"

Judging from code_llvm, the call show(::IO, ::TypeConstructor) is inlined. The llvm (and native) codes are identical for the IOBuffer and the TTY cases though, and they both look quite different from the ones for show(s, xs.body) (but I can't make sense of any of that, really).

In any case the commit indicated by git blame should be unrelated. Wild guess: maybe something funny is going on with the inlining step while choosing the show method? That could perhaps explain why adding a method to show may make a difference.

@ghost ghost assigned JeffBezanson Jan 30, 2014
@quinnj
Copy link
Member

quinnj commented Jun 5, 2014

I can't reproduce any of the TypeConstructor errors here. Did this get fixed along the way?

@JeffBezanson
Copy link
Member

Yeah, I think this issue is a bit stale.

@JayKickliter
Copy link

I see this issue is closed, but I get this error when reloading a module I'm working on.

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.1-pre+44 (2014-09-04 19:33 UTC)
 _/ |\__'_|_|_|\__'_|  |  release-0.3/929d12f* (fork: 70 commits, 27 days)
|__/                   |  x86_64-apple-darwin13.3.0

julia> reload( expanduser("~/.julia/v0.3/Multirate/src/Multirate.jl") )

julia> reload( expanduser("~/.julia/v0.3/Multirate/src/Multirate.jl") )
Warning: replacing module Multirate
Warning: Method definition filt(Array{T,1},Array{T,1}) in module Multirate at /Users/jaykickliter/.julia/v0.3/Multirate/src/Filters.jl:612 overwritten in module Multirate at /Users/jaykickliter/.julia/v0.3/Multirate/src/Filters.jl:612.
Warning: Method definition filt(ERROR: type TypeConstructor has no field name
 in show at show.jl:86
 in show_delim_array at show.jl:178
 in show at show.jl:197
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in reload at loading.jl:85
while loading /Users/jaykickliter/.julia/v0.3/Multirate/src/Filters.jl, in expression starting on line 611
while loading /Users/jaykickliter/.julia/v0.3/Multirate/src/Multirate.jl, in expression starting on line 22

julia> 

@stevengj
Copy link
Member Author

stevengj commented Sep 6, 2014

See #8163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

6 participants