Repository navigation
docs(language): adopt the Unit/Option/Result contract - #1
Merged
Merged
Conversation
- 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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the legacy
nullliteral andT?optional type with the implemented Unit/Option/Result contract, and corrects the pattern, carrier, projection, and host-argument rules against the current compiler.(); Option/Result use qualified constructors;?and?.are distinct.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.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.