Skip to content

0-kvspace/XValue header 统一为单一 kindexpr 字符串(ref/ndim/dims 全并入;值=具体 atom,定义=union) #70

Description

@miaobyte

背景

当前 XValue 只有一个 common head(kvspaceHead_t):kind[32] + ndim + dims[8],即「完整 kindexp」。它只能表达单一具体类型(一个 kind + 一个形状),是运行时落盘的自描述。

但 rwir/rwfunc 的定义(签名/参数)需要表达类型表达式 kindexpr,其中含 union 形式:

现 header 的 kind[32] 是单个定长 kind 串,无法承载 | 并集与递归闭包——「定义侧」与「值侧」需要不同表达。

定稿(已锁)

一个 head,唯一真相 = kindexpr 字符串:值侧 = 具体 atom,定义侧 = union。不拆两个 struct,差别只在 kindexpr 串内容。kind 改名 kindexprtype_expr 改名 kindexpr

XValueHead =
[kindexprlen 1B] # kindexpr 槽总长(含 NUL padding),reshape 恒定,≤255
[kindexpr + 0x00 pad] # 合计 = kindexprlen;首字节 */@ 表 ref;扫到首个 NUL 止
[ro 1B]
[vid 4B LE]
[body_len 4B LE]
[body]
  • body_offset = kindexprlen + 10,恒定。
  • reshape:新 kindexpr ≤ kindexprlen → 原地覆盖 + NUL 补齐,body 不动;超出重编码扩槽。
  • 派生 getter(解析 kindexpr,不落盘):ref=首字节 *→1(软链接) / @→2(扩展句柄) / 无→0(内联);is_ptr=ref==1;ndim/dims=解析 [dims] 段;array_len=∏dims(ndim=0→1)。
  • def 侧 union 的 */@ 按 atom 分布(非仅首字符)。

已定决策

  1. kindexpr 字符串统一值侧(具体 atom)与定义侧(union)。
  2. is_ptr/array_len/ref/ndim/dims 全部并入 kindexpr,head 只留 kindexpr 串 + framing(ro/vid/body_len)。
  3. */@ 表 ref(0=内联 1=软链接 2=扩展句柄),首字节;def union 按 atom。
  4. ro/vid 保留独立字段(非类型信息)。
  5. kindexprlen 1B 定长(槽总长,非内容长),≤255。
  6. body_len 4B LE 定长。
  7. padding = NUL 尾缀(无独立长度字段),reshape 原地改写。
  8. kindkindexprtype_exprkindexpr(layout/runtime 全套改名)。
  9. oldhero 已归档,不碰。

波及面(开工顺序,自底向上)

  1. kvspace-durable/src/xvalue.rs:head 编解码重写 + kindexpr 解析 getter。
  2. kvspace-c:head 同步,tutorial/test.py 交叉校验 durable/c 字节一致。
  3. kvlang/layoutffi.rskvspaceHead_tkvkind.rsnew_rwir/new_rwfunc(删 \n 签名列表)、type_expr.rskindexpr.rs
  4. kvlang/runtimeruntime_internal.hkvspaceHead_tkvcpu.cload_def_reads/check_read_types(手拆 \n 简化)、type_expr.ckindexpr.c

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