Skip to content

Conversation

ritoban23
Copy link

[stdlib][refactor] Remove UnsafePointer.offset method

This PR removes the deprecated UnsafePointer.offset() method from the Mojo standard library and replaces all usages with pointer arithmetic (ptr + n) or direct dereferencing (ptr[n]), as appropriate.

Key changes:

  • Removed UnsafePointer.offset() from the stdlib.
  • Replaced all usages of .offset() with + operator or [] indexing.
  • Updated affected modules, tests, and documentation.
  • No functional changes; all existing tests pass (except for unrelated infra issues).

Closes #5175.

@ritoban23 ritoban23 requested review from a team and ehein6 as code owners August 14, 2025 18:01
Copy link

github-actions bot commented Aug 14, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ritoban23
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

- Replace .offset() with + operator in int_tuple.mojo memcpy calls
- Replace .offset() with + operator in layout_tensor.mojo load/store operations
- Replace .offset() with + operator in bench_elementwise.mojo strided_load calls

These changes address the CI compilation errors after removing the offset method.
@ritoban23 ritoban23 force-pushed the remove-offset-method branch from c4a6988 to 6d8a93e Compare August 14, 2025 19:13
@ritoban23 ritoban23 requested a review from a team as a code owner August 14, 2025 19:13
modular-cla-bot bot added a commit to modular/cla that referenced this pull request Aug 14, 2025
@ritoban23 ritoban23 marked this pull request as draft August 14, 2025 20:05
- Replace all .offset() method calls with + operator across entire max/kernels directory
- Apply systematic sed replacements to convert pointer arithmetic patterns
- Handle various pointer variable names: ptr, data, src_ptr, dst_ptr, etc.
- Fix patterns in source files, test files, and benchmark files
- This completes comprehensive removal of deprecated .offset() method usage
- Fix patterns like 'ptr + (expr).load[' to '(ptr + expr).load['
- Fix patterns like 'ptr + (expr).store[' to '(ptr + expr).store['
- Correct broken pointer arithmetic expressions in:
  * _multistage_gemm_gpu.mojo
  * dual_gemm.mojo
  * matmul_amd.mojo
  * matmul_i8mm.mojo
  * matmul_vnni.mojo
  * conv.mojo
  * qmatmul.mojo
  * qmatmul_gpu.mojo
  * test files
- Ensure proper precedence for pointer arithmetic operations
- Fixes compilation errors: 'Int' value has no attribute 'load/store/bitcast'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[refactoring][stdlib] Remove UnsafePointer.offset method
2 participants