Skip to content

docs(language): adopt the Unit/Option/Result contract - #1

Merged
fffonion merged 5 commits into
masterfrom
feat/option-result-spec
Nov 14, 2026
Merged

fffonion merged 5 commits into
masterfrom
feat/option-result-spec

Conversation

@fffonion

Copy link
Copy Markdown
Contributor

Replaces the legacy null literal and T? optional type with the implemented Unit/Option/Result contract, and corrects the pattern, carrier, projection, and host-argument rules against the current compiler.

  • lexical/syntax/grammar: no null literal, no T? suffix, no null map key or null pattern; Unit is (); Option/Result use qualified constructors; ? and ?. are distinct.
  • Constructor patterns bind names; bare Some/None/Some(TypeName) are legacy optional-slot patterns with their actual diagnostics; Option/Result mixed arms are rejected separately.
  • Carriers: Unit is the internal Null value, Option::None is a tag-only map; Some(map) matches because the carrier's type name is map.
  • Typed host: GuestOption/GuestResult versus Rust Option argument omission, Procedure returns Unit, json::decode::<T> needs a concrete type.
  • ?.: receivers are object/map, arrays, strings, and projections rooted in a declared local; bytes type-checks then lowers to None; untyped literals and call results are refused.
  • VMBC v14, host schema tags 15/16 and compiler tags 19/20, no legacy readers.
  • TextMate grammar drops null highlighting and adds Unit/constructor/propagation scopes.
  • New contract test plus fixture; the fixture is executed with the real pd-vm-run (missing binary fails, never skips).

Verified: 8/8 Node contract tests with CORE_BIN; 1 deliberate failure without it; static CI path 7/7.

- lexical: drop the null keyword and null literal, add the `()` Unit value and
  document `?` versus `?.`.
- syntax/grammar: reject the `T?` suffix and the null literal, map key, and
  match pattern; add Unit, `Option::Some`/`Option::None`,
  `Result::Ok`/`Result::Err`, `?` propagation, and `?.` projection.
- host-functions: guest Option is `GuestOption<T>`, guest Result is
  `GuestResult<T, E>`, the outer `VmResult` is the fatal channel, procedures
  publish logical Unit, and typed `json::decode::<T>` needs a concrete type.
- bytecode: VMBC v14 only, Option/Unit schema tags 15/16 and 19/20, Result
  schema and tag/payload carriers, Unit as the physical Null constant.
- debugger: report Unit as `()` instead of a null value.
- TextMate grammar: drop the null literal rule and its function-call
  exclusions; add unit, constructor, propagation, and optional-access scopes.
- tests: add tests/option-result-contract.test.mjs and
  tests/fixtures/option-result.rss, and wire the static contract checks into CI.
Address the review of the Unit/Option/Result contract:

- syntax/grammar: `Option::Some(...)`, `Result::Ok(...)` and `Result::Err(...)`
  bind a name (or `_`); they never filter on a type, so `Option::Some(int)`
  binds a local called `int`. Drop the `Option::Some(TypeName)` /
  `Result::Ok(TypeName)` type-pattern alternatives and stop claiming that bare
  `Some`/`None`/`Ok`/`Err` fall back to value matching. `None` and
  `Some(name)` are legacy optional-slot patterns that now fail with
  "Some(...) and None match patterns require an optional value";
  `Some(TypeName)` is a receiver-type-name test with no optional-slot
  precondition; bare `Ok(...)`/`Err(...)` arms are parse errors, and legacy
  patterns cannot be mixed with constructor arms.
- grammar: admit `OptionNone` in `PrimaryExpr` so the production is not
  dangling.
- syntax: state one `?.` receiver rule - a declared struct, `map<T>`, declared
  array, or `string`, or a projection rooted in one - with declared-array and
  string index examples, instead of narrowing the rule to struct/`map<T>`.
- debugger: Unit's carrier is the internal Null value while `Option::None` is a
  tag-only Map, so an inspection view must derive `None` from the tag.
- host-functions: no host argument is ever omitted or normalized to `None`;
  only a declared-schema map/struct construction site materializes an omitted
  Option field.
- bytecode: scope the Unit carrier to the `()` schema so it agrees with the
  tag-only `Some(())` restoration rule.
- TextMate: match `Option::{Some,None}` and `Result::{Ok,Err}` only, so
  `Option::Ok` and `Result::Some` stay unhighlighted.
- tests: fold the new assertions into the existing contract checks, add
  fixture lines for the type-shaped binding name and array/string projection,
  and use `--test-skip-pattern` in the header to match README and CI.
… claims

The previous wording stated three rules more strongly than the VM implements
them, so each one is replaced by the rule the Core actually enforces.

- `Some(TypeName)` is a `type()` comparison against `MatchTypeName`. An
  `Option` carrier is a `Value::Map` whose type name is `map`, so
  `Some(map)`/`Some(Map)` do match it; only the payload names are false.
  syntax.md and grammar.md now say that instead of "always false".
  `number`/`Number` are documented as two names, `int` or `float`.
- Host argument omission is layered, not blanket: a trailing Rust `Option<T>`
  parameter may be omitted (`from_missing_arg` -> `Ok(None)`, label
  `int | null`), a `GuestOption<T>` parameter may not (`missing argument`),
  and every other type rejects an absent argument the same way. The
  declared-schema literal remains the only place an `Option` materializes
  without an argument.
- `?.` receivers are the set `infer_access_schema` admits, not every declared
  schema: int/number/Result/unresolved generics are refused, the field form
  needs a direct local with a literal key, and `bytes` type-checks but lowers
  to `Option::None` because the runtime projection dispatches only
  map/array/string.

Also records the `Some(_)` parse error, separates the `Option` and `Result`
mixing messages, and retargets the contract test at the corrected claims.
…ion receivers

Two passages still described behaviour the Core does not have.

- host-functions: the missing-argument error was given as
  `missing argument: <label>`. The generated wrapper actually expands every
  guest parameter to `args.get(index).ok_or_else(|| VmError::HostError(
  format!("missing {}", label)))?` with `label` = `"{wrapper} {param}"`, so the
  error is `missing {wrapper} {param}`. `GuestOption<T>` and
  `GuestResult<T, E>` share that decoder — `guest_result_shape` matches the
  guest `Option` wrapper too — so the layer is restated as: trailing Rust
  `Option<T>` omittable (`from_missing_arg` -> `Ok(None)`, label `int | null`),
  guest `Option`/`Result` parameters required and reported by wrapper and
  parameter, every other type rejected the same way. The declared-schema
  literal stays the only place an absent `Option` materializes as
  `Option::None`.
- syntax: drop the claim that the field form needs a direct local. The parser
  records `field_projection: false` for the language form, and the
  direct-local-and-literal-key check only fires when that flag is true, which
  only the internal lifetime passes set; `present?.b?.c` compiles and runs.
  The field form admits objects and `map<T>` plus projection chains rooted in a
  declared local, the index form adds declared arrays, `string`, and `bytes`
  with an int index, and the `:318` admission list now carries `bytes` with the
  type-checks-but-lowers-to-`Option::None` caveat so both paragraphs agree.

The contract test asserts the new `missing {wrapper} {param}` phrasing and
rejects the stale `missing argument: <label>` text.
The guest `GuestOption`/`GuestResult` decoder reports `missing {wrapper} {param}`,
while every other parameter type goes through `borrow_arg`/`take_arg` and reports
`missing argument: {label}`. The label is the generated Rust wrapper identifier
plus the parameter name, never the guest path, so the example must not use
`json::decode`.
@fffonion
fffonion merged commit c2161b3 into master Nov 14, 2026
4 checks passed
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