-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Update std to use pointer subtraction when appropriate #20712
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
base: master
Are you sure you want to change the base?
Conversation
I also aim to generally reduce unnecessary |
Closing for now as I realize that I am not well versed enough in wasm to make the zig1 changes necessary for bootstrapping zig with pointer subtraction in the standard library |
zig1.wasm isn't manually written! It's a WASM binary which can be generated by running |
Thank you, that would be perfect. Sorry for the misunderstanding |
Updated `removeByPtr` to use pointer subtraction
Make pointer subtraction less ambiguous in `removeByPtr` by casting the left hand side to a multi item pointer
Reverted previous commit which casted the left hand side of the pointer subtraction in `removeByPtr` to a multi item pointer
Use pointer subtraction, and provide a comptime implementation of `sliceContainsPtr` and `sliceContainsSlice`, making `FixedBufferAllocator` usable in comptime
Use pointer subtraction instead of `@intFromPtr` value subtraction when appropriate (Incidentally eliminates all usage of `@intFromPtr` in net.zig)
Rework some pointer arithmetic, make use of pointer subtraction
Rework some pointer arithmetic, reduce usage of `@intFromPtr`
Reworked pointer logic, reducing usage of `@intFromPtr`
Reworked pointer arithmetic to reduce usage of `@intFromPtr`
Altered todo comments in `sliceContainsPtr` and `sliceContainsSlice` to be more clear about the goal of a comptime available constant time implementation
This has covered pretty much all of the obvious pointer subtraction cases I could find on a cursory look of the standard library. Given that this PR is just for the cases in the standard library and not the compiler, I will be submitting this for review. The one bit of code I've added here that I'm iffy on, is in |
In many placed in std, there are a few instances where we take the results of two
@intFromPtr
values and subtract them to perform pointer subtraction, which is now unnecessary (and suboptimal given@intFromPtr
is not usable at comptime) with the addition of pointer subtraction as a language feature in #20089. This PR aims to replace instances of@intFromPtr
subtraction with pointer subtraction.