aboutsummaryrefslogtreecommitdiff
path: root/src/Sema/comptime_ptr_access.zig
diff options
context:
space:
mode:
authorDavid Rubin <daviru007@icloud.com>2024-08-11 19:28:42 -0700
committerDavid Rubin <daviru007@icloud.com>2024-08-25 15:16:46 -0700
commit80cd53d3bbf5cdc82715a4400592b40fb93cd5c9 (patch)
tree5f12824c1173b4a2fc9cc78f39a0226419a18f54 /src/Sema/comptime_ptr_access.zig
parentb4bb64ce78bf2dee9437f366a362ef4d8c77b204 (diff)
downloadzig-80cd53d3bbf5cdc82715a4400592b40fb93cd5c9.tar.gz
zig-80cd53d3bbf5cdc82715a4400592b40fb93cd5c9.zip
sema: clean-up `{union,struct}FieldAlignment` and friends
My main gripes with this design were that it was incorrectly namespaced, the naming was inconsistent and a bit wrong (`fooAlign` vs `fooAlignment`). This commit moves all the logic from `PerThread.zig` to use the zcu + tid system that the previous couple commits introduce. I've organized and merged the functions to be a bit more specific to their own purpose. - `fieldAlignment` takes a struct or union type, an index, and a Zcu (or the Sema version which takes a Pt), and gives you the alignment of the field at the index. - `structFieldAlignment` takes the field type itself, and provides the logic to handle special cases, such as externs. A design goal I had in mind was to avoid using the word 'struct' in the function name, when it worked for things that aren't structs, such as unions.
Diffstat (limited to 'src/Sema/comptime_ptr_access.zig')
-rw-r--r--src/Sema/comptime_ptr_access.zig4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/Sema/comptime_ptr_access.zig b/src/Sema/comptime_ptr_access.zig
index 8549e32d2b..893ea6db36 100644
--- a/src/Sema/comptime_ptr_access.zig
+++ b/src/Sema/comptime_ptr_access.zig
@@ -451,7 +451,7 @@ fn loadComptimePtrInner(
.@"packed" => break, // let the bitcast logic handle this
.@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
const start_off = cur_ty.structFieldOffset(field_idx, zcu);
- const end_off = start_off + try cur_ty.structFieldType(field_idx, zcu).abiSizeSema(pt);
+ const end_off = start_off + try cur_ty.fieldType(field_idx, zcu).abiSizeSema(pt);
if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
cur_val = try cur_val.getElem(sema.pt, field_idx);
cur_offset -= start_off;
@@ -873,7 +873,7 @@ fn prepareComptimePtrStore(
.@"packed" => break, // let the bitcast logic handle this
.@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
const start_off = cur_ty.structFieldOffset(field_idx, zcu);
- const end_off = start_off + try cur_ty.structFieldType(field_idx, zcu).abiSizeSema(pt);
+ const end_off = start_off + try cur_ty.fieldType(field_idx, zcu).abiSizeSema(pt);
if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
cur_val = try cur_val.elem(pt, sema.arena, field_idx);
cur_offset -= start_off;