Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noalias should be allowed on slice parameters #7742

Open
SpexGuy opened this issue Jan 10, 2021 · 3 comments
Open

Noalias should be allowed on slice parameters #7742

SpexGuy opened this issue Jan 10, 2021 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@SpexGuy
Copy link
Contributor

SpexGuy commented Jan 10, 2021

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 SpexGuy changed the title Noalias is not allowed on slice parameters Noalias should be allowed on slice parameters Jan 10, 2021
@Vexu Vexu added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Jan 26, 2021
@Vexu Vexu added this to the 0.8.0 milestone Jan 26, 2021
@Vexu Vexu added the accepted This proposal is planned. label Jan 26, 2021
@matu3ba
Copy link
Contributor

matu3ba commented Jan 26, 2021

see here for downsides.

@Vexu Vexu added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed accepted This proposal is planned. labels Jan 26, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@adworacz
Copy link
Sponsor

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
Copy link
Sponsor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

5 participants