Skip to content

Commit

Permalink
Add serialization upgrade script for type renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 1, 2024
1 parent 2505874 commit aff0a35
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Serialization/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ function load_object(s::DeserializerState, ::Type{<:FieldEmbeddingTypes})
end
end

@register_serialization_type Hecke.EmbeddedNumField uses_id
@register_serialization_type EmbeddedNumField uses_id

function save_object(s::SerializerState, E::Hecke.EmbeddedNumField)
function save_object(s::SerializerState, E::EmbeddedNumField)
K = number_field(E)
e = embedding(E)

Expand All @@ -507,7 +507,7 @@ function save_object(s::SerializerState, E::Hecke.EmbeddedNumField)
end
end

function load_object(s::DeserializerState, ::Type{Hecke.EmbeddedNumField})
function load_object(s::DeserializerState, ::Type{EmbeddedNumField})
K = load_typed_object(s, :num_field)
e = load_typed_object(s, :embedding)

Expand Down
2 changes: 1 addition & 1 deletion src/Serialization/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ end

################################################################################
# Laurent Series
@register_serialization_type Generic.LaurentSeriesRing "LaurentSeriesRing" uses_id
@register_serialization_type Generic.LaurentSeriesRing "LaurentSeriesRing" uses_id
@register_serialization_type Generic.LaurentSeriesField "LaurentSeriesField" uses_id
@register_serialization_type ZZLaurentSeriesRing uses_id

Expand Down
60 changes: 60 additions & 0 deletions src/Serialization/Upgrades/0.15.0.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
################################################################################
# Upgrade Summary
# This upgrade currentlz only adapts to type renamings.

push!(upgrade_scripts_set, UpgradeScript(
v"0.15.0",
function upgrade_0_15_0(s::UpgradeState, dict::Dict)

upgraded_dict = dict

renamings = Dict{String,String}([
("FlintPadicField", "PadicField"),
("padic", "PadicFieldElem"),
("arb", "ArbFieldElem"),
("acb", "AcbFieldElem"),
("AnticNumberField", "AbsSimpleNumField"),
("nf_elem", "AbsSimpleNumFieldElem"),
("NfAbsNS", "AbsNonSimpleNumField"),
("NfAbsNSElem", "AbsNonSimpleNumFieldElem"),
("Hecke.NfRel", "Hecke.RelSimpleNumField"),
("Hecke.NfRelElem", "Hecke.RelSimpleNumFieldElem"),
("Hecke.NfRelNS", "Hecke.RelNonSimpleNumField"),
("Hecke.NfRelNSElem", "Hecke.RelNonSimpleNumFieldElem"),
("Hecke.NumFieldEmbNfAbs", "Hecke.AbsSimpleNumFieldEmbedding"),
("Hecke.NumFieldEmbNfAbsNS", "Hecke.AbsNonSimpleNumFieldEmbedding"),
("Hecke.NumFieldEmbNfRel", "Hecke.RelSimpleNumFieldEmbedding"),
("Hecke.NumFieldEmbNfNS", "Hecke.RelNonSimpleNumFieldEmbedding"),
("GrpAbFinGen", "FinGenAbGroup"),
("GrpAbFinGenElem", "FinGenAbGroupElem"),
("Hecke.EmbeddedField", "EmbeddedNumField"),
("EmbeddedElem", "EmbeddedNumFieldElem"),
])

if haskey(dict, :_type) && dict[:_type] isa String && haskey(renamings, dict[:_type])
upgraded_dict[:_type] = renamings[dict[:_type]]
end
if haskey(dict, :_type) &&
dict[:_type] isa Dict &&
haskey(dict[:_type], :name) &&
dict[:_type][:name] isa String &&
haskey(renamings, dict[:_type][:name])
upgraded_dict[:_type][:name] = renamings[dict[:_type][:name]]
end

# handle data upgrade (recurse on sub tree)
if haskey(dict, :data) && dict[:data] isa Dict
upgraded_dict[:data] = upgrade_0_15_0(s, dict[:data])
end

if haskey(dict, :_refs)
upgraded_refs = Dict()
for (k, v) in dict[:_refs]
upgraded_refs[k] = upgrade_0_15_0(s, v)
end
upgraded_dict[:_refs] = upgraded_refs
end

return upgraded_dict
end
))
1 change: 1 addition & 0 deletions src/Serialization/Upgrades/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ include("0.11.3.jl")
include("0.12.0.jl")
include("0.12.2.jl")
include("0.13.0.jl")
include("0.15.0.jl")

upgrade_scripts = collect(upgrade_scripts_set)
sort!(upgrade_scripts; by=version)
Expand Down

0 comments on commit aff0a35

Please sign in to comment.