feat(types): DType carries its KClass witness; dtype-first storage constructors and loaders (SKEEP-003 P0, S0.2a) - #1050
Merged
Conversation
…nstructors and loaders (SKEEP-003 P0) Decision #13 merges LogicalDType into one sealed DType. Second step (milestone M0, #1001): DType becomes self-describing and every storage descriptor can be built from it, additively. - DType: witness: KClass<out DType> (each of the 14 objects narrows to its own class), isSigned (false for UInt*), sizeInBytes; companion entries (storage-layer order, index-aligned with LogicalDType.entries), fromWitness / fromWitnessOrNull (identity-keyed, no name-based reflection). Companion collections are lazy: with default members on the interface, initializing an object also initializes the interface statics on the JVM, and an eager map would capture a half-initialized object (class-init cycle). - Additive dtype-first API (primary constructors unchanged): TensorStorage(shape, dtype, encoding, buffer, ...), TensorStorageFactory.fromRawBytes / fromRawBytesOwned / fileBacked (dtype overloads), PackedBlockStorage.toTensorStorage(dtype, ...); toTensorData dispatches on storage.dtype with identical semantics. - Internal call sites moved to DType: TensorStorageFactory fromFloatArray/fromIntArray, DefaultKvCacheStore, TurboQuantKvCacheStore, StreamingGGUFReader (ggmlTypeToDType; quantized -> FP32, Opaque fallback kept), StreamingSafeTensorsReader (BOOL -> UInt8, UNKNOWN -> Int8 kept). - Tests: DTypeWitnessTest; dtype twins in TensorStorageContractTest; StorageIntegrationTest asserts storage.dtype === FP32 for F32 and Q8_0. - BCV: lang-core jvm dump regenerated (additions only). Closes #1007 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Local gate Targeted: lang-core |
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
aharakal
approved these changes
Aug 22, 2026
This was referenced Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SKEEP-003 slice S0.2a (milestone M0 #1001, decision #13 — merge
LogicalDTypeinto one sealedDType):DTypecarries its own witness, and every storage descriptor / loader can be built from aDTypeinstead of aLogicalDType. Purely additive;LogicalDTypeis untouched (its deprecation is the separate slice #1014).sk.ainet.lang.types.DType:witness: KClass<out DType>(each of the 14 objects narrows to its own class, e.g.FP32.witness: KClass<FP32>),isSigned(false only forUInt*),sizeInBytes, companionentries(storage-layer order, index-aligned withLogicalDType.entries),fromWitness(kclass)/fromWitnessOrNull(kclass)(identity-keyed map — no name-based reflection, JS/Wasm-safe).fromWitness(tensor.dtype)is how M0'sFormatslice turns aTensor.dtypeinto aDType.TensorStorage(shape, dtype, encoding, buffer, …),TensorStorageFactory.fromRawBytes / fromRawBytesOwned / fileBacked(… dtype: DType …),PackedBlockStorage.toTensorStorage(dtype, …);toTensorDatadispatches onstorage.dtypewith identical semantics.DType:TensorStorageFactory.fromFloatArray/fromIntArray,DefaultKvCacheStore,TurboQuantKvCacheStore,StreamingGGUFReader(ggmlTypeToDType; quantized →FP32,Opaquefallback kept),StreamingSafeTensorsReader(BOOL → UInt8,UNKNOWN → Int8kept).DTypeWitnessTest(entries/order, witness identity,fromWitnessinverse + rejection, signedness/width vs the storage enum, enum-likewhen), dtype twins inTensorStorageContractTest,StorageIntegrationTestassertsstorage.dtype === FP32for F32 and Q8_0 GGUF tensors.Test plan
Full local gate (
scripts/pr-gate.sh, JDK 25) +--golden; results in the first comment.Closes #1007
🤖 Generated with Claude Code