Name decoding with global cache
(obj: LeanBorrowed<'_>, global: &GlobalCache)
| 595 | } |
| 596 | |
| 597 | impl GlobalCache { |
| 598 | fn new() -> Self { |
| 599 | Self { names: DashMap::new() } |
| 600 | } |
| 601 | |
| 602 | fn with_capacity(capacity: usize) -> Self { |
| 603 | Self { names: DashMap::with_capacity(capacity) } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | // SAFETY: The raw pointers are only used as keys for identity comparison. |
| 608 | // The underlying Lean memory remains valid for the duration of decoding. |
| 609 | unsafe impl Send for GlobalCache {} |
| 610 | unsafe impl Sync for GlobalCache {} |
| 611 | |
| 612 | /// Thread-local cache for Levels and Exprs. |
| 613 | #[derive(Default)] |
| 614 | struct LocalCache { |
| 615 | univs: FxHashMap<*mut lean_ffi::include::lean_object, Level>, |
| 616 | exprs: FxHashMap<*mut lean_ffi::include::lean_object, Expr>, |
| 617 | } |
| 618 | |
| 619 | // SAFETY: LocalCache is only accessed by a single thread. |
| 620 | unsafe impl Send for LocalCache {} |
| 621 | |
| 622 | /// Combined cache reference passed to decoding functions. |
| 623 | pub struct Cache<'g> { |
no test coverage detected