Skip to content

[S0.2a] P0: DType carries its witness (DType.witness, fromWitness, entries); descriptors/readers report DType additively #1007

Closed

Description

@michalharakal

Sub-issue of #1001 · Phase P0 · Milestone M0 · PRD: M0-A3 (enabler) · Proposal: §0 DType, §10 decision #13
Branch: feature/1007-dtype-witness

Design docs: docs/design/memory/memory-architecture-proposal.md (proposal rev. 2, §-numbers below refer to it) and docs/design/memory/memory-architecture-milestones-prd.md (PRD, requirement IDs Mx-Fy/Mx-Ay) — both land with the SKEEP-003 docs PR; until merged they are attached to #932.

Task

  • sk.ainet.lang.types.DType: val witness: KClass<out DType> (each of the 14 objects narrows, e.g. FP32.witness: KClass<FP32>), val isSigned (default true, false on UInt*), val sizeInBytes; companion @JvmStatic fromWitness(kclass) (identity-keyed map — no name-based reflection, JS/wasm safe), entries (LogicalDType order). Do not reuse DType.kotlinClass() (value KClass).
  • Additive dtype: DType secondary constructors / overloads: TensorStorage, TensorStorageFactory (fromRawBytes, fromRawBytesOwned, fileBacked; toTensorData dispatches on DType with identical semantics), PackedBlockStorage (dtype = FP32 overload), DefaultKvCacheStore/TurboQuantKvCacheStore construct via the dtype ctor.
  • Readers: StreamingGGUFReader.ggmlTypeToDType() (quantized → FP32, Opaque fallback kept), StreamingSafeTensorsReader (BOOL→UInt8, UNKNOWN→Int8 kept).
  • Tests: DTypeWitnessTest; dtype twins in TensorStorageContractTest; io StorageIntegrationTest asserts assertSame(FP32, storage.dtype) for Q4_K.

Acceptance

  • All existing storage/io tests unchanged and green; new tests green on JVM + linuxX64 + js/wasm; apiCheck on lang-core, lang-dag, lang-models, backend-cpu, compile-* clean after dump.

Depends on

#1006 (S0.1).

Keeps develop green by

Secondary ctors/overloads only; primary ctors and toString() texts untouched; no deprecations yet (that is #1014 (S0.2b)).

Working rules (every slice)

  • One slice = one branch feature/1007-<slug> from develop = one PR (Closes #1007), merged independently.
  • develop stays usable after merge: additive API or behind façade / opt-in; no default behaviour switch without golden-parity + benchmark evidence in the PR; deprecate with ReplaceWith, never delete before a major (zero-consumer dead code may be removed with evidence in the PR). No new abstract members on TensorData/KernelProvider (defaults only); no data-class primary-constructor changes (secondary ctors only); BCV: apiDump both api/jvm and api/android, apiCheck clean.
  • Test gate before the PR (JDK 25, scripts/pr-gate.sh once it exists): ./gradlew jvmTest linuxX64Test assemble, ./gradlew verifyNpmPins jsTest wasmJsTest wasmWasiTest, ./gradlew apiCheck, ./gradlew :skainet-test:skainet-test-java:test; storage/backend slices add :skainet-lang:skainet-lang-core:jvmBenchmark and :skainet-backends:benchmarks:jvm-cpu-jmh:jmh before/after when a hot path changes.
  • Commits: conventional commit subject, Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> trailer. Do not edit CHANGELOG.md in slice PRs (parallel branches conflict on it; release notes are written at release time from the merged PRs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    codingImplementation task (DARC: C)file-format:ggufGGUF file formatfile-format:safetensorsSafeTensors file formatsub-issueSub-issue of a tracking issuetensorsTensor operations and data structures

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions