Skip to main content

Env

Struct Env 

Source
pub(crate) struct Env<'db> {
    pub log: LogHandle<'db>,
    universe: Universe,
    runtime: Runtime<'db>,
    pub scope: Arc<Scope<'db, 'db>>,
    variable_universes: Arc<Map<SymVariable<'db>, Universe>>,
    variable_tys: Arc<Map<SymVariable<'db>, VariableTypeCell<'db>>>,
    pub return_ty: Option<SymTy<'db>>,
    assumptions: Arc<Vec<Assumption<'db>>>,
}

Fields§

§log: LogHandle<'db>§universe: Universe§runtime: Runtime<'db>

Reference to the runtime

§scope: Arc<Scope<'db, 'db>>

Lexical scope for name resolution

§variable_universes: Arc<Map<SymVariable<'db>, Universe>>

Universe of each free generic variable that is in scope.

§variable_tys: Arc<Map<SymVariable<'db>, VariableTypeCell<'db>>>

Type for in-scope variables. Local variables are stored directly in symbolic form but function parameters are stored initially as AST types. Those types are symbolified lazily. See VariableType for details.

§return_ty: Option<SymTy<'db>>

If None, not type checking a function or method.

§assumptions: Arc<Vec<Assumption<'db>>>

Assumptions declared

Implementations§

Source§

impl<'db> Env<'db>

Source

pub async fn require( &mut self, a: impl AsyncFnOnce(&mut Env<'db>) -> Errors<bool>, because: impl FnOnce(&mut Env<'db>) -> Because<'db>, or_else: &dyn OrElse<'db>, ) -> Errors<()>

Source

