Skip to main content

Module unifier_reflexive_equal

Module unifier_reflexive_equal 

Source
Expand description

Reflexive structural-equality fast-path for the unifier.

C++ Luau keeps the if (superTy == subTy) return; pointer fast-path in tryUnify_ cheap because type-alias unions (and the function/pack types built over them) share a single TypeId across every use, so the pointer check fires pervasively. Our port does NOT pointer-share alias-derived composite types, so structurally-identical Color/function/pack values sit at distinct pointers and the pointer check misses — forcing the full element-by-element walk on every curried use and blowing the iteration limit on pathological inputs (luau_subtyping_is_np_hard).

Unifying a type/pack with a structurally-identical type/pack always succeeds by reflexivity, regardless of variance, so short-circuiting here is sound. The walk is log-aware (uses self.log.follow*) and depth-bounded; on hitting the bound it conservatively returns false and the normal unifier runs.