Casts between usize and u64
When converting between an index or length in-memory and a value saved in a file, is the cast safe?
Should we enforce usize == u64 or usize >= u64? Would the program work in 32-bit mode?
- [ ] Code tag
#0015
Suggestion:
- only support
usize >= 32(add assert) - add asserts wherever converting between different sizes; for most usage limits of 32-bit
usizewill not be exceeded
Note: usize is used for the number of elements per partition, but we only support 2^24 elements. usize is used for element data length, but format is far from ideal if data segments are gigabytes long. usize is also used for the number of changes in a commit (depends on application, but probably < 100).
Note: some sizes are restricted to 32-bits in file format already; probably all uses of usize could be restricted to 32-bits.
Explicit integer casts: This is precisely because of a point you note slightly further down - that narrowing casts can cause difficult-to-diagnose bugs. With type inference on top of that you'll get serious problems. A way to force the panicking semantics you want is to use some_val.try_into().unwrap(), which is noisier than some_val as _ but makes it explicit.