Skip to content

Type Tag × Operation Matrix ​

For each tag, every cell is either ✓ impl+tested, P partial, N/A by design, or ✗ missing.

Last updated: 2026-03-31


Tags ​

ValueTagDescription
0TAG_NILnil singleton
1TAG_BOOLEANboolean type
2TAG_NUMBERnumber type
3TAG_STRINGstring type
4TAG_ANYtop escape-hatch (bilateral)
5TAG_NEVERbottom type
6TAG_INTEGERLuaJIT integer subtype
7TAG_UNKNOWNunknown top type (must narrow)
8TAG_LITERALstring/number/boolean/nil literal
9TAG_FUNCTIONfunction with params/returns
10TAG_TABLEstructural table
11TAG_UNIONA | B sum type
12TAG_INTERSECTIONA & B overload/constraint set
13TAG_VARtype variable (unification target)
14TAG_ROWVARrow variable (open table tail)
15TAG_TUPLEfixed-length tuple
16TAG_NOMINALnewtype (identity-based)
17TAG_MATCH_TYPEpattern-match type
18TAG_INTRINSICbuilt-in type function
19TAG_TYPE_CALLtype constructor application
20TAG_FORALLuniversally quantified (generic)
21TAG_SPREADvariadic type (...T)
22TAG_NAMEDunresolved type name
23TAG_CDATAFFI cdata (opaque)
24TAG_ENUM_MEMBERNamed enum member (EnumName.MemberName literal)
25TAG_TYPEOFAnnotation-only: typeof <ident> deferred lookup
26TAG_FFICFFI C table resolved from ffi.cdef call sites
27TAG_CAPTUREPattern-position capture variable %Name (annotation arena only)
28TAG_PAT_ALL_FIELDS{ ...[%K]: %V } all-fields pattern (annotation arena only)
29TAG_PAT_REST_FIELDS{ ...[%Rest] } rest-field capture pattern (annotation arena only)
30TAG_PAT_META_SPREAD{ #...%M } meta-slot spread pattern (annotation arena only)
31TAG_PARTIAL_APPPartially-applied generic alias (deferred instantiation)

Matrix ​

Operations:

  • field — obj.field access
  • index — obj[key] indexing
  • call — function call
  • unify — M.unify (mutating, binds vars)
  • try_unify — M.try_unify (read-only check)
  • narrow — control-flow narrowing
  • display — human-readable string
  • serial — CRI serialize/deserialize
  • inst — instantiate (fresh vars for generics)
  • gen — generalize (mark free vars as generic)
  • ann — resolve_annotation_type (ann arena → checker arena)
Tagfieldindexcallunifytry_unifynarrowdisplayserialinstgenann
TAG_NILN/AN/AN/A✓✓✓ (nil-check)✓✓N/AN/A✓
TAG_BOOLEANN/AN/AN/A✓✓✓ (type-check)✓✓N/AN/A✓
TAG_NUMBERN/AN/AN/A✓✓✓ (type-check)✓✓N/AN/A✓
TAG_STRINGN/AN/AN/A✓✓✓ (type-check)✓✓N/AN/A✓
TAG_ANY✓✓✓✓✓N/A✓✓N/AN/A✓
TAG_NEVER✓✓✓✓✓N/A✓✓N/AN/A✓
TAG_INTEGERN/AN/AN/A✓ (<: number)✓✓ (type-check)✓✓N/AN/A✓
TAG_UNKNOWN✓✓✓✓ (top type)✓✓✓✓N/AN/A✓
TAG_LITERALN/AN/AN/A✓ (<: base)✓✓ (lit-eq, field-disc)✓✓N/AN/A✓
TAG_FUNCTIONN/AN/A✓✓✓N/A✓✓✓✓✓
TAG_TABLE✓✓N/A✓✓✓ (field-presence, disc)✓✓✓✓✓
TAG_UNION✓✓✓✓✓✓✓✓✓✓✓
TAG_INTERSECTION✓✓✓✓✓N/A✓✓✓✓✓
TAG_VAR✓✓✓✓ (bind)✓ (passthrough)N/A✓N/A (internal)✓✓✓
TAG_ROWVARN/A (row tail)N/AN/A✓ (bind)✓ (passthrough)N/A✓N/A (internal)✓✓✓
TAG_TUPLEN/A✓ (literal idx)N/A✓✓N/A✓✓✓✓✓
TAG_NOMINAL✓✓N/A✓ (identity)✓N/A✓✓N/AN/A✓
TAG_MATCH_TYPEN/AN/AN/AP (falls to error)P (false)N/A✓✓N/AN/A✓ (evaluates)
TAG_INTRINSICN/AN/A✓ (special)P (falls to error)P (false)N/A✓✓N/AN/A✓
TAG_TYPE_CALLN/AN/AN/AP (falls to error)P (false)N/A✓✓N/AN/A✓ (applies)
TAG_FORALLN/AN/AN/AP (falls to error)P (false)N/A✓✓N/AN/A✓ (subscope)
TAG_SPREADN/AN/AN/AP (falls to error)P (false)N/A✓✓✓✓✓
TAG_NAMED✓ (treat as any)✓ (treat as any)✓ (treat as any)✓ (treat as any)✓ (passthrough)N/A✓N/A (resolve first)N/AN/A✓ (resolves)
TAG_CDATAN/AN/AN/A✓ (universal)✓ (universal)N/A✓✓N/AN/A✓
TAG_ENUM_MEMBERN/AN/AN/A✓ (literal-eq)✓✓ (lit-eq disc)✓✓N/AN/A✓
TAG_TYPEOFN/AN/AN/AN/AN/AN/A✓N/AN/AN/A✓ (resolves in ann pass)
TAG_FFIC✓✓N/A✓ (cdef-backed)✓N/A✓N/A (internal)N/AN/A✓
TAG_CAPTUREN/AN/AN/AN/AN/AN/A✓N/A (pattern)N/AN/AN/A (ann-only)
TAG_PAT_ALL_FIELDSN/AN/AN/AN/AN/AN/A✓N/A (pattern)N/AN/AN/A (ann-only)
TAG_PAT_REST_FIELDSN/AN/AN/AN/AN/AN/A✓N/A (pattern)N/AN/AN/A (ann-only)
TAG_PAT_META_SPREADN/AN/AN/AN/AN/AN/A✓N/A (pattern)N/AN/AN/A (ann-only)
TAG_PARTIAL_APPN/AN/AN/AP (falls to error)P (false)N/A✓N/A (deferred)N/AN/A✓ (deferred inst)

P = partial means the tag reaches a generic fall-through that returns false/error rather than a correct rule.


Narrowing sub-operations ​

Narrowing is handled separately from unify. The narrowing system (narrow.lua) supports:

PatternTags narrowedStatus
x == nil / x ~= nilany✓
if x then / if not x thenany✓ (truthiness = nil-check)
x == "lit" / x ~= "lit"union of string literals, string✓ (2026-03-15)
x == true/false / x ~= true/falseboolean✓ (2026-03-15)
x.field == "lit" (string)union of tables (field-disc)✓
x.field == true/falseunion of tables (field-disc)✓ (2026-03-15)
x.field == integer_literalunion of tables✗ (numval indices are per-file, not globally comparable)
type(x) == "string" etc.any✓
if x.field thentables with optional field✓ (field-presence)
discriminated union after pcall okret-type union✓

Known limitation: integer discriminants (x.kind == 1) are not supported because numval indices (used to store number literals) are per-file, not globally comparable across annotation files and source files. String and boolean discriminants work because their IDs are globally interned.


Known gaps by category ​

Unify/try_unify (P cells above) ​

TAG_MATCH_TYPE, TAG_INTRINSIC, TAG_TYPE_CALL, TAG_FORALL, TAG_SPREAD all fall to the generic return false, "cannot assign..." at the bottom of M.unify. This means code that contains these types in value position may produce spurious errors.

Assessment: These tags are meta-level constructs (type-language, not value-language). They should only appear inside annotations and type arenas, never as the inferred type of a runtime value. If they appear, it signals a bug in annotation resolution. Current behavior (fall to error) is safe. They do not need unify rules for correctness.

Covariant/contravariant positions in generics ​

TAG_FORALL params are bound in a subscope during resolve_annotation_type but variance is not tracked or enforced. (T) -> T is correctly instantiated, but (Array<T>) -> Array<T> covariance/contravariance is not verified.

Assessment: Deferred until variance annotations are designed. Not blocking.

Recursive types ​

TAG_NOMINAL can appear recursively (linked-list node type). The occurs check in bind_var handles the immediate x = x or default case but not full structural recursion. The union-find representation makes cycles possible if not guarded.

Assessment: Tracked separately, not blocking for current use cases.

Tuple indexing (added 2026-03-15) ​

TAG_TUPLE now supports t[1] style literal numeric indexing. Non-literal keys (e.g., t[i] where i is a variable) return T_UNKNOWN — no indexer type for the whole range.


Audit history ​

  • 2026-03-15: Initial matrix written. Fixed: lit_eq narrowing (x == "val"), boolean field discriminant, TAG_ROWVAR in try_unify, TAG_TUPLE indexing.