(d: Expression)
| 445 | |
| 446 | // module-level cache hooks, installed per top-level int() call by the |
| 447 | // driver (see installCaches); fall back to uncached when absent |
| 448 | let activeCaches: Ctx['caches'] | undefined; |
| 449 | |
| 450 | export function installCaches(caches: Ctx['caches']): void { |
| 451 | activeCaches = caches; |
| 452 | } |
| 453 | |
| 454 | /** Snapshot the currently-installed caches so a re-entrant driver call can |
| 455 | * restore the outer call's warm caches after installing its own (see the |
| 456 | * native-rational fallback re-entry in driver.ts). */ |
| 457 | export function getActiveCaches(): Ctx['caches'] | undefined { |
| 458 | return activeCaches; |
| 459 | } |
| 460 | |
| 461 | function safeSimplify(e: Expression): Expression { |
| 462 | if (leafCount(e) > SIMPLIFY_LEAF_CAP) return e; |
| 463 | const key = activeCaches ? e.toString() : ''; |
| 464 | const cached = activeCaches?.simplify.get(key); |
| 465 | if (cached !== undefined) return cached; |
no test coverage detected