Skip to content

Keep type structure in the compiled schema (fixed array length, f32/f64, unions) #95

Closed

Description

@Kinflou

Freezing turns a field's type into text (KindValue::Namespaced("T[]", _)), and the text drops information:

  • Fixed array length. T[8] and T[] both freeze to "T[]". Generators can't emit [T; 8], nothing checks the length, and validator.rs's detect_cycle (ends_with("[]")) treats every array as a cycle escape, so struct Node { next: Node[4] } isn't caught. schema/idl/size.rs works on the AST instead of the IR because of this.
  • f32 vs f64. Both freeze to "float", so comline-rust's map_str_type emits f64 for an f32 field.
  • Unions. comline-rust's rust_type has no case for KindValue::Union and emits /* unknown_kind */.

Proposal

Freeze types as a structured value instead of a string: element type, array shape (dynamic, or fixed N), exact primitive. Generators render from that instead of parsing strings with strip_suffix("[]").

This shares a prerequisite with running validators (#96, step 4a: the validate condition also needs freezing as a tree). Doing both in one IR revision means one format bump, not two. .comline/ is CBOR with name-tagged fields, so old stores can still be read with #[serde(default)] where a field is added.

It is also the prerequisite for bounds written on types (#98).

Tasks

  • Structured type in FrozenUnit::Field, FrozenArgument, TypeAlias::target, constants
  • Keep fixed array length; keep f32/f64 distinct
  • detect_cycle: only a dynamic array breaks a cycle
  • Generators (generation/codegen kernel, comline-rust, comline-typescript) render from the structured type: [T; N] / fixed tuples or arrays as each target decides, f32 → f32, unions
  • size.rs can move to the IR if useful
  • Pin cascade (core → generation → comline-rust + comline-typescript → cli → language-server → playground)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1NextcodegenCode generationcompilerParser, IR, CASenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions