Description
Whilst working on #19630, it was suggested by @andrewrk to introduce the semantic rule that when loading a value from a pointer, if any bits are undefined
, the entire value is considered to be undefined
. This rule simplifies the language considerably, because it avoids the need to deal with the awkward concept of a comptime-known value with some undefined bits. However, it causes breakages in some code.
The main example I've noticed is std.PackedIntArray
, which uses a backing buffer to store a sequence of integer values bit-packed in memory. The problem is that if we initialize the buffer to undefined
, any load which crosses a boundary onto an adjacent element -- even if the element being loaded was set previously -- is considered undefined
. Thus, the only way to obey the new semantics is to always @memset
the buffer on creation, which is potentially wasteful.
This issue serves to track this design complexity and potential solutions to it. The example I brought up above could potentially be solved with runtime bit-pointers (related: #16271), but I can't say for sure whether that would solve all potential problems.
For now, this rule is never enforced at runtime, only at comptime. Workarounds have been placed in the standard library where necessary behind @inComptime()
checks (such checks link to this issue).