Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

docs: record ADR-26 (`instance of` type predicate); update README

public

docs: record ADR-26 (`instance of` type predicate); update README

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changesetd1ed0d0f58487eb6ed59f0e62a5dd9ebb3d1441b
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsb7e37c413fae
Children
Pushlog
by timo via ssh

modified DECISIONS.md +52 −1

@@ -766,8 +766,59 @@
766766
   data (`collect_context_keys`) so a filter referencing an element's entries fits the
767767
   slice.
768768
 - **Consequence:** §10.3.2.5 is complete. Still out of scope (documented): unary tests
769
-  (the non-interval `in` forms), `instance of`, and `sort`/matching-`list replace` (need a
769
+  (the non-interval `in` forms), and `sort`/matching-`list replace` (need a
770770
   function-valued comparator — feasible now that function values exist, ADR-23).
771
+
772
+## ADR-26: `instance of` type predicate — type lattice & structural conformance (DMN §10.3.2.9)
773
+
774
+- **Context:** `instance of` (`value instance of type`, grammar rule 51) was the last
775
+  comparison-level operator missing from feel-core, and the only one needing a notion the
776
+  engine lacked entirely: a *type*. DMN-TCK `0070-feel-instance-of` exercises it across
777
+  every value kind, against built-in/`Any`/`Null` types and inline generics.
778
+- **Decision:** add a minimal type lattice **L** as `ast::FeelType` (the primitive nodes,
779
+  `Any`/`Null`, the parameterised `list`/`range`/`context`/`function` nodes, and an
780
+  `Unknown` node for unmappable type names), and one AST node `Expr::InstanceOf(Box<Expr>,
781
+  FeelType)`. The `FeelType` is resolved **at parse time** — it carries no runtime data.
782
+  - **Type grammar (spec rule 52), restricted & LR(1)-clean:** the right operand parses
783
+    via a dedicated `InstanceType` sub-grammar reachable only after `instance of` — a
784
+    named type, `list<T>`/`range<T>`, `context<k: T, …>`, or `function<…> -> T`. The
785
+    field-vs-type choice inside `<…>` reuses the same one-token (`:`) lookahead the call
786
+    `Arg` rule already uses, so lalrpop builds conflict-free (the `build.rs` gate enforces
787
+    it). An unmappable name — a model `itemDefinition` type this standalone engine can't
788
+    resolve, a typo, or a bare `list`/`context` that "requires parameters" — becomes
789
+    `FeelType::Unknown`, so e.g. `123 instance of list` evaluates to `null` (the spec
790
+    result) rather than failing to parse.
791
+  - **`instance of` lexing (no new reserved words):** `instance` and `of` are **not**
792
+    reserved — FEEL names may contain them (`year of birth`, the `day of week` built-in),
793
+    so reserving `of` would break those. Instead a pre-pass ([`lexer::mark_instance_of`])
794
+    fuses only the adjacent `instance` `of` pair into one `Tok::InstanceOf` operator
795
+    *before* name-joining; a lone `instance`/`of` stays an ordinary name-word. The
796
+    function-type arrow `->` is a new `logos` token (it only ever appears literally in a
797
+    function type, so maximal-munch keeps `-`/`>` intact elsewhere). The three
798
+    keyword-containing temporal type names (`date and time`, `years and months duration`,
799
+    `days and time duration`) are now joined into a single `Name` **wherever they occur**
800
+    (previously only in call position) so they read as type names too; they are reserved
801
+    FEEL type/constructor names, so the only behaviour lost is logical-`and` of variables
802
+    literally named `date`/`time`/… — not meaningful FEEL.
803
+  - **Semantics — structural conformance (`types::value_conforms_to`):** rather than a
804
+    canonical `type(value)` + lattice `conforms_to` with joins, the value is checked
805
+    against the target type structurally (equivalent for every FEEL shape, less code).
806
+    Top level: an unmappable type → `null`; a `null`/error value is an instance only of
807
+    `Null`; otherwise the value must conform. A `null` nested in a list element or
808
+    context field has type `Null` and `Null <: T`, so it conforms — which is why
809
+    `{a: null} instance of context<a: string>` is `true` while top-level `null instance
810
+    of string` is `false`. `context` conformance allows extra value keys (n ≥ m);
811
+    functions check arity only (untyped closures map to `(Any, …) -> Any`).
812
+- **Tests:** ingested DMN-TCK `0070-feel-instance-of` (119 self-contained cases; the
813
+  slice detector now splits on `instance of` and validates the type's words against a
814
+  built-in whitelist). The 23 skipped cases reference model `itemDefinition` types (no
815
+  type registry exists — out of scope) or are function-literal *values* (function literals
816
+  aren't ingested generally); both are covered by feel-core unit tests, alongside the spec
817
+  Table 62 examples and the nested-null/`Null` edges.
818
+- **Consequence:** §10.3.2.9 type-checking is supported for the self-contained type
819
+  language. Still out of scope (documented): model-defined `itemDefinition` types (need a
820
+  type registry threaded from the embedder), and `range` *values* (no first-class range
821
+  value exists, so `instance of range<T>` is always `false`).
771822
 
772823
 ## Adding a wrapper — the host-binding contract
773824
 

modified README.md +9 −1

@@ -24,6 +24,10 @@
2424
   zero / type errors → `null`.
2525
 - **Comparison:** `< <= > >= = !=`, `between … and …`, interval `in`
2626
   (`[a..b]`, `(a..b]`, `[a..b)`, `(a..b)`) over numbers and strings.
27
+- **Type predicate (§10.3.2.9):** `value instance of type` over the built-in
28
+  types (`number`, `string`, `date and time`, …, `Any`, `Null`) and inline
29
+  generics `list<T>`, `context<k: T, …>`, `function<…> -> T`; an unmappable type
30
+  (e.g. a model-defined name) → `null` (ADR-26).
2731
 - **Logic:** `and` / `or` / `not(…)` with three-valued (Kleene) semantics.
2832
 - **Control flow:** `if … then … else …`, `for v in src return …`,
2933
   `some/every v in src satisfies …` (over list literals and integer ranges
@@ -117,7 +121,7 @@
117121
 (the `decimal-vs-f64` rule switches numeric results to epsilon comparison), and
118122
 prints a summary of processed / skipped cases and which deviation rules fired.
119123
 
120
-The fixtures used by the test (~68 files, ~1940 self-contained cases) are
124
+The fixtures used by the test (~71 files, ~2070 self-contained cases) are
121125
 regenerated by pointing the script at each TCK dir, e.g.:
122126
 
123127
 ```sh
@@ -132,6 +136,10 @@
132136
 # for-loops -> list results
133137
 python tools/ingest_tck.py tests/tck/TestCases/compliance-level-3/0084-feel-for-loops \
134138
   -o crates/feel-core/tests/fixtures/0084-feel-for-loops.json
139
+
140
+# `instance of` type predicate -> boolean (built-in types + inline generics)
141
+python tools/ingest_tck.py tests/tck/TestCases/compliance-level-3/0070-feel-instance-of \
142
+  -o crates/feel-core/tests/fixtures/0070-instance-of.json
135143
 ```
136144
 
137145
 The other ingested dirs include `0105-feel-math` (compliance-level-2),