std::memLow-level memory primitives (compiler-internal floor).
std::mem is the memory-intrinsic floor: the general-purpose heap
allocator and typed-pointer primitives that the generic containers
(Vec/HashMap/… in later waves) are built on top of.
These functions are declared as bodyless #[intrinsic("mem.*")] stubs:
the compiler supplies their semantics directly (the stdlib catalog row
provides the lowering). alloc/realloc/dealloc lower to calls of the
hew-runtime allocator (hew_alloc/hew_realloc/hew_dealloc, wrapping
std::alloc with a Layout::from_size_align floor); ptr_offset lowers
to a byte-level LLVM GEP and ptr_copy to @llvm.memcpy.
Every function here is an unsafe primitive and is compiler-internal
only. The #[intrinsic] surface is gated: only this floor module
(std.mem, on the INTRINSIC_FLOOR_MODULES allowlist) may declare or
call them. User code can never reach these — there is no surface
unsafe/@unsafe, and the typecheck gate rejects any #[intrinsic]
declaration outside an allowlisted floor module. They carry no bounds,
lifetime, or aliasing checks; correctness is the caller's obligation,
and the only callers are the compiler-authored containers.
alloc(size, align) / realloc(..) return a null pointer on an
invalid layout (zero/non-power-of-two/overflowing (size, align));
genuine out-of-memory aborts in the runtime. Every alloc must be
paired with exactly one dealloc carrying the same (size, align).dealloc with the matching (size, align) frees the block; passing a
mismatched layout is a compiler bug and aborts in the runtime.allocAllocate size bytes aligned to align. Returns a null pointer if the
(size, align) layout is invalid; aborts on genuine OOM. Pair with
dealloc carrying the same (size, align).
reallocResize the block at ptr (currently old_size bytes, align) to
new_size bytes, preserving the leading min(old_size, new_size) bytes.
Returns a null pointer if the new layout is invalid (the old block is left
intact); aborts on genuine OOM. A null ptr is treated as a fresh
alloc(new_size, align).
deallocFree the block at ptr, which must have been produced by alloc/realloc
with the same (size, align). A mismatched layout aborts in the runtime.
ptr_offsetReturn ptr.add(byte_offset) — byte-level pointer arithmetic with the same
contract as Rust's <*mut T>::add (A612: byte-level monomorphic, no
element-type scaling here; the caller has already multiplied by the element
size). Lowers to an inbounds GEP, so the resulting pointer must stay
within the bounds of the same allocation ptr points into — pointing one
byte past the end of that allocation is permitted, but any other
out-of-allocation or wrapping offset is undefined behaviour. Pure
arithmetic; no load or store. Cross-allocation or wrapping offsets are a
distinct future primitive and are intentionally not provided here (YAGNI).
ptr_copyCopy byte_count bytes from src to dst (raw memcpy; the regions must
not overlap). Byte-level monomorphic (A612): the caller has already
multiplied the element count by the element size. No bounds checking.