Hello everyone! ![]()
Recently I published a proposal about the issue and design flaws of the current UnsafePointer interface. This document proposes a new interface for UnsafePointer and a potential migration path.
In short, the current API of UnsafePointer has two major issues:
- Allowing unsafe implicit conversions of mutability and origins.
- Haphazard parameters: including a non-inferred mutability and a defaulted origin of
(Imm/M)utableAnyOrigin.
The newly proposed interface for UnsafePointer is as follows:
struct UnsafePointerV2[
mut: Bool, # Inferred mutability
type: AnyType,
origin: Origin[mut], # Non-defaulted origin
*,
address_space: AddressSpace = AddressSpace.GENERIC,
]:
...
Along with this parameter fixing, the constructors will be updated to prevent implicit unsafe mutability casting and unsafe origin casting. (These can still be achieved, they just require explicit calls to unsafe_mut_cast and similar functions). This also brings the parameter interface in line with other pointer-like types, Span, LayoutTensor, etc…
Migration Options
The final part is the migration path/transition from the old interface to the new one.
The first option (which is outlined in the document) proposes a non-breaking solution that slowly deprecates and then eventually replaces the old type with the new v2 types.
The rough estimated timeline would look like this:
Nightly (current)
- Introduce
UnsafePointerV2and helpful aliases. - Begin migrating
stdliband kernel code.
25.7 (late November 2025)
- Mark
UnsafePointeras deprecated. - Promote
UnsafePointerV2for general use.
26.1 (Jan 2026)
- Remove old
UnsafePointer. - Rename
UnsafePointerV2→UnsafePointer. - Deprecate the temporary
UnsafePointerV2name.
This path theoretically provides a transition period over ~2 releases that doesn’t immediately break code, but rather will deprecate the type. The issue with this is the interim UnsafePointerV2 type. As this type will be the replacement for UnsafePointer in 25.7 — requiring people to move over to it — and then in 26.1, will be deprecated, requiring people to rename UnsafePointerV2 back to UnsafePointer.
The second tentative option (not outlined in the document) is as follows:
25.7 (late November 2025)
- Rename the current
UnsafePointertoLegacyUnsafePointer. - Add the new and improved
UnsafePointer.
26.1 (Jan 2026)
- Deprecate
LegacyUnsafePointerand eventually remove it.
This path has the downside of breaking current code that uses UnsafePointer when the rename/replacement happens, but has the upside of making a clean break in 25.7, moving all of the transition steps to a single release. This provides a way for people to simply “mass rename” all UnsafePointer instances to LegacyUnsafePointer (then devs can slowly move from LegacyUnsafePointer to the new UnsafePointer type over the next release or two) or devs can immediately update their usages to the new interface bypassing the legacy type entirely.
Asks from the community
We’re currently set on making the changes to UnsafePointer (fixing the implicit constructors, and fixing the parameters) — but it would be nice to know people’s thoughts on the migration path forward. Do people mind a breaking change or would you prefer the extended “deprecation” approach? Feel free to leave your comments/suggestions ![]()