Skip to main content

ParserCache

Struct ParserCache 

Source
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

Source

pub fn new() -> Self

Construct a cache with the default ParserOptions (which reads BONSAI_PARSE_TIMEOUT_MS from the environment).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn invalidate(&self, file: FileId)

Invalidate every cached language interpretation of a single file.

Trait Implementations§

Source§

impl Clone for ParserCache

Source§

fn clone(&self) -> ParserCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParserCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParserCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.