implements PLN-0092

This commit is contained in:
2026-07-15 06:55:26 +01:00
parent ad2ae00f39
commit 917b0e1b9a
19 changed files with 955 additions and 18 deletions
@@ -76,10 +76,18 @@ Mandatory declaration metadata on required declaration nodes includes:
2. declared signature/surface when applicable (parameters/return),
3. declaration-level syntactic flags/attributes required by later phases,
4. stable `file/start/end` attribution,
5. lifecycle-marker metadata when a declaration carries `[Init]` or `[Frame]`.
5. lifecycle-marker metadata when a declaration carries `[Init]` or `[Frame]`,
6. documentation attribute metadata when a declaration carries `[Doc(markdown = """...""")]`.
Missing required attribution or metadata on mandatory nodes is non-conformant.
Documentation metadata rules:
- The AST MUST preserve the `Doc` attribute name, the `markdown` argument name, the raw documentation text block payload, and source attribution for the whole attribute and payload.
- The AST MUST distinguish documentation text block payloads from ordinary string literals.
- The AST MUST preserve enough attribution for later diagnostics to point at malformed or invalid `Doc` usage.
- AST construction MUST NOT normalize documentation text block content in a way that loses source-observable parse meaning before the semantic normalization step.
## 8. Mandatory Declaration Families
The v1 AST must represent, at minimum, declaration families for:
@@ -104,6 +112,8 @@ Lifecycle-observable declarations must preserve marker metadata explicitly:
- top-level `fn` marked with `[Frame]`,
- and host method signatures marked with `[InitAllowed]`.
Documentation-observable declarations must preserve `Doc` metadata explicitly on every accepted named API declaration surface that carries `[Doc(markdown = """...""")]`.
## 9. Mandatory Statement and Expression Families
The v1 AST must represent statement/expression families for the supported core syntax slice, including at minimum:
@@ -214,6 +214,19 @@ Reserved-attribute diagnostics for host-backed asset lowering must also cover:
- out-of-range `AssetLowering.param` indexes,
- and `AssetLowering` targets whose selected parameter is not statically typed as `Addressable`.
Documentation attribute diagnostics must cover:
- unterminated documentation text block syntax,
- `Doc` used without the required `markdown` argument,
- `Doc` with extra or unknown arguments,
- `Doc` with a non-documentation-text-block payload,
- duplicate `Doc` on the same declaration,
- `Doc` applied to a parameter or other non-documentable surface,
- normalized empty or whitespace-only documentation payload,
- and rejected aliases or alternate forms such as `text`, positional arguments, `html`, `format`, `Document`, `Documentation`, or `md"""..."""`.
Diagnostics for duplicate `Doc` attributes must be static semantic diagnostics and should include a related site for the conflicting declaration attribute when available.
At minimum, host-admission diagnostics must cover missing or malformed host capability metadata and unknown or undeclared capability names.
Only backend-originated failures that remain source-attributable and user-actionable belong to the PBS-facing diagnostics contract.
@@ -114,6 +114,13 @@ String literals:
- delimited by `"`.
- supported escapes: `\\`, `\"`, `\n`, `\r`, `\t`.
Documentation text block literals:
- delimited by `"""`.
- valid only as the value of the `markdown` argument in the reserved `[Doc(markdown = """...""")]` attribute surface.
- not part of the runtime expression literal surface in v1 core.
- preserve authored text for later documentation normalization.
Boolean literals:
- `true`, `false`.
@@ -241,7 +248,8 @@ Attribute ::= '[' Identifier AttrArgs? ']'
AttrArgs ::= '(' AttrArgList? ')'
AttrArgList ::= AttrArg (',' AttrArg)*
AttrArg ::= Identifier '=' AttrValue
AttrValue ::= StringLit | IntLit | BoolLit
AttrValue ::= StringLit | IntLit | BoolLit | DocTextBlock
DocTextBlock ::= '"""' DocTextBlockChar* '"""'
```
Rules:
@@ -250,11 +258,16 @@ Rules:
- Attributes do not introduce values, types, callables, or modules by themselves.
- In v1 core, ordinary user-authored modules MUST reject attributes unless another specification explicitly permits them.
- Ordinary userland source MAY use `[Init]` and `[Frame]` only on top-level `fn` declarations.
- Ordinary userland source MAY use `[Doc(markdown = """...""")]` on named API declarations where the static semantics specification permits documentation.
- Reserved stdlib/toolchain interface modules MAY use attributes where explicitly allowed by syntax and semantics.
- Reserved stdlib/toolchain interface modules MAY additionally use `[InitAllowed]` only on `declare host` method signatures where another specification explicitly permits it.
- Attribute interpretation is compile-time only unless another specification explicitly lowers its effect into runtime-facing metadata.
- Reserved attribute names used by builtin-type and intrinsic shells do not become ordinary value-level syntax.
- `Slot(...)` is not part of the v1 attribute surface; source that uses `Slot` must be rejected in syntax phase.
- `Doc` is a reserved documentation attribute name. Its only v1 syntactic shape is `[Doc(markdown = """...""")]`.
- The `Doc` attribute MUST NOT accept positional arguments, `text`, `html`, `format`, `Document`, `Documentation`, or prefixed text block forms such as `md"""..."""`.
- Documentation text blocks are not string literals and MUST NOT appear in ordinary expressions, parameter defaults, or non-`Doc` attribute arguments.
- Attribute ordering is syntactically insignificant; semantic validation determines duplicate or invalid attribute combinations.
### 6.2 Top-level declarations
@@ -80,7 +80,7 @@ Rules:
- Attributes are not first-class values and are not reflectable in v1 core.
- Attributes do not automatically survive into runtime or bytecode artifacts.
- An attribute affects runtime artifacts only when another specification defines an explicit lowering for its semantic effect.
- In v1 core, the normative reserved attributes are `Host`, `Capability`, `AssetLowering`, `BuiltinType`, `BuiltinConst`, `IntrinsicCall`, `Init`, `Frame`, and `InitAllowed`.
- In v1 core, the normative reserved attributes are `Host`, `Capability`, `AssetLowering`, `BuiltinType`, `BuiltinConst`, `IntrinsicCall`, `Init`, `Frame`, `InitAllowed`, and `Doc`.
- `Host` is valid only on a host method signature declared directly inside a reserved stdlib/interface-module `declare host` body.
- `Capability` is valid only on a host method signature declared directly inside a reserved stdlib/interface-module `declare host` body.
- `AssetLowering` is valid only on a host method signature declared directly inside a reserved stdlib/interface-module `declare host` body.
@@ -100,6 +100,42 @@ Rules:
- Builtin metadata is consumed by the compiler during VM-owned builtin and intrinsic lowering rather than by host-binding lowering.
- `Init` and `Frame` are consumed by lifecycle analysis and lowering rather than by ordinary runtime reflection.
- `InitAllowed` is consumed by init-time host-admission analysis and does not become ordinary userland metadata.
- `Doc` is compile/editor documentation metadata and is consumed by compiler-owned editorial surfaces.
- `Doc` MUST NOT be lowered into bytecode, PBX, cartridge, or runtime-facing artifacts unless a future specification explicitly defines such lowering.
### 2.3.1 `Doc` documentation metadata
`Doc` attaches authored Markdown documentation to a named API declaration.
Canonical v1 shape:
```pbs
[Doc(markdown = """
Draws a sprite.
- `x`: screen x
- `y`: screen y
""")]
```
Rules:
- `Doc` MUST declare exactly one named argument, `markdown`.
- `Doc.markdown` MUST be a documentation text block.
- `Doc` MUST NOT accept aliases or alternate forms such as `text`, positional arguments, `html`, `format`, `Document`, `Documentation`, or `md"""..."""`.
- A declaration MUST NOT carry more than one `Doc` attribute.
- Duplicate `Doc` attributes are static semantic errors and must not be rejected only as parser errors.
- Attribute order is semantically irrelevant; `Doc` colocated with other valid attributes has the same meaning regardless of ordering.
- `Doc` is valid only on named API declarations that introduce named semantic symbols and can carry attributes.
- The v1 documentable surface includes functions, methods, classes/structs when present, services, hosts, builtin and stdlib declarations, and interface declarations.
- Parameters MUST NOT receive `Doc` in v1. Parameter documentation, when present, MUST be authored inside the Markdown payload of the owning declaration.
- Fields, enum cases, tuple fields, local variables, expressions, and other non-API declaration surfaces MUST NOT receive `Doc` unless a future decision explicitly classifies them as documentable named API declarations.
- Documentation text block content MUST be normalized before semantic empty-payload validation and before exposure to editor consumers.
- Normalization MUST remove an incidental leading empty line, remove an incidental trailing empty line, compute the common indentation of non-empty content lines, remove that common indentation, preserve internal line breaks, and preserve Markdown content after indentation normalization.
- A normalized empty or whitespace-only `Doc.markdown` payload is invalid.
- The authored format is a supported Markdown subset. Rendering, sanitization, and unsupported Markdown constructs are consumer responsibilities.
- Compiler semantic metadata MUST preserve normalized Markdown documentation as metadata of the documented symbol.
- LSP and editor consumers MUST consume compiler-resolved documentation metadata rather than reparsing source text.
### 2.4 Tuple shapes
@@ -354,6 +354,8 @@ Rules:
- Renaming a public stdlib or host-backed parameter is API compatibility-sensitive and MUST be reviewed with the same discipline as other public callable-shape changes.
- Interface-module loaders MUST NOT replace missing or unavailable public parameter names with generated ordinal placeholders such as `arg0` or `arg1`.
- Missing canonical parameter identity MUST be represented as incomplete semantic metadata, not as a fabricated public name.
- Stdlib, SDK, and interface-module API declarations SHOULD carry authored English documentation through `[Doc(markdown = """...""")]` once the documentation surface is implemented.
- Stdlib and SDK parameter documentation MUST be authored inside the owning declaration's Markdown payload; parameters MUST NOT carry `[Doc]`.
### 9.3 Interface-module restrictions
@@ -441,6 +443,15 @@ Rules:
- Attributes are not exported as ordinary values, types, or runtime-reflectable objects.
- Attributes do not automatically survive into bytecode, PBX, or runtime metadata.
`Doc` is a reserved documentation attribute for compiler/editor metadata.
Rules:
- Stdlib, SDK, and interface modules MUST use the same `[Doc(markdown = """...""")]` surface as ordinary PBS source for authored API documentation.
- Authored source documentation takes precedence over imported or generated documentation for the same symbol.
- Conflicts between authored and imported/generated documentation MUST be resolved deterministically or reported through explicit diagnostics.
- `Doc` metadata enriches compiler/editor surfaces and MUST NOT change import resolution, host binding, ABI identity, executable lowering, or runtime behavior.
### 11.2 `Host` attribute
The canonical reserved host-binding attribute is: