Skip to main content

Purity

Enum Purity 

Source
pub enum Purity {
    Const,
    LoopingConst,
    Pure,
    LoopingPure,
    Opaque,
}
Expand description

What a call can do.

Five, because there are two questions with two answers each and then everything else. Does the result depend on memory, does the call come back, and if either answer is not known then the call is Purity::Opaque and no pass may assume anything at all.

Variants§

§

Const

Reads no memory, writes none, and comes back. __attribute__((const)), GCC’s ECF_CONST.

§

LoopingConst

Reads no memory and writes none, and may not come back. GCC’s ECF_CONST together with ECF_LOOPING_CONST_OR_PURE.

§

Pure

Reads memory, writes none, and comes back. __attribute__((pure)), GCC’s ECF_PURE.

§

LoopingPure

Reads memory, writes none, and may not come back.

§

Opaque

Anything, which is what a call is until something says otherwise.

Implementations§

Source§

impl Purity

Source

pub const ALL: [Self; 5]

The five, for a test that walks them.

Source

pub const fn as_str(self) -> &'static str

How it reads in a dump.

Source

pub const fn reads_memory(self) -> bool

Whether the call may read memory the caller cares about.

Source

pub const fn writes_memory(self) -> bool

Whether the call may write memory.

Only an opaque call may. That is what the other four have in common and it is most of what makes them worth telling apart from the rest.

Source

pub const fn terminates(self) -> bool

Whether control is known to come back from the call.

Not known and known not to are the same answer here, because both of them stop the same transformations. Which of the two it is belongs to noreturn, which is an attribute on the function rather than a level of this.

Source

pub const fn depends_only_on_arguments(self) -> bool

Whether the result is a function of the arguments and nothing else.

This is what lets two calls with the same arguments become one call with no question asked about what happened to memory in between. A Purity::Pure call can be folded the same way when the caller can show nothing wrote memory between the two, which is a question for the alias analysis and not for this.

Source

pub const fn can_be_deleted_when_unused(self) -> bool

Whether a call whose result nothing reads may be removed.

Both halves are needed. A call that writes memory does something even when its result is thrown away, and a call that may not come back does something by not coming back, which is why the looping levels exist at all.

Source

pub const fn stronger(self, other: Self) -> Self

The strongest thing true of both, for a caller that has two sources and believes each.

Purity::Opaque is nothing known, so it gives way to whatever the other source says. Two sources that each know half give the whole: a declaration saying the result comes out of the arguments and an analysis saying the loop inside terminates add up to Purity::Const.

Source

pub const fn weaker(self, other: Self) -> Self

The strongest thing true of either, for a caller that has to cover both.

Which is what a call site with more than one possible callee needs, and what a caller summarising a whole function needs.

Trait Implementations§

Source§

impl Clone for Purity

Source§

fn clone(&self) -> Purity

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 Copy for Purity

Source§

impl Debug for Purity

Source§

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

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

impl Display for Purity

Source§

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

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

impl Eq for Purity

Source§

impl Hash for Purity

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 Purity

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Purity

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.