pub struct ParserCache { /* private fields */ }Expand description
Concurrent parse cache. Cheap to clone; parser instances are pooled by
exact grammar variant while parsed tree cache reads use an RwLock.
A checkout removes one parser from its pool (or creates one if every parser
is busy), then releases the pool lock before parsing. Concurrent files in
the same grammar therefore do not serialize behind one mutable parser,
while completed workers still make their parser reusable. The tree cache
is logically keyed by (VFS instance, FileId, adapter, grammar, version).
Implementations§
Source§impl ParserCache
impl ParserCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a cache with the default ParserOptions (which
reads BONSAI_PARSE_TIMEOUT_MS from the environment).
Sourcepub fn with_options(options: ParserOptions) -> Self
pub fn with_options(options: ParserOptions) -> Self
Construct a cache with explicit options. Useful for tests or callers that deliberately need a bounded diagnostic parse.
Sourcepub fn parse(
&self,
file: FileId,
adapter: &AdapterArc,
vfs: &Vfs,
) -> Result<Arc<ParsedFile>, ParseError>
pub fn parse( &self, file: FileId, adapter: &AdapterArc, vfs: &Vfs, ) -> Result<Arc<ParsedFile>, ParseError>
Parse file with adapter, using any cached tree as a correctly edited
incremental reparse hint.
Sourcepub fn parse_snapshot(
&self,
snapshot: &FileSnapshot,
adapter: &AdapterArc,
vfs: &Vfs,
) -> Result<Arc<ParsedFile>, ParseError>
pub fn parse_snapshot( &self, snapshot: &FileSnapshot, adapter: &AdapterArc, vfs: &Vfs, ) -> Result<Arc<ParsedFile>, ParseError>
Parse an exact immutable snapshot.
This is the adapter bridge used by the analyzer database. It prevents a concurrent VFS write from returning a tree for a different source version than the snapshot an adapter is currently walking.
Sourcepub fn release(&self, file: FileId, adapter: &AdapterArc, vfs: &Vfs)
pub fn release(&self, file: FileId, adapter: &AdapterArc, vfs: &Vfs)
Release the cached tree for this exact workspace/file/language key.
Compiler lowering phases call this after all durable facts have been extracted. Exact removal keeps phase-local eviction O(1) and avoids serializing parallel workers behind a whole-cache scan. Edit invalidation remains broader because a file may have been parsed by more than one adapter over the cache’s lifetime.
Sourcepub fn invalidate(&self, file: FileId)
pub fn invalidate(&self, file: FileId)
Invalidate every cached language interpretation of a single file.
Trait Implementations§
Source§impl Clone for ParserCache
impl Clone for ParserCache
Source§fn clone(&self) -> ParserCache
fn clone(&self) -> ParserCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more