authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-25 16:01:13-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-11-25 16:01:13-05:00
log35d65cceb8aa4360accc0db30b2b1448159e7d26
tree34694475702f28f564546d6e61c114507e179b41
parent6b241d7b5d5a9db087c02113b4556d45b0a62e56
parenta647a88dfc6cdef66316399f10084b35f738b093
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3502 from mikdusan/stage1-mem-diet

unembed ConstExprValue from IrInstruction and intern 1-possible-value types

15 files changed, 2216 insertions(+), 2118 deletions(-)

src/all_types.hpp+50-43
...@@ -32,7 +32,7 @@ struct ErrorTableEntry;...@@ -32,7 +32,7 @@ struct ErrorTableEntry;
32struct BuiltinFnEntry;32struct BuiltinFnEntry;
33struct TypeStructField;33struct TypeStructField;
34struct CodeGen;34struct CodeGen;
35struct ConstExprValue;35struct ZigValue;
36struct IrInstruction;36struct IrInstruction;
37struct IrInstructionCast;37struct IrInstructionCast;
38struct IrInstructionAllocaGen;38struct IrInstructionAllocaGen;
...@@ -130,38 +130,38 @@ struct ConstParent {...@@ -130,38 +130,38 @@ struct ConstParent {
130130
131 union {131 union {
132 struct {132 struct {
133 ConstExprValue *array_val;133 ZigValue *array_val;
134 size_t elem_index;134 size_t elem_index;
135 } p_array;135 } p_array;
136 struct {136 struct {
137 ConstExprValue *struct_val;137 ZigValue *struct_val;
138 size_t field_index;138 size_t field_index;
139 } p_struct;139 } p_struct;
140 struct {140 struct {
141 ConstExprValue *err_union_val;141 ZigValue *err_union_val;
142 } p_err_union_code;142 } p_err_union_code;
143 struct {143 struct {
144 ConstExprValue *err_union_val;144 ZigValue *err_union_val;
145 } p_err_union_payload;145 } p_err_union_payload;
146 struct {146 struct {
147 ConstExprValue *optional_val;147 ZigValue *optional_val;
148 } p_optional_payload;148 } p_optional_payload;
149 struct {149 struct {
150 ConstExprValue *union_val;150 ZigValue *union_val;
151 } p_union;151 } p_union;
152 struct {152 struct {
153 ConstExprValue *scalar_val;153 ZigValue *scalar_val;
154 } p_scalar;154 } p_scalar;
155 } data;155 } data;
156};156};
157157
158struct ConstStructValue {158struct ConstStructValue {
159 ConstExprValue **fields;159 ZigValue **fields;
160};160};
161161
162struct ConstUnionValue {162struct ConstUnionValue {
163 BigInt tag;163 BigInt tag;
164 ConstExprValue *payload;164 ZigValue *payload;
165};165};
166166
167enum ConstArraySpecial {167enum ConstArraySpecial {
...@@ -174,7 +174,7 @@ struct ConstArrayValue {...@@ -174,7 +174,7 @@ struct ConstArrayValue {
174 ConstArraySpecial special;174 ConstArraySpecial special;
175 union {175 union {
176 struct {176 struct {
177 ConstExprValue *elements;177 ZigValue *elements;
178 } s_none;178 } s_none;
179 Buf *s_buf;179 Buf *s_buf;
180 } data;180 } data;
...@@ -235,24 +235,24 @@ struct ConstPtrValue {...@@ -235,24 +235,24 @@ struct ConstPtrValue {
235235
236 union {236 union {
237 struct {237 struct {
238 ConstExprValue *pointee;238 ZigValue *pointee;
239 } ref;239 } ref;
240 struct {240 struct {
241 ConstExprValue *array_val;241 ZigValue *array_val;
242 size_t elem_index;242 size_t elem_index;
243 } base_array;243 } base_array;
244 struct {244 struct {
245 ConstExprValue *struct_val;245 ZigValue *struct_val;
246 size_t field_index;246 size_t field_index;
247 } base_struct;247 } base_struct;
248 struct {248 struct {
249 ConstExprValue *err_union_val;249 ZigValue *err_union_val;
250 } base_err_union_code;250 } base_err_union_code;
251 struct {251 struct {
252 ConstExprValue *err_union_val;252 ZigValue *err_union_val;
253 } base_err_union_payload;253 } base_err_union_payload;
254 struct {254 struct {
255 ConstExprValue *optional_val;255 ZigValue *optional_val;
256 } base_optional_payload;256 } base_optional_payload;
257 struct {257 struct {
258 uint64_t addr;258 uint64_t addr;
...@@ -264,8 +264,8 @@ struct ConstPtrValue {...@@ -264,8 +264,8 @@ struct ConstPtrValue {
264};264};
265265
266struct ConstErrValue {266struct ConstErrValue {
267 ConstExprValue *error_set;267 ZigValue *error_set;
268 ConstExprValue *payload;268 ZigValue *payload;
269};269};
270270
271struct ConstBoundFnValue {271struct ConstBoundFnValue {
...@@ -406,7 +406,7 @@ struct LazyValueErrUnionType {...@@ -406,7 +406,7 @@ struct LazyValueErrUnionType {
406 Buf *type_name;406 Buf *type_name;
407};407};
408408
409struct ConstExprValue {409struct ZigValue {
410 ZigType *type;410 ZigType *type;
411 ConstValSpecial special;411 ConstValSpecial special;
412 ConstParent parent;412 ConstParent parent;
...@@ -423,7 +423,7 @@ struct ConstExprValue {...@@ -423,7 +423,7 @@ struct ConstExprValue {
423 bool x_bool;423 bool x_bool;
424 ConstBoundFnValue x_bound_fn;424 ConstBoundFnValue x_bound_fn;
425 ZigType *x_type;425 ZigType *x_type;
426 ConstExprValue *x_optional;426 ZigValue *x_optional;
427 ConstErrValue x_err_union;427 ConstErrValue x_err_union;
428 ErrorTableEntry *x_err_set;428 ErrorTableEntry *x_err_set;
429 BigInt x_enum_tag;429 BigInt x_enum_tag;
...@@ -443,8 +443,8 @@ struct ConstExprValue {...@@ -443,8 +443,8 @@ struct ConstExprValue {
443 } data;443 } data;
444444
445 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning445 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning
446 //ConstExprValue(const ConstExprValue &other) = delete; // plz zero initialize with {}446 //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {}
447 //ConstExprValue& operator= (const ConstExprValue &other) = delete; // use copy_const_val447 //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val
448};448};
449449
450enum ReturnKnowledge {450enum ReturnKnowledge {
...@@ -525,7 +525,7 @@ struct TldCompTime {...@@ -525,7 +525,7 @@ struct TldCompTime {
525struct TldUsingNamespace {525struct TldUsingNamespace {
526 Tld base;526 Tld base;
527527
528 ConstExprValue *using_namespace_value;528 ZigValue *using_namespace_value;
529};529};
530530
531struct TypeEnumField {531struct TypeEnumField {
...@@ -538,7 +538,7 @@ struct TypeEnumField {...@@ -538,7 +538,7 @@ struct TypeEnumField {
538struct TypeUnionField {538struct TypeUnionField {
539 Buf *name;539 Buf *name;
540 ZigType *type_entry; // available after ResolveStatusSizeKnown540 ZigType *type_entry; // available after ResolveStatusSizeKnown
541 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown541 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
542 TypeEnumField *enum_field;542 TypeEnumField *enum_field;
543 AstNode *decl_node;543 AstNode *decl_node;
544 uint32_t gen_index;544 uint32_t gen_index;
...@@ -1171,7 +1171,7 @@ struct FnTypeParamInfo {...@@ -1171,7 +1171,7 @@ struct FnTypeParamInfo {
1171struct GenericFnTypeId {1171struct GenericFnTypeId {
1172 CodeGen *codegen;1172 CodeGen *codegen;
1173 ZigFn *fn_entry;1173 ZigFn *fn_entry;
1174 ConstExprValue *params;1174 ZigValue *params;
1175 size_t param_count;1175 size_t param_count;
1176};1176};
11771177
...@@ -1213,7 +1213,7 @@ struct ZigTypePointer {...@@ -1213,7 +1213,7 @@ struct ZigTypePointer {
1213 // This can be null. If it is non-null, it means the pointer is terminated by this1213 // This can be null. If it is non-null, it means the pointer is terminated by this
1214 // sentinel value. This is most commonly used for C-style strings, with a 0 byte1214 // sentinel value. This is most commonly used for C-style strings, with a 0 byte
1215 // to specify the length of the memory pointed to.1215 // to specify the length of the memory pointed to.
1216 ConstExprValue *sentinel;1216 ZigValue *sentinel;
12171217
1218 PtrLen ptr_len;1218 PtrLen ptr_len;
1219 uint32_t explicit_alignment; // 0 means use ABI alignment1219 uint32_t explicit_alignment; // 0 means use ABI alignment
...@@ -1242,18 +1242,18 @@ struct ZigTypeFloat {...@@ -1242,18 +1242,18 @@ struct ZigTypeFloat {
1242struct ZigTypeArray {1242struct ZigTypeArray {
1243 ZigType *child_type;1243 ZigType *child_type;
1244 uint64_t len;1244 uint64_t len;
1245 ConstExprValue *sentinel;1245 ZigValue *sentinel;
1246};1246};
12471247
1248struct TypeStructField {1248struct TypeStructField {
1249 Buf *name;1249 Buf *name;
1250 ZigType *type_entry; // available after ResolveStatusSizeKnown1250 ZigType *type_entry; // available after ResolveStatusSizeKnown
1251 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown1251 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
1252 size_t src_index;1252 size_t src_index;
1253 size_t gen_index;1253 size_t gen_index;
1254 size_t offset; // byte offset from beginning of struct1254 size_t offset; // byte offset from beginning of struct
1255 AstNode *decl_node;1255 AstNode *decl_node;
1256 ConstExprValue *init_val; // null and then memoized1256 ZigValue *init_val; // null and then memoized
1257 uint32_t bit_offset_in_host; // offset from the memory at gen_index1257 uint32_t bit_offset_in_host; // offset from the memory at gen_index
1258 uint32_t host_int_bytes; // size of host integer1258 uint32_t host_int_bytes; // size of host integer
1259 uint32_t align;1259 uint32_t align;
...@@ -1515,7 +1515,7 @@ struct ZigType {...@@ -1515,7 +1515,7 @@ struct ZigType {
1515 ZigType *any_frame_parent;1515 ZigType *any_frame_parent;
1516 // If we generate a constant name value for this type, we memoize it here.1516 // If we generate a constant name value for this type, we memoize it here.
1517 // The type of this is array1517 // The type of this is array
1518 ConstExprValue *cached_const_name_val;1518 ZigValue *cached_const_name_val;
15191519
1520 OnePossibleValue one_possible_value;1520 OnePossibleValue one_possible_value;
1521 // Known after ResolveStatusAlignmentKnown.1521 // Known after ResolveStatusAlignmentKnown.
...@@ -1771,7 +1771,7 @@ struct TypeId {...@@ -1771,7 +1771,7 @@ struct TypeId {
1771 CodeGen *codegen;1771 CodeGen *codegen;
1772 ZigType *child_type;1772 ZigType *child_type;
1773 InferredStructField *inferred_struct_field;1773 InferredStructField *inferred_struct_field;
1774 ConstExprValue *sentinel;1774 ZigValue *sentinel;
1775 PtrLen ptr_len;1775 PtrLen ptr_len;
1776 uint32_t alignment;1776 uint32_t alignment;
17771777
...@@ -1787,7 +1787,7 @@ struct TypeId {...@@ -1787,7 +1787,7 @@ struct TypeId {
1787 CodeGen *codegen;1787 CodeGen *codegen;
1788 ZigType *child_type;1788 ZigType *child_type;
1789 uint64_t size;1789 uint64_t size;
1790 ConstExprValue *sentinel;1790 ZigValue *sentinel;
1791 } array;1791 } array;
1792 struct {1792 struct {
1793 bool is_signed;1793 bool is_signed;
...@@ -1960,13 +1960,13 @@ struct CodeGen {...@@ -1960,13 +1960,13 @@ struct CodeGen {
1960 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;1960 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
1961 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;1961 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;
1962 HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;1962 HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
1963 HashMap<Scope *, ConstExprValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;1963 HashMap<Scope *, ZigValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
1964 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;1964 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
1965 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;1965 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;
1966 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;1966 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
1967 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;1967 HashMap<Buf *, ZigValue *, buf_hash, buf_eql_buf> string_literals_table;
1968 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;1968 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1969 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> one_possible_values;1969 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> one_possible_values;
19701970
1971 ZigList<Tld *> resolve_queue;1971 ZigList<Tld *> resolve_queue;
1972 size_t resolve_queue_index;1972 size_t resolve_queue_index;
...@@ -2021,6 +2021,13 @@ struct CodeGen {...@@ -2021,6 +2021,13 @@ struct CodeGen {
2021 ZigType *entry_any_frame;2021 ZigType *entry_any_frame;
2022 } builtin_types;2022 } builtin_types;
20232023
2024 struct {
2025 ZigValue x_undefined;
2026 ZigValue x_void;
2027 ZigValue x_null;
2028 ZigValue x_unreachable;
2029 } intern_values;
2030
2024 ZigType *align_amt_type;2031 ZigType *align_amt_type;
2025 ZigType *stack_trace_type;2032 ZigType *stack_trace_type;
2026 ZigType *err_tag_type;2033 ZigType *err_tag_type;
...@@ -2043,9 +2050,9 @@ struct CodeGen {...@@ -2043,9 +2050,9 @@ struct CodeGen {
2043 IrInstruction *invalid_instruction;2050 IrInstruction *invalid_instruction;
2044 IrInstruction *unreach_instruction;2051 IrInstruction *unreach_instruction;
20452052
2046 ConstExprValue const_zero_byte;2053 ZigValue const_zero_byte;
2047 ConstExprValue const_void_val;2054 ZigValue const_void_val;
2048 ConstExprValue panic_msg_vals[PanicMsgIdCount];2055 ZigValue panic_msg_vals[PanicMsgIdCount];
20492056
2050 // The function definitions this module includes.2057 // The function definitions this module includes.
2051 ZigList<ZigFn *> fn_defs;2058 ZigList<ZigFn *> fn_defs;
...@@ -2163,7 +2170,7 @@ struct CodeGen {...@@ -2163,7 +2170,7 @@ struct CodeGen {
21632170
2164struct ZigVar {2171struct ZigVar {
2165 const char *name;2172 const char *name;
2166 ConstExprValue *const_value;2173 ZigValue *const_value;
2167 ZigType *var_type;2174 ZigType *var_type;
2168 LLVMValueRef value_ref;2175 LLVMValueRef value_ref;
2169 IrInstruction *is_comptime;2176 IrInstruction *is_comptime;
...@@ -2202,7 +2209,7 @@ struct ErrorTableEntry {...@@ -2202,7 +2209,7 @@ struct ErrorTableEntry {
2202 ZigType *set_with_only_this_in_it;2209 ZigType *set_with_only_this_in_it;
2203 // If we generate a constant error name value for this error, we memoize it here.2210 // If we generate a constant error name value for this error, we memoize it here.
2204 // The type of this is array2211 // The type of this is array
2205 ConstExprValue *cached_error_name_val;2212 ZigValue *cached_error_name_val;
2206};2213};
22072214
2208enum ScopeId {2215enum ScopeId {
...@@ -2621,7 +2628,7 @@ struct IrInstruction {...@@ -2621,7 +2628,7 @@ struct IrInstruction {
2621 Scope *scope;2628 Scope *scope;
2622 AstNode *source_node;2629 AstNode *source_node;
2623 LLVMValueRef llvm_value;2630 LLVMValueRef llvm_value;
2624 ConstExprValue value;2631 ZigValue *value;
2625 uint32_t debug_id;2632 uint32_t debug_id;
2626 // if ref_count is zero and the instruction has no side effects,2633 // if ref_count is zero and the instruction has no side effects,
2627 // the instruction can be omitted in codegen2634 // the instruction can be omitted in codegen
src/analyze.cpp+153-151
...@@ -511,7 +511,7 @@ static void append_ptr_type_attrs(Buf *type_name, ZigType *ptr_type) {...@@ -511,7 +511,7 @@ static void append_ptr_type_attrs(Buf *type_name, ZigType *ptr_type) {
511ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,511ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,
512 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,512 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
513 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero,513 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero,
514 uint32_t vector_index, InferredStructField *inferred_struct_field, ConstExprValue *sentinel)514 uint32_t vector_index, InferredStructField *inferred_struct_field, ZigValue *sentinel)
515{515{
516 assert(ptr_len != PtrLenC || allow_zero);516 assert(ptr_len != PtrLenC || allow_zero);
517 assert(!type_is_invalid(child_type));517 assert(!type_is_invalid(child_type));
...@@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
760 return entry;760 return entry;
761}761}
762762
763ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel) {763ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel) {
764 TypeId type_id = {};764 TypeId type_id = {};
765 type_id.id = ZigTypeIdArray;765 type_id.id = ZigTypeIdArray;
766 type_id.data.array.codegen = g;766 type_id.data.array.codegen = g;
...@@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
956956
957ZigType *get_stack_trace_type(CodeGen *g) {957ZigType *get_stack_trace_type(CodeGen *g) {
958 if (g->stack_trace_type == nullptr) {958 if (g->stack_trace_type == nullptr) {
959 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");959 ZigValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
960 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);960 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
961961
962 g->stack_trace_type = stack_trace_type_val->data.x_type;962 g->stack_trace_type = stack_trace_type_val->data.x_type;
...@@ -1095,7 +1095,7 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind...@@ -1095,7 +1095,7 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
1095 return entry;1095 return entry;
1096}1096}
10971097
1098ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,1098ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
1099 Buf *type_name, UndefAllowed undef)1099 Buf *type_name, UndefAllowed undef)
1100{1100{
1101 size_t backward_branch_count = 0;1101 size_t backward_branch_count = 0;
...@@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig...@@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig
1105 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);1105 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);
1106}1106}
11071107
1108Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,1108Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
1109 ConstExprValue *parent_type_val, bool *is_zero_bits)1109 ZigValue *parent_type_val, bool *is_zero_bits)
1110{1110{
1111 Error err;1111 Error err;
1112 if (type_val->special != ConstValSpecialLazy) {1112 if (type_val->special != ConstValSpecialLazy) {
...@@ -1134,7 +1134,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *...@@ -1134,7 +1134,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
1134 case LazyValueIdPtrType: {1134 case LazyValueIdPtrType: {
1135 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);1135 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);
11361136
1137 if (parent_type_val == &lazy_ptr_type->elem_type->value) {1137 if (parent_type_val == lazy_ptr_type->elem_type->value) {
1138 // Does a struct which contains a pointer field to itself have bits? Yes.1138 // Does a struct which contains a pointer field to itself have bits? Yes.
1139 *is_zero_bits = false;1139 *is_zero_bits = false;
1140 return ErrorNone;1140 return ErrorNone;
...@@ -1142,7 +1142,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *...@@ -1142,7 +1142,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
1142 if (parent_type_val == nullptr) {1142 if (parent_type_val == nullptr) {
1143 parent_type_val = type_val;1143 parent_type_val = type_val;
1144 }1144 }
1145 return type_val_resolve_zero_bits(g, &lazy_ptr_type->elem_type->value, parent_type,1145 return type_val_resolve_zero_bits(g, lazy_ptr_type->elem_type->value, parent_type,
1146 parent_type_val, is_zero_bits);1146 parent_type_val, is_zero_bits);
1147 }1147 }
1148 }1148 }
...@@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *...@@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
1160 zig_unreachable();1160 zig_unreachable();
1161}1161}
11621162
1163Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool *is_opaque_type) {1163Error type_val_resolve_is_opaque_type(CodeGen *g, ZigValue *type_val, bool *is_opaque_type) {
1164 if (type_val->special != ConstValSpecialLazy) {1164 if (type_val->special != ConstValSpecialLazy) {
1165 assert(type_val->special == ConstValSpecialStatic);1165 assert(type_val->special == ConstValSpecialStatic);
1166 if (type_val->data.x_type == g->builtin_types.entry_var) {1166 if (type_val->data.x_type == g->builtin_types.entry_var) {
...@@ -1186,7 +1186,7 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool...@@ -1186,7 +1186,7 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool
1186 zig_unreachable();1186 zig_unreachable();
1187}1187}
11881188
1189static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val) {1189static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ZigValue *type_val) {
1190 if (type_val->special != ConstValSpecialLazy) {1190 if (type_val->special != ConstValSpecialLazy) {
1191 return type_requires_comptime(g, type_val->data.x_type);1191 return type_requires_comptime(g, type_val->data.x_type);
1192 }1192 }
...@@ -1197,21 +1197,21 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1197,21 +1197,21 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1197 zig_unreachable();1197 zig_unreachable();
1198 case LazyValueIdSliceType: {1198 case LazyValueIdSliceType: {
1199 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);1199 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);
1200 return type_val_resolve_requires_comptime(g, &lazy_slice_type->elem_type->value);1200 return type_val_resolve_requires_comptime(g, lazy_slice_type->elem_type->value);
1201 }1201 }
1202 case LazyValueIdPtrType: {1202 case LazyValueIdPtrType: {
1203 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);1203 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);
1204 return type_val_resolve_requires_comptime(g, &lazy_ptr_type->elem_type->value);1204 return type_val_resolve_requires_comptime(g, lazy_ptr_type->elem_type->value);
1205 }1205 }
1206 case LazyValueIdOptType: {1206 case LazyValueIdOptType: {
1207 LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy);1207 LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy);
1208 return type_val_resolve_requires_comptime(g, &lazy_opt_type->payload_type->value);1208 return type_val_resolve_requires_comptime(g, lazy_opt_type->payload_type->value);
1209 }1209 }
1210 case LazyValueIdFnType: {1210 case LazyValueIdFnType: {
1211 LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy);1211 LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy);
1212 if (lazy_fn_type->is_generic)1212 if (lazy_fn_type->is_generic)
1213 return ReqCompTimeYes;1213 return ReqCompTimeYes;
1214 switch (type_val_resolve_requires_comptime(g, &lazy_fn_type->return_type->value)) {1214 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->return_type->value)) {
1215 case ReqCompTimeInvalid:1215 case ReqCompTimeInvalid:
1216 return ReqCompTimeInvalid;1216 return ReqCompTimeInvalid;
1217 case ReqCompTimeYes:1217 case ReqCompTimeYes:
...@@ -1224,7 +1224,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1224,7 +1224,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1224 AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i);1224 AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i);
1225 bool param_is_var_args = param_node->data.param_decl.is_var_args;1225 bool param_is_var_args = param_node->data.param_decl.is_var_args;
1226 if (param_is_var_args) break;1226 if (param_is_var_args) break;
1227 switch (type_val_resolve_requires_comptime(g, &lazy_fn_type->param_types[i]->value)) {1227 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->param_types[i]->value)) {
1228 case ReqCompTimeInvalid:1228 case ReqCompTimeInvalid:
1229 return ReqCompTimeInvalid;1229 return ReqCompTimeInvalid;
1230 case ReqCompTimeYes:1230 case ReqCompTimeYes:
...@@ -1238,13 +1238,13 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1238,13 +1238,13 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1238 case LazyValueIdErrUnionType: {1238 case LazyValueIdErrUnionType: {
1239 LazyValueErrUnionType *lazy_err_union_type =1239 LazyValueErrUnionType *lazy_err_union_type =
1240 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);1240 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);
1241 return type_val_resolve_requires_comptime(g, &lazy_err_union_type->payload_type->value);1241 return type_val_resolve_requires_comptime(g, lazy_err_union_type->payload_type->value);
1242 }1242 }
1243 }1243 }
1244 zig_unreachable();1244 zig_unreachable();
1245}1245}
12461246
1247Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val,1247Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,
1248 size_t *abi_size, size_t *size_in_bits)1248 size_t *abi_size, size_t *size_in_bits)
1249{1249{
1250 Error err;1250 Error err;
...@@ -1267,7 +1267,7 @@ start_over:...@@ -1267,7 +1267,7 @@ start_over:
1267 case LazyValueIdSliceType: {1267 case LazyValueIdSliceType: {
1268 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);1268 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);
1269 bool is_zero_bits;1269 bool is_zero_bits;
1270 if ((err = type_val_resolve_zero_bits(g, &lazy_slice_type->elem_type->value, nullptr,1270 if ((err = type_val_resolve_zero_bits(g, lazy_slice_type->elem_type->value, nullptr,
1271 nullptr, &is_zero_bits)))1271 nullptr, &is_zero_bits)))
1272 {1272 {
1273 return err;1273 return err;
...@@ -1284,7 +1284,7 @@ start_over:...@@ -1284,7 +1284,7 @@ start_over:
1284 case LazyValueIdPtrType: {1284 case LazyValueIdPtrType: {
1285 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);1285 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);
1286 bool is_zero_bits;1286 bool is_zero_bits;
1287 if ((err = type_val_resolve_zero_bits(g, &lazy_ptr_type->elem_type->value, nullptr,1287 if ((err = type_val_resolve_zero_bits(g, lazy_ptr_type->elem_type->value, nullptr,
1288 nullptr, &is_zero_bits)))1288 nullptr, &is_zero_bits)))
1289 {1289 {
1290 return err;1290 return err;
...@@ -1311,7 +1311,7 @@ start_over:...@@ -1311,7 +1311,7 @@ start_over:
1311 zig_unreachable();1311 zig_unreachable();
1312}1312}
13131313
1314Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align) {1314Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align) {
1315 Error err;1315 Error err;
1316 if (type_val->special != ConstValSpecialLazy) {1316 if (type_val->special != ConstValSpecialLazy) {
1317 assert(type_val->special == ConstValSpecialStatic);1317 assert(type_val->special == ConstValSpecialStatic);
...@@ -1337,13 +1337,13 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t...@@ -1337,13 +1337,13 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t
1337 return ErrorNone;1337 return ErrorNone;
1338 case LazyValueIdOptType: {1338 case LazyValueIdOptType: {
1339 LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy);1339 LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy);
1340 return type_val_resolve_abi_align(g, &lazy_opt_type->payload_type->value, abi_align);1340 return type_val_resolve_abi_align(g, lazy_opt_type->payload_type->value, abi_align);
1341 }1341 }
1342 case LazyValueIdErrUnionType: {1342 case LazyValueIdErrUnionType: {
1343 LazyValueErrUnionType *lazy_err_union_type =1343 LazyValueErrUnionType *lazy_err_union_type =
1344 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);1344 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);
1345 uint32_t payload_abi_align;1345 uint32_t payload_abi_align;
1346 if ((err = type_val_resolve_abi_align(g, &lazy_err_union_type->payload_type->value,1346 if ((err = type_val_resolve_abi_align(g, lazy_err_union_type->payload_type->value,
1347 &payload_abi_align)))1347 &payload_abi_align)))
1348 {1348 {
1349 return err;1349 return err;
...@@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t...@@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t
1356 zig_unreachable();1356 zig_unreachable();
1357}1357}
13581358
1359static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ConstExprValue *type_val) {1359static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ZigValue *type_val) {
1360 if (type_val->special != ConstValSpecialLazy) {1360 if (type_val->special != ConstValSpecialLazy) {
1361 return type_has_one_possible_value(g, type_val->data.x_type);1361 return type_has_one_possible_value(g, type_val->data.x_type);
1362 }1362 }
...@@ -1384,13 +1384,13 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons...@@ -1384,13 +1384,13 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
1384 case LazyValueIdErrUnionType: {1384 case LazyValueIdErrUnionType: {
1385 LazyValueErrUnionType *lazy_err_union_type =1385 LazyValueErrUnionType *lazy_err_union_type =
1386 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);1386 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);
1387 switch (type_val_resolve_has_one_possible_value(g, &lazy_err_union_type->err_set_type->value)) {1387 switch (type_val_resolve_has_one_possible_value(g, lazy_err_union_type->err_set_type->value)) {
1388 case OnePossibleValueInvalid:1388 case OnePossibleValueInvalid:
1389 return OnePossibleValueInvalid;1389 return OnePossibleValueInvalid;
1390 case OnePossibleValueNo:1390 case OnePossibleValueNo:
1391 return OnePossibleValueNo;1391 return OnePossibleValueNo;
1392 case OnePossibleValueYes:1392 case OnePossibleValueYes:
1393 return type_val_resolve_has_one_possible_value(g, &lazy_err_union_type->payload_type->value);1393 return type_val_resolve_has_one_possible_value(g, lazy_err_union_type->payload_type->value);
1394 }1394 }
1395 }1395 }
1396 }1396 }
...@@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons...@@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
1398}1398}
13991399
1400ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {1400ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1401 ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,1401 ZigValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,
1402 nullptr, UndefBad);1402 nullptr, UndefBad);
1403 if (type_is_invalid(result->type))1403 if (type_is_invalid(result->type))
1404 return g->builtin_types.entry_invalid;1404 return g->builtin_types.entry_invalid;
...@@ -1451,7 +1451,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou...@@ -1451,7 +1451,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou
1451}1451}
14521452
1453static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {1453static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {
1454 ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g),1454 ZigValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g),
1455 nullptr, UndefBad);1455 nullptr, UndefBad);
1456 if (type_is_invalid(align_result->type))1456 if (type_is_invalid(align_result->type))
1457 return false;1457 return false;
...@@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1474 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,1474 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1475 PtrLenUnknown, 0, 0, 0, false);1475 PtrLenUnknown, 0, 0, 0, false);
1476 ZigType *str_type = get_slice_type(g, ptr_type);1476 ZigType *str_type = get_slice_type(g, ptr_type);
1477 ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad);1477 ZigValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad);
1478 if (type_is_invalid(result_val->type))1478 if (type_is_invalid(result_val->type))
1479 return false;1479 return false;
14801480
1481 ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];1481 ZigValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1482 ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index];1482 ZigValue *len_field = result_val->data.x_struct.fields[slice_len_index];
14831483
1484 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);1484 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
1485 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;1485 ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
1486 if (array_val->data.x_array.special == ConstArraySpecialBuf) {1486 if (array_val->data.x_array.special == ConstArraySpecialBuf) {
1487 *out_buffer = array_val->data.x_array.data.s_buf;1487 *out_buffer = array_val->data.x_array.data.s_buf;
1488 return true;1488 return true;
...@@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1493 buf_resize(result, len);1493 buf_resize(result, len);
1494 for (size_t i = 0; i < len; i += 1) {1494 for (size_t i = 0; i < len; i += 1) {
1495 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;1495 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
1496 ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];1496 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
1497 if (char_val->special == ConstValSpecialUndef) {1497 if (char_val->special == ConstValSpecialUndef) {
1498 add_node_error(g, node, buf_sprintf("use of undefined value"));1498 add_node_error(g, node, buf_sprintf("use of undefined value"));
1499 return false;1499 return false;
...@@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26212621
2622 if (tag_value != nullptr) {2622 if (tag_value != nullptr) {
2623 // A user-specified value is available2623 // A user-specified value is available
2624 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,2624 ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
2625 nullptr, UndefBad);2625 nullptr, UndefBad);
2626 if (type_is_invalid(result->type)) {2626 if (type_is_invalid(result->type)) {
2627 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;2627 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
...@@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2756 return ErrorSemanticAnalyzeFail;2756 return ErrorSemanticAnalyzeFail;
2757 }2757 }
27582758
2759 ConstExprValue *field_type_val;2759 ZigValue *field_type_val;
2760 if (decl_node->type == NodeTypeContainerDecl) {2760 if (decl_node->type == NodeTypeContainerDecl) {
2761 field_type_val = analyze_const_value(g, scope,2761 field_type_val = analyze_const_value(g, scope,
2762 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);2762 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
...@@ -3051,7 +3051,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3051,7 +3051,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3051 return ErrorSemanticAnalyzeFail;3051 return ErrorSemanticAnalyzeFail;
3052 }3052 }
3053 } else {3053 } else {
3054 ConstExprValue *field_type_val = analyze_const_value(g, scope,3054 ZigValue *field_type_val = analyze_const_value(g, scope,
3055 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);3055 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
3056 if (type_is_invalid(field_type_val->type)) {3056 if (type_is_invalid(field_type_val->type)) {
3057 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3057 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3117 // In a second pass we will fill in the unspecified ones.3117 // In a second pass we will fill in the unspecified ones.
3118 if (tag_value != nullptr) {3118 if (tag_value != nullptr) {
3119 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;3119 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
3120 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,3120 ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
3121 nullptr, UndefBad);3121 nullptr, UndefBad);
3122 if (type_is_invalid(result->type)) {3122 if (type_is_invalid(result->type)) {
3123 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3123 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -3545,7 +3545,7 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source...@@ -3545,7 +3545,7 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source
3545 tld->parent_scope = parent_scope;3545 tld->parent_scope = parent_scope;
3546}3546}
35473547
3548void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {3548void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
3549 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);3549 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);
3550 resolve_top_level_decl(g, tld, tld->source_node, false);3550 resolve_top_level_decl(g, tld, tld->source_node, false);
3551 assert(tld->id == TldIdVar);3551 assert(tld->id == TldIdVar);
...@@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry...@@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
3717// Set name to nullptr to make the variable anonymous (not visible to programmer).3717// Set name to nullptr to make the variable anonymous (not visible to programmer).
3718// TODO merge with definition of add_local_var in ir.cpp3718// TODO merge with definition of add_local_var in ir.cpp
3719ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,3719ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
3720 bool is_const, ConstExprValue *const_value, Tld *src_tld, ZigType *var_type)3720 bool is_const, ZigValue *const_value, Tld *src_tld, ZigType *var_type)
3721{3721{
3722 Error err;3722 Error err;
3723 assert(const_value != nullptr);3723 assert(const_value != nullptr);
...@@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
38153815
3816 assert(!is_export || !is_extern);3816 assert(!is_export || !is_extern);
38173817
3818 ConstExprValue *init_value = nullptr;3818 ZigValue *init_value = nullptr;
38193819
3820 // TODO more validation for types that can't be used for export/extern variables3820 // TODO more validation for types that can't be used for export/extern variables
3821 ZigType *implicit_type = nullptr;3821 ZigType *implicit_type = nullptr;
...@@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
3853 ZigType *type = explicit_type ? explicit_type : implicit_type;3853 ZigType *type = explicit_type ? explicit_type : implicit_type;
3854 assert(type != nullptr); // should have been caught by the parser3854 assert(type != nullptr); // should have been caught by the parser
38553855
3856 ConstExprValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);3856 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);
38573857
3858 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,3858 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
3859 is_const, init_val, &tld_var->base, type);3859 is_const, init_val, &tld_var->base, type);
...@@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_...@@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_
3900 }3900 }
3901 }3901 }
39023902
3903 ConstExprValue *use_expr = src_using_namespace->using_namespace_value;3903 ZigValue *use_expr = src_using_namespace->using_namespace_value;
3904 if (type_is_invalid(use_expr->type)) {3904 if (type_is_invalid(use_expr->type)) {
3905 dest_decls_scope->any_imports_failed = true;3905 dest_decls_scope->any_imports_failed = true;
3906 return;3906 return;
...@@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
39773977
3978 using_namespace->base.resolution = TldResolutionResolving;3978 using_namespace->base.resolution = TldResolutionResolving;
3979 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);3979 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);
3980 ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base,3980 ZigValue *result = analyze_const_value(g, &dest_decls_scope->base,
3981 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,3981 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,
3982 nullptr, UndefBad);3982 nullptr, UndefBad);
3983 using_namespace->using_namespace_value = result;3983 using_namespace->using_namespace_value = result;
...@@ -3985,7 +3985,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -3985,7 +3985,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
3985 if (type_is_invalid(result->type)) {3985 if (type_is_invalid(result->type)) {
3986 dest_decls_scope->any_imports_failed = true;3986 dest_decls_scope->any_imports_failed = true;
3987 using_namespace->base.resolution = TldResolutionInvalid;3987 using_namespace->base.resolution = TldResolutionInvalid;
3988 using_namespace->using_namespace_value = &g->invalid_instruction->value;3988 using_namespace->using_namespace_value = g->invalid_instruction->value;
3989 return;3989 return;
3990 }3990 }
39913991
...@@ -3994,7 +3994,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -3994,7 +3994,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
3994 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));3994 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
3995 dest_decls_scope->any_imports_failed = true;3995 dest_decls_scope->any_imports_failed = true;
3996 using_namespace->base.resolution = TldResolutionInvalid;3996 using_namespace->base.resolution = TldResolutionInvalid;
3997 using_namespace->using_namespace_value = &g->invalid_instruction->value;3997 using_namespace->using_namespace_value = g->invalid_instruction->value;
3998 return;3998 return;
3999 }3999 }
4000}4000}
...@@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {...@@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
5029 return true;5029 return true;
5030}5030}
50315031
5032static uint32_t hash_const_val_error_set(ConstExprValue *const_val) {5032static uint32_t hash_const_val_error_set(ZigValue *const_val) {
5033 assert(const_val->data.x_err_set != nullptr);5033 assert(const_val->data.x_err_set != nullptr);
5034 return const_val->data.x_err_set->value ^ 2630160122;5034 return const_val->data.x_err_set->value ^ 2630160122;
5035}5035}
50365036
5037static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {5037static uint32_t hash_const_val_ptr(ZigValue *const_val) {
5038 uint32_t hash_val = 0;5038 uint32_t hash_val = 0;
5039 switch (const_val->data.x_ptr.mut) {5039 switch (const_val->data.x_ptr.mut) {
5040 case ConstPtrMutRuntimeVar:5040 case ConstPtrMutRuntimeVar:
...@@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {...@@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
5095 zig_unreachable();5095 zig_unreachable();
5096}5096}
50975097
5098static uint32_t hash_const_val(ConstExprValue *const_val) {5098static uint32_t hash_const_val(ZigValue *const_val) {
5099 assert(const_val->special == ConstValSpecialStatic);5099 assert(const_val->special == ConstValSpecialStatic);
5100 switch (const_val->type->id) {5100 switch (const_val->type->id) {
5101 case ZigTypeIdOpaque:5101 case ZigTypeIdOpaque:
...@@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {...@@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
5224 uint32_t result = 0;5224 uint32_t result = 0;
5225 result += hash_ptr(id->fn_entry);5225 result += hash_ptr(id->fn_entry);
5226 for (size_t i = 0; i < id->param_count; i += 1) {5226 for (size_t i = 0; i < id->param_count; i += 1) {
5227 ConstExprValue *generic_param = &id->params[i];5227 ZigValue *generic_param = &id->params[i];
5228 if (generic_param->special != ConstValSpecialRuntime) {5228 if (generic_param->special != ConstValSpecialRuntime) {
5229 result += hash_const_val(generic_param);5229 result += hash_const_val(generic_param);
5230 result += hash_ptr(generic_param->type);5230 result += hash_ptr(generic_param->type);
...@@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
5238 if (a->fn_entry != b->fn_entry) return false;5238 if (a->fn_entry != b->fn_entry) return false;
5239 if (a->param_count != b->param_count) return false;5239 if (a->param_count != b->param_count) return false;
5240 for (size_t i = 0; i < a->param_count; i += 1) {5240 for (size_t i = 0; i < a->param_count; i += 1) {
5241 ConstExprValue *a_val = &a->params[i];5241 ZigValue *a_val = &a->params[i];
5242 ConstExprValue *b_val = &b->params[i];5242 ZigValue *b_val = &b->params[i];
5243 if (a_val->type != b_val->type) return false;5243 if (a_val->type != b_val->type) return false;
5244 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {5244 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {
5245 assert(a_val->special == ConstValSpecialStatic);5245 assert(a_val->special == ConstValSpecialStatic);
...@@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
5254 return true;5254 return true;
5255}5255}
52565256
5257static bool can_mutate_comptime_var_state(ConstExprValue *value) {5257static bool can_mutate_comptime_var_state(ZigValue *value) {
5258 assert(value != nullptr);5258 assert(value != nullptr);
5259 switch (value->type->id) {5259 switch (value->type->id) {
5260 case ZigTypeIdInvalid:5260 case ZigTypeIdInvalid:
...@@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5562 zig_unreachable();5562 zig_unreachable();
5563}5563}
55645564
5565ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {5565ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5566 auto entry = g->one_possible_values.maybe_get(type_entry);5566 auto entry = g->one_possible_values.maybe_get(type_entry);
5567 if (entry != nullptr) {5567 if (entry != nullptr) {
5568 return entry->value;5568 return entry->value;
5569 }5569 }
5570 ConstExprValue *result = create_const_vals(1);5570 ZigValue *result = create_const_vals(1);
5571 result->type = type_entry;5571 result->type = type_entry;
5572 result->special = ConstValSpecialStatic;5572 result->special = ConstValSpecialStatic;
5573 g->one_possible_values.put(type_entry, result);5573 g->one_possible_values.put(type_entry, result);
...@@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {...@@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
5637 zig_unreachable();5637 zig_unreachable();
5638}5638}
56395639
5640void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {5640void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
5641 auto entry = g->string_literals_table.maybe_get(str);5641 auto entry = g->string_literals_table.maybe_get(str);
5642 if (entry != nullptr) {5642 if (entry != nullptr) {
5643 memcpy(const_val, entry->value, sizeof(ConstExprValue));5643 memcpy(const_val, entry->value, sizeof(ZigValue));
5644 return;5644 return;
5645 }5645 }
56465646
5647 // first we build the underlying array5647 // first we build the underlying array
5648 ConstExprValue *array_val = create_const_vals(1);5648 ZigValue *array_val = create_const_vals(1);
5649 array_val->special = ConstValSpecialStatic;5649 array_val->special = ConstValSpecialStatic;
5650 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte);5650 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte);
5651 array_val->data.x_array.special = ConstArraySpecialBuf;5651 array_val->data.x_array.special = ConstArraySpecialBuf;
...@@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {...@@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
5661 g->string_literals_table.put(str, const_val);5661 g->string_literals_table.put(str, const_val);
5662}5662}
56635663
5664ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {5664ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {
5665 ConstExprValue *const_val = create_const_vals(1);5665 ZigValue *const_val = create_const_vals(1);
5666 init_const_str_lit(g, const_val, str);5666 init_const_str_lit(g, const_val, str);
5667 return const_val;5667 return const_val;
5668}5668}
56695669
5670void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) {5670void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint) {
5671 const_val->special = ConstValSpecialStatic;5671 const_val->special = ConstValSpecialStatic;
5672 const_val->type = type;5672 const_val->type = type;
5673 bigint_init_bigint(&const_val->data.x_bigint, bigint);5673 bigint_init_bigint(&const_val->data.x_bigint, bigint);
5674}5674}
56755675
5676ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {5676ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5677 ConstExprValue *const_val = create_const_vals(1);5677 ZigValue *const_val = create_const_vals(1);
5678 init_const_bigint(const_val, type, bigint);5678 init_const_bigint(const_val, type, bigint);
5679 return const_val;5679 return const_val;
5680}5680}
56815681
56825682
5683void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) {5683void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative) {
5684 const_val->special = ConstValSpecialStatic;5684 const_val->special = ConstValSpecialStatic;
5685 const_val->type = type;5685 const_val->type = type;
5686 bigint_init_unsigned(&const_val->data.x_bigint, x);5686 bigint_init_unsigned(&const_val->data.x_bigint, x);
5687 const_val->data.x_bigint.is_negative = negative;5687 const_val->data.x_bigint.is_negative = negative;
5688}5688}
56895689
5690ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {5690ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5691 ConstExprValue *const_val = create_const_vals(1);5691 ZigValue *const_val = create_const_vals(1);
5692 init_const_unsigned_negative(const_val, type, x, negative);5692 init_const_unsigned_negative(const_val, type, x, negative);
5693 return const_val;5693 return const_val;
5694}5694}
56955695
5696void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x) {5696void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {
5697 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);5697 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);
5698}5698}
56995699
5700ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {5700ZigValue *create_const_usize(CodeGen *g, uint64_t x) {
5701 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);5701 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
5702}5702}
57035703
5704void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) {5704void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
5705 const_val->special = ConstValSpecialStatic;5705 const_val->special = ConstValSpecialStatic;
5706 const_val->type = type;5706 const_val->type = type;
5707 bigint_init_signed(&const_val->data.x_bigint, x);5707 bigint_init_signed(&const_val->data.x_bigint, x);
5708}5708}
57095709
5710ConstExprValue *create_const_signed(ZigType *type, int64_t x) {5710ZigValue *create_const_signed(ZigType *type, int64_t x) {
5711 ConstExprValue *const_val = create_const_vals(1);5711 ZigValue *const_val = create_const_vals(1);
5712 init_const_signed(const_val, type, x);5712 init_const_signed(const_val, type, x);
5713 return const_val;5713 return const_val;
5714}5714}
57155715
5716void init_const_null(ConstExprValue *const_val, ZigType *type) {5716void init_const_null(ZigValue *const_val, ZigType *type) {
5717 const_val->special = ConstValSpecialStatic;5717 const_val->special = ConstValSpecialStatic;
5718 const_val->type = type;5718 const_val->type = type;
5719 const_val->data.x_optional = nullptr;5719 const_val->data.x_optional = nullptr;
5720}5720}
57215721
5722ConstExprValue *create_const_null(ZigType *type) {5722ZigValue *create_const_null(ZigType *type) {
5723 ConstExprValue *const_val = create_const_vals(1);5723 ZigValue *const_val = create_const_vals(1);
5724 init_const_null(const_val, type);5724 init_const_null(const_val, type);
5725 return const_val;5725 return const_val;
5726}5726}
57275727
5728void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {5728void init_const_float(ZigValue *const_val, ZigType *type, double value) {
5729 const_val->special = ConstValSpecialStatic;5729 const_val->special = ConstValSpecialStatic;
5730 const_val->type = type;5730 const_val->type = type;
5731 if (type->id == ZigTypeIdComptimeFloat) {5731 if (type->id == ZigTypeIdComptimeFloat) {
...@@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {...@@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5752 }5752 }
5753}5753}
57545754
5755ConstExprValue *create_const_float(ZigType *type, double value) {5755ZigValue *create_const_float(ZigType *type, double value) {
5756 ConstExprValue *const_val = create_const_vals(1);5756 ZigValue *const_val = create_const_vals(1);
5757 init_const_float(const_val, type, value);5757 init_const_float(const_val, type, value);
5758 return const_val;5758 return const_val;
5759}5759}
57605760
5761void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) {5761void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {
5762 const_val->special = ConstValSpecialStatic;5762 const_val->special = ConstValSpecialStatic;
5763 const_val->type = type;5763 const_val->type = type;
5764 bigint_init_bigint(&const_val->data.x_enum_tag, tag);5764 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
5765}5765}
57665766
5767ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {5767ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {
5768 ConstExprValue *const_val = create_const_vals(1);5768 ZigValue *const_val = create_const_vals(1);
5769 init_const_enum(const_val, type, tag);5769 init_const_enum(const_val, type, tag);
5770 return const_val;5770 return const_val;
5771}5771}
57725772
57735773
5774void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value) {5774void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
5775 const_val->special = ConstValSpecialStatic;5775 const_val->special = ConstValSpecialStatic;
5776 const_val->type = g->builtin_types.entry_bool;5776 const_val->type = g->builtin_types.entry_bool;
5777 const_val->data.x_bool = value;5777 const_val->data.x_bool = value;
5778}5778}
57795779
5780ConstExprValue *create_const_bool(CodeGen *g, bool value) {5780ZigValue *create_const_bool(CodeGen *g, bool value) {
5781 ConstExprValue *const_val = create_const_vals(1);5781 ZigValue *const_val = create_const_vals(1);
5782 init_const_bool(g, const_val, value);5782 init_const_bool(g, const_val, value);
5783 return const_val;5783 return const_val;
5784}5784}
57855785
5786void init_const_runtime(ConstExprValue *const_val, ZigType *type) {5786void init_const_runtime(ZigValue *const_val, ZigType *type) {
5787 const_val->special = ConstValSpecialRuntime;5787 const_val->special = ConstValSpecialRuntime;
5788 const_val->type = type;5788 const_val->type = type;
5789}5789}
57905790
5791ConstExprValue *create_const_runtime(ZigType *type) {5791ZigValue *create_const_runtime(ZigType *type) {
5792 ConstExprValue *const_val = create_const_vals(1);5792 ZigValue *const_val = create_const_vals(1);
5793 init_const_runtime(const_val, type);5793 init_const_runtime(const_val, type);
5794 return const_val;5794 return const_val;
5795}5795}
57965796
5797void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) {5797void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {
5798 const_val->special = ConstValSpecialStatic;5798 const_val->special = ConstValSpecialStatic;
5799 const_val->type = g->builtin_types.entry_type;5799 const_val->type = g->builtin_types.entry_type;
5800 const_val->data.x_type = type_value;5800 const_val->data.x_type = type_value;
5801}5801}
58025802
5803ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {5803ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {
5804 ConstExprValue *const_val = create_const_vals(1);5804 ZigValue *const_val = create_const_vals(1);
5805 init_const_type(g, const_val, type_value);5805 init_const_type(g, const_val, type_value);
5806 return const_val;5806 return const_val;
5807}5807}
58085808
5809void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5809void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5810 size_t start, size_t len, bool is_const)5810 size_t start, size_t len, bool is_const)
5811{5811{
5812 assert(array_val->type->id == ZigTypeIdArray);5812 assert(array_val->type->id == ZigTypeIdArray);
...@@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr...@@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
5823 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);5823 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);
5824}5824}
58255825
5826ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {5826ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {
5827 ConstExprValue *const_val = create_const_vals(1);5827 ZigValue *const_val = create_const_vals(1);
5828 init_const_slice(g, const_val, array_val, start, len, is_const);5828 init_const_slice(g, const_val, array_val, start, len, is_const);
5829 return const_val;5829 return const_val;
5830}5830}
58315831
5832void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5832void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5833 size_t elem_index, bool is_const, PtrLen ptr_len)5833 size_t elem_index, bool is_const, PtrLen ptr_len)
5834{5834{
5835 assert(array_val->type->id == ZigTypeIdArray);5835 assert(array_val->type->id == ZigTypeIdArray);
...@@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue...@@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue
5843 const_val->data.x_ptr.data.base_array.elem_index = elem_index;5843 const_val->data.x_ptr.data.base_array.elem_index = elem_index;
5844}5844}
58455845
5846ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index, bool is_const,5846ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,
5847 PtrLen ptr_len)5847 PtrLen ptr_len)
5848{5848{
5849 ConstExprValue *const_val = create_const_vals(1);5849 ZigValue *const_val = create_const_vals(1);
5850 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);5850 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
5851 return const_val;5851 return const_val;
5852}5852}
58535853
5854void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const) {5854void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const) {
5855 const_val->special = ConstValSpecialStatic;5855 const_val->special = ConstValSpecialStatic;
5856 const_val->type = get_pointer_to_type(g, pointee_val->type, is_const);5856 const_val->type = get_pointer_to_type(g, pointee_val->type, is_const);
5857 const_val->data.x_ptr.special = ConstPtrSpecialRef;5857 const_val->data.x_ptr.special = ConstPtrSpecialRef;
5858 const_val->data.x_ptr.data.ref.pointee = pointee_val;5858 const_val->data.x_ptr.data.ref.pointee = pointee_val;
5859}5859}
58605860
5861ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const) {5861ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {
5862 ConstExprValue *const_val = create_const_vals(1);5862 ZigValue *const_val = create_const_vals(1);
5863 init_const_ptr_ref(g, const_val, pointee_val, is_const);5863 init_const_ptr_ref(g, const_val, pointee_val, is_const);
5864 return const_val;5864 return const_val;
5865}5865}
58665866
5867void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,5867void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type,
5868 size_t addr, bool is_const)5868 size_t addr, bool is_const)
5869{5869{
5870 const_val->special = ConstValSpecialStatic;5870 const_val->special = ConstValSpecialStatic;
...@@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy...@@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy
5873 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;5873 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
5874}5874}
58755875
5876ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,5876ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
5877 size_t addr, bool is_const)5877 size_t addr, bool is_const)
5878{5878{
5879 ConstExprValue *const_val = create_const_vals(1);5879 ZigValue *const_val = create_const_vals(1);
5880 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);5880 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
5881 return const_val;5881 return const_val;
5882}5882}
58835883
5884void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end) {5884void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end) {
5885 const_val->special = ConstValSpecialStatic;5885 const_val->special = ConstValSpecialStatic;
5886 const_val->type = g->builtin_types.entry_arg_tuple;5886 const_val->type = g->builtin_types.entry_arg_tuple;
5887 const_val->data.x_arg_tuple.start_index = arg_index_start;5887 const_val->data.x_arg_tuple.start_index = arg_index_start;
5888 const_val->data.x_arg_tuple.end_index = arg_index_end;5888 const_val->data.x_arg_tuple.end_index = arg_index_end;
5889}5889}
58905890
5891ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {5891ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {
5892 ConstExprValue *const_val = create_const_vals(1);5892 ZigValue *const_val = create_const_vals(1);
5893 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);5893 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);
5894 return const_val;5894 return const_val;
5895}5895}
58965896
58975897
5898ConstExprValue *create_const_vals(size_t count) {5898ZigValue *create_const_vals(size_t count) {
5899 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");5899 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5900 ConstExprValue *vals = allocate<ConstExprValue>(count, "ConstExprValue");5900 ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
5901 for (size_t i = 0; i < count; i += 1) {5901 for (size_t i = 0; i < count; i += 1) {
5902 vals[i].global_refs = &global_refs[i];5902 vals[i].global_refs = &global_refs[i];
5903 }5903 }
5904 return vals;5904 return vals;
5905}5905}
59065906
5907ConstExprValue **alloc_const_vals_ptrs(size_t count) {5907ZigValue **alloc_const_vals_ptrs(size_t count) {
5908 return realloc_const_vals_ptrs(nullptr, 0, count);5908 return realloc_const_vals_ptrs(nullptr, 0, count);
5909}5909}
59105910
5911ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count) {5911ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count) {
5912 assert(new_count >= old_count);5912 assert(new_count >= old_count);
59135913
5914 size_t new_item_count = new_count - old_count;5914 size_t new_item_count = new_count - old_count;
5915 ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*");5915 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");
5916 ConstExprValue *vals = create_const_vals(new_item_count);5916 ZigValue *vals = create_const_vals(new_item_count);
5917 for (size_t i = old_count; i < new_count; i += 1) {5917 for (size_t i = old_count; i < new_count; i += 1) {
5918 result[i] = &vals[i - old_count];5918 result[i] = &vals[i - old_count];
5919 }5919 }
...@@ -6106,7 +6106,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6106,7 +6106,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6106 alloca_gen->base.id = IrInstructionIdAllocaGen;6106 alloca_gen->base.id = IrInstructionIdAllocaGen;
6107 alloca_gen->base.source_node = fn->proto_node;6107 alloca_gen->base.source_node = fn->proto_node;
6108 alloca_gen->base.scope = fn->child_scope;6108 alloca_gen->base.scope = fn->child_scope;
6109 alloca_gen->base.value.type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);6109 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
6110 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6110 alloca_gen->base.ref_count = 1;6111 alloca_gen->base.ref_count = 1;
6111 alloca_gen->name_hint = "";6112 alloca_gen->name_hint = "";
6112 fn->alloca_gen_list.append(alloca_gen);6113 fn->alloca_gen_list.append(alloca_gen);
...@@ -6173,7 +6174,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6173,7 +6174,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6173 call->frame_result_loc = all_calls_alloca;6174 call->frame_result_loc = all_calls_alloca;
6174 }6175 }
6175 if (largest_call_frame_type != nullptr) {6176 if (largest_call_frame_type != nullptr) {
6176 all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false);6177 all_calls_alloca->value->type = get_pointer_to_type(g, largest_call_frame_type, false);
6177 }6178 }
61786179
6179 // Since this frame is async, an await might represent a suspend point, and6180 // Since this frame is async, an await might represent a suspend point, and
...@@ -6184,7 +6185,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6184,7 +6185,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6184 IrInstructionAwaitGen *await = fn->await_list.at(i);6185 IrInstructionAwaitGen *await = fn->await_list.at(i);
6185 // TODO If this is a noasync await, it doesn't suspend6186 // TODO If this is a noasync await, it doesn't suspend
6186 // https://github.com/ziglang/zig/issues/31576187 // https://github.com/ziglang/zig/issues/3157
6187 if (await->base.value.special != ConstValSpecialRuntime) {6188 if (await->base.value->special != ConstValSpecialRuntime) {
6188 // Known at comptime. No spill, no suspend.6189 // Known at comptime. No spill, no suspend.
6189 continue;6190 continue;
6190 }6191 }
...@@ -6211,10 +6212,10 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6211,10 +6212,10 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6211 }6212 }
6212 if (await->base.ref_count == 0)6213 if (await->base.ref_count == 0)
6213 continue;6214 continue;
6214 if (!type_has_bits(await->base.value.type))6215 if (!type_has_bits(await->base.value->type))
6215 continue;6216 continue;
6216 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,6217 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
6217 await->base.value.type, "");6218 await->base.value->type, "");
6218 }6219 }
6219 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6220 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6220 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);6221 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
...@@ -6239,17 +6240,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6239,17 +6240,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6239 // This instruction does its own spilling specially, or otherwise doesn't need it.6240 // This instruction does its own spilling specially, or otherwise doesn't need it.
6240 continue;6241 continue;
6241 }6242 }
6242 if (instruction->value.special != ConstValSpecialRuntime)6243 if (instruction->value->special != ConstValSpecialRuntime)
6243 continue;6244 continue;
6244 if (instruction->ref_count == 0)6245 if (instruction->ref_count == 0)
6245 continue;6246 continue;
6246 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown)))6247 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
6247 return ErrorSemanticAnalyzeFail;6248 return ErrorSemanticAnalyzeFail;
6248 if (!type_has_bits(instruction->value.type))6249 if (!type_has_bits(instruction->value->type))
6249 continue;6250 continue;
6250 if (scope_needs_spill(instruction->scope)) {6251 if (scope_needs_spill(instruction->scope)) {
6251 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,6252 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
6252 fn, instruction->value.type, "");6253 fn, instruction->value->type, "");
6253 }6254 }
6254 }6255 }
6255 }6256 }
...@@ -6301,15 +6302,15 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6301,15 +6302,15 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6301 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {6302 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {
6302 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);6303 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);
6303 instruction->field_index = SIZE_MAX;6304 instruction->field_index = SIZE_MAX;
6304 ZigType *ptr_type = instruction->base.value.type;6305 ZigType *ptr_type = instruction->base.value->type;
6305 assert(ptr_type->id == ZigTypeIdPointer);6306 assert(ptr_type->id == ZigTypeIdPointer);
6306 ZigType *child_type = ptr_type->data.pointer.child_type;6307 ZigType *child_type = ptr_type->data.pointer.child_type;
6307 if (!type_has_bits(child_type))6308 if (!type_has_bits(child_type))
6308 continue;6309 continue;
6309 if (instruction->base.ref_count == 0)6310 if (instruction->base.ref_count == 0)
6310 continue;6311 continue;
6311 if (instruction->base.value.special != ConstValSpecialRuntime) {6312 if (instruction->base.value->special != ConstValSpecialRuntime) {
6312 if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special !=6313 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
6313 ConstValSpecialRuntime)6314 ConstValSpecialRuntime)
6314 {6315 {
6315 continue;6316 continue;
...@@ -6446,17 +6447,17 @@ bool ir_get_var_is_comptime(ZigVar *var) {...@@ -6446,17 +6447,17 @@ bool ir_get_var_is_comptime(ZigVar *var) {
6446 // When the is_comptime field references an instruction that has to get analyzed, this6447 // When the is_comptime field references an instruction that has to get analyzed, this
6447 // is the value.6448 // is the value.
6448 if (var->is_comptime->child != nullptr) {6449 if (var->is_comptime->child != nullptr) {
6449 assert(var->is_comptime->child->value.type->id == ZigTypeIdBool);6450 assert(var->is_comptime->child->value->type->id == ZigTypeIdBool);
6450 return var->is_comptime->child->value.data.x_bool;6451 return var->is_comptime->child->value->data.x_bool;
6451 }6452 }
6452 // As an optimization, is_comptime values which are constant are allowed6453 // As an optimization, is_comptime values which are constant are allowed
6453 // to be omitted from analysis. In this case, there is no child instruction6454 // to be omitted from analysis. In this case, there is no child instruction
6454 // and we simply look at the unanalyzed const parent instruction.6455 // and we simply look at the unanalyzed const parent instruction.
6455 assert(var->is_comptime->value.type->id == ZigTypeIdBool);6456 assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6456 return var->is_comptime->value.data.x_bool;6457 return var->is_comptime->value->data.x_bool;
6457}6458}
64586459
6459bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {6460bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
6460 if (a->data.x_ptr.special != b->data.x_ptr.special)6461 if (a->data.x_ptr.special != b->data.x_ptr.special)
6461 return false;6462 return false;
6462 switch (a->data.x_ptr.special) {6463 switch (a->data.x_ptr.special) {
...@@ -6527,7 +6528,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {...@@ -6527,7 +6528,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
6527 zig_unreachable();6528 zig_unreachable();
6528}6529}
65296530
6530static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprValue *b, size_t len) {6531static bool const_values_equal_array(CodeGen *g, ZigValue *a, ZigValue *b, size_t len) {
6531 assert(a->data.x_array.special != ConstArraySpecialUndef);6532 assert(a->data.x_array.special != ConstArraySpecialUndef);
6532 assert(b->data.x_array.special != ConstArraySpecialUndef);6533 assert(b->data.x_array.special != ConstArraySpecialUndef);
6533 if (a->data.x_array.special == ConstArraySpecialBuf &&6534 if (a->data.x_array.special == ConstArraySpecialBuf &&
...@@ -6538,8 +6539,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal...@@ -6538,8 +6539,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal
6538 expand_undef_array(g, a);6539 expand_undef_array(g, a);
6539 expand_undef_array(g, b);6540 expand_undef_array(g, b);
65406541
6541 ConstExprValue *a_elems = a->data.x_array.data.s_none.elements;6542 ZigValue *a_elems = a->data.x_array.data.s_none.elements;
6542 ConstExprValue *b_elems = b->data.x_array.data.s_none.elements;6543 ZigValue *b_elems = b->data.x_array.data.s_none.elements;
65436544
6544 for (size_t i = 0; i < len; i += 1) {6545 for (size_t i = 0; i < len; i += 1) {
6545 if (!const_values_equal(g, &a_elems[i], &b_elems[i]))6546 if (!const_values_equal(g, &a_elems[i], &b_elems[i]))
...@@ -6549,7 +6550,7 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal...@@ -6549,7 +6550,7 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal
6549 return true;6550 return true;
6550}6551}
65516552
6552bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {6553bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
6553 if (a->type->id != b->type->id) return false;6554 if (a->type->id != b->type->id) return false;
6554 assert(a->special == ConstValSpecialStatic);6555 assert(a->special == ConstValSpecialStatic);
6555 assert(b->special == ConstValSpecialStatic);6556 assert(b->special == ConstValSpecialStatic);
...@@ -6623,8 +6624,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {...@@ -6623,8 +6624,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
6623 }6624 }
6624 case ZigTypeIdStruct:6625 case ZigTypeIdStruct:
6625 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {6626 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
6626 ConstExprValue *field_a = a->data.x_struct.fields[i];6627 ZigValue *field_a = a->data.x_struct.fields[i];
6627 ConstExprValue *field_b = b->data.x_struct.fields[i];6628 ZigValue *field_b = b->data.x_struct.fields[i];
6628 if (!const_values_equal(g, field_a, field_b))6629 if (!const_values_equal(g, field_a, field_b))
6629 return false;6630 return false;
6630 }6631 }
...@@ -6695,7 +6696,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool...@@ -6695,7 +6696,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool
6695 }6696 }
6696}6697}
66976698
6698void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {6699void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max) {
6699 if (type_entry->id == ZigTypeIdInt) {6700 if (type_entry->id == ZigTypeIdInt) {
6700 const_val->special = ConstValSpecialStatic;6701 const_val->special = ConstValSpecialStatic;
6701 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);6702 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);
...@@ -6709,7 +6710,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v...@@ -6709,7 +6710,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v
6709 }6710 }
6710}6711}
67116712
6712static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {6713static void render_const_val_ptr(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) {
6713 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {6714 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
6714 buf_append_buf(buf, &type_entry->name);6715 buf_append_buf(buf, &type_entry->name);
6715 return;6716 return;
...@@ -6752,7 +6753,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val...@@ -6752,7 +6753,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val
6752 zig_unreachable();6753 zig_unreachable();
6753}6754}
67546755
6755static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {6756static void render_const_val_err_set(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) {
6756 if (const_val->data.x_err_set == nullptr) {6757 if (const_val->data.x_err_set == nullptr) {
6757 buf_append_str(buf, "null");6758 buf_append_str(buf, "null");
6758 } else {6759 } else {
...@@ -6760,7 +6761,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const...@@ -6760,7 +6761,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const
6760 }6761 }
6761}6762}
67626763
6763static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstExprValue *const_val, uint64_t start, uint64_t len) {6764static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValue *const_val, uint64_t start, uint64_t len) {
6764 ConstArrayValue *array = &const_val->data.x_array;6765 ConstArrayValue *array = &const_val->data.x_array;
6765 switch (array->special) {6766 switch (array->special) {
6766 case ConstArraySpecialUndef:6767 case ConstArraySpecialUndef:
...@@ -6784,7 +6785,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx...@@ -6784,7 +6785,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx
6784 return;6785 return;
6785 }6786 }
6786 case ConstArraySpecialNone: {6787 case ConstArraySpecialNone: {
6787 ConstExprValue *base = &array->data.s_none.elements[start];6788 ZigValue *base = &array->data.s_none.elements[start];
6788 assert(start + len <= const_val->type->data.array.len);6789 assert(start + len <= const_val->type->data.array.len);
67896790
6790 buf_appendf(buf, "%s{", buf_ptr(type_name));6791 buf_appendf(buf, "%s{", buf_ptr(type_name));
...@@ -6799,7 +6800,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx...@@ -6799,7 +6800,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx
6799 zig_unreachable();6800 zig_unreachable();
6800}6801}
68016802
6802void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {6803void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
6803 switch (const_val->special) {6804 switch (const_val->special) {
6804 case ConstValSpecialRuntime:6805 case ConstValSpecialRuntime:
6805 buf_appendf(buf, "(runtime value)");6806 buf_appendf(buf, "(runtime value)");
...@@ -6927,17 +6928,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -6927,17 +6928,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
6927 case ZigTypeIdStruct:6928 case ZigTypeIdStruct:
6928 {6929 {
6929 if (is_slice(type_entry)) {6930 if (is_slice(type_entry)) {
6930 ConstExprValue *len_val = const_val->data.x_struct.fields[slice_len_index];6931 ZigValue *len_val = const_val->data.x_struct.fields[slice_len_index];
6931 size_t len = bigint_as_usize(&len_val->data.x_bigint);6932 size_t len = bigint_as_usize(&len_val->data.x_bigint);
69326933
6933 ConstExprValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];6934 ZigValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];
6934 if (ptr_val->special == ConstValSpecialUndef) {6935 if (ptr_val->special == ConstValSpecialUndef) {
6935 assert(len == 0);6936 assert(len == 0);
6936 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));6937 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));
6937 return;6938 return;
6938 }6939 }
6939 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);6940 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
6940 ConstExprValue *array = ptr_val->data.x_ptr.data.base_array.array_val;6941 ZigValue *array = ptr_val->data.x_ptr.data.base_array.array_val;
6941 size_t start = ptr_val->data.x_ptr.data.base_array.elem_index;6942 size_t start = ptr_val->data.x_ptr.data.base_array.elem_index;
69426943
6943 render_const_val_array(g, buf, &type_entry->name, array, start, len);6944 render_const_val_array(g, buf, &type_entry->name, array, start, len);
...@@ -7206,7 +7207,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {...@@ -7206,7 +7207,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
7206 zig_unreachable();7207 zig_unreachable();
7207}7208}
72087209
7209static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {7210static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
7210 Error err;7211 Error err;
7211 ZigType *wanted_type = const_val->type;7212 ZigType *wanted_type = const_val->type;
7212 if (wanted_type->id == ZigTypeIdArray) {7213 if (wanted_type->id == ZigTypeIdArray) {
...@@ -7221,7 +7222,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {...@@ -7221,7 +7222,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
7221 size_t field_count = wanted_type->data.structure.src_field_count;7222 size_t field_count = wanted_type->data.structure.src_field_count;
7222 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);7223 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
7223 for (size_t i = 0; i < field_count; i += 1) {7224 for (size_t i = 0; i < field_count; i += 1) {
7224 ConstExprValue *field_val = const_val->data.x_struct.fields[i];7225 ZigValue *field_val = const_val->data.x_struct.fields[i];
7225 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);7226 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
7226 assert(field_val->type);7227 assert(field_val->type);
7227 init_const_undefined(g, field_val);7228 init_const_undefined(g, field_val);
...@@ -7234,14 +7235,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {...@@ -7234,14 +7235,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
7234 }7235 }
7235}7236}
72367237
7237void expand_undef_struct(CodeGen *g, ConstExprValue *const_val) {7238void expand_undef_struct(CodeGen *g, ZigValue *const_val) {
7238 if (const_val->special == ConstValSpecialUndef) {7239 if (const_val->special == ConstValSpecialUndef) {
7239 init_const_undefined(g, const_val);7240 init_const_undefined(g, const_val);
7240 }7241 }
7241}7242}
72427243
7243// Canonicalize the array value as ConstArraySpecialNone7244// Canonicalize the array value as ConstArraySpecialNone
7244void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {7245void expand_undef_array(CodeGen *g, ZigValue *const_val) {
7245 size_t elem_count;7246 size_t elem_count;
7246 ZigType *elem_type;7247 ZigType *elem_type;
7247 if (const_val->type->id == ZigTypeIdArray) {7248 if (const_val->type->id == ZigTypeIdArray) {
...@@ -7264,7 +7265,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -7264,7 +7265,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
7264 const_val->data.x_array.special = ConstArraySpecialNone;7265 const_val->data.x_array.special = ConstArraySpecialNone;
7265 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);7266 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7266 for (size_t i = 0; i < elem_count; i += 1) {7267 for (size_t i = 0; i < elem_count; i += 1) {
7267 ConstExprValue *element_val = &const_val->data.x_array.data.s_none.elements[i];7268 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];
7268 element_val->type = elem_type;7269 element_val->type = elem_type;
7269 init_const_undefined(g, element_val);7270 init_const_undefined(g, element_val);
7270 element_val->parent.id = ConstParentIdArray;7271 element_val->parent.id = ConstParentIdArray;
...@@ -7283,7 +7284,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -7283,7 +7284,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
7283 assert(elem_count == buf_len(buf));7284 assert(elem_count == buf_len(buf));
7284 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);7285 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7285 for (size_t i = 0; i < elem_count; i += 1) {7286 for (size_t i = 0; i < elem_count; i += 1) {
7286 ConstExprValue *this_char = &const_val->data.x_array.data.s_none.elements[i];7287 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];
7287 this_char->special = ConstValSpecialStatic;7288 this_char->special = ConstValSpecialStatic;
7288 this_char->type = g->builtin_types.entry_u8;7289 this_char->type = g->builtin_types.entry_u8;
7289 bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(buf)[i]);7290 bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(buf)[i]);
...@@ -7541,12 +7542,12 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {...@@ -7541,12 +7542,12 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {
7541 return a == b;7542 return a == b;
7542}7543}
75437544
7544ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {7545ZigValue *get_builtin_value(CodeGen *codegen, const char *name) {
7545 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));7546 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
7546 resolve_top_level_decl(codegen, tld, nullptr, false);7547 resolve_top_level_decl(codegen, tld, nullptr, false);
7547 assert(tld->id == TldIdVar);7548 assert(tld->id == TldIdVar);
7548 TldVar *tld_var = (TldVar *)tld;7549 TldVar *tld_var = (TldVar *)tld;
7549 ConstExprValue *var_value = tld_var->var->const_value;7550 ZigValue *var_value = tld_var->var->const_value;
7550 assert(var_value != nullptr);7551 assert(var_value != nullptr);
7551 return var_value;7552 return var_value;
7552}7553}
...@@ -7733,9 +7734,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f...@@ -7733,9 +7734,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f
7733}7734}
77347735
7735Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,7736Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
7736 ConstExprValue *const_val, ZigType *wanted_type)7737 ZigValue *const_val, ZigType *wanted_type)
7737{7738{
7738 ConstExprValue ptr_val = {};7739 ZigValue ptr_val = {};
7739 ptr_val.special = ConstValSpecialStatic;7740 ptr_val.special = ConstValSpecialStatic;
7740 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);7741 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);
7741 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;7742 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;
...@@ -9113,7 +9114,8 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,...@@ -9113,7 +9114,8 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
9113 alloca_gen->base.id = IrInstructionIdAllocaGen;9114 alloca_gen->base.id = IrInstructionIdAllocaGen;
9114 alloca_gen->base.source_node = source_node;9115 alloca_gen->base.source_node = source_node;
9115 alloca_gen->base.scope = scope;9116 alloca_gen->base.scope = scope;
9116 alloca_gen->base.value.type = get_pointer_to_type(g, var_type, false);9117 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
9118 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
9117 alloca_gen->base.ref_count = 1;9119 alloca_gen->base.ref_count = 1;
9118 alloca_gen->name_hint = name_hint;9120 alloca_gen->name_hint = name_hint;
9119 fn->alloca_gen_list.append(alloca_gen);9121 fn->alloca_gen_list.append(alloca_gen);
src/analyze.hpp+53-53
...@@ -25,7 +25,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type,...@@ -25,7 +25,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type,
25 bool is_const, bool is_volatile, PtrLen ptr_len,25 bool is_const, bool is_volatile, PtrLen ptr_len,
26 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,26 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,
27 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field,27 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field,
28 ConstExprValue *sentinel);28 ZigValue *sentinel);
29uint64_t type_size(CodeGen *g, ZigType *type_entry);29uint64_t type_size(CodeGen *g, ZigType *type_entry);
30uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);30uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
31ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);31ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
...@@ -34,7 +34,7 @@ ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);...@@ -34,7 +34,7 @@ ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
34ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);34ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
35ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);35ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
36ZigType *get_optional_type(CodeGen *g, ZigType *child_type);36ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
37ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel);37ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel);
38ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);38ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
39ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,39ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
40 AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);40 AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);
...@@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope);...@@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope);
95ScopeTypeOf *get_scope_typeof(Scope *scope);95ScopeTypeOf *get_scope_typeof(Scope *scope);
96void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);96void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
97ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,97ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
98 bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type);98 bool is_const, ZigValue *init_value, Tld *src_tld, ZigType *var_type);
99ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);99ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);
101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);
...@@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);...@@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);
106void complete_enum(CodeGen *g, ZigType *enum_type);106void complete_enum(CodeGen *g, ZigType *enum_type);
107bool ir_get_var_is_comptime(ZigVar *var);107bool ir_get_var_is_comptime(ZigVar *var);
108bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b);108bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b);
109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max);
110void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);110void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
111111
112void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);112void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val);
113113
114ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent);114ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent);
115ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent);115ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent);
...@@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct...@@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct
124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
127void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);127void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);130void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint);
131ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);131ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint);
132132
133void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);133void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative);
134ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);134ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
135135
136void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);136void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x);
137ConstExprValue *create_const_signed(ZigType *type, int64_t x);137ZigValue *create_const_signed(ZigType *type, int64_t x);
138138
139void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142void init_const_float(ConstExprValue *const_val, ZigType *type, double value);142void init_const_float(ZigValue *const_val, ZigType *type, double value);
143ConstExprValue *create_const_float(ZigType *type, double value);143ZigValue *create_const_float(ZigType *type, double value);
144144
145void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);145void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag);
146ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);146ZigValue *create_const_enum(ZigType *type, const BigInt *tag);
147147
148void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149ConstExprValue *create_const_bool(CodeGen *g, bool value);149ZigValue *create_const_bool(CodeGen *g, bool value);
150150
151void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);151void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154void init_const_runtime(ConstExprValue *const_val, ZigType *type);154void init_const_runtime(ZigValue *const_val, ZigType *type);
155ConstExprValue *create_const_runtime(ZigType *type);155ZigValue *create_const_runtime(ZigType *type);
156156
157void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);
158ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);158ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const);
159159
160void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,160void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type,
161 size_t addr, bool is_const);161 size_t addr, bool is_const);
162ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,162ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
163 size_t addr, bool is_const);163 size_t addr, bool is_const);
164164
165void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,165void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
166 size_t elem_index, bool is_const, PtrLen ptr_len);166 size_t elem_index, bool is_const, PtrLen ptr_len);
167ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index,167ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index,
168 bool is_const, PtrLen ptr_len);168 bool is_const, PtrLen ptr_len);
169169
170void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,170void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
171 size_t start, size_t len, bool is_const);171 size_t start, size_t len, bool is_const);
172ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const);172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);174void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end);
175ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);175ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
176176
177void init_const_null(ConstExprValue *const_val, ZigType *type);177void init_const_null(ZigValue *const_val, ZigType *type);
178ConstExprValue *create_const_null(ZigType *type);178ZigValue *create_const_null(ZigType *type);
179179
180ConstExprValue *create_const_vals(size_t count);180ZigValue *create_const_vals(size_t count);
181ConstExprValue **alloc_const_vals_ptrs(size_t count);181ZigValue **alloc_const_vals_ptrs(size_t count);
182ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);182ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
183183
184TypeStructField **alloc_type_struct_fields(size_t count);184TypeStructField **alloc_type_struct_fields(size_t count);
185TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);185TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
186186
187ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);187ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
188void expand_undef_array(CodeGen *g, ConstExprValue *const_val);188void expand_undef_array(CodeGen *g, ZigValue *const_val);
189void expand_undef_struct(CodeGen *g, ConstExprValue *const_val);189void expand_undef_struct(CodeGen *g, ZigValue *const_val);
190void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);190void update_compile_var(CodeGen *g, Buf *name, ZigValue *value);
191191
192const char *type_id_name(ZigTypeId id);192const char *type_id_name(ZigTypeId id);
193ZigTypeId type_id_at_index(size_t index);193ZigTypeId type_id_at_index(size_t index);
...@@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);...@@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
201ZigType *get_align_amt_type(CodeGen *g);201ZigType *get_align_amt_type(CodeGen *g);
202ZigPackage *new_anonymous_package(void);202ZigPackage *new_anonymous_package(void);
203203
204Buf *const_value_to_buffer(ConstExprValue *const_val);204Buf *const_value_to_buffer(ZigValue *const_val);
205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);
206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);
207207
208208
209ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);209ZigValue *get_builtin_value(CodeGen *codegen, const char *name);
210ZigType *get_stack_trace_type(CodeGen *g);210ZigType *get_stack_trace_type(CodeGen *g);
211bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);211bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);
212212
...@@ -242,7 +242,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);...@@ -242,7 +242,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);
242OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);242OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);
243243
244Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,244Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
245 ConstExprValue *const_val, ZigType *wanted_type);245 ZigValue *const_val, ZigType *wanted_type);
246246
247void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);247void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
248Buf *type_bare_name(ZigType *t);248Buf *type_bare_name(ZigType *t);
...@@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa...@@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
256256
257void src_assert(bool ok, AstNode *source_node);257void src_assert(bool ok, AstNode *source_node);
258bool is_container(ZigType *type_entry);258bool is_container(ZigType *type_entry);
259ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,259ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
260 Buf *type_name, UndefAllowed undef);260 Buf *type_name, UndefAllowed undef);
261261
262void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);262void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);
263bool fn_is_async(ZigFn *fn);263bool fn_is_async(ZigFn *fn);
264264
265Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align);265Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align);
266Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val,266Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,
267 size_t *abi_size, size_t *size_in_bits);267 size_t *abi_size, size_t *size_in_bits);
268Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,268Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
269 ConstExprValue *parent_type_val, bool *is_zero_bits);269 ZigValue *parent_type_val, bool *is_zero_bits);
270ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);270ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);
271ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);271ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
272272
...@@ -276,5 +276,5 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,...@@ -276,5 +276,5 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
276 ZigType *var_type, const char *name_hint);276 ZigType *var_type, const char *name_hint);
277Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,277Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
278 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);278 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
279ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);279ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
280#endif280#endif
src/bigint.cpp+5
...@@ -195,6 +195,11 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {...@@ -195,6 +195,11 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {
195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);
196}196}
197197
198void bigint_deinit(BigInt *bi) {
199 if (bi->digit_count > 1)
200 deallocate<uint64_t>(bi->data.digits, bi->digit_count);
201}
202
198void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
199 float128_t zero;204 float128_t zero;
200 ui32_to_f128M(0, &zero);205 ui32_to_f128M(0, &zero);
src/bigint.hpp+1
...@@ -34,6 +34,7 @@ void bigint_init_signed(BigInt *dest, int64_t x);...@@ -34,6 +34,7 @@ void bigint_init_signed(BigInt *dest, int64_t x);
34void bigint_init_bigint(BigInt *dest, const BigInt *src);34void bigint_init_bigint(BigInt *dest, const BigInt *src);
35void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);35void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);
36void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);36void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);
37void bigint_deinit(BigInt *bi);
3738
38// panics if number won't fit39// panics if number won't fit
39uint64_t bigint_as_u64(const BigInt *bigint);40uint64_t bigint_as_u64(const BigInt *bigint);
src/codegen.cpp+232-202
...@@ -185,11 +185,11 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {...@@ -185,11 +185,11 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {
185}185}
186186
187187
188static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);188static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name);
189static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name);189static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name);
190static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);190static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name);
191static void generate_error_name_table(CodeGen *g);191static void generate_error_name_table(CodeGen *g);
192static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val);192static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
193static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);193static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
194static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);194static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
195static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,195static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
...@@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {...@@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
945}945}
946946
947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
948 ConstExprValue *val = &g->panic_msg_vals[msg_id];948 ZigValue *val = &g->panic_msg_vals[msg_id];
949 if (!val->global_refs->llvm_global) {949 if (!val->global_refs->llvm_global) {
950950
951 Buf *buf_msg = panic_msg_buf(msg_id);951 Buf *buf_msg = panic_msg_buf(msg_id);
952 ConstExprValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;952 ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;
953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);
954954
955 render_const_val(g, val, "");955 render_const_val(g, val, "");
...@@ -1700,37 +1700,37 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {...@@ -1700,37 +1700,37 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
17001700
1701static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {1701static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1702 Error err;1702 Error err;
1703 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) {1703 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown))) {
1704 codegen_report_errors_and_exit(g);1704 codegen_report_errors_and_exit(g);
1705 }1705 }
1706 if (!type_has_bits(instruction->value.type))1706 if (!type_has_bits(instruction->value->type))
1707 return nullptr;1707 return nullptr;
1708 if (!instruction->llvm_value) {1708 if (!instruction->llvm_value) {
1709 if (instruction->id == IrInstructionIdAwaitGen) {1709 if (instruction->id == IrInstructionIdAwaitGen) {
1710 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);1710 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);
1711 if (await->result_loc != nullptr) {1711 if (await->result_loc != nullptr) {
1712 return get_handle_value(g, ir_llvm_value(g, await->result_loc),1712 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
1713 await->result_loc->value.type->data.pointer.child_type, await->result_loc->value.type);1713 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);
1714 }1714 }
1715 }1715 }
1716 if (instruction->spill != nullptr) {1716 if (instruction->spill != nullptr) {
1717 ZigType *ptr_type = instruction->spill->value.type;1717 ZigType *ptr_type = instruction->spill->value->type;
1718 ir_assert(ptr_type->id == ZigTypeIdPointer, instruction);1718 ir_assert(ptr_type->id == ZigTypeIdPointer, instruction);
1719 return get_handle_value(g, ir_llvm_value(g, instruction->spill),1719 return get_handle_value(g, ir_llvm_value(g, instruction->spill),
1720 ptr_type->data.pointer.child_type, instruction->spill->value.type);1720 ptr_type->data.pointer.child_type, instruction->spill->value->type);
1721 }1721 }
1722 ir_assert(instruction->value.special != ConstValSpecialRuntime, instruction);1722 ir_assert(instruction->value->special != ConstValSpecialRuntime, instruction);
1723 assert(instruction->value.type);1723 assert(instruction->value->type);
1724 render_const_val(g, &instruction->value, "");1724 render_const_val(g, instruction->value, "");
1725 // we might have to do some pointer casting here due to the way union1725 // we might have to do some pointer casting here due to the way union
1726 // values are rendered with a type other than the one we expect1726 // values are rendered with a type other than the one we expect
1727 if (handle_is_ptr(instruction->value.type)) {1727 if (handle_is_ptr(instruction->value->type)) {
1728 render_const_val_global(g, &instruction->value, "");1728 render_const_val_global(g, instruction->value, "");
1729 ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);1729 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);
1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, get_llvm_type(g, ptr_type), "");1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_global, get_llvm_type(g, ptr_type), "");
1731 } else {1731 } else {
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value,1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_value,
1733 get_llvm_type(g, instruction->value.type), "");1733 get_llvm_type(g, instruction->value->type), "");
1734 }1734 }
1735 assert(instruction->llvm_value);1735 assert(instruction->llvm_value);
1736 }1736 }
...@@ -1791,7 +1791,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1791,7 +1791,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1791 if (src_i >= fn_walk->data.call.inst->arg_count)1791 if (src_i >= fn_walk->data.call.inst->arg_count)
1792 return false;1792 return false;
1793 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];1793 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
1794 ty = arg->value.type;1794 ty = arg->value->type;
1795 source_node = arg->source_node;1795 source_node = arg->source_node;
1796 val = ir_llvm_value(g, arg);1796 val = ir_llvm_value(g, arg);
1797 break;1797 break;
...@@ -2029,7 +2029,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2029,7 +2029,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2029 bool is_var_args = fn_walk->data.call.is_var_args;2029 bool is_var_args = fn_walk->data.call.is_var_args;
2030 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {2030 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2031 IrInstruction *param_instruction = instruction->args[call_i];2031 IrInstruction *param_instruction = instruction->args[call_i];
2032 ZigType *param_type = param_instruction->value.type;2032 ZigType *param_type = param_instruction->value->type;
2033 if (is_var_args || type_has_bits(param_type)) {2033 if (is_var_args || type_has_bits(param_type)) {
2034 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);2034 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
2035 assert(param_value);2035 assert(param_value);
...@@ -2345,13 +2345,13 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV...@@ -2345,13 +2345,13 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
2345static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {2345static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2346 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2346 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
23472347
2348 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value.type : nullptr;2348 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
2349 bool operand_has_bits = (operand_type != nullptr) && type_has_bits(operand_type);2349 bool operand_has_bits = (operand_type != nullptr) && type_has_bits(operand_type);
2350 ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;2350 ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
2351 bool ret_type_has_bits = type_has_bits(ret_type);2351 bool ret_type_has_bits = type_has_bits(ret_type);
23522352
2353 if (operand_has_bits && instruction->operand != nullptr) {2353 if (operand_has_bits && instruction->operand != nullptr) {
2354 bool need_store = instruction->operand->value.special != ConstValSpecialRuntime || !handle_is_ptr(ret_type);2354 bool need_store = instruction->operand->value->special != ConstValSpecialRuntime || !handle_is_ptr(ret_type);
2355 if (need_store) {2355 if (need_store) {
2356 // It didn't get written to the result ptr. We do that now.2356 // It didn't get written to the result ptr. We do that now.
2357 ZigType *ret_ptr_type = get_pointer_to_type(g, ret_type, true);2357 ZigType *ret_ptr_type = get_pointer_to_type(g, ret_type, true);
...@@ -2448,9 +2448,9 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns...@@ -2448,9 +2448,9 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
2448 return nullptr;2448 return nullptr;
2449 }2449 }
2450 assert(g->cur_ret_ptr);2450 assert(g->cur_ret_ptr);
2451 ir_assert(instruction->operand->value.special != ConstValSpecialRuntime, &instruction->base);2451 ir_assert(instruction->operand->value->special != ConstValSpecialRuntime, &instruction->base);
2452 LLVMValueRef value = ir_llvm_value(g, instruction->operand);2452 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
2453 ZigType *return_type = instruction->operand->value.type;2453 ZigType *return_type = instruction->operand->value->type;
2454 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);2454 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
2455 LLVMBuildRetVoid(g->builder);2455 LLVMBuildRetVoid(g->builder);
2456 } else if (g->cur_fn->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync &&2456 } else if (g->cur_fn->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync &&
...@@ -2784,7 +2784,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2784,7 +2784,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2784 IrInstruction *op1 = bin_op_instruction->op1;2784 IrInstruction *op1 = bin_op_instruction->op1;
2785 IrInstruction *op2 = bin_op_instruction->op2;2785 IrInstruction *op2 = bin_op_instruction->op2;
27862786
2787 ZigType *operand_type = op1->value.type;2787 ZigType *operand_type = op1->value->type;
2788 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;2788 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
27892789
2790 bool want_runtime_safety = bin_op_instruction->safety_check_on &&2790 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
...@@ -2884,7 +2884,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2884,7 +2884,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2884 case IrBinOpBitShiftLeftExact:2884 case IrBinOpBitShiftLeftExact:
2885 {2885 {
2886 assert(scalar_type->id == ZigTypeIdInt);2886 assert(scalar_type->id == ZigTypeIdInt);
2887 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value);2887 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value->type, scalar_type, op2_value);
2888 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);2888 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
2889 if (is_sloppy) {2889 if (is_sloppy) {
2890 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");2890 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");
...@@ -2900,7 +2900,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2900,7 +2900,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2900 case IrBinOpBitShiftRightExact:2900 case IrBinOpBitShiftRightExact:
2901 {2901 {
2902 assert(scalar_type->id == ZigTypeIdInt);2902 assert(scalar_type->id == ZigTypeIdInt);
2903 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value);2903 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value->type, scalar_type, op2_value);
2904 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);2904 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
2905 if (is_sloppy) {2905 if (is_sloppy) {
2906 if (scalar_type->data.integral.is_signed) {2906 if (scalar_type->data.integral.is_signed) {
...@@ -2990,8 +2990,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in...@@ -2990,8 +2990,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
2990static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,2990static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
2991 IrInstructionResizeSlice *instruction)2991 IrInstructionResizeSlice *instruction)
2992{2992{
2993 ZigType *actual_type = instruction->operand->value.type;2993 ZigType *actual_type = instruction->operand->value->type;
2994 ZigType *wanted_type = instruction->base.value.type;2994 ZigType *wanted_type = instruction->base.value->type;
2995 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);2995 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);
2996 assert(expr_val);2996 assert(expr_val);
29972997
...@@ -3058,8 +3058,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,...@@ -3058,8 +3058,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
3058static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,3058static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3059 IrInstructionCast *cast_instruction)3059 IrInstructionCast *cast_instruction)
3060{3060{
3061 ZigType *actual_type = cast_instruction->value->value.type;3061 ZigType *actual_type = cast_instruction->value->value->type;
3062 ZigType *wanted_type = cast_instruction->base.value.type;3062 ZigType *wanted_type = cast_instruction->base.value->type;
3063 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);3063 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
3064 assert(expr_val);3064 assert(expr_val);
30653065
...@@ -3136,8 +3136,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -3136,8 +3136,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3136static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,3136static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,
3137 IrInstructionPtrOfArrayToSlice *instruction)3137 IrInstructionPtrOfArrayToSlice *instruction)
3138{3138{
3139 ZigType *actual_type = instruction->operand->value.type;3139 ZigType *actual_type = instruction->operand->value->type;
3140 ZigType *slice_type = instruction->base.value.type;3140 ZigType *slice_type = instruction->base.value->type;
3141 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;3141 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
3142 size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;3142 size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
3143 size_t len_index = slice_type->data.structure.fields[slice_len_index]->gen_index;3143 size_t len_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
...@@ -3173,7 +3173,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex...@@ -3173,7 +3173,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
3173static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,3173static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3174 IrInstructionPtrCastGen *instruction)3174 IrInstructionPtrCastGen *instruction)
3175{3175{
3176 ZigType *wanted_type = instruction->base.value.type;3176 ZigType *wanted_type = instruction->base.value->type;
3177 if (!type_has_bits(wanted_type)) {3177 if (!type_has_bits(wanted_type)) {
3178 return nullptr;3178 return nullptr;
3179 }3179 }
...@@ -3199,8 +3199,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,...@@ -3199,8 +3199,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3199static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,3199static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3200 IrInstructionBitCastGen *instruction)3200 IrInstructionBitCastGen *instruction)
3201{3201{
3202 ZigType *wanted_type = instruction->base.value.type;3202 ZigType *wanted_type = instruction->base.value->type;
3203 ZigType *actual_type = instruction->operand->value.type;3203 ZigType *actual_type = instruction->operand->value->type;
3204 LLVMValueRef value = ir_llvm_value(g, instruction->operand);3204 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
32053205
3206 bool wanted_is_ptr = handle_is_ptr(wanted_type);3206 bool wanted_is_ptr = handle_is_ptr(wanted_type);
...@@ -3223,7 +3223,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,...@@ -3223,7 +3223,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3223static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,3223static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
3224 IrInstructionWidenOrShorten *instruction)3224 IrInstructionWidenOrShorten *instruction)
3225{3225{
3226 ZigType *actual_type = instruction->target->value.type;3226 ZigType *actual_type = instruction->target->value->type;
3227 // TODO instead of this logic, use the Noop instruction to change the type from3227 // TODO instead of this logic, use the Noop instruction to change the type from
3228 // enum_tag to the underlying int type3228 // enum_tag to the underlying int type
3229 ZigType *int_type;3229 ZigType *int_type;
...@@ -3234,11 +3234,11 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa...@@ -3234,11 +3234,11 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
3234 }3234 }
3235 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3235 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3236 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), int_type,3236 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), int_type,
3237 instruction->base.value.type, target_val);3237 instruction->base.value->type, target_val);
3238}3238}
32393239
3240static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {3240static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {
3241 ZigType *wanted_type = instruction->base.value.type;3241 ZigType *wanted_type = instruction->base.value->type;
3242 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3242 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3243 if (!ptr_allows_addr_zero(wanted_type) && ir_want_runtime_safety(g, &instruction->base)) {3243 if (!ptr_allows_addr_zero(wanted_type) && ir_want_runtime_safety(g, &instruction->base)) {
3244 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(target_val));3244 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(target_val));
...@@ -3256,19 +3256,19 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I...@@ -3256,19 +3256,19 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
3256}3256}
32573257
3258static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {3258static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {
3259 ZigType *wanted_type = instruction->base.value.type;3259 ZigType *wanted_type = instruction->base.value->type;
3260 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3260 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3261 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");3261 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
3262}3262}
32633263
3264static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {3264static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
3265 ZigType *wanted_type = instruction->base.value.type;3265 ZigType *wanted_type = instruction->base.value->type;
3266 assert(wanted_type->id == ZigTypeIdEnum);3266 assert(wanted_type->id == ZigTypeIdEnum);
3267 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;3267 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
32683268
3269 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3269 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3270 LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),3270 LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
3271 instruction->target->value.type, tag_int_type, target_val);3271 instruction->target->value->type, tag_int_type, target_val);
32723272
3273 if (ir_want_runtime_safety(g, &instruction->base)) {3273 if (ir_want_runtime_safety(g, &instruction->base)) {
3274 LLVMBasicBlockRef bad_value_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadValue");3274 LLVMBasicBlockRef bad_value_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadValue");
...@@ -3289,10 +3289,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,...@@ -3289,10 +3289,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
3289}3289}
32903290
3291static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {3291static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
3292 ZigType *wanted_type = instruction->base.value.type;3292 ZigType *wanted_type = instruction->base.value->type;
3293 assert(wanted_type->id == ZigTypeIdErrorSet);3293 assert(wanted_type->id == ZigTypeIdErrorSet);
32943294
3295 ZigType *actual_type = instruction->target->value.type;3295 ZigType *actual_type = instruction->target->value->type;
3296 assert(actual_type->id == ZigTypeIdInt);3296 assert(actual_type->id == ZigTypeIdInt);
3297 assert(!actual_type->data.integral.is_signed);3297 assert(!actual_type->data.integral.is_signed);
32983298
...@@ -3306,11 +3306,11 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -3306,11 +3306,11 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
3306}3306}
33073307
3308static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {3308static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
3309 ZigType *wanted_type = instruction->base.value.type;3309 ZigType *wanted_type = instruction->base.value->type;
3310 assert(wanted_type->id == ZigTypeIdInt);3310 assert(wanted_type->id == ZigTypeIdInt);
3311 assert(!wanted_type->data.integral.is_signed);3311 assert(!wanted_type->data.integral.is_signed);
33123312
3313 ZigType *actual_type = instruction->target->value.type;3313 ZigType *actual_type = instruction->target->value->type;
3314 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3314 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33153315
3316 if (actual_type->id == ZigTypeIdErrorSet) {3316 if (actual_type->id == ZigTypeIdErrorSet) {
...@@ -3360,7 +3360,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc...@@ -3360,7 +3360,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
3360static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {3360static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
3361 IrUnOp op_id = un_op_instruction->op_id;3361 IrUnOp op_id = un_op_instruction->op_id;
3362 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);3362 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
3363 ZigType *operand_type = un_op_instruction->value->value.type;3363 ZigType *operand_type = un_op_instruction->value->value->type;
3364 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;3364 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
33653365
3366 switch (op_id) {3366 switch (op_id) {
...@@ -3419,12 +3419,12 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrI...@@ -3419,12 +3419,12 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrI
3419static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,3419static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
3420 IrInstructionLoadPtrGen *instruction)3420 IrInstructionLoadPtrGen *instruction)
3421{3421{
3422 ZigType *child_type = instruction->base.value.type;3422 ZigType *child_type = instruction->base.value->type;
3423 if (!type_has_bits(child_type))3423 if (!type_has_bits(child_type))
3424 return nullptr;3424 return nullptr;
34253425
3426 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3426 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
3427 ZigType *ptr_type = instruction->ptr->value.type;3427 ZigType *ptr_type = instruction->ptr->value->type;
3428 assert(ptr_type->id == ZigTypeIdPointer);3428 assert(ptr_type->id == ZigTypeIdPointer);
34293429
3430 ir_assert(ptr_type->data.pointer.vector_index != VECTOR_INDEX_RUNTIME, &instruction->base);3430 ir_assert(ptr_type->data.pointer.vector_index != VECTOR_INDEX_RUNTIME, &instruction->base);
...@@ -3474,7 +3474,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,...@@ -3474,7 +3474,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
3474 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");3474 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");
3475}3475}
34763476
3477static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size_t len) {3477static bool value_is_all_undef_array(CodeGen *g, ZigValue *const_val, size_t len) {
3478 switch (const_val->data.x_array.special) {3478 switch (const_val->data.x_array.special) {
3479 case ConstArraySpecialUndef:3479 case ConstArraySpecialUndef:
3480 return true;3480 return true;
...@@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size...@@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size
3490 zig_unreachable();3490 zig_unreachable();
3491}3491}
34923492
3493static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {3493static bool value_is_all_undef(CodeGen *g, ZigValue *const_val) {
3494 Error err;3494 Error err;
3495 if (const_val->special == ConstValSpecialLazy &&3495 if (const_val->special == ConstValSpecialLazy &&
3496 (err = ir_resolve_lazy(g, nullptr, const_val)))3496 (err = ir_resolve_lazy(g, nullptr, const_val)))
...@@ -3622,7 +3622,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_...@@ -3622,7 +3622,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
3622static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {3622static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
3623 Error err;3623 Error err;
36243624
3625 ZigType *ptr_type = instruction->ptr->value.type;3625 ZigType *ptr_type = instruction->ptr->value->type;
3626 assert(ptr_type->id == ZigTypeIdPointer);3626 assert(ptr_type->id == ZigTypeIdPointer);
3627 bool ptr_type_has_bits;3627 bool ptr_type_has_bits;
3628 if ((err = type_has_bits2(g, ptr_type, &ptr_type_has_bits)))3628 if ((err = type_has_bits2(g, ptr_type, &ptr_type_has_bits)))
...@@ -3639,13 +3639,13 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -3639,13 +3639,13 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
3639 return nullptr;3639 return nullptr;
3640 }3640 }
36413641
3642 bool have_init_expr = !value_is_all_undef(g, &instruction->value->value);3642 bool have_init_expr = !value_is_all_undef(g, instruction->value->value);
3643 if (have_init_expr) {3643 if (have_init_expr) {
3644 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3644 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
3645 LLVMValueRef value = ir_llvm_value(g, instruction->value);3645 LLVMValueRef value = ir_llvm_value(g, instruction->value);
3646 gen_assign_raw(g, ptr, ptr_type, value);3646 gen_assign_raw(g, ptr, ptr_type, value);
3647 } else if (ir_want_runtime_safety(g, &instruction->base)) {3647 } else if (ir_want_runtime_safety(g, &instruction->base)) {
3648 gen_undef_init(g, get_ptr_align(g, ptr_type), instruction->value->value.type,3648 gen_undef_init(g, get_ptr_align(g, ptr_type), instruction->value->value->type,
3649 ir_llvm_value(g, instruction->ptr));3649 ir_llvm_value(g, instruction->ptr));
3650 }3650 }
3651 return nullptr;3651 return nullptr;
...@@ -3658,14 +3658,14 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut...@@ -3658,14 +3658,14 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
3658 LLVMValueRef index = ir_llvm_value(g, instruction->index);3658 LLVMValueRef index = ir_llvm_value(g, instruction->index);
3659 LLVMValueRef value = ir_llvm_value(g, instruction->value);3659 LLVMValueRef value = ir_llvm_value(g, instruction->value);
36603660
3661 LLVMValueRef loaded_vector = gen_load(g, vector_ptr, instruction->vector_ptr->value.type, "");3661 LLVMValueRef loaded_vector = gen_load(g, vector_ptr, instruction->vector_ptr->value->type, "");
3662 LLVMValueRef modified_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, index, "");3662 LLVMValueRef modified_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, index, "");
3663 gen_store(g, modified_vector, vector_ptr, instruction->vector_ptr->value.type);3663 gen_store(g, modified_vector, vector_ptr, instruction->vector_ptr->value->type);
3664 return nullptr;3664 return nullptr;
3665}3665}
36663666
3667static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {3667static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
3668 if (instruction->base.value.special != ConstValSpecialRuntime)3668 if (instruction->base.value->special != ConstValSpecialRuntime)
3669 return ir_llvm_value(g, &instruction->base);3669 return ir_llvm_value(g, &instruction->base);
3670 ZigVar *var = instruction->var;3670 ZigVar *var = instruction->var;
3671 if (type_has_bits(var->var_type)) {3671 if (type_has_bits(var->var_type)) {
...@@ -3679,7 +3679,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -3679,7 +3679,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
3679static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,3679static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3680 IrInstructionReturnPtr *instruction)3680 IrInstructionReturnPtr *instruction)
3681{3681{
3682 if (!type_has_bits(instruction->base.value.type))3682 if (!type_has_bits(instruction->base.value->type))
3683 return nullptr;3683 return nullptr;
3684 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);3684 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);
3685 return g->cur_ret_ptr;3685 return g->cur_ret_ptr;
...@@ -3687,7 +3687,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,...@@ -3687,7 +3687,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
36873687
3688static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {3688static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
3689 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);3689 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
3690 ZigType *array_ptr_type = instruction->array_ptr->value.type;3690 ZigType *array_ptr_type = instruction->array_ptr->value->type;
3691 assert(array_ptr_type->id == ZigTypeIdPointer);3691 assert(array_ptr_type->id == ZigTypeIdPointer);
3692 ZigType *array_type = array_ptr_type->data.pointer.child_type;3692 ZigType *array_type = array_ptr_type->data.pointer.child_type;
3693 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);3693 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
...@@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
3719 if (child_type->id == ZigTypeIdStruct &&3719 if (child_type->id == ZigTypeIdStruct &&
3720 child_type->data.structure.layout == ContainerLayoutPacked)3720 child_type->data.structure.layout == ContainerLayoutPacked)
3721 {3721 {
3722 ZigType *ptr_type = instruction->base.value.type;3722 ZigType *ptr_type = instruction->base.value->type;
3723 size_t host_int_bytes = ptr_type->data.pointer.host_int_bytes;3723 size_t host_int_bytes = ptr_type->data.pointer.host_int_bytes;
3724 if (host_int_bytes != 0) {3724 if (host_int_bytes != 0) {
3725 uint32_t size_in_bits = type_size_bits(g, ptr_type->data.pointer.child_type);3725 uint32_t size_in_bits = type_size_bits(g, ptr_type->data.pointer.child_type);
...@@ -3941,7 +3941,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3941,7 +3941,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3941 } else {3941 } else {
3942 assert(instruction->fn_ref);3942 assert(instruction->fn_ref);
3943 fn_val = ir_llvm_value(g, instruction->fn_ref);3943 fn_val = ir_llvm_value(g, instruction->fn_ref);
3944 fn_type = instruction->fn_ref->value.type;3944 fn_type = instruction->fn_ref->value->type;
3945 callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync;3945 callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync;
3946 }3946 }
39473947
...@@ -3975,8 +3975,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3975,8 +3975,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3975 LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), "");3975 LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), "");
3976 }3976 }
3977 } else {3977 } else {
3978 if (instruction->new_stack->value.type->id == ZigTypeIdPointer &&3978 if (instruction->new_stack->value->type->id == ZigTypeIdPointer &&
3979 instruction->new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)3979 instruction->new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
3980 {3980 {
3981 frame_result_loc = ir_llvm_value(g, instruction->new_stack);3981 frame_result_loc = ir_llvm_value(g, instruction->new_stack);
3982 } else {3982 } else {
...@@ -4189,7 +4189,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4189,7 +4189,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4189 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);4189 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
4190 if (instruction->new_stack != nullptr) {4190 if (instruction->new_stack != nullptr) {
4191 return LLVMBuildBitCast(g->builder, frame_result_loc,4191 return LLVMBuildBitCast(g->builder, frame_result_loc,
4192 get_llvm_type(g, instruction->base.value.type), "");4192 get_llvm_type(g, instruction->base.value->type), "");
4193 }4193 }
4194 return nullptr;4194 return nullptr;
4195 } else if (instruction->modifier == CallModifierNoAsync && !fn_is_async(g->cur_fn)) {4195 } else if (instruction->modifier == CallModifierNoAsync && !fn_is_async(g->cur_fn)) {
...@@ -4214,7 +4214,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4214,7 +4214,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4214 LLVMPositionBuilderAtEnd(g->builder, ok_block);4214 LLVMPositionBuilderAtEnd(g->builder, ok_block);
4215 }4215 }
42164216
4217 ZigType *result_type = instruction->base.value.type;4217 ZigType *result_type = instruction->base.value->type;
4218 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);4218 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);
4219 return gen_await_early_return(g, &instruction->base, frame_result_loc,4219 return gen_await_early_return(g, &instruction->base, frame_result_loc,
4220 result_type, ptr_result_type, result_loc, true);4220 result_type, ptr_result_type, result_loc, true);
...@@ -4285,7 +4285,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4285,7 +4285,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4285 return result_loc;4285 return result_loc;
4286 } else if (handle_is_ptr(src_return_type)) {4286 } else if (handle_is_ptr(src_return_type)) {
4287 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);4287 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
4288 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value.type));4288 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value->type));
4289 return result_loc;4289 return result_loc;
4290 } else if (!callee_is_async && instruction->modifier == CallModifierAsync) {4290 } else if (!callee_is_async && instruction->modifier == CallModifierAsync) {
4291 LLVMBuildStore(g->builder, result, ret_ptr);4291 LLVMBuildStore(g->builder, result, ret_ptr);
...@@ -4300,12 +4300,12 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -4300,12 +4300,12 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
4300{4300{
4301 Error err;4301 Error err;
43024302
4303 if (instruction->base.value.special != ConstValSpecialRuntime)4303 if (instruction->base.value->special != ConstValSpecialRuntime)
4304 return nullptr;4304 return nullptr;
43054305
4306 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);4306 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
4307 // not necessarily a pointer. could be ZigTypeIdStruct4307 // not necessarily a pointer. could be ZigTypeIdStruct
4308 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;4308 ZigType *struct_ptr_type = instruction->struct_ptr->value->type;
4309 TypeStructField *field = instruction->field;4309 TypeStructField *field = instruction->field;
43104310
4311 if (!type_has_bits(field->type_entry))4311 if (!type_has_bits(field->type_entry))
...@@ -4324,7 +4324,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -4324,7 +4324,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
43244324
4325 ir_assert(field->gen_index != SIZE_MAX, &instruction->base);4325 ir_assert(field->gen_index != SIZE_MAX, &instruction->base);
4326 LLVMValueRef field_ptr_val = LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");4326 LLVMValueRef field_ptr_val = LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");
4327 ZigType *res_type = instruction->base.value.type;4327 ZigType *res_type = instruction->base.value->type;
4328 ir_assert(res_type->id == ZigTypeIdPointer, &instruction->base);4328 ir_assert(res_type->id == ZigTypeIdPointer, &instruction->base);
4329 if (res_type->data.pointer.host_int_bytes != 0) {4329 if (res_type->data.pointer.host_int_bytes != 0) {
4330 // We generate packed structs with get_llvm_type_of_n_bytes, which is4330 // We generate packed structs with get_llvm_type_of_n_bytes, which is
...@@ -4340,10 +4340,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -4340,10 +4340,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
4340static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,4340static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
4341 IrInstructionUnionFieldPtr *instruction)4341 IrInstructionUnionFieldPtr *instruction)
4342{4342{
4343 if (instruction->base.value.special != ConstValSpecialRuntime)4343 if (instruction->base.value->special != ConstValSpecialRuntime)
4344 return nullptr;4344 return nullptr;
43454345
4346 ZigType *union_ptr_type = instruction->union_ptr->value.type;4346 ZigType *union_ptr_type = instruction->union_ptr->value->type;
4347 assert(union_ptr_type->id == ZigTypeIdPointer);4347 assert(union_ptr_type->id == ZigTypeIdPointer);
4348 ZigType *union_type = union_ptr_type->data.pointer.child_type;4348 ZigType *union_type = union_ptr_type->data.pointer.child_type;
4349 assert(union_type->id == ZigTypeIdUnion);4349 assert(union_type->id == ZigTypeIdUnion);
...@@ -4528,7 +4528,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4528,7 +4528,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
4528 buf_append_char(&constraint_buf, ',');4528 buf_append_char(&constraint_buf, ',');
4529 }4529 }
45304530
4531 ZigType *const type = ir_input->value.type;4531 ZigType *const type = ir_input->value->type;
4532 LLVMTypeRef type_ref = get_llvm_type(g, type);4532 LLVMTypeRef type_ref = get_llvm_type(g, type);
4533 LLVMValueRef value_ref = ir_llvm_value(g, ir_input);4533 LLVMValueRef value_ref = ir_llvm_value(g, ir_input);
4534 // Handle integers of non pot bitsize by widening them.4534 // Handle integers of non pot bitsize by widening them.
...@@ -4558,7 +4558,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4558,7 +4558,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
4558 if (instruction->return_count == 0) {4558 if (instruction->return_count == 0) {
4559 ret_type = LLVMVoidType();4559 ret_type = LLVMVoidType();
4560 } else {4560 } else {
4561 ret_type = get_llvm_type(g, instruction->base.value.type);4561 ret_type = get_llvm_type(g, instruction->base.value->type);
4562 }4562 }
4563 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);4563 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);
45644564
...@@ -4588,16 +4588,16 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR...@@ -4588,16 +4588,16 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
4588static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,4588static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,
4589 IrInstructionTestNonNull *instruction)4589 IrInstructionTestNonNull *instruction)
4590{4590{
4591 return gen_non_null_bit(g, instruction->value->value.type, ir_llvm_value(g, instruction->value));4591 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
4592}4592}
45934593
4594static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,4594static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,
4595 IrInstructionOptionalUnwrapPtr *instruction)4595 IrInstructionOptionalUnwrapPtr *instruction)
4596{4596{
4597 if (instruction->base.value.special != ConstValSpecialRuntime)4597 if (instruction->base.value->special != ConstValSpecialRuntime)
4598 return nullptr;4598 return nullptr;
45994599
4600 ZigType *ptr_type = instruction->base_ptr->value.type;4600 ZigType *ptr_type = instruction->base_ptr->value->type;
4601 assert(ptr_type->id == ZigTypeIdPointer);4601 assert(ptr_type->id == ZigTypeIdPointer);
4602 ZigType *maybe_type = ptr_type->data.pointer.child_type;4602 ZigType *maybe_type = ptr_type->data.pointer.child_type;
4603 assert(maybe_type->id == ZigTypeIdOptional);4603 assert(maybe_type->id == ZigTypeIdOptional);
...@@ -4695,7 +4695,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn...@@ -4695,7 +4695,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
4695}4695}
46964696
4697static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {4697static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
4698 ZigType *int_type = instruction->op->value.type;4698 ZigType *int_type = instruction->op->value->type;
4699 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);4699 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
4700 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4700 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
4701 LLVMValueRef params[] {4701 LLVMValueRef params[] {
...@@ -4703,11 +4703,11 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4703,11 +4703,11 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
4703 LLVMConstNull(LLVMInt1Type()),4703 LLVMConstNull(LLVMInt1Type()),
4704 };4704 };
4705 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, "");4705 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, "");
4706 return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int);4706 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4707}4707}
47084708
4709static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {4709static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
4710 ZigType *int_type = instruction->op->value.type;4710 ZigType *int_type = instruction->op->value->type;
4711 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);4711 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
4712 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4712 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
4713 LLVMValueRef params[] {4713 LLVMValueRef params[] {
...@@ -4715,12 +4715,12 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4715,12 +4715,12 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
4715 LLVMConstNull(LLVMInt1Type()),4715 LLVMConstNull(LLVMInt1Type()),
4716 };4716 };
4717 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, "");4717 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, "");
4718 return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int);4718 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4719}4719}
47204720
4721static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {4721static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {
4722 uint64_t len_a = instruction->a->value.type->data.vector.len;4722 uint64_t len_a = instruction->a->value->type->data.vector.len;
4723 uint64_t len_mask = instruction->mask->value.type->data.vector.len;4723 uint64_t len_mask = instruction->mask->value->type->data.vector.len;
47244724
4725 // LLVM uses integers larger than the length of the first array to4725 // LLVM uses integers larger than the length of the first array to
4726 // index into the second array. This was deemed unnecessarily fragile4726 // index into the second array. This was deemed unnecessarily fragile
...@@ -4730,10 +4730,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl...@@ -4730,10 +4730,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4730 IrInstruction *mask = instruction->mask;4730 IrInstruction *mask = instruction->mask;
4731 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);4731 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
4732 for (uint64_t i = 0; i < len_mask; i++) {4732 for (uint64_t i = 0; i < len_mask; i++) {
4733 if (mask->value.data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {4733 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
4734 values[i] = LLVMGetUndef(LLVMInt32Type());4734 values[i] = LLVMGetUndef(LLVMInt32Type());
4735 } else {4735 } else {
4736 int32_t v = bigint_as_signed(&mask->value.data.x_array.data.s_none.elements[i].data.x_bigint);4736 int32_t v = bigint_as_signed(&mask->value->data.x_array.data.s_none.elements[i].data.x_bigint);
4737 uint32_t index_val = (v >= 0) ? (uint32_t)v : (uint32_t)~v + (uint32_t)len_a;4737 uint32_t index_val = (v >= 0) ? (uint32_t)v : (uint32_t)~v + (uint32_t)len_a;
4738 values[i] = LLVMConstInt(LLVMInt32Type(), index_val, false);4738 values[i] = LLVMConstInt(LLVMInt32Type(), index_val, false);
4739 }4739 }
...@@ -4749,10 +4749,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl...@@ -4749,10 +4749,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4749}4749}
47504750
4751static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {4751static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {
4752 ZigType *result_type = instruction->base.value.type;4752 ZigType *result_type = instruction->base.value->type;
4753 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);4753 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
4754 uint32_t len = result_type->data.vector.len;4754 uint32_t len = result_type->data.vector.len;
4755 LLVMTypeRef op_llvm_type = LLVMVectorType(get_llvm_type(g, instruction->scalar->value.type), 1);4755 LLVMTypeRef op_llvm_type = LLVMVectorType(get_llvm_type(g, instruction->scalar->value->type), 1);
4756 LLVMTypeRef mask_llvm_type = LLVMVectorType(LLVMInt32Type(), len);4756 LLVMTypeRef mask_llvm_type = LLVMVectorType(LLVMInt32Type(), len);
4757 LLVMValueRef undef_vector = LLVMGetUndef(op_llvm_type);4757 LLVMValueRef undef_vector = LLVMGetUndef(op_llvm_type);
4758 LLVMValueRef op_vector = LLVMBuildInsertElement(g->builder, undef_vector,4758 LLVMValueRef op_vector = LLVMBuildInsertElement(g->builder, undef_vector,
...@@ -4761,11 +4761,11 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst...@@ -4761,11 +4761,11 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
4761}4761}
47624762
4763static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {4763static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {
4764 ZigType *int_type = instruction->op->value.type;4764 ZigType *int_type = instruction->op->value->type;
4765 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);4765 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
4766 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4766 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
4767 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, "");4767 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
4768 return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int);4768 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4769}4769}
47704770
4771static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {4771static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {
...@@ -4781,14 +4781,14 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir...@@ -4781,14 +4781,14 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
4781}4781}
47824782
4783static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {4783static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {
4784 if (!type_has_bits(instruction->base.value.type))4784 if (!type_has_bits(instruction->base.value->type))
4785 return nullptr;4785 return nullptr;
47864786
4787 LLVMTypeRef phi_type;4787 LLVMTypeRef phi_type;
4788 if (handle_is_ptr(instruction->base.value.type)) {4788 if (handle_is_ptr(instruction->base.value->type)) {
4789 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value.type), 0);4789 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0);
4790 } else {4790 } else {
4791 phi_type = get_llvm_type(g, instruction->base.value.type);4791 phi_type = get_llvm_type(g, instruction->base.value->type);
4792 }4792 }
47934793
4794 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");4794 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
...@@ -4803,11 +4803,11 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4803,11 +4803,11 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
4803}4803}
48044804
4805static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {4805static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {
4806 if (!type_has_bits(instruction->base.value.type)) {4806 if (!type_has_bits(instruction->base.value->type)) {
4807 return nullptr;4807 return nullptr;
4808 }4808 }
4809 LLVMValueRef value = ir_llvm_value(g, instruction->operand);4809 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
4810 if (handle_is_ptr(instruction->operand->value.type)) {4810 if (handle_is_ptr(instruction->operand->value->type)) {
4811 return value;4811 return value;
4812 } else {4812 } else {
4813 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);4813 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
...@@ -4940,7 +4940,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -4940,7 +4940,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
4940static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,4940static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
4941 IrInstructionTagName *instruction)4941 IrInstructionTagName *instruction)
4942{4942{
4943 ZigType *enum_type = instruction->target->value.type;4943 ZigType *enum_type = instruction->target->value->type;
4944 assert(enum_type->id == ZigTypeIdEnum);4944 assert(enum_type->id == ZigTypeIdEnum);
49454945
4946 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);4946 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);
...@@ -4953,7 +4953,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable...@@ -4953,7 +4953,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
4953static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,4953static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
4954 IrInstructionFieldParentPtr *instruction)4954 IrInstructionFieldParentPtr *instruction)
4955{4955{
4956 ZigType *container_ptr_type = instruction->base.value.type;4956 ZigType *container_ptr_type = instruction->base.value->type;
4957 assert(container_ptr_type->id == ZigTypeIdPointer);4957 assert(container_ptr_type->id == ZigTypeIdPointer);
49584958
4959 ZigType *container_type = container_ptr_type->data.pointer.child_type;4959 ZigType *container_type = container_ptr_type->data.pointer.child_type;
...@@ -4986,7 +4986,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -4986,7 +4986,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
4986 return target_val;4986 return target_val;
4987 }4987 }
49884988
4989 ZigType *target_type = instruction->base.value.type;4989 ZigType *target_type = instruction->base.value->type;
4990 uint32_t align_bytes;4990 uint32_t align_bytes;
4991 LLVMValueRef ptr_val;4991 LLVMValueRef ptr_val;
49924992
...@@ -5089,7 +5089,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -5089,7 +5089,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
5089 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,5089 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
5090 success_order, failure_order, instruction->is_weak);5090 success_order, failure_order, instruction->is_weak);
50915091
5092 ZigType *optional_type = instruction->base.value.type;5092 ZigType *optional_type = instruction->base.value->type;
5093 assert(optional_type->id == ZigTypeIdOptional);5093 assert(optional_type->id == ZigTypeIdOptional);
5094 ZigType *child_type = optional_type->data.maybe.child_type;5094 ZigType *child_type = optional_type->data.maybe.child_type;
50955095
...@@ -5100,7 +5100,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -5100,7 +5100,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
5100 }5100 }
51015101
5102 // When the cmpxchg is discarded, the result location will have no bits.5102 // When the cmpxchg is discarded, the result location will have no bits.
5103 if (!type_has_bits(instruction->result_loc->value.type)) {5103 if (!type_has_bits(instruction->result_loc->value->type)) {
5104 return nullptr;5104 return nullptr;
5105 }5105 }
51065106
...@@ -5127,8 +5127,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst...@@ -5127,8 +5127,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst
51275127
5128static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {5128static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
5129 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);5129 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5130 ZigType *dest_type = instruction->base.value.type;5130 ZigType *dest_type = instruction->base.value->type;
5131 ZigType *src_type = instruction->target->value.type;5131 ZigType *src_type = instruction->target->value->type;
5132 if (dest_type == src_type) {5132 if (dest_type == src_type) {
5133 // no-op5133 // no-op
5134 return target_val;5134 return target_val;
...@@ -5147,10 +5147,10 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -5147,10 +5147,10 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
5147 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);5147 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);
5148 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");5148 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
51495149
5150 ZigType *ptr_type = instruction->dest_ptr->value.type;5150 ZigType *ptr_type = instruction->dest_ptr->value->type;
5151 assert(ptr_type->id == ZigTypeIdPointer);5151 assert(ptr_type->id == ZigTypeIdPointer);
51525152
5153 bool val_is_undef = value_is_all_undef(g, &instruction->byte->value);5153 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
5154 LLVMValueRef fill_char;5154 LLVMValueRef fill_char;
5155 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {5155 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {
5156 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);5156 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
...@@ -5176,8 +5176,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -5176,8 +5176,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
5176 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");5176 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
5177 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");5177 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
51785178
5179 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;5179 ZigType *dest_ptr_type = instruction->dest_ptr->value->type;
5180 ZigType *src_ptr_type = instruction->src_ptr->value.type;5180 ZigType *src_ptr_type = instruction->src_ptr->value->type;
51815181
5182 assert(dest_ptr_type->id == ZigTypeIdPointer);5182 assert(dest_ptr_type->id == ZigTypeIdPointer);
5183 assert(src_ptr_type->id == ZigTypeIdPointer);5183 assert(src_ptr_type->id == ZigTypeIdPointer);
...@@ -5190,7 +5190,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -5190,7 +5190,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
51905190
5191static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {5191static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {
5192 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);5192 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
5193 ZigType *array_ptr_type = instruction->ptr->value.type;5193 ZigType *array_ptr_type = instruction->ptr->value->type;
5194 assert(array_ptr_type->id == ZigTypeIdPointer);5194 assert(array_ptr_type->id == ZigTypeIdPointer);
5195 ZigType *array_type = array_ptr_type->data.pointer.child_type;5195 ZigType *array_type = array_ptr_type->data.pointer.child_type;
5196 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);5196 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
...@@ -5213,7 +5213,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -5213,7 +5213,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
5213 end_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, array_type->data.array.len, false);5213 end_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, array_type->data.array.len, false);
5214 }5214 }
5215 if (want_runtime_safety) {5215 if (want_runtime_safety) {
5216 if (instruction->start->value.special == ConstValSpecialRuntime || instruction->end) {5216 if (instruction->start->value->special == ConstValSpecialRuntime || instruction->end) {
5217 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);5217 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
5218 }5218 }
5219 if (instruction->end) {5219 if (instruction->end) {
...@@ -5255,13 +5255,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -5255,13 +5255,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
5255 }5255 }
52565256
5257 if (type_has_bits(array_type)) {5257 if (type_has_bits(array_type)) {
5258 size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index]->gen_index;5258 size_t gen_ptr_index = instruction->base.value->type->data.structure.fields[slice_ptr_index]->gen_index;
5259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");5259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
5260 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");5260 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");
5261 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);5261 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
5262 }5262 }
52635263
5264 size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index]->gen_index;5264 size_t gen_len_index = instruction->base.value->type->data.structure.fields[slice_len_index]->gen_index;
5265 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");5265 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
5266 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");5266 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
5267 gen_store_untyped(g, len_value, len_field_ptr, 0, false);5267 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
...@@ -5375,8 +5375,8 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp...@@ -5375,8 +5375,8 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
5375 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);5375 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
5376 LLVMValueRef ptr_result = ir_llvm_value(g, instruction->result_ptr);5376 LLVMValueRef ptr_result = ir_llvm_value(g, instruction->result_ptr);
53775377
5378 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, instruction->op2->value.type,5378 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, instruction->op2->value->type,
5379 instruction->op1->value.type, op2);5379 instruction->op1->value->type, op2);
53805380
5381 LLVMValueRef result = LLVMBuildShl(g->builder, op1, op2_casted, "");5381 LLVMValueRef result = LLVMBuildShl(g->builder, op1, op2_casted, "");
5382 LLVMValueRef orig_val;5382 LLVMValueRef orig_val;
...@@ -5387,7 +5387,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp...@@ -5387,7 +5387,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
5387 }5387 }
5388 LLVMValueRef overflow_bit = LLVMBuildICmp(g->builder, LLVMIntNE, op1, orig_val, "");5388 LLVMValueRef overflow_bit = LLVMBuildICmp(g->builder, LLVMIntNE, op1, orig_val, "");
53895389
5390 gen_store(g, result, ptr_result, instruction->result_ptr->value.type);5390 gen_store(g, result, ptr_result, instruction->result_ptr->value->type);
53915391
5392 return overflow_bit;5392 return overflow_bit;
5393}5393}
...@@ -5425,13 +5425,13 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -5425,13 +5425,13 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
5425 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");5425 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");
5426 LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");5426 LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");
5427 LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, "");5427 LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, "");
5428 gen_store(g, result, ptr_result, instruction->result_ptr->value.type);5428 gen_store(g, result, ptr_result, instruction->result_ptr->value->type);
54295429
5430 return overflow_bit;5430 return overflow_bit;
5431}5431}
54325432
5433static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {5433static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {
5434 ZigType *err_union_type = instruction->err_union->value.type;5434 ZigType *err_union_type = instruction->err_union->value->type;
5435 ZigType *payload_type = err_union_type->data.error_union.payload_type;5435 ZigType *payload_type = err_union_type->data.error_union.payload_type;
5436 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);5436 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
54375437
...@@ -5450,10 +5450,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI...@@ -5450,10 +5450,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
5450static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,5450static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
5451 IrInstructionUnwrapErrCode *instruction)5451 IrInstructionUnwrapErrCode *instruction)
5452{5452{
5453 if (instruction->base.value.special != ConstValSpecialRuntime)5453 if (instruction->base.value->special != ConstValSpecialRuntime)
5454 return nullptr;5454 return nullptr;
54555455
5456 ZigType *ptr_type = instruction->err_union_ptr->value.type;5456 ZigType *ptr_type = instruction->err_union_ptr->value->type;
5457 assert(ptr_type->id == ZigTypeIdPointer);5457 assert(ptr_type->id == ZigTypeIdPointer);
5458 ZigType *err_union_type = ptr_type->data.pointer.child_type;5458 ZigType *err_union_type = ptr_type->data.pointer.child_type;
5459 ZigType *payload_type = err_union_type->data.error_union.payload_type;5459 ZigType *payload_type = err_union_type->data.error_union.payload_type;
...@@ -5470,14 +5470,14 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab...@@ -5470,14 +5470,14 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
5470static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,5470static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
5471 IrInstructionUnwrapErrPayload *instruction)5471 IrInstructionUnwrapErrPayload *instruction)
5472{5472{
5473 if (instruction->base.value.special != ConstValSpecialRuntime)5473 if (instruction->base.value->special != ConstValSpecialRuntime)
5474 return nullptr;5474 return nullptr;
54755475
5476 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&5476 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&
5477 g->errors_by_index.length > 1;5477 g->errors_by_index.length > 1;
5478 if (!want_safety && !type_has_bits(instruction->base.value.type))5478 if (!want_safety && !type_has_bits(instruction->base.value->type))
5479 return nullptr;5479 return nullptr;
5480 ZigType *ptr_type = instruction->value->value.type;5480 ZigType *ptr_type = instruction->value->value->type;
5481 assert(ptr_type->id == ZigTypeIdPointer);5481 assert(ptr_type->id == ZigTypeIdPointer);
5482 ZigType *err_union_type = ptr_type->data.pointer.child_type;5482 ZigType *err_union_type = ptr_type->data.pointer.child_type;
5483 ZigType *payload_type = err_union_type->data.error_union.payload_type;5483 ZigType *payload_type = err_union_type->data.error_union.payload_type;
...@@ -5521,7 +5521,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -5521,7 +5521,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
5521}5521}
55225522
5523static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {5523static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
5524 ZigType *wanted_type = instruction->base.value.type;5524 ZigType *wanted_type = instruction->base.value->type;
55255525
5526 assert(wanted_type->id == ZigTypeIdOptional);5526 assert(wanted_type->id == ZigTypeIdOptional);
55275527
...@@ -5548,7 +5548,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable...@@ -5548,7 +5548,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
5548 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5548 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
55495549
5550 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, "");5550 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, "");
5551 // child_type and instruction->value->value.type may differ by constness5551 // child_type and instruction->value->value->type may differ by constness
5552 gen_assign_raw(g, val_ptr, get_pointer_to_type(g, child_type, false), payload_val);5552 gen_assign_raw(g, val_ptr, get_pointer_to_type(g, child_type, false), payload_val);
5553 LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_null_index, "");5553 LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_null_index, "");
5554 gen_store_untyped(g, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr, 0, false);5554 gen_store_untyped(g, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr, 0, false);
...@@ -5557,7 +5557,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable...@@ -5557,7 +5557,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
5557}5557}
55585558
5559static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {5559static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
5560 ZigType *wanted_type = instruction->base.value.type;5560 ZigType *wanted_type = instruction->base.value->type;
55615561
5562 assert(wanted_type->id == ZigTypeIdErrorUnion);5562 assert(wanted_type->id == ZigTypeIdErrorUnion);
55635563
...@@ -5577,7 +5577,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable...@@ -5577,7 +5577,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
5577}5577}
55785578
5579static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {5579static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
5580 ZigType *wanted_type = instruction->base.value.type;5580 ZigType *wanted_type = instruction->base.value->type;
55815581
5582 assert(wanted_type->id == ZigTypeIdErrorUnion);5582 assert(wanted_type->id == ZigTypeIdErrorUnion);
55835583
...@@ -5608,7 +5608,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa...@@ -5608,7 +5608,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
5608}5608}
56095609
5610static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {5610static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
5611 ZigType *union_type = instruction->value->value.type;5611 ZigType *union_type = instruction->value->value->type;
56125612
5613 ZigType *tag_type = union_type->data.unionation.tag_type;5613 ZigType *tag_type = union_type->data.unionation.tag_type;
5614 if (!type_has_bits(tag_type))5614 if (!type_has_bits(tag_type))
...@@ -5636,7 +5636,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -5636,7 +5636,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5636 IrInstructionAtomicRmw *instruction)5636 IrInstructionAtomicRmw *instruction)
5637{5637{
5638 bool is_signed;5638 bool is_signed;
5639 ZigType *operand_type = instruction->operand->value.type;5639 ZigType *operand_type = instruction->operand->value->type;
5640 if (operand_type->id == ZigTypeIdInt) {5640 if (operand_type->id == ZigTypeIdInt) {
5641 is_signed = operand_type->data.integral.is_signed;5641 is_signed = operand_type->data.integral.is_signed;
5642 } else {5642 } else {
...@@ -5665,7 +5665,7 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,...@@ -5665,7 +5665,7 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
5665{5665{
5666 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5666 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5667 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5667 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5668 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value.type, "");5668 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");
5669 LLVMSetOrdering(load_inst, ordering);5669 LLVMSetOrdering(load_inst, ordering);
5670 return load_inst;5670 return load_inst;
5671}5671}
...@@ -5676,15 +5676,15 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,...@@ -5676,15 +5676,15 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5676 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5676 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5677 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5677 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5678 LLVMValueRef value = ir_llvm_value(g, instruction->value);5678 LLVMValueRef value = ir_llvm_value(g, instruction->value);
5679 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value.type);5679 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);
5680 LLVMSetOrdering(store_inst, ordering);5680 LLVMSetOrdering(store_inst, ordering);
5681 return nullptr;5681 return nullptr;
5682}5682}
56835683
5684static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {5684static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {
5685 LLVMValueRef op = ir_llvm_value(g, instruction->op1);5685 LLVMValueRef op = ir_llvm_value(g, instruction->op1);
5686 assert(instruction->base.value.type->id == ZigTypeIdFloat);5686 assert(instruction->base.value->type->id == ZigTypeIdFloat);
5687 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFloatOp, instruction->op);5687 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->op);
5688 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");5688 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
5689}5689}
56905690
...@@ -5692,9 +5692,9 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn...@@ -5692,9 +5692,9 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
5692 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);5692 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
5693 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);5693 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
5694 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);5694 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
5695 assert(instruction->base.value.type->id == ZigTypeIdFloat ||5695 assert(instruction->base.value->type->id == ZigTypeIdFloat ||
5696 instruction->base.value.type->id == ZigTypeIdVector);5696 instruction->base.value->type->id == ZigTypeIdVector);
5697 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd);5697 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd);
5698 LLVMValueRef args[3] = {5698 LLVMValueRef args[3] = {
5699 op1,5699 op1,
5700 op2,5700 op2,
...@@ -5705,7 +5705,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn...@@ -5705,7 +5705,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
57055705
5706static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {5706static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {
5707 LLVMValueRef op = ir_llvm_value(g, instruction->op);5707 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5708 ZigType *expr_type = instruction->base.value.type;5708 ZigType *expr_type = instruction->base.value->type;
5709 bool is_vector = expr_type->id == ZigTypeIdVector;5709 bool is_vector = expr_type->id == ZigTypeIdVector;
5710 ZigType *int_type = is_vector ? expr_type->data.vector.elem_type : expr_type;5710 ZigType *int_type = is_vector ? expr_type->data.vector.elem_type : expr_type;
5711 assert(int_type->id == ZigTypeIdInt);5711 assert(int_type->id == ZigTypeIdInt);
...@@ -5739,16 +5739,16 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst...@@ -5739,16 +5739,16 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
57395739
5740static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {5740static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {
5741 LLVMValueRef op = ir_llvm_value(g, instruction->op);5741 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5742 ZigType *int_type = instruction->base.value.type;5742 ZigType *int_type = instruction->base.value->type;
5743 assert(int_type->id == ZigTypeIdInt);5743 assert(int_type->id == ZigTypeIdInt);
5744 LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value.type, BuiltinFnIdBitReverse);5744 LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value->type, BuiltinFnIdBitReverse);
5745 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");5745 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
5746}5746}
57475747
5748static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,5748static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,
5749 IrInstructionVectorToArray *instruction)5749 IrInstructionVectorToArray *instruction)
5750{5750{
5751 ZigType *array_type = instruction->base.value.type;5751 ZigType *array_type = instruction->base.value->type;
5752 assert(array_type->id == ZigTypeIdArray);5752 assert(array_type->id == ZigTypeIdArray);
5753 assert(handle_is_ptr(array_type));5753 assert(handle_is_ptr(array_type));
5754 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5754 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
...@@ -5758,8 +5758,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab...@@ -5758,8 +5758,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
5758 bool bitcast_ok = elem_type->size_in_bits == elem_type->abi_size * 8;5758 bool bitcast_ok = elem_type->size_in_bits == elem_type->abi_size * 8;
5759 if (bitcast_ok) {5759 if (bitcast_ok) {
5760 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, result_loc,5760 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, result_loc,
5761 LLVMPointerType(get_llvm_type(g, instruction->vector->value.type), 0), "");5761 LLVMPointerType(get_llvm_type(g, instruction->vector->value->type), 0), "");
5762 uint32_t alignment = get_ptr_align(g, instruction->result_loc->value.type);5762 uint32_t alignment = get_ptr_align(g, instruction->result_loc->value->type);
5763 gen_store_untyped(g, vector, casted_ptr, alignment, false);5763 gen_store_untyped(g, vector, casted_ptr, alignment, false);
5764 } else {5764 } else {
5765 // If the ABI size of the element type is not evenly divisible by size_in_bits, a simple bitcast5765 // If the ABI size of the element type is not evenly divisible by size_in_bits, a simple bitcast
...@@ -5767,7 +5767,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab...@@ -5767,7 +5767,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
5767 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;5767 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
5768 LLVMTypeRef u32_type_ref = LLVMInt32Type();5768 LLVMTypeRef u32_type_ref = LLVMInt32Type();
5769 LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false);5769 LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false);
5770 for (uintptr_t i = 0; i < instruction->vector->value.type->data.vector.len; i++) {5770 for (uintptr_t i = 0; i < instruction->vector->value->type->data.vector.len; i++) {
5771 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);5771 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);
5772 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);5772 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);
5773 LLVMValueRef indexes[] = { zero, index_usize };5773 LLVMValueRef indexes[] = { zero, index_usize };
...@@ -5782,7 +5782,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab...@@ -5782,7 +5782,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
5782static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,5782static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,
5783 IrInstructionArrayToVector *instruction)5783 IrInstructionArrayToVector *instruction)
5784{5784{
5785 ZigType *vector_type = instruction->base.value.type;5785 ZigType *vector_type = instruction->base.value->type;
5786 assert(vector_type->id == ZigTypeIdVector);5786 assert(vector_type->id == ZigTypeIdVector);
5787 assert(!handle_is_ptr(vector_type));5787 assert(!handle_is_ptr(vector_type));
5788 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);5788 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);
...@@ -5793,7 +5793,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab...@@ -5793,7 +5793,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
5793 if (bitcast_ok) {5793 if (bitcast_ok) {
5794 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, array_ptr,5794 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, array_ptr,
5795 LLVMPointerType(vector_type_ref, 0), "");5795 LLVMPointerType(vector_type_ref, 0), "");
5796 ZigType *array_type = instruction->array->value.type;5796 ZigType *array_type = instruction->array->value->type;
5797 assert(array_type->id == ZigTypeIdArray);5797 assert(array_type->id == ZigTypeIdArray);
5798 uint32_t alignment = get_abi_alignment(g, array_type->data.array.child_type);5798 uint32_t alignment = get_abi_alignment(g, array_type->data.array.child_type);
5799 return gen_load_untyped(g, casted_ptr, alignment, false, "");5799 return gen_load_untyped(g, casted_ptr, alignment, false, "");
...@@ -5804,7 +5804,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab...@@ -5804,7 +5804,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
5804 LLVMTypeRef u32_type_ref = LLVMInt32Type();5804 LLVMTypeRef u32_type_ref = LLVMInt32Type();
5805 LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false);5805 LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false);
5806 LLVMValueRef vector = LLVMGetUndef(vector_type_ref);5806 LLVMValueRef vector = LLVMGetUndef(vector_type_ref);
5807 for (uintptr_t i = 0; i < instruction->base.value.type->data.vector.len; i++) {5807 for (uintptr_t i = 0; i < instruction->base.value->type->data.vector.len; i++) {
5808 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);5808 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);
5809 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);5809 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);
5810 LLVMValueRef indexes[] = { zero, index_usize };5810 LLVMValueRef indexes[] = { zero, index_usize };
...@@ -5820,7 +5820,7 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,...@@ -5820,7 +5820,7 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5820 IrInstructionAssertZero *instruction)5820 IrInstructionAssertZero *instruction)
5821{5821{
5822 LLVMValueRef target = ir_llvm_value(g, instruction->target);5822 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5823 ZigType *int_type = instruction->target->value.type;5823 ZigType *int_type = instruction->target->value->type;
5824 if (ir_want_runtime_safety(g, &instruction->base)) {5824 if (ir_want_runtime_safety(g, &instruction->base)) {
5825 return gen_assert_zero(g, target, int_type);5825 return gen_assert_zero(g, target, int_type);
5826 }5826 }
...@@ -5831,7 +5831,7 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab...@@ -5831,7 +5831,7 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
5831 IrInstructionAssertNonNull *instruction)5831 IrInstructionAssertNonNull *instruction)
5832{5832{
5833 LLVMValueRef target = ir_llvm_value(g, instruction->target);5833 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5834 ZigType *target_type = instruction->target->value.type;5834 ZigType *target_type = instruction->target->value->type;
58355835
5836 if (target_type->id == ZigTypeIdPointer) {5836 if (target_type->id == ZigTypeIdPointer) {
5837 assert(target_type->data.pointer.ptr_len == PtrLenC);5837 assert(target_type->data.pointer.ptr_len == PtrLenC);
...@@ -5917,7 +5917,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -5917,7 +5917,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
5917 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;5917 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
5918 LLVMValueRef zero = LLVMConstNull(usize_type_ref);5918 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
5919 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);5919 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
5920 ZigType *result_type = instruction->base.value.type;5920 ZigType *result_type = instruction->base.value->type;
5921 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);5921 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);
59225922
5923 LLVMValueRef result_loc = (instruction->result_loc == nullptr) ?5923 LLVMValueRef result_loc = (instruction->result_loc == nullptr) ?
...@@ -6000,7 +6000,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -6000,7 +6000,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
60006000
6001static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {6001static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {
6002 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);6002 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
6003 ZigType *frame_type = instruction->frame->value.type;6003 ZigType *frame_type = instruction->frame->value->type;
6004 assert(frame_type->id == ZigTypeIdAnyFrame);6004 assert(frame_type->id == ZigTypeIdAnyFrame);
60056005
6006 gen_resume(g, nullptr, frame, ResumeIdManual);6006 gen_resume(g, nullptr, frame, ResumeIdManual);
...@@ -6354,7 +6354,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {...@@ -6354,7 +6354,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
6354 instruction->llvm_value = ir_render_instruction(g, executable, instruction);6354 instruction->llvm_value = ir_render_instruction(g, executable, instruction);
6355 if (instruction->spill != nullptr) {6355 if (instruction->spill != nullptr) {
6356 LLVMValueRef spill_ptr = ir_llvm_value(g, instruction->spill);6356 LLVMValueRef spill_ptr = ir_llvm_value(g, instruction->spill);
6357 gen_assign_raw(g, spill_ptr, instruction->spill->value.type, instruction->llvm_value);6357 gen_assign_raw(g, spill_ptr, instruction->spill->value->type, instruction->llvm_value);
6358 instruction->llvm_value = nullptr;6358 instruction->llvm_value = nullptr;
6359 }6359 }
6360 }6360 }
...@@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {...@@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
6362 }6362 }
6363}6363}
63646364
6365static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index);6365static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index);
6366static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index);6366static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index);
6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val);6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val);
6368static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val);6368static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val);
6369static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val);6369static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val);
6370static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val);6370static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val);
63716371
6372static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent *parent) {6372static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *parent) {
6373 switch (parent->id) {6373 switch (parent->id) {
6374 case ConstParentIdNone:6374 case ConstParentIdNone:
6375 render_const_val(g, val, "");6375 render_const_val(g, val, "");
...@@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent...@@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent
6397 zig_unreachable();6397 zig_unreachable();
6398}6398}
63996399
6400static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index) {6400static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index) {
6401 expand_undef_array(g, array_const_val);6401 expand_undef_array(g, array_const_val);
6402 ConstParent *parent = &array_const_val->parent;6402 ConstParent *parent = &array_const_val->parent;
6403 LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent);6403 LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent);
...@@ -6423,7 +6423,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar...@@ -6423,7 +6423,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
6423 }6423 }
6424}6424}
64256425
6426static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index) {6426static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index) {
6427 ConstParent *parent = &struct_const_val->parent;6427 ConstParent *parent = &struct_const_val->parent;
6428 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);6428 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);
64296429
...@@ -6435,7 +6435,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s...@@ -6435,7 +6435,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s
6435 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6435 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6436}6436}
64376437
6438static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val) {6438static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val) {
6439 ConstParent *parent = &err_union_const_val->parent;6439 ConstParent *parent = &err_union_const_val->parent;
6440 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);6440 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);
64416441
...@@ -6447,7 +6447,7 @@ static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExpr...@@ -6447,7 +6447,7 @@ static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExpr
6447 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6447 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6448}6448}
64496449
6450static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val) {6450static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val) {
6451 ConstParent *parent = &err_union_const_val->parent;6451 ConstParent *parent = &err_union_const_val->parent;
6452 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);6452 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);
64536453
...@@ -6459,7 +6459,7 @@ static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstE...@@ -6459,7 +6459,7 @@ static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstE
6459 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6459 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6460}6460}
64616461
6462static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val) {6462static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val) {
6463 ConstParent *parent = &optional_const_val->parent;6463 ConstParent *parent = &optional_const_val->parent;
6464 LLVMValueRef base_ptr = gen_parent_ptr(g, optional_const_val, parent);6464 LLVMValueRef base_ptr = gen_parent_ptr(g, optional_const_val, parent);
64656465
...@@ -6471,7 +6471,7 @@ static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstEx...@@ -6471,7 +6471,7 @@ static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstEx
6471 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6471 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6472}6472}
64736473
6474static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val) {6474static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val) {
6475 ConstParent *parent = &union_const_val->parent;6475 ConstParent *parent = &union_const_val->parent;
6476 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);6476 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);
64776477
...@@ -6488,7 +6488,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un...@@ -6488,7 +6488,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
6488 return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1);6488 return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1);
6489}6489}
64906490
6491static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ConstExprValue *const_val) {6491static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ZigValue *const_val) {
6492 switch (const_val->special) {6492 switch (const_val->special) {
6493 case ConstValSpecialLazy:6493 case ConstValSpecialLazy:
6494 case ConstValSpecialRuntime:6494 case ConstValSpecialRuntime:
...@@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
6555 uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type);6555 uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type);
6556 size_t used_bits = 0;6556 size_t used_bits = 0;
6557 for (size_t i = 0; i < type_entry->data.array.len; i += 1) {6557 for (size_t i = 0; i < type_entry->data.array.len; i += 1) {
6558 ConstExprValue *elem_val = &const_val->data.x_array.data.s_none.elements[i];6558 ZigValue *elem_val = &const_val->data.x_array.data.s_none.elements[i];
6559 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val);6559 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val);
65606560
6561 if (is_big_endian) {6561 if (is_big_endian) {
...@@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu...@@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu
6616 return LLVMTypeOf(val) != get_llvm_type(g, type_entry);6616 return LLVMTypeOf(val) != get_llvm_type(g, type_entry);
6617}6617}
66186618
6619static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, const char *name) {6619static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const char *name) {
6620 switch (const_val->data.x_ptr.special) {6620 switch (const_val->data.x_ptr.special) {
6621 case ConstPtrSpecialInvalid:6621 case ConstPtrSpecialInvalid:
6622 case ConstPtrSpecialDiscard:6622 case ConstPtrSpecialDiscard:
...@@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6624 case ConstPtrSpecialRef:6624 case ConstPtrSpecialRef:
6625 {6625 {
6626 assert(const_val->global_refs != nullptr);6626 assert(const_val->global_refs != nullptr);
6627 ConstExprValue *pointee = const_val->data.x_ptr.data.ref.pointee;6627 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;
6628 render_const_val(g, pointee, "");6628 render_const_val(g, pointee, "");
6629 render_const_val_global(g, pointee, "");6629 render_const_val_global(g, pointee, "");
6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
...@@ -6634,11 +6634,11 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6634,11 +6634,11 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6634 case ConstPtrSpecialBaseArray:6634 case ConstPtrSpecialBaseArray:
6635 {6635 {
6636 assert(const_val->global_refs != nullptr);6636 assert(const_val->global_refs != nullptr);
6637 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;6637 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
6638 assert(array_const_val->type->id == ZigTypeIdArray);6638 assert(array_const_val->type->id == ZigTypeIdArray);
6639 if (!type_has_bits(array_const_val->type)) {6639 if (!type_has_bits(array_const_val->type)) {
6640 if (array_const_val->type->data.array.sentinel != nullptr) {6640 if (array_const_val->type->data.array.sentinel != nullptr) {
6641 ConstExprValue *pointee = array_const_val->type->data.array.sentinel;6641 ZigValue *pointee = array_const_val->type->data.array.sentinel;
6642 render_const_val(g, pointee, "");6642 render_const_val(g, pointee, "");
6643 render_const_val_global(g, pointee, "");6643 render_const_val_global(g, pointee, "");
6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
...@@ -6661,7 +6661,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6661,7 +6661,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6661 case ConstPtrSpecialBaseStruct:6661 case ConstPtrSpecialBaseStruct:
6662 {6662 {
6663 assert(const_val->global_refs != nullptr);6663 assert(const_val->global_refs != nullptr);
6664 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;6664 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
6665 assert(struct_const_val->type->id == ZigTypeIdStruct);6665 assert(struct_const_val->type->id == ZigTypeIdStruct);
6666 if (!type_has_bits(struct_const_val->type)) {6666 if (!type_has_bits(struct_const_val->type)) {
6667 // make this a null pointer6667 // make this a null pointer
...@@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6681 case ConstPtrSpecialBaseErrorUnionCode:6681 case ConstPtrSpecialBaseErrorUnionCode:
6682 {6682 {
6683 assert(const_val->global_refs != nullptr);6683 assert(const_val->global_refs != nullptr);
6684 ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;6684 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
6685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6686 if (!type_has_bits(err_union_const_val->type)) {6686 if (!type_has_bits(err_union_const_val->type)) {
6687 // make this a null pointer6687 // make this a null pointer
...@@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6698 case ConstPtrSpecialBaseErrorUnionPayload:6698 case ConstPtrSpecialBaseErrorUnionPayload:
6699 {6699 {
6700 assert(const_val->global_refs != nullptr);6700 assert(const_val->global_refs != nullptr);
6701 ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;6701 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
6702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6703 if (!type_has_bits(err_union_const_val->type)) {6703 if (!type_has_bits(err_union_const_val->type)) {
6704 // make this a null pointer6704 // make this a null pointer
...@@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6715 case ConstPtrSpecialBaseOptionalPayload:6715 case ConstPtrSpecialBaseOptionalPayload:
6716 {6716 {
6717 assert(const_val->global_refs != nullptr);6717 assert(const_val->global_refs != nullptr);
6718 ConstExprValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;6718 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
6719 assert(optional_const_val->type->id == ZigTypeIdOptional);6719 assert(optional_const_val->type->id == ZigTypeIdOptional);
6720 if (!type_has_bits(optional_const_val->type)) {6720 if (!type_has_bits(optional_const_val->type)) {
6721 // make this a null pointer6721 // make this a null pointer
...@@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6747 zig_unreachable();6747 zig_unreachable();
6748}6748}
67496749
6750static LLVMValueRef gen_const_val_err_set(CodeGen *g, ConstExprValue *const_val, const char *name) {6750static LLVMValueRef gen_const_val_err_set(CodeGen *g, ZigValue *const_val, const char *name) {
6751 uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value;6751 uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value;
6752 return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false);6752 return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false);
6753}6753}
67546754
6755static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {6755static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
6756 Error err;6756 Error err;
67576757
6758 ZigType *type_entry = const_val->type;6758 ZigType *type_entry = const_val->type;
...@@ -6864,7 +6864,7 @@ check: switch (const_val->special) {...@@ -6864,7 +6864,7 @@ check: switch (const_val->special) {
6864 }6864 }
68656865
6866 if (src_field_index + 1 == src_field_index_end) {6866 if (src_field_index + 1 == src_field_index_end) {
6867 ConstExprValue *field_val = const_val->data.x_struct.fields[src_field_index];6867 ZigValue *field_val = const_val->data.x_struct.fields[src_field_index];
6868 LLVMValueRef val = gen_const_val(g, field_val, "");6868 LLVMValueRef val = gen_const_val(g, field_val, "");
6869 fields[type_struct_field->gen_index] = val;6869 fields[type_struct_field->gen_index] = val;
6870 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);6870 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);
...@@ -6921,7 +6921,7 @@ check: switch (const_val->special) {...@@ -6921,7 +6921,7 @@ check: switch (const_val->special) {
6921 if (type_struct_field->gen_index == SIZE_MAX) {6921 if (type_struct_field->gen_index == SIZE_MAX) {
6922 continue;6922 continue;
6923 }6923 }
6924 ConstExprValue *field_val = const_val->data.x_struct.fields[i];6924 ZigValue *field_val = const_val->data.x_struct.fields[i];
6925 assert(field_val->type != nullptr);6925 assert(field_val->type != nullptr);
6926 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,6926 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
6927 type_struct_field->type_entry)))6927 type_struct_field->type_entry)))
...@@ -6970,7 +6970,7 @@ check: switch (const_val->special) {...@@ -6970,7 +6970,7 @@ check: switch (const_val->special) {
6970 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);6970 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
6971 bool make_unnamed_struct = false;6971 bool make_unnamed_struct = false;
6972 for (uint64_t i = 0; i < len; i += 1) {6972 for (uint64_t i = 0; i < len; i += 1) {
6973 ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];6973 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
6974 LLVMValueRef val = gen_const_val(g, elem_value, "");6974 LLVMValueRef val = gen_const_val(g, elem_value, "");
6975 values[i] = val;6975 values[i] = val;
6976 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);6976 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);
...@@ -7000,7 +7000,7 @@ check: switch (const_val->special) {...@@ -7000,7 +7000,7 @@ check: switch (const_val->special) {
7000 case ConstArraySpecialNone: {7000 case ConstArraySpecialNone: {
7001 LLVMValueRef *values = allocate<LLVMValueRef>(len);7001 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7002 for (uint64_t i = 0; i < len; i += 1) {7002 for (uint64_t i = 0; i < len; i += 1) {
7003 ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];7003 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
7004 values[i] = gen_const_val(g, elem_value, "");7004 values[i] = gen_const_val(g, elem_value, "");
7005 }7005 }
7006 return LLVMConstVector(values, len);7006 return LLVMConstVector(values, len);
...@@ -7036,7 +7036,7 @@ check: switch (const_val->special) {...@@ -7036,7 +7036,7 @@ check: switch (const_val->special) {
70367036
7037 LLVMValueRef union_value_ref;7037 LLVMValueRef union_value_ref;
7038 bool make_unnamed_struct;7038 bool make_unnamed_struct;
7039 ConstExprValue *payload_value = const_val->data.x_union.payload;7039 ZigValue *payload_value = const_val->data.x_union.payload;
7040 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {7040 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {
7041 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)7041 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)
7042 return LLVMGetUndef(get_llvm_type(g, type_entry));7042 return LLVMGetUndef(get_llvm_type(g, type_entry));
...@@ -7133,7 +7133,7 @@ check: switch (const_val->special) {...@@ -7133,7 +7133,7 @@ check: switch (const_val->special) {
7133 make_unnamed_struct = false;7133 make_unnamed_struct = false;
7134 } else {7134 } else {
7135 err_tag_value = LLVMConstNull(get_llvm_type(g, g->err_tag_type));7135 err_tag_value = LLVMConstNull(get_llvm_type(g, g->err_tag_type));
7136 ConstExprValue *payload_val = const_val->data.x_err_union.payload;7136 ZigValue *payload_val = const_val->data.x_err_union.payload;
7137 err_payload_value = gen_const_val(g, payload_val, "");7137 err_payload_value = gen_const_val(g, payload_val, "");
7138 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value);7138 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value);
7139 }7139 }
...@@ -7174,7 +7174,7 @@ check: switch (const_val->special) {...@@ -7174,7 +7174,7 @@ check: switch (const_val->special) {
7174 zig_unreachable();7174 zig_unreachable();
7175}7175}
71767176
7177static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {7177static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
7178 if (!const_val->global_refs)7178 if (!const_val->global_refs)
7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7180 if (!const_val->global_refs->llvm_value)7180 if (!const_val->global_refs->llvm_value)
...@@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *...@@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *
7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7185}7185}
71867186
7187static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name) {7187static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {
7188 if (!const_val->global_refs)7188 if (!const_val->global_refs)
7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);
71907190
...@@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) {
73247324
7325 if (var->var_type->id == ZigTypeIdComptimeFloat) {7325 if (var->var_type->id == ZigTypeIdComptimeFloat) {
7326 // Generate debug info for it but that's it.7326 // Generate debug info for it but that's it.
7327 ConstExprValue *const_val = var->const_value;7327 ZigValue *const_val = var->const_value;
7328 assert(const_val->special != ConstValSpecialRuntime);7328 assert(const_val->special != ConstValSpecialRuntime);
7329 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))7329 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
7330 zig_unreachable();7330 zig_unreachable();
...@@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) {
7332 zig_panic("TODO debug info for var with ptr casted value");7332 zig_panic("TODO debug info for var with ptr casted value");
7333 }7333 }
7334 ZigType *var_type = g->builtin_types.entry_f128;7334 ZigType *var_type = g->builtin_types.entry_f128;
7335 ConstExprValue coerced_value = {};7335 ZigValue coerced_value = {};
7336 coerced_value.special = ConstValSpecialStatic;7336 coerced_value.special = ConstValSpecialStatic;
7337 coerced_value.type = var_type;7337 coerced_value.type = var_type;
7338 coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);7338 coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
...@@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) {
73437343
7344 if (var->var_type->id == ZigTypeIdComptimeInt) {7344 if (var->var_type->id == ZigTypeIdComptimeInt) {
7345 // Generate debug info for it but that's it.7345 // Generate debug info for it but that's it.
7346 ConstExprValue *const_val = var->const_value;7346 ZigValue *const_val = var->const_value;
7347 assert(const_val->special != ConstValSpecialRuntime);7347 assert(const_val->special != ConstValSpecialRuntime);
7348 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))7348 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
7349 zig_unreachable();7349 zig_unreachable();
...@@ -7514,12 +7514,12 @@ static void do_code_gen(CodeGen *g) {...@@ -7514,12 +7514,12 @@ static void do_code_gen(CodeGen *g) {
7514 call->frame_result_loc = all_calls_alloca;7514 call->frame_result_loc = all_calls_alloca;
7515 }7515 }
7516 if (largest_call_frame_type != nullptr) {7516 if (largest_call_frame_type != nullptr) {
7517 all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false);7517 all_calls_alloca->value->type = get_pointer_to_type(g, largest_call_frame_type, false);
7518 }7518 }
7519 // allocate temporary stack data7519 // allocate temporary stack data
7520 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {7520 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
7521 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);7521 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
7522 ZigType *ptr_type = instruction->base.value.type;7522 ZigType *ptr_type = instruction->base.value->type;
7523 assert(ptr_type->id == ZigTypeIdPointer);7523 assert(ptr_type->id == ZigTypeIdPointer);
7524 ZigType *child_type = ptr_type->data.pointer.child_type;7524 ZigType *child_type = ptr_type->data.pointer.child_type;
7525 if (type_resolve(g, child_type, ResolveStatusSizeKnown))7525 if (type_resolve(g, child_type, ResolveStatusSizeKnown))
...@@ -7528,8 +7528,8 @@ static void do_code_gen(CodeGen *g) {...@@ -7528,8 +7528,8 @@ static void do_code_gen(CodeGen *g) {
7528 continue;7528 continue;
7529 if (instruction->base.ref_count == 0)7529 if (instruction->base.ref_count == 0)
7530 continue;7530 continue;
7531 if (instruction->base.value.special != ConstValSpecialRuntime) {7531 if (instruction->base.value->special != ConstValSpecialRuntime) {
7532 if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special !=7532 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
7533 ConstValSpecialRuntime)7533 ConstValSpecialRuntime)
7534 {7534 {
7535 continue;7535 continue;
...@@ -8008,6 +8008,33 @@ static void define_builtin_types(CodeGen *g) {...@@ -8008,6 +8008,33 @@ static void define_builtin_types(CodeGen *g) {
8008 }8008 }
8009}8009}
80108010
8011static void define_intern_values(CodeGen *g) {
8012 {
8013 auto& value = g->intern_values.x_undefined;
8014 value.type = g->builtin_types.entry_undef;
8015 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined");
8016 value.special = ConstValSpecialStatic;
8017 }
8018 {
8019 auto& value = g->intern_values.x_void;
8020 value.type = g->builtin_types.entry_void;
8021 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void");
8022 value.special = ConstValSpecialStatic;
8023 }
8024 {
8025 auto& value = g->intern_values.x_null;
8026 value.type = g->builtin_types.entry_null;
8027 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null");
8028 value.special = ConstValSpecialStatic;
8029 }
8030 {
8031 auto& value = g->intern_values.x_unreachable;
8032 value.type = g->builtin_types.entry_unreachable;
8033 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable");
8034 value.special = ConstValSpecialStatic;
8035 }
8036}
8037
8011static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {8038static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
8012 BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1);8039 BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1);
8013 buf_init_from_str(&builtin_fn->name, name);8040 buf_init_from_str(&builtin_fn->name, name);
...@@ -8629,15 +8656,18 @@ static void init(CodeGen *g) {...@@ -8629,15 +8656,18 @@ static void init(CodeGen *g) {
8629 g->dummy_di_file = nullptr;8656 g->dummy_di_file = nullptr;
86308657
8631 define_builtin_types(g);8658 define_builtin_types(g);
8659 define_intern_values(g);
86328660
8633 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);8661 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);
8634 g->invalid_instruction = &sentinel_instructions[0];8662 g->invalid_instruction = &sentinel_instructions[0];
8635 g->invalid_instruction->value.type = g->builtin_types.entry_invalid;8663 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
8636 g->invalid_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);8664 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8665 g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86378666
8638 g->unreach_instruction = &sentinel_instructions[1];8667 g->unreach_instruction = &sentinel_instructions[1];
8639 g->unreach_instruction->value.type = g->builtin_types.entry_unreachable;8668 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8640 g->unreach_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);8669 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
8670 g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86418671
8642 g->const_void_val.special = ConstValSpecialStatic;8672 g->const_void_val.special = ConstValSpecialStatic;
8643 g->const_void_val.type = g->builtin_types.entry_void;8673 g->const_void_val.type = g->builtin_types.entry_void;
...@@ -9080,13 +9110,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9080,13 +9110,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
90809110
9081 ZigType *fn_type = get_test_fn_type(g);9111 ZigType *fn_type = get_test_fn_type(g);
90829112
9083 ConstExprValue *test_fn_type_val = get_builtin_value(g, "TestFn");9113 ZigValue *test_fn_type_val = get_builtin_value(g, "TestFn");
9084 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);9114 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
9085 ZigType *struct_type = test_fn_type_val->data.x_type;9115 ZigType *struct_type = test_fn_type_val->data.x_type;
9086 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))9116 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
9087 zig_unreachable();9117 zig_unreachable();
90889118
9089 ConstExprValue *test_fn_array = create_const_vals(1);9119 ZigValue *test_fn_array = create_const_vals(1);
9090 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);9120 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
9091 test_fn_array->special = ConstValSpecialStatic;9121 test_fn_array->special = ConstValSpecialStatic;
9092 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);9122 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);
...@@ -9103,7 +9133,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9103,7 +9133,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9103 continue;9133 continue;
9104 }9134 }
91059135
9106 ConstExprValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];9136 ZigValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
9107 this_val->special = ConstValSpecialStatic;9137 this_val->special = ConstValSpecialStatic;
9108 this_val->type = struct_type;9138 this_val->type = struct_type;
9109 this_val->parent.id = ConstParentIdArray;9139 this_val->parent.id = ConstParentIdArray;
...@@ -9111,11 +9141,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9111,11 +9141,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9111 this_val->parent.data.p_array.elem_index = i;9141 this_val->parent.data.p_array.elem_index = i;
9112 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);9142 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
91139143
9114 ConstExprValue *name_field = this_val->data.x_struct.fields[0];9144 ZigValue *name_field = this_val->data.x_struct.fields[0];
9115 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;9145 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
9116 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);9146 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
91179147
9118 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];9148 ZigValue *fn_field = this_val->data.x_struct.fields[1];
9119 fn_field->type = fn_type;9149 fn_field->type = fn_type;
9120 fn_field->special = ConstValSpecialStatic;9150 fn_field->special = ConstValSpecialStatic;
9121 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;9151 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
...@@ -9124,7 +9154,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9124,7 +9154,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9124 }9154 }
9125 report_errors_and_maybe_exit(g);9155 report_errors_and_maybe_exit(g);
91269156
9127 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);9157 ZigValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
91289158
9129 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);9159 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
9130 assert(g->test_runner_package != nullptr);9160 assert(g->test_runner_package != nullptr);
...@@ -9221,7 +9251,7 @@ static void gen_root_source(CodeGen *g) {...@@ -9221,7 +9251,7 @@ static void gen_root_source(CodeGen *g) {
9221 report_errors_and_maybe_exit(g);9251 report_errors_and_maybe_exit(g);
9222 assert(builtin_tld->id == TldIdVar);9252 assert(builtin_tld->id == TldIdVar);
9223 TldVar *builtin_tld_var = (TldVar*)builtin_tld;9253 TldVar *builtin_tld_var = (TldVar*)builtin_tld;
9224 ConstExprValue *builtin_val = builtin_tld_var->var->const_value;9254 ZigValue *builtin_val = builtin_tld_var->var->const_value;
9225 assert(builtin_val->type->id == ZigTypeIdMetaType);9255 assert(builtin_val->type->id == ZigTypeIdMetaType);
9226 ZigType *builtin_type = builtin_val->data.x_type;9256 ZigType *builtin_type = builtin_val->data.x_type;
92279257
...@@ -9232,7 +9262,7 @@ static void gen_root_source(CodeGen *g) {...@@ -9232,7 +9262,7 @@ static void gen_root_source(CodeGen *g) {
9232 report_errors_and_maybe_exit(g);9262 report_errors_and_maybe_exit(g);
9233 assert(panic_tld->id == TldIdVar);9263 assert(panic_tld->id == TldIdVar);
9234 TldVar *panic_tld_var = (TldVar*)panic_tld;9264 TldVar *panic_tld_var = (TldVar*)panic_tld;
9235 ConstExprValue *panic_fn_val = panic_tld_var->var->const_value;9265 ZigValue *panic_fn_val = panic_tld_var->var->const_value;
9236 assert(panic_fn_val->type->id == ZigTypeIdFn);9266 assert(panic_fn_val->type->id == ZigTypeIdFn);
9237 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);9267 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);
9238 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;9268 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;
src/dump_analysis.cpp+4-4
...@@ -361,9 +361,9 @@ struct AnalDumpCtx {...@@ -361,9 +361,9 @@ struct AnalDumpCtx {
361};361};
362362
363static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);363static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);
364static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value);364static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value);
365365
366static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) {366static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) {
367 Error err;367 Error err;
368 if (value->type != ty) {368 if (value->type != ty) {
369 return;369 return;
...@@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) {...@@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) {
660 jw_string(jw, buf_ptr(file));660 jw_string(jw, buf_ptr(file));
661}661}
662662
663static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) {663static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) {
664 Error err;664 Error err;
665665
666 if (value->type != ty) {666 if (value->type != ty) {
...@@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const...@@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
1249 }1249 }
1250 scope = scope->parent;1250 scope = scope->parent;
1251 }1251 }
1252 ConstExprValue *result = entry->value;1252 ZigValue *result = entry->value;
12531253
1254 assert(fn != nullptr);1254 assert(fn != nullptr);
12551255
src/hash_map.hpp+6-6
...@@ -23,10 +23,10 @@ public:...@@ -23,10 +23,10 @@ public:
23 }23 }
2424
25 struct Entry {25 struct Entry {
26 bool used;
27 int distance_from_start_index;
28 K key;26 K key;
29 V value;27 V value;
28 bool used;
29 int distance_from_start_index;
30 };30 };
3131
32 void clear() {32 void clear() {
...@@ -187,10 +187,10 @@ private:...@@ -187,10 +187,10 @@ private:
187 if (distance_from_start_index > _max_distance_from_start_index)187 if (distance_from_start_index > _max_distance_from_start_index)
188 _max_distance_from_start_index = distance_from_start_index;188 _max_distance_from_start_index = distance_from_start_index;
189 *entry = {189 *entry = {
190 true,
191 distance_from_start_index,
192 key,190 key,
193 value,191 value,
192 true,
193 distance_from_start_index,
194 };194 };
195 key = tmp.key;195 key = tmp.key;
196 value = tmp.value;196 value = tmp.value;
...@@ -208,10 +208,10 @@ private:...@@ -208,10 +208,10 @@ private:
208 if (distance_from_start_index > _max_distance_from_start_index)208 if (distance_from_start_index > _max_distance_from_start_index)
209 _max_distance_from_start_index = distance_from_start_index;209 _max_distance_from_start_index = distance_from_start_index;
210 *entry = {210 *entry = {
211 true,
212 distance_from_start_index,
213 key,211 key,
214 value,212 value,
213 true,
214 distance_from_start_index,
215 };215 };
216 return;216 return;
217 }217 }
src/ir.cpp+1682-1644
...@@ -19,7 +19,7 @@...@@ -19,7 +19,7 @@
19#include <errno.h>19#include <errno.h>
2020
21struct IrExecContext {21struct IrExecContext {
22 ZigList<ConstExprValue *> mem_slot_list;22 ZigList<ZigValue *> mem_slot_list;
23};23};
2424
25struct IrBuilder {25struct IrBuilder {
...@@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
204static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);204static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);
205static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);205static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
206static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);206static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
207static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val);207static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
208static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);208static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
209static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,209static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
210 ConstExprValue *out_val, ConstExprValue *ptr_val);210 ZigValue *out_val, ZigValue *ptr_val);
211static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,211static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
212 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);212 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
213static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);213static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
214static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);214static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs);
215static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);215static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
216static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,216static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
217 ZigType *ptr_type);217 ZigType *ptr_type);
...@@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
244 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);244 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
245static ResultLoc *no_result_loc(void);245static ResultLoc *no_result_loc(void);
246246
247static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {247static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
248 assert(get_src_ptr_type(const_val->type) != nullptr);248 assert(get_src_ptr_type(const_val->type) != nullptr);
249 assert(const_val->special == ConstValSpecialStatic);249 assert(const_val->special == ConstValSpecialStatic);
250 ConstExprValue *result;250 ZigValue *result;
251251
252 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {252 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
253 case OnePossibleValueInvalid:253 case OnePossibleValueInvalid:
...@@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
265 result = const_val->data.x_ptr.data.ref.pointee;265 result = const_val->data.x_ptr.data.ref.pointee;
266 break;266 break;
267 case ConstPtrSpecialBaseArray: {267 case ConstPtrSpecialBaseArray: {
268 ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val;268 ZigValue *array_val = const_val->data.x_ptr.data.base_array.array_val;
269 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {269 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {
270 result = array_val->type->data.array.sentinel;270 result = array_val->type->data.array.sentinel;
271 } else {271 } else {
...@@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
275 break;275 break;
276 }276 }
277 case ConstPtrSpecialBaseStruct: {277 case ConstPtrSpecialBaseStruct: {
278 ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;278 ZigValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;
279 expand_undef_struct(g, struct_val);279 expand_undef_struct(g, struct_val);
280 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];280 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
281 break;281 break;
...@@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) {...@@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) {
317 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;317 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
318}318}
319319
320// This function returns true when you can change the type of a ConstExprValue and the320// This function returns true when you can change the type of a ZigValue and the
321// value remains meaningful.321// value remains meaningful.
322static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) {322static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) {
323 if (expected == actual)323 if (expected == actual)
...@@ -416,16 +416,16 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {...@@ -416,16 +416,16 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {
416 return exec->c_import_buf;416 return exec->c_import_buf;
417}417}
418418
419static bool value_is_comptime(ConstExprValue *const_val) {419static bool value_is_comptime(ZigValue *const_val) {
420 return const_val->special != ConstValSpecialRuntime;420 return const_val->special != ConstValSpecialRuntime;
421}421}
422422
423static bool instr_is_comptime(IrInstruction *instruction) {423static bool instr_is_comptime(IrInstruction *instruction) {
424 return value_is_comptime(&instruction->value);424 return value_is_comptime(instruction->value);
425}425}
426426
427static bool instr_is_unreachable(IrInstruction *instruction) {427static bool instr_is_unreachable(IrInstruction *instruction) {
428 return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable;428 return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable;
429}429}
430430
431static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {431static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {
...@@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) {...@@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) {
449}449}
450450
451ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {451ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
452 ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,452 ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,
453 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,453 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,
454 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);454 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);
455455
...@@ -1156,7 +1156,24 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no...@@ -1156,7 +1156,24 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no
1156 special_instruction->base.source_node = source_node;1156 special_instruction->base.source_node = source_node;
1157 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);1157 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1158 special_instruction->base.owner_bb = irb->current_basic_block;1158 special_instruction->base.owner_bb = irb->current_basic_block;
1159 special_instruction->base.value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs");1159 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1160 special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs");
1161 return special_instruction;
1162}
1163
1164template<typename T>
1165static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1166 const char *name = nullptr;
1167#ifdef ZIG_ENABLE_MEM_PROFILE
1168 T *dummy = nullptr;
1169 name = ir_instruction_type_str(ir_instruction_id(dummy));
1170#endif
1171 T *special_instruction = allocate<T>(1, name);
1172 special_instruction->base.id = ir_instruction_id(special_instruction);
1173 special_instruction->base.scope = scope;
1174 special_instruction->base.source_node = source_node;
1175 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1176 special_instruction->base.owner_bb = irb->current_basic_block;
1160 return special_instruction;1177 return special_instruction;
1161}1178}
11621179
...@@ -1184,8 +1201,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so...@@ -1184,8 +1201,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so
1184 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)1201 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)
1185{1202{
1186 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);1203 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);
1187 cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;1204 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1188 cond_br_instruction->base.value.special = ConstValSpecialStatic;1205 cond_br_instruction->base.value->special = ConstValSpecialStatic;
1189 cond_br_instruction->condition = condition;1206 cond_br_instruction->condition = condition;
1190 cond_br_instruction->then_block = then_block;1207 cond_br_instruction->then_block = then_block;
1191 cond_br_instruction->else_block = else_block;1208 cond_br_instruction->else_block = else_block;
...@@ -1203,8 +1220,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -1203,8 +1220,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
1203 IrInstruction *operand)1220 IrInstruction *operand)
1204{1221{
1205 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);1222 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);
1206 return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;1223 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1207 return_instruction->base.value.special = ConstValSpecialStatic;1224 return_instruction->base.value->special = ConstValSpecialStatic;
1208 return_instruction->operand = operand;1225 return_instruction->operand = operand;
12091226
1210 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);1227 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);
...@@ -1213,55 +1230,64 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -1213,55 +1230,64 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
1213}1230}
12141231
1215static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {1232static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1216 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1233#ifdef ZIG_ENABLE_MEM_PROFILE
1217 const_instruction->base.value.type = irb->codegen->builtin_types.entry_void;1234 memprof_intern_count.x_void += 1;
1218 const_instruction->base.value.special = ConstValSpecialStatic;1235#endif
1236 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
1237 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1238 const_instruction->base.value = &irb->codegen->intern_values.x_void;
1219 return &const_instruction->base;1239 return &const_instruction->base;
1220}1240}
12211241
1222static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {1242static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1223 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1243#ifdef ZIG_ENABLE_MEM_PROFILE
1224 const_instruction->base.value.special = ConstValSpecialUndef;1244 memprof_intern_count.x_undefined += 1;
1225 const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef;1245#endif
1246 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
1247 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1248 const_instruction->base.value = &irb->codegen->intern_values.x_undefined;
1226 return &const_instruction->base;1249 return &const_instruction->base;
1227}1250}
12281251
1229static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {1252static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1230 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1253 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1231 const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int;1254 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1232 const_instruction->base.value.special = ConstValSpecialStatic;1255 const_instruction->base.value->special = ConstValSpecialStatic;
1233 bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value);1256 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
1234 return &const_instruction->base;1257 return &const_instruction->base;
1235}1258}
12361259
1237static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {1260static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
1238 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1261 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1239 const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int;1262 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1240 const_instruction->base.value.special = ConstValSpecialStatic;1263 const_instruction->base.value->special = ConstValSpecialStatic;
1241 bigint_init_bigint(&const_instruction->base.value.data.x_bigint, bigint);1264 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);
1242 return &const_instruction->base;1265 return &const_instruction->base;
1243}1266}
12441267
1245static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {1268static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
1246 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1269 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1247 const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_float;1270 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;
1248 const_instruction->base.value.special = ConstValSpecialStatic;1271 const_instruction->base.value->special = ConstValSpecialStatic;
1249 bigfloat_init_bigfloat(&const_instruction->base.value.data.x_bigfloat, bigfloat);1272 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);
1250 return &const_instruction->base;1273 return &const_instruction->base;
1251}1274}
12521275
1253static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {1276static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1254 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1277#ifdef ZIG_ENABLE_MEM_PROFILE
1255 const_instruction->base.value.type = irb->codegen->builtin_types.entry_null;1278 memprof_intern_count.x_null += 1;
1256 const_instruction->base.value.special = ConstValSpecialStatic;1279#endif
1280 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
1281 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1282 const_instruction->base.value = &irb->codegen->intern_values.x_null;
1257 return &const_instruction->base;1283 return &const_instruction->base;
1258}1284}
12591285
1260static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {1286static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1261 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1287 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1262 const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize;1288 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;
1263 const_instruction->base.value.special = ConstValSpecialStatic;1289 const_instruction->base.value->special = ConstValSpecialStatic;
1264 bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value);1290 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
1265 return &const_instruction->base;1291 return &const_instruction->base;
1266}1292}
12671293
...@@ -1269,9 +1295,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode...@@ -1269,9 +1295,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
1269 ZigType *type_entry)1295 ZigType *type_entry)
1270{1296{
1271 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);1297 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1272 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;1298 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1273 const_instruction->base.value.special = ConstValSpecialStatic;1299 const_instruction->base.value->special = ConstValSpecialStatic;
1274 const_instruction->base.value.data.x_type = type_entry;1300 const_instruction->base.value->data.x_type = type_entry;
1275 return &const_instruction->base;1301 return &const_instruction->base;
1276}1302}
12771303
...@@ -1285,35 +1311,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode...@@ -1285,35 +1311,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode
12851311
1286static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {1312static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
1287 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);1313 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1288 const_instruction->base.value.type = fn_entry->type_entry;1314 const_instruction->base.value->type = fn_entry->type_entry;
1289 const_instruction->base.value.special = ConstValSpecialStatic;1315 const_instruction->base.value->special = ConstValSpecialStatic;
1290 const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry;1316 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;
1291 const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst;1317 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1292 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction;1318 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction;
1293 return &const_instruction->base;1319 return &const_instruction->base;
1294}1320}
12951321
1296static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {1322static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1297 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1323 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1298 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;1324 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1299 const_instruction->base.value.special = ConstValSpecialStatic;1325 const_instruction->base.value->special = ConstValSpecialStatic;
1300 const_instruction->base.value.data.x_type = import;1326 const_instruction->base.value->data.x_type = import;
1301 return &const_instruction->base;1327 return &const_instruction->base;
1302}1328}
13031329
1304static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {1330static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
1305 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1331 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1306 const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool;1332 const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool;
1307 const_instruction->base.value.special = ConstValSpecialStatic;1333 const_instruction->base.value->special = ConstValSpecialStatic;
1308 const_instruction->base.value.data.x_bool = value;1334 const_instruction->base.value->data.x_bool = value;
1309 return &const_instruction->base;1335 return &const_instruction->base;
1310}1336}
13111337
1312static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {1338static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {
1313 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1339 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1314 const_instruction->base.value.type = irb->codegen->builtin_types.entry_enum_literal;1340 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;
1315 const_instruction->base.value.special = ConstValSpecialStatic;1341 const_instruction->base.value->special = ConstValSpecialStatic;
1316 const_instruction->base.value.data.x_enum_literal = name;1342 const_instruction->base.value->data.x_enum_literal = name;
1317 return &const_instruction->base;1343 return &const_instruction->base;
1318}1344}
13191345
...@@ -1321,19 +1347,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN...@@ -1321,19 +1347,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN
1321 ZigFn *fn_entry, IrInstruction *first_arg)1347 ZigFn *fn_entry, IrInstruction *first_arg)
1322{1348{
1323 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1349 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1324 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);1350 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);
1325 const_instruction->base.value.special = ConstValSpecialStatic;1351 const_instruction->base.value->special = ConstValSpecialStatic;
1326 const_instruction->base.value.data.x_bound_fn.fn = fn_entry;1352 const_instruction->base.value->data.x_bound_fn.fn = fn_entry;
1327 const_instruction->base.value.data.x_bound_fn.first_arg = first_arg;1353 const_instruction->base.value->data.x_bound_fn.first_arg = first_arg;
1328 return &const_instruction->base;1354 return &const_instruction->base;
1329}1355}
13301356
1331static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {1357static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1332 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);1358 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1333 init_const_str_lit(irb->codegen, &const_instruction->base.value, str);1359 init_const_str_lit(irb->codegen, const_instruction->base.value, str);
13341360
1335 return &const_instruction->base;1361 return &const_instruction->base;
1336}1362}
1363
1337static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {1364static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1338 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);1365 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
1339 ir_instruction_append(irb->current_basic_block, instruction);1366 ir_instruction_append(irb->current_basic_block, instruction);
...@@ -1388,7 +1415,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so...@@ -1388,7 +1415,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so
1388static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {1415static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1389 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,1416 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,
1390 source_instruction->scope, source_instruction->source_node);1417 source_instruction->scope, source_instruction->source_node);
1391 instruction->base.value.type = ty;1418 instruction->base.value->type = ty;
1392 return &instruction->base;1419 return &instruction->base;
1393}1420}
13941421
...@@ -1513,7 +1540,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so...@@ -1513,7 +1540,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
1513{1540{
1514 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,1541 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
1515 source_instruction->scope, source_instruction->source_node);1542 source_instruction->scope, source_instruction->source_node);
1516 call_instruction->base.value.type = return_type;1543 call_instruction->base.value->type = return_type;
1517 call_instruction->fn_entry = fn_entry;1544 call_instruction->fn_entry = fn_entry;
1518 call_instruction->fn_ref = fn_ref;1545 call_instruction->fn_ref = fn_ref;
1519 call_instruction->fn_inline = fn_inline;1546 call_instruction->fn_inline = fn_inline;
...@@ -1558,8 +1585,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source...@@ -1558,8 +1585,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source
1558 IrBasicBlock *dest_block, IrInstruction *is_comptime)1585 IrBasicBlock *dest_block, IrInstruction *is_comptime)
1559{1586{
1560 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);1587 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);
1561 br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;1588 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1562 br_instruction->base.value.special = ConstValSpecialStatic;1589 br_instruction->base.value->special = ConstValSpecialStatic;
1563 br_instruction->dest_block = dest_block;1590 br_instruction->dest_block = dest_block;
1564 br_instruction->is_comptime = is_comptime;1591 br_instruction->is_comptime = is_comptime;
15651592
...@@ -1659,8 +1686,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop...@@ -1659,8 +1686,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
1659static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {1686static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1660 IrInstructionUnreachable *unreachable_instruction =1687 IrInstructionUnreachable *unreachable_instruction =
1661 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);1688 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
1662 unreachable_instruction->base.value.special = ConstValSpecialStatic;1689 unreachable_instruction->base.value->special = ConstValSpecialStatic;
1663 unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;1690 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1664 return &unreachable_instruction->base;1691 return &unreachable_instruction->base;
1665}1692}
16661693
...@@ -1668,8 +1695,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A...@@ -1668,8 +1695,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
1668 IrInstruction *ptr, IrInstruction *value)1695 IrInstruction *ptr, IrInstruction *value)
1669{1696{
1670 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);1697 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);
1671 instruction->base.value.special = ConstValSpecialStatic;1698 instruction->base.value->special = ConstValSpecialStatic;
1672 instruction->base.value.type = irb->codegen->builtin_types.entry_void;1699 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
1673 instruction->ptr = ptr;1700 instruction->ptr = ptr;
1674 instruction->value = value;1701 instruction->value = value;
16751702
...@@ -1684,7 +1711,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *...@@ -1684,7 +1711,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *
1684{1711{
1685 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(1712 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(
1686 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1713 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1687 inst->base.value.type = ira->codegen->builtin_types.entry_void;1714 inst->base.value->type = ira->codegen->builtin_types.entry_void;
1688 inst->vector_ptr = vector_ptr;1715 inst->vector_ptr = vector_ptr;
1689 inst->index = index;1716 inst->index = index;
1690 inst->value = value;1717 inst->value = value;
...@@ -1700,8 +1727,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod...@@ -1700,8 +1727,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod
1700 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)1727 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)
1701{1728{
1702 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);1729 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
1703 decl_var_instruction->base.value.special = ConstValSpecialStatic;1730 decl_var_instruction->base.value->special = ConstValSpecialStatic;
1704 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;1731 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
1705 decl_var_instruction->var = var;1732 decl_var_instruction->var = var;
1706 decl_var_instruction->align_value = align_value;1733 decl_var_instruction->align_value = align_value;
1707 decl_var_instruction->ptr = ptr;1734 decl_var_instruction->ptr = ptr;
...@@ -1717,8 +1744,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -1717,8 +1744,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc
1717{1744{
1718 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,1745 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,
1719 source_instruction->scope, source_instruction->source_node);1746 source_instruction->scope, source_instruction->source_node);
1720 decl_var_instruction->base.value.special = ConstValSpecialStatic;1747 decl_var_instruction->base.value->special = ConstValSpecialStatic;
1721 decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void;1748 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;
1722 decl_var_instruction->var = var;1749 decl_var_instruction->var = var;
1723 decl_var_instruction->var_ptr = var_ptr;1750 decl_var_instruction->var_ptr = var_ptr;
17241751
...@@ -1732,7 +1759,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc...@@ -1732,7 +1759,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc
1732{1759{
1733 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,1760 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,
1734 source_instruction->scope, source_instruction->source_node);1761 source_instruction->scope, source_instruction->source_node);
1735 instruction->base.value.type = ty;1762 instruction->base.value->type = ty;
1736 instruction->operand = operand;1763 instruction->operand = operand;
1737 instruction->result_loc = result_loc;1764 instruction->result_loc = result_loc;
17381765
...@@ -1747,8 +1774,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -1747,8 +1774,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
1747{1774{
1748 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(1775 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(
1749 irb, scope, source_node);1776 irb, scope, source_node);
1750 export_instruction->base.value.special = ConstValSpecialStatic;1777 export_instruction->base.value->special = ConstValSpecialStatic;
1751 export_instruction->base.value.type = irb->codegen->builtin_types.entry_void;1778 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
1752 export_instruction->name = name;1779 export_instruction->name = name;
1753 export_instruction->target = target;1780 export_instruction->target = target;
1754 export_instruction->linkage = linkage;1781 export_instruction->linkage = linkage;
...@@ -1925,7 +1952,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour...@@ -1925,7 +1952,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour
1925{1952{
1926 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(1953 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(
1927 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1954 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1928 instruction->base.value.type = result_ty;1955 instruction->base.value->type = result_ty;
1929 instruction->operand = operand;1956 instruction->operand = operand;
1930 instruction->result_loc = result_loc;1957 instruction->result_loc = result_loc;
19311958
...@@ -1940,7 +1967,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s...@@ -1940,7 +1967,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s
1940{1967{
1941 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(1968 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(
1942 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1969 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1943 instruction->base.value.type = result_type;1970 instruction->base.value->type = result_type;
1944 instruction->operand = operand;1971 instruction->operand = operand;
1945 instruction->result_loc = result_loc;1972 instruction->result_loc = result_loc;
19461973
...@@ -1955,7 +1982,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour...@@ -1955,7 +1982,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour
1955{1982{
1956 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(1983 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(
1957 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1984 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1958 instruction->base.value.type = result_type;1985 instruction->base.value->type = result_type;
1959 instruction->operand = operand;1986 instruction->operand = operand;
1960 instruction->result_loc = result_loc;1987 instruction->result_loc = result_loc;
19611988
...@@ -2025,8 +2052,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A...@@ -2025,8 +2052,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
2025 IrInstruction *switch_prongs_void)2052 IrInstruction *switch_prongs_void)
2026{2053{
2027 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);2054 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);
2028 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;2055 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2029 instruction->base.value.special = ConstValSpecialStatic;2056 instruction->base.value->special = ConstValSpecialStatic;
2030 instruction->target_value = target_value;2057 instruction->target_value = target_value;
2031 instruction->else_block = else_block;2058 instruction->else_block = else_block;
2032 instruction->case_count = case_count;2059 instruction->case_count = case_count;
...@@ -2122,7 +2149,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins...@@ -2122,7 +2149,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins
2122{2149{
2123 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,2150 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,
2124 source_instruction->scope, source_instruction->source_node);2151 source_instruction->scope, source_instruction->source_node);
2125 instruction->base.value.type = result_type;2152 instruction->base.value->type = result_type;
2126 instruction->operand = operand;2153 instruction->operand = operand;
2127 instruction->result_loc = result_loc;2154 instruction->result_loc = result_loc;
21282155
...@@ -2237,7 +2264,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source...@@ -2237,7 +2264,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
2237{2264{
2238 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,2265 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,
2239 source_instruction->scope, source_instruction->source_node);2266 source_instruction->scope, source_instruction->source_node);
2240 instruction->base.value.type = result_type;2267 instruction->base.value->type = result_type;
2241 instruction->ptr = ptr;2268 instruction->ptr = ptr;
2242 instruction->cmp_value = cmp_value;2269 instruction->cmp_value = cmp_value;
2243 instruction->new_value = new_value;2270 instruction->new_value = new_value;
...@@ -2482,7 +2509,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i...@@ -2482,7 +2509,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i
2482{2509{
2483 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(2510 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(
2484 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2511 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2485 instruction->base.value.type = result_type;2512 instruction->base.value->type = result_type;
2486 instruction->scalar = scalar;2513 instruction->scalar = scalar;
24872514
2488 ir_ref_instruction(scalar, ira->new_irb.current_basic_block);2515 ir_ref_instruction(scalar, ira->new_irb.current_basic_block);
...@@ -2495,7 +2522,7 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i...@@ -2495,7 +2522,7 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i
2495{2522{
2496 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(2523 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(
2497 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2524 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2498 instruction->base.value.type = slice_type;2525 instruction->base.value->type = slice_type;
2499 instruction->ptr = ptr;2526 instruction->ptr = ptr;
2500 instruction->start = start;2527 instruction->start = start;
2501 instruction->end = end;2528 instruction->end = end;
...@@ -2709,7 +2736,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -2709,7 +2736,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc
2709{2736{
2710 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(2737 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
2711 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2738 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2712 instruction->base.value.type = ira->codegen->builtin_types.entry_bool;2739 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
2713 instruction->err_union = err_union;2740 instruction->err_union = err_union;
27142741
2715 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);2742 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);
...@@ -2792,7 +2819,7 @@ static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -2792,7 +2819,7 @@ static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *sourc
2792{2819{
2793 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(2820 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(
2794 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2821 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2795 instruction->base.value.type = ptr_type;2822 instruction->base.value->type = ptr_type;
2796 instruction->ptr = ptr;2823 instruction->ptr = ptr;
2797 instruction->safety_check_on = safety_check_on;2824 instruction->safety_check_on = safety_check_on;
27982825
...@@ -2806,7 +2833,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -2806,7 +2833,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
2806{2833{
2807 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(2834 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(
2808 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2835 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2809 instruction->base.value.type = ty;2836 instruction->base.value->type = ty;
2810 instruction->ptr = ptr;2837 instruction->ptr = ptr;
2811 instruction->result_loc = result_loc;2838 instruction->result_loc = result_loc;
28122839
...@@ -2845,7 +2872,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -2845,7 +2872,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc
2845{2872{
2846 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(2873 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(
2847 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2874 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2848 instruction->base.value.type = ty;2875 instruction->base.value->type = ty;
2849 instruction->operand = operand;2876 instruction->operand = operand;
28502877
2851 ir_ref_instruction(operand, ira->new_irb.current_basic_block);2878 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
...@@ -2997,8 +3024,8 @@ static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2997,8 +3024,8 @@ static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *s
29973024
2998static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {3025static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
2999 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);3026 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);
3000 instruction->base.value.special = ConstValSpecialStatic;3027 instruction->base.value->special = ConstValSpecialStatic;
3001 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;3028 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
3002 instruction->msg = msg;3029 instruction->msg = msg;
30033030
3004 ir_ref_instruction(msg, irb->current_basic_block);3031 ir_ref_instruction(msg, irb->current_basic_block);
...@@ -3328,7 +3355,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so...@@ -3328,7 +3355,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so
3328{3355{
3329 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,3356 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,
3330 source_instruction->scope, source_instruction->source_node);3357 source_instruction->scope, source_instruction->source_node);
3331 instruction->base.value.type = result_type;3358 instruction->base.value->type = result_type;
3332 instruction->vector = vector;3359 instruction->vector = vector;
3333 instruction->result_loc = result_loc;3360 instruction->result_loc = result_loc;
33343361
...@@ -3343,7 +3370,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi...@@ -3343,7 +3370,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi
3343{3370{
3344 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,3371 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,
3345 source_instruction->scope, source_instruction->source_node);3372 source_instruction->scope, source_instruction->source_node);
3346 instruction->base.value.type = result_type;3373 instruction->base.value->type = result_type;
3347 instruction->operand = operand;3374 instruction->operand = operand;
3348 instruction->result_loc = result_loc;3375 instruction->result_loc = result_loc;
33493376
...@@ -3358,7 +3385,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so...@@ -3358,7 +3385,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so
3358{3385{
3359 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,3386 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,
3360 source_instruction->scope, source_instruction->source_node);3387 source_instruction->scope, source_instruction->source_node);
3361 instruction->base.value.type = result_type;3388 instruction->base.value->type = result_type;
3362 instruction->array = array;3389 instruction->array = array;
33633390
3364 ir_ref_instruction(array, ira->new_irb.current_basic_block);3391 ir_ref_instruction(array, ira->new_irb.current_basic_block);
...@@ -3371,7 +3398,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source...@@ -3371,7 +3398,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source
3371{3398{
3372 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,3399 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,
3373 source_instruction->scope, source_instruction->source_node);3400 source_instruction->scope, source_instruction->source_node);
3374 instruction->base.value.type = ira->codegen->builtin_types.entry_void;3401 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3375 instruction->target = target;3402 instruction->target = target;
33763403
3377 ir_ref_instruction(target, ira->new_irb.current_basic_block);3404 ir_ref_instruction(target, ira->new_irb.current_basic_block);
...@@ -3384,7 +3411,7 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so...@@ -3384,7 +3411,7 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so
3384{3411{
3385 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,3412 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,
3386 source_instruction->scope, source_instruction->source_node);3413 source_instruction->scope, source_instruction->source_node);
3387 instruction->base.value.type = ira->codegen->builtin_types.entry_void;3414 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3388 instruction->target = target;3415 instruction->target = target;
33893416
3390 ir_ref_instruction(target, ira->new_irb.current_basic_block);3417 ir_ref_instruction(target, ira->new_irb.current_basic_block);
...@@ -3433,7 +3460,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3433,7 +3460,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
34333460
3434static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {3461static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3435 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);3462 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);
3436 instruction->base.value.type = irb->codegen->builtin_types.entry_void;3463 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
34373464
3438 return instruction;3465 return instruction;
3439}3466}
...@@ -3442,7 +3469,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN...@@ -3442,7 +3469,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN
3442 IrInstructionSuspendBegin *begin)3469 IrInstructionSuspendBegin *begin)
3443{3470{
3444 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);3471 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);
3445 instruction->base.value.type = irb->codegen->builtin_types.entry_void;3472 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3446 instruction->begin = begin;3473 instruction->begin = begin;
34473474
3448 ir_ref_instruction(&begin->base, irb->current_basic_block);3475 ir_ref_instruction(&begin->base, irb->current_basic_block);
...@@ -3467,7 +3494,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *...@@ -3467,7 +3494,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *
3467{3494{
3468 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,3495 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,
3469 source_instruction->scope, source_instruction->source_node);3496 source_instruction->scope, source_instruction->source_node);
3470 instruction->base.value.type = result_type;3497 instruction->base.value->type = result_type;
3471 instruction->frame = frame;3498 instruction->frame = frame;
3472 instruction->result_loc = result_loc;3499 instruction->result_loc = result_loc;
34733500
...@@ -3479,7 +3506,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *...@@ -3479,7 +3506,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *
34793506
3480static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {3507static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {
3481 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);3508 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);
3482 instruction->base.value.type = irb->codegen->builtin_types.entry_void;3509 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3483 instruction->frame = frame;3510 instruction->frame = frame;
34843511
3485 ir_ref_instruction(frame, irb->current_basic_block);3512 ir_ref_instruction(frame, irb->current_basic_block);
...@@ -3491,8 +3518,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop...@@ -3491,8 +3518,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
3491 IrInstruction *operand, SpillId spill_id)3518 IrInstruction *operand, SpillId spill_id)
3492{3519{
3493 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);3520 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);
3494 instruction->base.value.special = ConstValSpecialStatic;3521 instruction->base.value->special = ConstValSpecialStatic;
3495 instruction->base.value.type = irb->codegen->builtin_types.entry_void;3522 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3496 instruction->operand = operand;3523 instruction->operand = operand;
3497 instruction->spill_id = spill_id;3524 instruction->spill_id = spill_id;
34983525
...@@ -3517,7 +3544,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction...@@ -3517,7 +3544,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction
3517{3544{
3518 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(3545 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(
3519 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3546 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3520 instruction->base.value.type = vector->value.type->data.vector.elem_type;3547 instruction->base.value->type = vector->value->type->data.vector.elem_type;
3521 instruction->vector = vector;3548 instruction->vector = vector;
3522 instruction->index = index;3549 instruction->index = index;
35233550
...@@ -3588,8 +3615,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -3588,8 +3615,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
3588 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;3615 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
3589 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);3616 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
3590 if (defer_expr_value != irb->codegen->invalid_instruction) {3617 if (defer_expr_value != irb->codegen->invalid_instruction) {
3591 if (defer_expr_value->value.type != nullptr &&3618 if (defer_expr_value->value->type != nullptr &&
3592 defer_expr_value->value.type->id == ZigTypeIdUnreachable)3619 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
3593 {3620 {
3594 is_noreturn = true;3621 is_noreturn = true;
3595 } else {3622 } else {
...@@ -4411,7 +4438,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode...@@ -4411,7 +4438,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
4411 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);4438 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
4412 tld_var->base.resolution = TldResolutionInvalid;4439 tld_var->base.resolution = TldResolutionInvalid;
4413 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,4440 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
4414 &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);4441 g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);
4415 scope_decls->decl_table.put(var_name, &tld_var->base);4442 scope_decls->decl_table.put(var_name, &tld_var->base);
4416}4443}
44174444
...@@ -4424,10 +4451,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4424,10 +4451,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4424 if (buf_eql_str(variable_name, "_")) {4451 if (buf_eql_str(variable_name, "_")) {
4425 if (lval == LValPtr) {4452 if (lval == LValPtr) {
4426 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);4453 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);
4427 const_instruction->base.value.type = get_pointer_to_type(irb->codegen,4454 const_instruction->base.value->type = get_pointer_to_type(irb->codegen,
4428 irb->codegen->builtin_types.entry_void, false);4455 irb->codegen->builtin_types.entry_void, false);
4429 const_instruction->base.value.special = ConstValSpecialStatic;4456 const_instruction->base.value->special = ConstValSpecialStatic;
4430 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard;4457 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;
4431 return &const_instruction->base;4458 return &const_instruction->base;
4432 } else {4459 } else {
4433 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));4460 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
...@@ -8698,26 +8725,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) {...@@ -8698,26 +8725,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) {
8698// This function takes a comptime ptr and makes the child const value conform to the type8725// This function takes a comptime ptr and makes the child const value conform to the type
8699// described by the pointer.8726// described by the pointer.
8700static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,8727static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
8701 ConstExprValue *ptr_val)8728 ZigValue *ptr_val)
8702{8729{
8703 Error err;8730 Error err;
8704 assert(ptr_val->type->id == ZigTypeIdPointer);8731 assert(ptr_val->type->id == ZigTypeIdPointer);
8705 assert(ptr_val->special == ConstValSpecialStatic);8732 assert(ptr_val->special == ConstValSpecialStatic);
8706 ConstExprValue tmp = {};8733 ZigValue tmp = {};
8707 tmp.special = ConstValSpecialStatic;8734 tmp.special = ConstValSpecialStatic;
8708 tmp.type = ptr_val->type->data.pointer.child_type;8735 tmp.type = ptr_val->type->data.pointer.child_type;
8709 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))8736 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
8710 return err;8737 return err;
8711 ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);8738 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
8712 copy_const_val(child_val, &tmp, false);8739 copy_const_val(child_val, &tmp, false);
8713 return ErrorNone;8740 return ErrorNone;
8714}8741}
87158742
8716ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,8743ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
8717 AstNode *source_node)8744 AstNode *source_node)
8718{8745{
8719 Error err;8746 Error err;
8720 ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val);8747 ZigValue *val = const_ptr_pointee_unchecked(codegen, const_val);
8721 assert(val != nullptr);8748 assert(val != nullptr);
8722 assert(const_val->type->id == ZigTypeIdPointer);8749 assert(const_val->type->id == ZigTypeIdPointer);
8723 ZigType *expected_type = const_val->type->data.pointer.child_type;8750 ZigType *expected_type = const_val->type->data.pointer.child_type;
...@@ -8740,19 +8767,19 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal...@@ -8740,19 +8767,19 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
8740 return val;8767 return val;
8741}8768}
87428769
8743static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {8770static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
8744 IrBasicBlock *bb = exec->basic_block_list.at(0);8771 IrBasicBlock *bb = exec->basic_block_list.at(0);
8745 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {8772 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
8746 IrInstruction *instruction = bb->instruction_list.at(i);8773 IrInstruction *instruction = bb->instruction_list.at(i);
8747 if (instruction->id == IrInstructionIdReturn) {8774 if (instruction->id == IrInstructionIdReturn) {
8748 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;8775 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
8749 IrInstruction *operand = ret_inst->operand;8776 IrInstruction *operand = ret_inst->operand;
8750 if (operand->value.special == ConstValSpecialRuntime) {8777 if (operand->value->special == ConstValSpecialRuntime) {
8751 exec_add_error_node(codegen, exec, operand->source_node,8778 exec_add_error_node(codegen, exec, operand->source_node,
8752 buf_sprintf("unable to evaluate constant expression"));8779 buf_sprintf("unable to evaluate constant expression"));
8753 return &codegen->invalid_instruction->value;8780 return codegen->invalid_instruction->value;
8754 }8781 }
8755 return &operand->value;8782 return operand->value;
8756 } else if (ir_has_side_effects(instruction)) {8783 } else if (ir_has_side_effects(instruction)) {
8757 if (instr_is_comptime(instruction)) {8784 if (instr_is_comptime(instruction)) {
8758 switch (instruction->id) {8785 switch (instruction->id) {
...@@ -8769,7 +8796,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec...@@ -8769,7 +8796,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec
8769 }8796 }
8770 exec_add_error_node(codegen, exec, instruction->source_node,8797 exec_add_error_node(codegen, exec, instruction->source_node,
8771 buf_sprintf("unable to evaluate constant expression"));8798 buf_sprintf("unable to evaluate constant expression"));
8772 return &codegen->invalid_instruction->value;8799 return codegen->invalid_instruction->value;
8773 }8800 }
8774 }8801 }
8775 zig_unreachable();8802 zig_unreachable();
...@@ -8783,14 +8810,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so...@@ -8783,14 +8810,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
8783 return true;8810 return true;
8784}8811}
87858812
8786static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {8813static bool const_val_fits_in_num_lit(ZigValue *const_val, ZigType *num_lit_type) {
8787 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&8814 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
8788 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||8815 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
8789 (num_lit_type->id == ZigTypeIdComptimeInt &&8816 (num_lit_type->id == ZigTypeIdComptimeInt &&
8790 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));8817 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
8791}8818}
87928819
8793static bool float_has_fraction(ConstExprValue *const_val) {8820static bool float_has_fraction(ZigValue *const_val) {
8794 if (const_val->type->id == ZigTypeIdComptimeFloat) {8821 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8795 return bigfloat_has_fraction(&const_val->data.x_bigfloat);8822 return bigfloat_has_fraction(&const_val->data.x_bigfloat);
8796 } else if (const_val->type->id == ZigTypeIdFloat) {8823 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8818,7 +8845,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {...@@ -8818,7 +8845,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {
8818 }8845 }
8819}8846}
88208847
8821static void float_append_buf(Buf *buf, ConstExprValue *const_val) {8848static void float_append_buf(Buf *buf, ZigValue *const_val) {
8822 if (const_val->type->id == ZigTypeIdComptimeFloat) {8849 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8823 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);8850 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
8824 } else if (const_val->type->id == ZigTypeIdFloat) {8851 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8856,7 +8883,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {...@@ -8856,7 +8883,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
8856 }8883 }
8857}8884}
88588885
8859static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {8886static void float_init_bigint(BigInt *bigint, ZigValue *const_val) {
8860 if (const_val->type->id == ZigTypeIdComptimeFloat) {8887 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8861 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);8888 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
8862 } else if (const_val->type->id == ZigTypeIdFloat) {8889 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8903,7 +8930,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {...@@ -8903,7 +8930,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
8903 }8930 }
8904}8931}
89058932
8906static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {8933static void float_init_bigfloat(ZigValue *dest_val, BigFloat *bigfloat) {
8907 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8934 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8908 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);8935 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
8909 } else if (dest_val->type->id == ZigTypeIdFloat) {8936 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8930,7 +8957,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {...@@ -8930,7 +8957,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
8930 }8957 }
8931}8958}
89328959
8933static void float_init_f16(ConstExprValue *dest_val, float16_t x) {8960static void float_init_f16(ZigValue *dest_val, float16_t x) {
8934 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8961 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8935 bigfloat_init_16(&dest_val->data.x_bigfloat, x);8962 bigfloat_init_16(&dest_val->data.x_bigfloat, x);
8936 } else if (dest_val->type->id == ZigTypeIdFloat) {8963 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8955,7 +8982,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {...@@ -8955,7 +8982,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
8955 }8982 }
8956}8983}
89578984
8958static void float_init_f32(ConstExprValue *dest_val, float x) {8985static void float_init_f32(ZigValue *dest_val, float x) {
8959 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8986 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8960 bigfloat_init_32(&dest_val->data.x_bigfloat, x);8987 bigfloat_init_32(&dest_val->data.x_bigfloat, x);
8961 } else if (dest_val->type->id == ZigTypeIdFloat) {8988 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8984,7 +9011,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {...@@ -8984,7 +9011,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
8984 }9011 }
8985}9012}
89869013
8987static void float_init_f64(ConstExprValue *dest_val, double x) {9014static void float_init_f64(ZigValue *dest_val, double x) {
8988 if (dest_val->type->id == ZigTypeIdComptimeFloat) {9015 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8989 bigfloat_init_64(&dest_val->data.x_bigfloat, x);9016 bigfloat_init_64(&dest_val->data.x_bigfloat, x);
8990 } else if (dest_val->type->id == ZigTypeIdFloat) {9017 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -9013,7 +9040,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {...@@ -9013,7 +9040,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
9013 }9040 }
9014}9041}
90159042
9016static void float_init_f128(ConstExprValue *dest_val, float128_t x) {9043static void float_init_f128(ZigValue *dest_val, float128_t x) {
9017 if (dest_val->type->id == ZigTypeIdComptimeFloat) {9044 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
9018 bigfloat_init_128(&dest_val->data.x_bigfloat, x);9045 bigfloat_init_128(&dest_val->data.x_bigfloat, x);
9019 } else if (dest_val->type->id == ZigTypeIdFloat) {9046 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -9046,7 +9073,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {...@@ -9046,7 +9073,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
9046 }9073 }
9047}9074}
90489075
9049static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {9076static void float_init_float(ZigValue *dest_val, ZigValue *src_val) {
9050 if (src_val->type->id == ZigTypeIdComptimeFloat) {9077 if (src_val->type->id == ZigTypeIdComptimeFloat) {
9051 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);9078 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
9052 } else if (src_val->type->id == ZigTypeIdFloat) {9079 } else if (src_val->type->id == ZigTypeIdFloat) {
...@@ -9071,7 +9098,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)...@@ -9071,7 +9098,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
9071 }9098 }
9072}9099}
90739100
9074static bool float_is_nan(ConstExprValue *op) {9101static bool float_is_nan(ZigValue *op) {
9075 if (op->type->id == ZigTypeIdComptimeFloat) {9102 if (op->type->id == ZigTypeIdComptimeFloat) {
9076 return bigfloat_is_nan(&op->data.x_bigfloat);9103 return bigfloat_is_nan(&op->data.x_bigfloat);
9077 } else if (op->type->id == ZigTypeIdFloat) {9104 } else if (op->type->id == ZigTypeIdFloat) {
...@@ -9092,7 +9119,7 @@ static bool float_is_nan(ConstExprValue *op) {...@@ -9092,7 +9119,7 @@ static bool float_is_nan(ConstExprValue *op) {
9092 }9119 }
9093}9120}
90949121
9095static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {9122static Cmp float_cmp(ZigValue *op1, ZigValue *op2) {
9096 assert(op1->type == op2->type);9123 assert(op1->type == op2->type);
9097 if (op1->type->id == ZigTypeIdComptimeFloat) {9124 if (op1->type->id == ZigTypeIdComptimeFloat) {
9098 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);9125 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
...@@ -9138,7 +9165,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {...@@ -9138,7 +9165,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
9138 }9165 }
9139}9166}
91409167
9141static Cmp float_cmp_zero(ConstExprValue *op) {9168static Cmp float_cmp_zero(ZigValue *op) {
9142 if (op->type->id == ZigTypeIdComptimeFloat) {9169 if (op->type->id == ZigTypeIdComptimeFloat) {
9143 return bigfloat_cmp_zero(&op->data.x_bigfloat);9170 return bigfloat_cmp_zero(&op->data.x_bigfloat);
9144 } else if (op->type->id == ZigTypeIdFloat) {9171 } else if (op->type->id == ZigTypeIdFloat) {
...@@ -9188,7 +9215,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {...@@ -9188,7 +9215,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
9188 }9215 }
9189}9216}
91909217
9191static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9218static void float_add(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9192 assert(op1->type == op2->type);9219 assert(op1->type == op2->type);
9193 out_val->type = op1->type;9220 out_val->type = op1->type;
9194 if (op1->type->id == ZigTypeIdComptimeFloat) {9221 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9215,7 +9242,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9215,7 +9242,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9215 }9242 }
9216}9243}
92179244
9218static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9245static void float_sub(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9219 assert(op1->type == op2->type);9246 assert(op1->type == op2->type);
9220 out_val->type = op1->type;9247 out_val->type = op1->type;
9221 if (op1->type->id == ZigTypeIdComptimeFloat) {9248 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9242,7 +9269,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9242,7 +9269,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9242 }9269 }
9243}9270}
92449271
9245static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9272static void float_mul(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9246 assert(op1->type == op2->type);9273 assert(op1->type == op2->type);
9247 out_val->type = op1->type;9274 out_val->type = op1->type;
9248 if (op1->type->id == ZigTypeIdComptimeFloat) {9275 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9269,7 +9296,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9269,7 +9296,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9269 }9296 }
9270}9297}
92719298
9272static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9299static void float_div(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9273 assert(op1->type == op2->type);9300 assert(op1->type == op2->type);
9274 out_val->type = op1->type;9301 out_val->type = op1->type;
9275 if (op1->type->id == ZigTypeIdComptimeFloat) {9302 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9296,7 +9323,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9296,7 +9323,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9296 }9323 }
9297}9324}
92989325
9299static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9326static void float_div_trunc(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9300 assert(op1->type == op2->type);9327 assert(op1->type == op2->type);
9301 out_val->type = op1->type;9328 out_val->type = op1->type;
9302 if (op1->type->id == ZigTypeIdComptimeFloat) {9329 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9325,7 +9352,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -9325,7 +9352,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
9325 }9352 }
9326}9353}
93279354
9328static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9355static void float_div_floor(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9329 assert(op1->type == op2->type);9356 assert(op1->type == op2->type);
9330 out_val->type = op1->type;9357 out_val->type = op1->type;
9331 if (op1->type->id == ZigTypeIdComptimeFloat) {9358 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9354,7 +9381,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -9354,7 +9381,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
9354 }9381 }
9355}9382}
93569383
9357static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9384static void float_rem(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9358 assert(op1->type == op2->type);9385 assert(op1->type == op2->type);
9359 out_val->type = op1->type;9386 out_val->type = op1->type;
9360 if (op1->type->id == ZigTypeIdComptimeFloat) {9387 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9399,7 +9426,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*...@@ -9399,7 +9426,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
9399 f128M_sub(a, c, c);9426 f128M_sub(a, c, c);
9400}9427}
94019428
9402static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9429static void float_mod(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9403 assert(op1->type == op2->type);9430 assert(op1->type == op2->type);
9404 out_val->type = op1->type;9431 out_val->type = op1->type;
9405 if (op1->type->id == ZigTypeIdComptimeFloat) {9432 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9426,7 +9453,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9426,7 +9453,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9426 }9453 }
9427}9454}
94289455
9429static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {9456static void float_negate(ZigValue *out_val, ZigValue *op) {
9430 out_val->type = op->type;9457 out_val->type = op->type;
9431 if (op->type->id == ZigTypeIdComptimeFloat) {9458 if (op->type->id == ZigTypeIdComptimeFloat) {
9432 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);9459 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
...@@ -9457,7 +9484,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {...@@ -9457,7 +9484,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
9457 }9484 }
9458}9485}
94599486
9460void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {9487void float_write_ieee597(ZigValue *op, uint8_t *buf, bool is_big_endian) {
9461 if (op->type->id == ZigTypeIdFloat) {9488 if (op->type->id == ZigTypeIdFloat) {
9462 switch (op->type->data.floating.bit_count) {9489 switch (op->type->data.floating.bit_count) {
9463 case 16:9490 case 16:
...@@ -9480,7 +9507,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {...@@ -9480,7 +9507,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
9480 }9507 }
9481}9508}
94829509
9483void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {9510void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
9484 if (val->type->id == ZigTypeIdFloat) {9511 if (val->type->id == ZigTypeIdFloat) {
9485 switch (val->type->data.floating.bit_count) {9512 switch (val->type->data.floating.bit_count) {
9486 case 16:9513 case 16:
...@@ -9510,7 +9537,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -9510,7 +9537,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
9510 return false;9537 return false;
9511 }9538 }
95129539
9513 ConstExprValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);9540 ZigValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);
9514 if (const_val == nullptr)9541 if (const_val == nullptr)
9515 return false;9542 return false;
95169543
...@@ -10217,13 +10244,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10217,13 +10244,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10217 size_t i = 0;10244 size_t i = 0;
10218 for (;;) {10245 for (;;) {
10219 prev_inst = instructions[i];10246 prev_inst = instructions[i];
10220 if (type_is_invalid(prev_inst->value.type)) {10247 if (type_is_invalid(prev_inst->value->type)) {
10221 return ira->codegen->builtin_types.entry_invalid;10248 return ira->codegen->builtin_types.entry_invalid;
10222 }10249 }
10223 if (prev_inst->value.type->id == ZigTypeIdUnreachable) {10250 if (prev_inst->value->type->id == ZigTypeIdUnreachable) {
10224 i += 1;10251 i += 1;
10225 if (i == instruction_count) {10252 if (i == instruction_count) {
10226 return prev_inst->value.type;10253 return prev_inst->value->type;
10227 }10254 }
10228 continue;10255 continue;
10229 }10256 }
...@@ -10232,14 +10259,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10232,14 +10259,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10232 ErrorTableEntry **errors = nullptr;10259 ErrorTableEntry **errors = nullptr;
10233 size_t errors_count = 0;10260 size_t errors_count = 0;
10234 ZigType *err_set_type = nullptr;10261 ZigType *err_set_type = nullptr;
10235 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {10262 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10236 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value.type, prev_inst->source_node)) {10263 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
10237 return ira->codegen->builtin_types.entry_invalid;10264 return ira->codegen->builtin_types.entry_invalid;
10238 }10265 }
10239 if (type_is_global_error_set(prev_inst->value.type)) {10266 if (type_is_global_error_set(prev_inst->value->type)) {
10240 err_set_type = ira->codegen->builtin_types.entry_global_error_set;10267 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
10241 } else {10268 } else {
10242 err_set_type = prev_inst->value.type;10269 err_set_type = prev_inst->value->type;
10243 update_errors_helper(ira->codegen, &errors, &errors_count);10270 update_errors_helper(ira->codegen, &errors, &errors_count);
1024410271
10245 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {10272 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
...@@ -10250,12 +10277,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10250,12 +10277,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10250 }10277 }
10251 }10278 }
1025210279
10253 bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);10280 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
10254 bool convert_to_const_slice = false;10281 bool convert_to_const_slice = false;
10255 for (; i < instruction_count; i += 1) {10282 for (; i < instruction_count; i += 1) {
10256 IrInstruction *cur_inst = instructions[i];10283 IrInstruction *cur_inst = instructions[i];
10257 ZigType *cur_type = cur_inst->value.type;10284 ZigType *cur_type = cur_inst->value->type;
10258 ZigType *prev_type = prev_inst->value.type;10285 ZigType *prev_type = prev_inst->value->type;
1025910286
10260 if (type_is_invalid(cur_type)) {10287 if (type_is_invalid(cur_type)) {
10261 return cur_type;10288 return cur_type;
...@@ -10559,20 +10586,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10559,20 +10586,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10559 }10586 }
1056010587
10561 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) {10588 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) {
10562 TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal);10589 TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value->data.x_enum_literal);
10563 if (field != nullptr) {10590 if (field != nullptr) {
10564 continue;10591 continue;
10565 }10592 }
10566 }10593 }
10567 if (is_tagged_union(prev_type) && cur_type->id == ZigTypeIdEnumLiteral) {10594 if (is_tagged_union(prev_type) && cur_type->id == ZigTypeIdEnumLiteral) {
10568 TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value.data.x_enum_literal);10595 TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value->data.x_enum_literal);
10569 if (field != nullptr) {10596 if (field != nullptr) {
10570 continue;10597 continue;
10571 }10598 }
10572 }10599 }
1057310600
10574 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) {10601 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) {
10575 TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal);10602 TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value->data.x_enum_literal);
10576 if (field != nullptr) {10603 if (field != nullptr) {
10577 prev_inst = cur_inst;10604 prev_inst = cur_inst;
10578 continue;10605 continue;
...@@ -10580,7 +10607,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10580,7 +10607,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10580 }10607 }
1058110608
10582 if (is_tagged_union(cur_type) && prev_type->id == ZigTypeIdEnumLiteral) {10609 if (is_tagged_union(cur_type) && prev_type->id == ZigTypeIdEnumLiteral) {
10583 TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value.data.x_enum_literal);10610 TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value->data.x_enum_literal);
10584 if (field != nullptr) {10611 if (field != nullptr) {
10585 prev_inst = cur_inst;10612 prev_inst = cur_inst;
10586 continue;10613 continue;
...@@ -10906,9 +10933,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10906,9 +10933,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10906 free(errors);10933 free(errors);
1090710934
10908 if (convert_to_const_slice) {10935 if (convert_to_const_slice) {
10909 if (prev_inst->value.type->id == ZigTypeIdArray) {10936 if (prev_inst->value->type->id == ZigTypeIdArray) {
10910 ZigType *ptr_type = get_pointer_to_type_extra(10937 ZigType *ptr_type = get_pointer_to_type_extra(
10911 ira->codegen, prev_inst->value.type->data.array.child_type,10938 ira->codegen, prev_inst->value->type->data.array.child_type,
10912 true, false, PtrLenUnknown,10939 true, false, PtrLenUnknown,
10913 0, 0, 0, false);10940 0, 0, 0, false);
10914 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);10941 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
...@@ -10917,12 +10944,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10917,12 +10944,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10917 } else {10944 } else {
10918 return slice_type;10945 return slice_type;
10919 }10946 }
10920 } else if (prev_inst->value.type->id == ZigTypeIdPointer) {10947 } else if (prev_inst->value->type->id == ZigTypeIdPointer) {
10921 ZigType *array_type = prev_inst->value.type->data.pointer.child_type;10948 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
10922 src_assert(array_type->id == ZigTypeIdArray, source_node);10949 src_assert(array_type->id == ZigTypeIdArray, source_node);
10923 ZigType *ptr_type = get_pointer_to_type_extra2(10950 ZigType *ptr_type = get_pointer_to_type_extra2(
10924 ira->codegen, array_type->data.array.child_type,10951 ira->codegen, array_type->data.array.child_type,
10925 prev_inst->value.type->data.pointer.is_const, false,10952 prev_inst->value->type->data.pointer.is_const, false,
10926 PtrLenUnknown,10953 PtrLenUnknown,
10927 0, 0, 0, false,10954 0, 0, 0, false,
10928 VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel);10955 VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel);
...@@ -10936,10 +10963,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10936,10 +10963,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10936 zig_unreachable();10963 zig_unreachable();
10937 }10964 }
10938 } else if (err_set_type != nullptr) {10965 } else if (err_set_type != nullptr) {
10939 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {10966 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10940 return err_set_type;10967 return err_set_type;
10941 } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {10968 } else if (prev_inst->value->type->id == ZigTypeIdErrorUnion) {
10942 ZigType *payload_type = prev_inst->value.type->data.error_union.payload_type;10969 ZigType *payload_type = prev_inst->value->type->data.error_union.payload_type;
10943 if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))10970 if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))
10944 return ira->codegen->builtin_types.entry_invalid;10971 return ira->codegen->builtin_types.entry_invalid;
10945 return get_error_union_type(ira->codegen, err_set_type, payload_type);10972 return get_error_union_type(ira->codegen, err_set_type, payload_type);
...@@ -10949,44 +10976,44 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10949,44 +10976,44 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10949 return ira->codegen->builtin_types.entry_invalid;10976 return ira->codegen->builtin_types.entry_invalid;
10950 return get_error_union_type(ira->codegen, err_set_type, payload_type);10977 return get_error_union_type(ira->codegen, err_set_type, payload_type);
10951 } else {10978 } else {
10952 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||10979 if (prev_inst->value->type->id == ZigTypeIdComptimeInt ||
10953 prev_inst->value.type->id == ZigTypeIdComptimeFloat)10980 prev_inst->value->type->id == ZigTypeIdComptimeFloat)
10954 {10981 {
10955 ir_add_error_node(ira, source_node,10982 ir_add_error_node(ira, source_node,
10956 buf_sprintf("unable to make error union out of number literal"));10983 buf_sprintf("unable to make error union out of number literal"));
10957 return ira->codegen->builtin_types.entry_invalid;10984 return ira->codegen->builtin_types.entry_invalid;
10958 } else if (prev_inst->value.type->id == ZigTypeIdNull) {10985 } else if (prev_inst->value->type->id == ZigTypeIdNull) {
10959 ir_add_error_node(ira, source_node,10986 ir_add_error_node(ira, source_node,
10960 buf_sprintf("unable to make error union out of null literal"));10987 buf_sprintf("unable to make error union out of null literal"));
10961 return ira->codegen->builtin_types.entry_invalid;10988 return ira->codegen->builtin_types.entry_invalid;
10962 } else {10989 } else {
10963 if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown)))10990 if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown)))
10964 return ira->codegen->builtin_types.entry_invalid;10991 return ira->codegen->builtin_types.entry_invalid;
10965 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);10992 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value->type);
10966 }10993 }
10967 }10994 }
10968 } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {10995 } else if (any_are_null && prev_inst->value->type->id != ZigTypeIdNull) {
10969 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||10996 if (prev_inst->value->type->id == ZigTypeIdComptimeInt ||
10970 prev_inst->value.type->id == ZigTypeIdComptimeFloat)10997 prev_inst->value->type->id == ZigTypeIdComptimeFloat)
10971 {10998 {
10972 ir_add_error_node(ira, source_node,10999 ir_add_error_node(ira, source_node,
10973 buf_sprintf("unable to make maybe out of number literal"));11000 buf_sprintf("unable to make maybe out of number literal"));
10974 return ira->codegen->builtin_types.entry_invalid;11001 return ira->codegen->builtin_types.entry_invalid;
10975 } else if (prev_inst->value.type->id == ZigTypeIdOptional) {11002 } else if (prev_inst->value->type->id == ZigTypeIdOptional) {
10976 return prev_inst->value.type;11003 return prev_inst->value->type;
10977 } else {11004 } else {
10978 if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown)))11005 if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown)))
10979 return ira->codegen->builtin_types.entry_invalid;11006 return ira->codegen->builtin_types.entry_invalid;
10980 return get_optional_type(ira->codegen, prev_inst->value.type);11007 return get_optional_type(ira->codegen, prev_inst->value->type);
10981 }11008 }
10982 } else {11009 } else {
10983 return prev_inst->value.type;11010 return prev_inst->value->type;
10984 }11011 }
10985}11012}
1098611013
10987static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {11014static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) {
10988 ConstGlobalRefs *global_refs = dest->global_refs;11015 ConstGlobalRefs *global_refs = dest->global_refs;
10989 memcpy(dest, src, sizeof(ConstExprValue));11016 memcpy(dest, src, sizeof(ZigValue));
10990 if (!same_global_refs) {11017 if (!same_global_refs) {
10991 dest->global_refs = global_refs;11018 dest->global_refs = global_refs;
10992 if (src->special != ConstValSpecialStatic)11019 if (src->special != ConstValSpecialStatic)
...@@ -11002,8 +11029,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -11002,8 +11029,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
1100211029
11003static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,11030static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
11004 CastOp cast_op,11031 CastOp cast_op,
11005 ConstExprValue *other_val, ZigType *other_type,11032 ZigValue *other_val, ZigType *other_type,
11006 ConstExprValue *const_val, ZigType *new_type)11033 ZigValue *const_val, ZigType *new_type)
11007{11034{
11008 const_val->special = other_val->special;11035 const_val->special = other_val->special;
1100911036
...@@ -11106,25 +11133,31 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z...@@ -11106,25 +11133,31 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z
11106 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,11133 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11107 old_instruction->scope, old_instruction->source_node);11134 old_instruction->scope, old_instruction->source_node);
11108 IrInstruction *new_instruction = &const_instruction->base;11135 IrInstruction *new_instruction = &const_instruction->base;
11109 new_instruction->value.type = ty;11136 new_instruction->value->type = ty;
11110 new_instruction->value.special = ConstValSpecialStatic;11137 new_instruction->value->special = ConstValSpecialStatic;
11111 return new_instruction;11138 return new_instruction;
11112}11139}
1111311140
11141static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) {
11142 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb,
11143 old_instruction->scope, old_instruction->source_node);
11144 return &const_instruction->base;
11145}
11146
11114static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,11147static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
11115 ZigType *wanted_type, CastOp cast_op)11148 ZigType *wanted_type, CastOp cast_op)
11116{11149{
11117 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {11150 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
11118 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11151 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11119 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, &value->value, value->value.type,11152 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
11120 &result->value, wanted_type))11153 result->value, wanted_type))
11121 {11154 {
11122 return ira->codegen->invalid_instruction;11155 return ira->codegen->invalid_instruction;
11123 }11156 }
11124 return result;11157 return result;
11125 } else {11158 } else {
11126 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);11159 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
11127 result->value.type = wanted_type;11160 result->value->type = wanted_type;
11128 return result;11161 return result;
11129 }11162 }
11130}11163}
...@@ -11132,35 +11165,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -11132,35 +11165,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
11132static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,11165static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
11133 IrInstruction *value, ZigType *wanted_type)11166 IrInstruction *value, ZigType *wanted_type)
11134{11167{
11135 assert(value->value.type->id == ZigTypeIdPointer);11168 assert(value->value->type->id == ZigTypeIdPointer);
1113611169
11137 Error err;11170 Error err;
1113811171
11139 if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type,11172 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,
11140 ResolveStatusAlignmentKnown)))11173 ResolveStatusAlignmentKnown)))
11141 {11174 {
11142 return ira->codegen->invalid_instruction;11175 return ira->codegen->invalid_instruction;
11143 }11176 }
1114411177
11145 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));11178 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
1114611179
11147 if (instr_is_comptime(value)) {11180 if (instr_is_comptime(value)) {
11148 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);11181 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
11149 if (pointee == nullptr)11182 if (pointee == nullptr)
11150 return ira->codegen->invalid_instruction;11183 return ira->codegen->invalid_instruction;
11151 if (pointee->special != ConstValSpecialRuntime) {11184 if (pointee->special != ConstValSpecialRuntime) {
11152 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11185 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11153 result->value.data.x_ptr.special = ConstPtrSpecialBaseArray;11186 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
11154 result->value.data.x_ptr.mut = value->value.data.x_ptr.mut;11187 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
11155 result->value.data.x_ptr.data.base_array.array_val = pointee;11188 result->value->data.x_ptr.data.base_array.array_val = pointee;
11156 result->value.data.x_ptr.data.base_array.elem_index = 0;11189 result->value->data.x_ptr.data.base_array.elem_index = 0;
11157 return result;11190 return result;
11158 }11191 }
11159 }11192 }
1116011193
11161 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,11194 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
11162 wanted_type, value, CastOpBitCast);11195 wanted_type, value, CastOpBitCast);
11163 result->value.type = wanted_type;11196 result->value->type = wanted_type;
11164 return result;11197 return result;
11165}11198}
1116611199
...@@ -11169,28 +11202,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -11169,28 +11202,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11169{11202{
11170 Error err;11203 Error err;
1117111204
11172 if ((err = type_resolve(ira->codegen, array_ptr->value.type->data.pointer.child_type,11205 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,
11173 ResolveStatusAlignmentKnown)))11206 ResolveStatusAlignmentKnown)))
11174 {11207 {
11175 return ira->codegen->invalid_instruction;11208 return ira->codegen->invalid_instruction;
11176 }11209 }
1117711210
11178 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type));11211 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));
1117911212
11180 if (instr_is_comptime(array_ptr)) {11213 if (instr_is_comptime(array_ptr)) {
11181 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node);11214 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);
11182 if (pointee == nullptr)11215 if (pointee == nullptr)
11183 return ira->codegen->invalid_instruction;11216 return ira->codegen->invalid_instruction;
11184 if (pointee->special != ConstValSpecialRuntime) {11217 if (pointee->special != ConstValSpecialRuntime) {
11185 assert(array_ptr->value.type->id == ZigTypeIdPointer);11218 assert(array_ptr->value->type->id == ZigTypeIdPointer);
11186 ZigType *array_type = array_ptr->value.type->data.pointer.child_type;11219 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;
11187 assert(is_slice(wanted_type));11220 assert(is_slice(wanted_type));
11188 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;11221 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1118911222
11190 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11223 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11191 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);11224 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
11192 result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value.data.x_ptr.mut;11225 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;
11193 result->value.type = wanted_type;11226 result->value->type = wanted_type;
11194 return result;11227 return result;
11195 }11228 }
11196 }11229 }
...@@ -11198,7 +11231,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -11198,7 +11231,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11198 if (result_loc == nullptr) result_loc = no_result_loc();11231 if (result_loc == nullptr) result_loc = no_result_loc();
11199 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,11232 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
11200 false, true);11233 false, true);
11201 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {11234 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
11202 return result_loc_inst;11235 return result_loc_inst;
11203 }11236 }
11204 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);11237 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
...@@ -11403,53 +11436,61 @@ static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruc...@@ -11403,53 +11436,61 @@ static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruc
11403}11436}
1140411437
11405static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {11438static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {
11406 if (instruction->value.type->id == ZigTypeIdUnreachable)11439 if (instruction->value->type->id == ZigTypeIdUnreachable)
11407 ir_finish_bb(ira);11440 ir_finish_bb(ira);
11408 return instruction;11441 return instruction;
11409}11442}
1141011443
11411static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {11444static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11412 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);11445 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
11413 result->value.data.x_type = ty;11446 result->value->data.x_type = ty;
11414 return result;11447 return result;
11415}11448}
1141611449
11417static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {11450static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {
11418 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);11451 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
11419 result->value.data.x_bool = value;11452 result->value->data.x_bool = value;
11420 return result;11453 return result;
11421}11454}
1142211455
11423static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {11456static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11424 IrInstruction *result = ir_const(ira, source_instruction, ty);11457 IrInstruction *result = ir_const(ira, source_instruction, ty);
11425 result->value.special = ConstValSpecialUndef;11458 result->value->special = ConstValSpecialUndef;
11426 return result;11459 return result;
11427}11460}
1142811461
11429static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {11462static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {
11430 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable);11463#ifdef ZIG_ENABLE_MEM_PROFILE
11431 result->value.special = ConstValSpecialStatic;11464 memprof_intern_count.x_unreachable += 1;
11465#endif
11466 IrInstruction *result = ir_const_noval(ira, source_instruction);
11467 result->value = &ira->codegen->intern_values.x_unreachable;
11432 return result;11468 return result;
11433}11469}
1143411470
11435static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {11471static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {
11436 return ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_void);11472#ifdef ZIG_ENABLE_MEM_PROFILE
11473 memprof_intern_count.x_void += 1;
11474#endif
11475 IrInstruction *result = ir_const_noval(ira, source_instruction);
11476 result->value = &ira->codegen->intern_values.x_void;
11477 return result;
11437}11478}
1143811479
11439static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {11480static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {
11440 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);11481 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
11441 bigint_init_unsigned(&result->value.data.x_bigint, value);11482 bigint_init_unsigned(&result->value->data.x_bigint, value);
11442 return result;11483 return result;
11443}11484}
1144411485
11445static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,11486static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
11446 ConstExprValue *pointee, ZigType *pointee_type,11487 ZigValue *pointee, ZigType *pointee_type,
11447 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)11488 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
11448{11489{
11449 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,11490 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
11450 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);11491 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
11451 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);11492 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);
11452 ConstExprValue *const_val = &const_instr->value;11493 ZigValue *const_val = const_instr->value;
11453 const_val->data.x_ptr.special = ConstPtrSpecialRef;11494 const_val->data.x_ptr.special = ConstPtrSpecialRef;
11454 const_val->data.x_ptr.mut = ptr_mut;11495 const_val->data.x_ptr.mut = ptr_mut;
11455 const_val->data.x_ptr.data.ref.pointee = pointee;11496 const_val->data.x_ptr.data.ref.pointee = pointee;
...@@ -11457,7 +11498,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -11457,7 +11498,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
11457}11498}
1145811499
11459static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,11500static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11460 ConstExprValue *val, UndefAllowed undef_allowed)11501 ZigValue *val, UndefAllowed undef_allowed)
11461{11502{
11462 Error err;11503 Error err;
11463 for (;;) {11504 for (;;) {
...@@ -11490,17 +11531,17 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -11490,17 +11531,17 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
11490 }11531 }
11491}11532}
1149211533
11493static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {11534static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
11494 Error err;11535 Error err;
11495 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,11536 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
11496 &value->value, undef_allowed)))11537 value->value, undef_allowed)))
11497 {11538 {
11498 return nullptr;11539 return nullptr;
11499 }11540 }
11500 return &value->value;11541 return value->value;
11501}11542}
1150211543
11503ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,11544ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
11504 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,11545 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
11505 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,11546 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
11506 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)11547 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
...@@ -11508,7 +11549,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -11508,7 +11549,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
11508 Error err;11549 Error err;
1150911550
11510 if (expected_type != nullptr && type_is_invalid(expected_type))11551 if (expected_type != nullptr && type_is_invalid(expected_type))
11511 return &codegen->invalid_instruction->value;11552 return codegen->invalid_instruction->value;
1151211553
11513 IrExecutable *ir_executable = allocate<IrExecutable>(1);11554 IrExecutable *ir_executable = allocate<IrExecutable>(1);
11514 ir_executable->source_node = source_node;11555 ir_executable->source_node = source_node;
...@@ -11522,7 +11563,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -11522,7 +11563,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1152211563
11523 if (ir_executable->first_err_trace_msg != nullptr) {11564 if (ir_executable->first_err_trace_msg != nullptr) {
11524 codegen->trace_err = ir_executable->first_err_trace_msg;11565 codegen->trace_err = ir_executable->first_err_trace_msg;
11525 return &codegen->invalid_instruction->value;11566 return codegen->invalid_instruction->value;
11526 }11567 }
1152711568
11528 if (codegen->verbose_ir) {11569 if (codegen->verbose_ir) {
...@@ -11545,7 +11586,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -11545,7 +11586,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
11545 analyzed_executable->begin_scope = scope;11586 analyzed_executable->begin_scope = scope;
11546 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);11587 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);
11547 if (type_is_invalid(result_type)) {11588 if (type_is_invalid(result_type)) {
11548 return &codegen->invalid_instruction->value;11589 return codegen->invalid_instruction->value;
11549 }11590 }
1155011591
11551 if (codegen->verbose_ir) {11592 if (codegen->verbose_ir) {
...@@ -11554,27 +11595,27 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -11554,27 +11595,27 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
11554 fprintf(stderr, "}\n");11595 fprintf(stderr, "}\n");
11555 }11596 }
1155611597
11557 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);11598 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
11558 if (type_is_invalid(result->type))11599 if (type_is_invalid(result->type))
11559 return &codegen->invalid_instruction->value;11600 return codegen->invalid_instruction->value;
1156011601
11561 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))11602 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
11562 return &codegen->invalid_instruction->value;11603 return codegen->invalid_instruction->value;
1156311604
11564 return result;11605 return result;
11565}11606}
1156611607
11567static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {11608static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {
11568 if (type_is_invalid(err_value->value.type))11609 if (type_is_invalid(err_value->value->type))
11569 return nullptr;11610 return nullptr;
1157011611
11571 if (err_value->value.type->id != ZigTypeIdErrorSet) {11612 if (err_value->value->type->id != ZigTypeIdErrorSet) {
11572 ir_add_error(ira, err_value,11613 ir_add_error(ira, err_value,
11573 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value.type->name)));11614 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
11574 return nullptr;11615 return nullptr;
11575 }11616 }
1157611617
11577 ConstExprValue *const_val = ir_resolve_const(ira, err_value, UndefBad);11618 ZigValue *const_val = ir_resolve_const(ira, err_value, UndefBad);
11578 if (!const_val)11619 if (!const_val)
11579 return nullptr;11620 return nullptr;
1158011621
...@@ -11583,7 +11624,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu...@@ -11583,7 +11624,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
11583}11624}
1158411625
11585static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,11626static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11586 ConstExprValue *val)11627 ZigValue *val)
11587{11628{
11588 Error err;11629 Error err;
11589 if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad)))11630 if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad)))
...@@ -11593,28 +11634,28 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN...@@ -11593,28 +11634,28 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
11593 return val->data.x_type;11634 return val->data.x_type;
11594}11635}
1159511636
11596static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {11637static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
11597 if (type_is_invalid(type_value->value.type))11638 if (type_is_invalid(type_value->value->type))
11598 return nullptr;11639 return nullptr;
1159911640
11600 if (type_value->value.type->id != ZigTypeIdMetaType) {11641 if (type_value->value->type->id != ZigTypeIdMetaType) {
11601 ir_add_error(ira, type_value,11642 ir_add_error(ira, type_value,
11602 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));11643 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
11603 return nullptr;11644 return nullptr;
11604 }11645 }
1160511646
11606 Error err;11647 Error err;
11607 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,11648 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,
11608 &type_value->value, LazyOk)))11649 type_value->value, LazyOk)))
11609 {11650 {
11610 return nullptr;11651 return nullptr;
11611 }11652 }
1161211653
11613 return &type_value->value;11654 return type_value->value;
11614}11655}
1161511656
11616static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {11657static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
11617 ConstExprValue *val = ir_resolve_type_lazy(ira, type_value);11658 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
11618 if (val == nullptr)11659 if (val == nullptr)
11619 return ira->codegen->builtin_types.entry_invalid;11660 return ira->codegen->builtin_types.entry_invalid;
1162011661
...@@ -11663,18 +11704,18 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -11663,18 +11704,18 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
11663}11704}
1166411705
11665static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) {11706static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) {
11666 if (type_is_invalid(type_value->value.type))11707 if (type_is_invalid(type_value->value->type))
11667 return ira->codegen->builtin_types.entry_invalid;11708 return ira->codegen->builtin_types.entry_invalid;
1166811709
11669 if (type_value->value.type->id != ZigTypeIdMetaType) {11710 if (type_value->value->type->id != ZigTypeIdMetaType) {
11670 ErrorMsg *msg = ir_add_error(ira, type_value,11711 ErrorMsg *msg = ir_add_error(ira, type_value,
11671 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value.type->name)));11712 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
11672 add_error_note(ira->codegen, msg, op_source->source_node,11713 add_error_note(ira->codegen, msg, op_source->source_node,
11673 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));11714 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
11674 return ira->codegen->builtin_types.entry_invalid;11715 return ira->codegen->builtin_types.entry_invalid;
11675 }11716 }
1167611717
11677 ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad);11718 ZigValue *const_val = ir_resolve_const(ira, type_value, UndefBad);
11678 if (!const_val)11719 if (!const_val)
11679 return ira->codegen->builtin_types.entry_invalid;11720 return ira->codegen->builtin_types.entry_invalid;
1168011721
...@@ -11694,16 +11735,16 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -11694,16 +11735,16 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
11694 if (fn_value == ira->codegen->invalid_instruction)11735 if (fn_value == ira->codegen->invalid_instruction)
11695 return nullptr;11736 return nullptr;
1169611737
11697 if (type_is_invalid(fn_value->value.type))11738 if (type_is_invalid(fn_value->value->type))
11698 return nullptr;11739 return nullptr;
1169911740
11700 if (fn_value->value.type->id != ZigTypeIdFn) {11741 if (fn_value->value->type->id != ZigTypeIdFn) {
11701 ir_add_error_node(ira, fn_value->source_node,11742 ir_add_error_node(ira, fn_value->source_node,
11702 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));11743 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
11703 return nullptr;11744 return nullptr;
11704 }11745 }
1170511746
11706 ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);11747 ZigValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);
11707 if (!const_val)11748 if (!const_val)
11708 return nullptr;11749 return nullptr;
1170911750
...@@ -11722,22 +11763,22 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -11722,22 +11763,22 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
11722 if (instr_is_comptime(value)) {11763 if (instr_is_comptime(value)) {
11723 ZigType *payload_type = wanted_type->data.maybe.child_type;11764 ZigType *payload_type = wanted_type->data.maybe.child_type;
11724 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);11765 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
11725 if (type_is_invalid(casted_payload->value.type))11766 if (type_is_invalid(casted_payload->value->type))
11726 return ira->codegen->invalid_instruction;11767 return ira->codegen->invalid_instruction;
1172711768
11728 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk);11769 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
11729 if (!val)11770 if (!val)
11730 return ira->codegen->invalid_instruction;11771 return ira->codegen->invalid_instruction;
1173111772
11732 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,11773 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11733 source_instr->scope, source_instr->source_node);11774 source_instr->scope, source_instr->source_node);
11734 const_instruction->base.value.special = ConstValSpecialStatic;11775 const_instruction->base.value->special = ConstValSpecialStatic;
11735 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {11776 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
11736 copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);11777 copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);
11737 } else {11778 } else {
11738 const_instruction->base.value.data.x_optional = val;11779 const_instruction->base.value->data.x_optional = val;
11739 }11780 }
11740 const_instruction->base.value.type = wanted_type;11781 const_instruction->base.value->type = wanted_type;
11741 return &const_instruction->base;11782 return &const_instruction->base;
11742 }11783 }
1174311784
...@@ -11747,12 +11788,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -11747,12 +11788,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
11747 IrInstruction *result_loc_inst = nullptr;11788 IrInstruction *result_loc_inst = nullptr;
11748 if (result_loc != nullptr) {11789 if (result_loc != nullptr) {
11749 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);11790 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
11750 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {11791 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
11751 return result_loc_inst;11792 return result_loc_inst;
11752 }11793 }
11753 }11794 }
11754 IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);11795 IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
11755 result->value.data.rh_maybe = RuntimeHintOptionalNonNull;11796 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
11756 return result;11797 return result;
11757}11798}
1175811799
...@@ -11765,24 +11806,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -11765,24 +11806,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
11765 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;11806 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
11766 if (instr_is_comptime(value)) {11807 if (instr_is_comptime(value)) {
11767 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);11808 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
11768 if (type_is_invalid(casted_payload->value.type))11809 if (type_is_invalid(casted_payload->value->type))
11769 return ira->codegen->invalid_instruction;11810 return ira->codegen->invalid_instruction;
1177011811
11771 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);11812 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
11772 if (!val)11813 if (!val)
11773 return ira->codegen->invalid_instruction;11814 return ira->codegen->invalid_instruction;
1177411815
11775 ConstExprValue *err_set_val = create_const_vals(1);11816 ZigValue *err_set_val = create_const_vals(1);
11776 err_set_val->type = err_set_type;11817 err_set_val->type = err_set_type;
11777 err_set_val->special = ConstValSpecialStatic;11818 err_set_val->special = ConstValSpecialStatic;
11778 err_set_val->data.x_err_set = nullptr;11819 err_set_val->data.x_err_set = nullptr;
1177911820
11780 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,11821 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11781 source_instr->scope, source_instr->source_node);11822 source_instr->scope, source_instr->source_node);
11782 const_instruction->base.value.type = wanted_type;11823 const_instruction->base.value->type = wanted_type;
11783 const_instruction->base.value.special = ConstValSpecialStatic;11824 const_instruction->base.value->special = ConstValSpecialStatic;
11784 const_instruction->base.value.data.x_err_union.error_set = err_set_val;11825 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
11785 const_instruction->base.value.data.x_err_union.payload = val;11826 const_instruction->base.value->data.x_err_union.payload = val;
11786 return &const_instruction->base;11827 return &const_instruction->base;
11787 }11828 }
1178811829
...@@ -11790,7 +11831,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -11790,7 +11831,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
11790 if (handle_is_ptr(wanted_type)) {11831 if (handle_is_ptr(wanted_type)) {
11791 if (result_loc == nullptr) result_loc = no_result_loc();11832 if (result_loc == nullptr) result_loc = no_result_loc();
11792 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);11833 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
11793 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {11834 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
11794 return result_loc_inst;11835 return result_loc_inst;
11795 }11836 }
11796 } else {11837 } else {
...@@ -11798,18 +11839,18 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -11798,18 +11839,18 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
11798 }11839 }
1179911840
11800 IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);11841 IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
11801 result->value.data.rh_error_union = RuntimeHintErrorUnionNonError;11842 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
11802 return result;11843 return result;
11803}11844}
1180411845
11805static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,11846static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
11806 ZigType *wanted_type)11847 ZigType *wanted_type)
11807{11848{
11808 assert(value->value.type->id == ZigTypeIdErrorSet);11849 assert(value->value->type->id == ZigTypeIdErrorSet);
11809 assert(wanted_type->id == ZigTypeIdErrorSet);11850 assert(wanted_type->id == ZigTypeIdErrorSet);
1181011851
11811 if (instr_is_comptime(value)) {11852 if (instr_is_comptime(value)) {
11812 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11853 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11813 if (!val)11854 if (!val)
11814 return ira->codegen->invalid_instruction;11855 return ira->codegen->invalid_instruction;
1181511856
...@@ -11834,14 +11875,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -11834,14 +11875,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1183411875
11835 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,11876 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11836 source_instr->scope, source_instr->source_node);11877 source_instr->scope, source_instr->source_node);
11837 const_instruction->base.value.type = wanted_type;11878 const_instruction->base.value->type = wanted_type;
11838 const_instruction->base.value.special = ConstValSpecialStatic;11879 const_instruction->base.value->special = ConstValSpecialStatic;
11839 const_instruction->base.value.data.x_err_set = val->data.x_err_set;11880 const_instruction->base.value->data.x_err_set = val->data.x_err_set;
11840 return &const_instruction->base;11881 return &const_instruction->base;
11841 }11882 }
1184211883
11843 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);11884 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);
11844 result->value.type = wanted_type;11885 result->value->type = wanted_type;
11845 return result;11886 return result;
11846}11887}
1184711888
...@@ -11849,7 +11890,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc...@@ -11849,7 +11890,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
11849 IrInstruction *frame_ptr, ZigType *wanted_type)11890 IrInstruction *frame_ptr, ZigType *wanted_type)
11850{11891{
11851 if (instr_is_comptime(frame_ptr)) {11892 if (instr_is_comptime(frame_ptr)) {
11852 ConstExprValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);11893 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
11853 if (ptr_val == nullptr)11894 if (ptr_val == nullptr)
11854 return ira->codegen->invalid_instruction;11895 return ira->codegen->invalid_instruction;
1185511896
...@@ -11861,7 +11902,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc...@@ -11861,7 +11902,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
1186111902
11862 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,11903 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
11863 wanted_type, frame_ptr, CastOpBitCast);11904 wanted_type, frame_ptr, CastOpBitCast);
11864 result->value.type = wanted_type;11905 result->value->type = wanted_type;
11865 return result;11906 return result;
11866}11907}
1186711908
...@@ -11874,7 +11915,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct...@@ -11874,7 +11915,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct
1187411915
11875 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,11916 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
11876 wanted_type, value, CastOpBitCast);11917 wanted_type, value, CastOpBitCast);
11877 result->value.type = wanted_type;11918 result->value->type = wanted_type;
11878 return result;11919 return result;
11879}11920}
1188011921
...@@ -11887,21 +11928,21 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -11887,21 +11928,21 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
11887 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);11928 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1188811929
11889 if (instr_is_comptime(casted_value)) {11930 if (instr_is_comptime(casted_value)) {
11890 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);11931 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
11891 if (!val)11932 if (!val)
11892 return ira->codegen->invalid_instruction;11933 return ira->codegen->invalid_instruction;
1189311934
11894 ConstExprValue *err_set_val = create_const_vals(1);11935 ZigValue *err_set_val = create_const_vals(1);
11895 err_set_val->special = ConstValSpecialStatic;11936 err_set_val->special = ConstValSpecialStatic;
11896 err_set_val->type = wanted_type->data.error_union.err_set_type;11937 err_set_val->type = wanted_type->data.error_union.err_set_type;
11897 err_set_val->data.x_err_set = val->data.x_err_set;11938 err_set_val->data.x_err_set = val->data.x_err_set;
1189811939
11899 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,11940 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11900 source_instr->scope, source_instr->source_node);11941 source_instr->scope, source_instr->source_node);
11901 const_instruction->base.value.type = wanted_type;11942 const_instruction->base.value->type = wanted_type;
11902 const_instruction->base.value.special = ConstValSpecialStatic;11943 const_instruction->base.value->special = ConstValSpecialStatic;
11903 const_instruction->base.value.data.x_err_union.error_set = err_set_val;11944 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
11904 const_instruction->base.value.data.x_err_union.payload = nullptr;11945 const_instruction->base.value->data.x_err_union.payload = nullptr;
11905 return &const_instruction->base;11946 return &const_instruction->base;
11906 }11947 }
1190711948
...@@ -11909,7 +11950,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -11909,7 +11950,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
11909 if (handle_is_ptr(wanted_type)) {11950 if (handle_is_ptr(wanted_type)) {
11910 if (result_loc == nullptr) result_loc = no_result_loc();11951 if (result_loc == nullptr) result_loc = no_result_loc();
11911 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);11952 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
11912 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {11953 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
11913 return result_loc_inst;11954 return result_loc_inst;
11914 }11955 }
11915 } else {11956 } else {
...@@ -11918,7 +11959,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -11918,7 +11959,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1191811959
1191911960
11920 IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);11961 IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
11921 result->value.data.rh_error_union = RuntimeHintErrorUnionError;11962 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
11922 return result;11963 return result;
11923}11964}
1192411965
...@@ -11926,17 +11967,17 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -11926,17 +11967,17 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
11926 assert(wanted_type->id == ZigTypeIdOptional);11967 assert(wanted_type->id == ZigTypeIdOptional);
11927 assert(instr_is_comptime(value));11968 assert(instr_is_comptime(value));
1192811969
11929 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11970 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11930 assert(val != nullptr);11971 assert(val != nullptr);
1193111972
11932 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11973 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11933 result->value.special = ConstValSpecialStatic;11974 result->value->special = ConstValSpecialStatic;
11934 if (get_codegen_ptr_type(wanted_type) != nullptr) {11975 if (get_codegen_ptr_type(wanted_type) != nullptr) {
11935 result->value.data.x_ptr.special = ConstPtrSpecialNull;11976 result->value->data.x_ptr.special = ConstPtrSpecialNull;
11936 } else if (is_opt_err_set(wanted_type)) {11977 } else if (is_opt_err_set(wanted_type)) {
11937 result->value.data.x_err_set = nullptr;11978 result->value->data.x_err_set = nullptr;
11938 } else {11979 } else {
11939 result->value.data.x_optional = nullptr;11980 result->value->data.x_optional = nullptr;
11940 }11981 }
11941 return result;11982 return result;
11942}11983}
...@@ -11948,12 +11989,12 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction...@@ -11948,12 +11989,12 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
11948 assert(wanted_type->data.pointer.ptr_len == PtrLenC);11989 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
11949 assert(instr_is_comptime(value));11990 assert(instr_is_comptime(value));
1195011991
11951 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11992 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11952 assert(val != nullptr);11993 assert(val != nullptr);
1195311994
11954 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11995 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11955 result->value.data.x_ptr.special = ConstPtrSpecialNull;11996 result->value->data.x_ptr.special = ConstPtrSpecialNull;
11956 result->value.data.x_ptr.mut = ConstPtrMutComptimeConst;11997 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
11957 return result;11998 return result;
11958}11999}
1195912000
...@@ -11962,36 +12003,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -11962,36 +12003,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
11962{12003{
11963 Error err;12004 Error err;
1196412005
11965 if (type_is_invalid(value->value.type))12006 if (type_is_invalid(value->value->type))
11966 return ira->codegen->invalid_instruction;12007 return ira->codegen->invalid_instruction;
1196712008
11968 if ((err = type_resolve(ira->codegen, value->value.type, ResolveStatusZeroBitsKnown)))12009 if ((err = type_resolve(ira->codegen, value->value->type, ResolveStatusZeroBitsKnown)))
11969 return ira->codegen->invalid_instruction;12010 return ira->codegen->invalid_instruction;
1197012011
11971 if (instr_is_comptime(value)) {12012 if (instr_is_comptime(value)) {
11972 ConstExprValue *val = ir_resolve_const(ira, value, LazyOk);12013 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
11973 if (!val)12014 if (!val)
11974 return ira->codegen->invalid_instruction;12015 return ira->codegen->invalid_instruction;
11975 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,12016 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,
11976 ConstPtrMutComptimeConst, is_const, is_volatile, 0);12017 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
11977 }12018 }
1197812019
11979 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,12020 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type,
11980 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);12021 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1198112022
11982 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))12023 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))
11983 return ira->codegen->invalid_instruction;12024 return ira->codegen->invalid_instruction;
1198412025
11985 IrInstruction *result_loc;12026 IrInstruction *result_loc;
11986 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) {12027 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {
11987 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true,12028 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,
11988 false, true);12029 false, true);
11989 } else {12030 } else {
11990 result_loc = nullptr;12031 result_loc = nullptr;
11991 }12032 }
1199212033
11993 IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);12034 IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
11994 new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;12035 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
11995 return new_instruction;12036 return new_instruction;
11996}12037}
1199712038
...@@ -12004,39 +12045,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s...@@ -12004,39 +12045,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1200412045
12005 IrInstruction *array_ptr = nullptr;12046 IrInstruction *array_ptr = nullptr;
12006 IrInstruction *array;12047 IrInstruction *array;
12007 if (array_arg->value.type->id == ZigTypeIdPointer) {12048 if (array_arg->value->type->id == ZigTypeIdPointer) {
12008 array = ir_get_deref(ira, source_instr, array_arg, nullptr);12049 array = ir_get_deref(ira, source_instr, array_arg, nullptr);
12009 array_ptr = array_arg;12050 array_ptr = array_arg;
12010 } else {12051 } else {
12011 array = array_arg;12052 array = array_arg;
12012 }12053 }
12013 ZigType *array_type = array->value.type;12054 ZigType *array_type = array->value->type;
12014 assert(array_type->id == ZigTypeIdArray);12055 assert(array_type->id == ZigTypeIdArray);
1201512056
12016 if (instr_is_comptime(array) || array_type->data.array.len == 0) {12057 if (instr_is_comptime(array) || array_type->data.array.len == 0) {
12017 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12058 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12018 init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true);12059 init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true);
12019 result->value.type = wanted_type;12060 result->value->type = wanted_type;
12020 return result;12061 return result;
12021 }12062 }
1202212063
12023 IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);12064 IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12024 init_const_usize(ira->codegen, &start->value, 0);12065 init_const_usize(ira->codegen, start->value, 0);
1202512066
12026 IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);12067 IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12027 init_const_usize(ira->codegen, &end->value, array_type->data.array.len);12068 init_const_usize(ira->codegen, end->value, array_type->data.array.len);
1202812069
12029 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);12070 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
1203012071
12031 if (result_loc == nullptr) result_loc = no_result_loc();12072 if (result_loc == nullptr) result_loc = no_result_loc();
12032 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,12073 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,
12033 true, false, true);12074 true, false, true);
12034 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {12075 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12035 return result_loc_inst;12076 return result_loc_inst;
12036 }12077 }
12037 IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst);12078 IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst);
12038 result->value.data.rh_slice.id = RuntimeHintSliceIdLen;12079 result->value->data.rh_slice.id = RuntimeHintSliceIdLen;
12039 result->value.data.rh_slice.len = array_type->data.array.len;12080 result->value->data.rh_slice.len = array_type->data.array.len;
1204012081
12041 return result;12082 return result;
12042}12083}
...@@ -12065,19 +12106,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12065,19 +12106,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1206512106
12066 IrInstruction *enum_target;12107 IrInstruction *enum_target;
12067 ZigType *enum_type;12108 ZigType *enum_type;
12068 if (target->value.type->id == ZigTypeIdUnion) {12109 if (target->value->type->id == ZigTypeIdUnion) {
12069 enum_type = ir_resolve_union_tag_type(ira, target, target->value.type);12110 enum_type = ir_resolve_union_tag_type(ira, target, target->value->type);
12070 if (type_is_invalid(enum_type))12111 if (type_is_invalid(enum_type))
12071 return ira->codegen->invalid_instruction;12112 return ira->codegen->invalid_instruction;
12072 enum_target = ir_implicit_cast(ira, target, enum_type);12113 enum_target = ir_implicit_cast(ira, target, enum_type);
12073 if (type_is_invalid(enum_target->value.type))12114 if (type_is_invalid(enum_target->value->type))
12074 return ira->codegen->invalid_instruction;12115 return ira->codegen->invalid_instruction;
12075 } else if (target->value.type->id == ZigTypeIdEnum) {12116 } else if (target->value->type->id == ZigTypeIdEnum) {
12076 enum_target = target;12117 enum_target = target;
12077 enum_type = target->value.type;12118 enum_type = target->value->type;
12078 } else {12119 } else {
12079 ir_add_error(ira, target,12120 ir_add_error(ira, target,
12080 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));12121 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
12081 return ira->codegen->invalid_instruction;12122 return ira->codegen->invalid_instruction;
12082 }12123 }
1208312124
...@@ -12092,41 +12133,41 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12092,41 +12133,41 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12092 enum_type->data.enumeration.src_field_count == 1)12133 enum_type->data.enumeration.src_field_count == 1)
12093 {12134 {
12094 IrInstruction *result = ir_const(ira, source_instr, tag_type);12135 IrInstruction *result = ir_const(ira, source_instr, tag_type);
12095 init_const_bigint(&result->value, tag_type,12136 init_const_bigint(result->value, tag_type,
12096 &enum_type->data.enumeration.fields[0].value);12137 &enum_type->data.enumeration.fields[0].value);
12097 return result;12138 return result;
12098 }12139 }
1209912140
12100 if (instr_is_comptime(enum_target)) {12141 if (instr_is_comptime(enum_target)) {
12101 ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad);12142 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
12102 if (!val)12143 if (!val)
12103 return ira->codegen->invalid_instruction;12144 return ira->codegen->invalid_instruction;
12104 IrInstruction *result = ir_const(ira, source_instr, tag_type);12145 IrInstruction *result = ir_const(ira, source_instr, tag_type);
12105 init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag);12146 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
12106 return result;12147 return result;
12107 }12148 }
1210812149
12109 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,12150 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12110 source_instr->source_node, enum_target);12151 source_instr->source_node, enum_target);
12111 result->value.type = tag_type;12152 result->value->type = tag_type;
12112 return result;12153 return result;
12113}12154}
1211412155
12115static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,12156static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
12116 IrInstruction *target, ZigType *wanted_type)12157 IrInstruction *target, ZigType *wanted_type)
12117{12158{
12118 assert(target->value.type->id == ZigTypeIdUnion);12159 assert(target->value->type->id == ZigTypeIdUnion);
12119 assert(wanted_type->id == ZigTypeIdEnum);12160 assert(wanted_type->id == ZigTypeIdEnum);
12120 assert(wanted_type == target->value.type->data.unionation.tag_type);12161 assert(wanted_type == target->value->type->data.unionation.tag_type);
1212112162
12122 if (instr_is_comptime(target)) {12163 if (instr_is_comptime(target)) {
12123 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12164 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12124 if (!val)12165 if (!val)
12125 return ira->codegen->invalid_instruction;12166 return ira->codegen->invalid_instruction;
12126 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12167 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12127 result->value.special = ConstValSpecialStatic;12168 result->value->special = ConstValSpecialStatic;
12128 result->value.type = wanted_type;12169 result->value->type = wanted_type;
12129 bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_union.tag);12170 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
12130 return result;12171 return result;
12131 }12172 }
1213212173
...@@ -12135,16 +12176,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12135,16 +12176,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12135 wanted_type->data.enumeration.src_field_count == 1)12176 wanted_type->data.enumeration.src_field_count == 1)
12136 {12177 {
12137 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12178 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12138 result->value.special = ConstValSpecialStatic;12179 result->value->special = ConstValSpecialStatic;
12139 result->value.type = wanted_type;12180 result->value->type = wanted_type;
12140 TypeEnumField *enum_field = target->value.type->data.unionation.fields[0].enum_field;12181 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
12141 bigint_init_bigint(&result->value.data.x_enum_tag, &enum_field->value);12182 bigint_init_bigint(&result->value->data.x_enum_tag, &enum_field->value);
12142 return result;12183 return result;
12143 }12184 }
1214412185
12145 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,12186 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,
12146 source_instr->source_node, target);12187 source_instr->source_node, target);
12147 result->value.type = wanted_type;12188 result->value->type = wanted_type;
12148 return result;12189 return result;
12149}12190}
1215012191
...@@ -12152,7 +12193,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc...@@ -12152,7 +12193,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
12152 IrInstruction *target, ZigType *wanted_type)12193 IrInstruction *target, ZigType *wanted_type)
12153{12194{
12154 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12195 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12155 result->value.special = ConstValSpecialUndef;12196 result->value->special = ConstValSpecialUndef;
12156 return result;12197 return result;
12157}12198}
1215812199
...@@ -12166,11 +12207,11 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12166,11 +12207,11 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12166 return ira->codegen->invalid_instruction;12207 return ira->codegen->invalid_instruction;
1216712208
12168 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);12209 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
12169 if (type_is_invalid(target->value.type))12210 if (type_is_invalid(target->value->type))
12170 return ira->codegen->invalid_instruction;12211 return ira->codegen->invalid_instruction;
1217112212
12172 if (instr_is_comptime(target)) {12213 if (instr_is_comptime(target)) {
12173 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12214 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12174 if (!val)12215 if (!val)
12175 return ira->codegen->invalid_instruction;12216 return ira->codegen->invalid_instruction;
12176 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);12217 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
...@@ -12201,12 +12242,12 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12201,12 +12242,12 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12201 }12242 }
1220212243
12203 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12244 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12204 result->value.special = ConstValSpecialStatic;12245 result->value->special = ConstValSpecialStatic;
12205 result->value.type = wanted_type;12246 result->value->type = wanted_type;
12206 bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag);12247 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
12207 result->value.data.x_union.payload = create_const_vals(1);12248 result->value->data.x_union.payload = create_const_vals(1);
12208 result->value.data.x_union.payload->special = ConstValSpecialStatic;12249 result->value->data.x_union.payload->special = ConstValSpecialStatic;
12209 result->value.data.x_union.payload->type = field_type;12250 result->value->data.x_union.payload->type = field_type;
12210 return result;12251 return result;
12211 }12252 }
1221212253
...@@ -12214,7 +12255,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12214,7 +12255,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12214 // and in fact it's a noop cast because the union value is just the enum value12255 // and in fact it's a noop cast because the union value is just the enum value
12215 if (wanted_type->data.unionation.gen_field_count == 0) {12256 if (wanted_type->data.unionation.gen_field_count == 0) {
12216 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop);12257 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop);
12217 result->value.type = wanted_type;12258 result->value->type = wanted_type;
12218 return result;12259 return result;
12219 }12260 }
1222012261
...@@ -12245,7 +12286,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12245,7 +12286,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12245 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);12286 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1224612287
12247 if (instr_is_comptime(target)) {12288 if (instr_is_comptime(target)) {
12248 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12289 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12249 if (!val)12290 if (!val)
12250 return ira->codegen->invalid_instruction;12291 return ira->codegen->invalid_instruction;
12251 if (wanted_type->id == ZigTypeIdInt) {12292 if (wanted_type->id == ZigTypeIdInt) {
...@@ -12259,16 +12300,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12259,16 +12300,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12259 {12300 {
12260 ir_add_error(ira, source_instr,12301 ir_add_error(ira, source_instr,
12261 buf_sprintf("cast from '%s' to '%s' truncates bits",12302 buf_sprintf("cast from '%s' to '%s' truncates bits",
12262 buf_ptr(&target->value.type->name), buf_ptr(&wanted_type->name)));12303 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));
12263 return ira->codegen->invalid_instruction;12304 return ira->codegen->invalid_instruction;
12264 }12305 }
12265 }12306 }
12266 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12307 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12267 result->value.type = wanted_type;12308 result->value->type = wanted_type;
12268 if (wanted_type->id == ZigTypeIdInt) {12309 if (wanted_type->id == ZigTypeIdInt) {
12269 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);12310 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);
12270 } else {12311 } else {
12271 float_init_float(&result->value, val);12312 float_init_float(result->value, val);
12272 }12313 }
12273 return result;12314 return result;
12274 }12315 }
...@@ -12278,16 +12319,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12278,16 +12319,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12278 // the target is zero.12319 // the target is zero.
12279 if (!type_has_bits(wanted_type)) {12320 if (!type_has_bits(wanted_type)) {
12280 assert(wanted_type->id == ZigTypeIdInt);12321 assert(wanted_type->id == ZigTypeIdInt);
12281 assert(type_has_bits(target->value.type));12322 assert(type_has_bits(target->value->type));
12282 ir_build_assert_zero(ira, source_instr, target);12323 ir_build_assert_zero(ira, source_instr, target);
12283 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);12324 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);
12284 result->value.type = wanted_type;12325 result->value->type = wanted_type;
12285 return result;12326 return result;
12286 }12327 }
1228712328
12288 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,12329 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12289 source_instr->source_node, target);12330 source_instr->source_node, target);
12290 result->value.type = wanted_type;12331 result->value->type = wanted_type;
12291 return result;12332 return result;
12292}12333}
1229312334
...@@ -12297,7 +12338,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12297,7 +12338,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12297 Error err;12338 Error err;
12298 assert(wanted_type->id == ZigTypeIdEnum);12339 assert(wanted_type->id == ZigTypeIdEnum);
1229912340
12300 ZigType *actual_type = target->value.type;12341 ZigType *actual_type = target->value->type;
1230112342
12302 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))12343 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
12303 return ira->codegen->invalid_instruction;12344 return ira->codegen->invalid_instruction;
...@@ -12313,7 +12354,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12313,7 +12354,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12313 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);12354 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
1231412355
12315 if (instr_is_comptime(target)) {12356 if (instr_is_comptime(target)) {
12316 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12357 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12317 if (!val)12358 if (!val)
12318 return ira->codegen->invalid_instruction;12359 return ira->codegen->invalid_instruction;
1231912360
...@@ -12330,28 +12371,28 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12330,28 +12371,28 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12330 }12371 }
1233112372
12332 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12373 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12333 bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_bigint);12374 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
12334 return result;12375 return result;
12335 }12376 }
1233612377
12337 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,12378 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
12338 source_instr->source_node, nullptr, target);12379 source_instr->source_node, nullptr, target);
12339 result->value.type = wanted_type;12380 result->value->type = wanted_type;
12340 return result;12381 return result;
12341}12382}
1234212383
12343static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,12384static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
12344 IrInstruction *target, ZigType *wanted_type)12385 IrInstruction *target, ZigType *wanted_type)
12345{12386{
12346 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12387 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12347 if (!val)12388 if (!val)
12348 return ira->codegen->invalid_instruction;12389 return ira->codegen->invalid_instruction;
1234912390
12350 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12391 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12351 if (wanted_type->id == ZigTypeIdComptimeFloat) {12392 if (wanted_type->id == ZigTypeIdComptimeFloat) {
12352 float_init_float(&result->value, val);12393 float_init_float(result->value, val);
12353 } else if (wanted_type->id == ZigTypeIdComptimeInt) {12394 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
12354 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);12395 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);
12355 } else {12396 } else {
12356 zig_unreachable();12397 zig_unreachable();
12357 }12398 }
...@@ -12361,12 +12402,12 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -12361,12 +12402,12 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
12361static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,12402static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
12362 ZigType *wanted_type)12403 ZigType *wanted_type)
12363{12404{
12364 assert(target->value.type->id == ZigTypeIdInt);12405 assert(target->value->type->id == ZigTypeIdInt);
12365 assert(!target->value.type->data.integral.is_signed);12406 assert(!target->value->type->data.integral.is_signed);
12366 assert(wanted_type->id == ZigTypeIdErrorSet);12407 assert(wanted_type->id == ZigTypeIdErrorSet);
1236712408
12368 if (instr_is_comptime(target)) {12409 if (instr_is_comptime(target)) {
12369 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12410 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12370 if (!val)12411 if (!val)
12371 return ira->codegen->invalid_instruction;12412 return ira->codegen->invalid_instruction;
1237212413
...@@ -12389,7 +12430,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12389,7 +12430,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12389 }12430 }
1239012431
12391 size_t index = bigint_as_usize(&val->data.x_bigint);12432 size_t index = bigint_as_usize(&val->data.x_bigint);
12392 result->value.data.x_err_set = ira->codegen->errors_by_index.at(index);12433 result->value->data.x_err_set = ira->codegen->errors_by_index.at(index);
12393 return result;12434 return result;
12394 } else {12435 } else {
12395 ErrorTableEntry *err = nullptr;12436 ErrorTableEntry *err = nullptr;
...@@ -12412,13 +12453,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12412,13 +12453,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12412 return ira->codegen->invalid_instruction;12453 return ira->codegen->invalid_instruction;
12413 }12454 }
1241412455
12415 result->value.data.x_err_set = err;12456 result->value->data.x_err_set = err;
12416 return result;12457 return result;
12417 }12458 }
12418 }12459 }
1241912460
12420 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);12461 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12421 result->value.type = wanted_type;12462 result->value->type = wanted_type;
12422 return result;12463 return result;
12423}12464}
1242412465
...@@ -12427,10 +12468,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12427,10 +12468,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12427{12468{
12428 assert(wanted_type->id == ZigTypeIdInt);12469 assert(wanted_type->id == ZigTypeIdInt);
1242912470
12430 ZigType *err_type = target->value.type;12471 ZigType *err_type = target->value->type;
1243112472
12432 if (instr_is_comptime(target)) {12473 if (instr_is_comptime(target)) {
12433 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12474 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12434 if (!val)12475 if (!val)
12435 return ira->codegen->invalid_instruction;12476 return ira->codegen->invalid_instruction;
1243612477
...@@ -12444,11 +12485,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12444,11 +12485,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12444 } else {12485 } else {
12445 zig_unreachable();12486 zig_unreachable();
12446 }12487 }
12447 result->value.type = wanted_type;12488 result->value->type = wanted_type;
12448 uint64_t err_value = err ? err->value : 0;12489 uint64_t err_value = err ? err->value : 0;
12449 bigint_init_unsigned(&result->value.data.x_bigint, err_value);12490 bigint_init_unsigned(&result->value->data.x_bigint, err_value);
1245012491
12451 if (!bigint_fits_in_bits(&result->value.data.x_bigint,12492 if (!bigint_fits_in_bits(&result->value->data.x_bigint,
12452 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))12493 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))
12453 {12494 {
12454 ir_add_error_node(ira, source_instr->source_node,12495 ir_add_error_node(ira, source_instr->source_node,
...@@ -12474,12 +12515,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12474,12 +12515,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12474 }12515 }
12475 if (err_set_type->data.error_set.err_count == 0) {12516 if (err_set_type->data.error_set.err_count == 0) {
12476 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12517 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12477 bigint_init_unsigned(&result->value.data.x_bigint, 0);12518 bigint_init_unsigned(&result->value->data.x_bigint, 0);
12478 return result;12519 return result;
12479 } else if (err_set_type->data.error_set.err_count == 1) {12520 } else if (err_set_type->data.error_set.err_count == 1) {
12480 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12521 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12481 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];12522 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
12482 bigint_init_unsigned(&result->value.data.x_bigint, err->value);12523 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
12483 return result;12524 return result;
12484 }12525 }
12485 }12526 }
...@@ -12493,7 +12534,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12493,7 +12534,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12493 }12534 }
1249412535
12495 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);12536 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12496 result->value.type = wanted_type;12537 result->value->type = wanted_type;
12497 return result;12538 return result;
12498}12539}
1249912540
...@@ -12502,25 +12543,25 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -12502,25 +12543,25 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
12502{12543{
12503 assert(wanted_type->id == ZigTypeIdPointer);12544 assert(wanted_type->id == ZigTypeIdPointer);
12504 Error err;12545 Error err;
12505 if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown)))12546 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12506 return ira->codegen->invalid_instruction;12547 return ira->codegen->invalid_instruction;
12507 assert((wanted_type->data.pointer.is_const && target->value.type->data.pointer.is_const) || !target->value.type->data.pointer.is_const);12548 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
12508 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type));12549 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
12509 ZigType *array_type = wanted_type->data.pointer.child_type;12550 ZigType *array_type = wanted_type->data.pointer.child_type;
12510 assert(array_type->id == ZigTypeIdArray);12551 assert(array_type->id == ZigTypeIdArray);
12511 assert(array_type->data.array.len == 1);12552 assert(array_type->data.array.len == 1);
1251212553
12513 if (instr_is_comptime(target)) {12554 if (instr_is_comptime(target)) {
12514 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12555 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12515 if (!val)12556 if (!val)
12516 return ira->codegen->invalid_instruction;12557 return ira->codegen->invalid_instruction;
1251712558
12518 assert(val->type->id == ZigTypeIdPointer);12559 assert(val->type->id == ZigTypeIdPointer);
12519 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);12560 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
12520 if (pointee == nullptr)12561 if (pointee == nullptr)
12521 return ira->codegen->invalid_instruction;12562 return ira->codegen->invalid_instruction;
12522 if (pointee->special != ConstValSpecialRuntime) {12563 if (pointee->special != ConstValSpecialRuntime) {
12523 ConstExprValue *array_val = create_const_vals(1);12564 ZigValue *array_val = create_const_vals(1);
12524 array_val->special = ConstValSpecialStatic;12565 array_val->special = ConstValSpecialStatic;
12525 array_val->type = array_type;12566 array_val->type = array_type;
12526 array_val->data.x_array.special = ConstArraySpecialNone;12567 array_val->data.x_array.special = ConstArraySpecialNone;
...@@ -12530,11 +12571,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -12530,11 +12571,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1253012571
12531 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,12572 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
12532 source_instr->scope, source_instr->source_node);12573 source_instr->scope, source_instr->source_node);
12533 const_instruction->base.value.type = wanted_type;12574 const_instruction->base.value->type = wanted_type;
12534 const_instruction->base.value.special = ConstValSpecialStatic;12575 const_instruction->base.value->special = ConstValSpecialStatic;
12535 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef;12576 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef;
12536 const_instruction->base.value.data.x_ptr.data.ref.pointee = array_val;12577 const_instruction->base.value->data.x_ptr.data.ref.pointee = array_val;
12537 const_instruction->base.value.data.x_ptr.mut = val->data.x_ptr.mut;12578 const_instruction->base.value->data.x_ptr.mut = val->data.x_ptr.mut;
12538 return &const_instruction->base;12579 return &const_instruction->base;
12539 }12580 }
12540 }12581 }
...@@ -12542,7 +12583,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -12542,7 +12583,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
12542 // pointer to array and pointer to single item are represented the same way at runtime12583 // pointer to array and pointer to single item are represented the same way at runtime
12543 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,12584 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,
12544 wanted_type, target, CastOpBitCast);12585 wanted_type, target, CastOpBitCast);
12545 result->value.type = wanted_type;12586 result->value->type = wanted_type;
12546 return result;12587 return result;
12547}12588}
1254812589
...@@ -12724,10 +12765,10 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *...@@ -12724,10 +12765,10 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
12724 IrInstruction *array, ZigType *vector_type)12765 IrInstruction *array, ZigType *vector_type)
12725{12766{
12726 if (instr_is_comptime(array)) {12767 if (instr_is_comptime(array)) {
12727 // arrays and vectors have the same ConstExprValue representation12768 // arrays and vectors have the same ZigValue representation
12728 IrInstruction *result = ir_const(ira, source_instr, vector_type);12769 IrInstruction *result = ir_const(ira, source_instr, vector_type);
12729 copy_const_val(&result->value, &array->value, false);12770 copy_const_val(result->value, array->value, false);
12730 result->value.type = vector_type;12771 result->value->type = vector_type;
12731 return result;12772 return result;
12732 }12773 }
12733 return ir_build_array_to_vector(ira, source_instr, array, vector_type);12774 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
...@@ -12737,10 +12778,10 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -12737,10 +12778,10 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
12737 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)12778 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)
12738{12779{
12739 if (instr_is_comptime(vector)) {12780 if (instr_is_comptime(vector)) {
12740 // arrays and vectors have the same ConstExprValue representation12781 // arrays and vectors have the same ZigValue representation
12741 IrInstruction *result = ir_const(ira, source_instr, array_type);12782 IrInstruction *result = ir_const(ira, source_instr, array_type);
12742 copy_const_val(&result->value, &vector->value, false);12783 copy_const_val(result->value, vector->value, false);
12743 result->value.type = array_type;12784 result->value->type = array_type;
12744 return result;12785 return result;
12745 }12786 }
12746 if (result_loc == nullptr) {12787 if (result_loc == nullptr) {
...@@ -12748,7 +12789,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -12748,7 +12789,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
12748 }12789 }
12749 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,12790 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
12750 true, false, true);12791 true, false, true);
12751 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {12792 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12752 return result_loc_inst;12793 return result_loc_inst;
12753 }12794 }
12754 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);12795 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
...@@ -12761,23 +12802,23 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -12761,23 +12802,23 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
12761 if (instr_is_comptime(integer)) {12802 if (instr_is_comptime(integer)) {
12762 unsigned_integer = integer;12803 unsigned_integer = integer;
12763 } else {12804 } else {
12764 assert(integer->value.type->id == ZigTypeIdInt);12805 assert(integer->value->type->id == ZigTypeIdInt);
1276512806
12766 if (integer->value.type->data.integral.bit_count >12807 if (integer->value->type->data.integral.bit_count >
12767 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)12808 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)
12768 {12809 {
12769 ir_add_error(ira, source_instr,12810 ir_add_error(ira, source_instr,
12770 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",12811 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
12771 buf_ptr(&integer->value.type->name),12812 buf_ptr(&integer->value->type->name),
12772 buf_ptr(&dest_type->name)));12813 buf_ptr(&dest_type->name)));
12773 return ira->codegen->invalid_instruction;12814 return ira->codegen->invalid_instruction;
12774 }12815 }
1277512816
12776 if (integer->value.type->data.integral.is_signed) {12817 if (integer->value->type->data.integral.is_signed) {
12777 ZigType *unsigned_int_type = get_int_type(ira->codegen, false,12818 ZigType *unsigned_int_type = get_int_type(ira->codegen, false,
12778 integer->value.type->data.integral.bit_count);12819 integer->value->type->data.integral.bit_count);
12779 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);12820 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
12780 if (type_is_invalid(unsigned_integer->value.type))12821 if (type_is_invalid(unsigned_integer->value->type))
12781 return ira->codegen->invalid_instruction;12822 return ira->codegen->invalid_instruction;
12782 } else {12823 } else {
12783 unsigned_integer = integer;12824 unsigned_integer = integer;
...@@ -12807,16 +12848,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou...@@ -12807,16 +12848,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
12807 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))12848 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
12808 return ira->codegen->invalid_instruction;12849 return ira->codegen->invalid_instruction;
1280912850
12810 TypeEnumField *field = find_enum_type_field(enum_type, value->value.data.x_enum_literal);12851 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
12811 if (field == nullptr) {12852 if (field == nullptr) {
12812 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",12853 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",
12813 buf_ptr(&enum_type->name), buf_ptr(value->value.data.x_enum_literal)));12854 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
12814 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,12855 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
12815 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));12856 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
12816 return ira->codegen->invalid_instruction;12857 return ira->codegen->invalid_instruction;
12817 }12858 }
12818 IrInstruction *result = ir_const(ira, source_instr, enum_type);12859 IrInstruction *result = ir_const(ira, source_instr, enum_type);
12819 bigint_init_bigint(&result->value.data.x_enum_tag, &field->value);12860 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
1282012861
12821 return result;12862 return result;
12822}12863}
...@@ -12885,7 +12926,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst...@@ -12885,7 +12926,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst
12885{12926{
12886 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);12927 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
12887 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,12928 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
12888 struct_operand->value.type, false);12929 struct_operand->value->type, false);
12889 return ir_get_deref(ira, source_instr, field_ptr, nullptr);12930 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
12890}12931}
1289112932
...@@ -12893,7 +12934,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12893,7 +12934,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12893 ZigType *wanted_type, IrInstruction *value)12934 ZigType *wanted_type, IrInstruction *value)
12894{12935{
12895 Error err;12936 Error err;
12896 ZigType *actual_type = value->value.type;12937 ZigType *actual_type = value->value->type;
12897 AstNode *source_node = source_instr->source_node;12938 AstNode *source_node = source_instr->source_node;
1289812939
12899 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {12940 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
...@@ -12915,13 +12956,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12915,13 +12956,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12915 }12956 }
1291612957
12917 if (const_cast_result.id == ConstCastResultIdFnCC) {12958 if (const_cast_result.id == ConstCastResultIdFnCC) {
12918 ir_assert(value->value.type->id == ZigTypeIdFn, source_instr);12959 ir_assert(value->value->type->id == ZigTypeIdFn, source_instr);
12919 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.12960 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.
12920 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&12961 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&
12921 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)12962 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)
12922 {12963 {
12923 ir_assert(value->value.data.x_ptr.special == ConstPtrSpecialFunction, source_instr);12964 ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
12924 ZigFn *fn = value->value.data.x_ptr.data.fn.fn_entry;12965 ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry;
12925 if (fn->inferred_async_node == nullptr) {12966 if (fn->inferred_async_node == nullptr) {
12926 fn->inferred_async_node = source_instr->source_node;12967 fn->inferred_async_node = source_instr->source_node;
12927 }12968 }
...@@ -12963,7 +13004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12963,7 +13004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12963 {13004 {
12964 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,13005 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
12965 wanted_child_type);13006 wanted_child_type);
12966 if (type_is_invalid(cast1->value.type))13007 if (type_is_invalid(cast1->value->type))
12967 return ira->codegen->invalid_instruction;13008 return ira->codegen->invalid_instruction;
12968 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);13009 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
12969 }13010 }
...@@ -12999,11 +13040,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12999,11 +13040,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12999 actual_type->id == ZigTypeIdComptimeFloat)13040 actual_type->id == ZigTypeIdComptimeFloat)
13000 {13041 {
13001 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);13042 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13002 if (type_is_invalid(cast1->value.type))13043 if (type_is_invalid(cast1->value->type))
13003 return ira->codegen->invalid_instruction;13044 return ira->codegen->invalid_instruction;
1300413045
13005 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);13046 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13006 if (type_is_invalid(cast2->value.type))13047 if (type_is_invalid(cast2->value->type))
13007 return ira->codegen->invalid_instruction;13048 return ira->codegen->invalid_instruction;
1300813049
13009 return cast2;13050 return cast2;
...@@ -13018,29 +13059,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13018,29 +13059,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13018 (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt ||13059 (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt ||
13019 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))13060 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
13020 {13061 {
13021 if (value->value.special == ConstValSpecialUndef) {13062 if (value->value->special == ConstValSpecialUndef) {
13022 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13063 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13023 result->value.special = ConstValSpecialUndef;13064 result->value->special = ConstValSpecialUndef;
13024 return result;13065 return result;
13025 }13066 }
13026 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {13067 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
13027 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {13068 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
13028 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13069 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13029 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {13070 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13030 copy_const_val(&result->value, &value->value, false);13071 copy_const_val(result->value, value->value, false);
13031 result->value.type = wanted_type;13072 result->value->type = wanted_type;
13032 } else {13073 } else {
13033 float_init_bigint(&result->value.data.x_bigint, &value->value);13074 float_init_bigint(&result->value->data.x_bigint, value->value);
13034 }13075 }
13035 return result;13076 return result;
13036 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {13077 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
13037 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13078 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13038 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {13079 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13039 BigFloat bf;13080 BigFloat bf;
13040 bigfloat_init_bigint(&bf, &value->value.data.x_bigint);13081 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
13041 float_init_bigfloat(&result->value, &bf);13082 float_init_bigfloat(result->value, &bf);
13042 } else {13083 } else {
13043 float_init_float(&result->value, &value->value);13084 float_init_float(result->value, value->value);
13044 }13085 }
13045 return result;13086 return result;
13046 }13087 }
...@@ -13102,11 +13143,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13102,11 +13143,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13102 source_node, false).id == ConstCastResultIdOk)13143 source_node, false).id == ConstCastResultIdOk)
13103 {13144 {
13104 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);13145 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13105 if (type_is_invalid(cast1->value.type))13146 if (type_is_invalid(cast1->value->type))
13106 return ira->codegen->invalid_instruction;13147 return ira->codegen->invalid_instruction;
1310713148
13108 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);13149 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13109 if (type_is_invalid(cast2->value.type))13150 if (type_is_invalid(cast2->value->type))
13110 return ira->codegen->invalid_instruction;13151 return ira->codegen->invalid_instruction;
1311113152
13112 return cast2;13153 return cast2;
...@@ -13121,11 +13162,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13121,11 +13162,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13121 actual_type->data.pointer.child_type->id == ZigTypeIdArray)13162 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13122 {13163 {
13123 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);13164 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13124 if (type_is_invalid(cast1->value.type))13165 if (type_is_invalid(cast1->value->type))
13125 return ira->codegen->invalid_instruction;13166 return ira->codegen->invalid_instruction;
1312613167
13127 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);13168 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13128 if (type_is_invalid(cast2->value.type))13169 if (type_is_invalid(cast2->value->type))
13129 return ira->codegen->invalid_instruction;13170 return ira->codegen->invalid_instruction;
1313013171
13131 return cast2;13172 return cast2;
...@@ -13202,11 +13243,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13202,11 +13243,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13202 if (ok_align) {13243 if (ok_align) {
13203 if (wanted_type->id == ZigTypeIdErrorUnion) {13244 if (wanted_type->id == ZigTypeIdErrorUnion) {
13204 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);13245 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
13205 if (type_is_invalid(cast1->value.type))13246 if (type_is_invalid(cast1->value->type))
13206 return ira->codegen->invalid_instruction;13247 return ira->codegen->invalid_instruction;
1320713248
13208 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);13249 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13209 if (type_is_invalid(cast2->value.type))13250 if (type_is_invalid(cast2->value->type))
13210 return ira->codegen->invalid_instruction;13251 return ira->codegen->invalid_instruction;
1321113252
13212 return cast2;13253 return cast2;
...@@ -13309,11 +13350,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13309,11 +13350,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13309 source_node, false).id == ConstCastResultIdOk)13350 source_node, false).id == ConstCastResultIdOk)
13310 {13351 {
13311 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);13352 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13312 if (type_is_invalid(cast1->value.type))13353 if (type_is_invalid(cast1->value->type))
13313 return ira->codegen->invalid_instruction;13354 return ira->codegen->invalid_instruction;
1331413355
13315 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);13356 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13316 if (type_is_invalid(cast2->value.type))13357 if (type_is_invalid(cast2->value->type))
13317 return ira->codegen->invalid_instruction;13358 return ira->codegen->invalid_instruction;
1331813359
13319 return cast2;13360 return cast2;
...@@ -13529,13 +13570,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou...@@ -13529,13 +13570,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
13529 assert(value);13570 assert(value);
13530 assert(value != ira->codegen->invalid_instruction);13571 assert(value != ira->codegen->invalid_instruction);
13531 assert(!expected_type || !type_is_invalid(expected_type));13572 assert(!expected_type || !type_is_invalid(expected_type));
13532 assert(value->value.type);13573 assert(value->value->type);
13533 assert(!type_is_invalid(value->value.type));13574 assert(!type_is_invalid(value->value->type));
13534 if (expected_type == nullptr)13575 if (expected_type == nullptr)
13535 return value; // anything will do13576 return value; // anything will do
13536 if (expected_type == value->value.type)13577 if (expected_type == value->value->type)
13537 return value; // match13578 return value; // match
13538 if (value->value.type->id == ZigTypeIdUnreachable)13579 if (value->value->type->id == ZigTypeIdUnreachable)
13539 return value;13580 return value;
1354013581
13541 return ir_analyze_cast(ira, value_source_instr, expected_type, value);13582 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
...@@ -13549,7 +13590,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13549,7 +13590,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13549 ResultLoc *result_loc)13590 ResultLoc *result_loc)
13550{13591{
13551 Error err;13592 Error err;
13552 ZigType *ptr_type = ptr->value.type;13593 ZigType *ptr_type = ptr->value->type;
13553 if (type_is_invalid(ptr_type))13594 if (type_is_invalid(ptr_type))
13554 return ira->codegen->invalid_instruction;13595 return ira->codegen->invalid_instruction;
1355513596
...@@ -13571,24 +13612,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13571,24 +13612,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13571 break;13612 break;
13572 }13613 }
13573 if (instr_is_comptime(ptr)) {13614 if (instr_is_comptime(ptr)) {
13574 if (ptr->value.special == ConstValSpecialUndef) {13615 if (ptr->value->special == ConstValSpecialUndef) {
13575 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));13616 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
13576 return ira->codegen->invalid_instruction;13617 return ira->codegen->invalid_instruction;
13577 }13618 }
13578 if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {13619 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
13579 ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);13620 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
13580 if (child_type == ira->codegen->builtin_types.entry_var) {13621 if (child_type == ira->codegen->builtin_types.entry_var) {
13581 child_type = pointee->type;13622 child_type = pointee->type;
13582 }13623 }
13583 if (pointee->special != ConstValSpecialRuntime) {13624 if (pointee->special != ConstValSpecialRuntime) {
13584 IrInstruction *result = ir_const(ira, source_instruction, child_type);13625 IrInstruction *result = ir_const(ira, source_instruction, child_type);
1358513626
13586 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, &result->value,13627 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
13587 &ptr->value)))13628 ptr->value)))
13588 {13629 {
13589 return ira->codegen->invalid_instruction;13630 return ira->codegen->invalid_instruction;
13590 }13631 }
13591 result->value.type = child_type;13632 result->value->type = child_type;
13592 return result;13633 return result;
13593 }13634 }
13594 }13635 }
...@@ -13626,7 +13667,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13626,7 +13667,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13626 if (result_loc == nullptr) result_loc = no_result_loc();13667 if (result_loc == nullptr) result_loc = no_result_loc();
13627 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,13668 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,
13628 true, false, true);13669 true, false, true);
13629 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {13670 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13630 return result_loc_inst;13671 return result_loc_inst;
13631 }13672 }
13632 } else {13673 } else {
...@@ -13637,7 +13678,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13637,7 +13678,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13637}13678}
1363813679
13639static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,13680static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13640 ConstExprValue *const_val, uint32_t *out)13681 ZigValue *const_val, uint32_t *out)
13641{13682{
13642 Error err;13683 Error err;
13643 if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad)))13684 if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad)))
...@@ -13660,15 +13701,15 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -13660,15 +13701,15 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
13660}13701}
1366113702
13662static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) {13703static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) {
13663 if (type_is_invalid(value->value.type))13704 if (type_is_invalid(value->value->type))
13664 return false;13705 return false;
1366513706
13666 // Look for this pattern: `*align(@alignOf(T)) T`.13707 // Look for this pattern: `*align(@alignOf(T)) T`.
13667 // This can be resolved to be `*out = 0` without resolving any alignment.13708 // This can be resolved to be `*out = 0` without resolving any alignment.
13668 if (elem_type != nullptr && value->value.special == ConstValSpecialLazy &&13709 if (elem_type != nullptr && value->value->special == ConstValSpecialLazy &&
13669 value->value.data.x_lazy->id == LazyValueIdAlignOf)13710 value->value->data.x_lazy->id == LazyValueIdAlignOf)
13670 {13711 {
13671 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value.data.x_lazy);13712 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value->data.x_lazy);
1367213713
13673 ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type);13714 ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type);
13674 if (type_is_invalid(lazy_elem_type))13715 if (type_is_invalid(lazy_elem_type))
...@@ -13681,22 +13722,22 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem...@@ -13681,22 +13722,22 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
13681 }13722 }
1368213723
13683 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));13724 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
13684 if (type_is_invalid(casted_value->value.type))13725 if (type_is_invalid(casted_value->value->type))
13685 return false;13726 return false;
1368613727
13687 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,13728 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
13688 &casted_value->value, out);13729 casted_value->value, out);
13689}13730}
1369013731
13691static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {13732static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {
13692 if (type_is_invalid(value->value.type))13733 if (type_is_invalid(value->value->type))
13693 return false;13734 return false;
1369413735
13695 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);13736 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);
13696 if (type_is_invalid(casted_value->value.type))13737 if (type_is_invalid(casted_value->value->type))
13697 return false;13738 return false;
1369813739
13699 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13740 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13700 if (!const_val)13741 if (!const_val)
13701 return false;13742 return false;
1370213743
...@@ -13709,14 +13750,14 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out...@@ -13709,14 +13750,14 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
13709}13750}
1371013751
13711static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {13752static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
13712 if (type_is_invalid(value->value.type))13753 if (type_is_invalid(value->value->type))
13713 return false;13754 return false;
1371413755
13715 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);13756 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
13716 if (type_is_invalid(casted_value->value.type))13757 if (type_is_invalid(casted_value->value->type))
13717 return false;13758 return false;
1371813759
13719 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13760 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13720 if (!const_val)13761 if (!const_val)
13721 return false;13762 return false;
1372213763
...@@ -13733,18 +13774,18 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)...@@ -13733,18 +13774,18 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
13733}13774}
1373413775
13735static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {13776static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
13736 if (type_is_invalid(value->value.type))13777 if (type_is_invalid(value->value->type))
13737 return false;13778 return false;
1373813779
13739 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");13780 ZigValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
13740 assert(atomic_order_val->type->id == ZigTypeIdMetaType);13781 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
13741 ZigType *atomic_order_type = atomic_order_val->data.x_type;13782 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1374213783
13743 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);13784 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
13744 if (type_is_invalid(casted_value->value.type))13785 if (type_is_invalid(casted_value->value->type))
13745 return false;13786 return false;
1374613787
13747 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13788 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13748 if (!const_val)13789 if (!const_val)
13749 return false;13790 return false;
1375013791
...@@ -13753,18 +13794,18 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -13753,18 +13794,18 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
13753}13794}
1375413795
13755static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) {13796static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) {
13756 if (type_is_invalid(value->value.type))13797 if (type_is_invalid(value->value->type))
13757 return false;13798 return false;
1375813799
13759 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");13800 ZigValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
13760 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);13801 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
13761 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;13802 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1376213803
13763 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);13804 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
13764 if (type_is_invalid(casted_value->value.type))13805 if (type_is_invalid(casted_value->value->type))
13765 return false;13806 return false;
1376613807
13767 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13808 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13768 if (!const_val)13809 if (!const_val)
13769 return false;13810 return false;
1377013811
...@@ -13773,18 +13814,18 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -13773,18 +13814,18 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
13773}13814}
1377413815
13775static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) {13816static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) {
13776 if (type_is_invalid(value->value.type))13817 if (type_is_invalid(value->value->type))
13777 return false;13818 return false;
1377813819
13779 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");13820 ZigValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
13780 assert(global_linkage_val->type->id == ZigTypeIdMetaType);13821 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
13781 ZigType *global_linkage_type = global_linkage_val->data.x_type;13822 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1378213823
13783 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);13824 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
13784 if (type_is_invalid(casted_value->value.type))13825 if (type_is_invalid(casted_value->value->type))
13785 return false;13826 return false;
1378613827
13787 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13828 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13788 if (!const_val)13829 if (!const_val)
13789 return false;13830 return false;
1379013831
...@@ -13793,18 +13834,18 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -13793,18 +13834,18 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
13793}13834}
1379413835
13795static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) {13836static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) {
13796 if (type_is_invalid(value->value.type))13837 if (type_is_invalid(value->value->type))
13797 return false;13838 return false;
1379813839
13799 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");13840 ZigValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
13800 assert(float_mode_val->type->id == ZigTypeIdMetaType);13841 assert(float_mode_val->type->id == ZigTypeIdMetaType);
13801 ZigType *float_mode_type = float_mode_val->data.x_type;13842 ZigType *float_mode_type = float_mode_val->data.x_type;
1380213843
13803 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);13844 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
13804 if (type_is_invalid(casted_value->value.type))13845 if (type_is_invalid(casted_value->value->type))
13805 return false;13846 return false;
1380613847
13807 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13848 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13808 if (!const_val)13849 if (!const_val)
13809 return false;13850 return false;
1381013851
...@@ -13813,25 +13854,25 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -13813,25 +13854,25 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
13813}13854}
1381413855
13815static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {13856static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13816 if (type_is_invalid(value->value.type))13857 if (type_is_invalid(value->value->type))
13817 return nullptr;13858 return nullptr;
1381813859
13819 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,13860 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
13820 true, false, PtrLenUnknown, 0, 0, 0, false);13861 true, false, PtrLenUnknown, 0, 0, 0, false);
13821 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);13862 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
13822 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);13863 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
13823 if (type_is_invalid(casted_value->value.type))13864 if (type_is_invalid(casted_value->value->type))
13824 return nullptr;13865 return nullptr;
1382513866
13826 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13867 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13827 if (!const_val)13868 if (!const_val)
13828 return nullptr;13869 return nullptr;
1382913870
13830 ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];13871 ZigValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13831 ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index];13872 ZigValue *len_field = const_val->data.x_struct.fields[slice_len_index];
1383213873
13833 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);13874 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
13834 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;13875 ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
13835 expand_undef_array(ira->codegen, array_val);13876 expand_undef_array(ira->codegen, array_val);
13836 size_t len = bigint_as_usize(&len_field->data.x_bigint);13877 size_t len = bigint_as_usize(&len_field->data.x_bigint);
13837 if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) {13878 if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) {
...@@ -13841,7 +13882,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13841,7 +13882,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13841 buf_resize(result, len);13882 buf_resize(result, len);
13842 for (size_t i = 0; i < len; i += 1) {13883 for (size_t i = 0; i < len; i += 1) {
13843 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;13884 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
13844 ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];13885 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
13845 if (char_val->special == ConstValSpecialUndef) {13886 if (char_val->special == ConstValSpecialUndef) {
13846 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));13887 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
13847 return nullptr;13888 return nullptr;
...@@ -13858,7 +13899,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze...@@ -13858,7 +13899,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
13858 IrInstructionAddImplicitReturnType *instruction)13899 IrInstructionAddImplicitReturnType *instruction)
13859{13900{
13860 IrInstruction *value = instruction->value->child;13901 IrInstruction *value = instruction->value->child;
13861 if (type_is_invalid(value->value.type))13902 if (type_is_invalid(value->value->type))
13862 return ir_unreach_error(ira);13903 return ir_unreach_error(ira);
1386313904
13864 if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) {13905 if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) {
...@@ -13870,11 +13911,11 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze...@@ -13870,11 +13911,11 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1387013911
13871static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {13912static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {
13872 IrInstruction *operand = instruction->operand->child;13913 IrInstruction *operand = instruction->operand->child;
13873 if (type_is_invalid(operand->value.type))13914 if (type_is_invalid(operand->value->type))
13874 return ir_unreach_error(ira);13915 return ir_unreach_error(ira);
1387513916
13876 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);13917 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
13877 if (type_is_invalid(casted_operand->value.type)) {13918 if (type_is_invalid(casted_operand->value->type)) {
13878 AstNode *source_node = ira->explicit_return_type_source_node;13919 AstNode *source_node = ira->explicit_return_type_source_node;
13879 if (source_node != nullptr) {13920 if (source_node != nullptr) {
13880 ErrorMsg *msg = ira->codegen->errors.last();13921 ErrorMsg *msg = ira->codegen->errors.last();
...@@ -13890,13 +13931,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -13890,13 +13931,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
13890 // result location mechanism took care of it.13931 // result location mechanism took care of it.
13891 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,13932 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13892 instruction->base.source_node, nullptr);13933 instruction->base.source_node, nullptr);
13893 result->value.type = ira->codegen->builtin_types.entry_unreachable;13934 result->value->type = ira->codegen->builtin_types.entry_unreachable;
13894 return ir_finish_anal(ira, result);13935 return ir_finish_anal(ira, result);
13895 }13936 }
1389613937
13897 if (casted_operand->value.special == ConstValSpecialRuntime &&13938 if (casted_operand->value->special == ConstValSpecialRuntime &&
13898 casted_operand->value.type->id == ZigTypeIdPointer &&13939 casted_operand->value->type->id == ZigTypeIdPointer &&
13899 casted_operand->value.data.rh_ptr == RuntimeHintPtrStack)13940 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
13900 {13941 {
13901 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));13942 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));
13902 return ir_unreach_error(ira);13943 return ir_unreach_error(ira);
...@@ -13904,23 +13945,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -13904,23 +13945,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1390413945
13905 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,13946 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13906 instruction->base.source_node, casted_operand);13947 instruction->base.source_node, casted_operand);
13907 result->value.type = ira->codegen->builtin_types.entry_unreachable;13948 result->value->type = ira->codegen->builtin_types.entry_unreachable;
13908 return ir_finish_anal(ira, result);13949 return ir_finish_anal(ira, result);
13909}13950}
1391013951
13911static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {13952static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
13912 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);13953 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
13913 copy_const_val(&result->value, &instruction->base.value, true);13954 copy_const_val(result->value, instruction->base.value, true);
13914 return result;13955 return result;
13915}13956}
1391613957
13917static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {13958static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
13918 IrInstruction *op1 = bin_op_instruction->op1->child;13959 IrInstruction *op1 = bin_op_instruction->op1->child;
13919 if (type_is_invalid(op1->value.type))13960 if (type_is_invalid(op1->value->type))
13920 return ira->codegen->invalid_instruction;13961 return ira->codegen->invalid_instruction;
1392113962
13922 IrInstruction *op2 = bin_op_instruction->op2->child;13963 IrInstruction *op2 = bin_op_instruction->op2->child;
13923 if (type_is_invalid(op2->value.type))13964 if (type_is_invalid(op2->value->type))
13924 return ira->codegen->invalid_instruction;13965 return ira->codegen->invalid_instruction;
1392513966
13926 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;13967 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
...@@ -13934,16 +13975,16 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -13934,16 +13975,16 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
13934 return ira->codegen->invalid_instruction;13975 return ira->codegen->invalid_instruction;
1393513976
13936 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {13977 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
13937 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);13978 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
13938 if (op1_val == nullptr)13979 if (op1_val == nullptr)
13939 return ira->codegen->invalid_instruction;13980 return ira->codegen->invalid_instruction;
1394013981
13941 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);13982 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
13942 if (op2_val == nullptr)13983 if (op2_val == nullptr)
13943 return ira->codegen->invalid_instruction;13984 return ira->codegen->invalid_instruction;
1394413985
13945 assert(casted_op1->value.type->id == ZigTypeIdBool);13986 assert(casted_op1->value->type->id == ZigTypeIdBool);
13946 assert(casted_op2->value.type->id == ZigTypeIdBool);13987 assert(casted_op2->value->type->id == ZigTypeIdBool);
13947 bool result_bool;13988 bool result_bool;
13948 if (bin_op_instruction->op_id == IrBinOpBoolOr) {13989 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
13949 result_bool = op1_val->data.x_bool || op2_val->data.x_bool;13990 result_bool = op1_val->data.x_bool || op2_val->data.x_bool;
...@@ -13958,7 +13999,7 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -13958,7 +13999,7 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
13958 IrInstruction *result = ir_build_bin_op(&ira->new_irb,13999 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
13959 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,14000 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
13960 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);14001 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
13961 result->value.type = bool_type;14002 result->value->type = bool_type;
13962 return result;14003 return result;
13963}14004}
1396414005
...@@ -13981,7 +14022,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {...@@ -13981,7 +14022,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
13981 }14022 }
13982}14023}
1398314024
13984static bool optional_value_is_null(ConstExprValue *val) {14025static bool optional_value_is_null(ZigValue *val) {
13985 assert(val->special == ConstValSpecialStatic);14026 assert(val->special == ConstValSpecialStatic);
13986 if (get_codegen_ptr_type(val->type) != nullptr) {14027 if (get_codegen_ptr_type(val->type) != nullptr) {
13987 if (val->data.x_ptr.special == ConstPtrSpecialNull) {14028 if (val->data.x_ptr.special == ConstPtrSpecialNull) {
...@@ -13999,7 +14040,7 @@ static bool optional_value_is_null(ConstExprValue *val) {...@@ -13999,7 +14040,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
13999}14040}
1400014041
14001static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,14042static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14002 ConstExprValue *op1_val, ConstExprValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,14043 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,
14003 bool one_possible_value) {14044 bool one_possible_value) {
14004 if (op1_val->special == ConstValSpecialUndef ||14045 if (op1_val->special == ConstValSpecialUndef ||
14005 op2_val->special == ConstValSpecialUndef)14046 op2_val->special == ConstValSpecialUndef)
...@@ -14052,7 +14093,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t...@@ -14052,7 +14093,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14052}14093}
1405314094
14054// Returns ErrorNotLazy when the value cannot be determined14095// Returns ErrorNotLazy when the value cannot be determined
14055static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *result) {14096static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
14056 Error err;14097 Error err;
1405714098
14058 switch (val->special) {14099 switch (val->special) {
...@@ -14079,7 +14120,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *resul...@@ -14079,7 +14120,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *resul
14079 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);14120 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
14080 IrAnalyze *ira = lazy_size_of->ira;14121 IrAnalyze *ira = lazy_size_of->ira;
14081 bool is_zero_bits;14122 bool is_zero_bits;
14082 if ((err = type_val_resolve_zero_bits(ira->codegen, &lazy_size_of->target_type->value,14123 if ((err = type_val_resolve_zero_bits(ira->codegen, lazy_size_of->target_type->value,
14083 nullptr, nullptr, &is_zero_bits)))14124 nullptr, nullptr, &is_zero_bits)))
14084 {14125 {
14085 return err;14126 return err;
...@@ -14098,33 +14139,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14098,33 +14139,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14098 Error err;14139 Error err;
1409914140
14100 IrInstruction *op1 = bin_op_instruction->op1->child;14141 IrInstruction *op1 = bin_op_instruction->op1->child;
14101 if (type_is_invalid(op1->value.type))14142 if (type_is_invalid(op1->value->type))
14102 return ira->codegen->invalid_instruction;14143 return ira->codegen->invalid_instruction;
1410314144
14104 IrInstruction *op2 = bin_op_instruction->op2->child;14145 IrInstruction *op2 = bin_op_instruction->op2->child;
14105 if (type_is_invalid(op2->value.type))14146 if (type_is_invalid(op2->value->type))
14106 return ira->codegen->invalid_instruction;14147 return ira->codegen->invalid_instruction;
1410714148
14108 AstNode *source_node = bin_op_instruction->base.source_node;14149 AstNode *source_node = bin_op_instruction->base.source_node;
1410914150
14110 IrBinOp op_id = bin_op_instruction->op_id;14151 IrBinOp op_id = bin_op_instruction->op_id;
14111 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);14152 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
14112 if (is_equality_cmp && op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) {14153 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
14113 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));14154 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));
14114 } else if (is_equality_cmp &&14155 } else if (is_equality_cmp &&
14115 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||14156 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
14116 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional)))14157 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
14117 {14158 {
14118 IrInstruction *maybe_op;14159 IrInstruction *maybe_op;
14119 if (op1->value.type->id == ZigTypeIdNull) {14160 if (op1->value->type->id == ZigTypeIdNull) {
14120 maybe_op = op2;14161 maybe_op = op2;
14121 } else if (op2->value.type->id == ZigTypeIdNull) {14162 } else if (op2->value->type->id == ZigTypeIdNull) {
14122 maybe_op = op1;14163 maybe_op = op1;
14123 } else {14164 } else {
14124 zig_unreachable();14165 zig_unreachable();
14125 }14166 }
14126 if (instr_is_comptime(maybe_op)) {14167 if (instr_is_comptime(maybe_op)) {
14127 ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);14168 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
14128 if (!maybe_val)14169 if (!maybe_val)
14129 return ira->codegen->invalid_instruction;14170 return ira->codegen->invalid_instruction;
14130 bool is_null = optional_value_is_null(maybe_val);14171 bool is_null = optional_value_is_null(maybe_val);
...@@ -14134,32 +14175,32 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14134,32 +14175,32 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1413414175
14135 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,14176 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
14136 source_node, maybe_op);14177 source_node, maybe_op);
14137 is_non_null->value.type = ira->codegen->builtin_types.entry_bool;14178 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1413814179
14139 if (op_id == IrBinOpCmpEq) {14180 if (op_id == IrBinOpCmpEq) {
14140 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,14181 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
14141 bin_op_instruction->base.source_node, is_non_null);14182 bin_op_instruction->base.source_node, is_non_null);
14142 result->value.type = ira->codegen->builtin_types.entry_bool;14183 result->value->type = ira->codegen->builtin_types.entry_bool;
14143 return result;14184 return result;
14144 } else {14185 } else {
14145 return is_non_null;14186 return is_non_null;
14146 }14187 }
14147 } else if (is_equality_cmp &&14188 } else if (is_equality_cmp &&
14148 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer &&14189 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdPointer &&
14149 op2->value.type->data.pointer.ptr_len == PtrLenC) ||14190 op2->value->type->data.pointer.ptr_len == PtrLenC) ||
14150 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer &&14191 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
14151 op1->value.type->data.pointer.ptr_len == PtrLenC)))14192 op1->value->type->data.pointer.ptr_len == PtrLenC)))
14152 {14193 {
14153 IrInstruction *c_ptr_op;14194 IrInstruction *c_ptr_op;
14154 if (op1->value.type->id == ZigTypeIdNull) {14195 if (op1->value->type->id == ZigTypeIdNull) {
14155 c_ptr_op = op2;14196 c_ptr_op = op2;
14156 } else if (op2->value.type->id == ZigTypeIdNull) {14197 } else if (op2->value->type->id == ZigTypeIdNull) {
14157 c_ptr_op = op1;14198 c_ptr_op = op1;
14158 } else {14199 } else {
14159 zig_unreachable();14200 zig_unreachable();
14160 }14201 }
14161 if (instr_is_comptime(c_ptr_op)) {14202 if (instr_is_comptime(c_ptr_op)) {
14162 ConstExprValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);14203 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
14163 if (!c_ptr_val)14204 if (!c_ptr_val)
14164 return ira->codegen->invalid_instruction;14205 return ira->codegen->invalid_instruction;
14165 if (c_ptr_val->special == ConstValSpecialUndef)14206 if (c_ptr_val->special == ConstValSpecialUndef)
...@@ -14172,46 +14213,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14172,46 +14213,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14172 }14213 }
14173 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,14214 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
14174 source_node, c_ptr_op);14215 source_node, c_ptr_op);
14175 is_non_null->value.type = ira->codegen->builtin_types.entry_bool;14216 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1417614217
14177 if (op_id == IrBinOpCmpEq) {14218 if (op_id == IrBinOpCmpEq) {
14178 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,14219 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
14179 bin_op_instruction->base.source_node, is_non_null);14220 bin_op_instruction->base.source_node, is_non_null);
14180 result->value.type = ira->codegen->builtin_types.entry_bool;14221 result->value->type = ira->codegen->builtin_types.entry_bool;
14181 return result;14222 return result;
14182 } else {14223 } else {
14183 return is_non_null;14224 return is_non_null;
14184 }14225 }
14185 } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) {14226 } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) {
14186 ZigType *non_null_type = (op1->value.type->id == ZigTypeIdNull) ? op2->value.type : op1->value.type;14227 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
14187 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",14228 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
14188 buf_ptr(&non_null_type->name)));14229 buf_ptr(&non_null_type->name)));
14189 return ira->codegen->invalid_instruction;14230 return ira->codegen->invalid_instruction;
14190 } else if (is_equality_cmp && (14231 } else if (is_equality_cmp && (
14191 (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) ||14232 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
14192 (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion)))14233 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
14193 {14234 {
14194 // Support equality comparison between a union's tag value and a enum literal14235 // Support equality comparison between a union's tag value and a enum literal
14195 IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2;14236 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
14196 IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1;14237 IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1419714238
14198 ZigType *tag_type = union_val->value.type->data.unionation.tag_type;14239 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
14199 assert(tag_type != nullptr);14240 assert(tag_type != nullptr);
1420014241
14201 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);14242 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);
14202 if (type_is_invalid(casted_union->value.type))14243 if (type_is_invalid(casted_union->value->type))
14203 return ira->codegen->invalid_instruction;14244 return ira->codegen->invalid_instruction;
1420414245
14205 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);14246 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
14206 if (type_is_invalid(casted_val->value.type))14247 if (type_is_invalid(casted_val->value->type))
14207 return ira->codegen->invalid_instruction;14248 return ira->codegen->invalid_instruction;
1420814249
14209 if (instr_is_comptime(casted_union)) {14250 if (instr_is_comptime(casted_union)) {
14210 ConstExprValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);14251 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
14211 if (!const_union_val)14252 if (!const_union_val)
14212 return ira->codegen->invalid_instruction;14253 return ira->codegen->invalid_instruction;
1421314254
14214 ConstExprValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);14255 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
14215 if (!const_enum_val)14256 if (!const_enum_val)
14216 return ira->codegen->invalid_instruction;14257 return ira->codegen->invalid_instruction;
1421714258
...@@ -14224,17 +14265,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14224,17 +14265,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14224 IrInstruction *result = ir_build_bin_op(&ira->new_irb,14265 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
14225 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,14266 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
14226 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);14267 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
14227 result->value.type = ira->codegen->builtin_types.entry_bool;14268 result->value->type = ira->codegen->builtin_types.entry_bool;
1422814269
14229 return result;14270 return result;
14230 }14271 }
1423114272
14232 if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) {14273 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {
14233 if (!is_equality_cmp) {14274 if (!is_equality_cmp) {
14234 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));14275 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
14235 return ira->codegen->invalid_instruction;14276 return ira->codegen->invalid_instruction;
14236 }14277 }
14237 ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);14278 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);
14238 if (type_is_invalid(intersect_type)) {14279 if (type_is_invalid(intersect_type)) {
14239 return ira->codegen->invalid_instruction;14280 return ira->codegen->invalid_instruction;
14240 }14281 }
...@@ -14247,7 +14288,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14247,7 +14288,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14247 // (and make it comptime known)14288 // (and make it comptime known)
14248 // this is a function which is evaluated at comptime and returns an inferred error set will have an empty14289 // this is a function which is evaluated at comptime and returns an inferred error set will have an empty
14249 // error set.14290 // error set.
14250 if (op1->value.type->data.error_set.err_count == 0 || op2->value.type->data.error_set.err_count == 0) {14291 if (op1->value->type->data.error_set.err_count == 0 || op2->value->type->data.error_set.err_count == 0) {
14251 bool are_equal = false;14292 bool are_equal = false;
14252 bool answer;14293 bool answer;
14253 if (op_id == IrBinOpCmpEq) {14294 if (op_id == IrBinOpCmpEq) {
...@@ -14264,10 +14305,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14264,10 +14305,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14264 if (intersect_type->data.error_set.err_count == 0) {14305 if (intersect_type->data.error_set.err_count == 0) {
14265 ir_add_error_node(ira, source_node,14306 ir_add_error_node(ira, source_node,
14266 buf_sprintf("error sets '%s' and '%s' have no common errors",14307 buf_sprintf("error sets '%s' and '%s' have no common errors",
14267 buf_ptr(&op1->value.type->name), buf_ptr(&op2->value.type->name)));14308 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
14268 return ira->codegen->invalid_instruction;14309 return ira->codegen->invalid_instruction;
14269 }14310 }
14270 if (op1->value.type->data.error_set.err_count == 1 && op2->value.type->data.error_set.err_count == 1) {14311 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {
14271 bool are_equal = true;14312 bool are_equal = true;
14272 bool answer;14313 bool answer;
14273 if (op_id == IrBinOpCmpEq) {14314 if (op_id == IrBinOpCmpEq) {
...@@ -14282,10 +14323,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14282,10 +14323,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14282 }14323 }
1428314324
14284 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {14325 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
14285 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);14326 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14286 if (op1_val == nullptr)14327 if (op1_val == nullptr)
14287 return ira->codegen->invalid_instruction;14328 return ira->codegen->invalid_instruction;
14288 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);14329 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
14289 if (op2_val == nullptr)14330 if (op2_val == nullptr)
14290 return ira->codegen->invalid_instruction;14331 return ira->codegen->invalid_instruction;
1429114332
...@@ -14305,7 +14346,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14305,7 +14346,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14305 IrInstruction *result = ir_build_bin_op(&ira->new_irb,14346 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
14306 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,14347 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
14307 op_id, op1, op2, bin_op_instruction->safety_check_on);14348 op_id, op1, op2, bin_op_instruction->safety_check_on);
14308 result->value.type = ira->codegen->builtin_types.entry_bool;14349 result->value->type = ira->codegen->builtin_types.entry_bool;
14309 return result;14350 return result;
14310 }14351 }
1431114352
...@@ -14390,12 +14431,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14390,12 +14431,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14390 // Before resolving the values, we special case comparisons against zero. These can often be done14431 // Before resolving the values, we special case comparisons against zero. These can often be done
14391 // without resolving lazy values, preventing potential dependency loops.14432 // without resolving lazy values, preventing potential dependency loops.
14392 Cmp op1_cmp_zero;14433 Cmp op1_cmp_zero;
14393 if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op1->value, &op1_cmp_zero))) {14434 if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op1->value, &op1_cmp_zero))) {
14394 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;14435 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
14395 return ira->codegen->invalid_instruction;14436 return ira->codegen->invalid_instruction;
14396 }14437 }
14397 Cmp op2_cmp_zero;14438 Cmp op2_cmp_zero;
14398 if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op2->value, &op2_cmp_zero))) {14439 if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op2->value, &op2_cmp_zero))) {
14399 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;14440 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
14400 return ira->codegen->invalid_instruction;14441 return ira->codegen->invalid_instruction;
14401 }14442 }
...@@ -14430,33 +14471,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14430,33 +14471,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14430 }14471 }
14431never_mind_just_calculate_it_normally:14472never_mind_just_calculate_it_normally:
1443214473
14433 ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);14474 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
14434 if (op1_val == nullptr)14475 if (op1_val == nullptr)
14435 return ira->codegen->invalid_instruction;14476 return ira->codegen->invalid_instruction;
14436 ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);14477 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
14437 if (op2_val == nullptr)14478 if (op2_val == nullptr)
14438 return ira->codegen->invalid_instruction;14479 return ira->codegen->invalid_instruction;
14439 if (resolved_type->id != ZigTypeIdVector)14480 if (resolved_type->id != ZigTypeIdVector)
14440 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);14481 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);
14441 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,14482 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,
14442 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));14483 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
14443 result->value.data.x_array.data.s_none.elements =14484 result->value->data.x_array.data.s_none.elements =
14444 create_const_vals(resolved_type->data.vector.len);14485 create_const_vals(resolved_type->data.vector.len);
1444514486
14446 expand_undef_array(ira->codegen, &result->value);14487 expand_undef_array(ira->codegen, result->value);
14447 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {14488 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
14448 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,14489 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
14449 &op1_val->data.x_array.data.s_none.elements[i],14490 &op1_val->data.x_array.data.s_none.elements[i],
14450 &op2_val->data.x_array.data.s_none.elements[i],14491 &op2_val->data.x_array.data.s_none.elements[i],
14451 bin_op_instruction, op_id, one_possible_value);14492 bin_op_instruction, op_id, one_possible_value);
14452 copy_const_val(&result->value.data.x_array.data.s_none.elements[i], &cur_res->value, false);14493 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false);
14453 }14494 }
14454 return result;14495 return result;
14455 }14496 }
1445614497
14457 // some comparisons with unsigned numbers can be evaluated14498 // some comparisons with unsigned numbers can be evaluated
14458 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {14499 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
14459 ConstExprValue *known_left_val;14500 ZigValue *known_left_val;
14460 IrBinOp flipped_op_id;14501 IrBinOp flipped_op_id;
14461 if (instr_is_comptime(casted_op1)) {14502 if (instr_is_comptime(casted_op1)) {
14462 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);14503 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);
...@@ -14495,16 +14536,16 @@ never_mind_just_calculate_it_normally:...@@ -14495,16 +14536,16 @@ never_mind_just_calculate_it_normally:
14495 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,14536 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
14496 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);14537 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
14497 if (resolved_type->id == ZigTypeIdVector) {14538 if (resolved_type->id == ZigTypeIdVector) {
14498 result->value.type = get_vector_type(ira->codegen, resolved_type->data.vector.len,14539 result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len,
14499 ira->codegen->builtin_types.entry_bool);14540 ira->codegen->builtin_types.entry_bool);
14500 } else {14541 } else {
14501 result->value.type = ira->codegen->builtin_types.entry_bool;14542 result->value->type = ira->codegen->builtin_types.entry_bool;
14502 }14543 }
14503 return result;14544 return result;
14504}14545}
1450514546
14506static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,14547static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
14507 ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val)14548 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
14508{14549{
14509 bool is_int;14550 bool is_int;
14510 bool is_float;14551 bool is_float;
...@@ -14646,7 +14687,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -14646,7 +14687,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
14646 }14687 }
14647 } else {14688 } else {
14648 float_div_trunc(out_val, op1_val, op2_val);14689 float_div_trunc(out_val, op1_val, op2_val);
14649 ConstExprValue remainder = {};14690 ZigValue remainder = {};
14650 float_rem(&remainder, op1_val, op2_val);14691 float_rem(&remainder, op1_val, op2_val);
14651 if (float_cmp_zero(&remainder) != CmpEQ) {14692 if (float_cmp_zero(&remainder) != CmpEQ) {
14652 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));14693 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));
...@@ -14684,10 +14725,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -14684,10 +14725,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
1468414725
14685// This works on operands that have already been checked to be comptime known.14726// This works on operands that have already been checked to be comptime known.
14686static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,14727static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,
14687 ZigType *type_entry, ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val)14728 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
14688{14729{
14689 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);14730 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);
14690 ConstExprValue *out_val = &result_instruction->value;14731 ZigValue *out_val = result_instruction->value;
14691 if (type_entry->id == ZigTypeIdVector) {14732 if (type_entry->id == ZigTypeIdVector) {
14692 expand_undef_array(ira->codegen, op1_val);14733 expand_undef_array(ira->codegen, op1_val);
14693 expand_undef_array(ira->codegen, op2_val);14734 expand_undef_array(ira->codegen, op2_val);
...@@ -14696,9 +14737,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -14696,9 +14737,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
14696 size_t len = type_entry->data.vector.len;14737 size_t len = type_entry->data.vector.len;
14697 ZigType *scalar_type = type_entry->data.vector.elem_type;14738 ZigType *scalar_type = type_entry->data.vector.elem_type;
14698 for (size_t i = 0; i < len; i += 1) {14739 for (size_t i = 0; i < len; i += 1) {
14699 ConstExprValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i];14740 ZigValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i];
14700 ConstExprValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i];14741 ZigValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i];
14701 ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];14742 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
14702 assert(scalar_op1_val->type == scalar_type);14743 assert(scalar_op1_val->type == scalar_type);
14703 assert(scalar_op2_val->type == scalar_type);14744 assert(scalar_op2_val->type == scalar_type);
14704 assert(scalar_out_val->type == scalar_type);14745 assert(scalar_out_val->type == scalar_type);
...@@ -14722,52 +14763,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -14722,52 +14763,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
1472214763
14723static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {14764static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
14724 IrInstruction *op1 = bin_op_instruction->op1->child;14765 IrInstruction *op1 = bin_op_instruction->op1->child;
14725 if (type_is_invalid(op1->value.type))14766 if (type_is_invalid(op1->value->type))
14726 return ira->codegen->invalid_instruction;14767 return ira->codegen->invalid_instruction;
1472714768
14728 if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) {14769 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {
14729 ir_add_error(ira, bin_op_instruction->op1,14770 ir_add_error(ira, bin_op_instruction->op1,
14730 buf_sprintf("bit shifting operation expected integer type, found '%s'",14771 buf_sprintf("bit shifting operation expected integer type, found '%s'",
14731 buf_ptr(&op1->value.type->name)));14772 buf_ptr(&op1->value->type->name)));
14732 return ira->codegen->invalid_instruction;14773 return ira->codegen->invalid_instruction;
14733 }14774 }
1473414775
14735 IrInstruction *op2 = bin_op_instruction->op2->child;14776 IrInstruction *op2 = bin_op_instruction->op2->child;
14736 if (type_is_invalid(op2->value.type))14777 if (type_is_invalid(op2->value->type))
14737 return ira->codegen->invalid_instruction;14778 return ira->codegen->invalid_instruction;
1473814779
14739 if (op2->value.type->id != ZigTypeIdInt && op2->value.type->id != ZigTypeIdComptimeInt) {14780 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {
14740 ir_add_error(ira, bin_op_instruction->op2,14781 ir_add_error(ira, bin_op_instruction->op2,
14741 buf_sprintf("shift amount has to be an integer type, but found '%s'",14782 buf_sprintf("shift amount has to be an integer type, but found '%s'",
14742 buf_ptr(&op2->value.type->name)));14783 buf_ptr(&op2->value->type->name)));
14743 return ira->codegen->invalid_instruction;14784 return ira->codegen->invalid_instruction;
14744 }14785 }
1474514786
14746 IrInstruction *casted_op2;14787 IrInstruction *casted_op2;
14747 IrBinOp op_id = bin_op_instruction->op_id;14788 IrBinOp op_id = bin_op_instruction->op_id;
14748 if (op1->value.type->id == ZigTypeIdComptimeInt) {14789 if (op1->value->type->id == ZigTypeIdComptimeInt) {
14749 casted_op2 = op2;14790 casted_op2 = op2;
1475014791
14751 if (op_id == IrBinOpBitShiftLeftLossy) {14792 if (op_id == IrBinOpBitShiftLeftLossy) {
14752 op_id = IrBinOpBitShiftLeftExact;14793 op_id = IrBinOpBitShiftLeftExact;
14753 }14794 }
1475414795
14755 if (casted_op2->value.data.x_bigint.is_negative) {14796 if (casted_op2->value->data.x_bigint.is_negative) {
14756 Buf *val_buf = buf_alloc();14797 Buf *val_buf = buf_alloc();
14757 bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10);14798 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);
14758 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));14799 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
14759 return ira->codegen->invalid_instruction;14800 return ira->codegen->invalid_instruction;
14760 }14801 }
14761 } else {14802 } else {
14762 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,14803 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
14763 op1->value.type->data.integral.bit_count - 1);14804 op1->value->type->data.integral.bit_count - 1);
14764 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&14805 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
14765 op2->value.type->id == ZigTypeIdComptimeInt) {14806 op2->value->type->id == ZigTypeIdComptimeInt) {
14766 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,14807 if (!bigint_fits_in_bits(&op2->value->data.x_bigint,
14767 shift_amt_type->data.integral.bit_count,14808 shift_amt_type->data.integral.bit_count,
14768 op2->value.data.x_bigint.is_negative)) {14809 op2->value->data.x_bigint.is_negative)) {
14769 Buf *val_buf = buf_alloc();14810 Buf *val_buf = buf_alloc();
14770 bigint_append_buf(val_buf, &op2->value.data.x_bigint, 10);14811 bigint_append_buf(val_buf, &op2->value->data.x_bigint, 10);
14771 ErrorMsg* msg = ir_add_error(ira,14812 ErrorMsg* msg = ir_add_error(ira,
14772 &bin_op_instruction->base,14813 &bin_op_instruction->base,
14773 buf_sprintf("RHS of shift is too large for LHS type"));14814 buf_sprintf("RHS of shift is too large for LHS type"));
...@@ -14788,30 +14829,30 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -14788,30 +14829,30 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
14788 }14829 }
1478914830
14790 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {14831 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
14791 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);14832 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14792 if (op1_val == nullptr)14833 if (op1_val == nullptr)
14793 return ira->codegen->invalid_instruction;14834 return ira->codegen->invalid_instruction;
1479414835
14795 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);14836 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
14796 if (op2_val == nullptr)14837 if (op2_val == nullptr)
14797 return ira->codegen->invalid_instruction;14838 return ira->codegen->invalid_instruction;
1479814839
14799 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value.type, op1_val, op_id, op2_val);14840 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val);
14800 } else if (op1->value.type->id == ZigTypeIdComptimeInt) {14841 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {
14801 ir_add_error(ira, &bin_op_instruction->base,14842 ir_add_error(ira, &bin_op_instruction->base,
14802 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));14843 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
14803 return ira->codegen->invalid_instruction;14844 return ira->codegen->invalid_instruction;
14804 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) {14845 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {
14805 IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,14846 IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,
14806 bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop);14847 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
14807 result->value.type = op1->value.type;14848 result->value->type = op1->value->type;
14808 return result;14849 return result;
14809 }14850 }
1481014851
14811 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,14852 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
14812 bin_op_instruction->base.source_node, op_id,14853 bin_op_instruction->base.source_node, op_id,
14813 op1, casted_op2, bin_op_instruction->safety_check_on);14854 op1, casted_op2, bin_op_instruction->safety_check_on);
14814 result->value.type = op1->value.type;14855 result->value->type = op1->value->type;
14815 return result;14856 return result;
14816}14857}
1481714858
...@@ -14880,42 +14921,42 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14880,42 +14921,42 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14880 Error err;14921 Error err;
1488114922
14882 IrInstruction *op1 = instruction->op1->child;14923 IrInstruction *op1 = instruction->op1->child;
14883 if (type_is_invalid(op1->value.type))14924 if (type_is_invalid(op1->value->type))
14884 return ira->codegen->invalid_instruction;14925 return ira->codegen->invalid_instruction;
1488514926
14886 IrInstruction *op2 = instruction->op2->child;14927 IrInstruction *op2 = instruction->op2->child;
14887 if (type_is_invalid(op2->value.type))14928 if (type_is_invalid(op2->value->type))
14888 return ira->codegen->invalid_instruction;14929 return ira->codegen->invalid_instruction;
1488914930
14890 IrBinOp op_id = instruction->op_id;14931 IrBinOp op_id = instruction->op_id;
1489114932
14892 // look for pointer math14933 // look for pointer math
14893 if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) {14934 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {
14894 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);14935 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
14895 if (type_is_invalid(casted_op2->value.type))14936 if (type_is_invalid(casted_op2->value->type))
14896 return ira->codegen->invalid_instruction;14937 return ira->codegen->invalid_instruction;
1489714938
14898 // If either operand is undef, result is undef.14939 // If either operand is undef, result is undef.
14899 ConstExprValue *op1_val = nullptr;14940 ZigValue *op1_val = nullptr;
14900 ConstExprValue *op2_val = nullptr;14941 ZigValue *op2_val = nullptr;
14901 if (instr_is_comptime(op1)) {14942 if (instr_is_comptime(op1)) {
14902 op1_val = ir_resolve_const(ira, op1, UndefOk);14943 op1_val = ir_resolve_const(ira, op1, UndefOk);
14903 if (op1_val == nullptr)14944 if (op1_val == nullptr)
14904 return ira->codegen->invalid_instruction;14945 return ira->codegen->invalid_instruction;
14905 if (op1_val->special == ConstValSpecialUndef)14946 if (op1_val->special == ConstValSpecialUndef)
14906 return ir_const_undef(ira, &instruction->base, op1->value.type);14947 return ir_const_undef(ira, &instruction->base, op1->value->type);
14907 }14948 }
14908 if (instr_is_comptime(casted_op2)) {14949 if (instr_is_comptime(casted_op2)) {
14909 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);14950 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
14910 if (op2_val == nullptr)14951 if (op2_val == nullptr)
14911 return ira->codegen->invalid_instruction;14952 return ira->codegen->invalid_instruction;
14912 if (op2_val->special == ConstValSpecialUndef)14953 if (op2_val->special == ConstValSpecialUndef)
14913 return ir_const_undef(ira, &instruction->base, op1->value.type);14954 return ir_const_undef(ira, &instruction->base, op1->value->type);
14914 }14955 }
1491514956
14916 if (op2_val != nullptr && op1_val != nullptr &&14957 if (op2_val != nullptr && op1_val != nullptr &&
14917 (op1->value.data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||14958 (op1->value->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
14918 op1->value.data.x_ptr.special == ConstPtrSpecialNull))14959 op1->value->data.x_ptr.special == ConstPtrSpecialNull))
14919 {14960 {
14920 uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ?14961 uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ?
14921 0 : op1_val->data.x_ptr.data.hard_coded_addr.addr;14962 0 : op1_val->data.x_ptr.data.hard_coded_addr.addr;
...@@ -14935,15 +14976,15 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14935,15 +14976,15 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14935 zig_unreachable();14976 zig_unreachable();
14936 }14977 }
14937 IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type);14978 IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type);
14938 result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;14979 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
14939 result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;14980 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
14940 result->value.data.x_ptr.data.hard_coded_addr.addr = new_addr;14981 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
14941 return result;14982 return result;
14942 }14983 }
1494314984
14944 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,14985 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
14945 instruction->base.source_node, op_id, op1, casted_op2, true);14986 instruction->base.source_node, op_id, op1, casted_op2, true);
14946 result->value.type = op1->value.type;14987 result->value->type = op1->value->type;
14947 return result;14988 return result;
14948 }14989 }
1494914990
...@@ -14958,21 +14999,21 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14958,21 +14999,21 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14958 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||14999 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
14959 resolved_type->id == ZigTypeIdFloat ||15000 resolved_type->id == ZigTypeIdFloat ||
14960 (resolved_type->id == ZigTypeIdComptimeFloat &&15001 (resolved_type->id == ZigTypeIdComptimeFloat &&
14961 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=15002 ((bigfloat_cmp_zero(&op1->value->data.x_bigfloat) != CmpGT) !=
14962 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||15003 (bigfloat_cmp_zero(&op2->value->data.x_bigfloat) != CmpGT))) ||
14963 (resolved_type->id == ZigTypeIdComptimeInt &&15004 (resolved_type->id == ZigTypeIdComptimeInt &&
14964 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=15005 ((bigint_cmp_zero(&op1->value->data.x_bigint) != CmpGT) !=
14965 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))15006 (bigint_cmp_zero(&op2->value->data.x_bigint) != CmpGT)))
14966 );15007 );
14967 if (op_id == IrBinOpDivUnspecified && is_int) {15008 if (op_id == IrBinOpDivUnspecified && is_int) {
14968 if (is_signed_div) {15009 if (is_signed_div) {
14969 bool ok = false;15010 bool ok = false;
14970 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {15011 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
14971 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);15012 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14972 if (op1_val == nullptr)15013 if (op1_val == nullptr)
14973 return ira->codegen->invalid_instruction;15014 return ira->codegen->invalid_instruction;
1497415015
14975 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);15016 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
14976 if (op2_val == nullptr)15017 if (op2_val == nullptr)
14977 return ira->codegen->invalid_instruction;15018 return ira->codegen->invalid_instruction;
1497815019
...@@ -14995,8 +15036,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14995,8 +15036,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14995 if (!ok) {15036 if (!ok) {
14996 ir_add_error(ira, &instruction->base,15037 ir_add_error(ira, &instruction->base,
14997 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",15038 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
14998 buf_ptr(&op1->value.type->name),15039 buf_ptr(&op1->value->type->name),
14999 buf_ptr(&op2->value.type->name)));15040 buf_ptr(&op2->value->type->name)));
15000 return ira->codegen->invalid_instruction;15041 return ira->codegen->invalid_instruction;
15001 }15042 }
15002 } else {15043 } else {
...@@ -15006,16 +15047,16 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15006,16 +15047,16 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15006 if (is_signed_div && (is_int || is_float)) {15047 if (is_signed_div && (is_int || is_float)) {
15007 bool ok = false;15048 bool ok = false;
15008 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {15049 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15009 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);15050 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15010 if (op1_val == nullptr)15051 if (op1_val == nullptr)
15011 return ira->codegen->invalid_instruction;15052 return ira->codegen->invalid_instruction;
1501215053
15013 if (is_int) {15054 if (is_int) {
15014 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);15055 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15015 if (op2_val == nullptr)15056 if (op2_val == nullptr)
15016 return ira->codegen->invalid_instruction;15057 return ira->codegen->invalid_instruction;
1501715058
15018 if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) {15059 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {
15019 // the division by zero error will be caught later, but we don't15060 // the division by zero error will be caught later, but we don't
15020 // have a remainder function ambiguity problem15061 // have a remainder function ambiguity problem
15021 ok = true;15062 ok = true;
...@@ -15031,17 +15072,17 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15031,17 +15072,17 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15031 if (casted_op2 == ira->codegen->invalid_instruction)15072 if (casted_op2 == ira->codegen->invalid_instruction)
15032 return ira->codegen->invalid_instruction;15073 return ira->codegen->invalid_instruction;
1503315074
15034 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15075 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15035 if (op2_val == nullptr)15076 if (op2_val == nullptr)
15036 return ira->codegen->invalid_instruction;15077 return ira->codegen->invalid_instruction;
1503715078
15038 if (float_cmp_zero(&casted_op2->value) == CmpEQ) {15079 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
15039 // the division by zero error will be caught later, but we don't15080 // the division by zero error will be caught later, but we don't
15040 // have a remainder function ambiguity problem15081 // have a remainder function ambiguity problem
15041 ok = true;15082 ok = true;
15042 } else {15083 } else {
15043 ConstExprValue rem_result = {};15084 ZigValue rem_result = {};
15044 ConstExprValue mod_result = {};15085 ZigValue mod_result = {};
15045 float_rem(&rem_result, op1_val, op2_val);15086 float_rem(&rem_result, op1_val, op2_val);
15046 float_mod(&mod_result, op1_val, op2_val);15087 float_mod(&mod_result, op1_val, op2_val);
15047 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;15088 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;
...@@ -15051,8 +15092,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15051,8 +15092,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15051 if (!ok) {15092 if (!ok) {
15052 ir_add_error(ira, &instruction->base,15093 ir_add_error(ira, &instruction->base,
15053 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",15094 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
15054 buf_ptr(&op1->value.type->name),15095 buf_ptr(&op1->value->type->name),
15055 buf_ptr(&op2->value.type->name)));15096 buf_ptr(&op2->value->type->name)));
15056 return ira->codegen->invalid_instruction;15097 return ira->codegen->invalid_instruction;
15057 }15098 }
15058 }15099 }
...@@ -15076,8 +15117,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15076,8 +15117,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15076 AstNode *source_node = instruction->base.source_node;15117 AstNode *source_node = instruction->base.source_node;
15077 ir_add_error_node(ira, source_node,15118 ir_add_error_node(ira, source_node,
15078 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",15119 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
15079 buf_ptr(&op1->value.type->name),15120 buf_ptr(&op1->value->type->name),
15080 buf_ptr(&op2->value.type->name)));15121 buf_ptr(&op2->value->type->name)));
15081 return ira->codegen->invalid_instruction;15122 return ira->codegen->invalid_instruction;
15082 }15123 }
1508315124
...@@ -15100,10 +15141,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15100,10 +15141,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15100 return ira->codegen->invalid_instruction;15141 return ira->codegen->invalid_instruction;
1510115142
15102 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {15143 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
15103 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);15144 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
15104 if (op1_val == nullptr)15145 if (op1_val == nullptr)
15105 return ira->codegen->invalid_instruction;15146 return ira->codegen->invalid_instruction;
15106 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15147 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15107 if (op2_val == nullptr)15148 if (op2_val == nullptr)
15108 return ira->codegen->invalid_instruction;15149 return ira->codegen->invalid_instruction;
1510915150
...@@ -15112,31 +15153,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15112,31 +15153,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1511215153
15113 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,15154 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
15114 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);15155 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);
15115 result->value.type = resolved_type;15156 result->value->type = resolved_type;
15116 return result;15157 return result;
15117}15158}
1511815159
15119static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {15160static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
15120 IrInstruction *op1 = instruction->op1->child;15161 IrInstruction *op1 = instruction->op1->child;
15121 ZigType *op1_type = op1->value.type;15162 ZigType *op1_type = op1->value->type;
15122 if (type_is_invalid(op1_type))15163 if (type_is_invalid(op1_type))
15123 return ira->codegen->invalid_instruction;15164 return ira->codegen->invalid_instruction;
1512415165
15125 IrInstruction *op2 = instruction->op2->child;15166 IrInstruction *op2 = instruction->op2->child;
15126 ZigType *op2_type = op2->value.type;15167 ZigType *op2_type = op2->value->type;
15127 if (type_is_invalid(op2_type))15168 if (type_is_invalid(op2_type))
15128 return ira->codegen->invalid_instruction;15169 return ira->codegen->invalid_instruction;
1512915170
15130 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);15171 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15131 if (!op1_val)15172 if (!op1_val)
15132 return ira->codegen->invalid_instruction;15173 return ira->codegen->invalid_instruction;
1513315174
15134 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);15175 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15135 if (!op2_val)15176 if (!op2_val)
15136 return ira->codegen->invalid_instruction;15177 return ira->codegen->invalid_instruction;
1513715178
15138 ConstExprValue *sentinel1 = nullptr;15179 ZigValue *sentinel1 = nullptr;
15139 ConstExprValue *op1_array_val;15180 ZigValue *op1_array_val;
15140 size_t op1_array_index;15181 size_t op1_array_index;
15141 size_t op1_array_end;15182 size_t op1_array_end;
15142 ZigType *child_type;15183 ZigType *child_type;
...@@ -15159,11 +15200,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15159,11 +15200,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15159 } else if (is_slice(op1_type)) {15200 } else if (is_slice(op1_type)) {
15160 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;15201 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
15161 child_type = ptr_type->data.pointer.child_type;15202 child_type = ptr_type->data.pointer.child_type;
15162 ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];15203 ZigValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];
15163 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);15204 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
15164 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;15205 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
15165 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;15206 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
15166 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];15207 ZigValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
15167 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);15208 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
15168 sentinel1 = ptr_type->data.pointer.sentinel;15209 sentinel1 = ptr_type->data.pointer.sentinel;
15169 } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle &&15210 } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle &&
...@@ -15178,13 +15219,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15178,13 +15219,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15178 op1_array_end = array_type->data.array.len;15219 op1_array_end = array_type->data.array.len;
15179 sentinel1 = array_type->data.array.sentinel;15220 sentinel1 = array_type->data.array.sentinel;
15180 } else {15221 } else {
15181 ir_add_error(ira, op1,15222 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
15182 buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name)));
15183 return ira->codegen->invalid_instruction;15223 return ira->codegen->invalid_instruction;
15184 }15224 }
1518515225
15186 ConstExprValue *sentinel2 = nullptr;15226 ZigValue *sentinel2 = nullptr;
15187 ConstExprValue *op2_array_val;15227 ZigValue *op2_array_val;
15188 size_t op2_array_index;15228 size_t op2_array_index;
15189 size_t op2_array_end;15229 size_t op2_array_end;
15190 bool op2_type_valid;15230 bool op2_type_valid;
...@@ -15207,11 +15247,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15207,11 +15247,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15207 } else if (is_slice(op2_type)) {15247 } else if (is_slice(op2_type)) {
15208 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;15248 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
15209 op2_type_valid = ptr_type->data.pointer.child_type == child_type;15249 op2_type_valid = ptr_type->data.pointer.child_type == child_type;
15210 ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];15250 ZigValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];
15211 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);15251 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
15212 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;15252 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
15213 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;15253 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
15214 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];15254 ZigValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
15215 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);15255 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
1521615256
15217 sentinel2 = ptr_type->data.pointer.sentinel;15257 sentinel2 = ptr_type->data.pointer.sentinel;
...@@ -15229,17 +15269,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15229,17 +15269,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15229 sentinel2 = array_type->data.array.sentinel;15269 sentinel2 = array_type->data.array.sentinel;
15230 } else {15270 } else {
15231 ir_add_error(ira, op2,15271 ir_add_error(ira, op2,
15232 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));15272 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
15233 return ira->codegen->invalid_instruction;15273 return ira->codegen->invalid_instruction;
15234 }15274 }
15235 if (!op2_type_valid) {15275 if (!op2_type_valid) {
15236 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",15276 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
15237 buf_ptr(&child_type->name),15277 buf_ptr(&child_type->name),
15238 buf_ptr(&op2->value.type->name)));15278 buf_ptr(&op2->value->type->name)));
15239 return ira->codegen->invalid_instruction;15279 return ira->codegen->invalid_instruction;
15240 }15280 }
1524115281
15242 ConstExprValue *sentinel;15282 ZigValue *sentinel;
15243 if (sentinel1 != nullptr && sentinel2 != nullptr) {15283 if (sentinel1 != nullptr && sentinel2 != nullptr) {
15244 // When there is a sentinel mismatch, no sentinel on the result. The type system15284 // When there is a sentinel mismatch, no sentinel on the result. The type system
15245 // will catch this if it is a problem.15285 // will catch this if it is a problem.
...@@ -15254,13 +15294,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15254,13 +15294,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1525415294
15255 // The type of result is populated in the following if blocks15295 // The type of result is populated in the following if blocks
15256 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);15296 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
15257 ConstExprValue *out_val = &result->value;15297 ZigValue *out_val = result->value;
1525815298
15259 ConstExprValue *out_array_val;15299 ZigValue *out_array_val;
15260 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);15300 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
15261 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {15301 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15262 result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel);15302 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15263
15264 out_array_val = out_val;15303 out_array_val = out_val;
15265 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {15304 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
15266 out_array_val = create_const_vals(1);15305 out_array_val = create_const_vals(1);
...@@ -15274,7 +15313,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15274,7 +15313,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15274 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type,15313 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type,
15275 true, false, PtrLenUnknown, 0, 0, 0, false,15314 true, false, PtrLenUnknown, 0, 0, 0, false,
15276 VECTOR_INDEX_NONE, nullptr, sentinel);15315 VECTOR_INDEX_NONE, nullptr, sentinel);
15277 result->value.type = get_slice_type(ira->codegen, ptr_type);15316 result->value->type = get_slice_type(ira->codegen, ptr_type);
15278 out_array_val = create_const_vals(1);15317 out_array_val = create_const_vals(1);
15279 out_array_val->special = ConstValSpecialStatic;15318 out_array_val->special = ConstValSpecialStatic;
15280 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);15319 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
...@@ -15291,9 +15330,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15291,9 +15330,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15291 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;15330 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
15292 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);15331 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
15293 } else {15332 } else {
15294 result->value.type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,15333 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
15295 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);15334 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
15296
15297 out_array_val = create_const_vals(1);15335 out_array_val = create_const_vals(1);
15298 out_array_val->special = ConstValSpecialStatic;15336 out_array_val->special = ConstValSpecialStatic;
15299 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);15337 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
...@@ -15317,21 +15355,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15317,21 +15355,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1531715355
15318 size_t next_index = 0;15356 size_t next_index = 0;
15319 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {15357 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
15320 ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15358 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15321 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);15359 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);
15322 elem_dest_val->parent.id = ConstParentIdArray;15360 elem_dest_val->parent.id = ConstParentIdArray;
15323 elem_dest_val->parent.data.p_array.array_val = out_array_val;15361 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15324 elem_dest_val->parent.data.p_array.elem_index = next_index;15362 elem_dest_val->parent.data.p_array.elem_index = next_index;
15325 }15363 }
15326 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {15364 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
15327 ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15365 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15328 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);15366 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);
15329 elem_dest_val->parent.id = ConstParentIdArray;15367 elem_dest_val->parent.id = ConstParentIdArray;
15330 elem_dest_val->parent.data.p_array.array_val = out_array_val;15368 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15331 elem_dest_val->parent.data.p_array.elem_index = next_index;15369 elem_dest_val->parent.data.p_array.elem_index = next_index;
15332 }15370 }
15333 if (next_index < full_len) {15371 if (next_index < full_len) {
15334 ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15372 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15335 copy_const_val(elem_dest_val, sentinel, false);15373 copy_const_val(elem_dest_val, sentinel, false);
15336 elem_dest_val->parent.id = ConstParentIdArray;15374 elem_dest_val->parent.id = ConstParentIdArray;
15337 elem_dest_val->parent.data.p_array.array_val = out_array_val;15375 elem_dest_val->parent.data.p_array.array_val = out_array_val;
...@@ -15345,34 +15383,34 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15345,34 +15383,34 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1534515383
15346static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {15384static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
15347 IrInstruction *op1 = instruction->op1->child;15385 IrInstruction *op1 = instruction->op1->child;
15348 if (type_is_invalid(op1->value.type))15386 if (type_is_invalid(op1->value->type))
15349 return ira->codegen->invalid_instruction;15387 return ira->codegen->invalid_instruction;
1535015388
15351 IrInstruction *op2 = instruction->op2->child;15389 IrInstruction *op2 = instruction->op2->child;
15352 if (type_is_invalid(op2->value.type))15390 if (type_is_invalid(op2->value->type))
15353 return ira->codegen->invalid_instruction;15391 return ira->codegen->invalid_instruction;
1535415392
15355 bool want_ptr_to_array = false;15393 bool want_ptr_to_array = false;
15356 ZigType *array_type;15394 ZigType *array_type;
15357 ConstExprValue *array_val;15395 ZigValue *array_val;
15358 if (op1->value.type->id == ZigTypeIdArray) {15396 if (op1->value->type->id == ZigTypeIdArray) {
15359 array_type = op1->value.type;15397 array_type = op1->value->type;
15360 array_val = ir_resolve_const(ira, op1, UndefOk);15398 array_val = ir_resolve_const(ira, op1, UndefOk);
15361 if (array_val == nullptr)15399 if (array_val == nullptr)
15362 return ira->codegen->invalid_instruction;15400 return ira->codegen->invalid_instruction;
15363 } else if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenSingle &&15401 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
15364 op1->value.type->data.pointer.child_type->id == ZigTypeIdArray)15402 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
15365 {15403 {
15366 array_type = op1->value.type->data.pointer.child_type;15404 array_type = op1->value->type->data.pointer.child_type;
15367 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);15405 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);
15368 if (type_is_invalid(array_inst->value.type))15406 if (type_is_invalid(array_inst->value->type))
15369 return ira->codegen->invalid_instruction;15407 return ira->codegen->invalid_instruction;
15370 array_val = ir_resolve_const(ira, array_inst, UndefOk);15408 array_val = ir_resolve_const(ira, array_inst, UndefOk);
15371 if (array_val == nullptr)15409 if (array_val == nullptr)
15372 return ira->codegen->invalid_instruction;15410 return ira->codegen->invalid_instruction;
15373 want_ptr_to_array = true;15411 want_ptr_to_array = true;
15374 } else {15412 } else {
15375 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));15413 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
15376 return ira->codegen->invalid_instruction;15414 return ira->codegen->invalid_instruction;
15377 }15415 }
1537815416
...@@ -15397,7 +15435,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15397,7 +15435,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15397 array_result = ir_const_undef(ira, &instruction->base, result_array_type);15435 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
15398 } else {15436 } else {
15399 array_result = ir_const(ira, &instruction->base, result_array_type);15437 array_result = ir_const(ira, &instruction->base, result_array_type);
15400 ConstExprValue *out_val = &array_result->value;15438 ZigValue *out_val = array_result->value;
1540115439
15402 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {15440 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
15403 case OnePossibleValueInvalid:15441 case OnePossibleValueInvalid:
...@@ -15416,7 +15454,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15416,7 +15454,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15416 uint64_t i = 0;15454 uint64_t i = 0;
15417 for (uint64_t x = 0; x < mult_amt; x += 1) {15455 for (uint64_t x = 0; x < mult_amt; x += 1) {
15418 for (uint64_t y = 0; y < old_array_len; y += 1) {15456 for (uint64_t y = 0; y < old_array_len; y += 1) {
15419 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15457 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15420 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);15458 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15421 elem_dest_val->parent.id = ConstParentIdArray;15459 elem_dest_val->parent.id = ConstParentIdArray;
15422 elem_dest_val->parent.data.p_array.array_val = out_val;15460 elem_dest_val->parent.data.p_array.array_val = out_val;
...@@ -15427,7 +15465,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15427,7 +15465,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15427 assert(i == new_array_len);15465 assert(i == new_array_len);
1542815466
15429 if (array_type->data.array.sentinel != nullptr) {15467 if (array_type->data.array.sentinel != nullptr) {
15430 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15468 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15431 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);15469 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);
15432 elem_dest_val->parent.id = ConstParentIdArray;15470 elem_dest_val->parent.id = ConstParentIdArray;
15433 elem_dest_val->parent.data.p_array.array_val = out_val;15471 elem_dest_val->parent.data.p_array.array_val = out_val;
...@@ -15554,25 +15592,25 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15554,25 +15592,25 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
15554 IrInstruction *var_ptr = decl_var_instruction->ptr->child;15592 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
15555 // if this is null, a compiler error happened and did not initialize the variable.15593 // if this is null, a compiler error happened and did not initialize the variable.
15556 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.15594 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
15557 if (var_ptr == nullptr || type_is_invalid(var_ptr->value.type)) {15595 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
15558 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);15596 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);
15559 var->var_type = ira->codegen->builtin_types.entry_invalid;15597 var->var_type = ira->codegen->builtin_types.entry_invalid;
15560 return ira->codegen->invalid_instruction;15598 return ira->codegen->invalid_instruction;
15561 }15599 }
1556215600
15563 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.15601 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
15564 ir_assert(var_ptr->value.type->id == ZigTypeIdPointer, &decl_var_instruction->base);15602 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base);
1556515603
15566 ZigType *result_type = var_ptr->value.type->data.pointer.child_type;15604 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
15567 if (type_is_invalid(result_type)) {15605 if (type_is_invalid(result_type)) {
15568 result_type = ira->codegen->builtin_types.entry_invalid;15606 result_type = ira->codegen->builtin_types.entry_invalid;
15569 } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) {15607 } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) {
15570 zig_unreachable();15608 zig_unreachable();
15571 }15609 }
1557215610
15573 ConstExprValue *init_val = nullptr;15611 ZigValue *init_val = nullptr;
15574 if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {15612 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15575 init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node);15613 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node);
15576 if (is_comptime_var) {15614 if (is_comptime_var) {
15577 if (var->gen_is_const) {15615 if (var->gen_is_const) {
15578 var->const_value = init_val;15616 var->const_value = init_val;
...@@ -15631,7 +15669,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15631,7 +15669,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
15631 new_var->owner_exec = var->owner_exec;15669 new_var->owner_exec = var->owner_exec;
15632 new_var->align_bytes = var->align_bytes;15670 new_var->align_bytes = var->align_bytes;
15633 if (var->mem_slot_index != SIZE_MAX) {15671 if (var->mem_slot_index != SIZE_MAX) {
15634 ConstExprValue *vals = create_const_vals(1);15672 ZigValue *vals = create_const_vals(1);
15635 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;15673 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;
15636 ira->exec_context.mem_slot_list.append(vals);15674 ira->exec_context.mem_slot_list.append(vals);
15637 }15675 }
...@@ -15665,29 +15703,29 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15665,29 +15703,29 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
15665 if (init_val != nullptr && value_is_comptime(init_val)) {15703 if (init_val != nullptr && value_is_comptime(init_val)) {
15666 // Resolve ConstPtrMutInfer15704 // Resolve ConstPtrMutInfer
15667 if (var->gen_is_const) {15705 if (var->gen_is_const) {
15668 var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeConst;15706 var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
15669 } else if (is_comptime_var) {15707 } else if (is_comptime_var) {
15670 var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar;15708 var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
15671 } else {15709 } else {
15672 // we need a runtime ptr but we have a comptime val.15710 // we need a runtime ptr but we have a comptime val.
15673 // since it's a comptime val there are no instructions for it.15711 // since it's a comptime val there are no instructions for it.
15674 // we memcpy the init value here15712 // we memcpy the init value here
15675 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);15713 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);
15676 if (type_is_invalid(deref->value.type)) {15714 if (type_is_invalid(deref->value->type)) {
15677 var->var_type = ira->codegen->builtin_types.entry_invalid;15715 var->var_type = ira->codegen->builtin_types.entry_invalid;
15678 return ira->codegen->invalid_instruction;15716 return ira->codegen->invalid_instruction;
15679 }15717 }
15680 // If this assertion trips, something is wrong with the IR instructions, because15718 // If this assertion trips, something is wrong with the IR instructions, because
15681 // we expected the above deref to return a constant value, but it created a runtime15719 // we expected the above deref to return a constant value, but it created a runtime
15682 // instruction.15720 // instruction.
15683 assert(deref->value.special != ConstValSpecialRuntime);15721 assert(deref->value->special != ConstValSpecialRuntime);
15684 var_ptr->value.special = ConstValSpecialRuntime;15722 var_ptr->value->special = ConstValSpecialRuntime;
15685 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);15723 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);
15686 }15724 }
1568715725
15688 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {15726 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
15689 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);15727 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
15690 ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);15728 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
15691 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);15729 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
1569215730
15693 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {15731 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
...@@ -15718,7 +15756,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15718,7 +15756,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15718 }15756 }
1571915757
15720 IrInstruction *target = instruction->target->child;15758 IrInstruction *target = instruction->target->child;
15721 if (type_is_invalid(target->value.type)) {15759 if (type_is_invalid(target->value->type)) {
15722 return ira->codegen->invalid_instruction;15760 return ira->codegen->invalid_instruction;
15723 }15761 }
1572415762
...@@ -15748,13 +15786,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15748,13 +15786,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15748 }15786 }
1574915787
15750 bool want_var_export = false;15788 bool want_var_export = false;
15751 switch (target->value.type->id) {15789 switch (target->value->type->id) {
15752 case ZigTypeIdInvalid:15790 case ZigTypeIdInvalid:
15753 case ZigTypeIdUnreachable:15791 case ZigTypeIdUnreachable:
15754 zig_unreachable();15792 zig_unreachable();
15755 case ZigTypeIdFn: {15793 case ZigTypeIdFn: {
15756 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);15794 assert(target->value->data.x_ptr.special == ConstPtrSpecialFunction);
15757 ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;15795 ZigFn *fn_entry = target->value->data.x_ptr.data.fn.fn_entry;
15758 tld_fn->fn_entry = fn_entry;15796 tld_fn->fn_entry = fn_entry;
15759 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;15797 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
15760 switch (cc) {15798 switch (cc) {
...@@ -15778,51 +15816,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15778,51 +15816,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15778 }15816 }
15779 } break;15817 } break;
15780 case ZigTypeIdStruct:15818 case ZigTypeIdStruct:
15781 if (is_slice(target->value.type)) {15819 if (is_slice(target->value->type)) {
15782 ir_add_error(ira, target,15820 ir_add_error(ira, target,
15783 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));15821 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
15784 } else if (target->value.type->data.structure.layout != ContainerLayoutExtern) {15822 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
15785 ErrorMsg *msg = ir_add_error(ira, target,15823 ErrorMsg *msg = ir_add_error(ira, target,
15786 buf_sprintf("exported struct value must be declared extern"));15824 buf_sprintf("exported struct value must be declared extern"));
15787 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));15825 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
15788 } else {15826 } else {
15789 want_var_export = true;15827 want_var_export = true;
15790 }15828 }
15791 break;15829 break;
15792 case ZigTypeIdUnion:15830 case ZigTypeIdUnion:
15793 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {15831 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
15794 ErrorMsg *msg = ir_add_error(ira, target,15832 ErrorMsg *msg = ir_add_error(ira, target,
15795 buf_sprintf("exported union value must be declared extern"));15833 buf_sprintf("exported union value must be declared extern"));
15796 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));15834 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
15797 } else {15835 } else {
15798 want_var_export = true;15836 want_var_export = true;
15799 }15837 }
15800 break;15838 break;
15801 case ZigTypeIdEnum:15839 case ZigTypeIdEnum:
15802 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {15840 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
15803 ErrorMsg *msg = ir_add_error(ira, target,15841 ErrorMsg *msg = ir_add_error(ira, target,
15804 buf_sprintf("exported enum value must be declared extern"));15842 buf_sprintf("exported enum value must be declared extern"));
15805 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));15843 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
15806 } else {15844 } else {
15807 want_var_export = true;15845 want_var_export = true;
15808 }15846 }
15809 break;15847 break;
15810 case ZigTypeIdArray: {15848 case ZigTypeIdArray: {
15811 bool ok_type;15849 bool ok_type;
15812 if ((err = type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type, &ok_type)))15850 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))
15813 return ira->codegen->invalid_instruction;15851 return ira->codegen->invalid_instruction;
1581415852
15815 if (!ok_type) {15853 if (!ok_type) {
15816 ir_add_error(ira, target,15854 ir_add_error(ira, target,
15817 buf_sprintf("array element type '%s' not extern-compatible",15855 buf_sprintf("array element type '%s' not extern-compatible",
15818 buf_ptr(&target->value.type->data.array.child_type->name)));15856 buf_ptr(&target->value->type->data.array.child_type->name)));
15819 } else {15857 } else {
15820 want_var_export = true;15858 want_var_export = true;
15821 }15859 }
15822 break;15860 break;
15823 }15861 }
15824 case ZigTypeIdMetaType: {15862 case ZigTypeIdMetaType: {
15825 ZigType *type_value = target->value.data.x_type;15863 ZigType *type_value = target->value->data.x_type;
15826 switch (type_value->id) {15864 switch (type_value->id) {
15827 case ZigTypeIdInvalid:15865 case ZigTypeIdInvalid:
15828 zig_unreachable();15866 zig_unreachable();
...@@ -15898,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15898,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15898 case ZigTypeIdErrorUnion:15936 case ZigTypeIdErrorUnion:
15899 case ZigTypeIdErrorSet:15937 case ZigTypeIdErrorSet:
15900 case ZigTypeIdVector:15938 case ZigTypeIdVector:
15901 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));15939 zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name));
15902 case ZigTypeIdBoundFn:15940 case ZigTypeIdBoundFn:
15903 case ZigTypeIdArgTuple:15941 case ZigTypeIdArgTuple:
15904 case ZigTypeIdOpaque:15942 case ZigTypeIdOpaque:
...@@ -15906,7 +15944,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15906,7 +15944,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15906 case ZigTypeIdFnFrame:15944 case ZigTypeIdFnFrame:
15907 case ZigTypeIdAnyFrame:15945 case ZigTypeIdAnyFrame:
15908 ir_add_error(ira, target,15946 ir_add_error(ira, target,
15909 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));15947 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
15910 break;15948 break;
15911 }15949 }
1591215950
...@@ -15936,7 +15974,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -15936,7 +15974,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
15936 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);15974 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
15937 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {15975 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
15938 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);15976 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);
15939 ConstExprValue *out_val = &result->value;15977 ZigValue *out_val = result->value;
15940 assert(get_codegen_ptr_type(optional_type) != nullptr);15978 assert(get_codegen_ptr_type(optional_type) != nullptr);
15941 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;15979 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
15942 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;15980 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
...@@ -15944,13 +15982,13 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -15944,13 +15982,13 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
15944 }15982 }
15945 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,15983 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
15946 instruction->base.source_node, instruction->optional);15984 instruction->base.source_node, instruction->optional);
15947 new_instruction->value.type = optional_type;15985 new_instruction->value->type = optional_type;
15948 return new_instruction;15986 return new_instruction;
15949 } else {15987 } else {
15950 assert(ira->codegen->have_err_ret_tracing);15988 assert(ira->codegen->have_err_ret_tracing);
15951 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,15989 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
15952 instruction->base.source_node, instruction->optional);15990 instruction->base.source_node, instruction->optional);
15953 new_instruction->value.type = ptr_to_stack_trace_type;15991 new_instruction->value->type = ptr_to_stack_trace_type;
15954 return new_instruction;15992 return new_instruction;
15955 }15993 }
15956}15994}
...@@ -15959,11 +15997,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -15959,11 +15997,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
15959 IrInstructionErrorUnion *instruction)15997 IrInstructionErrorUnion *instruction)
15960{15998{
15961 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);15999 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
15962 result->value.special = ConstValSpecialLazy;16000 result->value->special = ConstValSpecialLazy;
1596316001
15964 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1);16002 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1);
15965 lazy_err_union_type->ira = ira;16003 lazy_err_union_type->ira = ira;
15966 result->value.data.x_lazy = &lazy_err_union_type->base;16004 result->value->data.x_lazy = &lazy_err_union_type->base;
15967 lazy_err_union_type->base.id = LazyValueIdErrUnionType;16005 lazy_err_union_type->base.id = LazyValueIdErrUnionType;
1596816006
15969 lazy_err_union_type->err_set_type = instruction->err_set->child;16007 lazy_err_union_type->err_set_type = instruction->err_set->child;
...@@ -15982,14 +16020,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -15982,14 +16020,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
15982{16020{
15983 Error err;16021 Error err;
1598416022
15985 ConstExprValue *pointee = create_const_vals(1);16023 ZigValue *pointee = create_const_vals(1);
15986 pointee->special = ConstValSpecialUndef;16024 pointee->special = ConstValSpecialUndef;
1598716025
15988 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);16026 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
15989 result->base.value.special = ConstValSpecialStatic;16027 result->base.value->special = ConstValSpecialStatic;
15990 result->base.value.data.x_ptr.special = ConstPtrSpecialRef;16028 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
15991 result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;16029 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
15992 result->base.value.data.x_ptr.data.ref.pointee = pointee;16030 result->base.value->data.x_ptr.data.ref.pointee = pointee;
1599316031
15994 bool var_type_has_bits;16032 bool var_type_has_bits;
15995 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))16033 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))
...@@ -16004,10 +16042,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -16004,10 +16042,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
16004 return ira->codegen->invalid_instruction;16042 return ira->codegen->invalid_instruction;
16005 }16043 }
16006 }16044 }
16007 assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid);16045 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
1600816046
16009 pointee->type = var_type;16047 pointee->type = var_type;
16010 result->base.value.type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,16048 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
16011 PtrLenSingle, align, 0, 0, false);16049 PtrLenSingle, align, 0, 0, false);
1601216050
16013 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);16051 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
...@@ -16031,7 +16069,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe...@@ -16031,7 +16069,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe
16031 case ResultLocIdCast:16069 case ResultLocIdCast:
16032 return nullptr;16070 return nullptr;
16033 case ResultLocIdInstruction:16071 case ResultLocIdInstruction:
16034 return result_loc->source_instruction->child->value.type;16072 return result_loc->source_instruction->child->value->type;
16035 case ResultLocIdReturn:16073 case ResultLocIdReturn:
16036 return ira->explicit_return_type;16074 return ira->explicit_return_type;
16037 case ResultLocIdPeer:16075 case ResultLocIdPeer:
...@@ -16063,13 +16101,13 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -16063,13 +16101,13 @@ static bool type_can_bit_cast(ZigType *t) {
16063}16101}
1606416102
16065static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {16103static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
16066 ConstExprValue *undef_child = create_const_vals(1);16104 ZigValue *undef_child = create_const_vals(1);
16067 undef_child->type = ptr->value.type->data.pointer.child_type;16105 undef_child->type = ptr->value->type->data.pointer.child_type;
16068 undef_child->special = ConstValSpecialUndef;16106 undef_child->special = ConstValSpecialUndef;
16069 ptr->value.special = ConstValSpecialStatic;16107 ptr->value->special = ConstValSpecialStatic;
16070 ptr->value.data.x_ptr.mut = ConstPtrMutInfer;16108 ptr->value->data.x_ptr.mut = ConstPtrMutInfer;
16071 ptr->value.data.x_ptr.special = ConstPtrSpecialRef;16109 ptr->value->data.x_ptr.special = ConstPtrSpecialRef;
16072 ptr->value.data.x_ptr.data.ref.pointee = undef_child;16110 ptr->value->data.x_ptr.data.ref.pointee = undef_child;
16073}16111}
1607416112
16075static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) {16113static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) {
...@@ -16105,7 +16143,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su...@@ -16105,7 +16143,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
16105 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)16143 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
16106{16144{
16107 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");16145 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
16108 alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,16146 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
16109 PtrLenSingle, 0, 0, 0, false);16147 PtrLenSingle, 0, 0, 0, false);
16110 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);16148 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
16111 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);16149 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
...@@ -16158,7 +16196,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16158,7 +16196,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16158 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))16196 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
16159 return ira->codegen->invalid_instruction;16197 return ira->codegen->invalid_instruction;
16160 bool is_comptime = force_comptime || (value != nullptr &&16198 bool is_comptime = force_comptime || (value != nullptr &&
16161 value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);16199 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1616216200
16163 if (alloca_src->base.child == nullptr || is_comptime) {16201 if (alloca_src->base.child == nullptr || is_comptime) {
16164 uint32_t align = 0;16202 uint32_t align = 0;
...@@ -16167,8 +16205,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16167,8 +16205,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16167 }16205 }
16168 IrInstruction *alloca_gen;16206 IrInstruction *alloca_gen;
16169 if (is_comptime && value != nullptr) {16207 if (is_comptime && value != nullptr) {
16170 if (align > value->value.global_refs->align) {16208 if (align > value->value->global_refs->align) {
16171 value->value.global_refs->align = align;16209 value->value->global_refs->align = align;
16172 }16210 }
16173 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);16211 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
16174 } else {16212 } else {
...@@ -16191,7 +16229,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16191,7 +16229,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16191 }16229 }
16192 case ResultLocIdReturn: {16230 case ResultLocIdReturn: {
16193 if (!non_null_comptime) {16231 if (!non_null_comptime) {
16194 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;16232 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;
16195 if (is_comptime)16233 if (is_comptime)
16196 return nullptr;16234 return nullptr;
16197 }16235 }
...@@ -16222,8 +16260,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16222,8 +16260,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16222 value_type, value, force_runtime, non_null_comptime, true);16260 value_type, value, force_runtime, non_null_comptime, true);
16223 result_peer->suspend_pos.basic_block_index = SIZE_MAX;16261 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
16224 result_peer->suspend_pos.instruction_index = SIZE_MAX;16262 result_peer->suspend_pos.instruction_index = SIZE_MAX;
16225 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||16263 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16226 parent_result_loc->value.type->id == ZigTypeIdUnreachable)16264 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
16227 {16265 {
16228 return parent_result_loc;16266 return parent_result_loc;
16229 }16267 }
...@@ -16270,19 +16308,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16270,19 +16308,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1627016308
16271 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,16309 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
16272 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);16310 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);
16273 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||16311 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16274 parent_result_loc->value.type->id == ZigTypeIdUnreachable)16312 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
16275 {16313 {
16276 return parent_result_loc;16314 return parent_result_loc;
16277 }16315 }
16278 // because is_comptime is false, we mark this a runtime pointer16316 // because is_comptime is false, we mark this a runtime pointer
16279 parent_result_loc->value.special = ConstValSpecialRuntime;16317 parent_result_loc->value->special = ConstValSpecialRuntime;
16280 result_loc->written = true;16318 result_loc->written = true;
16281 result_loc->resolved_loc = parent_result_loc;16319 result_loc->resolved_loc = parent_result_loc;
16282 return result_loc->resolved_loc;16320 return result_loc->resolved_loc;
16283 }16321 }
16284 case ResultLocIdCast: {16322 case ResultLocIdCast: {
16285 if (value != nullptr && value->value.special != ConstValSpecialRuntime)16323 if (value != nullptr && value->value->special != ConstValSpecialRuntime)
16286 return nullptr;16324 return nullptr;
16287 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);16325 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
16288 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);16326 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
...@@ -16313,19 +16351,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16313,19 +16351,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16313 casted_value = nullptr;16351 casted_value = nullptr;
16314 }16352 }
1631516353
16316 if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) {16354 if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) {
16317 return casted_value;16355 return casted_value;
16318 }16356 }
1631916357
16320 bool old_parent_result_loc_written = result_cast->parent->written;16358 bool old_parent_result_loc_written = result_cast->parent->written;
16321 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,16359 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
16322 dest_type, casted_value, force_runtime, non_null_comptime, true);16360 dest_type, casted_value, force_runtime, non_null_comptime, true);
16323 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||16361 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16324 parent_result_loc->value.type->id == ZigTypeIdUnreachable)16362 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
16325 {16363 {
16326 return parent_result_loc;16364 return parent_result_loc;
16327 }16365 }
16328 ZigType *parent_ptr_type = parent_result_loc->value.type;16366 ZigType *parent_ptr_type = parent_result_loc->value->type;
16329 assert(parent_ptr_type->id == ZigTypeIdPointer);16367 assert(parent_ptr_type->id == ZigTypeIdPointer);
16330 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,16368 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
16331 ResolveStatusAlignmentKnown)))16369 ResolveStatusAlignmentKnown)))
...@@ -16358,7 +16396,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16358,7 +16396,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16358 {16396 {
16359 // we also need to check that this cast is OK.16397 // we also need to check that this cast is OK.
16360 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,16398 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16361 parent_result_loc->value.type, ptr_type,16399 parent_result_loc->value->type, ptr_type,
16362 result_cast->base.source_instruction->source_node, false);16400 result_cast->base.source_instruction->source_node, false);
16363 if (const_cast_result.id == ConstCastResultIdInvalid)16401 if (const_cast_result.id == ConstCastResultIdInvalid)
16364 return ira->codegen->invalid_instruction;16402 return ira->codegen->invalid_instruction;
...@@ -16413,18 +16451,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16413,18 +16451,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16413 bitcasted_value = nullptr;16451 bitcasted_value = nullptr;
16414 }16452 }
1641516453
16416 if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) {16454 if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) {
16417 return bitcasted_value;16455 return bitcasted_value;
16418 }16456 }
1641916457
16420 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,16458 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
16421 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);16459 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
16422 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||16460 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16423 parent_result_loc->value.type->id == ZigTypeIdUnreachable)16461 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
16424 {16462 {
16425 return parent_result_loc;16463 return parent_result_loc;
16426 }16464 }
16427 ZigType *parent_ptr_type = parent_result_loc->value.type;16465 ZigType *parent_ptr_type = parent_result_loc->value->type;
16428 assert(parent_ptr_type->id == ZigTypeIdPointer);16466 assert(parent_ptr_type->id == ZigTypeIdPointer);
16429 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,16467 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
16430 ResolveStatusAlignmentKnown)))16468 ResolveStatusAlignmentKnown)))
...@@ -16454,24 +16492,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16454,24 +16492,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16454{16492{
16455 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&16493 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
16456 instr_is_comptime(result_loc_pass1->source_instruction) &&16494 instr_is_comptime(result_loc_pass1->source_instruction) &&
16457 result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer &&16495 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
16458 result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard)16496 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
16459 {16497 {
16460 result_loc_pass1 = no_result_loc();16498 result_loc_pass1 = no_result_loc();
16461 }16499 }
16462 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,16500 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
16463 value, force_runtime, non_null_comptime);16501 value, force_runtime, non_null_comptime);
16464 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type)))16502 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
16465 return result_loc;16503 return result_loc;
1646616504
16467 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&16505 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&
16468 result_loc_pass1->written && result_loc->value.data.x_ptr.mut == ConstPtrMutInfer)16506 result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer)
16469 {16507 {
16470 result_loc->value.special = ConstValSpecialRuntime;16508 result_loc->value->special = ConstValSpecialRuntime;
16471 }16509 }
1647216510
16473 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr);16511 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
16474 ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type;16512 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
16475 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&16513 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
16476 value_type->id != ZigTypeIdNull)16514 value_type->id != ZigTypeIdNull)
16477 {16515 {
...@@ -16544,18 +16582,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,...@@ -16544,18 +16582,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
16544 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),16582 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
16545 implicit_elem_type, nullptr, false, true, true);16583 implicit_elem_type, nullptr, false, true, true);
16546 if (result_loc != nullptr &&16584 if (result_loc != nullptr &&
16547 (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))16585 (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
16548 {16586 {
16549 return result_loc;16587 return result_loc;
16550 }16588 }
16551 result_loc->value.special = ConstValSpecialRuntime;16589 result_loc->value->special = ConstValSpecialRuntime;
16552 return result_loc;16590 return result_loc;
16553 }16591 }
1655416592
16555 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);16593 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
16556 result->value.special = ConstValSpecialUndef;16594 result->value->special = ConstValSpecialUndef;
16557 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);16595 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);
16558 ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar;16596 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
16559 return ptr;16597 return ptr;
16560}16598}
1656116599
...@@ -16605,9 +16643,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal...@@ -16605,9 +16643,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal
16605{16643{
16606 ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base);16644 ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base);
16607 IrInstruction *ret_ptr_uncasted = call_instruction->args[call_instruction->arg_count]->child;16645 IrInstruction *ret_ptr_uncasted = call_instruction->args[call_instruction->arg_count]->child;
16608 if (type_is_invalid(ret_ptr_uncasted->value.type))16646 if (type_is_invalid(ret_ptr_uncasted->value->type))
16609 return ira->codegen->invalid_instruction;16647 return ira->codegen->invalid_instruction;
16610 if (ret_ptr_uncasted->value.type->id == ZigTypeIdVoid) {16648 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
16611 // Result location will be inside the async frame.16649 // Result location will be inside the async frame.
16612 return nullptr;16650 return nullptr;
16613 }16651 }
...@@ -16632,7 +16670,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc...@@ -16632,7 +16670,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
16632 if (casted_new_stack != nullptr) {16670 if (casted_new_stack != nullptr) {
16633 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;16671 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
16634 IrInstruction *ret_ptr = get_async_call_result_loc(ira, call_instruction, fn_ret_type);16672 IrInstruction *ret_ptr = get_async_call_result_loc(ira, call_instruction, fn_ret_type);
16635 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value.type))16673 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
16636 return ira->codegen->invalid_instruction;16674 return ira->codegen->invalid_instruction;
1663716675
16638 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);16676 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
...@@ -16645,11 +16683,11 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc...@@ -16645,11 +16683,11 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
16645 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);16683 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
16646 IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,16684 IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
16647 frame_type, nullptr, true, true, false);16685 frame_type, nullptr, true, true, false);
16648 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {16686 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
16649 return result_loc;16687 return result_loc;
16650 }16688 }
16651 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));16689 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));
16652 if (type_is_invalid(result_loc->value.type))16690 if (type_is_invalid(result_loc->value->type))
16653 return ira->codegen->invalid_instruction;16691 return ira->codegen->invalid_instruction;
16654 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,16692 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
16655 casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack,16693 casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack,
...@@ -16670,13 +16708,13 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -16670,13 +16708,13 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
16670 return false;16708 return false;
1667116709
16672 casted_arg = ir_implicit_cast(ira, arg, param_type);16710 casted_arg = ir_implicit_cast(ira, arg, param_type);
16673 if (type_is_invalid(casted_arg->value.type))16711 if (type_is_invalid(casted_arg->value->type))
16674 return false;16712 return false;
16675 } else {16713 } else {
16676 casted_arg = arg;16714 casted_arg = arg;
16677 }16715 }
1667816716
16679 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);16717 ZigValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);
16680 if (!arg_val)16718 if (!arg_val)
16681 return false;16719 return false;
1668216720
...@@ -16710,7 +16748,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16710,7 +16748,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16710 return false;16748 return false;
1671116749
16712 casted_arg = ir_implicit_cast(ira, arg, param_type);16750 casted_arg = ir_implicit_cast(ira, arg, param_type);
16713 if (type_is_invalid(casted_arg->value.type))16751 if (type_is_invalid(casted_arg->value->type))
16714 return false;16752 return false;
16715 } else {16753 } else {
16716 arg_part_of_generic_id = true;16754 arg_part_of_generic_id = true;
...@@ -16719,9 +16757,9 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16719,9 +16757,9 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16719 }16757 }
1672016758
16721 bool comptime_arg = param_decl_node->data.param_decl.is_comptime ||16759 bool comptime_arg = param_decl_node->data.param_decl.is_comptime ||
16722 casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;16760 casted_arg->value->type->id == ZigTypeIdComptimeInt || casted_arg->value->type->id == ZigTypeIdComptimeFloat;
1672316761
16724 ConstExprValue *arg_val;16762 ZigValue *arg_val;
1672516763
16726 if (comptime_arg) {16764 if (comptime_arg) {
16727 arg_part_of_generic_id = true;16765 arg_part_of_generic_id = true;
...@@ -16729,7 +16767,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16729,7 +16767,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16729 if (!arg_val)16767 if (!arg_val)
16730 return false;16768 return false;
16731 } else {16769 } else {
16732 arg_val = create_const_runtime(casted_arg->value.type);16770 arg_val = create_const_runtime(casted_arg->value->type);
16733 }16771 }
16734 if (arg_part_of_generic_id) {16772 if (arg_part_of_generic_id) {
16735 copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true);16773 copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true);
...@@ -16745,8 +16783,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16745,8 +16783,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16745 var->shadowable = !comptime_arg;16783 var->shadowable = !comptime_arg;
1674616784
16747 *next_proto_i += 1;16785 *next_proto_i += 1;
16748 } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||16786 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
16749 casted_arg->value.type->id == ZigTypeIdComptimeFloat)16787 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
16750 {16788 {
16751 ir_add_error(ira, casted_arg,16789 ir_add_error(ira, casted_arg,
16752 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));16790 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
...@@ -16754,10 +16792,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16754,10 +16792,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16754 }16792 }
1675516793
16756 if (!comptime_arg) {16794 if (!comptime_arg) {
16757 switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) {16795 switch (type_requires_comptime(ira->codegen, casted_arg->value->type)) {
16758 case ReqCompTimeYes:16796 case ReqCompTimeYes:
16759 ir_add_error(ira, casted_arg,16797 ir_add_error(ira, casted_arg,
16760 buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name)));16798 buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value->type->name)));
16761 return false;16799 return false;
16762 case ReqCompTimeInvalid:16800 case ReqCompTimeInvalid:
16763 return false;16801 return false;
...@@ -16767,7 +16805,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16767,7 +16805,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1676716805
16768 casted_args[fn_type_id->param_count] = casted_arg;16806 casted_args[fn_type_id->param_count] = casted_arg;
16769 FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count];16807 FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count];
16770 param_info->type = casted_arg->value.type;16808 param_info->type = casted_arg->value->type;
16771 param_info->is_noalias = param_decl_node->data.param_decl.is_noalias;16809 param_info->is_noalias = param_decl_node->data.param_decl.is_noalias;
16772 impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node;16810 impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node;
16773 fn_type_id->param_count += 1;16811 fn_type_id->param_count += 1;
...@@ -16805,7 +16843,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -16805,7 +16843,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
16805 if (var->var_type == nullptr || type_is_invalid(var->var_type))16843 if (var->var_type == nullptr || type_is_invalid(var->var_type))
16806 return ira->codegen->invalid_instruction;16844 return ira->codegen->invalid_instruction;
1680716845
16808 ConstExprValue *mem_slot = nullptr;16846 ZigValue *mem_slot = nullptr;
1680916847
16810 bool comptime_var_mem = ir_get_var_is_comptime(var);16848 bool comptime_var_mem = ir_get_var_is_comptime(var);
16811 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;16849 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
...@@ -16813,7 +16851,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -16813,7 +16851,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1681316851
16814 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,16852 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,
16815 instruction->scope, instruction->source_node, var);16853 instruction->scope, instruction->source_node, var);
16816 result->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type,16854 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,
16817 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);16855 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1681816856
16819 if (linkage_makes_it_runtime)16857 if (linkage_makes_it_runtime)
...@@ -16846,10 +16884,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -16846,10 +16884,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
16846 assert(!comptime_var_mem);16884 assert(!comptime_var_mem);
16847 ptr_mut = ConstPtrMutRuntimeVar;16885 ptr_mut = ConstPtrMutRuntimeVar;
16848 }16886 }
16849 result->value.special = ConstValSpecialStatic;16887 result->value->special = ConstValSpecialStatic;
16850 result->value.data.x_ptr.mut = ptr_mut;16888 result->value->data.x_ptr.mut = ptr_mut;
16851 result->value.data.x_ptr.special = ConstPtrSpecialRef;16889 result->value->data.x_ptr.special = ConstPtrSpecialRef;
16852 result->value.data.x_ptr.data.ref.pointee = mem_slot;16890 result->value->data.x_ptr.data.ref.pointee = mem_slot;
16853 return result;16891 return result;
16854 }16892 }
16855 }16893 }
...@@ -16859,13 +16897,13 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -16859,13 +16897,13 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
16859no_mem_slot:16897no_mem_slot:
1686016898
16861 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);16899 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
16862 result->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;16900 result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;
1686316901
16864 return result;16902 return result;
16865}16903}
1686616904
16867// This function is called when a comptime value becomes accessible at runtime.16905// This function is called when a comptime value becomes accessible at runtime.
16868static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *val) {16906static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) {
16869 ir_assert(value_is_comptime(val), source_instr);16907 ir_assert(value_is_comptime(val), source_instr);
16870 if (val->special == ConstValSpecialUndef)16908 if (val->special == ConstValSpecialUndef)
16871 return;16909 return;
...@@ -16881,11 +16919,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins...@@ -16881,11 +16919,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
16881static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,16919static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
16882 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)16920 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)
16883{16921{
16884 assert(ptr->value.type->id == ZigTypeIdPointer);16922 assert(ptr->value->type->id == ZigTypeIdPointer);
1688516923
16886 if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {16924 if (ptr->value->data.x_ptr.special == ConstPtrSpecialDiscard) {
16887 if (uncasted_value->value.type->id == ZigTypeIdErrorUnion ||16925 if (uncasted_value->value->type->id == ZigTypeIdErrorUnion ||
16888 uncasted_value->value.type->id == ZigTypeIdErrorSet)16926 uncasted_value->value->type->id == ZigTypeIdErrorSet)
16889 {16927 {
16890 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));16928 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
16891 return ira->codegen->invalid_instruction;16929 return ira->codegen->invalid_instruction;
...@@ -16893,7 +16931,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16893,7 +16931,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16893 return ir_const_void(ira, source_instr);16931 return ir_const_void(ira, source_instr);
16894 }16932 }
1689516933
16896 InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field;16934 InferredStructField *isf = ptr->value->type->data.pointer.inferred_struct_field;
16897 if (allow_write_through_const && isf != nullptr) {16935 if (allow_write_through_const && isf != nullptr) {
16898 // Now it's time to add the field to the struct type.16936 // Now it's time to add the field to the struct type.
16899 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;16937 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
...@@ -16904,7 +16942,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16904,7 +16942,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1690416942
16905 TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count];16943 TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count];
16906 field->name = isf->field_name;16944 field->name = isf->field_name;
16907 field->type_entry = uncasted_value->value.type;16945 field->type_entry = uncasted_value->value->type;
16908 field->type_val = create_const_type(ira->codegen, field->type_entry);16946 field->type_val = create_const_type(ira->codegen, field->type_entry);
16909 field->src_index = old_field_count;16947 field->src_index = old_field_count;
16910 field->decl_node = uncasted_value->source_node;16948 field->decl_node = uncasted_value->source_node;
...@@ -16913,25 +16951,25 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16913,25 +16951,25 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16913 IrInstruction *casted_ptr;16951 IrInstruction *casted_ptr;
16914 if (instr_is_comptime(ptr)) {16952 if (instr_is_comptime(ptr)) {
16915 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);16953 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);
16916 copy_const_val(&casted_ptr->value, &ptr->value, false);16954 copy_const_val(casted_ptr->value, ptr->value, false);
16917 casted_ptr->value.type = struct_ptr_type;16955 casted_ptr->value->type = struct_ptr_type;
16918 } else {16956 } else {
16919 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,16957 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,
16920 source_instr->source_node, struct_ptr_type, ptr, CastOpNoop);16958 source_instr->source_node, struct_ptr_type, ptr, CastOpNoop);
16921 casted_ptr->value.type = struct_ptr_type;16959 casted_ptr->value->type = struct_ptr_type;
16922 }16960 }
16923 if (instr_is_comptime(casted_ptr)) {16961 if (instr_is_comptime(casted_ptr)) {
16924 ConstExprValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);16962 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
16925 if (!ptr_val)16963 if (!ptr_val)
16926 return ira->codegen->invalid_instruction;16964 return ira->codegen->invalid_instruction;
16927 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {16965 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
16928 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,16966 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
16929 source_instr->source_node);16967 source_instr->source_node);
16930 struct_val->special = ConstValSpecialStatic;16968 struct_val->special = ConstValSpecialStatic;
16931 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,16969 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
16932 old_field_count, new_field_count);16970 old_field_count, new_field_count);
1693316971
16934 ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count];16972 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
16935 field_val->special = ConstValSpecialUndef;16973 field_val->special = ConstValSpecialUndef;
16936 field_val->type = field->type_entry;16974 field_val->type = field->type_entry;
16937 field_val->parent.id = ConstParentIdStruct;16975 field_val->parent.id = ConstParentIdStruct;
...@@ -16944,12 +16982,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16944,12 +16982,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16944 isf->inferred_struct_type, true);16982 isf->inferred_struct_type, true);
16945 }16983 }
1694616984
16947 if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) {16985 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
16948 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));16986 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
16949 return ira->codegen->invalid_instruction;16987 return ira->codegen->invalid_instruction;
16950 }16988 }
1695116989
16952 ZigType *child_type = ptr->value.type->data.pointer.child_type;16990 ZigType *child_type = ptr->value->type->data.pointer.child_type;
16953 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);16991 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);
16954 if (value == ira->codegen->invalid_instruction)16992 if (value == ira->codegen->invalid_instruction)
16955 return ira->codegen->invalid_instruction;16993 return ira->codegen->invalid_instruction;
...@@ -16963,16 +17001,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16963,16 +17001,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16963 break;17001 break;
16964 }17002 }
1696517003
16966 if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {17004 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
16967 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) {17005 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
16968 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));17006 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
16969 return ira->codegen->invalid_instruction;17007 return ira->codegen->invalid_instruction;
16970 }17008 }
16971 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar ||17009 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
16972 ptr->value.data.x_ptr.mut == ConstPtrMutInfer)17010 ptr->value->data.x_ptr.mut == ConstPtrMutInfer)
16973 {17011 {
16974 if (instr_is_comptime(value)) {17012 if (instr_is_comptime(value)) {
16975 ConstExprValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node);17013 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
16976 if (dest_val == nullptr)17014 if (dest_val == nullptr)
16977 return ira->codegen->invalid_instruction;17015 return ira->codegen->invalid_instruction;
16978 if (dest_val->special != ConstValSpecialRuntime) {17016 if (dest_val->special != ConstValSpecialRuntime) {
...@@ -16982,9 +17020,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16982,9 +17020,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16982 // * "string literal used as comptime slice is memoized"17020 // * "string literal used as comptime slice is memoized"
16983 // * "comptime modification of const struct field" - except modified to avoid17021 // * "comptime modification of const struct field" - except modified to avoid
16984 // ConstPtrMutComptimeVar, thus defeating the logic below.17022 // ConstPtrMutComptimeVar, thus defeating the logic below.
16985 bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar;17023 bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar;
16986 copy_const_val(dest_val, &value->value, same_global_refs);17024 copy_const_val(dest_val, value->value, same_global_refs);
16987 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar &&17025 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
16988 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)17026 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
16989 {17027 {
16990 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;17028 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;
...@@ -16992,12 +17030,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16992,12 +17030,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16992 return ir_const_void(ira, source_instr);17030 return ir_const_void(ira, source_instr);
16993 }17031 }
16994 }17032 }
16995 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {17033 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
16996 ptr->value.special = ConstValSpecialRuntime;17034 ptr->value->special = ConstValSpecialRuntime;
16997 } else {17035 } else {
16998 ir_add_error(ira, source_instr,17036 ir_add_error(ira, source_instr,
16999 buf_sprintf("cannot store runtime value in compile time variable"));17037 buf_sprintf("cannot store runtime value in compile time variable"));
17000 ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);17038 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
17001 dest_val->type = ira->codegen->builtin_types.entry_invalid;17039 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1700217040
17003 return ira->codegen->invalid_instruction;17041 return ira->codegen->invalid_instruction;
...@@ -17009,7 +17047,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -17009,7 +17047,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17009 case ReqCompTimeInvalid:17047 case ReqCompTimeInvalid:
17010 return ira->codegen->invalid_instruction;17048 return ira->codegen->invalid_instruction;
17011 case ReqCompTimeYes:17049 case ReqCompTimeYes:
17012 switch (type_has_one_possible_value(ira->codegen, ptr->value.type)) {17050 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {
17013 case OnePossibleValueInvalid:17051 case OnePossibleValueInvalid:
17014 return ira->codegen->invalid_instruction;17052 return ira->codegen->invalid_instruction;
17015 case OnePossibleValueNo:17053 case OnePossibleValueNo:
...@@ -17025,7 +17063,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -17025,7 +17063,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17025 }17063 }
1702617064
17027 if (instr_is_comptime(value)) {17065 if (instr_is_comptime(value)) {
17028 mark_comptime_value_escape(ira, source_instr, &value->value);17066 mark_comptime_value_escape(ira, source_instr, value->value);
17029 }17067 }
1703017068
17031 // If this is a store to a pointer with a runtime-known vector index,17069 // If this is a store to a pointer with a runtime-known vector index,
...@@ -17034,7 +17072,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -17034,7 +17072,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17034 // explaining why it is impossible for this store to work. Which is that17072 // explaining why it is impossible for this store to work. Which is that
17035 // the pointer address is of the vector; without the element index being known17073 // the pointer address is of the vector; without the element index being known
17036 // we cannot properly perform the insertion.17074 // we cannot properly perform the insertion.
17037 if (ptr->value.type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {17075 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
17038 if (ptr->id == IrInstructionIdElemPtr) {17076 if (ptr->id == IrInstructionIdElemPtr) {
17039 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;17077 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
17040 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,17078 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
...@@ -17042,7 +17080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -17042,7 +17080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17042 }17080 }
17043 ir_add_error(ira, ptr,17081 ir_add_error(ira, ptr,
17044 buf_sprintf("unable to determine vector element index of type '%s'",17082 buf_sprintf("unable to determine vector element index of type '%s'",
17045 buf_ptr(&ptr->value.type->name)));17083 buf_ptr(&ptr->value->type->name)));
17046 return ira->codegen->invalid_instruction;17084 return ira->codegen->invalid_instruction;
17047 }17085 }
1704817086
...@@ -17058,12 +17096,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall...@@ -17058,12 +17096,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall
17058 return nullptr;17096 return nullptr;
1705917097
17060 IrInstruction *new_stack = call_instruction->new_stack->child;17098 IrInstruction *new_stack = call_instruction->new_stack->child;
17061 if (type_is_invalid(new_stack->value.type))17099 if (type_is_invalid(new_stack->value->type))
17062 return ira->codegen->invalid_instruction;17100 return ira->codegen->invalid_instruction;
1706317101
17064 if (call_instruction->is_async_call_builtin &&17102 if (call_instruction->is_async_call_builtin &&
17065 fn_entry != nullptr && new_stack->value.type->id == ZigTypeIdPointer &&17103 fn_entry != nullptr && new_stack->value->type->id == ZigTypeIdPointer &&
17066 new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)17104 new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
17067 {17105 {
17068 ZigType *needed_frame_type = get_pointer_to_type(ira->codegen,17106 ZigType *needed_frame_type = get_pointer_to_type(ira->codegen,
17069 get_fn_frame_type(ira->codegen, fn_entry), false);17107 get_fn_frame_type(ira->codegen, fn_entry), false);
...@@ -17097,7 +17135,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17097,7 +17135,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1709717135
17098 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;17136 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
17099 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {17137 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
17100 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->child->value;17138 ZigValue *arg_tuple_value = call_instruction->args[i]->child->value;
17101 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {17139 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
17102 call_param_count -= 1;17140 call_param_count -= 1;
17103 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -17141 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
...@@ -17152,7 +17190,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17152,7 +17190,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1715217190
17153 size_t next_proto_i = 0;17191 size_t next_proto_i = 0;
17154 if (first_arg_ptr) {17192 if (first_arg_ptr) {
17155 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);17193 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1715617194
17157 bool first_arg_known_bare = false;17195 bool first_arg_known_bare = false;
17158 if (fn_type_id->next_param_index >= 1) {17196 if (fn_type_id->next_param_index >= 1) {
...@@ -17163,11 +17201,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17163,11 +17201,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17163 }17201 }
1716417202
17165 IrInstruction *first_arg;17203 IrInstruction *first_arg;
17166 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {17204 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
17167 first_arg = first_arg_ptr;17205 first_arg = first_arg_ptr;
17168 } else {17206 } else {
17169 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);17207 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
17170 if (type_is_invalid(first_arg->value.type))17208 if (type_is_invalid(first_arg->value->type))
17171 return ira->codegen->invalid_instruction;17209 return ira->codegen->invalid_instruction;
17172 }17210 }
1717317211
...@@ -17184,7 +17222,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17184,7 +17222,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1718417222
17185 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {17223 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
17186 IrInstruction *old_arg = call_instruction->args[call_i]->child;17224 IrInstruction *old_arg = call_instruction->args[call_i]->child;
17187 if (type_is_invalid(old_arg->value.type))17225 if (type_is_invalid(old_arg->value->type))
17188 return ira->codegen->invalid_instruction;17226 return ira->codegen->invalid_instruction;
1718917227
17190 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))17228 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
...@@ -17207,7 +17245,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17207,7 +17245,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17207 }17245 }
1720817246
17209 bool cacheable = fn_eval_cacheable(exec_scope, return_type);17247 bool cacheable = fn_eval_cacheable(exec_scope, return_type);
17210 ConstExprValue *result = nullptr;17248 ZigValue *result = nullptr;
17211 if (cacheable) {17249 if (cacheable) {
17212 auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope);17250 auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope);
17213 if (entry)17251 if (entry)
...@@ -17250,8 +17288,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17250,8 +17288,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17250 }17288 }
1725117289
17252 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);17290 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);
17253 copy_const_val(&new_instruction->value, result, true);17291 copy_const_val(new_instruction->value, result, true);
17254 new_instruction->value.type = return_type;17292 new_instruction->value->type = return_type;
17255 return ir_finish_anal(ira, new_instruction);17293 return ir_finish_anal(ira, new_instruction);
17256 }17294 }
1725717295
...@@ -17266,11 +17304,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17266,11 +17304,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17266 size_t new_fn_arg_count = first_arg_1_or_0;17304 size_t new_fn_arg_count = first_arg_1_or_0;
17267 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {17305 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
17268 IrInstruction *arg = call_instruction->args[call_i]->child;17306 IrInstruction *arg = call_instruction->args[call_i]->child;
17269 if (type_is_invalid(arg->value.type))17307 if (type_is_invalid(arg->value->type))
17270 return ira->codegen->invalid_instruction;17308 return ira->codegen->invalid_instruction;
1727117309
17272 if (arg->value.type->id == ZigTypeIdArgTuple) {17310 if (arg->value->type->id == ZigTypeIdArgTuple) {
17273 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;17311 new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index;
17274 } else {17312 } else {
17275 new_fn_arg_count += 1;17313 new_fn_arg_count += 1;
17276 }17314 }
...@@ -17299,7 +17337,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17299,7 +17337,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17299 size_t next_proto_i = 0;17337 size_t next_proto_i = 0;
1730017338
17301 if (first_arg_ptr) {17339 if (first_arg_ptr) {
17302 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);17340 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1730317341
17304 bool first_arg_known_bare = false;17342 bool first_arg_known_bare = false;
17305 if (fn_type_id->next_param_index >= 1) {17343 if (fn_type_id->next_param_index >= 1) {
...@@ -17310,11 +17348,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17310,11 +17348,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17310 }17348 }
1731117349
17312 IrInstruction *first_arg;17350 IrInstruction *first_arg;
17313 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {17351 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
17314 first_arg = first_arg_ptr;17352 first_arg = first_arg_ptr;
17315 } else {17353 } else {
17316 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);17354 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
17317 if (type_is_invalid(first_arg->value.type))17355 if (type_is_invalid(first_arg->value->type))
17318 return ira->codegen->invalid_instruction;17356 return ira->codegen->invalid_instruction;
17319 }17357 }
1732017358
...@@ -17332,12 +17370,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17332,12 +17370,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17332 assert(parent_fn_entry);17370 assert(parent_fn_entry);
17333 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {17371 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
17334 IrInstruction *arg = call_instruction->args[call_i]->child;17372 IrInstruction *arg = call_instruction->args[call_i]->child;
17335 if (type_is_invalid(arg->value.type))17373 if (type_is_invalid(arg->value->type))
17336 return ira->codegen->invalid_instruction;17374 return ira->codegen->invalid_instruction;
1733717375
17338 if (arg->value.type->id == ZigTypeIdArgTuple) {17376 if (arg->value->type->id == ZigTypeIdArgTuple) {
17339 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;17377 for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index;
17340 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)17378 arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
17341 {17379 {
17342 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);17380 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
17343 assert(param_decl_node->type == NodeTypeParamDecl);17381 assert(param_decl_node->type == NodeTypeParamDecl);
...@@ -17354,11 +17392,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17354,11 +17392,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17354 return ira->codegen->invalid_instruction;17392 return ira->codegen->invalid_instruction;
17355 }17393 }
17356 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);17394 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);
17357 if (type_is_invalid(arg_var_ptr_inst->value.type))17395 if (type_is_invalid(arg_var_ptr_inst->value->type))
17358 return ira->codegen->invalid_instruction;17396 return ira->codegen->invalid_instruction;
1735917397
17360 IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr);17398 IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr);
17361 if (type_is_invalid(arg_tuple_arg->value.type))17399 if (type_is_invalid(arg_tuple_arg->value->type))
17362 return ira->codegen->invalid_instruction;17400 return ira->codegen->invalid_instruction;
1736317401
17364 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope,17402 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope,
...@@ -17392,7 +17430,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17392,7 +17430,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17392 first_var_arg = inst_fn_type_id.param_count;17430 first_var_arg = inst_fn_type_id.param_count;
17393 }17431 }
1739417432
17395 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,17433 ZigValue *var_args_val = create_const_arg_tuple(ira->codegen,
17396 first_var_arg, inst_fn_type_id.param_count);17434 first_var_arg, inst_fn_type_id.param_count);
17397 ZigVar *var = add_variable(ira->codegen, param_decl_node,17435 ZigVar *var = add_variable(ira->codegen, param_decl_node,
17398 impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type);17436 impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type);
...@@ -17400,14 +17438,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17400,14 +17438,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17400 }17438 }
1740117439
17402 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {17440 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {
17403 ConstExprValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope,17441 ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope,
17404 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),17442 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),
17405 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,17443 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
17406 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,17444 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
17407 nullptr, UndefBad);17445 nullptr, UndefBad);
17408 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,17446 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
17409 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);17447 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
17410 copy_const_val(&const_instruction->base.value, align_result, true);17448 copy_const_val(const_instruction->base.value, align_result, true);
1741117449
17412 uint32_t align_bytes = 0;17450 uint32_t align_bytes = 0;
17413 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);17451 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
...@@ -17468,7 +17506,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17468,7 +17506,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17468 }17506 }
1746917507
17470 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, impl_fn);17508 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, impl_fn);
17471 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type))17509 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
17472 return ira->codegen->invalid_instruction;17510 return ira->codegen->invalid_instruction;
1747317511
17474 size_t impl_param_count = impl_fn_type_id->param_count;17512 size_t impl_param_count = impl_fn_type_id->param_count;
...@@ -17483,17 +17521,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17483,17 +17521,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17483 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,17521 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
17484 impl_fn_type_id->return_type, nullptr, true, true, false);17522 impl_fn_type_id->return_type, nullptr, true, true, false);
17485 if (result_loc != nullptr) {17523 if (result_loc != nullptr) {
17486 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {17524 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
17487 return result_loc;17525 return result_loc;
17488 }17526 }
17489 if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) {17527 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
17490 ir_reset_result(call_instruction->result_loc);17528 ir_reset_result(call_instruction->result_loc);
17491 result_loc = nullptr;17529 result_loc = nullptr;
17492 }17530 }
17493 }17531 }
17494 } else if (call_instruction->is_async_call_builtin) {17532 } else if (call_instruction->is_async_call_builtin) {
17495 result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type);17533 result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type);
17496 if (result_loc != nullptr && type_is_invalid(result_loc->value.type))17534 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
17497 return ira->codegen->invalid_instruction;17535 return ira->codegen->invalid_instruction;
17498 } else {17536 } else {
17499 result_loc = nullptr;17537 result_loc = nullptr;
...@@ -17530,7 +17568,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17530,7 +17568,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17530 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);17568 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
17531 size_t next_arg_index = 0;17569 size_t next_arg_index = 0;
17532 if (first_arg_ptr) {17570 if (first_arg_ptr) {
17533 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);17571 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1753417572
17535 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;17573 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
17536 if (type_is_invalid(param_type))17574 if (type_is_invalid(param_type))
...@@ -17538,17 +17576,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17538,17 +17576,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1753817576
17539 IrInstruction *first_arg;17577 IrInstruction *first_arg;
17540 if (param_type->id == ZigTypeIdPointer &&17578 if (param_type->id == ZigTypeIdPointer &&
17541 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))17579 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))
17542 {17580 {
17543 first_arg = first_arg_ptr;17581 first_arg = first_arg_ptr;
17544 } else {17582 } else {
17545 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);17583 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
17546 if (type_is_invalid(first_arg->value.type))17584 if (type_is_invalid(first_arg->value->type))
17547 return ira->codegen->invalid_instruction;17585 return ira->codegen->invalid_instruction;
17548 }17586 }
1754917587
17550 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);17588 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
17551 if (type_is_invalid(casted_arg->value.type))17589 if (type_is_invalid(casted_arg->value->type))
17552 return ira->codegen->invalid_instruction;17590 return ira->codegen->invalid_instruction;
1755317591
17554 casted_args[next_arg_index] = casted_arg;17592 casted_args[next_arg_index] = casted_arg;
...@@ -17556,12 +17594,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17556,12 +17594,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17556 }17594 }
17557 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {17595 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
17558 IrInstruction *old_arg = call_instruction->args[call_i]->child;17596 IrInstruction *old_arg = call_instruction->args[call_i]->child;
17559 if (type_is_invalid(old_arg->value.type))17597 if (type_is_invalid(old_arg->value->type))
17560 return ira->codegen->invalid_instruction;17598 return ira->codegen->invalid_instruction;
1756117599
17562 if (old_arg->value.type->id == ZigTypeIdArgTuple) {17600 if (old_arg->value->type->id == ZigTypeIdArgTuple) {
17563 for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index;17601 for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index;
17564 arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)17602 arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
17565 {17603 {
17566 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);17604 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
17567 if (arg_var == nullptr) {17605 if (arg_var == nullptr) {
...@@ -17570,11 +17608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17570,11 +17608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17570 return ira->codegen->invalid_instruction;17608 return ira->codegen->invalid_instruction;
17571 }17609 }
17572 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var);17610 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var);
17573 if (type_is_invalid(arg_var_ptr_inst->value.type))17611 if (type_is_invalid(arg_var_ptr_inst->value->type))
17574 return ira->codegen->invalid_instruction;17612 return ira->codegen->invalid_instruction;
1757517613
17576 IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr);17614 IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr);
17577 if (type_is_invalid(arg_tuple_arg->value.type))17615 if (type_is_invalid(arg_tuple_arg->value->type))
17578 return ira->codegen->invalid_instruction;17616 return ira->codegen->invalid_instruction;
1757917617
17580 IrInstruction *casted_arg;17618 IrInstruction *casted_arg;
...@@ -17583,7 +17621,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17583,7 +17621,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17583 if (type_is_invalid(param_type))17621 if (type_is_invalid(param_type))
17584 return ira->codegen->invalid_instruction;17622 return ira->codegen->invalid_instruction;
17585 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);17623 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);
17586 if (type_is_invalid(casted_arg->value.type))17624 if (type_is_invalid(casted_arg->value->type))
17587 return ira->codegen->invalid_instruction;17625 return ira->codegen->invalid_instruction;
17588 } else {17626 } else {
17589 casted_arg = arg_tuple_arg;17627 casted_arg = arg_tuple_arg;
...@@ -17599,7 +17637,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17599,7 +17637,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17599 if (type_is_invalid(param_type))17637 if (type_is_invalid(param_type))
17600 return ira->codegen->invalid_instruction;17638 return ira->codegen->invalid_instruction;
17601 casted_arg = ir_implicit_cast(ira, old_arg, param_type);17639 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
17602 if (type_is_invalid(casted_arg->value.type))17640 if (type_is_invalid(casted_arg->value->type))
17603 return ira->codegen->invalid_instruction;17641 return ira->codegen->invalid_instruction;
17604 } else {17642 } else {
17605 casted_arg = old_arg;17643 casted_arg = old_arg;
...@@ -17623,7 +17661,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17623,7 +17661,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17623 }17661 }
1762417662
17625 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, fn_entry);17663 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, fn_entry);
17626 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type))17664 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
17627 return ira->codegen->invalid_instruction;17665 return ira->codegen->invalid_instruction;
1762817666
17629 if (call_instruction->modifier == CallModifierAsync) {17667 if (call_instruction->modifier == CallModifierAsync) {
...@@ -17645,17 +17683,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17645,17 +17683,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17645 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,17683 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
17646 return_type, nullptr, true, true, false);17684 return_type, nullptr, true, true, false);
17647 if (result_loc != nullptr) {17685 if (result_loc != nullptr) {
17648 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {17686 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
17649 return result_loc;17687 return result_loc;
17650 }17688 }
17651 if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) {17689 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
17652 ir_reset_result(call_instruction->result_loc);17690 ir_reset_result(call_instruction->result_loc);
17653 result_loc = nullptr;17691 result_loc = nullptr;
17654 }17692 }
17655 }17693 }
17656 } else if (call_instruction->is_async_call_builtin) {17694 } else if (call_instruction->is_async_call_builtin) {
17657 result_loc = get_async_call_result_loc(ira, call_instruction, return_type);17695 result_loc = get_async_call_result_loc(ira, call_instruction, return_type);
17658 if (result_loc != nullptr && type_is_invalid(result_loc->value.type))17696 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
17659 return ira->codegen->invalid_instruction;17697 return ira->codegen->invalid_instruction;
17660 } else {17698 } else {
17661 result_loc = nullptr;17699 result_loc = nullptr;
...@@ -17672,14 +17710,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17672,14 +17710,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1767217710
17673static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {17711static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {
17674 IrInstruction *fn_ref = call_instruction->fn_ref->child;17712 IrInstruction *fn_ref = call_instruction->fn_ref->child;
17675 if (type_is_invalid(fn_ref->value.type))17713 if (type_is_invalid(fn_ref->value->type))
17676 return ira->codegen->invalid_instruction;17714 return ira->codegen->invalid_instruction;
1767717715
17678 bool is_comptime = call_instruction->is_comptime ||17716 bool is_comptime = call_instruction->is_comptime ||
17679 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);17717 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
1768017718
17681 if (is_comptime || instr_is_comptime(fn_ref)) {17719 if (is_comptime || instr_is_comptime(fn_ref)) {
17682 if (fn_ref->value.type->id == ZigTypeIdMetaType) {17720 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
17683 ZigType *ty = ir_resolve_type(ira, fn_ref);17721 ZigType *ty = ir_resolve_type(ira, fn_ref);
17684 if (ty == nullptr)17722 if (ty == nullptr)
17685 return ira->codegen->invalid_instruction;17723 return ira->codegen->invalid_instruction;
...@@ -17688,30 +17726,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -17688,30 +17726,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
17688 add_error_note(ira->codegen, msg, call_instruction->base.source_node,17726 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
17689 buf_sprintf("use @as builtin for type coercion"));17727 buf_sprintf("use @as builtin for type coercion"));
17690 return ira->codegen->invalid_instruction;17728 return ira->codegen->invalid_instruction;
17691 } else if (fn_ref->value.type->id == ZigTypeIdFn) {17729 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
17692 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);17730 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
17693 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type;17731 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;
17694 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type,17732 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type,
17695 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);17733 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
17696 } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {17734 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
17697 assert(fn_ref->value.special == ConstValSpecialStatic);17735 assert(fn_ref->value->special == ConstValSpecialStatic);
17698 ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;17736 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
17699 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;17737 IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
17700 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,17738 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
17701 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);17739 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);
17702 } else {17740 } else {
17703 ir_add_error_node(ira, fn_ref->source_node,17741 ir_add_error_node(ira, fn_ref->source_node,
17704 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name)));17742 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
17705 return ira->codegen->invalid_instruction;17743 return ira->codegen->invalid_instruction;
17706 }17744 }
17707 }17745 }
1770817746
17709 if (fn_ref->value.type->id == ZigTypeIdFn) {17747 if (fn_ref->value->type->id == ZigTypeIdFn) {
17710 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,17748 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value->type,
17711 fn_ref, nullptr, false, call_instruction->fn_inline);17749 fn_ref, nullptr, false, call_instruction->fn_inline);
17712 } else {17750 } else {
17713 ir_add_error_node(ira, fn_ref->source_node,17751 ir_add_error_node(ira, fn_ref->source_node,
17714 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name)));17752 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
17715 return ira->codegen->invalid_instruction;17753 return ira->codegen->invalid_instruction;
17716 }17754 }
17717}17755}
...@@ -17719,12 +17757,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -17719,12 +17757,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
17719// out_val->type must be the type to read the pointer as17757// out_val->type must be the type to read the pointer as
17720// if the type is different than the actual type then it does a comptime byte reinterpretation17758// if the type is different than the actual type then it does a comptime byte reinterpretation
17721static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,17759static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
17722 ConstExprValue *out_val, ConstExprValue *ptr_val)17760 ZigValue *out_val, ZigValue *ptr_val)
17723{17761{
17724 Error err;17762 Error err;
17725 assert(out_val->type != nullptr);17763 assert(out_val->type != nullptr);
1772617764
17727 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);17765 ZigValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);
17728 src_assert(pointee->type != nullptr, source_node);17766 src_assert(pointee->type != nullptr, source_node);
1772917767
17730 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))17768 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
...@@ -17765,7 +17803,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17765,7 +17803,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17765 return ErrorSemanticAnalyzeFail;17803 return ErrorSemanticAnalyzeFail;
17766 }17804 }
17767 case ConstPtrSpecialBaseArray: {17805 case ConstPtrSpecialBaseArray: {
17768 ConstExprValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val;17806 ZigValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val;
17769 assert(array_val->type->id == ZigTypeIdArray);17807 assert(array_val->type->id == ZigTypeIdArray);
17770 if (array_val->data.x_array.special != ConstArraySpecialNone)17808 if (array_val->data.x_array.special != ConstArraySpecialNone)
17771 zig_panic("TODO");17809 zig_panic("TODO");
...@@ -17782,7 +17820,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17782,7 +17820,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17782 Buf buf = BUF_INIT;17820 Buf buf = BUF_INIT;
17783 buf_resize(&buf, elem_count * elem_size);17821 buf_resize(&buf, elem_count * elem_size);
17784 for (size_t i = 0; i < elem_count; i += 1) {17822 for (size_t i = 0; i < elem_count; i += 1) {
17785 ConstExprValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i];17823 ZigValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i];
17786 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);17824 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);
17787 }17825 }
17788 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))17826 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))
...@@ -17803,11 +17841,11 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17803,11 +17841,11 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1780317841
17804static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {17842static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {
17805 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);17843 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
17806 result->value.special = ConstValSpecialLazy;17844 result->value->special = ConstValSpecialLazy;
1780717845
17808 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1);17846 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1);
17809 lazy_opt_type->ira = ira;17847 lazy_opt_type->ira = ira;
17810 result->value.data.x_lazy = &lazy_opt_type->base;17848 result->value->data.x_lazy = &lazy_opt_type->base;
17811 lazy_opt_type->base.id = LazyValueIdOptType;17849 lazy_opt_type->base.id = LazyValueIdOptType;
1781217850
17813 lazy_opt_type->payload_type = instruction->value->child;17851 lazy_opt_type->payload_type = instruction->value->child;
...@@ -17818,7 +17856,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp...@@ -17818,7 +17856,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
17818}17856}
1781917857
17820static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,17858static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,
17821 ConstExprValue *operand_val, ConstExprValue *scalar_out_val, bool is_wrap_op)17859 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
17822{17860{
17823 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);17861 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
1782417862
...@@ -17854,7 +17892,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i...@@ -17854,7 +17892,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i
1785417892
17855static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {17893static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {
17856 IrInstruction *value = instruction->value->child;17894 IrInstruction *value = instruction->value->child;
17857 ZigType *expr_type = value->value.type;17895 ZigType *expr_type = value->value->type;
17858 if (type_is_invalid(expr_type))17896 if (type_is_invalid(expr_type))
17859 return ira->codegen->invalid_instruction;17897 return ira->codegen->invalid_instruction;
1786017898
...@@ -17872,20 +17910,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -17872,20 +17910,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
17872 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;17910 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
1787317911
17874 if (instr_is_comptime(value)) {17912 if (instr_is_comptime(value)) {
17875 ConstExprValue *operand_val = ir_resolve_const(ira, value, UndefBad);17913 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
17876 if (!operand_val)17914 if (!operand_val)
17877 return ira->codegen->invalid_instruction;17915 return ira->codegen->invalid_instruction;
1787817916
17879 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);17917 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);
17880 ConstExprValue *out_val = &result_instruction->value;17918 ZigValue *out_val = result_instruction->value;
17881 if (expr_type->id == ZigTypeIdVector) {17919 if (expr_type->id == ZigTypeIdVector) {
17882 expand_undef_array(ira->codegen, operand_val);17920 expand_undef_array(ira->codegen, operand_val);
17883 out_val->special = ConstValSpecialUndef;17921 out_val->special = ConstValSpecialUndef;
17884 expand_undef_array(ira->codegen, out_val);17922 expand_undef_array(ira->codegen, out_val);
17885 size_t len = expr_type->data.vector.len;17923 size_t len = expr_type->data.vector.len;
17886 for (size_t i = 0; i < len; i += 1) {17924 for (size_t i = 0; i < len; i += 1) {
17887 ConstExprValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i];17925 ZigValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i];
17888 ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];17926 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
17889 assert(scalar_operand_val->type == scalar_type);17927 assert(scalar_operand_val->type == scalar_type);
17890 assert(scalar_out_val->type == scalar_type);17928 assert(scalar_out_val->type == scalar_type);
17891 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,17929 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,
...@@ -17911,31 +17949,31 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -17911,31 +17949,31 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
17911 IrInstruction *result = ir_build_un_op(&ira->new_irb,17949 IrInstruction *result = ir_build_un_op(&ira->new_irb,
17912 instruction->base.scope, instruction->base.source_node,17950 instruction->base.scope, instruction->base.source_node,
17913 instruction->op_id, value);17951 instruction->op_id, value);
17914 result->value.type = expr_type;17952 result->value->type = expr_type;
17915 return result;17953 return result;
17916}17954}
1791717955
17918static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {17956static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
17919 IrInstruction *value = instruction->value->child;17957 IrInstruction *value = instruction->value->child;
17920 ZigType *expr_type = value->value.type;17958 ZigType *expr_type = value->value->type;
17921 if (type_is_invalid(expr_type))17959 if (type_is_invalid(expr_type))
17922 return ira->codegen->invalid_instruction;17960 return ira->codegen->invalid_instruction;
1792317961
17924 if (expr_type->id == ZigTypeIdInt) {17962 if (expr_type->id == ZigTypeIdInt) {
17925 if (instr_is_comptime(value)) {17963 if (instr_is_comptime(value)) {
17926 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);17964 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
17927 if (target_const_val == nullptr)17965 if (target_const_val == nullptr)
17928 return ira->codegen->invalid_instruction;17966 return ira->codegen->invalid_instruction;
1792917967
17930 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);17968 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
17931 bigint_not(&result->value.data.x_bigint, &target_const_val->data.x_bigint,17969 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,
17932 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);17970 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
17933 return result;17971 return result;
17934 }17972 }
1793517973
17936 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,17974 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,
17937 instruction->base.source_node, IrUnOpBinNot, value);17975 instruction->base.source_node, IrUnOpBinNot, value);
17938 result->value.type = expr_type;17976 result->value->type = expr_type;
17939 return result;17977 return result;
17940 }17978 }
1794117979
...@@ -17956,9 +17994,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -17956,9 +17994,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
17956 return ir_analyze_negation(ira, instruction);17994 return ir_analyze_negation(ira, instruction);
17957 case IrUnOpDereference: {17995 case IrUnOpDereference: {
17958 IrInstruction *ptr = instruction->value->child;17996 IrInstruction *ptr = instruction->value->child;
17959 if (type_is_invalid(ptr->value.type))17997 if (type_is_invalid(ptr->value->type))
17960 return ira->codegen->invalid_instruction;17998 return ira->codegen->invalid_instruction;
17961 ZigType *ptr_type = ptr->value.type;17999 ZigType *ptr_type = ptr->value->type;
17962 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {18000 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
17963 ir_add_error_node(ira, instruction->base.source_node,18001 ir_add_error_node(ira, instruction->base.source_node,
17964 buf_sprintf("index syntax required for unknown-length pointer type '%s'",18002 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
...@@ -17971,9 +18009,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -17971,9 +18009,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
17971 return ira->codegen->invalid_instruction;18009 return ira->codegen->invalid_instruction;
1797218010
17973 // If the result needs to be an lvalue, type check it18011 // If the result needs to be an lvalue, type check it
17974 if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) {18012 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {
17975 ir_add_error(ira, &instruction->base,18013 ir_add_error(ira, &instruction->base,
17976 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name)));18014 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
17977 return ira->codegen->invalid_instruction;18015 return ira->codegen->invalid_instruction;
17978 }18016 }
1797918017
...@@ -18016,13 +18054,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr...@@ -18016,13 +18054,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
1801618054
18017 IrInstruction *result = ir_build_br(&ira->new_irb,18055 IrInstruction *result = ir_build_br(&ira->new_irb,
18018 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);18056 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
18019 result->value.type = ira->codegen->builtin_types.entry_unreachable;18057 result->value->type = ira->codegen->builtin_types.entry_unreachable;
18020 return ir_finish_anal(ira, result);18058 return ir_finish_anal(ira, result);
18021}18059}
1802218060
18023static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {18061static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
18024 IrInstruction *condition = cond_br_instruction->condition->child;18062 IrInstruction *condition = cond_br_instruction->condition->child;
18025 if (type_is_invalid(condition->value.type))18063 if (type_is_invalid(condition->value->type))
18026 return ir_unreach_error(ira);18064 return ir_unreach_error(ira);
1802718065
18028 bool is_comptime;18066 bool is_comptime;
...@@ -18031,7 +18069,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -18031,7 +18069,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1803118069
18032 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;18070 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
18033 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);18071 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
18034 if (type_is_invalid(casted_condition->value.type))18072 if (type_is_invalid(casted_condition->value->type))
18035 return ir_unreach_error(ira);18073 return ir_unreach_error(ira);
1803618074
18037 if (is_comptime || instr_is_comptime(casted_condition)) {18075 if (is_comptime || instr_is_comptime(casted_condition)) {
...@@ -18053,7 +18091,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -18053,7 +18091,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1805318091
18054 IrInstruction *result = ir_build_br(&ira->new_irb,18092 IrInstruction *result = ir_build_br(&ira->new_irb,
18055 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);18093 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);
18056 result->value.type = ira->codegen->builtin_types.entry_unreachable;18094 result->value->type = ira->codegen->builtin_types.entry_unreachable;
18057 return ir_finish_anal(ira, result);18095 return ir_finish_anal(ira, result);
18058 }18096 }
1805918097
...@@ -18072,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -18072,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
18072 IrInstruction *result = ir_build_cond_br(&ira->new_irb,18110 IrInstruction *result = ir_build_cond_br(&ira->new_irb,
18073 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,18111 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,
18074 casted_condition, new_then_block, new_else_block, nullptr);18112 casted_condition, new_then_block, new_else_block, nullptr);
18075 result->value.type = ira->codegen->builtin_types.entry_unreachable;18113 result->value->type = ira->codegen->builtin_types.entry_unreachable;
18076 return ir_finish_anal(ira, result);18114 return ir_finish_anal(ira, result);
18077}18115}
1807818116
...@@ -18081,7 +18119,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,...@@ -18081,7 +18119,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,
18081{18119{
18082 IrInstruction *result = ir_build_unreachable(&ira->new_irb,18120 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
18083 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);18121 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);
18084 result->value.type = ira->codegen->builtin_types.entry_unreachable;18122 result->value->type = ira->codegen->builtin_types.entry_unreachable;
18085 return ir_finish_anal(ira, result);18123 return ir_finish_anal(ira, result);
18086}18124}
1808718125
...@@ -18094,13 +18132,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18094,13 +18132,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18094 if (predecessor != ira->const_predecessor_bb)18132 if (predecessor != ira->const_predecessor_bb)
18095 continue;18133 continue;
18096 IrInstruction *value = phi_instruction->incoming_values[i]->child;18134 IrInstruction *value = phi_instruction->incoming_values[i]->child;
18097 assert(value->value.type);18135 assert(value->value->type);
18098 if (type_is_invalid(value->value.type))18136 if (type_is_invalid(value->value->type))
18099 return ira->codegen->invalid_instruction;18137 return ira->codegen->invalid_instruction;
1810018138
18101 if (value->value.special != ConstValSpecialRuntime) {18139 if (value->value->special != ConstValSpecialRuntime) {
18102 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);18140 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);
18103 copy_const_val(&result->value, &value->value, true);18141 copy_const_val(result->value, value->value, true);
18104 return result;18142 return result;
18105 } else {18143 } else {
18106 return value;18144 return value;
...@@ -18126,7 +18164,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18126,7 +18164,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18126 } else {18164 } else {
18127 instructions[i] = ir_const(ira, this_peer->base.source_instruction,18165 instructions[i] = ir_const(ira, this_peer->base.source_instruction,
18128 this_peer->base.implicit_elem_type);18166 this_peer->base.implicit_elem_type);
18129 instructions[i]->value.special = ConstValSpecialRuntime;18167 instructions[i]->value->special = ConstValSpecialRuntime;
18130 }18168 }
18131 } else {18169 } else {
18132 instructions[i] = gen_instruction;18170 instructions[i] = gen_instruction;
...@@ -18147,7 +18185,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18147,7 +18185,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18147 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,18185 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
18148 peer_parent->resolved_type, nullptr, false, false, true);18186 peer_parent->resolved_type, nullptr, false, false, true);
18149 if (parent_result_loc != nullptr &&18187 if (parent_result_loc != nullptr &&
18150 (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc)))18188 (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc)))
18151 {18189 {
18152 return parent_result_loc;18190 return parent_result_loc;
18153 }18191 }
...@@ -18160,7 +18198,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18160,7 +18198,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18160 if (instrs_to_move.length != 0) {18198 if (instrs_to_move.length != 0) {
18161 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;18199 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;
18162 IrInstruction *branch_instruction = predecessor->instruction_list.pop();18200 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
18163 ir_assert(branch_instruction->value.type->id == ZigTypeIdUnreachable, &phi_instruction->base);18201 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base);
18164 while (instrs_to_move.length != 0) {18202 while (instrs_to_move.length != 0) {
18165 predecessor->instruction_list.append(instrs_to_move.pop());18203 predecessor->instruction_list.append(instrs_to_move.pop());
18166 }18204 }
...@@ -18197,10 +18235,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18197,10 +18235,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18197 IrInstruction *old_value = phi_instruction->incoming_values[i];18235 IrInstruction *old_value = phi_instruction->incoming_values[i];
18198 assert(old_value);18236 assert(old_value);
18199 IrInstruction *new_value = old_value->child;18237 IrInstruction *new_value = old_value->child;
18200 if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)18238 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
18201 continue;18239 continue;
1820218240
18203 if (type_is_invalid(new_value->value.type))18241 if (type_is_invalid(new_value->value->type))
18204 return ira->codegen->invalid_instruction;18242 return ira->codegen->invalid_instruction;
1820518243
1820618244
...@@ -18212,7 +18250,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18212,7 +18250,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18212 if (new_incoming_blocks.length == 0) {18250 if (new_incoming_blocks.length == 0) {
18213 IrInstruction *result = ir_build_unreachable(&ira->new_irb,18251 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
18214 phi_instruction->base.scope, phi_instruction->base.source_node);18252 phi_instruction->base.scope, phi_instruction->base.source_node);
18215 result->value.type = ira->codegen->builtin_types.entry_unreachable;18253 result->value->type = ira->codegen->builtin_types.entry_unreachable;
18216 return ir_finish_anal(ira, result);18254 return ir_finish_anal(ira, result);
18217 }18255 }
1821818256
...@@ -18233,7 +18271,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18233,7 +18271,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
18233 if (type_is_invalid(resolved_type))18271 if (type_is_invalid(resolved_type))
18234 return ira->codegen->invalid_instruction;18272 return ira->codegen->invalid_instruction;
18235 } else {18273 } else {
18236 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;18274 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
18237 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);18275 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
18238 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;18276 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
18239 }18277 }
...@@ -18281,14 +18319,14 @@ skip_resolve_peer_types:...@@ -18281,14 +18319,14 @@ skip_resolve_peer_types:
18281 IrInstruction *branch_instruction = predecessor->instruction_list.pop();18319 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
18282 ir_set_cursor_at_end(&ira->new_irb, predecessor);18320 ir_set_cursor_at_end(&ira->new_irb, predecessor);
18283 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);18321 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
18284 if (type_is_invalid(casted_value->value.type)) {18322 if (type_is_invalid(casted_value->value->type)) {
18285 return ira->codegen->invalid_instruction;18323 return ira->codegen->invalid_instruction;
18286 }18324 }
18287 new_incoming_values.items[i] = casted_value;18325 new_incoming_values.items[i] = casted_value;
18288 predecessor->instruction_list.append(branch_instruction);18326 predecessor->instruction_list.append(branch_instruction);
1828918327
18290 if (all_stack_ptrs && (casted_value->value.special != ConstValSpecialRuntime ||18328 if (all_stack_ptrs && (casted_value->value->special != ConstValSpecialRuntime ||
18291 casted_value->value.data.rh_ptr != RuntimeHintPtrStack))18329 casted_value->value->data.rh_ptr != RuntimeHintPtrStack))
18292 {18330 {
18293 all_stack_ptrs = false;18331 all_stack_ptrs = false;
18294 }18332 }
...@@ -18298,11 +18336,11 @@ skip_resolve_peer_types:...@@ -18298,11 +18336,11 @@ skip_resolve_peer_types:
18298 IrInstruction *result = ir_build_phi(&ira->new_irb,18336 IrInstruction *result = ir_build_phi(&ira->new_irb,
18299 phi_instruction->base.scope, phi_instruction->base.source_node,18337 phi_instruction->base.scope, phi_instruction->base.source_node,
18300 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);18338 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);
18301 result->value.type = resolved_type;18339 result->value->type = resolved_type;
1830218340
18303 if (all_stack_ptrs) {18341 if (all_stack_ptrs) {
18304 assert(result->value.special == ConstValSpecialRuntime);18342 assert(result->value->special == ConstValSpecialRuntime);
18305 result->value.data.rh_ptr = RuntimeHintPtrStack;18343 result->value->data.rh_ptr = RuntimeHintPtrStack;
18306 }18344 }
1830718345
18308 return result;18346 return result;
...@@ -18358,13 +18396,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {...@@ -18358,13 +18396,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
18358static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {18396static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
18359 Error err;18397 Error err;
18360 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;18398 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;
18361 if (type_is_invalid(array_ptr->value.type))18399 if (type_is_invalid(array_ptr->value->type))
18362 return ira->codegen->invalid_instruction;18400 return ira->codegen->invalid_instruction;
1836318401
18364 ConstExprValue *orig_array_ptr_val = &array_ptr->value;18402 ZigValue *orig_array_ptr_val = array_ptr->value;
1836518403
18366 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;18404 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;
18367 if (type_is_invalid(elem_index->value.type))18405 if (type_is_invalid(elem_index->value->type))
18368 return ira->codegen->invalid_instruction;18406 return ira->codegen->invalid_instruction;
1836918407
18370 ZigType *ptr_type = orig_array_ptr_val->type;18408 ZigType *ptr_type = orig_array_ptr_val->type;
...@@ -18428,10 +18466,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18428,10 +18466,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18428 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,18466 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,
18429 elem_ptr_instruction->ptr_len);18467 elem_ptr_instruction->ptr_len);
18430 } else if (array_type->id == ZigTypeIdArgTuple) {18468 } else if (array_type->id == ZigTypeIdArgTuple) {
18431 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);18469 ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
18432 if (!ptr_val)18470 if (!ptr_val)
18433 return ira->codegen->invalid_instruction;18471 return ira->codegen->invalid_instruction;
18434 ConstExprValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);18472 ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);
18435 if (args_val == nullptr)18473 if (args_val == nullptr)
18436 return ira->codegen->invalid_instruction;18474 return ira->codegen->invalid_instruction;
18437 size_t start = args_val->data.x_arg_tuple.start_index;18475 size_t start = args_val->data.x_arg_tuple.start_index;
...@@ -18471,7 +18509,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18471,7 +18509,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18471 return ira->codegen->invalid_instruction;18509 return ira->codegen->invalid_instruction;
18472 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);18510 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
18473 Buf *field_name = buf_alloc();18511 Buf *field_name = buf_alloc();
18474 bigint_append_buf(field_name, &casted_elem_index->value.data.x_bigint, 10);18512 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
18475 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,18513 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,
18476 array_ptr, array_type);18514 array_ptr, array_type);
18477 } else {18515 } else {
...@@ -18487,13 +18525,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18487,13 +18525,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1848718525
18488 bool safety_check_on = elem_ptr_instruction->safety_check_on;18526 bool safety_check_on = elem_ptr_instruction->safety_check_on;
18489 if (instr_is_comptime(casted_elem_index)) {18527 if (instr_is_comptime(casted_elem_index)) {
18490 uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);18528 uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint);
18491 if (array_type->id == ZigTypeIdArray) {18529 if (array_type->id == ZigTypeIdArray) {
18492 uint64_t array_len = array_type->data.array.len;18530 uint64_t array_len = array_type->data.array.len;
18493 if (index == array_len && array_type->data.array.sentinel != nullptr) {18531 if (index == array_len && array_type->data.array.sentinel != nullptr) {
18494 ZigType *elem_type = array_type->data.array.child_type;18532 ZigType *elem_type = array_type->data.array.child_type;
18495 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);18533 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);
18496 copy_const_val(&sentinel_elem->value, array_type->data.array.sentinel, false);18534 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false);
18497 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);18535 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
18498 }18536 }
18499 if (index >= array_len) {18537 if (index >= array_len) {
...@@ -18544,7 +18582,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18544,7 +18582,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18544 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||18582 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
18545 array_type->id == ZigTypeIdArray))18583 array_type->id == ZigTypeIdArray))
18546 {18584 {
18547 ConstExprValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,18585 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
18548 elem_ptr_instruction->base.source_node);18586 elem_ptr_instruction->base.source_node);
18549 if (array_ptr_val == nullptr)18587 if (array_ptr_val == nullptr)
18550 return ira->codegen->invalid_instruction;18588 return ira->codegen->invalid_instruction;
...@@ -18557,7 +18595,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18557,7 +18595,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18557 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);18595 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
18558 array_ptr_val->special = ConstValSpecialStatic;18596 array_ptr_val->special = ConstValSpecialStatic;
18559 for (size_t i = 0; i < array_type->data.array.len; i += 1) {18597 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
18560 ConstExprValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];18598 ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
18561 elem_val->special = ConstValSpecialUndef;18599 elem_val->special = ConstValSpecialUndef;
18562 elem_val->type = array_type->data.array.child_type;18600 elem_val->type = array_type->data.array.child_type;
18563 elem_val->parent.id = ConstParentIdArray;18601 elem_val->parent.id = ConstParentIdArray;
...@@ -18565,8 +18603,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18565,8 +18603,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18565 elem_val->parent.data.p_array.elem_index = i;18603 elem_val->parent.data.p_array.elem_index = i;
18566 }18604 }
18567 } else if (is_slice(array_type)) {18605 } else if (is_slice(array_type)) {
18568 ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);18606 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);
18569 ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type;18607 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1857018608
18571 if (type_is_invalid(actual_array_type))18609 if (type_is_invalid(actual_array_type))
18572 return ira->codegen->invalid_instruction;18610 return ira->codegen->invalid_instruction;
...@@ -18576,14 +18614,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18576,14 +18614,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18576 return ira->codegen->invalid_instruction;18614 return ira->codegen->invalid_instruction;
18577 }18615 }
1857818616
18579 ConstExprValue *array_init_val = create_const_vals(1);18617 ZigValue *array_init_val = create_const_vals(1);
18580 array_init_val->special = ConstValSpecialStatic;18618 array_init_val->special = ConstValSpecialStatic;
18581 array_init_val->type = actual_array_type;18619 array_init_val->type = actual_array_type;
18582 array_init_val->data.x_array.special = ConstArraySpecialNone;18620 array_init_val->data.x_array.special = ConstArraySpecialNone;
18583 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);18621 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
18584 array_init_val->special = ConstValSpecialStatic;18622 array_init_val->special = ConstValSpecialStatic;
18585 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {18623 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {
18586 ConstExprValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];18624 ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];
18587 elem_val->special = ConstValSpecialUndef;18625 elem_val->special = ConstValSpecialUndef;
18588 elem_val->type = actual_array_type->data.array.child_type;18626 elem_val->type = actual_array_type->data.array.child_type;
18589 elem_val->parent.id = ConstParentIdArray;18627 elem_val->parent.id = ConstParentIdArray;
...@@ -18608,7 +18646,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18608,7 +18646,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18608 {18646 {
18609 if (array_type->id == ZigTypeIdPointer) {18647 if (array_type->id == ZigTypeIdPointer) {
18610 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);18648 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18611 ConstExprValue *out_val = &result->value;18649 ZigValue *out_val = result->value;
18612 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;18650 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
18613 size_t new_index;18651 size_t new_index;
18614 size_t mem_size;18652 size_t mem_size;
...@@ -18619,7 +18657,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18619,7 +18657,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18619 zig_unreachable();18657 zig_unreachable();
18620 case ConstPtrSpecialRef:18658 case ConstPtrSpecialRef:
18621 if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) {18659 if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) {
18622 ConstExprValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee;18660 ZigValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee;
18623 new_index = index;18661 new_index = index;
18624 ZigType *array_type = array_val->type;18662 ZigType *array_type = array_val->type;
18625 mem_size = array_type->data.array.len;18663 mem_size = array_type->data.array.len;
...@@ -18682,18 +18720,18 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18682,18 +18720,18 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18682 }18720 }
18683 return result;18721 return result;
18684 } else if (is_slice(array_type)) {18722 } else if (is_slice(array_type)) {
18685 ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];18723 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
18686 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);18724 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
18687 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {18725 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
18688 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,18726 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
18689 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,18727 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
18690 elem_ptr_instruction->ptr_len, nullptr);18728 elem_ptr_instruction->ptr_len, nullptr);
18691 result->value.type = return_type;18729 result->value->type = return_type;
18692 return result;18730 return result;
18693 }18731 }
18694 ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];18732 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
18695 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);18733 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18696 ConstExprValue *out_val = &result->value;18734 ZigValue *out_val = result->value;
18697 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;18735 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
18698 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);18736 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
18699 uint64_t full_slice_len = slice_len +18737 uint64_t full_slice_len = slice_len +
...@@ -18752,12 +18790,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18752,12 +18790,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18752 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,18790 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
18753 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,18791 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
18754 false, elem_ptr_instruction->ptr_len, nullptr);18792 false, elem_ptr_instruction->ptr_len, nullptr);
18755 result->value.type = return_type;18793 result->value->type = return_type;
18756 result->value.special = ConstValSpecialStatic;18794 result->value->special = ConstValSpecialStatic;
18757 } else {18795 } else {
18758 result = ir_const(ira, &elem_ptr_instruction->base, return_type);18796 result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18759 }18797 }
18760 ConstExprValue *out_val = &result->value;18798 ZigValue *out_val = result->value;
18761 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;18799 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
18762 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;18800 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
18763 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;18801 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
...@@ -18814,7 +18852,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18814,7 +18852,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18814 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,18852 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
18815 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,18853 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
18816 elem_ptr_instruction->ptr_len, nullptr);18854 elem_ptr_instruction->ptr_len, nullptr);
18817 result->value.type = return_type;18855 result->value->type = return_type;
18818 return result;18856 return result;
18819}18857}
1882018858
...@@ -18892,8 +18930,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18892,8 +18930,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18892 case OnePossibleValueNo:18930 case OnePossibleValueNo:
18893 break;18931 break;
18894 }18932 }
18895 bool is_const = struct_ptr->value.type->data.pointer.is_const;18933 bool is_const = struct_ptr->value->type->data.pointer.is_const;
18896 bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile;18934 bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile;
18897 ZigType *ptr_type;18935 ZigType *ptr_type;
18898 if (struct_type->data.structure.is_inferred) {18936 if (struct_type->data.structure.is_inferred) {
18899 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,18937 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
...@@ -18904,9 +18942,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18904,9 +18942,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18904 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;18942 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
18905 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))18943 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
18906 return ira->codegen->invalid_instruction;18944 return ira->codegen->invalid_instruction;
18907 assert(struct_ptr->value.type->id == ZigTypeIdPointer);18945 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
18908 uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host;18946 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
18909 uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes;18947 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;
18910 uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ?18948 uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ?
18911 get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes;18949 get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes;
18912 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,18950 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
...@@ -18915,12 +18953,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18915,12 +18953,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18915 (uint32_t)host_int_bytes_for_result_type, false);18953 (uint32_t)host_int_bytes_for_result_type, false);
18916 }18954 }
18917 if (instr_is_comptime(struct_ptr)) {18955 if (instr_is_comptime(struct_ptr)) {
18918 ConstExprValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);18956 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
18919 if (!ptr_val)18957 if (!ptr_val)
18920 return ira->codegen->invalid_instruction;18958 return ira->codegen->invalid_instruction;
1892118959
18922 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {18960 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18923 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);18961 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
18924 if (struct_val == nullptr)18962 if (struct_val == nullptr)
18925 return ira->codegen->invalid_instruction;18963 return ira->codegen->invalid_instruction;
18926 if (type_is_invalid(struct_val->type))18964 if (type_is_invalid(struct_val->type))
...@@ -18929,7 +18967,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18929,7 +18967,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18929 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);18967 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
18930 struct_val->special = ConstValSpecialStatic;18968 struct_val->special = ConstValSpecialStatic;
18931 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {18969 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
18932 ConstExprValue *field_val = struct_val->data.x_struct.fields[i];18970 ZigValue *field_val = struct_val->data.x_struct.fields[i];
18933 field_val->special = ConstValSpecialUndef;18971 field_val->special = ConstValSpecialUndef;
18934 field_val->type = resolve_struct_field_type(ira->codegen,18972 field_val->type = resolve_struct_field_type(ira->codegen,
18935 struct_type->data.structure.fields[i]);18973 struct_type->data.structure.fields[i]);
...@@ -18942,12 +18980,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18942,12 +18980,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18942 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {18980 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
18943 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,18981 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,
18944 source_instr->source_node, struct_ptr, field);18982 source_instr->source_node, struct_ptr, field);
18945 result->value.type = ptr_type;18983 result->value->type = ptr_type;
18946 result->value.special = ConstValSpecialStatic;18984 result->value->special = ConstValSpecialStatic;
18947 } else {18985 } else {
18948 result = ir_const(ira, source_instr, ptr_type);18986 result = ir_const(ira, source_instr, ptr_type);
18949 }18987 }
18950 ConstExprValue *const_val = &result->value;18988 ZigValue *const_val = result->value;
18951 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;18989 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
18952 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;18990 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
18953 const_val->data.x_ptr.data.base_struct.struct_val = struct_val;18991 const_val->data.x_ptr.data.base_struct.struct_val = struct_val;
...@@ -18957,7 +18995,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18957,7 +18995,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18957 }18995 }
18958 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,18996 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
18959 struct_ptr, field);18997 struct_ptr, field);
18960 result->value.type = ptr_type;18998 result->value->type = ptr_type;
18961 return result;18999 return result;
18962}19000}
1896319001
...@@ -18970,7 +19008,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -18970,7 +19008,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
18970 // the field type will then be available, and the field will be added to the inferred19008 // the field type will then be available, and the field will be added to the inferred
18971 // struct.19009 // struct.
1897219010
18973 ZigType *container_ptr_type = container_ptr->value.type;19011 ZigType *container_ptr_type = container_ptr->value->type;
18974 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);19012 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
1897519013
18976 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");19014 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");
...@@ -18984,14 +19022,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -18984,14 +19022,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1898419022
18985 if (instr_is_comptime(container_ptr)) {19023 if (instr_is_comptime(container_ptr)) {
18986 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);19024 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);
18987 copy_const_val(&result->value, &container_ptr->value, false);19025 copy_const_val(result->value, container_ptr->value, false);
18988 result->value.type = field_ptr_type;19026 result->value->type = field_ptr_type;
18989 return result;19027 return result;
18990 }19028 }
1899119029
18992 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,19030 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,
18993 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);19031 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
18994 result->value.type = field_ptr_type;19032 result->value->type = field_ptr_type;
18995 return result;19033 return result;
18996}19034}
1899719035
...@@ -19011,7 +19049,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19011,7 +19049,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19011 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))19049 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
19012 return ira->codegen->invalid_instruction;19050 return ira->codegen->invalid_instruction;
1901319051
19014 assert(container_ptr->value.type->id == ZigTypeIdPointer);19052 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19015 if (bare_type->id == ZigTypeIdStruct) {19053 if (bare_type->id == ZigTypeIdStruct) {
19016 TypeStructField *field = find_struct_type_field(bare_type, field_name);19054 TypeStructField *field = find_struct_type_field(bare_type, field_name);
19017 if (field != nullptr) {19055 if (field != nullptr) {
...@@ -19028,8 +19066,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19028,8 +19066,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19028 }19066 }
1902919067
19030 if (bare_type->id == ZigTypeIdUnion) {19068 if (bare_type->id == ZigTypeIdUnion) {
19031 bool is_const = container_ptr->value.type->data.pointer.is_const;19069 bool is_const = container_ptr->value->type->data.pointer.is_const;
19032 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;19070 bool is_volatile = container_ptr->value->type->data.pointer.is_volatile;
1903319071
19034 TypeUnionField *field = find_union_type_field(bare_type, field_name);19072 TypeUnionField *field = find_union_type_field(bare_type, field_name);
19035 if (field == nullptr) {19073 if (field == nullptr) {
...@@ -19044,20 +19082,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19044,20 +19082,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19044 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,19082 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
19045 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);19083 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
19046 if (instr_is_comptime(container_ptr)) {19084 if (instr_is_comptime(container_ptr)) {
19047 ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19085 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19048 if (!ptr_val)19086 if (!ptr_val)
19049 return ira->codegen->invalid_instruction;19087 return ira->codegen->invalid_instruction;
1905019088
19051 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&19089 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
19052 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {19090 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
19053 ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);19091 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
19054 if (union_val == nullptr)19092 if (union_val == nullptr)
19055 return ira->codegen->invalid_instruction;19093 return ira->codegen->invalid_instruction;
19056 if (type_is_invalid(union_val->type))19094 if (type_is_invalid(union_val->type))
19057 return ira->codegen->invalid_instruction;19095 return ira->codegen->invalid_instruction;
1905819096
19059 if (initializing) {19097 if (initializing) {
19060 ConstExprValue *payload_val = create_const_vals(1);19098 ZigValue *payload_val = create_const_vals(1);
19061 payload_val->special = ConstValSpecialUndef;19099 payload_val->special = ConstValSpecialUndef;
19062 payload_val->type = field_type;19100 payload_val->type = field_type;
19063 payload_val->parent.id = ConstParentIdUnion;19101 payload_val->parent.id = ConstParentIdUnion;
...@@ -19079,20 +19117,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19079,20 +19117,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19079 }19117 }
19080 }19118 }
1908119119
19082 ConstExprValue *payload_val = union_val->data.x_union.payload;19120 ZigValue *payload_val = union_val->data.x_union.payload;
1908319121
19084 IrInstruction *result;19122 IrInstruction *result;
19085 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {19123 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
19086 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,19124 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
19087 source_instr->source_node, container_ptr, field, true, initializing);19125 source_instr->source_node, container_ptr, field, true, initializing);
19088 result->value.type = ptr_type;19126 result->value->type = ptr_type;
19089 result->value.special = ConstValSpecialStatic;19127 result->value->special = ConstValSpecialStatic;
19090 } else {19128 } else {
19091 result = ir_const(ira, source_instr, ptr_type);19129 result = ir_const(ira, source_instr, ptr_type);
19092 }19130 }
19093 ConstExprValue *const_val = &result->value;19131 ZigValue *const_val = result->value;
19094 const_val->data.x_ptr.special = ConstPtrSpecialRef;19132 const_val->data.x_ptr.special = ConstPtrSpecialRef;
19095 const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut;19133 const_val->data.x_ptr.mut = container_ptr->value->data.x_ptr.mut;
19096 const_val->data.x_ptr.data.ref.pointee = payload_val;19134 const_val->data.x_ptr.data.ref.pointee = payload_val;
19097 return result;19135 return result;
19098 }19136 }
...@@ -19100,7 +19138,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19100,7 +19138,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1910019138
19101 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,19139 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
19102 source_instr->source_node, container_ptr, field, true, initializing);19140 source_instr->source_node, container_ptr, field, true, initializing);
19103 result->value.type = ptr_type;19141 result->value->type = ptr_type;
19104 return result;19142 return result;
19105 }19143 }
1910619144
...@@ -19205,10 +19243,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n...@@ -19205,10 +19243,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
19205static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {19243static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
19206 Error err;19244 Error err;
19207 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;19245 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;
19208 if (type_is_invalid(container_ptr->value.type))19246 if (type_is_invalid(container_ptr->value->type))
19209 return ira->codegen->invalid_instruction;19247 return ira->codegen->invalid_instruction;
1921019248
19211 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;19249 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;
1921219250
19213 Buf *field_name = field_ptr_instruction->field_name_buffer;19251 Buf *field_name = field_ptr_instruction->field_name_buffer;
19214 if (!field_name) {19252 if (!field_name) {
...@@ -19224,7 +19262,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19224,7 +19262,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19224 if (type_is_invalid(container_type)) {19262 if (type_is_invalid(container_type)) {
19225 return ira->codegen->invalid_instruction;19263 return ira->codegen->invalid_instruction;
19226 } else if (is_slice(container_type) || is_container_ref(container_type)) {19264 } else if (is_slice(container_type) || is_container_ref(container_type)) {
19227 assert(container_ptr->value.type->id == ZigTypeIdPointer);19265 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19228 if (container_type->id == ZigTypeIdPointer) {19266 if (container_type->id == ZigTypeIdPointer) {
19229 ZigType *bare_type = container_ref_type(container_type);19267 ZigType *bare_type = container_ref_type(container_type);
19230 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);19268 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);
...@@ -19236,7 +19274,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19236,7 +19274,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19236 }19274 }
19237 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {19275 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
19238 if (buf_eql_str(field_name, "len")) {19276 if (buf_eql_str(field_name, "len")) {
19239 ConstExprValue *len_val = create_const_vals(1);19277 ZigValue *len_val = create_const_vals(1);
19240 if (container_type->id == ZigTypeIdPointer) {19278 if (container_type->id == ZigTypeIdPointer) {
19241 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);19279 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
19242 } else {19280 } else {
...@@ -19255,17 +19293,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19255,17 +19293,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19255 return ira->codegen->invalid_instruction;19293 return ira->codegen->invalid_instruction;
19256 }19294 }
19257 } else if (container_type->id == ZigTypeIdArgTuple) {19295 } else if (container_type->id == ZigTypeIdArgTuple) {
19258 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19296 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19259 if (!container_ptr_val)19297 if (!container_ptr_val)
19260 return ira->codegen->invalid_instruction;19298 return ira->codegen->invalid_instruction;
1926119299
19262 assert(container_ptr->value.type->id == ZigTypeIdPointer);19300 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19263 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);19301 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19264 if (child_val == nullptr)19302 if (child_val == nullptr)
19265 return ira->codegen->invalid_instruction;19303 return ira->codegen->invalid_instruction;
1926619304
19267 if (buf_eql_str(field_name, "len")) {19305 if (buf_eql_str(field_name, "len")) {
19268 ConstExprValue *len_val = create_const_vals(1);19306 ZigValue *len_val = create_const_vals(1);
19269 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;19307 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
19270 init_const_usize(ira->codegen, len_val, len);19308 init_const_usize(ira->codegen, len_val, len);
1927119309
...@@ -19281,12 +19319,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19281,12 +19319,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19281 return ira->codegen->invalid_instruction;19319 return ira->codegen->invalid_instruction;
19282 }19320 }
19283 } else if (container_type->id == ZigTypeIdMetaType) {19321 } else if (container_type->id == ZigTypeIdMetaType) {
19284 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19322 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19285 if (!container_ptr_val)19323 if (!container_ptr_val)
19286 return ira->codegen->invalid_instruction;19324 return ira->codegen->invalid_instruction;
1928719325
19288 assert(container_ptr->value.type->id == ZigTypeIdPointer);19326 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19289 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);19327 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19290 if (child_val == nullptr)19328 if (child_val == nullptr)
19291 return ira->codegen->invalid_instruction;19329 return ira->codegen->invalid_instruction;
19292 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,19330 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
...@@ -19382,7 +19420,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19382,7 +19420,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19382 }19420 }
19383 err_set_type = child_type;19421 err_set_type = child_type;
19384 }19422 }
19385 ConstExprValue *const_val = create_const_vals(1);19423 ZigValue *const_val = create_const_vals(1);
19386 const_val->special = ConstValSpecialStatic;19424 const_val->special = ConstValSpecialStatic;
19387 const_val->type = err_set_type;19425 const_val->type = err_set_type;
19388 const_val->data.x_err_set = err_entry;19426 const_val->data.x_err_set = err_entry;
...@@ -19567,11 +19605,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19567,11 +19605,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1956719605
19568static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {19606static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {
19569 IrInstruction *ptr = instruction->ptr->child;19607 IrInstruction *ptr = instruction->ptr->child;
19570 if (type_is_invalid(ptr->value.type))19608 if (type_is_invalid(ptr->value->type))
19571 return ira->codegen->invalid_instruction;19609 return ira->codegen->invalid_instruction;
1957219610
19573 IrInstruction *value = instruction->value->child;19611 IrInstruction *value = instruction->value->child;
19574 if (type_is_invalid(value->value.type))19612 if (type_is_invalid(value->value->type))
19575 return ira->codegen->invalid_instruction;19613 return ira->codegen->invalid_instruction;
1957619614
19577 return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const);19615 return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const);
...@@ -19579,14 +19617,14 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc...@@ -19579,14 +19617,14 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc
1957919617
19580static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {19618static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {
19581 IrInstruction *ptr = instruction->ptr->child;19619 IrInstruction *ptr = instruction->ptr->child;
19582 if (type_is_invalid(ptr->value.type))19620 if (type_is_invalid(ptr->value->type))
19583 return ira->codegen->invalid_instruction;19621 return ira->codegen->invalid_instruction;
19584 return ir_get_deref(ira, &instruction->base, ptr, nullptr);19622 return ir_get_deref(ira, &instruction->base, ptr, nullptr);
19585}19623}
1958619624
19587static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {19625static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
19588 IrInstruction *expr_value = typeof_instruction->value->child;19626 IrInstruction *expr_value = typeof_instruction->value->child;
19589 ZigType *type_entry = expr_value->value.type;19627 ZigType *type_entry = expr_value->value->type;
19590 if (type_is_invalid(type_entry))19628 if (type_is_invalid(type_entry))
19591 return ira->codegen->invalid_instruction;19629 return ira->codegen->invalid_instruction;
19592 return ir_const_type(ira, &typeof_instruction->base, type_entry);19630 return ir_const_type(ira, &typeof_instruction->base, type_entry);
...@@ -19749,11 +19787,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -19749,11 +19787,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
19749 IrInstructionSliceType *slice_type_instruction)19787 IrInstructionSliceType *slice_type_instruction)
19750{19788{
19751 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);19789 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);
19752 result->value.special = ConstValSpecialLazy;19790 result->value->special = ConstValSpecialLazy;
1975319791
19754 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1);19792 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1);
19755 lazy_slice_type->ira = ira;19793 lazy_slice_type->ira = ira;
19756 result->value.data.x_lazy = &lazy_slice_type->base;19794 result->value->data.x_lazy = &lazy_slice_type->base;
19757 lazy_slice_type->base.id = LazyValueIdSliceType;19795 lazy_slice_type->base.id = LazyValueIdSliceType;
1975819796
19759 if (slice_type_instruction->align_value != nullptr) {19797 if (slice_type_instruction->align_value != nullptr) {
...@@ -19812,14 +19850,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -19812,14 +19850,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
1981219850
19813 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {19851 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
19814 IrInstruction *const input_value = asm_instruction->input_list[i]->child;19852 IrInstruction *const input_value = asm_instruction->input_list[i]->child;
19815 if (type_is_invalid(input_value->value.type))19853 if (type_is_invalid(input_value->value->type))
19816 return ira->codegen->invalid_instruction;19854 return ira->codegen->invalid_instruction;
1981719855
19818 if (instr_is_comptime(input_value) &&19856 if (instr_is_comptime(input_value) &&
19819 (input_value->value.type->id == ZigTypeIdComptimeInt ||19857 (input_value->value->type->id == ZigTypeIdComptimeInt ||
19820 input_value->value.type->id == ZigTypeIdComptimeFloat)) {19858 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
19821 ir_add_error_node(ira, input_value->source_node,19859 ir_add_error_node(ira, input_value->source_node,
19822 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name)));19860 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
19823 return ira->codegen->invalid_instruction;19861 return ira->codegen->invalid_instruction;
19824 }19862 }
1982519863
...@@ -19831,7 +19869,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -19831,7 +19869,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
19831 asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len,19869 asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len,
19832 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,19870 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
19833 asm_instruction->has_side_effects);19871 asm_instruction->has_side_effects);
19834 result->value.type = return_type;19872 result->value->type = return_type;
19835 return result;19873 return result;
19836}19874}
1983719875
...@@ -19850,13 +19888,13 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -19850,13 +19888,13 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
19850 if (type_is_invalid(child_type))19888 if (type_is_invalid(child_type))
19851 return ira->codegen->invalid_instruction;19889 return ira->codegen->invalid_instruction;
1985219890
19853 ConstExprValue *sentinel_val;19891 ZigValue *sentinel_val;
19854 if (array_type_instruction->sentinel != nullptr) {19892 if (array_type_instruction->sentinel != nullptr) {
19855 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;19893 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;
19856 if (type_is_invalid(uncasted_sentinel->value.type))19894 if (type_is_invalid(uncasted_sentinel->value->type))
19857 return ira->codegen->invalid_instruction;19895 return ira->codegen->invalid_instruction;
19858 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type);19896 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type);
19859 if (type_is_invalid(sentinel->value.type))19897 if (type_is_invalid(sentinel->value->type))
19860 return ira->codegen->invalid_instruction;19898 return ira->codegen->invalid_instruction;
19861 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);19899 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
19862 if (sentinel_val == nullptr)19900 if (sentinel_val == nullptr)
...@@ -19909,11 +19947,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -19909,11 +19947,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1990919947
19910static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {19948static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {
19911 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);19949 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
19912 result->value.special = ConstValSpecialLazy;19950 result->value->special = ConstValSpecialLazy;
1991319951
19914 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1);19952 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1);
19915 lazy_size_of->ira = ira;19953 lazy_size_of->ira = ira;
19916 result->value.data.x_lazy = &lazy_size_of->base;19954 result->value->data.x_lazy = &lazy_size_of->base;
19917 lazy_size_of->base.id = LazyValueIdSizeOf;19955 lazy_size_of->base.id = LazyValueIdSizeOf;
1991819956
19919 lazy_size_of->target_type = instruction->type_value->child;19957 lazy_size_of->target_type = instruction->type_value->child;
...@@ -19924,11 +19962,11 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi...@@ -19924,11 +19962,11 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
19924}19962}
1992519963
19926static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) {19964static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) {
19927 ZigType *type_entry = value->value.type;19965 ZigType *type_entry = value->value->type;
1992819966
19929 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {19967 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
19930 if (instr_is_comptime(value)) {19968 if (instr_is_comptime(value)) {
19931 ConstExprValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);19969 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
19932 if (c_ptr_val == nullptr)19970 if (c_ptr_val == nullptr)
19933 return ira->codegen->invalid_instruction;19971 return ira->codegen->invalid_instruction;
19934 if (c_ptr_val->special == ConstValSpecialUndef)19972 if (c_ptr_val->special == ConstValSpecialUndef)
...@@ -19941,11 +19979,11 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -19941,11 +19979,11 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1994119979
19942 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,19980 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
19943 source_inst->scope, source_inst->source_node, value);19981 source_inst->scope, source_inst->source_node, value);
19944 result->value.type = ira->codegen->builtin_types.entry_bool;19982 result->value->type = ira->codegen->builtin_types.entry_bool;
19945 return result;19983 return result;
19946 } else if (type_entry->id == ZigTypeIdOptional) {19984 } else if (type_entry->id == ZigTypeIdOptional) {
19947 if (instr_is_comptime(value)) {19985 if (instr_is_comptime(value)) {
19948 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefOk);19986 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
19949 if (maybe_val == nullptr)19987 if (maybe_val == nullptr)
19950 return ira->codegen->invalid_instruction;19988 return ira->codegen->invalid_instruction;
19951 if (maybe_val->special == ConstValSpecialUndef)19989 if (maybe_val->special == ConstValSpecialUndef)
...@@ -19956,7 +19994,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -19956,7 +19994,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1995619994
19957 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,19995 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
19958 source_inst->scope, source_inst->source_node, value);19996 source_inst->scope, source_inst->source_node, value);
19959 result->value.type = ira->codegen->builtin_types.entry_bool;19997 result->value->type = ira->codegen->builtin_types.entry_bool;
19960 return result;19998 return result;
19961 } else if (type_entry->id == ZigTypeIdNull) {19999 } else if (type_entry->id == ZigTypeIdNull) {
19962 return ir_const_bool(ira, source_inst, false);20000 return ir_const_bool(ira, source_inst, false);
...@@ -19967,23 +20005,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -19967,23 +20005,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1996720005
19968static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {20006static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
19969 IrInstruction *value = instruction->value->child;20007 IrInstruction *value = instruction->value->child;
19970 if (type_is_invalid(value->value.type))20008 if (type_is_invalid(value->value->type))
19971 return ira->codegen->invalid_instruction;20009 return ira->codegen->invalid_instruction;
1997220010
19973 return ir_analyze_test_non_null(ira, &instruction->base, value);20011 return ir_analyze_test_non_null(ira, &instruction->base, value);
19974}20012}
1997520013
19976static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {20014static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
19977 ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr);20015 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
19978 ZigType *elem_type = ptr->value.type->data.pointer.child_type;20016 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
19979 if (elem_type != g->builtin_types.entry_var)20017 if (elem_type != g->builtin_types.entry_var)
19980 return elem_type;20018 return elem_type;
1998120019
19982 if (ir_resolve_lazy(g, ptr->source_node, &ptr->value))20020 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))
19983 return g->builtin_types.entry_invalid;20021 return g->builtin_types.entry_invalid;
1998420022
19985 assert(value_is_comptime(&ptr->value));20023 assert(value_is_comptime(ptr->value));
19986 ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value);20024 ZigValue *pointee = const_ptr_pointee_unchecked(g, ptr->value);
19987 return pointee->type;20025 return pointee->type;
19988}20026}
1998920027
...@@ -19996,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -19996,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
1999620034
19997 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {20035 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
19998 if (instr_is_comptime(base_ptr)) {20036 if (instr_is_comptime(base_ptr)) {
19999 ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad);20037 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
20000 if (!val)20038 if (!val)
20001 return ira->codegen->invalid_instruction;20039 return ira->codegen->invalid_instruction;
20002 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {20040 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20003 ConstExprValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);20041 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
20004 if (c_ptr_val == nullptr)20042 if (c_ptr_val == nullptr)
20005 return ira->codegen->invalid_instruction;20043 return ira->codegen->invalid_instruction;
20006 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||20044 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
...@@ -20028,17 +20066,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20028,17 +20066,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2002820066
20029 ZigType *child_type = type_entry->data.maybe.child_type;20067 ZigType *child_type = type_entry->data.maybe.child_type;
20030 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,20068 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
20031 base_ptr->value.type->data.pointer.is_const, base_ptr->value.type->data.pointer.is_volatile,20069 base_ptr->value->type->data.pointer.is_const, base_ptr->value->type->data.pointer.is_volatile,
20032 PtrLenSingle, 0, 0, 0, false);20070 PtrLenSingle, 0, 0, 0, false);
2003320071
20034 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry);20072 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry);
2003520073
20036 if (instr_is_comptime(base_ptr)) {20074 if (instr_is_comptime(base_ptr)) {
20037 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);20075 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
20038 if (!ptr_val)20076 if (!ptr_val)
20039 return ira->codegen->invalid_instruction;20077 return ira->codegen->invalid_instruction;
20040 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {20078 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20041 ConstExprValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);20079 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20042 if (optional_val == nullptr)20080 if (optional_val == nullptr)
20043 return ira->codegen->invalid_instruction;20081 return ira->codegen->invalid_instruction;
2004420082
...@@ -20048,7 +20086,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20048,7 +20086,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20048 return ira->codegen->invalid_instruction;20086 return ira->codegen->invalid_instruction;
20049 case OnePossibleValueNo:20087 case OnePossibleValueNo:
20050 if (!same_comptime_repr) {20088 if (!same_comptime_repr) {
20051 ConstExprValue *payload_val = create_const_vals(1);20089 ZigValue *payload_val = create_const_vals(1);
20052 payload_val->type = child_type;20090 payload_val->type = child_type;
20053 payload_val->special = ConstValSpecialUndef;20091 payload_val->special = ConstValSpecialUndef;
20054 payload_val->parent.id = ConstParentIdOptionalPayload;20092 payload_val->parent.id = ConstParentIdOptionalPayload;
...@@ -20059,7 +20097,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20059,7 +20097,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20059 }20097 }
20060 break;20098 break;
20061 case OnePossibleValueYes: {20099 case OnePossibleValueYes: {
20062 ConstExprValue *pointee = create_const_vals(1);20100 ZigValue *pointee = create_const_vals(1);
20063 pointee->special = ConstValSpecialStatic;20101 pointee->special = ConstValSpecialStatic;
20064 pointee->type = child_type;20102 pointee->type = child_type;
20065 pointee->parent.id = ConstParentIdOptionalPayload;20103 pointee->parent.id = ConstParentIdOptionalPayload;
...@@ -20079,12 +20117,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20079,12 +20117,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20079 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {20117 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20080 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,20118 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
20081 source_instr->source_node, base_ptr, false, initializing);20119 source_instr->source_node, base_ptr, false, initializing);
20082 result->value.type = result_type;20120 result->value->type = result_type;
20083 result->value.special = ConstValSpecialStatic;20121 result->value->special = ConstValSpecialStatic;
20084 } else {20122 } else {
20085 result = ir_const(ira, source_instr, result_type);20123 result = ir_const(ira, source_instr, result_type);
20086 }20124 }
20087 ConstExprValue *result_val = &result->value;20125 ZigValue *result_val = result->value;
20088 result_val->data.x_ptr.special = ConstPtrSpecialRef;20126 result_val->data.x_ptr.special = ConstPtrSpecialRef;
20089 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;20127 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
20090 switch (type_has_one_possible_value(ira->codegen, child_type)) {20128 switch (type_has_one_possible_value(ira->codegen, child_type)) {
...@@ -20109,7 +20147,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20109,7 +20147,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2010920147
20110 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,20148 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
20111 source_instr->source_node, base_ptr, safety_check_on, initializing);20149 source_instr->source_node, base_ptr, safety_check_on, initializing);
20112 result->value.type = result_type;20150 result->value->type = result_type;
20113 return result;20151 return result;
20114}20152}
2011520153
...@@ -20117,7 +20155,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,...@@ -20117,7 +20155,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
20117 IrInstructionOptionalUnwrapPtr *instruction)20155 IrInstructionOptionalUnwrapPtr *instruction)
20118{20156{
20119 IrInstruction *base_ptr = instruction->base_ptr->child;20157 IrInstruction *base_ptr = instruction->base_ptr->child;
20120 if (type_is_invalid(base_ptr->value.type))20158 if (type_is_invalid(base_ptr->value->type))
20121 return ira->codegen->invalid_instruction;20159 return ira->codegen->invalid_instruction;
2012220160
20123 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,20161 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,
...@@ -20130,26 +20168,26 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt...@@ -20130,26 +20168,26 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt
20130 return ira->codegen->invalid_instruction;20168 return ira->codegen->invalid_instruction;
2013120169
20132 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20170 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
20133 if (type_is_invalid(op->value.type))20171 if (type_is_invalid(op->value->type))
20134 return ira->codegen->invalid_instruction;20172 return ira->codegen->invalid_instruction;
2013520173
20136 if (int_type->data.integral.bit_count == 0)20174 if (int_type->data.integral.bit_count == 0)
20137 return ir_const_unsigned(ira, &instruction->base, 0);20175 return ir_const_unsigned(ira, &instruction->base, 0);
2013820176
20139 if (instr_is_comptime(op)) {20177 if (instr_is_comptime(op)) {
20140 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20178 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20141 if (val == nullptr)20179 if (val == nullptr)
20142 return ira->codegen->invalid_instruction;20180 return ira->codegen->invalid_instruction;
20143 if (val->special == ConstValSpecialUndef)20181 if (val->special == ConstValSpecialUndef)
20144 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);20182 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
20145 size_t result_usize = bigint_ctz(&op->value.data.x_bigint, int_type->data.integral.bit_count);20183 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
20146 return ir_const_unsigned(ira, &instruction->base, result_usize);20184 return ir_const_unsigned(ira, &instruction->base, result_usize);
20147 }20185 }
2014820186
20149 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);20187 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
20150 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,20188 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,
20151 instruction->base.source_node, nullptr, op);20189 instruction->base.source_node, nullptr, op);
20152 result->value.type = return_type;20190 result->value->type = return_type;
20153 return result;20191 return result;
20154}20192}
2015520193
...@@ -20159,26 +20197,26 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl...@@ -20159,26 +20197,26 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl
20159 return ira->codegen->invalid_instruction;20197 return ira->codegen->invalid_instruction;
2016020198
20161 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20199 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
20162 if (type_is_invalid(op->value.type))20200 if (type_is_invalid(op->value->type))
20163 return ira->codegen->invalid_instruction;20201 return ira->codegen->invalid_instruction;
2016420202
20165 if (int_type->data.integral.bit_count == 0)20203 if (int_type->data.integral.bit_count == 0)
20166 return ir_const_unsigned(ira, &instruction->base, 0);20204 return ir_const_unsigned(ira, &instruction->base, 0);
2016720205
20168 if (instr_is_comptime(op)) {20206 if (instr_is_comptime(op)) {
20169 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20207 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20170 if (val == nullptr)20208 if (val == nullptr)
20171 return ira->codegen->invalid_instruction;20209 return ira->codegen->invalid_instruction;
20172 if (val->special == ConstValSpecialUndef)20210 if (val->special == ConstValSpecialUndef)
20173 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);20211 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
20174 size_t result_usize = bigint_clz(&op->value.data.x_bigint, int_type->data.integral.bit_count);20212 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
20175 return ir_const_unsigned(ira, &instruction->base, result_usize);20213 return ir_const_unsigned(ira, &instruction->base, result_usize);
20176 }20214 }
2017720215
20178 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);20216 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
20179 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,20217 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,
20180 instruction->base.source_node, nullptr, op);20218 instruction->base.source_node, nullptr, op);
20181 result->value.type = return_type;20219 result->value->type = return_type;
20182 return result;20220 return result;
20183}20221}
2018420222
...@@ -20188,14 +20226,14 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc...@@ -20188,14 +20226,14 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
20188 return ira->codegen->invalid_instruction;20226 return ira->codegen->invalid_instruction;
2018920227
20190 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20228 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
20191 if (type_is_invalid(op->value.type))20229 if (type_is_invalid(op->value->type))
20192 return ira->codegen->invalid_instruction;20230 return ira->codegen->invalid_instruction;
2019320231
20194 if (int_type->data.integral.bit_count == 0)20232 if (int_type->data.integral.bit_count == 0)
20195 return ir_const_unsigned(ira, &instruction->base, 0);20233 return ir_const_unsigned(ira, &instruction->base, 0);
2019620234
20197 if (instr_is_comptime(op)) {20235 if (instr_is_comptime(op)) {
20198 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20236 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20199 if (val == nullptr)20237 if (val == nullptr)
20200 return ira->codegen->invalid_instruction;20238 return ira->codegen->invalid_instruction;
20201 if (val->special == ConstValSpecialUndef)20239 if (val->special == ConstValSpecialUndef)
...@@ -20212,50 +20250,50 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc...@@ -20212,50 +20250,50 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
20212 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);20250 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
20213 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,20251 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,
20214 instruction->base.source_node, nullptr, op);20252 instruction->base.source_node, nullptr, op);
20215 result->value.type = return_type;20253 result->value->type = return_type;
20216 return result;20254 return result;
20217}20255}
2021820256
20219static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {20257static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
20220 if (type_is_invalid(value->value.type))20258 if (type_is_invalid(value->value->type))
20221 return ira->codegen->invalid_instruction;20259 return ira->codegen->invalid_instruction;
2022220260
20223 if (value->value.type->id == ZigTypeIdEnum) {20261 if (value->value->type->id == ZigTypeIdEnum) {
20224 return value;20262 return value;
20225 }20263 }
2022620264
20227 if (value->value.type->id != ZigTypeIdUnion) {20265 if (value->value->type->id != ZigTypeIdUnion) {
20228 ir_add_error(ira, value,20266 ir_add_error(ira, value,
20229 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));20267 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
20230 return ira->codegen->invalid_instruction;20268 return ira->codegen->invalid_instruction;
20231 }20269 }
20232 if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {20270 if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {
20233 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));20271 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
20234 if (value->value.type->data.unionation.decl_node != nullptr) {20272 if (value->value->type->data.unionation.decl_node != nullptr) {
20235 add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node,20273 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
20236 buf_sprintf("declared here"));20274 buf_sprintf("declared here"));
20237 }20275 }
20238 return ira->codegen->invalid_instruction;20276 return ira->codegen->invalid_instruction;
20239 }20277 }
2024020278
20241 ZigType *tag_type = value->value.type->data.unionation.tag_type;20279 ZigType *tag_type = value->value->type->data.unionation.tag_type;
20242 assert(tag_type->id == ZigTypeIdEnum);20280 assert(tag_type->id == ZigTypeIdEnum);
2024320281
20244 if (instr_is_comptime(value)) {20282 if (instr_is_comptime(value)) {
20245 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);20283 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
20246 if (!val)20284 if (!val)
20247 return ira->codegen->invalid_instruction;20285 return ira->codegen->invalid_instruction;
2024820286
20249 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,20287 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
20250 source_instr->scope, source_instr->source_node);20288 source_instr->scope, source_instr->source_node);
20251 const_instruction->base.value.type = tag_type;20289 const_instruction->base.value->type = tag_type;
20252 const_instruction->base.value.special = ConstValSpecialStatic;20290 const_instruction->base.value->special = ConstValSpecialStatic;
20253 bigint_init_bigint(&const_instruction->base.value.data.x_enum_tag, &val->data.x_union.tag);20291 bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag);
20254 return &const_instruction->base;20292 return &const_instruction->base;
20255 }20293 }
2025620294
20257 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);20295 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
20258 result->value.type = tag_type;20296 result->value->type = tag_type;
20259 return result;20297 return result;
20260}20298}
2026120299
...@@ -20263,11 +20301,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20263,11 +20301,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20263 IrInstructionSwitchBr *switch_br_instruction)20301 IrInstructionSwitchBr *switch_br_instruction)
20264{20302{
20265 IrInstruction *target_value = switch_br_instruction->target_value->child;20303 IrInstruction *target_value = switch_br_instruction->target_value->child;
20266 if (type_is_invalid(target_value->value.type))20304 if (type_is_invalid(target_value->value->type))
20267 return ir_unreach_error(ira);20305 return ir_unreach_error(ira);
2026820306
20269 if (switch_br_instruction->switch_prongs_void != nullptr) {20307 if (switch_br_instruction->switch_prongs_void != nullptr) {
20270 if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value.type)) {20308 if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value->type)) {
20271 return ir_unreach_error(ira);20309 return ir_unreach_error(ira);
20272 }20310 }
20273 }20311 }
...@@ -20280,7 +20318,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20280,7 +20318,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20280 return ira->codegen->invalid_instruction;20318 return ira->codegen->invalid_instruction;
2028120319
20282 if (is_comptime || instr_is_comptime(target_value)) {20320 if (is_comptime || instr_is_comptime(target_value)) {
20283 ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad);20321 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
20284 if (!target_val)20322 if (!target_val)
20285 return ir_unreach_error(ira);20323 return ir_unreach_error(ira);
2028620324
...@@ -20288,20 +20326,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20288,20 +20326,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20288 for (size_t i = 0; i < case_count; i += 1) {20326 for (size_t i = 0; i < case_count; i += 1) {
20289 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];20327 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
20290 IrInstruction *case_value = old_case->value->child;20328 IrInstruction *case_value = old_case->value->child;
20291 if (type_is_invalid(case_value->value.type))20329 if (type_is_invalid(case_value->value->type))
20292 return ir_unreach_error(ira);20330 return ir_unreach_error(ira);
2029320331
20294 if (case_value->value.type->id == ZigTypeIdEnum) {20332 if (case_value->value->type->id == ZigTypeIdEnum) {
20295 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);20333 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);
20296 if (type_is_invalid(case_value->value.type))20334 if (type_is_invalid(case_value->value->type))
20297 return ir_unreach_error(ira);20335 return ir_unreach_error(ira);
20298 }20336 }
2029920337
20300 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);20338 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
20301 if (type_is_invalid(casted_case_value->value.type))20339 if (type_is_invalid(casted_case_value->value->type))
20302 return ir_unreach_error(ira);20340 return ir_unreach_error(ira);
2030320341
20304 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);20342 ZigValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
20305 if (!case_val)20343 if (!case_val)
20306 return ir_unreach_error(ira);20344 return ir_unreach_error(ira);
2030720345
...@@ -20318,7 +20356,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20318,7 +20356,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20318 IrInstruction *result = ir_build_br(&ira->new_irb,20356 IrInstruction *result = ir_build_br(&ira->new_irb,
20319 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,20357 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
20320 new_dest_block, nullptr);20358 new_dest_block, nullptr);
20321 result->value.type = ira->codegen->builtin_types.entry_unreachable;20359 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20322 return ir_finish_anal(ira, result);20360 return ir_finish_anal(ira, result);
20323 }20361 }
20324 }20362 }
...@@ -20338,17 +20376,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20338,17 +20376,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2033820376
20339 IrInstruction *old_value = old_case->value;20377 IrInstruction *old_value = old_case->value;
20340 IrInstruction *new_value = old_value->child;20378 IrInstruction *new_value = old_value->child;
20341 if (type_is_invalid(new_value->value.type))20379 if (type_is_invalid(new_value->value->type))
20342 continue;20380 continue;
2034320381
20344 if (new_value->value.type->id == ZigTypeIdEnum) {20382 if (new_value->value->type->id == ZigTypeIdEnum) {
20345 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);20383 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);
20346 if (type_is_invalid(new_value->value.type))20384 if (type_is_invalid(new_value->value->type))
20347 continue;20385 continue;
20348 }20386 }
2034920387
20350 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);20388 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
20351 if (type_is_invalid(casted_new_value->value.type))20389 if (type_is_invalid(casted_new_value->value->type))
20352 continue;20390 continue;
2035320391
20354 if (!ir_resolve_const(ira, casted_new_value, UndefBad))20392 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
...@@ -20368,7 +20406,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20368,7 +20406,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20368 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,20406 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,
20369 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,20407 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
20370 target_value, new_else_block, case_count, cases, nullptr, nullptr);20408 target_value, new_else_block, case_count, cases, nullptr, nullptr);
20371 switch_br->base.value.type = ira->codegen->builtin_types.entry_unreachable;20409 switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable;
20372 return ir_finish_anal(ira, &switch_br->base);20410 return ir_finish_anal(ira, &switch_br->base);
20373}20411}
2037420412
...@@ -20377,20 +20415,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20377,20 +20415,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20377{20415{
20378 Error err;20416 Error err;
20379 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child;20417 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child;
20380 if (type_is_invalid(target_value_ptr->value.type))20418 if (type_is_invalid(target_value_ptr->value->type))
20381 return ira->codegen->invalid_instruction;20419 return ira->codegen->invalid_instruction;
2038220420
20383 if (target_value_ptr->value.type->id == ZigTypeIdMetaType) {20421 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
20384 assert(instr_is_comptime(target_value_ptr));20422 assert(instr_is_comptime(target_value_ptr));
20385 ZigType *ptr_type = target_value_ptr->value.data.x_type;20423 ZigType *ptr_type = target_value_ptr->value->data.x_type;
20386 assert(ptr_type->id == ZigTypeIdPointer);20424 assert(ptr_type->id == ZigTypeIdPointer);
20387 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);20425 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);
20388 }20426 }
2038920427
20390 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;20428 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
20391 ConstExprValue *pointee_val = nullptr;20429 ZigValue *pointee_val = nullptr;
20392 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {20430 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20393 pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node);20431 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
20394 if (pointee_val == nullptr)20432 if (pointee_val == nullptr)
20395 return ira->codegen->invalid_instruction;20433 return ira->codegen->invalid_instruction;
2039620434
...@@ -20416,13 +20454,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20416,13 +20454,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20416 case ZigTypeIdErrorSet: {20454 case ZigTypeIdErrorSet: {
20417 if (pointee_val) {20455 if (pointee_val) {
20418 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);20456 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
20419 copy_const_val(&result->value, pointee_val, true);20457 copy_const_val(result->value, pointee_val, true);
20420 result->value.type = target_type;20458 result->value->type = target_type;
20421 return result;20459 return result;
20422 }20460 }
2042320461
20424 IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);20462 IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
20425 result->value.type = target_type;20463 result->value->type = target_type;
20426 return result;20464 return result;
20427 }20465 }
20428 case ZigTypeIdUnion: {20466 case ZigTypeIdUnion: {
...@@ -20441,22 +20479,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20441,22 +20479,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20441 assert(tag_type->id == ZigTypeIdEnum);20479 assert(tag_type->id == ZigTypeIdEnum);
20442 if (pointee_val) {20480 if (pointee_val) {
20443 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);20481 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
20444 bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_union.tag);20482 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
20445 return result;20483 return result;
20446 }20484 }
20447 if (tag_type->data.enumeration.src_field_count == 1) {20485 if (tag_type->data.enumeration.src_field_count == 1) {
20448 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);20486 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
20449 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];20487 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
20450 bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value);20488 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
20451 return result;20489 return result;
20452 }20490 }
2045320491
20454 IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);20492 IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
20455 union_value->value.type = target_type;20493 union_value->value->type = target_type;
2045620494
20457 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,20495 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,
20458 switch_target_instruction->base.source_node, union_value);20496 switch_target_instruction->base.source_node, union_value);
20459 union_tag_inst->value.type = tag_type;20497 union_tag_inst->value->type = tag_type;
20460 return union_tag_inst;20498 return union_tag_inst;
20461 }20499 }
20462 case ZigTypeIdEnum: {20500 case ZigTypeIdEnum: {
...@@ -20465,18 +20503,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20465,18 +20503,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20465 if (target_type->data.enumeration.src_field_count < 2) {20503 if (target_type->data.enumeration.src_field_count < 2) {
20466 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];20504 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
20467 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);20505 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
20468 bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value);20506 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
20469 return result;20507 return result;
20470 }20508 }
2047120509
20472 if (pointee_val) {20510 if (pointee_val) {
20473 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);20511 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
20474 bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_enum_tag);20512 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
20475 return result;20513 return result;
20476 }20514 }
2047720515
20478 IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);20516 IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
20479 enum_value->value.type = target_type;20517 enum_value->value->type = target_type;
20480 return enum_value;20518 return enum_value;
20481 }20519 }
20482 case ZigTypeIdErrorUnion:20520 case ZigTypeIdErrorUnion:
...@@ -20501,12 +20539,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20501,12 +20539,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2050120539
20502static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {20540static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
20503 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;20541 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
20504 if (type_is_invalid(target_value_ptr->value.type))20542 if (type_is_invalid(target_value_ptr->value->type))
20505 return ira->codegen->invalid_instruction;20543 return ira->codegen->invalid_instruction;
2050620544
20507 ZigType *ref_type = target_value_ptr->value.type;20545 ZigType *ref_type = target_value_ptr->value->type;
20508 assert(ref_type->id == ZigTypeIdPointer);20546 assert(ref_type->id == ZigTypeIdPointer);
20509 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;20547 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
20510 if (target_type->id == ZigTypeIdUnion) {20548 if (target_type->id == ZigTypeIdUnion) {
20511 ZigType *enum_type = target_type->data.unionation.tag_type;20549 ZigType *enum_type = target_type->data.unionation.tag_type;
20512 assert(enum_type != nullptr);20550 assert(enum_type != nullptr);
...@@ -20514,14 +20552,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20514,14 +20552,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20514 assert(instruction->prongs_len > 0);20552 assert(instruction->prongs_len > 0);
2051520553
20516 IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child;20554 IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child;
20517 if (type_is_invalid(first_prong_value->value.type))20555 if (type_is_invalid(first_prong_value->value->type))
20518 return ira->codegen->invalid_instruction;20556 return ira->codegen->invalid_instruction;
2051920557
20520 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);20558 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
20521 if (type_is_invalid(first_casted_prong_value->value.type))20559 if (type_is_invalid(first_casted_prong_value->value->type))
20522 return ira->codegen->invalid_instruction;20560 return ira->codegen->invalid_instruction;
2052320561
20524 ConstExprValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);20562 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
20525 if (first_prong_val == nullptr)20563 if (first_prong_val == nullptr)
20526 return ira->codegen->invalid_instruction;20564 return ira->codegen->invalid_instruction;
2052720565
...@@ -20530,14 +20568,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20530,14 +20568,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20530 ErrorMsg *invalid_payload_msg = nullptr;20568 ErrorMsg *invalid_payload_msg = nullptr;
20531 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {20569 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {
20532 IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child;20570 IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
20533 if (type_is_invalid(this_prong_inst->value.type))20571 if (type_is_invalid(this_prong_inst->value->type))
20534 return ira->codegen->invalid_instruction;20572 return ira->codegen->invalid_instruction;
2053520573
20536 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);20574 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
20537 if (type_is_invalid(this_casted_prong_value->value.type))20575 if (type_is_invalid(this_casted_prong_value->value->type))
20538 return ira->codegen->invalid_instruction;20576 return ira->codegen->invalid_instruction;
2053920577
20540 ConstExprValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);20578 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
20541 if (this_prong == nullptr)20579 if (this_prong == nullptr)
20542 return ira->codegen->invalid_instruction;20580 return ira->codegen->invalid_instruction;
2054320581
...@@ -20560,18 +20598,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20560,18 +20598,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20560 }20598 }
2056120599
20562 if (instr_is_comptime(target_value_ptr)) {20600 if (instr_is_comptime(target_value_ptr)) {
20563 ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);20601 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
20564 if (!target_value_ptr)20602 if (!target_value_ptr)
20565 return ira->codegen->invalid_instruction;20603 return ira->codegen->invalid_instruction;
2056620604
20567 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);20605 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
20568 if (pointee_val == nullptr)20606 if (pointee_val == nullptr)
20569 return ira->codegen->invalid_instruction;20607 return ira->codegen->invalid_instruction;
2057020608
20571 IrInstruction *result = ir_const(ira, &instruction->base,20609 IrInstruction *result = ir_const(ira, &instruction->base,
20572 get_pointer_to_type(ira->codegen, first_field->type_entry,20610 get_pointer_to_type(ira->codegen, first_field->type_entry,
20573 target_val_ptr->type->data.pointer.is_const));20611 target_val_ptr->type->data.pointer.is_const));
20574 ConstExprValue *out_val = &result->value;20612 ZigValue *out_val = result->value;
20575 out_val->data.x_ptr.special = ConstPtrSpecialRef;20613 out_val->data.x_ptr.special = ConstPtrSpecialRef;
20576 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;20614 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
20577 out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload;20615 out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload;
...@@ -20580,8 +20618,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20580,8 +20618,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2058020618
20581 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,20619 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,
20582 instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false);20620 instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false);
20583 result->value.type = get_pointer_to_type(ira->codegen, first_field->type_entry,20621 result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry,
20584 target_value_ptr->value.type->data.pointer.is_const);20622 target_value_ptr->value->type->data.pointer.is_const);
20585 return result;20623 return result;
20586 } else if (target_type->id == ZigTypeIdErrorSet) {20624 } else if (target_type->id == ZigTypeIdErrorSet) {
20587 // construct an error set from the prong values20625 // construct an error set from the prong values
...@@ -20624,12 +20662,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -20624,12 +20662,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
20624 IrInstructionSwitchElseVar *instruction)20662 IrInstructionSwitchElseVar *instruction)
20625{20663{
20626 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;20664 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
20627 if (type_is_invalid(target_value_ptr->value.type))20665 if (type_is_invalid(target_value_ptr->value->type))
20628 return ira->codegen->invalid_instruction;20666 return ira->codegen->invalid_instruction;
2062920667
20630 ZigType *ref_type = target_value_ptr->value.type;20668 ZigType *ref_type = target_value_ptr->value->type;
20631 assert(ref_type->id == ZigTypeIdPointer);20669 assert(ref_type->id == ZigTypeIdPointer);
20632 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;20670 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
20633 if (target_type->id == ZigTypeIdErrorSet) {20671 if (target_type->id == ZigTypeIdErrorSet) {
20634 // make a new set that has the other cases removed20672 // make a new set that has the other cases removed
20635 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {20673 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {
...@@ -20645,12 +20683,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -20645,12 +20683,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
20645 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {20683 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {
20646 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];20684 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
20647 IrInstruction *case_expr = br_case->value->child;20685 IrInstruction *case_expr = br_case->value->child;
20648 if (case_expr->value.type->id == ZigTypeIdErrorSet) {20686 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
20649 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);20687 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
20650 if (err == nullptr)20688 if (err == nullptr)
20651 return ira->codegen->invalid_instruction;20689 return ira->codegen->invalid_instruction;
20652 errors[err->value] = err;20690 errors[err->value] = err;
20653 } else if (case_expr->value.type->id == ZigTypeIdMetaType) {20691 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
20654 ZigType *err_set_type = ir_resolve_type(ira, case_expr);20692 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
20655 if (type_is_invalid(err_set_type))20693 if (type_is_invalid(err_set_type))
20656 return ira->codegen->invalid_instruction;20694 return ira->codegen->invalid_instruction;
...@@ -20742,7 +20780,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio...@@ -20742,7 +20780,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
2074220780
20743static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {20781static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
20744 IrInstruction *value = ref_instruction->value->child;20782 IrInstruction *value = ref_instruction->value->child;
20745 if (type_is_invalid(value->value.type))20783 if (type_is_invalid(value->value->type))
20746 return ira->codegen->invalid_instruction;20784 return ira->codegen->invalid_instruction;
20747 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);20785 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
20748}20786}
...@@ -20768,13 +20806,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc...@@ -20768,13 +20806,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
20768 if (type_is_invalid(type_field->type_entry))20806 if (type_is_invalid(type_field->type_entry))
20769 return ira->codegen->invalid_instruction;20807 return ira->codegen->invalid_instruction;
2077020808
20771 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {20809 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
20772 if (instr_is_comptime(field_result_loc) &&20810 if (instr_is_comptime(field_result_loc) &&
20773 field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)20811 field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
20774 {20812 {
20775 // nothing20813 // nothing
20776 } else {20814 } else {
20777 result_loc->value.special = ConstValSpecialRuntime;20815 result_loc->value->special = ConstValSpecialRuntime;
20778 }20816 }
20779 }20817 }
2078020818
...@@ -20803,7 +20841,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -20803,7 +20841,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
20803 }20841 }
20804 IrInstructionContainerInitFieldsField *field = &fields[0];20842 IrInstructionContainerInitFieldsField *field = &fields[0];
20805 IrInstruction *field_result_loc = field->result_loc->child;20843 IrInstruction *field_result_loc = field->result_loc->child;
20806 if (type_is_invalid(field_result_loc->value.type))20844 if (type_is_invalid(field_result_loc->value->type))
20807 return ira->codegen->invalid_instruction;20845 return ira->codegen->invalid_instruction;
2080820846
20809 return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name,20847 return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name,
...@@ -20850,7 +20888,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -20850,7 +20888,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
20850 IrInstructionContainerInitFieldsField *field = &fields[i];20888 IrInstructionContainerInitFieldsField *field = &fields[i];
2085120889
20852 IrInstruction *field_result_loc = field->result_loc->child;20890 IrInstruction *field_result_loc = field->result_loc->child;
20853 if (type_is_invalid(field_result_loc->value.type))20891 if (type_is_invalid(field_result_loc->value->type))
20854 return ira->codegen->invalid_instruction;20892 return ira->codegen->invalid_instruction;
2085520893
20856 TypeStructField *type_field = find_struct_type_field(container_type, field->name);20894 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
...@@ -20874,7 +20912,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -20874,7 +20912,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
20874 field_assign_nodes[field_index] = field->source_node;20912 field_assign_nodes[field_index] = field->source_node;
2087520913
20876 if (instr_is_comptime(field_result_loc) &&20914 if (instr_is_comptime(field_result_loc) &&
20877 field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)20915 field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
20878 {20916 {
20879 const_ptrs.append(field_result_loc);20917 const_ptrs.append(field_result_loc);
20880 } else {20918 } else {
...@@ -20912,12 +20950,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -20912,12 +20950,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
20912 return ira->codegen->invalid_instruction;20950 return ira->codegen->invalid_instruction;
2091320951
20914 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);20952 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);
20915 copy_const_val(&runtime_inst->value, field->init_val, true);20953 copy_const_val(runtime_inst->value, field->init_val, true);
2091620954
20917 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,20955 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
20918 container_type, true);20956 container_type, true);
20919 ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false);20957 ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false);
20920 if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {20958 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20921 const_ptrs.append(field_ptr);20959 const_ptrs.append(field_ptr);
20922 } else {20960 } else {
20923 first_non_const_instruction = result_loc;20961 first_non_const_instruction = result_loc;
...@@ -20926,13 +20964,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -20926,13 +20964,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
20926 if (any_missing)20964 if (any_missing)
20927 return ira->codegen->invalid_instruction;20965 return ira->codegen->invalid_instruction;
2092820966
20929 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {20967 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
20930 if (const_ptrs.length != actual_field_count) {20968 if (const_ptrs.length != actual_field_count) {
20931 result_loc->value.special = ConstValSpecialRuntime;20969 result_loc->value->special = ConstValSpecialRuntime;
20932 for (size_t i = 0; i < const_ptrs.length; i += 1) {20970 for (size_t i = 0; i < const_ptrs.length; i += 1) {
20933 IrInstruction *field_result_loc = const_ptrs.at(i);20971 IrInstruction *field_result_loc = const_ptrs.at(i);
20934 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);20972 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);
20935 field_result_loc->value.special = ConstValSpecialRuntime;20973 field_result_loc->value->special = ConstValSpecialRuntime;
20936 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);20974 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);
20937 }20975 }
20938 }20976 }
...@@ -20954,11 +20992,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -20954,11 +20992,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
20954{20992{
20955 ir_assert(instruction->result_loc != nullptr, &instruction->base);20993 ir_assert(instruction->result_loc != nullptr, &instruction->base);
20956 IrInstruction *result_loc = instruction->result_loc->child;20994 IrInstruction *result_loc = instruction->result_loc->child;
20957 if (type_is_invalid(result_loc->value.type))20995 if (type_is_invalid(result_loc->value->type))
20958 return result_loc;20996 return result_loc;
20959 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);20997 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
2096020998
20961 ZigType *container_type = result_loc->value.type->data.pointer.child_type;20999 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2096221000
20963 size_t elem_count = instruction->item_count;21001 size_t elem_count = instruction->item_count;
2096421002
...@@ -20980,7 +21018,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -20980,7 +21018,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
20980 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {21018 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
20981 ir_assert(instruction->result_loc != nullptr, &instruction->base);21019 ir_assert(instruction->result_loc != nullptr, &instruction->base);
20982 IrInstruction *result_loc = instruction->result_loc->child;21020 IrInstruction *result_loc = instruction->result_loc->child;
20983 if (type_is_invalid(result_loc->value.type))21021 if (type_is_invalid(result_loc->value->type))
20984 return result_loc;21022 return result_loc;
20985 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);21023 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);
20986 }21024 }
...@@ -21041,13 +21079,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21041,13 +21079,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2104121079
21042 for (size_t i = 0; i < elem_count; i += 1) {21080 for (size_t i = 0; i < elem_count; i += 1) {
21043 IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child;21081 IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child;
21044 if (type_is_invalid(elem_result_loc->value.type))21082 if (type_is_invalid(elem_result_loc->value->type))
21045 return ira->codegen->invalid_instruction;21083 return ira->codegen->invalid_instruction;
2104621084
21047 assert(elem_result_loc->value.type->id == ZigTypeIdPointer);21085 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);
2104821086
21049 if (instr_is_comptime(elem_result_loc) &&21087 if (instr_is_comptime(elem_result_loc) &&
21050 elem_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)21088 elem_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
21051 {21089 {
21052 const_ptrs.append(elem_result_loc);21090 const_ptrs.append(elem_result_loc);
21053 } else {21091 } else {
...@@ -21055,14 +21093,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21055,14 +21093,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
21055 }21093 }
21056 }21094 }
2105721095
21058 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {21096 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
21059 if (const_ptrs.length != elem_count) {21097 if (const_ptrs.length != elem_count) {
21060 result_loc->value.special = ConstValSpecialRuntime;21098 result_loc->value->special = ConstValSpecialRuntime;
21061 for (size_t i = 0; i < const_ptrs.length; i += 1) {21099 for (size_t i = 0; i < const_ptrs.length; i += 1) {
21062 IrInstruction *elem_result_loc = const_ptrs.at(i);21100 IrInstruction *elem_result_loc = const_ptrs.at(i);
21063 assert(elem_result_loc->value.special == ConstValSpecialStatic);21101 assert(elem_result_loc->value->special == ConstValSpecialStatic);
21064 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);21102 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);
21065 elem_result_loc->value.special = ConstValSpecialRuntime;21103 elem_result_loc->value->special = ConstValSpecialRuntime;
21066 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);21104 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
21067 }21105 }
21068 }21106 }
...@@ -21078,7 +21116,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21078,7 +21116,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
21078 return ira->codegen->invalid_instruction;21116 return ira->codegen->invalid_instruction;
21079 }21117 }
2108021118
21081 ZigType *result_elem_type = result_loc->value.type->data.pointer.child_type;21119 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
21082 if (is_slice(result_elem_type)) {21120 if (is_slice(result_elem_type)) {
21083 ErrorMsg *msg = ir_add_error(ira, &instruction->base,21121 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
21084 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",21122 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
...@@ -21095,11 +21133,11 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir...@@ -21095,11 +21133,11 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir
21095{21133{
21096 ir_assert(instruction->result_loc != nullptr, &instruction->base);21134 ir_assert(instruction->result_loc != nullptr, &instruction->base);
21097 IrInstruction *result_loc = instruction->result_loc->child;21135 IrInstruction *result_loc = instruction->result_loc->child;
21098 if (type_is_invalid(result_loc->value.type))21136 if (type_is_invalid(result_loc->value->type))
21099 return result_loc;21137 return result_loc;
2110021138
21101 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);21139 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
21102 ZigType *container_type = result_loc->value.type->data.pointer.child_type;21140 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2110321141
21104 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,21142 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
21105 instruction->field_count, instruction->fields, result_loc);21143 instruction->field_count, instruction->fields, result_loc);
...@@ -21123,15 +21161,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr...@@ -21123,15 +21161,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
21123 fprintf(stderr, "| ");21161 fprintf(stderr, "| ");
21124 for (size_t i = 0; i < instruction->msg_count; i += 1) {21162 for (size_t i = 0; i < instruction->msg_count; i += 1) {
21125 IrInstruction *msg = instruction->msg_list[i]->child;21163 IrInstruction *msg = instruction->msg_list[i]->child;
21126 if (type_is_invalid(msg->value.type))21164 if (type_is_invalid(msg->value->type))
21127 return ira->codegen->invalid_instruction;21165 return ira->codegen->invalid_instruction;
21128 buf_resize(&buf, 0);21166 buf_resize(&buf, 0);
21129 if (msg->value.special == ConstValSpecialLazy) {21167 if (msg->value->special == ConstValSpecialLazy) {
21130 // Resolve any lazy value that's passed, we need its value21168 // Resolve any lazy value that's passed, we need its value
21131 if (ir_resolve_lazy(ira->codegen, msg->source_node, &msg->value))21169 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))
21132 return ira->codegen->invalid_instruction;21170 return ira->codegen->invalid_instruction;
21133 }21171 }
21134 render_const_value(ira->codegen, &buf, &msg->value);21172 render_const_value(ira->codegen, &buf, msg->value);
21135 const char *comma_str = (i != 0) ? ", " : "";21173 const char *comma_str = (i != 0) ? ", " : "";
21136 fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf));21174 fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf));
21137 }21175 }
...@@ -21150,28 +21188,28 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr...@@ -21150,28 +21188,28 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
2115021188
21151static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {21189static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
21152 IrInstruction *value = instruction->value->child;21190 IrInstruction *value = instruction->value->child;
21153 if (type_is_invalid(value->value.type))21191 if (type_is_invalid(value->value->type))
21154 return ira->codegen->invalid_instruction;21192 return ira->codegen->invalid_instruction;
2115521193
21156 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);21194 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
21157 if (type_is_invalid(casted_value->value.type))21195 if (type_is_invalid(casted_value->value->type))
21158 return ira->codegen->invalid_instruction;21196 return ira->codegen->invalid_instruction;
2115921197
21160 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,21198 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
21161 true, false, PtrLenUnknown, 0, 0, 0, false);21199 true, false, PtrLenUnknown, 0, 0, 0, false);
21162 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);21200 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
21163 if (instr_is_comptime(casted_value)) {21201 if (instr_is_comptime(casted_value)) {
21164 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);21202 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
21165 if (val == nullptr)21203 if (val == nullptr)
21166 return ira->codegen->invalid_instruction;21204 return ira->codegen->invalid_instruction;
21167 ErrorTableEntry *err = casted_value->value.data.x_err_set;21205 ErrorTableEntry *err = casted_value->value->data.x_err_set;
21168 if (!err->cached_error_name_val) {21206 if (!err->cached_error_name_val) {
21169 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;21207 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
21170 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);21208 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
21171 }21209 }
21172 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);21210 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21173 copy_const_val(&result->value, err->cached_error_name_val, true);21211 copy_const_val(result->value, err->cached_error_name_val, true);
21174 result->value.type = str_type;21212 result->value->type = str_type;
21175 return result;21213 return result;
21176 }21214 }
2117721215
...@@ -21179,25 +21217,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -21179,25 +21217,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2117921217
21180 IrInstruction *result = ir_build_err_name(&ira->new_irb,21218 IrInstruction *result = ir_build_err_name(&ira->new_irb,
21181 instruction->base.scope, instruction->base.source_node, value);21219 instruction->base.scope, instruction->base.source_node, value);
21182 result->value.type = str_type;21220 result->value->type = str_type;
21183 return result;21221 return result;
21184}21222}
2118521223
21186static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {21224static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
21187 Error err;21225 Error err;
21188 IrInstruction *target = instruction->target->child;21226 IrInstruction *target = instruction->target->child;
21189 if (type_is_invalid(target->value.type))21227 if (type_is_invalid(target->value->type))
21190 return ira->codegen->invalid_instruction;21228 return ira->codegen->invalid_instruction;
2119121229
21192 assert(target->value.type->id == ZigTypeIdEnum);21230 assert(target->value->type->id == ZigTypeIdEnum);
2119321231
21194 if (instr_is_comptime(target)) {21232 if (instr_is_comptime(target)) {
21195 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))21233 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
21196 return ira->codegen->invalid_instruction;21234 return ira->codegen->invalid_instruction;
21197 TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint);21235 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
21198 ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;21236 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
21199 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);21237 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21200 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);21238 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);
21201 return result;21239 return result;
21202 }21240 }
2120321241
...@@ -21207,7 +21245,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns...@@ -21207,7 +21245,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
21207 ira->codegen, ira->codegen->builtin_types.entry_u8,21245 ira->codegen, ira->codegen->builtin_types.entry_u8,
21208 true, false, PtrLenUnknown,21246 true, false, PtrLenUnknown,
21209 0, 0, 0, false);21247 0, 0, 0, false);
21210 result->value.type = get_slice_type(ira->codegen, u8_ptr_type);21248 result->value->type = get_slice_type(ira->codegen, u8_ptr_type);
21211 return result;21249 return result;
21212}21250}
2121321251
...@@ -21226,7 +21264,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21226,7 +21264,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21226 return ira->codegen->invalid_instruction;21264 return ira->codegen->invalid_instruction;
2122721265
21228 IrInstruction *field_ptr = instruction->field_ptr->child;21266 IrInstruction *field_ptr = instruction->field_ptr->child;
21229 if (type_is_invalid(field_ptr->value.type))21267 if (type_is_invalid(field_ptr->value->type))
21230 return ira->codegen->invalid_instruction;21268 return ira->codegen->invalid_instruction;
2123121269
21232 if (container_type->id != ZigTypeIdStruct) {21270 if (container_type->id != ZigTypeIdStruct) {
...@@ -21246,9 +21284,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21246,9 +21284,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21246 return ira->codegen->invalid_instruction;21284 return ira->codegen->invalid_instruction;
21247 }21285 }
2124821286
21249 if (field_ptr->value.type->id != ZigTypeIdPointer) {21287 if (field_ptr->value->type->id != ZigTypeIdPointer) {
21250 ir_add_error(ira, field_ptr,21288 ir_add_error(ira, field_ptr,
21251 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));21289 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
21252 return ira->codegen->invalid_instruction;21290 return ira->codegen->invalid_instruction;
21253 }21291 }
2125421292
...@@ -21257,22 +21295,22 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21257,22 +21295,22 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21257 uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);21295 uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);
2125821296
21259 ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,21297 ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
21260 field_ptr->value.type->data.pointer.is_const,21298 field_ptr->value->type->data.pointer.is_const,
21261 field_ptr->value.type->data.pointer.is_volatile,21299 field_ptr->value->type->data.pointer.is_volatile,
21262 PtrLenSingle,21300 PtrLenSingle,
21263 field_ptr_align, 0, 0, false);21301 field_ptr_align, 0, 0, false);
21264 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);21302 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
21265 if (type_is_invalid(casted_field_ptr->value.type))21303 if (type_is_invalid(casted_field_ptr->value->type))
21266 return ira->codegen->invalid_instruction;21304 return ira->codegen->invalid_instruction;
2126721305
21268 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,21306 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
21269 casted_field_ptr->value.type->data.pointer.is_const,21307 casted_field_ptr->value->type->data.pointer.is_const,
21270 casted_field_ptr->value.type->data.pointer.is_volatile,21308 casted_field_ptr->value->type->data.pointer.is_volatile,
21271 PtrLenSingle,21309 PtrLenSingle,
21272 parent_ptr_align, 0, 0, false);21310 parent_ptr_align, 0, 0, false);
2127321311
21274 if (instr_is_comptime(casted_field_ptr)) {21312 if (instr_is_comptime(casted_field_ptr)) {
21275 ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);21313 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
21276 if (!field_ptr_val)21314 if (!field_ptr_val)
21277 return ira->codegen->invalid_instruction;21315 return ira->codegen->invalid_instruction;
2127821316
...@@ -21291,7 +21329,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21291,7 +21329,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21291 }21329 }
2129221330
21293 IrInstruction *result = ir_const(ira, &instruction->base, result_type);21331 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
21294 ConstExprValue *out_val = &result->value;21332 ZigValue *out_val = result->value;
21295 out_val->data.x_ptr.special = ConstPtrSpecialRef;21333 out_val->data.x_ptr.special = ConstPtrSpecialRef;
21296 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;21334 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
21297 out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut;21335 out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut;
...@@ -21300,7 +21338,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21300,7 +21338,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2130021338
21301 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,21339 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,
21302 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);21340 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);
21303 result->value.type = result_type;21341 result->value->type = result_type;
21304 return result;21342 return result;
21305}21343}
2130621344
...@@ -21350,7 +21388,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,...@@ -21350,7 +21388,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,
21350 IrInstructionByteOffsetOf *instruction)21388 IrInstructionByteOffsetOf *instruction)
21351{21389{
21352 IrInstruction *type_value = instruction->type_value->child;21390 IrInstruction *type_value = instruction->type_value->child;
21353 if (type_is_invalid(type_value->value.type))21391 if (type_is_invalid(type_value->value->type))
21354 return ira->codegen->invalid_instruction;21392 return ira->codegen->invalid_instruction;
2135521393
21356 IrInstruction *field_name_value = instruction->field_name->child;21394 IrInstruction *field_name_value = instruction->field_name->child;
...@@ -21366,7 +21404,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,...@@ -21366,7 +21404,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
21366 IrInstructionBitOffsetOf *instruction)21404 IrInstructionBitOffsetOf *instruction)
21367{21405{
21368 IrInstruction *type_value = instruction->type_value->child;21406 IrInstruction *type_value = instruction->type_value->child;
21369 if (type_is_invalid(type_value->value.type))21407 if (type_is_invalid(type_value->value->type))
21370 return ira->codegen->invalid_instruction;21408 return ira->codegen->invalid_instruction;
21371 IrInstruction *field_name_value = instruction->field_name->child;21409 IrInstruction *field_name_value = instruction->field_name->child;
21372 size_t byte_offset = 0;21410 size_t byte_offset = 0;
...@@ -21390,7 +21428,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind...@@ -21390,7 +21428,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind
2139021428
21391static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {21429static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {
21392 Error err;21430 Error err;
21393 ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");21431 ZigValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
21394 assert(type_info_var->type->id == ZigTypeIdMetaType);21432 assert(type_info_var->type->id == ZigTypeIdMetaType);
21395 ZigType *type_info_type = type_info_var->data.x_type;21433 ZigType *type_info_type = type_info_var->data.x_type;
21396 assert(type_info_type->id == ZigTypeIdUnion);21434 assert(type_info_type->id == ZigTypeIdUnion);
...@@ -21423,7 +21461,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -21423,7 +21461,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
21423 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);21461 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
21424}21462}
2142521463
21426static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val,21464static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val,
21427 ScopeDecls *decls_scope)21465 ScopeDecls *decls_scope)
21428{21466{
21429 Error err;21467 Error err;
...@@ -21473,7 +21511,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21473,7 +21511,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21473 }21511 }
21474 }21512 }
2147521513
21476 ConstExprValue *declaration_array = create_const_vals(1);21514 ZigValue *declaration_array = create_const_vals(1);
21477 declaration_array->special = ConstValSpecialStatic;21515 declaration_array->special = ConstValSpecialStatic;
21478 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);21516 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
21479 declaration_array->data.x_array.special = ConstArraySpecialNone;21517 declaration_array->data.x_array.special = ConstArraySpecialNone;
...@@ -21494,13 +21532,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21494,13 +21532,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21494 continue;21532 continue;
21495 }21533 }
2149621534
21497 ConstExprValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];21535 ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];
2149821536
21499 declaration_val->special = ConstValSpecialStatic;21537 declaration_val->special = ConstValSpecialStatic;
21500 declaration_val->type = type_info_declaration_type;21538 declaration_val->type = type_info_declaration_type;
2150121539
21502 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);21540 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
21503 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;21541 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
21504 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);21542 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
21505 inner_fields[1]->special = ConstValSpecialStatic;21543 inner_fields[1]->special = ConstValSpecialStatic;
21506 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;21544 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
...@@ -21528,7 +21566,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21528,7 +21566,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21528 // 1: Data.Var: type21566 // 1: Data.Var: type
21529 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);21567 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2153021568
21531 ConstExprValue *payload = create_const_vals(1);21569 ZigValue *payload = create_const_vals(1);
21532 payload->special = ConstValSpecialStatic;21570 payload->special = ConstValSpecialStatic;
21533 payload->type = ira->codegen->builtin_types.entry_type;21571 payload->type = ira->codegen->builtin_types.entry_type;
21534 payload->data.x_type = var->const_value->type;21572 payload->data.x_type = var->const_value->type;
...@@ -21553,13 +21591,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21553,13 +21591,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2155321591
21554 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;21592 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2155521593
21556 ConstExprValue *fn_decl_val = create_const_vals(1);21594 ZigValue *fn_decl_val = create_const_vals(1);
21557 fn_decl_val->special = ConstValSpecialStatic;21595 fn_decl_val->special = ConstValSpecialStatic;
21558 fn_decl_val->type = type_info_fn_decl_type;21596 fn_decl_val->type = type_info_fn_decl_type;
21559 fn_decl_val->parent.id = ConstParentIdUnion;21597 fn_decl_val->parent.id = ConstParentIdUnion;
21560 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];21598 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2156121599
21562 ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9);21600 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9);
21563 fn_decl_val->data.x_struct.fields = fn_decl_fields;21601 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2156421602
21565 // fn_type: type21603 // fn_type: type
...@@ -21603,7 +21641,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21603,7 +21641,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21603 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));21641 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
21604 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {21642 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
21605 fn_decl_fields[6]->data.x_optional = create_const_vals(1);21643 fn_decl_fields[6]->data.x_optional = create_const_vals(1);
21606 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;21644 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
21607 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,21645 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
21608 buf_len(fn_node->lib_name), true);21646 buf_len(fn_node->lib_name), true);
21609 } else {21647 } else {
...@@ -21617,7 +21655,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21617,7 +21655,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21617 // arg_names: [][] const u821655 // arg_names: [][] const u8
21618 ensure_field_index(fn_decl_val->type, "arg_names", 8);21656 ensure_field_index(fn_decl_val->type, "arg_names", 8);
21619 size_t fn_arg_count = fn_entry->variable_list.length;21657 size_t fn_arg_count = fn_entry->variable_list.length;
21620 ConstExprValue *fn_arg_name_array = create_const_vals(1);21658 ZigValue *fn_arg_name_array = create_const_vals(1);
21621 fn_arg_name_array->special = ConstValSpecialStatic;21659 fn_arg_name_array->special = ConstValSpecialStatic;
21622 fn_arg_name_array->type = get_array_type(ira->codegen,21660 fn_arg_name_array->type = get_array_type(ira->codegen,
21623 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);21661 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
...@@ -21628,8 +21666,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21628,8 +21666,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2162821666
21629 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {21667 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
21630 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);21668 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
21631 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];21669 ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
21632 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,21670 ZigValue *arg_name = create_const_str_lit(ira->codegen,
21633 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;21671 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
21634 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);21672 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
21635 fn_arg_name_val->parent.id = ConstParentIdArray;21673 fn_arg_name_val->parent.id = ConstParentIdArray;
...@@ -21649,7 +21687,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21649,7 +21687,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21649 // This is a type.21687 // This is a type.
21650 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);21688 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2165121689
21652 ConstExprValue *payload = create_const_vals(1);21690 ZigValue *payload = create_const_vals(1);
21653 payload->special = ConstValSpecialStatic;21691 payload->special = ConstValSpecialStatic;
21654 payload->type = ira->codegen->builtin_types.entry_type;21692 payload->type = ira->codegen->builtin_types.entry_type;
21655 payload->data.x_type = type_entry;21693 payload->data.x_type = type_entry;
...@@ -21695,7 +21733,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {...@@ -21695,7 +21733,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
21695 zig_unreachable();21733 zig_unreachable();
21696}21734}
2169721735
21698static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {21736static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
21699 Error err;21737 Error err;
21700 ZigType *attrs_type;21738 ZigType *attrs_type;
21701 BuiltinPtrSize size_enum_index;21739 BuiltinPtrSize size_enum_index;
...@@ -21715,11 +21753,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -21715,11 +21753,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
21715 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);21753 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
21716 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));21754 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));
2171721755
21718 ConstExprValue *result = create_const_vals(1);21756 ZigValue *result = create_const_vals(1);
21719 result->special = ConstValSpecialStatic;21757 result->special = ConstValSpecialStatic;
21720 result->type = type_info_pointer_type;21758 result->type = type_info_pointer_type;
2172121759
21722 ConstExprValue **fields = alloc_const_vals_ptrs(7);21760 ZigValue **fields = alloc_const_vals_ptrs(7);
21723 result->data.x_struct.fields = fields;21761 result->data.x_struct.fields = fields;
2172421762
21725 // size: Size21763 // size: Size
...@@ -21769,17 +21807,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -21769,17 +21807,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
21769 return result;21807 return result;
21770};21808};
2177121809
21772static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,21810static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEnumField *enum_field,
21773 ZigType *type_info_enum_field_type)21811 ZigType *type_info_enum_field_type)
21774{21812{
21775 enum_field_val->special = ConstValSpecialStatic;21813 enum_field_val->special = ConstValSpecialStatic;
21776 enum_field_val->type = type_info_enum_field_type;21814 enum_field_val->type = type_info_enum_field_type;
2177721815
21778 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);21816 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
21779 inner_fields[1]->special = ConstValSpecialStatic;21817 inner_fields[1]->special = ConstValSpecialStatic;
21780 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;21818 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2178121819
21782 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee;21820 ZigValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee;
21783 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);21821 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2178421822
21785 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);21823 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);
...@@ -21788,7 +21826,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,...@@ -21788,7 +21826,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
21788}21826}
2178921827
21790static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,21828static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
21791 ConstExprValue **out)21829 ZigValue **out)
21792{21830{
21793 Error err;21831 Error err;
21794 assert(type_entry != nullptr);21832 assert(type_entry != nullptr);
...@@ -21803,7 +21841,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21803,7 +21841,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21803 return ErrorNone;21841 return ErrorNone;
21804 }21842 }
2180521843
21806 ConstExprValue *result = nullptr;21844 ZigValue *result = nullptr;
21807 switch (type_entry->id) {21845 switch (type_entry->id) {
21808 case ZigTypeIdInvalid:21846 case ZigTypeIdInvalid:
21809 zig_unreachable();21847 zig_unreachable();
...@@ -21826,7 +21864,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21826,7 +21864,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21826 result->special = ConstValSpecialStatic;21864 result->special = ConstValSpecialStatic;
21827 result->type = ir_type_info_get_type(ira, "Int", nullptr);21865 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2182821866
21829 ConstExprValue **fields = alloc_const_vals_ptrs(2);21867 ZigValue **fields = alloc_const_vals_ptrs(2);
21830 result->data.x_struct.fields = fields;21868 result->data.x_struct.fields = fields;
2183121869
21832 // is_signed: bool21870 // is_signed: bool
...@@ -21848,7 +21886,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21848,7 +21886,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21848 result->special = ConstValSpecialStatic;21886 result->special = ConstValSpecialStatic;
21849 result->type = ir_type_info_get_type(ira, "Float", nullptr);21887 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2185021888
21851 ConstExprValue **fields = alloc_const_vals_ptrs(1);21889 ZigValue **fields = alloc_const_vals_ptrs(1);
21852 result->data.x_struct.fields = fields;21890 result->data.x_struct.fields = fields;
2185321891
21854 // bits: u821892 // bits: u8
...@@ -21872,7 +21910,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21872,7 +21910,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21872 result->special = ConstValSpecialStatic;21910 result->special = ConstValSpecialStatic;
21873 result->type = ir_type_info_get_type(ira, "Array", nullptr);21911 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2187421912
21875 ConstExprValue **fields = alloc_const_vals_ptrs(3);21913 ZigValue **fields = alloc_const_vals_ptrs(3);
21876 result->data.x_struct.fields = fields;21914 result->data.x_struct.fields = fields;
2187721915
21878 // len: usize21916 // len: usize
...@@ -21896,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21896,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21896 result->special = ConstValSpecialStatic;21934 result->special = ConstValSpecialStatic;
21897 result->type = ir_type_info_get_type(ira, "Vector", nullptr);21935 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2189821936
21899 ConstExprValue **fields = alloc_const_vals_ptrs(2);21937 ZigValue **fields = alloc_const_vals_ptrs(2);
21900 result->data.x_struct.fields = fields;21938 result->data.x_struct.fields = fields;
2190121939
21902 // len: usize21940 // len: usize
...@@ -21918,7 +21956,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21918,7 +21956,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21918 result->special = ConstValSpecialStatic;21956 result->special = ConstValSpecialStatic;
21919 result->type = ir_type_info_get_type(ira, "Optional", nullptr);21957 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2192021958
21921 ConstExprValue **fields = alloc_const_vals_ptrs(1);21959 ZigValue **fields = alloc_const_vals_ptrs(1);
21922 result->data.x_struct.fields = fields;21960 result->data.x_struct.fields = fields;
2192321961
21924 // child: type21962 // child: type
...@@ -21934,7 +21972,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21934,7 +21972,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21934 result->special = ConstValSpecialStatic;21972 result->special = ConstValSpecialStatic;
21935 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);21973 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2193621974
21937 ConstExprValue **fields = alloc_const_vals_ptrs(1);21975 ZigValue **fields = alloc_const_vals_ptrs(1);
21938 result->data.x_struct.fields = fields;21976 result->data.x_struct.fields = fields;
2193921977
21940 // child: ?type21978 // child: ?type
...@@ -21951,7 +21989,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21951,7 +21989,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21951 result->special = ConstValSpecialStatic;21989 result->special = ConstValSpecialStatic;
21952 result->type = ir_type_info_get_type(ira, "Enum", nullptr);21990 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2195321991
21954 ConstExprValue **fields = alloc_const_vals_ptrs(4);21992 ZigValue **fields = alloc_const_vals_ptrs(4);
21955 result->data.x_struct.fields = fields;21993 result->data.x_struct.fields = fields;
2195621994
21957 // layout: ContainerLayout21995 // layout: ContainerLayout
...@@ -21973,7 +22011,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21973,7 +22011,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21973 }22011 }
21974 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;22012 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
2197522013
21976 ConstExprValue *enum_field_array = create_const_vals(1);22014 ZigValue *enum_field_array = create_const_vals(1);
21977 enum_field_array->special = ConstValSpecialStatic;22015 enum_field_array->special = ConstValSpecialStatic;
21978 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);22016 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
21979 enum_field_array->data.x_array.special = ConstArraySpecialNone;22017 enum_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -21984,7 +22022,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21984,7 +22022,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21984 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)22022 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
21985 {22023 {
21986 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index];22024 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index];
21987 ConstExprValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index];22025 ZigValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index];
21988 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);22026 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);
21989 enum_field_val->parent.id = ConstParentIdArray;22027 enum_field_val->parent.id = ConstParentIdArray;
21990 enum_field_val->parent.data.p_array.array_val = enum_field_array;22028 enum_field_val->parent.data.p_array.array_val = enum_field_array;
...@@ -22017,11 +22055,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22017,11 +22055,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22017 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {22055 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
22018 zig_unreachable();22056 zig_unreachable();
22019 }22057 }
22020 ConstExprValue *slice_val = create_const_vals(1);22058 ZigValue *slice_val = create_const_vals(1);
22021 result->data.x_optional = slice_val;22059 result->data.x_optional = slice_val;
2202222060
22023 uint32_t error_count = type_entry->data.error_set.err_count;22061 uint32_t error_count = type_entry->data.error_set.err_count;
22024 ConstExprValue *error_array = create_const_vals(1);22062 ZigValue *error_array = create_const_vals(1);
22025 error_array->special = ConstValSpecialStatic;22063 error_array->special = ConstValSpecialStatic;
22026 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);22064 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
22027 error_array->data.x_array.special = ConstArraySpecialNone;22065 error_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22030,16 +22068,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22030,16 +22068,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22030 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);22068 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
22031 for (uint32_t error_index = 0; error_index < error_count; error_index++) {22069 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
22032 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];22070 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];
22033 ConstExprValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];22071 ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];
2203422072
22035 error_val->special = ConstValSpecialStatic;22073 error_val->special = ConstValSpecialStatic;
22036 error_val->type = type_info_error_type;22074 error_val->type = type_info_error_type;
2203722075
22038 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);22076 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
22039 inner_fields[1]->special = ConstValSpecialStatic;22077 inner_fields[1]->special = ConstValSpecialStatic;
22040 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;22078 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2204122079
22042 ConstExprValue *name = nullptr;22080 ZigValue *name = nullptr;
22043 if (error->cached_error_name_val != nullptr)22081 if (error->cached_error_name_val != nullptr)
22044 name = error->cached_error_name_val;22082 name = error->cached_error_name_val;
22045 if (name == nullptr)22083 if (name == nullptr)
...@@ -22061,7 +22099,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22061,7 +22099,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22061 result->special = ConstValSpecialStatic;22099 result->special = ConstValSpecialStatic;
22062 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);22100 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2206322101
22064 ConstExprValue **fields = alloc_const_vals_ptrs(2);22102 ZigValue **fields = alloc_const_vals_ptrs(2);
22065 result->data.x_struct.fields = fields;22103 result->data.x_struct.fields = fields;
2206622104
22067 // error_set: type22105 // error_set: type
...@@ -22084,7 +22122,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22084,7 +22122,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22084 result->special = ConstValSpecialStatic;22122 result->special = ConstValSpecialStatic;
22085 result->type = ir_type_info_get_type(ira, "Union", nullptr);22123 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2208622124
22087 ConstExprValue **fields = alloc_const_vals_ptrs(4);22125 ZigValue **fields = alloc_const_vals_ptrs(4);
22088 result->data.x_struct.fields = fields;22126 result->data.x_struct.fields = fields;
2208922127
22090 // layout: ContainerLayout22128 // layout: ContainerLayout
...@@ -22101,7 +22139,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22101,7 +22139,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22101 if (union_decl_node->data.container_decl.auto_enum ||22139 if (union_decl_node->data.container_decl.auto_enum ||
22102 union_decl_node->data.container_decl.init_arg_expr != nullptr)22140 union_decl_node->data.container_decl.init_arg_expr != nullptr)
22103 {22141 {
22104 ConstExprValue *tag_type = create_const_vals(1);22142 ZigValue *tag_type = create_const_vals(1);
22105 tag_type->special = ConstValSpecialStatic;22143 tag_type->special = ConstValSpecialStatic;
22106 tag_type->type = ira->codegen->builtin_types.entry_type;22144 tag_type->type = ira->codegen->builtin_types.entry_type;
22107 tag_type->data.x_type = type_entry->data.unionation.tag_type;22145 tag_type->data.x_type = type_entry->data.unionation.tag_type;
...@@ -22117,7 +22155,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22117,7 +22155,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22117 zig_unreachable();22155 zig_unreachable();
22118 uint32_t union_field_count = type_entry->data.unionation.src_field_count;22156 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
2211922157
22120 ConstExprValue *union_field_array = create_const_vals(1);22158 ZigValue *union_field_array = create_const_vals(1);
22121 union_field_array->special = ConstValSpecialStatic;22159 union_field_array->special = ConstValSpecialStatic;
22122 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);22160 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
22123 union_field_array->data.x_array.special = ConstArraySpecialNone;22161 union_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22129,12 +22167,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22129,12 +22167,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2212922167
22130 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {22168 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
22131 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];22169 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];
22132 ConstExprValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index];22170 ZigValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index];
2213322171
22134 union_field_val->special = ConstValSpecialStatic;22172 union_field_val->special = ConstValSpecialStatic;
22135 union_field_val->type = type_info_union_field_type;22173 union_field_val->type = type_info_union_field_type;
2213622174
22137 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22175 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22138 inner_fields[1]->special = ConstValSpecialStatic;22176 inner_fields[1]->special = ConstValSpecialStatic;
22139 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);22177 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2214022178
...@@ -22149,7 +22187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22149,7 +22187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22149 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;22187 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
22150 inner_fields[2]->data.x_type = union_field->type_entry;22188 inner_fields[2]->data.x_type = union_field->type_entry;
2215122189
22152 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;22190 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
22153 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);22191 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2215422192
22155 union_field_val->data.x_struct.fields = inner_fields;22193 union_field_val->data.x_struct.fields = inner_fields;
...@@ -22180,7 +22218,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22180,7 +22218,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22180 result->special = ConstValSpecialStatic;22218 result->special = ConstValSpecialStatic;
22181 result->type = ir_type_info_get_type(ira, "Struct", nullptr);22219 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2218222220
22183 ConstExprValue **fields = alloc_const_vals_ptrs(3);22221 ZigValue **fields = alloc_const_vals_ptrs(3);
22184 result->data.x_struct.fields = fields;22222 result->data.x_struct.fields = fields;
2218522223
22186 // layout: ContainerLayout22224 // layout: ContainerLayout
...@@ -22197,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22197,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22197 }22235 }
22198 uint32_t struct_field_count = type_entry->data.structure.src_field_count;22236 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
2219922237
22200 ConstExprValue *struct_field_array = create_const_vals(1);22238 ZigValue *struct_field_array = create_const_vals(1);
22201 struct_field_array->special = ConstValSpecialStatic;22239 struct_field_array->special = ConstValSpecialStatic;
22202 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);22240 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
22203 struct_field_array->data.x_array.special = ConstArraySpecialNone;22241 struct_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22207,12 +22245,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22207,12 +22245,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2220722245
22208 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {22246 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
22209 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];22247 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];
22210 ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index];22248 ZigValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index];
2221122249
22212 struct_field_val->special = ConstValSpecialStatic;22250 struct_field_val->special = ConstValSpecialStatic;
22213 struct_field_val->type = type_info_struct_field_type;22251 struct_field_val->type = type_info_struct_field_type;
2221422252
22215 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22253 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22216 inner_fields[1]->special = ConstValSpecialStatic;22254 inner_fields[1]->special = ConstValSpecialStatic;
22217 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);22255 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2221822256
...@@ -22235,7 +22273,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22235,7 +22273,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22235 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;22273 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
22236 inner_fields[2]->data.x_type = struct_field->type_entry;22274 inner_fields[2]->data.x_type = struct_field->type_entry;
2223722275
22238 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;22276 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
22239 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);22277 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2224022278
22241 struct_field_val->data.x_struct.fields = inner_fields;22279 struct_field_val->data.x_struct.fields = inner_fields;
...@@ -22259,7 +22297,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22259,7 +22297,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22259 result->special = ConstValSpecialStatic;22297 result->special = ConstValSpecialStatic;
22260 result->type = ir_type_info_get_type(ira, "Fn", nullptr);22298 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2226122299
22262 ConstExprValue **fields = alloc_const_vals_ptrs(5);22300 ZigValue **fields = alloc_const_vals_ptrs(5);
22263 result->data.x_struct.fields = fields;22301 result->data.x_struct.fields = fields;
2226422302
22265 // calling_convention: TypeInfo.CallingConvention22303 // calling_convention: TypeInfo.CallingConvention
...@@ -22286,7 +22324,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22286,7 +22324,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22286 if (type_entry->data.fn.fn_type_id.return_type == nullptr)22324 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
22287 fields[3]->data.x_optional = nullptr;22325 fields[3]->data.x_optional = nullptr;
22288 else {22326 else {
22289 ConstExprValue *return_type = create_const_vals(1);22327 ZigValue *return_type = create_const_vals(1);
22290 return_type->special = ConstValSpecialStatic;22328 return_type->special = ConstValSpecialStatic;
22291 return_type->type = ira->codegen->builtin_types.entry_type;22329 return_type->type = ira->codegen->builtin_types.entry_type;
22292 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;22330 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
...@@ -22300,7 +22338,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22300,7 +22338,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22300 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -22338 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
22301 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);22339 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
2230222340
22303 ConstExprValue *fn_arg_array = create_const_vals(1);22341 ZigValue *fn_arg_array = create_const_vals(1);
22304 fn_arg_array->special = ConstValSpecialStatic;22342 fn_arg_array->special = ConstValSpecialStatic;
22305 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);22343 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
22306 fn_arg_array->data.x_array.special = ConstArraySpecialNone;22344 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22310,7 +22348,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22310,7 +22348,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2231022348
22311 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {22349 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
22312 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];22350 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
22313 ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index];22351 ZigValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index];
2231422352
22315 fn_arg_val->special = ConstValSpecialStatic;22353 fn_arg_val->special = ConstValSpecialStatic;
22316 fn_arg_val->type = type_info_fn_arg_type;22354 fn_arg_val->type = type_info_fn_arg_type;
...@@ -22318,7 +22356,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22318,7 +22356,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22318 bool arg_is_generic = fn_param_info->type == nullptr;22356 bool arg_is_generic = fn_param_info->type == nullptr;
22319 if (arg_is_generic) assert(is_generic);22357 if (arg_is_generic) assert(is_generic);
2232022358
22321 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22359 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22322 inner_fields[0]->special = ConstValSpecialStatic;22360 inner_fields[0]->special = ConstValSpecialStatic;
22323 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;22361 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
22324 inner_fields[0]->data.x_bool = arg_is_generic;22362 inner_fields[0]->data.x_bool = arg_is_generic;
...@@ -22331,7 +22369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22331,7 +22369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22331 if (arg_is_generic)22369 if (arg_is_generic)
22332 inner_fields[2]->data.x_optional = nullptr;22370 inner_fields[2]->data.x_optional = nullptr;
22333 else {22371 else {
22334 ConstExprValue *arg_type = create_const_vals(1);22372 ZigValue *arg_type = create_const_vals(1);
22335 arg_type->special = ConstValSpecialStatic;22373 arg_type->special = ConstValSpecialStatic;
22336 arg_type->type = ira->codegen->builtin_types.entry_type;22374 arg_type->type = ira->codegen->builtin_types.entry_type;
22337 arg_type->data.x_type = fn_param_info->type;22375 arg_type->data.x_type = fn_param_info->type;
...@@ -22376,12 +22414,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22376,12 +22414,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2237622414
22377 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);22415 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2237822416
22379 ConstExprValue *payload;22417 ZigValue *payload;
22380 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))22418 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
22381 return ira->codegen->invalid_instruction;22419 return ira->codegen->invalid_instruction;
2238222420
22383 IrInstruction *result = ir_const(ira, &instruction->base, result_type);22421 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
22384 ConstExprValue *out_val = &result->value;22422 ZigValue *out_val = result->value;
22385 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));22423 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
22386 out_val->data.x_union.payload = payload;22424 out_val->data.x_union.payload = payload;
2238722425
...@@ -22393,49 +22431,49 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22393,49 +22431,49 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
22393 return result;22431 return result;
22394}22432}
2239522433
22396static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22434static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22397{22435{
22398 ensure_field_index(struct_value->type, name, field_index);22436 ensure_field_index(struct_value->type, name, field_index);
22399 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);22437 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
22400 return struct_value->data.x_struct.fields[field_index];22438 return struct_value->data.x_struct.fields[field_index];
22401}22439}
2240222440
22403static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value,22441static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
22404 const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result)22442 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
22405{22443{
22406 ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index);22444 ZigValue *field_val = get_const_field(ira, struct_value, name, field_index);
22407 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);22445 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
22408 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,22446 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
22409 get_optional_type(ira->codegen, elem_type));22447 get_optional_type(ira->codegen, elem_type));
22410 if (type_is_invalid(casted_field_inst->value.type))22448 if (type_is_invalid(casted_field_inst->value->type))
22411 return ErrorSemanticAnalyzeFail;22449 return ErrorSemanticAnalyzeFail;
2241222450
22413 *result = casted_field_inst->value.data.x_optional;22451 *result = casted_field_inst->value->data.x_optional;
22414 return ErrorNone;22452 return ErrorNone;
22415}22453}
2241622454
22417static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22455static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22418{22456{
22419 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22457 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22420 assert(value->type == ira->codegen->builtin_types.entry_bool);22458 assert(value->type == ira->codegen->builtin_types.entry_bool);
22421 return value->data.x_bool;22459 return value->data.x_bool;
22422}22460}
2242322461
22424static BigInt *get_const_field_lit_int(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22462static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22425{22463{
22426 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22464 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22427 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);22465 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
22428 return &value->data.x_bigint;22466 return &value->data.x_bigint;
22429}22467}
2243022468
22431static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22469static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22432{22470{
22433 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22471 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22434 assert(value->type == ira->codegen->builtin_types.entry_type);22472 assert(value->type == ira->codegen->builtin_types.entry_type);
22435 return value->data.x_type;22473 return value->data.x_type;
22436}22474}
2243722475
22438static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) {22476static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) {
22439 Error err;22477 Error err;
22440 switch (tagTypeId) {22478 switch (tagTypeId) {
22441 case ZigTypeIdInvalid:22479 case ZigTypeIdInvalid:
...@@ -22474,12 +22512,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22474,12 +22512,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22474 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);22512 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
22475 assert(payload->special == ConstValSpecialStatic);22513 assert(payload->special == ConstValSpecialStatic);
22476 assert(payload->type == type_info_pointer_type);22514 assert(payload->type == type_info_pointer_type);
22477 ConstExprValue *size_value = get_const_field(ira, payload, "size", 0);22515 ZigValue *size_value = get_const_field(ira, payload, "size", 0);
22478 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));22516 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
22479 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);22517 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
22480 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);22518 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
22481 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);22519 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
22482 ConstExprValue *sentinel;22520 ZigValue *sentinel;
22483 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,22521 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
22484 elem_type, &sentinel)))22522 elem_type, &sentinel)))
22485 {22523 {
...@@ -22504,7 +22542,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22504,7 +22542,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22504 assert(payload->special == ConstValSpecialStatic);22542 assert(payload->special == ConstValSpecialStatic);
22505 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));22543 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
22506 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);22544 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
22507 ConstExprValue *sentinel;22545 ZigValue *sentinel;
22508 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,22546 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
22509 elem_type, &sentinel)))22547 elem_type, &sentinel)))
22510 {22548 {
...@@ -22549,14 +22587,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22549,14 +22587,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2254922587
22550static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {22588static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {
22551 IrInstruction *type_info_ir = instruction->type_info->child;22589 IrInstruction *type_info_ir = instruction->type_info->child;
22552 if (type_is_invalid(type_info_ir->value.type))22590 if (type_is_invalid(type_info_ir->value->type))
22553 return ira->codegen->invalid_instruction;22591 return ira->codegen->invalid_instruction;
2255422592
22555 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));22593 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));
22556 if (type_is_invalid(casted_ir->value.type))22594 if (type_is_invalid(casted_ir->value->type))
22557 return ira->codegen->invalid_instruction;22595 return ira->codegen->invalid_instruction;
2255822596
22559 ConstExprValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);22597 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);
22560 if (!type_info_value)22598 if (!type_info_value)
22561 return ira->codegen->invalid_instruction;22599 return ira->codegen->invalid_instruction;
22562 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));22600 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
...@@ -22574,12 +22612,12 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,...@@ -22574,12 +22612,12 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
22574 if (type_is_invalid(type_entry))22612 if (type_is_invalid(type_entry))
22575 return ira->codegen->invalid_instruction;22613 return ira->codegen->invalid_instruction;
2257622614
22577 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");22615 ZigValue *var_value = get_builtin_value(ira->codegen, "TypeId");
22578 assert(var_value->type->id == ZigTypeIdMetaType);22616 assert(var_value->type->id == ZigTypeIdMetaType);
22579 ZigType *result_type = var_value->data.x_type;22617 ZigType *result_type = var_value->data.x_type;
2258022618
22581 IrInstruction *result = ir_const(ira, &instruction->base, result_type);22619 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
22582 bigint_init_unsigned(&result->value.data.x_enum_tag, type_id_index(type_entry));22620 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
22583 return result;22621 return result;
22584}22622}
2258522623
...@@ -22607,7 +22645,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc...@@ -22607,7 +22645,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
22607 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));22645 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
22608 }22646 }
22609 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);22647 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
22610 copy_const_val(&result->value, type_entry->cached_const_name_val, true);22648 copy_const_val(result->value, type_entry->cached_const_name_val, true);
22611 return result;22649 return result;
22612}22650}
2261322651
...@@ -22628,7 +22666,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -22628,7 +22666,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2262822666
22629 // Execute the C import block like an inline function22667 // Execute the C import block like an inline function
22630 ZigType *void_type = ira->codegen->builtin_types.entry_void;22668 ZigType *void_type = ira->codegen->builtin_types.entry_void;
22631 ConstExprValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,22669 ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
22632 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,22670 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
22633 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);22671 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
22634 if (type_is_invalid(cimport_result->type))22672 if (type_is_invalid(cimport_result->type))
...@@ -22796,7 +22834,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -22796,7 +22834,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2279622834
22797static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {22835static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
22798 IrInstruction *name_value = instruction->name->child;22836 IrInstruction *name_value = instruction->name->child;
22799 if (type_is_invalid(name_value->value.type))22837 if (type_is_invalid(name_value->value->type))
22800 return ira->codegen->invalid_instruction;22838 return ira->codegen->invalid_instruction;
2280122839
22802 Buf *include_name = ir_resolve_str(ira, name_value);22840 Buf *include_name = ir_resolve_str(ira, name_value);
...@@ -22814,7 +22852,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc...@@ -22814,7 +22852,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc
2281422852
22815static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {22853static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
22816 IrInstruction *name = instruction->name->child;22854 IrInstruction *name = instruction->name->child;
22817 if (type_is_invalid(name->value.type))22855 if (type_is_invalid(name->value->type))
22818 return ira->codegen->invalid_instruction;22856 return ira->codegen->invalid_instruction;
2281922857
22820 Buf *define_name = ir_resolve_str(ira, name);22858 Buf *define_name = ir_resolve_str(ira, name);
...@@ -22822,12 +22860,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct...@@ -22822,12 +22860,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct
22822 return ira->codegen->invalid_instruction;22860 return ira->codegen->invalid_instruction;
2282322861
22824 IrInstruction *value = instruction->value->child;22862 IrInstruction *value = instruction->value->child;
22825 if (type_is_invalid(value->value.type))22863 if (type_is_invalid(value->value->type))
22826 return ira->codegen->invalid_instruction;22864 return ira->codegen->invalid_instruction;
2282722865
22828 Buf *define_value = nullptr;22866 Buf *define_value = nullptr;
22829 // The second parameter is either a string or void (equivalent to "")22867 // The second parameter is either a string or void (equivalent to "")
22830 if (value->value.type->id != ZigTypeIdVoid) {22868 if (value->value->type->id != ZigTypeIdVoid) {
22831 define_value = ir_resolve_str(ira, value);22869 define_value = ir_resolve_str(ira, value);
22832 if (!define_value)22870 if (!define_value)
22833 return ira->codegen->invalid_instruction;22871 return ira->codegen->invalid_instruction;
...@@ -22845,7 +22883,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct...@@ -22845,7 +22883,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct
2284522883
22846static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {22884static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
22847 IrInstruction *name = instruction->name->child;22885 IrInstruction *name = instruction->name->child;
22848 if (type_is_invalid(name->value.type))22886 if (type_is_invalid(name->value->type))
22849 return ira->codegen->invalid_instruction;22887 return ira->codegen->invalid_instruction;
2285022888
22851 Buf *undef_name = ir_resolve_str(ira, name);22889 Buf *undef_name = ir_resolve_str(ira, name);
...@@ -22863,7 +22901,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi...@@ -22863,7 +22901,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi
2286322901
22864static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {22902static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
22865 IrInstruction *name = instruction->name->child;22903 IrInstruction *name = instruction->name->child;
22866 if (type_is_invalid(name->value.type))22904 if (type_is_invalid(name->value->type))
22867 return ira->codegen->invalid_instruction;22905 return ira->codegen->invalid_instruction;
2286822906
22869 Buf *rel_file_path = ir_resolve_str(ira, name);22907 Buf *rel_file_path = ir_resolve_str(ira, name);
...@@ -22898,7 +22936,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru...@@ -22898,7 +22936,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
22898 ZigType *result_type = get_array_type(ira->codegen,22936 ZigType *result_type = get_array_type(ira->codegen,
22899 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);22937 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);
22900 IrInstruction *result = ir_const(ira, &instruction->base, result_type);22938 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
22901 init_const_str_lit(ira->codegen, &result->value, file_contents);22939 init_const_str_lit(ira->codegen, result->value, file_contents);
22902 return result;22940 return result;
22903}22941}
2290422942
...@@ -22908,25 +22946,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22908,25 +22946,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22908 return ira->codegen->invalid_instruction;22946 return ira->codegen->invalid_instruction;
2290922947
22910 IrInstruction *ptr = instruction->ptr->child;22948 IrInstruction *ptr = instruction->ptr->child;
22911 if (type_is_invalid(ptr->value.type))22949 if (type_is_invalid(ptr->value->type))
22912 return ira->codegen->invalid_instruction;22950 return ira->codegen->invalid_instruction;
2291322951
22914 // TODO let this be volatile22952 // TODO let this be volatile
22915 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);22953 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
22916 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);22954 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
22917 if (type_is_invalid(casted_ptr->value.type))22955 if (type_is_invalid(casted_ptr->value->type))
22918 return ira->codegen->invalid_instruction;22956 return ira->codegen->invalid_instruction;
2291922957
22920 IrInstruction *cmp_value = instruction->cmp_value->child;22958 IrInstruction *cmp_value = instruction->cmp_value->child;
22921 if (type_is_invalid(cmp_value->value.type))22959 if (type_is_invalid(cmp_value->value->type))
22922 return ira->codegen->invalid_instruction;22960 return ira->codegen->invalid_instruction;
2292322961
22924 IrInstruction *new_value = instruction->new_value->child;22962 IrInstruction *new_value = instruction->new_value->child;
22925 if (type_is_invalid(new_value->value.type))22963 if (type_is_invalid(new_value->value->type))
22926 return ira->codegen->invalid_instruction;22964 return ira->codegen->invalid_instruction;
2292722965
22928 IrInstruction *success_order_value = instruction->success_order_value->child;22966 IrInstruction *success_order_value = instruction->success_order_value->child;
22929 if (type_is_invalid(success_order_value->value.type))22967 if (type_is_invalid(success_order_value->value->type))
22930 return ira->codegen->invalid_instruction;22968 return ira->codegen->invalid_instruction;
2293122969
22932 AtomicOrder success_order;22970 AtomicOrder success_order;
...@@ -22934,7 +22972,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22934,7 +22972,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22934 return ira->codegen->invalid_instruction;22972 return ira->codegen->invalid_instruction;
2293522973
22936 IrInstruction *failure_order_value = instruction->failure_order_value->child;22974 IrInstruction *failure_order_value = instruction->failure_order_value->child;
22937 if (type_is_invalid(failure_order_value->value.type))22975 if (type_is_invalid(failure_order_value->value->type))
22938 return ira->codegen->invalid_instruction;22976 return ira->codegen->invalid_instruction;
2293922977
22940 AtomicOrder failure_order;22978 AtomicOrder failure_order;
...@@ -22942,11 +22980,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22942,11 +22980,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22942 return ira->codegen->invalid_instruction;22980 return ira->codegen->invalid_instruction;
2294322981
22944 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);22982 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);
22945 if (type_is_invalid(casted_cmp_value->value.type))22983 if (type_is_invalid(casted_cmp_value->value->type))
22946 return ira->codegen->invalid_instruction;22984 return ira->codegen->invalid_instruction;
2294722985
22948 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);22986 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);
22949 if (type_is_invalid(casted_new_value->value.type))22987 if (type_is_invalid(casted_new_value->value->type))
22950 return ira->codegen->invalid_instruction;22988 return ira->codegen->invalid_instruction;
2295122989
22952 if (success_order < AtomicOrderMonotonic) {22990 if (success_order < AtomicOrderMonotonic) {
...@@ -22970,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22970,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22970 return ira->codegen->invalid_instruction;23008 return ira->codegen->invalid_instruction;
22971 }23009 }
2297223010
22973 if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar &&23011 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
22974 instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {23012 instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
22975 zig_panic("TODO compile-time execution of cmpxchg");23013 zig_panic("TODO compile-time execution of cmpxchg");
22976 }23014 }
...@@ -22980,7 +23018,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22980,7 +23018,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22980 if (handle_is_ptr(result_type)) {23018 if (handle_is_ptr(result_type)) {
22981 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,23019 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
22982 result_type, nullptr, true, false, true);23020 result_type, nullptr, true, false, true);
22983 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {23021 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
22984 return result_loc;23022 return result_loc;
22985 }23023 }
22986 } else {23024 } else {
...@@ -22994,7 +23032,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22994,7 +23032,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2299423032
22995static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {23033static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
22996 IrInstruction *order_value = instruction->order_value->child;23034 IrInstruction *order_value = instruction->order_value->child;
22997 if (type_is_invalid(order_value->value.type))23035 if (type_is_invalid(order_value->value->type))
22998 return ira->codegen->invalid_instruction;23036 return ira->codegen->invalid_instruction;
2299923037
23000 AtomicOrder order;23038 AtomicOrder order;
...@@ -23009,7 +23047,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction...@@ -23009,7 +23047,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction
2300923047
23010 IrInstruction *result = ir_build_fence(&ira->new_irb,23048 IrInstruction *result = ir_build_fence(&ira->new_irb,
23011 instruction->base.scope, instruction->base.source_node, order_value, order);23049 instruction->base.scope, instruction->base.source_node, order_value, order);
23012 result->value.type = ira->codegen->builtin_types.entry_void;23050 result->value->type = ira->codegen->builtin_types.entry_void;
23013 return result;23051 return result;
23014}23052}
2301523053
...@@ -23027,7 +23065,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -23027,7 +23065,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
23027 }23065 }
2302823066
23029 IrInstruction *target = instruction->target->child;23067 IrInstruction *target = instruction->target->child;
23030 ZigType *src_type = target->value.type;23068 ZigType *src_type = target->value->type;
23031 if (type_is_invalid(src_type))23069 if (type_is_invalid(src_type))
23032 return ira->codegen->invalid_instruction;23070 return ira->codegen->invalid_instruction;
2303323071
...@@ -23043,19 +23081,19 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -23043,19 +23081,19 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
23043 }23081 }
2304423082
23045 if (instr_is_comptime(target)) {23083 if (instr_is_comptime(target)) {
23046 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);23084 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
23047 if (val == nullptr)23085 if (val == nullptr)
23048 return ira->codegen->invalid_instruction;23086 return ira->codegen->invalid_instruction;
2304923087
23050 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);23088 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
23051 bigint_truncate(&result->value.data.x_bigint, &val->data.x_bigint,23089 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
23052 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);23090 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
23053 return result;23091 return result;
23054 }23092 }
2305523093
23056 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {23094 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
23057 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);23095 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
23058 bigint_init_unsigned(&result->value.data.x_bigint, 0);23096 bigint_init_unsigned(&result->value->data.x_bigint, 0);
23059 return result;23097 return result;
23060 }23098 }
2306123099
...@@ -23071,7 +23109,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -23071,7 +23109,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2307123109
23072 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,23110 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,
23073 instruction->base.source_node, dest_type_value, target);23111 instruction->base.source_node, dest_type_value, target);
23074 new_instruction->value.type = dest_type;23112 new_instruction->value->type = dest_type;
23075 return new_instruction;23113 return new_instruction;
23076}23114}
2307723115
...@@ -23086,12 +23124,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct...@@ -23086,12 +23124,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
23086 }23124 }
2308723125
23088 IrInstruction *target = instruction->target->child;23126 IrInstruction *target = instruction->target->child;
23089 if (type_is_invalid(target->value.type))23127 if (type_is_invalid(target->value->type))
23090 return ira->codegen->invalid_instruction;23128 return ira->codegen->invalid_instruction;
2309123129
23092 if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) {23130 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
23093 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",23131 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
23094 buf_ptr(&target->value.type->name)));23132 buf_ptr(&target->value->type->name)));
23095 return ira->codegen->invalid_instruction;23133 return ira->codegen->invalid_instruction;
23096 }23134 }
2309723135
...@@ -23120,15 +23158,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -23120,15 +23158,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
23120 }23158 }
2312123159
23122 IrInstruction *target = instruction->target->child;23160 IrInstruction *target = instruction->target->child;
23123 if (type_is_invalid(target->value.type))23161 if (type_is_invalid(target->value->type))
23124 return ira->codegen->invalid_instruction;23162 return ira->codegen->invalid_instruction;
2312523163
23126 if (target->value.type->id == ZigTypeIdComptimeInt ||23164 if (target->value->type->id == ZigTypeIdComptimeInt ||
23127 target->value.type->id == ZigTypeIdComptimeFloat)23165 target->value->type->id == ZigTypeIdComptimeFloat)
23128 {23166 {
23129 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {23167 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
23130 CastOp op;23168 CastOp op;
23131 if (target->value.type->id == ZigTypeIdComptimeInt) {23169 if (target->value->type->id == ZigTypeIdComptimeInt) {
23132 op = CastOpIntToFloat;23170 op = CastOpIntToFloat;
23133 } else {23171 } else {
23134 op = CastOpNumLitToConcrete;23172 op = CastOpNumLitToConcrete;
...@@ -23139,9 +23177,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -23139,9 +23177,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
23139 }23177 }
23140 }23178 }
2314123179
23142 if (target->value.type->id != ZigTypeIdFloat) {23180 if (target->value->type->id != ZigTypeIdFloat) {
23143 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",23181 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
23144 buf_ptr(&target->value.type->name)));23182 buf_ptr(&target->value->type->name)));
23145 return ira->codegen->invalid_instruction;23183 return ira->codegen->invalid_instruction;
23146 }23184 }
2314723185
...@@ -23160,12 +23198,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst...@@ -23160,12 +23198,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst
23160 }23198 }
2316123199
23162 IrInstruction *target = instruction->target->child;23200 IrInstruction *target = instruction->target->child;
23163 if (type_is_invalid(target->value.type))23201 if (type_is_invalid(target->value->type))
23164 return ira->codegen->invalid_instruction;23202 return ira->codegen->invalid_instruction;
2316523203
23166 if (target->value.type->id != ZigTypeIdErrorSet) {23204 if (target->value->type->id != ZigTypeIdErrorSet) {
23167 ir_add_error(ira, instruction->target,23205 ir_add_error(ira, instruction->target,
23168 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));23206 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
23169 return ira->codegen->invalid_instruction;23207 return ira->codegen->invalid_instruction;
23170 }23208 }
2317123209
...@@ -23180,20 +23218,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23180,20 +23218,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23180 return ira->codegen->invalid_instruction;23218 return ira->codegen->invalid_instruction;
2318123219
23182 IrInstruction *target = instruction->target->child;23220 IrInstruction *target = instruction->target->child;
23183 if (type_is_invalid(target->value.type))23221 if (type_is_invalid(target->value->type))
23184 return ira->codegen->invalid_instruction;23222 return ira->codegen->invalid_instruction;
2318523223
23186 bool src_ptr_const;23224 bool src_ptr_const;
23187 bool src_ptr_volatile;23225 bool src_ptr_volatile;
23188 uint32_t src_ptr_align;23226 uint32_t src_ptr_align;
23189 if (target->value.type->id == ZigTypeIdPointer) {23227 if (target->value->type->id == ZigTypeIdPointer) {
23190 src_ptr_const = target->value.type->data.pointer.is_const;23228 src_ptr_const = target->value->type->data.pointer.is_const;
23191 src_ptr_volatile = target->value.type->data.pointer.is_volatile;23229 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
2319223230
23193 if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align)))23231 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
23194 return ira->codegen->invalid_instruction;23232 return ira->codegen->invalid_instruction;
23195 } else if (is_slice(target->value.type)) {23233 } else if (is_slice(target->value->type)) {
23196 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;23234 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
23197 src_ptr_const = src_ptr_type->data.pointer.is_const;23235 src_ptr_const = src_ptr_type->data.pointer.is_const;
23198 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;23236 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2319923237
...@@ -23203,10 +23241,10 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23203,10 +23241,10 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23203 src_ptr_const = true;23241 src_ptr_const = true;
23204 src_ptr_volatile = false;23242 src_ptr_volatile = false;
2320523243
23206 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown)))23244 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
23207 return ira->codegen->invalid_instruction;23245 return ira->codegen->invalid_instruction;
2320823246
23209 src_ptr_align = get_abi_alignment(ira->codegen, target->value.type);23247 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
23210 }23248 }
2321123249
23212 if (src_ptr_align != 0) {23250 if (src_ptr_align != 0) {
...@@ -23225,18 +23263,18 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23225,18 +23263,18 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23225 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);23263 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2322623264
23227 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);23265 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
23228 if (type_is_invalid(casted_value->value.type))23266 if (type_is_invalid(casted_value->value->type))
23229 return ira->codegen->invalid_instruction;23267 return ira->codegen->invalid_instruction;
2323023268
23231 bool have_known_len = false;23269 bool have_known_len = false;
23232 uint64_t known_len;23270 uint64_t known_len;
2323323271
23234 if (instr_is_comptime(casted_value)) {23272 if (instr_is_comptime(casted_value)) {
23235 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);23273 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
23236 if (!val)23274 if (!val)
23237 return ira->codegen->invalid_instruction;23275 return ira->codegen->invalid_instruction;
2323823276
23239 ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index];23277 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
23240 if (value_is_comptime(len_val)) {23278 if (value_is_comptime(len_val)) {
23241 known_len = bigint_as_u64(&len_val->data.x_bigint);23279 known_len = bigint_as_u64(&len_val->data.x_bigint);
23242 have_known_len = true;23280 have_known_len = true;
...@@ -23245,12 +23283,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23245,12 +23283,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2324523283
23246 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,23284 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
23247 dest_slice_type, nullptr, true, false, true);23285 dest_slice_type, nullptr, true, false, true);
23248 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) {23286 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) {
23249 return result_loc;23287 return result_loc;
23250 }23288 }
2325123289
23252 if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) {23290 if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
23253 known_len = casted_value->value.data.rh_slice.len;23291 known_len = casted_value->value->data.rh_slice.len;
23254 have_known_len = true;23292 have_known_len = true;
23255 }23293 }
2325623294
...@@ -23277,16 +23315,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -23277,16 +23315,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
23277 Error err;23315 Error err;
2327823316
23279 IrInstruction *target = instruction->target->child;23317 IrInstruction *target = instruction->target->child;
23280 if (type_is_invalid(target->value.type))23318 if (type_is_invalid(target->value->type))
23281 return ira->codegen->invalid_instruction;23319 return ira->codegen->invalid_instruction;
2328223320
23283 if (!is_slice(target->value.type)) {23321 if (!is_slice(target->value->type)) {
23284 ir_add_error(ira, instruction->target,23322 ir_add_error(ira, instruction->target,
23285 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name)));23323 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
23286 return ira->codegen->invalid_instruction;23324 return ira->codegen->invalid_instruction;
23287 }23325 }
2328823326
23289 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;23327 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2329023328
23291 uint32_t alignment;23329 uint32_t alignment;
23292 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))23330 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
...@@ -23298,22 +23336,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -23298,22 +23336,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
23298 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);23336 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
2329923337
23300 if (instr_is_comptime(target)) {23338 if (instr_is_comptime(target)) {
23301 ConstExprValue *target_val = ir_resolve_const(ira, target, UndefBad);23339 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
23302 if (target_val == nullptr)23340 if (target_val == nullptr)
23303 return ira->codegen->invalid_instruction;23341 return ira->codegen->invalid_instruction;
2330423342
23305 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);23343 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
23306 result->value.data.x_struct.fields = alloc_const_vals_ptrs(2);23344 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
2330723345
23308 ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index];23346 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
23309 ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];23347 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
23310 copy_const_val(ptr_val, target_ptr_val, false);23348 copy_const_val(ptr_val, target_ptr_val, false);
23311 ptr_val->type = dest_ptr_type;23349 ptr_val->type = dest_ptr_type;
2331223350
23313 ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index];23351 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
23314 len_val->special = ConstValSpecialStatic;23352 len_val->special = ConstValSpecialStatic;
23315 len_val->type = ira->codegen->builtin_types.entry_usize;23353 len_val->type = ira->codegen->builtin_types.entry_usize;
23316 ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];23354 ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
23317 ZigType *elem_type = src_ptr_type->data.pointer.child_type;23355 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
23318 BigInt elem_size_bigint;23356 BigInt elem_size_bigint;
23319 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));23357 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
...@@ -23324,7 +23362,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -23324,7 +23362,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2332423362
23325 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,23363 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
23326 dest_slice_type, nullptr, true, false, true);23364 dest_slice_type, nullptr, true, false, true);
23327 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {23365 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
23328 return result_loc;23366 return result_loc;
23329 }23367 }
2333023368
...@@ -23351,12 +23389,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst...@@ -23351,12 +23389,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
23351 return ira->codegen->invalid_instruction;23389 return ira->codegen->invalid_instruction;
2335223390
23353 IrInstruction *target = instruction->target->child;23391 IrInstruction *target = instruction->target->child;
23354 if (type_is_invalid(target->value.type))23392 if (type_is_invalid(target->value->type))
23355 return ira->codegen->invalid_instruction;23393 return ira->codegen->invalid_instruction;
2335623394
23357 if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) {23395 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
23358 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",23396 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
23359 buf_ptr(&target->value.type->name)));23397 buf_ptr(&target->value->type->name)));
23360 return ira->codegen->invalid_instruction;23398 return ira->codegen->invalid_instruction;
23361 }23399 }
2336223400
...@@ -23369,16 +23407,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst...@@ -23369,16 +23407,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
23369 return ira->codegen->invalid_instruction;23407 return ira->codegen->invalid_instruction;
2337023408
23371 IrInstruction *target = instruction->target->child;23409 IrInstruction *target = instruction->target->child;
23372 if (type_is_invalid(target->value.type))23410 if (type_is_invalid(target->value->type))
23373 return ira->codegen->invalid_instruction;23411 return ira->codegen->invalid_instruction;
2337423412
23375 if (target->value.type->id == ZigTypeIdComptimeInt) {23413 if (target->value->type->id == ZigTypeIdComptimeInt) {
23376 return ir_implicit_cast(ira, target, dest_type);23414 return ir_implicit_cast(ira, target, dest_type);
23377 }23415 }
2337823416
23379 if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {23417 if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) {
23380 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",23418 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
23381 buf_ptr(&target->value.type->name)));23419 buf_ptr(&target->value->type->name)));
23382 return ira->codegen->invalid_instruction;23420 return ira->codegen->invalid_instruction;
23383 }23421 }
2338423422
...@@ -23387,15 +23425,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst...@@ -23387,15 +23425,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
2338723425
23388static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {23426static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
23389 IrInstruction *target = instruction->target->child;23427 IrInstruction *target = instruction->target->child;
23390 if (type_is_invalid(target->value.type))23428 if (type_is_invalid(target->value->type))
23391 return ira->codegen->invalid_instruction;23429 return ira->codegen->invalid_instruction;
2339223430
23393 IrInstruction *casted_target;23431 IrInstruction *casted_target;
23394 if (target->value.type->id == ZigTypeIdErrorSet) {23432 if (target->value->type->id == ZigTypeIdErrorSet) {
23395 casted_target = target;23433 casted_target = target;
23396 } else {23434 } else {
23397 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);23435 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
23398 if (type_is_invalid(casted_target->value.type))23436 if (type_is_invalid(casted_target->value->type))
23399 return ira->codegen->invalid_instruction;23437 return ira->codegen->invalid_instruction;
23400 }23438 }
2340123439
...@@ -23404,11 +23442,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru...@@ -23404,11 +23442,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru
2340423442
23405static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {23443static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
23406 IrInstruction *target = instruction->target->child;23444 IrInstruction *target = instruction->target->child;
23407 if (type_is_invalid(target->value.type))23445 if (type_is_invalid(target->value->type))
23408 return ira->codegen->invalid_instruction;23446 return ira->codegen->invalid_instruction;
2340923447
23410 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);23448 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
23411 if (type_is_invalid(casted_target->value.type))23449 if (type_is_invalid(casted_target->value->type))
23412 return ira->codegen->invalid_instruction;23450 return ira->codegen->invalid_instruction;
2341323451
23414 return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set);23452 return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
...@@ -23416,12 +23454,12 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru...@@ -23416,12 +23454,12 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru
2341623454
23417static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {23455static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
23418 IrInstruction *target = instruction->target->child;23456 IrInstruction *target = instruction->target->child;
23419 if (type_is_invalid(target->value.type))23457 if (type_is_invalid(target->value->type))
23420 return ira->codegen->invalid_instruction;23458 return ira->codegen->invalid_instruction;
2342123459
23422 if (target->value.type->id != ZigTypeIdBool) {23460 if (target->value->type->id != ZigTypeIdBool) {
23423 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",23461 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
23424 buf_ptr(&target->value.type->name)));23462 buf_ptr(&target->value->type->name)));
23425 return ira->codegen->invalid_instruction;23463 return ira->codegen->invalid_instruction;
23426 }23464 }
2342723465
...@@ -23472,48 +23510,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23472,48 +23510,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23472 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);23510 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);
2347323511
23474 uint32_t len_mask;23512 uint32_t len_mask;
23475 if (mask->value.type->id == ZigTypeIdVector) {23513 if (mask->value->type->id == ZigTypeIdVector) {
23476 len_mask = mask->value.type->data.vector.len;23514 len_mask = mask->value->type->data.vector.len;
23477 } else if (mask->value.type->id == ZigTypeIdArray) {23515 } else if (mask->value->type->id == ZigTypeIdArray) {
23478 len_mask = mask->value.type->data.array.len;23516 len_mask = mask->value->type->data.array.len;
23479 } else {23517 } else {
23480 ir_add_error(ira, mask,23518 ir_add_error(ira, mask,
23481 buf_sprintf("expected vector or array, found '%s'",23519 buf_sprintf("expected vector or array, found '%s'",
23482 buf_ptr(&mask->value.type->name)));23520 buf_ptr(&mask->value->type->name)));
23483 return ira->codegen->invalid_instruction;23521 return ira->codegen->invalid_instruction;
23484 }23522 }
23485 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,23523 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
23486 ira->codegen->builtin_types.entry_i32));23524 ira->codegen->builtin_types.entry_i32));
23487 if (type_is_invalid(mask->value.type))23525 if (type_is_invalid(mask->value->type))
23488 return ira->codegen->invalid_instruction;23526 return ira->codegen->invalid_instruction;
2348923527
23490 uint32_t len_a;23528 uint32_t len_a;
23491 if (a->value.type->id == ZigTypeIdVector) {23529 if (a->value->type->id == ZigTypeIdVector) {
23492 len_a = a->value.type->data.vector.len;23530 len_a = a->value->type->data.vector.len;
23493 } else if (a->value.type->id == ZigTypeIdArray) {23531 } else if (a->value->type->id == ZigTypeIdArray) {
23494 len_a = a->value.type->data.array.len;23532 len_a = a->value->type->data.array.len;
23495 } else if (a->value.type->id == ZigTypeIdUndefined) {23533 } else if (a->value->type->id == ZigTypeIdUndefined) {
23496 len_a = UINT32_MAX;23534 len_a = UINT32_MAX;
23497 } else {23535 } else {
23498 ir_add_error(ira, a,23536 ir_add_error(ira, a,
23499 buf_sprintf("expected vector or array with element type '%s', found '%s'",23537 buf_sprintf("expected vector or array with element type '%s', found '%s'",
23500 buf_ptr(&scalar_type->name),23538 buf_ptr(&scalar_type->name),
23501 buf_ptr(&a->value.type->name)));23539 buf_ptr(&a->value->type->name)));
23502 return ira->codegen->invalid_instruction;23540 return ira->codegen->invalid_instruction;
23503 }23541 }
2350423542
23505 uint32_t len_b;23543 uint32_t len_b;
23506 if (b->value.type->id == ZigTypeIdVector) {23544 if (b->value->type->id == ZigTypeIdVector) {
23507 len_b = b->value.type->data.vector.len;23545 len_b = b->value->type->data.vector.len;
23508 } else if (b->value.type->id == ZigTypeIdArray) {23546 } else if (b->value->type->id == ZigTypeIdArray) {
23509 len_b = b->value.type->data.array.len;23547 len_b = b->value->type->data.array.len;
23510 } else if (b->value.type->id == ZigTypeIdUndefined) {23548 } else if (b->value->type->id == ZigTypeIdUndefined) {
23511 len_b = UINT32_MAX;23549 len_b = UINT32_MAX;
23512 } else {23550 } else {
23513 ir_add_error(ira, b,23551 ir_add_error(ira, b,
23514 buf_sprintf("expected vector or array with element type '%s', found '%s'",23552 buf_sprintf("expected vector or array with element type '%s', found '%s'",
23515 buf_ptr(&scalar_type->name),23553 buf_ptr(&scalar_type->name),
23516 buf_ptr(&b->value.type->name)));23554 buf_ptr(&b->value->type->name)));
23517 return ira->codegen->invalid_instruction;23555 return ira->codegen->invalid_instruction;
23518 }23556 }
2351923557
...@@ -23526,7 +23564,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23526,7 +23564,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23526 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));23564 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
23527 } else {23565 } else {
23528 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));23566 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
23529 if (type_is_invalid(a->value.type))23567 if (type_is_invalid(a->value->type))
23530 return ira->codegen->invalid_instruction;23568 return ira->codegen->invalid_instruction;
23531 }23569 }
2353223570
...@@ -23535,18 +23573,18 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23535,18 +23573,18 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23535 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));23573 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
23536 } else {23574 } else {
23537 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));23575 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
23538 if (type_is_invalid(b->value.type))23576 if (type_is_invalid(b->value->type))
23539 return ira->codegen->invalid_instruction;23577 return ira->codegen->invalid_instruction;
23540 }23578 }
2354123579
23542 ConstExprValue *mask_val = ir_resolve_const(ira, mask, UndefOk);23580 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
23543 if (mask_val == nullptr)23581 if (mask_val == nullptr)
23544 return ira->codegen->invalid_instruction;23582 return ira->codegen->invalid_instruction;
2354523583
23546 expand_undef_array(ira->codegen, mask_val);23584 expand_undef_array(ira->codegen, mask_val);
2354723585
23548 for (uint32_t i = 0; i < len_mask; i += 1) {23586 for (uint32_t i = 0; i < len_mask; i += 1) {
23549 ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];23587 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
23550 if (mask_elem_val->special == ConstValSpecialUndef)23588 if (mask_elem_val->special == ConstValSpecialUndef)
23551 continue;23589 continue;
23552 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);23590 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
...@@ -23559,12 +23597,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23559,12 +23597,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23559 v = (uint32_t)~v_i32;23597 v = (uint32_t)~v_i32;
23560 chosen_operand = b;23598 chosen_operand = b;
23561 }23599 }
23562 if (v >= chosen_operand->value.type->data.vector.len) {23600 if (v >= chosen_operand->value->type->data.vector.len) {
23563 ErrorMsg *msg = ir_add_error(ira, mask,23601 ErrorMsg *msg = ir_add_error(ira, mask,
23564 buf_sprintf("mask index '%u' has out-of-bounds selection", i));23602 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
23565 add_error_note(ira->codegen, msg, chosen_operand->source_node,23603 add_error_note(ira->codegen, msg, chosen_operand->source_node,
23566 buf_sprintf("selected index '%u' out of bounds of %s", v,23604 buf_sprintf("selected index '%u' out of bounds of %s", v,
23567 buf_ptr(&chosen_operand->value.type->name)));23605 buf_ptr(&chosen_operand->value->type->name)));
23568 if (chosen_operand == a && v < len_a + len_b) {23606 if (chosen_operand == a && v < len_a + len_b) {
23569 add_error_note(ira->codegen, msg, b->source_node,23607 add_error_note(ira->codegen, msg, b->source_node,
23570 buf_create_from_str("selections from the second vector are specified with negative numbers"));23608 buf_create_from_str("selections from the second vector are specified with negative numbers"));
...@@ -23575,11 +23613,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23575,11 +23613,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2357523613
23576 ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type);23614 ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type);
23577 if (instr_is_comptime(a) && instr_is_comptime(b)) {23615 if (instr_is_comptime(a) && instr_is_comptime(b)) {
23578 ConstExprValue *a_val = ir_resolve_const(ira, a, UndefOk);23616 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
23579 if (a_val == nullptr)23617 if (a_val == nullptr)
23580 return ira->codegen->invalid_instruction;23618 return ira->codegen->invalid_instruction;
2358123619
23582 ConstExprValue *b_val = ir_resolve_const(ira, b, UndefOk);23620 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
23583 if (b_val == nullptr)23621 if (b_val == nullptr)
23584 return ira->codegen->invalid_instruction;23622 return ira->codegen->invalid_instruction;
2358523623
...@@ -23587,24 +23625,24 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23587,24 +23625,24 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23587 expand_undef_array(ira->codegen, b_val);23625 expand_undef_array(ira->codegen, b_val);
2358823626
23589 IrInstruction *result = ir_const(ira, source_instr, result_type);23627 IrInstruction *result = ir_const(ira, source_instr, result_type);
23590 result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask);23628 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
23591 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {23629 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
23592 ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];23630 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
23593 ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];23631 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
23594 if (mask_elem_val->special == ConstValSpecialUndef) {23632 if (mask_elem_val->special == ConstValSpecialUndef) {
23595 result_elem_val->special = ConstValSpecialUndef;23633 result_elem_val->special = ConstValSpecialUndef;
23596 continue;23634 continue;
23597 }23635 }
23598 int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint);23636 int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint);
23599 // We've already checked for and emitted compile errors for index out of bounds here.23637 // We've already checked for and emitted compile errors for index out of bounds here.
23600 ConstExprValue *src_elem_val = (v >= 0) ?23638 ZigValue *src_elem_val = (v >= 0) ?
23601 &a->value.data.x_array.data.s_none.elements[v] :23639 &a->value->data.x_array.data.s_none.elements[v] :
23602 &b->value.data.x_array.data.s_none.elements[~v];23640 &b->value->data.x_array.data.s_none.elements[~v];
23603 copy_const_val(result_elem_val, src_elem_val, false);23641 copy_const_val(result_elem_val, src_elem_val, false);
2360423642
23605 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);23643 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
23606 }23644 }
23607 result->value.special = ConstValSpecialStatic;23645 result->value->special = ConstValSpecialStatic;
23608 return result;23646 return result;
23609 }23647 }
2361023648
...@@ -23620,12 +23658,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23620,12 +23658,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2362023658
23621 IrInstruction *expand_mask = ir_const(ira, mask,23659 IrInstruction *expand_mask = ir_const(ira, mask,
23622 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));23660 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
23623 expand_mask->value.data.x_array.data.s_none.elements = create_const_vals(len_max);23661 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
23624 uint32_t i = 0;23662 uint32_t i = 0;
23625 for (; i < len_min; i += 1)23663 for (; i < len_min; i += 1)
23626 bigint_init_unsigned(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, i);23664 bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i);
23627 for (; i < len_max; i += 1)23665 for (; i < len_max; i += 1)
23628 bigint_init_signed(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, -1);23666 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2362923667
23630 IrInstruction *undef = ir_const_undef(ira, source_instr,23668 IrInstruction *undef = ir_const_undef(ira, source_instr,
23631 get_vector_type(ira->codegen, len_min, scalar_type));23669 get_vector_type(ira->codegen, len_min, scalar_type));
...@@ -23640,7 +23678,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23640,7 +23678,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23640 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,23678 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,
23641 source_instr->scope, source_instr->source_node,23679 source_instr->scope, source_instr->source_node,
23642 nullptr, a, b, mask);23680 nullptr, a, b, mask);
23643 result->value.type = result_type;23681 result->value->type = result_type;
23644 return result;23682 return result;
23645}23683}
2364623684
...@@ -23650,15 +23688,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn...@@ -23650,15 +23688,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn
23650 return ira->codegen->invalid_instruction;23688 return ira->codegen->invalid_instruction;
2365123689
23652 IrInstruction *a = instruction->a->child;23690 IrInstruction *a = instruction->a->child;
23653 if (type_is_invalid(a->value.type))23691 if (type_is_invalid(a->value->type))
23654 return ira->codegen->invalid_instruction;23692 return ira->codegen->invalid_instruction;
2365523693
23656 IrInstruction *b = instruction->b->child;23694 IrInstruction *b = instruction->b->child;
23657 if (type_is_invalid(b->value.type))23695 if (type_is_invalid(b->value->type))
23658 return ira->codegen->invalid_instruction;23696 return ira->codegen->invalid_instruction;
2365923697
23660 IrInstruction *mask = instruction->mask->child;23698 IrInstruction *mask = instruction->mask->child;
23661 if (type_is_invalid(mask->value.type))23699 if (type_is_invalid(mask->value->type))
23662 return ira->codegen->invalid_instruction;23700 return ira->codegen->invalid_instruction;
2366323701
23664 return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask);23702 return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask);
...@@ -23668,11 +23706,11 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -23668,11 +23706,11 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
23668 Error err;23706 Error err;
2366923707
23670 IrInstruction *len = instruction->len->child;23708 IrInstruction *len = instruction->len->child;
23671 if (type_is_invalid(len->value.type))23709 if (type_is_invalid(len->value->type))
23672 return ira->codegen->invalid_instruction;23710 return ira->codegen->invalid_instruction;
2367323711
23674 IrInstruction *scalar = instruction->scalar->child;23712 IrInstruction *scalar = instruction->scalar->child;
23675 if (type_is_invalid(scalar->value.type))23713 if (type_is_invalid(scalar->value->type))
23676 return ira->codegen->invalid_instruction;23714 return ira->codegen->invalid_instruction;
2367723715
23678 uint64_t len_u64;23716 uint64_t len_u64;
...@@ -23680,22 +23718,22 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -23680,22 +23718,22 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
23680 return ira->codegen->invalid_instruction;23718 return ira->codegen->invalid_instruction;
23681 uint32_t len_int = len_u64;23719 uint32_t len_int = len_u64;
2368223720
23683 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value.type)))23721 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type)))
23684 return ira->codegen->invalid_instruction;23722 return ira->codegen->invalid_instruction;
2368523723
23686 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type);23724 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
2368723725
23688 if (instr_is_comptime(scalar)) {23726 if (instr_is_comptime(scalar)) {
23689 ConstExprValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);23727 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
23690 if (scalar_val == nullptr)23728 if (scalar_val == nullptr)
23691 return ira->codegen->invalid_instruction;23729 return ira->codegen->invalid_instruction;
23692 if (scalar_val->special == ConstValSpecialUndef)23730 if (scalar_val->special == ConstValSpecialUndef)
23693 return ir_const_undef(ira, &instruction->base, return_type);23731 return ir_const_undef(ira, &instruction->base, return_type);
2369423732
23695 IrInstruction *result = ir_const(ira, &instruction->base, return_type);23733 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
23696 result->value.data.x_array.data.s_none.elements = create_const_vals(len_int);23734 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
23697 for (uint32_t i = 0; i < len_int; i += 1) {23735 for (uint32_t i = 0; i < len_int; i += 1) {
23698 copy_const_val(&result->value.data.x_array.data.s_none.elements[i], scalar_val, false);23736 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false);
23699 }23737 }
23700 return result;23738 return result;
23701 }23739 }
...@@ -23705,17 +23743,17 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -23705,17 +23743,17 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2370523743
23706static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {23744static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
23707 IrInstruction *value = instruction->value->child;23745 IrInstruction *value = instruction->value->child;
23708 if (type_is_invalid(value->value.type))23746 if (type_is_invalid(value->value->type))
23709 return ira->codegen->invalid_instruction;23747 return ira->codegen->invalid_instruction;
2371023748
23711 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;23749 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2371223750
23713 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);23751 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
23714 if (type_is_invalid(casted_value->value.type))23752 if (type_is_invalid(casted_value->value->type))
23715 return ira->codegen->invalid_instruction;23753 return ira->codegen->invalid_instruction;
2371623754
23717 if (instr_is_comptime(casted_value)) {23755 if (instr_is_comptime(casted_value)) {
23718 ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad);23756 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
23719 if (value == nullptr)23757 if (value == nullptr)
23720 return ira->codegen->invalid_instruction;23758 return ira->codegen->invalid_instruction;
2372123759
...@@ -23724,7 +23762,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct...@@ -23724,7 +23762,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct
2372423762
23725 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,23763 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,
23726 instruction->base.source_node, casted_value);23764 instruction->base.source_node, casted_value);
23727 result->value.type = bool_type;23765 result->value->type = bool_type;
23728 return result;23766 return result;
23729}23767}
2373023768
...@@ -23732,18 +23770,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23732,18 +23770,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23732 Error err;23770 Error err;
2373323771
23734 IrInstruction *dest_ptr = instruction->dest_ptr->child;23772 IrInstruction *dest_ptr = instruction->dest_ptr->child;
23735 if (type_is_invalid(dest_ptr->value.type))23773 if (type_is_invalid(dest_ptr->value->type))
23736 return ira->codegen->invalid_instruction;23774 return ira->codegen->invalid_instruction;
2373723775
23738 IrInstruction *byte_value = instruction->byte->child;23776 IrInstruction *byte_value = instruction->byte->child;
23739 if (type_is_invalid(byte_value->value.type))23777 if (type_is_invalid(byte_value->value->type))
23740 return ira->codegen->invalid_instruction;23778 return ira->codegen->invalid_instruction;
2374123779
23742 IrInstruction *count_value = instruction->count->child;23780 IrInstruction *count_value = instruction->count->child;
23743 if (type_is_invalid(count_value->value.type))23781 if (type_is_invalid(count_value->value->type))
23744 return ira->codegen->invalid_instruction;23782 return ira->codegen->invalid_instruction;
2374523783
23746 ZigType *dest_uncasted_type = dest_ptr->value.type;23784 ZigType *dest_uncasted_type = dest_ptr->value->type;
23747 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&23785 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
23748 dest_uncasted_type->data.pointer.is_volatile;23786 dest_uncasted_type->data.pointer.is_volatile;
2374923787
...@@ -23760,15 +23798,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23760,15 +23798,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23760 PtrLenUnknown, dest_align, 0, 0, false);23798 PtrLenUnknown, dest_align, 0, 0, false);
2376123799
23762 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);23800 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
23763 if (type_is_invalid(casted_dest_ptr->value.type))23801 if (type_is_invalid(casted_dest_ptr->value->type))
23764 return ira->codegen->invalid_instruction;23802 return ira->codegen->invalid_instruction;
2376523803
23766 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);23804 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
23767 if (type_is_invalid(casted_byte->value.type))23805 if (type_is_invalid(casted_byte->value->type))
23768 return ira->codegen->invalid_instruction;23806 return ira->codegen->invalid_instruction;
2376923807
23770 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);23808 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
23771 if (type_is_invalid(casted_count->value.type))23809 if (type_is_invalid(casted_count->value->type))
23772 return ira->codegen->invalid_instruction;23810 return ira->codegen->invalid_instruction;
2377323811
23774 // TODO test this at comptime with u8 and non-u8 types23812 // TODO test this at comptime with u8 and non-u8 types
...@@ -23776,22 +23814,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23776,22 +23814,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23776 instr_is_comptime(casted_byte) &&23814 instr_is_comptime(casted_byte) &&
23777 instr_is_comptime(casted_count))23815 instr_is_comptime(casted_count))
23778 {23816 {
23779 ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);23817 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
23780 if (dest_ptr_val == nullptr)23818 if (dest_ptr_val == nullptr)
23781 return ira->codegen->invalid_instruction;23819 return ira->codegen->invalid_instruction;
2378223820
23783 ConstExprValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);23821 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
23784 if (byte_val == nullptr)23822 if (byte_val == nullptr)
23785 return ira->codegen->invalid_instruction;23823 return ira->codegen->invalid_instruction;
2378623824
23787 ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);23825 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
23788 if (count_val == nullptr)23826 if (count_val == nullptr)
23789 return ira->codegen->invalid_instruction;23827 return ira->codegen->invalid_instruction;
2379023828
23791 if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&23829 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
23792 casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)23830 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
23793 {23831 {
23794 ConstExprValue *dest_elements;23832 ZigValue *dest_elements;
23795 size_t start;23833 size_t start;
23796 size_t bound_end;23834 size_t bound_end;
23797 switch (dest_ptr_val->data.x_ptr.special) {23835 switch (dest_ptr_val->data.x_ptr.special) {
...@@ -23805,7 +23843,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23805,7 +23843,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23805 break;23843 break;
23806 case ConstPtrSpecialBaseArray:23844 case ConstPtrSpecialBaseArray:
23807 {23845 {
23808 ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;23846 ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;
23809 expand_undef_array(ira->codegen, array_val);23847 expand_undef_array(ira->codegen, array_val);
23810 dest_elements = array_val->data.x_array.data.s_none.elements;23848 dest_elements = array_val->data.x_array.data.s_none.elements;
23811 start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;23849 start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -23845,7 +23883,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23845,7 +23883,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2384523883
23846 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,23884 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
23847 casted_dest_ptr, casted_byte, casted_count);23885 casted_dest_ptr, casted_byte, casted_count);
23848 result->value.type = ira->codegen->builtin_types.entry_void;23886 result->value->type = ira->codegen->builtin_types.entry_void;
23849 return result;23887 return result;
23850}23888}
2385123889
...@@ -23853,20 +23891,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23853,20 +23891,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23853 Error err;23891 Error err;
2385423892
23855 IrInstruction *dest_ptr = instruction->dest_ptr->child;23893 IrInstruction *dest_ptr = instruction->dest_ptr->child;
23856 if (type_is_invalid(dest_ptr->value.type))23894 if (type_is_invalid(dest_ptr->value->type))
23857 return ira->codegen->invalid_instruction;23895 return ira->codegen->invalid_instruction;
2385823896
23859 IrInstruction *src_ptr = instruction->src_ptr->child;23897 IrInstruction *src_ptr = instruction->src_ptr->child;
23860 if (type_is_invalid(src_ptr->value.type))23898 if (type_is_invalid(src_ptr->value->type))
23861 return ira->codegen->invalid_instruction;23899 return ira->codegen->invalid_instruction;
2386223900
23863 IrInstruction *count_value = instruction->count->child;23901 IrInstruction *count_value = instruction->count->child;
23864 if (type_is_invalid(count_value->value.type))23902 if (type_is_invalid(count_value->value->type))
23865 return ira->codegen->invalid_instruction;23903 return ira->codegen->invalid_instruction;
2386623904
23867 ZigType *u8 = ira->codegen->builtin_types.entry_u8;23905 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
23868 ZigType *dest_uncasted_type = dest_ptr->value.type;23906 ZigType *dest_uncasted_type = dest_ptr->value->type;
23869 ZigType *src_uncasted_type = src_ptr->value.type;23907 ZigType *src_uncasted_type = src_ptr->value->type;
23870 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&23908 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
23871 dest_uncasted_type->data.pointer.is_volatile;23909 dest_uncasted_type->data.pointer.is_volatile;
23872 bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&23910 bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&
...@@ -23895,15 +23933,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23895,15 +23933,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23895 PtrLenUnknown, src_align, 0, 0, false);23933 PtrLenUnknown, src_align, 0, 0, false);
2389623934
23897 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);23935 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
23898 if (type_is_invalid(casted_dest_ptr->value.type))23936 if (type_is_invalid(casted_dest_ptr->value->type))
23899 return ira->codegen->invalid_instruction;23937 return ira->codegen->invalid_instruction;
2390023938
23901 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);23939 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
23902 if (type_is_invalid(casted_src_ptr->value.type))23940 if (type_is_invalid(casted_src_ptr->value->type))
23903 return ira->codegen->invalid_instruction;23941 return ira->codegen->invalid_instruction;
2390423942
23905 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);23943 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
23906 if (type_is_invalid(casted_count->value.type))23944 if (type_is_invalid(casted_count->value->type))
23907 return ira->codegen->invalid_instruction;23945 return ira->codegen->invalid_instruction;
2390823946
23909 // TODO test this at comptime with u8 and non-u8 types23947 // TODO test this at comptime with u8 and non-u8 types
...@@ -23912,22 +23950,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23912,22 +23950,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23912 instr_is_comptime(casted_src_ptr) &&23950 instr_is_comptime(casted_src_ptr) &&
23913 instr_is_comptime(casted_count))23951 instr_is_comptime(casted_count))
23914 {23952 {
23915 ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);23953 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
23916 if (dest_ptr_val == nullptr)23954 if (dest_ptr_val == nullptr)
23917 return ira->codegen->invalid_instruction;23955 return ira->codegen->invalid_instruction;
2391823956
23919 ConstExprValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);23957 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
23920 if (src_ptr_val == nullptr)23958 if (src_ptr_val == nullptr)
23921 return ira->codegen->invalid_instruction;23959 return ira->codegen->invalid_instruction;
2392223960
23923 ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);23961 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
23924 if (count_val == nullptr)23962 if (count_val == nullptr)
23925 return ira->codegen->invalid_instruction;23963 return ira->codegen->invalid_instruction;
2392623964
23927 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {23965 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
23928 size_t count = bigint_as_usize(&count_val->data.x_bigint);23966 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2392923967
23930 ConstExprValue *dest_elements;23968 ZigValue *dest_elements;
23931 size_t dest_start;23969 size_t dest_start;
23932 size_t dest_end;23970 size_t dest_end;
23933 switch (dest_ptr_val->data.x_ptr.special) {23971 switch (dest_ptr_val->data.x_ptr.special) {
...@@ -23941,7 +23979,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23941,7 +23979,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23941 break;23979 break;
23942 case ConstPtrSpecialBaseArray:23980 case ConstPtrSpecialBaseArray:
23943 {23981 {
23944 ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;23982 ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;
23945 expand_undef_array(ira->codegen, array_val);23983 expand_undef_array(ira->codegen, array_val);
23946 dest_elements = array_val->data.x_array.data.s_none.elements;23984 dest_elements = array_val->data.x_array.data.s_none.elements;
23947 dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;23985 dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -23969,7 +24007,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23969,7 +24007,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23969 return ira->codegen->invalid_instruction;24007 return ira->codegen->invalid_instruction;
23970 }24008 }
2397124009
23972 ConstExprValue *src_elements;24010 ZigValue *src_elements;
23973 size_t src_start;24011 size_t src_start;
23974 size_t src_end;24012 size_t src_end;
2397524013
...@@ -23984,7 +24022,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23984,7 +24022,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23984 break;24022 break;
23985 case ConstPtrSpecialBaseArray:24023 case ConstPtrSpecialBaseArray:
23986 {24024 {
23987 ConstExprValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val;24025 ZigValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val;
23988 expand_undef_array(ira->codegen, array_val);24026 expand_undef_array(ira->codegen, array_val);
23989 src_elements = array_val->data.x_array.data.s_none.elements;24027 src_elements = array_val->data.x_array.data.s_none.elements;
23990 src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index;24028 src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -24024,35 +24062,35 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -24024,35 +24062,35 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2402424062
24025 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,24063 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
24026 casted_dest_ptr, casted_src_ptr, casted_count);24064 casted_dest_ptr, casted_src_ptr, casted_count);
24027 result->value.type = ira->codegen->builtin_types.entry_void;24065 result->value->type = ira->codegen->builtin_types.entry_void;
24028 return result;24066 return result;
24029}24067}
2403024068
24031static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {24069static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {
24032 IrInstruction *ptr_ptr = instruction->ptr->child;24070 IrInstruction *ptr_ptr = instruction->ptr->child;
24033 if (type_is_invalid(ptr_ptr->value.type))24071 if (type_is_invalid(ptr_ptr->value->type))
24034 return ira->codegen->invalid_instruction;24072 return ira->codegen->invalid_instruction;
2403524073
24036 ZigType *ptr_ptr_type = ptr_ptr->value.type;24074 ZigType *ptr_ptr_type = ptr_ptr->value->type;
24037 assert(ptr_ptr_type->id == ZigTypeIdPointer);24075 assert(ptr_ptr_type->id == ZigTypeIdPointer);
24038 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;24076 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2403924077
24040 IrInstruction *start = instruction->start->child;24078 IrInstruction *start = instruction->start->child;
24041 if (type_is_invalid(start->value.type))24079 if (type_is_invalid(start->value->type))
24042 return ira->codegen->invalid_instruction;24080 return ira->codegen->invalid_instruction;
2404324081
24044 ZigType *usize = ira->codegen->builtin_types.entry_usize;24082 ZigType *usize = ira->codegen->builtin_types.entry_usize;
24045 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);24083 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
24046 if (type_is_invalid(casted_start->value.type))24084 if (type_is_invalid(casted_start->value->type))
24047 return ira->codegen->invalid_instruction;24085 return ira->codegen->invalid_instruction;
2404824086
24049 IrInstruction *end;24087 IrInstruction *end;
24050 if (instruction->end) {24088 if (instruction->end) {
24051 end = instruction->end->child;24089 end = instruction->end->child;
24052 if (type_is_invalid(end->value.type))24090 if (type_is_invalid(end->value->type))
24053 return ira->codegen->invalid_instruction;24091 return ira->codegen->invalid_instruction;
24054 end = ir_implicit_cast(ira, end, usize);24092 end = ir_implicit_cast(ira, end, usize);
24055 if (type_is_invalid(end->value.type))24093 if (type_is_invalid(end->value->type))
24056 return ira->codegen->invalid_instruction;24094 return ira->codegen->invalid_instruction;
24057 } else {24095 } else {
24058 end = nullptr;24096 end = nullptr;
...@@ -24061,8 +24099,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24061,8 +24099,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24061 ZigType *return_type;24099 ZigType *return_type;
2406224100
24063 if (array_type->id == ZigTypeIdArray) {24101 if (array_type->id == ZigTypeIdArray) {
24064 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&24102 bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic &&
24065 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;24103 ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst;
24066 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,24104 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
24067 ptr_ptr_type->data.pointer.is_const || is_comptime_const,24105 ptr_ptr_type->data.pointer.is_const || is_comptime_const,
24068 ptr_ptr_type->data.pointer.is_volatile,24106 ptr_ptr_type->data.pointer.is_volatile,
...@@ -24103,11 +24141,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24103,11 +24141,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24103 }24141 }
2410424142
24105 if (instr_is_comptime(ptr_ptr) &&24143 if (instr_is_comptime(ptr_ptr) &&
24106 value_is_comptime(&casted_start->value) &&24144 value_is_comptime(casted_start->value) &&
24107 (!end || value_is_comptime(&end->value)))24145 (!end || value_is_comptime(end->value)))
24108 {24146 {
24109 ConstExprValue *array_val;24147 ZigValue *array_val;
24110 ConstExprValue *parent_ptr;24148 ZigValue *parent_ptr;
24111 size_t abs_offset;24149 size_t abs_offset;
24112 size_t rel_end;24150 size_t rel_end;
24113 bool ptr_is_undef = false;24151 bool ptr_is_undef = false;
...@@ -24117,7 +24155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24117,7 +24155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24117 if (array_type->id == ZigTypeIdPointer) {24155 if (array_type->id == ZigTypeIdPointer) {
24118 ZigType *child_array_type = array_type->data.pointer.child_type;24156 ZigType *child_array_type = array_type->data.pointer.child_type;
24119 assert(child_array_type->id == ZigTypeIdArray);24157 assert(child_array_type->id == ZigTypeIdArray);
24120 parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);24158 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
24121 if (parent_ptr == nullptr)24159 if (parent_ptr == nullptr)
24122 return ira->codegen->invalid_instruction;24160 return ira->codegen->invalid_instruction;
2412324161
...@@ -24136,7 +24174,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24136,7 +24174,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24136 abs_offset = 0;24174 abs_offset = 0;
24137 }24175 }
24138 } else {24176 } else {
24139 array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);24177 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
24140 if (array_val == nullptr)24178 if (array_val == nullptr)
24141 return ira->codegen->invalid_instruction;24179 return ira->codegen->invalid_instruction;
24142 rel_end = array_type->data.array.len;24180 rel_end = array_type->data.array.len;
...@@ -24145,7 +24183,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24145,7 +24183,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24145 }24183 }
24146 } else if (array_type->id == ZigTypeIdPointer) {24184 } else if (array_type->id == ZigTypeIdPointer) {
24147 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);24185 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
24148 parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);24186 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
24149 if (parent_ptr == nullptr)24187 if (parent_ptr == nullptr)
24150 return ira->codegen->invalid_instruction;24188 return ira->codegen->invalid_instruction;
2415124189
...@@ -24193,7 +24231,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24193,7 +24231,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24193 zig_panic("TODO slice of null ptr");24231 zig_panic("TODO slice of null ptr");
24194 }24232 }
24195 } else if (is_slice(array_type)) {24233 } else if (is_slice(array_type)) {
24196 ConstExprValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);24234 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
24197 if (slice_ptr == nullptr)24235 if (slice_ptr == nullptr)
24198 return ira->codegen->invalid_instruction;24236 return ira->codegen->invalid_instruction;
2419924237
...@@ -24208,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24208,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24208 return ira->codegen->invalid_instruction;24246 return ira->codegen->invalid_instruction;
24209 }24247 }
2421024248
24211 ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];24249 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
2421224250
24213 switch (parent_ptr->data.x_ptr.special) {24251 switch (parent_ptr->data.x_ptr.special) {
24214 case ConstPtrSpecialInvalid:24252 case ConstPtrSpecialInvalid:
...@@ -24246,7 +24284,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24246,7 +24284,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24246 zig_unreachable();24284 zig_unreachable();
24247 }24285 }
2424824286
24249 ConstExprValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);24287 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
24250 if (!start_val)24288 if (!start_val)
24251 return ira->codegen->invalid_instruction;24289 return ira->codegen->invalid_instruction;
2425224290
...@@ -24258,7 +24296,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24258,7 +24296,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2425824296
24259 uint64_t end_scalar = rel_end;24297 uint64_t end_scalar = rel_end;
24260 if (end) {24298 if (end) {
24261 ConstExprValue *end_val = ir_resolve_const(ira, end, UndefBad);24299 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
24262 if (!end_val)24300 if (!end_val)
24263 return ira->codegen->invalid_instruction;24301 return ira->codegen->invalid_instruction;
24264 end_scalar = bigint_as_u64(&end_val->data.x_bigint);24302 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
...@@ -24279,17 +24317,17 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24279,17 +24317,17 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24279 }24317 }
2428024318
24281 IrInstruction *result = ir_const(ira, &instruction->base, return_type);24319 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
24282 ConstExprValue *out_val = &result->value;24320 ZigValue *out_val = result->value;
24283 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);24321 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2428424322
24285 ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];24323 ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2428624324
24287 if (array_val) {24325 if (array_val) {
24288 size_t index = abs_offset + start_scalar;24326 size_t index = abs_offset + start_scalar;
24289 bool is_const = slice_is_const(return_type);24327 bool is_const = slice_is_const(return_type);
24290 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);24328 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);
24291 if (array_type->id == ZigTypeIdArray) {24329 if (array_type->id == ZigTypeIdArray) {
24292 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;24330 ptr_val->data.x_ptr.mut = ptr_ptr->value->data.x_ptr.mut;
24293 } else if (is_slice(array_type)) {24331 } else if (is_slice(array_type)) {
24294 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;24332 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
24295 } else if (array_type->id == ZigTypeIdPointer) {24333 } else if (array_type->id == ZigTypeIdPointer) {
...@@ -24329,7 +24367,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24329,7 +24367,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24329 zig_panic("TODO");24367 zig_panic("TODO");
24330 }24368 }
2433124369
24332 ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index];24370 ZigValue *len_val = out_val->data.x_struct.fields[slice_len_index];
24333 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);24371 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);
2433424372
24335 return result;24373 return result;
...@@ -24337,7 +24375,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24337,7 +24375,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2433724375
24338 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,24376 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
24339 return_type, nullptr, true, false, true);24377 return_type, nullptr, true, false, true);
24340 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {24378 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
24341 return result_loc;24379 return result_loc;
24342 }24380 }
24343 return ir_build_slice_gen(ira, &instruction->base, return_type,24381 return ir_build_slice_gen(ira, &instruction->base, return_type,
...@@ -24347,7 +24385,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24347,7 +24385,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24347static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {24385static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
24348 Error err;24386 Error err;
24349 IrInstruction *container = instruction->container->child;24387 IrInstruction *container = instruction->container->child;
24350 if (type_is_invalid(container->value.type))24388 if (type_is_invalid(container->value->type))
24351 return ira->codegen->invalid_instruction;24389 return ira->codegen->invalid_instruction;
24352 ZigType *container_type = ir_resolve_type(ira, container);24390 ZigType *container_type = ir_resolve_type(ira, container);
2435324391
...@@ -24448,7 +24486,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr...@@ -24448,7 +24486,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
24448 TypeStructField *field = container_type->data.structure.fields[member_index];24486 TypeStructField *field = container_type->data.structure.fields[member_index];
2444924487
24450 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);24488 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
24451 init_const_str_lit(ira->codegen, &result->value, field->name);24489 init_const_str_lit(ira->codegen, result->value, field->name);
24452 return result;24490 return result;
24453 } else if (container_type->id == ZigTypeIdEnum) {24491 } else if (container_type->id == ZigTypeIdEnum) {
24454 if (member_index >= container_type->data.enumeration.src_field_count) {24492 if (member_index >= container_type->data.enumeration.src_field_count) {
...@@ -24460,7 +24498,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr...@@ -24460,7 +24498,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
24460 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];24498 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
2446124499
24462 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);24500 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
24463 init_const_str_lit(ira->codegen, &result->value, field->name);24501 init_const_str_lit(ira->codegen, result->value, field->name);
24464 return result;24502 return result;
24465 } else if (container_type->id == ZigTypeIdUnion) {24503 } else if (container_type->id == ZigTypeIdUnion) {
24466 if (member_index >= container_type->data.unionation.src_field_count) {24504 if (member_index >= container_type->data.unionation.src_field_count) {
...@@ -24472,7 +24510,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr...@@ -24472,7 +24510,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
24472 TypeUnionField *field = &container_type->data.unionation.fields[member_index];24510 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2447324511
24474 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);24512 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
24475 init_const_str_lit(ira->codegen, &result->value, field->name);24513 init_const_str_lit(ira->codegen, result->value, field->name);
24476 return result;24514 return result;
24477 } else {24515 } else {
24478 ir_add_error(ira, container_type_value,24516 ir_add_error(ira, container_type_value,
...@@ -24512,21 +24550,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc...@@ -24512,21 +24550,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
24512static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {24550static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
24513 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,24551 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,
24514 instruction->base.scope, instruction->base.source_node);24552 instruction->base.scope, instruction->base.source_node);
24515 result->value.type = ira->codegen->builtin_types.entry_void;24553 result->value->type = ira->codegen->builtin_types.entry_void;
24516 return result;24554 return result;
24517}24555}
2451824556
24519static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {24557static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
24520 IrInstruction *result = ir_build_return_address(&ira->new_irb,24558 IrInstruction *result = ir_build_return_address(&ira->new_irb,
24521 instruction->base.scope, instruction->base.source_node);24559 instruction->base.scope, instruction->base.source_node);
24522 result->value.type = ira->codegen->builtin_types.entry_usize;24560 result->value->type = ira->codegen->builtin_types.entry_usize;
24523 return result;24561 return result;
24524}24562}
2452524563
24526static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {24564static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
24527 IrInstruction *result = ir_build_frame_address(&ira->new_irb,24565 IrInstruction *result = ir_build_frame_address(&ira->new_irb,
24528 instruction->base.scope, instruction->base.source_node);24566 instruction->base.scope, instruction->base.source_node);
24529 result->value.type = ira->codegen->builtin_types.entry_usize;24567 result->value->type = ira->codegen->builtin_types.entry_usize;
24530 return result;24568 return result;
24531}24569}
2453224570
...@@ -24542,7 +24580,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst...@@ -24542,7 +24580,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst
24542 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);24580 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2454324581
24544 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);24582 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
24545 result->value.type = ptr_frame_type;24583 result->value->type = ptr_frame_type;
24546 return result;24584 return result;
24547}24585}
2454824586
...@@ -24563,12 +24601,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru...@@ -24563,12 +24601,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru
2456324601
24564static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {24602static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {
24565 IrInstruction *fn = instruction->fn->child;24603 IrInstruction *fn = instruction->fn->child;
24566 if (type_is_invalid(fn->value.type))24604 if (type_is_invalid(fn->value->type))
24567 return ira->codegen->invalid_instruction;24605 return ira->codegen->invalid_instruction;
2456824606
24569 if (fn->value.type->id != ZigTypeIdFn) {24607 if (fn->value->type->id != ZigTypeIdFn) {
24570 ir_add_error(ira, fn,24608 ir_add_error(ira, fn,
24571 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value.type->name)));24609 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
24572 return ira->codegen->invalid_instruction;24610 return ira->codegen->invalid_instruction;
24573 }24611 }
2457424612
...@@ -24576,7 +24614,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru...@@ -24576,7 +24614,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru
2457624614
24577 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,24615 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
24578 instruction->base.source_node, fn);24616 instruction->base.source_node, fn);
24579 result->value.type = ira->codegen->builtin_types.entry_usize;24617 result->value->type = ira->codegen->builtin_types.entry_usize;
24580 return result;24618 return result;
24581}24619}
2458224620
...@@ -24587,11 +24625,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -24587,11 +24625,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
24587 // field: []align(@alignOf(Node)) Node,24625 // field: []align(@alignOf(Node)) Node,
24588 // };24626 // };
24589 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);24627 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
24590 result->value.special = ConstValSpecialLazy;24628 result->value->special = ConstValSpecialLazy;
2459124629
24592 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1);24630 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1);
24593 lazy_align_of->ira = ira;24631 lazy_align_of->ira = ira;
24594 result->value.data.x_lazy = &lazy_align_of->base;24632 result->value->data.x_lazy = &lazy_align_of->base;
24595 lazy_align_of->base.id = LazyValueIdAlignOf;24633 lazy_align_of->base.id = LazyValueIdAlignOf;
2459624634
24597 lazy_align_of->target_type = instruction->type_value->child;24635 lazy_align_of->target_type = instruction->type_value->child;
...@@ -24605,7 +24643,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24605,7 +24643,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24605 Error err;24643 Error err;
2460624644
24607 IrInstruction *type_value = instruction->type_value->child;24645 IrInstruction *type_value = instruction->type_value->child;
24608 if (type_is_invalid(type_value->value.type))24646 if (type_is_invalid(type_value->value->type))
24609 return ira->codegen->invalid_instruction;24647 return ira->codegen->invalid_instruction;
2461024648
24611 ZigType *dest_type = ir_resolve_type(ira, type_value);24649 ZigType *dest_type = ir_resolve_type(ira, type_value);
...@@ -24619,15 +24657,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24619,15 +24657,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24619 }24657 }
2462024658
24621 IrInstruction *op1 = instruction->op1->child;24659 IrInstruction *op1 = instruction->op1->child;
24622 if (type_is_invalid(op1->value.type))24660 if (type_is_invalid(op1->value->type))
24623 return ira->codegen->invalid_instruction;24661 return ira->codegen->invalid_instruction;
2462424662
24625 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);24663 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
24626 if (type_is_invalid(casted_op1->value.type))24664 if (type_is_invalid(casted_op1->value->type))
24627 return ira->codegen->invalid_instruction;24665 return ira->codegen->invalid_instruction;
2462824666
24629 IrInstruction *op2 = instruction->op2->child;24667 IrInstruction *op2 = instruction->op2->child;
24630 if (type_is_invalid(op2->value.type))24668 if (type_is_invalid(op2->value->type))
24631 return ira->codegen->invalid_instruction;24669 return ira->codegen->invalid_instruction;
2463224670
24633 IrInstruction *casted_op2;24671 IrInstruction *casted_op2;
...@@ -24638,20 +24676,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24638,20 +24676,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24638 } else {24676 } else {
24639 casted_op2 = ir_implicit_cast(ira, op2, dest_type);24677 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
24640 }24678 }
24641 if (type_is_invalid(casted_op2->value.type))24679 if (type_is_invalid(casted_op2->value->type))
24642 return ira->codegen->invalid_instruction;24680 return ira->codegen->invalid_instruction;
2464324681
24644 IrInstruction *result_ptr = instruction->result_ptr->child;24682 IrInstruction *result_ptr = instruction->result_ptr->child;
24645 if (type_is_invalid(result_ptr->value.type))24683 if (type_is_invalid(result_ptr->value->type))
24646 return ira->codegen->invalid_instruction;24684 return ira->codegen->invalid_instruction;
2464724685
24648 ZigType *expected_ptr_type;24686 ZigType *expected_ptr_type;
24649 if (result_ptr->value.type->id == ZigTypeIdPointer) {24687 if (result_ptr->value->type->id == ZigTypeIdPointer) {
24650 uint32_t alignment;24688 uint32_t alignment;
24651 if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment)))24689 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))
24652 return ira->codegen->invalid_instruction;24690 return ira->codegen->invalid_instruction;
24653 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,24691 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
24654 false, result_ptr->value.type->data.pointer.is_volatile,24692 false, result_ptr->value->type->data.pointer.is_volatile,
24655 PtrLenSingle,24693 PtrLenSingle,
24656 alignment, 0, 0, false);24694 alignment, 0, 0, false);
24657 } else {24695 } else {
...@@ -24659,28 +24697,28 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24659,28 +24697,28 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24659 }24697 }
2466024698
24661 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);24699 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
24662 if (type_is_invalid(casted_result_ptr->value.type))24700 if (type_is_invalid(casted_result_ptr->value->type))
24663 return ira->codegen->invalid_instruction;24701 return ira->codegen->invalid_instruction;
2466424702
24665 if (instr_is_comptime(casted_op1) &&24703 if (instr_is_comptime(casted_op1) &&
24666 instr_is_comptime(casted_op2) &&24704 instr_is_comptime(casted_op2) &&
24667 instr_is_comptime(casted_result_ptr))24705 instr_is_comptime(casted_result_ptr))
24668 {24706 {
24669 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);24707 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
24670 if (op1_val == nullptr)24708 if (op1_val == nullptr)
24671 return ira->codegen->invalid_instruction;24709 return ira->codegen->invalid_instruction;
2467224710
24673 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);24711 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
24674 if (op2_val == nullptr)24712 if (op2_val == nullptr)
24675 return ira->codegen->invalid_instruction;24713 return ira->codegen->invalid_instruction;
2467624714
24677 ConstExprValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);24715 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
24678 if (result_val == nullptr)24716 if (result_val == nullptr)
24679 return ira->codegen->invalid_instruction;24717 return ira->codegen->invalid_instruction;
2468024718
24681 BigInt *op1_bigint = &op1_val->data.x_bigint;24719 BigInt *op1_bigint = &op1_val->data.x_bigint;
24682 BigInt *op2_bigint = &op2_val->data.x_bigint;24720 BigInt *op2_bigint = &op2_val->data.x_bigint;
24683 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,24721 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
24684 casted_result_ptr->source_node);24722 casted_result_ptr->source_node);
24685 if (pointee_val == nullptr)24723 if (pointee_val == nullptr)
24686 return ira->codegen->invalid_instruction;24724 return ira->codegen->invalid_instruction;
...@@ -24716,12 +24754,12 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24716,12 +24754,12 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24716 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,24754 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,
24717 instruction->base.scope, instruction->base.source_node,24755 instruction->base.scope, instruction->base.source_node,
24718 instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type);24756 instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type);
24719 result->value.type = ira->codegen->builtin_types.entry_bool;24757 result->value->type = ira->codegen->builtin_types.entry_bool;
24720 return result;24758 return result;
24721}24759}
2472224760
24723static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,24761static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,
24724 ConstExprValue *op1, ConstExprValue *op2, ConstExprValue *op3, ConstExprValue *out_val) {24762 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
24725 if (float_type->id == ZigTypeIdComptimeFloat) {24763 if (float_type->id == ZigTypeIdComptimeFloat) {
24726 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,24764 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
24727 &op3->data.x_bigfloat.value);24765 &op3->data.x_bigfloat.value);
...@@ -24749,7 +24787,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z...@@ -24749,7 +24787,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
2474924787
24750static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {24788static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {
24751 IrInstruction *type_value = instruction->type_value->child;24789 IrInstruction *type_value = instruction->type_value->child;
24752 if (type_is_invalid(type_value->value.type))24790 if (type_is_invalid(type_value->value->type))
24753 return ira->codegen->invalid_instruction;24791 return ira->codegen->invalid_instruction;
2475424792
24755 ZigType *expr_type = ir_resolve_type(ira, type_value);24793 ZigType *expr_type = ir_resolve_type(ira, type_value);
...@@ -24765,44 +24803,44 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24765,44 +24803,44 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24765 }24803 }
2476624804
24767 IrInstruction *op1 = instruction->op1->child;24805 IrInstruction *op1 = instruction->op1->child;
24768 if (type_is_invalid(op1->value.type))24806 if (type_is_invalid(op1->value->type))
24769 return ira->codegen->invalid_instruction;24807 return ira->codegen->invalid_instruction;
2477024808
24771 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);24809 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
24772 if (type_is_invalid(casted_op1->value.type))24810 if (type_is_invalid(casted_op1->value->type))
24773 return ira->codegen->invalid_instruction;24811 return ira->codegen->invalid_instruction;
2477424812
24775 IrInstruction *op2 = instruction->op2->child;24813 IrInstruction *op2 = instruction->op2->child;
24776 if (type_is_invalid(op2->value.type))24814 if (type_is_invalid(op2->value->type))
24777 return ira->codegen->invalid_instruction;24815 return ira->codegen->invalid_instruction;
2477824816
24779 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);24817 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
24780 if (type_is_invalid(casted_op2->value.type))24818 if (type_is_invalid(casted_op2->value->type))
24781 return ira->codegen->invalid_instruction;24819 return ira->codegen->invalid_instruction;
2478224820
24783 IrInstruction *op3 = instruction->op3->child;24821 IrInstruction *op3 = instruction->op3->child;
24784 if (type_is_invalid(op3->value.type))24822 if (type_is_invalid(op3->value->type))
24785 return ira->codegen->invalid_instruction;24823 return ira->codegen->invalid_instruction;
2478624824
24787 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);24825 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
24788 if (type_is_invalid(casted_op3->value.type))24826 if (type_is_invalid(casted_op3->value->type))
24789 return ira->codegen->invalid_instruction;24827 return ira->codegen->invalid_instruction;
2479024828
24791 if (instr_is_comptime(casted_op1) &&24829 if (instr_is_comptime(casted_op1) &&
24792 instr_is_comptime(casted_op2) &&24830 instr_is_comptime(casted_op2) &&
24793 instr_is_comptime(casted_op3)) {24831 instr_is_comptime(casted_op3)) {
24794 ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);24832 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
24795 if (!op1_const)24833 if (!op1_const)
24796 return ira->codegen->invalid_instruction;24834 return ira->codegen->invalid_instruction;
24797 ConstExprValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);24835 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
24798 if (!op2_const)24836 if (!op2_const)
24799 return ira->codegen->invalid_instruction;24837 return ira->codegen->invalid_instruction;
24800 ConstExprValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);24838 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
24801 if (!op3_const)24839 if (!op3_const)
24802 return ira->codegen->invalid_instruction;24840 return ira->codegen->invalid_instruction;
2480324841
24804 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);24842 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
24805 ConstExprValue *out_val = &result->value;24843 ZigValue *out_val = result->value;
2480624844
24807 if (expr_type->id == ZigTypeIdVector) {24845 if (expr_type->id == ZigTypeIdVector) {
24808 expand_undef_array(ira->codegen, op1_const);24846 expand_undef_array(ira->codegen, op1_const);
...@@ -24812,10 +24850,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24812,10 +24850,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24812 expand_undef_array(ira->codegen, out_val);24850 expand_undef_array(ira->codegen, out_val);
24813 size_t len = expr_type->data.vector.len;24851 size_t len = expr_type->data.vector.len;
24814 for (size_t i = 0; i < len; i += 1) {24852 for (size_t i = 0; i < len; i += 1) {
24815 ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];24853 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
24816 ConstExprValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i];24854 ZigValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i];
24817 ConstExprValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i];24855 ZigValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i];
24818 ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];24856 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
24819 assert(float_operand_op1->type == float_type);24857 assert(float_operand_op1->type == float_type);
24820 assert(float_operand_op2->type == float_type);24858 assert(float_operand_op2->type == float_type);
24821 assert(float_operand_op3->type == float_type);24859 assert(float_operand_op3->type == float_type);
...@@ -24835,13 +24873,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24835,13 +24873,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24835 IrInstruction *result = ir_build_mul_add(&ira->new_irb,24873 IrInstruction *result = ir_build_mul_add(&ira->new_irb,
24836 instruction->base.scope, instruction->base.source_node,24874 instruction->base.scope, instruction->base.source_node,
24837 type_value, casted_op1, casted_op2, casted_op3);24875 type_value, casted_op1, casted_op2, casted_op3);
24838 result->value.type = expr_type;24876 result->value->type = expr_type;
24839 return result;24877 return result;
24840}24878}
2484124879
24842static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {24880static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {
24843 IrInstruction *base_ptr = instruction->base_ptr->child;24881 IrInstruction *base_ptr = instruction->base_ptr->child;
24844 if (type_is_invalid(base_ptr->value.type))24882 if (type_is_invalid(base_ptr->value->type))
24845 return ira->codegen->invalid_instruction;24883 return ira->codegen->invalid_instruction;
2484624884
24847 IrInstruction *value;24885 IrInstruction *value;
...@@ -24851,12 +24889,12 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -24851,12 +24889,12 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
24851 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);24889 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);
24852 }24890 }
2485324891
24854 ZigType *type_entry = value->value.type;24892 ZigType *type_entry = value->value->type;
24855 if (type_is_invalid(type_entry))24893 if (type_is_invalid(type_entry))
24856 return ira->codegen->invalid_instruction;24894 return ira->codegen->invalid_instruction;
24857 if (type_entry->id == ZigTypeIdErrorUnion) {24895 if (type_entry->id == ZigTypeIdErrorUnion) {
24858 if (instr_is_comptime(value)) {24896 if (instr_is_comptime(value)) {
24859 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);24897 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
24860 if (!err_union_val)24898 if (!err_union_val)
24861 return ira->codegen->invalid_instruction;24899 return ira->codegen->invalid_instruction;
2486224900
...@@ -24890,7 +24928,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -24890,7 +24928,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
24890static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,24928static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
24891 IrInstruction *base_ptr, bool initializing)24929 IrInstruction *base_ptr, bool initializing)
24892{24930{
24893 ZigType *ptr_type = base_ptr->value.type;24931 ZigType *ptr_type = base_ptr->value->type;
2489424932
24895 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.24933 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
24896 assert(ptr_type->id == ZigTypeIdPointer);24934 assert(ptr_type->id == ZigTypeIdPointer);
...@@ -24911,20 +24949,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -24911,20 +24949,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
24911 ptr_type->data.pointer.explicit_alignment, 0, 0, false);24949 ptr_type->data.pointer.explicit_alignment, 0, 0, false);
2491224950
24913 if (instr_is_comptime(base_ptr)) {24951 if (instr_is_comptime(base_ptr)) {
24914 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);24952 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
24915 if (!ptr_val)24953 if (!ptr_val)
24916 return ira->codegen->invalid_instruction;24954 return ira->codegen->invalid_instruction;
24917 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&24955 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
24918 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)24956 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
24919 {24957 {
24920 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);24958 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
24921 if (err_union_val == nullptr)24959 if (err_union_val == nullptr)
24922 return ira->codegen->invalid_instruction;24960 return ira->codegen->invalid_instruction;
2492324961
24924 if (initializing && err_union_val->special == ConstValSpecialUndef) {24962 if (initializing && err_union_val->special == ConstValSpecialUndef) {
24925 ConstExprValue *vals = create_const_vals(2);24963 ZigValue *vals = create_const_vals(2);
24926 ConstExprValue *err_set_val = &vals[0];24964 ZigValue *err_set_val = &vals[0];
24927 ConstExprValue *payload_val = &vals[1];24965 ZigValue *payload_val = &vals[1];
2492824966
24929 err_set_val->special = ConstValSpecialUndef;24967 err_set_val->special = ConstValSpecialUndef;
24930 err_set_val->type = err_set_type;24968 err_set_val->type = err_set_type;
...@@ -24946,12 +24984,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -24946,12 +24984,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
24946 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {24984 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
24947 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,24985 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,
24948 source_instr->source_node, base_ptr);24986 source_instr->source_node, base_ptr);
24949 result->value.type = result_type;24987 result->value->type = result_type;
24950 result->value.special = ConstValSpecialStatic;24988 result->value->special = ConstValSpecialStatic;
24951 } else {24989 } else {
24952 result = ir_const(ira, source_instr, result_type);24990 result = ir_const(ira, source_instr, result_type);
24953 }24991 }
24954 ConstExprValue *const_val = &result->value;24992 ZigValue *const_val = result->value;
24955 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;24993 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;
24956 const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val;24994 const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val;
24957 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;24995 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
...@@ -24961,7 +24999,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -24961,7 +24999,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2496124999
24962 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,25000 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,
24963 source_instr->scope, source_instr->source_node, base_ptr);25001 source_instr->scope, source_instr->source_node, base_ptr);
24964 result->value.type = result_type;25002 result->value->type = result_type;
24965 return result;25003 return result;
24966}25004}
2496725005
...@@ -24969,7 +25007,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -24969,7 +25007,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
24969 IrInstructionUnwrapErrCode *instruction)25007 IrInstructionUnwrapErrCode *instruction)
24970{25008{
24971 IrInstruction *base_ptr = instruction->err_union_ptr->child;25009 IrInstruction *base_ptr = instruction->err_union_ptr->child;
24972 if (type_is_invalid(base_ptr->value.type))25010 if (type_is_invalid(base_ptr->value->type))
24973 return ira->codegen->invalid_instruction;25011 return ira->codegen->invalid_instruction;
24974 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);25012 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);
24975}25013}
...@@ -24977,7 +25015,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -24977,7 +25015,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
24977static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,25015static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
24978 IrInstruction *base_ptr, bool safety_check_on, bool initializing)25016 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
24979{25017{
24980 ZigType *ptr_type = base_ptr->value.type;25018 ZigType *ptr_type = base_ptr->value->type;
2498125019
24982 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.25020 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
24983 assert(ptr_type->id == ZigTypeIdPointer);25021 assert(ptr_type->id == ZigTypeIdPointer);
...@@ -25000,17 +25038,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -25000,17 +25038,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
25000 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,25038 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
25001 PtrLenSingle, 0, 0, 0, false);25039 PtrLenSingle, 0, 0, 0, false);
25002 if (instr_is_comptime(base_ptr)) {25040 if (instr_is_comptime(base_ptr)) {
25003 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);25041 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
25004 if (!ptr_val)25042 if (!ptr_val)
25005 return ira->codegen->invalid_instruction;25043 return ira->codegen->invalid_instruction;
25006 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {25044 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
25007 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);25045 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
25008 if (err_union_val == nullptr)25046 if (err_union_val == nullptr)
25009 return ira->codegen->invalid_instruction;25047 return ira->codegen->invalid_instruction;
25010 if (initializing && err_union_val->special == ConstValSpecialUndef) {25048 if (initializing && err_union_val->special == ConstValSpecialUndef) {
25011 ConstExprValue *vals = create_const_vals(2);25049 ZigValue *vals = create_const_vals(2);
25012 ConstExprValue *err_set_val = &vals[0];25050 ZigValue *err_set_val = &vals[0];
25013 ConstExprValue *payload_val = &vals[1];25051 ZigValue *payload_val = &vals[1];
2501425052
25015 err_set_val->special = ConstValSpecialStatic;25053 err_set_val->special = ConstValSpecialStatic;
25016 err_set_val->type = type_entry->data.error_union.err_set_type;25054 err_set_val->type = type_entry->data.error_union.err_set_type;
...@@ -25036,14 +25074,14 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -25036,14 +25074,14 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
25036 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {25074 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
25037 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,25075 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
25038 source_instr->source_node, base_ptr, safety_check_on, initializing);25076 source_instr->source_node, base_ptr, safety_check_on, initializing);
25039 result->value.type = result_type;25077 result->value->type = result_type;
25040 result->value.special = ConstValSpecialStatic;25078 result->value->special = ConstValSpecialStatic;
25041 } else {25079 } else {
25042 result = ir_const(ira, source_instr, result_type);25080 result = ir_const(ira, source_instr, result_type);
25043 }25081 }
25044 result->value.data.x_ptr.special = ConstPtrSpecialRef;25082 result->value->data.x_ptr.special = ConstPtrSpecialRef;
25045 result->value.data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;25083 result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;
25046 result->value.data.x_ptr.mut = ptr_val->data.x_ptr.mut;25084 result->value->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
25047 return result;25085 return result;
25048 }25086 }
25049 }25087 }
...@@ -25051,7 +25089,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -25051,7 +25089,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2505125089
25052 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,25090 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
25053 source_instr->source_node, base_ptr, safety_check_on, initializing);25091 source_instr->source_node, base_ptr, safety_check_on, initializing);
25054 result->value.type = result_type;25092 result->value->type = result_type;
25055 return result;25093 return result;
25056}25094}
2505725095
...@@ -25060,7 +25098,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -25060,7 +25098,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
25060{25098{
25061 assert(instruction->value->child);25099 assert(instruction->value->child);
25062 IrInstruction *value = instruction->value->child;25100 IrInstruction *value = instruction->value->child;
25063 if (type_is_invalid(value->value.type))25101 if (type_is_invalid(value->value->type))
25064 return ira->codegen->invalid_instruction;25102 return ira->codegen->invalid_instruction;
2506525103
25066 return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false);25104 return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false);
...@@ -25071,11 +25109,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -25071,11 +25109,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
25071 assert(proto_node->type == NodeTypeFnProto);25109 assert(proto_node->type == NodeTypeFnProto);
2507225110
25073 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);25111 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
25074 result->value.special = ConstValSpecialLazy;25112 result->value->special = ConstValSpecialLazy;
2507525113
25076 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1);25114 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1);
25077 lazy_fn_type->ira = ira;25115 lazy_fn_type->ira = ira;
25078 result->value.data.x_lazy = &lazy_fn_type->base;25116 result->value->data.x_lazy = &lazy_fn_type->base;
25079 lazy_fn_type->base.id = LazyValueIdFnType;25117 lazy_fn_type->base.id = LazyValueIdFnType;
2508025118
25081 if (proto_node->data.fn_proto.auto_err_set) {25119 if (proto_node->data.fn_proto.auto_err_set) {
...@@ -25110,7 +25148,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -25110,7 +25148,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
25110 }25148 }
2511125149
25112 IrInstruction *param_type_value = instruction->param_types[param_index]->child;25150 IrInstruction *param_type_value = instruction->param_types[param_index]->child;
25113 if (type_is_invalid(param_type_value->value.type))25151 if (type_is_invalid(param_type_value->value->type))
25114 return ira->codegen->invalid_instruction;25152 return ira->codegen->invalid_instruction;
25115 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)25153 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
25116 return ira->codegen->invalid_instruction;25154 return ira->codegen->invalid_instruction;
...@@ -25132,7 +25170,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -25132,7 +25170,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2513225170
25133static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {25171static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
25134 IrInstruction *value = instruction->value->child;25172 IrInstruction *value = instruction->value->child;
25135 if (type_is_invalid(value->value.type))25173 if (type_is_invalid(value->value->type))
25136 return ira->codegen->invalid_instruction;25174 return ira->codegen->invalid_instruction;
2513725175
25138 return ir_const_bool(ira, &instruction->base, instr_is_comptime(value));25176 return ir_const_bool(ira, &instruction->base, instr_is_comptime(value));
...@@ -25142,7 +25180,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25142,7 +25180,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25142 IrInstructionCheckSwitchProngs *instruction)25180 IrInstructionCheckSwitchProngs *instruction)
25143{25181{
25144 IrInstruction *target_value = instruction->target_value->child;25182 IrInstruction *target_value = instruction->target_value->child;
25145 ZigType *switch_type = target_value->value.type;25183 ZigType *switch_type = target_value->value->type;
25146 if (type_is_invalid(switch_type))25184 if (type_is_invalid(switch_type))
25147 return ira->codegen->invalid_instruction;25185 return ira->codegen->invalid_instruction;
2514825186
...@@ -25154,25 +25192,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25154,25 +25192,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25154 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];25192 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2515525193
25156 IrInstruction *start_value_uncasted = range->start->child;25194 IrInstruction *start_value_uncasted = range->start->child;
25157 if (type_is_invalid(start_value_uncasted->value.type))25195 if (type_is_invalid(start_value_uncasted->value->type))
25158 return ira->codegen->invalid_instruction;25196 return ira->codegen->invalid_instruction;
25159 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);25197 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
25160 if (type_is_invalid(start_value->value.type))25198 if (type_is_invalid(start_value->value->type))
25161 return ira->codegen->invalid_instruction;25199 return ira->codegen->invalid_instruction;
2516225200
25163 IrInstruction *end_value_uncasted = range->end->child;25201 IrInstruction *end_value_uncasted = range->end->child;
25164 if (type_is_invalid(end_value_uncasted->value.type))25202 if (type_is_invalid(end_value_uncasted->value->type))
25165 return ira->codegen->invalid_instruction;25203 return ira->codegen->invalid_instruction;
25166 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);25204 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
25167 if (type_is_invalid(end_value->value.type))25205 if (type_is_invalid(end_value->value->type))
25168 return ira->codegen->invalid_instruction;25206 return ira->codegen->invalid_instruction;
2516925207
25170 BigInt start_index;25208 BigInt start_index;
25171 bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);25209 bigint_init_bigint(&start_index, &start_value->value->data.x_enum_tag);
2517225210
25173 assert(end_value->value.type->id == ZigTypeIdEnum);25211 assert(end_value->value->type->id == ZigTypeIdEnum);
25174 BigInt end_index;25212 BigInt end_index;
25175 bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);25213 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2517625214
25177 BigInt field_index;25215 BigInt field_index;
25178 bigint_init_bigint(&field_index, &start_index);25216 bigint_init_bigint(&field_index, &start_index);
...@@ -25218,24 +25256,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25218,24 +25256,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25218 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];25256 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2521925257
25220 IrInstruction *start_value_uncasted = range->start->child;25258 IrInstruction *start_value_uncasted = range->start->child;
25221 if (type_is_invalid(start_value_uncasted->value.type))25259 if (type_is_invalid(start_value_uncasted->value->type))
25222 return ira->codegen->invalid_instruction;25260 return ira->codegen->invalid_instruction;
25223 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);25261 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
25224 if (type_is_invalid(start_value->value.type))25262 if (type_is_invalid(start_value->value->type))
25225 return ira->codegen->invalid_instruction;25263 return ira->codegen->invalid_instruction;
2522625264
25227 IrInstruction *end_value_uncasted = range->end->child;25265 IrInstruction *end_value_uncasted = range->end->child;
25228 if (type_is_invalid(end_value_uncasted->value.type))25266 if (type_is_invalid(end_value_uncasted->value->type))
25229 return ira->codegen->invalid_instruction;25267 return ira->codegen->invalid_instruction;
25230 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);25268 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
25231 if (type_is_invalid(end_value->value.type))25269 if (type_is_invalid(end_value->value->type))
25232 return ira->codegen->invalid_instruction;25270 return ira->codegen->invalid_instruction;
2523325271
25234 ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base);25272 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
25235 uint32_t start_index = start_value->value.data.x_err_set->value;25273 uint32_t start_index = start_value->value->data.x_err_set->value;
2523625274
25237 ir_assert(end_value->value.type->id == ZigTypeIdErrorSet, &instruction->base);25275 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
25238 uint32_t end_index = end_value->value.data.x_err_set->value;25276 uint32_t end_index = end_value->value->data.x_err_set->value;
2523925277
25240 if (start_index != end_index) {25278 if (start_index != end_index) {
25241 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));25279 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));
...@@ -25276,24 +25314,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25276,24 +25314,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25276 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];25314 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2527725315
25278 IrInstruction *start_value = range->start->child;25316 IrInstruction *start_value = range->start->child;
25279 if (type_is_invalid(start_value->value.type))25317 if (type_is_invalid(start_value->value->type))
25280 return ira->codegen->invalid_instruction;25318 return ira->codegen->invalid_instruction;
25281 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);25319 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
25282 if (type_is_invalid(casted_start_value->value.type))25320 if (type_is_invalid(casted_start_value->value->type))
25283 return ira->codegen->invalid_instruction;25321 return ira->codegen->invalid_instruction;
2528425322
25285 IrInstruction *end_value = range->end->child;25323 IrInstruction *end_value = range->end->child;
25286 if (type_is_invalid(end_value->value.type))25324 if (type_is_invalid(end_value->value->type))
25287 return ira->codegen->invalid_instruction;25325 return ira->codegen->invalid_instruction;
25288 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);25326 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
25289 if (type_is_invalid(casted_end_value->value.type))25327 if (type_is_invalid(casted_end_value->value->type))
25290 return ira->codegen->invalid_instruction;25328 return ira->codegen->invalid_instruction;
2529125329
25292 ConstExprValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);25330 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
25293 if (!start_val)25331 if (!start_val)
25294 return ira->codegen->invalid_instruction;25332 return ira->codegen->invalid_instruction;
2529525333
25296 ConstExprValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);25334 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
25297 if (!end_val)25335 if (!end_val)
25298 return ira->codegen->invalid_instruction;25336 return ira->codegen->invalid_instruction;
2529925337
...@@ -25326,10 +25364,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25326,10 +25364,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25326 IrInstruction *value = range->start->child;25364 IrInstruction *value = range->start->child;
2532725365
25328 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);25366 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);
25329 if (type_is_invalid(casted_value->value.type))25367 if (type_is_invalid(casted_value->value->type))
25330 return ira->codegen->invalid_instruction;25368 return ira->codegen->invalid_instruction;
2533125369
25332 ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);25370 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
25333 if (!const_expr_val)25371 if (!const_expr_val)
25334 return ira->codegen->invalid_instruction;25372 return ira->codegen->invalid_instruction;
2533525373
...@@ -25362,7 +25400,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *...@@ -25362,7 +25400,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *
25362 IrInstructionCheckStatementIsVoid *instruction)25400 IrInstructionCheckStatementIsVoid *instruction)
25363{25401{
25364 IrInstruction *statement_value = instruction->statement_value->child;25402 IrInstruction *statement_value = instruction->statement_value->child;
25365 ZigType *statement_type = statement_value->value.type;25403 ZigType *statement_type = statement_value->value->type;
25366 if (type_is_invalid(statement_type))25404 if (type_is_invalid(statement_type))
25367 return ira->codegen->invalid_instruction;25405 return ira->codegen->invalid_instruction;
2536825406
...@@ -25375,7 +25413,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *...@@ -25375,7 +25413,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *
2537525413
25376static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {25414static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
25377 IrInstruction *msg = instruction->msg->child;25415 IrInstruction *msg = instruction->msg->child;
25378 if (type_is_invalid(msg->value.type))25416 if (type_is_invalid(msg->value->type))
25379 return ir_unreach_error(ira);25417 return ir_unreach_error(ira);
2538025418
25381 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {25419 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
...@@ -25387,7 +25425,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction...@@ -25387,7 +25425,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction
25387 true, false, PtrLenUnknown, 0, 0, 0, false);25425 true, false, PtrLenUnknown, 0, 0, 0, false);
25388 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);25426 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
25389 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);25427 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
25390 if (type_is_invalid(casted_msg->value.type))25428 if (type_is_invalid(casted_msg->value->type))
25391 return ir_unreach_error(ira);25429 return ir_unreach_error(ira);
2539225430
25393 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,25431 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
...@@ -25398,7 +25436,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction...@@ -25398,7 +25436,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction
25398static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {25436static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
25399 Error err;25437 Error err;
2540025438
25401 ZigType *target_type = target->value.type;25439 ZigType *target_type = target->value->type;
25402 assert(!type_is_invalid(target_type));25440 assert(!type_is_invalid(target_type));
2540325441
25404 ZigType *result_type;25442 ZigType *result_type;
...@@ -25443,7 +25481,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -25443,7 +25481,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
25443 }25481 }
2544425482
25445 if (instr_is_comptime(target)) {25483 if (instr_is_comptime(target)) {
25446 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);25484 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
25447 if (!val)25485 if (!val)
25448 return ira->codegen->invalid_instruction;25486 return ira->codegen->invalid_instruction;
2544925487
...@@ -25457,8 +25495,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -25457,8 +25495,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
25457 }25495 }
2545825496
25459 IrInstruction *result = ir_const(ira, target, result_type);25497 IrInstruction *result = ir_const(ira, target, result_type);
25460 copy_const_val(&result->value, val, true);25498 copy_const_val(result->value, val, true);
25461 result->value.type = result_type;25499 result->value->type = result_type;
25462 return result;25500 return result;
25463 }25501 }
2546425502
...@@ -25468,7 +25506,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -25468,7 +25506,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
25468 } else {25506 } else {
25469 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);25507 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);
25470 }25508 }
25471 result->value.type = result_type;25509 result->value->type = result_type;
25472 return result;25510 return result;
25473}25511}
2547425512
...@@ -25477,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25477,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25477{25515{
25478 Error err;25516 Error err;
2547925517
25480 ZigType *src_type = ptr->value.type;25518 ZigType *src_type = ptr->value->type;
25481 assert(!type_is_invalid(src_type));25519 assert(!type_is_invalid(src_type));
2548225520
25483 if (src_type == dest_type) {25521 if (src_type == dest_type) {
...@@ -25515,7 +25553,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25515,7 +25553,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25515 if (instr_is_comptime(ptr)) {25553 if (instr_is_comptime(ptr)) {
25516 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);25554 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);
25517 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;25555 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
25518 ConstExprValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);25556 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
25519 if (!val)25557 if (!val)
25520 return ira->codegen->invalid_instruction;25558 return ira->codegen->invalid_instruction;
2552125559
...@@ -25531,7 +25569,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25531,7 +25569,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25531 }25569 }
2553225570
25533 IrInstruction *result;25571 IrInstruction *result;
25534 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {25572 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
25535 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);25573 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2553625574
25537 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))25575 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
...@@ -25539,8 +25577,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25539,8 +25577,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25539 } else {25577 } else {
25540 result = ir_const(ira, source_instr, dest_type);25578 result = ir_const(ira, source_instr, dest_type);
25541 }25579 }
25542 copy_const_val(&result->value, val, true);25580 copy_const_val(result->value, val, true);
25543 result->value.type = dest_type;25581 result->value->type = dest_type;
2554425582
25545 // Keep the bigger alignment, it can only help-25583 // Keep the bigger alignment, it can only help-
25546 // unless the target is zero bits.25584 // unless the target is zero bits.
...@@ -25584,7 +25622,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25584,7 +25622,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25584 IrInstruction *result;25622 IrInstruction *result;
25585 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {25623 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
25586 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);25624 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
25587 if (type_is_invalid(result->value.type))25625 if (type_is_invalid(result->value->type))
25588 return ira->codegen->invalid_instruction;25626 return ira->codegen->invalid_instruction;
25589 } else {25627 } else {
25590 result = casted_ptr;25628 result = casted_ptr;
...@@ -25599,7 +25637,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct...@@ -25599,7 +25637,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct
25599 return ira->codegen->invalid_instruction;25637 return ira->codegen->invalid_instruction;
2560025638
25601 IrInstruction *ptr = instruction->ptr->child;25639 IrInstruction *ptr = instruction->ptr->child;
25602 ZigType *src_type = ptr->value.type;25640 ZigType *src_type = ptr->value->type;
25603 if (type_is_invalid(src_type))25641 if (type_is_invalid(src_type))
25604 return ira->codegen->invalid_instruction;25642 return ira->codegen->invalid_instruction;
2560525643
...@@ -25607,18 +25645,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct...@@ -25607,18 +25645,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct
25607 instruction->safety_check_on);25645 instruction->safety_check_on);
25608}25646}
2560925647
25610static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ConstExprValue *val, size_t len) {25648static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {
25611 size_t buf_i = 0;25649 size_t buf_i = 0;
25612 // TODO optimize the buf case25650 // TODO optimize the buf case
25613 expand_undef_array(codegen, val);25651 expand_undef_array(codegen, val);
25614 for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) {25652 for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) {
25615 ConstExprValue *elem = &val->data.x_array.data.s_none.elements[elem_i];25653 ZigValue *elem = &val->data.x_array.data.s_none.elements[elem_i];
25616 buf_write_value_bytes(codegen, &buf[buf_i], elem);25654 buf_write_value_bytes(codegen, &buf[buf_i], elem);
25617 buf_i += type_size(codegen, elem->type);25655 buf_i += type_size(codegen, elem->type);
25618 }25656 }
25619}25657}
2562025658
25621static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {25659static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) {
25622 if (val->special == ConstValSpecialUndef) {25660 if (val->special == ConstValSpecialUndef) {
25623 expand_undef_struct(codegen, val);25661 expand_undef_struct(codegen, val);
25624 val->special = ConstValSpecialStatic;25662 val->special = ConstValSpecialStatic;
...@@ -25679,7 +25717,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25679,7 +25717,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25679 TypeStructField *struct_field = val->type->data.structure.fields[field_i];25717 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
25680 if (struct_field->gen_index == SIZE_MAX)25718 if (struct_field->gen_index == SIZE_MAX)
25681 continue;25719 continue;
25682 ConstExprValue *field_val = val->data.x_struct.fields[field_i];25720 ZigValue *field_val = val->data.x_struct.fields[field_i];
25683 size_t offset = struct_field->offset;25721 size_t offset = struct_field->offset;
25684 buf_write_value_bytes(codegen, buf + offset, field_val);25722 buf_write_value_bytes(codegen, buf + offset, field_val);
25685 }25723 }
...@@ -25754,7 +25792,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25754,7 +25792,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25754}25792}
2575525793
25756static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf,25794static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf,
25757 ConstExprValue *val, ZigType *elem_type, size_t len)25795 ZigValue *val, ZigType *elem_type, size_t len)
25758{25796{
25759 Error err;25797 Error err;
25760 uint64_t elem_size = type_size(codegen, elem_type);25798 uint64_t elem_size = type_size(codegen, elem_type);
...@@ -25763,7 +25801,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod...@@ -25763,7 +25801,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
25763 case ConstArraySpecialNone:25801 case ConstArraySpecialNone:
25764 val->data.x_array.data.s_none.elements = create_const_vals(len);25802 val->data.x_array.data.s_none.elements = create_const_vals(len);
25765 for (size_t i = 0; i < len; i++) {25803 for (size_t i = 0; i < len; i++) {
25766 ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i];25804 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];
25767 elem->special = ConstValSpecialStatic;25805 elem->special = ConstValSpecialStatic;
25768 elem->type = elem_type;25806 elem->type = elem_type;
25769 if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem)))25807 if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem)))
...@@ -25778,7 +25816,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod...@@ -25778,7 +25816,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
25778 zig_unreachable();25816 zig_unreachable();
25779}25817}
2578025818
25781static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) {25819static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val) {
25782 Error err;25820 Error err;
25783 src_assert(val->special == ConstValSpecialStatic, source_node);25821 src_assert(val->special == ConstValSpecialStatic, source_node);
25784 switch (val->type->id) {25822 switch (val->type->id) {
...@@ -25850,7 +25888,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25850,7 +25888,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25850 size_t src_field_count = val->type->data.structure.src_field_count;25888 size_t src_field_count = val->type->data.structure.src_field_count;
25851 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);25889 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
25852 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {25890 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
25853 ConstExprValue *field_val = val->data.x_struct.fields[field_i];25891 ZigValue *field_val = val->data.x_struct.fields[field_i];
25854 field_val->special = ConstValSpecialStatic;25892 field_val->special = ConstValSpecialStatic;
25855 TypeStructField *struct_field = val->type->data.structure.fields[field_i];25893 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
25856 field_val->type = struct_field->type_entry;25894 field_val->type = struct_field->type_entry;
...@@ -25887,7 +25925,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25887,7 +25925,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25887 src_assert(field->gen_index != SIZE_MAX, source_node);25925 src_assert(field->gen_index != SIZE_MAX, source_node);
25888 if (field->gen_index != gen_i)25926 if (field->gen_index != gen_i)
25889 break;25927 break;
25890 ConstExprValue *field_val = val->data.x_struct.fields[src_i];25928 ZigValue *field_val = val->data.x_struct.fields[src_i];
25891 field_val->special = ConstValSpecialStatic;25929 field_val->special = ConstValSpecialStatic;
25892 field_val->type = field->type_entry;25930 field_val->type = field->type_entry;
25893 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);25931 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);
...@@ -25941,7 +25979,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25941,7 +25979,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
25941{25979{
25942 Error err;25980 Error err;
2594325981
25944 ZigType *src_type = value->value.type;25982 ZigType *src_type = value->value->type;
25945 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);25983 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);
25946 ir_assert(type_can_bit_cast(src_type), source_instr);25984 ir_assert(type_can_bit_cast(src_type), source_instr);
25947 ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr);25985 ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr);
...@@ -25975,14 +26013,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25975,14 +26013,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
25975 }26013 }
2597626014
25977 if (instr_is_comptime(value)) {26015 if (instr_is_comptime(value)) {
25978 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);26016 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
25979 if (!val)26017 if (!val)
25980 return ira->codegen->invalid_instruction;26018 return ira->codegen->invalid_instruction;
2598126019
25982 IrInstruction *result = ir_const(ira, source_instr, dest_type);26020 IrInstruction *result = ir_const(ira, source_instr, dest_type);
25983 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);26021 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
25984 buf_write_value_bytes(ira->codegen, buf, val);26022 buf_write_value_bytes(ira->codegen, buf, val);
25985 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, &result->value)))26023 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
25986 return ira->codegen->invalid_instruction;26024 return ira->codegen->invalid_instruction;
25987 return result;26025 return result;
25988 }26026 }
...@@ -25997,11 +26035,11 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -25997,11 +26035,11 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
25997 ir_assert(type_has_bits(ptr_type), source_instr);26035 ir_assert(type_has_bits(ptr_type), source_instr);
2599826036
25999 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);26037 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
26000 if (type_is_invalid(casted_int->value.type))26038 if (type_is_invalid(casted_int->value->type))
26001 return ira->codegen->invalid_instruction;26039 return ira->codegen->invalid_instruction;
2600226040
26003 if (instr_is_comptime(casted_int)) {26041 if (instr_is_comptime(casted_int)) {
26004 ConstExprValue *val = ir_resolve_const(ira, casted_int, UndefBad);26042 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
26005 if (!val)26043 if (!val)
26006 return ira->codegen->invalid_instruction;26044 return ira->codegen->invalid_instruction;
2600726045
...@@ -26013,15 +26051,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -26013,15 +26051,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
26013 }26051 }
2601426052
26015 IrInstruction *result = ir_const(ira, source_instr, ptr_type);26053 IrInstruction *result = ir_const(ira, source_instr, ptr_type);
26016 result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;26054 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
26017 result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;26055 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
26018 result->value.data.x_ptr.data.hard_coded_addr.addr = addr;26056 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
26019 return result;26057 return result;
26020 }26058 }
2602126059
26022 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,26060 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,
26023 source_instr->source_node, nullptr, casted_int);26061 source_instr->source_node, nullptr, casted_int);
26024 result->value.type = ptr_type;26062 result->value->type = ptr_type;
26025 return result;26063 return result;
26026}26064}
2602726065
...@@ -26048,7 +26086,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru...@@ -26048,7 +26086,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru
2604826086
2604926087
26050 IrInstruction *target = instruction->target->child;26088 IrInstruction *target = instruction->target->child;
26051 if (type_is_invalid(target->value.type))26089 if (type_is_invalid(target->value->type))
26052 return ira->codegen->invalid_instruction;26090 return ira->codegen->invalid_instruction;
2605326091
26054 return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type);26092 return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type);
...@@ -26058,7 +26096,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -26058,7 +26096,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
26058 IrInstructionDeclRef *instruction)26096 IrInstructionDeclRef *instruction)
26059{26097{
26060 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);26098 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
26061 if (type_is_invalid(ref_instruction->value.type)) {26099 if (type_is_invalid(ref_instruction->value->type)) {
26062 return ira->codegen->invalid_instruction;26100 return ira->codegen->invalid_instruction;
26063 }26101 }
2606426102
...@@ -26072,51 +26110,51 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -26072,51 +26110,51 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
26072static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {26110static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
26073 Error err;26111 Error err;
26074 IrInstruction *target = instruction->target->child;26112 IrInstruction *target = instruction->target->child;
26075 if (type_is_invalid(target->value.type))26113 if (type_is_invalid(target->value->type))
26076 return ira->codegen->invalid_instruction;26114 return ira->codegen->invalid_instruction;
2607726115
26078 ZigType *usize = ira->codegen->builtin_types.entry_usize;26116 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2607926117
26080 // We check size explicitly so we can use get_src_ptr_type here.26118 // We check size explicitly so we can use get_src_ptr_type here.
26081 if (get_src_ptr_type(target->value.type) == nullptr) {26119 if (get_src_ptr_type(target->value->type) == nullptr) {
26082 ir_add_error(ira, target,26120 ir_add_error(ira, target,
26083 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));26121 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
26084 return ira->codegen->invalid_instruction;26122 return ira->codegen->invalid_instruction;
26085 }26123 }
2608626124
26087 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))26125 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
26088 return ira->codegen->invalid_instruction;26126 return ira->codegen->invalid_instruction;
26089 if (!type_has_bits(target->value.type)) {26127 if (!type_has_bits(target->value->type)) {
26090 ir_add_error(ira, target,26128 ir_add_error(ira, target,
26091 buf_sprintf("pointer to size 0 type has no address"));26129 buf_sprintf("pointer to size 0 type has no address"));
26092 return ira->codegen->invalid_instruction;26130 return ira->codegen->invalid_instruction;
26093 }26131 }
2609426132
26095 if (instr_is_comptime(target)) {26133 if (instr_is_comptime(target)) {
26096 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);26134 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
26097 if (!val)26135 if (!val)
26098 return ira->codegen->invalid_instruction;26136 return ira->codegen->invalid_instruction;
26099 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {26137 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
26100 IrInstruction *result = ir_const(ira, &instruction->base, usize);26138 IrInstruction *result = ir_const(ira, &instruction->base, usize);
26101 bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);26139 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
26102 result->value.type = usize;26140 result->value->type = usize;
26103 return result;26141 return result;
26104 }26142 }
26105 }26143 }
2610626144
26107 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,26145 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,
26108 instruction->base.source_node, target);26146 instruction->base.source_node, target);
26109 result->value.type = usize;26147 result->value->type = usize;
26110 return result;26148 return result;
26111}26149}
2611226150
26113static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {26151static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
26114 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);26152 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
26115 result->value.special = ConstValSpecialLazy;26153 result->value->special = ConstValSpecialLazy;
2611626154
26117 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1);26155 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1);
26118 lazy_ptr_type->ira = ira;26156 lazy_ptr_type->ira = ira;
26119 result->value.data.x_lazy = &lazy_ptr_type->base;26157 result->value->data.x_lazy = &lazy_ptr_type->base;
26120 lazy_ptr_type->base.id = LazyValueIdPtrType;26158 lazy_ptr_type->base.id = LazyValueIdPtrType;
2612126159
26122 if (instruction->sentinel != nullptr) {26160 if (instruction->sentinel != nullptr) {
...@@ -26147,15 +26185,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct...@@ -26147,15 +26185,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2614726185
26148static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {26186static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
26149 IrInstruction *target = instruction->target->child;26187 IrInstruction *target = instruction->target->child;
26150 if (type_is_invalid(target->value.type))26188 if (type_is_invalid(target->value->type))
26151 return ira->codegen->invalid_instruction;26189 return ira->codegen->invalid_instruction;
2615226190
26153 ZigType *elem_type = nullptr;26191 ZigType *elem_type = nullptr;
26154 if (is_slice(target->value.type)) {26192 if (is_slice(target->value->type)) {
26155 ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;26193 ZigType *slice_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
26156 elem_type = slice_ptr_type->data.pointer.child_type;26194 elem_type = slice_ptr_type->data.pointer.child_type;
26157 } else if (target->value.type->id == ZigTypeIdPointer) {26195 } else if (target->value->type->id == ZigTypeIdPointer) {
26158 elem_type = target->value.type->data.pointer.child_type;26196 elem_type = target->value->type->data.pointer.child_type;
26159 }26197 }
2616026198
26161 uint32_t align_bytes;26199 uint32_t align_bytes;
...@@ -26164,7 +26202,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru...@@ -26164,7 +26202,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
26164 return ira->codegen->invalid_instruction;26202 return ira->codegen->invalid_instruction;
2616526203
26166 IrInstruction *result = ir_align_cast(ira, target, align_bytes, true);26204 IrInstruction *result = ir_align_cast(ira, target, align_bytes, true);
26167 if (type_is_invalid(result->value.type))26205 if (type_is_invalid(result->value->type))
26168 return ira->codegen->invalid_instruction;26206 return ira->codegen->invalid_instruction;
2616926207
26170 return result;26208 return result;
...@@ -26350,13 +26388,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26350,13 +26388,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
26350 return ira->codegen->invalid_instruction;26388 return ira->codegen->invalid_instruction;
2635126389
26352 IrInstruction *ptr_inst = instruction->ptr->child;26390 IrInstruction *ptr_inst = instruction->ptr->child;
26353 if (type_is_invalid(ptr_inst->value.type))26391 if (type_is_invalid(ptr_inst->value->type))
26354 return ira->codegen->invalid_instruction;26392 return ira->codegen->invalid_instruction;
2635526393
26356 // TODO let this be volatile26394 // TODO let this be volatile
26357 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);26395 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
26358 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26396 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
26359 if (type_is_invalid(casted_ptr->value.type))26397 if (type_is_invalid(casted_ptr->value->type))
26360 return ira->codegen->invalid_instruction;26398 return ira->codegen->invalid_instruction;
2636126399
26362 AtomicRmwOp op;26400 AtomicRmwOp op;
...@@ -26375,11 +26413,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26375,11 +26413,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
26375 }26413 }
2637626414
26377 IrInstruction *operand = instruction->operand->child;26415 IrInstruction *operand = instruction->operand->child;
26378 if (type_is_invalid(operand->value.type))26416 if (type_is_invalid(operand->value->type))
26379 return ira->codegen->invalid_instruction;26417 return ira->codegen->invalid_instruction;
2638026418
26381 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);26419 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);
26382 if (type_is_invalid(casted_operand->value.type))26420 if (type_is_invalid(casted_operand->value->type))
26383 return ira->codegen->invalid_instruction;26421 return ira->codegen->invalid_instruction;
2638426422
26385 AtomicOrder ordering;26423 AtomicOrder ordering;
...@@ -26395,7 +26433,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26395,7 +26433,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
26395 }26433 }
26396 }26434 }
2639726435
26398 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)26436 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)
26399 {26437 {
26400 zig_panic("TODO compile-time execution of atomicRmw");26438 zig_panic("TODO compile-time execution of atomicRmw");
26401 }26439 }
...@@ -26403,7 +26441,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26403,7 +26441,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
26403 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,26441 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,
26404 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,26442 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,
26405 op, ordering);26443 op, ordering);
26406 result->value.type = operand_type;26444 result->value->type = operand_type;
26407 return result;26445 return result;
26408}26446}
2640926447
...@@ -26413,12 +26451,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr...@@ -26413,12 +26451,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
26413 return ira->codegen->invalid_instruction;26451 return ira->codegen->invalid_instruction;
2641426452
26415 IrInstruction *ptr_inst = instruction->ptr->child;26453 IrInstruction *ptr_inst = instruction->ptr->child;
26416 if (type_is_invalid(ptr_inst->value.type))26454 if (type_is_invalid(ptr_inst->value->type))
26417 return ira->codegen->invalid_instruction;26455 return ira->codegen->invalid_instruction;
2641826456
26419 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);26457 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
26420 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26458 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
26421 if (type_is_invalid(casted_ptr->value.type))26459 if (type_is_invalid(casted_ptr->value->type))
26422 return ira->codegen->invalid_instruction;26460 return ira->codegen->invalid_instruction;
2642326461
26424 AtomicOrder ordering;26462 AtomicOrder ordering;
...@@ -26438,13 +26476,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr...@@ -26438,13 +26476,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2643826476
26439 if (instr_is_comptime(casted_ptr)) {26477 if (instr_is_comptime(casted_ptr)) {
26440 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);26478 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);
26441 ir_assert(result->value.type != nullptr, &instruction->base);26479 ir_assert(result->value->type != nullptr, &instruction->base);
26442 return result;26480 return result;
26443 }26481 }
2644426482
26445 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,26483 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,
26446 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);26484 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
26447 result->value.type = operand_type;26485 result->value->type = operand_type;
26448 return result;26486 return result;
26449}26487}
2645026488
...@@ -26454,20 +26492,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst...@@ -26454,20 +26492,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
26454 return ira->codegen->invalid_instruction;26492 return ira->codegen->invalid_instruction;
2645526493
26456 IrInstruction *ptr_inst = instruction->ptr->child;26494 IrInstruction *ptr_inst = instruction->ptr->child;
26457 if (type_is_invalid(ptr_inst->value.type))26495 if (type_is_invalid(ptr_inst->value->type))
26458 return ira->codegen->invalid_instruction;26496 return ira->codegen->invalid_instruction;
2645926497
26460 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);26498 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
26461 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26499 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
26462 if (type_is_invalid(casted_ptr->value.type))26500 if (type_is_invalid(casted_ptr->value->type))
26463 return ira->codegen->invalid_instruction;26501 return ira->codegen->invalid_instruction;
2646426502
26465 IrInstruction *value = instruction->value->child;26503 IrInstruction *value = instruction->value->child;
26466 if (type_is_invalid(value->value.type))26504 if (type_is_invalid(value->value->type))
26467 return ira->codegen->invalid_instruction;26505 return ira->codegen->invalid_instruction;
2646826506
26469 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);26507 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);
26470 if (type_is_invalid(casted_value->value.type))26508 if (type_is_invalid(casted_value->value->type))
26471 return ira->codegen->invalid_instruction;26509 return ira->codegen->invalid_instruction;
2647226510
2647326511
...@@ -26488,25 +26526,25 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst...@@ -26488,25 +26526,25 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
2648826526
26489 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {26527 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
26490 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);26528 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
26491 result->value.type = ira->codegen->builtin_types.entry_void;26529 result->value->type = ira->codegen->builtin_types.entry_void;
26492 return result;26530 return result;
26493 }26531 }
2649426532
26495 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,26533 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,
26496 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);26534 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);
26497 result->value.type = ira->codegen->builtin_types.entry_void;26535 result->value->type = ira->codegen->builtin_types.entry_void;
26498 return result;26536 return result;
26499}26537}
2650026538
26501static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {26539static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
26502 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,26540 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
26503 instruction->base.source_node);26541 instruction->base.source_node);
26504 result->value.type = ira->codegen->builtin_types.entry_void;26542 result->value->type = ira->codegen->builtin_types.entry_void;
26505 return result;26543 return result;
26506}26544}
2650726545
26508static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type,26546static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type,
26509 ConstExprValue *op, ConstExprValue *out_val) {26547 ZigValue *op, ZigValue *out_val) {
26510 assert(ira && source_instr && float_type && out_val && op);26548 assert(ira && source_instr && float_type && out_val && op);
26511 assert(float_type->id == ZigTypeIdFloat ||26549 assert(float_type->id == ZigTypeIdFloat ||
26512 float_type->id == ZigTypeIdComptimeFloat);26550 float_type->id == ZigTypeIdComptimeFloat);
...@@ -26687,7 +26725,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr,...@@ -26687,7 +26725,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr,
2668726725
26688static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {26726static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {
26689 IrInstruction *type = instruction->type->child;26727 IrInstruction *type = instruction->type->child;
26690 if (type_is_invalid(type->value.type))26728 if (type_is_invalid(type->value->type))
26691 return ira->codegen->invalid_instruction;26729 return ira->codegen->invalid_instruction;
2669226730
26693 ZigType *expr_type = ir_resolve_type(ira, type);26731 ZigType *expr_type = ir_resolve_type(ira, type);
...@@ -26702,11 +26740,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26702,11 +26740,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26702 }26740 }
2670326741
26704 IrInstruction *op1 = instruction->op1->child;26742 IrInstruction *op1 = instruction->op1->child;
26705 if (type_is_invalid(op1->value.type))26743 if (type_is_invalid(op1->value->type))
26706 return ira->codegen->invalid_instruction;26744 return ira->codegen->invalid_instruction;
2670726745
26708 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type);26746 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type);
26709 if (type_is_invalid(casted_op1->value.type))26747 if (type_is_invalid(casted_op1->value->type))
26710 return ira->codegen->invalid_instruction;26748 return ira->codegen->invalid_instruction;
2671126749
26712 if (instr_is_comptime(casted_op1)) {26750 if (instr_is_comptime(casted_op1)) {
...@@ -26719,12 +26757,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26719,12 +26757,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26719 return ira->codegen->invalid_instruction;26757 return ira->codegen->invalid_instruction;
26720 }26758 }
2672126759
26722 ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);26760 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
26723 if (!op1_const)26761 if (!op1_const)
26724 return ira->codegen->invalid_instruction;26762 return ira->codegen->invalid_instruction;
2672526763
26726 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);26764 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
26727 ConstExprValue *out_val = &result->value;26765 ZigValue *out_val = result->value;
2672826766
26729 if (expr_type->id == ZigTypeIdVector) {26767 if (expr_type->id == ZigTypeIdVector) {
26730 expand_undef_array(ira->codegen, op1_const);26768 expand_undef_array(ira->codegen, op1_const);
...@@ -26732,8 +26770,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26732,8 +26770,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26732 expand_undef_array(ira->codegen, out_val);26770 expand_undef_array(ira->codegen, out_val);
26733 size_t len = expr_type->data.vector.len;26771 size_t len = expr_type->data.vector.len;
26734 for (size_t i = 0; i < len; i += 1) {26772 for (size_t i = 0; i < len; i += 1) {
26735 ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];26773 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
26736 ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];26774 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
26737 assert(float_operand_op1->type == float_type);26775 assert(float_operand_op1->type == float_type);
26738 assert(float_out_val->type == float_type);26776 assert(float_out_val->type == float_type);
26739 ir_eval_float_op(ira, instruction, float_type,26777 ir_eval_float_op(ira, instruction, float_type,
...@@ -26752,7 +26790,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26752,7 +26790,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2675226790
26753 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,26791 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,
26754 instruction->base.source_node, nullptr, casted_op1, instruction->op);26792 instruction->base.source_node, nullptr, casted_op1, instruction->op);
26755 result->value.type = expr_type;26793 result->value->type = expr_type;
26756 return result;26794 return result;
26757}26795}
2675826796
...@@ -26764,16 +26802,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26764,16 +26802,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26764 return ira->codegen->invalid_instruction;26802 return ira->codegen->invalid_instruction;
2676526803
26766 IrInstruction *uncasted_op = instruction->op->child;26804 IrInstruction *uncasted_op = instruction->op->child;
26767 if (type_is_invalid(uncasted_op->value.type))26805 if (type_is_invalid(uncasted_op->value->type))
26768 return ira->codegen->invalid_instruction;26806 return ira->codegen->invalid_instruction;
2676926807
26770 uint32_t vector_len; // UINT32_MAX means not a vector26808 uint32_t vector_len; // UINT32_MAX means not a vector
26771 if (uncasted_op->value.type->id == ZigTypeIdArray &&26809 if (uncasted_op->value->type->id == ZigTypeIdArray &&
26772 is_valid_vector_elem_type(uncasted_op->value.type->data.array.child_type))26810 is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type))
26773 {26811 {
26774 vector_len = uncasted_op->value.type->data.array.len;26812 vector_len = uncasted_op->value->type->data.array.len;
26775 } else if (uncasted_op->value.type->id == ZigTypeIdVector) {26813 } else if (uncasted_op->value->type->id == ZigTypeIdVector) {
26776 vector_len = uncasted_op->value.type->data.vector.len;26814 vector_len = uncasted_op->value->type->data.vector.len;
26777 } else {26815 } else {
26778 vector_len = UINT32_MAX;26816 vector_len = UINT32_MAX;
26779 }26817 }
...@@ -26782,7 +26820,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26782,7 +26820,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26782 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;26820 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2678326821
26784 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);26822 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);
26785 if (type_is_invalid(op->value.type))26823 if (type_is_invalid(op->value->type))
26786 return ira->codegen->invalid_instruction;26824 return ira->codegen->invalid_instruction;
2678726825
26788 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)26826 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)
...@@ -26796,7 +26834,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26796,7 +26834,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26796 }26834 }
2679726835
26798 if (instr_is_comptime(op)) {26836 if (instr_is_comptime(op)) {
26799 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);26837 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
26800 if (val == nullptr)26838 if (val == nullptr)
26801 return ira->codegen->invalid_instruction;26839 return ira->codegen->invalid_instruction;
26802 if (val->special == ConstValSpecialUndef)26840 if (val->special == ConstValSpecialUndef)
...@@ -26807,28 +26845,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26807,28 +26845,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26807 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);26845 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
26808 if (is_vector) {26846 if (is_vector) {
26809 expand_undef_array(ira->codegen, val);26847 expand_undef_array(ira->codegen, val);
26810 result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);26848 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
26811 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {26849 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
26812 ConstExprValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];26850 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
26813 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,26851 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
26814 op_elem_val, UndefOk)))26852 op_elem_val, UndefOk)))
26815 {26853 {
26816 return ira->codegen->invalid_instruction;26854 return ira->codegen->invalid_instruction;
26817 }26855 }
26818 ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];26856 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
26819 result_elem_val->type = int_type;26857 result_elem_val->type = int_type;
26820 result_elem_val->special = op_elem_val->special;26858 result_elem_val->special = op_elem_val->special;
26821 if (op_elem_val->special == ConstValSpecialUndef)26859 if (op_elem_val->special == ConstValSpecialUndef)
26822 continue;26860 continue;
2682326861
26824 bigint_write_twos_complement(&op_elem_val->data.x_bigint, buf, int_type->data.integral.bit_count, true);26862 bigint_write_twos_complement(&op_elem_val->data.x_bigint, buf, int_type->data.integral.bit_count, true);
26825 bigint_read_twos_complement(&result->value.data.x_array.data.s_none.elements[i].data.x_bigint,26863 bigint_read_twos_complement(&result->value->data.x_array.data.s_none.elements[i].data.x_bigint,
26826 buf, int_type->data.integral.bit_count, false,26864 buf, int_type->data.integral.bit_count, false,
26827 int_type->data.integral.is_signed);26865 int_type->data.integral.is_signed);
26828 }26866 }
26829 } else {26867 } else {
26830 bigint_write_twos_complement(&val->data.x_bigint, buf, int_type->data.integral.bit_count, true);26868 bigint_write_twos_complement(&val->data.x_bigint, buf, int_type->data.integral.bit_count, true);
26831 bigint_read_twos_complement(&result->value.data.x_bigint, buf, int_type->data.integral.bit_count, false,26869 bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false,
26832 int_type->data.integral.is_signed);26870 int_type->data.integral.is_signed);
26833 }26871 }
26834 free(buf);26872 free(buf);
...@@ -26837,7 +26875,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26837,7 +26875,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2683726875
26838 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,26876 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,
26839 instruction->base.source_node, nullptr, op);26877 instruction->base.source_node, nullptr, op);
26840 result->value.type = op_type;26878 result->value->type = op_type;
26841 return result;26879 return result;
26842}26880}
2684326881
...@@ -26847,17 +26885,17 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -26847,17 +26885,17 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
26847 return ira->codegen->invalid_instruction;26885 return ira->codegen->invalid_instruction;
2684826886
26849 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);26887 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
26850 if (type_is_invalid(op->value.type))26888 if (type_is_invalid(op->value->type))
26851 return ira->codegen->invalid_instruction;26889 return ira->codegen->invalid_instruction;
2685226890
26853 if (int_type->data.integral.bit_count == 0) {26891 if (int_type->data.integral.bit_count == 0) {
26854 IrInstruction *result = ir_const(ira, &instruction->base, int_type);26892 IrInstruction *result = ir_const(ira, &instruction->base, int_type);
26855 bigint_init_unsigned(&result->value.data.x_bigint, 0);26893 bigint_init_unsigned(&result->value->data.x_bigint, 0);
26856 return result;26894 return result;
26857 }26895 }
2685826896
26859 if (instr_is_comptime(op)) {26897 if (instr_is_comptime(op)) {
26860 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);26898 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
26861 if (val == nullptr)26899 if (val == nullptr)
26862 return ira->codegen->invalid_instruction;26900 return ira->codegen->invalid_instruction;
26863 if (val->special == ConstValSpecialUndef)26901 if (val->special == ConstValSpecialUndef)
...@@ -26881,7 +26919,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -26881,7 +26919,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
26881 }26919 }
26882 }26920 }
2688326921
26884 bigint_read_twos_complement(&result->value.data.x_bigint,26922 bigint_read_twos_complement(&result->value->data.x_bigint,
26885 result_buf,26923 result_buf,
26886 int_type->data.integral.bit_count,26924 int_type->data.integral.bit_count,
26887 ira->codegen->is_big_endian,26925 ira->codegen->is_big_endian,
...@@ -26892,14 +26930,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -26892,14 +26930,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2689226930
26893 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,26931 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,
26894 instruction->base.source_node, nullptr, op);26932 instruction->base.source_node, nullptr, op);
26895 result->value.type = int_type;26933 result->value->type = int_type;
26896 return result;26934 return result;
26897}26935}
2689826936
2689926937
26900static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {26938static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
26901 IrInstruction *target = instruction->target->child;26939 IrInstruction *target = instruction->target->child;
26902 if (type_is_invalid(target->value.type))26940 if (type_is_invalid(target->value->type))
26903 return ira->codegen->invalid_instruction;26941 return ira->codegen->invalid_instruction;
2690426942
26905 return ir_analyze_enum_to_int(ira, &instruction->base, target);26943 return ir_analyze_enum_to_int(ira, &instruction->base, target);
...@@ -26924,11 +26962,11 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr...@@ -26924,11 +26962,11 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr
26924 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;26962 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2692526963
26926 IrInstruction *target = instruction->target->child;26964 IrInstruction *target = instruction->target->child;
26927 if (type_is_invalid(target->value.type))26965 if (type_is_invalid(target->value->type))
26928 return ira->codegen->invalid_instruction;26966 return ira->codegen->invalid_instruction;
2692926967
26930 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);26968 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);
26931 if (type_is_invalid(casted_target->value.type))26969 if (type_is_invalid(casted_target->value->type))
26932 return ira->codegen->invalid_instruction;26970 return ira->codegen->invalid_instruction;
2693326971
26934 return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);26972 return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);
...@@ -26995,33 +27033,33 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir...@@ -26995,33 +27033,33 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir
2699527033
26996static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {27034static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {
26997 IrInstruction *value = instruction->value->child;27035 IrInstruction *value = instruction->value->child;
26998 if (type_is_invalid(value->value.type))27036 if (type_is_invalid(value->value->type))
26999 return ira->codegen->invalid_instruction;27037 return ira->codegen->invalid_instruction;
2700027038
27001 bool was_written = instruction->result_loc->written;27039 bool was_written = instruction->result_loc->written;
27002 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,27040 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
27003 value->value.type, value, false, false, true);27041 value->value->type, value, false, false, true);
27004 if (result_loc != nullptr) {27042 if (result_loc != nullptr) {
27005 if (type_is_invalid(result_loc->value.type))27043 if (type_is_invalid(result_loc->value->type))
27006 return ira->codegen->invalid_instruction;27044 return ira->codegen->invalid_instruction;
27007 if (result_loc->value.type->id == ZigTypeIdUnreachable)27045 if (result_loc->value->type->id == ZigTypeIdUnreachable)
27008 return result_loc;27046 return result_loc;
2700927047
27010 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {27048 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
27011 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,27049 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,
27012 instruction->result_loc->allow_write_through_const);27050 instruction->result_loc->allow_write_through_const);
27013 if (type_is_invalid(store_ptr->value.type)) {27051 if (type_is_invalid(store_ptr->value->type)) {
27014 return ira->codegen->invalid_instruction;27052 return ira->codegen->invalid_instruction;
27015 }27053 }
27016 }27054 }
2701727055
27018 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer &&27056 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer &&
27019 instruction->result_loc->id != ResultLocIdPeer)27057 instruction->result_loc->id != ResultLocIdPeer)
27020 {27058 {
27021 if (instr_is_comptime(value)) {27059 if (instr_is_comptime(value)) {
27022 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;27060 result_loc->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
27023 } else {27061 } else {
27024 result_loc->value.special = ConstValSpecialRuntime;27062 result_loc->value->special = ConstValSpecialRuntime;
27025 }27063 }
27026 }27064 }
27027 }27065 }
...@@ -27031,12 +27069,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -27031,12 +27069,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2703127069
27032static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {27070static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
27033 IrInstruction *operand = instruction->operand->child;27071 IrInstruction *operand = instruction->operand->child;
27034 if (type_is_invalid(operand->value.type))27072 if (type_is_invalid(operand->value->type))
27035 return operand;27073 return operand;
2703627074
27037 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,27075 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
27038 &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true);27076 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);
27039 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))27077 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
27040 return result_loc;27078 return result_loc;
2704127079
27042 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {27080 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
...@@ -27051,12 +27089,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns...@@ -27051,12 +27089,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
2705127089
27052static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {27090static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
27053 IrInstruction *operand = instruction->operand->child;27091 IrInstruction *operand = instruction->operand->child;
27054 if (type_is_invalid(operand->value.type))27092 if (type_is_invalid(operand->value->type))
27055 return operand;27093 return operand;
2705627094
27057 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,27095 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
27058 &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false, true);27096 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);
27059 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))27097 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
27060 return result_loc;27098 return result_loc;
2706127099
27062 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {27100 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {
...@@ -27084,11 +27122,11 @@ static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *i...@@ -27084,11 +27122,11 @@ static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *i
27084 return ira->codegen->invalid_instruction;27122 return ira->codegen->invalid_instruction;
2708527123
27086 IrInstruction *field_result_loc = instruction->field_result_loc->child;27124 IrInstruction *field_result_loc = instruction->field_result_loc->child;
27087 if (type_is_invalid(field_result_loc->value.type))27125 if (type_is_invalid(field_result_loc->value->type))
27088 return ira->codegen->invalid_instruction;27126 return ira->codegen->invalid_instruction;
2708927127
27090 IrInstruction *result_loc = instruction->result_loc->child;27128 IrInstruction *result_loc = instruction->result_loc->child;
27091 if (type_is_invalid(result_loc->value.type))27129 if (type_is_invalid(result_loc->value->type))
27092 return ira->codegen->invalid_instruction;27130 return ira->codegen->invalid_instruction;
2709327131
27094 return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node,27132 return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node,
...@@ -27105,7 +27143,7 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,...@@ -27105,7 +27143,7 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
27105 IrInstructionSuspendFinish *instruction)27143 IrInstructionSuspendFinish *instruction)
27106{27144{
27107 IrInstruction *begin_base = instruction->begin->base.child;27145 IrInstruction *begin_base = instruction->begin->base.child;
27108 if (type_is_invalid(begin_base->value.type))27146 if (type_is_invalid(begin_base->value->type))
27109 return ira->codegen->invalid_instruction;27147 return ira->codegen->invalid_instruction;
27110 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);27148 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);
27111 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);27149 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);
...@@ -27123,44 +27161,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,...@@ -27123,44 +27161,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
27123static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,27161static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,
27124 IrInstruction *frame_ptr, ZigFn **target_fn)27162 IrInstruction *frame_ptr, ZigFn **target_fn)
27125{27163{
27126 if (type_is_invalid(frame_ptr->value.type))27164 if (type_is_invalid(frame_ptr->value->type))
27127 return ira->codegen->invalid_instruction;27165 return ira->codegen->invalid_instruction;
2712827166
27129 *target_fn = nullptr;27167 *target_fn = nullptr;
2713027168
27131 ZigType *result_type;27169 ZigType *result_type;
27132 IrInstruction *frame;27170 IrInstruction *frame;
27133 if (frame_ptr->value.type->id == ZigTypeIdPointer &&27171 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
27134 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&27172 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
27135 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)27173 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27136 {27174 {
27137 ZigFn *func = frame_ptr->value.type->data.pointer.child_type->data.frame.fn;27175 ZigFn *func = frame_ptr->value->type->data.pointer.child_type->data.frame.fn;
27138 result_type = func->type_entry->data.fn.fn_type_id.return_type;27176 result_type = func->type_entry->data.fn.fn_type_id.return_type;
27139 *target_fn = func;27177 *target_fn = func;
27140 frame = frame_ptr;27178 frame = frame_ptr;
27141 } else {27179 } else {
27142 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);27180 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);
27143 if (frame->value.type->id == ZigTypeIdPointer &&27181 if (frame->value->type->id == ZigTypeIdPointer &&
27144 frame->value.type->data.pointer.ptr_len == PtrLenSingle &&27182 frame->value->type->data.pointer.ptr_len == PtrLenSingle &&
27145 frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)27183 frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27146 {27184 {
27147 ZigFn *func = frame->value.type->data.pointer.child_type->data.frame.fn;27185 ZigFn *func = frame->value->type->data.pointer.child_type->data.frame.fn;
27148 result_type = func->type_entry->data.fn.fn_type_id.return_type;27186 result_type = func->type_entry->data.fn.fn_type_id.return_type;
27149 *target_fn = func;27187 *target_fn = func;
27150 } else if (frame->value.type->id != ZigTypeIdAnyFrame ||27188 } else if (frame->value->type->id != ZigTypeIdAnyFrame ||
27151 frame->value.type->data.any_frame.result_type == nullptr)27189 frame->value->type->data.any_frame.result_type == nullptr)
27152 {27190 {
27153 ir_add_error(ira, source_instr,27191 ir_add_error(ira, source_instr,
27154 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value.type->name)));27192 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
27155 return ira->codegen->invalid_instruction;27193 return ira->codegen->invalid_instruction;
27156 } else {27194 } else {
27157 result_type = frame->value.type->data.any_frame.result_type;27195 result_type = frame->value->type->data.any_frame.result_type;
27158 }27196 }
27159 }27197 }
2716027198
27161 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);27199 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
27162 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);27200 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
27163 if (type_is_invalid(casted_frame->value.type))27201 if (type_is_invalid(casted_frame->value->type))
27164 return ira->codegen->invalid_instruction;27202 return ira->codegen->invalid_instruction;
2716527203
27166 return casted_frame;27204 return casted_frame;
...@@ -27168,14 +27206,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct...@@ -27168,14 +27206,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2716827206
27169static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {27207static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {
27170 IrInstruction *operand = instruction->frame->child;27208 IrInstruction *operand = instruction->frame->child;
27171 if (type_is_invalid(operand->value.type))27209 if (type_is_invalid(operand->value->type))
27172 return ira->codegen->invalid_instruction;27210 return ira->codegen->invalid_instruction;
27173 ZigFn *target_fn;27211 ZigFn *target_fn;
27174 IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn);27212 IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn);
27175 if (type_is_invalid(frame->value.type))27213 if (type_is_invalid(frame->value->type))
27176 return ira->codegen->invalid_instruction;27214 return ira->codegen->invalid_instruction;
2717727215
27178 ZigType *result_type = frame->value.type->data.any_frame.result_type;27216 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2717927217
27180 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);27218 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
27181 ir_assert(fn_entry != nullptr, &instruction->base);27219 ir_assert(fn_entry != nullptr, &instruction->base);
...@@ -27195,7 +27233,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction...@@ -27195,7 +27233,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
27195 if (type_has_bits(result_type)) {27233 if (type_has_bits(result_type)) {
27196 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,27234 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
27197 result_type, nullptr, true, true, true);27235 result_type, nullptr, true, true, true);
27198 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))27236 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
27199 return result_loc;27237 return result_loc;
27200 } else {27238 } else {
27201 result_loc = nullptr;27239 result_loc = nullptr;
...@@ -27209,13 +27247,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction...@@ -27209,13 +27247,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2720927247
27210static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {27248static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {
27211 IrInstruction *frame_ptr = instruction->frame->child;27249 IrInstruction *frame_ptr = instruction->frame->child;
27212 if (type_is_invalid(frame_ptr->value.type))27250 if (type_is_invalid(frame_ptr->value->type))
27213 return ira->codegen->invalid_instruction;27251 return ira->codegen->invalid_instruction;
2721427252
27215 IrInstruction *frame;27253 IrInstruction *frame;
27216 if (frame_ptr->value.type->id == ZigTypeIdPointer &&27254 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
27217 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&27255 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
27218 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)27256 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27219 {27257 {
27220 frame = frame_ptr;27258 frame = frame_ptr;
27221 } else {27259 } else {
...@@ -27224,7 +27262,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio...@@ -27224,7 +27262,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio
2722427262
27225 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);27263 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
27226 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);27264 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
27227 if (type_is_invalid(casted_frame->value.type))27265 if (type_is_invalid(casted_frame->value->type))
27228 return ira->codegen->invalid_instruction;27266 return ira->codegen->invalid_instruction;
2722927267
27230 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);27268 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);
...@@ -27235,10 +27273,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr...@@ -27235,10 +27273,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr
27235 return ir_const_void(ira, &instruction->base);27273 return ir_const_void(ira, &instruction->base);
2723627274
27237 IrInstruction *operand = instruction->operand->child;27275 IrInstruction *operand = instruction->operand->child;
27238 if (type_is_invalid(operand->value.type))27276 if (type_is_invalid(operand->value->type))
27239 return ira->codegen->invalid_instruction;27277 return ira->codegen->invalid_instruction;
2724027278
27241 if (!type_has_bits(operand->value.type))27279 if (!type_has_bits(operand->value->type))
27242 return ir_const_void(ira, &instruction->base);27280 return ir_const_void(ira, &instruction->base);
2724327281
27244 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);27282 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);
...@@ -27251,10 +27289,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr...@@ -27251,10 +27289,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr
2725127289
27252static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {27290static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {
27253 IrInstruction *operand = instruction->begin->operand->child;27291 IrInstruction *operand = instruction->begin->operand->child;
27254 if (type_is_invalid(operand->value.type))27292 if (type_is_invalid(operand->value->type))
27255 return ira->codegen->invalid_instruction;27293 return ira->codegen->invalid_instruction;
2725627294
27257 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value.type))27295 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type))
27258 return operand;27296 return operand;
2725927297
27260 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);27298 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);
...@@ -27262,7 +27300,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc...@@ -27262,7 +27300,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc
2726227300
27263 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,27301 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,
27264 instruction->base.source_node, begin);27302 instruction->base.source_node, begin);
27265 result->value.type = operand->value.type;27303 result->value->type = operand->value->type;
27266 return result;27304 return result;
27267}27305}
2726827306
...@@ -27601,7 +27639,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -27601,7 +27639,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
27601 ira->new_irb.codegen = codegen;27639 ira->new_irb.codegen = codegen;
27602 ira->new_irb.exec = new_exec;27640 ira->new_irb.exec = new_exec;
2760327641
27604 ConstExprValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count);27642 ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count);
27605 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);27643 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);
27606 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {27644 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {
27607 ira->exec_context.mem_slot_list.items[i] = &vals[i];27645 ira->exec_context.mem_slot_list.items[i] = &vals[i];
...@@ -27628,10 +27666,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -27628,10 +27666,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
27628 }27666 }
27629 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);27667 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
27630 if (new_instruction != nullptr) {27668 if (new_instruction != nullptr) {
27631 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);27669 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction);
27632 old_instruction->child = new_instruction;27670 old_instruction->child = new_instruction;
2763327671
27634 if (type_is_invalid(new_instruction->value.type)) {27672 if (type_is_invalid(new_instruction->value->type)) {
27635 if (new_exec->first_err_trace_msg != nullptr) {27673 if (new_exec->first_err_trace_msg != nullptr) {
27636 ira->codegen->trace_err = new_exec->first_err_trace_msg;27674 ira->codegen->trace_err = new_exec->first_err_trace_msg;
27637 } else {27675 } else {
...@@ -27648,7 +27686,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -27648,7 +27686,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
27648 }27686 }
2764927687
27650 // unreachable instructions do their own control flow.27688 // unreachable instructions do their own control flow.
27651 if (new_instruction->value.type->id == ZigTypeIdUnreachable)27689 if (new_instruction->value->type->id == ZigTypeIdUnreachable)
27652 continue;27690 continue;
27653 }27691 }
2765427692
...@@ -27947,7 +27985,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -27947,7 +27985,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
27947 return get_fn_type(ira->codegen, &fn_type_id);27985 return get_fn_type(ira->codegen, &fn_type_id);
27948}27986}
2794927987
27950static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {27988static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
27951 Error err;27989 Error err;
27952 if (val->special != ConstValSpecialLazy)27990 if (val->special != ConstValSpecialLazy)
27953 return ErrorNone;27991 return ErrorNone;
...@@ -27958,8 +27996,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -27958,8 +27996,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
27958 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);27996 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
27959 IrAnalyze *ira = lazy_align_of->ira;27997 IrAnalyze *ira = lazy_align_of->ira;
2796027998
27961 if (lazy_align_of->target_type->value.special == ConstValSpecialStatic) {27999 if (lazy_align_of->target_type->value->special == ConstValSpecialStatic) {
27962 switch (lazy_align_of->target_type->value.data.x_type->id) {28000 switch (lazy_align_of->target_type->value->data.x_type->id) {
27963 case ZigTypeIdInvalid:28001 case ZigTypeIdInvalid:
27964 zig_unreachable();28002 zig_unreachable();
27965 case ZigTypeIdMetaType:28003 case ZigTypeIdMetaType:
...@@ -27975,7 +28013,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -27975,7 +28013,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
27975 case ZigTypeIdOpaque:28013 case ZigTypeIdOpaque:
27976 ir_add_error(ira, lazy_align_of->target_type,28014 ir_add_error(ira, lazy_align_of->target_type,
27977 buf_sprintf("no align available for type '%s'",28015 buf_sprintf("no align available for type '%s'",
27978 buf_ptr(&lazy_align_of->target_type->value.data.x_type->name)));28016 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
27979 return ErrorSemanticAnalyzeFail;28017 return ErrorSemanticAnalyzeFail;
27980 case ZigTypeIdBool:28018 case ZigTypeIdBool:
27981 case ZigTypeIdInt:28019 case ZigTypeIdInt:
...@@ -27997,7 +28035,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -27997,7 +28035,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
27997 }28035 }
2799828036
27999 uint32_t align_in_bytes;28037 uint32_t align_in_bytes;
28000 if ((err = type_val_resolve_abi_align(ira->codegen, &lazy_align_of->target_type->value,28038 if ((err = type_val_resolve_abi_align(ira->codegen, lazy_align_of->target_type->value,
28001 &align_in_bytes)))28039 &align_in_bytes)))
28002 {28040 {
28003 return err;28041 return err;
...@@ -28012,8 +28050,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28012,8 +28050,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28012 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);28050 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
28013 IrAnalyze *ira = lazy_size_of->ira;28051 IrAnalyze *ira = lazy_size_of->ira;
2801428052
28015 if (lazy_size_of->target_type->value.special == ConstValSpecialStatic) {28053 if (lazy_size_of->target_type->value->special == ConstValSpecialStatic) {
28016 switch (lazy_size_of->target_type->value.data.x_type->id) {28054 switch (lazy_size_of->target_type->value->data.x_type->id) {
28017 case ZigTypeIdInvalid: // handled above28055 case ZigTypeIdInvalid: // handled above
28018 zig_unreachable();28056 zig_unreachable();
28019 case ZigTypeIdUnreachable:28057 case ZigTypeIdUnreachable:
...@@ -28024,7 +28062,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28024,7 +28062,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28024 case ZigTypeIdOpaque:28062 case ZigTypeIdOpaque:
28025 ir_add_error(ira, lazy_size_of->target_type,28063 ir_add_error(ira, lazy_size_of->target_type,
28026 buf_sprintf("no size available for type '%s'",28064 buf_sprintf("no size available for type '%s'",
28027 buf_ptr(&lazy_size_of->target_type->value.data.x_type->name)));28065 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
28028 return ErrorSemanticAnalyzeFail;28066 return ErrorSemanticAnalyzeFail;
28029 case ZigTypeIdMetaType:28067 case ZigTypeIdMetaType:
28030 case ZigTypeIdEnumLiteral:28068 case ZigTypeIdEnumLiteral:
...@@ -28052,7 +28090,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28052,7 +28090,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2805228090
28053 size_t abi_size;28091 size_t abi_size;
28054 size_t size_in_bits;28092 size_t size_in_bits;
28055 if ((err = type_val_resolve_abi_size(ira->codegen, source_node, &lazy_size_of->target_type->value,28093 if ((err = type_val_resolve_abi_size(ira->codegen, source_node, lazy_size_of->target_type->value,
28056 &abi_size, &size_in_bits)))28094 &abi_size, &size_in_bits)))
28057 {28095 {
28058 return err;28096 return err;
...@@ -28071,12 +28109,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28071,12 +28109,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28071 if (type_is_invalid(elem_type))28109 if (type_is_invalid(elem_type))
28072 return ErrorSemanticAnalyzeFail;28110 return ErrorSemanticAnalyzeFail;
2807328111
28074 ConstExprValue *sentinel_val;28112 ZigValue *sentinel_val;
28075 if (lazy_slice_type->sentinel != nullptr) {28113 if (lazy_slice_type->sentinel != nullptr) {
28076 if (type_is_invalid(lazy_slice_type->sentinel->value.type))28114 if (type_is_invalid(lazy_slice_type->sentinel->value->type))
28077 return ErrorSemanticAnalyzeFail;28115 return ErrorSemanticAnalyzeFail;
28078 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);28116 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
28079 if (type_is_invalid(sentinel->value.type))28117 if (type_is_invalid(sentinel->value->type))
28080 return ErrorSemanticAnalyzeFail;28118 return ErrorSemanticAnalyzeFail;
28081 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);28119 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
28082 if (sentinel_val == nullptr)28120 if (sentinel_val == nullptr)
...@@ -28149,12 +28187,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28149,12 +28187,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28149 if (type_is_invalid(elem_type))28187 if (type_is_invalid(elem_type))
28150 return ErrorSemanticAnalyzeFail;28188 return ErrorSemanticAnalyzeFail;
2815128189
28152 ConstExprValue *sentinel_val;28190 ZigValue *sentinel_val;
28153 if (lazy_ptr_type->sentinel != nullptr) {28191 if (lazy_ptr_type->sentinel != nullptr) {
28154 if (type_is_invalid(lazy_ptr_type->sentinel->value.type))28192 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))
28155 return ErrorSemanticAnalyzeFail;28193 return ErrorSemanticAnalyzeFail;
28156 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);28194 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
28157 if (type_is_invalid(sentinel->value.type))28195 if (type_is_invalid(sentinel->value->type))
28158 return ErrorSemanticAnalyzeFail;28196 return ErrorSemanticAnalyzeFail;
28159 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);28197 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
28160 if (sentinel_val == nullptr)28198 if (sentinel_val == nullptr)
...@@ -28276,7 +28314,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28276,7 +28314,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28276 zig_unreachable();28314 zig_unreachable();
28277}28315}
2827828316
28279Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) {28317Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
28280 Error err;28318 Error err;
28281 if ((err = ir_resolve_lazy_raw(source_node, val))) {28319 if ((err = ir_resolve_lazy_raw(source_node, val))) {
28282 if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) {28320 if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) {
src/ir.hpp+3-3
...@@ -18,12 +18,12 @@ enum IrPass {...@@ -18,12 +18,12 @@ enum IrPass {
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
2020
21ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,21ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2525
26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val);26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2727
28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
29 ZigType *expected_type, AstNode *expected_type_source_node);29 ZigType *expected_type, AstNode *expected_type_source_node);
...@@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_...@@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_
31bool ir_has_side_effects(IrInstruction *instruction);31bool ir_has_side_effects(IrInstruction *instruction);
3232
33struct IrAnalyze;33struct IrAnalyze;
34ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,34ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
35 AstNode *source_node);35 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op, bool llvm_name);36const char *float_op_to_name(BuiltinFnId op, bool llvm_name);
3737
src/ir_print.cpp+6-6
...@@ -389,14 +389,14 @@ static void ir_print_indent(IrPrint *irp) {...@@ -389,14 +389,14 @@ static void ir_print_indent(IrPrint *irp) {
389static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {389static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {
390 ir_print_indent(irp);390 ir_print_indent(irp);
391 const char mark = trailing ? ':' : '#';391 const char mark = trailing ? ':' : '#';
392 const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)";392 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
393 const char *ref_count = ir_has_side_effects(instruction) ?393 const char *ref_count = ir_has_side_effects(instruction) ?
394 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));394 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
395 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,395 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
396 ir_instruction_type_str(instruction->id), type_name, ref_count);396 ir_instruction_type_str(instruction->id), type_name, ref_count);
397}397}
398398
399static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {399static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {
400 Buf buf = BUF_INIT;400 Buf buf = BUF_INIT;
401 buf_resize(&buf, 0);401 buf_resize(&buf, 0);
402 render_const_value(irp->codegen, &buf, const_val);402 render_const_value(irp->codegen, &buf, const_val);
...@@ -417,8 +417,8 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction)...@@ -417,8 +417,8 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction)
417 return;417 return;
418 }418 }
419419
420 if (instruction->value.special != ConstValSpecialRuntime) {420 if (instruction->value->special != ConstValSpecialRuntime) {
421 ir_print_const_value(irp, &instruction->value);421 ir_print_const_value(irp, instruction->value);
422 } else {422 } else {
423 ir_print_var_instruction(irp, instruction);423 ir_print_var_instruction(irp, instruction);
424 }424 }
...@@ -438,7 +438,7 @@ static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {...@@ -438,7 +438,7 @@ static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {
438}438}
439439
440static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {440static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
441 ir_print_const_value(irp, &const_instruction->base.value);441 ir_print_const_value(irp, const_instruction->base.value);
442}442}
443443
444static const char *ir_bin_op_id_str(IrBinOp op_id) {444static const char *ir_bin_op_id_str(IrBinOp op_id) {
...@@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,...@@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,
2576 ir_print_instruction(irp, instruction, false);2576 ir_print_instruction(irp, instruction, false);
2577}2577}
25782578
2579void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass) {2579void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {
2580 IrPrint ir_print = {};2580 IrPrint ir_print = {};
2581 IrPrint *irp = &ir_print;2581 IrPrint *irp = &ir_print;
2582 irp->pass = pass;2582 irp->pass = pass;
src/ir_print.hpp+1-1
...@@ -14,7 +14,7 @@...@@ -14,7 +14,7 @@
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass);17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);
1818
19const char* ir_instruction_type_str(IrInstructionId id);19const char* ir_instruction_type_str(IrInstructionId id);
2020
src/memory_profiling.cpp+8-1
...@@ -6,6 +6,8 @@...@@ -6,6 +6,8 @@
66
7#ifdef ZIG_ENABLE_MEM_PROFILE7#ifdef ZIG_ENABLE_MEM_PROFILE
88
9MemprofInternCount memprof_intern_count;
10
9static bool str_eql_str(const char *a, const char *b) {11static bool str_eql_str(const char *a, const char *b) {
10 return strcmp(a, b) == 0;12 return strcmp(a, b) == 0;
11}13}
...@@ -29,7 +31,6 @@ ZigList<const char *> unknown_names = {};...@@ -29,7 +31,6 @@ ZigList<const char *> unknown_names = {};
29HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {};31HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {};
30bool table_active = false;32bool table_active = false;
3133
32
33static const char *get_default_name(const char *name_or_null, size_t type_size) {34static const char *get_default_name(const char *name_or_null, size_t type_size) {
34 if (name_or_null != nullptr) return name_or_null;35 if (name_or_null != nullptr) return name_or_null;
35 if (type_size >= unknown_names.length) {36 if (type_size >= unknown_names.length) {
...@@ -134,6 +135,12 @@ void memprof_dump_stats(FILE *file) {...@@ -134,6 +135,12 @@ void memprof_dump_stats(FILE *file) {
134135
135 list.deinit();136 list.deinit();
136 table_active = true;137 table_active = true;
138
139 fprintf(stderr, "\n");
140 fprintf(stderr, "undefined: interned %zu times\n", memprof_intern_count.x_undefined);
141 fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void);
142 fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null);
143 fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable);
137}144}
138145
139#endif146#endif
src/memory_profiling.hpp+8
...@@ -13,6 +13,14 @@...@@ -13,6 +13,14 @@
13#include <stddef.h>13#include <stddef.h>
14#include <stdio.h>14#include <stdio.h>
1515
16struct MemprofInternCount {
17 size_t x_undefined;
18 size_t x_void;
19 size_t x_null;
20 size_t x_unreachable;
21};
22extern MemprofInternCount memprof_intern_count;
23
16void memprof_init(void);24void memprof_init(void);
1725
18void memprof_alloc(const char *name, size_t item_count, size_t type_size);26void memprof_alloc(const char *name, size_t item_count, size_t type_size);
src/util.cpp+4-4
...@@ -121,18 +121,18 @@ SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) {...@@ -121,18 +121,18 @@ SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) {
121121
122void zig_pretty_print_bytes(FILE *f, double n) {122void zig_pretty_print_bytes(FILE *f, double n) {
123 if (n > 1024.0 * 1024.0 * 1024.0) {123 if (n > 1024.0 * 1024.0 * 1024.0) {
124 fprintf(f, "%.02f GiB", n / 1024.0 / 1024.0 / 1024.0);124 fprintf(f, "%.03f GiB", n / 1024.0 / 1024.0 / 1024.0);
125 return;125 return;
126 }126 }
127 if (n > 1024.0 * 1024.0) {127 if (n > 1024.0 * 1024.0) {
128 fprintf(f, "%.02f MiB", n / 1024.0 / 1024.0);128 fprintf(f, "%.03f MiB", n / 1024.0 / 1024.0);
129 return;129 return;
130 }130 }
131 if (n > 1024.0) {131 if (n > 1024.0) {
132 fprintf(f, "%.02f KiB", n / 1024.0);132 fprintf(f, "%.03f KiB", n / 1024.0);
133 return;133 return;
134 }134 }
135 fprintf(f, "%.02f bytes", n );135 fprintf(f, "%.03f bytes", n );
136 return;136 return;
137}137}
138138