From aff0a3558cd65c4090b5b0145eb2ea87385520d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 1 Feb 2024 19:57:35 +0100 Subject: [PATCH] Add serialization upgrade script for type renaming --- src/Serialization/Fields.jl | 6 +-- src/Serialization/Rings.jl | 2 +- src/Serialization/Upgrades/0.15.0.jl | 60 ++++++++++++++++++++++++++++ src/Serialization/Upgrades/main.jl | 1 + 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/Serialization/Upgrades/0.15.0.jl diff --git a/src/Serialization/Fields.jl b/src/Serialization/Fields.jl index 4293a8b2b1cc..9fa63fcf5600 100644 --- a/src/Serialization/Fields.jl +++ b/src/Serialization/Fields.jl @@ -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) @@ -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) diff --git a/src/Serialization/Rings.jl b/src/Serialization/Rings.jl index d29217b4d37c..fe130aaee3a3 100644 --- a/src/Serialization/Rings.jl +++ b/src/Serialization/Rings.jl @@ -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 diff --git a/src/Serialization/Upgrades/0.15.0.jl b/src/Serialization/Upgrades/0.15.0.jl new file mode 100644 index 000000000000..6ead1bb57d0e --- /dev/null +++ b/src/Serialization/Upgrades/0.15.0.jl @@ -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 +)) diff --git a/src/Serialization/Upgrades/main.jl b/src/Serialization/Upgrades/main.jl index 13f1bd3b50cb..1ba2e528be89 100644 --- a/src/Serialization/Upgrades/main.jl +++ b/src/Serialization/Upgrades/main.jl @@ -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)