From 3017e2e4c614cadfbe60d838b8a36fdad603aa6d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 28 Oct 2025 17:39:32 +0100 Subject: [PATCH 1/3] Revise type_param delegation For elements, use type plus parent. For rings, default to just the type. --- experimental/LieAlgebras/src/serialization.jl | 4 --- src/Serialization/Algebras.jl | 2 ++ src/Serialization/Fields.jl | 11 +++---- src/Serialization/Groups.jl | 2 -- src/Serialization/LieTheory.jl | 4 --- src/Serialization/Rings.jl | 30 +++++++++++-------- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/experimental/LieAlgebras/src/serialization.jl b/experimental/LieAlgebras/src/serialization.jl index ba5fd65d67cd..9e7f74c28891 100644 --- a/experimental/LieAlgebras/src/serialization.jl +++ b/experimental/LieAlgebras/src/serialization.jl @@ -127,8 +127,6 @@ end @register_serialization_type LinearLieAlgebraElem @register_serialization_type DirectSumLieAlgebraElem -type_params(x::T) where {T<:LieAlgebraElem} = TypeParams(T, parent(x)) - function save_object(s::SerializerState, x::LieAlgebraElem) save_object(s, coefficients(x)) end @@ -222,8 +220,6 @@ end @register_serialization_type LieAlgebraModuleElem -type_params(x::T) where {T<:LieAlgebraModuleElem} = TypeParams(T, parent(x)) - function save_object(s::SerializerState, x::LieAlgebraModuleElem) save_object(s, coefficients(x)) end diff --git a/src/Serialization/Algebras.jl b/src/Serialization/Algebras.jl index 87b170a82f66..f8c42b093e29 100644 --- a/src/Serialization/Algebras.jl +++ b/src/Serialization/Algebras.jl @@ -4,6 +4,8 @@ # Free associative algebra serialization @register_serialization_type FreeAssociativeAlgebra uses_id +type_params(R::T) where T <: FreeAssociativeAlgebra = TypeParams(T, coefficient_ring(R)) + function save_object(s::SerializerState, A::FreeAssociativeAlgebra) save_data_dict(s) do save_object(s, symbols(A), :symbols) diff --git a/src/Serialization/Fields.jl b/src/Serialization/Fields.jl index c63dfaf01efa..cea5bec0944e 100644 --- a/src/Serialization/Fields.jl +++ b/src/Serialization/Fields.jl @@ -5,13 +5,6 @@ ################################################################################ # field of rationals (singleton type) @register_serialization_type QQField -# exclude from ring union definition -type_params(::QQField) = TypeParams(QQField, nothing) -type_params(::QQFieldElem) = TypeParams(QQFieldElem, nothing) -type_params(::fpField) = TypeParams(fpField, nothing) -type_params(::FpField) = TypeParams(FpField, nothing) -type_params(::QQBarField) = TypeParams(QQBarField, nothing) -type_params(::PadicField) = TypeParams(PadicField, nothing) ################################################################################ # type_params for field extension types @@ -244,6 +237,8 @@ end @register_serialization_type FracField uses_id +type_params(R::T) where T <: FracField = TypeParams(T, base_ring(R)) + const FracUnionTypes = Union{MPolyRingElem, PolyRingElem, UniversalPolyRingElem} # we use the union to prevent QQField from using these save methods @@ -282,6 +277,8 @@ end @register_serialization_type AbstractAlgebra.Generic.RationalFunctionField "RationalFunctionField" uses_id +type_params(R::T) where T <: AbstractAlgebra.Generic.RationalFunctionField = TypeParams(T, base_ring(R)) + function save_object(s::SerializerState, RF::AbstractAlgebra.Generic.RationalFunctionField{<: FieldElem, <: MPolyRingElem}) save_data_dict(s) do diff --git a/src/Serialization/Groups.jl b/src/Serialization/Groups.jl index 3dbf4cb4e571..37ad2fb73b71 100644 --- a/src/Serialization/Groups.jl +++ b/src/Serialization/Groups.jl @@ -90,8 +90,6 @@ using Oscar: GAPGroup, _coeff # `GAPGroupElem` objects get serialized together with their parents. const GrpElemUnionType = Union{GAPGroupElem, FinGenAbGroupElem} -type_params(p::T) where T <: GrpElemUnionType = TypeParams(T, parent(p)) - ############################################################################# # attributes handling const GAPGroup_attributes = [ diff --git a/src/Serialization/LieTheory.jl b/src/Serialization/LieTheory.jl index 83e4e9c2cfd5..f2ff09dd5889 100644 --- a/src/Serialization/LieTheory.jl +++ b/src/Serialization/LieTheory.jl @@ -74,8 +74,6 @@ end @register_serialization_type WeightLatticeElem -type_params(w::WeightLatticeElem) = TypeParams(WeightLatticeElem, parent(w)) - function save_object(s::SerializerState, w::WeightLatticeElem) save_object(s, _vec(coefficients(w))) end @@ -107,8 +105,6 @@ end @register_serialization_type WeylGroupElem -type_params(w::WeylGroupElem) = TypeParams(WeylGroupElem, parent(w)) - function save_object(s::SerializerState, x::WeylGroupElem) save_object(s, word(x)) end diff --git a/src/Serialization/Rings.jl b/src/Serialization/Rings.jl index 2b7e5962759b..5dbb6cb1111b 100644 --- a/src/Serialization/Rings.jl +++ b/src/Serialization/Rings.jl @@ -1,8 +1,6 @@ ################################################################################ # Common union types -const RingMatElemUnion = Union{NCRingElem, MatElem, SMat} -const RingMatSpaceUnion = Union{NCRing, MatSpace, SMatSpace} const ModRingUnion = Union{zzModRing, ZZModRing} const ModRingElemUnion = Union{zzModRingElem, ZZModRingElem} @@ -31,14 +29,18 @@ const LaurentUnionType = Union{Generic.LaurentSeriesRing, ################################################################################ # type_params functions -type_params(x::T) where T <: RingMatElemUnion = TypeParams(T, parent(x)) -type_params(R::T) where T <: RingMatSpaceUnion = TypeParams(T, base_ring(R)) +# element types by default use their parent as reference object +type_params(x::T) where T <: SetElem = TypeParams(T, parent(x)) +type_params(x::T) where T <: SMat = TypeParams(T, parent(x)) + +# rings, groups etc. default have no reference object +type_params(R::T) where T <: AbstractAlgebra.Set = TypeParams(T, nothing) + +# ideals and matrix spaces have their base ring as reference object type_params(x::T) where T <: Ideal = TypeParams(T, base_ring(x)) -# exclude from ring union -type_params(::ZZRing) = TypeParams(ZZRing, nothing) -type_params(::ZZRingElem) = TypeParams(ZZRingElem, nothing) -type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R)) -type_params(R::T) where T <: ModRingUnion = TypeParams(T, nothing) +type_params(x::T) where T <: MatSpace = TypeParams(T, base_ring(x)) +type_params(x::T) where T <: SMatSpace = TypeParams(T, base_ring(x)) + ################################################################################ # ring of integers (singleton type) @@ -85,6 +87,9 @@ end @register_serialization_type MPolyDecRing uses_id @register_serialization_type AbstractAlgebra.Generic.LaurentMPolyWrapRing uses_id +# polynomial-like rings use their coefficient ring as reference object +type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R)) + function save_object(s::SerializerState, R::PolyRingUnionType) save_data_dict(s) do save_object(s, symbols(R), :symbols) @@ -378,6 +383,7 @@ end # Power Series @register_serialization_type SeriesRing uses_id +type_params(R::T) where T <: SeriesRing = TypeParams(T, base_ring(R)) function save_object(s::SerializerState, R::RelPowerSeriesUnionType) save_data_dict(s) do @@ -497,6 +503,8 @@ end @register_serialization_type Generic.LaurentSeriesField "LaurentSeriesField" uses_id @register_serialization_type ZZLaurentSeriesRing uses_id +type_params(R::T) where T <: LaurentUnionType = TypeParams(T, base_ring(R)) + function save_object(s::SerializerState, R::LaurentUnionType) save_data_dict(s) do save_object(s, var(R), :var) @@ -702,8 +710,6 @@ end @register_serialization_type MPolyLocRingElem -type_params(a::MPolyLocRingElem) = TypeParams(MPolyLocRingElem, parent(a)) - function save_object(s::SerializerState, a::MPolyLocRingElem) # `save_type_params` will store the output of type_params # in this case the parent ring @@ -742,8 +748,6 @@ end @register_serialization_type MPolyQuoLocRingElem -type_params(a::T) where {T<:MPolyQuoLocRingElem} = TypeParams(T, parent(a)) - function save_object(s::SerializerState, a::MPolyQuoLocRingElem) save_object(s, [lifted_numerator(a), lifted_denominator(a)]) end From 280a407761ac4633eb3b3f9f77710b7bc5905cfb Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 6 Nov 2025 09:59:36 +0100 Subject: [PATCH 2/3] typos --- src/Serialization/main.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serialization/main.jl b/src/Serialization/main.jl index 1d42e3039048..0974be733f9e 100644 --- a/src/Serialization/main.jl +++ b/src/Serialization/main.jl @@ -419,7 +419,7 @@ function load_typed_object(s::DeserializerState, key::Symbol; override_params::A end # The load mechanism first checks if the type needs to load necessary -# parameters before loading it's data, if so a type tree is traversed +# parameters before loading its data, if so a type tree is traversed function load_typed_object(s::DeserializerState; override_params::Any = nothing) T = decode_type(s) Base.issingletontype(T) && return T() @@ -702,7 +702,7 @@ Load the object stored in the given io stream respectively in the file `filename`. If `params` is specified, then the root object of the loaded data -either will attempt a load using these parameters. In the case of Rings this +either will attempt a load using these parameters. In the case of rings this results in setting its parent, or in the case of a container of ring types such as `Vector` or `Tuple`, then the parent of the entries will be set using their `params`. From 710e899adbdf9a01aa9497ab8c0c16b5aaeedb64 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 6 Nov 2025 10:00:11 +0100 Subject: [PATCH 3/3] No params in TypeParams for singleton types --- src/Serialization/main.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Serialization/main.jl b/src/Serialization/main.jl index 0974be733f9e..6353fd23e6c2 100644 --- a/src/Serialization/main.jl +++ b/src/Serialization/main.jl @@ -167,12 +167,17 @@ struct TypeParams{T, S} type::Type{T} params::S - function TypeParams(T::Type, args::Pair...) - return new{T, typeof(args)}(T, args) + function TypeParams(T::Type, params) + if Base.issingletontype(T) + return new{T, Nothing}(T, nothing) + else + return new{T, typeof(params)}(T, params) + end end - TypeParams(T::Type, obj) = new{T, typeof(obj)}(T, obj) end +TypeParams(T::Type, args::Pair...) = TypeParams(T, args) + params(tp::TypeParams) = tp.params type(tp::TypeParams) = tp.type