JuliaIO/JLD2.jl

Reconstruction of UnionAll type parameters

lhupe opened this issue · 0 comments

lhupe commented

MWE

Create a file using

using JLD2
struct Foo{T}
    val
end
jldsave("test.jld2", test = Foo{Foo}(4))

then load in a new session without the type definitions

using JLD2
load("test.jld2")

which results in a verbose error message

┌ Error: Exception while generating log record in module JLD2 at /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:607
│   exception =
│    MethodError: no method matching typestring(::Type{JLD2.UnknownType{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{T}}, Tuple{T}} where T})
│    
│    Closest candidates are:
│      typestring(::Type{JLD2.UnknownType{T, P}}) where {T, P}
│       @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:502
│    
│    Stacktrace:
│      [1] typestring(::Type{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{JLD2.UnknownType{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{T}}, Tuple{T}} where T}}})
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:512
│      [2] macro expansion
│        @ ./logging.jl:372 [inlined]
│      [3] constructrr(f::JLD2.JLDFile{JLD2.MmapIO}, unk::Type{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{JLD2.UnknownType{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{T}}, Tuple{T}} where T}}}, dt::JLD2.CompoundDatatype, attrs::Vector{JLD2.ReadAttribute})
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:607
│      [4] jltype(f::JLD2.JLDFile{JLD2.MmapIO}, cdt::JLD2.CommittedDatatype)
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:116
│      [5] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, dataspace::JLD2.ReadDataspace, datatype_class::UInt8, datatype_offset::Int64, layout::JLD2.DataLayout, filters::JLD2.FilterPipeline, header_offset::JLD2.RelOffset, attributes::Vector{JLD2.ReadAttribute})
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/datasets.jl:183
│      [6] load_dataset(f::JLD2.JLDFile{JLD2.MmapIO}, offset::JLD2.RelOffset)
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/datasets.jl:125
│      [7] getindex(g::JLD2.Group{JLD2.JLDFile{JLD2.MmapIO}}, name::String)
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/groups.jl:109
│      [8] getindex
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/JLD2.jl:494 [inlined]
│      [9] loadtodict!(d::Dict{String, Any}, g::JLD2.JLDFile{JLD2.MmapIO}, prefix::String)
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/loadsave.jl:155
│     [10] loadtodict!
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/loadsave.jl:154 [inlined]
│     [11] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String}; nested::Bool, kwargs::@Kwargs{})
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/fileio.jl:43
│     [12] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String})
│        @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/fileio.jl:37
│     [13] #invokelatest#2
│        @ Base ./essentials.jl:887 [inlined]
│     [14] invokelatest
│        @ Base ./essentials.jl:884 [inlined]
│     [15] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::@Kwargs{})
│        @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:219
│     [16] action
│        @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:196 [inlined]
│     [17] action
│        @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:185 [inlined]
│     [18] load(::String; options::@Kwargs{})
│        @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:113
│     [19] load(::String)
│        @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:109
│     [20] top-level scope
│        @ REPL[2]:1
│     [21] eval
│        @ Core ./boot.jl:385 [inlined]
│     [22] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
│        @ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:150
│     [23] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
│        @ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:246
│     [24] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
│        @ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:231
│     [25] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
│        @ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:389
│     [26] run_repl(repl::REPL.AbstractREPL, consumer::Any)
│        @ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:375
│     [27] (::Base.var"#1013#1015"{Bool, Bool, Bool})(REPL::Module)
│        @ Base ./client.jl:432
│     [28] #invokelatest#2
│        @ Base ./essentials.jl:887 [inlined]
│     [29] invokelatest
│        @ Base ./essentials.jl:884 [inlined]
│     [30] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
│        @ Base ./client.jl:416
│     [31] exec_options(opts::Base.JLOptions)
│        @ Base ./client.jl:333
│     [32] _start()
│        @ Base ./client.jl:552
└ @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:607
Error encountered while load FileIO.File{FileIO.DataFormat{:JLD2}, String}("test.jld2").

Fatal error:
ERROR: MethodError: no method matching shorttypestring(::Type{JLD2.UnknownType{JLD2.UnknownType{Symbol("Main.Foo"), Tuple{T}}, Tuple{T}} where T})

Closest candidates are:
  shorttypestring(::Type{JLD2.UnknownType{T, P}}) where {T, P}
   @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/data/reconstructing_datatypes.jl:529

Stacktrace:
  [1] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String}; nested::Bool, kwargs::@Kwargs{})
    @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/fileio.jl:46
  [2] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String})
    @ JLD2 /data.lmp/lhupe/.julia/packages/JLD2/oYEEg/src/fileio.jl:37
  [3] #invokelatest#2
    @ Base ./essentials.jl:887 [inlined]
  [4] invokelatest
    @ Base ./essentials.jl:884 [inlined]
  [5] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::@Kwargs{})
    @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:219
  [6] action
    @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:196 [inlined]
  [7] action
    @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:185 [inlined]
  [8] load(::String; options::@Kwargs{})
    @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:113
  [9] load(::String)
    @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:109
 [10] top-level scope
    @ REPL[2]:1
Stacktrace:
 [1] handle_error(e::MethodError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/error_handling.jl:61
 [2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector}}, action::String)
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/error_handling.jl:56
 [3] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::@Kwargs{})
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:228
 [4] action
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:196 [inlined]
 [5] action
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:185 [inlined]
 [6] load(::String; options::@Kwargs{})
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:113
 [7] load(::String)
   @ FileIO /data.lmp/lhupe/.julia/packages/FileIO/jMf68/src/loadsave.jl:109
 [8] top-level scope
   @ REPL[2]:1