pub struct Type {
pub types: AtomicVec,
pub possibly_undefined: bool,
pub from_docblock: bool,
pub falsy_stripped: bool,
pub possibly_absent_offset: 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.
falsy_stripped: boolA false/null failure variant was deliberately stripped from this type
(e.g. preg_split’s regex-error false) because real code overwhelmingly
never checks for it. A defensive === false/=== null check or a
(string)/(array) cast guarding against that exact stripped variant is
still legitimate, so the impossibility/redundancy checks (ImpossibleIdenticalComparison,
RedundantCast, the === null narrowing divergence) exempt it instead of
flagging the caller’s own defensive code.
possibly_absent_offset: boolThis type was read from a generic array/list offset ($arr[$key])
whose key presence isn’t statically provable — PHP returns null
(with a warning) for a missing offset, so a defensive === null/
!== null check against it is legitimate even though the inferred
value type itself doesn’t literally include null (adding null
unconditionally to every generic-array read would drown real code in
PossiblyNull* noise for the overwhelmingly common case where the key
really is present). The impossibility/redundancy checks
(ImpossibleIdenticalComparison, the === null narrowing divergence)
exempt it, mirroring falsy_stripped.
Implementations§
Source§impl Type
impl Type
Sourcepub fn array_depth(&self) -> usize
pub fn array_depth(&self) -> usize
Deepest array nesting in this type: int is 0, list<int> 1, array{0: list<int>} 2.
Sourcepub fn generalized(&self) -> Type
pub fn generalized(&self) -> Type
Literals to base types, shapes to generic arrays, values two levels down to mixed; idempotent.
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 array_key() -> Self
pub fn array_key() -> Self
int|string — the canonical PHP array-key type, used as the default
key type when a docblock/inferred array has no more specific key.
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
Sourcepub fn is_array_key(&self) -> bool
pub fn is_array_key(&self) -> bool
True when this is exactly int|string — the array-key domain, which
is already the maximal set of legal PHP array keys and so should be
treated like a “default”/unconstrained key, same as mixed would be
for a non-key type parameter.
pub fn is_mixed(&self) -> bool
Sourcepub fn is_mixed_not_template(&self) -> bool
pub fn is_mixed_not_template(&self) -> bool
True only when the type contains TMixed atoms and no TTemplateParam atoms.
Unlike Self::is_mixed, this does not treat an unconstrained template parameter as
“mixed” — a T placeholder is an intentionally parameterised type that will be
instantiated at the call site, so it must not trigger MixedAssignment warnings.
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.
TFalse is dropped; TBool becomes TTrue since bool - false = true.
Sourcepub fn remove_true(&self) -> Type
pub fn remove_true(&self) -> Type
Remove true from the union.
TTrue is dropped; TBool becomes TFalse since bool - true = false.
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. mixed/scalar become a concrete
string (rather than staying mixed) so downstream string-only
operations see a usable type instead of reporting Mixed*.
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 widen_non_empty(&self) -> Type
pub fn widen_non_empty(&self) -> Type
Turns a top-level non-empty-list/non-empty-array into list/array.
Sourcepub fn widen_nested_non_empty(&self) -> Type
pub fn widen_nested_non_empty(&self) -> Type
Keeps the outer collection kind but turns every nested non-empty-list/non-empty-array
into list/array, for comparisons that ignore element emptiness.
Sourcepub fn narrow_to_non_empty_collection(&self) -> Type
pub fn narrow_to_non_empty_collection(&self) -> Type
Narrow array/list types to their non-empty variants (for count() > 0 etc.),
dropping the closed empty shape array{}.
Sourcepub fn narrow_to_empty_collection(&self) -> Type
pub fn narrow_to_empty_collection(&self) -> Type
Narrow array/list types when proven empty (e.g. array_key_first($x) === null,
$arr === []). Drops the non-empty variants outright — they can never
be empty — and narrows a plain array/list down to the same closed,
zero-property TKeyedArray an empty [] literal itself types as, so
e.g. $values[0] on a proven-empty branch is flagged as a
NonExistentArrayOffset instead of silently keeping the pre-narrow
element type. TKeyedArray atoms are left unchanged — narrowing an
already-shaped array to “empty” when it may declare required
properties is a separate, more nuanced case.
Sourcepub fn narrow_to_list(&self) -> Type
pub fn narrow_to_list(&self) -> Type
Narrow as if array_is_list($x) is true.
Lists have sequential integer keys starting from 0, so:
list<T>/non-empty-list<T>are kept unchanged.array<int, T>is narrowed tolist<T>(could be sequential).non-empty-array<int, T>is narrowed tonon-empty-list<T>.TKeyedArray(shape) is kept only when its ownis_listflag is already true — that flag is precise (set from the actual literal’s keys, or an explicitlist{...}docblock), not a hint, so a string-keyed or non-contiguous shape is correctly excluded.mixedbecomeslist<mixed>(array_is_list implies array).- All other types (string-keyed arrays, non-arrays) are dropped.
Sourcepub fn narrow_to_object(&self) -> Type
pub fn narrow_to_object(&self) -> Type
Narrow as if is_object($x) is true. A mixed becomes a concrete bare
object (rather than staying mixed) so downstream object-only
operations — clone, instanceof, method calls — see an object type
instead of reporting Mixed*.
Sourcepub fn narrow_to_not_callable(&self) -> Type
pub fn narrow_to_not_callable(&self) -> Type
Narrow as if is_callable($x) is false: the [class, method] array a
callable was narrowed to by is_array() is callable too.
Sourcepub fn narrow_to_callable(&self) -> Type
pub fn narrow_to_callable(&self) -> Type
Narrow as if is_callable($x) is true.
PHP accepts closures, TCallable, strings (function names), arrays ([‘Class’, ‘method’] or [$obj, ‘method’]), and objects with __invoke. Keep all of these; only drop atoms that are definitely not callable (scalars, null, bool, etc.).
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.
Sourcepub fn narrow_to_class_string(&self) -> Type
pub fn narrow_to_class_string(&self) -> Type
Narrow as if class_exists($x) returned true for a string variable.
String atoms become class-string; existing class-string atoms pass through;
mixed/scalar becomes class-string. Non-string atoms are dropped (returning
empty so the caller can mark the branch as diverging).
Sourcepub fn narrow_to_interface_string(&self) -> Type
pub fn narrow_to_interface_string(&self) -> Type
Narrow as if interface_exists($x) returned true for a string variable.
String atoms become interface-string; existing interface-string atoms pass
through; mixed/scalar becomes interface-string. Non-string atoms are dropped
(returning empty so the caller can mark the branch as diverging).
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 expand_small_int_ranges(&self) -> Option<Type>
pub fn expand_small_int_ranges(&self) -> Option<Type>
Rewrites small bounded int ranges as literal ints so int<-1, 1> fits -1|0|1.
Sourcepub fn is_subtype_by_template_bounds(&self, other: &Type) -> bool
pub fn is_subtype_by_template_bounds(&self, other: &Type) -> bool
Like is_subtype_structural, but a template atom is judged by its bound
(an unbound one is mixed and fits anything).
Sourcepub fn accepts_atomic_structural(&self, sub: &Atomic) -> bool
pub fn accepts_atomic_structural(&self, sub: &Atomic) -> bool
sub <: self, structurally, for a single atomic — equivalent to
Type::single(sub.clone()).is_subtype_structural(self) without the
clone and the temporary single-atomic union.
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.
Sourcepub fn falsy_stripped(self) -> Self
pub fn falsy_stripped(self) -> Self
Mark this union as having had a false/null failure variant stripped
for flow purposes (see the field doc on Type::falsy_stripped).
Sourcepub fn possibly_absent_offset(self) -> Self
pub fn possibly_absent_offset(self) -> Self
Mark this union as read from a generic array/list offset whose key
presence isn’t statically provable (see the field doc on
Type::possibly_absent_offset).
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 Forget for Type
impl Freeze for Typewhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const u8 is !null: Freeze,
*const ArcInner<[Type]> is !null: Freeze,
PhantomData<ArcInner<[Type]>>: Freeze,
*const Vec<FnParam> is !null: Freeze,
PhantomData<Vec<FnParam>>: Freeze,
*const Type is !null: Freeze,
PhantomData<Type>: Freeze,
*const ClosureData is !null: Freeze,
PhantomData<ClosureData>: Freeze,
*const ArcInner<KeyedProperties> is !null: Freeze,
PhantomData<ArcInner<KeyedProperties>>: Freeze,
*const ConditionalData is !null: Freeze,
PhantomData<ConditionalData>: Freeze,
*const Atomic is !null: Freeze,
PhantomData<Atomic>: Freeze,
impl Move for Type
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnsafeUnpin for Typewhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
*const ArcInner<[Type]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Type]>>: UnsafeUnpin,
*const Vec<FnParam> is !null: UnsafeUnpin,
PhantomData<Vec<FnParam>>: UnsafeUnpin,
*const Type is !null: UnsafeUnpin,
PhantomData<Type>: UnsafeUnpin,
*const ClosureData is !null: UnsafeUnpin,
PhantomData<ClosureData>: UnsafeUnpin,
*const ArcInner<KeyedProperties> is !null: UnsafeUnpin,
PhantomData<ArcInner<KeyedProperties>>: UnsafeUnpin,
*const ConditionalData is !null: UnsafeUnpin,
PhantomData<ConditionalData>: UnsafeUnpin,
*const Atomic is !null: UnsafeUnpin,
PhantomData<Atomic>: UnsafeUnpin,
impl UnwindSafe for Typewhere
Arc<str>: UnwindSafe,
NonNull<u8>: UnwindSafe,
Arc<[Type]>: UnwindSafe,
BoxRaw<Vec<FnParam>>: UnwindSafe,
BoxRaw<Type>: UnwindSafe,
BoxRaw<ClosureData>: UnwindSafe,
Arc<KeyedProperties>: UnwindSafe,
BoxRaw<ConditionalData>: UnwindSafe,
NonNull<Atomic>: UnwindSafe,
Atomic: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.