Skip to main content

Module type_normalize

Module type_normalize 

Source
Expand description

CIP-100 canonical type normalization and name rendering.

CanonType is the single normalized form of a Cypher type: default names (CIP-100 “Type name normalization”), CIP-100’s semantic simplifications (flatten nested unions, drop redundant/subtype members, combine NULL with NOT NULL types), and the canonical type order all already applied. Two semantically equivalent types always normalize to structurally equal CanonType trees.

This is the shared engine behind two features:

  • CIP-90’s valueType(), which renders a runtime value’s dynamic type (built bottom-up from the value’s own shape by the engine, see relate-executor’s value_type_name).
  • The normalization of a parsed TypeExpr (property type constraints, exposed via SHOW CONSTRAINTS.propertyType).

Note: TypeExpr (CIP-86 grammar), the type predicate evaluator, and this module’s type_expr_to_canon all live in the parser crate since normalization is purely a function of the parsed type grammar; nothing here depends on CypherValue.

Structs§

CanonType
A fully CIP-100-normalized Cypher type.

Enums§

CanonKind

Functions§

normalize_union
Normalizes a set of already-normalized component types into their single CIP-100 normalized form: flattens nested unions, removes duplicate/subtype members, applies the “combine NULL and NOT NULL types” encompassing rule (a union with at least one nullable member makes every member nullable), and orders what remains. Returns the single member directly if only one remains once simplified (CIP-100 “Simplify dynamic unions with one type”), or NOTHING for an empty input.
parse_canon_type_str
Reverse of render_canon for a property type constraint’s stored canonical string: reconstructs a TypeExpr a caller can feed to a value-type matcher. Only understands the shape render_canon actually produces for a validate_property_type-accepted type (predefined names, LIST<...>, a trailing NOT NULL, and " | "-separated unions) – not general Cypher type syntax. Used to re-derive a runtime type matcher for a constraint loaded back from storage (CIP-85 enforcement), where only the rendered string persists. Returns None if s doesn’t match that shape (should not happen for a string this module itself produced).
render_canon
Renders a CanonType to its CIP-100 canonical string: uppercase, single-space word separators, no space around <>, | surrounded by exactly one space on each side.
type_expr_to_canon
Converts a parsed TypeExpr (CIP-86 grammar) to its CIP-100 canonical form.
validate_list_element
Validates a LIST<...> inner element type (CIP-85: “lists cannot have a union/list/nullable inner type”, NOT NULL is mandatory on the element). Errors are rendered against list_canon (the whole LIST<...> type), matching Neo4j’s error shape. pub (not just used by validate_property_type) because CIP-178/181’s graph-type property types share this exact restriction while allowing top-level NOT NULL (which validate_property_type itself forbids – that rule is specific to standalone property type constraints, not a node/edge type’s own declared properties).
validate_property_type
Validates a normalized type against Relate’s property type constraint restrictions (CIP-85): no top-level NOT NULL (on a scalar or on the list itself – Neo4j 2026.05 does not implement TYPE NOT NULL for property type constraints), no NOTHING/NULL/ANY/NODE/ RELATIONSHIP/PATH/MAP, and – inside a LIST<...> – no union, no nested list, and no nullable inner type (NOT NULL is mandatory there).
validate_property_type_expr
The <value type> expression form of validate_property_type, for callers that still hold the parsed type: PROPERTY VALUE canonicalizes into an open union of every storable scalar, so the canonical form alone cannot tell it apart from an explicitly written union – and Neo4j rejects it as a property type constraint while accepting the union (live corpus: Create*PropertyTypeConstraintCommands). One entry point for both call sites, so the expression-level rule cannot drift from the canonical one.