Activate the thread-local parse cache for `content`. While the returned [`ParseCacheGuard`] is alive, every call to [`with_parsed_program`] whose `content` argument is byte-equal to the cached content will reuse the already-parsed `Program` instead of re-parsing. Typical usage: ```ignore let _guard = with_parse_cache(content); // … many calls to resolve_variable_types / resolve_variable_type /
(content: &str)
| 711 | /// // Guard is dropped here, clearing the cache. |
| 712 | /// ``` |
| 713 | pub(crate) fn with_parse_cache(content: &str) -> ParseCacheGuard { |
| 714 | // If there's already an active cache (nested call), just return a |
| 715 | // no-op guard — the outermost guard owns the lifetime. |
| 716 | let already_active = PARSE_CACHE.with(|cell| cell.borrow().is_some()); |
| 717 | if already_active { |
| 718 | return ParseCacheGuard { owns_cache: false }; |
| 719 | } |
| 720 | |
| 721 | // Store only the content string. The actual parse is deferred |
| 722 | // until the first `with_parsed_program` call that hits the cache. |
| 723 | PARSE_CACHE.with(|cell| { |
| 724 | *cell.borrow_mut() = Some(ParseCacheEntry { |
| 725 | content: content.to_string(), |
| 726 | arena: None, |
| 727 | program_ptr: None, |
| 728 | }); |
| 729 | }); |
| 730 | |
| 731 | ParseCacheGuard { owns_cache: true } |
| 732 | } |
| 733 | |
| 734 | /// Parse `content` with the mago-syntax parser and pass the resulting |
| 735 | /// `Program` (plus the content string) to `f`. |
no outgoing calls
no test coverage detected