Update std to use pointer subtraction when appropriate
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.
I also aim to generally reduce unnecessary @intFromPtr usage or to at least use alternative methods at comptime where appropriate
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 zig build update-zig1. Feel free to re-open this PR and I can commit a zig1 update for you (a Zig core team member has to be the one to commit those updates for security reasons).
zig1.wasm isn't manually written! It's a WASM binary which can be generated by running
zig build update-zig1. Feel free to re-open this PR and I can commit a zig1 update for you (a Zig core team member has to be the one to commit those updates for security reasons).
Thank you, that would be perfect. Sorry for the misunderstanding
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 heap.zig, where I provide a comptime implementation of sliceContainsPtr and sliceContainsSlice, making FixedBufferAllocator comptime available. Due to a lack of pointer comparison, the comptime solution had to be implemented with a loop, giving it an O(n) time complexity.
Sorry, it bitrotted before I got around to it.