@@ -15,10 +15,10 @@ import SymbolicUtils: @matchable, Sym, Term, istree, operation, arguments,
1515# #== state management ==##
1616
1717struct NameState
18- symbolify :: Dict{Any, Any}
18+ rewrites :: Dict{Any, Any}
1919end
2020NameState () = NameState (Dict {Any, Any} ())
21- function union_symbolify ! (n, ts)
21+ function union_rewrites ! (n, ts)
2222 for t in ts
2323 n[t] = Symbol (string (t))
2424 end
@@ -34,7 +34,7 @@ function Base.get(st::LazyState)
3434 s === nothing ? getfield (st, :ref )[] = NameState () : s
3535end
3636
37- @inline Base. getproperty (st:: LazyState , f:: Symbol ) = getproperty (get (st), f)
37+ @inline Base. getproperty (st:: LazyState , f:: Symbol ) = f == :symbolify ? getproperty (st, :rewrites ) : getproperty (get (st), f)
3838
3939# #========================##
4040
@@ -105,7 +105,7 @@ toexpr(a::Assignment, st) = :($(toexpr(a.lhs, st)) = $(toexpr(a.rhs, st)))
105105function_to_expr (op, args, st) = nothing
106106
107107function function_to_expr (op:: Union{typeof(*),typeof(+)} , O, st)
108- out = get (st. symbolify , O, nothing )
108+ out = get (st. rewrites , O, nothing )
109109 out === nothing || return out
110110 args = map (Base. Fix2 (toexpr, st), arguments (O))
111111 if length (args) >= 3 && symtype (O) <: Number
@@ -138,13 +138,13 @@ function function_to_expr(::typeof(SymbolicUtils.ifelse), O, st)
138138 :($ (toexpr (args[1 ], st)) ? $ (toexpr (args[2 ], st)) : $ (toexpr (args[3 ], st)))
139139end
140140
141- function_to_expr (:: Sym , O, st) = get (st. symbolify , O, nothing )
141+ function_to_expr (:: Sym , O, st) = get (st. rewrites , O, nothing )
142142
143143toexpr (O:: Expr , st) = O
144144
145145function substitute_name (O, st)
146- if (issym (O) || istree (O)) && haskey (st. symbolify , O)
147- st. symbolify [O]
146+ if (issym (O) || istree (O)) && haskey (st. rewrites , O)
147+ st. rewrites [O]
148148 else
149149 O
150150 end
@@ -193,13 +193,16 @@ components. See example in `Func` for more information.
193193DestructuredArgs
194194
195195toexpr (x:: DestructuredArgs , st) = toexpr (x. name, st)
196- get_symbolify (args:: DestructuredArgs ) = ()
197- function get_symbolify (args:: Union{AbstractArray, Tuple} )
198- cflatten (map (get_symbolify , args))
196+ get_rewrites (args:: DestructuredArgs ) = ()
197+ function get_rewrites (args:: Union{AbstractArray, Tuple} )
198+ cflatten (map (get_rewrites , args))
199199end
200- get_symbolify (x) = istree (x) ? (x,) : ()
200+ get_rewrites (x) = istree (x) ? (x,) : ()
201201cflatten (x) = Iterators. flatten (x) |> collect
202202
203+ # Used in Symbolics
204+ Base. @deprecate_binding get_symbolify get_rewrites
205+
203206function get_assignments (d:: DestructuredArgs , st)
204207 name = toexpr (d, st)
205208 map (d. inds, d. elems) do i, a
@@ -237,7 +240,7 @@ function toexpr(l::Let, st)
237240 append! (assignments, get_assignments (x, st))
238241 else
239242 for a in get_assignments (x, st)
240- st. symbolify [a. lhs] = a. rhs
243+ st. rewrites [a. lhs] = a. rhs
241244 end
242245 end
243246 elseif x isa Assignment && x. lhs isa DestructuredArgs
@@ -247,7 +250,7 @@ function toexpr(l::Let, st)
247250 else
248251 push! (assignments, x. lhs. name ← x. rhs)
249252 for a in get_assignments (x. lhs, st)
250- st. symbolify [a. lhs] = a. rhs
253+ st. rewrites [a. lhs] = a. rhs
251254 end
252255 end
253256 else
@@ -258,8 +261,8 @@ function toexpr(l::Let, st)
258261 return toexpr (Let (assignments, l. body, l. let_block), st)
259262 end
260263
261- funkyargs = get_symbolify (map (lhs, dargs))
262- union_symbolify ! (st. symbolify , funkyargs)
264+ funkyargs = get_rewrites (map (lhs, dargs))
265+ union_rewrites ! (st. rewrites , funkyargs)
263266
264267 bindings = map (p-> toexpr (p, st), dargs)
265268 l. let_block ? Expr (:let ,
334337toexpr_kw (f, st) = Expr (:kw , toexpr (f, st). args... )
335338
336339function toexpr (f:: Func , st)
337- funkyargs = get_symbolify (vcat (f. args, map (lhs, f. kwargs)))
338- union_symbolify ! (st. symbolify , funkyargs)
340+ funkyargs = get_rewrites (vcat (f. args, map (lhs, f. kwargs)))
341+ union_rewrites ! (st. rewrites , funkyargs)
339342 dargs = filter (x-> x isa DestructuredArgs, f. args)
340343 if ! isempty (dargs)
341344 body = Let (dargs, f. body, false )
0 commit comments