Skip to content

Commit 5805181

Browse files
remove kwargs merge when constructing BSImpl
1 parent ff2ee29 commit 5805181

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/types.jl

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,28 @@ Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
8484
struct Sym
8585
const name::Symbol
8686
const metadata::MetadataT
87-
hash2::UInt
8887
const shape::ShapeT
88+
hash2::UInt
8989
id::IdentT
9090
end
9191
struct Term
9292
const f::Any
9393
const args::ArgsT
9494
const metadata::MetadataT
95+
const shape::ShapeT
9596
hash::UInt
9697
hash2::UInt
97-
const shape::ShapeT
9898
id::IdentT
9999
end
100100
struct AddOrMul
101101
const variant::AddMulVariant.T
102102
const coeff::T
103103
const dict::RODict{Symbolic, T}
104-
const args::ArgsT
105104
const metadata::MetadataT
105+
const shape::ShapeT
106+
const args::ArgsT
106107
hash::UInt
107108
hash2::UInt
108-
const shape::ShapeT
109109
id::IdentT
110110
end
111111
struct Div
@@ -119,16 +119,16 @@ Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
119119
# algorithms to not try to eliminate more.
120120
const simplified::Bool
121121
const metadata::MetadataT
122-
hash2::UInt
123122
const shape::ShapeT
123+
hash2::UInt
124124
id::IdentT
125125
end
126126
struct Pow
127127
const base::Any
128128
const exp::Any
129129
const metadata::MetadataT
130-
hash2::UInt
131130
const shape::ShapeT
131+
hash2::UInt
132132
id::IdentT
133133
end
134134
end
@@ -203,12 +203,6 @@ override_properties(obj::BSImpl.Type) = override_properties(MData.variant_type(o
203203

204204
function override_properties(obj::Type{<:BSImpl.Variant})
205205
@match obj begin
206-
# Type{<:BSImpl.Const} => (; id = Ref{IdentT}(nothing))
207-
# ::Type{<:BSImpl.Sym} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
208-
# ::Type{<:BSImpl.Term} => (; id = Ref{IdentT}(nothing), hash = Ref{UInt}(0), hash2 = Ref{UInt}(0))
209-
# ::Type{<:BSImpl.AddOrMul} => (; id = Ref{IdentT}(nothing), hash = Ref{UInt}(0), hash2 = Ref{UInt}(0))
210-
# ::Type{<:BSImpl.Div} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
211-
# ::Type{<:BSImpl.Pow} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
212206
::Type{<:BSImpl.Sym} => (; id = nothing, hash2 = 0)
213207
::Type{<:BSImpl.Term} => (; id = nothing, hash = 0, hash2 = 0)
214208
::Type{<:BSImpl.AddOrMul} => (; id = nothing, hash = 0, hash2 = 0)
@@ -218,6 +212,17 @@ function override_properties(obj::Type{<:BSImpl.Variant})
218212
end
219213
end
220214

215+
function ordered_override_properties(obj::Type{<:BSImpl.Variant})
216+
@match obj begin
217+
::Type{<:BSImpl.Sym} => (0, nothing)
218+
::Type{<:BSImpl.Term} => (0, 0, nothing)
219+
::Type{<:BSImpl.AddOrMul} => (ArgsT(), 0, 0, nothing)
220+
::Type{<:BSImpl.Div} => (0, nothing)
221+
::Type{<:BSImpl.Pow} => (0, nothing)
222+
_ => throw(UnimplementedForVariantError(override_properties, obj))
223+
end
224+
end
225+
221226
function ConstructionBase.getproperties(obj::BSImpl.Type)
222227
@match obj begin
223228
BSImpl.Sym(; name, metadata, hash2, shape, id) => (; name, metadata, hash2, shape, id)
@@ -419,10 +424,8 @@ function isequal_symdict(a::Dict, b::Dict, val)
419424
end
420425

421426
function isequal_bsimpl(a::BSImpl.Type, b::BSImpl.Type, val)
422-
# @show "E"
423427
full = isone(val)
424428
partial = @match (a, b) begin
425-
# (BSImpl.Const(; val = v1), BSImpl.Const(; val = v2)) => return isequal(v1, v2)
426429
(BSImpl.Sym(; name = n1, shape = s1), BSImpl.Sym(; name = n2, shape = s2)) => begin
427430
n1 === n2 && s1 == s2
428431
end
@@ -808,34 +811,38 @@ end
808811

809812
function BSImpl.Sym{T}(name::Symbol; metadata = nothing, shape = default_shape(T)) where {T}
810813
metadata = parse_metadata(metadata)
811-
hashcons(BSImpl.Sym{T}(; name, metadata, shape, override_properties(BSImpl.Sym{T})...))
814+
props = ordered_override_properties(BSImpl.Sym)
815+
hashcons(BSImpl.Sym{T}(name, metadata, shape, props...))
812816
end
813817

814818
function BSImpl.Term{T}(f, args; metadata = nothing, shape = default_shape(T)) where {T}
815819
metadata = parse_metadata(metadata)
816820
args = parse_args(args)
817-
hashcons(BSImpl.Term{T}(; f, args, metadata, shape, override_properties(BSImpl.Term{T})...))
821+
props = ordered_override_properties(BSImpl.Term)
822+
hashcons(BSImpl.Term{T}(f, args, metadata, shape, props...))
818823
end
819824

820825
function BSImpl.AddOrMul{T}(variant::AddMulVariant.T, coeff::T, dict::AbstractDict; metadata = nothing, shape = default_shape(T)) where {T}
821826
metadata = parse_metadata(metadata)
822827
dict = parse_dict(T, dict)
823-
args = ArgsT()
824-
hashcons(BSImpl.AddOrMul{T}(; variant, coeff, dict, args, metadata, shape, override_properties(BSImpl.AddOrMul{T})...))
828+
props = ordered_override_properties(BSImpl.AddOrMul)
829+
hashcons(BSImpl.AddOrMul{T}(variant, coeff, dict, metadata, shape, props...))
825830
end
826831

827832
function BSImpl.Div{T}(num, den, simplified::Bool; metadata = nothing, shape = default_shape(T)) where {T}
828833
metadata = parse_metadata(metadata)
829834
num = parse_maybe_symbolic(num)
830835
den = parse_maybe_symbolic(den)
831-
hashcons(BSImpl.Div{T}(; num, den, simplified, metadata, shape, override_properties(BSImpl.Div{T})...))
836+
props = ordered_override_properties(BSImpl.Div)
837+
hashcons(BSImpl.Div{T}(num, den, simplified, metadata, shape, props...))
832838
end
833839

834840
function BSImpl.Pow{T}(base, exp; metadata = nothing, shape = default_shape(T)) where {T}
835841
metadata = parse_metadata(metadata)
836842
base = parse_maybe_symbolic(base)
837843
exp = parse_maybe_symbolic(exp)
838-
hashcons(BSImpl.Pow{T}(; base, exp, metadata, shape, override_properties(BSImpl.Pow{T})...))
844+
props = ordered_override_properties(BSImpl.Pow)
845+
hashcons(BSImpl.Pow{T}(base, exp, metadata, shape, props...))
839846
end
840847

841848
# struct Const{T} end

0 commit comments

Comments
 (0)