Skip to main content

ShapeMask

Struct ShapeMask 

Source
pub struct ShapeMask(/* private fields */);
Expand description

The set of NodeShapes occurring anywhere in a subterm — one u16, computed once at interning time and answered in O(1) thereafter.

§The Lean design this copies

Lean’s Expr carries a 64-bit Expr.Data word in every node, and four of its bits are exactly this idea: hasFVar, hasExprMVar, hasLevelMVar, hasLevelParam (Lean/Expr.lean:121-124). Expr.mkAppData propagates all four with a single OR of the two children’s words — ((fData ||| aData) &&& (15 <<< 40)) ||| … (Lean/Expr.lean:193) — so an application’s bits cost one instruction rather than a traversal. What they BUY is visible at Lean/Expr.lean:1661: let rec visit (e : Expr) := if !e.hasFVar then false else …, a walk that stops before it starts.

Ours widens the idea from four hand-picked predicates to one bit per node kind, which is what lets beta_zeta_normal_form decide in O(1) whether a term can hold a redex it does not own. The cost is the same: one OR per child at interning time, in TermStore::compute_info.

Implementations§

Source§

impl ShapeMask

Source

pub const NONE: ShapeMask

The empty mask — no shape occurs.

Source

pub const BETA_ZETA: ShapeMask

The shapes a term made only of Sort, Var, Global, App, Lambda, Pi and Let can have — the admissible surface of beta_zeta_normal_form. Its complement is Const, Match, Fix, MutualFix, Lit, Hole and Bound.

Source

pub fn contains(self, shape: NodeShape) -> bool

Whether shape occurs anywhere in the subterm.

Source

pub fn subset_of(self, other: ShapeMask) -> bool

Whether every shape in this mask is also in other.

Source

pub fn union(self, other: ShapeMask) -> ShapeMask

The union of two masks.

Source

pub fn with(self, shape: NodeShape) -> ShapeMask

This mask with shape added.

Source

pub fn bits(self) -> u16

The raw bits, for a caller that wants to store or compare them.

Trait Implementations§

Source§

impl Clone for ShapeMask

Source§

fn clone(&self) -> ShapeMask

Returns a duplicate 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 ShapeMask

Source§

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

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

impl Default for ShapeMask

Source§

fn default() -> ShapeMask

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

impl Hash for ShapeMask

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ShapeMask

Source§

fn eq(&self, other: &ShapeMask) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ShapeMask

Source§

impl Eq for ShapeMask

Source§

impl StructuralPartialEq for ShapeMask

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> 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.