Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Upgradeable ArrayBuffers #368

@sffc

Description

@sffc

Possibly related: #134, #218

A potential direction this proposal could take, which would solve a new set of problems, could be "upgradeable ArrayBuffers":

  • The new language primitive is a byte array (ArrayBuffer by value).
  • The primitive can be "upgraded" by applying a schema to access data.

Something sort-of like this...

let input = { a: 1, b: 2 };

// Convert the object to its immutable value type
let primitive = Record.create(input);

// Convert the immutable value type back to an object using a pattern schema
let output = primitive.upgrade({ a: Number, b: Number });

// Access a field without upgrading (for efficiency)
primitive.get({ a: Number, b: Number }, `.a`)

What this achieves:

  1. Immutability
  2. Value Types
  3. Equality is trivial (a byte comparison)
  4. Hopefully easier to implement
  5. Step toward zero-copy deserialization

Some initial open questions:

  1. How to handle variable-length types in the record, like a String or a BigInt
    • Could allow one of these only in the final position (like Rust DSTs)
    • Or, variable-length fields could require a length prefix (but how is that represented?)
  2. Syntax for how to access fields
    • Call site needs the whole schema; how can this be expressed ergonomically?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions