authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-23 19:48:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-25 19:57:02-07:00
logf841b265c5523147f69127b968806454b64e1944
tree31eae5e7f743df5653a922d52e7969e58adafe64
parent426b5982d77fc78a736829f6b1b618eab6535fe1

Sema: move `@typeInfo` anon decls to new mechanism


1 files changed, 136 insertions(+), 173 deletions(-)

src/Sema.zig+136-173
......@@ -16813,9 +16813,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1681316813 .val = .void_value,
1681416814 } }))),
1681516815 .Fn => {
16816 var params_anon_decl = try block.startAnonDecl();
16817 defer params_anon_decl.deinit();
16818
1681916816 const fn_info_decl_index = (try sema.namespaceLookup(
1682016817 block,
1682116818 src,
......@@ -16872,23 +16869,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1687216869 .len = param_vals.len,
1687316870 .child = param_info_ty.toIntern(),
1687416871 });
16875 const new_decl = try params_anon_decl.finish(
16876 new_decl_ty,
16877 (try mod.intern(.{ .aggregate = .{
16878 .ty = new_decl_ty.toIntern(),
16879 .storage = .{ .elems = param_vals },
16880 } })).toValue(),
16881 .none, // default alignment
16882 );
16872 const new_decl_val = try mod.intern(.{ .aggregate = .{
16873 .ty = new_decl_ty.toIntern(),
16874 .storage = .{ .elems = param_vals },
16875 } });
16876 const ptr_ty = (try sema.ptrType(.{
16877 .child = param_info_ty.toIntern(),
16878 .flags = .{
16879 .size = .Slice,
16880 .is_const = true,
16881 },
16882 })).toIntern();
1688316883 break :v try mod.intern(.{ .ptr = .{
16884 .ty = (try sema.ptrType(.{
16885 .child = param_info_ty.toIntern(),
16886 .flags = .{
16887 .size = .Slice,
16888 .is_const = true,
16889 },
16890 })).toIntern(),
16891 .addr = .{ .decl = new_decl },
16884 .ty = ptr_ty,
16885 .addr = .{ .anon_decl = .{
16886 .orig_ty = ptr_ty,
16887 .val = new_decl_val,
16888 } },
1689216889 .len = (try mod.intValue(Type.usize, param_vals.len)).toIntern(),
1689316890 } });
1689416891 };
......@@ -17133,9 +17130,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1713317130 } })));
1713417131 },
1713517132 .ErrorSet => {
17136 var fields_anon_decl = try block.startAnonDecl();
17137 defer fields_anon_decl.deinit();
17138
1713917133 // Get the Error type
1714017134 const error_field_ty = t: {
1714117135 const set_field_ty_decl_index = (try sema.namespaceLookup(
......@@ -17164,23 +17158,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1716417158 // TODO: write something like getCoercedInts to avoid needing to dupe
1716517159 const name = try sema.arena.dupe(u8, ip.stringToSlice(names.get(ip)[i]));
1716617160 const name_val = v: {
17167 var anon_decl = try block.startAnonDecl();
17168 defer anon_decl.deinit();
1716917161 const new_decl_ty = try mod.arrayType(.{
1717017162 .len = name.len,
1717117163 .child = .u8_type,
1717217164 });
17173 const new_decl = try anon_decl.finish(
17174 new_decl_ty,
17175 (try mod.intern(.{ .aggregate = .{
17176 .ty = new_decl_ty.toIntern(),
17177 .storage = .{ .bytes = name },
17178 } })).toValue(),
17179 .none, // default alignment
17180 );
17165 const new_decl_val = try mod.intern(.{ .aggregate = .{
17166 .ty = new_decl_ty.toIntern(),
17167 .storage = .{ .bytes = name },
17168 } });
1718117169 break :v try mod.intern(.{ .ptr = .{
1718217170 .ty = .slice_const_u8_type,
17183 .addr = .{ .decl = new_decl },
17171 .addr = .{ .anon_decl = .{
17172 .val = new_decl_val,
17173 .orig_ty = .slice_const_u8_type,
17174 } },
1718417175 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
1718517176 } });
1718617177 };
......@@ -17213,17 +17204,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1721317204 .len = vals.len,
1721417205 .child = error_field_ty.toIntern(),
1721517206 });
17216 const new_decl = try fields_anon_decl.finish(
17217 array_errors_ty,
17218 (try mod.intern(.{ .aggregate = .{
17219 .ty = array_errors_ty.toIntern(),
17220 .storage = .{ .elems = vals },
17221 } })).toValue(),
17222 .none, // default alignment
17223 );
17207 const new_decl_val = try mod.intern(.{ .aggregate = .{
17208 .ty = array_errors_ty.toIntern(),
17209 .storage = .{ .elems = vals },
17210 } });
1722417211 break :v try mod.intern(.{ .ptr = .{
1722517212 .ty = slice_errors_ty.toIntern(),
17226 .addr = .{ .decl = new_decl },
17213 .addr = .{ .anon_decl = .{
17214 .orig_ty = slice_errors_ty.toIntern(),
17215 .val = new_decl_val,
17216 } },
1722717217 .len = (try mod.intValue(Type.usize, vals.len)).toIntern(),
1722817218 } });
1722917219 } else .none;
......@@ -17271,9 +17261,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1727117261 .Enum => {
1727217262 const is_exhaustive = Value.makeBool(ip.indexToKey(ty.toIntern()).enum_type.tag_mode != .nonexhaustive);
1727317263
17274 var fields_anon_decl = try block.startAnonDecl();
17275 defer fields_anon_decl.deinit();
17276
1727717264 const enum_field_ty = t: {
1727817265 const enum_field_ty_decl_index = (try sema.namespaceLookup(
1727917266 block,
......@@ -17301,23 +17288,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1730117288 // TODO: write something like getCoercedInts to avoid needing to dupe
1730217289 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i]));
1730317290 const name_val = v: {
17304 var anon_decl = try block.startAnonDecl();
17305 defer anon_decl.deinit();
1730617291 const new_decl_ty = try mod.arrayType(.{
1730717292 .len = name.len,
1730817293 .child = .u8_type,
1730917294 });
17310 const new_decl = try anon_decl.finish(
17311 new_decl_ty,
17312 (try mod.intern(.{ .aggregate = .{
17313 .ty = new_decl_ty.toIntern(),
17314 .storage = .{ .bytes = name },
17315 } })).toValue(),
17316 .none, // default alignment
17317 );
17295 const new_decl_val = try mod.intern(.{ .aggregate = .{
17296 .ty = new_decl_ty.toIntern(),
17297 .storage = .{ .bytes = name },
17298 } });
1731817299 break :v try mod.intern(.{ .ptr = .{
1731917300 .ty = .slice_const_u8_type,
17320 .addr = .{ .decl = new_decl },
17301 .addr = .{ .anon_decl = .{
17302 .val = new_decl_val,
17303 .orig_ty = .slice_const_u8_type,
17304 } },
1732117305 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
1732217306 } });
1732317307 };
......@@ -17339,23 +17323,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1733917323 .len = enum_field_vals.len,
1734017324 .child = enum_field_ty.toIntern(),
1734117325 });
17342 const new_decl = try fields_anon_decl.finish(
17343 fields_array_ty,
17344 (try mod.intern(.{ .aggregate = .{
17345 .ty = fields_array_ty.toIntern(),
17346 .storage = .{ .elems = enum_field_vals },
17347 } })).toValue(),
17348 .none, // default alignment
17349 );
17326 const new_decl_val = try mod.intern(.{ .aggregate = .{
17327 .ty = fields_array_ty.toIntern(),
17328 .storage = .{ .elems = enum_field_vals },
17329 } });
17330 const ptr_ty = (try sema.ptrType(.{
17331 .child = enum_field_ty.toIntern(),
17332 .flags = .{
17333 .size = .Slice,
17334 .is_const = true,
17335 },
17336 })).toIntern();
1735017337 break :v try mod.intern(.{ .ptr = .{
17351 .ty = (try sema.ptrType(.{
17352 .child = enum_field_ty.toIntern(),
17353 .flags = .{
17354 .size = .Slice,
17355 .is_const = true,
17356 },
17357 })).toIntern(),
17358 .addr = .{ .decl = new_decl },
17338 .ty = ptr_ty,
17339 .addr = .{ .anon_decl = .{
17340 .val = new_decl_val,
17341 .orig_ty = ptr_ty,
17342 } },
1735917343 .len = (try mod.intValue(Type.usize, enum_field_vals.len)).toIntern(),
1736017344 } });
1736117345 };
......@@ -17395,9 +17379,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1739517379 } })));
1739617380 },
1739717381 .Union => {
17398 var fields_anon_decl = try block.startAnonDecl();
17399 defer fields_anon_decl.deinit();
17400
1740117382 const type_union_ty = t: {
1740217383 const type_union_ty_decl_index = (try sema.namespaceLookup(
1740317384 block,
......@@ -17435,23 +17416,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1743517416 // TODO: write something like getCoercedInts to avoid needing to dupe
1743617417 const name = try sema.arena.dupe(u8, ip.stringToSlice(union_obj.field_names.get(ip)[i]));
1743717418 const name_val = v: {
17438 var anon_decl = try block.startAnonDecl();
17439 defer anon_decl.deinit();
1744017419 const new_decl_ty = try mod.arrayType(.{
1744117420 .len = name.len,
1744217421 .child = .u8_type,
1744317422 });
17444 const new_decl = try anon_decl.finish(
17445 new_decl_ty,
17446 (try mod.intern(.{ .aggregate = .{
17447 .ty = new_decl_ty.toIntern(),
17448 .storage = .{ .bytes = name },
17449 } })).toValue(),
17450 .none, // default alignment
17451 );
17423 const new_decl_val = try mod.intern(.{ .aggregate = .{
17424 .ty = new_decl_ty.toIntern(),
17425 .storage = .{ .bytes = name },
17426 } });
1745217427 break :v try mod.intern(.{ .ptr = .{
1745317428 .ty = .slice_const_u8_type,
17454 .addr = .{ .decl = new_decl },
17429 .addr = .{ .anon_decl = .{
17430 .val = new_decl_val,
17431 .orig_ty = .slice_const_u8_type,
17432 } },
1745517433 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
1745617434 } });
1745717435 };
......@@ -17481,23 +17459,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1748117459 .len = union_field_vals.len,
1748217460 .child = union_field_ty.toIntern(),
1748317461 });
17484 const new_decl = try fields_anon_decl.finish(
17485 array_fields_ty,
17486 (try mod.intern(.{ .aggregate = .{
17487 .ty = array_fields_ty.toIntern(),
17488 .storage = .{ .elems = union_field_vals },
17489 } })).toValue(),
17490 .none, // default alignment
17491 );
17462 const new_decl_val = try mod.intern(.{ .aggregate = .{
17463 .ty = array_fields_ty.toIntern(),
17464 .storage = .{ .elems = union_field_vals },
17465 } });
17466 const ptr_ty = (try sema.ptrType(.{
17467 .child = union_field_ty.toIntern(),
17468 .flags = .{
17469 .size = .Slice,
17470 .is_const = true,
17471 },
17472 })).toIntern();
1749217473 break :v try mod.intern(.{ .ptr = .{
17493 .ty = (try sema.ptrType(.{
17494 .child = union_field_ty.toIntern(),
17495 .flags = .{
17496 .size = .Slice,
17497 .is_const = true,
17498 },
17499 })).toIntern(),
17500 .addr = .{ .decl = new_decl },
17474 .ty = ptr_ty,
17475 .addr = .{ .anon_decl = .{
17476 .orig_ty = ptr_ty,
17477 .val = new_decl_val,
17478 } },
1750117479 .len = (try mod.intValue(Type.usize, union_field_vals.len)).toIntern(),
1750217480 } });
1750317481 };
......@@ -17543,9 +17521,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1754317521 } })));
1754417522 },
1754517523 .Struct => {
17546 var fields_anon_decl = try block.startAnonDecl();
17547 defer fields_anon_decl.deinit();
17548
1754917524 const type_struct_ty = t: {
1755017525 const type_struct_ty_decl_index = (try sema.namespaceLookup(
1755117526 block,
......@@ -17585,8 +17560,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1758517560 const field_ty = anon_struct_type.types.get(ip)[i];
1758617561 const field_val = anon_struct_type.values.get(ip)[i];
1758717562 const name_val = v: {
17588 var anon_decl = try block.startAnonDecl();
17589 defer anon_decl.deinit();
1759017563 // TODO: write something like getCoercedInts to avoid needing to dupe
1759117564 const bytes = if (tuple.names.len != 0)
1759217565 // https://github.com/ziglang/zig/issues/15709
......@@ -17597,17 +17570,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1759717570 .len = bytes.len,
1759817571 .child = .u8_type,
1759917572 });
17600 const new_decl = try anon_decl.finish(
17601 new_decl_ty,
17602 (try mod.intern(.{ .aggregate = .{
17603 .ty = new_decl_ty.toIntern(),
17604 .storage = .{ .bytes = bytes },
17605 } })).toValue(),
17606 .none, // default alignment
17607 );
17573 const new_decl_val = try mod.intern(.{ .aggregate = .{
17574 .ty = new_decl_ty.toIntern(),
17575 .storage = .{ .bytes = bytes },
17576 } });
1760817577 break :v try mod.intern(.{ .ptr = .{
1760917578 .ty = .slice_const_u8_type,
17610 .addr = .{ .decl = new_decl },
17579 .addr = .{ .anon_decl = .{
17580 .val = new_decl_val,
17581 .orig_ty = .slice_const_u8_type,
17582 } },
1761117583 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
1761217584 } });
1761317585 };
......@@ -17651,23 +17623,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1765117623 const field_init = struct_type.fieldInit(ip, i);
1765217624 const field_is_comptime = struct_type.fieldIsComptime(ip, i);
1765317625 const name_val = v: {
17654 var anon_decl = try block.startAnonDecl();
17655 defer anon_decl.deinit();
1765617626 const new_decl_ty = try mod.arrayType(.{
1765717627 .len = name.len,
1765817628 .child = .u8_type,
1765917629 });
17660 const new_decl = try anon_decl.finish(
17661 new_decl_ty,
17662 (try mod.intern(.{ .aggregate = .{
17663 .ty = new_decl_ty.toIntern(),
17664 .storage = .{ .bytes = name },
17665 } })).toValue(),
17666 .none, // default alignment
17667 );
17630 const new_decl_val = try mod.intern(.{ .aggregate = .{
17631 .ty = new_decl_ty.toIntern(),
17632 .storage = .{ .bytes = name },
17633 } });
1766817634 break :v try mod.intern(.{ .ptr = .{
1766917635 .ty = .slice_const_u8_type,
17670 .addr = .{ .decl = new_decl },
17636 .addr = .{ .anon_decl = .{
17637 .val = new_decl_val,
17638 .orig_ty = .slice_const_u8_type,
17639 } },
1767117640 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
1767217641 } });
1767317642 };
......@@ -17707,23 +17676,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1770717676 .len = struct_field_vals.len,
1770817677 .child = struct_field_ty.toIntern(),
1770917678 });
17710 const new_decl = try fields_anon_decl.finish(
17711 array_fields_ty,
17712 (try mod.intern(.{ .aggregate = .{
17713 .ty = array_fields_ty.toIntern(),
17714 .storage = .{ .elems = struct_field_vals },
17715 } })).toValue(),
17716 .none, // default alignment
17717 );
17679 const new_decl_val = try mod.intern(.{ .aggregate = .{
17680 .ty = array_fields_ty.toIntern(),
17681 .storage = .{ .elems = struct_field_vals },
17682 } });
17683 const ptr_ty = (try sema.ptrType(.{
17684 .child = struct_field_ty.toIntern(),
17685 .flags = .{
17686 .size = .Slice,
17687 .is_const = true,
17688 },
17689 })).toIntern();
1771817690 break :v try mod.intern(.{ .ptr = .{
17719 .ty = (try sema.ptrType(.{
17720 .child = struct_field_ty.toIntern(),
17721 .flags = .{
17722 .size = .Slice,
17723 .is_const = true,
17724 },
17725 })).toIntern(),
17726 .addr = .{ .decl = new_decl },
17691 .ty = ptr_ty,
17692 .addr = .{ .anon_decl = .{
17693 .orig_ty = ptr_ty,
17694 .val = new_decl_val,
17695 } },
1772717696 .len = (try mod.intValue(Type.usize, struct_field_vals.len)).toIntern(),
1772817697 } });
1772917698 };
......@@ -17819,9 +17788,6 @@ fn typeInfoDecls(
1781917788 const mod = sema.mod;
1782017789 const gpa = sema.gpa;
1782117790
17822 var decls_anon_decl = try block.startAnonDecl();
17823 defer decls_anon_decl.deinit();
17824
1782517791 const declaration_ty = t: {
1782617792 const declaration_ty_decl_index = (try sema.namespaceLookup(
1782717793 block,
......@@ -17851,23 +17817,23 @@ fn typeInfoDecls(
1785117817 .len = decl_vals.items.len,
1785217818 .child = declaration_ty.toIntern(),
1785317819 });
17854 const new_decl = try decls_anon_decl.finish(
17855 array_decl_ty,
17856 (try mod.intern(.{ .aggregate = .{
17857 .ty = array_decl_ty.toIntern(),
17858 .storage = .{ .elems = decl_vals.items },
17859 } })).toValue(),
17860 .none, // default alignment
17861 );
17820 const new_decl_val = try mod.intern(.{ .aggregate = .{
17821 .ty = array_decl_ty.toIntern(),
17822 .storage = .{ .elems = decl_vals.items },
17823 } });
17824 const ptr_ty = (try sema.ptrType(.{
17825 .child = declaration_ty.toIntern(),
17826 .flags = .{
17827 .size = .Slice,
17828 .is_const = true,
17829 },
17830 })).toIntern();
1786217831 return try mod.intern(.{ .ptr = .{
17863 .ty = (try sema.ptrType(.{
17864 .child = declaration_ty.toIntern(),
17865 .flags = .{
17866 .size = .Slice,
17867 .is_const = true,
17868 },
17869 })).toIntern(),
17870 .addr = .{ .decl = new_decl },
17832 .ty = ptr_ty,
17833 .addr = .{ .anon_decl = .{
17834 .orig_ty = ptr_ty,
17835 .val = new_decl_val,
17836 } },
1787117837 .len = (try mod.intValue(Type.usize, decl_vals.items.len)).toIntern(),
1787217838 } });
1787317839}
......@@ -17896,25 +17862,22 @@ fn typeInfoNamespaceDecls(
1789617862 }
1789717863 if (decl.kind != .named or !decl.is_pub) continue;
1789817864 const name_val = v: {
17899 var anon_decl = try block.startAnonDecl();
17900 defer anon_decl.deinit();
1790117865 // TODO: write something like getCoercedInts to avoid needing to dupe
1790217866 const name = try sema.arena.dupe(u8, ip.stringToSlice(decl.name));
1790317867 const new_decl_ty = try mod.arrayType(.{
1790417868 .len = name.len,
1790517869 .child = .u8_type,
1790617870 });
17907 const new_decl = try anon_decl.finish(
17908 new_decl_ty,
17909 (try mod.intern(.{ .aggregate = .{
17910 .ty = new_decl_ty.toIntern(),
17911 .storage = .{ .bytes = name },
17912 } })).toValue(),
17913 .none, // default alignment
17914 );
17871 const new_decl_val = try mod.intern(.{ .aggregate = .{
17872 .ty = new_decl_ty.toIntern(),
17873 .storage = .{ .bytes = name },
17874 } });
1791517875 break :v try mod.intern(.{ .ptr = .{
1791617876 .ty = .slice_const_u8_type,
17917 .addr = .{ .decl = new_decl },
17877 .addr = .{ .anon_decl = .{
17878 .orig_ty = .slice_const_u8_type,
17879 .val = new_decl_val,
17880 } },
1791817881 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
1791917882 } });
1792017883 };