Skip to content

Adds the presence operators - #258

Merged
johnnyt merged 1 commit into
mainfrom
px-h5pp-presence-operators
Nov 21, 2026
Merged

johnnyt merged 1 commit into
mainfrom
px-h5pp-presence-operators

Conversation

@johnnyt

@johnnyt johnnyt commented Nov 20, 2026

Copy link
Copy Markdown
Member

Adds the presence operators expr is [not] blank, expr is [not] present and expr is [not] defined, as ADR-0021 (on main at proposed) decides them. They answer true or false for every value, so a host that runs with builtins: false can ask whether a value was supplied. The presence semantics, the surface, the opcode, ISA v7 and tier 10 were ruled by the operator, 2026-11-20.

Refs: px-h5pp

Open for the operator: is not present

The bead's acceptance says "is present and every negation follow it with the existing not opcode". ADR-0021's compile table compiles x is not present to ["presence", "blank"] alone, the same instructions as x is blank. This PR builds the record's table:

Spelling Instructions after the operand
x is blank ["presence", "blank"]
x is not blank ["presence", "blank"], ["not"]
x is present ["presence", "blank"], ["not"]
x is not present ["presence", "blank"]
x is defined ["presence", "defined"]
x is not defined ["presence", "defined"], ["not"]

The literal reading of the acceptance would compile x is not present to ["presence", "blank"], ["not"], ["not"]; the answer is the same either way. This PR is held unmerged until the operator answers; the other reading is one change to presence_instruction/2 in lib/predicator/visitors/instructions_visitor.ex, one compile-surface case in the corpus and a Note on the record.

What changes

  • Parser. parse_comparison/1 reads is, an optional not, then blank, present or defined directly after a complete operand, and builds {:presence, kind, negated?, expr, pos}. The words are read by position (presence_word/1), so none is reserved and each stays an ordinary identifier everywhere else: as a variable, a property name, an object key, an assignment target and the first word after a block's closing brace. Each word is accepted in lower case and in upper case. The operators sit at comparison precedence and do not chain. A partial suffix, or one with a parenthesised word (x is not (blank)), falls through to the parse error it already was.
  • Compiler. One presence opcode with the operand "blank" or "defined", followed by not as the table above states.
  • Evaluator. execute_presence/2 answers per ADR-0021's table. Blank strings are matched code point by code point against the Unicode White_Space list in docs/isa.md, never through String.trim/1, so the answer does not depend on the running Elixir's Unicode tables. The opcode never errors on a value; a load under on_unbound: :error keeps its own contract.
  • Decompiler. Writes each of the six spellings as written, in lower case and with single spaces.
  • Reading surfaces. Predicator.AST walks into the operand; Predicator.Analysis reads the operand as a reference in both the AST and the instruction forms; Predicator.Vocabulary lists the eight word spellings under a new :presence category, as identifiers and outside keywords/0; Predicator.Simple admits the six spellings on a field path as a clause with no value.

ISA

ISA v7. presence is a new opcode (pops 1, pushes a boolean), tier 10, named "presence and overlap". docs/isa.md gains its opcode row, its section 5 entry with the White_Space code points, the v7 history row and the tier 10 row; the current-version line reads v7. Predicator.isa_version/0 answers 7 and Predicator.Instructions.required_isa/1 answers 7 for a list holding the opcode.

Migration (ADR-0003): none needed. Every v6 instruction list is still valid at v7 and runs unchanged; this is an additive version, so it ships in a minor release. A sibling at v6 keeps every tier 1 through 9 claim and refuses a list holding presence by its version.

Corpus

Cause: the new opcode. New authored file conformance/cases/presence.json, generated into the new conformance/corpus/tier-10.json; the manifest gains tier 10 and its isa_version moves to 7, so its corpus_hash moves. No existing case is edited or removed, and tiers 1 through 9 are byte-identical. The cases: for each of the six spellings, one case per value kind (unbound, undefined, null, the empty string, spaces, a no-break space, an ideographic space, a zero-width space, a non-empty string, 0, 0.0, 1, true, false, an empty list, a list holding an empty string, a list holding null, an empty object, a one-key object, a date, a datetime, a zero-length duration) and one missed path; then precedence with AND, OR and not, a parenthesised operand, an upper-case spelling, and the words as variable and property names. Every case has a source, so each has a compile-surface form. conformance/examples/registry.example.json is re-pinned to the new hash and ISA v7, as its binding test requires.

Records

ADR-0017 gains a dated Note (2026-11-20) at its foot: Predicator.Simple admits the six presence spellings as {path, op, nil}. Zero removed lines under docs/adr/. Direction check: the Note's claims cite clause_from_ast/1 and clause_to_ast/1 in lib/predicator/simple.ex, both on this branch, so they are cited by anchor; ADR-0021 is on main at proposed and is cited by file.

