From a3f130e6e682ef3b0207d3d7489d3072f0ba9cb7 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 29 Jul 2017 17:25:54 -0700 Subject: [PATCH] Bump minimum Julia version to 0.6 (#175) --- .travis.yml | 2 - README.md | 3 +- REQUIRE | 4 +- appveyor.yml | 4 - src/JLD.jl | 165 ++++++++++------------------------- src/JLD00.jl | 92 +++++++++---------- src/datafile.jl | 6 +- src/jld_types.jl | 57 +++++------- test/JLDTest.jl | 2 +- test/custom_serialization.jl | 22 ++--- test/jldtests.jl | 99 ++++++++++----------- test/type_translation.jl | 6 +- 12 files changed, 176 insertions(+), 286 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05d49b1..9b2eb2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ os: - linux - osx julia: - - 0.4 - - 0.5 - 0.6 - nightly notifications: diff --git a/README.md b/README.md index 36d16a0..0301055 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ [![Build status](https://ci.appveyor.com/api/projects/status/o2rc8yj3qnrhn738/branch/master?svg=true)](https://ci.appveyor.com/project/timholy/jld-jl-28dqq/branch/master) [![codecov.io](http://codecov.io/github/JuliaIO/JLD.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaIO/JLD.jl?branch=master) -[![JLD](http://pkg.julialang.org/badges/JLD_0.3.svg)](http://pkg.julialang.org/?pkg=JLD&ver=0.3) -[![JLD](http://pkg.julialang.org/badges/JLD_0.4.svg)](http://pkg.julialang.org/?pkg=JLD&ver=0.4) +[![JLD](http://pkg.julialang.org/badges/JLD_0.6.svg)](http://pkg.julialang.org/detail/JLD) JLD, for which files conventionally have the extension `.jld`, is a widely-used format for data storage with the Julia programming diff --git a/REQUIRE b/REQUIRE index a9db306..83a734a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,5 @@ -julia 0.4 +julia 0.6 HDF5 Compat 0.18.0 FileIO -LegacyStrings # for julia-0.5 +LegacyStrings diff --git a/appveyor.yml b/appveyor.yml index 396c445..e848da6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,5 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" diff --git a/src/JLD.jl b/src/JLD.jl index cf22dfe..a4f9f08 100644 --- a/src/JLD.jl +++ b/src/JLD.jl @@ -2,11 +2,12 @@ __precompile__() module JLD using HDF5, FileIO, Compat -using Compat.String import HDF5: close, dump, exists, file, getindex, setindex!, g_create, g_open, o_delete, name, names, read, write, HDF5ReferenceObj, HDF5BitsKind, ismmappable, readmmap -import Base: convert, length, endof, show, done, next, ndims, start, delete!, eltype, size, sizeof, unsafe_convert +import Base: convert, length, endof, show, done, next, ndims, start, delete!, eltype, + size, sizeof, unsafe_convert, datatype_pointerfree +import LegacyStrings: UTF16String const magic_base = "Julia data file (HDF5), version " const version_current = v"0.1.1" @@ -18,38 +19,25 @@ const name_type_attr = "julia type" const BitsKindOrString = Union{HDF5BitsKind, String} -if VERSION >= v"0.5.0-dev+5149" - import Base.datatype_pointerfree -else - datatype_pointerfree(T::DataType) = T.pointerfree -end - -replacements = Any[] -if isdefined(Core, :String) && isdefined(Core, :AbstractString) - push!(replacements, :(s = replace(s, r"ASCIIString|UTF8String|ByteString", "String"))) -end -if !isdefined(Base, :UTF16String) - push!(replacements, :(s = replace(s, "Base.UTF16String", "LegacyStrings.UTF16String"))) -end -ex = Expr(:block, replacements...) -@eval function julia_type(s::AbstractString) - $ex +function julia_type(s::AbstractString) + s = replace(s, r"ASCIIString|UTF8String|ByteString", "String") + s = replace(s, "Base.UTF16String", "LegacyStrings.UTF16String") _julia_type(s) end ### Dummy types used for converting attribute strings to Julia types -type UnsupportedType; end -type UnconvertedType; end -type CompositeKind; end # here this means "a type with fields" +mutable struct UnsupportedType; end +mutable struct UnconvertedType; end +mutable struct CompositeKind; end # here this means "a type with fields" -immutable JldDatatype +struct JldDatatype dtype::HDF5Datatype index::Int end sizeof(T::JldDatatype) = sizeof(T.dtype) -immutable JldWriteSession +struct JldWriteSession persist::Vector{Any} # To hold objects that should not be garbage-collected h5ref::ObjectIdDict # To hold mapping from Object/Array -> HDF5ReferenceObject @@ -61,7 +49,7 @@ end # length(group) only returns the number of _completed_ items in a group. Since # we'll write recursively, we need to keep track of the number of reference # objects _started_. -type JldFile <: HDF5.DataFile +mutable struct JldFile <: HDF5.DataFile plain::HDF5File version::VersionNumber toclose::Bool @@ -90,12 +78,12 @@ type JldFile <: HDF5.DataFile end end -immutable JldGroup +struct JldGroup plain::HDF5Group file::JldFile end -immutable JldDataset +struct JldDataset plain::HDF5Dataset file::JldFile end @@ -109,10 +97,10 @@ iscompressed(g::JldGroup) = g.file.compress ismmapped(f::JldFile) = f.mmaparrays ismmapped(d::JldGroup) = d.file.mmaparrays -immutable PointerException <: Exception; end +struct PointerException <: Exception; end show(io::IO, ::PointerException) = print(io, "cannot write a pointer to JLD file") -immutable TypeMismatchException <: Exception +struct TypeMismatchException <: Exception typename::String end show(io::IO, e::TypeMismatchException) = @@ -401,7 +389,7 @@ function read(obj::JldDataset) end ## Scalars -read_scalar{T<:BitsKindOrString}(obj::JldDataset, dtype::HDF5Datatype, ::Type{T}) = +read_scalar(obj::JldDataset, dtype::HDF5Datatype, ::Type{T}) where {T<:BitsKindOrString} = read(obj.plain, T) function read_scalar(obj::JldDataset, dtype::HDF5Datatype, T::Type) buf = Vector{UInt8}(sizeof(dtype)) @@ -423,8 +411,8 @@ function read_array(obj::JldDataset, dtype::HDF5Datatype, dspace_id::HDF5.Hid, d end # Arrays of basic HDF5 kinds -function read_vals{S<:HDF5BitsKind}(obj::JldDataset, dtype::HDF5Datatype, T::Union{Type{S}, Type{Complex{S}}}, - dspace_id::HDF5.Hid, dsel_id::HDF5.Hid, dims::Tuple{Vararg{Int}}) +function read_vals(obj::JldDataset, dtype::HDF5Datatype, T::Union{Type{S}, Type{Complex{S}}}, + dspace_id::HDF5.Hid, dsel_id::HDF5.Hid, dims::Tuple{Vararg{Int}}) where {S<:HDF5BitsKind} if obj.file.mmaparrays && HDF5.iscontiguous(obj.plain) && dsel_id == HDF5.H5S_ALL readmmap(obj.plain, Array{T}) else @@ -470,8 +458,8 @@ function read_vals(obj::JldDataset, dtype::HDF5Datatype, T::Type, dspace_id::HDF end # Arrays of references -function read_refs{T}(obj::JldDataset, ::Type{T}, dspace_id::HDF5.Hid, dsel_id::HDF5.Hid, - dims::Tuple{Vararg{Int}}) +function read_refs(obj::JldDataset, ::Type{T}, dspace_id::HDF5.Hid, dsel_id::HDF5.Hid, + dims::Tuple{Vararg{Int}}) where T refs = Array{HDF5ReferenceObj}(dims) HDF5.h5d_read(obj.plain.id, HDF5.H5T_STD_REF_OBJ, dspace_id, dsel_id, HDF5.H5P_DEFAULT, refs) @@ -562,9 +550,9 @@ function _write{T<:Union{HDF5BitsKind, String}}(parent::Union{JldFile, JldGroup} end # General array types -function _write{T}(parent::Union{JldFile, JldGroup}, - path::String, data::Array{T}, - wsession::JldWriteSession; kargs...) +function _write(parent::Union{JldFile, JldGroup}, + path::String, data::Array{T}, + wsession::JldWriteSession; kargs...) where T f = file(parent) dtype = h5fieldtype(f, T, true) buf = h5convert_array(f, data, dtype, wsession) @@ -738,7 +726,7 @@ function getindex(dset::JldDataset, indices::Union{Range{Int},Integer}...) end end -function setindex!{T,N}(dset::JldDataset, X::AbstractArray{T,N}, indices::Union{Range{Int},Integer}...) +function setindex!(dset::JldDataset, X::AbstractArray{T,N}, indices::Union{Range{Int},Integer}...) where {T,N} f = file(dset) sz = map(length, indices) dsel_id = HDF5.hyperslab(dset.plain, indices...) @@ -787,20 +775,20 @@ writeas(x) = x # Wrapper for associative keys # We write this instead of the associative to avoid dependence on the # Julia hash function -immutable AssociativeWrapper{K,V,T<:Associative} +struct AssociativeWrapper{K,V,T<:Associative} keys::Vector{K} values::Vector{V} end -readas{K,V,T}(x::AssociativeWrapper{K,V,T}) = convert(T, x) -function writeas{T<:Associative}(x::T) +readas(x::AssociativeWrapper{K,V,T}) where {K,V,T} = convert(T, x) +function writeas(x::T) where T<:Associative K, V = destructure(eltype(x)) convert(AssociativeWrapper{K,V,T}, x) end -destructure{K,V}(::Type{Pair{K,V}}) = K, V # not inferrable, julia#10880 +destructure(::Type{Pair{K,V}}) where {K,V} = K, V # not inferrable, julia#10880 # Special case for associative, to rehash keys -function convert{K,V,T<:Associative}(::Type{T}, x::AssociativeWrapper{K,V,T}) +function convert(::Type{T}, x::AssociativeWrapper{K,V,T}) where {K,V,T<:Associative} ret = T() keys = x.keys values = x.values @@ -814,7 +802,7 @@ function convert{K,V,T<:Associative}(::Type{T}, x::AssociativeWrapper{K,V,T}) ret end -function convert{K,V,T}(::Type{AssociativeWrapper{K,V,T}}, d::Associative) +function convert(::Type{AssociativeWrapper{K,V,T}}, d::Associative) where {K,V,T} n = length(d) ks = Vector{K}(n) vs = Vector{V}(n) @@ -828,7 +816,7 @@ end # Special case for SimpleVector # Wrapper for SimpleVector -immutable SimpleVectorWrapper +struct SimpleVectorWrapper elements::Vector end @@ -849,7 +837,7 @@ function func2expr(fun::Function) ast = Base.uncompressed_ast(fun.code) Expr(:function, Expr(:tuple, ast.args[1]...), Expr(:block, ast.args[3].args...)) end -immutable AnonymousFunctionSerializer +struct AnonymousFunctionSerializer expr::Expr mod::AbstractString AnonymousFunctionSerializer(fun::Function) = new(func2expr(fun), string(fun.code.module)) @@ -858,7 +846,7 @@ readas(ast::AnonymousFunctionSerializer) = eval(modname2mod(ast.mod)).eval(ast.e writeas(fun::Function) = AnonymousFunctionSerializer(fun) # Serializer for GlobalRef -immutable GlobalRefSerializer +struct GlobalRefSerializer mod::AbstractString name::Symbol GlobalRefSerializer(g::GlobalRef) = new(string(g.mod), g.name) @@ -867,65 +855,28 @@ readas(grs::GlobalRefSerializer) = GlobalRef(eval(modname2mod(grs.mod)), grs.nam writeas(gr::GlobalRef) = GlobalRefSerializer(gr) # StackFrame (Null the LambdaInfo in 0.5) -if VERSION > v"0.5.0-dev+2420" - if VERSION < v"0.6.0-dev.615" - JLD.writeas(data::StackFrame) = Base.StackFrame( - data.func, - data.file, - data.line, - Nullable{Core.LambdaInfo}(), - data.from_c, - data.inlined, - data.pointer) - else # or Core.MethodInstance in 0.6 - JLD.writeas(data::StackFrame) = Base.StackFrame( - data.func, - data.file, - data.line, - Nullable{Core.MethodInstance}(), - data.from_c, - data.inlined, - data.pointer) - end -end +# or Core.MethodInstance in 0.6 +JLD.writeas(data::StackFrame) = + Base.StackFrame(data.func, + data.file, + data.line, + Nullable{Core.MethodInstance}(), + data.from_c, + data.inlined, + data.pointer) ### Converting attribute strings to Julia types const _where_macrocall = Symbol("@where") function expand_where_macro(e::Expr) - if TYPESYSTEM_06 - e.head = :where - shift!(e.args) - else - e.head = :let - tv = e.args[2] - if isa(tv, Symbol) - sym = tv - tv = :(TypeVar($sym)) - elseif isa(tv, Expr) - if tv.head === :comparison - lb = tv.args[1] - sym = tv.args[3] - ub = tv.args[5] - tv = :(TypeVar($sym, $lb, $ub)) - elseif tv.head === :(<:) - sym = tv.args[1] - ub = tv.args[2] - tv = :(TypeVar($sym, $ub)) - else - return false - end - else - return false - end - e.args[2] = Expr(:(=), sym, tv) - end + e.head = :where + shift!(e.args) return true end is_valid_type_ex(s::Symbol) = true is_valid_type_ex(s::QuoteNode) = true -is_valid_type_ex{T}(::T) = isbits(T) +is_valid_type_ex(::T) where {T} = isbits(T) function is_valid_type_ex(e::Expr) if e.head === :curly || e.head == :tuple || e.head == :. return all(is_valid_type_ex, e.args) @@ -949,7 +900,7 @@ const typemap_Core = Dict( :Nothing => :Void ) -const _typedict = Dict{Compat.UTF8String,Type}() +const _typedict = Dict{String,Type}() fixtypes(typ) = typ function fixtypes(typ::Expr) @@ -1020,7 +971,7 @@ end ### Converting Julia types to fully qualified names function full_typename(io::IO, file::JldFile, jltype::Union) print(io, "Union(") - types = uniontypes(jltype) + types = Base.uniontypes(jltype) if !isempty(types) full_typename(io, file, types[1]) for i = 2:length(types) @@ -1030,7 +981,6 @@ function full_typename(io::IO, file::JldFile, jltype::Union) end print(io, ')') end -if TYPESYSTEM_06 function full_typename(io::IO, file::JldFile, x::typeof(Union{})) print(io, "Union()") end @@ -1058,25 +1008,6 @@ end function full_typename(io::IO, file::JldFile, tv::TypeVar) print(io, tv.name) end -else -function full_typename(io::IO, file::JldFile, tv::TypeVar) - if tv.lb === Union{} && tv.ub === Any - print(io, "TypeVar(:", tv.name, ")") - elseif tv.lb === Union{} - print(io, "TypeVar(:", tv.name, ",") - full_typename(io, file, tv.ub) - print(io, ')') - else - print(io, "TypeVar(:") - print(io, tv.name) - print(io, ',') - full_typename(io, file, tv.lb) - print(io, ',') - full_typename(io, file, tv.ub) - print(io, ')') - end -end -end function full_typename(io::IO, ::JldFile, x) # Only allow bitstypes that show as AST literals and make sure that they # read back exactly as they are saved. Use show here (instead of print) to diff --git a/src/JLD00.jl b/src/JLD00.jl index 4347f8e..13fafb9 100644 --- a/src/JLD00.jl +++ b/src/JLD00.jl @@ -4,20 +4,12 @@ module JLD00 using HDF5, Compat, LegacyStrings -using Compat.String # Add methods to... import HDF5: close, dump, exists, file, getindex, setindex!, g_create, g_open, o_delete, name, names, read, size, write, HDF5ReferenceObj, HDF5BitsKind, ismmappable, readmmap import Base: length, endof, show, done, next, start, delete! import JLD -if !isdefined(:setfield!) - const setfield! = setfield -end -if !isdefined(:read!) - const read! = read -end - # See julia issue #8907 replacements = Any[] push!(replacements, :(s = replace(s, r"Uint(?=\d{1,3})", "UInt"))) @@ -38,18 +30,18 @@ const pathrequire = "/_require" const name_type_attr = "julia type" ### Dummy types used for converting attribute strings to Julia types -type UnsupportedType; end -type UnconvertedType; end -type CompositeKind; end # here this means "a type with fields" +mutable struct UnsupportedType; end +mutable struct UnconvertedType; end +mutable struct CompositeKind; end # here this means "a type with fields" # The Julia Data file type # Purpose of the nrefs field: # length(group) only returns the number of _completed_ items in a group. Since # we'll write recursively, we need to keep track of the number of reference # objects _started_. -type JldFile <: HDF5.DataFile +mutable struct JldFile <: HDF5.DataFile plain::HDF5File - version::Compat.UTF8String + version::String toclose::Bool writeheader::Bool mmaparrays::Bool @@ -64,12 +56,12 @@ type JldFile <: HDF5.DataFile end end -immutable JldGroup +struct JldGroup plain::HDF5Group file::JldFile end -immutable JldDataset +struct JldDataset plain::HDF5Dataset file::JldFile end @@ -347,8 +339,8 @@ readsafely(parent::Union{JldFile,JldGroup}, name::Symbol) = readsafely(parent, b # Basic types const BitsKindOrString = Union{HDF5BitsKind, String} -read{T<:BitsKindOrString}(obj::JldDataset, ::Type{T}) = read(obj.plain, T) -function read{T<:HDF5BitsKind}(obj::JldDataset, ::Type{Array{T}}) +read(obj::JldDataset, ::Type{T}) where {T<:BitsKindOrString} = read(obj.plain, T) +function read(obj::JldDataset, ::Type{Array{T}}) where T<:HDF5BitsKind A = obj.file.mmaparrays && HDF5.iscontiguous(obj.plain) ? readmmap(obj.plain, Array{T}) : read(obj.plain, Array{T}) if isempty(A) && exists(obj, "dims") dims = a_read(obj.plain, "dims") @@ -356,11 +348,11 @@ function read{T<:HDF5BitsKind}(obj::JldDataset, ::Type{Array{T}}) end A end -read{T<:String}(obj::JldDataset, ::Type{Array{T}}) = read(obj.plain, Array{T}) -read{T<:BitsKindOrString,N}(obj::JldDataset, ::Type{Array{T,N}}) = read(obj, Array{T}) +read(obj::JldDataset, ::Type{Array{T}}) where {T<:String} = read(obj.plain, Array{T}) +read(obj::JldDataset, ::Type{Array{T,N}}) where {T<:BitsKindOrString,N} = read(obj, Array{T}) # Arrays-of-arrays of basic types -function read{T<:HDF5BitsKind,M,N}(obj::JldDataset, ::Type{Array{Array{T,N},M}}) +function read(obj::JldDataset, ::Type{Array{Array{T,N},M}}) where {T<:HDF5BitsKind,M,N} # fallback for backwards compatibility with pre-v0.2.27 format HDF5.hdf5_to_julia_eltype(datatype(obj.plain)) == HDF5ReferenceObj && return getrefs(obj, Array{T,N}) @@ -377,10 +369,10 @@ read(obj::JldDataset, ::Type{Void}) = nothing read(obj::JldDataset, ::Type{Bool}) = read(obj, UInt8) != 0 # Types -read{T}(obj::JldDataset, ::Type{Type{T}}) = T +read(obj::JldDataset, ::Type{Type{T}}) where {T} = T # Bool -function read{N}(obj::JldDataset, ::Type{Array{Bool,N}}) +function read(obj::JldDataset, ::Type{Array{Bool,N}}) where N format = a_read(obj.plain, "julia_format") if format == "EachUint8" bool(read(obj.plain, Array{UInt8})) @@ -390,27 +382,27 @@ function read{N}(obj::JldDataset, ::Type{Array{Bool,N}}) end # Complex -function read{T}(obj::JldDataset, ::Type{Complex{T}}) +function read(obj::JldDataset, ::Type{Complex{T}}) where T a = read(obj.plain, Array{T}) a[1]+a[2]*im end -function read{T<:Complex,N}(obj::JldDataset, ::Type{Array{T,N}}) +function read(obj::JldDataset, ::Type{Array{T,N}}) where {T<:Complex,N} A = read(obj, Array{realtype(T)}) reinterpret(T, A, ntuple(i->size(A, i+1), ndims(A)-1)) end # Symbol read(obj::JldDataset, ::Type{Symbol}) = Symbol(read(obj.plain, String)) -read{N}(obj::JldDataset, ::Type{Array{Symbol,N}}) = map(Symbol, read(obj.plain, Array{String})) +read(obj::JldDataset, ::Type{Array{Symbol,N}}) where {N} = map(Symbol, read(obj.plain, Array{String})) # Char read(obj::JldDataset, ::Type{Char}) = Char(read(obj.plain, UInt32)) read(obj::JldDataset, ::Type{UTF16String}) = UTF16String(read(obj.plain, Array{UInt16})) -read{N}(obj::JldDataset, ::Type{Array{UTF16String,N}}) = map(x->UTF16String(x), read(obj, Array{Vector{UInt16},N})) +read(obj::JldDataset, ::Type{Array{UTF16String,N}}) where {N} = map(x->UTF16String(x), read(obj, Array{Vector{UInt16},N})) # General arrays -read{T,N}(obj::JldDataset, t::Type{Array{T,N}}) = getrefs(obj, T) +read(obj::JldDataset, t::Type{Array{T,N}}) where {T,N} = getrefs(obj, T) # Tuple function read_tuple(obj::JldDataset) @@ -423,7 +415,7 @@ function read_tuple(obj::JldDataset, indices::AbstractVector) end # Dict -function read{T<:Associative}(obj::JldDataset, ::Type{T}) +function read(obj::JldDataset, ::Type{T}) where T<:Associative kv = getrefs(obj, Any) ret = T() for (cn, c) in zip(kv[1], kv[2]) @@ -481,7 +473,7 @@ function read_bitstype(obj::JldDataset, T::DataType) end # Read an array of references -function getrefs{T}(obj::JldDataset, ::Type{T}) +function getrefs(obj::JldDataset, ::Type{T}) where T refs = read(obj.plain, Array{HDF5ReferenceObj}) out = Array{T}(size(refs)) f = file(obj) @@ -497,7 +489,7 @@ function getrefs{T}(obj::JldDataset, ::Type{T}) end return out end -function getrefs{T}(obj::JldDataset, ::Type{T}, indices::Union{Integer, AbstractVector}...) +function getrefs(obj::JldDataset, ::Type{T}, indices::Union{Integer, AbstractVector}...) where T refs = read(obj.plain, Array{HDF5ReferenceObj}) refs = refs[indices...] f = file(obj) @@ -552,8 +544,8 @@ write{T<:Union{HDF5BitsKind, String}}(parent::Union{JldFile, JldGroup}, name::St write{T<:Union{HDF5BitsKind, String}}(parent::Union{JldFile, JldGroup}, name::String, data::Array{Array{T,1}}) = write(parent, name, data, full_typename(typeof(data))) -function write{T}(parent::Union{JldFile, JldGroup}, name::String, - data::HDF5.HDF5Vlen{T}, astype::String) +function write(parent::Union{JldFile, JldGroup}, name::String, + data::HDF5.HDF5Vlen{T}, astype::String) where T # Create the dataset dset, dtype = d_create(parent.plain, name, data) try @@ -586,12 +578,10 @@ write(parent::Union{JldFile, JldGroup}, name::String, n::Void) = write(parent, n # Types # the first is needed to avoid an ambiguity warning -if isdefined(Core, :Top) - write{T<:Top}(parent::Union{JldFile, JldGroup}, name::String, t::Tuple{Vararg{Type{T}}}) = write(parent, name, Any[t...], "Tuple") -else - write{T}(parent::Union{JldFile, JldGroup}, name::String, t::Tuple{Vararg{Type{T}}}) = write(parent, name, Any[t...], "Tuple") -end -write{T}(parent::Union{JldFile, JldGroup}, name::String, t::Type{T}) = write(parent, name, nothing, string("Type{", full_typename(t), "}")) +write(parent::Union{JldFile, JldGroup}, name::String, t::Tuple{Vararg{Type{T}}}) where {T} = + write(parent, name, Any[t...], "Tuple") +write(parent::Union{JldFile, JldGroup}, name::String, t::Type{T}) where {T} = + write(parent, name, nothing, string("Type{", full_typename(t), "}")) # Bools write(parent::Union{JldFile, JldGroup}, name::String, tf::Bool) = write(parent, name, uint8(tf), "Bool") @@ -601,12 +591,12 @@ function write(parent::Union{JldFile, JldGroup}, name::String, tf::Array{Bool}) end # Complex -realtype{T}(::Type{Complex{T}}) = T +realtype(::Type{Complex{T}}) where {T} = T function write(parent::Union{JldFile, JldGroup}, name::String, c::Complex) reim = [real(c), imag(c)] write(parent, name, reim, full_typename(typeof(c))) end -function write{T<:Complex}(parent::Union{JldFile, JldGroup}, name::String, C::Array{T}) +function write(parent::Union{JldFile, JldGroup}, name::String, C::Array{T}) where T<:Complex reim = reinterpret(realtype(T), C, ntuple(i->i==1?2:size(C,i-1), ndims(C)+1)) write(parent, name, reim, full_typename(typeof(C))) end @@ -622,10 +612,11 @@ write(parent::Union{JldFile, JldGroup}, name::String, char::Char) = write(parent #UTF16String write(parent::Union{JldFile, JldGroup}, name::String, str::UTF16String) = write(parent, name, str.data, "UTF16String") -write{N}(parent::Union{JldFile, JldGroup}, name::String, strs::Array{UTF16String,N}) = write(parent, name, map(x->x.data, strs), "Array{UTF16String,$N}") +write(parent::Union{JldFile, JldGroup}, name::String, strs::Array{UTF16String,N}) where {N} = + write(parent, name, map(x->x.data, strs), "Array{UTF16String,$N}") # General array types (as arrays of references) -function write{T}(parent::Union{JldFile, JldGroup}, path::String, data::Array{T}, astype::AbstractString) +function write(parent::Union{JldFile, JldGroup}, path::String, data::Array{T}, astype::AbstractString) where T local gref # a group, inside /_refs, for all the elements in data local refs # Determine whether parent already exists in /_refs, so we can avoid group/dataset conflict @@ -678,7 +669,8 @@ function write{T}(parent::Union{JldFile, JldGroup}, path::String, data::Array{T} close(cset) end end -write{T}(parent::Union{JldFile, JldGroup}, path::String, data::Array{T}) = write(parent, path, data, full_typename(typeof(data))) +write(parent::Union{JldFile, JldGroup}, path::String, data::Array{T}) where {T} = + write(parent, path, data, full_typename(typeof(data))) # Tuple write(parent::Union{JldFile, JldGroup}, name::String, t::Tuple) = write(parent, name, Any[t...], "Tuple") @@ -845,7 +837,7 @@ end length(dset::JldDataset) = prod(size(dset)) endof(dset::JldDataset) = length(dset) -isarraycomplex{T<:Complex, N}(::Type{Array{T, N}}) = true +isarraycomplex(::Type{Array{T, N}}) where {T<:Complex, N} = true isarraycomplex(t) = false ### Read/write via getindex/setindex! ### @@ -864,15 +856,17 @@ function getindex(dset::JldDataset, indices::Union{Integer, RangeIndex}...) _getindex(dset, T, indices...) end -_getindex{T<:HDF5BitsKind,N}(dset::JldDataset, ::Type{Array{T,N}}, indices::RangeIndex...) = HDF5._getindex(dset.plain, T, indices...) -function _getindex{T<:Complex,N}(dset::JldDataset, ::Type{Array{T,N}}, indices::RangeIndex...) +_getindex(dset::JldDataset, ::Type{Array{T,N}}, indices::RangeIndex...) where {T<:HDF5BitsKind,N} = + HDF5._getindex(dset.plain, T, indices...) +function _getindex(dset::JldDataset, ::Type{Array{T,N}}, indices::RangeIndex...) where {T<:Complex,N} reinterpret(T, HDF5._getindex(dset.plain, realtype(T), 1:2, indices...), ntuple(i->length(indices[i]), length(indices))) end -function _getindex{N}(dset::JldDataset, ::Type{Array{Bool,N}}, indices::RangeIndex...) +function _getindex(dset::JldDataset, ::Type{Array{Bool,N}}, indices::RangeIndex...) where N tf = HDF5._getindex(dset.plain, UInt8, indices...) bool(tf) end -_getindex{T,N}(dset::JldDataset, ::Type{Array{T,N}}, indices::Union{Integer, RangeIndex}...) = getrefs(dset, T, indices...) +_getindex(dset::JldDataset, ::Type{Array{T,N}}, indices::Union{Integer, RangeIndex}...) where {T,N} = + getrefs(dset, T, indices...) function setindex!(dset::JldDataset, X::Array, indices::RangeIndex...) if !exists(attrs(dset.plain), name_type_attr) # Fallback to plain read @@ -933,7 +927,7 @@ is_valid_type_ex(x::Int) = true is_valid_type_ex(e::Expr) = ((e.head == :curly || e.head == :tuple || e.head == :.) && all(is_valid_type_ex, e.args)) || (e.head == :call && (e.args[1] == :Union || e.args[1] == :TypeVar)) -const _typedict = Dict{Compat.UTF8String,Type}() +const _typedict = Dict{String,Type}() function _julia_type(s::AbstractString) typ = get(_typedict, s, UnconvertedType) if typ == UnconvertedType diff --git a/src/datafile.jl b/src/datafile.jl index e6d8362..bfbb56f 100644 --- a/src/datafile.jl +++ b/src/datafile.jl @@ -9,7 +9,7 @@ # Types inheriting from DataFile should have names, read, and write # methods -@compat abstract type DataFile end +abstract type DataFile end import Base: read, write @@ -29,13 +29,13 @@ end # Read a list of variables, read(parent, "A", "B", "x", ...) read(parent::DataFile, name::ASCIIString...) = - tuple([read(parent, x) for x in name]...) + tuple([read(parent, x) for x in name]...) # Read one or more variables and pass them to a function. This is # convenient for avoiding type inference pitfalls with the usual # read syntax. read(f::Base.Callable, parent::DataFile, name::ASCIIString...) = - f(read(parent, name...)...) + f(read(parent, name...)...) # Read every variable in the file function read(f::DataFile) diff --git a/src/jld_types.jl b/src/jld_types.jl index 455e059..0fb1555 100644 --- a/src/jld_types.jl +++ b/src/jld_types.jl @@ -1,5 +1,3 @@ -using LegacyStrings - # Controls whether tuples and non-pointerfree immutables, which Julia # stores as references, are stored inline in compound types when # possible. Currently this is problematic because Julia fields of these @@ -15,18 +13,16 @@ const H5CONVERT_INFO = Dict{Any, Any}() const EMPTY_TUPLE_TYPE = Tuple{} const TypesType = SimpleVector -@compat TupleType{T<:Tuple} = Type{T} +TupleType{T<:Tuple} = Type{T} tupletypes(T::TupleType) = T.parameters typetuple(types) = Tuple{types...} -const TYPESYSTEM_06 = isdefined(Int.name, :wrapper) - ## Helper functions translate(oldname::String, newname::String) = JL_TYPENAME_TRANSLATE[oldname] = newname # Holds information about the mapping between a Julia and HDF5 type -immutable JldTypeInfo +struct JldTypeInfo dtypes::Vector{JldDatatype} offsets::Vector{Int} size::Int @@ -44,13 +40,8 @@ function JldTypeInfo(parent::JldFile, types::TypesType, commit::Bool) end JldTypeInfo(dtypes, offsets, offset) end -if TYPESYSTEM_06 JldTypeInfo(parent::JldFile, T::ANY, commit::Bool) = JldTypeInfo(parent, Base.unwrap_unionall(T).types, commit) -else -JldTypeInfo(parent::JldFile, T::ANY, commit::Bool) = - JldTypeInfo(parent, T.types, commit) -end # Write an HDF5 datatype to the file function commit_datatype(parent::JldFile, dtype::HDF5Datatype, T::ANY) @@ -119,14 +110,8 @@ Base.convert(::Type{HDF5.Hid}, x::JldDatatype) = x.dtype.id ## HDF5 bits kinds -if TYPESYSTEM_06 - uniontypes(t::ANY) = Base.uniontypes(t) -else - uniontypes(t::ANY) = isa(t,Union) ? t.types : t -end - # This construction prevents these methods from getting called on type unions -const BitsKindTypes = Union{map(x->Type{x}, uniontypes(HDF5.HDF5BitsKind))...} +const BitsKindTypes = Union{map(x->Type{x}, Base.uniontypes(HDF5.HDF5BitsKind))...} h5fieldtype(parent::JldFile, T::BitsKindTypes, ::Bool) = h5type(parent, T, false) @@ -134,11 +119,11 @@ h5fieldtype(parent::JldFile, T::BitsKindTypes, ::Bool) = h5type(::JldFile, T::BitsKindTypes, ::Bool) = JldDatatype(HDF5Datatype(HDF5.hdf5_type_id(T), false), 0) -h5convert!{T<:HDF5.HDF5BitsKind}(out::Ptr, ::JldFile, x::T, ::JldWriteSession) = +h5convert!(out::Ptr, ::JldFile, x::T, ::JldWriteSession) where {T<:HDF5.HDF5BitsKind} = unsafe_store!(convert(Ptr{T}, out), x) -_jlconvert_bits{T}(::Type{T}, ptr::Ptr) = unsafe_load(convert(Ptr{T}, ptr)) -_jlconvert_bits!{T}(out::Ptr, ::Type{T}, ptr::Ptr) = +_jlconvert_bits(::Type{T}, ptr::Ptr) where {T} = unsafe_load(convert(Ptr{T}, ptr)) +_jlconvert_bits!(out::Ptr, ::Type{T}, ptr::Ptr) where {T} = (unsafe_store!(convert(Ptr{T}, out), unsafe_load(convert(Ptr{T}, ptr))); nothing) jlconvert(T::BitsKindTypes, ::JldFile, ptr::Ptr) = _jlconvert_bits(T, ptr) @@ -154,11 +139,11 @@ h5convert!(out::Ptr, ::JldFile, x::Void, ::JldWriteSession) = nothing ## Strings -h5fieldtype{T<:String}(parent::JldFile, ::Type{T}, ::Bool) = +h5fieldtype(parent::JldFile, ::Type{T}, ::Bool) where {T<:String} = h5type(parent, T, false) # Stored as variable-length strings -function h5type{T<:String}(::JldFile, ::Type{T}, ::Bool) +function h5type(::JldFile, ::Type{T}, ::Bool) where T<:String type_id = HDF5.h5t_copy(HDF5.hdf5_type_id(T)) HDF5.h5t_set_size(type_id, HDF5.H5T_VARIABLE) HDF5.h5t_set_cset(type_id, HDF5.cset(T)) @@ -262,11 +247,11 @@ jlconvert(::Type{BigFloat}, file::JldFile, ptr::Ptr) = ## Types -h5fieldtype{T<:Type}(parent::JldFile, ::Type{T}, commit::Bool) = +h5fieldtype(parent::JldFile, ::Type{T}, commit::Bool) where {T<:Type} = h5type(parent, Type, commit) # Stored as a compound type that contains a variable length string -function h5type{T<:Type}(parent::JldFile, ::Type{T}, commit::Bool) +function h5type(parent::JldFile, ::Type{T}, commit::Bool) where T<:Type haskey(parent.jlh5type, Type) && return parent.jlh5type[Type] id = HDF5.h5t_create(HDF5.H5T_COMPOUND, 8) HDF5.h5t_insert(id, "typename_", 0, h5fieldtype(parent, Compat.UTF8String, commit)) @@ -280,11 +265,12 @@ function h5convert!(out::Ptr, file::JldFile, x::Type, wsession::JldWriteSession) h5convert!(out, file, str, wsession) end -jlconvert{T<:Type}(::Type{T}, file::JldFile, ptr::Ptr) = julia_type(jlconvert(Compat.UTF8String, file, ptr)) +jlconvert(::Type{T}, file::JldFile, ptr::Ptr) where {T<:Type} = + julia_type(jlconvert(String, file, ptr)) ## Pointers -h5type{T<:Ptr}(parent::JldFile, ::Type{T}, ::Bool) = throw(PointerException()) +h5type(parent::JldFile, ::Type{T}, ::Bool) where {T<:Ptr} = throw(PointerException()) ## Union{} @@ -294,7 +280,7 @@ h5fieldtype(parent::JldFile, ::Type{Union{}}, ::Bool) = JLD_REF_TYPE # These show up as having T.size == 0, hence the need for # specialization. -h5fieldtype{T,N}(parent::JldFile, ::Type{Array{T,N}}, ::Bool) = JLD_REF_TYPE +h5fieldtype(parent::JldFile, ::Type{Array{T,N}}, ::Bool) where {T,N} = JLD_REF_TYPE ## User-defined types ## @@ -573,11 +559,11 @@ function gen_jlconvert!(T::ANY) end end -@generated function jlconvert!{T}(out::Ptr, ::Type{T}, file::JldFile, ptr::Ptr) +@generated function jlconvert!(out::Ptr, ::Type{T}, file::JldFile, ptr::Ptr) where T return gen_jlconvert!(T) end -@generated function jlconvert{T}(::Type{T}, file::JldFile, ptr::Ptr) +@generated function jlconvert(::Type{T}, file::JldFile, ptr::Ptr) where T return gen_jlconvert(T) end @@ -681,7 +667,7 @@ function _gen_h5convert!(T::ANY) return ex end -@generated function h5convert!{T}(out::Ptr, file::JldFile, x::T, wsession::JldWriteSession) +@generated function h5convert!(out::Ptr, file::JldFile, x::T, wsession::JldWriteSession) where T return _gen_h5convert!(T) end @@ -765,13 +751,10 @@ function reconstruct_type(parent::JldFile, dtype::HDF5Datatype, savedname::Abstr class_id = HDF5.h5t_get_class(dtype.id) if class_id == HDF5.H5T_OPAQUE if exists(dtype, "empty") - @eval (immutable $name; end; $name) + @eval (struct $name; end; $name) else sz = Int(HDF5.h5t_get_size(dtype.id))*8 - # The new line between `$name` and `$sz` for the `$sz` to be parsed correctly - # on 0.4 and 0.5 - @eval (@compat primitive type $name - $sz end; $name) + @eval (primitive type $name $sz end; $name) end else # Figure out field names and types @@ -807,7 +790,7 @@ function reconstruct_type(parent::JldFile, dtype::HDF5Datatype, savedname::Abstr else # We're reconstructing some other type @eval begin - immutable $name + struct $name $([:($(fieldnames[i])::$(fieldtypes[i])) for i = 1:nfields]...) end $name diff --git a/test/JLDTest.jl b/test/JLDTest.jl index e4c9170..9a0832d 100644 --- a/test/JLDTest.jl +++ b/test/JLDTest.jl @@ -2,7 +2,7 @@ module JLDTest export Object -type Object +mutable struct Object data::Int16 end diff --git a/test/custom_serialization.jl b/test/custom_serialization.jl index 82e3406..6b4bac3 100644 --- a/test/custom_serialization.jl +++ b/test/custom_serialization.jl @@ -6,23 +6,23 @@ using Compat ## Objects we want to save # data in MyType is always of length 5, and that is the basis for a more efficient serialization -immutable MyType{T} +struct MyType{T} data::Vector{T} id::Int - @compat function (::Type{MyType{T}}){T}(v::Vector{T}, id::Integer) + function MyType{T}(v::Vector{T}, id::Integer) where T length(v) == 5 || error("All vectors must be of length 5") new{T}(v, id) end end -MyType{T}(v::Vector{T}, id::Integer) = MyType{T}(v, id) -Base.eltype{T}(::Type{MyType{T}}) = T +MyType(v::Vector{T}, id::Integer) where {T} = MyType{T}(v, id) +Base.eltype(::Type{MyType{T}}) where {T} = T ==(a::MyType, b::MyType) = a.data == b.data && a.id == b.id -immutable MyContainer{T} +struct MyContainer{T} objs::Vector{MyType{T}} end -Base.eltype{T}(::Type{MyContainer{T}}) = T +Base.eltype(::Type{MyContainer{T}}) where {T} = T ==(a::MyContainer, b::MyContainer) = length(a.objs) == length(b.objs) && all(i->a.objs[i]==b.objs[i], 1:length(a.objs)) end @@ -35,17 +35,17 @@ module MySerializer using HDF5, JLD, MyTypes ## Defining the serialization format -type MyContainerSerializer{T} +mutable struct MyContainerSerializer{T} data::Matrix{T} ids::Vector{Int} end -MyContainerSerializer{T}(data::Matrix{T},ids) = MyContainerSerializer{T}(data, ids) -Base.eltype{T}(::Type{MyContainerSerializer{T}}) = T -Base.eltype{T}(::MyContainerSerializer{T}) = T +MyContainerSerializer(data::Matrix{T},ids) where {T} = MyContainerSerializer{T}(data, ids) +Base.eltype(::Type{MyContainerSerializer{T}}) where {T} = T +Base.eltype(::MyContainerSerializer{T}) where {T} = T JLD.readas(serdata::MyContainerSerializer) = MyContainer([MyType(serdata.data[:,i], serdata.ids[i]) for i = 1:length(serdata.ids)]) -function JLD.writeas{T}(data::MyContainer{T}) +function JLD.writeas(data::MyContainer{T}) where T ids = [obj.id for obj in data.objs] n = length(data.objs) vectors = Matrix{T}(5, n) diff --git a/test/jldtests.jl b/test/jldtests.jl index ac3f5f9..a14cf72 100644 --- a/test/jldtests.jl +++ b/test/jldtests.jl @@ -1,6 +1,5 @@ using HDF5, JLD using Compat, LegacyStrings -using Compat: String, view using Base.Test # Define variables of different types @@ -8,13 +7,13 @@ x = 3.7 A = reshape(collect(1:15), 3, 5) Aarray = Vector{Float64}[[1.2,1.3],[2.2,2.3,2.4]] str = "Hello" -stringsA = Compat.ASCIIString["It", "was", "a", "dark", "and", "stormy", "night"] -stringsU = Compat.UTF8String["It", "was", "a", "dark", "and", "stormy", "night"] +stringsA = String["It", "was", "a", "dark", "and", "stormy", "night"] +stringsU = String["It", "was", "a", "dark", "and", "stormy", "night"] strings16 = convert(Array{UTF16String}, stringsA) strings16_2d = reshape(strings16[1:6], (2,3)) empty_string = "" -empty_string_array = Compat.ASCIIString[] -empty_array_of_strings = Compat.ASCIIString[""] +empty_string_array = String[] +empty_array_of_strings = String[""] tf = true TF = A .> 10 B = [-1.5 sqrt(2) NaN 6; @@ -28,7 +27,7 @@ emptyA = zeros(0,2) emptyB = zeros(2,0) try global MyStruct - type MyStruct + mutable struct MyStruct len::Int data::Array{Float64} MyStruct(len::Int) = new(len) @@ -64,15 +63,9 @@ unicode_char = '\U10ffff' β = Any[[1, 2], [3, 4]] # issue #93 vv = Vector{Int}[[1,2,3]] # issue #123 typevar = Array{Int}[[1]] -if JLD.TYPESYSTEM_06 eval(parse("typevar_lb = (Vector{U} where U<:Integer)[[1]]")) eval(parse("typevar_ub = (Vector{U} where Int<:U<:Any)[[1]]")) eval(parse("typevar_lb_ub = (Vector{U} where Int<:U<:Real)[[1]]")) -else -typevar_lb = Vector{TypeVar(:U, Integer)}[[1]] -typevar_ub = Vector{TypeVar(:U, Int, Any)}[[1]] -typevar_lb_ub = Vector{TypeVar(:U, Int, Real)}[[1]] -end undef = Vector{Any}(1) undefs = Matrix{Any}(2, 2) ms_undef = MyStruct(0) @@ -81,12 +74,12 @@ cpus = Base.Sys.cpu_info() # Immutable type: rng = 1:5 # Type with a pointer field (#84) -immutable ObjWithPointer +struct ObjWithPointer a::Ptr{Void} end objwithpointer = ObjWithPointer(0) # Custom PrimitiveType (#99) -@compat primitive type MyBT 64 end +primitive type MyBT 64 end bt = reinterpret(MyBT, Int64(55)) # Symbol arrays (#100) sa_asc = [:a, :b] @@ -95,39 +88,39 @@ sa_utf8 = [:α, :β] subarray = view([1:5;], 1:5) # Array of empty tuples (to test tuple type params) arr_empty_tuple = (Tuple{})[] -immutable EmptyImmutable end +struct EmptyImmutable end emptyimmutable = EmptyImmutable() arr_emptyimmutable = [emptyimmutable] -type EmptyType end +mutable struct EmptyType end emptytype = EmptyType() arr_emptytype = [emptytype] -immutable EmptyII +struct EmptyII x::EmptyImmutable end emptyii = EmptyII(EmptyImmutable()) -immutable EmptyIT +struct EmptyIT x::EmptyType end emptyit = EmptyIT(EmptyType()) -type EmptyTI +mutable struct EmptyTI x::EmptyImmutable end emptyti = EmptyTI(EmptyImmutable()) -type EmptyTT +mutable struct EmptyTT x::EmptyType end emptytt = EmptyTT(EmptyType()) -immutable EmptyIIOtherField +struct EmptyIIOtherField x::EmptyImmutable y::Float64 end emptyiiotherfield = EmptyIIOtherField(EmptyImmutable(), 5.0) # Unicode type field names (#118) -type MyUnicodeStruct☺{τ} +mutable struct MyUnicodeStruct☺{τ} α::τ ∂ₓα::τ - @compat (::Type{MyUnicodeStruct☺{τ}}){τ}(α::τ, ∂ₓα::τ) = new{τ}(α, ∂ₓα) + MyUnicodeStruct☺{τ}(α::τ, ∂ₓα::τ) where {τ} = new{τ}(α, ∂ₓα) end unicodestruct☺ = MyUnicodeStruct☺{Float64}(1.0, -1.0) # Arrays of matrices (#131) @@ -137,41 +130,37 @@ tup = (1, 2, [1, 2], [1 2; 3 4], bt) # Empty tuple empty_tup = () # Non-pointer-free immutable -immutable MyImmutable{T} +struct MyImmutable{T} x::Int y::Vector{T} z::Bool end nonpointerfree_immutable_1 = MyImmutable(1, [1., 2., 3.], false) nonpointerfree_immutable_2 = MyImmutable(2, Any[3., 4., 5.], true) -immutable MyImmutable2 +struct MyImmutable2 x::Vector{Int} MyImmutable2() = new() end nonpointerfree_immutable_3 = MyImmutable2() # Immutable with a non-concrete datatype (issue #143) -immutable Vague +struct Vague x::Integer end vague = Vague(7) # Immutable with a union of BitsTypes -immutable BitsUnion +struct BitsUnion x::Union{Int64, Float64} end bitsunion = BitsUnion(5.0) # Immutable with a union of Types -let UT = if JLD.TYPESYSTEM_06 - eval(parse("Type{T} where T <: Union{Int64, Float64}")) - else - Union{Type{Int64}, Type{Float64}} - end - @eval immutable TypeUnionField +let UT = eval(parse("Type{T} where T <: Union{Int64, Float64}")) + @eval struct TypeUnionField x::$UT end end typeunionfield = TypeUnionField(Int64) # Generic union type field -immutable GenericUnionField +struct GenericUnionField x::Union{Vector{Int},Int} end genericunionfield = GenericUnionField(1) @@ -180,7 +169,7 @@ arr_contained = [1, 2, 3] arr_ref = typeof(arr_contained)[] push!(arr_ref, arr_contained, arr_contained) # Object references -type ObjRefType +mutable struct ObjRefType x::ObjRefType y::ObjRefType ObjRefType() = new() @@ -189,7 +178,7 @@ end ref1 = ObjRefType() obj_ref = ObjRefType(ObjRefType(ref1, ref1), ObjRefType(ref1, ref1)) # Immutable that requires padding between elements in array -immutable PaddingTest +struct PaddingTest x::Int64 y::Int8 end @@ -217,7 +206,7 @@ Bbig = Any[i for i=1:3000] Sbig = "A test string "^1000 # Bits type type parameters -type BitsParams{x}; end +mutable struct BitsParams{x}; end bitsparamfloat = BitsParams{1.0}() bitsparambool = BitsParams{true}() bitsparamsymbol = BitsParams{:x}() @@ -234,10 +223,10 @@ iseq(x::SimpleVector, y::SimpleVector) = collect(x) == collect(y) # Issue #243 # Type that overloads != so that it is not boolean -type NALikeType; end -@compat Base.:(!=)(::NALikeType, ::NALikeType) = NALikeType() -@compat Base.:(!=)(::NALikeType, ::Void) = NALikeType() -@compat Base.:(!=)(::Void, ::NALikeType) = NALikeType() +mutable struct NALikeType; end +Base.:(!=)(::NALikeType, ::NALikeType) = NALikeType() +Base.:(!=)(::NALikeType, ::Void) = NALikeType() +Base.:(!=)(::Void, ::NALikeType) = NALikeType() natyperef = Any[NALikeType(), NALikeType()] # Issue #110 @@ -355,9 +344,9 @@ fn = joinpath(tempdir(),"test.jld") # Issue #106 module Mod106 using Compat: @compat -@compat primitive type Typ{T} 64 end -typ{T}(x::Int64, ::Type{T}) = reinterpret(Typ{T}, x) -@compat abstract type UnexportedT end +primitive type Typ{T} 64 end +typ(x::Int64, ::Type{T}) where {T} = reinterpret(Typ{T}, x) +abstract type UnexportedT end end @@ -804,25 +793,25 @@ using Compat: @compat using JLD import ..fn, Core.Intrinsics.box -type TestType1 +mutable struct TestType1 x::Int end -type TestType2 +mutable struct TestType2 x::Int end -immutable TestType3 +struct TestType3 x::TestType2 end -type TestType4 +mutable struct TestType4 x::Int end -type TestType5 +mutable struct TestType5 x::TestType4 end -type TestType6 end -@compat primitive type TestType7 8 end -immutable TestType8 +mutable struct TestType6 end +primitive type TestType7 8 end +struct TestType8 a::TestType4 b::TestType5 c::TestType6 @@ -847,13 +836,13 @@ jldopen(fn, "w") do file end end -type TestType1 +mutable struct TestType1 x::Float64 end -type TestType2 +mutable struct TestType2 x::Int end -immutable TestType3 +struct TestType3 x::TestType1 end diff --git a/test/type_translation.jl b/test/type_translation.jl index 5d131b1..e2898c8 100644 --- a/test/type_translation.jl +++ b/test/type_translation.jl @@ -7,7 +7,7 @@ module Writing using JLD import ..Translation: filename -type MyType +mutable struct MyType a::Int end @@ -24,12 +24,12 @@ module Reading using JLD, Base.Test import ..Translation: filename -type MyType +mutable struct MyType a::Int b::Float32 end -type MyOldType +mutable struct MyOldType a::Int end