| ... | @@ -1233,8 +1233,6 @@ fn walkInstruction( | ... | @@ -1233,8 +1233,6 @@ fn walkInstruction( |
| 1233 | .frame_type, | 1233 | .frame_type, |
| 1234 | .frame_size, | 1234 | .frame_size, |
| 1235 | .ptr_to_int, | 1235 | .ptr_to_int, |
| 1236 | .error_to_int, | | |
| 1237 | .int_to_error, | | |
| 1238 | .minimum, | 1236 | .minimum, |
| 1239 | .maximum, | 1237 | .maximum, |
| 1240 | .bit_not, | 1238 | .bit_not, |
| ... | @@ -2521,12 +2519,6 @@ fn walkInstruction( | ... | @@ -2521,12 +2519,6 @@ fn walkInstruction( |
| 2521 | } else null; | 2519 | } else null; |
| 2522 | _ = src_node; | 2520 | _ = src_node; |
| 2523 | | 2521 | |
| 2524 | const body_len = if (small.has_body_len) blk: { | | |
| 2525 | const body_len = file.zir.extra[extra_index]; | | |
| 2526 | extra_index += 1; | | |
| 2527 | break :blk body_len; | | |
| 2528 | } else 0; | | |
| 2529 | | | |
| 2530 | const fields_len = if (small.has_fields_len) blk: { | 2522 | const fields_len = if (small.has_fields_len) blk: { |
| 2531 | const fields_len = file.zir.extra[extra_index]; | 2523 | const fields_len = file.zir.extra[extra_index]; |
| 2532 | extra_index += 1; | 2524 | extra_index += 1; |
| ... | @@ -2570,9 +2562,6 @@ fn walkInstruction( | ... | @@ -2570,9 +2562,6 @@ fn walkInstruction( |
| 2570 | extra_index, | 2562 | extra_index, |
| 2571 | ); | 2563 | ); |
| 2572 | | 2564 | |
| 2573 | // const body = file.zir.extra[extra_index..][0..body_len]; | | |
| 2574 | extra_index += body_len; | | |
| 2575 | | | |
| 2576 | var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{}; | 2565 | var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{}; |
| 2577 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; | 2566 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 2578 | try self.collectStructFieldInfo( | 2567 | try self.collectStructFieldInfo( |
| ... | @@ -2614,6 +2603,24 @@ fn walkInstruction( | ... | @@ -2614,6 +2603,24 @@ fn walkInstruction( |
| 2614 | .expr = .{ .this = parent_scope.enclosing_type }, | 2603 | .expr = .{ .this = parent_scope.enclosing_type }, |
| 2615 | }; | 2604 | }; |
| 2616 | }, | 2605 | }, |
| | 2606 | .error_to_int, |
| | 2607 | .int_to_error, |
| | 2608 | => { |
| | 2609 | const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data; |
| | 2610 | const bin_index = self.exprs.items.len; |
| | 2611 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); |
| | 2612 | const param = try self.walkRef(file, parent_scope, extra.operand, false); |
| | 2613 | |
| | 2614 | const param_index = self.exprs.items.len; |
| | 2615 | try self.exprs.append(self.arena, param.expr); |
| | 2616 | |
| | 2617 | self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = param_index } }; |
| | 2618 | |
| | 2619 | return DocData.WalkResult{ |
| | 2620 | .typeRef = param.typeRef orelse .{ .type = @enumToInt(Ref.type_type) }, |
| | 2621 | .expr = .{ .builtinIndex = bin_index }, |
| | 2622 | }; |
| | 2623 | }, |
| 2617 | } | 2624 | } |
| 2618 | }, | 2625 | }, |
| 2619 | } | 2626 | } |
| ... | @@ -3627,6 +3634,17 @@ fn collectStructFieldInfo( | ... | @@ -3627,6 +3634,17 @@ fn collectStructFieldInfo( |
| 3627 | const bits_per_field = 4; | 3634 | const bits_per_field = 4; |
| 3628 | const fields_per_u32 = 32 / bits_per_field; | 3635 | const fields_per_u32 = 32 / bits_per_field; |
| 3629 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; | 3636 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; |
| | 3637 | |
| | 3638 | const Field = struct { |
| | 3639 | field_name: u32, |
| | 3640 | doc_comment_index: u32, |
| | 3641 | type_body_len: u32 = 0, |
| | 3642 | align_body_len: u32 = 0, |
| | 3643 | init_body_len: u32 = 0, |
| | 3644 | type_ref: Zir.Inst.Ref = .none, |
| | 3645 | }; |
| | 3646 | const fields = try self.arena.alloc(Field, fields_len); |
| | 3647 | |
| 3630 | var bit_bag_index: usize = extra_index; | 3648 | var bit_bag_index: usize = extra_index; |
| 3631 | extra_index += bit_bags_count; | 3649 | extra_index += bit_bags_count; |
| 3632 | | 3650 | |
| ... | @@ -3643,35 +3661,69 @@ fn collectStructFieldInfo( | ... | @@ -3643,35 +3661,69 @@ fn collectStructFieldInfo( |
| 3643 | cur_bit_bag >>= 1; | 3661 | cur_bit_bag >>= 1; |
| 3644 | // const is_comptime = @truncate(u1, cur_bit_bag) != 0; | 3662 | // const is_comptime = @truncate(u1, cur_bit_bag) != 0; |
| 3645 | cur_bit_bag >>= 1; | 3663 | cur_bit_bag >>= 1; |
| 3646 | const unused = @truncate(u1, cur_bit_bag) != 0; | 3664 | const has_type_body = @truncate(u1, cur_bit_bag) != 0; |
| 3647 | cur_bit_bag >>= 1; | 3665 | cur_bit_bag >>= 1; |
| 3648 | _ = unused; | | |
| 3649 | | 3666 | |
| 3650 | const field_name = file.zir.nullTerminatedString(file.zir.extra[extra_index]); | 3667 | const field_name = file.zir.extra[extra_index]; |
| 3651 | extra_index += 1; | | |
| 3652 | const field_type = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); | | |
| 3653 | extra_index += 1; | 3668 | extra_index += 1; |
| 3654 | const doc_comment_index = file.zir.extra[extra_index]; | 3669 | const doc_comment_index = file.zir.extra[extra_index]; |
| 3655 | extra_index += 1; | 3670 | extra_index += 1; |
| 3656 | | 3671 | |
| 3657 | if (has_align) extra_index += 1; | 3672 | fields[field_i] = .{ |
| 3658 | if (has_default) extra_index += 1; | 3673 | .field_name = field_name, |
| | 3674 | .doc_comment_index = doc_comment_index, |
| | 3675 | }; |
| 3659 | | 3676 | |
| 3660 | // type | 3677 | if (has_type_body) { |
| 3661 | { | 3678 | fields[field_i].type_body_len = file.zir.extra[extra_index]; |
| 3662 | const walk_result = try self.walkRef(file, scope, field_type, false); | 3679 | } else { |
| 3663 | try field_type_refs.append(self.arena, walk_result.expr); | 3680 | fields[field_i].type_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| | 3681 | } |
| | 3682 | extra_index += 1; |
| | 3683 | |
| | 3684 | if (has_align) { |
| | 3685 | fields[field_i].align_body_len = file.zir.extra[extra_index]; |
| | 3686 | extra_index += 1; |
| 3664 | } | 3687 | } |
| | 3688 | if (has_default) { |
| | 3689 | fields[field_i].init_body_len = file.zir.extra[extra_index]; |
| | 3690 | extra_index += 1; |
| | 3691 | } |
| | 3692 | } |
| | 3693 | |
| | 3694 | const data = file.zir.instructions.items(.data); |
| | 3695 | |
| | 3696 | for (fields) |field| { |
| | 3697 | const type_expr = expr: { |
| | 3698 | if (field.type_ref != .none) { |
| | 3699 | const walk_result = try self.walkRef(file, scope, field.type_ref, false); |
| | 3700 | break :expr walk_result.expr; |
| | 3701 | } |
| | 3702 | |
| | 3703 | std.debug.assert(field.type_body_len != 0); |
| | 3704 | const body = file.zir.extra[extra_index..][0..field.type_body_len]; |
| | 3705 | extra_index += body.len; |
| | 3706 | |
| | 3707 | const break_inst = body[body.len - 1]; |
| | 3708 | const operand = data[break_inst].@"break".operand; |
| | 3709 | const walk_result = try self.walkRef(file, scope, operand, false); |
| | 3710 | break :expr walk_result.expr; |
| | 3711 | }; |
| | 3712 | |
| | 3713 | extra_index += field.align_body_len; |
| | 3714 | extra_index += field.init_body_len; |
| | 3715 | |
| | 3716 | try field_type_refs.append(self.arena, type_expr); |
| 3665 | | 3717 | |
| 3666 | // ast node | 3718 | // ast node |
| 3667 | { | 3719 | { |
| 3668 | try field_name_indexes.append(self.arena, self.ast_nodes.items.len); | 3720 | try field_name_indexes.append(self.arena, self.ast_nodes.items.len); |
| 3669 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) | 3721 | const doc_comment: ?[]const u8 = if (field.doc_comment_index != 0) |
| 3670 | file.zir.nullTerminatedString(doc_comment_index) | 3722 | file.zir.nullTerminatedString(field.doc_comment_index) |
| 3671 | else | 3723 | else |
| 3672 | null; | 3724 | null; |
| 3673 | try self.ast_nodes.append(self.arena, .{ | 3725 | try self.ast_nodes.append(self.arena, .{ |
| 3674 | .name = field_name, | 3726 | .name = file.zir.nullTerminatedString(field.field_name), |
| 3675 | .docs = doc_comment, | 3727 | .docs = doc_comment, |
| 3676 | }); | 3728 | }); |
| 3677 | } | 3729 | } |