-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Implement writeToMemory
/readFromMemory
for pointers
#11734
Conversation
Shoot, I shouldn't have missed the meeting 😅 Additionally, you aren't really saving any complexity. This code is still well defined: pub fn betterPtrToInt(comptime ptr: anytype) usize {
return @ptrCast(*const usize, &ptr).*;
} |
The things that can be done with
This can easily be made to have an error like test {
comptime var a = 1;
comptime @compileLog(betterPtrToInt(&a));
} |
This features should exist. There is no justification for removing it. |
I don't understand what you're trying to say. |
@Vexu if you wouldn't mind rebasing this and getting the CI checks passing, I'll prioritize accepting it / rejecting it. I'm leaning towards accepting it, and amending the spec, as long as it doesn't break any valuable use case. |
I confused myself on that one. I agree, in comptime it's hard to understand what compiler might come up with, so removing @ptrToInt for comptime variables makes sense to not allow "C hacks" in comptime. |
349d132
to
545478d
Compare
The current behavior of Whether this should be a compile error can be decided when solving #2471 as far as I'm concerned. |
@ptrToInt
on address of comptime variable an errorwriteToMemory
/readFromMemory
for pointers
545478d
to
d37746c
Compare
d37746c
to
72cd436
Compare
This is in direct contradiction to parts of #9646 and these two test cases https://github.com/ziglang/zig/blob/master/test/behavior/comptime_memory.zig#L319-L371.
As discussed in the self hosted compiler meetings the justification for this is change is that it seems like a lot of work for little value and making it an error also avoids the complications brought by comptime only types.
cc @SpexGuy
Closes #11211