Skip to main content

Module polymorphic

Module polymorphic 

Source
Expand description

Polymorphic pseudo-types — Fase 3 extension.

PG-style anyelement / anyarray / anynonarray / anycompatible family. These don’t exist as concrete DataType variants because the analyzer instantiates them fresh at every call site — a function with signature array_append(anyarray, anyelement) → anyarray becomes a distinct concrete signature array_append(int[], int) → int[] when called with int / int[] arguments.

This module owns:

  • The PseudoType enum that the function catalog uses in its arg_types slice when declaring polymorphic entries.
  • The PolymorphicResolver that instantiates pseudo-types against concrete call-site arguments, enforcing the consistency rule: every anyelement at the same signature must resolve to the same concrete type.

Scope today (Fase 3 W3):

  • AnyElement — matches any single concrete type.
  • AnyArray — matches any array type. Inferred from the AnyElement it shares a signature with.
  • AnyNonArray — matches any concrete type except arrays.
  • AnyCompatible — like AnyElement but tolerates implicit widening (e.g. int + float → float).

Deferred:

  • AnyRange / AnyMultirange — ranges aren’t in Fase 3.
  • AnyEnum — enums are fine via concrete DataType::Enum today; polymorphic enum wait.

This module is not yet wired into the function catalog or expr_typing. Wiring adds a PseudoType-aware overload in function_catalog::resolve when the catalog starts shipping polymorphic rows.

Structs§

Substitution
The resolver’s output — a substitution map that every pseudo-type in a signature has been bound to. Used by expr_typing to compute the concrete return type from a signature that mentions the same pseudo-type in its return position.

Enums§

ArgSlot
A single position in a function argument list — either a concrete type or a pseudo-type waiting for substitution.
PseudoType
PG-style pseudo-type used by polymorphic function signatures. The resolver substitutes each variant with a concrete DataType at analyze time based on call-site arguments.
ResolveError
Errors raised during polymorphic resolution.

Functions§

resolve
Attempt to resolve a polymorphic signature against a list of concrete call-site argument types. Returns the substitution on success so expr_typing can apply it to the return type.