Skip to content

Explicitly forbid \x00 (null bytes) in @"" identifier syntax #8262

@andrewrk

Description

@andrewrk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions