preserve allowzero, align, volatile, and addrspace on pointer types#3172
Open
barry3406 wants to merge 1 commit intozigtools:masterfrom
Open
preserve allowzero, align, volatile, and addrspace on pointer types#3172barry3406 wants to merge 1 commit intozigtools:masterfrom
barry3406 wants to merge 1 commit intozigtools:masterfrom
Conversation
The `ptr_type` resolver in analysis.zig only read `const_token` from `ptr_info`, and `Data.createPointer` only set `is_const` on the `InternPool.pointer_type` flags. As a result, types like `*allowzero u8`, `*align(4) u8`, `*volatile u8` were collapsed to `*u8` in inlay hints (and any other surface that runs through `stringifyTypeOf`). Read `volatile_token`, `allowzero_token`, and the integer literal in `ast.align_node` from `ptr_info`, plumb them through `createPointerType` / `Data.createPointer` into the IP flags and the `.pointer` Data fallback, and update `rawStringify` so the fallback path matches the InternPool printer. Address-space resolution from arbitrary expressions still defers to `.generic`; only the literal alignment integer is read for now. Fixes zigtools#2603.
3cfe1a1 to
e2cfbe7
Compare
Techatrix
requested changes
Apr 21, 2026
| , .{ .kind = .Type }); | ||
| } | ||
|
|
||
| test "var decl - pointer modifiers" { |
Member
There was a problem hiding this comment.
These tests shouldn't need to go through inlay hints. Instead, add new tests to tests/analysis/pointer.zig which directly target the analysis backend without going through LSP requests.
Example:
diff --git a/tests/analysis/pointer.zig b/tests/analysis/pointer.zig
index 4086f8d4..5aa7acab 100644
--- a/tests/analysis/pointer.zig
+++ b/tests/analysis/pointer.zig
@@ -270,6 +270,9 @@ const ManyPointerWithSentinel = [*:.{}]addrspace(.generic) const packed struct {
// ^ (packed struct {})()
// ^^^^^^^^ (AddressSpace)()
+const VolatilePointer = *volatile u32;
+// ^^^^^^^^^^^^^^^ (type)(*volatile u32)
+
var runtime_index: usize = 5;
var runtime_u8: u8 = 1;
var runtime_i8: i8 = -1;
Comment on lines
3810
to
3817
| size: std.builtin.Type.Pointer.Size, | ||
| sentinel: InternPool.Index, | ||
| is_const: bool, | ||
| is_volatile: bool, | ||
| is_allowzero: bool, | ||
| alignment: u16, | ||
| address_space: std.builtin.AddressSpace, | ||
| elem_ty: Type, |
Member
There was a problem hiding this comment.
We already have a type that can store most pointer attributes. So the number of function parameters can be reduced here:
Suggested change
| size: std.builtin.Type.Pointer.Size, | |
| sentinel: InternPool.Index, | |
| is_const: bool, | |
| is_volatile: bool, | |
| is_allowzero: bool, | |
| alignment: u16, | |
| address_space: std.builtin.AddressSpace, | |
| elem_ty: Type, | |
| elem_ty: Type, | |
| sentinel: InternPool.Index, | |
| flags: InternPool.Key.Pointer.Flags, |
Comment on lines
+3204
to
+3208
| is_volatile: bool = false, | ||
| is_allowzero: bool = false, | ||
| /// `0` means default alignment. | ||
| alignment: u16 = 0, | ||
| address_space: std.builtin.AddressSpace = .generic, |
Member
There was a problem hiding this comment.
We already have a type that can store most pointer attributes.
elem_ty: *Type,
/// `.none` means no sentinel, `.unknown_unknown` means unknown sentinel
sentinel: InternPool.Index,
flags: InternPool.Key.Pointer.Flags,
Comment on lines
3312
to
3319
| size: std.builtin.Type.Pointer.Size, | ||
| sentinel: InternPool.Index, | ||
| is_const: bool, | ||
| is_volatile: bool, | ||
| is_allowzero: bool, | ||
| alignment: u16, | ||
| address_space: std.builtin.AddressSpace, | ||
| elem_ty: Type, |
Member
There was a problem hiding this comment.
We already have a type that can store most pointer attributes. So the number of function parameters can be reduced here:
Suggested change
| size: std.builtin.Type.Pointer.Size, | |
| sentinel: InternPool.Index, | |
| is_const: bool, | |
| is_volatile: bool, | |
| is_allowzero: bool, | |
| alignment: u16, | |
| address_space: std.builtin.AddressSpace, | |
| elem_ty: Type, | |
| elem_ty: Type, | |
| sentinel: InternPool.Index, | |
| flags: InternPool.Key.Pointer.Flags, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
ptr_typeresolver inanalysis.zigonly readconst_tokenfromptr_info, andData.createPointeronly setis_conston theInternPool.pointer_typeflags. So*allowzero u8,*align(4) u8,*volatile u8and friends all collapsed to*u8in inlay hints (and anywhere else that runs throughstringifyTypeOf).This reads
volatile_token,allowzero_token, and the literal integer inast.align_nodefromptr_info, plumbs them throughcreatePointerType/Data.createPointerinto the IP flags and the.pointerData fallback, and updatesrawStringifyso the fallback path matches the InternPool printer.Address-space resolution from arbitrary expressions still defers to
.generic; the field is plumbed through but only the literal alignment integer is currently read.Regression coverage added in
tests/lsp_features/inlay_hints.zig.Fixes #2603.