zig
zig copied to clipboard
Noalias should be allowed on slice parameters
Noalias is currently disallowed on slice parameters. This limitation means that I need to split slices into ptr + len parameters when noalias is important to specify, which is inconvenient. If the inner function doesn't actually need the length, my code becomes less safe because it doesn't have bounds checks anymore in debug mode. #1108 does not solve this, because the opposite problem exists if mayalias is disallowed on slice parameters.
I don't think there are any significant downsides to allowing this, the intent is clear.
see here for downsides.
Adding a +1 here, and also hoping that an array of slices (like [3][]const u8) can be specified as noalias. I often use an array of slices to ship groups of pointers around, and all slices should be considered noalias.
If there was some kind of workaround with assert that we could use to hint to the compiler that the slices don't overlap, that would be great in the meantime.
Actually... I just checked, and it appears that using noalias on a slice is working!
Godbolt proof: https://zig.godbolt.org/z/P18P59E7d
Simply add and remove the 'noalias' keyword from the foo2 function parameter, and you can see the output change. The LLVM IR contains references to declare void @llvm.experimental.noalias.scope.decl as well.
So this might already be solved, at least in some cases?