implements PR029
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
# PR-029 - PBS Builtin Slot Inference and Canonical Layout Semantics
|
||||
|
||||
## Briefing
|
||||
|
||||
Hoje o frontend aceita `Slot(index=...)` manual em `declare builtin type`, e parte da validacao de layout fica empurrada para `load-facing`.
|
||||
Isso abre espaco para inconsistencias entre declaracao de campos, flattening e offsets.
|
||||
|
||||
Esta PR move ownership de slot para o compilador: offsets passam a ser inferidos deterministicamente a partir do layout canonico flattenado, sem autoria manual de `Slot`.
|
||||
|
||||
## Motivation
|
||||
|
||||
- Reduzir superficie de erro humano em builtin layout.
|
||||
- Alinhar semantica estatica com o contrato de layout flattenado.
|
||||
- Evitar que erros de layout aparecam tarde em `load-facing` quando sao semanticos.
|
||||
|
||||
## Target
|
||||
|
||||
- Tornar `Slot(index=...)` proibido na superficie de fonte de builtin field.
|
||||
- Banir `Slot(...)` da gramatica PBS (erro de sintaxe), sem fallback transitorio.
|
||||
- Inferir `slotStart` automaticamente no frontend com base em:
|
||||
- ordem canonica dos campos,
|
||||
- largura flattenada dos tipos admissiveis,
|
||||
- composicao builtin aninhada.
|
||||
- Mover validacoes de layout para `static semantics`.
|
||||
- Atualizar extracao de metadata reservada para usar slots inferidos (nao lidos de atributo).
|
||||
- Atualizar fixtures do SDK minimo (`@core:color` etc.) removendo `Slot`.
|
||||
|
||||
## Scope
|
||||
|
||||
- `frontends/prometeu-frontend-pbs` (semantica + metadata extraction + testes).
|
||||
- Atualizacao de specs PBS relacionadas a builtin layout e diagnosticos.
|
||||
|
||||
## Method
|
||||
|
||||
1. Introduzir um resolvedor de layout builtin na fase semantica.
|
||||
2. Calcular largura flattenada por tipo builtin e mapear offsets por campo.
|
||||
3. Banir `Slot(...)` no parser (erro de sintaxe deterministico) com remocao da forma da superficie da linguagem.
|
||||
4. Produzir diagnosticos `E_SEM_*` deterministicos para:
|
||||
- tipo de campo nao admissivel para layout builtin,
|
||||
- composicao ciclica de builtin layout,
|
||||
- impossibilidade de resolver largura flattenada.
|
||||
5. Persistir offsets inferidos no metadata model de lowering (`IRReservedMetadata`).
|
||||
6. Remover a exigencia de `Slot` no loader/extractor.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- Builtin fields sem `Slot` compilam quando o layout e admissivel.
|
||||
- Qualquer `Slot(...)` manual e rejeitado como erro de sintaxe (breaking imediato).
|
||||
- `Pixel(x:int, y:int, color:Color)` recebe offsets inferidos consistentes com flattening.
|
||||
- Erros de layout builtin deixam de depender de `E_LOAD_*` para serem detectados.
|
||||
- Suite Gate U cobre positivo e negativo para inferencia de slot.
|
||||
|
||||
## Tests
|
||||
|
||||
- Positivo: inferencia de offsets em builtin simples e composto.
|
||||
- Negativo: `Slot` manual presente (falha de parser).
|
||||
- Negativo: campo com tipo nao admissivel.
|
||||
- Negativo: ciclo de composicao builtin.
|
||||
- Asserts por `code`, `phase`, `templateId`, `span`.
|
||||
|
||||
## Non-Goals
|
||||
|
||||
- Alterar o contrato de runtime/verifier para alem da inferencia de layout no frontend.
|
||||
- Definir encoding final de artifact/PBX.
|
||||
|
||||
## Affected Documents
|
||||
|
||||
- `docs/pbs/specs/4. Static Semantics Specification.md`
|
||||
- `docs/pbs/specs/3. Core Syntax Specification.md`
|
||||
- `docs/pbs/specs/6.1. Intrinsics and Builtin Types Specification.md`
|
||||
- `docs/pbs/specs/8. Stdlib Environment Packaging and Loading Specification.md`
|
||||
- `docs/pbs/specs/12. Diagnostics Specification.md`
|
||||
@@ -248,6 +248,7 @@ Rules:
|
||||
- Reserved stdlib/toolchain interface modules MAY use attributes where explicitly allowed by syntax and semantics.
|
||||
- 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.
|
||||
|
||||
### 6.2 Top-level declarations
|
||||
|
||||
|
||||
@@ -62,7 +62,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`, `BuiltinType`, `BuiltinConst`, `IntrinsicCall`, and `Slot`.
|
||||
- In v1 core, the normative reserved attributes are `Host`, `BuiltinType`, `BuiltinConst`, and `IntrinsicCall`.
|
||||
- `Host` is valid only on a host method signature declared directly inside a reserved stdlib/interface-module `declare host` body.
|
||||
- `Host` is invalid on ordinary user-authored modules, top-level `fn`, struct methods, service methods, callbacks, contracts, and constants.
|
||||
- `Host` metadata is consumed by the compiler during host-binding lowering.
|
||||
@@ -70,7 +70,6 @@ Rules:
|
||||
- `BuiltinType` is valid only on a reserved top-level `declare builtin type` declaration.
|
||||
- `BuiltinConst` is valid only on a reserved top-level `declare const` declaration that omits an initializer.
|
||||
- `IntrinsicCall` is valid only on a method signature declared directly inside a reserved `declare builtin type` body.
|
||||
- `Slot` is valid only on a field declaration in the header of a reserved `declare builtin type`.
|
||||
- Builtin metadata is consumed by the compiler during VM-owned builtin and intrinsic lowering rather than by host-binding lowering.
|
||||
|
||||
### 2.4 Tuple shapes
|
||||
@@ -184,7 +183,9 @@ Rules:
|
||||
- `BuiltinType.version` MUST be a positive integer literal.
|
||||
- Two builtin type declarations in the same resolved stdlib environment MUST NOT lower to the same canonical `(name, version)` unless they denote the same builtin declaration after project/module resolution.
|
||||
- A builtin field type must be builtin-layout-admissible as defined by the builtin/intrinsics specification.
|
||||
- A builtin field `Slot` attribute, when present, MUST declare a non-negative integer literal and must match the declaration's canonical flattened layout.
|
||||
- Builtin field slot offsets are inferred by the compiler from canonical field order and flattened builtin layout width.
|
||||
- Builtin layout composition must be acyclic.
|
||||
- A builtin field that depends on a builtin layout with unresolved flattened width is statically invalid.
|
||||
- `IntrinsicCall` MUST declare exactly the named argument `name` and MAY additionally declare `version`.
|
||||
- `IntrinsicCall.name` MUST be a non-empty string literal.
|
||||
- `IntrinsicCall.version`, when present, MUST be a positive integer literal.
|
||||
@@ -657,7 +658,6 @@ At minimum, deterministic static diagnostics are required for:
|
||||
- invalid `BuiltinType` attribute target,
|
||||
- invalid `BuiltinConst` attribute target,
|
||||
- invalid `IntrinsicCall` attribute target,
|
||||
- invalid `Slot` attribute target,
|
||||
- duplicate `Host` attribute on one host method,
|
||||
- missing required `Host` attribute on a reserved host method,
|
||||
- malformed `Host(module=..., name=..., version=...)` argument set,
|
||||
@@ -675,9 +675,9 @@ At minimum, deterministic static diagnostics are required for:
|
||||
- malformed `BuiltinConst(target=..., name=..., version=...)` argument set,
|
||||
- invalid empty `BuiltinConst.target` or `BuiltinConst.name`,
|
||||
- invalid non-positive `BuiltinConst.version`,
|
||||
- invalid builtin field `Slot(...)`,
|
||||
- overlapping builtin field slot range,
|
||||
- builtin field type not builtin-layout-admissible,
|
||||
- cyclic builtin layout composition,
|
||||
- unresolved flattened builtin layout width,
|
||||
- duplicate canonical builtin type identity,
|
||||
- duplicate canonical builtin intrinsic identity,
|
||||
- duplicate canonical builtin constant identity,
|
||||
|
||||
@@ -117,8 +117,8 @@ Illustrative form:
|
||||
```pbs
|
||||
[BuiltinType(name="vec2", version=1)]
|
||||
declare builtin type Vec2(
|
||||
[Slot(0)] pub x: float,
|
||||
[Slot(1)] pub y: float,
|
||||
pub x: float,
|
||||
pub y: float,
|
||||
) {
|
||||
[IntrinsicCall(name="dot")]
|
||||
fn dot(other: Vec2) -> float;
|
||||
@@ -196,22 +196,16 @@ Consequences:
|
||||
- a builtin field declaration does not imply that builtin values are structs,
|
||||
- and a builtin field declaration does not allow user code to provide storage-level implementation bodies.
|
||||
|
||||
## 10. `Slot` Metadata
|
||||
## 10. Builtin Slot Inference
|
||||
|
||||
`Slot(n)` identifies the starting flattened slot offset of a builtin field within
|
||||
the enclosing builtin layout.
|
||||
Builtin field slot offsets are inferred by the compiler, not authored in source.
|
||||
|
||||
Rules:
|
||||
|
||||
- `n` is zero-based,
|
||||
- `Slot(n)` refers to the starting slot offset after flattening nested builtin-layout-admissible fields,
|
||||
- slot offsets must be unique,
|
||||
- slot offsets must match the declaration's canonical flattened layout,
|
||||
- and overlapping slot ranges are invalid.
|
||||
|
||||
`Slot` exists to make canonical layout explicit.
|
||||
Future grammar may allow offset inference by declaration order, but explicit slot
|
||||
metadata is valid and authoritative in this temporary contract.
|
||||
- slot offsets are zero-based and deterministic,
|
||||
- offsets are computed from declaration order plus flattened widths of field types,
|
||||
- nested builtin fields contribute their full flattened width to subsequent offsets,
|
||||
- and source-level `Slot(...)` metadata is forbidden in v1.
|
||||
|
||||
## 11. Builtin Layout Admissibility
|
||||
|
||||
@@ -256,14 +250,14 @@ Example:
|
||||
```pbs
|
||||
[BuiltinType(name="color", version=1)]
|
||||
declare builtin type Color(
|
||||
[Slot(0)] pub raw: int,
|
||||
pub raw: int,
|
||||
);
|
||||
|
||||
[BuiltinType(name="pixel", version=1)]
|
||||
declare builtin type Pixel(
|
||||
[Slot(0)] pub x: int,
|
||||
[Slot(1)] pub y: int,
|
||||
[Slot(2)] pub color: Color,
|
||||
pub x: int,
|
||||
pub y: int,
|
||||
pub color: Color,
|
||||
);
|
||||
```
|
||||
|
||||
@@ -332,8 +326,8 @@ Example:
|
||||
```pbs
|
||||
[BuiltinType(name="vec2", version=1)]
|
||||
declare builtin type Vec2(
|
||||
[Slot(0)] pub x: float,
|
||||
[Slot(1)] pub y: float,
|
||||
pub x: float,
|
||||
pub y: float,
|
||||
) {
|
||||
[IntrinsicCall(name="dot")]
|
||||
fn dot(other: Vec2) -> float;
|
||||
@@ -530,13 +524,13 @@ At minimum, a conforming implementation must reject:
|
||||
1. `declare builtin type` in an ordinary user-authored module,
|
||||
2. missing required `BuiltinType` metadata on a builtin declaration,
|
||||
3. duplicate builtin field names within one declaration,
|
||||
4. duplicate or overlapping slot assignments,
|
||||
4. source-level `Slot(...)` usage in builtin declarations,
|
||||
5. builtin field types that are not builtin-layout-admissible,
|
||||
6. `IntrinsicCall` used outside a builtin declaration body,
|
||||
7. `BuiltinConst` used outside a reserved top-level `declare const` shell,
|
||||
8. duplicate canonical builtin type identities in the same compilation environment,
|
||||
9. duplicate intrinsic canonical identities within the same builtin owner and version line,
|
||||
10. mismatched declared field slot metadata versus flattened layout,
|
||||
10. cyclic or unresolved flattened builtin layout composition,
|
||||
11. executable member bodies inside builtin declarations,
|
||||
12. any lowering that routes VM-owned builtin operations through the host-binding pipeline.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user