authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-05-29 13:19:08+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-05-30 19:43:36+02:00
logb2a984cda67edd25fa2bf3ebe697649d561ff80f
tree198ed214fcc02afd1f5c14ca432aea5b4b3e8514
parent96a66d14a16a89f759c1ed86a61cef710e3a7d05
signaturelock-open Commit is signed but in an unrecognized format.

spirv: basic setup for using new type constant cache


3 files changed, 229 insertions(+), 103 deletions(-)

src/codegen/spirv.zig+66
......@@ -22,6 +22,8 @@ const IdResultType = spec.IdResultType;
2222const StorageClass = spec.StorageClass;
2323
2424const SpvModule = @import("spirv/Module.zig");
25const SpvRef = SpvModule.TypeConstantCache.Ref;
26
2527const SpvSection = @import("spirv/Section.zig");
2628const SpvType = @import("spirv/type.zig").Type;
2729const SpvAssembler = @import("spirv/Assembler.zig");
......@@ -1158,6 +1160,18 @@ pub const DeclGen = struct {
11581160 return try self.spv.resolveType(try SpvType.int(self.spv.arena, signedness, backing_bits));
11591161 }
11601162
1163 fn intType2(self: *DeclGen, signedness: std.builtin.Signedness, bits: u16) !SpvRef {
1164 const backing_bits = self.backingIntBits(bits) orelse {
1165 // TODO: Integers too big for any native type are represented as "composite integers":
1166 // An array of largestSupportedIntBits.
1167 return self.todo("Implement {s} composite int type of {} bits", .{ @tagName(signedness), bits });
1168 };
1169 return try self.spv.resolve(.{ .int_type = .{
1170 .signedness = signedness,
1171 .bits = backing_bits,
1172 } });
1173 }
1174
11611175 /// Create an integer type that represents 'usize'.
11621176 fn sizeType(self: *DeclGen) !SpvType.Ref {
11631177 return try self.intType(.unsigned, self.getTarget().ptrBitWidth());
......@@ -1238,9 +1252,61 @@ pub const DeclGen = struct {
12381252 return try self.spv.simpleStructType(members.slice());
12391253 }
12401254
1255 fn resolveType2(self: *DeclGen, ty: Type, repr: Repr) !SpvRef {
1256 const target = self.getTarget();
1257 switch (ty.zigTypeTag()) {
1258 .Void, .NoReturn => return try self.spv.resolve(.void_type),
1259 .Bool => switch (repr) {
1260 .direct => return try self.spv.resolve(.bool_type),
1261 .indirect => return try self.intType2(.unsigned, 1),
1262 },
1263 .Int => {
1264 const int_info = ty.intInfo(target);
1265 return try self.intType2(int_info.signedness, int_info.bits);
1266 },
1267 .Enum => {
1268 var buffer: Type.Payload.Bits = undefined;
1269 const tag_ty = ty.intTagType(&buffer);
1270 return self.resolveType2(tag_ty, repr);
1271 },
1272 .Float => {
1273 // We can (and want) not really emulate floating points with other floating point types like with the integer types,
1274 // so if the float is not supported, just return an error.
1275 const bits = ty.floatBits(target);
1276 const supported = switch (bits) {
1277 16 => Target.spirv.featureSetHas(target.cpu.features, .Float16),
1278 // 32-bit floats are always supported (see spec, 2.16.1, Data rules).
1279 32 => true,
1280 64 => Target.spirv.featureSetHas(target.cpu.features, .Float64),
1281 else => false,
1282 };
1283
1284 if (!supported) {
1285 return self.fail("Floating point width of {} bits is not supported for the current SPIR-V feature set", .{bits});
1286 }
1287
1288 return try self.spv.resolve(.{ .float_type = .{ .bits = bits } });
1289 },
1290 .Array => {
1291 const elem_ty = ty.childType();
1292 const elem_ty_ref = try self.resolveType2(elem_ty, .direct);
1293 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel()) orelse {
1294 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel()});
1295 };
1296 _ = total_len;
1297 return self.spv.resolve(.{ .array_type = .{
1298 .element_type = elem_ty_ref,
1299 .length = @intToEnum(SpvRef, 0),
1300 } });
1301 },
1302 else => unreachable, // TODO
1303 }
1304 }
1305
12411306 /// Turn a Zig type into a SPIR-V Type, and return a reference to it.
12421307 fn resolveType(self: *DeclGen, ty: Type, repr: Repr) Error!SpvType.Ref {
12431308 log.debug("resolveType: ty = {}", .{ty.fmt(self.module)});
1309 _ = try self.resolveType2(ty, repr);
12441310 const target = self.getTarget();
12451311 switch (ty.zigTypeTag()) {
12461312 .Void, .NoReturn => return try self.spv.resolveType(SpvType.initTag(.void)),
src/codegen/spirv/Module.zig+36-14
......@@ -21,6 +21,7 @@ const IdResultType = spec.IdResultType;
2121
2222const Section = @import("Section.zig");
2323const Type = @import("type.zig").Type;
24pub const TypeConstantCache = @import("TypeConstantCache.zig");
2425
2526const TypeCache = std.ArrayHashMapUnmanaged(Type, IdResultType, Type.ShallowHashContext32, true);
2627
......@@ -125,8 +126,16 @@ sections: struct {
125126 // OpModuleProcessed - skip for now.
126127 /// Annotation instructions (OpDecorate etc).
127128 annotations: Section = .{},
128 /// Type and constant declarations that are generated by the TypeConstantCache.
129 types_and_constants: Section = .{},
129 /// Global variable declarations
130 /// From this section, OpLine and OpNoLine is allowed.
131 /// According to the SPIR-V documentation, this section normally
132 /// also holds type and constant instructions. These are managed
133 /// via the tc_cache instead, which is the sole structure that
134 /// manages that section. These will be inserted between this and
135 /// the previous section when emitting the final binary.
136 /// TODO: Do we need this section? Globals are also managed with another mechanism.
137 /// The only thing that needs to be kept here is OpUndef
138 globals: Section = .{},
130139 /// Type declarations, constants, global variables
131140 /// Below this section, OpLine and OpNoLine is allowed.
132141 types_globals_constants: Section = .{},
......@@ -143,11 +152,10 @@ next_result_id: Word,
143152/// just the ones for OpLine. Note that OpLine needs the result of OpString, and not that of OpSource.
144153source_file_names: std.StringHashMapUnmanaged(IdRef) = .{},
145154
146/// SPIR-V type cache. Note that according to SPIR-V spec section 2.8, Types and Variables, non-pointer
147/// non-aggrerate types (which includes matrices and vectors) must have a _unique_ representation in
148/// the final binary.
149/// Note: Uses ArrayHashMap which is insertion ordered, so that we may refer to other types by index (Type.Ref).
150155type_cache: TypeCache = .{},
156/// SPIR-V type- and constant cache. This structure is used to store information about these in a more
157/// efficient manner.
158tc_cache: TypeConstantCache = .{},
151159
152160/// Set of Decls, referred to by Decl.Index.
153161decls: std.ArrayListUnmanaged(Decl) = .{},
......@@ -165,7 +173,7 @@ globals: struct {
165173 globals: std.AutoArrayHashMapUnmanaged(Decl.Index, Global) = .{},
166174 /// This pseudo-section contains the initialization code for all the globals. Instructions from
167175 /// here are reordered when flushing the module. Its contents should be part of the
168 /// `types_globals_constants` SPIR-V section.
176 /// `types_globals_constants` SPIR-V section when the module is emitted.
169177 section: Section = .{},
170178} = .{},
171179
......@@ -184,12 +192,11 @@ pub fn deinit(self: *Module) void {
184192 self.sections.debug_strings.deinit(self.gpa);
185193 self.sections.debug_names.deinit(self.gpa);
186194 self.sections.annotations.deinit(self.gpa);
187 self.sections.types_and_constants(self.gpa);
188 self.sections.types_globals_constants.deinit(self.gpa);
195 self.sections.globals.deinit(self.gpa);
189196 self.sections.functions.deinit(self.gpa);
190197
191198 self.source_file_names.deinit(self.gpa);
192 self.type_cache.deinit(self.gpa);
199 self.tc_cache.deinit(self);
193200
194201 self.decls.deinit(self.gpa);
195202 self.decl_deps.deinit(self.gpa);
......@@ -216,6 +223,18 @@ pub fn idBound(self: Module) Word {
216223 return self.next_result_id;
217224}
218225
226pub fn resolve(self: *Module, key: TypeConstantCache.Key) !TypeConstantCache.Ref {
227 return self.tc_cache.resolve(self, key);
228}
229
230pub fn resultId(self: *Module, ref: TypeConstantCache.Ref) IdResult {
231 return self.tc_cache.resultId(ref);
232}
233
234pub fn resolveId(self: *Module, key: TypeConstantCache.Key) !IdResult {
235 return self.resultId(try self.resolve(key));
236}
237
219238fn orderGlobalsInto(
220239 self: *Module,
221240 decl_index: Decl.Index,
......@@ -327,6 +346,9 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
327346 var entry_points = try self.entryPoints();
328347 defer entry_points.deinit(self.gpa);
329348
349 var types_constants = try self.tc_cache.materialize(self);
350 defer types_constants.deinit(self.gpa);
351
330352 // Note: needs to be kept in order according to section 2.3!
331353 const buffers = &[_][]const Word{
332354 &header,
......@@ -337,8 +359,8 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
337359 self.sections.debug_strings.toWords(),
338360 self.sections.debug_names.toWords(),
339361 self.sections.annotations.toWords(),
340 self.sections.types_constants.toWords(),
341 self.sections.types_globals_constants.toWords(),
362 types_constants.toWords(),
363 self.sections.globals.toWords(),
342364 globals.toWords(),
343365 self.sections.functions.toWords(),
344366 };
......@@ -891,8 +913,8 @@ pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8
891913pub fn debugName(self: *Module, target: IdResult, comptime fmt: []const u8, args: anytype) !void {
892914 const name = try std.fmt.allocPrint(self.gpa, fmt, args);
893915 defer self.gpa.free(name);
894 try debug.emit(self.gpa, .OpName, .{
895 .target = result_id,
916 try self.sections.debug_names.emit(self.gpa, .OpName, .{
917 .target = target,
896918 .name = name,
897919 });
898920}
src/codegen/spirv/TypeConstantCache.zig+127-89
......@@ -1,16 +1,19 @@
11//! This file implements an InternPool-like structure that caches
2//! SPIR-V types and constants.
3//! In the case of SPIR-V, the type- and constant instructions
4//! describe the type and constant fully. This means we can save
5//! memory by representing these items directly in spir-v code,
6//! and decoding that when required.
7//! This does not work for OpDecorate instructions though, and for
8//! those we keep some additional metadata.
2//! SPIR-V types and constants. Instead of generating type and
3//! constant instructions directly, we first keep a representation
4//! in a compressed database. This is then only later turned into
5//! actual SPIR-V instructions.
6//! Note: This cache is insertion-ordered. This means that we
7//! can materialize the SPIR-V instructions in the proper order,
8//! as SPIR-V requires that the type is emitted before use.
9//! Note: According to SPIR-V spec section 2.8, Types and Variables,
10//! non-pointer non-aggrerate types (which includes matrices and
11//! vectors) must have a _unique_ representation in the final binary.
912
1013const std = @import("std");
1114const Allocator = std.mem.Allocator;
1215
13const Section = @import("section.zig");
16const Section = @import("Section.zig");
1417const Module = @import("Module.zig");
1518
1619const spec = @import("spec.zig");
......@@ -21,7 +24,7 @@ const Self = @This();
2124
2225map: std.AutoArrayHashMapUnmanaged(void, void) = .{},
2326items: std.MultiArrayList(Item) = .{},
24extra: std.ArrayHashMapUnmanaged(u32) = .{},
27extra: std.ArrayListUnmanaged(u32) = .{},
2528
2629const Item = struct {
2730 tag: Tag,
......@@ -32,6 +35,7 @@ const Item = struct {
3235};
3336
3437const Tag = enum {
38 // -- Types
3539 /// Simple type that has no additional data.
3640 /// data is SimpleType.
3741 type_simple,
......@@ -45,13 +49,18 @@ const Tag = enum {
4549 /// data is number of bits
4650 type_float,
4751 /// Vector type
48 /// data is payload to Key.VectorType
52 /// data is payload to VectorType
4953 type_vector,
54 /// Array type
55 /// data is payload to ArrayType
56 type_array,
5057
51 const SimpleType = enum {
52 void,
53 bool,
54 };
58 // -- Values
59
60 const SimpleType = enum { void, bool };
61
62 const VectorType = Key.VectorType;
63 const ArrayType = Key.ArrayType;
5564};
5665
5766pub const Ref = enum(u32) { _ };
......@@ -61,11 +70,15 @@ pub const Ref = enum(u32) { _ };
6170/// database: Values described for this structure are ephemeral and stored
6271/// in a more memory-efficient manner internally.
6372pub const Key = union(enum) {
64 void_ty,
65 bool_ty,
66 int_ty: IntType,
67 float_ty: FloatType,
68 vector_ty: VectorType,
73 // -- Types
74 void_type,
75 bool_type,
76 int_type: IntType,
77 float_type: FloatType,
78 vector_type: VectorType,
79 array_type: ArrayType,
80
81 // -- values
6982
7083 pub const IntType = std.builtin.Type.Int;
7184 pub const FloatType = std.builtin.Type.Float;
......@@ -75,55 +88,66 @@ pub const Key = union(enum) {
7588 component_count: u32,
7689 };
7790
91 pub const ArrayType = struct {
92 /// Child type of this array.
93 element_type: Ref,
94 /// Reference to a constant.
95 length: Ref,
96 /// Type has the 'ArrayStride' decoration.
97 /// If zero, no stride is present.
98 stride: u32 = 0,
99 };
100
78101 fn hash(self: Key) u32 {
79102 var hasher = std.hash.Wyhash.init(0);
80103 std.hash.autoHash(&hasher, self);
81104 return @truncate(u32, hasher.final());
82105 }
83106
84 fn eql(a: Key, b: Key) u32 {
107 fn eql(a: Key, b: Key) bool {
85108 return std.meta.eql(a, b);
86109 }
87110
88111 pub const Adapter = struct {
89112 self: *const Self,
90113
91 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: u32) bool {
114 pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {
92115 _ = b_void;
93 return ctx.self.lookup(@intToEnum(Ref, b_map_index)).eql(a);
116 return ctx.self.lookup(@intToEnum(Ref, b_index)).eql(a);
94117 }
95118
96119 pub fn hash(ctx: @This(), a: Key) u32 {
97 return ctx.self.hash(a);
120 _ = ctx;
121 return a.hash();
98122 }
99123 };
100124
101125 fn toSimpleType(self: Key) Tag.SimpleType {
102126 return switch (self) {
103 .void_ty => .void,
104 .bool_ty => .bool,
127 .void_type => .void,
128 .bool_type => .bool,
105129 else => unreachable,
106130 };
107131 }
108132};
109133
110pub fn deinit(self: *Self, spv: Module) void {
134pub fn deinit(self: *Self, spv: *const Module) void {
111135 self.map.deinit(spv.gpa);
112136 self.items.deinit(spv.gpa);
113137 self.extra.deinit(spv.gpa);
114138}
115139
116140/// Actually materialize the database into spir-v instructions.
117// TODO: This should generate decorations as well as regular instructions.
118// Important is that these are generated in-order, but that should be fine.
119pub fn finalize(self: *Self, spv: *Module) !void {
120 // This function should really be the only one that modifies spv.types_and_constants.
121 // TODO: Make this function return the section instead.
122 std.debug.assert(spv.sections.types_and_constants.instructions.items.len == 0);
123
141/// This function returns a spir-v section of (only) constant and type instructions.
142/// Additionally, decorations, debug names, etc, are all directly emitted into the
143/// `spv` module. The section is allocated with `spv.gpa`.
144pub fn materialize(self: *Self, spv: *Module) !Section {
145 var section = Section{};
146 errdefer section.deinit(spv.gpa);
124147 for (self.items.items(.result_id), 0..) |result_id, index| {
125 try self.emit(spv, result_id, @intToEnum(Ref, index));
148 try self.emit(spv, result_id, @intToEnum(Ref, index), &section);
126149 }
150 return section;
127151}
128152
129153fn emit(
......@@ -131,97 +155,104 @@ fn emit(
131155 spv: *Module,
132156 result_id: IdResult,
133157 ref: Ref,
158 section: *Section,
134159) !void {
135 const tc = &spv.sections.types_and_constants;
136160 const key = self.lookup(ref);
137161 switch (key) {
138 .void_ty => {
139 try tc.emit(spv.gpa, .OpTypeVoid, .{ .id_result = result_id });
162 .void_type => {
163 try section.emit(spv.gpa, .OpTypeVoid, .{ .id_result = result_id });
140164 try spv.debugName(result_id, "void", .{});
141165 },
142 .bool_ty => {
143 try tc.emit(spv.gpa, .OpTypeBool, .{ .id_result = result_id });
166 .bool_type => {
167 try section.emit(spv.gpa, .OpTypeBool, .{ .id_result = result_id });
144168 try spv.debugName(result_id, "bool", .{});
145169 },
146 .int_ty => |int| {
147 try tc.emit(spv.gpa, .OpTypeInt, .{
170 .int_type => |int| {
171 try section.emit(spv.gpa, .OpTypeInt, .{
148172 .id_result = result_id,
149173 .width = int.bits,
150174 .signedness = switch (int.signedness) {
151 .unsigned => 0,
175 .unsigned => @as(spec.Word, 0),
152176 .signed => 1,
153177 },
154178 });
155179 const ui: []const u8 = switch (int.signedness) {
156 0 => "u",
157 1 => "i",
158 else => unreachable,
180 .unsigned => "u",
181 .signed => "i",
159182 };
160183 try spv.debugName(result_id, "{s}{}", .{ ui, int.bits });
161184 },
162 .float_ty => |float| {
163 try tc.emit(spv.gpa, .OpTypeFloat, .{
185 .float_type => |float| {
186 try section.emit(spv.gpa, .OpTypeFloat, .{
164187 .id_result = result_id,
165188 .width = float.bits,
166189 });
167190 try spv.debugName(result_id, "f{}", .{float.bits});
168191 },
169 .vector_ty => |vector| {
170 try tc.emit(spv.gpa, .OpTypeVector, .{
192 .vector_type => |vector| {
193 try section.emit(spv.gpa, .OpTypeVector, .{
171194 .id_result = result_id,
172195 .component_type = self.resultId(vector.component_type),
173196 .component_count = vector.component_count,
174197 });
175198 },
199 .array_type => |array| {
200 try section.emit(spv.gpa, .OpTypeArray, .{
201 .id_result = result_id,
202 .element_type = self.resultId(array.element_type),
203 .length = self.resultId(array.length),
204 });
205 if (array.stride != 0) {
206 try spv.decorate(result_id, .{ .ArrayStride = .{ .array_stride = array.stride } });
207 }
208 },
176209 }
177210}
178211
179212/// Add a key to this cache. Returns a reference to the key that
180213/// was added. The corresponding result-id can be queried using
181214/// self.resultId with the result.
182pub fn add(self: *Self, spv: *Module, key: Key) !Ref {
215pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
183216 const adapter: Key.Adapter = .{ .self = self };
184217 const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);
185218 if (entry.found_existing) {
186219 return @intToEnum(Ref, entry.index);
187220 }
188221 const result_id = spv.allocId();
189 try self.items.ensureUnusedCapacity(spv.gpa, 1);
190 switch (key) {
191 inline .void_ty, .bool_ty => {
192 self.items.appendAssumeCapacity(.{
193 .tag = .type_simple,
194 .result_id = result_id,
195 .data = @enumToInt(key.toSimpleType()),
196 });
222 const item: Item = switch (key) {
223 inline .void_type, .bool_type => .{
224 .tag = .type_simple,
225 .result_id = result_id,
226 .data = @enumToInt(key.toSimpleType()),
197227 },
198 .int_ty => |int| {
228 .int_type => |int| blk: {
199229 const t: Tag = switch (int.signedness) {
200230 .signed => .type_int_signed,
201231 .unsigned => .type_int_unsigned,
202232 };
203 self.items.appendAssumeCapacity(.{
233 break :blk .{
204234 .tag = t,
205235 .result_id = result_id,
206236 .data = int.bits,
207 });
237 };
208238 },
209 .float_ty => |float| {
210 self.items.appendAssumeCapacity(.{
211 .tag = .type_float,
212 .result_id = result_id,
213 .data = float.bits,
214 });
239 .float_type => |float| .{
240 .tag = .type_float,
241 .result_id = result_id,
242 .data = float.bits,
215243 },
216 .vector_ty => |vec| {
217 const payload = try self.addExtra(vec);
218 self.items.appendAssumeCapacity(.{
219 .tag = .type_vector,
220 .result_id = result_id,
221 .data = payload,
222 });
244 .vector_type => |vector| .{
245 .tag = .type_vector,
246 .result_id = result_id,
247 .data = try self.addExtra(spv, vector),
223248 },
224 }
249 .array_type => |array| .{
250 .tag = .type_array,
251 .result_id = result_id,
252 .data = try self.addExtra(spv, array),
253 },
254 };
255 try self.items.append(spv.gpa, item);
225256
226257 return @intToEnum(Ref, entry.index);
227258}
......@@ -238,36 +269,35 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
238269 const data = item.data;
239270 return switch (item.tag) {
240271 .type_simple => switch (@intToEnum(Tag.SimpleType, data)) {
241 .void => .void_ty,
242 .bool => .bool_ty,
272 .void => .void_type,
273 .bool => .bool_type,
243274 },
244 .type_int_signed => .{ .int_ty = .{
275 .type_int_signed => .{ .int_type = .{
245276 .signedness = .signed,
246277 .bits = @intCast(u16, data),
247278 } },
248 .type_int_unsigned => .{ .int_ty = .{
279 .type_int_unsigned => .{ .int_type = .{
249280 .signedness = .unsigned,
250281 .bits = @intCast(u16, data),
251282 } },
252 .type_float => .{ .float_ty = .{
283 .type_float => .{ .float_type = .{
253284 .bits = @intCast(u16, data),
254285 } },
255 .type_vector => .{
256 .vector_ty = self.extraData(Key.VectorType, data),
257 },
286 .type_vector => .{ .vector_type = self.extraData(Tag.VectorType, data) },
287 .type_array => .{ .array_type = self.extraData(Tag.ArrayType, data) },
258288 };
259289}
260290
261fn addExtra(self: *Self, gpa: Allocator, extra: anytype) !u32 {
291fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
262292 const fields = @typeInfo(@TypeOf(extra)).Struct.fields;
263 try self.extra.ensureUnusedCapacity(gpa, fields.len);
264 try self.addExtraAssumeCapacity(extra);
293 try self.extra.ensureUnusedCapacity(spv.gpa, fields.len);
294 return try self.addExtraAssumeCapacity(extra);
265295}
266296
267297fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {
268298 const payload_offset = @intCast(u32, self.extra.items.len);
269299 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
270 const field_val = @field(field, field.name);
300 const field_val = @field(extra, field.name);
271301 const word = switch (field.type) {
272302 u32 => field_val,
273303 Ref => @enumToInt(field_val),
......@@ -279,8 +309,13 @@ fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {
279309}
280310
281311fn extraData(self: Self, comptime T: type, offset: u32) T {
312 return self.extraDataTrail(T, offset).data;
313}
314
315fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, trail: u32 } {
282316 var result: T = undefined;
283 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {
317 const fields = @typeInfo(T).Struct.fields;
318 inline for (fields, 0..) |field, i| {
284319 const word = self.extra.items[offset + i];
285320 @field(result, field.name) = switch (field.type) {
286321 u32 => word,
......@@ -288,5 +323,8 @@ fn extraData(self: Self, comptime T: type, offset: u32) T {
288323 else => @compileError("Invalid type: " ++ @typeName(field.type)),
289324 };
290325 }
291 return result;
326 return .{
327 .data = result,
328 .trail = offset + @intCast(u32, fields.len),
329 };
292330}