-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Some object formats, such as ELF, rely on null bytes to terminate strings, making it impossible to represent symbol names which contain null bytes. So there already exist at least some targets for which this must be rejected. This proposal is to unconditionally reject null bytes in identifiers for all targets.
Additionally, third party tools which attempt to integrate with Zig code or the Zig compiler may want to use null terminated strings in order to represent identifier names. By explicitly making it illegal to have null bytes in @"" identifier strings, this prevents possible bugs in the wild having to do with analysis of Zig code.
If this is accepted, it means the self-hosted compiler can sometimes use null termination to save bytes of memory in ZIR. For example an enum literal or field access could be a u32 index into a string table, rather than a index and a length. When the shrinkage from 8 bytes to 4 bytes allows an instruction to fit inside the 8 bytes allocated for every IR instruction rather than indexing into an extra_data array, this ends up saving an additional 4 bytes, for a total saving of 8 bytes per relevant instruction.