polix.optimized.analyzer
Policy analysis for optimized evaluation tier selection.
Provides type inference from constraint literals, operator classification, and tier selection for the optimized evaluation pipeline.
all-complex-bytecode-eligible?
(all-complex-bytecode-eligible? constraint-set)Returns true if all complex entries in a constraint set are bytecode-eligible.
analyze-constraint
(analyze-constraint constraint)Analyzes a single constraint and returns type information.
Returns a map with: - :path - document path - :op - operator keyword - :expected - expected value - :type - inferred type - :op-class - :builtin or :custom
analyze-constraint-set
(analyze-constraint-set constraint-set)Analyzes a constraint set and builds a type environment.
Returns a map with: - :type-env - TypeEnv with path -> type mappings - :constraints - vector of analyzed constraints - :has-custom-ops - true if any custom operators found - :has-complex - true if complex (non-constraint) nodes found - :errors - vector of type errors (empty if none)
analyze-policy
(analyze-policy constraint-set)Analyzes a policy for optimized evaluation.
Takes a constraint set (output of compiler/normalize-and-merge) and returns analysis results including type environment, tier selection, and operator classification.
Returns a map with: - :tier - :t0, :t1, or :t2 - :type-env - TypeEnv with inferred types - :constraints - analyzed constraints - :operators - {:builtin [...] :custom [...]} - :errors - type errors (if any)
builtin-op?
(builtin-op? op-key)Returns true if the operator is a built-in that can be fully optimized.
builtin-ops
Set of built-in operators that can be fully optimized.
classify-operator
(classify-operator op-key)Classifies an operator as :builtin or :custom.
compatible-types?
(compatible-types? t1 t2)Returns true if two types are compatible for unification.
complex-entry-bytecode-eligible?
(complex-entry-bytecode-eligible? entry)Returns true if a complex entry can be bytecode-compiled.
Entry structure is {:complex {:op :quantifier/:let-binding, :ast …}}
empty-type-env
(empty-type-env)Creates an empty type environment.
infer-element-type
(infer-element-type s)Infers the element type of a set.
infer-type-from-op
(infer-type-from-op op-key expected-value)Infers the expected document type based on operator and expected value.
For example: - [:= path "admin"] -> :string - [:> path 5] -> :long or :double - [:in path #{"a" "b"}] -> element type of set - [:matches path #".*"] -> :string
infer-type-from-value
(infer-type-from-value value)Infers a type from a literal value.
Returns one of: - :string - String - :long - integer/long - :double - floating point - :boolean - boolean - :set - set collection - :pattern - regex pattern - :keyword - keyword - :unknown - cannot determine type
ITypeEnv
protocol
Protocol for type environment operations.
members
get-type
(get-type this path)Returns the inferred type for a document path.
unify-type
(unify-type this path new-type)Unifies a new type constraint, returns updated env or error.
narrowest-type
(narrowest-type t1 t2)Returns the narrowest (most specific) of two compatible types.
select-tier
(select-tier {:keys [has-custom-ops has-complex errors]})Selects the evaluation tier based on analysis results.
Returns: - :t2 - Optimized closures (all builtin operators, no complex nodes) - :t1 - Guarded closures (has custom operators, needs version guards) - :t0 - Interpreted (has complex nodes or type errors)