Skip to content

Commit 625923f

Browse files
authored
move Serializer to stdlib (#25628)
1 parent 4f0b09e commit 625923f

34 files changed

+220
-194
lines changed

base/deprecated.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ end
979979
@deprecate_moved randjump "Random" true true
980980
@deprecate_moved GLOBAL_RNG "Random" false true
981981

982+
@deprecate_moved serialize "Serialization" true true
983+
@deprecate_moved deserialize "Serialization" true true
984+
@deprecate_moved AbstractSerializer "Serialization" true true
985+
@deprecate_moved SerializationState "Serialization" true true
986+
982987
# 24595
983988
@deprecate falses(A::AbstractArray) falses(size(A))
984989
@deprecate trues(A::AbstractArray) trues(size(A))

base/dict.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function show(io::IO, t::AbstractDict{K,V}) where V where K
5555
end
5656
end
5757

58-
abstract type AbstractSerializer end
59-
6058
# Dict
6159

6260
# These can be changed, to trade off better performance for space

base/exports.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export
88
StackTraces,
99
Sys,
1010
Libc,
11-
Serializer,
1211
Docs,
1312
Markdown,
1413
Threads,
@@ -83,8 +82,6 @@ export
8382
RoundNearestTiesUp,
8483
RoundToZero,
8584
RoundUp,
86-
AbstractSerializer,
87-
SerializationState,
8885
Set,
8986
Some,
9087
StepRange,
@@ -835,7 +832,6 @@ export
835832
close,
836833
connect,
837834
countlines,
838-
deserialize,
839835
eachline,
840836
eof,
841837
fd,
@@ -886,7 +882,6 @@ export
886882
seekend,
887883
seekstart,
888884
send,
889-
serialize,
890885
skip,
891886
skipchars,
892887
take!,

base/loading.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
561561
rm(output, force=true) # Remove file if it exists
562562
code_object = """
563563
while !eof(STDIN)
564-
eval(Main, deserialize(STDIN))
564+
eval(Main, Meta.parse(chop(readuntil(STDIN, '\\0'))))
565565
end
566566
"""
567567
io = open(pipeline(detach(`$(julia_cmd()) -O0
@@ -572,26 +572,28 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
572572
"w", STDOUT)
573573
in = io.in
574574
try
575-
serialize(in, quote
575+
write(in, """
576+
begin
576577
empty!(Base.LOAD_PATH)
577-
append!(Base.LOAD_PATH, $LOAD_PATH)
578+
append!(Base.LOAD_PATH, $(repr(LOAD_PATH)))
578579
empty!(Base.LOAD_CACHE_PATH)
579-
append!(Base.LOAD_CACHE_PATH, $LOAD_CACHE_PATH)
580+
append!(Base.LOAD_CACHE_PATH, $(repr(LOAD_CACHE_PATH)))
580581
empty!(Base.DL_LOAD_PATH)
581-
append!(Base.DL_LOAD_PATH, $DL_LOAD_PATH)
582+
append!(Base.DL_LOAD_PATH, $(repr(DL_LOAD_PATH)))
582583
empty!(Base._concrete_dependencies)
583-
append!(Base._concrete_dependencies, $concrete_deps)
584+
append!(Base._concrete_dependencies, $(repr(concrete_deps)))
584585
Base._track_dependencies[] = true
585-
end)
586+
end\0
587+
""")
586588
source = source_path(nothing)
587589
if source !== nothing
588-
serialize(in, quote
589-
task_local_storage()[:SOURCE_PATH] = $(source)
590-
end)
590+
write(in, """
591+
task_local_storage()[:SOURCE_PATH] = $(repr(source))\0
592+
""")
591593
end
592-
serialize(in, :(Base.include(Base.__toplevel__, $(abspath(input)))))
594+
write(in, "Base.include(Base.__toplevel__, $(repr(abspath(input))))\0")
593595
if source !== nothing
594-
serialize(in, :(delete!(task_local_storage(), :SOURCE_PATH)))
596+
write(in, "delete!(task_local_storage(), :SOURCE_PATH)\0")
595597
end
596598
close(in)
597599
catch ex

base/pkg/entry.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ end
581581

582582
function build(pkg::AbstractString, build_file::AbstractString, errfile::AbstractString)
583583
# To isolate the build from the running Julia process, we execute each build.jl file in
584-
# a separate process. Errors are serialized to errfile for later reporting.
585-
# TODO: serialize the same way the load cache does, not with strings
584+
# a separate process. Errors are written to errfile for later reporting.
586585
LOAD_PATH = filter(x -> x isa AbstractString, Base.LOAD_PATH)
587586
code = """
588587
empty!(Base.LOAD_PATH)
@@ -603,8 +602,8 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac
603602
------------------------------------------------------------
604603
# Build failed for \$pkg
605604
\""" exception=err,catch_backtrace()
606-
serialize(f, pkg)
607-
serialize(f, err)
605+
write(f, pkg); write(f, 0x00)
606+
write(f, sprint(showerror, err)); write(f, 0x00)
608607
end
609608
end
610609
"""
@@ -636,8 +635,8 @@ function build!(pkgs::Vector, errs::Dict, seen::Set=Set())
636635
mktemp() do errfile, f
637636
build!(pkgs, seen, errfile)
638637
while !eof(f)
639-
pkg = deserialize(f)
640-
err = deserialize(f)
638+
pkg = chop(readuntil(f, '\0'))
639+
err = chop(readuntil(f, '\0'))
641640
errs[pkg] = err
642641
end
643642
end

base/precompile.jl

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,6 @@ precompile(Tuple{typeof(Base.unsafe_write), Base.TCPSocket, Base.RefValue{UInt8}
11901190
precompile(Tuple{typeof(Core.Compiler.length), Tuple{Core.Compiler.Const, DataType, Core.Compiler.Const}})
11911191
precompile(Tuple{typeof(Core.Compiler.getindex), Tuple{Core.Compiler.Const, DataType, Core.Compiler.Const}, Int64})
11921192
precompile(Tuple{typeof(Base.unsafe_write), Base.TCPSocket, Base.RefValue{Int32}, Int64})
1193-
precompile(Tuple{typeof(Base.Serializer.write_as_tag), Base.TCPSocket, Int32})
11941193
precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Base.MethodList})
11951194
precompile(Tuple{typeof(Base.ht_keyindex), Base.Dict{UInt64, UInt64}, UInt64})
11961195
precompile(Tuple{typeof(Base.unique), Array{Symbol, 1}})
@@ -1203,7 +1202,6 @@ precompile(Tuple{typeof(Base.rehash!), Base.Dict{UInt64, Nothing}, Int64})
12031202
precompile(Tuple{typeof(Base.ht_keyindex2!), Base.Dict{UInt64, Nothing}, UInt64})
12041203
precompile(Tuple{typeof(Base._setindex!), Base.Dict{UInt64, Nothing}, Nothing, UInt64, Int64})
12051204
precompile(Tuple{typeof(Base.ht_keyindex), Base.Dict{WeakRef, Any}, TypeName})
1206-
precompile(Tuple{typeof(Base.Serializer.object_number), TypeName})
12071205
precompile(Tuple{typeof(Base.isassigned), Array{Union{Tuple{Any, Int64}, Tuple{Tuple{}, Any, Bool}}, 1}, Int64})
12081206
precompile(Tuple{typeof(Base.uvfinalize), Base.TCPSocket})
12091207
precompile(Tuple{typeof(Base.close), Base.TCPSocket})
@@ -1292,7 +1290,6 @@ precompile(Tuple{typeof(Base.put_unbuffered), Base.Channel{Int64}, Int64})
12921290
precompile(Tuple{typeof(Base.put!), Base.Channel{Int64}, Int64})
12931291
precompile(Tuple{typeof(Base._delete!), Base.Dict{Any, Any}, Int64})
12941292
precompile(Tuple{typeof(Base.write), Base.TCPSocket, Array{Int64, 1}})
1295-
precompile(Tuple{typeof(Base.Serializer.serialize_array_data), Base.TCPSocket, Array{Int64, 1}})
12961293
precompile(Tuple{typeof(Base.sort!), Array{Int64, 1}, Int64, Int64, Base.Sort.InsertionSortAlg, Base.Order.ForwardOrdering})
12971294
precompile(Tuple{typeof(Base.Sort.partition!), Array{Int64, 1}, Int64, Int64, Base.Order.ForwardOrdering})
12981295
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})
14551452
precompile(Tuple{typeof(Base.resize!), Array{Base.Condition, 1}, Int64})
14561453
precompile(Tuple{typeof(Base.resize!), Array{Tuple{String, Float64}, 1}, Int64})
14571454
precompile(Tuple{typeof(Base.resize!), Array{UInt8, 1}, Int32})
1458-
precompile(Tuple{typeof(Base.Serializer.deserialize_array), Base.Serializer.SerializationState{Base.PipeEndpoint}})
1459-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.PipeEndpoint})
1460-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}})
1461-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{Int64}})
1462-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{QuoteNode}})
1463-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{String}})
1464-
precompile(Tuple{typeof(Base.Serializer.deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Type{UInt64}})
1465-
precompile(Tuple{typeof(Base.Serializer.deserialize_cycle), Base.Serializer.SerializationState{Base.PipeEndpoint}, Expr})
1466-
precompile(Tuple{typeof(Base.Serializer.deserialize_datatype), Base.Serializer.SerializationState{Base.PipeEndpoint}})
1467-
precompile(Tuple{typeof(Base.Serializer.deserialize_expr), Base.Serializer.SerializationState{Base.PipeEndpoint}, Int64})
1468-
precompile(Tuple{typeof(Base.Serializer.handle_deserialize), Base.Serializer.SerializationState{Base.PipeEndpoint}, Int32})
1469-
precompile(Tuple{typeof(Base.Serializer.serialize_any), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode})
1470-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Array{Any, 1}})
1471-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Array{String, 1}})
1472-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Bool})
1473-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Expr})
1474-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Int64})
1475-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Module})
1476-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode})
1477-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, SimpleVector})
1478-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, String})
1479-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Symbol})
1480-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Tuple{Int64}})
1481-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Tuple{Symbol, UInt64}})
1482-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}})
1483-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, TypeName})
1484-
precompile(Tuple{typeof(Base.Serializer.serialize), Base.Serializer.SerializationState{Base.Pipe}, UInt64})
1485-
precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, Expr})
1486-
precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, TypeName})
1487-
precompile(Tuple{typeof(Base.Serializer.serialize_cycle), Base.Serializer.SerializationState{Base.Pipe}, UInt64})
1488-
precompile(Tuple{typeof(Base.Serializer.serialize_cycle_header), Base.Serializer.SerializationState{Base.Pipe}, QuoteNode})
1489-
precompile(Tuple{typeof(Base.Serializer.serialize_mod_names), Base.Serializer.SerializationState{Base.Pipe}, Module})
1490-
precompile(Tuple{typeof(Base.Serializer.serialize_type), Base.Serializer.SerializationState{Base.Pipe}, DataType})
1491-
precompile(Tuple{typeof(Base.Serializer.serialize_type_data), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}, Bool})
1492-
precompile(Tuple{typeof(Base.Serializer.serialize_typename), Base.Serializer.SerializationState{Base.Pipe}, TypeName})
1493-
precompile(Tuple{typeof(Base.Serializer.should_send_whole_type), Base.Serializer.SerializationState{Base.Pipe}, Type{Any}})
1494-
precompile(Tuple{typeof(Base.Serializer.write_as_tag), Base.Pipe, Int32})
14951455
precompile(Tuple{typeof(Base.setindex!), Base.Dict{Symbol, Base.Condition}, Base.Condition, Symbol})
14961456
precompile(Tuple{typeof(Base._setindex!), Base.Dict{Symbol, Base.Condition}, Base.Condition, Symbol, Int64})
14971457
precompile(Tuple{typeof(Base.setindex!), Base.Dict{Symbol, UInt64}, UInt64, Symbol})

base/stacktraces.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module StackTraces
77

88

99
import Base: hash, ==, show
10-
import Base.Serializer: serialize, deserialize
1110
using Base.Printf: @printf
1211
using Base: coalesce
1312

@@ -96,29 +95,6 @@ function hash(frame::StackFrame, h::UInt)
9695
h = hash(frame.inlined, h)
9796
end
9897

99-
# provide a custom serializer that skips attempting to serialize the `outer_linfo`
100-
# which is likely to contain complex references, types, and module references
101-
# that may not exist on the receiver end
102-
function serialize(s::AbstractSerializer, frame::StackFrame)
103-
Serializer.serialize_type(s, typeof(frame))
104-
serialize(s, frame.func)
105-
serialize(s, frame.file)
106-
write(s.io, frame.line)
107-
write(s.io, frame.from_c)
108-
write(s.io, frame.inlined)
109-
write(s.io, frame.pointer)
110-
end
111-
112-
function deserialize(s::AbstractSerializer, ::Type{StackFrame})
113-
func = deserialize(s)
114-
file = deserialize(s)
115-
line = read(s.io, Int)
116-
from_c = read(s.io, Bool)
117-
inlined = read(s.io, Bool)
118-
pointer = read(s.io, UInt64)
119-
return StackFrame(func, file, line, nothing, from_c, inlined, pointer)
120-
end
121-
12298

12399
"""
124100
lookup(pointer::Union{Ptr{Cvoid}, UInt}) -> Vector{StackFrame}

base/sysimg.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ include("Enums.jl")
410410
using .Enums
411411

412412
# concurrency and parallelism
413-
include("serialize.jl")
414-
using .Serializer
415-
import .Serializer: serialize, deserialize
416413
include("channels.jl")
417414

418415
# utilities - timing, help, edit
@@ -509,6 +506,7 @@ Base.require(:Base64)
509506
Base.require(:CRC32c)
510507
Base.require(:Dates)
511508
Base.require(:DelimitedFiles)
509+
Base.require(:Serialization)
512510
Base.require(:Distributed)
513511
Base.require(:FileWatching)
514512
Base.require(:Future)
@@ -533,6 +531,7 @@ Base.require(:Unicode)
533531
@deprecate_binding Dates root_module(:Dates) true ", run `using Dates` instead"
534532
@deprecate_binding Distributed root_module(:Distributed) true ", run `using Distributed` instead"
535533
@deprecate_binding Random root_module(:Random) true ", run `using Random` instead"
534+
@deprecate_binding Serializer root_module(:Serialization) true ", run `using Serialization` instead"
536535

537536
# PR #25249
538537
@deprecate_binding SparseArrays root_module(:SparseArrays) true ", run `using SparseArrays` instead"

doc/src/base/base.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Base.Libc
9393
Base.Markdown
9494
Base.Meta
9595
Base.Pkg
96-
Base.Serializer
9796
Base.StackTraces
9897
Base.Sys
9998
Base.Threads

doc/src/base/io-network.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Base.isreadonly
3232
Base.iswritable
3333
Base.isreadable
3434
Base.isopen
35-
Base.Serializer.serialize
36-
Base.Serializer.deserialize
37-
Base.Serializer.writeheader
3835
Base.Grisu.print_shortest
3936
Base.fd
4037
Base.redirect_stdout

0 commit comments

Comments
 (0)