@@ -287,7 +287,7 @@ Modifying `Base.isequal` directly breaks numerous tests in `SymbolicUtils.jl` an
287287downstream packages like `ModelingToolkit.jl`, hence the need for this separate
288288function.
289289"""
290- function isequal2 (a:: BasicSymbolic , b:: BasicSymbolic ):: Bool
290+ function isequal_with_metadata (a:: BasicSymbolic , b:: BasicSymbolic ):: Bool
291291 isequal (a, b) && isequal (metadata (a), metadata (b))
292292end
293293
@@ -362,23 +362,23 @@ Implements hash consing (flyweight design pattern) for `BasicSymbolic` objects.
362362This function checks if an equivalent `BasicSymbolic` object already exists. It uses a
363363custom hash function (`hash2`) incorporating metadata and symtypes to search for existing
364364objects in a `WeakValueDict` (`wvd`). Due to the possibility of hash collisions (where
365- different objects produce the same hash), a custom equality check (`isequal2`) which
366- includes metadata comparison, is used to confirm the equivalence of objects with matching
367- hashes. If an equivalent object is found, the existing object is returned; otherwise, the
368- input `s` is returned. This reduces memory usage, improves compilation time for runtime
369- code generation, and supports built-in common subexpression elimination, particularly when
370- working with symbolic objects with metadata.
365+ different objects produce the same hash), a custom equality check (`isequal_with_metadata`)
366+ which includes metadata comparison, is used to confirm the equivalence of objects with
367+ matching hashes. If an equivalent object is found, the existing object is returned;
368+ otherwise, the input `s` is returned. This reduces memory usage, improves compilation time
369+ for runtime code generation, and supports built-in common subexpression elimination,
370+ particularly when working with symbolic objects with metadata.
371371
372372Using a `WeakValueDict` ensures that only weak references to `BasicSymbolic` objects are
373373stored, allowing objects that are no longer strongly referenced to be garbage collected.
374- Custom functions `hash2` and `isequal2 ` are used instead of `Base.hash` and `Base.isequal`
375- to accommodate metadata without disrupting existing tests reliant on the original behavior
376- of those functions.
374+ Custom functions `hash2` and `isequal_with_metadata ` are used instead of `Base.hash` and
375+ `Base.isequal` to accommodate metadata without disrupting existing tests reliant on the
376+ original behavior of those functions.
377377"""
378378function BasicSymbolic (s:: BasicSymbolic ):: BasicSymbolic
379379 h = hash2 (s)
380380 t = get! (wvd, h, s)
381- if t === s || isequal2 (t, s)
381+ if t === s || isequal_with_metadata (t, s)
382382 return t
383383 else
384384 return s
0 commit comments