Created
March 11, 2025 08:09
-
-
Save ClarkeRemy/e4eb9189c8e0d2e6daedba8b07bcecc6 to your computer and use it in GitHub Desktop.
Type Witness Prototype
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
use std::marker::PhantomData; | |
/// We limit the size of a node to u16::MAX. If you want bigger, make a tree or use a Tensor | |
pub type Mem = u16; | |
pub type Offset = usize; | |
type InternalHandleRepr = u32; | |
struct InternalHandle<T>{handle : InternalHandleRepr, _boo : PhantomData<T>} | |
pub type ExtHandleRepr = u64; | |
pub struct ExtHandle<T>{handle : ExtHandleRepr, _boo : PhantomData<T>} | |
pub struct ExtListHandle<T>{handle : ExtHandleRepr, len : Mem, _boo : PhantomData<T>} | |
#[repr(C)] | |
pub struct Layout { align : Mem, size : Mem } | |
#[repr(C)] | |
pub struct SumWitness { tag_offset : Mem /* derived from fields */, | |
layout : Layout /* derived from fields max align, plus tag in padding */, | |
fields : ExtListHandle<Type> | |
} | |
#[repr(C)] | |
pub struct ProductWitness { layout : Layout /* derived from fields */, | |
offset : ExtListHandle<Mem>, | |
fields : ExtListHandle<Type> | |
} | |
enum Rank { | |
Static(Mem), | |
Dynamic, | |
} | |
/// Rank::Static(0) has one element, it is the InternalHandle type | |
#[repr(C)] | |
pub struct TensorWitness{rank : Rank, type_ : ExtHandle<Type>} | |
/// primitive types are encoded with this type | |
#[repr(C)] | |
pub struct BytesWitness { layout : Layout } | |
pub enum Type { | |
Bytes(BytesWitness), | |
Sum(SumWitness), | |
Product(ProductWitness), | |
Tensor(TensorWitness), | |
} | |
/* | |
Tree (SumWitness<Tree> = 2 (0=Branch) (1=Leaf)) | |
Branch (ProductWitness<Branch> = 3 (val_offset val_type) (left_offset handle<Tree>) (right_offset handle<Tree>)) | |
tag val handle<Tree> handle<Tree> | |
Leaf (ProductWitness<Leaf> = 0 ) | |
tag | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment