authorgravatar for exonorid@gmail.comExonorid <exonorid@gmail.com> 2021-06-10 13:56:55-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-12 19:16:01+03:00
logf63338195da893bf3f50326fc69c1801182ebe80
tree4664ad2a53c23be168462cb0364e2ac0f72e2f45
parent2ba68f9f4c1de8677db35851cf9e019be132d65b

Renamed @byteOffsetOf to @offsetOf


19 files changed, 114 insertions(+), 114 deletions(-)

doc/langref.html.in+7-7
......@@ -2715,7 +2715,7 @@ test "pointer to non-bit-aligned field" {
27152715}
27162716 {#code_end#}
27172717 <p>
2718 This can be observed with {#link|@bitOffsetOf#} and {#link|byteOffsetOf#}:
2718 This can be observed with {#link|@bitOffsetOf#} and {#link|offsetOf#}:
27192719 </p>
27202720 {#code_begin|test#}
27212721const std = @import("std");
......@@ -2733,9 +2733,9 @@ test "pointer to non-bit-aligned field" {
27332733 try expect(@bitOffsetOf(BitField, "b") == 3);
27342734 try expect(@bitOffsetOf(BitField, "c") == 6);
27352735
2736 try expect(@byteOffsetOf(BitField, "a") == 0);
2737 try expect(@byteOffsetOf(BitField, "b") == 0);
2738 try expect(@byteOffsetOf(BitField, "c") == 0);
2736 try expect(@offsetOf(BitField, "a") == 0);
2737 try expect(@offsetOf(BitField, "b") == 0);
2738 try expect(@offsetOf(BitField, "c") == 0);
27392739 }
27402740}
27412741 {#code_end#}
......@@ -7026,7 +7026,7 @@ fn func(y: *i32) void {
70267026 For packed structs, non-byte-aligned fields will share a byte offset, but they will have different
70277027 bit offsets.
70287028 </p>
7029 {#see_also|@byteOffsetOf#}
7029 {#see_also|@offsetOf#}
70307030 {#header_close#}
70317031
70327032 {#header_open|@boolToInt#}
......@@ -7106,8 +7106,8 @@ fn func(y: *i32) void {
71067106 </p>
71077107 {#header_close#}
71087108
7109 {#header_open|@byteOffsetOf#}
7110 <pre>{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
7109 {#header_open|@offsetOf#}
7110 <pre>{#syntax#}@offsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
71117111 <p>
71127112 Returns the byte offset of a field relative to its containing struct.
71137113 </p>
lib/std/os/bits/darwin.zig+13-13
......@@ -188,12 +188,12 @@ pub const Kevent = extern struct {
188188// to make sure the struct is laid out the same. These values were
189189// produced from C code using the offsetof macro.
190190comptime {
191 assert(@byteOffsetOf(Kevent, "ident") == 0);
192 assert(@byteOffsetOf(Kevent, "filter") == 8);
193 assert(@byteOffsetOf(Kevent, "flags") == 10);
194 assert(@byteOffsetOf(Kevent, "fflags") == 12);
195 assert(@byteOffsetOf(Kevent, "data") == 16);
196 assert(@byteOffsetOf(Kevent, "udata") == 24);
191 assert(@offsetOf(Kevent, "ident") == 0);
192 assert(@offsetOf(Kevent, "filter") == 8);
193 assert(@offsetOf(Kevent, "flags") == 10);
194 assert(@offsetOf(Kevent, "fflags") == 12);
195 assert(@offsetOf(Kevent, "data") == 16);
196 assert(@offsetOf(Kevent, "udata") == 24);
197197}
198198
199199pub const kevent64_s = extern struct {
......@@ -210,13 +210,13 @@ pub const kevent64_s = extern struct {
210210// to make sure the struct is laid out the same. These values were
211211// produced from C code using the offsetof macro.
212212comptime {
213 assert(@byteOffsetOf(kevent64_s, "ident") == 0);
214 assert(@byteOffsetOf(kevent64_s, "filter") == 8);
215 assert(@byteOffsetOf(kevent64_s, "flags") == 10);
216 assert(@byteOffsetOf(kevent64_s, "fflags") == 12);
217 assert(@byteOffsetOf(kevent64_s, "data") == 16);
218 assert(@byteOffsetOf(kevent64_s, "udata") == 24);
219 assert(@byteOffsetOf(kevent64_s, "ext") == 32);
213 assert(@offsetOf(kevent64_s, "ident") == 0);
214 assert(@offsetOf(kevent64_s, "filter") == 8);
215 assert(@offsetOf(kevent64_s, "flags") == 10);
216 assert(@offsetOf(kevent64_s, "fflags") == 12);
217 assert(@offsetOf(kevent64_s, "data") == 16);
218 assert(@offsetOf(kevent64_s, "udata") == 24);
219 assert(@offsetOf(kevent64_s, "ext") == 32);
220220}
221221
222222pub const mach_port_t = c_uint;
lib/std/os/bits/dragonfly.zig+1-1
......@@ -360,7 +360,7 @@ pub const dirent = extern struct {
360360 d_name: [256]u8,
361361
362362 pub fn reclen(self: dirent) u16 {
363 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
363 return (@offsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
364364 }
365365};
366366
src/AstGen.zig+2-2
......@@ -2027,7 +2027,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) Inner
20272027 .shl_exact,
20282028 .shr_exact,
20292029 .bit_offset_of,
2030 .byte_offset_of,
2030 .offset_of,
20312031 .cmpxchg_strong,
20322032 .cmpxchg_weak,
20332033 .splat,
......@@ -6816,7 +6816,7 @@ fn builtinCall(
68166816 .shr_exact => return shiftOp(gz, scope, rl, node, params[0], params[1], .shr_exact),
68176817
68186818 .bit_offset_of => return offsetOf(gz, scope, rl, node, params[0], params[1], .bit_offset_of),
6819 .byte_offset_of => return offsetOf(gz, scope, rl, node, params[0], params[1], .byte_offset_of),
6819 .offset_of => return offsetOf(gz, scope, rl, node, params[0], params[1], .offset_of),
68206820
68216821 .c_undef => return simpleCBuiltin(gz, scope, rl, node, params[0], .c_undef),
68226822 .c_include => return simpleCBuiltin(gz, scope, rl, node, params[0], .c_include),
src/BuiltinFn.zig+3-3
......@@ -17,7 +17,7 @@ pub const Tag = enum {
1717 mul_add,
1818 byte_swap,
1919 bit_reverse,
20 byte_offset_of,
20 offset_of,
2121 call,
2222 c_define,
2323 c_import,
......@@ -235,9 +235,9 @@ pub const list = list: {
235235 },
236236 },
237237 .{
238 "@byteOffsetOf",
238 "@offsetOf",
239239 .{
240 .tag = .byte_offset_of,
240 .tag = .offset_of,
241241 .param_count = 2,
242242 },
243243 },
src/Sema.zig+3-3
......@@ -322,7 +322,7 @@ pub fn analyzeBody(
322322 .shl_exact => try sema.zirShlExact(block, inst),
323323 .shr_exact => try sema.zirShrExact(block, inst),
324324 .bit_offset_of => try sema.zirBitOffsetOf(block, inst),
325 .byte_offset_of => try sema.zirByteOffsetOf(block, inst),
325 .offset_of => try sema.zirOffsetOf(block, inst),
326326 .cmpxchg_strong => try sema.zirCmpxchg(block, inst),
327327 .cmpxchg_weak => try sema.zirCmpxchg(block, inst),
328328 .splat => try sema.zirSplat(block, inst),
......@@ -5860,10 +5860,10 @@ fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
58605860 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
58615861}
58625862
5863fn zirByteOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5863fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
58645864 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58655865 const src = inst_data.src();
5866 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteOffsetOf", .{});
5866 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
58675867}
58685868
58695869fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
src/Zir.zig+5-5
......@@ -859,9 +859,9 @@ pub const Inst = struct {
859859 /// Implements the `@bitOffsetOf` builtin.
860860 /// Uses the `pl_node` union field with payload `Bin`.
861861 bit_offset_of,
862 /// Implements the `@byteOffsetOf` builtin.
862 /// Implements the `@offsetOf` builtin.
863863 /// Uses the `pl_node` union field with payload `Bin`.
864 byte_offset_of,
864 offset_of,
865865 /// Implements the `@cmpxchgStrong` builtin.
866866 /// Uses the `pl_node` union field with payload `Cmpxchg`.
867867 cmpxchg_strong,
......@@ -1166,7 +1166,7 @@ pub const Inst = struct {
11661166 .shl_exact,
11671167 .shr_exact,
11681168 .bit_offset_of,
1169 .byte_offset_of,
1169 .offset_of,
11701170 .cmpxchg_strong,
11711171 .cmpxchg_weak,
11721172 .splat,
......@@ -1436,7 +1436,7 @@ pub const Inst = struct {
14361436 .shr_exact = .pl_node,
14371437
14381438 .bit_offset_of = .pl_node,
1439 .byte_offset_of = .pl_node,
1439 .offset_of = .pl_node,
14401440 .cmpxchg_strong = .pl_node,
14411441 .cmpxchg_weak = .pl_node,
14421442 .splat = .pl_node,
......@@ -2992,7 +2992,7 @@ const Writer = struct {
29922992 .mod,
29932993 .rem,
29942994 .bit_offset_of,
2995 .byte_offset_of,
2995 .offset_of,
29962996 .splat,
29972997 .reduce,
29982998 .atomic_load,
src/air.zig+1-1
......@@ -407,7 +407,7 @@ pub const Inst = struct {
407407 pub const convertable_br_size = std.math.max(@sizeOf(BrBlockFlat), @sizeOf(Br));
408408 pub const convertable_br_align = std.math.max(@alignOf(BrBlockFlat), @alignOf(Br));
409409 comptime {
410 assert(@byteOffsetOf(BrBlockFlat, "base") == @byteOffsetOf(Br, "base"));
410 assert(@offsetOf(BrBlockFlat, "base") == @offsetOf(Br, "base"));
411411 }
412412
413413 pub const BrBlockFlat = struct {
src/stage1/all_types.hpp+3-3
......@@ -1768,7 +1768,7 @@ enum BuiltinFnId {
17681768 BuiltinFnIdPtrToInt,
17691769 BuiltinFnIdTagName,
17701770 BuiltinFnIdFieldParentPtr,
1771 BuiltinFnIdByteOffsetOf,
1771 BuiltinFnIdOffsetOf,
17721772 BuiltinFnIdBitOffsetOf,
17731773 BuiltinFnIdAsyncCall,
17741774 BuiltinFnIdShlExact,
......@@ -2576,7 +2576,7 @@ enum IrInstSrcId {
25762576 IrInstSrcIdPanic,
25772577 IrInstSrcIdTagName,
25782578 IrInstSrcIdFieldParentPtr,
2579 IrInstSrcIdByteOffsetOf,
2579 IrInstSrcIdOffsetOf,
25802580 IrInstSrcIdBitOffsetOf,
25812581 IrInstSrcIdTypeInfo,
25822582 IrInstSrcIdType,
......@@ -4047,7 +4047,7 @@ struct IrInstGenFieldParentPtr {
40474047 TypeStructField *field;
40484048};
40494049
4050struct IrInstSrcByteOffsetOf {
4050struct IrInstSrcOffsetOf {
40514051 IrInstSrc base;
40524052
40534053 IrInstSrc *type_value;
src/stage1/astgen.cpp+8-8
......@@ -256,8 +256,8 @@ void destroy_instruction_src(IrInstSrc *inst) {
256256 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPanic *>(inst));
257257 case IrInstSrcIdFieldParentPtr:
258258 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst));
259 case IrInstSrcIdByteOffsetOf:
260 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst));
259 case IrInstSrcIdOffsetOf:
260 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOffsetOf *>(inst));
261261 case IrInstSrcIdBitOffsetOf:
262262 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst));
263263 case IrInstSrcIdTypeInfo:
......@@ -777,8 +777,8 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
777777 return IrInstSrcIdFieldParentPtr;
778778}
779779
780static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) {
781 return IrInstSrcIdByteOffsetOf;
780static constexpr IrInstSrcId ir_inst_id(IrInstSrcOffsetOf *) {
781 return IrInstSrcIdOffsetOf;
782782}
783783
784784static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) {
......@@ -2472,10 +2472,10 @@ static IrInstSrc *ir_build_field_parent_ptr_src(Stage1AstGen *ag, Scope *scope,
24722472 return &inst->base;
24732473}
24742474
2475static IrInstSrc *ir_build_byte_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
2475static IrInstSrc *ir_build_offset_of(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
24762476 IrInstSrc *type_value, IrInstSrc *field_name)
24772477{
2478 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(ag, scope, source_node);
2478 IrInstSrcOffsetOf *instruction = ir_build_instruction<IrInstSrcOffsetOf>(ag, scope, source_node);
24792479 instruction->type_value = type_value;
24802480 instruction->field_name = field_name;
24812481
......@@ -4945,7 +4945,7 @@ static IrInstSrc *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
49454945 arg0_value, arg1_value, arg2_value);
49464946 return ir_lval_wrap(ag, scope, field_parent_ptr, lval, result_loc);
49474947 }
4948 case BuiltinFnIdByteOffsetOf:
4948 case BuiltinFnIdOffsetOf:
49494949 {
49504950 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
49514951 IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope);
......@@ -4957,7 +4957,7 @@ static IrInstSrc *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
49574957 if (arg1_value == ag->codegen->invalid_inst_src)
49584958 return arg1_value;
49594959
4960 IrInstSrc *offset_of = ir_build_byte_offset_of(ag, scope, node, arg0_value, arg1_value);
4960 IrInstSrc *offset_of = ir_build_offset_of(ag, scope, node, arg0_value, arg1_value);
49614961 return ir_lval_wrap(ag, scope, offset_of, lval, result_loc);
49624962 }
49634963 case BuiltinFnIdBitOffsetOf:
src/stage1/codegen.cpp+1-1
......@@ -8902,7 +8902,7 @@ static void define_builtin_fns(CodeGen *g) {
89028902 create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1);
89038903 create_builtin_fn(g, BuiltinFnIdTagName, "tagName", 1);
89048904 create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3);
8905 create_builtin_fn(g, BuiltinFnIdByteOffsetOf, "byteOffsetOf", 2);
8905 create_builtin_fn(g, BuiltinFnIdOffsetOf, "offsetOf", 2);
89068906 create_builtin_fn(g, BuiltinFnIdBitOffsetOf, "bitOffsetOf", 2);
89078907 create_builtin_fn(g, BuiltinFnIdDivExact, "divExact", 2);
89088908 create_builtin_fn(g, BuiltinFnIdDivTrunc, "divTrunc", 2);
src/stage1/ir.cpp+4-4
......@@ -17082,7 +17082,7 @@ static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
1708217082 return field;
1708317083}
1708417084
17085static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) {
17085static IrInstGen *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstSrcOffsetOf *instruction) {
1708617086 IrInstGen *type_value = instruction->type_value->child;
1708717087 if (type_is_invalid(type_value->value->type))
1708817088 return ira->codegen->invalid_inst_gen;
......@@ -24368,8 +24368,8 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2436824368 return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction);
2436924369 case IrInstSrcIdFieldParentPtr:
2437024370 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction);
24371 case IrInstSrcIdByteOffsetOf:
24372 return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction);
24371 case IrInstSrcIdOffsetOf:
24372 return ir_analyze_instruction_offset_of(ira, (IrInstSrcOffsetOf *)instruction);
2437324373 case IrInstSrcIdBitOffsetOf:
2437424374 return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction);
2437524375 case IrInstSrcIdTypeInfo:
......@@ -24824,7 +24824,7 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
2482424824 case IrInstSrcIdTypeName:
2482524825 case IrInstSrcIdTagName:
2482624826 case IrInstSrcIdFieldParentPtr:
24827 case IrInstSrcIdByteOffsetOf:
24827 case IrInstSrcIdOffsetOf:
2482824828 case IrInstSrcIdBitOffsetOf:
2482924829 case IrInstSrcIdTypeInfo:
2483024830 case IrInstSrcIdType:
src/stage1/ir_print.cpp+6-6
......@@ -287,8 +287,8 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
287287 return "SrcTagName";
288288 case IrInstSrcIdFieldParentPtr:
289289 return "SrcFieldParentPtr";
290 case IrInstSrcIdByteOffsetOf:
291 return "SrcByteOffsetOf";
290 case IrInstSrcIdOffsetOf:
291 return "SrcOffsetOf";
292292 case IrInstSrcIdBitOffsetOf:
293293 return "SrcBitOffsetOf";
294294 case IrInstSrcIdTypeInfo:
......@@ -2292,8 +2292,8 @@ static void ir_print_field_parent_ptr(IrPrintGen *irp, IrInstGenFieldParentPtr *
22922292 fprintf(irp->f, ")");
22932293}
22942294
2295static void ir_print_byte_offset_of(IrPrintSrc *irp, IrInstSrcByteOffsetOf *instruction) {
2296 fprintf(irp->f, "@byte_offset_of(");
2295static void ir_print_offset_of(IrPrintSrc *irp, IrInstSrcOffsetOf *instruction) {
2296 fprintf(irp->f, "@offset_of(");
22972297 ir_print_other_inst_src(irp, instruction->type_value);
22982298 fprintf(irp->f, ",");
22992299 ir_print_other_inst_src(irp, instruction->field_name);
......@@ -2946,8 +2946,8 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
29462946 case IrInstSrcIdFieldParentPtr:
29472947 ir_print_field_parent_ptr(irp, (IrInstSrcFieldParentPtr *)instruction);
29482948 break;
2949 case IrInstSrcIdByteOffsetOf:
2950 ir_print_byte_offset_of(irp, (IrInstSrcByteOffsetOf *)instruction);
2949 case IrInstSrcIdOffsetOf:
2950 ir_print_offset_of(irp, (IrInstSrcOffsetOf *)instruction);
29512951 break;
29522952 case IrInstSrcIdBitOffsetOf:
29532953 ir_print_bit_offset_of(irp, (IrInstSrcBitOffsetOf *)instruction);
src/translate_c.zig+1-1
......@@ -1426,7 +1426,7 @@ fn transSimpleOffsetOfExpr(
14261426 const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name});
14271427 const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name);
14281428
1429 return Tag.byte_offset_of.create(c.arena, .{
1429 return Tag.offset_of.create(c.arena, .{
14301430 .lhs = type_node,
14311431 .rhs = field_name_node,
14321432 });
src/translate_c/ast.zig+7-7
......@@ -158,8 +158,8 @@ pub const Node = extern union {
158158 ptr_cast,
159159 /// @divExact(lhs, rhs)
160160 div_exact,
161 /// @byteOffsetOf(lhs, rhs)
162 byte_offset_of,
161 /// @offsetOf(lhs, rhs)
162 offset_of,
163163 /// @shuffle(type, a, b, mask)
164164 shuffle,
165165
......@@ -335,7 +335,7 @@ pub const Node = extern union {
335335 .std_meta_vector,
336336 .ptr_cast,
337337 .div_exact,
338 .byte_offset_of,
338 .offset_of,
339339 .std_meta_cast,
340340 => Payload.BinOp,
341341
......@@ -1304,9 +1304,9 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
13041304 const payload = node.castTag(.div_exact).?.data;
13051305 return renderBuiltinCall(c, "@divExact", &.{ payload.lhs, payload.rhs });
13061306 },
1307 .byte_offset_of => {
1308 const payload = node.castTag(.byte_offset_of).?.data;
1309 return renderBuiltinCall(c, "@byteOffsetOf", &.{ payload.lhs, payload.rhs });
1307 .offset_of => {
1308 const payload = node.castTag(.offset_of).?.data;
1309 return renderBuiltinCall(c, "@offsetOf", &.{ payload.lhs, payload.rhs });
13101310 },
13111311 .sizeof => {
13121312 const payload = node.castTag(.sizeof).?.data;
......@@ -2274,7 +2274,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
22742274 .null_sentinel_array_type,
22752275 .bool_to_int,
22762276 .div_exact,
2277 .byte_offset_of,
2277 .offset_of,
22782278 .shuffle,
22792279 => {
22802280 // no grouping needed
test/behavior/bugs/6781.zig+3-3
......@@ -15,7 +15,7 @@ pub const JournalHeader = packed struct {
1515 assert(entry.len >= @sizeOf(JournalHeader));
1616 assert(entry.len == self.size);
1717
18 const checksum_offset = @byteOffsetOf(JournalHeader, "checksum");
18 const checksum_offset = @offsetOf(JournalHeader, "checksum");
1919 const checksum_size = @sizeOf(@TypeOf(self.checksum));
2020 assert(checksum_offset == 0 + 16 + 16);
2121 assert(checksum_size == 16);
......@@ -29,12 +29,12 @@ pub const JournalHeader = packed struct {
2929 const hash_chain_root_size = @sizeOf(@TypeOf(self.hash_chain_root));
3030 assert(hash_chain_root_size == 16);
3131
32 const prev_hash_chain_root_offset = @byteOffsetOf(JournalHeader, "prev_hash_chain_root");
32 const prev_hash_chain_root_offset = @offsetOf(JournalHeader, "prev_hash_chain_root");
3333 const prev_hash_chain_root_size = @sizeOf(@TypeOf(self.prev_hash_chain_root));
3434 assert(prev_hash_chain_root_offset == 0 + 16);
3535 assert(prev_hash_chain_root_size == 16);
3636
37 const checksum_offset = @byteOffsetOf(JournalHeader, "checksum");
37 const checksum_offset = @offsetOf(JournalHeader, "checksum");
3838 const checksum_size = @sizeOf(@TypeOf(self.checksum));
3939 assert(checksum_offset == 0 + 16 + 16);
4040 assert(checksum_size == 16);
test/behavior/sizeof_and_typeof.zig+37-37
......@@ -34,71 +34,71 @@ const P = packed struct {
3434 i: u7,
3535};
3636
37test "@byteOffsetOf" {
37test "@offsetOf" {
3838 // Packed structs have fixed memory layout
39 try expect(@byteOffsetOf(P, "a") == 0);
40 try expect(@byteOffsetOf(P, "b") == 1);
41 try expect(@byteOffsetOf(P, "c") == 5);
42 try expect(@byteOffsetOf(P, "d") == 6);
43 try expect(@byteOffsetOf(P, "e") == 6);
44 try expect(@byteOffsetOf(P, "f") == 7);
45 try expect(@byteOffsetOf(P, "g") == 9);
46 try expect(@byteOffsetOf(P, "h") == 11);
47 try expect(@byteOffsetOf(P, "i") == 12);
39 try expect(@offsetOf(P, "a") == 0);
40 try expect(@offsetOf(P, "b") == 1);
41 try expect(@offsetOf(P, "c") == 5);
42 try expect(@offsetOf(P, "d") == 6);
43 try expect(@offsetOf(P, "e") == 6);
44 try expect(@offsetOf(P, "f") == 7);
45 try expect(@offsetOf(P, "g") == 9);
46 try expect(@offsetOf(P, "h") == 11);
47 try expect(@offsetOf(P, "i") == 12);
4848
4949 // Normal struct fields can be moved/padded
5050 var a: A = undefined;
51 try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
52 try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
53 try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
54 try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
55 try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
56 try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
57 try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
58 try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
59 try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
51 try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @offsetOf(A, "a"));
52 try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @offsetOf(A, "b"));
53 try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @offsetOf(A, "c"));
54 try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @offsetOf(A, "d"));
55 try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @offsetOf(A, "e"));
56 try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @offsetOf(A, "f"));
57 try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @offsetOf(A, "g"));
58 try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @offsetOf(A, "h"));
59 try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @offsetOf(A, "i"));
6060}
6161
62test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {
62test "@offsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {
6363 const p3a_len = 3;
6464 const P3 = packed struct {
6565 a: [p3a_len]u8,
6666 b: usize,
6767 };
68 try std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
69 try std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
68 try std.testing.expectEqual(0, @offsetOf(P3, "a"));
69 try std.testing.expectEqual(p3a_len, @offsetOf(P3, "b"));
7070
7171 const p5a_len = 5;
7272 const P5 = packed struct {
7373 a: [p5a_len]u8,
7474 b: usize,
7575 };
76 try std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
77 try std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
76 try std.testing.expectEqual(0, @offsetOf(P5, "a"));
77 try std.testing.expectEqual(p5a_len, @offsetOf(P5, "b"));
7878
7979 const p6a_len = 6;
8080 const P6 = packed struct {
8181 a: [p6a_len]u8,
8282 b: usize,
8383 };
84 try std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
85 try std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
84 try std.testing.expectEqual(0, @offsetOf(P6, "a"));
85 try std.testing.expectEqual(p6a_len, @offsetOf(P6, "b"));
8686
8787 const p7a_len = 7;
8888 const P7 = packed struct {
8989 a: [p7a_len]u8,
9090 b: usize,
9191 };
92 try std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
93 try std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
92 try std.testing.expectEqual(0, @offsetOf(P7, "a"));
93 try std.testing.expectEqual(p7a_len, @offsetOf(P7, "b"));
9494
9595 const p9a_len = 9;
9696 const P9 = packed struct {
9797 a: [p9a_len]u8,
9898 b: usize,
9999 };
100 try std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
101 try std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
100 try std.testing.expectEqual(0, @offsetOf(P9, "a"));
101 try std.testing.expectEqual(p9a_len, @offsetOf(P9, "b"));
102102
103103 // 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases
104104}
......@@ -113,13 +113,13 @@ test "@bitOffsetOf" {
113113 try expect(@bitOffsetOf(P, "f") == 56);
114114 try expect(@bitOffsetOf(P, "g") == 72);
115115
116 try expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
117 try expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
118 try expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
119 try expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
120 try expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
121 try expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
122 try expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
116 try expect(@offsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
117 try expect(@offsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
118 try expect(@offsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
119 try expect(@offsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
120 try expect(@offsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
121 try expect(@offsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
122 try expect(@offsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
123123}
124124
125125test "@sizeOf on compile-time types" {
test/behavior/struct.zig+1-1
......@@ -699,7 +699,7 @@ test "non-packed struct with u128 entry in union" {
699699
700700 var sx: S = undefined;
701701 var s = &sx;
702 try std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2"));
702 try std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @offsetOf(S, "f2"));
703703 var v2 = U{ .Num = 123 };
704704 s.f2 = v2;
705705 try std.testing.expect(s.f2.Num == 123);
test/compile_errors.zig+8-8
......@@ -6669,24 +6669,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66696669 "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'",
66706670 });
66716671
6672 cases.add("@byteOffsetOf - non struct",
6672 cases.add("@offsetOf - non struct",
66736673 \\const Foo = i32;
66746674 \\export fn foo() usize {
6675 \\ return @byteOffsetOf(Foo, "a",);
6675 \\ return @offsetOf(Foo, "a",);
66766676 \\}
66776677 , &[_][]const u8{
6678 "tmp.zig:3:26: error: expected struct type, found 'i32'",
6678 "tmp.zig:3:22: error: expected struct type, found 'i32'",
66796679 });
66806680
6681 cases.add("@byteOffsetOf - bad field name",
6681 cases.add("@offsetOf - bad field name",
66826682 \\const Foo = struct {
66836683 \\ derp: i32,
66846684 \\};
66856685 \\export fn foo() usize {
6686 \\ return @byteOffsetOf(Foo, "a",);
6686 \\ return @offsetOf(Foo, "a",);
66876687 \\}
66886688 , &[_][]const u8{
6689 "tmp.zig:5:31: error: struct 'Foo' has no field 'a'",
6689 "tmp.zig:5:27: error: struct 'Foo' has no field 'a'",
66906690 });
66916691
66926692 cases.addExe("missing main fn in executable",
......@@ -7693,10 +7693,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
76937693 \\ val: void,
76947694 \\};
76957695 \\export fn foo() void {
7696 \\ const fieldOffset = @byteOffsetOf(Empty, "val",);
7696 \\ const fieldOffset = @offsetOf(Empty, "val",);
76977697 \\}
76987698 , &[_][]const u8{
7699 "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset",
7699 "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset",
77007700 });
77017701
77027702 cases.add("taking bit offset of void field in struct",