4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
fn comptimeDecl(
astgen: *AstGen,
gz: *GenZir,
scope: *Scope,
wip_decls: *WipDecls,
node: Ast.Node.Index,
) InnerError!void {
const tree = astgen.tree;
const body_node = tree.nodeData(node).node;
const old_hasher = astgen.src_hasher;
defer astgen.src_hasher = old_hasher;
astgen.src_hasher = std.zig.SrcHasher.init(.{});
astgen.src_hasher.update(tree.getNodeSource(node));
astgen.src_hasher.update(std.mem.asBytes(&astgen.source_column));
// Up top so the ZIR instruction index marks the start range of this
// top-level declaration.
const decl_inst = try gz.makeDeclaration(node);
wip_decls.nextDecl(decl_inst);
astgen.advanceSourceCursorToNode(node);
// This is just needed for the `setDeclaration` call.
var dummy_gz = gz.makeSubBlock(scope);
defer dummy_gz.unstack();
var comptime_gz: GenZir = .{
.is_comptime = true,
.decl_node_index = node,
.decl_line = astgen.source_line,
.parent = scope,
.astgen = astgen,
.instructions = dummy_gz.instructions,
.instructions_top = dummy_gz.instructions.items.len,
};
defer comptime_gz.unstack();
const decl_column = astgen.source_column;
const block_result = try fullBodyExpr(&comptime_gz, &comptime_gz.base, .{ .rl = .none }, body_node, .normal);
if (comptime_gz.isEmpty() or !comptime_gz.refIsNoReturn(block_result)) {
_ = try comptime_gz.addBreak(.break_inline, decl_inst, .void_value);
}
var hash: std.zig.SrcHash = undefined;
astgen.src_hasher.final(&hash);
try setDeclaration(decl_inst, .{
.src_hash = hash,
.src_line = comptime_gz.decl_line,
.src_column = decl_column,
.kind = .@"comptime",
.name = .empty,
.is_pub = false,
.is_threadlocal = false,
.linkage = .normal,
.type_gz = &dummy_gz,
.align_gz = &dummy_gz,
.linksection_gz = &dummy_gz,
.addrspace_gz = &dummy_gz,
.value_gz = &comptime_gz,
});
}