Provenance

Engineering choices this PR makes that the record does not fix:

  • Predicator.Simple's presence ops are spelled after the source: :is_blank, :is_not_blank, :is_present, :is_not_present, :is_defined, :is_not_defined, with nil for the value. Recorded in the ADR-0017 Note.
  • Predicator.Vocabulary lists the presence words in a new :presence category, as :identifier entries without the operator keys, beside :duration_unit as the other positional words; keywords/0 leaves them out because none is reserved.
  • The decompiler writes the presence words in lower case, the spelling ADR-0021 states them in.
  • No feature tag is added for presence; tier 10 selects its cases.
  • docs/architecture.md's grammar gains the presence production; docs/reference/ast.md gains the node and its blame and span rows; docs/reference/language.md gains the presence table from ADR-0021 and a row in the reject-or-propagate table.
  • The changelog fragment carries an Added heading and a Changed heading (Predicator.isa_version/0 answers 7), as changelog.d/README.md allows one file to.

Tests

  • test/predicator/presence_test.exs: parsing, positions and spans, letter case, precedence, non-chaining, the words as identifiers everywhere else, the compile table, every value kind, all 25 White_Space code points, U+200B and U+FEFF, unbound roots under both on_unbound settings, malformed instructions, decompiling, Analysis, AST, Vocabulary and Simple.
  • test/predicator/vocabulary_sync_test.exs binds the vocabulary's presence words to the parser's presence_word/1 clause heads, both ways. Sabotage: removing the present row from the vocabulary, and separately the DEFINED clause from the parser, each turned that test red on its assertion, and each restore was byte-equal.
  • The clause-coverage and ISA sync counts move with the new node and opcode.

Gate: full mix quality green on the committed tree; the commit was made from the byte-identical staged tree the gate ran green on, with the gate lock and a machine slot held across both.

expr is [not] blank, present and defined answer true or false for
every value (ADR-0021). The words are read by position directly after
an operand, so none is reserved. They compile to a new presence
opcode with the operand "blank" or "defined", followed by not for
is present and the negations the record's table lists.

ISA v7: presence is a new opcode in a new tier 10, "presence and
overlap"; docs/isa.md gains its row, its semantics entry with the
White_Space code points, the v7 history row and the tier row. Every
v6 instruction list still runs unchanged.

Corpus: the new opcode adds conformance/cases/presence.json, generated
into corpus/tier-10.json; the manifest gains tier 10 and moves to ISA
v7 and a new hash. No existing case changes.

Predicator.AST, Analysis, Vocabulary and Simple know the node and the
words; ADR-0017 gains a dated Note for the Simple clauses.

Refs: px-h5pp
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/predicator/parser.ex 95.45% 1 Missing ⚠️
Files with missing lines Coverage Δ
lib/predicator.ex 97.14% <ø> (ø)
lib/predicator/analysis.ex 100.00% <100.00%> (ø)
lib/predicator/ast.ex 100.00% <100.00%> (ø)
lib/predicator/conformance/generator.ex 96.29% <ø> (ø)
lib/predicator/evaluator.ex 94.10% <100.00%> (+0.20%) ⬆️
lib/predicator/instructions.ex 100.00% <ø> (ø)
lib/predicator/simple.ex 98.27% <100.00%> (+0.07%) ⬆️
lib/predicator/visitors/instructions_visitor.ex 100.00% <100.00%> (ø)
lib/predicator/visitors/string_visitor.ex 95.97% <100.00%> (+0.19%) ⬆️
lib/predicator/vocabulary.ex 100.00% <100.00%> (ø)
... and 1 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnnyt
johnnyt merged commit b4f2aad into main Nov 21, 2026
2 checks passed
@johnnyt
johnnyt deleted the px-h5pp-presence-operators branch November 21, 2026 19:15
johnnyt added a commit that referenced this pull request Nov 21, 2026
ADR-0021's Status line now reads accepted, naming predicator 9.6.0,
the version that carries its code: the record landed in #257, the
presence operators in #258, total containment and intersects in #259,
the release prep #260 merged at 8d5081e, and the tag v9.6.0 on that
commit published through run 44942037795. The index row in
docs/adr/README.md reads accepted.

A dated foot Note records the evidence and the SHA of origin/main at
which every claim the record makes was re-verified today. One
sentence is superseded: the consequence that new containment cases go
in tier 3. The containment change (c269e4f) put the four cases whose
container is a duration or an object literal in tier 4, because a
case's tier is the highest tier among its opcodes; the Note names the
sentence and cites that change. The flip was decided by the conductor
under a standing consent, 2026-11-21.

Only docs/adr/ changes: the Status line and the index row are the only
removed lines. No Elixir touched, no gate run.

Refs: px-s9xr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant