LookupTable

Struct LookupTable 

Source
struct LookupTable<'db> {
    data: FxHashMap<Type<'db>, AlternativeExprs<'db>>,
    new_types: FxHashMap<NewTypesKey, Vec<Type<'db>>>,
    types_wishlist: FxHashSet<Type<'db>>,
    many_threshold: usize,
}
Expand description

Lookup table keeps all the state during term search. This means it knows what types and how are reachable.

The secondary functionality for lookup table is to keep track of new types reached since last iteration as well as keeping track of which ScopeDef items have been used. Both of them are to speed up the term search by leaving out types / ScopeDefs that likely do not produce any new results.

Fields§

§data: FxHashMap<Type<'db>, AlternativeExprs<'db>>

All the Exprs in “value” produce the type of “key”

§new_types: FxHashMap<NewTypesKey, Vec<Type<'db>>>

New types reached since last query by the NewTypesKey

§types_wishlist: FxHashSet<Type<'db>>

Types queried but not present

§many_threshold: usize

Threshold to squash trees to Many

Implementations§

Source§

impl<'db> LookupTable<'db>

Source

fn new(many_threshold: usize, goal: Type<'db>) -> Self

Initialize lookup table

Source

fn find( &mut self, db: &'db dyn HirDatabase, ty: &Type<'db>, ) -> Option<Vec<Expr<'db>>>

Find all Exprs that unify with the ty

Source

fn find_autoref( &mut self, db: &'db dyn HirDatabase, ty: &Type<'db>, ) -> Option<Vec<Expr<'db>>>

Same as find but automatically creates shared reference of types in the lookup

For example if we have type i32 in data and we query for &i32 it map all the type trees we have for i32 with Expr::Reference and returns them.

Source

fn insert(&mut self, ty: Type<'db>, exprs: impl Iterator<Item = Expr<'db>>)

Insert new type trees for type

Note that the types have to be the same, unification is not enough as unification is not transitive. For example Vec<i32> and FxHashSet<i32> both unify with Iterator<Item = i32>, but they clearly do not unify themselves.

Source

fn iter_types(&self) -> impl Iterator<Item = Type<'db>> + '_

Iterate all the reachable types

Source

fn new_types(&mut self, key: NewTypesKey) -> Vec<Type<'db>>

Query new types reached since last query by key

Create new key if you wish to query it to avoid conflicting with existing queries.

Source

fn types_wishlist(&mut self) -> &FxHashSet<Type<'db>>

Types queried but not found

Trait Implementations§

Source§

impl<'db> Debug for LookupTable<'db>

Source§

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

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

impl<'db> Default for LookupTable<'db>

Source§

fn default() -> LookupTable<'db>

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

Auto Trait Implementations§

§

impl<'db> Freeze for LookupTable<'db>

§

impl<'db> RefUnwindSafe for LookupTable<'db>

§

impl<'db> Send for LookupTable<'db>

§

impl<'db> Sync for LookupTable<'db>

§

impl<'db> Unpin for LookupTable<'db>

§

impl<'db> UnwindSafe for LookupTable<'db>

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
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Sync + Send> for T
where T: Any + Send + Sync,

§

fn into_box(self) -> Box<dyn Any + Sync + Send>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<'a, T> Captures<'a> for T
where T: ?Sized,