diff --git a/base/deprecated.jl b/base/deprecated.jl index d5b3a1f1d26118..f3030d7087230e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -978,6 +978,11 @@ end @deprecate_moved randjump "Random" true true @deprecate_moved GLOBAL_RNG "Random" false true +@deprecate_moved serialize "Serialization" true true +@deprecate_moved deserialize "Serialization" true true +@deprecate_moved AbstractSerializer "Serialization" true true +@deprecate_moved SerializationState "Serialization" true true + # 24595 @deprecate falses(A::AbstractArray) falses(size(A)) @deprecate trues(A::AbstractArray) trues(size(A)) diff --git a/base/dict.jl b/base/dict.jl index d42dc8d1ff3622..8ee9bdc20a14d4 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -55,8 +55,6 @@ function show(io::IO, t::AbstractDict{K,V}) where V where K end end -abstract type AbstractSerializer end - # Dict # These can be changed, to trade off better performance for space diff --git a/base/exports.jl b/base/exports.jl index 9894fdff2a37fe..63fa0411ce73e5 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -8,7 +8,6 @@ export StackTraces, Sys, Libc, - Serializer, Docs, Markdown, Threads, @@ -83,8 +82,6 @@ export RoundNearestTiesUp, RoundToZero, RoundUp, - AbstractSerializer, - SerializationState, Set, Some, StepRange, @@ -832,7 +829,6 @@ export close, connect, countlines, - deserialize, eachline, eof, fd, @@ -883,7 +879,6 @@ export seekend, seekstart, send, - serialize, skip, skipchars, take!, diff --git a/base/loading.jl b/base/loading.jl index fad783f1ac056f..901395aa138933 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -561,7 +561,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof( rm(output, force=true) # Remove file if it exists code_object = """ while !eof(STDIN) - eval(Main, deserialize(STDIN)) + eval(Main, Meta.parse(chop(readuntil(STDIN, '\\0')))) end """ io = open(pipeline(detach(`$(julia_cmd()) -O0 @@ -572,26 +572,28 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof( "w", STDOUT) in = io.in try - serialize(in, quote + write(in, """ + begin empty!(Base.LOAD_PATH) - append!(Base.LOAD_PATH, $LOAD_PATH) + append!(Base.LOAD_PATH, $(repr(LOAD_PATH))) empty!(Base.LOAD_CACHE_PATH) - append!(Base.LOAD_CACHE_PATH, $LOAD_CACHE_PATH) + append!(Base.LOAD_CACHE_PATH, $(repr(LOAD_CACHE_PATH))) empty!(Base.DL_LOAD_PATH) - append!(Base.DL_LOAD_PATH, $DL_LOAD_PATH) + append!(Base.DL_LOAD_PATH, $(repr(DL_LOAD_PATH))) empty!(Base._concrete_dependencies) - append!(Base._concrete_dependencies, $concrete_deps) + append!(Base._concrete_dependencies, $(repr(concrete_deps))) Base._track_dependencies[] = true - end) + end\0 + """) source = source_path(nothing) if source !== nothing - serialize(in, quote - task_local_storage()[:SOURCE_PATH] = $(source) - end) + write(in, """ + task_local_storage()[:SOURCE_PATH] = $(repr(source))\0 + """) end - serialize(in, :(Base.include(Base.__toplevel__, $(abspath(input))))) + write(in, "Base.include(Base.__toplevel__, $(repr(abspath(input))))\0") if source !== nothing - serialize(in, :(delete!(task_local_storage(), :SOURCE_PATH))) + write(in, "delete!(task_local_storage(), :SOURCE_PATH)\0") end close(in) catch ex diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 54d19bade231ac..f77a6d9280654a 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -581,8 +581,7 @@ end function build(pkg::AbstractString, build_file::AbstractString, errfile::AbstractString) # To isolate the build from the running Julia process, we execute each build.jl file in - # a separate process. Errors are serialized to errfile for later reporting. - # TODO: serialize the same way the load cache does, not with strings + # a separate process. Errors are written to errfile for later reporting. LOAD_PATH = filter(x -> x isa AbstractString, Base.LOAD_PATH) code = """ empty!(Base.LOAD_PATH) @@ -603,8 +602,8 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac ------------------------------------------------------------ # Build failed for \$pkg \""" exception=err,catch_backtrace() - serialize(f, pkg) - serialize(f, err) + write(f, pkg); write(f, 0x00) + write(f, sprint(showerror, err)); write(f, 0x00) end end """ @@ -636,8 +635,8 @@ function build!(pkgs::Vector, errs::Dict, seen::Set=Set()) mktemp() do errfile, f build!(pkgs, seen, errfile) while !eof(f) - pkg = deserialize(f) - err = deserialize(f) + pkg = chop(readuntil(f, '\0')) + err = chop(readuntil(f, '\0')) errs[pkg] = err end end diff --git a/base/precompile.jl b/base/precompile.jl index ae754410d0a406..652e31bda0c091 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -1190,7 +1190,6 @@ precompile(Tuple{typeof(Base.unsafe_write), Base.TCPSocket, Base.RefValue{UInt8} precompile(Tuple{typeof(Core.Compiler.length), Tuple{Core.Compiler.Const, DataType, Core.Compiler.Const}}) precompile(Tuple{typeof(Core.Compiler.getindex), Tuple{Core.Compiler.Const, DataType, Core.Compiler.Const}, Int64}) precompile(Tuple{typeof(Base.unsafe_write), Base.TCPSocket, Base.RefValue{Int32}, Int64}) -precompile(Tuple{typeof(Base.Serializer.write_as_tag), Base.TCPSocket, Int32}) precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Base.MethodList}) precompile(Tuple{typeof(Base.ht_keyindex), Base.Dict{UInt64, UInt64}, UInt64}) precompile(Tuple{typeof(Base.unique), Array{Symbol, 1}}) @@ -1203,7 +1202,6 @@ precompile(Tuple{typeof(Base.rehash!), Base.Dict{UInt64, Nothing}, Int64}) precompile(Tuple{typeof(Base.ht_keyindex2!), Base.Dict{UInt64, Nothing}, UInt64}) precompile(Tuple{typeof(Base._setindex!), Base.Dict{UInt64, Nothing}, Nothing, UInt64, Int64}) precompile(Tuple{typeof(Base.ht_keyindex), Base.Dict{WeakRef, Any}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.object_number), TypeName}) precompile(Tuple{typeof(Base.isassigned), Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}, Int64}) precompile(Tuple{typeof(Base.uvfinalize), Base.TCPSocket}) precompile(Tuple{typeof(Base.close), Base.TCPSocket}) @@ -1292,7 +1290,6 @@ precompile(Tuple{typeof(Base.put_unbuffered), Base.Channel{Int64}, Int64}) precompile(Tuple{typeof(Base.put!), Base.Channel{Int64}, Int64}) precompile(Tuple{typeof(Base._delete!), Base.Dict{Any, Any}, Int64}) precompile(Tuple{typeof(Base.write), Base.TCPSocket, Array{Int64, 1}}) -precompile(Tuple{typeof(Base.Serializer.serialize_array_data), Base.TCPSocket, Array{Int64, 1}}) precompile(Tuple{typeof(Base.sort!), Array{Int64, 1}, Int64, Int64, Base.Sort.InsertionSortAlg, Base.Order.ForwardOrdering}) precompile(Tuple{typeof(Base.Sort.partition!), Array{Int64, 1}, Int64, Int64, Base.Order.ForwardOrdering}) precompile(Tuple{typeof(Base.sort!), Array{Int64, 1}, Int64, Int64, Base.Sort.QuickSortAlg, Base.Order.ForwardOrdering}) @@ -1455,43 +1452,6 @@ precompile(Tuple{typeof(Base.require), Symbol}) precompile(Tuple{typeof(Base.resize!), Array{Base.Condition, 1}, Int64}) precompile(Tuple{typeof(Base.resize!), Array{Tuple{String, Float64}, 1}, Int64}) precompile(Tuple{typeof(Base.resize!), Array{UInt8, 1}, Int32}) -precompile(Tuple{typeof(Base.Serializer.deserialize_array), Base.Serializer.SerializationState{Base.PipeEndpoint}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.PipeEndpoint}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{Int64}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{QuoteNode}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{String}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{UInt64}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_cycle), Base.Serializer.SerializationState{Base.PipeEndpoint}, Expr}) -precompile(Tuple{typeof(Base.Serializer.deserialize_datatype), Base.Serializer.SerializationState{Base.PipeEndpoint}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_expr), Base.Serializer.SerializationState{Base.PipeEndpoint}, Int64}) -precompile(Tuple{typeof(Base.Serializer.handle_deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Int32}) -precompile(Tuple{typeof(Base.Serializer.serialize_any), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Array{Any, 1}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Array{String, 1}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Bool}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Expr}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Int64}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Module}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, SimpleVector}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, String}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Symbol}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Tuple{Int64}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Tuple{Symbol, UInt64}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, UInt64}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, Expr}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, UInt64}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle_header), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode}) -precompile(Tuple{typeof(Base.Serializer.serialize_mod_names), Base.Serializer.SerializationState{Base.Pipe}, Module}) -precompile(Tuple{typeof(Base.Serializer.serialize_type), Base.Serializer.SerializationState{Base.Pipe}, DataType}) -precompile(Tuple{typeof(Base.Serializer.serialize_type_data), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}, Bool}) -precompile(Tuple{typeof(Base.Serializer.serialize_typename), Base.Serializer.SerializationState{Base.Pipe}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.should_send_whole_type), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}}) -precompile(Tuple{typeof(Base.Serializer.write_as_tag), Base.Pipe, Int32}) precompile(Tuple{typeof(Base.setindex!), Base.Dict{Symbol, Base.Condition}, Base.Condition, Symbol}) precompile(Tuple{typeof(Base._setindex!), Base.Dict{Symbol, Base.Condition}, Base.Condition, Symbol, Int64}) precompile(Tuple{typeof(Base.setindex!), Base.Dict{Symbol, UInt64}, UInt64, Symbol}) diff --git a/base/stacktraces.jl b/base/stacktraces.jl index 587801630f6e30..745eaabc67e2d1 100644 --- a/base/stacktraces.jl +++ b/base/stacktraces.jl @@ -7,7 +7,6 @@ module StackTraces import Base: hash, ==, show -import Base.Serializer: serialize, deserialize using Base.Printf: @printf using Base: coalesce @@ -96,29 +95,6 @@ function hash(frame::StackFrame, h::UInt) h = hash(frame.inlined, h) end -# provide a custom serializer that skips attempting to serialize the `outer_linfo` -# which is likely to contain complex references, types, and module references -# that may not exist on the receiver end -function serialize(s::AbstractSerializer, frame::StackFrame) - Serializer.serialize_type(s, typeof(frame)) - serialize(s, frame.func) - serialize(s, frame.file) - write(s.io, frame.line) - write(s.io, frame.from_c) - write(s.io, frame.inlined) - write(s.io, frame.pointer) -end - -function deserialize(s::AbstractSerializer, ::Type{StackFrame}) - func = deserialize(s) - file = deserialize(s) - line = read(s.io, Int) - from_c = read(s.io, Bool) - inlined = read(s.io, Bool) - pointer = read(s.io, UInt64) - return StackFrame(func, file, line, nothing, from_c, inlined, pointer) -end - """ lookup(pointer::Union{Ptr{Cvoid}, UInt}) -> Vector{StackFrame} diff --git a/base/sysimg.jl b/base/sysimg.jl index 3d2a358dc24b13..bc3c2501cc2642 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -410,9 +410,6 @@ include("Enums.jl") using .Enums # concurrency and parallelism -include("serialize.jl") -using .Serializer -import .Serializer: serialize, deserialize include("channels.jl") # utilities - timing, help, edit @@ -509,6 +506,7 @@ Base.require(:Base64) Base.require(:CRC32c) Base.require(:Dates) Base.require(:DelimitedFiles) +Base.require(:Serialization) Base.require(:Distributed) Base.require(:FileWatching) Base.require(:Future) @@ -533,6 +531,7 @@ Base.require(:Unicode) @deprecate_binding Dates root_module(:Dates) true ", run `using Dates` instead" @deprecate_binding Distributed root_module(:Distributed) true ", run `using Distributed` instead" @deprecate_binding Random root_module(:Random) true ", run `using Random` instead" + @deprecate_binding Serializer root_module(:Serialization) true ", run `using Serialization` instead" # PR #25249 @deprecate_binding SparseArrays root_module(:SparseArrays) true ", run `using SparseArrays` instead" diff --git a/doc/src/base/base.md b/doc/src/base/base.md index 7a94e593a5d14f..595eccc8406640 100644 --- a/doc/src/base/base.md +++ b/doc/src/base/base.md @@ -93,7 +93,6 @@ Base.Libc Base.Markdown Base.Meta Base.Pkg -Base.Serializer Base.StackTraces Base.Sys Base.Threads diff --git a/doc/src/base/io-network.md b/doc/src/base/io-network.md index 2fb060f88f58c7..b3b1e6825c4499 100644 --- a/doc/src/base/io-network.md +++ b/doc/src/base/io-network.md @@ -32,9 +32,6 @@ Base.isreadonly Base.iswritable Base.isreadable Base.isopen -Base.Serializer.serialize -Base.Serializer.deserialize -Base.Serializer.writeheader Base.Grisu.print_shortest Base.fd Base.redirect_stdout diff --git a/stdlib/Distributed/src/Distributed.jl b/stdlib/Distributed/src/Distributed.jl index 6bd4563037c614..ea53439d91c76a 100644 --- a/stdlib/Distributed/src/Distributed.jl +++ b/stdlib/Distributed/src/Distributed.jl @@ -9,7 +9,7 @@ module Distributed # imports for extension import Base: getindex, wait, put!, take!, fetch, isready, push!, length, - hash, ==, connect, kill, serialize, deserialize, close, showerror + hash, ==, connect, kill, close, showerror # imports for use using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connected, @@ -18,7 +18,10 @@ using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connecte AsyncGenerator, acquire, release, invokelatest, shell_escape_posixly, uv_error, coalesce, notnothing -# NOTE: clusterserialize.jl imports additional symbols from Base.Serializer for use +using Serialization +import Serialization: serialize, deserialize + +# NOTE: clusterserialize.jl imports additional symbols from Serialization for use export @spawn, diff --git a/stdlib/Distributed/src/clusterserialize.jl b/stdlib/Distributed/src/clusterserialize.jl index 7af4485c29bade..01c5ada9f5fdb0 100644 --- a/stdlib/Distributed/src/clusterserialize.jl +++ b/stdlib/Distributed/src/clusterserialize.jl @@ -1,10 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Base.Serializer: serialize_cycle, deserialize_cycle, writetag, - __deserialized_types__, serialize_typename, deserialize_typename, - TYPENAME_TAG, reset_state, serialize_type +using Serialization: serialize_cycle, deserialize_cycle, writetag, + __deserialized_types__, serialize_typename, deserialize_typename, + TYPENAME_TAG, reset_state, serialize_type -import Base.Serializer: object_number, lookup_object_number, remember_object +import Serialization: object_number, lookup_object_number, remember_object mutable struct ClusterSerializer{I<:IO} <: AbstractSerializer io::I diff --git a/stdlib/Distributed/src/messages.jl b/stdlib/Distributed/src/messages.jl index 0dd70baff6d779..c44ea38a660ef6 100644 --- a/stdlib/Distributed/src/messages.jl +++ b/stdlib/Distributed/src/messages.jl @@ -76,7 +76,7 @@ struct JoinCompleteMsg <: AbstractMsg end # Avoiding serializing AbstractMsg containers results in a speedup -# of approximately 10%. Can be removed once module Serializer +# of approximately 10%. Can be removed once module Serialization # has been suitably improved. const msgtypes = Any[CallWaitMsg, IdentifySocketAckMsg, IdentifySocketMsg, diff --git a/stdlib/Distributed/src/precompile.jl b/stdlib/Distributed/src/precompile.jl index f5c7f64d22dadb..9b3b5ac9d35147 100644 --- a/stdlib/Distributed/src/precompile.jl +++ b/stdlib/Distributed/src/precompile.jl @@ -116,28 +116,28 @@ precompile(Tuple{typeof(Distributed.disable_nagle), Base.TCPSocket}) precompile(Tuple{typeof(Distributed.message_handler_loop), Base.TCPSocket, Base.TCPSocket, Bool}) precompile(Tuple{typeof(Distributed.process_tcp_streams), Base.TCPSocket, Base.TCPSocket, Bool}) precompile(Tuple{Type{Distributed.JoinPGRPMsg}, Int64, Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}, Symbol, Bool}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.JoinPGRPMsg}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}}) -precompile(Tuple{typeof(Base.Serializer.should_send_whole_type), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, SimpleVector}) -precompile(Tuple{typeof(Base.Serializer.serialize_type_data), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}, Bool}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{Int64}}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) -precompile(Tuple{typeof(Base.Serializer.serialize_type), Distributed.ClusterSerializer{Base.TCPSocket}, DataType}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Bool}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.JoinPGRPMsg}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}}) +precompile(Tuple{typeof(Serialization.should_send_whole_type), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, SimpleVector}) +precompile(Tuple{typeof(Serialization.serialize_type_data), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}, Bool}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Any}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{Int64}}) +precompile(Tuple{typeof(Serialization.serialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) +precompile(Tuple{typeof(Serialization.serialize_type), Distributed.ClusterSerializer{Base.TCPSocket}, DataType}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Bool}) precompile(Tuple{typeof(Distributed.serialize_global_from_main), Distributed.ClusterSerializer{Base.TCPSocket}, Symbol}) -precompile(Tuple{typeof(Base.Serializer.serialize_mod_names), Distributed.ClusterSerializer{Base.TCPSocket}, Module}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Symbol}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Module}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Any, 1}}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.serialize_typename), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Symbol, 1}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) -precompile(Tuple{typeof(Base.Serializer.serialize_cycle_header), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) -precompile(Tuple{typeof(Base.Serializer.serialize_any), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) +precompile(Tuple{typeof(Serialization.serialize_mod_names), Distributed.ClusterSerializer{Base.TCPSocket}, Module}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Symbol}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Module}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Any, 1}}) +precompile(Tuple{typeof(Serialization.serialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) +precompile(Tuple{typeof(Serialization.serialize_typename), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Symbol, 1}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, TypeName}) +precompile(Tuple{typeof(Serialization.serialize_cycle_header), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) +precompile(Tuple{typeof(Serialization.serialize_any), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}}}) precompile(Tuple{typeof(Distributed.send_msg_), Distributed.Worker, Distributed.MsgHeader, Distributed.ResultMsg, Bool}) precompile(Tuple{typeof(Distributed.send_msg_now), Distributed.Worker, Distributed.MsgHeader, Distributed.ResultMsg}) precompile(Tuple{Type{Core.Compiler.Generator{I, F} where F where I}, Type{Core.Compiler.Const}, Tuple{Int64, typeof(Distributed.rmprocs)}}) @@ -158,12 +158,12 @@ precompile(Tuple{typeof(Core.Compiler.getindex), Tuple{Int64, typeof(Distributed precompile(Tuple{typeof(Core.Compiler.start), Tuple{typeof(Distributed.rmprocs), Int64}}) precompile(Tuple{typeof(Core.Compiler.indexed_next), Tuple{typeof(Distributed.rmprocs), Int64}, Int64, Int64}) precompile(Tuple{typeof(Core.Compiler.getindex), Tuple{typeof(Distributed.rmprocs), Int64}, Int64}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Expr}) -precompile(Tuple{typeof(Base.Serializer.handle_deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int32}) -precompile(Tuple{typeof(Base.Serializer.deserialize_array), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_datatype), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_expr), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Expr}) +precompile(Tuple{typeof(Serialization.handle_deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int32}) +precompile(Tuple{typeof(Serialization.deserialize_array), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_datatype), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_expr), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) precompile(Tuple{typeof(Core.Compiler.isbits), Tuple{Int64, typeof(Distributed.rmprocs)}}) precompile(Tuple{Type{Core.Compiler.Generator{I, F} where F where I}, Type{QuoteNode}, Tuple{Int64, typeof(Distributed.rmprocs)}}) precompile(Tuple{Type{Core.Compiler.Generator{Tuple{Int64, typeof(Distributed.rmprocs)}, Type{QuoteNode}}}, Type{QuoteNode}, Tuple{Int64, typeof(Distributed.rmprocs)}}) @@ -190,9 +190,9 @@ precompile(Tuple{typeof(Distributed.deliver_result), Base.TCPSocket, Symbol, Dis precompile(Tuple{typeof(Distributed.disable_nagle), Base.TCPSocket}) precompile(Tuple{typeof(Distributed.message_handler_loop), Base.TCPSocket, Base.TCPSocket, Bool}) precompile(Tuple{typeof(Distributed.process_tcp_streams), Base.TCPSocket, Base.TCPSocket, Bool}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Module}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{SimpleVector}}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Union}}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Module}}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{SimpleVector}}) precompile(Tuple{Type{Distributed.JoinPGRPMsg}, Int64, Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}, Symbol, Bool}) precompile(Tuple{typeof(Distributed.handle_msg), Distributed.JoinPGRPMsg, Distributed.MsgHeader, Base.TCPSocket, Base.TCPSocket, Base.VersionNumber}) precompile(Tuple{Type{Distributed.WorkerConfig}}) @@ -206,15 +206,15 @@ precompile(Tuple{typeof(Base.convert), Type{Distributed.ClusterManager}, Distrib precompile(Tuple{typeof(Base.convert), Type{Distributed.WorkerConfig}, Distributed.WorkerConfig}) precompile(Tuple{typeof(Distributed.send_connection_hdr), Distributed.Worker, Bool}) precompile(Tuple{typeof(Distributed.manage), Distributed.LocalManager, Int64, Distributed.WorkerConfig, Symbol}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.JoinCompleteMsg}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Expr}) -precompile(Tuple{typeof(Base.Serializer.handle_deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int32}) -precompile(Tuple{typeof(Base.Serializer.deserialize_array), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_datatype), Distributed.ClusterSerializer{Base.TCPSocket}}) -precompile(Tuple{typeof(Base.Serializer.deserialize_expr), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Int64}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.JoinCompleteMsg}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_cycle), Distributed.ClusterSerializer{Base.TCPSocket}, Expr}) +precompile(Tuple{typeof(Serialization.handle_deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Int32}) +precompile(Tuple{typeof(Serialization.deserialize_array), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_datatype), Distributed.ClusterSerializer{Base.TCPSocket}}) +precompile(Tuple{typeof(Serialization.deserialize_expr), Distributed.ClusterSerializer{Base.TCPSocket}, Int64}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{Int64}}) precompile(Tuple{Type{Distributed.JoinCompleteMsg}, Int64, Int64}) precompile(Tuple{typeof(Distributed.handle_msg), Distributed.JoinCompleteMsg, Distributed.MsgHeader, Base.TCPSocket, Base.TCPSocket, Base.VersionNumber}) precompile(Tuple{typeof(Base.hash), Distributed.RemoteChannel{Base.Channel{Any}}, UInt64}) @@ -235,18 +235,18 @@ precompile(Tuple{typeof(Base.put!), Base.Channel{Any}, Distributed.WorkerPool}) precompile(Tuple{typeof(Base.put_buffered), Base.Channel{Any}, Distributed.WorkerPool}) precompile(Tuple{typeof(Base.put_unbuffered), Base.Channel{Any}, Distributed.WorkerPool}) precompile(Tuple{typeof(Base.push!), Distributed.WorkerPool, Int64}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.RemoteDoMsg}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, typeof(Distributed.set_valid_processes)}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{Array{Int64, 1}}}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Int64, 1}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{typeof(Distributed.set_valid_processes)}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Distributed.RemoteDoMsg}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, typeof(Distributed.set_valid_processes)}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{Array{Int64, 1}}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Array{Int64, 1}}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{typeof(Distributed.set_valid_processes)}}) precompile(Tuple{typeof(Distributed.handle_msg), Distributed.RemoteDoMsg, Distributed.MsgHeader, Base.TCPSocket, Base.TCPSocket, Base.VersionNumber}) precompile(Tuple{typeof(Distributed.set_valid_processes), Array{Int64, 1}}) precompile(Tuple{typeof(Distributed._rmprocs), Array{Int64, 1}, Float64}) precompile(Tuple{typeof(Base.kill), Distributed.LocalManager, Int64, Distributed.WorkerConfig}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, typeof(Base.exit)}) -precompile(Tuple{typeof(Base.Serializer.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{}}) -precompile(Tuple{typeof(Base.Serializer.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{typeof(Base.exit)}}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, typeof(Base.exit)}) +precompile(Tuple{typeof(Serialization.serialize), Distributed.ClusterSerializer{Base.TCPSocket}, Tuple{}}) +precompile(Tuple{typeof(Serialization.deserialize), Distributed.ClusterSerializer{Base.TCPSocket}, Type{typeof(Base.exit)}}) precompile(Tuple{typeof(Distributed.finalize_ref), Distributed.RemoteChannel{Base.Channel{Any}}}) precompile(Tuple{typeof(Distributed.send_del_client), Distributed.RemoteChannel{Base.Channel{Any}}}) precompile(Tuple{typeof(Base.:(==)), Distributed.RemoteChannel{Base.Channel{Any}}, Distributed.RemoteChannel{Base.Channel{Any}}}) diff --git a/stdlib/Distributed/src/workerpool.jl b/stdlib/Distributed/src/workerpool.jl index f3ce4e8c3ae486..3070a6d56f32de 100644 --- a/stdlib/Distributed/src/workerpool.jl +++ b/stdlib/Distributed/src/workerpool.jl @@ -48,7 +48,7 @@ function serialize(S::AbstractSerializer, pool::WorkerPool) # initialize the `ref` to point to self and only send the ref. # Other workers will forward all put!, take!, calls to the process owning # the ref (and hence the pool). - Serializer.serialize_type(S, typeof(pool)) + Serialization.serialize_type(S, typeof(pool)) serialize(S, pool.ref) end diff --git a/stdlib/Distributed/test/distributed_exec.jl b/stdlib/Distributed/test/distributed_exec.jl index 9eb6d9cd5a5470..41a5f1f439daf2 100644 --- a/stdlib/Distributed/test/distributed_exec.jl +++ b/stdlib/Distributed/test/distributed_exec.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Test, Distributed, Random +using Test, Distributed, Random, Serialization import Distributed: launch, manage include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl")) @@ -1149,6 +1149,7 @@ v6 = FooModEverywhere # b) hash value has not changed. @everywhere begin + using Serialization global testsercnt_d = Dict() mutable struct TestSerCnt v @@ -1157,15 +1158,15 @@ v6 = FooModEverywhere hash(x::TestSerCnt, h::UInt) = hash(hash(x.v), h) ==(x1::TestSerCnt, x2::TestSerCnt) = (x1.v == x2.v) - function Base.serialize(s::AbstractSerializer, t::TestSerCnt) - Base.Serializer.serialize_type(s, TestSerCnt) + function Serialization.serialize(s::AbstractSerializer, t::TestSerCnt) + Serialization.serialize_type(s, TestSerCnt) serialize(s, t.v) global testsercnt_d cnt = get!(testsercnt_d, objectid(t), 0) testsercnt_d[objectid(t)] = cnt+1 end - Base.deserialize(s::AbstractSerializer, ::Type{TestSerCnt}) = TestSerCnt(deserialize(s)) + Serialization.deserialize(s::AbstractSerializer, ::Type{TestSerCnt}) = TestSerCnt(deserialize(s)) end # hash value of tsc is not changed diff --git a/stdlib/Profile/test/runtests.jl b/stdlib/Profile/test/runtests.jl index 1585153b681a97..0e1db25e4b2201 100644 --- a/stdlib/Profile/test/runtests.jl +++ b/stdlib/Profile/test/runtests.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Test, Profile +using Test, Profile, Serialization function busywait(t, n_tries) iter = 0 diff --git a/stdlib/Random/src/RNGs.jl b/stdlib/Random/src/RNGs.jl index 669b4a43f6ce97..df66918af69c09 100644 --- a/stdlib/Random/src/RNGs.jl +++ b/stdlib/Random/src/RNGs.jl @@ -29,7 +29,7 @@ else # !windows rand(rd::RandomDevice, sp::SamplerBoolBitInteger) = read( rd.file, sp[]) function serialize(s::AbstractSerializer, rd::RandomDevice) - Serializer.serialize_type(s, typeof(rd)) + Serialization.serialize_type(s, typeof(rd)) serialize(s, rd.unlimited) end function deserialize(s::AbstractSerializer, t::Type{RandomDevice}) diff --git a/stdlib/Random/src/Random.jl b/stdlib/Random/src/Random.jl index 24c9fa185abbbb..1631e7b0042813 100644 --- a/stdlib/Random/src/Random.jl +++ b/stdlib/Random/src/Random.jl @@ -12,7 +12,9 @@ using Base.GMP: Limb using Base: BitInteger, BitInteger_types, BitUnsigned, @gc_preserve -import Base: copymutable, copy, copy!, ==, hash, serialize, deserialize, convert +import Base: copymutable, copy, copy!, ==, hash, convert +using Serialization +import Serialization: serialize, deserialize import Base: rand, randn export srand, diff --git a/stdlib/Serialization/docs/src/index.md b/stdlib/Serialization/docs/src/index.md new file mode 100644 index 00000000000000..c01ead7a7eaea5 --- /dev/null +++ b/stdlib/Serialization/docs/src/index.md @@ -0,0 +1,7 @@ +# Serialization + +```@docs +Serialization.serialize +Serialization.deserialize +Serialization.writeheader +``` diff --git a/base/serialize.jl b/stdlib/Serialization/src/Serialization.jl similarity index 95% rename from base/serialize.jl rename to stdlib/Serialization/src/Serialization.jl index 1dfb6984fae356..710bbe8bf7505a 100644 --- a/base/serialize.jl +++ b/stdlib/Serialization/src/Serialization.jl @@ -1,32 +1,34 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license """ -Provide serialization of Julia code via the functions +Provide serialization of Julia objects via the functions * [`serialize`](@ref) * [`deserialize`](@ref) """ -module Serializer +module Serialization import Base: GMP, Bottom, unsafe_convert, uncompressed_ast import Core: svec using Base: ViewIndex, Slice, index_lengths, unwrap_unionall -export serialize, deserialize, SerializationState +export serialize, deserialize, AbstractSerializer, Serializer -mutable struct SerializationState{I<:IO} <: AbstractSerializer +abstract type AbstractSerializer end + +mutable struct Serializer{I<:IO} <: AbstractSerializer io::I counter::Int table::IdDict pending_refs::Vector{Int} known_object_data::Dict{UInt64,Any} - SerializationState{I}(io::I) where I<:IO = new(io, 0, IdDict(), Int[], Dict{UInt64,Any}()) + Serializer{I}(io::I) where I<:IO = new(io, 0, IdDict(), Int[], Dict{UInt64,Any}()) end -SerializationState(io::IO) = SerializationState{typeof(io)}(io) +Serializer(io::IO) = Serializer{typeof(io)}(io) -## serializing values ## +@deprecate SerializationState Serializer -# types AbstractSerializer and Serializer # defined in dict.jl +## serializing values ## const n_int_literals = 33 const n_reserved_slots = 25 @@ -386,11 +388,11 @@ lookup_object_number(s::AbstractSerializer, n::UInt64) = nothing remember_object(s::AbstractSerializer, @nospecialize(o), n::UInt64) = nothing -function lookup_object_number(s::SerializationState, n::UInt64) +function lookup_object_number(s::Serializer, n::UInt64) return get(s.known_object_data, n, nothing) end -function remember_object(s::SerializationState, @nospecialize(o), n::UInt64) +function remember_object(s::Serializer, @nospecialize(o), n::UInt64) s.known_object_data[n] = o return nothing end @@ -648,7 +650,7 @@ function serialize_any(s::AbstractSerializer, @nospecialize(x)) end """ - Serializer.writeheader(s::AbstractSerializer) + Serialization.writeheader(s::AbstractSerializer) Write an identifying header to the specified serializer. The header consists of 8 bytes as follows: @@ -688,11 +690,11 @@ versions of Julia, or an instance of Julia with a different system image. `Ptr` serialized as all-zero bit patterns (`NULL`). An 8-byte identifying header is written to the stream first. To avoid writing the header, -construct a `SerializationState` and use it as the first argument to `serialize` instead. -See also [`Serializer.writeheader`](@ref). +construct a `Serializer` and use it as the first argument to `serialize` instead. +See also [`Serialization.writeheader`](@ref). """ function serialize(s::IO, x) - ss = SerializationState(s) + ss = Serializer(s) writeheader(ss) serialize(ss, x) end @@ -708,7 +710,7 @@ It has been designed with simplicity and performance as a goal and does not vali the data read. Malformed data can result in process termination. The caller has to ensure the integrity and correctness of data read from `stream`. """ -deserialize(s::IO) = deserialize(SerializationState(s)) +deserialize(s::IO) = deserialize(Serializer(s)) function deserialize(s::AbstractSerializer) handle_deserialize(s, Int32(read(s.io, UInt8)::UInt8)) @@ -1195,4 +1197,31 @@ function deserialize(s::AbstractSerializer, t::Type{Regex}) Regex(pattern, compile_options, match_options) end +## StackTraces + +# provide a custom serializer that skips attempting to serialize the `outer_linfo` +# which is likely to contain complex references, types, and module references +# that may not exist on the receiver end +function serialize(s::AbstractSerializer, frame::Base.StackTraces.StackFrame) + serialize_type(s, typeof(frame)) + serialize(s, frame.func) + serialize(s, frame.file) + write(s.io, frame.line) + write(s.io, frame.from_c) + write(s.io, frame.inlined) + write(s.io, frame.pointer) +end + +function deserialize(s::AbstractSerializer, ::Type{Base.StackTraces.StackFrame}) + func = deserialize(s) + file = deserialize(s) + line = read(s.io, Int) + from_c = read(s.io, Bool) + inlined = read(s.io, Bool) + pointer = read(s.io, UInt64) + return Base.StackTraces.StackFrame(func, file, line, nothing, from_c, inlined, pointer) +end + +include("precompile.jl") + end diff --git a/stdlib/Serialization/src/precompile.jl b/stdlib/Serialization/src/precompile.jl new file mode 100644 index 00000000000000..2f29f05c2cb326 --- /dev/null +++ b/stdlib/Serialization/src/precompile.jl @@ -0,0 +1,40 @@ +precompile(Tuple{typeof(Serialization.write_as_tag), Base.TCPSocket, Int32}) +precompile(Tuple{typeof(Serialization.object_number), TypeName}) +precompile(Tuple{typeof(Serialization.serialize_array_data), Base.TCPSocket, Array{Int64, 1}}) +precompile(Tuple{typeof(Serialization.deserialize_array), Serialization.Serializer{Base.PipeEndpoint}}) +precompile(Tuple{typeof(Serialization.deserialize), Base.PipeEndpoint}) +precompile(Tuple{typeof(Serialization.deserialize), Serialization.Serializer{Base.PipeEndpoint}}) +precompile(Tuple{typeof(Serialization.deserialize), Serialization.Serializer{Base.PipeEndpoint}, Type{Int64}}) +precompile(Tuple{typeof(Serialization.deserialize), Serialization.Serializer{Base.PipeEndpoint}, Type{QuoteNode}}) +precompile(Tuple{typeof(Serialization.deserialize), Serialization.Serializer{Base.PipeEndpoint}, Type{String}}) +precompile(Tuple{typeof(Serialization.deserialize), Serialization.Serializer{Base.PipeEndpoint}, Type{UInt64}}) +precompile(Tuple{typeof(Serialization.deserialize_cycle), Serialization.Serializer{Base.PipeEndpoint}, Expr}) +precompile(Tuple{typeof(Serialization.deserialize_datatype), Serialization.Serializer{Base.PipeEndpoint}}) +precompile(Tuple{typeof(Serialization.deserialize_expr), Serialization.Serializer{Base.PipeEndpoint}, Int64}) +precompile(Tuple{typeof(Serialization.handle_deserialize), Serialization.Serializer{Base.PipeEndpoint}, Int32}) +precompile(Tuple{typeof(Serialization.serialize_any), Serialization.Serializer{Base.Pipe}, QuoteNode}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Array{Any, 1}}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Array{String, 1}}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Bool}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Expr}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Int64}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Module}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, QuoteNode}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, SimpleVector}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, String}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Symbol}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Tuple{Int64}}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Tuple{Symbol, UInt64}}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, Type{Any}}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, TypeName}) +precompile(Tuple{typeof(Serialization.serialize), Serialization.Serializer{Base.Pipe}, UInt64}) +precompile(Tuple{typeof(Serialization.serialize_cycle), Serialization.Serializer{Base.Pipe}, Expr}) +precompile(Tuple{typeof(Serialization.serialize_cycle), Serialization.Serializer{Base.Pipe}, TypeName}) +precompile(Tuple{typeof(Serialization.serialize_cycle), Serialization.Serializer{Base.Pipe}, UInt64}) +precompile(Tuple{typeof(Serialization.serialize_cycle_header), Serialization.Serializer{Base.Pipe}, QuoteNode}) +precompile(Tuple{typeof(Serialization.serialize_mod_names), Serialization.Serializer{Base.Pipe}, Module}) +precompile(Tuple{typeof(Serialization.serialize_type), Serialization.Serializer{Base.Pipe}, DataType}) +precompile(Tuple{typeof(Serialization.serialize_type_data), Serialization.Serializer{Base.Pipe}, Type{Any}, Bool}) +precompile(Tuple{typeof(Serialization.serialize_typename), Serialization.Serializer{Base.Pipe}, TypeName}) +precompile(Tuple{typeof(Serialization.should_send_whole_type), Serialization.Serializer{Base.Pipe}, Type{Any}}) +precompile(Tuple{typeof(Serialization.write_as_tag), Base.Pipe, Int32}) diff --git a/test/serialize.jl b/stdlib/Serialization/test/runtests.jl similarity index 94% rename from test/serialize.jl rename to stdlib/Serialization/test/runtests.jl index 456d08fbbe3e7d..21f158a18d0dab 100644 --- a/test/serialize.jl +++ b/stdlib/Serialization/test/runtests.jl @@ -1,11 +1,11 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Test, Random +using Test, Random, Serialization # Check that serializer hasn't gone out-of-frame -@test Serializer.sertag(Symbol) == 1 -@test Serializer.sertag(()) == 68 -@test Serializer.sertag(false) == 76 +@test Serialization.sertag(Symbol) == 1 +@test Serialization.sertag(()) == 68 +@test Serialization.sertag(false) == 76 function create_serialization_stream(f::Function) s = IOBuffer() @@ -15,20 +15,20 @@ end # Tags create_serialization_stream() do s - Serializer.writetag(s, Serializer.sertag(Bool)) - @test take!(s)[end] == UInt8(Serializer.sertag(Bool)) + Serialization.writetag(s, Serialization.sertag(Bool)) + @test take!(s)[end] == UInt8(Serialization.sertag(Bool)) end create_serialization_stream() do s - Serializer.write_as_tag(s, Serializer.sertag(Bool)) - @test take!(s)[end] == UInt8(Serializer.sertag(Bool)) + Serialization.write_as_tag(s, Serialization.sertag(Bool)) + @test take!(s)[end] == UInt8(Serialization.sertag(Bool)) end create_serialization_stream() do s - Serializer.write_as_tag(s, Serializer.sertag(Symbol)) + Serialization.write_as_tag(s, Serialization.sertag(Symbol)) data = take!(s) @test data[end-1] == 0x00 - @test data[end] == UInt8(Serializer.sertag(Symbol)) + @test data[end] == UInt8(Serialization.sertag(Symbol)) end # SubString @@ -306,13 +306,14 @@ end # Anonymous Functions main_ex = quote + using Serialization $create_serialization_stream() do s local g() = :magic_token_anon_fun_test serialize(s, g) serialize(s, g) seekstart(s) - ds = SerializationState(s) + ds = Serializer(s) local g2 = deserialize(ds) $Test.@test g2 !== g $Test.@test g2() == :magic_token_anon_fun_test @@ -425,7 +426,7 @@ end # issue #13452 module Test13452 -using Test +using Test, Serialization module Shell export foo @@ -510,9 +511,9 @@ let io = IOBuffer() serialize(io, ()) seekstart(io) b = read(io) - @test b[1] == Serializer.HEADER_TAG + @test b[1] == Serialization.HEADER_TAG @test b[2:3] == b"JL" - @test b[4] == Serializer.ser_version + @test b[4] == Serialization.ser_version @test (b[5] & 0x3) == (ENDIAN_BOM == 0x01020304) @test ((b[5] & 0xc)>>2) == (sizeof(Int) == 8) @test (b[5] & 0xf0) == 0 diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 0387857bb7403c..9784b5f156ff58 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -9,10 +9,12 @@ module SharedArrays using Mmap, Distributed, Random -import Base: length, size, ndims, IndexStyle, reshape, convert, deepcopy_internal, serialize, deserialize, +import Base: length, size, ndims, IndexStyle, reshape, convert, deepcopy_internal, show, getindex, setindex!, fill!, similar, reduce, map!, copyto!, unsafe_convert import Random -import Base.Serializer: serialize_cycle_header, serialize_type, writetag, UNDEFREF_TAG +using Serialization +using Serialization: serialize_cycle_header, serialize_type, writetag, UNDEFREF_TAG, serialize, deserialize +import Serialization: serialize, deserialize import Distributed: RRID, procs import Base.Filesystem: JL_O_CREAT, JL_O_RDWR, S_IRUSR, S_IWUSR using Base.Printf.@sprintf diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index 1efa24ecfba51a..828fdaba7e960c 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -3,6 +3,7 @@ using SuiteSparse.CHOLMOD using DelimitedFiles using Test +using Serialization # CHOLMOD tests srand(123) diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index f10a10bf1dfafb..d2fb0f3a99eb51 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -2,6 +2,8 @@ module TestHelpers +using Serialization + include("dimensionful.jl") export Furlong @@ -56,6 +58,7 @@ end function challenge_prompt(code::Expr, challenges; timeout::Integer=10, debug::Bool=true) output_file = tempname() wrapped_code = quote + using Serialization result = let $code end diff --git a/test/bigint.jl b/test/bigint.jl index 0c29a8a961aa95..f705ff7268d9f6 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Random +using Random, Serialization a = parse(BigInt,"123456789012345678901234567890") b = parse(BigInt,"123456789012345678901234567891") diff --git a/test/choosetests.jl b/test/choosetests.jl index 3520359ce009b9..1d33a94539032e 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -49,7 +49,7 @@ function choosetests(choices = []) "euler", "show", "lineedit", "replcompletions", "repl", "replutil", "sets", "goto", "llvmcall", "llvmcall2", "grisu", "some", "meta", "stacktraces", "libgit2", "docs", - "markdown", "serialize", "misc", "threads", + "markdown", "misc", "threads", "enums", "cmdlineargs", "i18n", "int", "checked", "bitset", "floatfuncs", "compile", "inline", "boundscheck", "error", "ambiguous", "cartesian", "asmvariant", "osutils", diff --git a/test/compile.jl b/test/compile.jl index b2787eab7f8a05..6b6ed13dfffcaa 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -220,7 +220,7 @@ try Dict(s => Base.module_uuid(Base.root_module(s)) for s in [:Base64, :CRC32c, :Dates, :DelimitedFiles, :Distributed, :FileWatching, :Future, :IterativeEigensolvers, :Libdl, :LinearAlgebra, :Logging, :Mmap, :Printf, - :Profile, :Random, :SharedArrays, :SparseArrays, :SuiteSparse, :Test, :Unicode])) + :Profile, :Random, :Serialization, :SharedArrays, :SparseArrays, :SuiteSparse, :Test, :Unicode])) @test discard_module.(deps) == deps1 @test current_task()(0x01, 0x4000, 0x30031234) == 2 diff --git a/test/core.jl b/test/core.jl index b6040eb90ea4e7..913746cdb5100a 100644 --- a/test/core.jl +++ b/test/core.jl @@ -5725,6 +5725,8 @@ t4 = vcat(A23567, t2, t3) @test t4[6:10] == A23567 @test t4[11:15] == A23567 +using Serialization + for U in unboxedunions local U for N in (1, 2, 3, 4) diff --git a/test/enums.jl b/test/enums.jl index 97f83810920bfe..6f4a5a8e145cea 100644 --- a/test/enums.jl +++ b/test/enums.jl @@ -3,7 +3,7 @@ # For curmod_* include("testenv.jl") -using Test +using Test, Serialization @test_throws MethodError convert(Enum, 1.0) diff --git a/test/libgit2.jl b/test/libgit2.jl index cd0db741a2abab..210837f3129ac8 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -3,7 +3,7 @@ isdefined(Main, :TestHelpers) || @eval Main include(joinpath(@__DIR__, "TestHelpers.jl")) import Main.TestHelpers: challenge_prompt -using Random +using Random, Serialization const LIBGIT2_MIN_VER = v"0.23.0" const LIBGIT2_HELPER_PATH = joinpath(@__DIR__, "libgit2-helpers.jl") @@ -2598,6 +2598,7 @@ mktempdir() do dir repo_url = "https://$common_name:$port/Example.jl" repo_dir = joinpath(root, "dest") code = """ + using Serialization dest_dir = "$repo_dir" open("$errfile", "w+") do f try diff --git a/test/mpfr.jl b/test/mpfr.jl index 7c107c253b0ff9..8eaab11847535a 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +using Serialization + import Base.MPFR @testset "constructors" begin setprecision(53) do diff --git a/test/stacktraces.jl b/test/stacktraces.jl index ca51dec7498609..4db3de6ca08ec1 100644 --- a/test/stacktraces.jl +++ b/test/stacktraces.jl @@ -2,6 +2,8 @@ # Tests for /base/stacktraces.jl +using Serialization + let @noinline child() = stacktrace() @noinline parent() = child()