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 2, 2024
1 parent 9302a8e commit a103b6c
Show file tree
Hide file tree
Showing 4 changed files with 71 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
66 changes: 66 additions & 0 deletions src/Serialization/Upgrades/0.15.0.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
################################################################################
# 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"),
])

function upgrade_type(d::String)
return get(renamings, d, d)
end
function upgrade_type(d::Dict)
upg_d = d
upg_d[:name] = get(renamings, d[:name], d[:name])
if d[:params] isa Dict && haskey(d[:params], :_type)
upg_d[:params][:_type] = upgrade_type(d[:params][:_type])
elseif d[:params] isa Vector
upg_d[:params] = [upgrade_type(v) for v in d[:params]]
end
return upg_d
end

if haskey(dict, :_type)
upgraded_dict[:_type] = upgrade_type(dict[:_type])
end

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 a103b6c

Please sign in to comment.