pub struct Type {
pub types: AtomicVec,
pub possibly_undefined: bool,
pub from_docblock: bool,
}Fields§
§types: AtomicVec§possibly_undefined: boolThe variable holding this type may not be initialized at this point.
from_docblock: boolThis type originated from a docblock annotation rather than inference.
Implementations§
Source§impl Type
impl Type
pub fn empty() -> Self
pub fn single(atomic: Atomic) -> Self
pub fn mixed() -> Self
pub fn void() -> Self
pub fn never() -> Self
pub fn null() -> Self
pub fn bool() -> Self
pub fn int() -> Self
pub fn float() -> Self
pub fn string() -> Self
Sourcepub fn from_vec(atomics: Vec<Atomic>) -> Self
pub fn from_vec(atomics: Vec<Atomic>) -> Self
Build a union from multiple atomics, de-duplicating on the fly.
pub fn is_empty(&self) -> bool
pub fn is_single(&self) -> bool
pub fn is_nullable(&self) -> bool
pub fn is_mixed(&self) -> bool
pub fn is_never(&self) -> bool
Sourcepub fn clone_validity(&self) -> CloneValidity
pub fn clone_validity(&self) -> CloneValidity
Classify this type for clone validity. Recurses into template-param
bounds (like Type::is_mixed). Callers handle mixed separately.
pub fn is_void(&self) -> bool
pub fn can_be_falsy(&self) -> bool
pub fn can_be_truthy(&self) -> bool
pub fn contains<F: Fn(&Atomic) -> bool>(&self, f: F) -> bool
pub fn has_named_object(&self, fqcn: &str) -> bool
Sourcepub fn add_type(&mut self, atomic: Atomic)
pub fn add_type(&mut self, atomic: Atomic)
Add an atomic to this union, skipping duplicates. Subsumption rules: anything ⊆ TMixed; TLiteralInt ⊆ TInt; etc.
Sourcepub fn remove_null(&self) -> Type
pub fn remove_null(&self) -> Type
Remove null from the union (e.g. after a null check).
Sourcepub fn remove_false(&self) -> Type
pub fn remove_false(&self) -> Type
Remove false from the union.
Sourcepub fn core_type(&self) -> Type
pub fn core_type(&self) -> Type
Remove both null and false from the union (core type without nullable/falsy variants).
Sourcepub fn narrow_to_truthy(&self) -> Type
pub fn narrow_to_truthy(&self) -> Type
Keep only truthy atomics (e.g. after if ($x)).
Sourcepub fn narrow_to_falsy(&self) -> Type
pub fn narrow_to_falsy(&self) -> Type
Keep only falsy atomics (e.g. after if (!$x)).
Sourcepub fn narrow_instanceof(&self, class: &str) -> Type
pub fn narrow_instanceof(&self, class: &str) -> Type
Narrow this type as if $x instanceof ClassName is true.
The instanceof check guarantees the value IS an instance of class, so we
replace any object / mixed constituents with the specific named object. Scalar
constituents are dropped (they can never satisfy instanceof).
Sourcepub fn narrow_to_string(&self) -> Type
pub fn narrow_to_string(&self) -> Type
Narrow as if is_string($x) is true.
Sourcepub fn narrow_to_int(&self) -> Type
pub fn narrow_to_int(&self) -> Type
Narrow as if is_int($x) is true.
Sourcepub fn narrow_to_float(&self) -> Type
pub fn narrow_to_float(&self) -> Type
Narrow as if is_float($x) is true.
Sourcepub fn narrow_to_bool(&self) -> Type
pub fn narrow_to_bool(&self) -> Type
Narrow as if is_bool($x) is true.
Sourcepub fn narrow_to_null(&self) -> Type
pub fn narrow_to_null(&self) -> Type
Narrow as if is_null($x) is true.
Sourcepub fn narrow_to_array(&self) -> Type
pub fn narrow_to_array(&self) -> Type
Narrow as if is_array($x) is true.
Sourcepub fn narrow_to_object(&self) -> Type
pub fn narrow_to_object(&self) -> Type
Narrow as if is_object($x) is true.
Sourcepub fn narrow_to_callable(&self) -> Type
pub fn narrow_to_callable(&self) -> Type
Narrow as if is_callable($x) is true.
Sourcepub fn narrow_to_scalar(&self) -> Type
pub fn narrow_to_scalar(&self) -> Type
Narrow as if is_scalar($x) is true (int | string | float | bool).
Sourcepub fn narrow_to_iterable(&self) -> Type
pub fn narrow_to_iterable(&self) -> Type
Narrow as if is_iterable($x) is true (array | Traversable).
For simplicity, this narrows to arrays or objects (can’t easily verify interfaces).
Sourcepub fn narrow_to_countable(&self) -> Type
pub fn narrow_to_countable(&self) -> Type
Narrow as if is_countable($x) is true (array | Countable).
For simplicity, this narrows to arrays or objects (can’t easily verify Countable interface).
Sourcepub fn narrow_to_resource(&self) -> Type
pub fn narrow_to_resource(&self) -> Type
Narrow as if is_resource($x) is true.
Note: No TResource atomic type exists in the type system; this is a no-op.
Resources are declining in modern PHP and not actively tracked.
Sourcepub fn merge(a: &Type, b: &Type) -> Type
pub fn merge(a: &Type, b: &Type) -> Type
Merge two unions at a branch join point (e.g. after if/else). The result is the union of all types in both.
Sourcepub fn merge_with(&mut self, other: &Type)
pub fn merge_with(&mut self, other: &Type)
Merge other into self in-place (avoids cloning self).
Sourcepub fn intersect_with(&self, other: &Type) -> Type
pub fn intersect_with(&self, other: &Type) -> Type
Intersect with another union: keep only types present in other, widening
where self contains mixed (which is compatible with everything).
Used for match-arm subject narrowing.
Sourcepub fn substitute_templates(&self, bindings: &FxHashMap<Name, Type>) -> Type
pub fn substitute_templates(&self, bindings: &FxHashMap<Name, Type>) -> Type
Replace template param references with their resolved types.
Sourcepub fn resolve_conditional_returns<F>(self, lookup: F) -> Type
pub fn resolve_conditional_returns<F>(self, lookup: F) -> Type
Resolves TConditional atoms whose discriminator is known at the call site.
lookup(param_name) returns the call-site argument type for the named parameter,
or None if the argument is not available. Handles is null, is string, and
is array conditions; other condition types pass through unchanged.
Sourcepub fn is_subtype_structural(&self, other: &Type) -> bool
pub fn is_subtype_structural(&self, other: &Type) -> bool
Returns true if every atomic in self is a subtype of some atomic in other,
using only structural rules — no extends / implements walk.
Two distinct user-defined classes are never related here, even when one
extends the other. Within mir-analyzer, when a db is in scope,
prefer crate::subtype::is_subtype(db, sub, sup) which layers
inheritance resolution on top of this check.
Sourcepub fn possibly_undefined(self) -> Self
pub fn possibly_undefined(self) -> Self
Mark this union as possibly-undefined and return it.
Sourcepub fn from_docblock(self) -> Self
pub fn from_docblock(self) -> Self
Mark this union as coming from a docblock annotation.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Type
impl<'de> Deserialize<'de> for Type
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Type
impl StructuralPartialEq for Type
Auto Trait Implementations§
impl Freeze for Type
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnsafeUnpin for Type
impl UnwindSafe for Type
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.