authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-13 20:26:09-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-14 03:52:36-05:00
logf2f698a888afdc8709142912f8394376d28e16ea
treeec0077cb1fca066eb6a8ca678ca06b02b8fa22cb
parentb83ce08a3b51c58096ab0b2383212a2124794c82
signaturelock-open Commit is signed but in an unrecognized format.

rework comptime struct value layout, removing 1/2 hacks

in the implementation of anonymous struct literals

5 files changed, 277 insertions(+), 266 deletions(-)

src/all_types.hpp+1-1
...@@ -152,7 +152,7 @@ struct ConstParent {...@@ -152,7 +152,7 @@ struct ConstParent {
152};152};
153153
154struct ConstStructValue {154struct ConstStructValue {
155 ConstExprValue *fields;155 ConstExprValue **fields;
156};156};
157157
158struct ConstUnionValue {158struct ConstUnionValue {
src/analyze.cpp+29-12
...@@ -1461,8 +1461,8 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1461,8 +1461,8 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1461 if (type_is_invalid(result_val->type))1461 if (type_is_invalid(result_val->type))
1462 return false;1462 return false;
14631463
1464 ConstExprValue *ptr_field = &result_val->data.x_struct.fields[slice_ptr_index];1464 ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1465 ConstExprValue *len_field = &result_val->data.x_struct.fields[slice_len_index];1465 ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index];
14661466
1467 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);1467 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
1468 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;1468 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
...@@ -5283,7 +5283,7 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -5283,7 +5283,7 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
5283 zig_unreachable();5283 zig_unreachable();
5284 case ZigTypeIdStruct:5284 case ZigTypeIdStruct:
5285 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {5285 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
5286 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))5286 if (can_mutate_comptime_var_state(value->data.x_struct.fields[i]))
5287 return true;5287 return true;
5288 }5288 }
5289 return false;5289 return false;
...@@ -5798,11 +5798,11 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr...@@ -5798,11 +5798,11 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
57985798
5799 const_val->special = ConstValSpecialStatic;5799 const_val->special = ConstValSpecialStatic;
5800 const_val->type = get_slice_type(g, ptr_type);5800 const_val->type = get_slice_type(g, ptr_type);
5801 const_val->data.x_struct.fields = create_const_vals(2);5801 const_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
58025802
5803 init_const_ptr_array(g, &const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,5803 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
5804 PtrLenUnknown);5804 PtrLenUnknown);
5805 init_const_usize(g, &const_val->data.x_struct.fields[slice_len_index], len);5805 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);
5806}5806}
58075807
5808ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {5808ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {
...@@ -5886,6 +5886,23 @@ ConstExprValue *create_const_vals(size_t count) {...@@ -5886,6 +5886,23 @@ ConstExprValue *create_const_vals(size_t count) {
5886 return vals;5886 return vals;
5887}5887}
58885888
5889ConstExprValue **alloc_const_vals_ptrs(size_t count) {
5890 return realloc_const_vals_ptrs(nullptr, 0, count);
5891}
5892
5893ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count) {
5894 assert(new_count >= old_count);
5895
5896 size_t new_item_count = new_count - old_count;
5897 ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*");
5898 ConstExprValue *vals = create_const_vals(new_item_count);
5899 for (size_t i = old_count; i < new_count; i += 1) {
5900 result[i] = &vals[i - old_count];
5901 }
5902 return result;
5903}
5904
5905
5889static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {5906static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
5890 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)5907 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)
5891 return orig_fn_type;5908 return orig_fn_type;
...@@ -6567,8 +6584,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {...@@ -6567,8 +6584,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
6567 }6584 }
6568 case ZigTypeIdStruct:6585 case ZigTypeIdStruct:
6569 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {6586 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
6570 ConstExprValue *field_a = &a->data.x_struct.fields[i];6587 ConstExprValue *field_a = a->data.x_struct.fields[i];
6571 ConstExprValue *field_b = &b->data.x_struct.fields[i];6588 ConstExprValue *field_b = b->data.x_struct.fields[i];
6572 if (!const_values_equal(g, field_a, field_b))6589 if (!const_values_equal(g, field_a, field_b))
6573 return false;6590 return false;
6574 }6591 }
...@@ -6876,10 +6893,10 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -6876,10 +6893,10 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
6876 case ZigTypeIdStruct:6893 case ZigTypeIdStruct:
6877 {6894 {
6878 if (is_slice(type_entry)) {6895 if (is_slice(type_entry)) {
6879 ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index];6896 ConstExprValue *len_val = const_val->data.x_struct.fields[slice_len_index];
6880 size_t len = bigint_as_usize(&len_val->data.x_bigint);6897 size_t len = bigint_as_usize(&len_val->data.x_bigint);
68816898
6882 ConstExprValue *ptr_val = &const_val->data.x_struct.fields[slice_ptr_index];6899 ConstExprValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];
6883 if (ptr_val->special == ConstValSpecialUndef) {6900 if (ptr_val->special == ConstValSpecialUndef) {
6884 assert(len == 0);6901 assert(len == 0);
6885 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));6902 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));
...@@ -7156,9 +7173,9 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {...@@ -7156,9 +7173,9 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
71567173
7157 const_val->special = ConstValSpecialStatic;7174 const_val->special = ConstValSpecialStatic;
7158 size_t field_count = wanted_type->data.structure.src_field_count;7175 size_t field_count = wanted_type->data.structure.src_field_count;
7159 const_val->data.x_struct.fields = create_const_vals(field_count);7176 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
7160 for (size_t i = 0; i < field_count; i += 1) {7177 for (size_t i = 0; i < field_count; i += 1) {
7161 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];7178 ConstExprValue *field_val = const_val->data.x_struct.fields[i];
7162 field_val->type = resolve_struct_field_type(g, &wanted_type->data.structure.fields[i]);7179 field_val->type = resolve_struct_field_type(g, &wanted_type->data.structure.fields[i]);
7163 assert(field_val->type);7180 assert(field_val->type);
7164 init_const_undefined(g, field_val);7181 init_const_undefined(g, field_val);
src/analyze.hpp+2
...@@ -177,6 +177,8 @@ void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_inde...@@ -177,6 +177,8 @@ void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_inde
177ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);177ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
178178
179ConstExprValue *create_const_vals(size_t count);179ConstExprValue *create_const_vals(size_t count);
180ConstExprValue **alloc_const_vals_ptrs(size_t count);
181ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);
180182
181ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);183ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
182void expand_undef_array(CodeGen *g, ConstExprValue *const_val);184void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
src/codegen.cpp+8-8
...@@ -3508,7 +3508,7 @@ static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {...@@ -3508,7 +3508,7 @@ static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {
3508 case ConstValSpecialStatic:3508 case ConstValSpecialStatic:
3509 if (const_val->type->id == ZigTypeIdStruct) {3509 if (const_val->type->id == ZigTypeIdStruct) {
3510 for (size_t i = 0; i < const_val->type->data.structure.src_field_count; i += 1) {3510 for (size_t i = 0; i < const_val->type->data.structure.src_field_count; i += 1) {
3511 if (!value_is_all_undef(g, &const_val->data.x_struct.fields[i]))3511 if (!value_is_all_undef(g, const_val->data.x_struct.fields[i]))
3512 return false;3512 return false;
3513 }3513 }
3514 return true;3514 return true;
...@@ -6572,7 +6572,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -6572,7 +6572,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
6572 if (field->gen_index == SIZE_MAX) {6572 if (field->gen_index == SIZE_MAX) {
6573 continue;6573 continue;
6574 }6574 }
6575 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, &const_val->data.x_struct.fields[i]);6575 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, const_val->data.x_struct.fields[i]);
6576 uint32_t packed_bits_size = type_size_bits(g, field->type_entry);6576 uint32_t packed_bits_size = type_size_bits(g, field->type_entry);
6577 if (is_big_endian) {6577 if (is_big_endian) {
6578 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref, packed_bits_size, false);6578 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref, packed_bits_size, false);
...@@ -6840,7 +6840,7 @@ check: switch (const_val->special) {...@@ -6840,7 +6840,7 @@ check: switch (const_val->special) {
6840 }6840 }
68416841
6842 if (src_field_index + 1 == src_field_index_end) {6842 if (src_field_index + 1 == src_field_index_end) {
6843 ConstExprValue *field_val = &const_val->data.x_struct.fields[src_field_index];6843 ConstExprValue *field_val = const_val->data.x_struct.fields[src_field_index];
6844 LLVMValueRef val = gen_const_val(g, field_val, "");6844 LLVMValueRef val = gen_const_val(g, field_val, "");
6845 fields[type_struct_field->gen_index] = val;6845 fields[type_struct_field->gen_index] = val;
6846 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);6846 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);
...@@ -6858,7 +6858,7 @@ check: switch (const_val->special) {...@@ -6858,7 +6858,7 @@ check: switch (const_val->special) {
6858 continue;6858 continue;
6859 }6859 }
6860 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref,6860 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref,
6861 &const_val->data.x_struct.fields[i]);6861 const_val->data.x_struct.fields[i]);
6862 uint32_t packed_bits_size = type_size_bits(g, it_field->type_entry);6862 uint32_t packed_bits_size = type_size_bits(g, it_field->type_entry);
6863 if (is_big_endian) {6863 if (is_big_endian) {
6864 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref,6864 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref,
...@@ -6897,7 +6897,7 @@ check: switch (const_val->special) {...@@ -6897,7 +6897,7 @@ check: switch (const_val->special) {
6897 if (type_struct_field->gen_index == SIZE_MAX) {6897 if (type_struct_field->gen_index == SIZE_MAX) {
6898 continue;6898 continue;
6899 }6899 }
6900 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];6900 ConstExprValue *field_val = const_val->data.x_struct.fields[i];
6901 assert(field_val->type != nullptr);6901 assert(field_val->type != nullptr);
6902 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,6902 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
6903 type_struct_field->type_entry)))6903 type_struct_field->type_entry)))
...@@ -9074,13 +9074,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9074,13 +9074,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9074 this_val->parent.id = ConstParentIdArray;9074 this_val->parent.id = ConstParentIdArray;
9075 this_val->parent.data.p_array.array_val = test_fn_array;9075 this_val->parent.data.p_array.array_val = test_fn_array;
9076 this_val->parent.data.p_array.elem_index = i;9076 this_val->parent.data.p_array.elem_index = i;
9077 this_val->data.x_struct.fields = create_const_vals(2);9077 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
90789078
9079 ConstExprValue *name_field = &this_val->data.x_struct.fields[0];9079 ConstExprValue *name_field = this_val->data.x_struct.fields[0];
9080 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name);9080 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name);
9081 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);9081 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
90829082
9083 ConstExprValue *fn_field = &this_val->data.x_struct.fields[1];9083 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];
9084 fn_field->type = fn_type;9084 fn_field->type = fn_type;
9085 fn_field->special = ConstValSpecialStatic;9085 fn_field->special = ConstValSpecialStatic;
9086 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;9086 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
src/ir.cpp+237-245
...@@ -240,7 +240,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -240,7 +240,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
240 case ConstPtrSpecialBaseStruct: {240 case ConstPtrSpecialBaseStruct: {
241 ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;241 ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;
242 expand_undef_struct(g, struct_val);242 expand_undef_struct(g, struct_val);
243 result = &struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];243 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
244 break;244 break;
245 }245 }
246 case ConstPtrSpecialBaseErrorUnionCode:246 case ConstPtrSpecialBaseErrorUnionCode:
...@@ -10784,9 +10784,9 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -10784,9 +10784,9 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
10784 if (src->special != ConstValSpecialStatic)10784 if (src->special != ConstValSpecialStatic)
10785 return;10785 return;
10786 if (dest->type->id == ZigTypeIdStruct) {10786 if (dest->type->id == ZigTypeIdStruct) {
10787 dest->data.x_struct.fields = create_const_vals(dest->type->data.structure.src_field_count);10787 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
10788 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {10788 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
10789 copy_const_val(&dest->data.x_struct.fields[i], &src->data.x_struct.fields[i], false);10789 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false);
10790 }10790 }
10791 }10791 }
10792 }10792 }
...@@ -10982,8 +10982,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -10982,8 +10982,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1098210982
10983 IrInstruction *result = ir_const(ira, source_instr, wanted_type);10983 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
10984 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);10984 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);
10985 result->value.data.x_struct.fields[slice_ptr_index].data.x_ptr.mut =10985 result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = value->value.data.x_ptr.mut;
10986 value->value.data.x_ptr.mut;
10987 result->value.type = wanted_type;10986 result->value.type = wanted_type;
10988 return result;10987 return result;
10989 }10988 }
...@@ -13491,8 +13490,8 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13491,8 +13490,8 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13491 if (!const_val)13490 if (!const_val)
13492 return nullptr;13491 return nullptr;
1349313492
13494 ConstExprValue *ptr_field = &const_val->data.x_struct.fields[slice_ptr_index];13493 ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13495 ConstExprValue *len_field = &const_val->data.x_struct.fields[slice_len_index];13494 ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index];
1349613495
13497 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);13496 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
13498 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;13497 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
...@@ -14820,11 +14819,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14820,11 +14819,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14820 } else if (is_slice(op1_type)) {14819 } else if (is_slice(op1_type)) {
14821 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;14820 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
14822 child_type = ptr_type->data.pointer.child_type;14821 child_type = ptr_type->data.pointer.child_type;
14823 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];14822 ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];
14824 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);14823 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
14825 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;14824 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
14826 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;14825 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14827 ConstExprValue *len_val = &op1_val->data.x_struct.fields[slice_len_index];14826 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
14828 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);14827 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
14829 } else {14828 } else {
14830 ir_add_error(ira, op1,14829 ir_add_error(ira, op1,
...@@ -14853,11 +14852,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14853,11 +14852,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14853 } else if (is_slice(op2_type)) {14852 } else if (is_slice(op2_type)) {
14854 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;14853 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
14855 op2_type_valid = ptr_type->data.pointer.child_type == child_type;14854 op2_type_valid = ptr_type->data.pointer.child_type == child_type;
14856 ConstExprValue *ptr_val = &op2_val->data.x_struct.fields[slice_ptr_index];14855 ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];
14857 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);14856 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
14858 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;14857 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
14859 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;14858 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14860 ConstExprValue *len_val = &op2_val->data.x_struct.fields[slice_len_index];14859 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
14861 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);14860 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
14862 } else {14861 } else {
14863 ir_add_error(ira, op2,14862 ir_add_error(ira, op2,
...@@ -14889,17 +14888,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14889,17 +14888,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14889 out_array_val->special = ConstValSpecialStatic;14888 out_array_val->special = ConstValSpecialStatic;
14890 out_array_val->type = get_array_type(ira->codegen, child_type, new_len);14889 out_array_val->type = get_array_type(ira->codegen, child_type, new_len);
1489114890
14892 out_val->data.x_struct.fields = create_const_vals(2);14891 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
1489314892
14894 out_val->data.x_struct.fields[slice_ptr_index].type = ptr_type;14893 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;
14895 out_val->data.x_struct.fields[slice_ptr_index].special = ConstValSpecialStatic;14894 out_val->data.x_struct.fields[slice_ptr_index]->special = ConstValSpecialStatic;
14896 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.special = ConstPtrSpecialBaseArray;14895 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.special = ConstPtrSpecialBaseArray;
14897 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.array_val = out_array_val;14896 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.data.base_array.array_val = out_array_val;
14898 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.elem_index = 0;14897 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.data.base_array.elem_index = 0;
1489914898
14900 out_val->data.x_struct.fields[slice_len_index].type = ira->codegen->builtin_types.entry_usize;14899 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
14901 out_val->data.x_struct.fields[slice_len_index].special = ConstValSpecialStatic;14900 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
14902 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index].data.x_bigint, new_len);14901 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
14903 } else {14902 } else {
14904 new_len += 1; // null byte14903 new_len += 1; // null byte
1490514904
...@@ -16496,17 +16495,10 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16496,17 +16495,10 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16496 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,16495 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
16497 source_instr->source_node);16496 source_instr->source_node);
16498 struct_val->special = ConstValSpecialStatic;16497 struct_val->special = ConstValSpecialStatic;
16499 if (new_field_count > 16) {16498 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
16500 // This thing with 16 is a hack to allow this functionality to work without16499 old_field_count, new_field_count);
16501 // modifying the ConstExprValue layout of structs. That reworking needs to be
16502 // done, but this hack lets us do it separately, in the future.
16503 zig_panic("TODO need to rework the layout of ConstExprValue for structs. This realloc would have caused invalid pointer references");
16504 }
16505 if (struct_val->data.x_struct.fields == nullptr) {
16506 struct_val->data.x_struct.fields = create_const_vals(16);
16507 }
1650816500
16509 ConstExprValue *field_val = &struct_val->data.x_struct.fields[old_field_count];16501 ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count];
16510 field_val->special = ConstValSpecialUndef;16502 field_val->special = ConstValSpecialUndef;
16511 field_val->type = field->type_entry;16503 field_val->type = field->type_entry;
16512 field_val->parent.id = ConstParentIdStruct;16504 field_val->parent.id = ConstParentIdStruct;
...@@ -18156,7 +18148,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18156,7 +18148,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1815618148
18157 init_const_slice(ira->codegen, array_ptr_val, array_init_val, 0, actual_array_type->data.array.len,18149 init_const_slice(ira->codegen, array_ptr_val, array_init_val, 0, actual_array_type->data.array.len,
18158 false);18150 false);
18159 array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer;18151 array_ptr_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutInfer;
18160 } else {18152 } else {
18161 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,18153 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
18162 buf_sprintf("expected array type or [_], found '%s'",18154 buf_sprintf("expected array type or [_], found '%s'",
...@@ -18228,7 +18220,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18228,7 +18220,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18228 }18220 }
18229 return result;18221 return result;
18230 } else if (is_slice(array_type)) {18222 } else if (is_slice(array_type)) {
18231 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];18223 ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
18232 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);18224 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
18233 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {18225 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
18234 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,18226 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
...@@ -18237,7 +18229,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18237,7 +18229,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18237 result->value.type = return_type;18229 result->value.type = return_type;
18238 return result;18230 return result;
18239 }18231 }
18240 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];18232 ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
18241 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);18233 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18242 ConstExprValue *out_val = &result->value;18234 ConstExprValue *out_val = &result->value;
18243 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);18235 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
...@@ -18466,10 +18458,10 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18466,10 +18458,10 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18466 if (type_is_invalid(struct_val->type))18458 if (type_is_invalid(struct_val->type))
18467 return ira->codegen->invalid_instruction;18459 return ira->codegen->invalid_instruction;
18468 if (initializing && struct_val->special == ConstValSpecialUndef) {18460 if (initializing && struct_val->special == ConstValSpecialUndef) {
18469 struct_val->data.x_struct.fields = create_const_vals(struct_type->data.structure.src_field_count);18461 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
18470 struct_val->special = ConstValSpecialStatic;18462 struct_val->special = ConstValSpecialStatic;
18471 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {18463 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
18472 ConstExprValue *field_val = &struct_val->data.x_struct.fields[i];18464 ConstExprValue *field_val = struct_val->data.x_struct.fields[i];
18473 field_val->special = ConstValSpecialUndef;18465 field_val->special = ConstValSpecialUndef;
18474 field_val->type = resolve_struct_field_type(ira->codegen,18466 field_val->type = resolve_struct_field_type(ira->codegen,
18475 &struct_type->data.structure.fields[i]);18467 &struct_type->data.structure.fields[i]);
...@@ -21005,17 +20997,17 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21005,17 +20997,17 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21005 declaration_val->special = ConstValSpecialStatic;20997 declaration_val->special = ConstValSpecialStatic;
21006 declaration_val->type = type_info_declaration_type;20998 declaration_val->type = type_info_declaration_type;
2100720999
21008 ConstExprValue *inner_fields = create_const_vals(3);21000 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21009 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key);21001 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key);
21010 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(curr_entry->key), true);21002 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
21011 inner_fields[1].special = ConstValSpecialStatic;21003 inner_fields[1]->special = ConstValSpecialStatic;
21012 inner_fields[1].type = ira->codegen->builtin_types.entry_bool;21004 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
21013 inner_fields[1].data.x_bool = curr_entry->value->visib_mod == VisibModPub;21005 inner_fields[1]->data.x_bool = curr_entry->value->visib_mod == VisibModPub;
21014 inner_fields[2].special = ConstValSpecialStatic;21006 inner_fields[2]->special = ConstValSpecialStatic;
21015 inner_fields[2].type = type_info_declaration_data_type;21007 inner_fields[2]->type = type_info_declaration_data_type;
21016 inner_fields[2].parent.id = ConstParentIdStruct;21008 inner_fields[2]->parent.id = ConstParentIdStruct;
21017 inner_fields[2].parent.data.p_struct.struct_val = declaration_val;21009 inner_fields[2]->parent.data.p_struct.struct_val = declaration_val;
21018 inner_fields[2].parent.data.p_struct.field_index = 1;21010 inner_fields[2]->parent.data.p_struct.field_index = 1;
2101921011
21020 switch (curr_entry->value->id) {21012 switch (curr_entry->value->id) {
21021 case TldIdVar:21013 case TldIdVar:
...@@ -21027,19 +21019,19 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21027,19 +21019,19 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21027 if (var->const_value->type->id == ZigTypeIdMetaType) {21019 if (var->const_value->type->id == ZigTypeIdMetaType) {
21028 // We have a variable of type 'type', so it's actually a type declaration.21020 // We have a variable of type 'type', so it's actually a type declaration.
21029 // 0: Data.Type: type21021 // 0: Data.Type: type
21030 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);21022 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
21031 inner_fields[2].data.x_union.payload = var->const_value;21023 inner_fields[2]->data.x_union.payload = var->const_value;
21032 } else {21024 } else {
21033 // We have a variable of another type, so we store the type of the variable.21025 // We have a variable of another type, so we store the type of the variable.
21034 // 1: Data.Var: type21026 // 1: Data.Var: type
21035 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 1);21027 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2103621028
21037 ConstExprValue *payload = create_const_vals(1);21029 ConstExprValue *payload = create_const_vals(1);
21038 payload->special = ConstValSpecialStatic;21030 payload->special = ConstValSpecialStatic;
21039 payload->type = ira->codegen->builtin_types.entry_type;21031 payload->type = ira->codegen->builtin_types.entry_type;
21040 payload->data.x_type = var->const_value->type;21032 payload->data.x_type = var->const_value->type;
2104121033
21042 inner_fields[2].data.x_union.payload = payload;21034 inner_fields[2]->data.x_union.payload = payload;
21043 }21035 }
2104421036
21045 break;21037 break;
...@@ -21047,7 +21039,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21047,7 +21039,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21047 case TldIdFn:21039 case TldIdFn:
21048 {21040 {
21049 // 2: Data.Fn: Data.FnDecl21041 // 2: Data.Fn: Data.FnDecl
21050 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2);21042 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 2);
2105121043
21052 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;21044 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
21053 assert(!fn_entry->is_test);21045 assert(!fn_entry->is_test);
...@@ -21063,63 +21055,63 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21063,63 +21055,63 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21063 fn_decl_val->special = ConstValSpecialStatic;21055 fn_decl_val->special = ConstValSpecialStatic;
21064 fn_decl_val->type = type_info_fn_decl_type;21056 fn_decl_val->type = type_info_fn_decl_type;
21065 fn_decl_val->parent.id = ConstParentIdUnion;21057 fn_decl_val->parent.id = ConstParentIdUnion;
21066 fn_decl_val->parent.data.p_union.union_val = &inner_fields[2];21058 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2106721059
21068 ConstExprValue *fn_decl_fields = create_const_vals(9);21060 ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9);
21069 fn_decl_val->data.x_struct.fields = fn_decl_fields;21061 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2107021062
21071 // fn_type: type21063 // fn_type: type
21072 ensure_field_index(fn_decl_val->type, "fn_type", 0);21064 ensure_field_index(fn_decl_val->type, "fn_type", 0);
21073 fn_decl_fields[0].special = ConstValSpecialStatic;21065 fn_decl_fields[0]->special = ConstValSpecialStatic;
21074 fn_decl_fields[0].type = ira->codegen->builtin_types.entry_type;21066 fn_decl_fields[0]->type = ira->codegen->builtin_types.entry_type;
21075 fn_decl_fields[0].data.x_type = fn_entry->type_entry;21067 fn_decl_fields[0]->data.x_type = fn_entry->type_entry;
21076 // inline_type: Data.FnDecl.Inline21068 // inline_type: Data.FnDecl.Inline
21077 ensure_field_index(fn_decl_val->type, "inline_type", 1);21069 ensure_field_index(fn_decl_val->type, "inline_type", 1);
21078 fn_decl_fields[1].special = ConstValSpecialStatic;21070 fn_decl_fields[1]->special = ConstValSpecialStatic;
21079 fn_decl_fields[1].type = type_info_fn_decl_inline_type;21071 fn_decl_fields[1]->type = type_info_fn_decl_inline_type;
21080 bigint_init_unsigned(&fn_decl_fields[1].data.x_enum_tag, fn_entry->fn_inline);21072 bigint_init_unsigned(&fn_decl_fields[1]->data.x_enum_tag, fn_entry->fn_inline);
21081 // calling_convention: TypeInfo.CallingConvention21073 // calling_convention: TypeInfo.CallingConvention
21082 ensure_field_index(fn_decl_val->type, "calling_convention", 2);21074 ensure_field_index(fn_decl_val->type, "calling_convention", 2);
21083 fn_decl_fields[2].special = ConstValSpecialStatic;21075 fn_decl_fields[2]->special = ConstValSpecialStatic;
21084 fn_decl_fields[2].type = ir_type_info_get_type(ira, "CallingConvention", nullptr);21076 fn_decl_fields[2]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
21085 bigint_init_unsigned(&fn_decl_fields[2].data.x_enum_tag, fn_node->cc);21077 bigint_init_unsigned(&fn_decl_fields[2]->data.x_enum_tag, fn_node->cc);
21086 // is_var_args: bool21078 // is_var_args: bool
21087 ensure_field_index(fn_decl_val->type, "is_var_args", 3);21079 ensure_field_index(fn_decl_val->type, "is_var_args", 3);
21088 bool is_varargs = fn_node->is_var_args;21080 bool is_varargs = fn_node->is_var_args;
21089 fn_decl_fields[3].special = ConstValSpecialStatic;21081 fn_decl_fields[3]->special = ConstValSpecialStatic;
21090 fn_decl_fields[3].type = ira->codegen->builtin_types.entry_bool;21082 fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;
21091 fn_decl_fields[3].data.x_bool = is_varargs;21083 fn_decl_fields[3]->data.x_bool = is_varargs;
21092 // is_extern: bool21084 // is_extern: bool
21093 ensure_field_index(fn_decl_val->type, "is_extern", 4);21085 ensure_field_index(fn_decl_val->type, "is_extern", 4);
21094 fn_decl_fields[4].special = ConstValSpecialStatic;21086 fn_decl_fields[4]->special = ConstValSpecialStatic;
21095 fn_decl_fields[4].type = ira->codegen->builtin_types.entry_bool;21087 fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;
21096 fn_decl_fields[4].data.x_bool = fn_node->is_extern;21088 fn_decl_fields[4]->data.x_bool = fn_node->is_extern;
21097 // is_export: bool21089 // is_export: bool
21098 ensure_field_index(fn_decl_val->type, "is_export", 5);21090 ensure_field_index(fn_decl_val->type, "is_export", 5);
21099 fn_decl_fields[5].special = ConstValSpecialStatic;21091 fn_decl_fields[5]->special = ConstValSpecialStatic;
21100 fn_decl_fields[5].type = ira->codegen->builtin_types.entry_bool;21092 fn_decl_fields[5]->type = ira->codegen->builtin_types.entry_bool;
21101 fn_decl_fields[5].data.x_bool = fn_node->is_export;21093 fn_decl_fields[5]->data.x_bool = fn_node->is_export;
21102 // lib_name: ?[]const u821094 // lib_name: ?[]const u8
21103 ensure_field_index(fn_decl_val->type, "lib_name", 6);21095 ensure_field_index(fn_decl_val->type, "lib_name", 6);
21104 fn_decl_fields[6].special = ConstValSpecialStatic;21096 fn_decl_fields[6]->special = ConstValSpecialStatic;
21105 ZigType *u8_ptr = get_pointer_to_type_extra(21097 ZigType *u8_ptr = get_pointer_to_type_extra(
21106 ira->codegen, ira->codegen->builtin_types.entry_u8,21098 ira->codegen, ira->codegen->builtin_types.entry_u8,
21107 true, false, PtrLenUnknown,21099 true, false, PtrLenUnknown,
21108 0, 0, 0, false);21100 0, 0, 0, false);
21109 fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));21101 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
21110 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {21102 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
21111 fn_decl_fields[6].data.x_optional = create_const_vals(1);21103 fn_decl_fields[6]->data.x_optional = create_const_vals(1);
21112 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);21104 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
21113 init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0,21105 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
21114 buf_len(fn_node->lib_name), true);21106 buf_len(fn_node->lib_name), true);
21115 } else {21107 } else {
21116 fn_decl_fields[6].data.x_optional = nullptr;21108 fn_decl_fields[6]->data.x_optional = nullptr;
21117 }21109 }
21118 // return_type: type21110 // return_type: type
21119 ensure_field_index(fn_decl_val->type, "return_type", 7);21111 ensure_field_index(fn_decl_val->type, "return_type", 7);
21120 fn_decl_fields[7].special = ConstValSpecialStatic;21112 fn_decl_fields[7]->special = ConstValSpecialStatic;
21121 fn_decl_fields[7].type = ira->codegen->builtin_types.entry_type;21113 fn_decl_fields[7]->type = ira->codegen->builtin_types.entry_type;
21122 fn_decl_fields[7].data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;21114 fn_decl_fields[7]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
21123 // arg_names: [][] const u821115 // arg_names: [][] const u8
21124 ensure_field_index(fn_decl_val->type, "arg_names", 8);21116 ensure_field_index(fn_decl_val->type, "arg_names", 8);
21125 size_t fn_arg_count = fn_entry->variable_list.length;21117 size_t fn_arg_count = fn_entry->variable_list.length;
...@@ -21130,7 +21122,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21130,7 +21122,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21130 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;21122 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
21131 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);21123 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2113221124
21133 init_const_slice(ira->codegen, &fn_decl_fields[8], fn_arg_name_array, 0, fn_arg_count, false);21125 init_const_slice(ira->codegen, fn_decl_fields[8], fn_arg_name_array, 0, fn_arg_count, false);
2113421126
21135 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {21127 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
21136 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);21128 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
...@@ -21143,7 +21135,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21143,7 +21135,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21143 fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;21135 fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;
21144 }21136 }
2114521137
21146 inner_fields[2].data.x_union.payload = fn_decl_val;21138 inner_fields[2]->data.x_union.payload = fn_decl_val;
21147 break;21139 break;
21148 }21140 }
21149 case TldIdContainer:21141 case TldIdContainer:
...@@ -21153,14 +21145,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21153,14 +21145,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21153 return ErrorSemanticAnalyzeFail;21145 return ErrorSemanticAnalyzeFail;
2115421146
21155 // This is a type.21147 // This is a type.
21156 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);21148 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2115721149
21158 ConstExprValue *payload = create_const_vals(1);21150 ConstExprValue *payload = create_const_vals(1);
21159 payload->special = ConstValSpecialStatic;21151 payload->special = ConstValSpecialStatic;
21160 payload->type = ira->codegen->builtin_types.entry_type;21152 payload->type = ira->codegen->builtin_types.entry_type;
21161 payload->data.x_type = type_entry;21153 payload->data.x_type = type_entry;
2116221154
21163 inner_fields[2].data.x_union.payload = payload;21155 inner_fields[2]->data.x_union.payload = payload;
2116421156
21165 break;21157 break;
21166 }21158 }
...@@ -21169,7 +21161,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21169,7 +21161,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21169 }21161 }
2117021162
21171 declaration_val->data.x_struct.fields = inner_fields;21163 declaration_val->data.x_struct.fields = inner_fields;
21172 declaration_index++;21164 declaration_index += 1;
21173 }21165 }
2117421166
21175 assert(declaration_index == declaration_count);21167 assert(declaration_index == declaration_count);
...@@ -21225,42 +21217,42 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -21225,42 +21217,42 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
21225 result->special = ConstValSpecialStatic;21217 result->special = ConstValSpecialStatic;
21226 result->type = type_info_pointer_type;21218 result->type = type_info_pointer_type;
2122721219
21228 ConstExprValue *fields = create_const_vals(6);21220 ConstExprValue **fields = alloc_const_vals_ptrs(6);
21229 result->data.x_struct.fields = fields;21221 result->data.x_struct.fields = fields;
2123021222
21231 // size: Size21223 // size: Size
21232 ensure_field_index(result->type, "size", 0);21224 ensure_field_index(result->type, "size", 0);
21233 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);21225 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
21234 assertNoError(type_resolve(ira->codegen, type_info_pointer_size_type, ResolveStatusSizeKnown));21226 assertNoError(type_resolve(ira->codegen, type_info_pointer_size_type, ResolveStatusSizeKnown));
21235 fields[0].special = ConstValSpecialStatic;21227 fields[0]->special = ConstValSpecialStatic;
21236 fields[0].type = type_info_pointer_size_type;21228 fields[0]->type = type_info_pointer_size_type;
21237 bigint_init_unsigned(&fields[0].data.x_enum_tag, size_enum_index);21229 bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index);
2123821230
21239 // is_const: bool21231 // is_const: bool
21240 ensure_field_index(result->type, "is_const", 1);21232 ensure_field_index(result->type, "is_const", 1);
21241 fields[1].special = ConstValSpecialStatic;21233 fields[1]->special = ConstValSpecialStatic;
21242 fields[1].type = ira->codegen->builtin_types.entry_bool;21234 fields[1]->type = ira->codegen->builtin_types.entry_bool;
21243 fields[1].data.x_bool = attrs_type->data.pointer.is_const;21235 fields[1]->data.x_bool = attrs_type->data.pointer.is_const;
21244 // is_volatile: bool21236 // is_volatile: bool
21245 ensure_field_index(result->type, "is_volatile", 2);21237 ensure_field_index(result->type, "is_volatile", 2);
21246 fields[2].special = ConstValSpecialStatic;21238 fields[2]->special = ConstValSpecialStatic;
21247 fields[2].type = ira->codegen->builtin_types.entry_bool;21239 fields[2]->type = ira->codegen->builtin_types.entry_bool;
21248 fields[2].data.x_bool = attrs_type->data.pointer.is_volatile;21240 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
21249 // alignment: u3221241 // alignment: u32
21250 ensure_field_index(result->type, "alignment", 3);21242 ensure_field_index(result->type, "alignment", 3);
21251 fields[3].special = ConstValSpecialStatic;21243 fields[3]->special = ConstValSpecialStatic;
21252 fields[3].type = ira->codegen->builtin_types.entry_num_lit_int;21244 fields[3]->type = ira->codegen->builtin_types.entry_num_lit_int;
21253 bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type));21245 bigint_init_unsigned(&fields[3]->data.x_bigint, get_ptr_align(ira->codegen, attrs_type));
21254 // child: type21246 // child: type
21255 ensure_field_index(result->type, "child", 4);21247 ensure_field_index(result->type, "child", 4);
21256 fields[4].special = ConstValSpecialStatic;21248 fields[4]->special = ConstValSpecialStatic;
21257 fields[4].type = ira->codegen->builtin_types.entry_type;21249 fields[4]->type = ira->codegen->builtin_types.entry_type;
21258 fields[4].data.x_type = attrs_type->data.pointer.child_type;21250 fields[4]->data.x_type = attrs_type->data.pointer.child_type;
21259 // is_allowzero: bool21251 // is_allowzero: bool
21260 ensure_field_index(result->type, "is_allowzero", 5);21252 ensure_field_index(result->type, "is_allowzero", 5);
21261 fields[5].special = ConstValSpecialStatic;21253 fields[5]->special = ConstValSpecialStatic;
21262 fields[5].type = ira->codegen->builtin_types.entry_bool;21254 fields[5]->type = ira->codegen->builtin_types.entry_bool;
21263 fields[5].data.x_bool = attrs_type->data.pointer.allow_zero;21255 fields[5]->data.x_bool = attrs_type->data.pointer.allow_zero;
2126421256
21265 return result;21257 return result;
21266};21258};
...@@ -21271,14 +21263,14 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,...@@ -21271,14 +21263,14 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
21271 enum_field_val->special = ConstValSpecialStatic;21263 enum_field_val->special = ConstValSpecialStatic;
21272 enum_field_val->type = type_info_enum_field_type;21264 enum_field_val->type = type_info_enum_field_type;
2127321265
21274 ConstExprValue *inner_fields = create_const_vals(2);21266 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);
21275 inner_fields[1].special = ConstValSpecialStatic;21267 inner_fields[1]->special = ConstValSpecialStatic;
21276 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;21268 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2127721269
21278 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);21270 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
21279 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);21271 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2128021272
21281 bigint_init_bigint(&inner_fields[1].data.x_bigint, &enum_field->value);21273 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);
2128221274
21283 enum_field_val->data.x_struct.fields = inner_fields;21275 enum_field_val->data.x_struct.fields = inner_fields;
21284}21276}
...@@ -21322,19 +21314,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21322,19 +21314,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21322 result->special = ConstValSpecialStatic;21314 result->special = ConstValSpecialStatic;
21323 result->type = ir_type_info_get_type(ira, "Int", nullptr);21315 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2132421316
21325 ConstExprValue *fields = create_const_vals(2);21317 ConstExprValue **fields = alloc_const_vals_ptrs(2);
21326 result->data.x_struct.fields = fields;21318 result->data.x_struct.fields = fields;
2132721319
21328 // is_signed: bool21320 // is_signed: bool
21329 ensure_field_index(result->type, "is_signed", 0);21321 ensure_field_index(result->type, "is_signed", 0);
21330 fields[0].special = ConstValSpecialStatic;21322 fields[0]->special = ConstValSpecialStatic;
21331 fields[0].type = ira->codegen->builtin_types.entry_bool;21323 fields[0]->type = ira->codegen->builtin_types.entry_bool;
21332 fields[0].data.x_bool = type_entry->data.integral.is_signed;21324 fields[0]->data.x_bool = type_entry->data.integral.is_signed;
21333 // bits: u821325 // bits: u8
21334 ensure_field_index(result->type, "bits", 1);21326 ensure_field_index(result->type, "bits", 1);
21335 fields[1].special = ConstValSpecialStatic;21327 fields[1]->special = ConstValSpecialStatic;
21336 fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;21328 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
21337 bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);21329 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count);
2133821330
21339 break;21331 break;
21340 }21332 }
...@@ -21344,14 +21336,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21344,14 +21336,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21344 result->special = ConstValSpecialStatic;21336 result->special = ConstValSpecialStatic;
21345 result->type = ir_type_info_get_type(ira, "Float", nullptr);21337 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2134621338
21347 ConstExprValue *fields = create_const_vals(1);21339 ConstExprValue **fields = alloc_const_vals_ptrs(1);
21348 result->data.x_struct.fields = fields;21340 result->data.x_struct.fields = fields;
2134921341
21350 // bits: u821342 // bits: u8
21351 ensure_field_index(result->type, "bits", 0);21343 ensure_field_index(result->type, "bits", 0);
21352 fields[0].special = ConstValSpecialStatic;21344 fields[0]->special = ConstValSpecialStatic;
21353 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;21345 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21354 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);21346 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count);
2135521347
21356 break;21348 break;
21357 }21349 }
...@@ -21368,19 +21360,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21368,19 +21360,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21368 result->special = ConstValSpecialStatic;21360 result->special = ConstValSpecialStatic;
21369 result->type = ir_type_info_get_type(ira, "Array", nullptr);21361 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2137021362
21371 ConstExprValue *fields = create_const_vals(2);21363 ConstExprValue **fields = alloc_const_vals_ptrs(2);
21372 result->data.x_struct.fields = fields;21364 result->data.x_struct.fields = fields;
2137321365
21374 // len: usize21366 // len: usize
21375 ensure_field_index(result->type, "len", 0);21367 ensure_field_index(result->type, "len", 0);
21376 fields[0].special = ConstValSpecialStatic;21368 fields[0]->special = ConstValSpecialStatic;
21377 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;21369 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21378 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);21370 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len);
21379 // child: type21371 // child: type
21380 ensure_field_index(result->type, "child", 1);21372 ensure_field_index(result->type, "child", 1);
21381 fields[1].special = ConstValSpecialStatic;21373 fields[1]->special = ConstValSpecialStatic;
21382 fields[1].type = ira->codegen->builtin_types.entry_type;21374 fields[1]->type = ira->codegen->builtin_types.entry_type;
21383 fields[1].data.x_type = type_entry->data.array.child_type;21375 fields[1]->data.x_type = type_entry->data.array.child_type;
2138421376
21385 break;21377 break;
21386 }21378 }
...@@ -21389,19 +21381,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21389,19 +21381,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21389 result->special = ConstValSpecialStatic;21381 result->special = ConstValSpecialStatic;
21390 result->type = ir_type_info_get_type(ira, "Vector", nullptr);21382 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2139121383
21392 ConstExprValue *fields = create_const_vals(2);21384 ConstExprValue **fields = alloc_const_vals_ptrs(2);
21393 result->data.x_struct.fields = fields;21385 result->data.x_struct.fields = fields;
2139421386
21395 // len: usize21387 // len: usize
21396 ensure_field_index(result->type, "len", 0);21388 ensure_field_index(result->type, "len", 0);
21397 fields[0].special = ConstValSpecialStatic;21389 fields[0]->special = ConstValSpecialStatic;
21398 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;21390 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21399 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len);21391 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len);
21400 // child: type21392 // child: type
21401 ensure_field_index(result->type, "child", 1);21393 ensure_field_index(result->type, "child", 1);
21402 fields[1].special = ConstValSpecialStatic;21394 fields[1]->special = ConstValSpecialStatic;
21403 fields[1].type = ira->codegen->builtin_types.entry_type;21395 fields[1]->type = ira->codegen->builtin_types.entry_type;
21404 fields[1].data.x_type = type_entry->data.vector.elem_type;21396 fields[1]->data.x_type = type_entry->data.vector.elem_type;
2140521397
21406 break;21398 break;
21407 }21399 }
...@@ -21411,14 +21403,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21411,14 +21403,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21411 result->special = ConstValSpecialStatic;21403 result->special = ConstValSpecialStatic;
21412 result->type = ir_type_info_get_type(ira, "Optional", nullptr);21404 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2141321405
21414 ConstExprValue *fields = create_const_vals(1);21406 ConstExprValue **fields = alloc_const_vals_ptrs(1);
21415 result->data.x_struct.fields = fields;21407 result->data.x_struct.fields = fields;
2141621408
21417 // child: type21409 // child: type
21418 ensure_field_index(result->type, "child", 0);21410 ensure_field_index(result->type, "child", 0);
21419 fields[0].special = ConstValSpecialStatic;21411 fields[0]->special = ConstValSpecialStatic;
21420 fields[0].type = ira->codegen->builtin_types.entry_type;21412 fields[0]->type = ira->codegen->builtin_types.entry_type;
21421 fields[0].data.x_type = type_entry->data.maybe.child_type;21413 fields[0]->data.x_type = type_entry->data.maybe.child_type;
2142221414
21423 break;21415 break;
21424 }21416 }
...@@ -21427,14 +21419,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21427,14 +21419,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21427 result->special = ConstValSpecialStatic;21419 result->special = ConstValSpecialStatic;
21428 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);21420 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2142921421
21430 ConstExprValue *fields = create_const_vals(1);21422 ConstExprValue **fields = alloc_const_vals_ptrs(1);
21431 result->data.x_struct.fields = fields;21423 result->data.x_struct.fields = fields;
2143221424
21433 // child: ?type21425 // child: ?type
21434 ensure_field_index(result->type, "child", 0);21426 ensure_field_index(result->type, "child", 0);
21435 fields[0].special = ConstValSpecialStatic;21427 fields[0]->special = ConstValSpecialStatic;
21436 fields[0].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);21428 fields[0]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21437 fields[0].data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :21429 fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :
21438 create_const_type(ira->codegen, type_entry->data.any_frame.result_type);21430 create_const_type(ira->codegen, type_entry->data.any_frame.result_type);
21439 break;21431 break;
21440 }21432 }
...@@ -21444,19 +21436,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21444,19 +21436,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21444 result->special = ConstValSpecialStatic;21436 result->special = ConstValSpecialStatic;
21445 result->type = ir_type_info_get_type(ira, "Enum", nullptr);21437 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2144621438
21447 ConstExprValue *fields = create_const_vals(4);21439 ConstExprValue **fields = alloc_const_vals_ptrs(4);
21448 result->data.x_struct.fields = fields;21440 result->data.x_struct.fields = fields;
2144921441
21450 // layout: ContainerLayout21442 // layout: ContainerLayout
21451 ensure_field_index(result->type, "layout", 0);21443 ensure_field_index(result->type, "layout", 0);
21452 fields[0].special = ConstValSpecialStatic;21444 fields[0]->special = ConstValSpecialStatic;
21453 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);21445 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21454 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.enumeration.layout);21446 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.enumeration.layout);
21455 // tag_type: type21447 // tag_type: type
21456 ensure_field_index(result->type, "tag_type", 1);21448 ensure_field_index(result->type, "tag_type", 1);
21457 fields[1].special = ConstValSpecialStatic;21449 fields[1]->special = ConstValSpecialStatic;
21458 fields[1].type = ira->codegen->builtin_types.entry_type;21450 fields[1]->type = ira->codegen->builtin_types.entry_type;
21459 fields[1].data.x_type = type_entry->data.enumeration.tag_int_type;21451 fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type;
21460 // fields: []TypeInfo.EnumField21452 // fields: []TypeInfo.EnumField
21461 ensure_field_index(result->type, "fields", 2);21453 ensure_field_index(result->type, "fields", 2);
2146221454
...@@ -21472,7 +21464,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21472,7 +21464,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21472 enum_field_array->data.x_array.special = ConstArraySpecialNone;21464 enum_field_array->data.x_array.special = ConstArraySpecialNone;
21473 enum_field_array->data.x_array.data.s_none.elements = create_const_vals(enum_field_count);21465 enum_field_array->data.x_array.data.s_none.elements = create_const_vals(enum_field_count);
2147421466
21475 init_const_slice(ira->codegen, &fields[2], enum_field_array, 0, enum_field_count, false);21467 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false);
2147621468
21477 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)21469 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
21478 {21470 {
...@@ -21485,7 +21477,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21485,7 +21477,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21485 }21477 }
21486 // decls: []TypeInfo.Declaration21478 // decls: []TypeInfo.Declaration
21487 ensure_field_index(result->type, "decls", 3);21479 ensure_field_index(result->type, "decls", 3);
21488 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[3],21480 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
21489 type_entry->data.enumeration.decls_scope)))21481 type_entry->data.enumeration.decls_scope)))
21490 {21482 {
21491 return err;21483 return err;
...@@ -21528,17 +21520,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21528,17 +21520,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21528 error_val->special = ConstValSpecialStatic;21520 error_val->special = ConstValSpecialStatic;
21529 error_val->type = type_info_error_type;21521 error_val->type = type_info_error_type;
2153021522
21531 ConstExprValue *inner_fields = create_const_vals(2);21523 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);
21532 inner_fields[1].special = ConstValSpecialStatic;21524 inner_fields[1]->special = ConstValSpecialStatic;
21533 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;21525 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2153421526
21535 ConstExprValue *name = nullptr;21527 ConstExprValue *name = nullptr;
21536 if (error->cached_error_name_val != nullptr)21528 if (error->cached_error_name_val != nullptr)
21537 name = error->cached_error_name_val;21529 name = error->cached_error_name_val;
21538 if (name == nullptr)21530 if (name == nullptr)
21539 name = create_const_str_lit(ira->codegen, &error->name);21531 name = create_const_str_lit(ira->codegen, &error->name);
21540 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(&error->name), true);21532 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true);
21541 bigint_init_unsigned(&inner_fields[1].data.x_bigint, error->value);21533 bigint_init_unsigned(&inner_fields[1]->data.x_bigint, error->value);
2154221534
21543 error_val->data.x_struct.fields = inner_fields;21535 error_val->data.x_struct.fields = inner_fields;
21544 error_val->parent.id = ConstParentIdArray;21536 error_val->parent.id = ConstParentIdArray;
...@@ -21554,20 +21546,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21554,20 +21546,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21554 result->special = ConstValSpecialStatic;21546 result->special = ConstValSpecialStatic;
21555 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);21547 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2155621548
21557 ConstExprValue *fields = create_const_vals(2);21549 ConstExprValue **fields = alloc_const_vals_ptrs(2);
21558 result->data.x_struct.fields = fields;21550 result->data.x_struct.fields = fields;
2155921551
21560 // error_set: type21552 // error_set: type
21561 ensure_field_index(result->type, "error_set", 0);21553 ensure_field_index(result->type, "error_set", 0);
21562 fields[0].special = ConstValSpecialStatic;21554 fields[0]->special = ConstValSpecialStatic;
21563 fields[0].type = ira->codegen->builtin_types.entry_type;21555 fields[0]->type = ira->codegen->builtin_types.entry_type;
21564 fields[0].data.x_type = type_entry->data.error_union.err_set_type;21556 fields[0]->data.x_type = type_entry->data.error_union.err_set_type;
2156521557
21566 // payload: type21558 // payload: type
21567 ensure_field_index(result->type, "payload", 1);21559 ensure_field_index(result->type, "payload", 1);
21568 fields[1].special = ConstValSpecialStatic;21560 fields[1]->special = ConstValSpecialStatic;
21569 fields[1].type = ira->codegen->builtin_types.entry_type;21561 fields[1]->type = ira->codegen->builtin_types.entry_type;
21570 fields[1].data.x_type = type_entry->data.error_union.payload_type;21562 fields[1]->data.x_type = type_entry->data.error_union.payload_type;
2157121563
21572 break;21564 break;
21573 }21565 }
...@@ -21577,18 +21569,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21577,18 +21569,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21577 result->special = ConstValSpecialStatic;21569 result->special = ConstValSpecialStatic;
21578 result->type = ir_type_info_get_type(ira, "Union", nullptr);21570 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2157921571
21580 ConstExprValue *fields = create_const_vals(4);21572 ConstExprValue **fields = alloc_const_vals_ptrs(4);
21581 result->data.x_struct.fields = fields;21573 result->data.x_struct.fields = fields;
2158221574
21583 // layout: ContainerLayout21575 // layout: ContainerLayout
21584 ensure_field_index(result->type, "layout", 0);21576 ensure_field_index(result->type, "layout", 0);
21585 fields[0].special = ConstValSpecialStatic;21577 fields[0]->special = ConstValSpecialStatic;
21586 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);21578 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21587 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.unionation.layout);21579 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.unionation.layout);
21588 // tag_type: ?type21580 // tag_type: ?type
21589 ensure_field_index(result->type, "tag_type", 1);21581 ensure_field_index(result->type, "tag_type", 1);
21590 fields[1].special = ConstValSpecialStatic;21582 fields[1]->special = ConstValSpecialStatic;
21591 fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);21583 fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2159221584
21593 AstNode *union_decl_node = type_entry->data.unionation.decl_node;21585 AstNode *union_decl_node = type_entry->data.unionation.decl_node;
21594 if (union_decl_node->data.container_decl.auto_enum ||21586 if (union_decl_node->data.container_decl.auto_enum ||
...@@ -21598,9 +21590,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21598,9 +21590,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21598 tag_type->special = ConstValSpecialStatic;21590 tag_type->special = ConstValSpecialStatic;
21599 tag_type->type = ira->codegen->builtin_types.entry_type;21591 tag_type->type = ira->codegen->builtin_types.entry_type;
21600 tag_type->data.x_type = type_entry->data.unionation.tag_type;21592 tag_type->data.x_type = type_entry->data.unionation.tag_type;
21601 fields[1].data.x_optional = tag_type;21593 fields[1]->data.x_optional = tag_type;
21602 } else {21594 } else {
21603 fields[1].data.x_optional = nullptr;21595 fields[1]->data.x_optional = nullptr;
21604 }21596 }
21605 // fields: []TypeInfo.UnionField21597 // fields: []TypeInfo.UnionField
21606 ensure_field_index(result->type, "fields", 2);21598 ensure_field_index(result->type, "fields", 2);
...@@ -21616,7 +21608,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21616,7 +21608,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21616 union_field_array->data.x_array.special = ConstArraySpecialNone;21608 union_field_array->data.x_array.special = ConstArraySpecialNone;
21617 union_field_array->data.x_array.data.s_none.elements = create_const_vals(union_field_count);21609 union_field_array->data.x_array.data.s_none.elements = create_const_vals(union_field_count);
2161821610
21619 init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false);21611 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false);
2162021612
21621 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);21613 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
2162221614
...@@ -21627,23 +21619,23 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21627,23 +21619,23 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21627 union_field_val->special = ConstValSpecialStatic;21619 union_field_val->special = ConstValSpecialStatic;
21628 union_field_val->type = type_info_union_field_type;21620 union_field_val->type = type_info_union_field_type;
2162921621
21630 ConstExprValue *inner_fields = create_const_vals(3);21622 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21631 inner_fields[1].special = ConstValSpecialStatic;21623 inner_fields[1]->special = ConstValSpecialStatic;
21632 inner_fields[1].type = get_optional_type(ira->codegen, type_info_enum_field_type);21624 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2163321625
21634 if (fields[1].data.x_optional == nullptr) {21626 if (fields[1]->data.x_optional == nullptr) {
21635 inner_fields[1].data.x_optional = nullptr;21627 inner_fields[1]->data.x_optional = nullptr;
21636 } else {21628 } else {
21637 inner_fields[1].data.x_optional = create_const_vals(1);21629 inner_fields[1]->data.x_optional = create_const_vals(1);
21638 make_enum_field_val(ira, inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);21630 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);
21639 }21631 }
2164021632
21641 inner_fields[2].special = ConstValSpecialStatic;21633 inner_fields[2]->special = ConstValSpecialStatic;
21642 inner_fields[2].type = ira->codegen->builtin_types.entry_type;21634 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21643 inner_fields[2].data.x_type = union_field->type_entry;21635 inner_fields[2]->data.x_type = union_field->type_entry;
2164421636
21645 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name);21637 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name);
21646 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(union_field->name), true);21638 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2164721639
21648 union_field_val->data.x_struct.fields = inner_fields;21640 union_field_val->data.x_struct.fields = inner_fields;
21649 union_field_val->parent.id = ConstParentIdArray;21641 union_field_val->parent.id = ConstParentIdArray;
...@@ -21652,7 +21644,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21652,7 +21644,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21652 }21644 }
21653 // decls: []TypeInfo.Declaration21645 // decls: []TypeInfo.Declaration
21654 ensure_field_index(result->type, "decls", 3);21646 ensure_field_index(result->type, "decls", 3);
21655 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[3],21647 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
21656 type_entry->data.unionation.decls_scope)))21648 type_entry->data.unionation.decls_scope)))
21657 {21649 {
21658 return err;21650 return err;
...@@ -21673,14 +21665,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21673,14 +21665,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21673 result->special = ConstValSpecialStatic;21665 result->special = ConstValSpecialStatic;
21674 result->type = ir_type_info_get_type(ira, "Struct", nullptr);21666 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2167521667
21676 ConstExprValue *fields = create_const_vals(3);21668 ConstExprValue **fields = alloc_const_vals_ptrs(3);
21677 result->data.x_struct.fields = fields;21669 result->data.x_struct.fields = fields;
2167821670
21679 // layout: ContainerLayout21671 // layout: ContainerLayout
21680 ensure_field_index(result->type, "layout", 0);21672 ensure_field_index(result->type, "layout", 0);
21681 fields[0].special = ConstValSpecialStatic;21673 fields[0]->special = ConstValSpecialStatic;
21682 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);21674 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21683 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.structure.layout);21675 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.structure.layout);
21684 // fields: []TypeInfo.StructField21676 // fields: []TypeInfo.StructField
21685 ensure_field_index(result->type, "fields", 1);21677 ensure_field_index(result->type, "fields", 1);
2168621678
...@@ -21696,7 +21688,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21696,7 +21688,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21696 struct_field_array->data.x_array.special = ConstArraySpecialNone;21688 struct_field_array->data.x_array.special = ConstArraySpecialNone;
21697 struct_field_array->data.x_array.data.s_none.elements = create_const_vals(struct_field_count);21689 struct_field_array->data.x_array.data.s_none.elements = create_const_vals(struct_field_count);
2169821690
21699 init_const_slice(ira->codegen, &fields[1], struct_field_array, 0, struct_field_count, false);21691 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false);
2170021692
21701 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {21693 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
21702 TypeStructField *struct_field = &type_entry->data.structure.fields[struct_field_index];21694 TypeStructField *struct_field = &type_entry->data.structure.fields[struct_field_index];
...@@ -21705,9 +21697,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21705,9 +21697,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21705 struct_field_val->special = ConstValSpecialStatic;21697 struct_field_val->special = ConstValSpecialStatic;
21706 struct_field_val->type = type_info_struct_field_type;21698 struct_field_val->type = type_info_struct_field_type;
2170721699
21708 ConstExprValue *inner_fields = create_const_vals(3);21700 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21709 inner_fields[1].special = ConstValSpecialStatic;21701 inner_fields[1]->special = ConstValSpecialStatic;
21710 inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);21702 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2171121703
21712 ZigType *field_type = resolve_struct_field_type(ira->codegen, struct_field);21704 ZigType *field_type = resolve_struct_field_type(ira->codegen, struct_field);
21713 if (field_type == nullptr)21705 if (field_type == nullptr)
...@@ -21715,21 +21707,21 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21715,21 +21707,21 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21715 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))21707 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
21716 return err;21708 return err;
21717 if (!type_has_bits(struct_field->type_entry)) {21709 if (!type_has_bits(struct_field->type_entry)) {
21718 inner_fields[1].data.x_optional = nullptr;21710 inner_fields[1]->data.x_optional = nullptr;
21719 } else {21711 } else {
21720 size_t byte_offset = struct_field->offset;21712 size_t byte_offset = struct_field->offset;
21721 inner_fields[1].data.x_optional = create_const_vals(1);21713 inner_fields[1]->data.x_optional = create_const_vals(1);
21722 inner_fields[1].data.x_optional->special = ConstValSpecialStatic;21714 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
21723 inner_fields[1].data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;21715 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
21724 bigint_init_unsigned(&inner_fields[1].data.x_optional->data.x_bigint, byte_offset);21716 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);
21725 }21717 }
2172621718
21727 inner_fields[2].special = ConstValSpecialStatic;21719 inner_fields[2]->special = ConstValSpecialStatic;
21728 inner_fields[2].type = ira->codegen->builtin_types.entry_type;21720 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21729 inner_fields[2].data.x_type = struct_field->type_entry;21721 inner_fields[2]->data.x_type = struct_field->type_entry;
2173021722
21731 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name);21723 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name);
21732 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(struct_field->name), true);21724 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2173321725
21734 struct_field_val->data.x_struct.fields = inner_fields;21726 struct_field_val->data.x_struct.fields = inner_fields;
21735 struct_field_val->parent.id = ConstParentIdArray;21727 struct_field_val->parent.id = ConstParentIdArray;
...@@ -21738,7 +21730,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21738,7 +21730,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21738 }21730 }
21739 // decls: []TypeInfo.Declaration21731 // decls: []TypeInfo.Declaration
21740 ensure_field_index(result->type, "decls", 2);21732 ensure_field_index(result->type, "decls", 2);
21741 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[2],21733 if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
21742 type_entry->data.structure.decls_scope)))21734 type_entry->data.structure.decls_scope)))
21743 {21735 {
21744 return err;21736 return err;
...@@ -21752,38 +21744,38 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21752,38 +21744,38 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21752 result->special = ConstValSpecialStatic;21744 result->special = ConstValSpecialStatic;
21753 result->type = ir_type_info_get_type(ira, "Fn", nullptr);21745 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2175421746
21755 ConstExprValue *fields = create_const_vals(5);21747 ConstExprValue **fields = alloc_const_vals_ptrs(5);
21756 result->data.x_struct.fields = fields;21748 result->data.x_struct.fields = fields;
2175721749
21758 // calling_convention: TypeInfo.CallingConvention21750 // calling_convention: TypeInfo.CallingConvention
21759 ensure_field_index(result->type, "calling_convention", 0);21751 ensure_field_index(result->type, "calling_convention", 0);
21760 fields[0].special = ConstValSpecialStatic;21752 fields[0]->special = ConstValSpecialStatic;
21761 fields[0].type = ir_type_info_get_type(ira, "CallingConvention", nullptr);21753 fields[0]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
21762 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);21754 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
21763 // is_generic: bool21755 // is_generic: bool
21764 ensure_field_index(result->type, "is_generic", 1);21756 ensure_field_index(result->type, "is_generic", 1);
21765 bool is_generic = type_entry->data.fn.is_generic;21757 bool is_generic = type_entry->data.fn.is_generic;
21766 fields[1].special = ConstValSpecialStatic;21758 fields[1]->special = ConstValSpecialStatic;
21767 fields[1].type = ira->codegen->builtin_types.entry_bool;21759 fields[1]->type = ira->codegen->builtin_types.entry_bool;
21768 fields[1].data.x_bool = is_generic;21760 fields[1]->data.x_bool = is_generic;
21769 // is_varargs: bool21761 // is_varargs: bool
21770 ensure_field_index(result->type, "is_var_args", 2);21762 ensure_field_index(result->type, "is_var_args", 2);
21771 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;21763 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
21772 fields[2].special = ConstValSpecialStatic;21764 fields[2]->special = ConstValSpecialStatic;
21773 fields[2].type = ira->codegen->builtin_types.entry_bool;21765 fields[2]->type = ira->codegen->builtin_types.entry_bool;
21774 fields[2].data.x_bool = type_entry->data.fn.fn_type_id.is_var_args;21766 fields[2]->data.x_bool = type_entry->data.fn.fn_type_id.is_var_args;
21775 // return_type: ?type21767 // return_type: ?type
21776 ensure_field_index(result->type, "return_type", 3);21768 ensure_field_index(result->type, "return_type", 3);
21777 fields[3].special = ConstValSpecialStatic;21769 fields[3]->special = ConstValSpecialStatic;
21778 fields[3].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);21770 fields[3]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21779 if (type_entry->data.fn.fn_type_id.return_type == nullptr)21771 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
21780 fields[3].data.x_optional = nullptr;21772 fields[3]->data.x_optional = nullptr;
21781 else {21773 else {
21782 ConstExprValue *return_type = create_const_vals(1);21774 ConstExprValue *return_type = create_const_vals(1);
21783 return_type->special = ConstValSpecialStatic;21775 return_type->special = ConstValSpecialStatic;
21784 return_type->type = ira->codegen->builtin_types.entry_type;21776 return_type->type = ira->codegen->builtin_types.entry_type;
21785 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;21777 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
21786 fields[3].data.x_optional = return_type;21778 fields[3]->data.x_optional = return_type;
21787 }21779 }
21788 // args: []TypeInfo.FnArg21780 // args: []TypeInfo.FnArg
21789 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);21781 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
...@@ -21799,7 +21791,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21799,7 +21791,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21799 fn_arg_array->data.x_array.special = ConstArraySpecialNone;21791 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
21800 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);21792 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2180121793
21802 init_const_slice(ira->codegen, &fields[4], fn_arg_array, 0, fn_arg_count, false);21794 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);
2180321795
21804 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {21796 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
21805 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];21797 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
...@@ -21811,24 +21803,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21811,24 +21803,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21811 bool arg_is_generic = fn_param_info->type == nullptr;21803 bool arg_is_generic = fn_param_info->type == nullptr;
21812 if (arg_is_generic) assert(is_generic);21804 if (arg_is_generic) assert(is_generic);
2181321805
21814 ConstExprValue *inner_fields = create_const_vals(3);21806 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21815 inner_fields[0].special = ConstValSpecialStatic;21807 inner_fields[0]->special = ConstValSpecialStatic;
21816 inner_fields[0].type = ira->codegen->builtin_types.entry_bool;21808 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
21817 inner_fields[0].data.x_bool = arg_is_generic;21809 inner_fields[0]->data.x_bool = arg_is_generic;
21818 inner_fields[1].special = ConstValSpecialStatic;21810 inner_fields[1]->special = ConstValSpecialStatic;
21819 inner_fields[1].type = ira->codegen->builtin_types.entry_bool;21811 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
21820 inner_fields[1].data.x_bool = fn_param_info->is_noalias;21812 inner_fields[1]->data.x_bool = fn_param_info->is_noalias;
21821 inner_fields[2].special = ConstValSpecialStatic;21813 inner_fields[2]->special = ConstValSpecialStatic;
21822 inner_fields[2].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);21814 inner_fields[2]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2182321815
21824 if (arg_is_generic)21816 if (arg_is_generic)
21825 inner_fields[2].data.x_optional = nullptr;21817 inner_fields[2]->data.x_optional = nullptr;
21826 else {21818 else {
21827 ConstExprValue *arg_type = create_const_vals(1);21819 ConstExprValue *arg_type = create_const_vals(1);
21828 arg_type->special = ConstValSpecialStatic;21820 arg_type->special = ConstValSpecialStatic;
21829 arg_type->type = ira->codegen->builtin_types.entry_type;21821 arg_type->type = ira->codegen->builtin_types.entry_type;
21830 arg_type->data.x_type = fn_param_info->type;21822 arg_type->data.x_type = fn_param_info->type;
21831 inner_fields[2].data.x_optional = arg_type;21823 inner_fields[2]->data.x_optional = arg_type;
21832 }21824 }
2183321825
21834 fn_arg_val->data.x_struct.fields = inner_fields;21826 fn_arg_val->data.x_struct.fields = inner_fields;
...@@ -21889,8 +21881,8 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -21889,8 +21881,8 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
21889static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)21881static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
21890{21882{
21891 ensure_field_index(struct_value->type, name, field_index);21883 ensure_field_index(struct_value->type, name, field_index);
21892 assert(struct_value->data.x_struct.fields[field_index].special == ConstValSpecialStatic);21884 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
21893 return &struct_value->data.x_struct.fields[field_index];21885 return struct_value->data.x_struct.fields[field_index];
21894}21886}
2189521887
21896static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)21888static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
...@@ -22698,7 +22690,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -22698,7 +22690,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
22698 if (!val)22690 if (!val)
22699 return ira->codegen->invalid_instruction;22691 return ira->codegen->invalid_instruction;
2270022692
22701 ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index];22693 ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index];
22702 if (value_is_comptime(len_val)) {22694 if (value_is_comptime(len_val)) {
22703 known_len = bigint_as_u64(&len_val->data.x_bigint);22695 known_len = bigint_as_u64(&len_val->data.x_bigint);
22704 have_known_len = true;22696 have_known_len = true;
...@@ -22765,17 +22757,17 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -22765,17 +22757,17 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
22765 return ira->codegen->invalid_instruction;22757 return ira->codegen->invalid_instruction;
2276622758
22767 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);22759 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
22768 result->value.data.x_struct.fields = create_const_vals(2);22760 result->value.data.x_struct.fields = alloc_const_vals_ptrs(2);
2276922761
22770 ConstExprValue *ptr_val = &result->value.data.x_struct.fields[slice_ptr_index];22762 ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index];
22771 ConstExprValue *target_ptr_val = &target_val->data.x_struct.fields[slice_ptr_index];22763 ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
22772 copy_const_val(ptr_val, target_ptr_val, false);22764 copy_const_val(ptr_val, target_ptr_val, false);
22773 ptr_val->type = dest_ptr_type;22765 ptr_val->type = dest_ptr_type;
2277422766
22775 ConstExprValue *len_val = &result->value.data.x_struct.fields[slice_len_index];22767 ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index];
22776 len_val->special = ConstValSpecialStatic;22768 len_val->special = ConstValSpecialStatic;
22777 len_val->type = ira->codegen->builtin_types.entry_usize;22769 len_val->type = ira->codegen->builtin_types.entry_usize;
22778 ConstExprValue *target_len_val = &target_val->data.x_struct.fields[slice_len_index];22770 ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
22779 ZigType *elem_type = src_ptr_type->data.pointer.child_type;22771 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
22780 BigInt elem_size_bigint;22772 BigInt elem_size_bigint;
22781 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));22773 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
...@@ -23664,13 +23656,13 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -23664,13 +23656,13 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
23664 return ira->codegen->invalid_instruction;23656 return ira->codegen->invalid_instruction;
23665 }23657 }
2366623658
23667 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];23659 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
23668 if (parent_ptr->special == ConstValSpecialUndef) {23660 if (parent_ptr->special == ConstValSpecialUndef) {
23669 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));23661 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
23670 return ira->codegen->invalid_instruction;23662 return ira->codegen->invalid_instruction;
23671 }23663 }
2367223664
23673 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];23665 ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
2367423666
23675 switch (parent_ptr->data.x_ptr.special) {23667 switch (parent_ptr->data.x_ptr.special) {
23676 case ConstPtrSpecialInvalid:23668 case ConstPtrSpecialInvalid:
...@@ -23742,9 +23734,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -23742,9 +23734,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2374223734
23743 IrInstruction *result = ir_const(ira, &instruction->base, return_type);23735 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
23744 ConstExprValue *out_val = &result->value;23736 ConstExprValue *out_val = &result->value;
23745 out_val->data.x_struct.fields = create_const_vals(2);23737 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2374623738
23747 ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index];23739 ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2374823740
23749 if (array_val) {23741 if (array_val) {
23750 size_t index = abs_offset + start_scalar;23742 size_t index = abs_offset + start_scalar;
...@@ -23791,7 +23783,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -23791,7 +23783,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
23791 zig_panic("TODO");23783 zig_panic("TODO");
23792 }23784 }
2379323785
23794 ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index];23786 ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index];
23795 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);23787 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);
2379623788
23797 return result;23789 return result;
...@@ -25141,7 +25133,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25141,7 +25133,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25141 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];25133 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];
25142 if (struct_field->gen_index == SIZE_MAX)25134 if (struct_field->gen_index == SIZE_MAX)
25143 continue;25135 continue;
25144 ConstExprValue *field_val = &val->data.x_struct.fields[field_i];25136 ConstExprValue *field_val = val->data.x_struct.fields[field_i];
25145 size_t offset = struct_field->offset;25137 size_t offset = struct_field->offset;
25146 buf_write_value_bytes(codegen, buf + offset, field_val);25138 buf_write_value_bytes(codegen, buf + offset, field_val);
25147 }25139 }
...@@ -25172,7 +25164,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25172,7 +25164,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25172 if (field->gen_index != gen_i)25164 if (field->gen_index != gen_i)
25173 break;25165 break;
25174 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);25166 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);
25175 buf_write_value_bytes(codegen, child_buf, &val->data.x_struct.fields[src_i]);25167 buf_write_value_bytes(codegen, child_buf, val->data.x_struct.fields[src_i]);
25176 BigInt child_val;25168 BigInt child_val;
25177 bigint_read_twos_complement(&child_val, child_buf, packed_bits_size, is_big_endian,25169 bigint_read_twos_complement(&child_val, child_buf, packed_bits_size, is_big_endian,
25178 false);25170 false);
...@@ -25310,9 +25302,9 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25310,9 +25302,9 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25310 }25302 }
25311 case ContainerLayoutExtern: {25303 case ContainerLayoutExtern: {
25312 size_t src_field_count = val->type->data.structure.src_field_count;25304 size_t src_field_count = val->type->data.structure.src_field_count;
25313 val->data.x_struct.fields = create_const_vals(src_field_count);25305 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
25314 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {25306 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
25315 ConstExprValue *field_val = &val->data.x_struct.fields[field_i];25307 ConstExprValue *field_val = val->data.x_struct.fields[field_i];
25316 field_val->special = ConstValSpecialStatic;25308 field_val->special = ConstValSpecialStatic;
25317 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];25309 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];
25318 field_val->type = struct_field->type_entry;25310 field_val->type = struct_field->type_entry;
...@@ -25327,7 +25319,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25327,7 +25319,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25327 }25319 }
25328 case ContainerLayoutPacked: {25320 case ContainerLayoutPacked: {
25329 size_t src_field_count = val->type->data.structure.src_field_count;25321 size_t src_field_count = val->type->data.structure.src_field_count;
25330 val->data.x_struct.fields = create_const_vals(src_field_count);25322 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
25331 size_t gen_field_count = val->type->data.structure.gen_field_count;25323 size_t gen_field_count = val->type->data.structure.gen_field_count;
25332 size_t gen_i = 0;25324 size_t gen_i = 0;
25333 size_t src_i = 0;25325 size_t src_i = 0;
...@@ -25349,7 +25341,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25349,7 +25341,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25349 src_assert(field->gen_index != SIZE_MAX, source_node);25341 src_assert(field->gen_index != SIZE_MAX, source_node);
25350 if (field->gen_index != gen_i)25342 if (field->gen_index != gen_i)
25351 break;25343 break;
25352 ConstExprValue *field_val = &val->data.x_struct.fields[src_i];25344 ConstExprValue *field_val = val->data.x_struct.fields[src_i];
25353 field_val->special = ConstValSpecialStatic;25345 field_val->special = ConstValSpecialStatic;
25354 field_val->type = field->type_entry;25346 field_val->type = field->type_entry;
25355 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);25347 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);