@@ -33,7 +33,7 @@ module Rewriters
3333using SymbolicUtils: @timer
3434using TermInterface
3535
36- import SymbolicUtils: similarterm, istree, operation, arguments, unsorted_arguments, metadata, node_count
36+ import SymbolicUtils: iscall, operation, arguments, unsorted_arguments, metadata, node_count, _promote_symtype
3737export Empty, IfElse, If, Chain, RestartedChain, Fixpoint, Postwalk, Prewalk, PassThrough
3838
3939# Cache of printed rules to speed up @timer
@@ -167,24 +167,41 @@ end
167167struct Walk{ord, C, F, threaded}
168168 rw:: C
169169 thread_cutoff:: Int
170- similarterm:: F
170+ maketerm:: F # XXX : for the 2.0 deprecation cycle, we actually store a function
171+ # that behaves like `similarterm` here, we use `compatmaker` to wrap
172+ # maketerm-like input to do this, with a warning if similarterm provided
173+ # we need this workaround to deprecate because similarterm takes value
174+ # but maketerm only knows the type.
171175end
172176
173177function instrument (x:: Walk{ord, C,F,threaded} , f) where {ord,C,F,threaded}
174178 irw = instrument (x. rw, f)
175- Walk {ord, typeof(irw), typeof(x.similarterm ), threaded} (irw,
179+ Walk {ord, typeof(irw), typeof(x.maketerm ), threaded} (irw,
176180 x. thread_cutoff,
177- x. similarterm )
181+ x. maketerm )
178182end
179183
180184using . Threads
181185
182- function Postwalk (rw; threaded:: Bool = false , thread_cutoff= 100 , similarterm= similarterm)
183- Walk {:post, typeof(rw), typeof(similarterm), threaded} (rw, thread_cutoff, similarterm)
186+ function compatmaker (similarterm, maketerm)
187+ # XXX : delete this and only use maketerm in a future release.
188+ if similarterm isa Nothing
189+ function (x, f, args, type= _promote_symtype (f, args); metadata)
190+ maketerm (typeof (x), f, args, type, metadata)
191+ end
192+ else
193+ Base. depwarn (" Prewalk and Postwalk now take maketerm instead of similarterm keyword argument. similarterm(x, f, args, type; metadata) is now maketerm(typeof(x), f, args, type, metadata)" , :similarterm )
194+ similarterm
195+ end
196+ end
197+ function Postwalk (rw; threaded:: Bool = false , thread_cutoff= 100 , maketerm= maketerm, similarterm= nothing )
198+ maker = compatmaker (similarterm, maketerm)
199+ Walk {:post, typeof(rw), typeof(maker), threaded} (rw, thread_cutoff, maker)
184200end
185201
186- function Prewalk (rw; threaded:: Bool = false , thread_cutoff= 100 , similarterm= similarterm)
187- Walk {:pre, typeof(rw), typeof(similarterm), threaded} (rw, thread_cutoff, similarterm)
202+ function Prewalk (rw; threaded:: Bool = false , thread_cutoff= 100 , maketerm= maketerm, similarterm= nothing )
203+ maker = compatmaker (similarterm, maketerm)
204+ Walk {:pre, typeof(rw), typeof(maker), threaded} (rw, thread_cutoff, maker)
188205end
189206
190207struct PassThrough{C}
@@ -202,8 +219,8 @@ function (p::Walk{ord, C, F, false})(x) where {ord, C, F}
202219 x = p. rw (x)
203220 end
204221
205- if istree (x)
206- x = p. similarterm (x, operation (x), map (PassThrough (p),
222+ if iscall (x)
223+ x = p. maketerm (x, operation (x), map (PassThrough (p),
207224 unsorted_arguments (x)), metadata= metadata (x))
208225 end
209226
@@ -228,7 +245,7 @@ function (p::Walk{ord, C, F, true})(x) where {ord, C, F}
228245 end
229246 end
230247 args = map ((t,a) -> passthrough (t isa Task ? fetch (t) : t, a), _args, arguments (x))
231- t = p. similarterm (x, operation (x), args, metadata= metadata (x))
248+ t = p. maketerm (x, operation (x), args, metadata= metadata (x))
232249 end
233250 return ord === :post ? p. rw (t) : t
234251 else
0 commit comments