zig icon indicating copy to clipboard operation
zig copied to clipboard

Noalias should be allowed on slice parameters

Open SpexGuy opened this issue 4 years ago • 3 comments
trafficstars

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.

SpexGuy avatar Jan 10 '21 16:01 SpexGuy

see here for downsides.

matu3ba avatar Jan 26 '21 20:01 matu3ba

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.

adworacz avatar May 18 '24 14:05 adworacz

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?

adworacz avatar May 18 '24 22:05 adworacz