authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-23 19:10:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-25 19:57:02-07:00
log7a106645fd2075634682fa458988ab7c24803f8a
tree4f50f6d1328c89a18dfac3c1e7b8294e33bd6d92
parentcc394431ae6eb69e7abd677c268a8ab7299f8aeb

Sema: migrate `@src` to new anon decl mechanism


1 files changed, 34 insertions(+), 39 deletions(-)

src/Sema.zig+34-39
...@@ -5474,13 +5474,13 @@ fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref {...@@ -5474,13 +5474,13 @@ fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref {
5474 .address_space = .generic,5474 .address_space = .generic,
5475 },5475 },
5476 });5476 });
5477 return Air.internedToRef((try mod.intern(.{ .ptr = .{5477 return Air.internedToRef(try mod.intern(.{ .ptr = .{
5478 .ty = ptr_ty.toIntern(),5478 .ty = ptr_ty.toIntern(),
5479 .addr = .{ .anon_decl = .{5479 .addr = .{ .anon_decl = .{
5480 .val = val,5480 .val = val,
5481 .orig_ty = ptr_ty.toIntern(),5481 .orig_ty = ptr_ty.toIntern(),
5482 } },5482 } },
5483 } })));5483 } }));
5484}5484}
54855485
5486fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5486fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -16724,54 +16724,49 @@ fn zirBuiltinSrc(...@@ -16724,54 +16724,49 @@ fn zirBuiltinSrc(
16724 const src = LazySrcLoc.nodeOffset(extra.node);16724 const src = LazySrcLoc.nodeOffset(extra.node);
16725 if (sema.func_index == .none) return sema.fail(block, src, "@src outside function", .{});16725 if (sema.func_index == .none) return sema.fail(block, src, "@src outside function", .{});
16726 const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);16726 const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
16727 const ip = &mod.intern_pool;
16728 const gpa = sema.gpa;
1672716729
16728 const func_name_val = blk: {16730 const func_name_val = v: {
16729 var anon_decl = try block.startAnonDecl();16731 // This dupe prevents InternPool string pool memory from being reallocated
16730 defer anon_decl.deinit();16732 // while a reference exists.
16731 // TODO: write something like getCoercedInts to avoid needing to dupe16733 const bytes = try sema.arena.dupe(u8, ip.stringToSlice(fn_owner_decl.name));
16732 const name = try sema.arena.dupe(u8, mod.intern_pool.stringToSlice(fn_owner_decl.name));16734 const array_ty = try ip.get(gpa, .{ .array_type = .{
16733 const new_decl_ty = try mod.arrayType(.{16735 .len = bytes.len,
16734 .len = name.len,
16735 .sentinel = .zero_u8,16736 .sentinel = .zero_u8,
16736 .child = .u8_type,16737 .child = .u8_type,
16737 });16738 } });
16738 const new_decl = try anon_decl.finish(16739 break :v try ip.get(gpa, .{ .ptr = .{
16739 new_decl_ty,
16740 (try mod.intern(.{ .aggregate = .{
16741 .ty = new_decl_ty.toIntern(),
16742 .storage = .{ .bytes = name },
16743 } })).toValue(),
16744 .none, // default alignment
16745 );
16746 break :blk try mod.intern(.{ .ptr = .{
16747 .ty = .slice_const_u8_sentinel_0_type,16740 .ty = .slice_const_u8_sentinel_0_type,
16748 .addr = .{ .decl = new_decl },16741 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
16749 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),16742 .addr = .{ .anon_decl = .{
16743 .orig_ty = .slice_const_u8_sentinel_0_type,
16744 .val = try ip.get(gpa, .{ .aggregate = .{
16745 .ty = array_ty,
16746 .storage = .{ .bytes = bytes },
16747 } }),
16748 } },
16750 } });16749 } });
16751 };16750 };
1675216751
16753 const file_name_val = blk: {16752 const file_name_val = v: {
16754 var anon_decl = try block.startAnonDecl();
16755 defer anon_decl.deinit();
16756 // The compiler must not call realpath anywhere.16753 // The compiler must not call realpath anywhere.
16757 const name = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena);16754 const bytes = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena);
16758 const new_decl_ty = try mod.arrayType(.{16755 const array_ty = try ip.get(gpa, .{ .array_type = .{
16759 .len = name.len,16756 .len = bytes.len,
16760 .sentinel = .zero_u8,16757 .sentinel = .zero_u8,
16761 .child = .u8_type,16758 .child = .u8_type,
16762 });16759 } });
16763 const new_decl = try anon_decl.finish(16760 break :v try ip.get(gpa, .{ .ptr = .{
16764 new_decl_ty,
16765 (try mod.intern(.{ .aggregate = .{
16766 .ty = new_decl_ty.toIntern(),
16767 .storage = .{ .bytes = name },
16768 } })).toValue(),
16769 .none, // default alignment
16770 );
16771 break :blk try mod.intern(.{ .ptr = .{
16772 .ty = .slice_const_u8_sentinel_0_type,16761 .ty = .slice_const_u8_sentinel_0_type,
16773 .addr = .{ .decl = new_decl },16762 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
16774 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),16763 .addr = .{ .anon_decl = .{
16764 .orig_ty = .slice_const_u8_sentinel_0_type,
16765 .val = try ip.get(gpa, .{ .aggregate = .{
16766 .ty = array_ty,
16767 .storage = .{ .bytes = bytes },
16768 } }),
16769 } },
16775 } });16770 } });
16776 };16771 };
1677716772