Log
22b4fc65594a
feat(core): opaque comparison-test value `(< 10)` in value position
public
feat(core): opaque comparison-test value `(< 10)` in value position
A parenthesised comparison test in value position — `(< 10)`, `(= 10)`,
`(!= 10)` — is now an opaque unary-test value, not a boolean and not a
promoted range. It equals a structurally identical test reflexively
(`(<10) = (<10)` → true) but is never equal to a `Range`
(`(<10) = (null..10)`, `(=10) = [10..10]` → false) — the measured 0068
semantics that falsified the desugar-to-range hypothesis (ADR-28's
`range_006` question).
- grammar: one new `Primary` alternative `"(" CmpOp Sum ")"` — LR(1)-clean
(no `CmpOp` in `FIRST(Expr)`, so no clash with grouping or the range
form), carried by a new `Expr::UnaryTestVal(CmpOp, Box<Expr>)` node.
- value: `Value::UnaryTestVal(Box<UnaryTestVal>)`, boxed so `Value` stays
40 bytes. Equality is structural + reflexive and a definite `false`
against a `Range` or anything else (not the type-mismatch error-null).
- it has no order, no `instance of` type but `Any`; `string(...)` echoes
the written form; the feel-py / feel-lua wrappers cross it out as
host `None`/`nil` like a native closure.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
modified
crates/feel-core/src/ast.rs
+9 −1
@@ -67,6 +67,14 @@
67 67 /// ([`UnaryTest::Not`]), `x in not(t)` ≡ `not(x satisfies t)` (Kleene), never the 68 68 /// boolean `not(…)` built-in. 69 69 In(Box < Expr> , Vec < UnaryTest> ), 70 + /// A parenthesised comparison-test *value* in value position — `(< 10)`, 71 + /// `(= 10)`, `(!= 10)` (DMN §10.3.4.6). Distinct from a [`Compare`](Expr::Compare): 72 + /// here the comparison has no left operand, so it is not a boolean but an **opaque 73 + /// unary-test value** ([`Value::UnaryTestVal`](crate::Value::UnaryTestVal)) with 74 + /// reflexive, range-*incompatible* equality (ADR-32) — `(<10) = (<10)` is true but 75 + /// `(<10) = (null..10)` is false. The `in`-position forms (`x in (=10)`) keep the 76 + /// dedicated [`UnaryTest::Compare`] test; this is the value-position sibling. 77 + UnaryTestVal(CmpOp, Box < Expr> ), 70 78 /// Type predicate `value instance of type` (DMN §10.3.2.9, grammar rule 51). 71 79 /// The right operand is a [`FeelType`] resolved at parse time (it carries no 72 80 /// runtime data); an unmappable type name parses as [`FeelType::Unknown`] so
@@ -366,7 +374,7 @@
366 374 & & args.named.iter().all(| (_, e)| e.is_clock_free()) 367 375 } 368 376 Expr::FnDef { body, .. } = > body.is_clock_free(), 369 - Expr::Neg(e) | Expr::Not(e) = > e.is_clock_free(), 377 + Expr::Neg(e) | Expr::Not(e) | Expr::UnaryTestVal(_, e) = > e.is_clock_free(), 370 378 Expr::Arith(_, a, b) | Expr::Compare(_, a, b) | Expr::And(a, b) | Expr::Or(a, b) = > { 371 379 a.is_clock_free() & & b.is_clock_free() 372 380 }
modified
crates/feel-core/src/builtins.rs
+20 −0
@@ -911,7 +911,27 @@
911 911 r.end.as_ref().map(render_member).unwrap_or_default(), 912 912 if r.end_open { ')' } else { ']' }, 913 913 ), 914 + // An opaque comparison-test value `(< 10)` (ADR-32) renders in its written 915 + // parenthesised form, `(< 10)` / `(= 10)` / `(!= 10)`, with the endpoint quoted 916 + // as a list member is (so a string endpoint keeps its quotes). 917 + Value::UnaryTestVal(t) = > { 918 + format! (" ({} {}) " , cmp_op_str(t.op), render_member(& t.endpoint)) 919 + } 914 920 Value::Null | Value::Error = > " null " .to_string(), 921 + } 922 +} 923 + 924 +/// The FEEL source spelling of a comparison operator (for stringifying a 925 +/// [`Value::UnaryTestVal`]). 926 +fn cmp_op_str (op: crate ::ast::CmpOp) -> & ' static str { 927 + use crate ::ast::CmpOp::* ; 928 + match op { 929 + Lt = > " < " , 930 + Le = > " <= " , 931 + Gt = > " > " , 932 + Ge = > " >= " , 933 + Eq = > " = " , 934 + Ne = > " != " , 915 935 } 916 936 } 917 937
modified
crates/feel-core/src/eval.rs
+26 −0
@@ -87,6 +87,15 @@
87 87 end_open: iv .end_open, 88 88 }))) 89 89 } 90 + // A parenthesised comparison-test value `(< 10)` (DMN §10.3.4.6; ADR-32): 91 + // evaluate the endpoint and wrap it in an opaque `Value::UnaryTestVal`. It is 92 + // NOT a range — its equality is structural and range-incompatible (see below). 93 + Expr::UnaryTestVal(op, e) = > Ok (Value::UnaryTestVal(Box ::new( 94 + crate ::value::UnaryTestVal { 95 + op: * op, 96 + endpoint: self .eval(e, ctx)? .forced(), 97 + }, 98 + ))), 90 99 Expr::Var(name) = > Ok (ctx.get(name).cloned().unwrap_or(Value::Null)), 91 100 Expr::ContextLit(entries) = > self .eval_context_lit(entries, ctx), 92 101 Expr::Path(target, name) = > Ok (match self .eval(target, ctx)? {
@@ -480,6 +489,23 @@
480 489 (Some (true ), Some (true )) = > Some (true ), 481 490 } 482 491 } 492 + // An opaque parenthesised comparison-test value `(< 10)` (ADR-32). It equals 493 + // ONLY a structurally identical test — same operator AND FEEL-equal endpoint — 494 + // reflexively (`(<10) = (<10)`, `(=10) = (=10)`, `(!=10) = (!=10)` → true). A 495 + // differing operator is a definite `false`; the endpoint comparison three-values 496 + // through (an endpoint type mismatch is the usual error-null). 497 + (Value::UnaryTestVal(x), Value::UnaryTestVal(y)) = > { 498 + if x.op ! = y.op { 499 + Some (false ) 500 + } else { 501 + feel_equal_depth(& x.endpoint, & y.endpoint, depth + 1 ) 502 + } 503 + } 504 + // …but it is NEVER equal to a `Range` or anything else: `(<10) = (null..10)` and 505 + // `(=10) = [10..10]` are a definite `false` (the measured 0068 semantics that 506 + // falsified the desugar-to-range hypothesis), not a type-mismatch error-null. 507 + // (Null/error on either side was already settled above.) 508 + (Value::UnaryTestVal(_), _) | (_, Value::UnaryTestVal(_)) = > Some (false ), 483 509 // Temporal: same-type -> Some(bool); cross temporal type -> None (-> error-null). 484 510 (x, y) if temporal::is_temporal(x) & & temporal::is_temporal(y) = > temporal::equal(x, y), 485 511 _ = > None , // different, non-null types
modified
crates/feel-core/src/feel.lalrpop
+6 −0
@@ -238,6 +238,12 @@
238 238 Context, 239 239 "not" "(" <e:Expr> ")" => Expr::Not(Box::new(e)), 240 240 "(" <e:Expr> ")" => e, 241 + // A parenthesised comparison-test *value* `(< 10)` / `(= 10)` / `(!= 10)` (DMN 242 + // §10.3.4.6; ADR-32). LR(1)-clean: no `CmpOp` token is in FIRST(Expr), so seeing a 243 + // `CmpOp` right after `(` is an unambiguous new path that never competes with the 244 + // `"(" Expr ")"` grouping or the `"(" Sum ".." …` range form. It evaluates to an 245 + // opaque `Value::UnaryTestVal`, NOT a promoted range (the measured 0068 semantics). 246 + "(" <op:CmpOp> <e:Sum> ")" => Expr::UnaryTestVal(op, Box::new(e)), 241 247 Name => Expr::Var(<>), 242 248 }; 243 249
modified
crates/feel-core/src/value.rs
+26 −0
@@ -34,6 +34,18 @@
34 34 /// orderable, same-typed [`Value`]s; the booleans carry each bracket's openness 35 35 /// (`[`/`]` closed, `(`/`)` open). 36 36 Range(Box < RangeVal> ), 37 + /// An opaque parenthesised comparison-test *value* — `(< 10)`, `(= 10)`, `(!= 10)` 38 + /// in value position (DMN §10.3.4.6; ADR-32). Boxed so the variant stays one word 39 + /// and `Value` does not grow past 40 bytes (see the size test in `lib.rs`). 40 + /// 41 + /// Unlike the desugar hypothesis ADR-28 floated, this is **not** a promoted 42 + /// [`Range`](Value::Range): the measured TCK semantics (0068) are that it equals an 43 + /// *identical test* reflexively — `(<10) = (<10)`, `(=10) = (=10)`, `(!=10) = (!=10)` 44 + /// are all true — but is **never** equal to a `Range` (`(<10) = (null..10)` and 45 + /// `(=10) = [10..10]` are both false). So equality is structural (same op + FEEL-equal 46 + /// endpoint) and range-incompatible. It has no order, no host type, and conforms to no 47 + /// `instance of` type but `Any`. 48 + UnaryTestVal(Box < UnaryTestVal> ), 37 49 /// A lazily-resolved host value (a Python/JS object behind a target-specific 38 50 /// [`ForeignObject`](crate::foreign::ForeignObject)). Only the wrapper crates 39 51 /// ever construct one (ADR-21); the FEEL dot resolves it by name on demand,
@@ -83,6 +95,15 @@
83 95 pub end_open: bool , 84 96 } 85 97 98 +/// The payload of a [`Value::UnaryTestVal`]: the comparison operator and the 99 +/// already-evaluated endpoint of an opaque parenthesised comparison-test value 100 +/// (`(< 10)` → `op: Lt, endpoint: Number(10)`; ADR-32). 101 +#[ derive(Debug, Clone, PartialEq) ] 102 +pub struct UnaryTestVal { 103 + pub op: crate ::ast::CmpOp, 104 + pub endpoint: Value , 105 +} 106 + 86 107 impl Value { 87 108 /// True if this value is, or transitively contains, an [`Value::Error`]. 88 109 /// Used by the strict boundary policy in the wrappers.
@@ -95,6 +116,7 @@
95 116 r.start.as_ref().is_some_and(Value::contains_error) 96 117 | | r.end.as_ref().is_some_and(Value::contains_error) 97 118 } 119 + Value::UnaryTestVal(t) = > t.endpoint.contains_error(), 98 120 _ = > false , 99 121 } 100 122 }
@@ -132,6 +154,10 @@
132 154 end: r .end.map(Value::into_lenient), 133 155 .. * r 134 156 })), 157 + Value::UnaryTestVal(t) = > Value::UnaryTestVal(Box ::new(UnaryTestVal { 158 + op: t .op, 159 + endpoint: t .endpoint.into_lenient(), 160 + })), 135 161 other = > other, 136 162 } 137 163 }
modified
crates/feel-lua/src/lib.rs
+3 −0
@@ -414,6 +414,9 @@
414 414 }, 415 415 Func::Closure(_) = > LuaValue::Nil, 416 416 }, 417 + // An opaque comparison-test value `(< 10)` (ADR-32) has no native Lua type; 418 + // like a native FEEL closure it crosses out as `nil`. 419 + Value::UnaryTestVal(_) = > LuaValue::Nil, 417 420 }) 418 421 } 419 422
modified
crates/feel-py/src/lib.rs
+3 −0
@@ -543,6 +543,9 @@
543 543 }, 544 544 Func::Closure(_) = > py.None ().into_bound(py), 545 545 }, 546 + // An opaque comparison-test value `(< 10)` (ADR-32) has no native Python type; 547 + // like a native FEEL closure it crosses out as `None`. 548 + Value::UnaryTestVal(_) = > py.None ().into_bound(py), 546 549 }) 547 550 } 548 551