pub fn require_for_all<T>( &mut self, items: impl IntoIterator<Item = T>, f: impl AsyncFn(&mut Env<'db>, T) -> Errors<()>, ) -> impl Future<Output = Errors<()>>

Source

pub fn require_all(&mut self) -> RequireAll<'_, 'db>

Source

pub fn require_both( &mut self, a: impl AsyncFnOnce(&mut Self) -> Errors<()>, b: impl AsyncFnOnce(&mut Self) -> Errors<()>, ) -> impl Future<Output = Errors<()>>

Source

pub fn join<A, B>( &mut self, a: impl AsyncFnOnce(&mut Self) -> A, b: impl AsyncFnOnce(&mut Self) -> B, ) -> impl Future<Output = (A, B)>
where A: Serialize, B: Serialize,

Source

pub fn either( &mut self, a: impl AsyncFnOnce(&mut Env<'db>) -> Errors<bool>, b: impl AsyncFnOnce(&mut Env<'db>) -> Errors<bool>, ) -> impl Future<Output = Errors<bool>>

Source

pub fn for_all<T>( &mut self, items: impl IntoIterator<Item = T>, test_fn: impl AsyncFn(&mut Env<'db>, T) -> Errors<bool>, ) -> impl Future<Output = Errors<bool>>

Returns true if any of the items satisfies the predicate. Returns false if not. Stops executing as soon as either an error or a true result is found.

Source

pub fn exists<T>( &mut self, items: impl IntoIterator<Item = T>, test_fn: impl AsyncFn(&mut Env<'db>, T) -> Errors<bool>, ) -> impl Future<Output = Errors<bool>>

Returns true if any of the items satisfies the predicate. Returns false if not. Stops executing as soon as either an error or a true result is d.

Source

pub fn both( &mut self, a: impl AsyncFnOnce(&mut Env<'db>) -> Errors<bool>, b: impl AsyncFnOnce(&mut Env<'db>) -> Errors<bool>, ) -> impl Future<Output = Errors<bool>>

True if both a and b are true. Stops as soon as one is found to be false.

Source

pub fn term_bounds( &self, perm: SymPerm<'db>, infer: InferVarIndex, ) -> SymGenericTermBoundIterator<'db>

Returns an iterator over the bounds on an inference variable that appears under perm, yielding terms:

  • If this is a permission inference variable, the result are series of permission terms. These are directly converted from the RedPerm bounds you get if you call Self::red_perm_bounds.
  • If this is a type inference variable, the result are series of type terms. They do not include the permission inference variable.
Source

pub fn red_perm_bounds(&self, infer: InferVarIndex) -> RedPermBoundIterator<'db>

Returns an iterator over the red perm bounds on a permission inference variable.

Source

pub fn red_ty_bounds(&self, infer: InferVarIndex) -> RedTyBoundIterator<'db>

Returns an iterator over the red ty bounds on a type inference variable. Note that each type inference variable has an associated permission inference variable and that this permission is not reflected in the red ty bound. Use Self::term_bounds to get back the complete inferred type.

Source

pub fn loop_on_inference_var<T>( &self, infer: InferVarIndex, op: impl FnMut(&InferenceVarData<'db>) -> Option<T>, ) -> impl Future<Output = Option<T>>
where T: Serialize,

Source

pub async fn for_each_bound( &mut self, direction: Direction, infer: InferVarIndex, op: impl AsyncFnMut(&mut Env<'db>, &RedTy<'db>, ArcOrElse<'db>) -> Errors<()>, ) -> Errors<()>

Invoke op for each new lower (or upper, depending on direction) bound on ?X.

Source§

impl<'db> Env<'db>

Source

pub(crate) fn new(runtime: &Runtime<'db>, scope: Scope<'db, 'db>) -> Self

Create an empty environment

Source

pub fn into_scope(self) -> Scope<'db, 'db>

Extract the scope from the environment.

§Panics

If the scope has an outstanding reference.

Source

pub fn universe(&self) -> Universe

Source

pub fn db(&self) -> &'db dyn Db

Get the database

Source

pub fn runtime(&self) -> &Runtime<'db>

Access the lower-level type checking runtime

Source

pub fn fork( &self, log: impl FnOnce(&LogHandle<'db>) -> LogHandle<'db>, ) -> Env<'db>

Create a new environment from this environment. The log will be adjusted per the log function.

Source

pub fn var_is_declared_to_be( &self, var: SymVariable<'db>, predicate: Predicate, ) -> bool

True if the given variable is declared to meet the given predicate.

Source

fn assumed( &self, var: SymVariable<'db>, kind: impl Fn(AssumptionKind) -> bool, ) -> bool

Source

pub fn open_universally<T>(&mut self, value: &T) -> T::LeafTerm
where T: BoundTerm<'db>,

Open the given symbols as universally quantified. Creates a new universe.

Source

pub fn existential_substitution( &mut self, span: Span<'db>, variables: &[SymVariable<'db>], ) -> Vec<SymGenericTerm<'db>>

Create a substitution for binder consisting of inference variables

Source

pub fn increment_universe(&mut self)

Source

pub fn set_variable_sym_ty(&mut self, lv: SymVariable<'db>, ty: SymTy<'db>)

Sets the symbolic type for a program variable. Used during environment construction but typically you should use Self::push_program_variable_with_ty instead.

Source

pub fn set_variable_ast_ty( &mut self, lv: SymVariable<'db>, decl: VariableDecl<'db>, )

Sets the AST type for a parameter that is in scope already. This AST type will be lazily symbolified when requested.

Source

pub fn push_program_variable_with_ty( &mut self, lv: SymVariable<'db>, ty: SymTy<'db>, )

Extends the scope with a new program variable given its type.

Source

pub fn set_return_ty(&mut self, ty: SymTy<'db>)

Set the return type of the current function.

Source

pub fn return_ty(&self) -> Option<SymTy<'db>>

Source

pub async fn variable_ty(&mut self, lv: SymVariable<'db>) -> SymTy<'db>

Returns the type of the given variable.

§Panics

If the variable is not present.

Source

pub fn fresh_inference_var( &mut self, kind: SymGenericKind, span: Span<'db>, ) -> InferVarIndex

Create a fresh inference variable of the given kind.

Source

pub fn fresh_inference_var_term( &mut self, kind: SymGenericKind, span: Span<'db>, ) -> SymGenericTerm<'db>

A fresh term with an inference variable of the given kind.

Source

pub fn fresh_ty_inference_var(&mut self, span: Span<'db>) -> SymTy<'db>

Create a fresh type inference variable.

Source

pub(super) fn spawn_require_assignable_type( &mut self, live_after: LivePlaces, value_ty: SymTy<'db>, place_ty: SymTy<'db>, or_else: &dyn OrElse<'db>, )

Spawn a subtask that will require value_ty be assignable to place_ty.

Source

pub(super) fn spawn_require_equal_types( &self, live_after: LivePlaces, expected_ty: SymTy<'db>, found_ty: SymTy<'db>, or_else: &dyn OrElse<'db>, )

Spawn a subtask that will require expected_ty be equal to found_ty.

Source

pub(super) fn spawn_require_my_numeric_type( &mut self, live_after: LivePlaces, ty: SymTy<'db>, or_else: &dyn OrElse<'db>, )

Check that the value is a numeric type and has the permission my.

Source

pub(super) fn spawn_require_numeric_type( &mut self, ty: SymTy<'db>, or_else: &dyn OrElse<'db>, )

Check that the value is a numeric type with any permission.

Source

pub(super) fn spawn_require_future_type( &self, live_after: LivePlaces, ty: SymTy<'db>, awaited_ty: SymTy<'db>, or_else: &dyn OrElse<'db>, )

Source

pub(super) fn spawn_require_where_clause( &self, where_clause: SymWhereClause<'db>, or_else: &dyn OrElse<'db>, )

Source

pub fn spawn_if_not_never( &mut self, tys: &[SymTy<'db>], op: impl AsyncFnOnce(&mut Env<'db>) + 'db, )

Check whether any type in tys is known to be never (or error). If so, do nothing. Otherwise, if no type in tys is known to be never, invoke op (asynchronously).

Source

pub fn describe_ty<'a>(&'a self, ty: SymTy<'db>) -> impl Display + 'a

Source

pub fn spawn<R>( &mut self, task_description: TaskDescription<'db>, op: impl AsyncFnOnce(&mut Self) -> R + 'db, )
where R: DeferResult,

Source

pub(crate) fn require_expr_has_bool_ty( &mut self, live_after: LivePlaces, expr: SymExpr<'db>, )

Source

pub fn is_leased_var(&self, _var: SymVariable<'db>) -> bool

Check if the given (perm, type) variable is declared as mutable.

Source

pub(crate) fn infer_var_span(&self, v: InferVarIndex) -> Span<'db>

Span for code that prompted creation of inference variable v.

Source

pub(crate) fn infer_var_kind(&self, v: InferVarIndex) -> InferVarKind

Kind of this inference variable.

Source

pub(crate) fn variances(&self, n: SymTyName<'db>) -> Vec<Variance>

Source

pub fn perm_infer(&self, infer: InferVarIndex) -> InferVarIndex

If infer is a type variable, returns the permission variable associated with infer. If infer is a permission variable, just returns infer.

Source

pub fn report(&self, diagnostic: Diagnostic) -> Reported

Source

pub fn log(&self, message: &'static str, values: &[&dyn Serialize])

Source

pub fn indent<R>( &mut self, message: &'static str, values: &[&dyn Serialize], op: impl AsyncFnOnce(&mut Self) -> R, ) -> impl Future<Output = R>
where R: Serialize,

Source

pub async fn indent_with_compiler_location<R>( &mut self, compiler_location: &'static Location<'static>, message: &'static str, values: &[&dyn Serialize], op: impl AsyncFnOnce(&mut Self) -> R, ) -> R
where R: Serialize,

Source

pub fn log_result<T>( &mut self, compiler_location: &'static Location<'static>, value: T, ) -> T
where T: Serialize,

Source

pub(crate) fn bound_vars(&self) -> Vec<SymVariable<'db>>

Return a vector with all variables that are “bound” in the environment. These correspond to in-scope function parameters, generic types, etc.

Source

pub fn insert_sub_infer_var_pair( &mut self, lower: InferVarIndex, upper: InferVarIndex, ) -> bool

Record that lower <: upper must hold, returning true if this is the first time that this has been recorded or false if it has been recorded before.

§Panics

If lower == upper, as that is just always true, why record it?

Source

pub fn red_bound( &self, infer: InferVarIndex, direction: Direction, ) -> RedBound<'_, 'db>

Return a struct that gives ability to peek, modify, or block on the lower or upper red-ty-bound on the given inference variable.

Trait Implementations§

Source§

impl<'db> Debug for Env<'db>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'db> Freeze for Env<'db>

§

impl<'db> !RefUnwindSafe for Env<'db>

§

impl<'db> !Send for Env<'db>

§

impl<'db> !Sync for Env<'db>

§

impl<'db> Unpin for Env<'db>

§

impl<'db> UnsafeUnpin for Env<'db>

§

impl<'db> !UnwindSafe for Env<'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
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.

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> Lookup<T> for T

§

fn into_owned(self) -> T

§

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<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
Source§

impl<T> DebugArgument for T
where T: Debug,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T