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;
3232struct BuiltinFnEntry;
3333struct TypeStructField;
3434struct CodeGen;
35struct ConstExprValue;
35struct ZigValue;
3636struct IrInstruction;
3737struct IrInstructionCast;
3838struct IrInstructionAllocaGen;
......@@ -130,38 +130,38 @@ struct ConstParent {
130130
131131 union {
132132 struct {
133 ConstExprValue *array_val;
133 ZigValue *array_val;
134134 size_t elem_index;
135135 } p_array;
136136 struct {
137 ConstExprValue *struct_val;
137 ZigValue *struct_val;
138138 size_t field_index;
139139 } p_struct;
140140 struct {
141 ConstExprValue *err_union_val;
141 ZigValue *err_union_val;
142142 } p_err_union_code;
143143 struct {
144 ConstExprValue *err_union_val;
144 ZigValue *err_union_val;
145145 } p_err_union_payload;
146146 struct {
147 ConstExprValue *optional_val;
147 ZigValue *optional_val;
148148 } p_optional_payload;
149149 struct {
150 ConstExprValue *union_val;
150 ZigValue *union_val;
151151 } p_union;
152152 struct {
153 ConstExprValue *scalar_val;
153 ZigValue *scalar_val;
154154 } p_scalar;
155155 } data;
156156};
157157
158158struct ConstStructValue {
159 ConstExprValue **fields;
159 ZigValue **fields;
160160};
161161
162162struct ConstUnionValue {
163163 BigInt tag;
164 ConstExprValue *payload;
164 ZigValue *payload;
165165};
166166
167167enum ConstArraySpecial {
......@@ -174,7 +174,7 @@ struct ConstArrayValue {
174174 ConstArraySpecial special;
175175 union {
176176 struct {
177 ConstExprValue *elements;
177 ZigValue *elements;
178178 } s_none;
179179 Buf *s_buf;
180180 } data;
......@@ -235,24 +235,24 @@ struct ConstPtrValue {
235235
236236 union {
237237 struct {
238 ConstExprValue *pointee;
238 ZigValue *pointee;
239239 } ref;
240240 struct {
241 ConstExprValue *array_val;
241 ZigValue *array_val;
242242 size_t elem_index;
243243 } base_array;
244244 struct {
245 ConstExprValue *struct_val;
245 ZigValue *struct_val;
246246 size_t field_index;
247247 } base_struct;
248248 struct {
249 ConstExprValue *err_union_val;
249 ZigValue *err_union_val;
250250 } base_err_union_code;
251251 struct {
252 ConstExprValue *err_union_val;
252 ZigValue *err_union_val;
253253 } base_err_union_payload;
254254 struct {
255 ConstExprValue *optional_val;
255 ZigValue *optional_val;
256256 } base_optional_payload;
257257 struct {
258258 uint64_t addr;
......@@ -264,8 +264,8 @@ struct ConstPtrValue {
264264};
265265
266266struct ConstErrValue {
267 ConstExprValue *error_set;
268 ConstExprValue *payload;
267 ZigValue *error_set;
268 ZigValue *payload;
269269};
270270
271271struct ConstBoundFnValue {
......@@ -406,7 +406,7 @@ struct LazyValueErrUnionType {
406406 Buf *type_name;
407407};
408408
409struct ConstExprValue {
409struct ZigValue {
410410 ZigType *type;
411411 ConstValSpecial special;
412412 ConstParent parent;
......@@ -423,7 +423,7 @@ struct ConstExprValue {
423423 bool x_bool;
424424 ConstBoundFnValue x_bound_fn;
425425 ZigType *x_type;
426 ConstExprValue *x_optional;
426 ZigValue *x_optional;
427427 ConstErrValue x_err_union;
428428 ErrorTableEntry *x_err_set;
429429 BigInt x_enum_tag;
......@@ -443,8 +443,8 @@ struct ConstExprValue {
443443 } data;
444444
445445 // 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 {}
447 //ConstExprValue& operator= (const ConstExprValue &other) = delete; // use copy_const_val
446 //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {}
447 //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val
448448};
449449
450450enum ReturnKnowledge {
......@@ -525,7 +525,7 @@ struct TldCompTime {
525525struct TldUsingNamespace {
526526 Tld base;
527527
528 ConstExprValue *using_namespace_value;
528 ZigValue *using_namespace_value;
529529};
530530
531531struct TypeEnumField {
......@@ -538,7 +538,7 @@ struct TypeEnumField {
538538struct TypeUnionField {
539539 Buf *name;
540540 ZigType *type_entry; // available after ResolveStatusSizeKnown
541 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown
541 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
542542 TypeEnumField *enum_field;
543543 AstNode *decl_node;
544544 uint32_t gen_index;
......@@ -1171,7 +1171,7 @@ struct FnTypeParamInfo {
11711171struct GenericFnTypeId {
11721172 CodeGen *codegen;
11731173 ZigFn *fn_entry;
1174 ConstExprValue *params;
1174 ZigValue *params;
11751175 size_t param_count;
11761176};
11771177
......@@ -1213,7 +1213,7 @@ struct ZigTypePointer {
12131213 // This can be null. If it is non-null, it means the pointer is terminated by this
12141214 // sentinel value. This is most commonly used for C-style strings, with a 0 byte
12151215 // to specify the length of the memory pointed to.
1216 ConstExprValue *sentinel;
1216 ZigValue *sentinel;
12171217
12181218 PtrLen ptr_len;
12191219 uint32_t explicit_alignment; // 0 means use ABI alignment
......@@ -1242,18 +1242,18 @@ struct ZigTypeFloat {
12421242struct ZigTypeArray {
12431243 ZigType *child_type;
12441244 uint64_t len;
1245 ConstExprValue *sentinel;
1245 ZigValue *sentinel;
12461246};
12471247
12481248struct TypeStructField {
12491249 Buf *name;
12501250 ZigType *type_entry; // available after ResolveStatusSizeKnown
1251 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown
1251 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
12521252 size_t src_index;
12531253 size_t gen_index;
12541254 size_t offset; // byte offset from beginning of struct
12551255 AstNode *decl_node;
1256 ConstExprValue *init_val; // null and then memoized
1256 ZigValue *init_val; // null and then memoized
12571257 uint32_t bit_offset_in_host; // offset from the memory at gen_index
12581258 uint32_t host_int_bytes; // size of host integer
12591259 uint32_t align;
......@@ -1515,7 +1515,7 @@ struct ZigType {
15151515 ZigType *any_frame_parent;
15161516 // If we generate a constant name value for this type, we memoize it here.
15171517 // The type of this is array
1518 ConstExprValue *cached_const_name_val;
1518 ZigValue *cached_const_name_val;
15191519
15201520 OnePossibleValue one_possible_value;
15211521 // Known after ResolveStatusAlignmentKnown.
......@@ -1771,7 +1771,7 @@ struct TypeId {
17711771 CodeGen *codegen;
17721772 ZigType *child_type;
17731773 InferredStructField *inferred_struct_field;
1774 ConstExprValue *sentinel;
1774 ZigValue *sentinel;
17751775 PtrLen ptr_len;
17761776 uint32_t alignment;
17771777
......@@ -1787,7 +1787,7 @@ struct TypeId {
17871787 CodeGen *codegen;
17881788 ZigType *child_type;
17891789 uint64_t size;
1790 ConstExprValue *sentinel;
1790 ZigValue *sentinel;
17911791 } array;
17921792 struct {
17931793 bool is_signed;
......@@ -1960,13 +1960,13 @@ struct CodeGen {
19601960 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
19611961 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;
19621962 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;
19641964 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
19651965 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;
19661966 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
1967 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
1968 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1969 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> one_possible_values;
1967 HashMap<Buf *, ZigValue *, buf_hash, buf_eql_buf> string_literals_table;
1968 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1969 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> one_possible_values;
19701970
19711971 ZigList<Tld *> resolve_queue;
19721972 size_t resolve_queue_index;
......@@ -2021,6 +2021,13 @@ struct CodeGen {
20212021 ZigType *entry_any_frame;
20222022 } 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
20242031 ZigType *align_amt_type;
20252032 ZigType *stack_trace_type;
20262033 ZigType *err_tag_type;
......@@ -2043,9 +2050,9 @@ struct CodeGen {
20432050 IrInstruction *invalid_instruction;
20442051 IrInstruction *unreach_instruction;
20452052
2046 ConstExprValue const_zero_byte;
2047 ConstExprValue const_void_val;
2048 ConstExprValue panic_msg_vals[PanicMsgIdCount];
2053 ZigValue const_zero_byte;
2054 ZigValue const_void_val;
2055 ZigValue panic_msg_vals[PanicMsgIdCount];
20492056
20502057 // The function definitions this module includes.
20512058 ZigList<ZigFn *> fn_defs;
......@@ -2163,7 +2170,7 @@ struct CodeGen {
21632170
21642171struct ZigVar {
21652172 const char *name;
2166 ConstExprValue *const_value;
2173 ZigValue *const_value;
21672174 ZigType *var_type;
21682175 LLVMValueRef value_ref;
21692176 IrInstruction *is_comptime;
......@@ -2202,7 +2209,7 @@ struct ErrorTableEntry {
22022209 ZigType *set_with_only_this_in_it;
22032210 // If we generate a constant error name value for this error, we memoize it here.
22042211 // The type of this is array
2205 ConstExprValue *cached_error_name_val;
2212 ZigValue *cached_error_name_val;
22062213};
22072214
22082215enum ScopeId {
......@@ -2621,7 +2628,7 @@ struct IrInstruction {
26212628 Scope *scope;
26222629 AstNode *source_node;
26232630 LLVMValueRef llvm_value;
2624 ConstExprValue value;
2631 ZigValue *value;
26252632 uint32_t debug_id;
26262633 // if ref_count is zero and the instruction has no side effects,
26272634 // 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) {
511511ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,
512512 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
513513 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)
515515{
516516 assert(ptr_len != PtrLenC || allow_zero);
517517 assert(!type_is_invalid(child_type));
......@@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
760760 return entry;
761761}
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) {
764764 TypeId type_id = {};
765765 type_id.id = ZigTypeIdArray;
766766 type_id.data.array.codegen = g;
......@@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
956956
957957ZigType *get_stack_trace_type(CodeGen *g) {
958958 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");
960960 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
961961
962962 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
10951095 return entry;
10961096}
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,
10991099 Buf *type_name, UndefAllowed undef)
11001100{
11011101 size_t backward_branch_count = 0;
......@@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig
11051105 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);
11061106}
11071107
1108Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,
1109 ConstExprValue *parent_type_val, bool *is_zero_bits)
1108Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
1109 ZigValue *parent_type_val, bool *is_zero_bits)
11101110{
11111111 Error err;
11121112 if (type_val->special != ConstValSpecialLazy) {
......@@ -1134,7 +1134,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
11341134 case LazyValueIdPtrType: {
11351135 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) {
11381138 // Does a struct which contains a pointer field to itself have bits? Yes.
11391139 *is_zero_bits = false;
11401140 return ErrorNone;
......@@ -1142,7 +1142,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
11421142 if (parent_type_val == nullptr) {
11431143 parent_type_val = type_val;
11441144 }
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,
11461146 parent_type_val, is_zero_bits);
11471147 }
11481148 }
......@@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
11601160 zig_unreachable();
11611161}
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) {
11641164 if (type_val->special != ConstValSpecialLazy) {
11651165 assert(type_val->special == ConstValSpecialStatic);
11661166 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
11861186 zig_unreachable();
11871187}
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) {
11901190 if (type_val->special != ConstValSpecialLazy) {
11911191 return type_requires_comptime(g, type_val->data.x_type);
11921192 }
......@@ -1197,21 +1197,21 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
11971197 zig_unreachable();
11981198 case LazyValueIdSliceType: {
11991199 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);
12011201 }
12021202 case LazyValueIdPtrType: {
12031203 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);
12051205 }
12061206 case LazyValueIdOptType: {
12071207 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);
12091209 }
12101210 case LazyValueIdFnType: {
12111211 LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy);
12121212 if (lazy_fn_type->is_generic)
12131213 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)) {
12151215 case ReqCompTimeInvalid:
12161216 return ReqCompTimeInvalid;
12171217 case ReqCompTimeYes:
......@@ -1224,7 +1224,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
12241224 AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i);
12251225 bool param_is_var_args = param_node->data.param_decl.is_var_args;
12261226 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)) {
12281228 case ReqCompTimeInvalid:
12291229 return ReqCompTimeInvalid;
12301230 case ReqCompTimeYes:
......@@ -1238,13 +1238,13 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
12381238 case LazyValueIdErrUnionType: {
12391239 LazyValueErrUnionType *lazy_err_union_type =
12401240 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);
12421242 }
12431243 }
12441244 zig_unreachable();
12451245}
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,
12481248 size_t *abi_size, size_t *size_in_bits)
12491249{
12501250 Error err;
......@@ -1267,7 +1267,7 @@ start_over:
12671267 case LazyValueIdSliceType: {
12681268 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);
12691269 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,
12711271 nullptr, &is_zero_bits)))
12721272 {
12731273 return err;
......@@ -1284,7 +1284,7 @@ start_over:
12841284 case LazyValueIdPtrType: {
12851285 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);
12861286 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,
12881288 nullptr, &is_zero_bits)))
12891289 {
12901290 return err;
......@@ -1311,7 +1311,7 @@ start_over:
13111311 zig_unreachable();
13121312}
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) {
13151315 Error err;
13161316 if (type_val->special != ConstValSpecialLazy) {
13171317 assert(type_val->special == ConstValSpecialStatic);
......@@ -1337,13 +1337,13 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t
13371337 return ErrorNone;
13381338 case LazyValueIdOptType: {
13391339 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);
13411341 }
13421342 case LazyValueIdErrUnionType: {
13431343 LazyValueErrUnionType *lazy_err_union_type =
13441344 reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy);
13451345 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,
13471347 &payload_abi_align)))
13481348 {
13491349 return err;
......@@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t
13561356 zig_unreachable();
13571357}
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) {
13601360 if (type_val->special != ConstValSpecialLazy) {
13611361 return type_has_one_possible_value(g, type_val->data.x_type);
13621362 }
......@@ -1384,13 +1384,13 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
13841384 case LazyValueIdErrUnionType: {
13851385 LazyValueErrUnionType *lazy_err_union_type =
13861386 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)) {
13881388 case OnePossibleValueInvalid:
13891389 return OnePossibleValueInvalid;
13901390 case OnePossibleValueNo:
13911391 return OnePossibleValueNo;
13921392 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);
13941394 }
13951395 }
13961396 }
......@@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
13981398}
13991399
14001400ZigType *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,
14021402 nullptr, UndefBad);
14031403 if (type_is_invalid(result->type))
14041404 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
14511451}
14521452
14531453static 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),
14551455 nullptr, UndefBad);
14561456 if (type_is_invalid(align_result->type))
14571457 return false;
......@@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
14741474 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
14751475 PtrLenUnknown, 0, 0, 0, false);
14761476 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);
14781478 if (type_is_invalid(result_val->type))
14791479 return false;
14801480
1481 ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1482 ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index];
1481 ZigValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1482 ZigValue *len_field = result_val->data.x_struct.fields[slice_len_index];
14831483
14841484 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;
14861486 if (array_val->data.x_array.special == ConstArraySpecialBuf) {
14871487 *out_buffer = array_val->data.x_array.data.s_buf;
14881488 return true;
......@@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
14931493 buf_resize(result, len);
14941494 for (size_t i = 0; i < len; i += 1) {
14951495 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];
14971497 if (char_val->special == ConstValSpecialUndef) {
14981498 add_node_error(g, node, buf_sprintf("use of undefined value"));
14991499 return false;
......@@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26212621
26222622 if (tag_value != nullptr) {
26232623 // 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,
26252625 nullptr, UndefBad);
26262626 if (type_is_invalid(result->type)) {
26272627 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
......@@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
27562756 return ErrorSemanticAnalyzeFail;
27572757 }
27582758
2759 ConstExprValue *field_type_val;
2759 ZigValue *field_type_val;
27602760 if (decl_node->type == NodeTypeContainerDecl) {
27612761 field_type_val = analyze_const_value(g, scope,
27622762 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) {
30513051 return ErrorSemanticAnalyzeFail;
30523052 }
30533053 } else {
3054 ConstExprValue *field_type_val = analyze_const_value(g, scope,
3054 ZigValue *field_type_val = analyze_const_value(g, scope,
30553055 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
30563056 if (type_is_invalid(field_type_val->type)) {
30573057 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
......@@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
31173117 // In a second pass we will fill in the unspecified ones.
31183118 if (tag_value != nullptr) {
31193119 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,
31213121 nullptr, UndefBad);
31223122 if (type_is_invalid(result->type)) {
31233123 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
35453545 tld->parent_scope = parent_scope;
35463546}
35473547
3548void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {
3548void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
35493549 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);
35503550 resolve_top_level_decl(g, tld, tld->source_node, false);
35513551 assert(tld->id == TldIdVar);
......@@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
37173717// Set name to nullptr to make the variable anonymous (not visible to programmer).
37183718// TODO merge with definition of add_local_var in ir.cpp
37193719ZigVar *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)
37213721{
37223722 Error err;
37233723 assert(const_value != nullptr);
......@@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
38153815
38163816 assert(!is_export || !is_extern);
38173817
3818 ConstExprValue *init_value = nullptr;
3818 ZigValue *init_value = nullptr;
38193819
38203820 // TODO more validation for types that can't be used for export/extern variables
38213821 ZigType *implicit_type = nullptr;
......@@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
38533853 ZigType *type = explicit_type ? explicit_type : implicit_type;
38543854 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
38583858 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
38593859 is_const, init_val, &tld_var->base, type);
......@@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_
39003900 }
39013901 }
39023902
3903 ConstExprValue *use_expr = src_using_namespace->using_namespace_value;
3903 ZigValue *use_expr = src_using_namespace->using_namespace_value;
39043904 if (type_is_invalid(use_expr->type)) {
39053905 dest_decls_scope->any_imports_failed = true;
39063906 return;
......@@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
39773977
39783978 using_namespace->base.resolution = TldResolutionResolving;
39793979 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,
39813981 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,
39823982 nullptr, UndefBad);
39833983 using_namespace->using_namespace_value = result;
......@@ -3985,7 +3985,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
39853985 if (type_is_invalid(result->type)) {
39863986 dest_decls_scope->any_imports_failed = true;
39873987 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;
39893989 return;
39903990 }
39913991
......@@ -3994,7 +3994,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
39943994 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
39953995 dest_decls_scope->any_imports_failed = true;
39963996 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;
39983998 return;
39993999 }
40004000}
......@@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
50295029 return true;
50305030}
50315031
5032static uint32_t hash_const_val_error_set(ConstExprValue *const_val) {
5032static uint32_t hash_const_val_error_set(ZigValue *const_val) {
50335033 assert(const_val->data.x_err_set != nullptr);
50345034 return const_val->data.x_err_set->value ^ 2630160122;
50355035}
50365036
5037static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
5037static uint32_t hash_const_val_ptr(ZigValue *const_val) {
50385038 uint32_t hash_val = 0;
50395039 switch (const_val->data.x_ptr.mut) {
50405040 case ConstPtrMutRuntimeVar:
......@@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
50955095 zig_unreachable();
50965096}
50975097
5098static uint32_t hash_const_val(ConstExprValue *const_val) {
5098static uint32_t hash_const_val(ZigValue *const_val) {
50995099 assert(const_val->special == ConstValSpecialStatic);
51005100 switch (const_val->type->id) {
51015101 case ZigTypeIdOpaque:
......@@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
52245224 uint32_t result = 0;
52255225 result += hash_ptr(id->fn_entry);
52265226 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];
52285228 if (generic_param->special != ConstValSpecialRuntime) {
52295229 result += hash_const_val(generic_param);
52305230 result += hash_ptr(generic_param->type);
......@@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
52385238 if (a->fn_entry != b->fn_entry) return false;
52395239 if (a->param_count != b->param_count) return false;
52405240 for (size_t i = 0; i < a->param_count; i += 1) {
5241 ConstExprValue *a_val = &a->params[i];
5242 ConstExprValue *b_val = &b->params[i];
5241 ZigValue *a_val = &a->params[i];
5242 ZigValue *b_val = &b->params[i];
52435243 if (a_val->type != b_val->type) return false;
52445244 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {
52455245 assert(a_val->special == ConstValSpecialStatic);
......@@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
52545254 return true;
52555255}
52565256
5257static bool can_mutate_comptime_var_state(ConstExprValue *value) {
5257static bool can_mutate_comptime_var_state(ZigValue *value) {
52585258 assert(value != nullptr);
52595259 switch (value->type->id) {
52605260 case ZigTypeIdInvalid:
......@@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
55625562 zig_unreachable();
55635563}
55645564
5565ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5565ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
55665566 auto entry = g->one_possible_values.maybe_get(type_entry);
55675567 if (entry != nullptr) {
55685568 return entry->value;
55695569 }
5570 ConstExprValue *result = create_const_vals(1);
5570 ZigValue *result = create_const_vals(1);
55715571 result->type = type_entry;
55725572 result->special = ConstValSpecialStatic;
55735573 g->one_possible_values.put(type_entry, result);
......@@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
56375637 zig_unreachable();
56385638}
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) {
56415641 auto entry = g->string_literals_table.maybe_get(str);
56425642 if (entry != nullptr) {
5643 memcpy(const_val, entry->value, sizeof(ConstExprValue));
5643 memcpy(const_val, entry->value, sizeof(ZigValue));
56445644 return;
56455645 }
56465646
56475647 // first we build the underlying array
5648 ConstExprValue *array_val = create_const_vals(1);
5648 ZigValue *array_val = create_const_vals(1);
56495649 array_val->special = ConstValSpecialStatic;
56505650 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte);
56515651 array_val->data.x_array.special = ConstArraySpecialBuf;
......@@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
56615661 g->string_literals_table.put(str, const_val);
56625662}
56635663
5664ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {
5665 ConstExprValue *const_val = create_const_vals(1);
5664ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {
5665 ZigValue *const_val = create_const_vals(1);
56665666 init_const_str_lit(g, const_val, str);
56675667 return const_val;
56685668}
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) {
56715671 const_val->special = ConstValSpecialStatic;
56725672 const_val->type = type;
56735673 bigint_init_bigint(&const_val->data.x_bigint, bigint);
56745674}
56755675
5676ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5677 ConstExprValue *const_val = create_const_vals(1);
5676ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5677 ZigValue *const_val = create_const_vals(1);
56785678 init_const_bigint(const_val, type, bigint);
56795679 return const_val;
56805680}
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) {
56845684 const_val->special = ConstValSpecialStatic;
56855685 const_val->type = type;
56865686 bigint_init_unsigned(&const_val->data.x_bigint, x);
56875687 const_val->data.x_bigint.is_negative = negative;
56885688}
56895689
5690ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5691 ConstExprValue *const_val = create_const_vals(1);
5690ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5691 ZigValue *const_val = create_const_vals(1);
56925692 init_const_unsigned_negative(const_val, type, x, negative);
56935693 return const_val;
56945694}
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) {
56975697 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);
56985698}
56995699
5700ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {
5700ZigValue *create_const_usize(CodeGen *g, uint64_t x) {
57015701 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
57025702}
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) {
57055705 const_val->special = ConstValSpecialStatic;
57065706 const_val->type = type;
57075707 bigint_init_signed(&const_val->data.x_bigint, x);
57085708}
57095709
5710ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
5711 ConstExprValue *const_val = create_const_vals(1);
5710ZigValue *create_const_signed(ZigType *type, int64_t x) {
5711 ZigValue *const_val = create_const_vals(1);
57125712 init_const_signed(const_val, type, x);
57135713 return const_val;
57145714}
57155715
5716void init_const_null(ConstExprValue *const_val, ZigType *type) {
5716void init_const_null(ZigValue *const_val, ZigType *type) {
57175717 const_val->special = ConstValSpecialStatic;
57185718 const_val->type = type;
57195719 const_val->data.x_optional = nullptr;
57205720}
57215721
5722ConstExprValue *create_const_null(ZigType *type) {
5723 ConstExprValue *const_val = create_const_vals(1);
5722ZigValue *create_const_null(ZigType *type) {
5723 ZigValue *const_val = create_const_vals(1);
57245724 init_const_null(const_val, type);
57255725 return const_val;
57265726}
57275727
5728void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5728void init_const_float(ZigValue *const_val, ZigType *type, double value) {
57295729 const_val->special = ConstValSpecialStatic;
57305730 const_val->type = type;
57315731 if (type->id == ZigTypeIdComptimeFloat) {
......@@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
57525752 }
57535753}
57545754
5755ConstExprValue *create_const_float(ZigType *type, double value) {
5756 ConstExprValue *const_val = create_const_vals(1);
5755ZigValue *create_const_float(ZigType *type, double value) {
5756 ZigValue *const_val = create_const_vals(1);
57575757 init_const_float(const_val, type, value);
57585758 return const_val;
57595759}
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) {
57625762 const_val->special = ConstValSpecialStatic;
57635763 const_val->type = type;
57645764 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
57655765}
57665766
5767ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {
5768 ConstExprValue *const_val = create_const_vals(1);
5767ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {
5768 ZigValue *const_val = create_const_vals(1);
57695769 init_const_enum(const_val, type, tag);
57705770 return const_val;
57715771}
57725772
57735773
5774void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value) {
5774void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
57755775 const_val->special = ConstValSpecialStatic;
57765776 const_val->type = g->builtin_types.entry_bool;
57775777 const_val->data.x_bool = value;
57785778}
57795779
5780ConstExprValue *create_const_bool(CodeGen *g, bool value) {
5781 ConstExprValue *const_val = create_const_vals(1);
5780ZigValue *create_const_bool(CodeGen *g, bool value) {
5781 ZigValue *const_val = create_const_vals(1);
57825782 init_const_bool(g, const_val, value);
57835783 return const_val;
57845784}
57855785
5786void init_const_runtime(ConstExprValue *const_val, ZigType *type) {
5786void init_const_runtime(ZigValue *const_val, ZigType *type) {
57875787 const_val->special = ConstValSpecialRuntime;
57885788 const_val->type = type;
57895789}
57905790
5791ConstExprValue *create_const_runtime(ZigType *type) {
5792 ConstExprValue *const_val = create_const_vals(1);
5791ZigValue *create_const_runtime(ZigType *type) {
5792 ZigValue *const_val = create_const_vals(1);
57935793 init_const_runtime(const_val, type);
57945794 return const_val;
57955795}
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) {
57985798 const_val->special = ConstValSpecialStatic;
57995799 const_val->type = g->builtin_types.entry_type;
58005800 const_val->data.x_type = type_value;
58015801}
58025802
5803ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {
5804 ConstExprValue *const_val = create_const_vals(1);
5803ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {
5804 ZigValue *const_val = create_const_vals(1);
58055805 init_const_type(g, const_val, type_value);
58065806 return const_val;
58075807}
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,
58105810 size_t start, size_t len, bool is_const)
58115811{
58125812 assert(array_val->type->id == ZigTypeIdArray);
......@@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
58235823 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);
58245824}
58255825
5826ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {
5827 ConstExprValue *const_val = create_const_vals(1);
5826ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {
5827 ZigValue *const_val = create_const_vals(1);
58285828 init_const_slice(g, const_val, array_val, start, len, is_const);
58295829 return const_val;
58305830}
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,
58335833 size_t elem_index, bool is_const, PtrLen ptr_len)
58345834{
58355835 assert(array_val->type->id == ZigTypeIdArray);
......@@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue
58435843 const_val->data.x_ptr.data.base_array.elem_index = elem_index;
58445844}
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,
58475847 PtrLen ptr_len)
58485848{
5849 ConstExprValue *const_val = create_const_vals(1);
5849 ZigValue *const_val = create_const_vals(1);
58505850 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
58515851 return const_val;
58525852}
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) {
58555855 const_val->special = ConstValSpecialStatic;
58565856 const_val->type = get_pointer_to_type(g, pointee_val->type, is_const);
58575857 const_val->data.x_ptr.special = ConstPtrSpecialRef;
58585858 const_val->data.x_ptr.data.ref.pointee = pointee_val;
58595859}
58605860
5861ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const) {
5862 ConstExprValue *const_val = create_const_vals(1);
5861ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {
5862 ZigValue *const_val = create_const_vals(1);
58635863 init_const_ptr_ref(g, const_val, pointee_val, is_const);
58645864 return const_val;
58655865}
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,
58685868 size_t addr, bool is_const)
58695869{
58705870 const_val->special = ConstValSpecialStatic;
......@@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy
58735873 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
58745874}
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,
58775877 size_t addr, bool is_const)
58785878{
5879 ConstExprValue *const_val = create_const_vals(1);
5879 ZigValue *const_val = create_const_vals(1);
58805880 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
58815881 return const_val;
58825882}
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) {
58855885 const_val->special = ConstValSpecialStatic;
58865886 const_val->type = g->builtin_types.entry_arg_tuple;
58875887 const_val->data.x_arg_tuple.start_index = arg_index_start;
58885888 const_val->data.x_arg_tuple.end_index = arg_index_end;
58895889}
58905890
5891ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {
5892 ConstExprValue *const_val = create_const_vals(1);
5891ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {
5892 ZigValue *const_val = create_const_vals(1);
58935893 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);
58945894 return const_val;
58955895}
58965896
58975897
5898ConstExprValue *create_const_vals(size_t count) {
5898ZigValue *create_const_vals(size_t count) {
58995899 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5900 ConstExprValue *vals = allocate<ConstExprValue>(count, "ConstExprValue");
5900 ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
59015901 for (size_t i = 0; i < count; i += 1) {
59025902 vals[i].global_refs = &global_refs[i];
59035903 }
59045904 return vals;
59055905}
59065906
5907ConstExprValue **alloc_const_vals_ptrs(size_t count) {
5907ZigValue **alloc_const_vals_ptrs(size_t count) {
59085908 return realloc_const_vals_ptrs(nullptr, 0, count);
59095909}
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) {
59125912 assert(new_count >= old_count);
59135913
59145914 size_t new_item_count = new_count - old_count;
5915 ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*");
5916 ConstExprValue *vals = create_const_vals(new_item_count);
5915 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");
5916 ZigValue *vals = create_const_vals(new_item_count);
59175917 for (size_t i = old_count; i < new_count; i += 1) {
59185918 result[i] = &vals[i - old_count];
59195919 }
......@@ -6106,7 +6106,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
61066106 alloca_gen->base.id = IrInstructionIdAllocaGen;
61076107 alloca_gen->base.source_node = fn->proto_node;
61086108 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);
61106111 alloca_gen->base.ref_count = 1;
61116112 alloca_gen->name_hint = "";
61126113 fn->alloca_gen_list.append(alloca_gen);
......@@ -6173,7 +6174,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
61736174 call->frame_result_loc = all_calls_alloca;
61746175 }
61756176 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);
61776178 }
61786179
61796180 // 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) {
61846185 IrInstructionAwaitGen *await = fn->await_list.at(i);
61856186 // TODO If this is a noasync await, it doesn't suspend
61866187 // https://github.com/ziglang/zig/issues/3157
6187 if (await->base.value.special != ConstValSpecialRuntime) {
6188 if (await->base.value->special != ConstValSpecialRuntime) {
61886189 // Known at comptime. No spill, no suspend.
61896190 continue;
61906191 }
......@@ -6211,10 +6212,10 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62116212 }
62126213 if (await->base.ref_count == 0)
62136214 continue;
6214 if (!type_has_bits(await->base.value.type))
6215 if (!type_has_bits(await->base.value->type))
62156216 continue;
62166217 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, "");
62186219 }
62196220 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
62206221 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) {
62396240 // This instruction does its own spilling specially, or otherwise doesn't need it.
62406241 continue;
62416242 }
6242 if (instruction->value.special != ConstValSpecialRuntime)
6243 if (instruction->value->special != ConstValSpecialRuntime)
62436244 continue;
62446245 if (instruction->ref_count == 0)
62456246 continue;
6246 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown)))
6247 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
62476248 return ErrorSemanticAnalyzeFail;
6248 if (!type_has_bits(instruction->value.type))
6249 if (!type_has_bits(instruction->value->type))
62496250 continue;
62506251 if (scope_needs_spill(instruction->scope)) {
62516252 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
6252 fn, instruction->value.type, "");
6253 fn, instruction->value->type, "");
62536254 }
62546255 }
62556256 }
......@@ -6301,15 +6302,15 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
63016302 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {
63026303 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);
63036304 instruction->field_index = SIZE_MAX;
6304 ZigType *ptr_type = instruction->base.value.type;
6305 ZigType *ptr_type = instruction->base.value->type;
63056306 assert(ptr_type->id == ZigTypeIdPointer);
63066307 ZigType *child_type = ptr_type->data.pointer.child_type;
63076308 if (!type_has_bits(child_type))
63086309 continue;
63096310 if (instruction->base.ref_count == 0)
63106311 continue;
6311 if (instruction->base.value.special != ConstValSpecialRuntime) {
6312 if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special !=
6312 if (instruction->base.value->special != ConstValSpecialRuntime) {
6313 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
63136314 ConstValSpecialRuntime)
63146315 {
63156316 continue;
......@@ -6446,17 +6447,17 @@ bool ir_get_var_is_comptime(ZigVar *var) {
64466447 // When the is_comptime field references an instruction that has to get analyzed, this
64476448 // is the value.
64486449 if (var->is_comptime->child != nullptr) {
6449 assert(var->is_comptime->child->value.type->id == ZigTypeIdBool);
6450 return var->is_comptime->child->value.data.x_bool;
6450 assert(var->is_comptime->child->value->type->id == ZigTypeIdBool);
6451 return var->is_comptime->child->value->data.x_bool;
64516452 }
64526453 // As an optimization, is_comptime values which are constant are allowed
64536454 // to be omitted from analysis. In this case, there is no child instruction
64546455 // and we simply look at the unanalyzed const parent instruction.
6455 assert(var->is_comptime->value.type->id == ZigTypeIdBool);
6456 return var->is_comptime->value.data.x_bool;
6456 assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6457 return var->is_comptime->value->data.x_bool;
64576458}
64586459
6459bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
6460bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
64606461 if (a->data.x_ptr.special != b->data.x_ptr.special)
64616462 return false;
64626463 switch (a->data.x_ptr.special) {
......@@ -6527,7 +6528,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
65276528 zig_unreachable();
65286529}
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) {
65316532 assert(a->data.x_array.special != ConstArraySpecialUndef);
65326533 assert(b->data.x_array.special != ConstArraySpecialUndef);
65336534 if (a->data.x_array.special == ConstArraySpecialBuf &&
......@@ -6538,8 +6539,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal
65386539 expand_undef_array(g, a);
65396540 expand_undef_array(g, b);
65406541
6541 ConstExprValue *a_elems = a->data.x_array.data.s_none.elements;
6542 ConstExprValue *b_elems = b->data.x_array.data.s_none.elements;
6542 ZigValue *a_elems = a->data.x_array.data.s_none.elements;
6543 ZigValue *b_elems = b->data.x_array.data.s_none.elements;
65436544
65446545 for (size_t i = 0; i < len; i += 1) {
65456546 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
65496550 return true;
65506551}
65516552
6552bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
6553bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
65536554 if (a->type->id != b->type->id) return false;
65546555 assert(a->special == ConstValSpecialStatic);
65556556 assert(b->special == ConstValSpecialStatic);
......@@ -6623,8 +6624,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
66236624 }
66246625 case ZigTypeIdStruct:
66256626 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 ConstExprValue *field_b = b->data.x_struct.fields[i];
6627 ZigValue *field_a = a->data.x_struct.fields[i];
6628 ZigValue *field_b = b->data.x_struct.fields[i];
66286629 if (!const_values_equal(g, field_a, field_b))
66296630 return false;
66306631 }
......@@ -6695,7 +6696,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool
66956696 }
66966697}
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) {
66996700 if (type_entry->id == ZigTypeIdInt) {
67006701 const_val->special = ConstValSpecialStatic;
67016702 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
67096710 }
67106711}
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) {
67136714 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
67146715 buf_append_buf(buf, &type_entry->name);
67156716 return;
......@@ -6752,7 +6753,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val
67526753 zig_unreachable();
67536754}
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) {
67566757 if (const_val->data.x_err_set == nullptr) {
67576758 buf_append_str(buf, "null");
67586759 } else {
......@@ -6760,7 +6761,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const
67606761 }
67616762}
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) {
67646765 ConstArrayValue *array = &const_val->data.x_array;
67656766 switch (array->special) {
67666767 case ConstArraySpecialUndef:
......@@ -6784,7 +6785,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx
67846785 return;
67856786 }
67866787 case ConstArraySpecialNone: {
6787 ConstExprValue *base = &array->data.s_none.elements[start];
6788 ZigValue *base = &array->data.s_none.elements[start];
67886789 assert(start + len <= const_val->type->data.array.len);
67896790
67906791 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
67996800 zig_unreachable();
68006801}
68016802
6802void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
6803void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
68036804 switch (const_val->special) {
68046805 case ConstValSpecialRuntime:
68056806 buf_appendf(buf, "(runtime value)");
......@@ -6927,17 +6928,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
69276928 case ZigTypeIdStruct:
69286929 {
69296930 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];
69316932 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];
69346935 if (ptr_val->special == ConstValSpecialUndef) {
69356936 assert(len == 0);
69366937 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));
69376938 return;
69386939 }
69396940 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;
69416942 size_t start = ptr_val->data.x_ptr.data.base_array.elem_index;
69426943
69436944 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) {
72067207 zig_unreachable();
72077208}
72087209
7209static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
7210static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
72107211 Error err;
72117212 ZigType *wanted_type = const_val->type;
72127213 if (wanted_type->id == ZigTypeIdArray) {
......@@ -7221,7 +7222,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
72217222 size_t field_count = wanted_type->data.structure.src_field_count;
72227223 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
72237224 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];
72257226 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
72267227 assert(field_val->type);
72277228 init_const_undefined(g, field_val);
......@@ -7234,14 +7235,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
72347235 }
72357236}
72367237
7237void expand_undef_struct(CodeGen *g, ConstExprValue *const_val) {
7238void expand_undef_struct(CodeGen *g, ZigValue *const_val) {
72387239 if (const_val->special == ConstValSpecialUndef) {
72397240 init_const_undefined(g, const_val);
72407241 }
72417242}
72427243
72437244// Canonicalize the array value as ConstArraySpecialNone
7244void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
7245void expand_undef_array(CodeGen *g, ZigValue *const_val) {
72457246 size_t elem_count;
72467247 ZigType *elem_type;
72477248 if (const_val->type->id == ZigTypeIdArray) {
......@@ -7264,7 +7265,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
72647265 const_val->data.x_array.special = ConstArraySpecialNone;
72657266 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
72667267 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];
72687269 element_val->type = elem_type;
72697270 init_const_undefined(g, element_val);
72707271 element_val->parent.id = ConstParentIdArray;
......@@ -7283,7 +7284,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
72837284 assert(elem_count == buf_len(buf));
72847285 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
72857286 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];
72877288 this_char->special = ConstValSpecialStatic;
72887289 this_char->type = g->builtin_types.entry_u8;
72897290 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) {
75417542 return a == b;
75427543}
75437544
7544ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
7545ZigValue *get_builtin_value(CodeGen *codegen, const char *name) {
75457546 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
75467547 resolve_top_level_decl(codegen, tld, nullptr, false);
75477548 assert(tld->id == TldIdVar);
75487549 TldVar *tld_var = (TldVar *)tld;
7549 ConstExprValue *var_value = tld_var->var->const_value;
7550 ZigValue *var_value = tld_var->var->const_value;
75507551 assert(var_value != nullptr);
75517552 return var_value;
75527553}
......@@ -7733,9 +7734,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f
77337734}
77347735
77357736Error 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)
77377738{
7738 ConstExprValue ptr_val = {};
7739 ZigValue ptr_val = {};
77397740 ptr_val.special = ConstValSpecialStatic;
77407741 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);
77417742 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;
......@@ -9113,7 +9114,8 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
91139114 alloca_gen->base.id = IrInstructionIdAllocaGen;
91149115 alloca_gen->base.source_node = source_node;
91159116 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);
91179119 alloca_gen->base.ref_count = 1;
91189120 alloca_gen->name_hint = name_hint;
91199121 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,
2525 bool is_const, bool is_volatile, PtrLen ptr_len,
2626 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,
2727 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field,
28 ConstExprValue *sentinel);
28 ZigValue *sentinel);
2929uint64_t type_size(CodeGen *g, ZigType *type_entry);
3030uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
3131ZigType *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);
3434ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
3535ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
3636ZigType *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);
3838ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
3939ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
4040 AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);
......@@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope);
9595ScopeTypeOf *get_scope_typeof(Scope *scope);
9696void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
9797ZigVar *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);
9999ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
100100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);
101101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);
......@@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
105105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);
106106void complete_enum(CodeGen *g, ZigType *enum_type);
107107bool ir_get_var_is_comptime(ZigVar *var);
108bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b);
109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);
108bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b);
109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max);
110110void 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
114114ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent);
115115ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent);
......@@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct
124124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
127void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
128ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
127void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
131ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
130void init_const_bigint(ZigValue *const_val, 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);
134ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
133void init_const_unsigned_negative(ZigValue *const_val, 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);
137ConstExprValue *create_const_signed(ZigType *type, int64_t x);
136void init_const_signed(ZigValue *const_val, 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);
140ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142void init_const_float(ConstExprValue *const_val, ZigType *type, double value);
143ConstExprValue *create_const_float(ZigType *type, double value);
142void init_const_float(ZigValue *const_val, 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);
146ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);
145void init_const_enum(ZigValue *const_val, 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);
149ConstExprValue *create_const_bool(CodeGen *g, bool value);
148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149ZigValue *create_const_bool(CodeGen *g, bool value);
150150
151void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);
152ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);
151void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154void init_const_runtime(ConstExprValue *const_val, ZigType *type);
155ConstExprValue *create_const_runtime(ZigType *type);
154void init_const_runtime(ZigValue *const_val, 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);
158ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);
157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *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,
161161 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,
163163 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,
166166 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,
168168 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,
171171 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);
175ConstExprValue *create_const_arg_tuple(CodeGen *g, 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);
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);
178ConstExprValue *create_const_null(ZigType *type);
177void init_const_null(ZigValue *const_val, ZigType *type);
178ZigValue *create_const_null(ZigType *type);
179179
180ConstExprValue *create_const_vals(size_t count);
181ConstExprValue **alloc_const_vals_ptrs(size_t count);
182ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);
180ZigValue *create_const_vals(size_t count);
181ZigValue **alloc_const_vals_ptrs(size_t count);
182ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
183183
184184TypeStructField **alloc_type_struct_fields(size_t count);
185185TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
186186
187187ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
188void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
189void expand_undef_struct(CodeGen *g, ConstExprValue *const_val);
190void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);
188void expand_undef_array(CodeGen *g, ZigValue *const_val);
189void expand_undef_struct(CodeGen *g, ZigValue *const_val);
190void update_compile_var(CodeGen *g, Buf *name, ZigValue *value);
191191
192192const char *type_id_name(ZigTypeId id);
193193ZigTypeId type_id_at_index(size_t index);
......@@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
201201ZigType *get_align_amt_type(CodeGen *g);
202202ZigPackage *new_anonymous_package(void);
203203
204Buf *const_value_to_buffer(ConstExprValue *const_val);
204Buf *const_value_to_buffer(ZigValue *const_val);
205205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);
206206void 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);
210210ZigType *get_stack_trace_type(CodeGen *g);
211211bool 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);
242242OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);
243243
244244Error 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
247247void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
248248Buf *type_bare_name(ZigType *t);
......@@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
256256
257257void src_assert(bool ok, AstNode *source_node);
258258bool 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,
260260 Buf *type_name, UndefAllowed undef);
261261
262262void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);
263263bool fn_is_async(ZigFn *fn);
264264
265Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align);
266Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val,
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, ZigValue *type_val,
267267 size_t *abi_size, size_t *size_in_bits);
268Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,
269 ConstExprValue *parent_type_val, bool *is_zero_bits);
268Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
269 ZigValue *parent_type_val, bool *is_zero_bits);
270270ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);
271271ZigType *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,
276276 ZigType *var_type, const char *name_hint);
277277Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
278278 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);
280280#endif
src/bigint.cpp+5
......@@ -195,6 +195,11 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {
195195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);
196196}
197197
198void bigint_deinit(BigInt *bi) {
199 if (bi->digit_count > 1)
200 deallocate<uint64_t>(bi->data.digits, bi->digit_count);
201}
202
198203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
199204 float128_t zero;
200205 ui32_to_f128M(0, &zero);
src/bigint.hpp+1
......@@ -34,6 +34,7 @@ void bigint_init_signed(BigInt *dest, int64_t x);
3434void bigint_init_bigint(BigInt *dest, const BigInt *src);
3535void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);
3636void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);
37void bigint_deinit(BigInt *bi);
3738
3839// panics if number won't fit
3940uint64_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) {
185185}
186186
187187
188static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);
189static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name);
190static LLVMValueRef gen_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, ZigValue *const_val, const char *name);
190static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name);
191191static 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);
193193static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
194194static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
195195static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
......@@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
945945}
946946
947947static 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];
949949 if (!val->global_refs->llvm_global) {
950950
951951 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;
953953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);
954954
955955 render_const_val(g, val, "");
......@@ -1700,37 +1700,37 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
17001700
17011701static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
17021702 Error err;
1703 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) {
1703 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown))) {
17041704 codegen_report_errors_and_exit(g);
17051705 }
1706 if (!type_has_bits(instruction->value.type))
1706 if (!type_has_bits(instruction->value->type))
17071707 return nullptr;
17081708 if (!instruction->llvm_value) {
17091709 if (instruction->id == IrInstructionIdAwaitGen) {
17101710 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);
17111711 if (await->result_loc != nullptr) {
17121712 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);
17141714 }
17151715 }
17161716 if (instruction->spill != nullptr) {
1717 ZigType *ptr_type = instruction->spill->value.type;
1717 ZigType *ptr_type = instruction->spill->value->type;
17181718 ir_assert(ptr_type->id == ZigTypeIdPointer, instruction);
17191719 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);
17211721 }
1722 ir_assert(instruction->value.special != ConstValSpecialRuntime, instruction);
1723 assert(instruction->value.type);
1724 render_const_val(g, &instruction->value, "");
1722 ir_assert(instruction->value->special != ConstValSpecialRuntime, instruction);
1723 assert(instruction->value->type);
1724 render_const_val(g, instruction->value, "");
17251725 // we might have to do some pointer casting here due to the way union
17261726 // values are rendered with a type other than the one we expect
1727 if (handle_is_ptr(instruction->value.type)) {
1728 render_const_val_global(g, &instruction->value, "");
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), "");
1727 if (handle_is_ptr(instruction->value->type)) {
1728 render_const_val_global(g, instruction->value, "");
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), "");
17311731 } else {
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value,
1733 get_llvm_type(g, instruction->value.type), "");
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_value,
1733 get_llvm_type(g, instruction->value->type), "");
17341734 }
17351735 assert(instruction->llvm_value);
17361736 }
......@@ -1791,7 +1791,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
17911791 if (src_i >= fn_walk->data.call.inst->arg_count)
17921792 return false;
17931793 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
1794 ty = arg->value.type;
1794 ty = arg->value->type;
17951795 source_node = arg->source_node;
17961796 val = ir_llvm_value(g, arg);
17971797 break;
......@@ -2029,7 +2029,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
20292029 bool is_var_args = fn_walk->data.call.is_var_args;
20302030 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
20312031 IrInstruction *param_instruction = instruction->args[call_i];
2032 ZigType *param_type = param_instruction->value.type;
2032 ZigType *param_type = param_instruction->value->type;
20332033 if (is_var_args || type_has_bits(param_type)) {
20342034 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
20352035 assert(param_value);
......@@ -2345,13 +2345,13 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
23452345static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
23462346 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;
23492349 bool operand_has_bits = (operand_type != nullptr) && type_has_bits(operand_type);
23502350 ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
23512351 bool ret_type_has_bits = type_has_bits(ret_type);
23522352
23532353 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);
23552355 if (need_store) {
23562356 // It didn't get written to the result ptr. We do that now.
23572357 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
24482448 return nullptr;
24492449 }
24502450 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);
24522452 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
2453 ZigType *return_type = instruction->operand->value.type;
2453 ZigType *return_type = instruction->operand->value->type;
24542454 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
24552455 LLVMBuildRetVoid(g->builder);
24562456 } 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,
27842784 IrInstruction *op1 = bin_op_instruction->op1;
27852785 IrInstruction *op2 = bin_op_instruction->op2;
27862786
2787 ZigType *operand_type = op1->value.type;
2787 ZigType *operand_type = op1->value->type;
27882788 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
27892789
27902790 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
......@@ -2884,7 +2884,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
28842884 case IrBinOpBitShiftLeftExact:
28852885 {
28862886 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);
28882888 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
28892889 if (is_sloppy) {
28902890 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");
......@@ -2900,7 +2900,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
29002900 case IrBinOpBitShiftRightExact:
29012901 {
29022902 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);
29042904 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
29052905 if (is_sloppy) {
29062906 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
29902990static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
29912991 IrInstructionResizeSlice *instruction)
29922992{
2993 ZigType *actual_type = instruction->operand->value.type;
2994 ZigType *wanted_type = instruction->base.value.type;
2993 ZigType *actual_type = instruction->operand->value->type;
2994 ZigType *wanted_type = instruction->base.value->type;
29952995 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);
29962996 assert(expr_val);
29972997
......@@ -3058,8 +3058,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
30583058static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
30593059 IrInstructionCast *cast_instruction)
30603060{
3061 ZigType *actual_type = cast_instruction->value->value.type;
3062 ZigType *wanted_type = cast_instruction->base.value.type;
3061 ZigType *actual_type = cast_instruction->value->value->type;
3062 ZigType *wanted_type = cast_instruction->base.value->type;
30633063 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
30643064 assert(expr_val);
30653065
......@@ -3136,8 +3136,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
31363136static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,
31373137 IrInstructionPtrOfArrayToSlice *instruction)
31383138{
3139 ZigType *actual_type = instruction->operand->value.type;
3140 ZigType *slice_type = instruction->base.value.type;
3139 ZigType *actual_type = instruction->operand->value->type;
3140 ZigType *slice_type = instruction->base.value->type;
31413141 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
31423142 size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
31433143 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
31733173static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
31743174 IrInstructionPtrCastGen *instruction)
31753175{
3176 ZigType *wanted_type = instruction->base.value.type;
3176 ZigType *wanted_type = instruction->base.value->type;
31773177 if (!type_has_bits(wanted_type)) {
31783178 return nullptr;
31793179 }
......@@ -3199,8 +3199,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
31993199static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
32003200 IrInstructionBitCastGen *instruction)
32013201{
3202 ZigType *wanted_type = instruction->base.value.type;
3203 ZigType *actual_type = instruction->operand->value.type;
3202 ZigType *wanted_type = instruction->base.value->type;
3203 ZigType *actual_type = instruction->operand->value->type;
32043204 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
32053205
32063206 bool wanted_is_ptr = handle_is_ptr(wanted_type);
......@@ -3223,7 +3223,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
32233223static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
32243224 IrInstructionWidenOrShorten *instruction)
32253225{
3226 ZigType *actual_type = instruction->target->value.type;
3226 ZigType *actual_type = instruction->target->value->type;
32273227 // TODO instead of this logic, use the Noop instruction to change the type from
32283228 // enum_tag to the underlying int type
32293229 ZigType *int_type;
......@@ -3234,11 +3234,11 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
32343234 }
32353235 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
32363236 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);
32383238}
32393239
32403240static 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;
32423242 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
32433243 if (!ptr_allows_addr_zero(wanted_type) && ir_want_runtime_safety(g, &instruction->base)) {
32443244 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(target_val));
......@@ -3256,19 +3256,19 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
32563256}
32573257
32583258static 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;
32603260 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
32613261 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
32623262}
32633263
32643264static 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;
32663266 assert(wanted_type->id == ZigTypeIdEnum);
32673267 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
32683268
32693269 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
32703270 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
32733273 if (ir_want_runtime_safety(g, &instruction->base)) {
32743274 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,
32893289}
32903290
32913291static 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;
32933293 assert(wanted_type->id == ZigTypeIdErrorSet);
32943294
3295 ZigType *actual_type = instruction->target->value.type;
3295 ZigType *actual_type = instruction->target->value->type;
32963296 assert(actual_type->id == ZigTypeIdInt);
32973297 assert(!actual_type->data.integral.is_signed);
32983298
......@@ -3306,11 +3306,11 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
33063306}
33073307
33083308static 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;
33103310 assert(wanted_type->id == ZigTypeIdInt);
33113311 assert(!wanted_type->data.integral.is_signed);
33123312
3313 ZigType *actual_type = instruction->target->value.type;
3313 ZigType *actual_type = instruction->target->value->type;
33143314 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33153315
33163316 if (actual_type->id == ZigTypeIdErrorSet) {
......@@ -3360,7 +3360,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
33603360static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
33613361 IrUnOp op_id = un_op_instruction->op_id;
33623362 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;
33643364 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
33653365
33663366 switch (op_id) {
......@@ -3419,12 +3419,12 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrI
34193419static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
34203420 IrInstructionLoadPtrGen *instruction)
34213421{
3422 ZigType *child_type = instruction->base.value.type;
3422 ZigType *child_type = instruction->base.value->type;
34233423 if (!type_has_bits(child_type))
34243424 return nullptr;
34253425
34263426 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
3427 ZigType *ptr_type = instruction->ptr->value.type;
3427 ZigType *ptr_type = instruction->ptr->value->type;
34283428 assert(ptr_type->id == ZigTypeIdPointer);
34293429
34303430 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,
34743474 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");
34753475}
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) {
34783478 switch (const_val->data.x_array.special) {
34793479 case ConstArraySpecialUndef:
34803480 return true;
......@@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size
34903490 zig_unreachable();
34913491}
34923492
3493static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {
3493static bool value_is_all_undef(CodeGen *g, ZigValue *const_val) {
34943494 Error err;
34953495 if (const_val->special == ConstValSpecialLazy &&
34963496 (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_
36223622static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
36233623 Error err;
36243624
3625 ZigType *ptr_type = instruction->ptr->value.type;
3625 ZigType *ptr_type = instruction->ptr->value->type;
36263626 assert(ptr_type->id == ZigTypeIdPointer);
36273627 bool ptr_type_has_bits;
36283628 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
36393639 return nullptr;
36403640 }
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);
36433643 if (have_init_expr) {
36443644 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
36453645 LLVMValueRef value = ir_llvm_value(g, instruction->value);
36463646 gen_assign_raw(g, ptr, ptr_type, value);
36473647 } 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,
36493649 ir_llvm_value(g, instruction->ptr));
36503650 }
36513651 return nullptr;
......@@ -3658,14 +3658,14 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
36583658 LLVMValueRef index = ir_llvm_value(g, instruction->index);
36593659 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, "");
36623662 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);
36643664 return nullptr;
36653665}
36663666
36673667static 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)
36693669 return ir_llvm_value(g, &instruction->base);
36703670 ZigVar *var = instruction->var;
36713671 if (type_has_bits(var->var_type)) {
......@@ -3679,7 +3679,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
36793679static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
36803680 IrInstructionReturnPtr *instruction)
36813681{
3682 if (!type_has_bits(instruction->base.value.type))
3682 if (!type_has_bits(instruction->base.value->type))
36833683 return nullptr;
36843684 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);
36853685 return g->cur_ret_ptr;
......@@ -3687,7 +3687,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
36873687
36883688static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
36893689 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;
36913691 assert(array_ptr_type->id == ZigTypeIdPointer);
36923692 ZigType *array_type = array_ptr_type->data.pointer.child_type;
36933693 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
37193719 if (child_type->id == ZigTypeIdStruct &&
37203720 child_type->data.structure.layout == ContainerLayoutPacked)
37213721 {
3722 ZigType *ptr_type = instruction->base.value.type;
3722 ZigType *ptr_type = instruction->base.value->type;
37233723 size_t host_int_bytes = ptr_type->data.pointer.host_int_bytes;
37243724 if (host_int_bytes != 0) {
37253725 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
39413941 } else {
39423942 assert(instruction->fn_ref);
39433943 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;
39453945 callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync;
39463946 }
39473947
......@@ -3975,8 +3975,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
39753975 LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), "");
39763976 }
39773977 } else {
3978 if (instruction->new_stack->value.type->id == ZigTypeIdPointer &&
3979 instruction->new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
3978 if (instruction->new_stack->value->type->id == ZigTypeIdPointer &&
3979 instruction->new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
39803980 {
39813981 frame_result_loc = ir_llvm_value(g, instruction->new_stack);
39823982 } else {
......@@ -4189,7 +4189,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
41894189 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
41904190 if (instruction->new_stack != nullptr) {
41914191 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), "");
41934193 }
41944194 return nullptr;
41954195 } 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
42144214 LLVMPositionBuilderAtEnd(g->builder, ok_block);
42154215 }
42164216
4217 ZigType *result_type = instruction->base.value.type;
4217 ZigType *result_type = instruction->base.value->type;
42184218 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);
42194219 return gen_await_early_return(g, &instruction->base, frame_result_loc,
42204220 result_type, ptr_result_type, result_loc, true);
......@@ -4285,7 +4285,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
42854285 return result_loc;
42864286 } else if (handle_is_ptr(src_return_type)) {
42874287 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));
42894289 return result_loc;
42904290 } else if (!callee_is_async && instruction->modifier == CallModifierAsync) {
42914291 LLVMBuildStore(g->builder, result, ret_ptr);
......@@ -4300,12 +4300,12 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
43004300{
43014301 Error err;
43024302
4303 if (instruction->base.value.special != ConstValSpecialRuntime)
4303 if (instruction->base.value->special != ConstValSpecialRuntime)
43044304 return nullptr;
43054305
43064306 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
43074307 // 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;
43094309 TypeStructField *field = instruction->field;
43104310
43114311 if (!type_has_bits(field->type_entry))
......@@ -4324,7 +4324,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
43244324
43254325 ir_assert(field->gen_index != SIZE_MAX, &instruction->base);
43264326 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;
43284328 ir_assert(res_type->id == ZigTypeIdPointer, &instruction->base);
43294329 if (res_type->data.pointer.host_int_bytes != 0) {
43304330 // 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
43404340static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
43414341 IrInstructionUnionFieldPtr *instruction)
43424342{
4343 if (instruction->base.value.special != ConstValSpecialRuntime)
4343 if (instruction->base.value->special != ConstValSpecialRuntime)
43444344 return nullptr;
43454345
4346 ZigType *union_ptr_type = instruction->union_ptr->value.type;
4346 ZigType *union_ptr_type = instruction->union_ptr->value->type;
43474347 assert(union_ptr_type->id == ZigTypeIdPointer);
43484348 ZigType *union_type = union_ptr_type->data.pointer.child_type;
43494349 assert(union_type->id == ZigTypeIdUnion);
......@@ -4528,7 +4528,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
45284528 buf_append_char(&constraint_buf, ',');
45294529 }
45304530
4531 ZigType *const type = ir_input->value.type;
4531 ZigType *const type = ir_input->value->type;
45324532 LLVMTypeRef type_ref = get_llvm_type(g, type);
45334533 LLVMValueRef value_ref = ir_llvm_value(g, ir_input);
45344534 // Handle integers of non pot bitsize by widening them.
......@@ -4558,7 +4558,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
45584558 if (instruction->return_count == 0) {
45594559 ret_type = LLVMVoidType();
45604560 } else {
4561 ret_type = get_llvm_type(g, instruction->base.value.type);
4561 ret_type = get_llvm_type(g, instruction->base.value->type);
45624562 }
45634563 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
45884588static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,
45894589 IrInstructionTestNonNull *instruction)
45904590{
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));
45924592}
45934593
45944594static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,
45954595 IrInstructionOptionalUnwrapPtr *instruction)
45964596{
4597 if (instruction->base.value.special != ConstValSpecialRuntime)
4597 if (instruction->base.value->special != ConstValSpecialRuntime)
45984598 return nullptr;
45994599
4600 ZigType *ptr_type = instruction->base_ptr->value.type;
4600 ZigType *ptr_type = instruction->base_ptr->value->type;
46014601 assert(ptr_type->id == ZigTypeIdPointer);
46024602 ZigType *maybe_type = ptr_type->data.pointer.child_type;
46034603 assert(maybe_type->id == ZigTypeIdOptional);
......@@ -4695,7 +4695,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
46954695}
46964696
46974697static 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;
46994699 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
47004700 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
47014701 LLVMValueRef params[] {
......@@ -4703,11 +4703,11 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
47034703 LLVMConstNull(LLVMInt1Type()),
47044704 };
47054705 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);
47074707}
47084708
47094709static 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;
47114711 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
47124712 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
47134713 LLVMValueRef params[] {
......@@ -4715,12 +4715,12 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
47154715 LLVMConstNull(LLVMInt1Type()),
47164716 };
47174717 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);
47194719}
47204720
47214721static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {
4722 uint64_t len_a = instruction->a->value.type->data.vector.len;
4723 uint64_t len_mask = instruction->mask->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;
47244724
47254725 // LLVM uses integers larger than the length of the first array to
47264726 // index into the second array. This was deemed unnecessarily fragile
......@@ -4730,10 +4730,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
47304730 IrInstruction *mask = instruction->mask;
47314731 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
47324732 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) {
47344734 values[i] = LLVMGetUndef(LLVMInt32Type());
47354735 } 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);
47374737 uint32_t index_val = (v >= 0) ? (uint32_t)v : (uint32_t)~v + (uint32_t)len_a;
47384738 values[i] = LLVMConstInt(LLVMInt32Type(), index_val, false);
47394739 }
......@@ -4749,10 +4749,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
47494749}
47504750
47514751static 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;
47534753 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
47544754 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);
47564756 LLVMTypeRef mask_llvm_type = LLVMVectorType(LLVMInt32Type(), len);
47574757 LLVMValueRef undef_vector = LLVMGetUndef(op_llvm_type);
47584758 LLVMValueRef op_vector = LLVMBuildInsertElement(g->builder, undef_vector,
......@@ -4761,11 +4761,11 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
47614761}
47624762
47634763static 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;
47654765 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
47664766 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
47674767 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);
47694769}
47704770
47714771static 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
47814781}
47824782
47834783static 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))
47854785 return nullptr;
47864786
47874787 LLVMTypeRef phi_type;
4788 if (handle_is_ptr(instruction->base.value.type)) {
4789 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value.type), 0);
4788 if (handle_is_ptr(instruction->base.value->type)) {
4789 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0);
47904790 } else {
4791 phi_type = get_llvm_type(g, instruction->base.value.type);
4791 phi_type = get_llvm_type(g, instruction->base.value->type);
47924792 }
47934793
47944794 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
......@@ -4803,11 +4803,11 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
48034803}
48044804
48054805static 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)) {
48074807 return nullptr;
48084808 }
48094809 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)) {
48114811 return value;
48124812 } else {
48134813 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) {
49404940static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
49414941 IrInstructionTagName *instruction)
49424942{
4943 ZigType *enum_type = instruction->target->value.type;
4943 ZigType *enum_type = instruction->target->value->type;
49444944 assert(enum_type->id == ZigTypeIdEnum);
49454945
49464946 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
49534953static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
49544954 IrInstructionFieldParentPtr *instruction)
49554955{
4956 ZigType *container_ptr_type = instruction->base.value.type;
4956 ZigType *container_ptr_type = instruction->base.value->type;
49574957 assert(container_ptr_type->id == ZigTypeIdPointer);
49584958
49594959 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
49864986 return target_val;
49874987 }
49884988
4989 ZigType *target_type = instruction->base.value.type;
4989 ZigType *target_type = instruction->base.value->type;
49904990 uint32_t align_bytes;
49914991 LLVMValueRef ptr_val;
49924992
......@@ -5089,7 +5089,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
50895089 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
50905090 success_order, failure_order, instruction->is_weak);
50915091
5092 ZigType *optional_type = instruction->base.value.type;
5092 ZigType *optional_type = instruction->base.value->type;
50935093 assert(optional_type->id == ZigTypeIdOptional);
50945094 ZigType *child_type = optional_type->data.maybe.child_type;
50955095
......@@ -5100,7 +5100,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
51005100 }
51015101
51025102 // 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)) {
51045104 return nullptr;
51055105 }
51065106
......@@ -5127,8 +5127,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst
51275127
51285128static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
51295129 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5130 ZigType *dest_type = instruction->base.value.type;
5131 ZigType *src_type = instruction->target->value.type;
5130 ZigType *dest_type = instruction->base.value->type;
5131 ZigType *src_type = instruction->target->value->type;
51325132 if (dest_type == src_type) {
51335133 // no-op
51345134 return target_val;
......@@ -5147,10 +5147,10 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
51475147 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);
51485148 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;
51515151 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);
51545154 LLVMValueRef fill_char;
51555155 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {
51565156 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
......@@ -5176,8 +5176,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
51765176 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
51775177 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
51785178
5179 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;
5180 ZigType *src_ptr_type = instruction->src_ptr->value.type;
5179 ZigType *dest_ptr_type = instruction->dest_ptr->value->type;
5180 ZigType *src_ptr_type = instruction->src_ptr->value->type;
51815181
51825182 assert(dest_ptr_type->id == ZigTypeIdPointer);
51835183 assert(src_ptr_type->id == ZigTypeIdPointer);
......@@ -5190,7 +5190,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
51905190
51915191static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {
51925192 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;
51945194 assert(array_ptr_type->id == ZigTypeIdPointer);
51955195 ZigType *array_type = array_ptr_type->data.pointer.child_type;
51965196 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
52135213 end_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, array_type->data.array.len, false);
52145214 }
52155215 if (want_runtime_safety) {
5216 if (instruction->start->value.special == ConstValSpecialRuntime || instruction->end) {
5216 if (instruction->start->value->special == ConstValSpecialRuntime || instruction->end) {
52175217 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
52185218 }
52195219 if (instruction->end) {
......@@ -5255,13 +5255,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
52555255 }
52565256
52575257 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;
52595259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
52605260 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");
52615261 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
52625262 }
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;
52655265 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
52665266 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
52675267 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
......@@ -5375,8 +5375,8 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
53755375 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
53765376 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,
5379 instruction->op1->value.type, op2);
5378 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, instruction->op2->value->type,
5379 instruction->op1->value->type, op2);
53805380
53815381 LLVMValueRef result = LLVMBuildShl(g->builder, op1, op2_casted, "");
53825382 LLVMValueRef orig_val;
......@@ -5387,7 +5387,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
53875387 }
53885388 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
53925392 return overflow_bit;
53935393}
......@@ -5425,13 +5425,13 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
54255425 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");
54265426 LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");
54275427 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
54305430 return overflow_bit;
54315431}
54325432
54335433static 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;
54355435 ZigType *payload_type = err_union_type->data.error_union.payload_type;
54365436 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
54505450static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
54515451 IrInstructionUnwrapErrCode *instruction)
54525452{
5453 if (instruction->base.value.special != ConstValSpecialRuntime)
5453 if (instruction->base.value->special != ConstValSpecialRuntime)
54545454 return nullptr;
54555455
5456 ZigType *ptr_type = instruction->err_union_ptr->value.type;
5456 ZigType *ptr_type = instruction->err_union_ptr->value->type;
54575457 assert(ptr_type->id == ZigTypeIdPointer);
54585458 ZigType *err_union_type = ptr_type->data.pointer.child_type;
54595459 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
54705470static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
54715471 IrInstructionUnwrapErrPayload *instruction)
54725472{
5473 if (instruction->base.value.special != ConstValSpecialRuntime)
5473 if (instruction->base.value->special != ConstValSpecialRuntime)
54745474 return nullptr;
54755475
54765476 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&
54775477 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))
54795479 return nullptr;
5480 ZigType *ptr_type = instruction->value->value.type;
5480 ZigType *ptr_type = instruction->value->value->type;
54815481 assert(ptr_type->id == ZigTypeIdPointer);
54825482 ZigType *err_union_type = ptr_type->data.pointer.child_type;
54835483 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
55215521}
55225522
55235523static 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
55265526 assert(wanted_type->id == ZigTypeIdOptional);
55275527
......@@ -5548,7 +5548,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
55485548 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
55495549
55505550 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, "");
5551 // child_type and instruction->value->value.type may differ by constness
5551 // child_type and instruction->value->value->type may differ by constness
55525552 gen_assign_raw(g, val_ptr, get_pointer_to_type(g, child_type, false), payload_val);
55535553 LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_null_index, "");
55545554 gen_store_untyped(g, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr, 0, false);
......@@ -5557,7 +5557,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
55575557}
55585558
55595559static 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
55625562 assert(wanted_type->id == ZigTypeIdErrorUnion);
55635563
......@@ -5577,7 +5577,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
55775577}
55785578
55795579static 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
55825582 assert(wanted_type->id == ZigTypeIdErrorUnion);
55835583
......@@ -5608,7 +5608,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
56085608}
56095609
56105610static 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
56135613 ZigType *tag_type = union_type->data.unionation.tag_type;
56145614 if (!type_has_bits(tag_type))
......@@ -5636,7 +5636,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
56365636 IrInstructionAtomicRmw *instruction)
56375637{
56385638 bool is_signed;
5639 ZigType *operand_type = instruction->operand->value.type;
5639 ZigType *operand_type = instruction->operand->value->type;
56405640 if (operand_type->id == ZigTypeIdInt) {
56415641 is_signed = operand_type->data.integral.is_signed;
56425642 } else {
......@@ -5665,7 +5665,7 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
56655665{
56665666 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
56675667 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, "");
56695669 LLVMSetOrdering(load_inst, ordering);
56705670 return load_inst;
56715671}
......@@ -5676,15 +5676,15 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
56765676 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
56775677 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
56785678 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);
56805680 LLVMSetOrdering(store_inst, ordering);
56815681 return nullptr;
56825682}
56835683
56845684static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {
56855685 LLVMValueRef op = ir_llvm_value(g, instruction->op1);
5686 assert(instruction->base.value.type->id == ZigTypeIdFloat);
5687 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFloatOp, instruction->op);
5686 assert(instruction->base.value->type->id == ZigTypeIdFloat);
5687 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->op);
56885688 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
56895689}
56905690
......@@ -5692,9 +5692,9 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
56925692 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
56935693 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
56945694 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
5695 assert(instruction->base.value.type->id == ZigTypeIdFloat ||
5696 instruction->base.value.type->id == ZigTypeIdVector);
5697 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd);
5695 assert(instruction->base.value->type->id == ZigTypeIdFloat ||
5696 instruction->base.value->type->id == ZigTypeIdVector);
5697 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd);
56985698 LLVMValueRef args[3] = {
56995699 op1,
57005700 op2,
......@@ -5705,7 +5705,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
57055705
57065706static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {
57075707 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5708 ZigType *expr_type = instruction->base.value.type;
5708 ZigType *expr_type = instruction->base.value->type;
57095709 bool is_vector = expr_type->id == ZigTypeIdVector;
57105710 ZigType *int_type = is_vector ? expr_type->data.vector.elem_type : expr_type;
57115711 assert(int_type->id == ZigTypeIdInt);
......@@ -5739,16 +5739,16 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
57395739
57405740static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {
57415741 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5742 ZigType *int_type = instruction->base.value.type;
5742 ZigType *int_type = instruction->base.value->type;
57435743 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);
57455745 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
57465746}
57475747
57485748static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,
57495749 IrInstructionVectorToArray *instruction)
57505750{
5751 ZigType *array_type = instruction->base.value.type;
5751 ZigType *array_type = instruction->base.value->type;
57525752 assert(array_type->id == ZigTypeIdArray);
57535753 assert(handle_is_ptr(array_type));
57545754 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
57585758 bool bitcast_ok = elem_type->size_in_bits == elem_type->abi_size * 8;
57595759 if (bitcast_ok) {
57605760 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, result_loc,
5761 LLVMPointerType(get_llvm_type(g, instruction->vector->value.type), 0), "");
5762 uint32_t alignment = get_ptr_align(g, instruction->result_loc->value.type);
5761 LLVMPointerType(get_llvm_type(g, instruction->vector->value->type), 0), "");
5762 uint32_t alignment = get_ptr_align(g, instruction->result_loc->value->type);
57635763 gen_store_untyped(g, vector, casted_ptr, alignment, false);
57645764 } else {
57655765 // 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
57675767 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
57685768 LLVMTypeRef u32_type_ref = LLVMInt32Type();
57695769 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++) {
57715771 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);
57725772 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);
57735773 LLVMValueRef indexes[] = { zero, index_usize };
......@@ -5782,7 +5782,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
57825782static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,
57835783 IrInstructionArrayToVector *instruction)
57845784{
5785 ZigType *vector_type = instruction->base.value.type;
5785 ZigType *vector_type = instruction->base.value->type;
57865786 assert(vector_type->id == ZigTypeIdVector);
57875787 assert(!handle_is_ptr(vector_type));
57885788 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);
......@@ -5793,7 +5793,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
57935793 if (bitcast_ok) {
57945794 LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, array_ptr,
57955795 LLVMPointerType(vector_type_ref, 0), "");
5796 ZigType *array_type = instruction->array->value.type;
5796 ZigType *array_type = instruction->array->value->type;
57975797 assert(array_type->id == ZigTypeIdArray);
57985798 uint32_t alignment = get_abi_alignment(g, array_type->data.array.child_type);
57995799 return gen_load_untyped(g, casted_ptr, alignment, false, "");
......@@ -5804,7 +5804,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
58045804 LLVMTypeRef u32_type_ref = LLVMInt32Type();
58055805 LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false);
58065806 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++) {
58085808 LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false);
58095809 LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false);
58105810 LLVMValueRef indexes[] = { zero, index_usize };
......@@ -5820,7 +5820,7 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
58205820 IrInstructionAssertZero *instruction)
58215821{
58225822 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5823 ZigType *int_type = instruction->target->value.type;
5823 ZigType *int_type = instruction->target->value->type;
58245824 if (ir_want_runtime_safety(g, &instruction->base)) {
58255825 return gen_assert_zero(g, target, int_type);
58265826 }
......@@ -5831,7 +5831,7 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
58315831 IrInstructionAssertNonNull *instruction)
58325832{
58335833 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
58365836 if (target_type->id == ZigTypeIdPointer) {
58375837 assert(target_type->data.pointer.ptr_len == PtrLenC);
......@@ -5917,7 +5917,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
59175917 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
59185918 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
59195919 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;
59215921 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);
59225922
59235923 LLVMValueRef result_loc = (instruction->result_loc == nullptr) ?
......@@ -6000,7 +6000,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
60006000
60016001static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {
60026002 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
6003 ZigType *frame_type = instruction->frame->value.type;
6003 ZigType *frame_type = instruction->frame->value->type;
60046004 assert(frame_type->id == ZigTypeIdAnyFrame);
60056005
60066006 gen_resume(g, nullptr, frame, ResumeIdManual);
......@@ -6354,7 +6354,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
63546354 instruction->llvm_value = ir_render_instruction(g, executable, instruction);
63556355 if (instruction->spill != nullptr) {
63566356 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);
63586358 instruction->llvm_value = nullptr;
63596359 }
63606360 }
......@@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
63626362 }
63636363}
63646364
6365static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index);
6366static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index);
6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val);
6368static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val);
6369static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val);
6370static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val);
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, ZigValue *array_const_val, size_t index);
6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *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, ZigValue *err_union_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) {
63736373 switch (parent->id) {
63746374 case ConstParentIdNone:
63756375 render_const_val(g, val, "");
......@@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent
63976397 zig_unreachable();
63986398}
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) {
64016401 expand_undef_array(g, array_const_val);
64026402 ConstParent *parent = &array_const_val->parent;
64036403 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
64236423 }
64246424}
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) {
64276427 ConstParent *parent = &struct_const_val->parent;
64286428 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
64356435 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
64366436}
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) {
64396439 ConstParent *parent = &err_union_const_val->parent;
64406440 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
64476447 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
64486448}
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) {
64516451 ConstParent *parent = &err_union_const_val->parent;
64526452 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
64596459 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
64606460}
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) {
64636463 ConstParent *parent = &optional_const_val->parent;
64646464 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
64716471 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
64726472}
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) {
64756475 ConstParent *parent = &union_const_val->parent;
64766476 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
64886488 return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1);
64896489}
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) {
64926492 switch (const_val->special) {
64936493 case ConstValSpecialLazy:
64946494 case ConstValSpecialRuntime:
......@@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
65556555 uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type);
65566556 size_t used_bits = 0;
65576557 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];
65596559 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val);
65606560
65616561 if (is_big_endian) {
......@@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu
66166616 return LLVMTypeOf(val) != get_llvm_type(g, type_entry);
66176617}
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) {
66206620 switch (const_val->data.x_ptr.special) {
66216621 case ConstPtrSpecialInvalid:
66226622 case ConstPtrSpecialDiscard:
......@@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
66246624 case ConstPtrSpecialRef:
66256625 {
66266626 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;
66286628 render_const_val(g, pointee, "");
66296629 render_const_val_global(g, pointee, "");
66306630 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
66346634 case ConstPtrSpecialBaseArray:
66356635 {
66366636 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;
66386638 assert(array_const_val->type->id == ZigTypeIdArray);
66396639 if (!type_has_bits(array_const_val->type)) {
66406640 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;
66426642 render_const_val(g, pointee, "");
66436643 render_const_val_global(g, pointee, "");
66446644 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
66616661 case ConstPtrSpecialBaseStruct:
66626662 {
66636663 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;
66656665 assert(struct_const_val->type->id == ZigTypeIdStruct);
66666666 if (!type_has_bits(struct_const_val->type)) {
66676667 // make this a null pointer
......@@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
66816681 case ConstPtrSpecialBaseErrorUnionCode:
66826682 {
66836683 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;
66856685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
66866686 if (!type_has_bits(err_union_const_val->type)) {
66876687 // make this a null pointer
......@@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
66986698 case ConstPtrSpecialBaseErrorUnionPayload:
66996699 {
67006700 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;
67026702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
67036703 if (!type_has_bits(err_union_const_val->type)) {
67046704 // make this a null pointer
......@@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
67156715 case ConstPtrSpecialBaseOptionalPayload:
67166716 {
67176717 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;
67196719 assert(optional_const_val->type->id == ZigTypeIdOptional);
67206720 if (!type_has_bits(optional_const_val->type)) {
67216721 // make this a null pointer
......@@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
67476747 zig_unreachable();
67486748}
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) {
67516751 uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value;
67526752 return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false);
67536753}
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) {
67566756 Error err;
67576757
67586758 ZigType *type_entry = const_val->type;
......@@ -6864,7 +6864,7 @@ check: switch (const_val->special) {
68646864 }
68656865
68666866 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];
68686868 LLVMValueRef val = gen_const_val(g, field_val, "");
68696869 fields[type_struct_field->gen_index] = val;
68706870 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) {
69216921 if (type_struct_field->gen_index == SIZE_MAX) {
69226922 continue;
69236923 }
6924 ConstExprValue *field_val = const_val->data.x_struct.fields[i];
6924 ZigValue *field_val = const_val->data.x_struct.fields[i];
69256925 assert(field_val->type != nullptr);
69266926 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
69276927 type_struct_field->type_entry)))
......@@ -6970,7 +6970,7 @@ check: switch (const_val->special) {
69706970 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
69716971 bool make_unnamed_struct = false;
69726972 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];
69746974 LLVMValueRef val = gen_const_val(g, elem_value, "");
69756975 values[i] = val;
69766976 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) {
70007000 case ConstArraySpecialNone: {
70017001 LLVMValueRef *values = allocate<LLVMValueRef>(len);
70027002 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];
70047004 values[i] = gen_const_val(g, elem_value, "");
70057005 }
70067006 return LLVMConstVector(values, len);
......@@ -7036,7 +7036,7 @@ check: switch (const_val->special) {
70367036
70377037 LLVMValueRef union_value_ref;
70387038 bool make_unnamed_struct;
7039 ConstExprValue *payload_value = const_val->data.x_union.payload;
7039 ZigValue *payload_value = const_val->data.x_union.payload;
70407040 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {
70417041 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)
70427042 return LLVMGetUndef(get_llvm_type(g, type_entry));
......@@ -7133,7 +7133,7 @@ check: switch (const_val->special) {
71337133 make_unnamed_struct = false;
71347134 } else {
71357135 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;
71377137 err_payload_value = gen_const_val(g, payload_val, "");
71387138 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value);
71397139 }
......@@ -7174,7 +7174,7 @@ check: switch (const_val->special) {
71747174 zig_unreachable();
71757175}
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) {
71787178 if (!const_val->global_refs)
71797179 const_val->global_refs = allocate<ConstGlobalRefs>(1);
71807180 if (!const_val->global_refs->llvm_value)
......@@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *
71847184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
71857185}
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) {
71887188 if (!const_val->global_refs)
71897189 const_val->global_refs = allocate<ConstGlobalRefs>(1);
71907190
......@@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) {
73247324
73257325 if (var->var_type->id == ZigTypeIdComptimeFloat) {
73267326 // Generate debug info for it but that's it.
7327 ConstExprValue *const_val = var->const_value;
7327 ZigValue *const_val = var->const_value;
73287328 assert(const_val->special != ConstValSpecialRuntime);
73297329 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
73307330 zig_unreachable();
......@@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) {
73327332 zig_panic("TODO debug info for var with ptr casted value");
73337333 }
73347334 ZigType *var_type = g->builtin_types.entry_f128;
7335 ConstExprValue coerced_value = {};
7335 ZigValue coerced_value = {};
73367336 coerced_value.special = ConstValSpecialStatic;
73377337 coerced_value.type = var_type;
73387338 coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
......@@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) {
73437343
73447344 if (var->var_type->id == ZigTypeIdComptimeInt) {
73457345 // Generate debug info for it but that's it.
7346 ConstExprValue *const_val = var->const_value;
7346 ZigValue *const_val = var->const_value;
73477347 assert(const_val->special != ConstValSpecialRuntime);
73487348 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
73497349 zig_unreachable();
......@@ -7514,12 +7514,12 @@ static void do_code_gen(CodeGen *g) {
75147514 call->frame_result_loc = all_calls_alloca;
75157515 }
75167516 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);
75187518 }
75197519 // allocate temporary stack data
75207520 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
75217521 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;
75237523 assert(ptr_type->id == ZigTypeIdPointer);
75247524 ZigType *child_type = ptr_type->data.pointer.child_type;
75257525 if (type_resolve(g, child_type, ResolveStatusSizeKnown))
......@@ -7528,8 +7528,8 @@ static void do_code_gen(CodeGen *g) {
75287528 continue;
75297529 if (instruction->base.ref_count == 0)
75307530 continue;
7531 if (instruction->base.value.special != ConstValSpecialRuntime) {
7532 if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special !=
7531 if (instruction->base.value->special != ConstValSpecialRuntime) {
7532 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
75337533 ConstValSpecialRuntime)
75347534 {
75357535 continue;
......@@ -8008,6 +8008,33 @@ static void define_builtin_types(CodeGen *g) {
80088008 }
80098009}
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
80118038static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
80128039 BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1);
80138040 buf_init_from_str(&builtin_fn->name, name);
......@@ -8629,15 +8656,18 @@ static void init(CodeGen *g) {
86298656 g->dummy_di_file = nullptr;
86308657
86318658 define_builtin_types(g);
8659 define_intern_values(g);
86328660
86338661 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);
86348662 g->invalid_instruction = &sentinel_instructions[0];
8635 g->invalid_instruction->value.type = g->builtin_types.entry_invalid;
8636 g->invalid_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);
8663 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
8664 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8665 g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86378666
86388667 g->unreach_instruction = &sentinel_instructions[1];
8639 g->unreach_instruction->value.type = g->builtin_types.entry_unreachable;
8640 g->unreach_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);
8668 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8669 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
8670 g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86418671
86428672 g->const_void_val.special = ConstValSpecialStatic;
86438673 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) {
90809110
90819111 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");
90849114 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
90859115 ZigType *struct_type = test_fn_type_val->data.x_type;
90869116 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
90879117 zig_unreachable();
90889118
9089 ConstExprValue *test_fn_array = create_const_vals(1);
9119 ZigValue *test_fn_array = create_const_vals(1);
90909120 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
90919121 test_fn_array->special = ConstValSpecialStatic;
90929122 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) {
91039133 continue;
91049134 }
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];
91079137 this_val->special = ConstValSpecialStatic;
91089138 this_val->type = struct_type;
91099139 this_val->parent.id = ConstParentIdArray;
......@@ -9111,11 +9141,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
91119141 this_val->parent.data.p_array.elem_index = i;
91129142 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
91139143
9114 ConstExprValue *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;
9144 ZigValue *name_field = this_val->data.x_struct.fields[0];
9145 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
91169146 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];
91199149 fn_field->type = fn_type;
91209150 fn_field->special = ConstValSpecialStatic;
91219151 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
......@@ -9124,7 +9154,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
91249154 }
91259155 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
91299159 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
91309160 assert(g->test_runner_package != nullptr);
......@@ -9221,7 +9251,7 @@ static void gen_root_source(CodeGen *g) {
92219251 report_errors_and_maybe_exit(g);
92229252 assert(builtin_tld->id == TldIdVar);
92239253 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;
92259255 assert(builtin_val->type->id == ZigTypeIdMetaType);
92269256 ZigType *builtin_type = builtin_val->data.x_type;
92279257
......@@ -9232,7 +9262,7 @@ static void gen_root_source(CodeGen *g) {
92329262 report_errors_and_maybe_exit(g);
92339263 assert(panic_tld->id == TldIdVar);
92349264 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;
92369266 assert(panic_fn_val->type->id == ZigTypeIdFn);
92379267 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);
92389268 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 {
361361};
362362
363363static 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) {
367367 Error err;
368368 if (value->type != ty) {
369369 return;
......@@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) {
660660 jw_string(jw, buf_ptr(file));
661661}
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) {
664664 Error err;
665665
666666 if (value->type != ty) {
......@@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
12491249 }
12501250 scope = scope->parent;
12511251 }
1252 ConstExprValue *result = entry->value;
1252 ZigValue *result = entry->value;
12531253
12541254 assert(fn != nullptr);
12551255
src/hash_map.hpp+6-6
......@@ -23,10 +23,10 @@ public:
2323 }
2424
2525 struct Entry {
26 bool used;
27 int distance_from_start_index;
2826 K key;
2927 V value;
28 bool used;
29 int distance_from_start_index;
3030 };
3131
3232 void clear() {
......@@ -187,10 +187,10 @@ private:
187187 if (distance_from_start_index > _max_distance_from_start_index)
188188 _max_distance_from_start_index = distance_from_start_index;
189189 *entry = {
190 true,
191 distance_from_start_index,
192190 key,
193191 value,
192 true,
193 distance_from_start_index,
194194 };
195195 key = tmp.key;
196196 value = tmp.value;
......@@ -208,10 +208,10 @@ private:
208208 if (distance_from_start_index > _max_distance_from_start_index)
209209 _max_distance_from_start_index = distance_from_start_index;
210210 *entry = {
211 true,
212 distance_from_start_index,
213211 key,
214212 value,
213 true,
214 distance_from_start_index,
215215 };
216216 return;
217217 }
src/ir.cpp+1682-1644
......@@ -19,7 +19,7 @@
1919#include <errno.h>
2020
2121struct IrExecContext {
22 ZigList<ConstExprValue *> mem_slot_list;
22 ZigList<ZigValue *> mem_slot_list;
2323};
2424
2525struct IrBuilder {
......@@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
204204static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);
205205static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
206206static 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);
208static void buf_write_value_bytes(CodeGen *codegen, 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, ZigValue *val);
209209static 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);
211211static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
212212 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
213static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
214static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);
213static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
214static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs);
215215static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
216216static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
217217 ZigType *ptr_type);
......@@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
244244 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
245245static 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) {
248248 assert(get_src_ptr_type(const_val->type) != nullptr);
249249 assert(const_val->special == ConstValSpecialStatic);
250 ConstExprValue *result;
250 ZigValue *result;
251251
252252 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
253253 case OnePossibleValueInvalid:
......@@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
265265 result = const_val->data.x_ptr.data.ref.pointee;
266266 break;
267267 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;
269269 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {
270270 result = array_val->type->data.array.sentinel;
271271 } else {
......@@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
275275 break;
276276 }
277277 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;
279279 expand_undef_struct(g, struct_val);
280280 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
281281 break;
......@@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) {
317317 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
318318}
319319
320// This function returns true when you can change the type of a ConstExprValue and the
320// This function returns true when you can change the type of a ZigValue and the
321321// value remains meaningful.
322322static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) {
323323 if (expected == actual)
......@@ -416,16 +416,16 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {
416416 return exec->c_import_buf;
417417}
418418
419static bool value_is_comptime(ConstExprValue *const_val) {
419static bool value_is_comptime(ZigValue *const_val) {
420420 return const_val->special != ConstValSpecialRuntime;
421421}
422422
423423static bool instr_is_comptime(IrInstruction *instruction) {
424 return value_is_comptime(&instruction->value);
424 return value_is_comptime(instruction->value);
425425}
426426
427427static 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;
429429}
430430
431431static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {
......@@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) {
449449}
450450
451451ZigType *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,
453453 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,
454454 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
11561156 special_instruction->base.source_node = source_node;
11571157 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
11581158 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;
11601177 return special_instruction;
11611178}
11621179
......@@ -1184,8 +1201,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so
11841201 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)
11851202{
11861203 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;
1188 cond_br_instruction->base.value.special = ConstValSpecialStatic;
1204 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1205 cond_br_instruction->base.value->special = ConstValSpecialStatic;
11891206 cond_br_instruction->condition = condition;
11901207 cond_br_instruction->then_block = then_block;
11911208 cond_br_instruction->else_block = else_block;
......@@ -1203,8 +1220,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
12031220 IrInstruction *operand)
12041221{
12051222 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);
1206 return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
1207 return_instruction->base.value.special = ConstValSpecialStatic;
1223 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1224 return_instruction->base.value->special = ConstValSpecialStatic;
12081225 return_instruction->operand = operand;
12091226
12101227 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
12131230}
12141231
12151232static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1216 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1217 const_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1218 const_instruction->base.value.special = ConstValSpecialStatic;
1233#ifdef ZIG_ENABLE_MEM_PROFILE
1234 memprof_intern_count.x_void += 1;
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;
12191239 return &const_instruction->base;
12201240}
12211241
12221242static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1223 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1224 const_instruction->base.value.special = ConstValSpecialUndef;
1225 const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef;
1243#ifdef ZIG_ENABLE_MEM_PROFILE
1244 memprof_intern_count.x_undefined += 1;
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;
12261249 return &const_instruction->base;
12271250}
12281251
12291252static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
12301253 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;
1232 const_instruction->base.value.special = ConstValSpecialStatic;
1233 bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value);
1254 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1255 const_instruction->base.value->special = ConstValSpecialStatic;
1256 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
12341257 return &const_instruction->base;
12351258}
12361259
12371260static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
12381261 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;
1240 const_instruction->base.value.special = ConstValSpecialStatic;
1241 bigint_init_bigint(&const_instruction->base.value.data.x_bigint, bigint);
1262 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1263 const_instruction->base.value->special = ConstValSpecialStatic;
1264 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);
12421265 return &const_instruction->base;
12431266}
12441267
12451268static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
12461269 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;
1248 const_instruction->base.value.special = ConstValSpecialStatic;
1249 bigfloat_init_bigfloat(&const_instruction->base.value.data.x_bigfloat, bigfloat);
1270 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;
1271 const_instruction->base.value->special = ConstValSpecialStatic;
1272 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);
12501273 return &const_instruction->base;
12511274}
12521275
12531276static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1254 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1255 const_instruction->base.value.type = irb->codegen->builtin_types.entry_null;
1256 const_instruction->base.value.special = ConstValSpecialStatic;
1277#ifdef ZIG_ENABLE_MEM_PROFILE
1278 memprof_intern_count.x_null += 1;
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;
12571283 return &const_instruction->base;
12581284}
12591285
12601286static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
12611287 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1262 const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize;
1263 const_instruction->base.value.special = ConstValSpecialStatic;
1264 bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value);
1288 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;
1289 const_instruction->base.value->special = ConstValSpecialStatic;
1290 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
12651291 return &const_instruction->base;
12661292}
12671293
......@@ -1269,9 +1295,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
12691295 ZigType *type_entry)
12701296{
12711297 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1272 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
1273 const_instruction->base.value.special = ConstValSpecialStatic;
1274 const_instruction->base.value.data.x_type = type_entry;
1298 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1299 const_instruction->base.value->special = ConstValSpecialStatic;
1300 const_instruction->base.value->data.x_type = type_entry;
12751301 return &const_instruction->base;
12761302}
12771303
......@@ -1285,35 +1311,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode
12851311
12861312static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
12871313 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1288 const_instruction->base.value.type = fn_entry->type_entry;
1289 const_instruction->base.value.special = ConstValSpecialStatic;
1290 const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry;
1291 const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst;
1292 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction;
1314 const_instruction->base.value->type = fn_entry->type_entry;
1315 const_instruction->base.value->special = ConstValSpecialStatic;
1316 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;
1317 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1318 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction;
12931319 return &const_instruction->base;
12941320}
12951321
12961322static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
12971323 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1298 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
1299 const_instruction->base.value.special = ConstValSpecialStatic;
1300 const_instruction->base.value.data.x_type = import;
1324 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1325 const_instruction->base.value->special = ConstValSpecialStatic;
1326 const_instruction->base.value->data.x_type = import;
13011327 return &const_instruction->base;
13021328}
13031329
13041330static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
13051331 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1306 const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool;
1307 const_instruction->base.value.special = ConstValSpecialStatic;
1308 const_instruction->base.value.data.x_bool = value;
1332 const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool;
1333 const_instruction->base.value->special = ConstValSpecialStatic;
1334 const_instruction->base.value->data.x_bool = value;
13091335 return &const_instruction->base;
13101336}
13111337
13121338static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {
13131339 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1314 const_instruction->base.value.type = irb->codegen->builtin_types.entry_enum_literal;
1315 const_instruction->base.value.special = ConstValSpecialStatic;
1316 const_instruction->base.value.data.x_enum_literal = name;
1340 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;
1341 const_instruction->base.value->special = ConstValSpecialStatic;
1342 const_instruction->base.value->data.x_enum_literal = name;
13171343 return &const_instruction->base;
13181344}
13191345
......@@ -1321,19 +1347,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN
13211347 ZigFn *fn_entry, IrInstruction *first_arg)
13221348{
13231349 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);
1325 const_instruction->base.value.special = ConstValSpecialStatic;
1326 const_instruction->base.value.data.x_bound_fn.fn = fn_entry;
1327 const_instruction->base.value.data.x_bound_fn.first_arg = first_arg;
1350 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);
1351 const_instruction->base.value->special = ConstValSpecialStatic;
1352 const_instruction->base.value->data.x_bound_fn.fn = fn_entry;
1353 const_instruction->base.value->data.x_bound_fn.first_arg = first_arg;
13281354 return &const_instruction->base;
13291355}
13301356
13311357static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
13321358 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
13351361 return &const_instruction->base;
13361362}
1363
13371364static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
13381365 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
13391366 ir_instruction_append(irb->current_basic_block, instruction);
......@@ -1388,7 +1415,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so
13881415static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
13891416 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,
13901417 source_instruction->scope, source_instruction->source_node);
1391 instruction->base.value.type = ty;
1418 instruction->base.value->type = ty;
13921419 return &instruction->base;
13931420}
13941421
......@@ -1513,7 +1540,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
15131540{
15141541 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
15151542 source_instruction->scope, source_instruction->source_node);
1516 call_instruction->base.value.type = return_type;
1543 call_instruction->base.value->type = return_type;
15171544 call_instruction->fn_entry = fn_entry;
15181545 call_instruction->fn_ref = fn_ref;
15191546 call_instruction->fn_inline = fn_inline;
......@@ -1558,8 +1585,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source
15581585 IrBasicBlock *dest_block, IrInstruction *is_comptime)
15591586{
15601587 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);
1561 br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
1562 br_instruction->base.value.special = ConstValSpecialStatic;
1588 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1589 br_instruction->base.value->special = ConstValSpecialStatic;
15631590 br_instruction->dest_block = dest_block;
15641591 br_instruction->is_comptime = is_comptime;
15651592
......@@ -1659,8 +1686,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
16591686static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
16601687 IrInstructionUnreachable *unreachable_instruction =
16611688 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
1662 unreachable_instruction->base.value.special = ConstValSpecialStatic;
1663 unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
1689 unreachable_instruction->base.value->special = ConstValSpecialStatic;
1690 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
16641691 return &unreachable_instruction->base;
16651692}
16661693
......@@ -1668,8 +1695,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
16681695 IrInstruction *ptr, IrInstruction *value)
16691696{
16701697 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);
1671 instruction->base.value.special = ConstValSpecialStatic;
1672 instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1698 instruction->base.value->special = ConstValSpecialStatic;
1699 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
16731700 instruction->ptr = ptr;
16741701 instruction->value = value;
16751702
......@@ -1684,7 +1711,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *
16841711{
16851712 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(
16861713 &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;
16881715 inst->vector_ptr = vector_ptr;
16891716 inst->index = index;
16901717 inst->value = value;
......@@ -1700,8 +1727,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod
17001727 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)
17011728{
17021729 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
1703 decl_var_instruction->base.value.special = ConstValSpecialStatic;
1704 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1730 decl_var_instruction->base.value->special = ConstValSpecialStatic;
1731 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
17051732 decl_var_instruction->var = var;
17061733 decl_var_instruction->align_value = align_value;
17071734 decl_var_instruction->ptr = ptr;
......@@ -1717,8 +1744,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc
17171744{
17181745 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,
17191746 source_instruction->scope, source_instruction->source_node);
1720 decl_var_instruction->base.value.special = ConstValSpecialStatic;
1721 decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void;
1747 decl_var_instruction->base.value->special = ConstValSpecialStatic;
1748 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;
17221749 decl_var_instruction->var = var;
17231750 decl_var_instruction->var_ptr = var_ptr;
17241751
......@@ -1732,7 +1759,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc
17321759{
17331760 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,
17341761 source_instruction->scope, source_instruction->source_node);
1735 instruction->base.value.type = ty;
1762 instruction->base.value->type = ty;
17361763 instruction->operand = operand;
17371764 instruction->result_loc = result_loc;
17381765
......@@ -1747,8 +1774,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
17471774{
17481775 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(
17491776 irb, scope, source_node);
1750 export_instruction->base.value.special = ConstValSpecialStatic;
1751 export_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1777 export_instruction->base.value->special = ConstValSpecialStatic;
1778 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
17521779 export_instruction->name = name;
17531780 export_instruction->target = target;
17541781 export_instruction->linkage = linkage;
......@@ -1925,7 +1952,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour
19251952{
19261953 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(
19271954 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1928 instruction->base.value.type = result_ty;
1955 instruction->base.value->type = result_ty;
19291956 instruction->operand = operand;
19301957 instruction->result_loc = result_loc;
19311958
......@@ -1940,7 +1967,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s
19401967{
19411968 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(
19421969 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1943 instruction->base.value.type = result_type;
1970 instruction->base.value->type = result_type;
19441971 instruction->operand = operand;
19451972 instruction->result_loc = result_loc;
19461973
......@@ -1955,7 +1982,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour
19551982{
19561983 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(
19571984 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1958 instruction->base.value.type = result_type;
1985 instruction->base.value->type = result_type;
19591986 instruction->operand = operand;
19601987 instruction->result_loc = result_loc;
19611988
......@@ -2025,8 +2052,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
20252052 IrInstruction *switch_prongs_void)
20262053{
20272054 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);
2028 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
2029 instruction->base.value.special = ConstValSpecialStatic;
2055 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2056 instruction->base.value->special = ConstValSpecialStatic;
20302057 instruction->target_value = target_value;
20312058 instruction->else_block = else_block;
20322059 instruction->case_count = case_count;
......@@ -2122,7 +2149,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins
21222149{
21232150 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,
21242151 source_instruction->scope, source_instruction->source_node);
2125 instruction->base.value.type = result_type;
2152 instruction->base.value->type = result_type;
21262153 instruction->operand = operand;
21272154 instruction->result_loc = result_loc;
21282155
......@@ -2237,7 +2264,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
22372264{
22382265 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,
22392266 source_instruction->scope, source_instruction->source_node);
2240 instruction->base.value.type = result_type;
2267 instruction->base.value->type = result_type;
22412268 instruction->ptr = ptr;
22422269 instruction->cmp_value = cmp_value;
22432270 instruction->new_value = new_value;
......@@ -2482,7 +2509,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i
24822509{
24832510 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(
24842511 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2485 instruction->base.value.type = result_type;
2512 instruction->base.value->type = result_type;
24862513 instruction->scalar = scalar;
24872514
24882515 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
24952522{
24962523 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(
24972524 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2498 instruction->base.value.type = slice_type;
2525 instruction->base.value->type = slice_type;
24992526 instruction->ptr = ptr;
25002527 instruction->start = start;
25012528 instruction->end = end;
......@@ -2709,7 +2736,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc
27092736{
27102737 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
27112738 &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;
27132740 instruction->err_union = err_union;
27142741
27152742 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
27922819{
27932820 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(
27942821 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2795 instruction->base.value.type = ptr_type;
2822 instruction->base.value->type = ptr_type;
27962823 instruction->ptr = ptr;
27972824 instruction->safety_check_on = safety_check_on;
27982825
......@@ -2806,7 +2833,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
28062833{
28072834 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(
28082835 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2809 instruction->base.value.type = ty;
2836 instruction->base.value->type = ty;
28102837 instruction->ptr = ptr;
28112838 instruction->result_loc = result_loc;
28122839
......@@ -2845,7 +2872,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc
28452872{
28462873 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(
28472874 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2848 instruction->base.value.type = ty;
2875 instruction->base.value->type = ty;
28492876 instruction->operand = operand;
28502877
28512878 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
29973024
29983025static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
29993026 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);
3000 instruction->base.value.special = ConstValSpecialStatic;
3001 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
3027 instruction->base.value->special = ConstValSpecialStatic;
3028 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
30023029 instruction->msg = msg;
30033030
30043031 ir_ref_instruction(msg, irb->current_basic_block);
......@@ -3328,7 +3355,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so
33283355{
33293356 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,
33303357 source_instruction->scope, source_instruction->source_node);
3331 instruction->base.value.type = result_type;
3358 instruction->base.value->type = result_type;
33323359 instruction->vector = vector;
33333360 instruction->result_loc = result_loc;
33343361
......@@ -3343,7 +3370,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi
33433370{
33443371 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,
33453372 source_instruction->scope, source_instruction->source_node);
3346 instruction->base.value.type = result_type;
3373 instruction->base.value->type = result_type;
33473374 instruction->operand = operand;
33483375 instruction->result_loc = result_loc;
33493376
......@@ -3358,7 +3385,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so
33583385{
33593386 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,
33603387 source_instruction->scope, source_instruction->source_node);
3361 instruction->base.value.type = result_type;
3388 instruction->base.value->type = result_type;
33623389 instruction->array = array;
33633390
33643391 ir_ref_instruction(array, ira->new_irb.current_basic_block);
......@@ -3371,7 +3398,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source
33713398{
33723399 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,
33733400 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;
33753402 instruction->target = target;
33763403
33773404 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
33843411{
33853412 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,
33863413 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;
33883415 instruction->target = target;
33893416
33903417 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
34333460
34343461static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {
34353462 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
34383465 return instruction;
34393466}
......@@ -3442,7 +3469,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN
34423469 IrInstructionSuspendBegin *begin)
34433470{
34443471 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;
34463473 instruction->begin = begin;
34473474
34483475 ir_ref_instruction(&begin->base, irb->current_basic_block);
......@@ -3467,7 +3494,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *
34673494{
34683495 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,
34693496 source_instruction->scope, source_instruction->source_node);
3470 instruction->base.value.type = result_type;
3497 instruction->base.value->type = result_type;
34713498 instruction->frame = frame;
34723499 instruction->result_loc = result_loc;
34733500
......@@ -3479,7 +3506,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *
34793506
34803507static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {
34813508 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;
34833510 instruction->frame = frame;
34843511
34853512 ir_ref_instruction(frame, irb->current_basic_block);
......@@ -3491,8 +3518,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
34913518 IrInstruction *operand, SpillId spill_id)
34923519{
34933520 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);
3494 instruction->base.value.special = ConstValSpecialStatic;
3495 instruction->base.value.type = irb->codegen->builtin_types.entry_void;
3521 instruction->base.value->special = ConstValSpecialStatic;
3522 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
34963523 instruction->operand = operand;
34973524 instruction->spill_id = spill_id;
34983525
......@@ -3517,7 +3544,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction
35173544{
35183545 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(
35193546 &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;
35213548 instruction->vector = vector;
35223549 instruction->index = index;
35233550
......@@ -3588,8 +3615,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
35883615 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
35893616 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
35903617 if (defer_expr_value != irb->codegen->invalid_instruction) {
3591 if (defer_expr_value->value.type != nullptr &&
3592 defer_expr_value->value.type->id == ZigTypeIdUnreachable)
3618 if (defer_expr_value->value->type != nullptr &&
3619 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
35933620 {
35943621 is_noreturn = true;
35953622 } else {
......@@ -4411,7 +4438,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
44114438 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
44124439 tld_var->base.resolution = TldResolutionInvalid;
44134440 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);
44154442 scope_decls->decl_table.put(var_name, &tld_var->base);
44164443}
44174444
......@@ -4424,10 +4451,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
44244451 if (buf_eql_str(variable_name, "_")) {
44254452 if (lval == LValPtr) {
44264453 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,
44284455 irb->codegen->builtin_types.entry_void, false);
4429 const_instruction->base.value.special = ConstValSpecialStatic;
4430 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard;
4456 const_instruction->base.value->special = ConstValSpecialStatic;
4457 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;
44314458 return &const_instruction->base;
44324459 } else {
44334460 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) {
86988725// This function takes a comptime ptr and makes the child const value conform to the type
86998726// described by the pointer.
87008727static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
8701 ConstExprValue *ptr_val)
8728 ZigValue *ptr_val)
87028729{
87038730 Error err;
87048731 assert(ptr_val->type->id == ZigTypeIdPointer);
87058732 assert(ptr_val->special == ConstValSpecialStatic);
8706 ConstExprValue tmp = {};
8733 ZigValue tmp = {};
87078734 tmp.special = ConstValSpecialStatic;
87088735 tmp.type = ptr_val->type->data.pointer.child_type;
87098736 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
87108737 return err;
8711 ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
8738 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
87128739 copy_const_val(child_val, &tmp, false);
87138740 return ErrorNone;
87148741}
87158742
8716ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,
8743ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
87178744 AstNode *source_node)
87188745{
87198746 Error err;
8720 ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val);
8747 ZigValue *val = const_ptr_pointee_unchecked(codegen, const_val);
87218748 assert(val != nullptr);
87228749 assert(const_val->type->id == ZigTypeIdPointer);
87238750 ZigType *expected_type = const_val->type->data.pointer.child_type;
......@@ -8740,19 +8767,19 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
87408767 return val;
87418768}
87428769
8743static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
8770static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
87448771 IrBasicBlock *bb = exec->basic_block_list.at(0);
87458772 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
87468773 IrInstruction *instruction = bb->instruction_list.at(i);
87478774 if (instruction->id == IrInstructionIdReturn) {
87488775 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
87498776 IrInstruction *operand = ret_inst->operand;
8750 if (operand->value.special == ConstValSpecialRuntime) {
8777 if (operand->value->special == ConstValSpecialRuntime) {
87518778 exec_add_error_node(codegen, exec, operand->source_node,
87528779 buf_sprintf("unable to evaluate constant expression"));
8753 return &codegen->invalid_instruction->value;
8780 return codegen->invalid_instruction->value;
87548781 }
8755 return &operand->value;
8782 return operand->value;
87568783 } else if (ir_has_side_effects(instruction)) {
87578784 if (instr_is_comptime(instruction)) {
87588785 switch (instruction->id) {
......@@ -8769,7 +8796,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec
87698796 }
87708797 exec_add_error_node(codegen, exec, instruction->source_node,
87718798 buf_sprintf("unable to evaluate constant expression"));
8772 return &codegen->invalid_instruction->value;
8799 return codegen->invalid_instruction->value;
87738800 }
87748801 }
87758802 zig_unreachable();
......@@ -8783,14 +8810,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
87838810 return true;
87848811}
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) {
87878814 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
87888815 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
87898816 (num_lit_type->id == ZigTypeIdComptimeInt &&
87908817 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
87918818}
87928819
8793static bool float_has_fraction(ConstExprValue *const_val) {
8820static bool float_has_fraction(ZigValue *const_val) {
87948821 if (const_val->type->id == ZigTypeIdComptimeFloat) {
87958822 return bigfloat_has_fraction(&const_val->data.x_bigfloat);
87968823 } else if (const_val->type->id == ZigTypeIdFloat) {
......@@ -8818,7 +8845,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {
88188845 }
88198846}
88208847
8821static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
8848static void float_append_buf(Buf *buf, ZigValue *const_val) {
88228849 if (const_val->type->id == ZigTypeIdComptimeFloat) {
88238850 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
88248851 } else if (const_val->type->id == ZigTypeIdFloat) {
......@@ -8856,7 +8883,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
88568883 }
88578884}
88588885
8859static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
8886static void float_init_bigint(BigInt *bigint, ZigValue *const_val) {
88608887 if (const_val->type->id == ZigTypeIdComptimeFloat) {
88618888 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
88628889 } else if (const_val->type->id == ZigTypeIdFloat) {
......@@ -8903,7 +8930,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
89038930 }
89048931}
89058932
8906static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
8933static void float_init_bigfloat(ZigValue *dest_val, BigFloat *bigfloat) {
89078934 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
89088935 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
89098936 } else if (dest_val->type->id == ZigTypeIdFloat) {
......@@ -8930,7 +8957,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
89308957 }
89318958}
89328959
8933static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
8960static void float_init_f16(ZigValue *dest_val, float16_t x) {
89348961 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
89358962 bigfloat_init_16(&dest_val->data.x_bigfloat, x);
89368963 } else if (dest_val->type->id == ZigTypeIdFloat) {
......@@ -8955,7 +8982,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
89558982 }
89568983}
89578984
8958static void float_init_f32(ConstExprValue *dest_val, float x) {
8985static void float_init_f32(ZigValue *dest_val, float x) {
89598986 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
89608987 bigfloat_init_32(&dest_val->data.x_bigfloat, x);
89618988 } else if (dest_val->type->id == ZigTypeIdFloat) {
......@@ -8984,7 +9011,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
89849011 }
89859012}
89869013
8987static void float_init_f64(ConstExprValue *dest_val, double x) {
9014static void float_init_f64(ZigValue *dest_val, double x) {
89889015 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
89899016 bigfloat_init_64(&dest_val->data.x_bigfloat, x);
89909017 } else if (dest_val->type->id == ZigTypeIdFloat) {
......@@ -9013,7 +9040,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
90139040 }
90149041}
90159042
9016static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
9043static void float_init_f128(ZigValue *dest_val, float128_t x) {
90179044 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
90189045 bigfloat_init_128(&dest_val->data.x_bigfloat, x);
90199046 } else if (dest_val->type->id == ZigTypeIdFloat) {
......@@ -9046,7 +9073,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
90469073 }
90479074}
90489075
9049static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
9076static void float_init_float(ZigValue *dest_val, ZigValue *src_val) {
90509077 if (src_val->type->id == ZigTypeIdComptimeFloat) {
90519078 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
90529079 } else if (src_val->type->id == ZigTypeIdFloat) {
......@@ -9071,7 +9098,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
90719098 }
90729099}
90739100
9074static bool float_is_nan(ConstExprValue *op) {
9101static bool float_is_nan(ZigValue *op) {
90759102 if (op->type->id == ZigTypeIdComptimeFloat) {
90769103 return bigfloat_is_nan(&op->data.x_bigfloat);
90779104 } else if (op->type->id == ZigTypeIdFloat) {
......@@ -9092,7 +9119,7 @@ static bool float_is_nan(ConstExprValue *op) {
90929119 }
90939120}
90949121
9095static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
9122static Cmp float_cmp(ZigValue *op1, ZigValue *op2) {
90969123 assert(op1->type == op2->type);
90979124 if (op1->type->id == ZigTypeIdComptimeFloat) {
90989125 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
......@@ -9138,7 +9165,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
91389165 }
91399166}
91409167
9141static Cmp float_cmp_zero(ConstExprValue *op) {
9168static Cmp float_cmp_zero(ZigValue *op) {
91429169 if (op->type->id == ZigTypeIdComptimeFloat) {
91439170 return bigfloat_cmp_zero(&op->data.x_bigfloat);
91449171 } else if (op->type->id == ZigTypeIdFloat) {
......@@ -9188,7 +9215,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
91889215 }
91899216}
91909217
9191static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9218static void float_add(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
91929219 assert(op1->type == op2->type);
91939220 out_val->type = op1->type;
91949221 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9215,7 +9242,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
92159242 }
92169243}
92179244
9218static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9245static void float_sub(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
92199246 assert(op1->type == op2->type);
92209247 out_val->type = op1->type;
92219248 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9242,7 +9269,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
92429269 }
92439270}
92449271
9245static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9272static void float_mul(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
92469273 assert(op1->type == op2->type);
92479274 out_val->type = op1->type;
92489275 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9269,7 +9296,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
92699296 }
92709297}
92719298
9272static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9299static void float_div(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
92739300 assert(op1->type == op2->type);
92749301 out_val->type = op1->type;
92759302 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9296,7 +9323,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
92969323 }
92979324}
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) {
93009327 assert(op1->type == op2->type);
93019328 out_val->type = op1->type;
93029329 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9325,7 +9352,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
93259352 }
93269353}
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) {
93299356 assert(op1->type == op2->type);
93309357 out_val->type = op1->type;
93319358 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9354,7 +9381,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
93549381 }
93559382}
93569383
9357static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9384static void float_rem(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
93589385 assert(op1->type == op2->type);
93599386 out_val->type = op1->type;
93609387 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9399,7 +9426,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
93999426 f128M_sub(a, c, c);
94009427}
94019428
9402static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
9429static void float_mod(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
94039430 assert(op1->type == op2->type);
94049431 out_val->type = op1->type;
94059432 if (op1->type->id == ZigTypeIdComptimeFloat) {
......@@ -9426,7 +9453,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
94269453 }
94279454}
94289455
9429static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
9456static void float_negate(ZigValue *out_val, ZigValue *op) {
94309457 out_val->type = op->type;
94319458 if (op->type->id == ZigTypeIdComptimeFloat) {
94329459 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
......@@ -9457,7 +9484,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
94579484 }
94589485}
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) {
94619488 if (op->type->id == ZigTypeIdFloat) {
94629489 switch (op->type->data.floating.bit_count) {
94639490 case 16:
......@@ -9480,7 +9507,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
94809507 }
94819508}
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) {
94849511 if (val->type->id == ZigTypeIdFloat) {
94859512 switch (val->type->data.floating.bit_count) {
94869513 case 16:
......@@ -9510,7 +9537,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
95109537 return false;
95119538 }
95129539
9513 ConstExprValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);
9540 ZigValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);
95149541 if (const_val == nullptr)
95159542 return false;
95169543
......@@ -10217,13 +10244,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1021710244 size_t i = 0;
1021810245 for (;;) {
1021910246 prev_inst = instructions[i];
10220 if (type_is_invalid(prev_inst->value.type)) {
10247 if (type_is_invalid(prev_inst->value->type)) {
1022110248 return ira->codegen->builtin_types.entry_invalid;
1022210249 }
10223 if (prev_inst->value.type->id == ZigTypeIdUnreachable) {
10250 if (prev_inst->value->type->id == ZigTypeIdUnreachable) {
1022410251 i += 1;
1022510252 if (i == instruction_count) {
10226 return prev_inst->value.type;
10253 return prev_inst->value->type;
1022710254 }
1022810255 continue;
1022910256 }
......@@ -10232,14 +10259,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1023210259 ErrorTableEntry **errors = nullptr;
1023310260 size_t errors_count = 0;
1023410261 ZigType *err_set_type = nullptr;
10235 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
10236 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value.type, prev_inst->source_node)) {
10262 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10263 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
1023710264 return ira->codegen->builtin_types.entry_invalid;
1023810265 }
10239 if (type_is_global_error_set(prev_inst->value.type)) {
10266 if (type_is_global_error_set(prev_inst->value->type)) {
1024010267 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
1024110268 } else {
10242 err_set_type = prev_inst->value.type;
10269 err_set_type = prev_inst->value->type;
1024310270 update_errors_helper(ira->codegen, &errors, &errors_count);
1024410271
1024510272 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
1025010277 }
1025110278 }
1025210279
10253 bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
10280 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
1025410281 bool convert_to_const_slice = false;
1025510282 for (; i < instruction_count; i += 1) {
1025610283 IrInstruction *cur_inst = instructions[i];
10257 ZigType *cur_type = cur_inst->value.type;
10258 ZigType *prev_type = prev_inst->value.type;
10284 ZigType *cur_type = cur_inst->value->type;
10285 ZigType *prev_type = prev_inst->value->type;
1025910286
1026010287 if (type_is_invalid(cur_type)) {
1026110288 return cur_type;
......@@ -10559,20 +10586,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1055910586 }
1056010587
1056110588 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);
1056310590 if (field != nullptr) {
1056410591 continue;
1056510592 }
1056610593 }
1056710594 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);
1056910596 if (field != nullptr) {
1057010597 continue;
1057110598 }
1057210599 }
1057310600
1057410601 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);
1057610603 if (field != nullptr) {
1057710604 prev_inst = cur_inst;
1057810605 continue;
......@@ -10580,7 +10607,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1058010607 }
1058110608
1058210609 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);
1058410611 if (field != nullptr) {
1058510612 prev_inst = cur_inst;
1058610613 continue;
......@@ -10906,9 +10933,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1090610933 free(errors);
1090710934
1090810935 if (convert_to_const_slice) {
10909 if (prev_inst->value.type->id == ZigTypeIdArray) {
10936 if (prev_inst->value->type->id == ZigTypeIdArray) {
1091010937 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,
1091210939 true, false, PtrLenUnknown,
1091310940 0, 0, 0, false);
1091410941 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
1091710944 } else {
1091810945 return slice_type;
1091910946 }
10920 } else if (prev_inst->value.type->id == ZigTypeIdPointer) {
10921 ZigType *array_type = prev_inst->value.type->data.pointer.child_type;
10947 } else if (prev_inst->value->type->id == ZigTypeIdPointer) {
10948 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
1092210949 src_assert(array_type->id == ZigTypeIdArray, source_node);
1092310950 ZigType *ptr_type = get_pointer_to_type_extra2(
1092410951 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,
1092610953 PtrLenUnknown,
1092710954 0, 0, 0, false,
1092810955 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
1093610963 zig_unreachable();
1093710964 }
1093810965 } else if (err_set_type != nullptr) {
10939 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
10966 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
1094010967 return err_set_type;
10941 } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {
10942 ZigType *payload_type = prev_inst->value.type->data.error_union.payload_type;
10968 } else if (prev_inst->value->type->id == ZigTypeIdErrorUnion) {
10969 ZigType *payload_type = prev_inst->value->type->data.error_union.payload_type;
1094310970 if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))
1094410971 return ira->codegen->builtin_types.entry_invalid;
1094510972 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
1094910976 return ira->codegen->builtin_types.entry_invalid;
1095010977 return get_error_union_type(ira->codegen, err_set_type, payload_type);
1095110978 } else {
10952 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
10953 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
10979 if (prev_inst->value->type->id == ZigTypeIdComptimeInt ||
10980 prev_inst->value->type->id == ZigTypeIdComptimeFloat)
1095410981 {
1095510982 ir_add_error_node(ira, source_node,
1095610983 buf_sprintf("unable to make error union out of number literal"));
1095710984 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) {
1095910986 ir_add_error_node(ira, source_node,
1096010987 buf_sprintf("unable to make error union out of null literal"));
1096110988 return ira->codegen->builtin_types.entry_invalid;
1096210989 } 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)))
1096410991 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);
1096610993 }
1096710994 }
10968 } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {
10969 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
10970 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
10995 } else if (any_are_null && prev_inst->value->type->id != ZigTypeIdNull) {
10996 if (prev_inst->value->type->id == ZigTypeIdComptimeInt ||
10997 prev_inst->value->type->id == ZigTypeIdComptimeFloat)
1097110998 {
1097210999 ir_add_error_node(ira, source_node,
1097311000 buf_sprintf("unable to make maybe out of number literal"));
1097411001 return ira->codegen->builtin_types.entry_invalid;
10975 } else if (prev_inst->value.type->id == ZigTypeIdOptional) {
10976 return prev_inst->value.type;
11002 } else if (prev_inst->value->type->id == ZigTypeIdOptional) {
11003 return prev_inst->value->type;
1097711004 } 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)))
1097911006 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);
1098111008 }
1098211009 } else {
10983 return prev_inst->value.type;
11010 return prev_inst->value->type;
1098411011 }
1098511012}
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) {
1098811015 ConstGlobalRefs *global_refs = dest->global_refs;
10989 memcpy(dest, src, sizeof(ConstExprValue));
11016 memcpy(dest, src, sizeof(ZigValue));
1099011017 if (!same_global_refs) {
1099111018 dest->global_refs = global_refs;
1099211019 if (src->special != ConstValSpecialStatic)
......@@ -11002,8 +11029,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
1100211029
1100311030static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
1100411031 CastOp cast_op,
11005 ConstExprValue *other_val, ZigType *other_type,
11006 ConstExprValue *const_val, ZigType *new_type)
11032 ZigValue *other_val, ZigType *other_type,
11033 ZigValue *const_val, ZigType *new_type)
1100711034{
1100811035 const_val->special = other_val->special;
1100911036
......@@ -11106,25 +11133,31 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z
1110611133 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1110711134 old_instruction->scope, old_instruction->source_node);
1110811135 IrInstruction *new_instruction = &const_instruction->base;
11109 new_instruction->value.type = ty;
11110 new_instruction->value.special = ConstValSpecialStatic;
11136 new_instruction->value->type = ty;
11137 new_instruction->value->special = ConstValSpecialStatic;
1111111138 return new_instruction;
1111211139}
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
1111411147static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
1111511148 ZigType *wanted_type, CastOp cast_op)
1111611149{
1111711150 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
1111811151 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,
11120 &result->value, wanted_type))
11152 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
11153 result->value, wanted_type))
1112111154 {
1112211155 return ira->codegen->invalid_instruction;
1112311156 }
1112411157 return result;
1112511158 } else {
1112611159 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;
1112811161 return result;
1112911162 }
1113011163}
......@@ -11132,35 +11165,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
1113211165static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
1113311166 IrInstruction *value, ZigType *wanted_type)
1113411167{
11135 assert(value->value.type->id == ZigTypeIdPointer);
11168 assert(value->value->type->id == ZigTypeIdPointer);
1113611169
1113711170 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,
1114011173 ResolveStatusAlignmentKnown)))
1114111174 {
1114211175 return ira->codegen->invalid_instruction;
1114311176 }
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
1114711180 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);
1114911182 if (pointee == nullptr)
1115011183 return ira->codegen->invalid_instruction;
1115111184 if (pointee->special != ConstValSpecialRuntime) {
1115211185 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11153 result->value.data.x_ptr.special = ConstPtrSpecialBaseArray;
11154 result->value.data.x_ptr.mut = value->value.data.x_ptr.mut;
11155 result->value.data.x_ptr.data.base_array.array_val = pointee;
11156 result->value.data.x_ptr.data.base_array.elem_index = 0;
11186 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
11187 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
11188 result->value->data.x_ptr.data.base_array.array_val = pointee;
11189 result->value->data.x_ptr.data.base_array.elem_index = 0;
1115711190 return result;
1115811191 }
1115911192 }
1116011193
1116111194 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
1116211195 wanted_type, value, CastOpBitCast);
11163 result->value.type = wanted_type;
11196 result->value->type = wanted_type;
1116411197 return result;
1116511198}
1116611199
......@@ -11169,28 +11202,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1116911202{
1117011203 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,
1117311206 ResolveStatusAlignmentKnown)))
1117411207 {
1117511208 return ira->codegen->invalid_instruction;
1117611209 }
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
1118011213 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);
1118211215 if (pointee == nullptr)
1118311216 return ira->codegen->invalid_instruction;
1118411217 if (pointee->special != ConstValSpecialRuntime) {
11185 assert(array_ptr->value.type->id == ZigTypeIdPointer);
11186 ZigType *array_type = array_ptr->value.type->data.pointer.child_type;
11218 assert(array_ptr->value->type->id == ZigTypeIdPointer);
11219 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;
1118711220 assert(is_slice(wanted_type));
1118811221 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1118911222
1119011223 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);
11192 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;
11224 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
11225 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;
11226 result->value->type = wanted_type;
1119411227 return result;
1119511228 }
1119611229 }
......@@ -11198,7 +11231,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1119811231 if (result_loc == nullptr) result_loc = no_result_loc();
1119911232 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
1120011233 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)) {
1120211235 return result_loc_inst;
1120311236 }
1120411237 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
1140311436}
1140411437
1140511438static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {
11406 if (instruction->value.type->id == ZigTypeIdUnreachable)
11439 if (instruction->value->type->id == ZigTypeIdUnreachable)
1140711440 ir_finish_bb(ira);
1140811441 return instruction;
1140911442}
1141011443
1141111444static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1141211445 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;
1141411447 return result;
1141511448}
1141611449
1141711450static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {
1141811451 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;
1142011453 return result;
1142111454}
1142211455
1142311456static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1142411457 IrInstruction *result = ir_const(ira, source_instruction, ty);
11425 result->value.special = ConstValSpecialUndef;
11458 result->value->special = ConstValSpecialUndef;
1142611459 return result;
1142711460}
1142811461
1142911462static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {
11430 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable);
11431 result->value.special = ConstValSpecialStatic;
11463#ifdef ZIG_ENABLE_MEM_PROFILE
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;
1143211468 return result;
1143311469}
1143411470
1143511471static 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;
1143711478}
1143811479
1143911480static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {
1144011481 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);
1144211483 return result;
1144311484}
1144411485
1144511486static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
11446 ConstExprValue *pointee, ZigType *pointee_type,
11487 ZigValue *pointee, ZigType *pointee_type,
1144711488 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
1144811489{
1144911490 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
1145011491 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
1145111492 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);
11452 ConstExprValue *const_val = &const_instr->value;
11493 ZigValue *const_val = const_instr->value;
1145311494 const_val->data.x_ptr.special = ConstPtrSpecialRef;
1145411495 const_val->data.x_ptr.mut = ptr_mut;
1145511496 const_val->data.x_ptr.data.ref.pointee = pointee;
......@@ -11457,7 +11498,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
1145711498}
1145811499
1145911500static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11460 ConstExprValue *val, UndefAllowed undef_allowed)
11501 ZigValue *val, UndefAllowed undef_allowed)
1146111502{
1146211503 Error err;
1146311504 for (;;) {
......@@ -11490,17 +11531,17 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
1149011531 }
1149111532}
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) {
1149411535 Error err;
1149511536 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)))
1149711538 {
1149811539 return nullptr;
1149911540 }
11500 return &value->value;
11541 return value->value;
1150111542}
1150211543
11503ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
11544ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1150411545 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
1150511546 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
1150611547 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
1150811549 Error err;
1150911550
1151011551 if (expected_type != nullptr && type_is_invalid(expected_type))
11511 return &codegen->invalid_instruction->value;
11552 return codegen->invalid_instruction->value;
1151211553
1151311554 IrExecutable *ir_executable = allocate<IrExecutable>(1);
1151411555 ir_executable->source_node = source_node;
......@@ -11522,7 +11563,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1152211563
1152311564 if (ir_executable->first_err_trace_msg != nullptr) {
1152411565 codegen->trace_err = ir_executable->first_err_trace_msg;
11525 return &codegen->invalid_instruction->value;
11566 return codegen->invalid_instruction->value;
1152611567 }
1152711568
1152811569 if (codegen->verbose_ir) {
......@@ -11545,7 +11586,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1154511586 analyzed_executable->begin_scope = scope;
1154611587 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);
1154711588 if (type_is_invalid(result_type)) {
11548 return &codegen->invalid_instruction->value;
11589 return codegen->invalid_instruction->value;
1154911590 }
1155011591
1155111592 if (codegen->verbose_ir) {
......@@ -11554,27 +11595,27 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1155411595 fprintf(stderr, "}\n");
1155511596 }
1155611597
11557 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);
11598 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
1155811599 if (type_is_invalid(result->type))
11559 return &codegen->invalid_instruction->value;
11600 return codegen->invalid_instruction->value;
1156011601
1156111602 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
1156411605 return result;
1156511606}
1156611607
1156711608static 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))
1156911610 return nullptr;
1157011611
11571 if (err_value->value.type->id != ZigTypeIdErrorSet) {
11612 if (err_value->value->type->id != ZigTypeIdErrorSet) {
1157211613 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)));
1157411615 return nullptr;
1157511616 }
1157611617
11577 ConstExprValue *const_val = ir_resolve_const(ira, err_value, UndefBad);
11618 ZigValue *const_val = ir_resolve_const(ira, err_value, UndefBad);
1157811619 if (!const_val)
1157911620 return nullptr;
1158011621
......@@ -11583,7 +11624,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
1158311624}
1158411625
1158511626static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11586 ConstExprValue *val)
11627 ZigValue *val)
1158711628{
1158811629 Error err;
1158911630 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
1159311634 return val->data.x_type;
1159411635}
1159511636
11596static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
11597 if (type_is_invalid(type_value->value.type))
11637static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
11638 if (type_is_invalid(type_value->value->type))
1159811639 return nullptr;
1159911640
11600 if (type_value->value.type->id != ZigTypeIdMetaType) {
11641 if (type_value->value->type->id != ZigTypeIdMetaType) {
1160111642 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)));
1160311644 return nullptr;
1160411645 }
1160511646
1160611647 Error err;
1160711648 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)))
1160911650 {
1161011651 return nullptr;
1161111652 }
1161211653
11613 return &type_value->value;
11654 return type_value->value;
1161411655}
1161511656
1161611657static 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);
1161811659 if (val == nullptr)
1161911660 return ira->codegen->builtin_types.entry_invalid;
1162011661
......@@ -11663,18 +11704,18 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
1166311704}
1166411705
1166511706static 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))
1166711708 return ira->codegen->builtin_types.entry_invalid;
1166811709
11669 if (type_value->value.type->id != ZigTypeIdMetaType) {
11710 if (type_value->value->type->id != ZigTypeIdMetaType) {
1167011711 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)));
1167211713 add_error_note(ira->codegen, msg, op_source->source_node,
1167311714 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
1167411715 return ira->codegen->builtin_types.entry_invalid;
1167511716 }
1167611717
11677 ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad);
11718 ZigValue *const_val = ir_resolve_const(ira, type_value, UndefBad);
1167811719 if (!const_val)
1167911720 return ira->codegen->builtin_types.entry_invalid;
1168011721
......@@ -11694,16 +11735,16 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
1169411735 if (fn_value == ira->codegen->invalid_instruction)
1169511736 return nullptr;
1169611737
11697 if (type_is_invalid(fn_value->value.type))
11738 if (type_is_invalid(fn_value->value->type))
1169811739 return nullptr;
1169911740
11700 if (fn_value->value.type->id != ZigTypeIdFn) {
11741 if (fn_value->value->type->id != ZigTypeIdFn) {
1170111742 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)));
1170311744 return nullptr;
1170411745 }
1170511746
11706 ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);
11747 ZigValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);
1170711748 if (!const_val)
1170811749 return nullptr;
1170911750
......@@ -11722,22 +11763,22 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1172211763 if (instr_is_comptime(value)) {
1172311764 ZigType *payload_type = wanted_type->data.maybe.child_type;
1172411765 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))
1172611767 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);
1172911770 if (!val)
1173011771 return ira->codegen->invalid_instruction;
1173111772
1173211773 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1173311774 source_instr->scope, source_instr->source_node);
11734 const_instruction->base.value.special = ConstValSpecialStatic;
11775 const_instruction->base.value->special = ConstValSpecialStatic;
1173511776 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);
1173711778 } else {
11738 const_instruction->base.value.data.x_optional = val;
11779 const_instruction->base.value->data.x_optional = val;
1173911780 }
11740 const_instruction->base.value.type = wanted_type;
11781 const_instruction->base.value->type = wanted_type;
1174111782 return &const_instruction->base;
1174211783 }
1174311784
......@@ -11747,12 +11788,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1174711788 IrInstruction *result_loc_inst = nullptr;
1174811789 if (result_loc != nullptr) {
1174911790 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)) {
1175111792 return result_loc_inst;
1175211793 }
1175311794 }
1175411795 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;
1175611797 return result;
1175711798}
1175811799
......@@ -11765,24 +11806,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1176511806 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
1176611807 if (instr_is_comptime(value)) {
1176711808 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))
1176911810 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);
1177211813 if (!val)
1177311814 return ira->codegen->invalid_instruction;
1177411815
11775 ConstExprValue *err_set_val = create_const_vals(1);
11816 ZigValue *err_set_val = create_const_vals(1);
1177611817 err_set_val->type = err_set_type;
1177711818 err_set_val->special = ConstValSpecialStatic;
1177811819 err_set_val->data.x_err_set = nullptr;
1177911820
1178011821 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1178111822 source_instr->scope, source_instr->source_node);
11782 const_instruction->base.value.type = wanted_type;
11783 const_instruction->base.value.special = ConstValSpecialStatic;
11784 const_instruction->base.value.data.x_err_union.error_set = err_set_val;
11785 const_instruction->base.value.data.x_err_union.payload = val;
11823 const_instruction->base.value->type = wanted_type;
11824 const_instruction->base.value->special = ConstValSpecialStatic;
11825 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
11826 const_instruction->base.value->data.x_err_union.payload = val;
1178611827 return &const_instruction->base;
1178711828 }
1178811829
......@@ -11790,7 +11831,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1179011831 if (handle_is_ptr(wanted_type)) {
1179111832 if (result_loc == nullptr) result_loc = no_result_loc();
1179211833 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)) {
1179411835 return result_loc_inst;
1179511836 }
1179611837 } else {
......@@ -11798,18 +11839,18 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1179811839 }
1179911840
1180011841 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;
1180211843 return result;
1180311844}
1180411845
1180511846static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
1180611847 ZigType *wanted_type)
1180711848{
11808 assert(value->value.type->id == ZigTypeIdErrorSet);
11849 assert(value->value->type->id == ZigTypeIdErrorSet);
1180911850 assert(wanted_type->id == ZigTypeIdErrorSet);
1181011851
1181111852 if (instr_is_comptime(value)) {
11812 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
11853 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1181311854 if (!val)
1181411855 return ira->codegen->invalid_instruction;
1181511856
......@@ -11834,14 +11875,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1183411875
1183511876 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1183611877 source_instr->scope, source_instr->source_node);
11837 const_instruction->base.value.type = wanted_type;
11838 const_instruction->base.value.special = ConstValSpecialStatic;
11839 const_instruction->base.value.data.x_err_set = val->data.x_err_set;
11878 const_instruction->base.value->type = wanted_type;
11879 const_instruction->base.value->special = ConstValSpecialStatic;
11880 const_instruction->base.value->data.x_err_set = val->data.x_err_set;
1184011881 return &const_instruction->base;
1184111882 }
1184211883
1184311884 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;
1184511886 return result;
1184611887}
1184711888
......@@ -11849,7 +11890,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
1184911890 IrInstruction *frame_ptr, ZigType *wanted_type)
1185011891{
1185111892 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);
1185311894 if (ptr_val == nullptr)
1185411895 return ira->codegen->invalid_instruction;
1185511896
......@@ -11861,7 +11902,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
1186111902
1186211903 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
1186311904 wanted_type, frame_ptr, CastOpBitCast);
11864 result->value.type = wanted_type;
11905 result->value->type = wanted_type;
1186511906 return result;
1186611907}
1186711908
......@@ -11874,7 +11915,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct
1187411915
1187511916 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
1187611917 wanted_type, value, CastOpBitCast);
11877 result->value.type = wanted_type;
11918 result->value->type = wanted_type;
1187811919 return result;
1187911920}
1188011921
......@@ -11887,21 +11928,21 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1188711928 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1188811929
1188911930 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);
1189111932 if (!val)
1189211933 return ira->codegen->invalid_instruction;
1189311934
11894 ConstExprValue *err_set_val = create_const_vals(1);
11935 ZigValue *err_set_val = create_const_vals(1);
1189511936 err_set_val->special = ConstValSpecialStatic;
1189611937 err_set_val->type = wanted_type->data.error_union.err_set_type;
1189711938 err_set_val->data.x_err_set = val->data.x_err_set;
1189811939
1189911940 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1190011941 source_instr->scope, source_instr->source_node);
11901 const_instruction->base.value.type = wanted_type;
11902 const_instruction->base.value.special = ConstValSpecialStatic;
11903 const_instruction->base.value.data.x_err_union.error_set = err_set_val;
11904 const_instruction->base.value.data.x_err_union.payload = nullptr;
11942 const_instruction->base.value->type = wanted_type;
11943 const_instruction->base.value->special = ConstValSpecialStatic;
11944 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
11945 const_instruction->base.value->data.x_err_union.payload = nullptr;
1190511946 return &const_instruction->base;
1190611947 }
1190711948
......@@ -11909,7 +11950,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1190911950 if (handle_is_ptr(wanted_type)) {
1191011951 if (result_loc == nullptr) result_loc = no_result_loc();
1191111952 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)) {
1191311954 return result_loc_inst;
1191411955 }
1191511956 } else {
......@@ -11918,7 +11959,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1191811959
1191911960
1192011961 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;
1192211963 return result;
1192311964}
1192411965
......@@ -11926,17 +11967,17 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
1192611967 assert(wanted_type->id == ZigTypeIdOptional);
1192711968 assert(instr_is_comptime(value));
1192811969
11929 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
11970 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1193011971 assert(val != nullptr);
1193111972
1193211973 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11933 result->value.special = ConstValSpecialStatic;
11974 result->value->special = ConstValSpecialStatic;
1193411975 if (get_codegen_ptr_type(wanted_type) != nullptr) {
11935 result->value.data.x_ptr.special = ConstPtrSpecialNull;
11976 result->value->data.x_ptr.special = ConstPtrSpecialNull;
1193611977 } else if (is_opt_err_set(wanted_type)) {
11937 result->value.data.x_err_set = nullptr;
11978 result->value->data.x_err_set = nullptr;
1193811979 } else {
11939 result->value.data.x_optional = nullptr;
11980 result->value->data.x_optional = nullptr;
1194011981 }
1194111982 return result;
1194211983}
......@@ -11948,12 +11989,12 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
1194811989 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
1194911990 assert(instr_is_comptime(value));
1195011991
11951 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
11992 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1195211993 assert(val != nullptr);
1195311994
1195411995 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11955 result->value.data.x_ptr.special = ConstPtrSpecialNull;
11956 result->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
11996 result->value->data.x_ptr.special = ConstPtrSpecialNull;
11997 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1195711998 return result;
1195811999}
1195912000
......@@ -11962,36 +12003,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1196212003{
1196312004 Error err;
1196412005
11965 if (type_is_invalid(value->value.type))
12006 if (type_is_invalid(value->value->type))
1196612007 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)))
1196912010 return ira->codegen->invalid_instruction;
1197012011
1197112012 if (instr_is_comptime(value)) {
11972 ConstExprValue *val = ir_resolve_const(ira, value, LazyOk);
12013 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
1197312014 if (!val)
1197412015 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,
1197612017 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
1197712018 }
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,
1198012021 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1198112022
1198212023 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))
1198312024 return ira->codegen->invalid_instruction;
1198412025
1198512026 IrInstruction *result_loc;
11986 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,
12027 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {
12028 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,
1198812029 false, true);
1198912030 } else {
1199012031 result_loc = nullptr;
1199112032 }
1199212033
1199312034 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;
1199512036 return new_instruction;
1199612037}
1199712038
......@@ -12004,39 +12045,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1200412045
1200512046 IrInstruction *array_ptr = nullptr;
1200612047 IrInstruction *array;
12007 if (array_arg->value.type->id == ZigTypeIdPointer) {
12048 if (array_arg->value->type->id == ZigTypeIdPointer) {
1200812049 array = ir_get_deref(ira, source_instr, array_arg, nullptr);
1200912050 array_ptr = array_arg;
1201012051 } else {
1201112052 array = array_arg;
1201212053 }
12013 ZigType *array_type = array->value.type;
12054 ZigType *array_type = array->value->type;
1201412055 assert(array_type->id == ZigTypeIdArray);
1201512056
1201612057 if (instr_is_comptime(array) || array_type->data.array.len == 0) {
1201712058 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);
12019 result->value.type = wanted_type;
12059 init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true);
12060 result->value->type = wanted_type;
1202012061 return result;
1202112062 }
1202212063
1202312064 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
1202612067 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
1202912070 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
1203012071
1203112072 if (result_loc == nullptr) result_loc = no_result_loc();
1203212073 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,
1203312074 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)) {
1203512076 return result_loc_inst;
1203612077 }
1203712078 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;
12039 result->value.data.rh_slice.len = array_type->data.array.len;
12079 result->value->data.rh_slice.id = RuntimeHintSliceIdLen;
12080 result->value->data.rh_slice.len = array_type->data.array.len;
1204012081
1204112082 return result;
1204212083}
......@@ -12065,19 +12106,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1206512106
1206612107 IrInstruction *enum_target;
1206712108 ZigType *enum_type;
12068 if (target->value.type->id == ZigTypeIdUnion) {
12069 enum_type = ir_resolve_union_tag_type(ira, target, target->value.type);
12109 if (target->value->type->id == ZigTypeIdUnion) {
12110 enum_type = ir_resolve_union_tag_type(ira, target, target->value->type);
1207012111 if (type_is_invalid(enum_type))
1207112112 return ira->codegen->invalid_instruction;
1207212113 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))
1207412115 return ira->codegen->invalid_instruction;
12075 } else if (target->value.type->id == ZigTypeIdEnum) {
12116 } else if (target->value->type->id == ZigTypeIdEnum) {
1207612117 enum_target = target;
12077 enum_type = target->value.type;
12118 enum_type = target->value->type;
1207812119 } else {
1207912120 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)));
1208112122 return ira->codegen->invalid_instruction;
1208212123 }
1208312124
......@@ -12092,41 +12133,41 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1209212133 enum_type->data.enumeration.src_field_count == 1)
1209312134 {
1209412135 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,
1209612137 &enum_type->data.enumeration.fields[0].value);
1209712138 return result;
1209812139 }
1209912140
1210012141 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);
1210212143 if (!val)
1210312144 return ira->codegen->invalid_instruction;
1210412145 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);
1210612147 return result;
1210712148 }
1210812149
1210912150 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
1211012151 source_instr->source_node, enum_target);
12111 result->value.type = tag_type;
12152 result->value->type = tag_type;
1211212153 return result;
1211312154}
1211412155
1211512156static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
1211612157 IrInstruction *target, ZigType *wanted_type)
1211712158{
12118 assert(target->value.type->id == ZigTypeIdUnion);
12159 assert(target->value->type->id == ZigTypeIdUnion);
1211912160 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
1212212163 if (instr_is_comptime(target)) {
12123 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12164 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1212412165 if (!val)
1212512166 return ira->codegen->invalid_instruction;
1212612167 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12127 result->value.special = ConstValSpecialStatic;
12128 result->value.type = wanted_type;
12129 bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_union.tag);
12168 result->value->special = ConstValSpecialStatic;
12169 result->value->type = wanted_type;
12170 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
1213012171 return result;
1213112172 }
1213212173
......@@ -12135,16 +12176,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1213512176 wanted_type->data.enumeration.src_field_count == 1)
1213612177 {
1213712178 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12138 result->value.special = ConstValSpecialStatic;
12139 result->value.type = wanted_type;
12140 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);
12179 result->value->special = ConstValSpecialStatic;
12180 result->value->type = wanted_type;
12181 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
12182 bigint_init_bigint(&result->value->data.x_enum_tag, &enum_field->value);
1214212183 return result;
1214312184 }
1214412185
1214512186 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,
1214612187 source_instr->source_node, target);
12147 result->value.type = wanted_type;
12188 result->value->type = wanted_type;
1214812189 return result;
1214912190}
1215012191
......@@ -12152,7 +12193,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
1215212193 IrInstruction *target, ZigType *wanted_type)
1215312194{
1215412195 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12155 result->value.special = ConstValSpecialUndef;
12196 result->value->special = ConstValSpecialUndef;
1215612197 return result;
1215712198}
1215812199
......@@ -12166,11 +12207,11 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1216612207 return ira->codegen->invalid_instruction;
1216712208
1216812209 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))
1217012211 return ira->codegen->invalid_instruction;
1217112212
1217212213 if (instr_is_comptime(target)) {
12173 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12214 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1217412215 if (!val)
1217512216 return ira->codegen->invalid_instruction;
1217612217 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
1220112242 }
1220212243
1220312244 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12204 result->value.special = ConstValSpecialStatic;
12205 result->value.type = wanted_type;
12206 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);
12208 result->value.data.x_union.payload->special = ConstValSpecialStatic;
12209 result->value.data.x_union.payload->type = field_type;
12245 result->value->special = ConstValSpecialStatic;
12246 result->value->type = wanted_type;
12247 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
12248 result->value->data.x_union.payload = create_const_vals(1);
12249 result->value->data.x_union.payload->special = ConstValSpecialStatic;
12250 result->value->data.x_union.payload->type = field_type;
1221012251 return result;
1221112252 }
1221212253
......@@ -12214,7 +12255,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1221412255 // and in fact it's a noop cast because the union value is just the enum value
1221512256 if (wanted_type->data.unionation.gen_field_count == 0) {
1221612257 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;
1221812259 return result;
1221912260 }
1222012261
......@@ -12245,7 +12286,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1224512286 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1224612287
1224712288 if (instr_is_comptime(target)) {
12248 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12289 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1224912290 if (!val)
1225012291 return ira->codegen->invalid_instruction;
1225112292 if (wanted_type->id == ZigTypeIdInt) {
......@@ -12259,16 +12300,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1225912300 {
1226012301 ir_add_error(ira, source_instr,
1226112302 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)));
1226312304 return ira->codegen->invalid_instruction;
1226412305 }
1226512306 }
1226612307 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12267 result->value.type = wanted_type;
12308 result->value->type = wanted_type;
1226812309 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);
1227012311 } else {
12271 float_init_float(&result->value, val);
12312 float_init_float(result->value, val);
1227212313 }
1227312314 return result;
1227412315 }
......@@ -12278,16 +12319,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1227812319 // the target is zero.
1227912320 if (!type_has_bits(wanted_type)) {
1228012321 assert(wanted_type->id == ZigTypeIdInt);
12281 assert(type_has_bits(target->value.type));
12322 assert(type_has_bits(target->value->type));
1228212323 ir_build_assert_zero(ira, source_instr, target);
1228312324 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);
12284 result->value.type = wanted_type;
12325 result->value->type = wanted_type;
1228512326 return result;
1228612327 }
1228712328
1228812329 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
1228912330 source_instr->source_node, target);
12290 result->value.type = wanted_type;
12331 result->value->type = wanted_type;
1229112332 return result;
1229212333}
1229312334
......@@ -12297,7 +12338,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1229712338 Error err;
1229812339 assert(wanted_type->id == ZigTypeIdEnum);
1229912340
12300 ZigType *actual_type = target->value.type;
12341 ZigType *actual_type = target->value->type;
1230112342
1230212343 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
1230312344 return ira->codegen->invalid_instruction;
......@@ -12313,7 +12354,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1231312354 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
1231412355
1231512356 if (instr_is_comptime(target)) {
12316 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12357 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1231712358 if (!val)
1231812359 return ira->codegen->invalid_instruction;
1231912360
......@@ -12330,28 +12371,28 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1233012371 }
1233112372
1233212373 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);
1233412375 return result;
1233512376 }
1233612377
1233712378 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
1233812379 source_instr->source_node, nullptr, target);
12339 result->value.type = wanted_type;
12380 result->value->type = wanted_type;
1234012381 return result;
1234112382}
1234212383
1234312384static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
1234412385 IrInstruction *target, ZigType *wanted_type)
1234512386{
12346 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12387 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1234712388 if (!val)
1234812389 return ira->codegen->invalid_instruction;
1234912390
1235012391 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1235112392 if (wanted_type->id == ZigTypeIdComptimeFloat) {
12352 float_init_float(&result->value, val);
12393 float_init_float(result->value, val);
1235312394 } 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);
1235512396 } else {
1235612397 zig_unreachable();
1235712398 }
......@@ -12361,12 +12402,12 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1236112402static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
1236212403 ZigType *wanted_type)
1236312404{
12364 assert(target->value.type->id == ZigTypeIdInt);
12365 assert(!target->value.type->data.integral.is_signed);
12405 assert(target->value->type->id == ZigTypeIdInt);
12406 assert(!target->value->type->data.integral.is_signed);
1236612407 assert(wanted_type->id == ZigTypeIdErrorSet);
1236712408
1236812409 if (instr_is_comptime(target)) {
12369 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12410 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1237012411 if (!val)
1237112412 return ira->codegen->invalid_instruction;
1237212413
......@@ -12389,7 +12430,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1238912430 }
1239012431
1239112432 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);
1239312434 return result;
1239412435 } else {
1239512436 ErrorTableEntry *err = nullptr;
......@@ -12412,13 +12453,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1241212453 return ira->codegen->invalid_instruction;
1241312454 }
1241412455
12415 result->value.data.x_err_set = err;
12456 result->value->data.x_err_set = err;
1241612457 return result;
1241712458 }
1241812459 }
1241912460
1242012461 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;
1242212463 return result;
1242312464}
1242412465
......@@ -12427,10 +12468,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1242712468{
1242812469 assert(wanted_type->id == ZigTypeIdInt);
1242912470
12430 ZigType *err_type = target->value.type;
12471 ZigType *err_type = target->value->type;
1243112472
1243212473 if (instr_is_comptime(target)) {
12433 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12474 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1243412475 if (!val)
1243512476 return ira->codegen->invalid_instruction;
1243612477
......@@ -12444,11 +12485,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1244412485 } else {
1244512486 zig_unreachable();
1244612487 }
12447 result->value.type = wanted_type;
12488 result->value->type = wanted_type;
1244812489 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,
1245212493 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))
1245312494 {
1245412495 ir_add_error_node(ira, source_instr->source_node,
......@@ -12474,12 +12515,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1247412515 }
1247512516 if (err_set_type->data.error_set.err_count == 0) {
1247612517 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);
1247812519 return result;
1247912520 } else if (err_set_type->data.error_set.err_count == 1) {
1248012521 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1248112522 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);
1248312524 return result;
1248412525 }
1248512526 }
......@@ -12493,7 +12534,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1249312534 }
1249412535
1249512536 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;
1249712538 return result;
1249812539}
1249912540
......@@ -12502,25 +12543,25 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1250212543{
1250312544 assert(wanted_type->id == ZigTypeIdPointer);
1250412545 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)))
1250612547 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);
12508 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type));
12548 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
12549 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
1250912550 ZigType *array_type = wanted_type->data.pointer.child_type;
1251012551 assert(array_type->id == ZigTypeIdArray);
1251112552 assert(array_type->data.array.len == 1);
1251212553
1251312554 if (instr_is_comptime(target)) {
12514 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
12555 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1251512556 if (!val)
1251612557 return ira->codegen->invalid_instruction;
1251712558
1251812559 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);
1252012561 if (pointee == nullptr)
1252112562 return ira->codegen->invalid_instruction;
1252212563 if (pointee->special != ConstValSpecialRuntime) {
12523 ConstExprValue *array_val = create_const_vals(1);
12564 ZigValue *array_val = create_const_vals(1);
1252412565 array_val->special = ConstValSpecialStatic;
1252512566 array_val->type = array_type;
1252612567 array_val->data.x_array.special = ConstArraySpecialNone;
......@@ -12530,11 +12571,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1253012571
1253112572 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1253212573 source_instr->scope, source_instr->source_node);
12533 const_instruction->base.value.type = wanted_type;
12534 const_instruction->base.value.special = ConstValSpecialStatic;
12535 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef;
12536 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;
12574 const_instruction->base.value->type = wanted_type;
12575 const_instruction->base.value->special = ConstValSpecialStatic;
12576 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef;
12577 const_instruction->base.value->data.x_ptr.data.ref.pointee = array_val;
12578 const_instruction->base.value->data.x_ptr.mut = val->data.x_ptr.mut;
1253812579 return &const_instruction->base;
1253912580 }
1254012581 }
......@@ -12542,7 +12583,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1254212583 // pointer to array and pointer to single item are represented the same way at runtime
1254312584 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,
1254412585 wanted_type, target, CastOpBitCast);
12545 result->value.type = wanted_type;
12586 result->value->type = wanted_type;
1254612587 return result;
1254712588}
1254812589
......@@ -12724,10 +12765,10 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
1272412765 IrInstruction *array, ZigType *vector_type)
1272512766{
1272612767 if (instr_is_comptime(array)) {
12727 // arrays and vectors have the same ConstExprValue representation
12768 // arrays and vectors have the same ZigValue representation
1272812769 IrInstruction *result = ir_const(ira, source_instr, vector_type);
12729 copy_const_val(&result->value, &array->value, false);
12730 result->value.type = vector_type;
12770 copy_const_val(result->value, array->value, false);
12771 result->value->type = vector_type;
1273112772 return result;
1273212773 }
1273312774 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 *
1273712778 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)
1273812779{
1273912780 if (instr_is_comptime(vector)) {
12740 // arrays and vectors have the same ConstExprValue representation
12781 // arrays and vectors have the same ZigValue representation
1274112782 IrInstruction *result = ir_const(ira, source_instr, array_type);
12742 copy_const_val(&result->value, &vector->value, false);
12743 result->value.type = array_type;
12783 copy_const_val(result->value, vector->value, false);
12784 result->value->type = array_type;
1274412785 return result;
1274512786 }
1274612787 if (result_loc == nullptr) {
......@@ -12748,7 +12789,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1274812789 }
1274912790 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
1275012791 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)) {
1275212793 return result_loc_inst;
1275312794 }
1275412795 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
1276112802 if (instr_is_comptime(integer)) {
1276212803 unsigned_integer = integer;
1276312804 } 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 >
1276712808 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)
1276812809 {
1276912810 ir_add_error(ira, source_instr,
1277012811 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),
1277212813 buf_ptr(&dest_type->name)));
1277312814 return ira->codegen->invalid_instruction;
1277412815 }
1277512816
12776 if (integer->value.type->data.integral.is_signed) {
12817 if (integer->value->type->data.integral.is_signed) {
1277712818 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);
1277912820 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))
1278112822 return ira->codegen->invalid_instruction;
1278212823 } else {
1278312824 unsigned_integer = integer;
......@@ -12807,16 +12848,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
1280712848 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
1280812849 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);
1281112852 if (field == nullptr) {
1281212853 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)));
1281412855 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
1281512856 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
1281612857 return ira->codegen->invalid_instruction;
1281712858 }
1281812859 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
1282112862 return result;
1282212863}
......@@ -12885,7 +12926,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst
1288512926{
1288612927 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
1288712928 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);
1288912930 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
1289012931}
1289112932
......@@ -12893,7 +12934,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1289312934 ZigType *wanted_type, IrInstruction *value)
1289412935{
1289512936 Error err;
12896 ZigType *actual_type = value->value.type;
12937 ZigType *actual_type = value->value->type;
1289712938 AstNode *source_node = source_instr->source_node;
1289812939
1289912940 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
1291512956 }
1291612957
1291712958 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);
1291912960 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.
1292012961 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&
1292112962 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)
1292212963 {
12923 ir_assert(value->value.data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
12924 ZigFn *fn = value->value.data.x_ptr.data.fn.fn_entry;
12964 ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
12965 ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry;
1292512966 if (fn->inferred_async_node == nullptr) {
1292612967 fn->inferred_async_node = source_instr->source_node;
1292712968 }
......@@ -12963,7 +13004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1296313004 {
1296413005 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
1296513006 wanted_child_type);
12966 if (type_is_invalid(cast1->value.type))
13007 if (type_is_invalid(cast1->value->type))
1296713008 return ira->codegen->invalid_instruction;
1296813009 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
1296913010 }
......@@ -12999,11 +13040,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1299913040 actual_type->id == ZigTypeIdComptimeFloat)
1300013041 {
1300113042 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))
1300313044 return ira->codegen->invalid_instruction;
1300413045
1300513046 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))
1300713048 return ira->codegen->invalid_instruction;
1300813049
1300913050 return cast2;
......@@ -13018,29 +13059,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1301813059 (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt ||
1301913060 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
1302013061 {
13021 if (value->value.special == ConstValSpecialUndef) {
13062 if (value->value->special == ConstValSpecialUndef) {
1302213063 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13023 result->value.special = ConstValSpecialUndef;
13064 result->value->special = ConstValSpecialUndef;
1302413065 return result;
1302513066 }
1302613067 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
1302713068 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
1302813069 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1302913070 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13030 copy_const_val(&result->value, &value->value, false);
13031 result->value.type = wanted_type;
13071 copy_const_val(result->value, value->value, false);
13072 result->value->type = wanted_type;
1303213073 } else {
13033 float_init_bigint(&result->value.data.x_bigint, &value->value);
13074 float_init_bigint(&result->value->data.x_bigint, value->value);
1303413075 }
1303513076 return result;
1303613077 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
1303713078 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1303813079 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
1303913080 BigFloat bf;
13040 bigfloat_init_bigint(&bf, &value->value.data.x_bigint);
13041 float_init_bigfloat(&result->value, &bf);
13081 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
13082 float_init_bigfloat(result->value, &bf);
1304213083 } else {
13043 float_init_float(&result->value, &value->value);
13084 float_init_float(result->value, value->value);
1304413085 }
1304513086 return result;
1304613087 }
......@@ -13102,11 +13143,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1310213143 source_node, false).id == ConstCastResultIdOk)
1310313144 {
1310413145 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))
1310613147 return ira->codegen->invalid_instruction;
1310713148
1310813149 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))
1311013151 return ira->codegen->invalid_instruction;
1311113152
1311213153 return cast2;
......@@ -13121,11 +13162,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1312113162 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1312213163 {
1312313164 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))
1312513166 return ira->codegen->invalid_instruction;
1312613167
1312713168 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))
1312913170 return ira->codegen->invalid_instruction;
1313013171
1313113172 return cast2;
......@@ -13202,11 +13243,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1320213243 if (ok_align) {
1320313244 if (wanted_type->id == ZigTypeIdErrorUnion) {
1320413245 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))
1320613247 return ira->codegen->invalid_instruction;
1320713248
1320813249 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))
1321013251 return ira->codegen->invalid_instruction;
1321113252
1321213253 return cast2;
......@@ -13309,11 +13350,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1330913350 source_node, false).id == ConstCastResultIdOk)
1331013351 {
1331113352 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))
1331313354 return ira->codegen->invalid_instruction;
1331413355
1331513356 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))
1331713358 return ira->codegen->invalid_instruction;
1331813359
1331913360 return cast2;
......@@ -13529,13 +13570,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
1352913570 assert(value);
1353013571 assert(value != ira->codegen->invalid_instruction);
1353113572 assert(!expected_type || !type_is_invalid(expected_type));
13532 assert(value->value.type);
13533 assert(!type_is_invalid(value->value.type));
13573 assert(value->value->type);
13574 assert(!type_is_invalid(value->value->type));
1353413575 if (expected_type == nullptr)
1353513576 return value; // anything will do
13536 if (expected_type == value->value.type)
13577 if (expected_type == value->value->type)
1353713578 return value; // match
13538 if (value->value.type->id == ZigTypeIdUnreachable)
13579 if (value->value->type->id == ZigTypeIdUnreachable)
1353913580 return value;
1354013581
1354113582 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
1354913590 ResultLoc *result_loc)
1355013591{
1355113592 Error err;
13552 ZigType *ptr_type = ptr->value.type;
13593 ZigType *ptr_type = ptr->value->type;
1355313594 if (type_is_invalid(ptr_type))
1355413595 return ira->codegen->invalid_instruction;
1355513596
......@@ -13571,24 +13612,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1357113612 break;
1357213613 }
1357313614 if (instr_is_comptime(ptr)) {
13574 if (ptr->value.special == ConstValSpecialUndef) {
13615 if (ptr->value->special == ConstValSpecialUndef) {
1357513616 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
1357613617 return ira->codegen->invalid_instruction;
1357713618 }
13578 if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {
13579 ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);
13619 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
13620 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
1358013621 if (child_type == ira->codegen->builtin_types.entry_var) {
1358113622 child_type = pointee->type;
1358213623 }
1358313624 if (pointee->special != ConstValSpecialRuntime) {
1358413625 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,
13587 &ptr->value)))
13627 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
13628 ptr->value)))
1358813629 {
1358913630 return ira->codegen->invalid_instruction;
1359013631 }
13591 result->value.type = child_type;
13632 result->value->type = child_type;
1359213633 return result;
1359313634 }
1359413635 }
......@@ -13626,7 +13667,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1362613667 if (result_loc == nullptr) result_loc = no_result_loc();
1362713668 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,
1362813669 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)) {
1363013671 return result_loc_inst;
1363113672 }
1363213673 } else {
......@@ -13637,7 +13678,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1363713678}
1363813679
1363913680static 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)
1364113682{
1364213683 Error err;
1364313684 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
1366013701}
1366113702
1366213703static 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))
1366413705 return false;
1366513706
1366613707 // Look for this pattern: `*align(@alignOf(T)) T`.
1366713708 // This can be resolved to be `*out = 0` without resolving any alignment.
13668 if (elem_type != nullptr && value->value.special == ConstValSpecialLazy &&
13669 value->value.data.x_lazy->id == LazyValueIdAlignOf)
13709 if (elem_type != nullptr && value->value->special == ConstValSpecialLazy &&
13710 value->value->data.x_lazy->id == LazyValueIdAlignOf)
1367013711 {
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
1367313714 ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type);
1367413715 if (type_is_invalid(lazy_elem_type))
......@@ -13681,22 +13722,22 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
1368113722 }
1368213723
1368313724 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))
1368513726 return false;
1368613727
1368713728 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
13688 &casted_value->value, out);
13729 casted_value->value, out);
1368913730}
1369013731
1369113732static 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))
1369313734 return false;
1369413735
1369513736 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))
1369713738 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);
1370013741 if (!const_val)
1370113742 return false;
1370213743
......@@ -13709,14 +13750,14 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
1370913750}
1371013751
1371113752static 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))
1371313754 return false;
1371413755
1371513756 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))
1371713758 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);
1372013761 if (!const_val)
1372113762 return false;
1372213763
......@@ -13733,18 +13774,18 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
1373313774}
1373413775
1373513776static 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))
1373713778 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");
1374013781 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
1374113782 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1374213783
1374313784 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))
1374513786 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);
1374813789 if (!const_val)
1374913790 return false;
1375013791
......@@ -13753,18 +13794,18 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
1375313794}
1375413795
1375513796static 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))
1375713798 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");
1376013801 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
1376113802 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1376213803
1376313804 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))
1376513806 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);
1376813809 if (!const_val)
1376913810 return false;
1377013811
......@@ -13773,18 +13814,18 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
1377313814}
1377413815
1377513816static 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))
1377713818 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");
1378013821 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
1378113822 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1378213823
1378313824 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))
1378513826 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);
1378813829 if (!const_val)
1378913830 return false;
1379013831
......@@ -13793,18 +13834,18 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
1379313834}
1379413835
1379513836static 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))
1379713838 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");
1380013841 assert(float_mode_val->type->id == ZigTypeIdMetaType);
1380113842 ZigType *float_mode_type = float_mode_val->data.x_type;
1380213843
1380313844 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))
1380513846 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);
1380813849 if (!const_val)
1380913850 return false;
1381013851
......@@ -13813,25 +13854,25 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
1381313854}
1381413855
1381513856static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13816 if (type_is_invalid(value->value.type))
13857 if (type_is_invalid(value->value->type))
1381713858 return nullptr;
1381813859
1381913860 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1382013861 true, false, PtrLenUnknown, 0, 0, 0, false);
1382113862 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
1382213863 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))
1382413865 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);
1382713868 if (!const_val)
1382813869 return nullptr;
1382913870
13830 ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13831 ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index];
13871 ZigValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13872 ZigValue *len_field = const_val->data.x_struct.fields[slice_len_index];
1383213873
1383313874 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;
1383513876 expand_undef_array(ira->codegen, array_val);
1383613877 size_t len = bigint_as_usize(&len_field->data.x_bigint);
1383713878 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) {
1384113882 buf_resize(result, len);
1384213883 for (size_t i = 0; i < len; i += 1) {
1384313884 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];
1384513886 if (char_val->special == ConstValSpecialUndef) {
1384613887 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
1384713888 return nullptr;
......@@ -13858,7 +13899,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1385813899 IrInstructionAddImplicitReturnType *instruction)
1385913900{
1386013901 IrInstruction *value = instruction->value->child;
13861 if (type_is_invalid(value->value.type))
13902 if (type_is_invalid(value->value->type))
1386213903 return ir_unreach_error(ira);
1386313904
1386413905 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
1387013911
1387113912static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {
1387213913 IrInstruction *operand = instruction->operand->child;
13873 if (type_is_invalid(operand->value.type))
13914 if (type_is_invalid(operand->value->type))
1387413915 return ir_unreach_error(ira);
1387513916
1387613917 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)) {
1387813919 AstNode *source_node = ira->explicit_return_type_source_node;
1387913920 if (source_node != nullptr) {
1388013921 ErrorMsg *msg = ira->codegen->errors.last();
......@@ -13890,13 +13931,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1389013931 // result location mechanism took care of it.
1389113932 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
1389213933 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;
1389413935 return ir_finish_anal(ira, result);
1389513936 }
1389613937
13897 if (casted_operand->value.special == ConstValSpecialRuntime &&
13898 casted_operand->value.type->id == ZigTypeIdPointer &&
13899 casted_operand->value.data.rh_ptr == RuntimeHintPtrStack)
13938 if (casted_operand->value->special == ConstValSpecialRuntime &&
13939 casted_operand->value->type->id == ZigTypeIdPointer &&
13940 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
1390013941 {
1390113942 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));
1390213943 return ir_unreach_error(ira);
......@@ -13904,23 +13945,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1390413945
1390513946 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
1390613947 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;
1390813949 return ir_finish_anal(ira, result);
1390913950}
1391013951
1391113952static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
1391213953 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);
1391413955 return result;
1391513956}
1391613957
1391713958static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1391813959 IrInstruction *op1 = bin_op_instruction->op1->child;
13919 if (type_is_invalid(op1->value.type))
13960 if (type_is_invalid(op1->value->type))
1392013961 return ira->codegen->invalid_instruction;
1392113962
1392213963 IrInstruction *op2 = bin_op_instruction->op2->child;
13923 if (type_is_invalid(op2->value.type))
13964 if (type_is_invalid(op2->value->type))
1392413965 return ira->codegen->invalid_instruction;
1392513966
1392613967 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
......@@ -13934,16 +13975,16 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1393413975 return ira->codegen->invalid_instruction;
1393513976
1393613977 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);
1393813979 if (op1_val == nullptr)
1393913980 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);
1394213983 if (op2_val == nullptr)
1394313984 return ira->codegen->invalid_instruction;
1394413985
13945 assert(casted_op1->value.type->id == ZigTypeIdBool);
13946 assert(casted_op2->value.type->id == ZigTypeIdBool);
13986 assert(casted_op1->value->type->id == ZigTypeIdBool);
13987 assert(casted_op2->value->type->id == ZigTypeIdBool);
1394713988 bool result_bool;
1394813989 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
1394913990 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
1395813999 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
1395914000 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
1396014001 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;
1396214003 return result;
1396314004}
1396414005
......@@ -13981,7 +14022,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
1398114022 }
1398214023}
1398314024
13984static bool optional_value_is_null(ConstExprValue *val) {
14025static bool optional_value_is_null(ZigValue *val) {
1398514026 assert(val->special == ConstValSpecialStatic);
1398614027 if (get_codegen_ptr_type(val->type) != nullptr) {
1398714028 if (val->data.x_ptr.special == ConstPtrSpecialNull) {
......@@ -13999,7 +14040,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
1399914040}
1400014041
1400114042static 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,
1400314044 bool one_possible_value) {
1400414045 if (op1_val->special == ConstValSpecialUndef ||
1400514046 op2_val->special == ConstValSpecialUndef)
......@@ -14052,7 +14093,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
1405214093}
1405314094
1405414095// 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) {
1405614097 Error err;
1405714098
1405814099 switch (val->special) {
......@@ -14079,7 +14120,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *resul
1407914120 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
1408014121 IrAnalyze *ira = lazy_size_of->ira;
1408114122 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,
1408314124 nullptr, nullptr, &is_zero_bits)))
1408414125 {
1408514126 return err;
......@@ -14098,33 +14139,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1409814139 Error err;
1409914140
1410014141 IrInstruction *op1 = bin_op_instruction->op1->child;
14101 if (type_is_invalid(op1->value.type))
14142 if (type_is_invalid(op1->value->type))
1410214143 return ira->codegen->invalid_instruction;
1410314144
1410414145 IrInstruction *op2 = bin_op_instruction->op2->child;
14105 if (type_is_invalid(op2->value.type))
14146 if (type_is_invalid(op2->value->type))
1410614147 return ira->codegen->invalid_instruction;
1410714148
1410814149 AstNode *source_node = bin_op_instruction->base.source_node;
1410914150
1411014151 IrBinOp op_id = bin_op_instruction->op_id;
1411114152 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) {
1411314154 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));
1411414155 } else if (is_equality_cmp &&
14115 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||
14116 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional)))
14156 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
14157 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
1411714158 {
1411814159 IrInstruction *maybe_op;
14119 if (op1->value.type->id == ZigTypeIdNull) {
14160 if (op1->value->type->id == ZigTypeIdNull) {
1412014161 maybe_op = op2;
14121 } else if (op2->value.type->id == ZigTypeIdNull) {
14162 } else if (op2->value->type->id == ZigTypeIdNull) {
1412214163 maybe_op = op1;
1412314164 } else {
1412414165 zig_unreachable();
1412514166 }
1412614167 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);
1412814169 if (!maybe_val)
1412914170 return ira->codegen->invalid_instruction;
1413014171 bool is_null = optional_value_is_null(maybe_val);
......@@ -14134,32 +14175,32 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1413414175
1413514176 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
1413614177 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
1413914180 if (op_id == IrBinOpCmpEq) {
1414014181 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
1414114182 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;
1414314184 return result;
1414414185 } else {
1414514186 return is_non_null;
1414614187 }
1414714188 } else if (is_equality_cmp &&
14148 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer &&
14149 op2->value.type->data.pointer.ptr_len == PtrLenC) ||
14150 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer &&
14151 op1->value.type->data.pointer.ptr_len == PtrLenC)))
14189 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdPointer &&
14190 op2->value->type->data.pointer.ptr_len == PtrLenC) ||
14191 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
14192 op1->value->type->data.pointer.ptr_len == PtrLenC)))
1415214193 {
1415314194 IrInstruction *c_ptr_op;
14154 if (op1->value.type->id == ZigTypeIdNull) {
14195 if (op1->value->type->id == ZigTypeIdNull) {
1415514196 c_ptr_op = op2;
14156 } else if (op2->value.type->id == ZigTypeIdNull) {
14197 } else if (op2->value->type->id == ZigTypeIdNull) {
1415714198 c_ptr_op = op1;
1415814199 } else {
1415914200 zig_unreachable();
1416014201 }
1416114202 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);
1416314204 if (!c_ptr_val)
1416414205 return ira->codegen->invalid_instruction;
1416514206 if (c_ptr_val->special == ConstValSpecialUndef)
......@@ -14172,46 +14213,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1417214213 }
1417314214 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
1417414215 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
1417714218 if (op_id == IrBinOpCmpEq) {
1417814219 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
1417914220 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;
1418114222 return result;
1418214223 } else {
1418314224 return is_non_null;
1418414225 }
14185 } 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;
14226 } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) {
14227 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
1418714228 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
1418814229 buf_ptr(&non_null_type->name)));
1418914230 return ira->codegen->invalid_instruction;
1419014231 } else if (is_equality_cmp && (
14191 (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) ||
14192 (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion)))
14232 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
14233 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
1419314234 {
1419414235 // Support equality comparison between a union's tag value and a enum literal
14195 IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2;
14196 IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1;
14236 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
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;
1419914240 assert(tag_type != nullptr);
1420014241
1420114242 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))
1420314244 return ira->codegen->invalid_instruction;
1420414245
1420514246 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))
1420714248 return ira->codegen->invalid_instruction;
1420814249
1420914250 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);
1421114252 if (!const_union_val)
1421214253 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);
1421514256 if (!const_enum_val)
1421614257 return ira->codegen->invalid_instruction;
1421714258
......@@ -14224,17 +14265,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1422414265 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
1422514266 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
1422614267 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
1422914270 return result;
1423014271 }
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) {
1423314274 if (!is_equality_cmp) {
1423414275 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
1423514276 return ira->codegen->invalid_instruction;
1423614277 }
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);
1423814279 if (type_is_invalid(intersect_type)) {
1423914280 return ira->codegen->invalid_instruction;
1424014281 }
......@@ -14247,7 +14288,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1424714288 // (and make it comptime known)
1424814289 // this is a function which is evaluated at comptime and returns an inferred error set will have an empty
1424914290 // 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) {
1425114292 bool are_equal = false;
1425214293 bool answer;
1425314294 if (op_id == IrBinOpCmpEq) {
......@@ -14264,10 +14305,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1426414305 if (intersect_type->data.error_set.err_count == 0) {
1426514306 ir_add_error_node(ira, source_node,
1426614307 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)));
1426814309 return ira->codegen->invalid_instruction;
1426914310 }
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) {
1427114312 bool are_equal = true;
1427214313 bool answer;
1427314314 if (op_id == IrBinOpCmpEq) {
......@@ -14282,10 +14323,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1428214323 }
1428314324
1428414325 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);
1428614327 if (op1_val == nullptr)
1428714328 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);
1428914330 if (op2_val == nullptr)
1429014331 return ira->codegen->invalid_instruction;
1429114332
......@@ -14305,7 +14346,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1430514346 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
1430614347 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
1430714348 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;
1430914350 return result;
1431014351 }
1431114352
......@@ -14390,12 +14431,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1439014431 // Before resolving the values, we special case comparisons against zero. These can often be done
1439114432 // without resolving lazy values, preventing potential dependency loops.
1439214433 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))) {
1439414435 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
1439514436 return ira->codegen->invalid_instruction;
1439614437 }
1439714438 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))) {
1439914440 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
1440014441 return ira->codegen->invalid_instruction;
1440114442 }
......@@ -14430,33 +14471,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1443014471 }
1443114472never_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);
1443414475 if (op1_val == nullptr)
1443514476 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);
1443714478 if (op2_val == nullptr)
1443814479 return ira->codegen->invalid_instruction;
1443914480 if (resolved_type->id != ZigTypeIdVector)
1444014481 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);
1444114482 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,
1444214483 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 =
1444414485 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);
1444714488 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
1444814489 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
1444914490 &op1_val->data.x_array.data.s_none.elements[i],
1445014491 &op2_val->data.x_array.data.s_none.elements[i],
1445114492 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);
1445314494 }
1445414495 return result;
1445514496 }
1445614497
1445714498 // some comparisons with unsigned numbers can be evaluated
1445814499 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
14459 ConstExprValue *known_left_val;
14500 ZigValue *known_left_val;
1446014501 IrBinOp flipped_op_id;
1446114502 if (instr_is_comptime(casted_op1)) {
1446214503 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);
......@@ -14495,16 +14536,16 @@ never_mind_just_calculate_it_normally:
1449514536 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
1449614537 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
1449714538 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,
1449914540 ira->codegen->builtin_types.entry_bool);
1450014541 } else {
14501 result->value.type = ira->codegen->builtin_types.entry_bool;
14542 result->value->type = ira->codegen->builtin_types.entry_bool;
1450214543 }
1450314544 return result;
1450414545}
1450514546
1450614547static 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)
1450814549{
1450914550 bool is_int;
1451014551 bool is_float;
......@@ -14646,7 +14687,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
1464614687 }
1464714688 } else {
1464814689 float_div_trunc(out_val, op1_val, op2_val);
14649 ConstExprValue remainder = {};
14690 ZigValue remainder = {};
1465014691 float_rem(&remainder, op1_val, op2_val);
1465114692 if (float_cmp_zero(&remainder) != CmpEQ) {
1465214693 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
1468414725
1468514726// This works on operands that have already been checked to be comptime known.
1468614727static 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)
1468814729{
1468914730 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);
14690 ConstExprValue *out_val = &result_instruction->value;
14731 ZigValue *out_val = result_instruction->value;
1469114732 if (type_entry->id == ZigTypeIdVector) {
1469214733 expand_undef_array(ira->codegen, op1_val);
1469314734 expand_undef_array(ira->codegen, op2_val);
......@@ -14696,9 +14737,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
1469614737 size_t len = type_entry->data.vector.len;
1469714738 ZigType *scalar_type = type_entry->data.vector.elem_type;
1469814739 for (size_t i = 0; i < len; i += 1) {
14699 ConstExprValue *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];
14701 ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
14740 ZigValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i];
14741 ZigValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i];
14742 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
1470214743 assert(scalar_op1_val->type == scalar_type);
1470314744 assert(scalar_op2_val->type == scalar_type);
1470414745 assert(scalar_out_val->type == scalar_type);
......@@ -14722,52 +14763,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
1472214763
1472314764static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1472414765 IrInstruction *op1 = bin_op_instruction->op1->child;
14725 if (type_is_invalid(op1->value.type))
14766 if (type_is_invalid(op1->value->type))
1472614767 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) {
1472914770 ir_add_error(ira, bin_op_instruction->op1,
1473014771 buf_sprintf("bit shifting operation expected integer type, found '%s'",
14731 buf_ptr(&op1->value.type->name)));
14772 buf_ptr(&op1->value->type->name)));
1473214773 return ira->codegen->invalid_instruction;
1473314774 }
1473414775
1473514776 IrInstruction *op2 = bin_op_instruction->op2->child;
14736 if (type_is_invalid(op2->value.type))
14777 if (type_is_invalid(op2->value->type))
1473714778 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) {
1474014781 ir_add_error(ira, bin_op_instruction->op2,
1474114782 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)));
1474314784 return ira->codegen->invalid_instruction;
1474414785 }
1474514786
1474614787 IrInstruction *casted_op2;
1474714788 IrBinOp op_id = bin_op_instruction->op_id;
14748 if (op1->value.type->id == ZigTypeIdComptimeInt) {
14789 if (op1->value->type->id == ZigTypeIdComptimeInt) {
1474914790 casted_op2 = op2;
1475014791
1475114792 if (op_id == IrBinOpBitShiftLeftLossy) {
1475214793 op_id = IrBinOpBitShiftLeftExact;
1475314794 }
1475414795
14755 if (casted_op2->value.data.x_bigint.is_negative) {
14796 if (casted_op2->value->data.x_bigint.is_negative) {
1475614797 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);
1475814799 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
1475914800 return ira->codegen->invalid_instruction;
1476014801 }
1476114802 } else {
1476214803 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);
1476414805 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
14765 op2->value.type->id == ZigTypeIdComptimeInt) {
14766 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,
14806 op2->value->type->id == ZigTypeIdComptimeInt) {
14807 if (!bigint_fits_in_bits(&op2->value->data.x_bigint,
1476714808 shift_amt_type->data.integral.bit_count,
14768 op2->value.data.x_bigint.is_negative)) {
14809 op2->value->data.x_bigint.is_negative)) {
1476914810 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);
1477114812 ErrorMsg* msg = ir_add_error(ira,
1477214813 &bin_op_instruction->base,
1477314814 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
1478814829 }
1478914830
1479014831 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);
1479214833 if (op1_val == nullptr)
1479314834 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);
1479614837 if (op2_val == nullptr)
1479714838 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);
14800 } else if (op1->value.type->id == ZigTypeIdComptimeInt) {
14840 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val);
14841 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {
1480114842 ir_add_error(ira, &bin_op_instruction->base,
1480214843 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
1480314844 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) {
1480514846 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);
14807 result->value.type = op1->value.type;
14847 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
14848 result->value->type = op1->value->type;
1480814849 return result;
1480914850 }
1481014851
1481114852 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
1481214853 bin_op_instruction->base.source_node, op_id,
1481314854 op1, casted_op2, bin_op_instruction->safety_check_on);
14814 result->value.type = op1->value.type;
14855 result->value->type = op1->value->type;
1481514856 return result;
1481614857}
1481714858
......@@ -14880,42 +14921,42 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1488014921 Error err;
1488114922
1488214923 IrInstruction *op1 = instruction->op1->child;
14883 if (type_is_invalid(op1->value.type))
14924 if (type_is_invalid(op1->value->type))
1488414925 return ira->codegen->invalid_instruction;
1488514926
1488614927 IrInstruction *op2 = instruction->op2->child;
14887 if (type_is_invalid(op2->value.type))
14928 if (type_is_invalid(op2->value->type))
1488814929 return ira->codegen->invalid_instruction;
1488914930
1489014931 IrBinOp op_id = instruction->op_id;
1489114932
1489214933 // 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)) {
1489414935 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))
1489614937 return ira->codegen->invalid_instruction;
1489714938
1489814939 // If either operand is undef, result is undef.
14899 ConstExprValue *op1_val = nullptr;
14900 ConstExprValue *op2_val = nullptr;
14940 ZigValue *op1_val = nullptr;
14941 ZigValue *op2_val = nullptr;
1490114942 if (instr_is_comptime(op1)) {
1490214943 op1_val = ir_resolve_const(ira, op1, UndefOk);
1490314944 if (op1_val == nullptr)
1490414945 return ira->codegen->invalid_instruction;
1490514946 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);
1490714948 }
1490814949 if (instr_is_comptime(casted_op2)) {
1490914950 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
1491014951 if (op2_val == nullptr)
1491114952 return ira->codegen->invalid_instruction;
1491214953 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);
1491414955 }
1491514956
1491614957 if (op2_val != nullptr && op1_val != nullptr &&
14917 (op1->value.data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
14918 op1->value.data.x_ptr.special == ConstPtrSpecialNull))
14958 (op1->value->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
14959 op1->value->data.x_ptr.special == ConstPtrSpecialNull))
1491914960 {
1492014961 uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ?
1492114962 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
1493514976 zig_unreachable();
1493614977 }
1493714978 IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type);
14938 result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
14939 result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;
14940 result->value.data.x_ptr.data.hard_coded_addr.addr = new_addr;
14979 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
14980 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
14981 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
1494114982 return result;
1494214983 }
1494314984
1494414985 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
1494514986 instruction->base.source_node, op_id, op1, casted_op2, true);
14946 result->value.type = op1->value.type;
14987 result->value->type = op1->value->type;
1494714988 return result;
1494814989 }
1494914990
......@@ -14958,21 +14999,21 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1495814999 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
1495915000 resolved_type->id == ZigTypeIdFloat ||
1496015001 (resolved_type->id == ZigTypeIdComptimeFloat &&
14961 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
14962 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
15002 ((bigfloat_cmp_zero(&op1->value->data.x_bigfloat) != CmpGT) !=
15003 (bigfloat_cmp_zero(&op2->value->data.x_bigfloat) != CmpGT))) ||
1496315004 (resolved_type->id == ZigTypeIdComptimeInt &&
14964 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
14965 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
15005 ((bigint_cmp_zero(&op1->value->data.x_bigint) != CmpGT) !=
15006 (bigint_cmp_zero(&op2->value->data.x_bigint) != CmpGT)))
1496615007 );
1496715008 if (op_id == IrBinOpDivUnspecified && is_int) {
1496815009 if (is_signed_div) {
1496915010 bool ok = false;
1497015011 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);
1497215013 if (op1_val == nullptr)
1497315014 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);
1497615017 if (op2_val == nullptr)
1497715018 return ira->codegen->invalid_instruction;
1497815019
......@@ -14995,8 +15036,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1499515036 if (!ok) {
1499615037 ir_add_error(ira, &instruction->base,
1499715038 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
14998 buf_ptr(&op1->value.type->name),
14999 buf_ptr(&op2->value.type->name)));
15039 buf_ptr(&op1->value->type->name),
15040 buf_ptr(&op2->value->type->name)));
1500015041 return ira->codegen->invalid_instruction;
1500115042 }
1500215043 } else {
......@@ -15006,16 +15047,16 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1500615047 if (is_signed_div && (is_int || is_float)) {
1500715048 bool ok = false;
1500815049 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);
1501015051 if (op1_val == nullptr)
1501115052 return ira->codegen->invalid_instruction;
1501215053
1501315054 if (is_int) {
15014 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15055 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1501515056 if (op2_val == nullptr)
1501615057 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) {
1501915060 // the division by zero error will be caught later, but we don't
1502015061 // have a remainder function ambiguity problem
1502115062 ok = true;
......@@ -15031,17 +15072,17 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1503115072 if (casted_op2 == ira->codegen->invalid_instruction)
1503215073 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);
1503515076 if (op2_val == nullptr)
1503615077 return ira->codegen->invalid_instruction;
1503715078
15038 if (float_cmp_zero(&casted_op2->value) == CmpEQ) {
15079 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
1503915080 // the division by zero error will be caught later, but we don't
1504015081 // have a remainder function ambiguity problem
1504115082 ok = true;
1504215083 } else {
15043 ConstExprValue rem_result = {};
15044 ConstExprValue mod_result = {};
15084 ZigValue rem_result = {};
15085 ZigValue mod_result = {};
1504515086 float_rem(&rem_result, op1_val, op2_val);
1504615087 float_mod(&mod_result, op1_val, op2_val);
1504715088 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;
......@@ -15051,8 +15092,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1505115092 if (!ok) {
1505215093 ir_add_error(ira, &instruction->base,
1505315094 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
15054 buf_ptr(&op1->value.type->name),
15055 buf_ptr(&op2->value.type->name)));
15095 buf_ptr(&op1->value->type->name),
15096 buf_ptr(&op2->value->type->name)));
1505615097 return ira->codegen->invalid_instruction;
1505715098 }
1505815099 }
......@@ -15076,8 +15117,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1507615117 AstNode *source_node = instruction->base.source_node;
1507715118 ir_add_error_node(ira, source_node,
1507815119 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
15079 buf_ptr(&op1->value.type->name),
15080 buf_ptr(&op2->value.type->name)));
15120 buf_ptr(&op1->value->type->name),
15121 buf_ptr(&op2->value->type->name)));
1508115122 return ira->codegen->invalid_instruction;
1508215123 }
1508315124
......@@ -15100,10 +15141,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1510015141 return ira->codegen->invalid_instruction;
1510115142
1510215143 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);
1510415145 if (op1_val == nullptr)
1510515146 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);
1510715148 if (op2_val == nullptr)
1510815149 return ira->codegen->invalid_instruction;
1510915150
......@@ -15112,31 +15153,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1511215153
1511315154 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
1511415155 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;
1511615157 return result;
1511715158}
1511815159
1511915160static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
1512015161 IrInstruction *op1 = instruction->op1->child;
15121 ZigType *op1_type = op1->value.type;
15162 ZigType *op1_type = op1->value->type;
1512215163 if (type_is_invalid(op1_type))
1512315164 return ira->codegen->invalid_instruction;
1512415165
1512515166 IrInstruction *op2 = instruction->op2->child;
15126 ZigType *op2_type = op2->value.type;
15167 ZigType *op2_type = op2->value->type;
1512715168 if (type_is_invalid(op2_type))
1512815169 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);
1513115172 if (!op1_val)
1513215173 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);
1513515176 if (!op2_val)
1513615177 return ira->codegen->invalid_instruction;
1513715178
15138 ConstExprValue *sentinel1 = nullptr;
15139 ConstExprValue *op1_array_val;
15179 ZigValue *sentinel1 = nullptr;
15180 ZigValue *op1_array_val;
1514015181 size_t op1_array_index;
1514115182 size_t op1_array_end;
1514215183 ZigType *child_type;
......@@ -15159,11 +15200,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1515915200 } else if (is_slice(op1_type)) {
1516015201 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
1516115202 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];
1516315204 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
1516415205 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
1516515206 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];
1516715208 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
1516815209 sentinel1 = ptr_type->data.pointer.sentinel;
1516915210 } 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
1517815219 op1_array_end = array_type->data.array.len;
1517915220 sentinel1 = array_type->data.array.sentinel;
1518015221 } else {
15181 ir_add_error(ira, op1,
15182 buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name)));
15222 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
1518315223 return ira->codegen->invalid_instruction;
1518415224 }
1518515225
15186 ConstExprValue *sentinel2 = nullptr;
15187 ConstExprValue *op2_array_val;
15226 ZigValue *sentinel2 = nullptr;
15227 ZigValue *op2_array_val;
1518815228 size_t op2_array_index;
1518915229 size_t op2_array_end;
1519015230 bool op2_type_valid;
......@@ -15207,11 +15247,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1520715247 } else if (is_slice(op2_type)) {
1520815248 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
1520915249 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];
1521115251 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
1521215252 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
1521315253 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];
1521515255 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
1521615256
1521715257 sentinel2 = ptr_type->data.pointer.sentinel;
......@@ -15229,17 +15269,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1522915269 sentinel2 = array_type->data.array.sentinel;
1523015270 } else {
1523115271 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)));
1523315273 return ira->codegen->invalid_instruction;
1523415274 }
1523515275 if (!op2_type_valid) {
1523615276 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
1523715277 buf_ptr(&child_type->name),
15238 buf_ptr(&op2->value.type->name)));
15278 buf_ptr(&op2->value->type->name)));
1523915279 return ira->codegen->invalid_instruction;
1524015280 }
1524115281
15242 ConstExprValue *sentinel;
15282 ZigValue *sentinel;
1524315283 if (sentinel1 != nullptr && sentinel2 != nullptr) {
1524415284 // When there is a sentinel mismatch, no sentinel on the result. The type system
1524515285 // will catch this if it is a problem.
......@@ -15254,13 +15294,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1525415294
1525515295 // The type of result is populated in the following if blocks
1525615296 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;
1526015300 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
1526115301 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15262 result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15263
15302 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1526415303 out_array_val = out_val;
1526515304 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
1526615305 out_array_val = create_const_vals(1);
......@@ -15274,7 +15313,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1527415313 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type,
1527515314 true, false, PtrLenUnknown, 0, 0, 0, false,
1527615315 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);
1527815317 out_array_val = create_const_vals(1);
1527915318 out_array_val->special = ConstValSpecialStatic;
1528015319 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
1529115330 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
1529215331 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
1529315332 } 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,
1529515334 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
15296
1529715335 out_array_val = create_const_vals(1);
1529815336 out_array_val->special = ConstValSpecialStatic;
1529915337 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
1531715355
1531815356 size_t next_index = 0;
1531915357 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];
1532115359 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);
1532215360 elem_dest_val->parent.id = ConstParentIdArray;
1532315361 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1532415362 elem_dest_val->parent.data.p_array.elem_index = next_index;
1532515363 }
1532615364 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];
1532815366 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);
1532915367 elem_dest_val->parent.id = ConstParentIdArray;
1533015368 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1533115369 elem_dest_val->parent.data.p_array.elem_index = next_index;
1533215370 }
1533315371 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];
1533515373 copy_const_val(elem_dest_val, sentinel, false);
1533615374 elem_dest_val->parent.id = ConstParentIdArray;
1533715375 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
1534515383
1534615384static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
1534715385 IrInstruction *op1 = instruction->op1->child;
15348 if (type_is_invalid(op1->value.type))
15386 if (type_is_invalid(op1->value->type))
1534915387 return ira->codegen->invalid_instruction;
1535015388
1535115389 IrInstruction *op2 = instruction->op2->child;
15352 if (type_is_invalid(op2->value.type))
15390 if (type_is_invalid(op2->value->type))
1535315391 return ira->codegen->invalid_instruction;
1535415392
1535515393 bool want_ptr_to_array = false;
1535615394 ZigType *array_type;
15357 ConstExprValue *array_val;
15358 if (op1->value.type->id == ZigTypeIdArray) {
15359 array_type = op1->value.type;
15395 ZigValue *array_val;
15396 if (op1->value->type->id == ZigTypeIdArray) {
15397 array_type = op1->value->type;
1536015398 array_val = ir_resolve_const(ira, op1, UndefOk);
1536115399 if (array_val == nullptr)
1536215400 return ira->codegen->invalid_instruction;
15363 } 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)
15401 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
15402 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
1536515403 {
15366 array_type = op1->value.type->data.pointer.child_type;
15404 array_type = op1->value->type->data.pointer.child_type;
1536715405 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))
1536915407 return ira->codegen->invalid_instruction;
1537015408 array_val = ir_resolve_const(ira, array_inst, UndefOk);
1537115409 if (array_val == nullptr)
1537215410 return ira->codegen->invalid_instruction;
1537315411 want_ptr_to_array = true;
1537415412 } 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)));
1537615414 return ira->codegen->invalid_instruction;
1537715415 }
1537815416
......@@ -15397,7 +15435,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1539715435 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
1539815436 } else {
1539915437 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
1540215440 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
1540315441 case OnePossibleValueInvalid:
......@@ -15416,7 +15454,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1541615454 uint64_t i = 0;
1541715455 for (uint64_t x = 0; x < mult_amt; x += 1) {
1541815456 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];
1542015458 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
1542115459 elem_dest_val->parent.id = ConstParentIdArray;
1542215460 elem_dest_val->parent.data.p_array.array_val = out_val;
......@@ -15427,7 +15465,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1542715465 assert(i == new_array_len);
1542815466
1542915467 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];
1543115469 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);
1543215470 elem_dest_val->parent.id = ConstParentIdArray;
1543315471 elem_dest_val->parent.data.p_array.array_val = out_val;
......@@ -15554,25 +15592,25 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1555415592 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
1555515593 // if this is null, a compiler error happened and did not initialize the variable.
1555615594 // 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)) {
1555815596 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);
1555915597 var->var_type = ira->codegen->builtin_types.entry_invalid;
1556015598 return ira->codegen->invalid_instruction;
1556115599 }
1556215600
1556315601 // 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;
1556715605 if (type_is_invalid(result_type)) {
1556815606 result_type = ira->codegen->builtin_types.entry_invalid;
1556915607 } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) {
1557015608 zig_unreachable();
1557115609 }
1557215610
15573 ConstExprValue *init_val = nullptr;
15574 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);
15611 ZigValue *init_val = nullptr;
15612 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15613 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node);
1557615614 if (is_comptime_var) {
1557715615 if (var->gen_is_const) {
1557815616 var->const_value = init_val;
......@@ -15631,7 +15669,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1563115669 new_var->owner_exec = var->owner_exec;
1563215670 new_var->align_bytes = var->align_bytes;
1563315671 if (var->mem_slot_index != SIZE_MAX) {
15634 ConstExprValue *vals = create_const_vals(1);
15672 ZigValue *vals = create_const_vals(1);
1563515673 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;
1563615674 ira->exec_context.mem_slot_list.append(vals);
1563715675 }
......@@ -15665,29 +15703,29 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1566515703 if (init_val != nullptr && value_is_comptime(init_val)) {
1566615704 // Resolve ConstPtrMutInfer
1566715705 if (var->gen_is_const) {
15668 var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
15706 var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1566915707 } else if (is_comptime_var) {
15670 var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar;
15708 var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
1567115709 } else {
1567215710 // we need a runtime ptr but we have a comptime val.
1567315711 // since it's a comptime val there are no instructions for it.
1567415712 // we memcpy the init value here
1567515713 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)) {
1567715715 var->var_type = ira->codegen->builtin_types.entry_invalid;
1567815716 return ira->codegen->invalid_instruction;
1567915717 }
1568015718 // If this assertion trips, something is wrong with the IR instructions, because
1568115719 // we expected the above deref to return a constant value, but it created a runtime
1568215720 // instruction.
15683 assert(deref->value.special != ConstValSpecialRuntime);
15684 var_ptr->value.special = ConstValSpecialRuntime;
15721 assert(deref->value->special != ConstValSpecialRuntime);
15722 var_ptr->value->special = ConstValSpecialRuntime;
1568515723 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);
1568615724 }
1568715725
1568815726 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
1568915727 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);
1569115729 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
1569215730
1569315731 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
1571815756 }
1571915757
1572015758 IrInstruction *target = instruction->target->child;
15721 if (type_is_invalid(target->value.type)) {
15759 if (type_is_invalid(target->value->type)) {
1572215760 return ira->codegen->invalid_instruction;
1572315761 }
1572415762
......@@ -15748,13 +15786,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1574815786 }
1574915787
1575015788 bool want_var_export = false;
15751 switch (target->value.type->id) {
15789 switch (target->value->type->id) {
1575215790 case ZigTypeIdInvalid:
1575315791 case ZigTypeIdUnreachable:
1575415792 zig_unreachable();
1575515793 case ZigTypeIdFn: {
15756 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);
15757 ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
15794 assert(target->value->data.x_ptr.special == ConstPtrSpecialFunction);
15795 ZigFn *fn_entry = target->value->data.x_ptr.data.fn.fn_entry;
1575815796 tld_fn->fn_entry = fn_entry;
1575915797 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
1576015798 switch (cc) {
......@@ -15778,51 +15816,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1577815816 }
1577915817 } break;
1578015818 case ZigTypeIdStruct:
15781 if (is_slice(target->value.type)) {
15819 if (is_slice(target->value->type)) {
1578215820 ir_add_error(ira, target,
15783 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) {
15821 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
15822 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
1578515823 ErrorMsg *msg = ir_add_error(ira, target,
1578615824 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"));
1578815826 } else {
1578915827 want_var_export = true;
1579015828 }
1579115829 break;
1579215830 case ZigTypeIdUnion:
15793 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {
15831 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
1579415832 ErrorMsg *msg = ir_add_error(ira, target,
1579515833 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"));
1579715835 } else {
1579815836 want_var_export = true;
1579915837 }
1580015838 break;
1580115839 case ZigTypeIdEnum:
15802 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {
15840 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
1580315841 ErrorMsg *msg = ir_add_error(ira, target,
1580415842 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"));
1580615844 } else {
1580715845 want_var_export = true;
1580815846 }
1580915847 break;
1581015848 case ZigTypeIdArray: {
1581115849 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)))
1581315851 return ira->codegen->invalid_instruction;
1581415852
1581515853 if (!ok_type) {
1581615854 ir_add_error(ira, target,
1581715855 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)));
1581915857 } else {
1582015858 want_var_export = true;
1582115859 }
1582215860 break;
1582315861 }
1582415862 case ZigTypeIdMetaType: {
15825 ZigType *type_value = target->value.data.x_type;
15863 ZigType *type_value = target->value->data.x_type;
1582615864 switch (type_value->id) {
1582715865 case ZigTypeIdInvalid:
1582815866 zig_unreachable();
......@@ -15898,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1589815936 case ZigTypeIdErrorUnion:
1589915937 case ZigTypeIdErrorSet:
1590015938 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));
1590215940 case ZigTypeIdBoundFn:
1590315941 case ZigTypeIdArgTuple:
1590415942 case ZigTypeIdOpaque:
......@@ -15906,7 +15944,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1590615944 case ZigTypeIdFnFrame:
1590715945 case ZigTypeIdAnyFrame:
1590815946 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)));
1591015948 break;
1591115949 }
1591215950
......@@ -15936,7 +15974,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1593615974 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
1593715975 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
1593815976 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);
15939 ConstExprValue *out_val = &result->value;
15977 ZigValue *out_val = result->value;
1594015978 assert(get_codegen_ptr_type(optional_type) != nullptr);
1594115979 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1594215980 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,
1594415982 }
1594515983 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
1594615984 instruction->base.source_node, instruction->optional);
15947 new_instruction->value.type = optional_type;
15985 new_instruction->value->type = optional_type;
1594815986 return new_instruction;
1594915987 } else {
1595015988 assert(ira->codegen->have_err_ret_tracing);
1595115989 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
1595215990 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;
1595415992 return new_instruction;
1595515993 }
1595615994}
......@@ -15959,11 +15997,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
1595915997 IrInstructionErrorUnion *instruction)
1596015998{
1596115999 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
15962 result->value.special = ConstValSpecialLazy;
16000 result->value->special = ConstValSpecialLazy;
1596316001
1596416002 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1);
1596516003 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;
1596716005 lazy_err_union_type->base.id = LazyValueIdErrUnionType;
1596816006
1596916007 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
1598216020{
1598316021 Error err;
1598416022
15985 ConstExprValue *pointee = create_const_vals(1);
16023 ZigValue *pointee = create_const_vals(1);
1598616024 pointee->special = ConstValSpecialUndef;
1598716025
1598816026 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
15989 result->base.value.special = ConstValSpecialStatic;
15990 result->base.value.data.x_ptr.special = ConstPtrSpecialRef;
15991 result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
15992 result->base.value.data.x_ptr.data.ref.pointee = pointee;
16027 result->base.value->special = ConstValSpecialStatic;
16028 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
16029 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
16030 result->base.value->data.x_ptr.data.ref.pointee = pointee;
1599316031
1599416032 bool var_type_has_bits;
1599516033 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
1600416042 return ira->codegen->invalid_instruction;
1600516043 }
1600616044 }
16007 assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid);
16045 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
1600816046
1600916047 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,
1601116049 PtrLenSingle, align, 0, 0, false);
1601216050
1601316051 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
1603116069 case ResultLocIdCast:
1603216070 return nullptr;
1603316071 case ResultLocIdInstruction:
16034 return result_loc->source_instruction->child->value.type;
16072 return result_loc->source_instruction->child->value->type;
1603516073 case ResultLocIdReturn:
1603616074 return ira->explicit_return_type;
1603716075 case ResultLocIdPeer:
......@@ -16063,13 +16101,13 @@ static bool type_can_bit_cast(ZigType *t) {
1606316101}
1606416102
1606516103static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
16066 ConstExprValue *undef_child = create_const_vals(1);
16067 undef_child->type = ptr->value.type->data.pointer.child_type;
16104 ZigValue *undef_child = create_const_vals(1);
16105 undef_child->type = ptr->value->type->data.pointer.child_type;
1606816106 undef_child->special = ConstValSpecialUndef;
16069 ptr->value.special = ConstValSpecialStatic;
16070 ptr->value.data.x_ptr.mut = ConstPtrMutInfer;
16071 ptr->value.data.x_ptr.special = ConstPtrSpecialRef;
16072 ptr->value.data.x_ptr.data.ref.pointee = undef_child;
16107 ptr->value->special = ConstValSpecialStatic;
16108 ptr->value->data.x_ptr.mut = ConstPtrMutInfer;
16109 ptr->value->data.x_ptr.special = ConstPtrSpecialRef;
16110 ptr->value->data.x_ptr.data.ref.pointee = undef_child;
1607316111}
1607416112
1607516113static 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
1610516143 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
1610616144{
1610716145 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,
1610916147 PtrLenSingle, 0, 0, 0, false);
1611016148 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
1611116149 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
......@@ -16158,7 +16196,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1615816196 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
1615916197 return ira->codegen->invalid_instruction;
1616016198 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
1616316201 if (alloca_src->base.child == nullptr || is_comptime) {
1616416202 uint32_t align = 0;
......@@ -16167,8 +16205,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1616716205 }
1616816206 IrInstruction *alloca_gen;
1616916207 if (is_comptime && value != nullptr) {
16170 if (align > value->value.global_refs->align) {
16171 value->value.global_refs->align = align;
16208 if (align > value->value->global_refs->align) {
16209 value->value->global_refs->align = align;
1617216210 }
1617316211 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
1617416212 } else {
......@@ -16191,7 +16229,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1619116229 }
1619216230 case ResultLocIdReturn: {
1619316231 if (!non_null_comptime) {
16194 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;
16232 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;
1619516233 if (is_comptime)
1619616234 return nullptr;
1619716235 }
......@@ -16222,8 +16260,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1622216260 value_type, value, force_runtime, non_null_comptime, true);
1622316261 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
1622416262 result_peer->suspend_pos.instruction_index = SIZE_MAX;
16225 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
16226 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
16263 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16264 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
1622716265 {
1622816266 return parent_result_loc;
1622916267 }
......@@ -16270,19 +16308,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1627016308
1627116309 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1627216310 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) ||
16274 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
16311 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16312 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
1627516313 {
1627616314 return parent_result_loc;
1627716315 }
1627816316 // 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;
1628016318 result_loc->written = true;
1628116319 result_loc->resolved_loc = parent_result_loc;
1628216320 return result_loc->resolved_loc;
1628316321 }
1628416322 case ResultLocIdCast: {
16285 if (value != nullptr && value->value.special != ConstValSpecialRuntime)
16323 if (value != nullptr && value->value->special != ConstValSpecialRuntime)
1628616324 return nullptr;
1628716325 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
1628816326 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
1631316351 casted_value = nullptr;
1631416352 }
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)) {
1631716355 return casted_value;
1631816356 }
1631916357
1632016358 bool old_parent_result_loc_written = result_cast->parent->written;
1632116359 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
1632216360 dest_type, casted_value, force_runtime, non_null_comptime, true);
16323 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
16324 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
16361 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16362 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
1632516363 {
1632616364 return parent_result_loc;
1632716365 }
16328 ZigType *parent_ptr_type = parent_result_loc->value.type;
16366 ZigType *parent_ptr_type = parent_result_loc->value->type;
1632916367 assert(parent_ptr_type->id == ZigTypeIdPointer);
1633016368 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
1633116369 ResolveStatusAlignmentKnown)))
......@@ -16358,7 +16396,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1635816396 {
1635916397 // we also need to check that this cast is OK.
1636016398 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,
1636216400 result_cast->base.source_instruction->source_node, false);
1636316401 if (const_cast_result.id == ConstCastResultIdInvalid)
1636416402 return ira->codegen->invalid_instruction;
......@@ -16413,18 +16451,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1641316451 bitcasted_value = nullptr;
1641416452 }
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)) {
1641716455 return bitcasted_value;
1641816456 }
1641916457
1642016458 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
1642116459 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
16422 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
16423 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
16460 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16461 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
1642416462 {
1642516463 return parent_result_loc;
1642616464 }
16427 ZigType *parent_ptr_type = parent_result_loc->value.type;
16465 ZigType *parent_ptr_type = parent_result_loc->value->type;
1642816466 assert(parent_ptr_type->id == ZigTypeIdPointer);
1642916467 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
1643016468 ResolveStatusAlignmentKnown)))
......@@ -16454,24 +16492,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1645416492{
1645516493 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
1645616494 instr_is_comptime(result_loc_pass1->source_instruction) &&
16457 result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer &&
16458 result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard)
16495 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
16496 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
1645916497 {
1646016498 result_loc_pass1 = no_result_loc();
1646116499 }
1646216500 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1646316501 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)))
1646516503 return result_loc;
1646616504
1646716505 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)
1646916507 {
16470 result_loc->value.special = ConstValSpecialRuntime;
16508 result_loc->value->special = ConstValSpecialRuntime;
1647116509 }
1647216510
16473 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr);
16474 ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type;
16511 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
16512 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
1647516513 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
1647616514 value_type->id != ZigTypeIdNull)
1647716515 {
......@@ -16544,18 +16582,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
1654416582 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
1654516583 implicit_elem_type, nullptr, false, true, true);
1654616584 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)))
1654816586 {
1654916587 return result_loc;
1655016588 }
16551 result_loc->value.special = ConstValSpecialRuntime;
16589 result_loc->value->special = ConstValSpecialRuntime;
1655216590 return result_loc;
1655316591 }
1655416592
1655516593 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
16556 result->value.special = ConstValSpecialUndef;
16594 result->value->special = ConstValSpecialUndef;
1655716595 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;
1655916597 return ptr;
1656016598}
1656116599
......@@ -16605,9 +16643,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal
1660516643{
1660616644 ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base);
1660716645 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))
1660916647 return ira->codegen->invalid_instruction;
16610 if (ret_ptr_uncasted->value.type->id == ZigTypeIdVoid) {
16648 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
1661116649 // Result location will be inside the async frame.
1661216650 return nullptr;
1661316651 }
......@@ -16632,7 +16670,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
1663216670 if (casted_new_stack != nullptr) {
1663316671 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
1663416672 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))
1663616674 return ira->codegen->invalid_instruction;
1663716675
1663816676 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
1664516683 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
1664616684 IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
1664716685 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)) {
1664916687 return result_loc;
1665016688 }
1665116689 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))
1665316691 return ira->codegen->invalid_instruction;
1665416692 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
1665516693 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
1667016708 return false;
1667116709
1667216710 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))
1667416712 return false;
1667516713 } else {
1667616714 casted_arg = arg;
1667716715 }
1667816716
16679 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);
16717 ZigValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);
1668016718 if (!arg_val)
1668116719 return false;
1668216720
......@@ -16710,7 +16748,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1671016748 return false;
1671116749
1671216750 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))
1671416752 return false;
1671516753 } else {
1671616754 arg_part_of_generic_id = true;
......@@ -16719,9 +16757,9 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1671916757 }
1672016758
1672116759 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
1672616764 if (comptime_arg) {
1672716765 arg_part_of_generic_id = true;
......@@ -16729,7 +16767,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1672916767 if (!arg_val)
1673016768 return false;
1673116769 } else {
16732 arg_val = create_const_runtime(casted_arg->value.type);
16770 arg_val = create_const_runtime(casted_arg->value->type);
1673316771 }
1673416772 if (arg_part_of_generic_id) {
1673516773 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
1674516783 var->shadowable = !comptime_arg;
1674616784
1674716785 *next_proto_i += 1;
16748 } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||
16749 casted_arg->value.type->id == ZigTypeIdComptimeFloat)
16786 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
16787 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
1675016788 {
1675116789 ir_add_error(ira, casted_arg,
1675216790 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
1675416792 }
1675516793
1675616794 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)) {
1675816796 case ReqCompTimeYes:
1675916797 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)));
1676116799 return false;
1676216800 case ReqCompTimeInvalid:
1676316801 return false;
......@@ -16767,7 +16805,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1676716805
1676816806 casted_args[fn_type_id->param_count] = casted_arg;
1676916807 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;
1677116809 param_info->is_noalias = param_decl_node->data.param_decl.is_noalias;
1677216810 impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node;
1677316811 fn_type_id->param_count += 1;
......@@ -16805,7 +16843,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1680516843 if (var->var_type == nullptr || type_is_invalid(var->var_type))
1680616844 return ira->codegen->invalid_instruction;
1680716845
16808 ConstExprValue *mem_slot = nullptr;
16846 ZigValue *mem_slot = nullptr;
1680916847
1681016848 bool comptime_var_mem = ir_get_var_is_comptime(var);
1681116849 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,
1681316851
1681416852 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,
1681516853 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,
1681716855 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1681816856
1681916857 if (linkage_makes_it_runtime)
......@@ -16846,10 +16884,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1684616884 assert(!comptime_var_mem);
1684716885 ptr_mut = ConstPtrMutRuntimeVar;
1684816886 }
16849 result->value.special = ConstValSpecialStatic;
16850 result->value.data.x_ptr.mut = ptr_mut;
16851 result->value.data.x_ptr.special = ConstPtrSpecialRef;
16852 result->value.data.x_ptr.data.ref.pointee = mem_slot;
16887 result->value->special = ConstValSpecialStatic;
16888 result->value->data.x_ptr.mut = ptr_mut;
16889 result->value->data.x_ptr.special = ConstPtrSpecialRef;
16890 result->value->data.x_ptr.data.ref.pointee = mem_slot;
1685316891 return result;
1685416892 }
1685516893 }
......@@ -16859,13 +16897,13 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1685916897no_mem_slot:
1686016898
1686116899 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
1686416902 return result;
1686516903}
1686616904
1686716905// 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) {
1686916907 ir_assert(value_is_comptime(val), source_instr);
1687016908 if (val->special == ConstValSpecialUndef)
1687116909 return;
......@@ -16881,11 +16919,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
1688116919static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
1688216920 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)
1688316921{
16884 assert(ptr->value.type->id == ZigTypeIdPointer);
16922 assert(ptr->value->type->id == ZigTypeIdPointer);
1688516923
16886 if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {
16887 if (uncasted_value->value.type->id == ZigTypeIdErrorUnion ||
16888 uncasted_value->value.type->id == ZigTypeIdErrorSet)
16924 if (ptr->value->data.x_ptr.special == ConstPtrSpecialDiscard) {
16925 if (uncasted_value->value->type->id == ZigTypeIdErrorUnion ||
16926 uncasted_value->value->type->id == ZigTypeIdErrorSet)
1688916927 {
1689016928 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
1689116929 return ira->codegen->invalid_instruction;
......@@ -16893,7 +16931,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1689316931 return ir_const_void(ira, source_instr);
1689416932 }
1689516933
16896 InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field;
16934 InferredStructField *isf = ptr->value->type->data.pointer.inferred_struct_field;
1689716935 if (allow_write_through_const && isf != nullptr) {
1689816936 // Now it's time to add the field to the struct type.
1689916937 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
1690416942
1690516943 TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count];
1690616944 field->name = isf->field_name;
16907 field->type_entry = uncasted_value->value.type;
16945 field->type_entry = uncasted_value->value->type;
1690816946 field->type_val = create_const_type(ira->codegen, field->type_entry);
1690916947 field->src_index = old_field_count;
1691016948 field->decl_node = uncasted_value->source_node;
......@@ -16913,25 +16951,25 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1691316951 IrInstruction *casted_ptr;
1691416952 if (instr_is_comptime(ptr)) {
1691516953 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);
16916 copy_const_val(&casted_ptr->value, &ptr->value, false);
16917 casted_ptr->value.type = struct_ptr_type;
16954 copy_const_val(casted_ptr->value, ptr->value, false);
16955 casted_ptr->value->type = struct_ptr_type;
1691816956 } else {
1691916957 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,
1692016958 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;
1692216960 }
1692316961 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);
1692516963 if (!ptr_val)
1692616964 return ira->codegen->invalid_instruction;
1692716965 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,
1692916967 source_instr->source_node);
1693016968 struct_val->special = ConstValSpecialStatic;
1693116969 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
1693216970 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];
1693516973 field_val->special = ConstValSpecialUndef;
1693616974 field_val->type = field->type_entry;
1693716975 field_val->parent.id = ConstParentIdStruct;
......@@ -16944,12 +16982,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1694416982 isf->inferred_struct_type, true);
1694516983 }
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) {
1694816986 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
1694916987 return ira->codegen->invalid_instruction;
1695016988 }
1695116989
16952 ZigType *child_type = ptr->value.type->data.pointer.child_type;
16990 ZigType *child_type = ptr->value->type->data.pointer.child_type;
1695316991 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);
1695416992 if (value == ira->codegen->invalid_instruction)
1695516993 return ira->codegen->invalid_instruction;
......@@ -16963,16 +17001,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1696317001 break;
1696417002 }
1696517003
16966 if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
16967 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) {
17004 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
17005 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
1696817006 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
1696917007 return ira->codegen->invalid_instruction;
1697017008 }
16971 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar ||
16972 ptr->value.data.x_ptr.mut == ConstPtrMutInfer)
17009 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
17010 ptr->value->data.x_ptr.mut == ConstPtrMutInfer)
1697317011 {
1697417012 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);
1697617014 if (dest_val == nullptr)
1697717015 return ira->codegen->invalid_instruction;
1697817016 if (dest_val->special != ConstValSpecialRuntime) {
......@@ -16982,9 +17020,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1698217020 // * "string literal used as comptime slice is memoized"
1698317021 // * "comptime modification of const struct field" - except modified to avoid
1698417022 // ConstPtrMutComptimeVar, thus defeating the logic below.
16985 bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar;
16986 copy_const_val(dest_val, &value->value, same_global_refs);
16987 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar &&
17023 bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar;
17024 copy_const_val(dest_val, value->value, same_global_refs);
17025 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
1698817026 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
1698917027 {
1699017028 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
1699217030 return ir_const_void(ira, source_instr);
1699317031 }
1699417032 }
16995 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {
16996 ptr->value.special = ConstValSpecialRuntime;
17033 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
17034 ptr->value->special = ConstValSpecialRuntime;
1699717035 } else {
1699817036 ir_add_error(ira, source_instr,
1699917037 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);
1700117039 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1700217040
1700317041 return ira->codegen->invalid_instruction;
......@@ -17009,7 +17047,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1700917047 case ReqCompTimeInvalid:
1701017048 return ira->codegen->invalid_instruction;
1701117049 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)) {
1701317051 case OnePossibleValueInvalid:
1701417052 return ira->codegen->invalid_instruction;
1701517053 case OnePossibleValueNo:
......@@ -17025,7 +17063,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1702517063 }
1702617064
1702717065 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);
1702917067 }
1703017068
1703117069 // 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
1703417072 // explaining why it is impossible for this store to work. Which is that
1703517073 // the pointer address is of the vector; without the element index being known
1703617074 // 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) {
1703817076 if (ptr->id == IrInstructionIdElemPtr) {
1703917077 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
1704017078 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
1704217080 }
1704317081 ir_add_error(ira, ptr,
1704417082 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)));
1704617084 return ira->codegen->invalid_instruction;
1704717085 }
1704817086
......@@ -17058,12 +17096,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall
1705817096 return nullptr;
1705917097
1706017098 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))
1706217100 return ira->codegen->invalid_instruction;
1706317101
1706417102 if (call_instruction->is_async_call_builtin &&
17065 fn_entry != nullptr && new_stack->value.type->id == ZigTypeIdPointer &&
17066 new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
17103 fn_entry != nullptr && new_stack->value->type->id == ZigTypeIdPointer &&
17104 new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
1706717105 {
1706817106 ZigType *needed_frame_type = get_pointer_to_type(ira->codegen,
1706917107 get_fn_frame_type(ira->codegen, fn_entry), false);
......@@ -17097,7 +17135,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1709717135
1709817136 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
1709917137 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;
1710117139 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
1710217140 call_param_count -= 1;
1710317141 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
1715217190
1715317191 size_t next_proto_i = 0;
1715417192 if (first_arg_ptr) {
17155 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
17193 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1715617194
1715717195 bool first_arg_known_bare = false;
1715817196 if (fn_type_id->next_param_index >= 1) {
......@@ -17163,11 +17201,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1716317201 }
1716417202
1716517203 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)) {
1716717205 first_arg = first_arg_ptr;
1716817206 } else {
1716917207 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))
1717117209 return ira->codegen->invalid_instruction;
1717217210 }
1717317211
......@@ -17184,7 +17222,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1718417222
1718517223 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1718617224 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))
1718817226 return ira->codegen->invalid_instruction;
1718917227
1719017228 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
1720717245 }
1720817246
1720917247 bool cacheable = fn_eval_cacheable(exec_scope, return_type);
17210 ConstExprValue *result = nullptr;
17248 ZigValue *result = nullptr;
1721117249 if (cacheable) {
1721217250 auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope);
1721317251 if (entry)
......@@ -17250,8 +17288,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1725017288 }
1725117289
1725217290 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);
17253 copy_const_val(&new_instruction->value, result, true);
17254 new_instruction->value.type = return_type;
17291 copy_const_val(new_instruction->value, result, true);
17292 new_instruction->value->type = return_type;
1725517293 return ir_finish_anal(ira, new_instruction);
1725617294 }
1725717295
......@@ -17266,11 +17304,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1726617304 size_t new_fn_arg_count = first_arg_1_or_0;
1726717305 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1726817306 IrInstruction *arg = call_instruction->args[call_i]->child;
17269 if (type_is_invalid(arg->value.type))
17307 if (type_is_invalid(arg->value->type))
1727017308 return ira->codegen->invalid_instruction;
1727117309
17272 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;
17310 if (arg->value->type->id == ZigTypeIdArgTuple) {
17311 new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index;
1727417312 } else {
1727517313 new_fn_arg_count += 1;
1727617314 }
......@@ -17299,7 +17337,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1729917337 size_t next_proto_i = 0;
1730017338
1730117339 if (first_arg_ptr) {
17302 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
17340 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1730317341
1730417342 bool first_arg_known_bare = false;
1730517343 if (fn_type_id->next_param_index >= 1) {
......@@ -17310,11 +17348,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1731017348 }
1731117349
1731217350 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)) {
1731417352 first_arg = first_arg_ptr;
1731517353 } else {
1731617354 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))
1731817356 return ira->codegen->invalid_instruction;
1731917357 }
1732017358
......@@ -17332,12 +17370,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1733217370 assert(parent_fn_entry);
1733317371 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1733417372 IrInstruction *arg = call_instruction->args[call_i]->child;
17335 if (type_is_invalid(arg->value.type))
17373 if (type_is_invalid(arg->value->type))
1733617374 return ira->codegen->invalid_instruction;
1733717375
17338 if (arg->value.type->id == ZigTypeIdArgTuple) {
17339 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)
17376 if (arg->value->type->id == ZigTypeIdArgTuple) {
17377 for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index;
17378 arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
1734117379 {
1734217380 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
1734317381 assert(param_decl_node->type == NodeTypeParamDecl);
......@@ -17354,11 +17392,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1735417392 return ira->codegen->invalid_instruction;
1735517393 }
1735617394 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))
1735817396 return ira->codegen->invalid_instruction;
1735917397
1736017398 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))
1736217400 return ira->codegen->invalid_instruction;
1736317401
1736417402 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
1739217430 first_var_arg = inst_fn_type_id.param_count;
1739317431 }
1739417432
17395 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,
17433 ZigValue *var_args_val = create_const_arg_tuple(ira->codegen,
1739617434 first_var_arg, inst_fn_type_id.param_count);
1739717435 ZigVar *var = add_variable(ira->codegen, param_decl_node,
1739817436 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
1740017438 }
1740117439
1740217440 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,
1740417442 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),
1740517443 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
1740617444 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
1740717445 nullptr, UndefBad);
1740817446 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1740917447 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
1741217450 uint32_t align_bytes = 0;
1741317451 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
......@@ -17468,7 +17506,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1746817506 }
1746917507
1747017508 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))
1747217510 return ira->codegen->invalid_instruction;
1747317511
1747417512 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
1748317521 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
1748417522 impl_fn_type_id->return_type, nullptr, true, true, false);
1748517523 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)) {
1748717525 return result_loc;
1748817526 }
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)) {
1749017528 ir_reset_result(call_instruction->result_loc);
1749117529 result_loc = nullptr;
1749217530 }
1749317531 }
1749417532 } else if (call_instruction->is_async_call_builtin) {
1749517533 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))
1749717535 return ira->codegen->invalid_instruction;
1749817536 } else {
1749917537 result_loc = nullptr;
......@@ -17530,7 +17568,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1753017568 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
1753117569 size_t next_arg_index = 0;
1753217570 if (first_arg_ptr) {
17533 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
17571 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1753417572
1753517573 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1753617574 if (type_is_invalid(param_type))
......@@ -17538,17 +17576,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1753817576
1753917577 IrInstruction *first_arg;
1754017578 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))
1754217580 {
1754317581 first_arg = first_arg_ptr;
1754417582 } else {
1754517583 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))
1754717585 return ira->codegen->invalid_instruction;
1754817586 }
1754917587
1755017588 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))
1755217590 return ira->codegen->invalid_instruction;
1755317591
1755417592 casted_args[next_arg_index] = casted_arg;
......@@ -17556,12 +17594,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1755617594 }
1755717595 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1755817596 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))
1756017598 return ira->codegen->invalid_instruction;
1756117599
17562 if (old_arg->value.type->id == ZigTypeIdArgTuple) {
17563 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)
17600 if (old_arg->value->type->id == ZigTypeIdArgTuple) {
17601 for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index;
17602 arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
1756517603 {
1756617604 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
1756717605 if (arg_var == nullptr) {
......@@ -17570,11 +17608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1757017608 return ira->codegen->invalid_instruction;
1757117609 }
1757217610 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))
1757417612 return ira->codegen->invalid_instruction;
1757517613
1757617614 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))
1757817616 return ira->codegen->invalid_instruction;
1757917617
1758017618 IrInstruction *casted_arg;
......@@ -17583,7 +17621,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1758317621 if (type_is_invalid(param_type))
1758417622 return ira->codegen->invalid_instruction;
1758517623 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))
1758717625 return ira->codegen->invalid_instruction;
1758817626 } else {
1758917627 casted_arg = arg_tuple_arg;
......@@ -17599,7 +17637,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1759917637 if (type_is_invalid(param_type))
1760017638 return ira->codegen->invalid_instruction;
1760117639 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))
1760317641 return ira->codegen->invalid_instruction;
1760417642 } else {
1760517643 casted_arg = old_arg;
......@@ -17623,7 +17661,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1762317661 }
1762417662
1762517663 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))
1762717665 return ira->codegen->invalid_instruction;
1762817666
1762917667 if (call_instruction->modifier == CallModifierAsync) {
......@@ -17645,17 +17683,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1764517683 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
1764617684 return_type, nullptr, true, true, false);
1764717685 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)) {
1764917687 return result_loc;
1765017688 }
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)) {
1765217690 ir_reset_result(call_instruction->result_loc);
1765317691 result_loc = nullptr;
1765417692 }
1765517693 }
1765617694 } else if (call_instruction->is_async_call_builtin) {
1765717695 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))
1765917697 return ira->codegen->invalid_instruction;
1766017698 } else {
1766117699 result_loc = nullptr;
......@@ -17672,14 +17710,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1767217710
1767317711static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {
1767417712 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))
1767617714 return ira->codegen->invalid_instruction;
1767717715
1767817716 bool is_comptime = call_instruction->is_comptime ||
1767917717 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
1768017718
1768117719 if (is_comptime || instr_is_comptime(fn_ref)) {
17682 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
17720 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
1768317721 ZigType *ty = ir_resolve_type(ira, fn_ref);
1768417722 if (ty == nullptr)
1768517723 return ira->codegen->invalid_instruction;
......@@ -17688,30 +17726,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1768817726 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
1768917727 buf_sprintf("use @as builtin for type coercion"));
1769017728 return ira->codegen->invalid_instruction;
17691 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
17729 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
1769217730 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;
1769417732 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type,
1769517733 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
17696 } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {
17697 assert(fn_ref->value.special == ConstValSpecialStatic);
17698 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;
17734 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
17735 assert(fn_ref->value->special == ConstValSpecialStatic);
17736 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
17737 IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
1770017738 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1770117739 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);
1770217740 } else {
1770317741 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)));
1770517743 return ira->codegen->invalid_instruction;
1770617744 }
1770717745 }
1770817746
17709 if (fn_ref->value.type->id == ZigTypeIdFn) {
17710 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
17747 if (fn_ref->value->type->id == ZigTypeIdFn) {
17748 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value->type,
1771117749 fn_ref, nullptr, false, call_instruction->fn_inline);
1771217750 } else {
1771317751 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)));
1771517753 return ira->codegen->invalid_instruction;
1771617754 }
1771717755}
......@@ -17719,12 +17757,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1771917757// out_val->type must be the type to read the pointer as
1772017758// if the type is different than the actual type then it does a comptime byte reinterpretation
1772117759static 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)
1772317761{
1772417762 Error err;
1772517763 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);
1772817766 src_assert(pointee->type != nullptr, source_node);
1772917767
1773017768 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
......@@ -17765,7 +17803,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1776517803 return ErrorSemanticAnalyzeFail;
1776617804 }
1776717805 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;
1776917807 assert(array_val->type->id == ZigTypeIdArray);
1777017808 if (array_val->data.x_array.special != ConstArraySpecialNone)
1777117809 zig_panic("TODO");
......@@ -17782,7 +17820,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1778217820 Buf buf = BUF_INIT;
1778317821 buf_resize(&buf, elem_count * elem_size);
1778417822 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];
1778617824 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);
1778717825 }
1778817826 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
1780317841
1780417842static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {
1780517843 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
17806 result->value.special = ConstValSpecialLazy;
17844 result->value->special = ConstValSpecialLazy;
1780717845
1780817846 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1);
1780917847 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;
1781117849 lazy_opt_type->base.id = LazyValueIdOptType;
1781217850
1781317851 lazy_opt_type->payload_type = instruction->value->child;
......@@ -17818,7 +17856,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1781817856}
1781917857
1782017858static 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)
1782217860{
1782317861 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
1785417892
1785517893static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {
1785617894 IrInstruction *value = instruction->value->child;
17857 ZigType *expr_type = value->value.type;
17895 ZigType *expr_type = value->value->type;
1785817896 if (type_is_invalid(expr_type))
1785917897 return ira->codegen->invalid_instruction;
1786017898
......@@ -17872,20 +17910,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1787217910 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
1787317911
1787417912 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);
1787617914 if (!operand_val)
1787717915 return ira->codegen->invalid_instruction;
1787817916
1787917917 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);
17880 ConstExprValue *out_val = &result_instruction->value;
17918 ZigValue *out_val = result_instruction->value;
1788117919 if (expr_type->id == ZigTypeIdVector) {
1788217920 expand_undef_array(ira->codegen, operand_val);
1788317921 out_val->special = ConstValSpecialUndef;
1788417922 expand_undef_array(ira->codegen, out_val);
1788517923 size_t len = expr_type->data.vector.len;
1788617924 for (size_t i = 0; i < len; i += 1) {
17887 ConstExprValue *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];
17925 ZigValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i];
17926 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
1788917927 assert(scalar_operand_val->type == scalar_type);
1789017928 assert(scalar_out_val->type == scalar_type);
1789117929 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,
......@@ -17911,31 +17949,31 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1791117949 IrInstruction *result = ir_build_un_op(&ira->new_irb,
1791217950 instruction->base.scope, instruction->base.source_node,
1791317951 instruction->op_id, value);
17914 result->value.type = expr_type;
17952 result->value->type = expr_type;
1791517953 return result;
1791617954}
1791717955
1791817956static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
1791917957 IrInstruction *value = instruction->value->child;
17920 ZigType *expr_type = value->value.type;
17958 ZigType *expr_type = value->value->type;
1792117959 if (type_is_invalid(expr_type))
1792217960 return ira->codegen->invalid_instruction;
1792317961
1792417962 if (expr_type->id == ZigTypeIdInt) {
1792517963 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);
1792717965 if (target_const_val == nullptr)
1792817966 return ira->codegen->invalid_instruction;
1792917967
1793017968 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,
1793217970 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
1793317971 return result;
1793417972 }
1793517973
1793617974 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,
1793717975 instruction->base.source_node, IrUnOpBinNot, value);
17938 result->value.type = expr_type;
17976 result->value->type = expr_type;
1793917977 return result;
1794017978 }
1794117979
......@@ -17956,9 +17994,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1795617994 return ir_analyze_negation(ira, instruction);
1795717995 case IrUnOpDereference: {
1795817996 IrInstruction *ptr = instruction->value->child;
17959 if (type_is_invalid(ptr->value.type))
17997 if (type_is_invalid(ptr->value->type))
1796017998 return ira->codegen->invalid_instruction;
17961 ZigType *ptr_type = ptr->value.type;
17999 ZigType *ptr_type = ptr->value->type;
1796218000 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
1796318001 ir_add_error_node(ira, instruction->base.source_node,
1796418002 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
1797118009 return ira->codegen->invalid_instruction;
1797218010
1797318011 // 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) {
1797518013 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)));
1797718015 return ira->codegen->invalid_instruction;
1797818016 }
1797918017
......@@ -18016,13 +18054,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
1801618054
1801718055 IrInstruction *result = ir_build_br(&ira->new_irb,
1801818056 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;
1802018058 return ir_finish_anal(ira, result);
1802118059}
1802218060
1802318061static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
1802418062 IrInstruction *condition = cond_br_instruction->condition->child;
18025 if (type_is_invalid(condition->value.type))
18063 if (type_is_invalid(condition->value->type))
1802618064 return ir_unreach_error(ira);
1802718065
1802818066 bool is_comptime;
......@@ -18031,7 +18069,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1803118069
1803218070 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1803318071 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))
1803518073 return ir_unreach_error(ira);
1803618074
1803718075 if (is_comptime || instr_is_comptime(casted_condition)) {
......@@ -18053,7 +18091,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1805318091
1805418092 IrInstruction *result = ir_build_br(&ira->new_irb,
1805518093 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;
1805718095 return ir_finish_anal(ira, result);
1805818096 }
1805918097
......@@ -18072,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1807218110 IrInstruction *result = ir_build_cond_br(&ira->new_irb,
1807318111 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,
1807418112 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;
1807618114 return ir_finish_anal(ira, result);
1807718115}
1807818116
......@@ -18081,7 +18119,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,
1808118119{
1808218120 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
1808318121 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;
1808518123 return ir_finish_anal(ira, result);
1808618124}
1808718125
......@@ -18094,13 +18132,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1809418132 if (predecessor != ira->const_predecessor_bb)
1809518133 continue;
1809618134 IrInstruction *value = phi_instruction->incoming_values[i]->child;
18097 assert(value->value.type);
18098 if (type_is_invalid(value->value.type))
18135 assert(value->value->type);
18136 if (type_is_invalid(value->value->type))
1809918137 return ira->codegen->invalid_instruction;
1810018138
18101 if (value->value.special != ConstValSpecialRuntime) {
18139 if (value->value->special != ConstValSpecialRuntime) {
1810218140 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);
1810418142 return result;
1810518143 } else {
1810618144 return value;
......@@ -18126,7 +18164,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1812618164 } else {
1812718165 instructions[i] = ir_const(ira, this_peer->base.source_instruction,
1812818166 this_peer->base.implicit_elem_type);
18129 instructions[i]->value.special = ConstValSpecialRuntime;
18167 instructions[i]->value->special = ConstValSpecialRuntime;
1813018168 }
1813118169 } else {
1813218170 instructions[i] = gen_instruction;
......@@ -18147,7 +18185,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1814718185 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
1814818186 peer_parent->resolved_type, nullptr, false, false, true);
1814918187 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)))
1815118189 {
1815218190 return parent_result_loc;
1815318191 }
......@@ -18160,7 +18198,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1816018198 if (instrs_to_move.length != 0) {
1816118199 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;
1816218200 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);
1816418202 while (instrs_to_move.length != 0) {
1816518203 predecessor->instruction_list.append(instrs_to_move.pop());
1816618204 }
......@@ -18197,10 +18235,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1819718235 IrInstruction *old_value = phi_instruction->incoming_values[i];
1819818236 assert(old_value);
1819918237 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)
1820118239 continue;
1820218240
18203 if (type_is_invalid(new_value->value.type))
18241 if (type_is_invalid(new_value->value->type))
1820418242 return ira->codegen->invalid_instruction;
1820518243
1820618244
......@@ -18212,7 +18250,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1821218250 if (new_incoming_blocks.length == 0) {
1821318251 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
1821418252 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;
1821618254 return ir_finish_anal(ira, result);
1821718255 }
1821818256
......@@ -18233,7 +18271,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1823318271 if (type_is_invalid(resolved_type))
1823418272 return ira->codegen->invalid_instruction;
1823518273 } 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;
1823718275 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
1823818276 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
1823918277 }
......@@ -18281,14 +18319,14 @@ skip_resolve_peer_types:
1828118319 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
1828218320 ir_set_cursor_at_end(&ira->new_irb, predecessor);
1828318321 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)) {
1828518323 return ira->codegen->invalid_instruction;
1828618324 }
1828718325 new_incoming_values.items[i] = casted_value;
1828818326 predecessor->instruction_list.append(branch_instruction);
1828918327
18290 if (all_stack_ptrs && (casted_value->value.special != ConstValSpecialRuntime ||
18291 casted_value->value.data.rh_ptr != RuntimeHintPtrStack))
18328 if (all_stack_ptrs && (casted_value->value->special != ConstValSpecialRuntime ||
18329 casted_value->value->data.rh_ptr != RuntimeHintPtrStack))
1829218330 {
1829318331 all_stack_ptrs = false;
1829418332 }
......@@ -18298,11 +18336,11 @@ skip_resolve_peer_types:
1829818336 IrInstruction *result = ir_build_phi(&ira->new_irb,
1829918337 phi_instruction->base.scope, phi_instruction->base.source_node,
1830018338 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
1830318341 if (all_stack_ptrs) {
18304 assert(result->value.special == ConstValSpecialRuntime);
18305 result->value.data.rh_ptr = RuntimeHintPtrStack;
18342 assert(result->value->special == ConstValSpecialRuntime);
18343 result->value->data.rh_ptr = RuntimeHintPtrStack;
1830618344 }
1830718345
1830818346 return result;
......@@ -18358,13 +18396,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
1835818396static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
1835918397 Error err;
1836018398 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))
1836218400 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
1836618404 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))
1836818406 return ira->codegen->invalid_instruction;
1836918407
1837018408 ZigType *ptr_type = orig_array_ptr_val->type;
......@@ -18428,10 +18466,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1842818466 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,
1842918467 elem_ptr_instruction->ptr_len);
1843018468 } 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);
1843218470 if (!ptr_val)
1843318471 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);
1843518473 if (args_val == nullptr)
1843618474 return ira->codegen->invalid_instruction;
1843718475 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
1847118509 return ira->codegen->invalid_instruction;
1847218510 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
1847318511 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);
1847518513 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,
1847618514 array_ptr, array_type);
1847718515 } else {
......@@ -18487,13 +18525,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1848718525
1848818526 bool safety_check_on = elem_ptr_instruction->safety_check_on;
1848918527 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);
1849118529 if (array_type->id == ZigTypeIdArray) {
1849218530 uint64_t array_len = array_type->data.array.len;
1849318531 if (index == array_len && array_type->data.array.sentinel != nullptr) {
1849418532 ZigType *elem_type = array_type->data.array.child_type;
1849518533 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);
1849718535 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
1849818536 }
1849918537 if (index >= array_len) {
......@@ -18544,7 +18582,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1854418582 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
1854518583 array_type->id == ZigTypeIdArray))
1854618584 {
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,
1854818586 elem_ptr_instruction->base.source_node);
1854918587 if (array_ptr_val == nullptr)
1855018588 return ira->codegen->invalid_instruction;
......@@ -18557,7 +18595,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1855718595 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
1855818596 array_ptr_val->special = ConstValSpecialStatic;
1855918597 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];
1856118599 elem_val->special = ConstValSpecialUndef;
1856218600 elem_val->type = array_type->data.array.child_type;
1856318601 elem_val->parent.id = ConstParentIdArray;
......@@ -18565,8 +18603,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1856518603 elem_val->parent.data.p_array.elem_index = i;
1856618604 }
1856718605 } else if (is_slice(array_type)) {
18568 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;
18606 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);
18607 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1857018608
1857118609 if (type_is_invalid(actual_array_type))
1857218610 return ira->codegen->invalid_instruction;
......@@ -18576,14 +18614,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1857618614 return ira->codegen->invalid_instruction;
1857718615 }
1857818616
18579 ConstExprValue *array_init_val = create_const_vals(1);
18617 ZigValue *array_init_val = create_const_vals(1);
1858018618 array_init_val->special = ConstValSpecialStatic;
1858118619 array_init_val->type = actual_array_type;
1858218620 array_init_val->data.x_array.special = ConstArraySpecialNone;
1858318621 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
1858418622 array_init_val->special = ConstValSpecialStatic;
1858518623 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];
1858718625 elem_val->special = ConstValSpecialUndef;
1858818626 elem_val->type = actual_array_type->data.array.child_type;
1858918627 elem_val->parent.id = ConstParentIdArray;
......@@ -18608,7 +18646,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1860818646 {
1860918647 if (array_type->id == ZigTypeIdPointer) {
1861018648 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18611 ConstExprValue *out_val = &result->value;
18649 ZigValue *out_val = result->value;
1861218650 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
1861318651 size_t new_index;
1861418652 size_t mem_size;
......@@ -18619,7 +18657,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1861918657 zig_unreachable();
1862018658 case ConstPtrSpecialRef:
1862118659 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;
1862318661 new_index = index;
1862418662 ZigType *array_type = array_val->type;
1862518663 mem_size = array_type->data.array.len;
......@@ -18682,18 +18720,18 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1868218720 }
1868318721 return result;
1868418722 } 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];
1868618724 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
1868718725 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
1868818726 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1868918727 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
1869018728 elem_ptr_instruction->ptr_len, nullptr);
18691 result->value.type = return_type;
18729 result->value->type = return_type;
1869218730 return result;
1869318731 }
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];
1869518733 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18696 ConstExprValue *out_val = &result->value;
18734 ZigValue *out_val = result->value;
1869718735 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
1869818736 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
1869918737 uint64_t full_slice_len = slice_len +
......@@ -18752,12 +18790,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1875218790 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1875318791 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
1875418792 false, elem_ptr_instruction->ptr_len, nullptr);
18755 result->value.type = return_type;
18756 result->value.special = ConstValSpecialStatic;
18793 result->value->type = return_type;
18794 result->value->special = ConstValSpecialStatic;
1875718795 } else {
1875818796 result = ir_const(ira, &elem_ptr_instruction->base, return_type);
1875918797 }
18760 ConstExprValue *out_val = &result->value;
18798 ZigValue *out_val = result->value;
1876118799 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
1876218800 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
1876318801 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
1881418852 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1881518853 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
1881618854 elem_ptr_instruction->ptr_len, nullptr);
18817 result->value.type = return_type;
18855 result->value->type = return_type;
1881818856 return result;
1881918857}
1882018858
......@@ -18892,8 +18930,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1889218930 case OnePossibleValueNo:
1889318931 break;
1889418932 }
18895 bool is_const = struct_ptr->value.type->data.pointer.is_const;
18896 bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile;
18933 bool is_const = struct_ptr->value->type->data.pointer.is_const;
18934 bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile;
1889718935 ZigType *ptr_type;
1889818936 if (struct_type->data.structure.is_inferred) {
1889918937 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
1890418942 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
1890518943 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
1890618944 return ira->codegen->invalid_instruction;
18907 assert(struct_ptr->value.type->id == ZigTypeIdPointer);
18908 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;
18945 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
18946 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
18947 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;
1891018948 uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ?
1891118949 get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes;
1891218950 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
1891518953 (uint32_t)host_int_bytes_for_result_type, false);
1891618954 }
1891718955 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);
1891918957 if (!ptr_val)
1892018958 return ira->codegen->invalid_instruction;
1892118959
1892218960 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);
1892418962 if (struct_val == nullptr)
1892518963 return ira->codegen->invalid_instruction;
1892618964 if (type_is_invalid(struct_val->type))
......@@ -18929,7 +18967,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1892918967 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
1893018968 struct_val->special = ConstValSpecialStatic;
1893118969 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];
1893318971 field_val->special = ConstValSpecialUndef;
1893418972 field_val->type = resolve_struct_field_type(ira->codegen,
1893518973 struct_type->data.structure.fields[i]);
......@@ -18942,12 +18980,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1894218980 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
1894318981 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,
1894418982 source_instr->source_node, struct_ptr, field);
18945 result->value.type = ptr_type;
18946 result->value.special = ConstValSpecialStatic;
18983 result->value->type = ptr_type;
18984 result->value->special = ConstValSpecialStatic;
1894718985 } else {
1894818986 result = ir_const(ira, source_instr, ptr_type);
1894918987 }
18950 ConstExprValue *const_val = &result->value;
18988 ZigValue *const_val = result->value;
1895118989 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
1895218990 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
1895318991 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
1895718995 }
1895818996 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
1895918997 struct_ptr, field);
18960 result->value.type = ptr_type;
18998 result->value->type = ptr_type;
1896118999 return result;
1896219000}
1896319001
......@@ -18970,7 +19008,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1897019008 // the field type will then be available, and the field will be added to the inferred
1897119009 // struct.
1897219010
18973 ZigType *container_ptr_type = container_ptr->value.type;
19011 ZigType *container_ptr_type = container_ptr->value->type;
1897419012 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
1897519013
1897619014 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");
......@@ -18984,14 +19022,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1898419022
1898519023 if (instr_is_comptime(container_ptr)) {
1898619024 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);
18987 copy_const_val(&result->value, &container_ptr->value, false);
18988 result->value.type = field_ptr_type;
19025 copy_const_val(result->value, container_ptr->value, false);
19026 result->value->type = field_ptr_type;
1898919027 return result;
1899019028 }
1899119029
1899219030 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,
1899319031 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
18994 result->value.type = field_ptr_type;
19032 result->value->type = field_ptr_type;
1899519033 return result;
1899619034}
1899719035
......@@ -19011,7 +19049,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1901119049 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
1901219050 return ira->codegen->invalid_instruction;
1901319051
19014 assert(container_ptr->value.type->id == ZigTypeIdPointer);
19052 assert(container_ptr->value->type->id == ZigTypeIdPointer);
1901519053 if (bare_type->id == ZigTypeIdStruct) {
1901619054 TypeStructField *field = find_struct_type_field(bare_type, field_name);
1901719055 if (field != nullptr) {
......@@ -19028,8 +19066,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1902819066 }
1902919067
1903019068 if (bare_type->id == ZigTypeIdUnion) {
19031 bool is_const = container_ptr->value.type->data.pointer.is_const;
19032 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;
19069 bool is_const = container_ptr->value->type->data.pointer.is_const;
19070 bool is_volatile = container_ptr->value->type->data.pointer.is_volatile;
1903319071
1903419072 TypeUnionField *field = find_union_type_field(bare_type, field_name);
1903519073 if (field == nullptr) {
......@@ -19044,20 +19082,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1904419082 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
1904519083 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1904619084 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);
1904819086 if (!ptr_val)
1904919087 return ira->codegen->invalid_instruction;
1905019088
1905119089 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
1905219090 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);
1905419092 if (union_val == nullptr)
1905519093 return ira->codegen->invalid_instruction;
1905619094 if (type_is_invalid(union_val->type))
1905719095 return ira->codegen->invalid_instruction;
1905819096
1905919097 if (initializing) {
19060 ConstExprValue *payload_val = create_const_vals(1);
19098 ZigValue *payload_val = create_const_vals(1);
1906119099 payload_val->special = ConstValSpecialUndef;
1906219100 payload_val->type = field_type;
1906319101 payload_val->parent.id = ConstParentIdUnion;
......@@ -19079,20 +19117,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1907919117 }
1908019118 }
1908119119
19082 ConstExprValue *payload_val = union_val->data.x_union.payload;
19120 ZigValue *payload_val = union_val->data.x_union.payload;
1908319121
1908419122 IrInstruction *result;
1908519123 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
1908619124 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
1908719125 source_instr->source_node, container_ptr, field, true, initializing);
19088 result->value.type = ptr_type;
19089 result->value.special = ConstValSpecialStatic;
19126 result->value->type = ptr_type;
19127 result->value->special = ConstValSpecialStatic;
1909019128 } else {
1909119129 result = ir_const(ira, source_instr, ptr_type);
1909219130 }
19093 ConstExprValue *const_val = &result->value;
19131 ZigValue *const_val = result->value;
1909419132 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;
1909619134 const_val->data.x_ptr.data.ref.pointee = payload_val;
1909719135 return result;
1909819136 }
......@@ -19100,7 +19138,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1910019138
1910119139 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
1910219140 source_instr->source_node, container_ptr, field, true, initializing);
19103 result->value.type = ptr_type;
19141 result->value->type = ptr_type;
1910419142 return result;
1910519143 }
1910619144
......@@ -19205,10 +19243,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
1920519243static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
1920619244 Error err;
1920719245 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))
1920919247 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
1921319251 Buf *field_name = field_ptr_instruction->field_name_buffer;
1921419252 if (!field_name) {
......@@ -19224,7 +19262,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1922419262 if (type_is_invalid(container_type)) {
1922519263 return ira->codegen->invalid_instruction;
1922619264 } 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);
1922819266 if (container_type->id == ZigTypeIdPointer) {
1922919267 ZigType *bare_type = container_ref_type(container_type);
1923019268 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
1923619274 }
1923719275 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
1923819276 if (buf_eql_str(field_name, "len")) {
19239 ConstExprValue *len_val = create_const_vals(1);
19277 ZigValue *len_val = create_const_vals(1);
1924019278 if (container_type->id == ZigTypeIdPointer) {
1924119279 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
1924219280 } else {
......@@ -19255,17 +19293,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1925519293 return ira->codegen->invalid_instruction;
1925619294 }
1925719295 } 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);
1925919297 if (!container_ptr_val)
1926019298 return ira->codegen->invalid_instruction;
1926119299
19262 assert(container_ptr->value.type->id == ZigTypeIdPointer);
19263 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19300 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19301 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
1926419302 if (child_val == nullptr)
1926519303 return ira->codegen->invalid_instruction;
1926619304
1926719305 if (buf_eql_str(field_name, "len")) {
19268 ConstExprValue *len_val = create_const_vals(1);
19306 ZigValue *len_val = create_const_vals(1);
1926919307 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
1927019308 init_const_usize(ira->codegen, len_val, len);
1927119309
......@@ -19281,12 +19319,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1928119319 return ira->codegen->invalid_instruction;
1928219320 }
1928319321 } 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);
1928519323 if (!container_ptr_val)
1928619324 return ira->codegen->invalid_instruction;
1928719325
19288 assert(container_ptr->value.type->id == ZigTypeIdPointer);
19289 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19326 assert(container_ptr->value->type->id == ZigTypeIdPointer);
19327 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
1929019328 if (child_val == nullptr)
1929119329 return ira->codegen->invalid_instruction;
1929219330 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
1938219420 }
1938319421 err_set_type = child_type;
1938419422 }
19385 ConstExprValue *const_val = create_const_vals(1);
19423 ZigValue *const_val = create_const_vals(1);
1938619424 const_val->special = ConstValSpecialStatic;
1938719425 const_val->type = err_set_type;
1938819426 const_val->data.x_err_set = err_entry;
......@@ -19567,11 +19605,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1956719605
1956819606static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {
1956919607 IrInstruction *ptr = instruction->ptr->child;
19570 if (type_is_invalid(ptr->value.type))
19608 if (type_is_invalid(ptr->value->type))
1957119609 return ira->codegen->invalid_instruction;
1957219610
1957319611 IrInstruction *value = instruction->value->child;
19574 if (type_is_invalid(value->value.type))
19612 if (type_is_invalid(value->value->type))
1957519613 return ira->codegen->invalid_instruction;
1957619614
1957719615 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
1957919617
1958019618static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {
1958119619 IrInstruction *ptr = instruction->ptr->child;
19582 if (type_is_invalid(ptr->value.type))
19620 if (type_is_invalid(ptr->value->type))
1958319621 return ira->codegen->invalid_instruction;
1958419622 return ir_get_deref(ira, &instruction->base, ptr, nullptr);
1958519623}
1958619624
1958719625static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
1958819626 IrInstruction *expr_value = typeof_instruction->value->child;
19589 ZigType *type_entry = expr_value->value.type;
19627 ZigType *type_entry = expr_value->value->type;
1959019628 if (type_is_invalid(type_entry))
1959119629 return ira->codegen->invalid_instruction;
1959219630 return ir_const_type(ira, &typeof_instruction->base, type_entry);
......@@ -19749,11 +19787,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1974919787 IrInstructionSliceType *slice_type_instruction)
1975019788{
1975119789 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
1975419792 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1);
1975519793 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;
1975719795 lazy_slice_type->base.id = LazyValueIdSliceType;
1975819796
1975919797 if (slice_type_instruction->align_value != nullptr) {
......@@ -19812,14 +19850,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
1981219850
1981319851 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
1981419852 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))
1981619854 return ira->codegen->invalid_instruction;
1981719855
1981819856 if (instr_is_comptime(input_value) &&
19819 (input_value->value.type->id == ZigTypeIdComptimeInt ||
19820 input_value->value.type->id == ZigTypeIdComptimeFloat)) {
19857 (input_value->value->type->id == ZigTypeIdComptimeInt ||
19858 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
1982119859 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)));
1982319861 return ira->codegen->invalid_instruction;
1982419862 }
1982519863
......@@ -19831,7 +19869,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
1983119869 asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len,
1983219870 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
1983319871 asm_instruction->has_side_effects);
19834 result->value.type = return_type;
19872 result->value->type = return_type;
1983519873 return result;
1983619874}
1983719875
......@@ -19850,13 +19888,13 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1985019888 if (type_is_invalid(child_type))
1985119889 return ira->codegen->invalid_instruction;
1985219890
19853 ConstExprValue *sentinel_val;
19891 ZigValue *sentinel_val;
1985419892 if (array_type_instruction->sentinel != nullptr) {
1985519893 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))
1985719895 return ira->codegen->invalid_instruction;
1985819896 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))
1986019898 return ira->codegen->invalid_instruction;
1986119899 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
1986219900 if (sentinel_val == nullptr)
......@@ -19909,11 +19947,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1990919947
1991019948static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {
1991119949 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
1991419952 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1);
1991519953 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;
1991719955 lazy_size_of->base.id = LazyValueIdSizeOf;
1991819956
1991919957 lazy_size_of->target_type = instruction->type_value->child;
......@@ -19924,11 +19962,11 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
1992419962}
1992519963
1992619964static 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
1992919967 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
1993019968 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);
1993219970 if (c_ptr_val == nullptr)
1993319971 return ira->codegen->invalid_instruction;
1993419972 if (c_ptr_val->special == ConstValSpecialUndef)
......@@ -19941,11 +19979,11 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1994119979
1994219980 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
1994319981 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;
1994519983 return result;
1994619984 } else if (type_entry->id == ZigTypeIdOptional) {
1994719985 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);
1994919987 if (maybe_val == nullptr)
1995019988 return ira->codegen->invalid_instruction;
1995119989 if (maybe_val->special == ConstValSpecialUndef)
......@@ -19956,7 +19994,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1995619994
1995719995 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
1995819996 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;
1996019998 return result;
1996119999 } else if (type_entry->id == ZigTypeIdNull) {
1996220000 return ir_const_bool(ira, source_inst, false);
......@@ -19967,23 +20005,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1996720005
1996820006static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
1996920007 IrInstruction *value = instruction->value->child;
19970 if (type_is_invalid(value->value.type))
20008 if (type_is_invalid(value->value->type))
1997120009 return ira->codegen->invalid_instruction;
1997220010
1997320011 return ir_analyze_test_non_null(ira, &instruction->base, value);
1997420012}
1997520013
1997620014static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
19977 ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr);
19978 ZigType *elem_type = ptr->value.type->data.pointer.child_type;
20015 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
20016 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
1997920017 if (elem_type != g->builtin_types.entry_var)
1998020018 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))
1998320021 return g->builtin_types.entry_invalid;
1998420022
19985 assert(value_is_comptime(&ptr->value));
19986 ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value);
20023 assert(value_is_comptime(ptr->value));
20024 ZigValue *pointee = const_ptr_pointee_unchecked(g, ptr->value);
1998720025 return pointee->type;
1998820026}
1998920027
......@@ -19996,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
1999620034
1999720035 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
1999820036 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);
2000020038 if (!val)
2000120039 return ira->codegen->invalid_instruction;
2000220040 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);
2000420042 if (c_ptr_val == nullptr)
2000520043 return ira->codegen->invalid_instruction;
2000620044 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
2002820066
2002920067 ZigType *child_type = type_entry->data.maybe.child_type;
2003020068 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,
2003220070 PtrLenSingle, 0, 0, 0, false);
2003320071
2003420072 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry);
2003520073
2003620074 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);
2003820076 if (!ptr_val)
2003920077 return ira->codegen->invalid_instruction;
2004020078 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);
2004220080 if (optional_val == nullptr)
2004320081 return ira->codegen->invalid_instruction;
2004420082
......@@ -20048,7 +20086,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2004820086 return ira->codegen->invalid_instruction;
2004920087 case OnePossibleValueNo:
2005020088 if (!same_comptime_repr) {
20051 ConstExprValue *payload_val = create_const_vals(1);
20089 ZigValue *payload_val = create_const_vals(1);
2005220090 payload_val->type = child_type;
2005320091 payload_val->special = ConstValSpecialUndef;
2005420092 payload_val->parent.id = ConstParentIdOptionalPayload;
......@@ -20059,7 +20097,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2005920097 }
2006020098 break;
2006120099 case OnePossibleValueYes: {
20062 ConstExprValue *pointee = create_const_vals(1);
20100 ZigValue *pointee = create_const_vals(1);
2006320101 pointee->special = ConstValSpecialStatic;
2006420102 pointee->type = child_type;
2006520103 pointee->parent.id = ConstParentIdOptionalPayload;
......@@ -20079,12 +20117,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2007920117 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
2008020118 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
2008120119 source_instr->source_node, base_ptr, false, initializing);
20082 result->value.type = result_type;
20083 result->value.special = ConstValSpecialStatic;
20120 result->value->type = result_type;
20121 result->value->special = ConstValSpecialStatic;
2008420122 } else {
2008520123 result = ir_const(ira, source_instr, result_type);
2008620124 }
20087 ConstExprValue *result_val = &result->value;
20125 ZigValue *result_val = result->value;
2008820126 result_val->data.x_ptr.special = ConstPtrSpecialRef;
2008920127 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
2009020128 switch (type_has_one_possible_value(ira->codegen, child_type)) {
......@@ -20109,7 +20147,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2010920147
2011020148 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
2011120149 source_instr->source_node, base_ptr, safety_check_on, initializing);
20112 result->value.type = result_type;
20150 result->value->type = result_type;
2011320151 return result;
2011420152}
2011520153
......@@ -20117,7 +20155,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
2011720155 IrInstructionOptionalUnwrapPtr *instruction)
2011820156{
2011920157 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))
2012120159 return ira->codegen->invalid_instruction;
2012220160
2012320161 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,
......@@ -20130,26 +20168,26 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt
2013020168 return ira->codegen->invalid_instruction;
2013120169
2013220170 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))
2013420172 return ira->codegen->invalid_instruction;
2013520173
2013620174 if (int_type->data.integral.bit_count == 0)
2013720175 return ir_const_unsigned(ira, &instruction->base, 0);
2013820176
2013920177 if (instr_is_comptime(op)) {
20140 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);
20178 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2014120179 if (val == nullptr)
2014220180 return ira->codegen->invalid_instruction;
2014320181 if (val->special == ConstValSpecialUndef)
2014420182 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);
2014620184 return ir_const_unsigned(ira, &instruction->base, result_usize);
2014720185 }
2014820186
2014920187 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
2015020188 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,
2015120189 instruction->base.source_node, nullptr, op);
20152 result->value.type = return_type;
20190 result->value->type = return_type;
2015320191 return result;
2015420192}
2015520193
......@@ -20159,26 +20197,26 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl
2015920197 return ira->codegen->invalid_instruction;
2016020198
2016120199 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))
2016320201 return ira->codegen->invalid_instruction;
2016420202
2016520203 if (int_type->data.integral.bit_count == 0)
2016620204 return ir_const_unsigned(ira, &instruction->base, 0);
2016720205
2016820206 if (instr_is_comptime(op)) {
20169 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);
20207 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2017020208 if (val == nullptr)
2017120209 return ira->codegen->invalid_instruction;
2017220210 if (val->special == ConstValSpecialUndef)
2017320211 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);
2017520213 return ir_const_unsigned(ira, &instruction->base, result_usize);
2017620214 }
2017720215
2017820216 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
2017920217 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,
2018020218 instruction->base.source_node, nullptr, op);
20181 result->value.type = return_type;
20219 result->value->type = return_type;
2018220220 return result;
2018320221}
2018420222
......@@ -20188,14 +20226,14 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
2018820226 return ira->codegen->invalid_instruction;
2018920227
2019020228 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))
2019220230 return ira->codegen->invalid_instruction;
2019320231
2019420232 if (int_type->data.integral.bit_count == 0)
2019520233 return ir_const_unsigned(ira, &instruction->base, 0);
2019620234
2019720235 if (instr_is_comptime(op)) {
20198 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);
20236 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2019920237 if (val == nullptr)
2020020238 return ira->codegen->invalid_instruction;
2020120239 if (val->special == ConstValSpecialUndef)
......@@ -20212,50 +20250,50 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
2021220250 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
2021320251 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,
2021420252 instruction->base.source_node, nullptr, op);
20215 result->value.type = return_type;
20253 result->value->type = return_type;
2021620254 return result;
2021720255}
2021820256
2021920257static 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))
2022120259 return ira->codegen->invalid_instruction;
2022220260
20223 if (value->value.type->id == ZigTypeIdEnum) {
20261 if (value->value->type->id == ZigTypeIdEnum) {
2022420262 return value;
2022520263 }
2022620264
20227 if (value->value.type->id != ZigTypeIdUnion) {
20265 if (value->value->type->id != ZigTypeIdUnion) {
2022820266 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)));
2023020268 return ira->codegen->invalid_instruction;
2023120269 }
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) {
2023320271 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) {
20235 add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node,
20272 if (value->value->type->data.unionation.decl_node != nullptr) {
20273 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
2023620274 buf_sprintf("declared here"));
2023720275 }
2023820276 return ira->codegen->invalid_instruction;
2023920277 }
2024020278
20241 ZigType *tag_type = value->value.type->data.unionation.tag_type;
20279 ZigType *tag_type = value->value->type->data.unionation.tag_type;
2024220280 assert(tag_type->id == ZigTypeIdEnum);
2024320281
2024420282 if (instr_is_comptime(value)) {
20245 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
20283 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2024620284 if (!val)
2024720285 return ira->codegen->invalid_instruction;
2024820286
2024920287 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
2025020288 source_instr->scope, source_instr->source_node);
20251 const_instruction->base.value.type = tag_type;
20252 const_instruction->base.value.special = ConstValSpecialStatic;
20253 bigint_init_bigint(&const_instruction->base.value.data.x_enum_tag, &val->data.x_union.tag);
20289 const_instruction->base.value->type = tag_type;
20290 const_instruction->base.value->special = ConstValSpecialStatic;
20291 bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag);
2025420292 return &const_instruction->base;
2025520293 }
2025620294
2025720295 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;
2025920297 return result;
2026020298}
2026120299
......@@ -20263,11 +20301,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2026320301 IrInstructionSwitchBr *switch_br_instruction)
2026420302{
2026520303 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))
2026720305 return ir_unreach_error(ira);
2026820306
2026920307 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)) {
2027120309 return ir_unreach_error(ira);
2027220310 }
2027320311 }
......@@ -20280,7 +20318,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2028020318 return ira->codegen->invalid_instruction;
2028120319
2028220320 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);
2028420322 if (!target_val)
2028520323 return ir_unreach_error(ira);
2028620324
......@@ -20288,20 +20326,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2028820326 for (size_t i = 0; i < case_count; i += 1) {
2028920327 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
2029020328 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))
2029220330 return ir_unreach_error(ira);
2029320331
20294 if (case_value->value.type->id == ZigTypeIdEnum) {
20332 if (case_value->value->type->id == ZigTypeIdEnum) {
2029520333 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))
2029720335 return ir_unreach_error(ira);
2029820336 }
2029920337
20300 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);
20301 if (type_is_invalid(casted_case_value->value.type))
20338 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
20339 if (type_is_invalid(casted_case_value->value->type))
2030220340 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);
2030520343 if (!case_val)
2030620344 return ir_unreach_error(ira);
2030720345
......@@ -20318,7 +20356,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2031820356 IrInstruction *result = ir_build_br(&ira->new_irb,
2031920357 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
2032020358 new_dest_block, nullptr);
20321 result->value.type = ira->codegen->builtin_types.entry_unreachable;
20359 result->value->type = ira->codegen->builtin_types.entry_unreachable;
2032220360 return ir_finish_anal(ira, result);
2032320361 }
2032420362 }
......@@ -20338,17 +20376,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2033820376
2033920377 IrInstruction *old_value = old_case->value;
2034020378 IrInstruction *new_value = old_value->child;
20341 if (type_is_invalid(new_value->value.type))
20379 if (type_is_invalid(new_value->value->type))
2034220380 continue;
2034320381
20344 if (new_value->value.type->id == ZigTypeIdEnum) {
20382 if (new_value->value->type->id == ZigTypeIdEnum) {
2034520383 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))
2034720385 continue;
2034820386 }
2034920387
20350 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);
20351 if (type_is_invalid(casted_new_value->value.type))
20388 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
20389 if (type_is_invalid(casted_new_value->value->type))
2035220390 continue;
2035320391
2035420392 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
......@@ -20368,7 +20406,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2036820406 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,
2036920407 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
2037020408 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;
2037220410 return ir_finish_anal(ira, &switch_br->base);
2037320411}
2037420412
......@@ -20377,20 +20415,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2037720415{
2037820416 Error err;
2037920417 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))
2038120419 return ira->codegen->invalid_instruction;
2038220420
20383 if (target_value_ptr->value.type->id == ZigTypeIdMetaType) {
20421 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
2038420422 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;
2038620424 assert(ptr_type->id == ZigTypeIdPointer);
2038720425 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);
2038820426 }
2038920427
20390 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
20391 ConstExprValue *pointee_val = nullptr;
20392 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);
20428 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
20429 ZigValue *pointee_val = nullptr;
20430 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20431 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
2039420432 if (pointee_val == nullptr)
2039520433 return ira->codegen->invalid_instruction;
2039620434
......@@ -20416,13 +20454,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2041620454 case ZigTypeIdErrorSet: {
2041720455 if (pointee_val) {
2041820456 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
20419 copy_const_val(&result->value, pointee_val, true);
20420 result->value.type = target_type;
20457 copy_const_val(result->value, pointee_val, true);
20458 result->value->type = target_type;
2042120459 return result;
2042220460 }
2042320461
2042420462 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;
2042620464 return result;
2042720465 }
2042820466 case ZigTypeIdUnion: {
......@@ -20441,22 +20479,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2044120479 assert(tag_type->id == ZigTypeIdEnum);
2044220480 if (pointee_val) {
2044320481 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);
2044520483 return result;
2044620484 }
2044720485 if (tag_type->data.enumeration.src_field_count == 1) {
2044820486 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
2044920487 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);
2045120489 return result;
2045220490 }
2045320491
2045420492 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
2045720495 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,
2045820496 switch_target_instruction->base.source_node, union_value);
20459 union_tag_inst->value.type = tag_type;
20497 union_tag_inst->value->type = tag_type;
2046020498 return union_tag_inst;
2046120499 }
2046220500 case ZigTypeIdEnum: {
......@@ -20465,18 +20503,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2046520503 if (target_type->data.enumeration.src_field_count < 2) {
2046620504 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
2046720505 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);
2046920507 return result;
2047020508 }
2047120509
2047220510 if (pointee_val) {
2047320511 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);
2047520513 return result;
2047620514 }
2047720515
2047820516 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;
2048020518 return enum_value;
2048120519 }
2048220520 case ZigTypeIdErrorUnion:
......@@ -20501,12 +20539,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2050120539
2050220540static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
2050320541 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))
2050520543 return ira->codegen->invalid_instruction;
2050620544
20507 ZigType *ref_type = target_value_ptr->value.type;
20545 ZigType *ref_type = target_value_ptr->value->type;
2050820546 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;
2051020548 if (target_type->id == ZigTypeIdUnion) {
2051120549 ZigType *enum_type = target_type->data.unionation.tag_type;
2051220550 assert(enum_type != nullptr);
......@@ -20514,14 +20552,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2051420552 assert(instruction->prongs_len > 0);
2051520553
2051620554 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))
2051820556 return ira->codegen->invalid_instruction;
2051920557
2052020558 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))
2052220560 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);
2052520563 if (first_prong_val == nullptr)
2052620564 return ira->codegen->invalid_instruction;
2052720565
......@@ -20530,14 +20568,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2053020568 ErrorMsg *invalid_payload_msg = nullptr;
2053120569 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {
2053220570 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))
2053420572 return ira->codegen->invalid_instruction;
2053520573
2053620574 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))
2053820576 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);
2054120579 if (this_prong == nullptr)
2054220580 return ira->codegen->invalid_instruction;
2054320581
......@@ -20560,18 +20598,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2056020598 }
2056120599
2056220600 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);
2056420602 if (!target_value_ptr)
2056520603 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);
2056820606 if (pointee_val == nullptr)
2056920607 return ira->codegen->invalid_instruction;
2057020608
2057120609 IrInstruction *result = ir_const(ira, &instruction->base,
2057220610 get_pointer_to_type(ira->codegen, first_field->type_entry,
2057320611 target_val_ptr->type->data.pointer.is_const));
20574 ConstExprValue *out_val = &result->value;
20612 ZigValue *out_val = result->value;
2057520613 out_val->data.x_ptr.special = ConstPtrSpecialRef;
2057620614 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
2057720615 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
2058020618
2058120619 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,
2058220620 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,
20584 target_value_ptr->value.type->data.pointer.is_const);
20621 result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry,
20622 target_value_ptr->value->type->data.pointer.is_const);
2058520623 return result;
2058620624 } else if (target_type->id == ZigTypeIdErrorSet) {
2058720625 // construct an error set from the prong values
......@@ -20624,12 +20662,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2062420662 IrInstructionSwitchElseVar *instruction)
2062520663{
2062620664 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))
2062820666 return ira->codegen->invalid_instruction;
2062920667
20630 ZigType *ref_type = target_value_ptr->value.type;
20668 ZigType *ref_type = target_value_ptr->value->type;
2063120669 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;
2063320671 if (target_type->id == ZigTypeIdErrorSet) {
2063420672 // make a new set that has the other cases removed
2063520673 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,
2064520683 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {
2064620684 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
2064720685 IrInstruction *case_expr = br_case->value->child;
20648 if (case_expr->value.type->id == ZigTypeIdErrorSet) {
20686 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
2064920687 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
2065020688 if (err == nullptr)
2065120689 return ira->codegen->invalid_instruction;
2065220690 errors[err->value] = err;
20653 } else if (case_expr->value.type->id == ZigTypeIdMetaType) {
20691 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
2065420692 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
2065520693 if (type_is_invalid(err_set_type))
2065620694 return ira->codegen->invalid_instruction;
......@@ -20742,7 +20780,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
2074220780
2074320781static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
2074420782 IrInstruction *value = ref_instruction->value->child;
20745 if (type_is_invalid(value->value.type))
20783 if (type_is_invalid(value->value->type))
2074620784 return ira->codegen->invalid_instruction;
2074720785 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
2074820786}
......@@ -20768,13 +20806,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
2076820806 if (type_is_invalid(type_field->type_entry))
2076920807 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) {
2077220810 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)
2077420812 {
2077520813 // nothing
2077620814 } else {
20777 result_loc->value.special = ConstValSpecialRuntime;
20815 result_loc->value->special = ConstValSpecialRuntime;
2077820816 }
2077920817 }
2078020818
......@@ -20803,7 +20841,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2080320841 }
2080420842 IrInstructionContainerInitFieldsField *field = &fields[0];
2080520843 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))
2080720845 return ira->codegen->invalid_instruction;
2080820846
2080920847 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
2085020888 IrInstructionContainerInitFieldsField *field = &fields[i];
2085120889
2085220890 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))
2085420892 return ira->codegen->invalid_instruction;
2085520893
2085620894 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
2087420912 field_assign_nodes[field_index] = field->source_node;
2087520913
2087620914 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)
2087820916 {
2087920917 const_ptrs.append(field_result_loc);
2088020918 } else {
......@@ -20912,12 +20950,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2091220950 return ira->codegen->invalid_instruction;
2091320951
2091420952 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
2091720955 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
2091820956 container_type, true);
2091920957 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) {
2092120959 const_ptrs.append(field_ptr);
2092220960 } else {
2092320961 first_non_const_instruction = result_loc;
......@@ -20926,13 +20964,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2092620964 if (any_missing)
2092720965 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) {
2093020968 if (const_ptrs.length != actual_field_count) {
20931 result_loc->value.special = ConstValSpecialRuntime;
20969 result_loc->value->special = ConstValSpecialRuntime;
2093220970 for (size_t i = 0; i < const_ptrs.length; i += 1) {
2093320971 IrInstruction *field_result_loc = const_ptrs.at(i);
2093420972 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;
2093620974 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);
2093720975 }
2093820976 }
......@@ -20954,11 +20992,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2095420992{
2095520993 ir_assert(instruction->result_loc != nullptr, &instruction->base);
2095620994 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))
2095820996 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
2096321001 size_t elem_count = instruction->item_count;
2096421002
......@@ -20980,7 +21018,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2098021018 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
2098121019 ir_assert(instruction->result_loc != nullptr, &instruction->base);
2098221020 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))
2098421022 return result_loc;
2098521023 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);
2098621024 }
......@@ -21041,13 +21079,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2104121079
2104221080 for (size_t i = 0; i < elem_count; i += 1) {
2104321081 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))
2104521083 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
2104921087 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)
2105121089 {
2105221090 const_ptrs.append(elem_result_loc);
2105321091 } else {
......@@ -21055,14 +21093,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2105521093 }
2105621094 }
2105721095
21058 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
21096 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
2105921097 if (const_ptrs.length != elem_count) {
21060 result_loc->value.special = ConstValSpecialRuntime;
21098 result_loc->value->special = ConstValSpecialRuntime;
2106121099 for (size_t i = 0; i < const_ptrs.length; i += 1) {
2106221100 IrInstruction *elem_result_loc = const_ptrs.at(i);
21063 assert(elem_result_loc->value.special == ConstValSpecialStatic);
21101 assert(elem_result_loc->value->special == ConstValSpecialStatic);
2106421102 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;
2106621104 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
2106721105 }
2106821106 }
......@@ -21078,7 +21116,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2107821116 return ira->codegen->invalid_instruction;
2107921117 }
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;
2108221120 if (is_slice(result_elem_type)) {
2108321121 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
2108421122 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
2109521133{
2109621134 ir_assert(instruction->result_loc != nullptr, &instruction->base);
2109721135 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))
2109921137 return result_loc;
2110021138
21101 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);
21102 ZigType *container_type = result_loc->value.type->data.pointer.child_type;
21139 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
21140 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2110321141
2110421142 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
2110521143 instruction->field_count, instruction->fields, result_loc);
......@@ -21123,15 +21161,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
2112321161 fprintf(stderr, "| ");
2112421162 for (size_t i = 0; i < instruction->msg_count; i += 1) {
2112521163 IrInstruction *msg = instruction->msg_list[i]->child;
21126 if (type_is_invalid(msg->value.type))
21164 if (type_is_invalid(msg->value->type))
2112721165 return ira->codegen->invalid_instruction;
2112821166 buf_resize(&buf, 0);
21129 if (msg->value.special == ConstValSpecialLazy) {
21167 if (msg->value->special == ConstValSpecialLazy) {
2113021168 // 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))
2113221170 return ira->codegen->invalid_instruction;
2113321171 }
21134 render_const_value(ira->codegen, &buf, &msg->value);
21172 render_const_value(ira->codegen, &buf, msg->value);
2113521173 const char *comma_str = (i != 0) ? ", " : "";
2113621174 fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf));
2113721175 }
......@@ -21150,28 +21188,28 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
2115021188
2115121189static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
2115221190 IrInstruction *value = instruction->value->child;
21153 if (type_is_invalid(value->value.type))
21191 if (type_is_invalid(value->value->type))
2115421192 return ira->codegen->invalid_instruction;
2115521193
2115621194 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))
2115821196 return ira->codegen->invalid_instruction;
2115921197
2116021198 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2116121199 true, false, PtrLenUnknown, 0, 0, 0, false);
2116221200 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
2116321201 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);
2116521203 if (val == nullptr)
2116621204 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;
2116821206 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;
2117021208 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2117121209 }
2117221210 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21173 copy_const_val(&result->value, err->cached_error_name_val, true);
21174 result->value.type = str_type;
21211 copy_const_val(result->value, err->cached_error_name_val, true);
21212 result->value->type = str_type;
2117521213 return result;
2117621214 }
2117721215
......@@ -21179,25 +21217,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2117921217
2118021218 IrInstruction *result = ir_build_err_name(&ira->new_irb,
2118121219 instruction->base.scope, instruction->base.source_node, value);
21182 result->value.type = str_type;
21220 result->value->type = str_type;
2118321221 return result;
2118421222}
2118521223
2118621224static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
2118721225 Error err;
2118821226 IrInstruction *target = instruction->target->child;
21189 if (type_is_invalid(target->value.type))
21227 if (type_is_invalid(target->value->type))
2119021228 return ira->codegen->invalid_instruction;
2119121229
21192 assert(target->value.type->id == ZigTypeIdEnum);
21230 assert(target->value->type->id == ZigTypeIdEnum);
2119321231
2119421232 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)))
2119621234 return ira->codegen->invalid_instruction;
21197 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;
21235 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
21236 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
2119921237 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);
2120121239 return result;
2120221240 }
2120321241
......@@ -21207,7 +21245,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2120721245 ira->codegen, ira->codegen->builtin_types.entry_u8,
2120821246 true, false, PtrLenUnknown,
2120921247 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);
2121121249 return result;
2121221250}
2121321251
......@@ -21226,7 +21264,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2122621264 return ira->codegen->invalid_instruction;
2122721265
2122821266 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))
2123021268 return ira->codegen->invalid_instruction;
2123121269
2123221270 if (container_type->id != ZigTypeIdStruct) {
......@@ -21246,9 +21284,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2124621284 return ira->codegen->invalid_instruction;
2124721285 }
2124821286
21249 if (field_ptr->value.type->id != ZigTypeIdPointer) {
21287 if (field_ptr->value->type->id != ZigTypeIdPointer) {
2125021288 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)));
2125221290 return ira->codegen->invalid_instruction;
2125321291 }
2125421292
......@@ -21257,22 +21295,22 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2125721295 uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);
2125821296
2125921297 ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
21260 field_ptr->value.type->data.pointer.is_const,
21261 field_ptr->value.type->data.pointer.is_volatile,
21298 field_ptr->value->type->data.pointer.is_const,
21299 field_ptr->value->type->data.pointer.is_volatile,
2126221300 PtrLenSingle,
2126321301 field_ptr_align, 0, 0, false);
2126421302 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))
2126621304 return ira->codegen->invalid_instruction;
2126721305
2126821306 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
21269 casted_field_ptr->value.type->data.pointer.is_const,
21270 casted_field_ptr->value.type->data.pointer.is_volatile,
21307 casted_field_ptr->value->type->data.pointer.is_const,
21308 casted_field_ptr->value->type->data.pointer.is_volatile,
2127121309 PtrLenSingle,
2127221310 parent_ptr_align, 0, 0, false);
2127321311
2127421312 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);
2127621314 if (!field_ptr_val)
2127721315 return ira->codegen->invalid_instruction;
2127821316
......@@ -21291,7 +21329,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2129121329 }
2129221330
2129321331 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
21294 ConstExprValue *out_val = &result->value;
21332 ZigValue *out_val = result->value;
2129521333 out_val->data.x_ptr.special = ConstPtrSpecialRef;
2129621334 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
2129721335 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,
2130021338
2130121339 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,
2130221340 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;
2130421342 return result;
2130521343}
2130621344
......@@ -21350,7 +21388,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,
2135021388 IrInstructionByteOffsetOf *instruction)
2135121389{
2135221390 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))
2135421392 return ira->codegen->invalid_instruction;
2135521393
2135621394 IrInstruction *field_name_value = instruction->field_name->child;
......@@ -21366,7 +21404,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
2136621404 IrInstructionBitOffsetOf *instruction)
2136721405{
2136821406 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))
2137021408 return ira->codegen->invalid_instruction;
2137121409 IrInstruction *field_name_value = instruction->field_name->child;
2137221410 size_t byte_offset = 0;
......@@ -21390,7 +21428,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind
2139021428
2139121429static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {
2139221430 Error err;
21393 ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
21431 ZigValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
2139421432 assert(type_info_var->type->id == ZigTypeIdMetaType);
2139521433 ZigType *type_info_type = type_info_var->data.x_type;
2139621434 assert(type_info_type->id == ZigTypeIdUnion);
......@@ -21423,7 +21461,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
2142321461 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
2142421462}
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,
2142721465 ScopeDecls *decls_scope)
2142821466{
2142921467 Error err;
......@@ -21473,7 +21511,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2147321511 }
2147421512 }
2147521513
21476 ConstExprValue *declaration_array = create_const_vals(1);
21514 ZigValue *declaration_array = create_const_vals(1);
2147721515 declaration_array->special = ConstValSpecialStatic;
2147821516 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
2147921517 declaration_array->data.x_array.special = ConstArraySpecialNone;
......@@ -21494,13 +21532,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2149421532 continue;
2149521533 }
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
2149921537 declaration_val->special = ConstValSpecialStatic;
2150021538 declaration_val->type = type_info_declaration_type;
2150121539
21502 ConstExprValue **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;
21540 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
21541 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
2150421542 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
2150521543 inner_fields[1]->special = ConstValSpecialStatic;
2150621544 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
2152821566 // 1: Data.Var: type
2152921567 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);
2153221570 payload->special = ConstValSpecialStatic;
2153321571 payload->type = ira->codegen->builtin_types.entry_type;
2153421572 payload->data.x_type = var->const_value->type;
......@@ -21553,13 +21591,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2155321591
2155421592 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);
2155721595 fn_decl_val->special = ConstValSpecialStatic;
2155821596 fn_decl_val->type = type_info_fn_decl_type;
2155921597 fn_decl_val->parent.id = ConstParentIdUnion;
2156021598 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);
2156321601 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2156421602
2156521603 // fn_type: type
......@@ -21603,7 +21641,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2160321641 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
2160421642 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
2160521643 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;
2160721645 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
2160821646 buf_len(fn_node->lib_name), true);
2160921647 } else {
......@@ -21617,7 +21655,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2161721655 // arg_names: [][] const u8
2161821656 ensure_field_index(fn_decl_val->type, "arg_names", 8);
2161921657 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);
2162121659 fn_arg_name_array->special = ConstValSpecialStatic;
2162221660 fn_arg_name_array->type = get_array_type(ira->codegen,
2162321661 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
2162821666
2162921667 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2163021668 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];
21632 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,
21669 ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
21670 ZigValue *arg_name = create_const_str_lit(ira->codegen,
2163321671 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
2163421672 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
2163521673 fn_arg_name_val->parent.id = ConstParentIdArray;
......@@ -21649,7 +21687,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2164921687 // This is a type.
2165021688 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);
2165321691 payload->special = ConstValSpecialStatic;
2165421692 payload->type = ira->codegen->builtin_types.entry_type;
2165521693 payload->data.x_type = type_entry;
......@@ -21695,7 +21733,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
2169521733 zig_unreachable();
2169621734}
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) {
2169921737 Error err;
2170021738 ZigType *attrs_type;
2170121739 BuiltinPtrSize size_enum_index;
......@@ -21715,11 +21753,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
2171521753 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2171621754 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);
2171921757 result->special = ConstValSpecialStatic;
2172021758 result->type = type_info_pointer_type;
2172121759
21722 ConstExprValue **fields = alloc_const_vals_ptrs(7);
21760 ZigValue **fields = alloc_const_vals_ptrs(7);
2172321761 result->data.x_struct.fields = fields;
2172421762
2172521763 // size: Size
......@@ -21769,17 +21807,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
2176921807 return result;
2177021808};
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,
2177321811 ZigType *type_info_enum_field_type)
2177421812{
2177521813 enum_field_val->special = ConstValSpecialStatic;
2177621814 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);
2177921817 inner_fields[1]->special = ConstValSpecialStatic;
2178021818 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;
2178321821 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2178421822
2178521823 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,
2178821826}
2178921827
2179021828static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
21791 ConstExprValue **out)
21829 ZigValue **out)
2179221830{
2179321831 Error err;
2179421832 assert(type_entry != nullptr);
......@@ -21803,7 +21841,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2180321841 return ErrorNone;
2180421842 }
2180521843
21806 ConstExprValue *result = nullptr;
21844 ZigValue *result = nullptr;
2180721845 switch (type_entry->id) {
2180821846 case ZigTypeIdInvalid:
2180921847 zig_unreachable();
......@@ -21826,7 +21864,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2182621864 result->special = ConstValSpecialStatic;
2182721865 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);
2183021868 result->data.x_struct.fields = fields;
2183121869
2183221870 // is_signed: bool
......@@ -21848,7 +21886,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2184821886 result->special = ConstValSpecialStatic;
2184921887 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);
2185221890 result->data.x_struct.fields = fields;
2185321891
2185421892 // bits: u8
......@@ -21872,7 +21910,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2187221910 result->special = ConstValSpecialStatic;
2187321911 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);
2187621914 result->data.x_struct.fields = fields;
2187721915
2187821916 // len: usize
......@@ -21896,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2189621934 result->special = ConstValSpecialStatic;
2189721935 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);
2190021938 result->data.x_struct.fields = fields;
2190121939
2190221940 // len: usize
......@@ -21918,7 +21956,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2191821956 result->special = ConstValSpecialStatic;
2191921957 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);
2192221960 result->data.x_struct.fields = fields;
2192321961
2192421962 // child: type
......@@ -21934,7 +21972,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2193421972 result->special = ConstValSpecialStatic;
2193521973 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);
2193821976 result->data.x_struct.fields = fields;
2193921977
2194021978 // child: ?type
......@@ -21951,7 +21989,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2195121989 result->special = ConstValSpecialStatic;
2195221990 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);
2195521993 result->data.x_struct.fields = fields;
2195621994
2195721995 // layout: ContainerLayout
......@@ -21973,7 +22011,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2197322011 }
2197422012 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);
2197722015 enum_field_array->special = ConstValSpecialStatic;
2197822016 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
2197922017 enum_field_array->data.x_array.special = ConstArraySpecialNone;
......@@ -21984,7 +22022,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2198422022 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
2198522023 {
2198622024 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];
2198822026 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);
2198922027 enum_field_val->parent.id = ConstParentIdArray;
2199022028 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
2201722055 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
2201822056 zig_unreachable();
2201922057 }
22020 ConstExprValue *slice_val = create_const_vals(1);
22058 ZigValue *slice_val = create_const_vals(1);
2202122059 result->data.x_optional = slice_val;
2202222060
2202322061 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);
2202522063 error_array->special = ConstValSpecialStatic;
2202622064 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
2202722065 error_array->data.x_array.special = ConstArraySpecialNone;
......@@ -22030,16 +22068,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2203022068 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
2203122069 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
2203222070 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
2203522073 error_val->special = ConstValSpecialStatic;
2203622074 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);
2203922077 inner_fields[1]->special = ConstValSpecialStatic;
2204022078 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2204122079
22042 ConstExprValue *name = nullptr;
22080 ZigValue *name = nullptr;
2204322081 if (error->cached_error_name_val != nullptr)
2204422082 name = error->cached_error_name_val;
2204522083 if (name == nullptr)
......@@ -22061,7 +22099,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2206122099 result->special = ConstValSpecialStatic;
2206222100 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);
2206522103 result->data.x_struct.fields = fields;
2206622104
2206722105 // error_set: type
......@@ -22084,7 +22122,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2208422122 result->special = ConstValSpecialStatic;
2208522123 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);
2208822126 result->data.x_struct.fields = fields;
2208922127
2209022128 // layout: ContainerLayout
......@@ -22101,7 +22139,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2210122139 if (union_decl_node->data.container_decl.auto_enum ||
2210222140 union_decl_node->data.container_decl.init_arg_expr != nullptr)
2210322141 {
22104 ConstExprValue *tag_type = create_const_vals(1);
22142 ZigValue *tag_type = create_const_vals(1);
2210522143 tag_type->special = ConstValSpecialStatic;
2210622144 tag_type->type = ira->codegen->builtin_types.entry_type;
2210722145 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
2211722155 zig_unreachable();
2211822156 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);
2212122159 union_field_array->special = ConstValSpecialStatic;
2212222160 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
2212322161 union_field_array->data.x_array.special = ConstArraySpecialNone;
......@@ -22129,12 +22167,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2212922167
2213022168 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
2213122169 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
2213422172 union_field_val->special = ConstValSpecialStatic;
2213522173 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);
2213822176 inner_fields[1]->special = ConstValSpecialStatic;
2213922177 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
2214922187 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
2215022188 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;
2215322191 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2215422192
2215522193 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
2218022218 result->special = ConstValSpecialStatic;
2218122219 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);
2218422222 result->data.x_struct.fields = fields;
2218522223
2218622224 // layout: ContainerLayout
......@@ -22197,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2219722235 }
2219822236 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);
2220122239 struct_field_array->special = ConstValSpecialStatic;
2220222240 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
2220322241 struct_field_array->data.x_array.special = ConstArraySpecialNone;
......@@ -22207,12 +22245,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2220722245
2220822246 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
2220922247 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
2221222250 struct_field_val->special = ConstValSpecialStatic;
2221322251 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);
2221622254 inner_fields[1]->special = ConstValSpecialStatic;
2221722255 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
2223522273 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
2223622274 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;
2223922277 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2224022278
2224122279 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
2225922297 result->special = ConstValSpecialStatic;
2226022298 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);
2226322301 result->data.x_struct.fields = fields;
2226422302
2226522303 // calling_convention: TypeInfo.CallingConvention
......@@ -22286,7 +22324,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2228622324 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
2228722325 fields[3]->data.x_optional = nullptr;
2228822326 else {
22289 ConstExprValue *return_type = create_const_vals(1);
22327 ZigValue *return_type = create_const_vals(1);
2229022328 return_type->special = ConstValSpecialStatic;
2229122329 return_type->type = ira->codegen->builtin_types.entry_type;
2229222330 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
2230022338 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
2230122339 (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);
2230422342 fn_arg_array->special = ConstValSpecialStatic;
2230522343 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
2230622344 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
......@@ -22310,7 +22348,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2231022348
2231122349 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2231222350 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
2231522353 fn_arg_val->special = ConstValSpecialStatic;
2231622354 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
2231822356 bool arg_is_generic = fn_param_info->type == nullptr;
2231922357 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);
2232222360 inner_fields[0]->special = ConstValSpecialStatic;
2232322361 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
2232422362 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
2233122369 if (arg_is_generic)
2233222370 inner_fields[2]->data.x_optional = nullptr;
2233322371 else {
22334 ConstExprValue *arg_type = create_const_vals(1);
22372 ZigValue *arg_type = create_const_vals(1);
2233522373 arg_type->special = ConstValSpecialStatic;
2233622374 arg_type->type = ira->codegen->builtin_types.entry_type;
2233722375 arg_type->data.x_type = fn_param_info->type;
......@@ -22376,12 +22414,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2237622414
2237722415 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2237822416
22379 ConstExprValue *payload;
22417 ZigValue *payload;
2238022418 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
2238122419 return ira->codegen->invalid_instruction;
2238222420
2238322421 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
22384 ConstExprValue *out_val = &result->value;
22422 ZigValue *out_val = result->value;
2238522423 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
2238622424 out_val->data.x_union.payload = payload;
2238722425
......@@ -22393,49 +22431,49 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2239322431 return result;
2239422432}
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)
2239722435{
2239822436 ensure_field_index(struct_value->type, name, field_index);
2239922437 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
2240022438 return struct_value->data.x_struct.fields[field_index];
2240122439}
2240222440
22403static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value,
22404 const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result)
22441static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
22442 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
2240522443{
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);
2240722445 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
2240822446 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
2240922447 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))
2241122449 return ErrorSemanticAnalyzeFail;
2241222450
22413 *result = casted_field_inst->value.data.x_optional;
22451 *result = casted_field_inst->value->data.x_optional;
2241422452 return ErrorNone;
2241522453}
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)
2241822456{
22419 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
22457 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
2242022458 assert(value->type == ira->codegen->builtin_types.entry_bool);
2242122459 return value->data.x_bool;
2242222460}
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)
2242522463{
22426 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
22464 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
2242722465 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
2242822466 return &value->data.x_bigint;
2242922467}
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)
2243222470{
22433 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
22471 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
2243422472 assert(value->type == ira->codegen->builtin_types.entry_type);
2243522473 return value->data.x_type;
2243622474}
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) {
2243922477 Error err;
2244022478 switch (tagTypeId) {
2244122479 case ZigTypeIdInvalid:
......@@ -22474,12 +22512,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2247422512 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2247522513 assert(payload->special == ConstValSpecialStatic);
2247622514 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);
2247822516 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
2247922517 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
2248022518 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
2248122519 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
22482 ConstExprValue *sentinel;
22520 ZigValue *sentinel;
2248322521 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
2248422522 elem_type, &sentinel)))
2248522523 {
......@@ -22504,7 +22542,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2250422542 assert(payload->special == ConstValSpecialStatic);
2250522543 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
2250622544 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
22507 ConstExprValue *sentinel;
22545 ZigValue *sentinel;
2250822546 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
2250922547 elem_type, &sentinel)))
2251022548 {
......@@ -22549,14 +22587,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2254922587
2255022588static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {
2255122589 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))
2255322591 return ira->codegen->invalid_instruction;
2255422592
2255522593 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))
2255722595 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);
2256022598 if (!type_info_value)
2256122599 return ira->codegen->invalid_instruction;
2256222600 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,
2257422612 if (type_is_invalid(type_entry))
2257522613 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");
2257822616 assert(var_value->type->id == ZigTypeIdMetaType);
2257922617 ZigType *result_type = var_value->data.x_type;
2258022618
2258122619 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));
2258322621 return result;
2258422622}
2258522623
......@@ -22607,7 +22645,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
2260722645 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2260822646 }
2260922647 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);
2261122649 return result;
2261222650}
2261322651
......@@ -22628,7 +22666,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2262822666
2262922667 // Execute the C import block like an inline function
2263022668 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,
2263222670 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
2263322671 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
2263422672 if (type_is_invalid(cimport_result->type))
......@@ -22796,7 +22834,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2279622834
2279722835static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
2279822836 IrInstruction *name_value = instruction->name->child;
22799 if (type_is_invalid(name_value->value.type))
22837 if (type_is_invalid(name_value->value->type))
2280022838 return ira->codegen->invalid_instruction;
2280122839
2280222840 Buf *include_name = ir_resolve_str(ira, name_value);
......@@ -22814,7 +22852,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc
2281422852
2281522853static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
2281622854 IrInstruction *name = instruction->name->child;
22817 if (type_is_invalid(name->value.type))
22855 if (type_is_invalid(name->value->type))
2281822856 return ira->codegen->invalid_instruction;
2281922857
2282022858 Buf *define_name = ir_resolve_str(ira, name);
......@@ -22822,12 +22860,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct
2282222860 return ira->codegen->invalid_instruction;
2282322861
2282422862 IrInstruction *value = instruction->value->child;
22825 if (type_is_invalid(value->value.type))
22863 if (type_is_invalid(value->value->type))
2282622864 return ira->codegen->invalid_instruction;
2282722865
2282822866 Buf *define_value = nullptr;
2282922867 // 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) {
2283122869 define_value = ir_resolve_str(ira, value);
2283222870 if (!define_value)
2283322871 return ira->codegen->invalid_instruction;
......@@ -22845,7 +22883,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct
2284522883
2284622884static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
2284722885 IrInstruction *name = instruction->name->child;
22848 if (type_is_invalid(name->value.type))
22886 if (type_is_invalid(name->value->type))
2284922887 return ira->codegen->invalid_instruction;
2285022888
2285122889 Buf *undef_name = ir_resolve_str(ira, name);
......@@ -22863,7 +22901,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi
2286322901
2286422902static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
2286522903 IrInstruction *name = instruction->name->child;
22866 if (type_is_invalid(name->value.type))
22904 if (type_is_invalid(name->value->type))
2286722905 return ira->codegen->invalid_instruction;
2286822906
2286922907 Buf *rel_file_path = ir_resolve_str(ira, name);
......@@ -22898,7 +22936,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
2289822936 ZigType *result_type = get_array_type(ira->codegen,
2289922937 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);
2290022938 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);
2290222940 return result;
2290322941}
2290422942
......@@ -22908,25 +22946,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2290822946 return ira->codegen->invalid_instruction;
2290922947
2291022948 IrInstruction *ptr = instruction->ptr->child;
22911 if (type_is_invalid(ptr->value.type))
22949 if (type_is_invalid(ptr->value->type))
2291222950 return ira->codegen->invalid_instruction;
2291322951
2291422952 // TODO let this be volatile
2291522953 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2291622954 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))
2291822956 return ira->codegen->invalid_instruction;
2291922957
2292022958 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))
2292222960 return ira->codegen->invalid_instruction;
2292322961
2292422962 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))
2292622964 return ira->codegen->invalid_instruction;
2292722965
2292822966 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))
2293022968 return ira->codegen->invalid_instruction;
2293122969
2293222970 AtomicOrder success_order;
......@@ -22934,7 +22972,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2293422972 return ira->codegen->invalid_instruction;
2293522973
2293622974 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))
2293822976 return ira->codegen->invalid_instruction;
2293922977
2294022978 AtomicOrder failure_order;
......@@ -22942,11 +22980,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2294222980 return ira->codegen->invalid_instruction;
2294322981
2294422982 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))
2294622984 return ira->codegen->invalid_instruction;
2294722985
2294822986 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))
2295022988 return ira->codegen->invalid_instruction;
2295122989
2295222990 if (success_order < AtomicOrderMonotonic) {
......@@ -22970,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2297023008 return ira->codegen->invalid_instruction;
2297123009 }
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 &&
2297423012 instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
2297523013 zig_panic("TODO compile-time execution of cmpxchg");
2297623014 }
......@@ -22980,7 +23018,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2298023018 if (handle_is_ptr(result_type)) {
2298123019 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2298223020 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)) {
2298423022 return result_loc;
2298523023 }
2298623024 } else {
......@@ -22994,7 +23032,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2299423032
2299523033static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
2299623034 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))
2299823036 return ira->codegen->invalid_instruction;
2299923037
2300023038 AtomicOrder order;
......@@ -23009,7 +23047,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction
2300923047
2301023048 IrInstruction *result = ir_build_fence(&ira->new_irb,
2301123049 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;
2301323051 return result;
2301423052}
2301523053
......@@ -23027,7 +23065,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2302723065 }
2302823066
2302923067 IrInstruction *target = instruction->target->child;
23030 ZigType *src_type = target->value.type;
23068 ZigType *src_type = target->value->type;
2303123069 if (type_is_invalid(src_type))
2303223070 return ira->codegen->invalid_instruction;
2303323071
......@@ -23043,19 +23081,19 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2304323081 }
2304423082
2304523083 if (instr_is_comptime(target)) {
23046 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
23084 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2304723085 if (val == nullptr)
2304823086 return ira->codegen->invalid_instruction;
2304923087
2305023088 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,
2305223090 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
2305323091 return result;
2305423092 }
2305523093
2305623094 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
2305723095 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);
2305923097 return result;
2306023098 }
2306123099
......@@ -23071,7 +23109,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2307123109
2307223110 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,
2307323111 instruction->base.source_node, dest_type_value, target);
23074 new_instruction->value.type = dest_type;
23112 new_instruction->value->type = dest_type;
2307523113 return new_instruction;
2307623114}
2307723115
......@@ -23086,12 +23124,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
2308623124 }
2308723125
2308823126 IrInstruction *target = instruction->target->child;
23089 if (type_is_invalid(target->value.type))
23127 if (type_is_invalid(target->value->type))
2309023128 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) {
2309323131 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)));
2309523133 return ira->codegen->invalid_instruction;
2309623134 }
2309723135
......@@ -23120,15 +23158,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
2312023158 }
2312123159
2312223160 IrInstruction *target = instruction->target->child;
23123 if (type_is_invalid(target->value.type))
23161 if (type_is_invalid(target->value->type))
2312423162 return ira->codegen->invalid_instruction;
2312523163
23126 if (target->value.type->id == ZigTypeIdComptimeInt ||
23127 target->value.type->id == ZigTypeIdComptimeFloat)
23164 if (target->value->type->id == ZigTypeIdComptimeInt ||
23165 target->value->type->id == ZigTypeIdComptimeFloat)
2312823166 {
2312923167 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
2313023168 CastOp op;
23131 if (target->value.type->id == ZigTypeIdComptimeInt) {
23169 if (target->value->type->id == ZigTypeIdComptimeInt) {
2313223170 op = CastOpIntToFloat;
2313323171 } else {
2313423172 op = CastOpNumLitToConcrete;
......@@ -23139,9 +23177,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
2313923177 }
2314023178 }
2314123179
23142 if (target->value.type->id != ZigTypeIdFloat) {
23180 if (target->value->type->id != ZigTypeIdFloat) {
2314323181 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)));
2314523183 return ira->codegen->invalid_instruction;
2314623184 }
2314723185
......@@ -23160,12 +23198,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst
2316023198 }
2316123199
2316223200 IrInstruction *target = instruction->target->child;
23163 if (type_is_invalid(target->value.type))
23201 if (type_is_invalid(target->value->type))
2316423202 return ira->codegen->invalid_instruction;
2316523203
23166 if (target->value.type->id != ZigTypeIdErrorSet) {
23204 if (target->value->type->id != ZigTypeIdErrorSet) {
2316723205 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)));
2316923207 return ira->codegen->invalid_instruction;
2317023208 }
2317123209
......@@ -23180,20 +23218,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2318023218 return ira->codegen->invalid_instruction;
2318123219
2318223220 IrInstruction *target = instruction->target->child;
23183 if (type_is_invalid(target->value.type))
23221 if (type_is_invalid(target->value->type))
2318423222 return ira->codegen->invalid_instruction;
2318523223
2318623224 bool src_ptr_const;
2318723225 bool src_ptr_volatile;
2318823226 uint32_t src_ptr_align;
23189 if (target->value.type->id == ZigTypeIdPointer) {
23190 src_ptr_const = target->value.type->data.pointer.is_const;
23191 src_ptr_volatile = target->value.type->data.pointer.is_volatile;
23227 if (target->value->type->id == ZigTypeIdPointer) {
23228 src_ptr_const = target->value->type->data.pointer.is_const;
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)))
2319423232 return ira->codegen->invalid_instruction;
23195 } else if (is_slice(target->value.type)) {
23196 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;
23233 } else if (is_slice(target->value->type)) {
23234 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2319723235 src_ptr_const = src_ptr_type->data.pointer.is_const;
2319823236 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
2320323241 src_ptr_const = true;
2320423242 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)))
2320723245 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);
2321023248 }
2321123249
2321223250 if (src_ptr_align != 0) {
......@@ -23225,18 +23263,18 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2322523263 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2322623264
2322723265 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))
2322923267 return ira->codegen->invalid_instruction;
2323023268
2323123269 bool have_known_len = false;
2323223270 uint64_t known_len;
2323323271
2323423272 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);
2323623274 if (!val)
2323723275 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];
2324023278 if (value_is_comptime(len_val)) {
2324123279 known_len = bigint_as_u64(&len_val->data.x_bigint);
2324223280 have_known_len = true;
......@@ -23245,12 +23283,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2324523283
2324623284 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2324723285 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))) {
2324923287 return result_loc;
2325023288 }
2325123289
23252 if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) {
23253 known_len = casted_value->value.data.rh_slice.len;
23290 if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
23291 known_len = casted_value->value->data.rh_slice.len;
2325423292 have_known_len = true;
2325523293 }
2325623294
......@@ -23277,16 +23315,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2327723315 Error err;
2327823316
2327923317 IrInstruction *target = instruction->target->child;
23280 if (type_is_invalid(target->value.type))
23318 if (type_is_invalid(target->value->type))
2328123319 return ira->codegen->invalid_instruction;
2328223320
23283 if (!is_slice(target->value.type)) {
23321 if (!is_slice(target->value->type)) {
2328423322 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)));
2328623324 return ira->codegen->invalid_instruction;
2328723325 }
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
2329123329 uint32_t alignment;
2329223330 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
......@@ -23298,22 +23336,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2329823336 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
2329923337
2330023338 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);
2330223340 if (target_val == nullptr)
2330323341 return ira->codegen->invalid_instruction;
2330423342
2330523343 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];
23309 ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
23346 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
23347 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
2331023348 copy_const_val(ptr_val, target_ptr_val, false);
2331123349 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];
2331423352 len_val->special = ConstValSpecialStatic;
2331523353 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];
2331723355 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
2331823356 BigInt elem_size_bigint;
2331923357 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
2332423362
2332523363 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2332623364 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)) {
2332823366 return result_loc;
2332923367 }
2333023368
......@@ -23351,12 +23389,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
2335123389 return ira->codegen->invalid_instruction;
2335223390
2335323391 IrInstruction *target = instruction->target->child;
23354 if (type_is_invalid(target->value.type))
23392 if (type_is_invalid(target->value->type))
2335523393 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) {
2335823396 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)));
2336023398 return ira->codegen->invalid_instruction;
2336123399 }
2336223400
......@@ -23369,16 +23407,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
2336923407 return ira->codegen->invalid_instruction;
2337023408
2337123409 IrInstruction *target = instruction->target->child;
23372 if (type_is_invalid(target->value.type))
23410 if (type_is_invalid(target->value->type))
2337323411 return ira->codegen->invalid_instruction;
2337423412
23375 if (target->value.type->id == ZigTypeIdComptimeInt) {
23413 if (target->value->type->id == ZigTypeIdComptimeInt) {
2337623414 return ir_implicit_cast(ira, target, dest_type);
2337723415 }
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) {
2338023418 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)));
2338223420 return ira->codegen->invalid_instruction;
2338323421 }
2338423422
......@@ -23387,15 +23425,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
2338723425
2338823426static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
2338923427 IrInstruction *target = instruction->target->child;
23390 if (type_is_invalid(target->value.type))
23428 if (type_is_invalid(target->value->type))
2339123429 return ira->codegen->invalid_instruction;
2339223430
2339323431 IrInstruction *casted_target;
23394 if (target->value.type->id == ZigTypeIdErrorSet) {
23432 if (target->value->type->id == ZigTypeIdErrorSet) {
2339523433 casted_target = target;
2339623434 } else {
2339723435 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))
2339923437 return ira->codegen->invalid_instruction;
2340023438 }
2340123439
......@@ -23404,11 +23442,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru
2340423442
2340523443static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
2340623444 IrInstruction *target = instruction->target->child;
23407 if (type_is_invalid(target->value.type))
23445 if (type_is_invalid(target->value->type))
2340823446 return ira->codegen->invalid_instruction;
2340923447
2341023448 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))
2341223450 return ira->codegen->invalid_instruction;
2341323451
2341423452 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
2341623454
2341723455static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
2341823456 IrInstruction *target = instruction->target->child;
23419 if (type_is_invalid(target->value.type))
23457 if (type_is_invalid(target->value->type))
2342023458 return ira->codegen->invalid_instruction;
2342123459
23422 if (target->value.type->id != ZigTypeIdBool) {
23460 if (target->value->type->id != ZigTypeIdBool) {
2342323461 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)));
2342523463 return ira->codegen->invalid_instruction;
2342623464 }
2342723465
......@@ -23472,48 +23510,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2347223510 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);
2347323511
2347423512 uint32_t len_mask;
23475 if (mask->value.type->id == ZigTypeIdVector) {
23476 len_mask = mask->value.type->data.vector.len;
23477 } else if (mask->value.type->id == ZigTypeIdArray) {
23478 len_mask = mask->value.type->data.array.len;
23513 if (mask->value->type->id == ZigTypeIdVector) {
23514 len_mask = mask->value->type->data.vector.len;
23515 } else if (mask->value->type->id == ZigTypeIdArray) {
23516 len_mask = mask->value->type->data.array.len;
2347923517 } else {
2348023518 ir_add_error(ira, mask,
2348123519 buf_sprintf("expected vector or array, found '%s'",
23482 buf_ptr(&mask->value.type->name)));
23520 buf_ptr(&mask->value->type->name)));
2348323521 return ira->codegen->invalid_instruction;
2348423522 }
2348523523 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
2348623524 ira->codegen->builtin_types.entry_i32));
23487 if (type_is_invalid(mask->value.type))
23525 if (type_is_invalid(mask->value->type))
2348823526 return ira->codegen->invalid_instruction;
2348923527
2349023528 uint32_t len_a;
23491 if (a->value.type->id == ZigTypeIdVector) {
23492 len_a = a->value.type->data.vector.len;
23493 } else if (a->value.type->id == ZigTypeIdArray) {
23494 len_a = a->value.type->data.array.len;
23495 } else if (a->value.type->id == ZigTypeIdUndefined) {
23529 if (a->value->type->id == ZigTypeIdVector) {
23530 len_a = a->value->type->data.vector.len;
23531 } else if (a->value->type->id == ZigTypeIdArray) {
23532 len_a = a->value->type->data.array.len;
23533 } else if (a->value->type->id == ZigTypeIdUndefined) {
2349623534 len_a = UINT32_MAX;
2349723535 } else {
2349823536 ir_add_error(ira, a,
2349923537 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2350023538 buf_ptr(&scalar_type->name),
23501 buf_ptr(&a->value.type->name)));
23539 buf_ptr(&a->value->type->name)));
2350223540 return ira->codegen->invalid_instruction;
2350323541 }
2350423542
2350523543 uint32_t len_b;
23506 if (b->value.type->id == ZigTypeIdVector) {
23507 len_b = b->value.type->data.vector.len;
23508 } else if (b->value.type->id == ZigTypeIdArray) {
23509 len_b = b->value.type->data.array.len;
23510 } else if (b->value.type->id == ZigTypeIdUndefined) {
23544 if (b->value->type->id == ZigTypeIdVector) {
23545 len_b = b->value->type->data.vector.len;
23546 } else if (b->value->type->id == ZigTypeIdArray) {
23547 len_b = b->value->type->data.array.len;
23548 } else if (b->value->type->id == ZigTypeIdUndefined) {
2351123549 len_b = UINT32_MAX;
2351223550 } else {
2351323551 ir_add_error(ira, b,
2351423552 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2351523553 buf_ptr(&scalar_type->name),
23516 buf_ptr(&b->value.type->name)));
23554 buf_ptr(&b->value->type->name)));
2351723555 return ira->codegen->invalid_instruction;
2351823556 }
2351923557
......@@ -23526,7 +23564,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2352623564 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
2352723565 } else {
2352823566 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))
2353023568 return ira->codegen->invalid_instruction;
2353123569 }
2353223570
......@@ -23535,18 +23573,18 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2353523573 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
2353623574 } else {
2353723575 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))
2353923577 return ira->codegen->invalid_instruction;
2354023578 }
2354123579
23542 ConstExprValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
23580 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
2354323581 if (mask_val == nullptr)
2354423582 return ira->codegen->invalid_instruction;
2354523583
2354623584 expand_undef_array(ira->codegen, mask_val);
2354723585
2354823586 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];
2355023588 if (mask_elem_val->special == ConstValSpecialUndef)
2355123589 continue;
2355223590 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
2355923597 v = (uint32_t)~v_i32;
2356023598 chosen_operand = b;
2356123599 }
23562 if (v >= chosen_operand->value.type->data.vector.len) {
23600 if (v >= chosen_operand->value->type->data.vector.len) {
2356323601 ErrorMsg *msg = ir_add_error(ira, mask,
2356423602 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
2356523603 add_error_note(ira->codegen, msg, chosen_operand->source_node,
2356623604 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)));
2356823606 if (chosen_operand == a && v < len_a + len_b) {
2356923607 add_error_note(ira->codegen, msg, b->source_node,
2357023608 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
2357523613
2357623614 ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type);
2357723615 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);
2357923617 if (a_val == nullptr)
2358023618 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);
2358323621 if (b_val == nullptr)
2358423622 return ira->codegen->invalid_instruction;
2358523623
......@@ -23587,24 +23625,24 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2358723625 expand_undef_array(ira->codegen, b_val);
2358823626
2358923627 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);
2359123629 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];
23593 ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];
23630 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
23631 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
2359423632 if (mask_elem_val->special == ConstValSpecialUndef) {
2359523633 result_elem_val->special = ConstValSpecialUndef;
2359623634 continue;
2359723635 }
2359823636 int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint);
2359923637 // We've already checked for and emitted compile errors for index out of bounds here.
23600 ConstExprValue *src_elem_val = (v >= 0) ?
23601 &a->value.data.x_array.data.s_none.elements[v] :
23602 &b->value.data.x_array.data.s_none.elements[~v];
23638 ZigValue *src_elem_val = (v >= 0) ?
23639 &a->value->data.x_array.data.s_none.elements[v] :
23640 &b->value->data.x_array.data.s_none.elements[~v];
2360323641 copy_const_val(result_elem_val, src_elem_val, false);
2360423642
2360523643 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
2360623644 }
23607 result->value.special = ConstValSpecialStatic;
23645 result->value->special = ConstValSpecialStatic;
2360823646 return result;
2360923647 }
2361023648
......@@ -23620,12 +23658,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2362023658
2362123659 IrInstruction *expand_mask = ir_const(ira, mask,
2362223660 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);
2362423662 uint32_t i = 0;
2362523663 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);
2362723665 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
2363023668 IrInstruction *undef = ir_const_undef(ira, source_instr,
2363123669 get_vector_type(ira->codegen, len_min, scalar_type));
......@@ -23640,7 +23678,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2364023678 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,
2364123679 source_instr->scope, source_instr->source_node,
2364223680 nullptr, a, b, mask);
23643 result->value.type = result_type;
23681 result->value->type = result_type;
2364423682 return result;
2364523683}
2364623684
......@@ -23650,15 +23688,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn
2365023688 return ira->codegen->invalid_instruction;
2365123689
2365223690 IrInstruction *a = instruction->a->child;
23653 if (type_is_invalid(a->value.type))
23691 if (type_is_invalid(a->value->type))
2365423692 return ira->codegen->invalid_instruction;
2365523693
2365623694 IrInstruction *b = instruction->b->child;
23657 if (type_is_invalid(b->value.type))
23695 if (type_is_invalid(b->value->type))
2365823696 return ira->codegen->invalid_instruction;
2365923697
2366023698 IrInstruction *mask = instruction->mask->child;
23661 if (type_is_invalid(mask->value.type))
23699 if (type_is_invalid(mask->value->type))
2366223700 return ira->codegen->invalid_instruction;
2366323701
2366423702 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
2366823706 Error err;
2366923707
2367023708 IrInstruction *len = instruction->len->child;
23671 if (type_is_invalid(len->value.type))
23709 if (type_is_invalid(len->value->type))
2367223710 return ira->codegen->invalid_instruction;
2367323711
2367423712 IrInstruction *scalar = instruction->scalar->child;
23675 if (type_is_invalid(scalar->value.type))
23713 if (type_is_invalid(scalar->value->type))
2367623714 return ira->codegen->invalid_instruction;
2367723715
2367823716 uint64_t len_u64;
......@@ -23680,22 +23718,22 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2368023718 return ira->codegen->invalid_instruction;
2368123719 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)))
2368423722 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
2368823726 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);
2369023728 if (scalar_val == nullptr)
2369123729 return ira->codegen->invalid_instruction;
2369223730 if (scalar_val->special == ConstValSpecialUndef)
2369323731 return ir_const_undef(ira, &instruction->base, return_type);
2369423732
2369523733 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);
2369723735 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);
2369923737 }
2370023738 return result;
2370123739 }
......@@ -23705,17 +23743,17 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2370523743
2370623744static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
2370723745 IrInstruction *value = instruction->value->child;
23708 if (type_is_invalid(value->value.type))
23746 if (type_is_invalid(value->value->type))
2370923747 return ira->codegen->invalid_instruction;
2371023748
2371123749 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2371223750
2371323751 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))
2371523753 return ira->codegen->invalid_instruction;
2371623754
2371723755 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);
2371923757 if (value == nullptr)
2372023758 return ira->codegen->invalid_instruction;
2372123759
......@@ -23724,7 +23762,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct
2372423762
2372523763 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,
2372623764 instruction->base.source_node, casted_value);
23727 result->value.type = bool_type;
23765 result->value->type = bool_type;
2372823766 return result;
2372923767}
2373023768
......@@ -23732,18 +23770,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2373223770 Error err;
2373323771
2373423772 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))
2373623774 return ira->codegen->invalid_instruction;
2373723775
2373823776 IrInstruction *byte_value = instruction->byte->child;
23739 if (type_is_invalid(byte_value->value.type))
23777 if (type_is_invalid(byte_value->value->type))
2374023778 return ira->codegen->invalid_instruction;
2374123779
2374223780 IrInstruction *count_value = instruction->count->child;
23743 if (type_is_invalid(count_value->value.type))
23781 if (type_is_invalid(count_value->value->type))
2374423782 return ira->codegen->invalid_instruction;
2374523783
23746 ZigType *dest_uncasted_type = dest_ptr->value.type;
23784 ZigType *dest_uncasted_type = dest_ptr->value->type;
2374723785 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
2374823786 dest_uncasted_type->data.pointer.is_volatile;
2374923787
......@@ -23760,15 +23798,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2376023798 PtrLenUnknown, dest_align, 0, 0, false);
2376123799
2376223800 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))
2376423802 return ira->codegen->invalid_instruction;
2376523803
2376623804 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))
2376823806 return ira->codegen->invalid_instruction;
2376923807
2377023808 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))
2377223810 return ira->codegen->invalid_instruction;
2377323811
2377423812 // TODO test this at comptime with u8 and non-u8 types
......@@ -23776,22 +23814,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2377623814 instr_is_comptime(casted_byte) &&
2377723815 instr_is_comptime(casted_count))
2377823816 {
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);
2378023818 if (dest_ptr_val == nullptr)
2378123819 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);
2378423822 if (byte_val == nullptr)
2378523823 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);
2378823826 if (count_val == nullptr)
2378923827 return ira->codegen->invalid_instruction;
2379023828
23791 if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
23792 casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)
23829 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
23830 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
2379323831 {
23794 ConstExprValue *dest_elements;
23832 ZigValue *dest_elements;
2379523833 size_t start;
2379623834 size_t bound_end;
2379723835 switch (dest_ptr_val->data.x_ptr.special) {
......@@ -23805,7 +23843,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2380523843 break;
2380623844 case ConstPtrSpecialBaseArray:
2380723845 {
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;
2380923847 expand_undef_array(ira->codegen, array_val);
2381023848 dest_elements = array_val->data.x_array.data.s_none.elements;
2381123849 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
2384523883
2384623884 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
2384723885 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;
2384923887 return result;
2385023888}
2385123889
......@@ -23853,20 +23891,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2385323891 Error err;
2385423892
2385523893 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))
2385723895 return ira->codegen->invalid_instruction;
2385823896
2385923897 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))
2386123899 return ira->codegen->invalid_instruction;
2386223900
2386323901 IrInstruction *count_value = instruction->count->child;
23864 if (type_is_invalid(count_value->value.type))
23902 if (type_is_invalid(count_value->value->type))
2386523903 return ira->codegen->invalid_instruction;
2386623904
2386723905 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
23868 ZigType *dest_uncasted_type = dest_ptr->value.type;
23869 ZigType *src_uncasted_type = src_ptr->value.type;
23906 ZigType *dest_uncasted_type = dest_ptr->value->type;
23907 ZigType *src_uncasted_type = src_ptr->value->type;
2387023908 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
2387123909 dest_uncasted_type->data.pointer.is_volatile;
2387223910 bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&
......@@ -23895,15 +23933,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2389523933 PtrLenUnknown, src_align, 0, 0, false);
2389623934
2389723935 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))
2389923937 return ira->codegen->invalid_instruction;
2390023938
2390123939 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))
2390323941 return ira->codegen->invalid_instruction;
2390423942
2390523943 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))
2390723945 return ira->codegen->invalid_instruction;
2390823946
2390923947 // TODO test this at comptime with u8 and non-u8 types
......@@ -23912,22 +23950,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2391223950 instr_is_comptime(casted_src_ptr) &&
2391323951 instr_is_comptime(casted_count))
2391423952 {
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);
2391623954 if (dest_ptr_val == nullptr)
2391723955 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);
2392023958 if (src_ptr_val == nullptr)
2392123959 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);
2392423962 if (count_val == nullptr)
2392523963 return ira->codegen->invalid_instruction;
2392623964
2392723965 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2392823966 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2392923967
23930 ConstExprValue *dest_elements;
23968 ZigValue *dest_elements;
2393123969 size_t dest_start;
2393223970 size_t dest_end;
2393323971 switch (dest_ptr_val->data.x_ptr.special) {
......@@ -23941,7 +23979,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2394123979 break;
2394223980 case ConstPtrSpecialBaseArray:
2394323981 {
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;
2394523983 expand_undef_array(ira->codegen, array_val);
2394623984 dest_elements = array_val->data.x_array.data.s_none.elements;
2394723985 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
2396924007 return ira->codegen->invalid_instruction;
2397024008 }
2397124009
23972 ConstExprValue *src_elements;
24010 ZigValue *src_elements;
2397324011 size_t src_start;
2397424012 size_t src_end;
2397524013
......@@ -23984,7 +24022,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2398424022 break;
2398524023 case ConstPtrSpecialBaseArray:
2398624024 {
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;
2398824026 expand_undef_array(ira->codegen, array_val);
2398924027 src_elements = array_val->data.x_array.data.s_none.elements;
2399024028 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
2402424062
2402524063 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
2402624064 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;
2402824066 return result;
2402924067}
2403024068
2403124069static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {
2403224070 IrInstruction *ptr_ptr = instruction->ptr->child;
24033 if (type_is_invalid(ptr_ptr->value.type))
24071 if (type_is_invalid(ptr_ptr->value->type))
2403424072 return ira->codegen->invalid_instruction;
2403524073
24036 ZigType *ptr_ptr_type = ptr_ptr->value.type;
24074 ZigType *ptr_ptr_type = ptr_ptr->value->type;
2403724075 assert(ptr_ptr_type->id == ZigTypeIdPointer);
2403824076 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2403924077
2404024078 IrInstruction *start = instruction->start->child;
24041 if (type_is_invalid(start->value.type))
24079 if (type_is_invalid(start->value->type))
2404224080 return ira->codegen->invalid_instruction;
2404324081
2404424082 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2404524083 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))
2404724085 return ira->codegen->invalid_instruction;
2404824086
2404924087 IrInstruction *end;
2405024088 if (instruction->end) {
2405124089 end = instruction->end->child;
24052 if (type_is_invalid(end->value.type))
24090 if (type_is_invalid(end->value->type))
2405324091 return ira->codegen->invalid_instruction;
2405424092 end = ir_implicit_cast(ira, end, usize);
24055 if (type_is_invalid(end->value.type))
24093 if (type_is_invalid(end->value->type))
2405624094 return ira->codegen->invalid_instruction;
2405724095 } else {
2405824096 end = nullptr;
......@@ -24061,8 +24099,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2406124099 ZigType *return_type;
2406224100
2406324101 if (array_type->id == ZigTypeIdArray) {
24064 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
24065 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
24102 bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic &&
24103 ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst;
2406624104 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
2406724105 ptr_ptr_type->data.pointer.is_const || is_comptime_const,
2406824106 ptr_ptr_type->data.pointer.is_volatile,
......@@ -24103,11 +24141,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2410324141 }
2410424142
2410524143 if (instr_is_comptime(ptr_ptr) &&
24106 value_is_comptime(&casted_start->value) &&
24107 (!end || value_is_comptime(&end->value)))
24144 value_is_comptime(casted_start->value) &&
24145 (!end || value_is_comptime(end->value)))
2410824146 {
24109 ConstExprValue *array_val;
24110 ConstExprValue *parent_ptr;
24147 ZigValue *array_val;
24148 ZigValue *parent_ptr;
2411124149 size_t abs_offset;
2411224150 size_t rel_end;
2411324151 bool ptr_is_undef = false;
......@@ -24117,7 +24155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2411724155 if (array_type->id == ZigTypeIdPointer) {
2411824156 ZigType *child_array_type = array_type->data.pointer.child_type;
2411924157 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);
2412124159 if (parent_ptr == nullptr)
2412224160 return ira->codegen->invalid_instruction;
2412324161
......@@ -24136,7 +24174,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2413624174 abs_offset = 0;
2413724175 }
2413824176 } 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);
2414024178 if (array_val == nullptr)
2414124179 return ira->codegen->invalid_instruction;
2414224180 rel_end = array_type->data.array.len;
......@@ -24145,7 +24183,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2414524183 }
2414624184 } else if (array_type->id == ZigTypeIdPointer) {
2414724185 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);
2414924187 if (parent_ptr == nullptr)
2415024188 return ira->codegen->invalid_instruction;
2415124189
......@@ -24193,7 +24231,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2419324231 zig_panic("TODO slice of null ptr");
2419424232 }
2419524233 } 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);
2419724235 if (slice_ptr == nullptr)
2419824236 return ira->codegen->invalid_instruction;
2419924237
......@@ -24208,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2420824246 return ira->codegen->invalid_instruction;
2420924247 }
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
2421324251 switch (parent_ptr->data.x_ptr.special) {
2421424252 case ConstPtrSpecialInvalid:
......@@ -24246,7 +24284,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2424624284 zig_unreachable();
2424724285 }
2424824286
24249 ConstExprValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
24287 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
2425024288 if (!start_val)
2425124289 return ira->codegen->invalid_instruction;
2425224290
......@@ -24258,7 +24296,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2425824296
2425924297 uint64_t end_scalar = rel_end;
2426024298 if (end) {
24261 ConstExprValue *end_val = ir_resolve_const(ira, end, UndefBad);
24299 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
2426224300 if (!end_val)
2426324301 return ira->codegen->invalid_instruction;
2426424302 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
......@@ -24279,17 +24317,17 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2427924317 }
2428024318
2428124319 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
24282 ConstExprValue *out_val = &result->value;
24320 ZigValue *out_val = result->value;
2428324321 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
2428724325 if (array_val) {
2428824326 size_t index = abs_offset + start_scalar;
2428924327 bool is_const = slice_is_const(return_type);
2429024328 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);
2429124329 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;
2429324331 } else if (is_slice(array_type)) {
2429424332 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
2429524333 } else if (array_type->id == ZigTypeIdPointer) {
......@@ -24329,7 +24367,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2432924367 zig_panic("TODO");
2433024368 }
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];
2433324371 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);
2433424372
2433524373 return result;
......@@ -24337,7 +24375,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2433724375
2433824376 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2433924377 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)) {
2434124379 return result_loc;
2434224380 }
2434324381 return ir_build_slice_gen(ira, &instruction->base, return_type,
......@@ -24347,7 +24385,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2434724385static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
2434824386 Error err;
2434924387 IrInstruction *container = instruction->container->child;
24350 if (type_is_invalid(container->value.type))
24388 if (type_is_invalid(container->value->type))
2435124389 return ira->codegen->invalid_instruction;
2435224390 ZigType *container_type = ir_resolve_type(ira, container);
2435324391
......@@ -24448,7 +24486,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
2444824486 TypeStructField *field = container_type->data.structure.fields[member_index];
2444924487
2445024488 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);
2445224490 return result;
2445324491 } else if (container_type->id == ZigTypeIdEnum) {
2445424492 if (member_index >= container_type->data.enumeration.src_field_count) {
......@@ -24460,7 +24498,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
2446024498 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
2446124499
2446224500 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);
2446424502 return result;
2446524503 } else if (container_type->id == ZigTypeIdUnion) {
2446624504 if (member_index >= container_type->data.unionation.src_field_count) {
......@@ -24472,7 +24510,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
2447224510 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2447324511
2447424512 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);
2447624514 return result;
2447724515 } else {
2447824516 ir_add_error(ira, container_type_value,
......@@ -24512,21 +24550,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
2451224550static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
2451324551 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,
2451424552 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;
2451624554 return result;
2451724555}
2451824556
2451924557static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
2452024558 IrInstruction *result = ir_build_return_address(&ira->new_irb,
2452124559 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;
2452324561 return result;
2452424562}
2452524563
2452624564static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
2452724565 IrInstruction *result = ir_build_frame_address(&ira->new_irb,
2452824566 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;
2453024568 return result;
2453124569}
2453224570
......@@ -24542,7 +24580,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst
2454224580 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2454324581
2454424582 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;
2454624584 return result;
2454724585}
2454824586
......@@ -24563,12 +24601,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru
2456324601
2456424602static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {
2456524603 IrInstruction *fn = instruction->fn->child;
24566 if (type_is_invalid(fn->value.type))
24604 if (type_is_invalid(fn->value->type))
2456724605 return ira->codegen->invalid_instruction;
2456824606
24569 if (fn->value.type->id != ZigTypeIdFn) {
24607 if (fn->value->type->id != ZigTypeIdFn) {
2457024608 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)));
2457224610 return ira->codegen->invalid_instruction;
2457324611 }
2457424612
......@@ -24576,7 +24614,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru
2457624614
2457724615 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
2457824616 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;
2458024618 return result;
2458124619}
2458224620
......@@ -24587,11 +24625,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2458724625 // field: []align(@alignOf(Node)) Node,
2458824626 // };
2458924627 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
2459224630 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1);
2459324631 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;
2459524633 lazy_align_of->base.id = LazyValueIdAlignOf;
2459624634
2459724635 lazy_align_of->target_type = instruction->type_value->child;
......@@ -24605,7 +24643,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2460524643 Error err;
2460624644
2460724645 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))
2460924647 return ira->codegen->invalid_instruction;
2461024648
2461124649 ZigType *dest_type = ir_resolve_type(ira, type_value);
......@@ -24619,15 +24657,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2461924657 }
2462024658
2462124659 IrInstruction *op1 = instruction->op1->child;
24622 if (type_is_invalid(op1->value.type))
24660 if (type_is_invalid(op1->value->type))
2462324661 return ira->codegen->invalid_instruction;
2462424662
2462524663 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))
2462724665 return ira->codegen->invalid_instruction;
2462824666
2462924667 IrInstruction *op2 = instruction->op2->child;
24630 if (type_is_invalid(op2->value.type))
24668 if (type_is_invalid(op2->value->type))
2463124669 return ira->codegen->invalid_instruction;
2463224670
2463324671 IrInstruction *casted_op2;
......@@ -24638,20 +24676,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2463824676 } else {
2463924677 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
2464024678 }
24641 if (type_is_invalid(casted_op2->value.type))
24679 if (type_is_invalid(casted_op2->value->type))
2464224680 return ira->codegen->invalid_instruction;
2464324681
2464424682 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))
2464624684 return ira->codegen->invalid_instruction;
2464724685
2464824686 ZigType *expected_ptr_type;
24649 if (result_ptr->value.type->id == ZigTypeIdPointer) {
24687 if (result_ptr->value->type->id == ZigTypeIdPointer) {
2465024688 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)))
2465224690 return ira->codegen->invalid_instruction;
2465324691 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,
2465524693 PtrLenSingle,
2465624694 alignment, 0, 0, false);
2465724695 } else {
......@@ -24659,28 +24697,28 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2465924697 }
2466024698
2466124699 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))
2466324701 return ira->codegen->invalid_instruction;
2466424702
2466524703 if (instr_is_comptime(casted_op1) &&
2466624704 instr_is_comptime(casted_op2) &&
2466724705 instr_is_comptime(casted_result_ptr))
2466824706 {
24669 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
24707 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
2467024708 if (op1_val == nullptr)
2467124709 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);
2467424712 if (op2_val == nullptr)
2467524713 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);
2467824716 if (result_val == nullptr)
2467924717 return ira->codegen->invalid_instruction;
2468024718
2468124719 BigInt *op1_bigint = &op1_val->data.x_bigint;
2468224720 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,
2468424722 casted_result_ptr->source_node);
2468524723 if (pointee_val == nullptr)
2468624724 return ira->codegen->invalid_instruction;
......@@ -24716,12 +24754,12 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2471624754 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,
2471724755 instruction->base.scope, instruction->base.source_node,
2471824756 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;
2472024758 return result;
2472124759}
2472224760
2472324761static 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) {
2472524763 if (float_type->id == ZigTypeIdComptimeFloat) {
2472624764 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
2472724765 &op3->data.x_bigfloat.value);
......@@ -24749,7 +24787,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
2474924787
2475024788static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {
2475124789 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))
2475324791 return ira->codegen->invalid_instruction;
2475424792
2475524793 ZigType *expr_type = ir_resolve_type(ira, type_value);
......@@ -24765,44 +24803,44 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
2476524803 }
2476624804
2476724805 IrInstruction *op1 = instruction->op1->child;
24768 if (type_is_invalid(op1->value.type))
24806 if (type_is_invalid(op1->value->type))
2476924807 return ira->codegen->invalid_instruction;
2477024808
2477124809 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))
2477324811 return ira->codegen->invalid_instruction;
2477424812
2477524813 IrInstruction *op2 = instruction->op2->child;
24776 if (type_is_invalid(op2->value.type))
24814 if (type_is_invalid(op2->value->type))
2477724815 return ira->codegen->invalid_instruction;
2477824816
2477924817 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))
2478124819 return ira->codegen->invalid_instruction;
2478224820
2478324821 IrInstruction *op3 = instruction->op3->child;
24784 if (type_is_invalid(op3->value.type))
24822 if (type_is_invalid(op3->value->type))
2478524823 return ira->codegen->invalid_instruction;
2478624824
2478724825 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))
2478924827 return ira->codegen->invalid_instruction;
2479024828
2479124829 if (instr_is_comptime(casted_op1) &&
2479224830 instr_is_comptime(casted_op2) &&
2479324831 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);
2479524833 if (!op1_const)
2479624834 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);
2479824836 if (!op2_const)
2479924837 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);
2480124839 if (!op3_const)
2480224840 return ira->codegen->invalid_instruction;
2480324841
2480424842 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
24805 ConstExprValue *out_val = &result->value;
24843 ZigValue *out_val = result->value;
2480624844
2480724845 if (expr_type->id == ZigTypeIdVector) {
2480824846 expand_undef_array(ira->codegen, op1_const);
......@@ -24812,10 +24850,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
2481224850 expand_undef_array(ira->codegen, out_val);
2481324851 size_t len = expr_type->data.vector.len;
2481424852 for (size_t i = 0; i < len; i += 1) {
24815 ConstExprValue *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];
24817 ConstExprValue *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];
24853 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
24854 ZigValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i];
24855 ZigValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i];
24856 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
2481924857 assert(float_operand_op1->type == float_type);
2482024858 assert(float_operand_op2->type == float_type);
2482124859 assert(float_operand_op3->type == float_type);
......@@ -24835,13 +24873,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
2483524873 IrInstruction *result = ir_build_mul_add(&ira->new_irb,
2483624874 instruction->base.scope, instruction->base.source_node,
2483724875 type_value, casted_op1, casted_op2, casted_op3);
24838 result->value.type = expr_type;
24876 result->value->type = expr_type;
2483924877 return result;
2484024878}
2484124879
2484224880static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {
2484324881 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))
2484524883 return ira->codegen->invalid_instruction;
2484624884
2484724885 IrInstruction *value;
......@@ -24851,12 +24889,12 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
2485124889 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);
2485224890 }
2485324891
24854 ZigType *type_entry = value->value.type;
24892 ZigType *type_entry = value->value->type;
2485524893 if (type_is_invalid(type_entry))
2485624894 return ira->codegen->invalid_instruction;
2485724895 if (type_entry->id == ZigTypeIdErrorUnion) {
2485824896 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);
2486024898 if (!err_union_val)
2486124899 return ira->codegen->invalid_instruction;
2486224900
......@@ -24890,7 +24928,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
2489024928static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
2489124929 IrInstruction *base_ptr, bool initializing)
2489224930{
24893 ZigType *ptr_type = base_ptr->value.type;
24931 ZigType *ptr_type = base_ptr->value->type;
2489424932
2489524933 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
2489624934 assert(ptr_type->id == ZigTypeIdPointer);
......@@ -24911,20 +24949,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2491124949 ptr_type->data.pointer.explicit_alignment, 0, 0, false);
2491224950
2491324951 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);
2491524953 if (!ptr_val)
2491624954 return ira->codegen->invalid_instruction;
2491724955 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2491824956 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
2491924957 {
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);
2492124959 if (err_union_val == nullptr)
2492224960 return ira->codegen->invalid_instruction;
2492324961
2492424962 if (initializing && err_union_val->special == ConstValSpecialUndef) {
24925 ConstExprValue *vals = create_const_vals(2);
24926 ConstExprValue *err_set_val = &vals[0];
24927 ConstExprValue *payload_val = &vals[1];
24963 ZigValue *vals = create_const_vals(2);
24964 ZigValue *err_set_val = &vals[0];
24965 ZigValue *payload_val = &vals[1];
2492824966
2492924967 err_set_val->special = ConstValSpecialUndef;
2493024968 err_set_val->type = err_set_type;
......@@ -24946,12 +24984,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2494624984 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
2494724985 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,
2494824986 source_instr->source_node, base_ptr);
24949 result->value.type = result_type;
24950 result->value.special = ConstValSpecialStatic;
24987 result->value->type = result_type;
24988 result->value->special = ConstValSpecialStatic;
2495124989 } else {
2495224990 result = ir_const(ira, source_instr, result_type);
2495324991 }
24954 ConstExprValue *const_val = &result->value;
24992 ZigValue *const_val = result->value;
2495524993 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;
2495624994 const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val;
2495724995 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 *
2496124999
2496225000 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,
2496325001 source_instr->scope, source_instr->source_node, base_ptr);
24964 result->value.type = result_type;
25002 result->value->type = result_type;
2496525003 return result;
2496625004}
2496725005
......@@ -24969,7 +25007,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
2496925007 IrInstructionUnwrapErrCode *instruction)
2497025008{
2497125009 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))
2497325011 return ira->codegen->invalid_instruction;
2497425012 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);
2497525013}
......@@ -24977,7 +25015,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
2497725015static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
2497825016 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
2497925017{
24980 ZigType *ptr_type = base_ptr->value.type;
25018 ZigType *ptr_type = base_ptr->value->type;
2498125019
2498225020 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
2498325021 assert(ptr_type->id == ZigTypeIdPointer);
......@@ -25000,17 +25038,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2500025038 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
2500125039 PtrLenSingle, 0, 0, 0, false);
2500225040 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);
2500425042 if (!ptr_val)
2500525043 return ira->codegen->invalid_instruction;
2500625044 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);
2500825046 if (err_union_val == nullptr)
2500925047 return ira->codegen->invalid_instruction;
2501025048 if (initializing && err_union_val->special == ConstValSpecialUndef) {
25011 ConstExprValue *vals = create_const_vals(2);
25012 ConstExprValue *err_set_val = &vals[0];
25013 ConstExprValue *payload_val = &vals[1];
25049 ZigValue *vals = create_const_vals(2);
25050 ZigValue *err_set_val = &vals[0];
25051 ZigValue *payload_val = &vals[1];
2501425052
2501525053 err_set_val->special = ConstValSpecialStatic;
2501625054 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
2503625074 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
2503725075 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
2503825076 source_instr->source_node, base_ptr, safety_check_on, initializing);
25039 result->value.type = result_type;
25040 result->value.special = ConstValSpecialStatic;
25077 result->value->type = result_type;
25078 result->value->special = ConstValSpecialStatic;
2504125079 } else {
2504225080 result = ir_const(ira, source_instr, result_type);
2504325081 }
25044 result->value.data.x_ptr.special = ConstPtrSpecialRef;
25045 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;
25082 result->value->data.x_ptr.special = ConstPtrSpecialRef;
25083 result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;
25084 result->value->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
2504725085 return result;
2504825086 }
2504925087 }
......@@ -25051,7 +25089,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2505125089
2505225090 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
2505325091 source_instr->source_node, base_ptr, safety_check_on, initializing);
25054 result->value.type = result_type;
25092 result->value->type = result_type;
2505525093 return result;
2505625094}
2505725095
......@@ -25060,7 +25098,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
2506025098{
2506125099 assert(instruction->value->child);
2506225100 IrInstruction *value = instruction->value->child;
25063 if (type_is_invalid(value->value.type))
25101 if (type_is_invalid(value->value->type))
2506425102 return ira->codegen->invalid_instruction;
2506525103
2506625104 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
2507125109 assert(proto_node->type == NodeTypeFnProto);
2507225110
2507325111 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
25074 result->value.special = ConstValSpecialLazy;
25112 result->value->special = ConstValSpecialLazy;
2507525113
2507625114 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1);
2507725115 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;
2507925117 lazy_fn_type->base.id = LazyValueIdFnType;
2508025118
2508125119 if (proto_node->data.fn_proto.auto_err_set) {
......@@ -25110,7 +25148,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2511025148 }
2511125149
2511225150 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))
2511425152 return ira->codegen->invalid_instruction;
2511525153 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
2511625154 return ira->codegen->invalid_instruction;
......@@ -25132,7 +25170,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2513225170
2513325171static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
2513425172 IrInstruction *value = instruction->value->child;
25135 if (type_is_invalid(value->value.type))
25173 if (type_is_invalid(value->value->type))
2513625174 return ira->codegen->invalid_instruction;
2513725175
2513825176 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,
2514225180 IrInstructionCheckSwitchProngs *instruction)
2514325181{
2514425182 IrInstruction *target_value = instruction->target_value->child;
25145 ZigType *switch_type = target_value->value.type;
25183 ZigType *switch_type = target_value->value->type;
2514625184 if (type_is_invalid(switch_type))
2514725185 return ira->codegen->invalid_instruction;
2514825186
......@@ -25154,25 +25192,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2515425192 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2515525193
2515625194 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))
2515825196 return ira->codegen->invalid_instruction;
2515925197 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))
2516125199 return ira->codegen->invalid_instruction;
2516225200
2516325201 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))
2516525203 return ira->codegen->invalid_instruction;
2516625204 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))
2516825206 return ira->codegen->invalid_instruction;
2516925207
2517025208 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);
2517425212 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
2517725215 BigInt field_index;
2517825216 bigint_init_bigint(&field_index, &start_index);
......@@ -25218,24 +25256,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2521825256 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2521925257
2522025258 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))
2522225260 return ira->codegen->invalid_instruction;
2522325261 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))
2522525263 return ira->codegen->invalid_instruction;
2522625264
2522725265 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))
2522925267 return ira->codegen->invalid_instruction;
2523025268 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))
2523225270 return ira->codegen->invalid_instruction;
2523325271
25234 ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base);
25235 uint32_t start_index = start_value->value.data.x_err_set->value;
25272 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
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);
25238 uint32_t end_index = end_value->value.data.x_err_set->value;
25275 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
25276 uint32_t end_index = end_value->value->data.x_err_set->value;
2523925277
2524025278 if (start_index != end_index) {
2524125279 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,
2527625314 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2527725315
2527825316 IrInstruction *start_value = range->start->child;
25279 if (type_is_invalid(start_value->value.type))
25317 if (type_is_invalid(start_value->value->type))
2528025318 return ira->codegen->invalid_instruction;
2528125319 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))
2528325321 return ira->codegen->invalid_instruction;
2528425322
2528525323 IrInstruction *end_value = range->end->child;
25286 if (type_is_invalid(end_value->value.type))
25324 if (type_is_invalid(end_value->value->type))
2528725325 return ira->codegen->invalid_instruction;
2528825326 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))
2529025328 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);
2529325331 if (!start_val)
2529425332 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);
2529725335 if (!end_val)
2529825336 return ira->codegen->invalid_instruction;
2529925337
......@@ -25326,10 +25364,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2532625364 IrInstruction *value = range->start->child;
2532725365
2532825366 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))
2533025368 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);
2533325371 if (!const_expr_val)
2533425372 return ira->codegen->invalid_instruction;
2533525373
......@@ -25362,7 +25400,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *
2536225400 IrInstructionCheckStatementIsVoid *instruction)
2536325401{
2536425402 IrInstruction *statement_value = instruction->statement_value->child;
25365 ZigType *statement_type = statement_value->value.type;
25403 ZigType *statement_type = statement_value->value->type;
2536625404 if (type_is_invalid(statement_type))
2536725405 return ira->codegen->invalid_instruction;
2536825406
......@@ -25375,7 +25413,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *
2537525413
2537625414static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
2537725415 IrInstruction *msg = instruction->msg->child;
25378 if (type_is_invalid(msg->value.type))
25416 if (type_is_invalid(msg->value->type))
2537925417 return ir_unreach_error(ira);
2538025418
2538125419 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
......@@ -25387,7 +25425,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction
2538725425 true, false, PtrLenUnknown, 0, 0, 0, false);
2538825426 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
2538925427 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))
2539125429 return ir_unreach_error(ira);
2539225430
2539325431 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
2539825436static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
2539925437 Error err;
2540025438
25401 ZigType *target_type = target->value.type;
25439 ZigType *target_type = target->value->type;
2540225440 assert(!type_is_invalid(target_type));
2540325441
2540425442 ZigType *result_type;
......@@ -25443,7 +25481,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2544325481 }
2544425482
2544525483 if (instr_is_comptime(target)) {
25446 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
25484 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2544725485 if (!val)
2544825486 return ira->codegen->invalid_instruction;
2544925487
......@@ -25457,8 +25495,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2545725495 }
2545825496
2545925497 IrInstruction *result = ir_const(ira, target, result_type);
25460 copy_const_val(&result->value, val, true);
25461 result->value.type = result_type;
25498 copy_const_val(result->value, val, true);
25499 result->value->type = result_type;
2546225500 return result;
2546325501 }
2546425502
......@@ -25468,7 +25506,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2546825506 } else {
2546925507 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);
2547025508 }
25471 result->value.type = result_type;
25509 result->value->type = result_type;
2547225510 return result;
2547325511}
2547425512
......@@ -25477,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2547725515{
2547825516 Error err;
2547925517
25480 ZigType *src_type = ptr->value.type;
25518 ZigType *src_type = ptr->value->type;
2548125519 assert(!type_is_invalid(src_type));
2548225520
2548325521 if (src_type == dest_type) {
......@@ -25515,7 +25553,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2551525553 if (instr_is_comptime(ptr)) {
2551625554 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);
2551725555 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);
2551925557 if (!val)
2552025558 return ira->codegen->invalid_instruction;
2552125559
......@@ -25531,7 +25569,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2553125569 }
2553225570
2553325571 IrInstruction *result;
25534 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {
25572 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
2553525573 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2553625574
2553725575 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
......@@ -25539,8 +25577,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2553925577 } else {
2554025578 result = ir_const(ira, source_instr, dest_type);
2554125579 }
25542 copy_const_val(&result->value, val, true);
25543 result->value.type = dest_type;
25580 copy_const_val(result->value, val, true);
25581 result->value->type = dest_type;
2554425582
2554525583 // Keep the bigger alignment, it can only help-
2554625584 // unless the target is zero bits.
......@@ -25584,7 +25622,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2558425622 IrInstruction *result;
2558525623 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
2558625624 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))
2558825626 return ira->codegen->invalid_instruction;
2558925627 } else {
2559025628 result = casted_ptr;
......@@ -25599,7 +25637,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct
2559925637 return ira->codegen->invalid_instruction;
2560025638
2560125639 IrInstruction *ptr = instruction->ptr->child;
25602 ZigType *src_type = ptr->value.type;
25640 ZigType *src_type = ptr->value->type;
2560325641 if (type_is_invalid(src_type))
2560425642 return ira->codegen->invalid_instruction;
2560525643
......@@ -25607,18 +25645,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct
2560725645 instruction->safety_check_on);
2560825646}
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) {
2561125649 size_t buf_i = 0;
2561225650 // TODO optimize the buf case
2561325651 expand_undef_array(codegen, val);
2561425652 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];
2561625654 buf_write_value_bytes(codegen, &buf[buf_i], elem);
2561725655 buf_i += type_size(codegen, elem->type);
2561825656 }
2561925657}
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) {
2562225660 if (val->special == ConstValSpecialUndef) {
2562325661 expand_undef_struct(codegen, val);
2562425662 val->special = ConstValSpecialStatic;
......@@ -25679,7 +25717,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2567925717 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
2568025718 if (struct_field->gen_index == SIZE_MAX)
2568125719 continue;
25682 ConstExprValue *field_val = val->data.x_struct.fields[field_i];
25720 ZigValue *field_val = val->data.x_struct.fields[field_i];
2568325721 size_t offset = struct_field->offset;
2568425722 buf_write_value_bytes(codegen, buf + offset, field_val);
2568525723 }
......@@ -25754,7 +25792,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2575425792}
2575525793
2575625794static 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)
2575825796{
2575925797 Error err;
2576025798 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
2576325801 case ConstArraySpecialNone:
2576425802 val->data.x_array.data.s_none.elements = create_const_vals(len);
2576525803 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];
2576725805 elem->special = ConstValSpecialStatic;
2576825806 elem->type = elem_type;
2576925807 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
2577825816 zig_unreachable();
2577925817}
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) {
2578225820 Error err;
2578325821 src_assert(val->special == ConstValSpecialStatic, source_node);
2578425822 switch (val->type->id) {
......@@ -25850,7 +25888,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2585025888 size_t src_field_count = val->type->data.structure.src_field_count;
2585125889 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
2585225890 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];
2585425892 field_val->special = ConstValSpecialStatic;
2585525893 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
2585625894 field_val->type = struct_field->type_entry;
......@@ -25887,7 +25925,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2588725925 src_assert(field->gen_index != SIZE_MAX, source_node);
2588825926 if (field->gen_index != gen_i)
2588925927 break;
25890 ConstExprValue *field_val = val->data.x_struct.fields[src_i];
25928 ZigValue *field_val = val->data.x_struct.fields[src_i];
2589125929 field_val->special = ConstValSpecialStatic;
2589225930 field_val->type = field->type_entry;
2589325931 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_
2594125979{
2594225980 Error err;
2594325981
25944 ZigType *src_type = value->value.type;
25982 ZigType *src_type = value->value->type;
2594525983 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);
2594625984 ir_assert(type_can_bit_cast(src_type), source_instr);
2594725985 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_
2597526013 }
2597626014
2597726015 if (instr_is_comptime(value)) {
25978 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
26016 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2597926017 if (!val)
2598026018 return ira->codegen->invalid_instruction;
2598126019
2598226020 IrInstruction *result = ir_const(ira, source_instr, dest_type);
2598326021 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
2598426022 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)))
2598626024 return ira->codegen->invalid_instruction;
2598726025 return result;
2598826026 }
......@@ -25997,11 +26035,11 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
2599726035 ir_assert(type_has_bits(ptr_type), source_instr);
2599826036
2599926037 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))
2600126039 return ira->codegen->invalid_instruction;
2600226040
2600326041 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);
2600526043 if (!val)
2600626044 return ira->codegen->invalid_instruction;
2600726045
......@@ -26013,15 +26051,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
2601326051 }
2601426052
2601526053 IrInstruction *result = ir_const(ira, source_instr, ptr_type);
26016 result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
26017 result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;
26018 result->value.data.x_ptr.data.hard_coded_addr.addr = addr;
26054 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
26055 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
26056 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
2601926057 return result;
2602026058 }
2602126059
2602226060 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,
2602326061 source_instr->source_node, nullptr, casted_int);
26024 result->value.type = ptr_type;
26062 result->value->type = ptr_type;
2602526063 return result;
2602626064}
2602726065
......@@ -26048,7 +26086,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru
2604826086
2604926087
2605026088 IrInstruction *target = instruction->target->child;
26051 if (type_is_invalid(target->value.type))
26089 if (type_is_invalid(target->value->type))
2605226090 return ira->codegen->invalid_instruction;
2605326091
2605426092 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,
2605826096 IrInstructionDeclRef *instruction)
2605926097{
2606026098 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)) {
2606226100 return ira->codegen->invalid_instruction;
2606326101 }
2606426102
......@@ -26072,51 +26110,51 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2607226110static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
2607326111 Error err;
2607426112 IrInstruction *target = instruction->target->child;
26075 if (type_is_invalid(target->value.type))
26113 if (type_is_invalid(target->value->type))
2607626114 return ira->codegen->invalid_instruction;
2607726115
2607826116 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2607926117
2608026118 // 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) {
2608226120 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)));
2608426122 return ira->codegen->invalid_instruction;
2608526123 }
2608626124
26087 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))
26125 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
2608826126 return ira->codegen->invalid_instruction;
26089 if (!type_has_bits(target->value.type)) {
26127 if (!type_has_bits(target->value->type)) {
2609026128 ir_add_error(ira, target,
2609126129 buf_sprintf("pointer to size 0 type has no address"));
2609226130 return ira->codegen->invalid_instruction;
2609326131 }
2609426132
2609526133 if (instr_is_comptime(target)) {
26096 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
26134 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2609726135 if (!val)
2609826136 return ira->codegen->invalid_instruction;
2609926137 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
2610026138 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);
26102 result->value.type = usize;
26139 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
26140 result->value->type = usize;
2610326141 return result;
2610426142 }
2610526143 }
2610626144
2610726145 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,
2610826146 instruction->base.source_node, target);
26109 result->value.type = usize;
26147 result->value->type = usize;
2611026148 return result;
2611126149}
2611226150
2611326151static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
2611426152 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
26115 result->value.special = ConstValSpecialLazy;
26153 result->value->special = ConstValSpecialLazy;
2611626154
2611726155 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1);
2611826156 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;
2612026158 lazy_ptr_type->base.id = LazyValueIdPtrType;
2612126159
2612226160 if (instruction->sentinel != nullptr) {
......@@ -26147,15 +26185,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2614726185
2614826186static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
2614926187 IrInstruction *target = instruction->target->child;
26150 if (type_is_invalid(target->value.type))
26188 if (type_is_invalid(target->value->type))
2615126189 return ira->codegen->invalid_instruction;
2615226190
2615326191 ZigType *elem_type = nullptr;
26154 if (is_slice(target->value.type)) {
26155 ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;
26192 if (is_slice(target->value->type)) {
26193 ZigType *slice_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2615626194 elem_type = slice_ptr_type->data.pointer.child_type;
26157 } else if (target->value.type->id == ZigTypeIdPointer) {
26158 elem_type = target->value.type->data.pointer.child_type;
26195 } else if (target->value->type->id == ZigTypeIdPointer) {
26196 elem_type = target->value->type->data.pointer.child_type;
2615926197 }
2616026198
2616126199 uint32_t align_bytes;
......@@ -26164,7 +26202,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
2616426202 return ira->codegen->invalid_instruction;
2616526203
2616626204 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))
2616826206 return ira->codegen->invalid_instruction;
2616926207
2617026208 return result;
......@@ -26350,13 +26388,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2635026388 return ira->codegen->invalid_instruction;
2635126389
2635226390 IrInstruction *ptr_inst = instruction->ptr->child;
26353 if (type_is_invalid(ptr_inst->value.type))
26391 if (type_is_invalid(ptr_inst->value->type))
2635426392 return ira->codegen->invalid_instruction;
2635526393
2635626394 // TODO let this be volatile
2635726395 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2635826396 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))
2636026398 return ira->codegen->invalid_instruction;
2636126399
2636226400 AtomicRmwOp op;
......@@ -26375,11 +26413,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2637526413 }
2637626414
2637726415 IrInstruction *operand = instruction->operand->child;
26378 if (type_is_invalid(operand->value.type))
26416 if (type_is_invalid(operand->value->type))
2637926417 return ira->codegen->invalid_instruction;
2638026418
2638126419 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))
2638326421 return ira->codegen->invalid_instruction;
2638426422
2638526423 AtomicOrder ordering;
......@@ -26395,7 +26433,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2639526433 }
2639626434 }
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)
2639926437 {
2640026438 zig_panic("TODO compile-time execution of atomicRmw");
2640126439 }
......@@ -26403,7 +26441,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2640326441 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,
2640426442 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,
2640526443 op, ordering);
26406 result->value.type = operand_type;
26444 result->value->type = operand_type;
2640726445 return result;
2640826446}
2640926447
......@@ -26413,12 +26451,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2641326451 return ira->codegen->invalid_instruction;
2641426452
2641526453 IrInstruction *ptr_inst = instruction->ptr->child;
26416 if (type_is_invalid(ptr_inst->value.type))
26454 if (type_is_invalid(ptr_inst->value->type))
2641726455 return ira->codegen->invalid_instruction;
2641826456
2641926457 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
2642026458 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))
2642226460 return ira->codegen->invalid_instruction;
2642326461
2642426462 AtomicOrder ordering;
......@@ -26438,13 +26476,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2643826476
2643926477 if (instr_is_comptime(casted_ptr)) {
2644026478 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);
2644226480 return result;
2644326481 }
2644426482
2644526483 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,
2644626484 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
26447 result->value.type = operand_type;
26485 result->value->type = operand_type;
2644826486 return result;
2644926487}
2645026488
......@@ -26454,20 +26492,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
2645426492 return ira->codegen->invalid_instruction;
2645526493
2645626494 IrInstruction *ptr_inst = instruction->ptr->child;
26457 if (type_is_invalid(ptr_inst->value.type))
26495 if (type_is_invalid(ptr_inst->value->type))
2645826496 return ira->codegen->invalid_instruction;
2645926497
2646026498 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2646126499 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))
2646326501 return ira->codegen->invalid_instruction;
2646426502
2646526503 IrInstruction *value = instruction->value->child;
26466 if (type_is_invalid(value->value.type))
26504 if (type_is_invalid(value->value->type))
2646726505 return ira->codegen->invalid_instruction;
2646826506
2646926507 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))
2647126509 return ira->codegen->invalid_instruction;
2647226510
2647326511
......@@ -26488,25 +26526,25 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
2648826526
2648926527 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
2649026528 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;
2649226530 return result;
2649326531 }
2649426532
2649526533 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,
2649626534 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;
2649826536 return result;
2649926537}
2650026538
2650126539static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
2650226540 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
2650326541 instruction->base.source_node);
26504 result->value.type = ira->codegen->builtin_types.entry_void;
26542 result->value->type = ira->codegen->builtin_types.entry_void;
2650526543 return result;
2650626544}
2650726545
2650826546static 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) {
2651026548 assert(ira && source_instr && float_type && out_val && op);
2651126549 assert(float_type->id == ZigTypeIdFloat ||
2651226550 float_type->id == ZigTypeIdComptimeFloat);
......@@ -26687,7 +26725,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr,
2668726725
2668826726static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {
2668926727 IrInstruction *type = instruction->type->child;
26690 if (type_is_invalid(type->value.type))
26728 if (type_is_invalid(type->value->type))
2669126729 return ira->codegen->invalid_instruction;
2669226730
2669326731 ZigType *expr_type = ir_resolve_type(ira, type);
......@@ -26702,11 +26740,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2670226740 }
2670326741
2670426742 IrInstruction *op1 = instruction->op1->child;
26705 if (type_is_invalid(op1->value.type))
26743 if (type_is_invalid(op1->value->type))
2670626744 return ira->codegen->invalid_instruction;
2670726745
2670826746 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))
2671026748 return ira->codegen->invalid_instruction;
2671126749
2671226750 if (instr_is_comptime(casted_op1)) {
......@@ -26719,12 +26757,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2671926757 return ira->codegen->invalid_instruction;
2672026758 }
2672126759
26722 ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
26760 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
2672326761 if (!op1_const)
2672426762 return ira->codegen->invalid_instruction;
2672526763
2672626764 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
26727 ConstExprValue *out_val = &result->value;
26765 ZigValue *out_val = result->value;
2672826766
2672926767 if (expr_type->id == ZigTypeIdVector) {
2673026768 expand_undef_array(ira->codegen, op1_const);
......@@ -26732,8 +26770,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2673226770 expand_undef_array(ira->codegen, out_val);
2673326771 size_t len = expr_type->data.vector.len;
2673426772 for (size_t i = 0; i < len; i += 1) {
26735 ConstExprValue *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];
26773 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
26774 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
2673726775 assert(float_operand_op1->type == float_type);
2673826776 assert(float_out_val->type == float_type);
2673926777 ir_eval_float_op(ira, instruction, float_type,
......@@ -26752,7 +26790,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2675226790
2675326791 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,
2675426792 instruction->base.source_node, nullptr, casted_op1, instruction->op);
26755 result->value.type = expr_type;
26793 result->value->type = expr_type;
2675626794 return result;
2675726795}
2675826796
......@@ -26764,16 +26802,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2676426802 return ira->codegen->invalid_instruction;
2676526803
2676626804 IrInstruction *uncasted_op = instruction->op->child;
26767 if (type_is_invalid(uncasted_op->value.type))
26805 if (type_is_invalid(uncasted_op->value->type))
2676826806 return ira->codegen->invalid_instruction;
2676926807
2677026808 uint32_t vector_len; // UINT32_MAX means not a vector
26771 if (uncasted_op->value.type->id == ZigTypeIdArray &&
26772 is_valid_vector_elem_type(uncasted_op->value.type->data.array.child_type))
26809 if (uncasted_op->value->type->id == ZigTypeIdArray &&
26810 is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type))
2677326811 {
26774 vector_len = uncasted_op->value.type->data.array.len;
26775 } else if (uncasted_op->value.type->id == ZigTypeIdVector) {
26776 vector_len = uncasted_op->value.type->data.vector.len;
26812 vector_len = uncasted_op->value->type->data.array.len;
26813 } else if (uncasted_op->value->type->id == ZigTypeIdVector) {
26814 vector_len = uncasted_op->value->type->data.vector.len;
2677726815 } else {
2677826816 vector_len = UINT32_MAX;
2677926817 }
......@@ -26782,7 +26820,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2678226820 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2678326821
2678426822 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))
2678626824 return ira->codegen->invalid_instruction;
2678726825
2678826826 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
2679626834 }
2679726835
2679826836 if (instr_is_comptime(op)) {
26799 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);
26837 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2680026838 if (val == nullptr)
2680126839 return ira->codegen->invalid_instruction;
2680226840 if (val->special == ConstValSpecialUndef)
......@@ -26807,28 +26845,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2680726845 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
2680826846 if (is_vector) {
2680926847 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);
2681126849 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];
2681326851 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
2681426852 op_elem_val, UndefOk)))
2681526853 {
2681626854 return ira->codegen->invalid_instruction;
2681726855 }
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];
2681926857 result_elem_val->type = int_type;
2682026858 result_elem_val->special = op_elem_val->special;
2682126859 if (op_elem_val->special == ConstValSpecialUndef)
2682226860 continue;
2682326861
2682426862 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,
2682626864 buf, int_type->data.integral.bit_count, false,
2682726865 int_type->data.integral.is_signed);
2682826866 }
2682926867 } else {
2683026868 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,
2683226870 int_type->data.integral.is_signed);
2683326871 }
2683426872 free(buf);
......@@ -26837,7 +26875,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2683726875
2683826876 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,
2683926877 instruction->base.source_node, nullptr, op);
26840 result->value.type = op_type;
26878 result->value->type = op_type;
2684126879 return result;
2684226880}
2684326881
......@@ -26847,17 +26885,17 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2684726885 return ira->codegen->invalid_instruction;
2684826886
2684926887 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))
2685126889 return ira->codegen->invalid_instruction;
2685226890
2685326891 if (int_type->data.integral.bit_count == 0) {
2685426892 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);
2685626894 return result;
2685726895 }
2685826896
2685926897 if (instr_is_comptime(op)) {
26860 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);
26898 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2686126899 if (val == nullptr)
2686226900 return ira->codegen->invalid_instruction;
2686326901 if (val->special == ConstValSpecialUndef)
......@@ -26881,7 +26919,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2688126919 }
2688226920 }
2688326921
26884 bigint_read_twos_complement(&result->value.data.x_bigint,
26922 bigint_read_twos_complement(&result->value->data.x_bigint,
2688526923 result_buf,
2688626924 int_type->data.integral.bit_count,
2688726925 ira->codegen->is_big_endian,
......@@ -26892,14 +26930,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2689226930
2689326931 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,
2689426932 instruction->base.source_node, nullptr, op);
26895 result->value.type = int_type;
26933 result->value->type = int_type;
2689626934 return result;
2689726935}
2689826936
2689926937
2690026938static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
2690126939 IrInstruction *target = instruction->target->child;
26902 if (type_is_invalid(target->value.type))
26940 if (type_is_invalid(target->value->type))
2690326941 return ira->codegen->invalid_instruction;
2690426942
2690526943 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
2692426962 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2692526963
2692626964 IrInstruction *target = instruction->target->child;
26927 if (type_is_invalid(target->value.type))
26965 if (type_is_invalid(target->value->type))
2692826966 return ira->codegen->invalid_instruction;
2692926967
2693026968 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))
2693226970 return ira->codegen->invalid_instruction;
2693326971
2693426972 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
2699527033
2699627034static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {
2699727035 IrInstruction *value = instruction->value->child;
26998 if (type_is_invalid(value->value.type))
27036 if (type_is_invalid(value->value->type))
2699927037 return ira->codegen->invalid_instruction;
2700027038
2700127039 bool was_written = instruction->result_loc->written;
2700227040 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);
2700427042 if (result_loc != nullptr) {
27005 if (type_is_invalid(result_loc->value.type))
27043 if (type_is_invalid(result_loc->value->type))
2700627044 return ira->codegen->invalid_instruction;
27007 if (result_loc->value.type->id == ZigTypeIdUnreachable)
27045 if (result_loc->value->type->id == ZigTypeIdUnreachable)
2700827046 return result_loc;
2700927047
2701027048 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
2701127049 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,
2701227050 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)) {
2701427052 return ira->codegen->invalid_instruction;
2701527053 }
2701627054 }
2701727055
27018 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer &&
27056 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer &&
2701927057 instruction->result_loc->id != ResultLocIdPeer)
2702027058 {
2702127059 if (instr_is_comptime(value)) {
27022 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
27060 result_loc->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
2702327061 } else {
27024 result_loc->value.special = ConstValSpecialRuntime;
27062 result_loc->value->special = ConstValSpecialRuntime;
2702527063 }
2702627064 }
2702727065 }
......@@ -27031,12 +27069,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2703127069
2703227070static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
2703327071 IrInstruction *operand = instruction->operand->child;
27034 if (type_is_invalid(operand->value.type))
27072 if (type_is_invalid(operand->value->type))
2703527073 return operand;
2703627074
2703727075 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
27038 &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)))
27076 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);
27077 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
2704027078 return result_loc;
2704127079
2704227080 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
......@@ -27051,12 +27089,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
2705127089
2705227090static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
2705327091 IrInstruction *operand = instruction->operand->child;
27054 if (type_is_invalid(operand->value.type))
27092 if (type_is_invalid(operand->value->type))
2705527093 return operand;
2705627094
2705727095 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
27058 &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)))
27096 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);
27097 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
2706027098 return result_loc;
2706127099
2706227100 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
2708427122 return ira->codegen->invalid_instruction;
2708527123
2708627124 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))
2708827126 return ira->codegen->invalid_instruction;
2708927127
2709027128 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))
2709227130 return ira->codegen->invalid_instruction;
2709327131
2709427132 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,
2710527143 IrInstructionSuspendFinish *instruction)
2710627144{
2710727145 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))
2710927147 return ira->codegen->invalid_instruction;
2711027148 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);
2711127149 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);
......@@ -27123,44 +27161,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
2712327161static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,
2712427162 IrInstruction *frame_ptr, ZigFn **target_fn)
2712527163{
27126 if (type_is_invalid(frame_ptr->value.type))
27164 if (type_is_invalid(frame_ptr->value->type))
2712727165 return ira->codegen->invalid_instruction;
2712827166
2712927167 *target_fn = nullptr;
2713027168
2713127169 ZigType *result_type;
2713227170 IrInstruction *frame;
27133 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
27134 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
27135 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27171 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
27172 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
27173 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2713627174 {
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;
2713827176 result_type = func->type_entry->data.fn.fn_type_id.return_type;
2713927177 *target_fn = func;
2714027178 frame = frame_ptr;
2714127179 } else {
2714227180 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);
27143 if (frame->value.type->id == ZigTypeIdPointer &&
27144 frame->value.type->data.pointer.ptr_len == PtrLenSingle &&
27145 frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27181 if (frame->value->type->id == ZigTypeIdPointer &&
27182 frame->value->type->data.pointer.ptr_len == PtrLenSingle &&
27183 frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2714627184 {
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;
2714827186 result_type = func->type_entry->data.fn.fn_type_id.return_type;
2714927187 *target_fn = func;
27150 } else if (frame->value.type->id != ZigTypeIdAnyFrame ||
27151 frame->value.type->data.any_frame.result_type == nullptr)
27188 } else if (frame->value->type->id != ZigTypeIdAnyFrame ||
27189 frame->value->type->data.any_frame.result_type == nullptr)
2715227190 {
2715327191 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)));
2715527193 return ira->codegen->invalid_instruction;
2715627194 } else {
27157 result_type = frame->value.type->data.any_frame.result_type;
27195 result_type = frame->value->type->data.any_frame.result_type;
2715827196 }
2715927197 }
2716027198
2716127199 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
2716227200 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))
2716427202 return ira->codegen->invalid_instruction;
2716527203
2716627204 return casted_frame;
......@@ -27168,14 +27206,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2716827206
2716927207static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {
2717027208 IrInstruction *operand = instruction->frame->child;
27171 if (type_is_invalid(operand->value.type))
27209 if (type_is_invalid(operand->value->type))
2717227210 return ira->codegen->invalid_instruction;
2717327211 ZigFn *target_fn;
2717427212 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))
2717627214 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
2718027218 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
2718127219 ir_assert(fn_entry != nullptr, &instruction->base);
......@@ -27195,7 +27233,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2719527233 if (type_has_bits(result_type)) {
2719627234 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2719727235 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)))
2719927237 return result_loc;
2720027238 } else {
2720127239 result_loc = nullptr;
......@@ -27209,13 +27247,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2720927247
2721027248static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {
2721127249 IrInstruction *frame_ptr = instruction->frame->child;
27212 if (type_is_invalid(frame_ptr->value.type))
27250 if (type_is_invalid(frame_ptr->value->type))
2721327251 return ira->codegen->invalid_instruction;
2721427252
2721527253 IrInstruction *frame;
27216 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
27217 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
27218 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
27254 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
27255 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
27256 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2721927257 {
2722027258 frame = frame_ptr;
2722127259 } else {
......@@ -27224,7 +27262,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio
2722427262
2722527263 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
2722627264 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))
2722827266 return ira->codegen->invalid_instruction;
2722927267
2723027268 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
2723527273 return ir_const_void(ira, &instruction->base);
2723627274
2723727275 IrInstruction *operand = instruction->operand->child;
27238 if (type_is_invalid(operand->value.type))
27276 if (type_is_invalid(operand->value->type))
2723927277 return ira->codegen->invalid_instruction;
2724027278
27241 if (!type_has_bits(operand->value.type))
27279 if (!type_has_bits(operand->value->type))
2724227280 return ir_const_void(ira, &instruction->base);
2724327281
2724427282 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);
......@@ -27251,10 +27289,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr
2725127289
2725227290static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {
2725327291 IrInstruction *operand = instruction->begin->operand->child;
27254 if (type_is_invalid(operand->value.type))
27292 if (type_is_invalid(operand->value->type))
2725527293 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))
2725827296 return operand;
2725927297
2726027298 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);
......@@ -27262,7 +27300,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc
2726227300
2726327301 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,
2726427302 instruction->base.source_node, begin);
27265 result->value.type = operand->value.type;
27303 result->value->type = operand->value->type;
2726627304 return result;
2726727305}
2726827306
......@@ -27601,7 +27639,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2760127639 ira->new_irb.codegen = codegen;
2760227640 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);
2760527643 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);
2760627644 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {
2760727645 ira->exec_context.mem_slot_list.items[i] = &vals[i];
......@@ -27628,10 +27666,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2762827666 }
2762927667 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2763027668 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);
2763227670 old_instruction->child = new_instruction;
2763327671
27634 if (type_is_invalid(new_instruction->value.type)) {
27672 if (type_is_invalid(new_instruction->value->type)) {
2763527673 if (new_exec->first_err_trace_msg != nullptr) {
2763627674 ira->codegen->trace_err = new_exec->first_err_trace_msg;
2763727675 } else {
......@@ -27648,7 +27686,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2764827686 }
2764927687
2765027688 // unreachable instructions do their own control flow.
27651 if (new_instruction->value.type->id == ZigTypeIdUnreachable)
27689 if (new_instruction->value->type->id == ZigTypeIdUnreachable)
2765227690 continue;
2765327691 }
2765427692
......@@ -27947,7 +27985,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2794727985 return get_fn_type(ira->codegen, &fn_type_id);
2794827986}
2794927987
27950static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
27988static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2795127989 Error err;
2795227990 if (val->special != ConstValSpecialLazy)
2795327991 return ErrorNone;
......@@ -27958,8 +27996,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2795827996 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
2795927997 IrAnalyze *ira = lazy_align_of->ira;
2796027998
27961 if (lazy_align_of->target_type->value.special == ConstValSpecialStatic) {
27962 switch (lazy_align_of->target_type->value.data.x_type->id) {
27999 if (lazy_align_of->target_type->value->special == ConstValSpecialStatic) {
28000 switch (lazy_align_of->target_type->value->data.x_type->id) {
2796328001 case ZigTypeIdInvalid:
2796428002 zig_unreachable();
2796528003 case ZigTypeIdMetaType:
......@@ -27975,7 +28013,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2797528013 case ZigTypeIdOpaque:
2797628014 ir_add_error(ira, lazy_align_of->target_type,
2797728015 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)));
2797928017 return ErrorSemanticAnalyzeFail;
2798028018 case ZigTypeIdBool:
2798128019 case ZigTypeIdInt:
......@@ -27997,7 +28035,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2799728035 }
2799828036
2799928037 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,
2800128039 &align_in_bytes)))
2800228040 {
2800328041 return err;
......@@ -28012,8 +28050,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2801228050 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
2801328051 IrAnalyze *ira = lazy_size_of->ira;
2801428052
28015 if (lazy_size_of->target_type->value.special == ConstValSpecialStatic) {
28016 switch (lazy_size_of->target_type->value.data.x_type->id) {
28053 if (lazy_size_of->target_type->value->special == ConstValSpecialStatic) {
28054 switch (lazy_size_of->target_type->value->data.x_type->id) {
2801728055 case ZigTypeIdInvalid: // handled above
2801828056 zig_unreachable();
2801928057 case ZigTypeIdUnreachable:
......@@ -28024,7 +28062,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2802428062 case ZigTypeIdOpaque:
2802528063 ir_add_error(ira, lazy_size_of->target_type,
2802628064 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)));
2802828066 return ErrorSemanticAnalyzeFail;
2802928067 case ZigTypeIdMetaType:
2803028068 case ZigTypeIdEnumLiteral:
......@@ -28052,7 +28090,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2805228090
2805328091 size_t abi_size;
2805428092 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,
2805628094 &abi_size, &size_in_bits)))
2805728095 {
2805828096 return err;
......@@ -28071,12 +28109,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2807128109 if (type_is_invalid(elem_type))
2807228110 return ErrorSemanticAnalyzeFail;
2807328111
28074 ConstExprValue *sentinel_val;
28112 ZigValue *sentinel_val;
2807528113 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))
2807728115 return ErrorSemanticAnalyzeFail;
2807828116 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))
2808028118 return ErrorSemanticAnalyzeFail;
2808128119 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
2808228120 if (sentinel_val == nullptr)
......@@ -28149,12 +28187,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2814928187 if (type_is_invalid(elem_type))
2815028188 return ErrorSemanticAnalyzeFail;
2815128189
28152 ConstExprValue *sentinel_val;
28190 ZigValue *sentinel_val;
2815328191 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))
2815528193 return ErrorSemanticAnalyzeFail;
2815628194 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))
2815828196 return ErrorSemanticAnalyzeFail;
2815928197 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
2816028198 if (sentinel_val == nullptr)
......@@ -28276,7 +28314,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
2827628314 zig_unreachable();
2827728315}
2827828316
28279Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) {
28317Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2828028318 Error err;
2828128319 if ((err = ir_resolve_lazy_raw(source_node, val))) {
2828228320 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 {
1818bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
1919bool 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,
2222 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
2323 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
2424 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
2828ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
2929 ZigType *expected_type, AstNode *expected_type_source_node);
......@@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_
3131bool ir_has_side_effects(IrInstruction *instruction);
3232
3333struct IrAnalyze;
34ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,
34ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
3535 AstNode *source_node);
3636const 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) {
389389static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {
390390 ir_print_indent(irp);
391391 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)";
393393 const char *ref_count = ir_has_side_effects(instruction) ?
394394 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
395395 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
396396 ir_instruction_type_str(instruction->id), type_name, ref_count);
397397}
398398
399static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
399static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {
400400 Buf buf = BUF_INIT;
401401 buf_resize(&buf, 0);
402402 render_const_value(irp->codegen, &buf, const_val);
......@@ -417,8 +417,8 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction)
417417 return;
418418 }
419419
420 if (instruction->value.special != ConstValSpecialRuntime) {
421 ir_print_const_value(irp, &instruction->value);
420 if (instruction->value->special != ConstValSpecialRuntime) {
421 ir_print_const_value(irp, instruction->value);
422422 } else {
423423 ir_print_var_instruction(irp, instruction);
424424 }
......@@ -438,7 +438,7 @@ static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {
438438}
439439
440440static 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);
442442}
443443
444444static const char *ir_bin_op_id_str(IrBinOp op_id) {
......@@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,
25762576 ir_print_instruction(irp, instruction, false);
25772577}
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) {
25802580 IrPrint ir_print = {};
25812581 IrPrint *irp = &ir_print;
25822582 irp->pass = pass;
src/ir_print.hpp+1-1
......@@ -14,7 +14,7 @@
1414
1515void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
1616void 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
1919const char* ir_instruction_type_str(IrInstructionId id);
2020
src/memory_profiling.cpp+8-1
......@@ -6,6 +6,8 @@
66
77#ifdef ZIG_ENABLE_MEM_PROFILE
88
9MemprofInternCount memprof_intern_count;
10
911static bool str_eql_str(const char *a, const char *b) {
1012 return strcmp(a, b) == 0;
1113}
......@@ -29,7 +31,6 @@ ZigList<const char *> unknown_names = {};
2931HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {};
3032bool table_active = false;
3133
32
3334static const char *get_default_name(const char *name_or_null, size_t type_size) {
3435 if (name_or_null != nullptr) return name_or_null;
3536 if (type_size >= unknown_names.length) {
......@@ -134,6 +135,12 @@ void memprof_dump_stats(FILE *file) {
134135
135136 list.deinit();
136137 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);
137144}
138145
139146#endif
src/memory_profiling.hpp+8
......@@ -13,6 +13,14 @@
1313#include <stddef.h>
1414#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
1624void memprof_init(void);
1725
1826void 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) {
121121
122122void zig_pretty_print_bytes(FILE *f, double n) {
123123 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);
125125 return;
126126 }
127127 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);
129129 return;
130130 }
131131 if (n > 1024.0) {
132 fprintf(f, "%.02f KiB", n / 1024.0);
132 fprintf(f, "%.03f KiB", n / 1024.0);
133133 return;
134134 }
135 fprintf(f, "%.02f bytes", n );
135 fprintf(f, "%.03f bytes", n );
136136 return;
137137}
138138