Skip to content

Commit 68177e0

Browse files
authored
Restrict static params of our types, so e.g. PolyRing{T} now always must satisfy T<:RingElement (#2286)
This gives a lot of extra hints to JET and also Julia itself.
1 parent bdeb681 commit 68177e0

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

src/AbstractAlgebra.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,6 @@ pretty_eq(x::Number, y::Number) = (x == y)
190190

191191
include("julia/JuliaTypes.jl")
192192

193-
# Unions of AbstractAlgebra abstract types and Julia types
194-
const JuliaRingElement = Union{Integer, Rational, AbstractFloat}
195-
const JuliaFieldElement = Union{Rational, AbstractFloat}
196-
const JuliaExactRingElement = Union{Integer, Rational}
197-
198-
const RingElement = Union{RingElem, JuliaRingElement}
199-
const NCRingElement = Union{NCRingElem, JuliaRingElement}
200-
201-
const FieldElement = Union{FieldElem, JuliaFieldElement}
202-
203193
include("ConcreteTypes.jl")
204194

205195
###############################################################################

src/AbstractTypes.jl

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,20 @@ abstract type RingElem <: NCRingElem end
3737

3838
abstract type FieldElem <: RingElem end
3939

40+
# unions of AbstractAlgebra abstract types and Julia types
41+
42+
const JuliaRingElement = Union{Integer, Rational, AbstractFloat}
43+
const JuliaFieldElement = Union{Rational, AbstractFloat}
44+
const JuliaExactRingElement = Union{Integer, Rational}
45+
46+
const RingElement = Union{RingElem, JuliaRingElement}
47+
const NCRingElement = Union{NCRingElem, JuliaRingElement}
48+
49+
const FieldElement = Union{FieldElem, JuliaFieldElement}
50+
4051
# parameterized domains
4152

42-
abstract type Module{T} <: AdditiveGroup end
53+
abstract type Module{T<:NCRingElement} <: AdditiveGroup end
4354

4455
abstract type FPModule{T} <: Module{T} end
4556

@@ -49,7 +60,7 @@ abstract type IdealSet{T} <: Set end
4960

5061
# elements of parameterised domains
5162

52-
abstract type ModuleElem{T} <: AdditiveGroupElem end
63+
abstract type ModuleElem{T<:NCRingElement} <: AdditiveGroupElem end
5364

5465
abstract type FPModuleElem{T} <: ModuleElem{T} end
5566

@@ -71,35 +82,35 @@ abstract type FPModuleHomomorphism <: FunctionalMap end
7182
# and for which a generic implementation is possible
7283
# over that base ring
7384

74-
abstract type PolyRing{T} <: Ring end
85+
abstract type PolyRing{T<:RingElement} <: Ring end
7586

76-
abstract type NCPolyRing{T} <: NCRing end
87+
abstract type NCPolyRing{T<:NCRingElement} <: NCRing end
7788

78-
abstract type MPolyRing{T} <: Ring end
89+
abstract type MPolyRing{T<:RingElement} <: Ring end
7990

80-
abstract type UniversalPolyRing{T} <: Ring end
91+
abstract type UniversalPolyRing{T<:RingElement} <: Ring end
8192

82-
abstract type LaurentPolyRing{T} <: Ring end
93+
abstract type LaurentPolyRing{T<:RingElement} <: Ring end
8394

84-
abstract type LaurentMPolyRing{T} <: Ring end
95+
abstract type LaurentMPolyRing{T<:RingElement} <: Ring end
8596

86-
abstract type SeriesRing{T} <: Ring end
97+
abstract type SeriesRing{T<:RingElement} <: Ring end
8798

88-
abstract type MSeriesRing{T} <: Ring end
99+
abstract type MSeriesRing{T<:RingElement} <: Ring end
89100

90-
abstract type ResidueRing{T} <: Ring end
101+
abstract type ResidueRing{T<:RingElement} <: Ring end
91102

92-
abstract type ResidueField{T} <: Field end
103+
abstract type ResidueField{T<:RingElement} <: Field end
93104

94-
abstract type FracField{T} <: Field end
105+
abstract type FracField{T<:RingElement} <: Field end
95106

96-
abstract type MatRing{T} <: NCRing end
107+
abstract type MatRing{T<:NCRingElement} <: NCRing end
97108

98-
abstract type FreeAssociativeAlgebra{T} <: NCRing end
109+
abstract type FreeAssociativeAlgebra{T<:RingElement} <: NCRing end
99110

100111
# Abstract types for number fields, parmeterised by the element type of
101112
# the base field.
102-
abstract type NumField{T} <: Field end
113+
abstract type NumField{T<:RingElement} <: Field end
103114

104115
# A type for number fields, which are represented using a primitive element.
105116
# (simple number fields)
@@ -110,27 +121,27 @@ abstract type SimpleNumField{T} <: NumField{T} end
110121
# that have some kind of base ring, and a generic
111122
# implementation is meaningful over that base ring
112123

113-
abstract type PolyRingElem{T} <: RingElem end
124+
abstract type PolyRingElem{T<:RingElement} <: RingElem end
114125

115-
abstract type NCPolyRingElem{T} <: NCRingElem end
126+
abstract type NCPolyRingElem{T<:NCRingElement} <: NCRingElem end
116127

117-
abstract type MPolyRingElem{T} <: RingElem end
128+
abstract type MPolyRingElem{T<:RingElement} <: RingElem end
118129

119-
abstract type UniversalPolyRingElem{T} <: RingElem end
130+
abstract type UniversalPolyRingElem{T<:RingElement} <: RingElem end
120131

121-
abstract type LaurentPolyRingElem{T} <: RingElem end
132+
abstract type LaurentPolyRingElem{T<:RingElement} <: RingElem end
122133

123-
abstract type LaurentMPolyRingElem{T} <: RingElem end
134+
abstract type LaurentMPolyRingElem{T<:RingElement} <: RingElem end
124135

125-
abstract type ResElem{T} <: RingElem end
136+
abstract type ResElem{T<:RingElement} <: RingElem end
126137

127-
abstract type ResFieldElem{T} <: FieldElem end
138+
abstract type ResFieldElem{T<:RingElement} <: FieldElem end
128139

129-
abstract type FracElem{T} <: FieldElem end
140+
abstract type FracElem{T<:RingElement} <: FieldElem end
130141

131-
abstract type SeriesElem{T} <: RingElem end
142+
abstract type SeriesElem{T<:RingElement} <: RingElem end
132143

133-
abstract type MSeriesElem{T} <: RingElem end
144+
abstract type MSeriesElem{T<:RingElement} <: RingElem end
134145

135146
abstract type RelPowerSeriesRingElem{T} <: SeriesElem{T} end
136147

@@ -140,11 +151,11 @@ abstract type AbsMSeriesElem{T} <: MSeriesElem{T} end
140151

141152
abstract type MatElem{T} <: ModuleElem{T} end
142153

143-
abstract type MatRingElem{T} <: NCRingElem end
154+
abstract type MatRingElem{T<:NCRingElement} <: NCRingElem end
144155

145-
abstract type FreeAssociativeAlgebraElem{T} <: NCRingElem end
156+
abstract type FreeAssociativeAlgebraElem{T<:RingElement} <: NCRingElem end
146157

147-
abstract type NumFieldElem{T} <: FieldElem end
158+
abstract type NumFieldElem{T<:RingElement} <: FieldElem end
148159

149160
abstract type SimpleNumFieldElem{T} <: NumFieldElem{T} end
150161

0 commit comments

Comments
 (0)