| ... | @@ -1244,7 +1244,7 @@ pub const DeclGen = struct { | ... | @@ -1244,7 +1244,7 @@ pub const DeclGen = struct { |
| 1244 | const elem_ty = array_type.child.toType(); | 1244 | const elem_ty = array_type.child.toType(); |
| 1245 | const elem_ty_ref = try self.resolveType(elem_ty, .indirect); | 1245 | const elem_ty_ref = try self.resolveType(elem_ty, .indirect); |
| 1246 | | 1246 | |
| 1247 | var constituents = try self.gpa.alloc(IdRef, ty.arrayLenIncludingSentinel(mod)); | 1247 | const constituents = try self.gpa.alloc(IdRef, ty.arrayLenIncludingSentinel(mod)); |
| 1248 | defer self.gpa.free(constituents); | 1248 | defer self.gpa.free(constituents); |
| 1249 | | 1249 | |
| 1250 | switch (aggregate.storage) { | 1250 | switch (aggregate.storage) { |
| ... | @@ -1272,8 +1272,33 @@ pub const DeclGen = struct { | ... | @@ -1272,8 +1272,33 @@ pub const DeclGen = struct { |
| 1272 | } | 1272 | } |
| 1273 | return try self.constructStruct(result_ty_ref, constituents); | 1273 | return try self.constructStruct(result_ty_ref, constituents); |
| 1274 | }, | 1274 | }, |
| 1275 | .vector_type => return self.todo("constant aggregate of type {}", .{ty.fmt(mod)}), | 1275 | .struct_type => { |
| 1276 | .anon_struct_type => unreachable, // TODO | 1276 | const struct_ty = mod.typeToStruct(ty).?; |
| | 1277 | if (struct_ty.layout == .Packed) { |
| | 1278 | return self.todo("packed struct constants", .{}); |
| | 1279 | } |
| | 1280 | |
| | 1281 | var constituents = std.ArrayList(IdRef).init(self.gpa); |
| | 1282 | defer constituents.deinit(); |
| | 1283 | |
| | 1284 | for (struct_ty.fields.values(), 0..) |field, i| { |
| | 1285 | if (field.is_comptime or !field.ty.hasRuntimeBits(mod)) continue; |
| | 1286 | |
| | 1287 | const field_val = switch (aggregate.storage) { |
| | 1288 | .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{ |
| | 1289 | .ty = field.ty.toIntern(), |
| | 1290 | .storage = .{ .u64 = bytes[i] }, |
| | 1291 | } }), |
| | 1292 | .elems => |elems| elems[i], |
| | 1293 | .repeated_elem => |elem| elem, |
| | 1294 | }; |
| | 1295 | const field_id = try self.constant(field.ty, field_val.toValue(), .indirect); |
| | 1296 | try constituents.append(field_id); |
| | 1297 | } |
| | 1298 | |
| | 1299 | return try self.constructStruct(result_ty_ref, constituents.items); |
| | 1300 | }, |
| | 1301 | .vector_type, .anon_struct_type => unreachable, // TODO |
| 1277 | else => unreachable, | 1302 | else => unreachable, |
| 1278 | }, | 1303 | }, |
| 1279 | else => { | 1304 | else => { |