pub struct EffectSet(/* private fields */);Expand description
the set of effects a function performs.
an empty set IS pure – Pure is implicit, not a stored flag. the u8 repr
makes union a single | op, is_subset_of a single mask, and equality a
one-byte compare. instances are immutable; every operation returns a fresh
EffectSet rather than mutating in place. Copy matters because the
type checker stores an EffectSet on every typed function and reads it
at every call site; one byte is cheaper to copy than to reference.
Default derives EffectSet(0), which equals EffectSet::pure – the
type checker initialises every unannotated function at the bottom of the
lattice and unions upward during fixed-point ascent.
Implementations§
Source§impl EffectSet
impl EffectSet
Sourcepub fn pure() -> Self
pub fn pure() -> Self
the empty set: no flags set, the lattice bottom.
equivalent to is pure annotated functions. constructing a function’s
initial EffectSet for fixed-point ascent starts here.
Sourcepub fn full() -> Self
pub fn full() -> Self
every flag set: the lattice top.
used as the upper bound for the unannotated-caller fallback: when the
type checker calls a function it cannot resolve a signature for, it
treats the call as producing full() so an annotated caller’s check
fails closed rather than silently accepting.
Sourcepub fn is_pure(self) -> bool
pub fn is_pure(self) -> bool
is this the empty set?
true iff no flags are set. an is pure-annotated function’s effect
set is exactly this case.
Sourcepub fn union(self, other: Self) -> Self
pub fn union(self, other: Self) -> Self
the lattice join: the union of self’s flags and other’s flags.
idempotent (a.union(a) == a), commutative (a.union(b) == b.union(a)),
and associative. these properties are what guarantee Plan 4’s
fixed-point loop converges monotonically.
Sourcepub fn is_subset_of(self, other: Self) -> bool
pub fn is_subset_of(self, other: Self) -> bool
is every flag set in self also set in other?
reflexive (a.is_subset_of(a) == true), antisymmetric (a ⊆ b and
b ⊆ a implies a == b), and transitive. the type checker’s
annotation check is inferred.is_subset_of(annotated) – the inferred
effect of the body must not exceed what the annotation allows.
Sourcepub fn display(&self) -> String
pub fn display(&self) -> String
the canonical comma-joined rendering for diagnostics.
flags appear in fixed (Io, Alloc, Panic) order regardless of how the
set was constructed, so io().union(alloc()) and
alloc().union(io()) both render "io, alloc". an empty set renders
"pure". this is the determinism contract the renderer’s
byte-identical-output tests depend on.