| ... | ... | @@ -16418,9 +16418,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16418 | 16418 | }, |
| 16419 | 16419 | .Enum => { |
| 16420 | 16420 | // TODO: look into memoizing this result. |
| 16421 | | const enum_type = ip.indexToKey(ty.toIntern()).enum_type; |
| 16422 | | |
| 16423 | | const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive); |
| 16421 | const is_exhaustive = Value.makeBool(ip.indexToKey(ty.toIntern()).enum_type.tag_mode != .nonexhaustive); |
| 16424 | 16422 | |
| 16425 | 16423 | var fields_anon_decl = try block.startAnonDecl(); |
| 16426 | 16424 | defer fields_anon_decl.deinit(); |
| ... | ... | @@ -16438,10 +16436,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16438 | 16436 | break :t enum_field_ty_decl.val.toType(); |
| 16439 | 16437 | }; |
| 16440 | 16438 | |
| 16441 | | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); |
| 16439 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.indexToKey(ty.toIntern()).enum_type.names.len); |
| 16442 | 16440 | for (enum_field_vals, 0..) |*field_val, i| { |
| 16441 | const enum_type = ip.indexToKey(ty.toIntern()).enum_type; |
| 16442 | const value_val = if (enum_type.values.len > 0) |
| 16443 | try mod.intern_pool.getCoerced(gpa, enum_type.values[i], .comptime_int_type) |
| 16444 | else |
| 16445 | try mod.intern(.{ .int = .{ |
| 16446 | .ty = .comptime_int_type, |
| 16447 | .storage = .{ .u64 = @intCast(u64, i) }, |
| 16448 | } }); |
| 16443 | 16449 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16444 | | const name = try sema.arena.dupe(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).enum_type.names[i])); |
| 16450 | const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names[i])); |
| 16445 | 16451 | const name_val = v: { |
| 16446 | 16452 | var anon_decl = try block.startAnonDecl(); |
| 16447 | 16453 | defer anon_decl.deinit(); |
| ... | ... | @@ -16468,7 +16474,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16468 | 16474 | // name: []const u8, |
| 16469 | 16475 | name_val, |
| 16470 | 16476 | // value: comptime_int, |
| 16471 | | (try mod.intValue(Type.comptime_int, i)).toIntern(), |
| 16477 | value_val, |
| 16472 | 16478 | }; |
| 16473 | 16479 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16474 | 16480 | .ty = enum_field_ty.toIntern(), |
| ... | ... | @@ -16503,7 +16509,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16503 | 16509 | } }); |
| 16504 | 16510 | }; |
| 16505 | 16511 | |
| 16506 | | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, enum_type.namespace); |
| 16512 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.indexToKey(ty.toIntern()).enum_type.namespace); |
| 16507 | 16513 | |
| 16508 | 16514 | const type_enum_ty = t: { |
| 16509 | 16515 | const type_enum_ty_decl_index = (try sema.namespaceLookup( |
| ... | ... | @@ -16520,7 +16526,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16520 | 16526 | |
| 16521 | 16527 | const field_values = .{ |
| 16522 | 16528 | // tag_type: type, |
| 16523 | | enum_type.tag_ty, |
| 16529 | ip.indexToKey(ty.toIntern()).enum_type.tag_ty, |
| 16524 | 16530 | // fields: []const EnumField, |
| 16525 | 16531 | fields_val, |
| 16526 | 16532 | // decls: []const Declaration, |