@@ -287,7 +287,7 @@ Modifying `Base.isequal` directly breaks numerous tests in `SymbolicUtils.jl` an
287
287
downstream packages like `ModelingToolkit.jl`, hence the need for this separate
288
288
function.
289
289
"""
290
- function isequal2 (a:: BasicSymbolic , b:: BasicSymbolic ):: Bool
290
+ function isequal_with_metadata (a:: BasicSymbolic , b:: BasicSymbolic ):: Bool
291
291
isequal (a, b) && isequal (metadata (a), metadata (b))
292
292
end
293
293
@@ -362,23 +362,23 @@ Implements hash consing (flyweight design pattern) for `BasicSymbolic` objects.
362
362
This function checks if an equivalent `BasicSymbolic` object already exists. It uses a
363
363
custom hash function (`hash2`) incorporating metadata and symtypes to search for existing
364
364
objects 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.
371
371
372
372
Using a `WeakValueDict` ensures that only weak references to `BasicSymbolic` objects are
373
373
stored, 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.
377
377
"""
378
378
function BasicSymbolic (s:: BasicSymbolic ):: BasicSymbolic
379
379
h = hash2 (s)
380
380
t = get! (wvd, h, s)
381
- if t === s || isequal2 (t, s)
381
+ if t === s || isequal_with_metadata (t, s)
382
382
return t
383
383
else
384
384
return s
0 commit comments