Skip to content

std.builtin.Type: renames #22496

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

Closed
wants to merge 7 commits into from
Closed

Conversation

mlugg
Copy link
Member

@mlugg mlugg commented Jan 15, 2025

See commit messages. In brief:

  • Rename field std.builtin.Type.Pointer.sentinel to sentinel_ptr
  • Rename field std.builtin.Type.Array.sentinel to sentinel_ptr
  • Rename field std.builtin.Type.StructField.default_value to default_value_ptr
  • Add helper method std.builtin.Type.Pointer.sentinel
  • Add helper method std.builtin.Type.Array.sentinel
  • Add helper method std.builtin.Type.StructField.defaultValue
  • Lowercase fields of std.builtin.Type.Pointer.Size

This is a breaking change. Note that the 0.14.0 release cycle has already had a major breaking change which affects all uses of std.builtin.Type: #21225.

@mlugg mlugg added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. labels Jan 15, 2025
@mlugg mlugg force-pushed the builtin-type-changes branch from c4a5a98 to f9de2ce Compare January 15, 2025 20:17
mlugg added 6 commits January 16, 2025 09:34
The commit 2 after this will explain this diff.
Implementing the changes from the prior commit, to prepare for the
following commit.

Signed-off-by: mlugg <[email protected]>
For representing struct field default values and array/pointer type
sentinel values, we use `*const anyopaque`, since there is no way for
`std.builtin.Type.StructField` etc to refer back to its `type` field.
However, when introspecting a type, this is quite awkward due to the
pointer casts necessary.

As such, this commit renames the `sentinel` fields to `sentinel_ptr`,
and the `default_value` field to `default_value_ptr`, and introduces
helper methods `sentinel()` and `defaultValue()` to load the values.
These methods are marked as `inline` because their return value, which
is always comptime-known, is very often required at comptime by use
sites, so this avoids having to annotate such calls with `comptime`.

This is a breaking change, although note that 0.14.0 is already a
breaking release for all users of `std.builtin.Type` due to the union
fields being renamed.
This matches established naming conventions. Now is an opportune time to
make this change, since we're already performing breaking changes to
`std.builtin.Type`.
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
@mlugg mlugg force-pushed the builtin-type-changes branch from f9de2ce to dfdf03e Compare January 16, 2025 09:48
I missed a few things before.
@mlugg mlugg removed breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. labels Jan 16, 2025
@mlugg
Copy link
Member Author

mlugg commented Jan 16, 2025

Removing labels to avoid confusion; this is superceded by #22505.

@mlugg mlugg closed this Jan 16, 2025
@mlugg mlugg deleted the builtin-type-changes branch May 18, 2025 20:00
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.

1 participant