flux_refineck::type_env

Struct TypeEnv

Source
pub struct TypeEnv<'a> {
    bindings: PlacesTree,
    local_decls: &'a LocalDecls,
}

Fields§

§bindings: PlacesTree§local_decls: &'a LocalDecls

Implementations§

Source§

impl<'a> TypeEnv<'a>

Source

pub fn new( infcx: &mut InferCtxt<'_, '_, '_>, body: &'a Body<'_>, fn_sig: &FnSig, check_overflow: bool, ) -> TypeEnv<'a>

Source

pub fn empty() -> TypeEnv<'a>

Source

fn alloc_with_ty(&mut self, local: Local, ty: Ty)

Source

fn alloc(&mut self, local: Local)

Source

pub(crate) fn into_infer( self, scope: Scope, ) -> Result<BasicBlockEnvShape, CheckerErrKind>

Source

pub(crate) fn lookup_rust_ty( &self, genv: GlobalEnv<'_, '_>, place: &Place, ) -> QueryResult<Ty>

Source

pub(crate) fn lookup_place( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, ) -> Result<Ty, CheckerErrKind>

Source

pub(crate) fn get(&self, path: &Path) -> Ty

Source

pub fn update_path(&mut self, path: &Path, new_ty: Ty)

Source

pub(crate) fn borrow( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, re: Region, mutbl: Mutability, place: &Place, ) -> Result<Ty, CheckerErrKind>

When checking a borrow in the right hand side of an assignment x = &'?n p, we use the annotated region '?n in the type of the result. This region will only be used temporarily and then replaced by the region in the type of x after the assignment. See TypeEnv::assign

Source

pub(crate) fn ptr_to_ref_at_place( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, ) -> Result<(), CheckerErrKind>

Source

pub(crate) fn ptr_to_ref( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, reason: ConstrReason, re: Region, path: &Path, bound: PtrToRefBound, ) -> InferResult<Ty>

Convert a (strong) pointer to a mutable reference.

This roughly implements the following inference rule:

                  t₁ <: t₂
-------------------------------------------------
Γ₁,ℓ:t1,Γ₂ ; ptr(mut, ℓ) => Γ₁,ℓ:†t₂,Γ₂ ; &mut t2

That’s it, we first get the current type t₁ at location and check it is a subtype of t₂. Then, we update the type of to t₂ and block the place.

The bound t₂ can be either inferred (PtrToRefBound::Infer), explicitly provided (PtrToRefBound::Ty), or made equal to t₁ (PtrToRefBound::Identity).

As an example, consider the environment x: i32[a] and the pointer ptr(mut, x). Converting the pointer to a mutable reference with an inferred bound produces the following derivation (roughly):

                   i32[a] <: i32{v: $k(v)}
----------------------------------------------------------------
x: i32[a] ; ptr(mut, x) => x:†i32{v: $k(v)} ; &mut i32{v: $k(v)}
Source

pub(crate) fn fold_local_ptrs( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, ) -> InferResult<()>

Source

pub(crate) fn assign( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, new_ty: Ty, ) -> Result<(), CheckerErrKind>

Updates the type of place to new_ty. This may involve a strong update if we have ownership of place or a weak update if it’s behind a reference (which fires a subtyping constraint)

When strong updating, the process involves recovering the original regions (lifetimes) used in the (unrefined) Rust type of place and then substituting these regions in new_ty. For instance, if we are assigning a value of type S<&'?10 i32{v: v > 0}> to a variable x, and the (unrefined) Rust type of x is S<&'?5 i32>, before the assignment, we identify a substitution that maps the region '?10 to '?5. After applying this substitution, the type of the place x is updated accordingly. This ensures that the lifetimes in the assigned type are consistent with those expected by the place’s original type definition.

Source

pub(crate) fn move_place( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, ) -> Result<Ty, CheckerErrKind>

Source

pub(crate) fn unpack( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, check_overflow: bool, )

Source

pub(crate) fn unblock( &mut self, rcx: &mut RefineCtxt<'_>, place: &Place, check_overflow: bool, )

Source

pub(crate) fn check_goto( self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, bb_env: &BasicBlockEnv, target: BasicBlock, ) -> Result<(), CheckerErrKind>

Source

pub(crate) fn fold( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, ) -> Result<(), CheckerErrKind>

Source

pub(crate) fn unfold_local_ptr( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, bound: &Ty, ) -> InferResult<Loc>

Source

pub(crate) fn unfold_strg_ref( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, path: &Path, ty: &Ty, ) -> InferResult<Loc>

-----------------------------------
Γ ; &strg <ℓ: t> => Γ,ℓ: t ; ptr(ℓ)
Source

pub(crate) fn unfold( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, place: &Place, checker_conf: CheckerConfig, ) -> Result<(), CheckerErrKind>

Source

pub(crate) fn downcast( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, place: &Place, variant_idx: VariantIdx, checker_config: CheckerConfig, ) -> Result<(), CheckerErrKind>

Source

pub fn replace_evars(&mut self, evars: &EVarSol)

Source

pub(crate) fn update_ensures( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, output: &FnOutput, overflow_checking: bool, )

Source

pub(crate) fn check_ensures( &mut self, at: &mut InferCtxtAt<'_, '_, '_, '_>, output: &FnOutput, reason: ConstrReason, ) -> InferResult

Trait Implementations§

Source§

impl<'a> Clone for TypeEnv<'a>

Source§

fn clone(&self) -> TypeEnv<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeEnv<'_>

Source§

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

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

impl<'a> Default for TypeEnv<'a>

Source§

fn default() -> TypeEnv<'a>

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

impl LocEnv for TypeEnv<'_>

Source§

fn ptr_to_ref( &mut self, infcx: &mut InferCtxtAt<'_, '_, '_, '_>, reason: ConstrReason, re: Region, path: &Path, bound: Ty, ) -> InferResult<Ty>

Source§

fn get(&self, path: &Path) -> Ty

Source§

fn unfold_strg_ref( &mut self, infcx: &mut InferCtxt<'_, '_, '_>, path: &Path, ty: &Ty, ) -> InferResult<Loc>

Source§

impl Pretty for TypeEnv<'_>

Source§

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

Source§

fn default_cx(tcx: TyCtxt<'_>) -> PrettyCx<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for TypeEnv<'a>

§

impl<'a> RefUnwindSafe for TypeEnv<'a>

§

impl<'a> Send for TypeEnv<'a>

§

impl<'a> Sync for TypeEnv<'a>

§

impl<'a> Unpin for TypeEnv<'a>

§

impl<'a> UnwindSafe for TypeEnv<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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
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.
§

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