Unified lists, arrays (and iterators/pipes?) ============================================ Problems with lists (vs arrays): 1. Can't be stored directly in strutcs/arrays (need a reference). 2. Types smaller than a pointer use extra space (i.e. byte, int16, sometimes int32, and on CHERI platforms even int64). 3. The length cannot be specified in the type system Solution to 1 & 2: Serialization -------------------------------- Fixed-size lists in structs could be stored in serialized form. For example, for this struct: struct { uint16 info List array uint16 trailer } It could be stored like this in memory: (on a 32-bit platform, but the technique works on 64-bit as well): uint16 info uint16 alignment_padding1 uint32 serialization_marker_and_type (type = immutable byte array) uint32 length (small lengths could be merged into the marker) byte value1 byte value2 byte value3 byte alignment_padding2 uint16 trailer Note: The serialization marker could include a mutability bit to allow for modification (but not size change) or serialized lists. Advantages: * Can be used where a reference to a list is expected (no copying needed). * Can be used in .rodata * Can be used for mutable but fixed-size lists. Disadvantages: * Can obviously only support fixed-size lists. * Uses up to two additional words + alignment padding before and after. (in the example, it is 8+2 = 10 additional bytes for a 3 byte array, on a 64-bit system it would have been 16+7 = 25 additional bytes. I.e. 4.3x vs 8.3x memory usage, but this is close to the worst case) * The serialization format of immutable-List is different from String. Note that String cannot have a fully compatible format, because it is not fixed size and it can additionally change size on element mutation (non-UTF-8 or NUL bytes in the beginning require a header with length etc). Solution to 3 ------------- Allow a type parameter to be: * Type only * Value only * Value+Type * ?Value+Type or Usage syntax: Cache BitArray<3> List List<3 byte> List Definition syntax with support for usize only: (should booleans, enums and signed integers be allowed?) type Cache type BitArray type List Problem: Confusing when some types can be used without "ref" ------------------------------------------------------------ It could be confusing that List can be placed directly in a struct/array, but List or "OtherType" or "PrivateType" can't. Solutions: * Automatically add "ref" if needed? * Support serialization on user-defined types? * Make List a fully built-in type and call it (along with string) by a lower-case name?