authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-11-25 15:04:29-05:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-11-25 15:04:29-05:00
logacd95546b73bafca6e73af6f22c5e7c963c5c0c3
treeae1358d09d9c05d428162734c06def2b99bb663f
parent5a98dd42b38b9188cfb96c9ab57dc91af923029f
signaturelock-open Commit is signed but in an unrecognized format.

rename ConstExprValue → ZigValue


9 files changed, 686 insertions(+), 686 deletions(-)

src/all_types.hpp+43-43
...@@ -32,7 +32,7 @@ struct ErrorTableEntry;...@@ -32,7 +32,7 @@ struct ErrorTableEntry;
32struct BuiltinFnEntry;32struct BuiltinFnEntry;
33struct TypeStructField;33struct TypeStructField;
34struct CodeGen;34struct CodeGen;
35struct ConstExprValue;35struct ZigValue;
36struct IrInstruction;36struct IrInstruction;
37struct IrInstructionCast;37struct IrInstructionCast;
38struct IrInstructionAllocaGen;38struct IrInstructionAllocaGen;
...@@ -130,38 +130,38 @@ struct ConstParent {...@@ -130,38 +130,38 @@ struct ConstParent {
130130
131 union {131 union {
132 struct {132 struct {
133 ConstExprValue *array_val;133 ZigValue *array_val;
134 size_t elem_index;134 size_t elem_index;
135 } p_array;135 } p_array;
136 struct {136 struct {
137 ConstExprValue *struct_val;137 ZigValue *struct_val;
138 size_t field_index;138 size_t field_index;
139 } p_struct;139 } p_struct;
140 struct {140 struct {
141 ConstExprValue *err_union_val;141 ZigValue *err_union_val;
142 } p_err_union_code;142 } p_err_union_code;
143 struct {143 struct {
144 ConstExprValue *err_union_val;144 ZigValue *err_union_val;
145 } p_err_union_payload;145 } p_err_union_payload;
146 struct {146 struct {
147 ConstExprValue *optional_val;147 ZigValue *optional_val;
148 } p_optional_payload;148 } p_optional_payload;
149 struct {149 struct {
150 ConstExprValue *union_val;150 ZigValue *union_val;
151 } p_union;151 } p_union;
152 struct {152 struct {
153 ConstExprValue *scalar_val;153 ZigValue *scalar_val;
154 } p_scalar;154 } p_scalar;
155 } data;155 } data;
156};156};
157157
158struct ConstStructValue {158struct ConstStructValue {
159 ConstExprValue **fields;159 ZigValue **fields;
160};160};
161161
162struct ConstUnionValue {162struct ConstUnionValue {
163 BigInt tag;163 BigInt tag;
164 ConstExprValue *payload;164 ZigValue *payload;
165};165};
166166
167enum ConstArraySpecial {167enum ConstArraySpecial {
...@@ -174,7 +174,7 @@ struct ConstArrayValue {...@@ -174,7 +174,7 @@ struct ConstArrayValue {
174 ConstArraySpecial special;174 ConstArraySpecial special;
175 union {175 union {
176 struct {176 struct {
177 ConstExprValue *elements;177 ZigValue *elements;
178 } s_none;178 } s_none;
179 Buf *s_buf;179 Buf *s_buf;
180 } data;180 } data;
...@@ -235,24 +235,24 @@ struct ConstPtrValue {...@@ -235,24 +235,24 @@ struct ConstPtrValue {
235235
236 union {236 union {
237 struct {237 struct {
238 ConstExprValue *pointee;238 ZigValue *pointee;
239 } ref;239 } ref;
240 struct {240 struct {
241 ConstExprValue *array_val;241 ZigValue *array_val;
242 size_t elem_index;242 size_t elem_index;
243 } base_array;243 } base_array;
244 struct {244 struct {
245 ConstExprValue *struct_val;245 ZigValue *struct_val;
246 size_t field_index;246 size_t field_index;
247 } base_struct;247 } base_struct;
248 struct {248 struct {
249 ConstExprValue *err_union_val;249 ZigValue *err_union_val;
250 } base_err_union_code;250 } base_err_union_code;
251 struct {251 struct {
252 ConstExprValue *err_union_val;252 ZigValue *err_union_val;
253 } base_err_union_payload;253 } base_err_union_payload;
254 struct {254 struct {
255 ConstExprValue *optional_val;255 ZigValue *optional_val;
256 } base_optional_payload;256 } base_optional_payload;
257 struct {257 struct {
258 uint64_t addr;258 uint64_t addr;
...@@ -264,8 +264,8 @@ struct ConstPtrValue {...@@ -264,8 +264,8 @@ struct ConstPtrValue {
264};264};
265265
266struct ConstErrValue {266struct ConstErrValue {
267 ConstExprValue *error_set;267 ZigValue *error_set;
268 ConstExprValue *payload;268 ZigValue *payload;
269};269};
270270
271struct ConstBoundFnValue {271struct ConstBoundFnValue {
...@@ -406,7 +406,7 @@ struct LazyValueErrUnionType {...@@ -406,7 +406,7 @@ struct LazyValueErrUnionType {
406 Buf *type_name;406 Buf *type_name;
407};407};
408408
409struct ConstExprValue {409struct ZigValue {
410 ZigType *type;410 ZigType *type;
411 ConstValSpecial special;411 ConstValSpecial special;
412 ConstParent parent;412 ConstParent parent;
...@@ -423,7 +423,7 @@ struct ConstExprValue {...@@ -423,7 +423,7 @@ struct ConstExprValue {
423 bool x_bool;423 bool x_bool;
424 ConstBoundFnValue x_bound_fn;424 ConstBoundFnValue x_bound_fn;
425 ZigType *x_type;425 ZigType *x_type;
426 ConstExprValue *x_optional;426 ZigValue *x_optional;
427 ConstErrValue x_err_union;427 ConstErrValue x_err_union;
428 ErrorTableEntry *x_err_set;428 ErrorTableEntry *x_err_set;
429 BigInt x_enum_tag;429 BigInt x_enum_tag;
...@@ -443,8 +443,8 @@ struct ConstExprValue {...@@ -443,8 +443,8 @@ struct ConstExprValue {
443 } data;443 } data;
444444
445 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning445 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning
446 //ConstExprValue(const ConstExprValue &other) = delete; // plz zero initialize with {}446 //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {}
447 //ConstExprValue& operator= (const ConstExprValue &other) = delete; // use copy_const_val447 //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val
448};448};
449449
450enum ReturnKnowledge {450enum ReturnKnowledge {
...@@ -525,7 +525,7 @@ struct TldCompTime {...@@ -525,7 +525,7 @@ struct TldCompTime {
525struct TldUsingNamespace {525struct TldUsingNamespace {
526 Tld base;526 Tld base;
527527
528 ConstExprValue *using_namespace_value;528 ZigValue *using_namespace_value;
529};529};
530530
531struct TypeEnumField {531struct TypeEnumField {
...@@ -538,7 +538,7 @@ struct TypeEnumField {...@@ -538,7 +538,7 @@ struct TypeEnumField {
538struct TypeUnionField {538struct TypeUnionField {
539 Buf *name;539 Buf *name;
540 ZigType *type_entry; // available after ResolveStatusSizeKnown540 ZigType *type_entry; // available after ResolveStatusSizeKnown
541 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown541 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
542 TypeEnumField *enum_field;542 TypeEnumField *enum_field;
543 AstNode *decl_node;543 AstNode *decl_node;
544 uint32_t gen_index;544 uint32_t gen_index;
...@@ -1171,7 +1171,7 @@ struct FnTypeParamInfo {...@@ -1171,7 +1171,7 @@ struct FnTypeParamInfo {
1171struct GenericFnTypeId {1171struct GenericFnTypeId {
1172 CodeGen *codegen;1172 CodeGen *codegen;
1173 ZigFn *fn_entry;1173 ZigFn *fn_entry;
1174 ConstExprValue *params;1174 ZigValue *params;
1175 size_t param_count;1175 size_t param_count;
1176};1176};
11771177
...@@ -1213,7 +1213,7 @@ struct ZigTypePointer {...@@ -1213,7 +1213,7 @@ struct ZigTypePointer {
1213 // This can be null. If it is non-null, it means the pointer is terminated by this1213 // This can be null. If it is non-null, it means the pointer is terminated by this
1214 // sentinel value. This is most commonly used for C-style strings, with a 0 byte1214 // sentinel value. This is most commonly used for C-style strings, with a 0 byte
1215 // to specify the length of the memory pointed to.1215 // to specify the length of the memory pointed to.
1216 ConstExprValue *sentinel;1216 ZigValue *sentinel;
12171217
1218 PtrLen ptr_len;1218 PtrLen ptr_len;
1219 uint32_t explicit_alignment; // 0 means use ABI alignment1219 uint32_t explicit_alignment; // 0 means use ABI alignment
...@@ -1242,18 +1242,18 @@ struct ZigTypeFloat {...@@ -1242,18 +1242,18 @@ struct ZigTypeFloat {
1242struct ZigTypeArray {1242struct ZigTypeArray {
1243 ZigType *child_type;1243 ZigType *child_type;
1244 uint64_t len;1244 uint64_t len;
1245 ConstExprValue *sentinel;1245 ZigValue *sentinel;
1246};1246};
12471247
1248struct TypeStructField {1248struct TypeStructField {
1249 Buf *name;1249 Buf *name;
1250 ZigType *type_entry; // available after ResolveStatusSizeKnown1250 ZigType *type_entry; // available after ResolveStatusSizeKnown
1251 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown1251 ZigValue *type_val; // available after ResolveStatusZeroBitsKnown
1252 size_t src_index;1252 size_t src_index;
1253 size_t gen_index;1253 size_t gen_index;
1254 size_t offset; // byte offset from beginning of struct1254 size_t offset; // byte offset from beginning of struct
1255 AstNode *decl_node;1255 AstNode *decl_node;
1256 ConstExprValue *init_val; // null and then memoized1256 ZigValue *init_val; // null and then memoized
1257 uint32_t bit_offset_in_host; // offset from the memory at gen_index1257 uint32_t bit_offset_in_host; // offset from the memory at gen_index
1258 uint32_t host_int_bytes; // size of host integer1258 uint32_t host_int_bytes; // size of host integer
1259 uint32_t align;1259 uint32_t align;
...@@ -1515,7 +1515,7 @@ struct ZigType {...@@ -1515,7 +1515,7 @@ struct ZigType {
1515 ZigType *any_frame_parent;1515 ZigType *any_frame_parent;
1516 // If we generate a constant name value for this type, we memoize it here.1516 // If we generate a constant name value for this type, we memoize it here.
1517 // The type of this is array1517 // The type of this is array
1518 ConstExprValue *cached_const_name_val;1518 ZigValue *cached_const_name_val;
15191519
1520 OnePossibleValue one_possible_value;1520 OnePossibleValue one_possible_value;
1521 // Known after ResolveStatusAlignmentKnown.1521 // Known after ResolveStatusAlignmentKnown.
...@@ -1771,7 +1771,7 @@ struct TypeId {...@@ -1771,7 +1771,7 @@ struct TypeId {
1771 CodeGen *codegen;1771 CodeGen *codegen;
1772 ZigType *child_type;1772 ZigType *child_type;
1773 InferredStructField *inferred_struct_field;1773 InferredStructField *inferred_struct_field;
1774 ConstExprValue *sentinel;1774 ZigValue *sentinel;
1775 PtrLen ptr_len;1775 PtrLen ptr_len;
1776 uint32_t alignment;1776 uint32_t alignment;
17771777
...@@ -1787,7 +1787,7 @@ struct TypeId {...@@ -1787,7 +1787,7 @@ struct TypeId {
1787 CodeGen *codegen;1787 CodeGen *codegen;
1788 ZigType *child_type;1788 ZigType *child_type;
1789 uint64_t size;1789 uint64_t size;
1790 ConstExprValue *sentinel;1790 ZigValue *sentinel;
1791 } array;1791 } array;
1792 struct {1792 struct {
1793 bool is_signed;1793 bool is_signed;
...@@ -1960,13 +1960,13 @@ struct CodeGen {...@@ -1960,13 +1960,13 @@ struct CodeGen {
1960 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;1960 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
1961 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;1961 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;
1962 HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;1962 HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
1963 HashMap<Scope *, ConstExprValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;1963 HashMap<Scope *, ZigValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
1964 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;1964 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
1965 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;1965 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;
1966 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;1966 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
1967 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;1967 HashMap<Buf *, ZigValue *, buf_hash, buf_eql_buf> string_literals_table;
1968 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;1968 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1969 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> one_possible_values;1969 HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> one_possible_values;
19701970
1971 ZigList<Tld *> resolve_queue;1971 ZigList<Tld *> resolve_queue;
1972 size_t resolve_queue_index;1972 size_t resolve_queue_index;
...@@ -2043,9 +2043,9 @@ struct CodeGen {...@@ -2043,9 +2043,9 @@ struct CodeGen {
2043 IrInstruction *invalid_instruction;2043 IrInstruction *invalid_instruction;
2044 IrInstruction *unreach_instruction;2044 IrInstruction *unreach_instruction;
20452045
2046 ConstExprValue const_zero_byte;2046 ZigValue const_zero_byte;
2047 ConstExprValue const_void_val;2047 ZigValue const_void_val;
2048 ConstExprValue panic_msg_vals[PanicMsgIdCount];2048 ZigValue panic_msg_vals[PanicMsgIdCount];
20492049
2050 // The function definitions this module includes.2050 // The function definitions this module includes.
2051 ZigList<ZigFn *> fn_defs;2051 ZigList<ZigFn *> fn_defs;
...@@ -2163,7 +2163,7 @@ struct CodeGen {...@@ -2163,7 +2163,7 @@ struct CodeGen {
21632163
2164struct ZigVar {2164struct ZigVar {
2165 const char *name;2165 const char *name;
2166 ConstExprValue *const_value;2166 ZigValue *const_value;
2167 ZigType *var_type;2167 ZigType *var_type;
2168 LLVMValueRef value_ref;2168 LLVMValueRef value_ref;
2169 IrInstruction *is_comptime;2169 IrInstruction *is_comptime;
...@@ -2202,7 +2202,7 @@ struct ErrorTableEntry {...@@ -2202,7 +2202,7 @@ struct ErrorTableEntry {
2202 ZigType *set_with_only_this_in_it;2202 ZigType *set_with_only_this_in_it;
2203 // If we generate a constant error name value for this error, we memoize it here.2203 // If we generate a constant error name value for this error, we memoize it here.
2204 // The type of this is array2204 // The type of this is array
2205 ConstExprValue *cached_error_name_val;2205 ZigValue *cached_error_name_val;
2206};2206};
22072207
2208enum ScopeId {2208enum ScopeId {
...@@ -2621,7 +2621,7 @@ struct IrInstruction {...@@ -2621,7 +2621,7 @@ struct IrInstruction {
2621 Scope *scope;2621 Scope *scope;
2622 AstNode *source_node;2622 AstNode *source_node;
2623 LLVMValueRef llvm_value;2623 LLVMValueRef llvm_value;
2624 ConstExprValue value;2624 ZigValue value;
2625 uint32_t debug_id;2625 uint32_t debug_id;
2626 // if ref_count is zero and the instruction has no side effects,2626 // if ref_count is zero and the instruction has no side effects,
2627 // the instruction can be omitted in codegen2627 // the instruction can be omitted in codegen
src/analyze.cpp+118-118
...@@ -511,7 +511,7 @@ static void append_ptr_type_attrs(Buf *type_name, ZigType *ptr_type) {...@@ -511,7 +511,7 @@ static void append_ptr_type_attrs(Buf *type_name, ZigType *ptr_type) {
511ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,511ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,
512 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,512 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
513 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero,513 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero,
514 uint32_t vector_index, InferredStructField *inferred_struct_field, ConstExprValue *sentinel)514 uint32_t vector_index, InferredStructField *inferred_struct_field, ZigValue *sentinel)
515{515{
516 assert(ptr_len != PtrLenC || allow_zero);516 assert(ptr_len != PtrLenC || allow_zero);
517 assert(!type_is_invalid(child_type));517 assert(!type_is_invalid(child_type));
...@@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
760 return entry;760 return entry;
761}761}
762762
763ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel) {763ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel) {
764 TypeId type_id = {};764 TypeId type_id = {};
765 type_id.id = ZigTypeIdArray;765 type_id.id = ZigTypeIdArray;
766 type_id.data.array.codegen = g;766 type_id.data.array.codegen = g;
...@@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
956956
957ZigType *get_stack_trace_type(CodeGen *g) {957ZigType *get_stack_trace_type(CodeGen *g) {
958 if (g->stack_trace_type == nullptr) {958 if (g->stack_trace_type == nullptr) {
959 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");959 ZigValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
960 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);960 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
961961
962 g->stack_trace_type = stack_trace_type_val->data.x_type;962 g->stack_trace_type = stack_trace_type_val->data.x_type;
...@@ -1095,7 +1095,7 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind...@@ -1095,7 +1095,7 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
1095 return entry;1095 return entry;
1096}1096}
10971097
1098ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,1098ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
1099 Buf *type_name, UndefAllowed undef)1099 Buf *type_name, UndefAllowed undef)
1100{1100{
1101 size_t backward_branch_count = 0;1101 size_t backward_branch_count = 0;
...@@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig...@@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig
1105 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);1105 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);
1106}1106}
11071107
1108Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,1108Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
1109 ConstExprValue *parent_type_val, bool *is_zero_bits)1109 ZigValue *parent_type_val, bool *is_zero_bits)
1110{1110{
1111 Error err;1111 Error err;
1112 if (type_val->special != ConstValSpecialLazy) {1112 if (type_val->special != ConstValSpecialLazy) {
...@@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *...@@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
1160 zig_unreachable();1160 zig_unreachable();
1161}1161}
11621162
1163Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool *is_opaque_type) {1163Error type_val_resolve_is_opaque_type(CodeGen *g, ZigValue *type_val, bool *is_opaque_type) {
1164 if (type_val->special != ConstValSpecialLazy) {1164 if (type_val->special != ConstValSpecialLazy) {
1165 assert(type_val->special == ConstValSpecialStatic);1165 assert(type_val->special == ConstValSpecialStatic);
1166 if (type_val->data.x_type == g->builtin_types.entry_var) {1166 if (type_val->data.x_type == g->builtin_types.entry_var) {
...@@ -1186,7 +1186,7 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool...@@ -1186,7 +1186,7 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool
1186 zig_unreachable();1186 zig_unreachable();
1187}1187}
11881188
1189static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val) {1189static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ZigValue *type_val) {
1190 if (type_val->special != ConstValSpecialLazy) {1190 if (type_val->special != ConstValSpecialLazy) {
1191 return type_requires_comptime(g, type_val->data.x_type);1191 return type_requires_comptime(g, type_val->data.x_type);
1192 }1192 }
...@@ -1244,7 +1244,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1244,7 +1244,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1244 zig_unreachable();1244 zig_unreachable();
1245}1245}
12461246
1247Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val,1247Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,
1248 size_t *abi_size, size_t *size_in_bits)1248 size_t *abi_size, size_t *size_in_bits)
1249{1249{
1250 Error err;1250 Error err;
...@@ -1311,7 +1311,7 @@ start_over:...@@ -1311,7 +1311,7 @@ start_over:
1311 zig_unreachable();1311 zig_unreachable();
1312}1312}
13131313
1314Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align) {1314Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align) {
1315 Error err;1315 Error err;
1316 if (type_val->special != ConstValSpecialLazy) {1316 if (type_val->special != ConstValSpecialLazy) {
1317 assert(type_val->special == ConstValSpecialStatic);1317 assert(type_val->special == ConstValSpecialStatic);
...@@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t...@@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t
1356 zig_unreachable();1356 zig_unreachable();
1357}1357}
13581358
1359static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ConstExprValue *type_val) {1359static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ZigValue *type_val) {
1360 if (type_val->special != ConstValSpecialLazy) {1360 if (type_val->special != ConstValSpecialLazy) {
1361 return type_has_one_possible_value(g, type_val->data.x_type);1361 return type_has_one_possible_value(g, type_val->data.x_type);
1362 }1362 }
...@@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons...@@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
1398}1398}
13991399
1400ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {1400ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1401 ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,1401 ZigValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,
1402 nullptr, UndefBad);1402 nullptr, UndefBad);
1403 if (type_is_invalid(result->type))1403 if (type_is_invalid(result->type))
1404 return g->builtin_types.entry_invalid;1404 return g->builtin_types.entry_invalid;
...@@ -1451,7 +1451,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou...@@ -1451,7 +1451,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou
1451}1451}
14521452
1453static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {1453static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {
1454 ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g),1454 ZigValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g),
1455 nullptr, UndefBad);1455 nullptr, UndefBad);
1456 if (type_is_invalid(align_result->type))1456 if (type_is_invalid(align_result->type))
1457 return false;1457 return false;
...@@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1474 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,1474 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1475 PtrLenUnknown, 0, 0, 0, false);1475 PtrLenUnknown, 0, 0, 0, false);
1476 ZigType *str_type = get_slice_type(g, ptr_type);1476 ZigType *str_type = get_slice_type(g, ptr_type);
1477 ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad);1477 ZigValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad);
1478 if (type_is_invalid(result_val->type))1478 if (type_is_invalid(result_val->type))
1479 return false;1479 return false;
14801480
1481 ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];1481 ZigValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1482 ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index];1482 ZigValue *len_field = result_val->data.x_struct.fields[slice_len_index];
14831483
1484 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);1484 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
1485 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;1485 ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
1486 if (array_val->data.x_array.special == ConstArraySpecialBuf) {1486 if (array_val->data.x_array.special == ConstArraySpecialBuf) {
1487 *out_buffer = array_val->data.x_array.data.s_buf;1487 *out_buffer = array_val->data.x_array.data.s_buf;
1488 return true;1488 return true;
...@@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1493 buf_resize(result, len);1493 buf_resize(result, len);
1494 for (size_t i = 0; i < len; i += 1) {1494 for (size_t i = 0; i < len; i += 1) {
1495 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;1495 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
1496 ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];1496 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
1497 if (char_val->special == ConstValSpecialUndef) {1497 if (char_val->special == ConstValSpecialUndef) {
1498 add_node_error(g, node, buf_sprintf("use of undefined value"));1498 add_node_error(g, node, buf_sprintf("use of undefined value"));
1499 return false;1499 return false;
...@@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26212621
2622 if (tag_value != nullptr) {2622 if (tag_value != nullptr) {
2623 // A user-specified value is available2623 // A user-specified value is available
2624 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,2624 ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
2625 nullptr, UndefBad);2625 nullptr, UndefBad);
2626 if (type_is_invalid(result->type)) {2626 if (type_is_invalid(result->type)) {
2627 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;2627 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
...@@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2756 return ErrorSemanticAnalyzeFail;2756 return ErrorSemanticAnalyzeFail;
2757 }2757 }
27582758
2759 ConstExprValue *field_type_val;2759 ZigValue *field_type_val;
2760 if (decl_node->type == NodeTypeContainerDecl) {2760 if (decl_node->type == NodeTypeContainerDecl) {
2761 field_type_val = analyze_const_value(g, scope,2761 field_type_val = analyze_const_value(g, scope,
2762 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);2762 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
...@@ -3051,7 +3051,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3051,7 +3051,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3051 return ErrorSemanticAnalyzeFail;3051 return ErrorSemanticAnalyzeFail;
3052 }3052 }
3053 } else {3053 } else {
3054 ConstExprValue *field_type_val = analyze_const_value(g, scope,3054 ZigValue *field_type_val = analyze_const_value(g, scope,
3055 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);3055 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
3056 if (type_is_invalid(field_type_val->type)) {3056 if (type_is_invalid(field_type_val->type)) {
3057 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3057 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3117 // In a second pass we will fill in the unspecified ones.3117 // In a second pass we will fill in the unspecified ones.
3118 if (tag_value != nullptr) {3118 if (tag_value != nullptr) {
3119 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;3119 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
3120 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,3120 ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
3121 nullptr, UndefBad);3121 nullptr, UndefBad);
3122 if (type_is_invalid(result->type)) {3122 if (type_is_invalid(result->type)) {
3123 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3123 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -3545,7 +3545,7 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source...@@ -3545,7 +3545,7 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source
3545 tld->parent_scope = parent_scope;3545 tld->parent_scope = parent_scope;
3546}3546}
35473547
3548void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {3548void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
3549 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);3549 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);
3550 resolve_top_level_decl(g, tld, tld->source_node, false);3550 resolve_top_level_decl(g, tld, tld->source_node, false);
3551 assert(tld->id == TldIdVar);3551 assert(tld->id == TldIdVar);
...@@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry...@@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
3717// Set name to nullptr to make the variable anonymous (not visible to programmer).3717// Set name to nullptr to make the variable anonymous (not visible to programmer).
3718// TODO merge with definition of add_local_var in ir.cpp3718// TODO merge with definition of add_local_var in ir.cpp
3719ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,3719ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
3720 bool is_const, ConstExprValue *const_value, Tld *src_tld, ZigType *var_type)3720 bool is_const, ZigValue *const_value, Tld *src_tld, ZigType *var_type)
3721{3721{
3722 Error err;3722 Error err;
3723 assert(const_value != nullptr);3723 assert(const_value != nullptr);
...@@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
38153815
3816 assert(!is_export || !is_extern);3816 assert(!is_export || !is_extern);
38173817
3818 ConstExprValue *init_value = nullptr;3818 ZigValue *init_value = nullptr;
38193819
3820 // TODO more validation for types that can't be used for export/extern variables3820 // TODO more validation for types that can't be used for export/extern variables
3821 ZigType *implicit_type = nullptr;3821 ZigType *implicit_type = nullptr;
...@@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
3853 ZigType *type = explicit_type ? explicit_type : implicit_type;3853 ZigType *type = explicit_type ? explicit_type : implicit_type;
3854 assert(type != nullptr); // should have been caught by the parser3854 assert(type != nullptr); // should have been caught by the parser
38553855
3856 ConstExprValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);3856 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);
38573857
3858 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,3858 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
3859 is_const, init_val, &tld_var->base, type);3859 is_const, init_val, &tld_var->base, type);
...@@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_...@@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_
3900 }3900 }
3901 }3901 }
39023902
3903 ConstExprValue *use_expr = src_using_namespace->using_namespace_value;3903 ZigValue *use_expr = src_using_namespace->using_namespace_value;
3904 if (type_is_invalid(use_expr->type)) {3904 if (type_is_invalid(use_expr->type)) {
3905 dest_decls_scope->any_imports_failed = true;3905 dest_decls_scope->any_imports_failed = true;
3906 return;3906 return;
...@@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
39773977
3978 using_namespace->base.resolution = TldResolutionResolving;3978 using_namespace->base.resolution = TldResolutionResolving;
3979 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);3979 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);
3980 ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base,3980 ZigValue *result = analyze_const_value(g, &dest_decls_scope->base,
3981 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,3981 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,
3982 nullptr, UndefBad);3982 nullptr, UndefBad);
3983 using_namespace->using_namespace_value = result;3983 using_namespace->using_namespace_value = result;
...@@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {...@@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
5029 return true;5029 return true;
5030}5030}
50315031
5032static uint32_t hash_const_val_error_set(ConstExprValue *const_val) {5032static uint32_t hash_const_val_error_set(ZigValue *const_val) {
5033 assert(const_val->data.x_err_set != nullptr);5033 assert(const_val->data.x_err_set != nullptr);
5034 return const_val->data.x_err_set->value ^ 2630160122;5034 return const_val->data.x_err_set->value ^ 2630160122;
5035}5035}
50365036
5037static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {5037static uint32_t hash_const_val_ptr(ZigValue *const_val) {
5038 uint32_t hash_val = 0;5038 uint32_t hash_val = 0;
5039 switch (const_val->data.x_ptr.mut) {5039 switch (const_val->data.x_ptr.mut) {
5040 case ConstPtrMutRuntimeVar:5040 case ConstPtrMutRuntimeVar:
...@@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {...@@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
5095 zig_unreachable();5095 zig_unreachable();
5096}5096}
50975097
5098static uint32_t hash_const_val(ConstExprValue *const_val) {5098static uint32_t hash_const_val(ZigValue *const_val) {
5099 assert(const_val->special == ConstValSpecialStatic);5099 assert(const_val->special == ConstValSpecialStatic);
5100 switch (const_val->type->id) {5100 switch (const_val->type->id) {
5101 case ZigTypeIdOpaque:5101 case ZigTypeIdOpaque:
...@@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {...@@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
5224 uint32_t result = 0;5224 uint32_t result = 0;
5225 result += hash_ptr(id->fn_entry);5225 result += hash_ptr(id->fn_entry);
5226 for (size_t i = 0; i < id->param_count; i += 1) {5226 for (size_t i = 0; i < id->param_count; i += 1) {
5227 ConstExprValue *generic_param = &id->params[i];5227 ZigValue *generic_param = &id->params[i];
5228 if (generic_param->special != ConstValSpecialRuntime) {5228 if (generic_param->special != ConstValSpecialRuntime) {
5229 result += hash_const_val(generic_param);5229 result += hash_const_val(generic_param);
5230 result += hash_ptr(generic_param->type);5230 result += hash_ptr(generic_param->type);
...@@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
5238 if (a->fn_entry != b->fn_entry) return false;5238 if (a->fn_entry != b->fn_entry) return false;
5239 if (a->param_count != b->param_count) return false;5239 if (a->param_count != b->param_count) return false;
5240 for (size_t i = 0; i < a->param_count; i += 1) {5240 for (size_t i = 0; i < a->param_count; i += 1) {
5241 ConstExprValue *a_val = &a->params[i];5241 ZigValue *a_val = &a->params[i];
5242 ConstExprValue *b_val = &b->params[i];5242 ZigValue *b_val = &b->params[i];
5243 if (a_val->type != b_val->type) return false;5243 if (a_val->type != b_val->type) return false;
5244 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {5244 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {
5245 assert(a_val->special == ConstValSpecialStatic);5245 assert(a_val->special == ConstValSpecialStatic);
...@@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
5254 return true;5254 return true;
5255}5255}
52565256
5257static bool can_mutate_comptime_var_state(ConstExprValue *value) {5257static bool can_mutate_comptime_var_state(ZigValue *value) {
5258 assert(value != nullptr);5258 assert(value != nullptr);
5259 switch (value->type->id) {5259 switch (value->type->id) {
5260 case ZigTypeIdInvalid:5260 case ZigTypeIdInvalid:
...@@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5562 zig_unreachable();5562 zig_unreachable();
5563}5563}
55645564
5565ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {5565ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5566 auto entry = g->one_possible_values.maybe_get(type_entry);5566 auto entry = g->one_possible_values.maybe_get(type_entry);
5567 if (entry != nullptr) {5567 if (entry != nullptr) {
5568 return entry->value;5568 return entry->value;
5569 }5569 }
5570 ConstExprValue *result = create_const_vals(1);5570 ZigValue *result = create_const_vals(1);
5571 result->type = type_entry;5571 result->type = type_entry;
5572 result->special = ConstValSpecialStatic;5572 result->special = ConstValSpecialStatic;
5573 g->one_possible_values.put(type_entry, result);5573 g->one_possible_values.put(type_entry, result);
...@@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {...@@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
5637 zig_unreachable();5637 zig_unreachable();
5638}5638}
56395639
5640void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {5640void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
5641 auto entry = g->string_literals_table.maybe_get(str);5641 auto entry = g->string_literals_table.maybe_get(str);
5642 if (entry != nullptr) {5642 if (entry != nullptr) {
5643 memcpy(const_val, entry->value, sizeof(ConstExprValue));5643 memcpy(const_val, entry->value, sizeof(ZigValue));
5644 return;5644 return;
5645 }5645 }
56465646
5647 // first we build the underlying array5647 // first we build the underlying array
5648 ConstExprValue *array_val = create_const_vals(1);5648 ZigValue *array_val = create_const_vals(1);
5649 array_val->special = ConstValSpecialStatic;5649 array_val->special = ConstValSpecialStatic;
5650 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte);5650 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte);
5651 array_val->data.x_array.special = ConstArraySpecialBuf;5651 array_val->data.x_array.special = ConstArraySpecialBuf;
...@@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {...@@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
5661 g->string_literals_table.put(str, const_val);5661 g->string_literals_table.put(str, const_val);
5662}5662}
56635663
5664ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {5664ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {
5665 ConstExprValue *const_val = create_const_vals(1);5665 ZigValue *const_val = create_const_vals(1);
5666 init_const_str_lit(g, const_val, str);5666 init_const_str_lit(g, const_val, str);
5667 return const_val;5667 return const_val;
5668}5668}
56695669
5670void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) {5670void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint) {
5671 const_val->special = ConstValSpecialStatic;5671 const_val->special = ConstValSpecialStatic;
5672 const_val->type = type;5672 const_val->type = type;
5673 bigint_init_bigint(&const_val->data.x_bigint, bigint);5673 bigint_init_bigint(&const_val->data.x_bigint, bigint);
5674}5674}
56755675
5676ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {5676ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5677 ConstExprValue *const_val = create_const_vals(1);5677 ZigValue *const_val = create_const_vals(1);
5678 init_const_bigint(const_val, type, bigint);5678 init_const_bigint(const_val, type, bigint);
5679 return const_val;5679 return const_val;
5680}5680}
56815681
56825682
5683void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) {5683void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative) {
5684 const_val->special = ConstValSpecialStatic;5684 const_val->special = ConstValSpecialStatic;
5685 const_val->type = type;5685 const_val->type = type;
5686 bigint_init_unsigned(&const_val->data.x_bigint, x);5686 bigint_init_unsigned(&const_val->data.x_bigint, x);
5687 const_val->data.x_bigint.is_negative = negative;5687 const_val->data.x_bigint.is_negative = negative;
5688}5688}
56895689
5690ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {5690ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5691 ConstExprValue *const_val = create_const_vals(1);5691 ZigValue *const_val = create_const_vals(1);
5692 init_const_unsigned_negative(const_val, type, x, negative);5692 init_const_unsigned_negative(const_val, type, x, negative);
5693 return const_val;5693 return const_val;
5694}5694}
56955695
5696void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x) {5696void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {
5697 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);5697 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);
5698}5698}
56995699
5700ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {5700ZigValue *create_const_usize(CodeGen *g, uint64_t x) {
5701 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);5701 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
5702}5702}
57035703
5704void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) {5704void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
5705 const_val->special = ConstValSpecialStatic;5705 const_val->special = ConstValSpecialStatic;
5706 const_val->type = type;5706 const_val->type = type;
5707 bigint_init_signed(&const_val->data.x_bigint, x);5707 bigint_init_signed(&const_val->data.x_bigint, x);
5708}5708}
57095709
5710ConstExprValue *create_const_signed(ZigType *type, int64_t x) {5710ZigValue *create_const_signed(ZigType *type, int64_t x) {
5711 ConstExprValue *const_val = create_const_vals(1);5711 ZigValue *const_val = create_const_vals(1);
5712 init_const_signed(const_val, type, x);5712 init_const_signed(const_val, type, x);
5713 return const_val;5713 return const_val;
5714}5714}
57155715
5716void init_const_null(ConstExprValue *const_val, ZigType *type) {5716void init_const_null(ZigValue *const_val, ZigType *type) {
5717 const_val->special = ConstValSpecialStatic;5717 const_val->special = ConstValSpecialStatic;
5718 const_val->type = type;5718 const_val->type = type;
5719 const_val->data.x_optional = nullptr;5719 const_val->data.x_optional = nullptr;
5720}5720}
57215721
5722ConstExprValue *create_const_null(ZigType *type) {5722ZigValue *create_const_null(ZigType *type) {
5723 ConstExprValue *const_val = create_const_vals(1);5723 ZigValue *const_val = create_const_vals(1);
5724 init_const_null(const_val, type);5724 init_const_null(const_val, type);
5725 return const_val;5725 return const_val;
5726}5726}
57275727
5728void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {5728void init_const_float(ZigValue *const_val, ZigType *type, double value) {
5729 const_val->special = ConstValSpecialStatic;5729 const_val->special = ConstValSpecialStatic;
5730 const_val->type = type;5730 const_val->type = type;
5731 if (type->id == ZigTypeIdComptimeFloat) {5731 if (type->id == ZigTypeIdComptimeFloat) {
...@@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {...@@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5752 }5752 }
5753}5753}
57545754
5755ConstExprValue *create_const_float(ZigType *type, double value) {5755ZigValue *create_const_float(ZigType *type, double value) {
5756 ConstExprValue *const_val = create_const_vals(1);5756 ZigValue *const_val = create_const_vals(1);
5757 init_const_float(const_val, type, value);5757 init_const_float(const_val, type, value);
5758 return const_val;5758 return const_val;
5759}5759}
57605760
5761void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) {5761void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {
5762 const_val->special = ConstValSpecialStatic;5762 const_val->special = ConstValSpecialStatic;
5763 const_val->type = type;5763 const_val->type = type;
5764 bigint_init_bigint(&const_val->data.x_enum_tag, tag);5764 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
5765}5765}
57665766
5767ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {5767ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {
5768 ConstExprValue *const_val = create_const_vals(1);5768 ZigValue *const_val = create_const_vals(1);
5769 init_const_enum(const_val, type, tag);5769 init_const_enum(const_val, type, tag);
5770 return const_val;5770 return const_val;
5771}5771}
57725772
57735773
5774void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value) {5774void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
5775 const_val->special = ConstValSpecialStatic;5775 const_val->special = ConstValSpecialStatic;
5776 const_val->type = g->builtin_types.entry_bool;5776 const_val->type = g->builtin_types.entry_bool;
5777 const_val->data.x_bool = value;5777 const_val->data.x_bool = value;
5778}5778}
57795779
5780ConstExprValue *create_const_bool(CodeGen *g, bool value) {5780ZigValue *create_const_bool(CodeGen *g, bool value) {
5781 ConstExprValue *const_val = create_const_vals(1);5781 ZigValue *const_val = create_const_vals(1);
5782 init_const_bool(g, const_val, value);5782 init_const_bool(g, const_val, value);
5783 return const_val;5783 return const_val;
5784}5784}
57855785
5786void init_const_runtime(ConstExprValue *const_val, ZigType *type) {5786void init_const_runtime(ZigValue *const_val, ZigType *type) {
5787 const_val->special = ConstValSpecialRuntime;5787 const_val->special = ConstValSpecialRuntime;
5788 const_val->type = type;5788 const_val->type = type;
5789}5789}
57905790
5791ConstExprValue *create_const_runtime(ZigType *type) {5791ZigValue *create_const_runtime(ZigType *type) {
5792 ConstExprValue *const_val = create_const_vals(1);5792 ZigValue *const_val = create_const_vals(1);
5793 init_const_runtime(const_val, type);5793 init_const_runtime(const_val, type);
5794 return const_val;5794 return const_val;
5795}5795}
57965796
5797void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) {5797void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {
5798 const_val->special = ConstValSpecialStatic;5798 const_val->special = ConstValSpecialStatic;
5799 const_val->type = g->builtin_types.entry_type;5799 const_val->type = g->builtin_types.entry_type;
5800 const_val->data.x_type = type_value;5800 const_val->data.x_type = type_value;
5801}5801}
58025802
5803ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {5803ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {
5804 ConstExprValue *const_val = create_const_vals(1);5804 ZigValue *const_val = create_const_vals(1);
5805 init_const_type(g, const_val, type_value);5805 init_const_type(g, const_val, type_value);
5806 return const_val;5806 return const_val;
5807}5807}
58085808
5809void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5809void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5810 size_t start, size_t len, bool is_const)5810 size_t start, size_t len, bool is_const)
5811{5811{
5812 assert(array_val->type->id == ZigTypeIdArray);5812 assert(array_val->type->id == ZigTypeIdArray);
...@@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr...@@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
5823 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);5823 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);
5824}5824}
58255825
5826ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {5826ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {
5827 ConstExprValue *const_val = create_const_vals(1);5827 ZigValue *const_val = create_const_vals(1);
5828 init_const_slice(g, const_val, array_val, start, len, is_const);5828 init_const_slice(g, const_val, array_val, start, len, is_const);
5829 return const_val;5829 return const_val;
5830}5830}
58315831
5832void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5832void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5833 size_t elem_index, bool is_const, PtrLen ptr_len)5833 size_t elem_index, bool is_const, PtrLen ptr_len)
5834{5834{
5835 assert(array_val->type->id == ZigTypeIdArray);5835 assert(array_val->type->id == ZigTypeIdArray);
...@@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue...@@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue
5843 const_val->data.x_ptr.data.base_array.elem_index = elem_index;5843 const_val->data.x_ptr.data.base_array.elem_index = elem_index;
5844}5844}
58455845
5846ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index, bool is_const,5846ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,
5847 PtrLen ptr_len)5847 PtrLen ptr_len)
5848{5848{
5849 ConstExprValue *const_val = create_const_vals(1);5849 ZigValue *const_val = create_const_vals(1);
5850 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);5850 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
5851 return const_val;5851 return const_val;
5852}5852}
58535853
5854void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const) {5854void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const) {
5855 const_val->special = ConstValSpecialStatic;5855 const_val->special = ConstValSpecialStatic;
5856 const_val->type = get_pointer_to_type(g, pointee_val->type, is_const);5856 const_val->type = get_pointer_to_type(g, pointee_val->type, is_const);
5857 const_val->data.x_ptr.special = ConstPtrSpecialRef;5857 const_val->data.x_ptr.special = ConstPtrSpecialRef;
5858 const_val->data.x_ptr.data.ref.pointee = pointee_val;5858 const_val->data.x_ptr.data.ref.pointee = pointee_val;
5859}5859}
58605860
5861ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const) {5861ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {
5862 ConstExprValue *const_val = create_const_vals(1);5862 ZigValue *const_val = create_const_vals(1);
5863 init_const_ptr_ref(g, const_val, pointee_val, is_const);5863 init_const_ptr_ref(g, const_val, pointee_val, is_const);
5864 return const_val;5864 return const_val;
5865}5865}
58665866
5867void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,5867void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type,
5868 size_t addr, bool is_const)5868 size_t addr, bool is_const)
5869{5869{
5870 const_val->special = ConstValSpecialStatic;5870 const_val->special = ConstValSpecialStatic;
...@@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy...@@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy
5873 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;5873 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
5874}5874}
58755875
5876ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,5876ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
5877 size_t addr, bool is_const)5877 size_t addr, bool is_const)
5878{5878{
5879 ConstExprValue *const_val = create_const_vals(1);5879 ZigValue *const_val = create_const_vals(1);
5880 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);5880 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
5881 return const_val;5881 return const_val;
5882}5882}
58835883
5884void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end) {5884void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end) {
5885 const_val->special = ConstValSpecialStatic;5885 const_val->special = ConstValSpecialStatic;
5886 const_val->type = g->builtin_types.entry_arg_tuple;5886 const_val->type = g->builtin_types.entry_arg_tuple;
5887 const_val->data.x_arg_tuple.start_index = arg_index_start;5887 const_val->data.x_arg_tuple.start_index = arg_index_start;
5888 const_val->data.x_arg_tuple.end_index = arg_index_end;5888 const_val->data.x_arg_tuple.end_index = arg_index_end;
5889}5889}
58905890
5891ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {5891ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {
5892 ConstExprValue *const_val = create_const_vals(1);5892 ZigValue *const_val = create_const_vals(1);
5893 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);5893 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);
5894 return const_val;5894 return const_val;
5895}5895}
58965896
58975897
5898ConstExprValue *create_const_vals(size_t count) {5898ZigValue *create_const_vals(size_t count) {
5899 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");5899 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5900 ConstExprValue *vals = allocate<ConstExprValue>(count, "ConstExprValue");5900 ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
5901 for (size_t i = 0; i < count; i += 1) {5901 for (size_t i = 0; i < count; i += 1) {
5902 vals[i].global_refs = &global_refs[i];5902 vals[i].global_refs = &global_refs[i];
5903 }5903 }
5904 return vals;5904 return vals;
5905}5905}
59065906
5907ConstExprValue **alloc_const_vals_ptrs(size_t count) {5907ZigValue **alloc_const_vals_ptrs(size_t count) {
5908 return realloc_const_vals_ptrs(nullptr, 0, count);5908 return realloc_const_vals_ptrs(nullptr, 0, count);
5909}5909}
59105910
5911ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count) {5911ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count) {
5912 assert(new_count >= old_count);5912 assert(new_count >= old_count);
59135913
5914 size_t new_item_count = new_count - old_count;5914 size_t new_item_count = new_count - old_count;
5915 ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*");5915 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");
5916 ConstExprValue *vals = create_const_vals(new_item_count);5916 ZigValue *vals = create_const_vals(new_item_count);
5917 for (size_t i = old_count; i < new_count; i += 1) {5917 for (size_t i = old_count; i < new_count; i += 1) {
5918 result[i] = &vals[i - old_count];5918 result[i] = &vals[i - old_count];
5919 }5919 }
...@@ -6456,7 +6456,7 @@ bool ir_get_var_is_comptime(ZigVar *var) {...@@ -6456,7 +6456,7 @@ bool ir_get_var_is_comptime(ZigVar *var) {
6456 return var->is_comptime->value.data.x_bool;6456 return var->is_comptime->value.data.x_bool;
6457}6457}
64586458
6459bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {6459bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
6460 if (a->data.x_ptr.special != b->data.x_ptr.special)6460 if (a->data.x_ptr.special != b->data.x_ptr.special)
6461 return false;6461 return false;
6462 switch (a->data.x_ptr.special) {6462 switch (a->data.x_ptr.special) {
...@@ -6527,7 +6527,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {...@@ -6527,7 +6527,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
6527 zig_unreachable();6527 zig_unreachable();
6528}6528}
65296529
6530static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprValue *b, size_t len) {6530static bool const_values_equal_array(CodeGen *g, ZigValue *a, ZigValue *b, size_t len) {
6531 assert(a->data.x_array.special != ConstArraySpecialUndef);6531 assert(a->data.x_array.special != ConstArraySpecialUndef);
6532 assert(b->data.x_array.special != ConstArraySpecialUndef);6532 assert(b->data.x_array.special != ConstArraySpecialUndef);
6533 if (a->data.x_array.special == ConstArraySpecialBuf &&6533 if (a->data.x_array.special == ConstArraySpecialBuf &&
...@@ -6538,8 +6538,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal...@@ -6538,8 +6538,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal
6538 expand_undef_array(g, a);6538 expand_undef_array(g, a);
6539 expand_undef_array(g, b);6539 expand_undef_array(g, b);
65406540
6541 ConstExprValue *a_elems = a->data.x_array.data.s_none.elements;6541 ZigValue *a_elems = a->data.x_array.data.s_none.elements;
6542 ConstExprValue *b_elems = b->data.x_array.data.s_none.elements;6542 ZigValue *b_elems = b->data.x_array.data.s_none.elements;
65436543
6544 for (size_t i = 0; i < len; i += 1) {6544 for (size_t i = 0; i < len; i += 1) {
6545 if (!const_values_equal(g, &a_elems[i], &b_elems[i]))6545 if (!const_values_equal(g, &a_elems[i], &b_elems[i]))
...@@ -6549,7 +6549,7 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal...@@ -6549,7 +6549,7 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal
6549 return true;6549 return true;
6550}6550}
65516551
6552bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {6552bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
6553 if (a->type->id != b->type->id) return false;6553 if (a->type->id != b->type->id) return false;
6554 assert(a->special == ConstValSpecialStatic);6554 assert(a->special == ConstValSpecialStatic);
6555 assert(b->special == ConstValSpecialStatic);6555 assert(b->special == ConstValSpecialStatic);
...@@ -6623,8 +6623,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {...@@ -6623,8 +6623,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
6623 }6623 }
6624 case ZigTypeIdStruct:6624 case ZigTypeIdStruct:
6625 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {6625 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];6626 ZigValue *field_a = a->data.x_struct.fields[i];
6627 ConstExprValue *field_b = b->data.x_struct.fields[i];6627 ZigValue *field_b = b->data.x_struct.fields[i];
6628 if (!const_values_equal(g, field_a, field_b))6628 if (!const_values_equal(g, field_a, field_b))
6629 return false;6629 return false;
6630 }6630 }
...@@ -6695,7 +6695,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool...@@ -6695,7 +6695,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool
6695 }6695 }
6696}6696}
66976697
6698void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {6698void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max) {
6699 if (type_entry->id == ZigTypeIdInt) {6699 if (type_entry->id == ZigTypeIdInt) {
6700 const_val->special = ConstValSpecialStatic;6700 const_val->special = ConstValSpecialStatic;
6701 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);6701 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);
...@@ -6709,7 +6709,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v...@@ -6709,7 +6709,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v
6709 }6709 }
6710}6710}
67116711
6712static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {6712static void render_const_val_ptr(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) {
6713 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {6713 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
6714 buf_append_buf(buf, &type_entry->name);6714 buf_append_buf(buf, &type_entry->name);
6715 return;6715 return;
...@@ -6752,7 +6752,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val...@@ -6752,7 +6752,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val
6752 zig_unreachable();6752 zig_unreachable();
6753}6753}
67546754
6755static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {6755static void render_const_val_err_set(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) {
6756 if (const_val->data.x_err_set == nullptr) {6756 if (const_val->data.x_err_set == nullptr) {
6757 buf_append_str(buf, "null");6757 buf_append_str(buf, "null");
6758 } else {6758 } else {
...@@ -6760,7 +6760,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const...@@ -6760,7 +6760,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const
6760 }6760 }
6761}6761}
67626762
6763static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstExprValue *const_val, uint64_t start, uint64_t len) {6763static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValue *const_val, uint64_t start, uint64_t len) {
6764 ConstArrayValue *array = &const_val->data.x_array;6764 ConstArrayValue *array = &const_val->data.x_array;
6765 switch (array->special) {6765 switch (array->special) {
6766 case ConstArraySpecialUndef:6766 case ConstArraySpecialUndef:
...@@ -6784,7 +6784,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx...@@ -6784,7 +6784,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx
6784 return;6784 return;
6785 }6785 }
6786 case ConstArraySpecialNone: {6786 case ConstArraySpecialNone: {
6787 ConstExprValue *base = &array->data.s_none.elements[start];6787 ZigValue *base = &array->data.s_none.elements[start];
6788 assert(start + len <= const_val->type->data.array.len);6788 assert(start + len <= const_val->type->data.array.len);
67896789
6790 buf_appendf(buf, "%s{", buf_ptr(type_name));6790 buf_appendf(buf, "%s{", buf_ptr(type_name));
...@@ -6799,7 +6799,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx...@@ -6799,7 +6799,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx
6799 zig_unreachable();6799 zig_unreachable();
6800}6800}
68016801
6802void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {6802void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
6803 switch (const_val->special) {6803 switch (const_val->special) {
6804 case ConstValSpecialRuntime:6804 case ConstValSpecialRuntime:
6805 buf_appendf(buf, "(runtime value)");6805 buf_appendf(buf, "(runtime value)");
...@@ -6927,17 +6927,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -6927,17 +6927,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
6927 case ZigTypeIdStruct:6927 case ZigTypeIdStruct:
6928 {6928 {
6929 if (is_slice(type_entry)) {6929 if (is_slice(type_entry)) {
6930 ConstExprValue *len_val = const_val->data.x_struct.fields[slice_len_index];6930 ZigValue *len_val = const_val->data.x_struct.fields[slice_len_index];
6931 size_t len = bigint_as_usize(&len_val->data.x_bigint);6931 size_t len = bigint_as_usize(&len_val->data.x_bigint);
69326932
6933 ConstExprValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];6933 ZigValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];
6934 if (ptr_val->special == ConstValSpecialUndef) {6934 if (ptr_val->special == ConstValSpecialUndef) {
6935 assert(len == 0);6935 assert(len == 0);
6936 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));6936 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));
6937 return;6937 return;
6938 }6938 }
6939 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);6939 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
6940 ConstExprValue *array = ptr_val->data.x_ptr.data.base_array.array_val;6940 ZigValue *array = ptr_val->data.x_ptr.data.base_array.array_val;
6941 size_t start = ptr_val->data.x_ptr.data.base_array.elem_index;6941 size_t start = ptr_val->data.x_ptr.data.base_array.elem_index;
69426942
6943 render_const_val_array(g, buf, &type_entry->name, array, start, len);6943 render_const_val_array(g, buf, &type_entry->name, array, start, len);
...@@ -7206,7 +7206,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {...@@ -7206,7 +7206,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
7206 zig_unreachable();7206 zig_unreachable();
7207}7207}
72087208
7209static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {7209static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
7210 Error err;7210 Error err;
7211 ZigType *wanted_type = const_val->type;7211 ZigType *wanted_type = const_val->type;
7212 if (wanted_type->id == ZigTypeIdArray) {7212 if (wanted_type->id == ZigTypeIdArray) {
...@@ -7221,7 +7221,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {...@@ -7221,7 +7221,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
7221 size_t field_count = wanted_type->data.structure.src_field_count;7221 size_t field_count = wanted_type->data.structure.src_field_count;
7222 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);7222 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
7223 for (size_t i = 0; i < field_count; i += 1) {7223 for (size_t i = 0; i < field_count; i += 1) {
7224 ConstExprValue *field_val = const_val->data.x_struct.fields[i];7224 ZigValue *field_val = const_val->data.x_struct.fields[i];
7225 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);7225 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
7226 assert(field_val->type);7226 assert(field_val->type);
7227 init_const_undefined(g, field_val);7227 init_const_undefined(g, field_val);
...@@ -7234,14 +7234,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {...@@ -7234,14 +7234,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
7234 }7234 }
7235}7235}
72367236
7237void expand_undef_struct(CodeGen *g, ConstExprValue *const_val) {7237void expand_undef_struct(CodeGen *g, ZigValue *const_val) {
7238 if (const_val->special == ConstValSpecialUndef) {7238 if (const_val->special == ConstValSpecialUndef) {
7239 init_const_undefined(g, const_val);7239 init_const_undefined(g, const_val);
7240 }7240 }
7241}7241}
72427242
7243// Canonicalize the array value as ConstArraySpecialNone7243// Canonicalize the array value as ConstArraySpecialNone
7244void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {7244void expand_undef_array(CodeGen *g, ZigValue *const_val) {
7245 size_t elem_count;7245 size_t elem_count;
7246 ZigType *elem_type;7246 ZigType *elem_type;
7247 if (const_val->type->id == ZigTypeIdArray) {7247 if (const_val->type->id == ZigTypeIdArray) {
...@@ -7264,7 +7264,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -7264,7 +7264,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
7264 const_val->data.x_array.special = ConstArraySpecialNone;7264 const_val->data.x_array.special = ConstArraySpecialNone;
7265 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);7265 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7266 for (size_t i = 0; i < elem_count; i += 1) {7266 for (size_t i = 0; i < elem_count; i += 1) {
7267 ConstExprValue *element_val = &const_val->data.x_array.data.s_none.elements[i];7267 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];
7268 element_val->type = elem_type;7268 element_val->type = elem_type;
7269 init_const_undefined(g, element_val);7269 init_const_undefined(g, element_val);
7270 element_val->parent.id = ConstParentIdArray;7270 element_val->parent.id = ConstParentIdArray;
...@@ -7283,7 +7283,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -7283,7 +7283,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
7283 assert(elem_count == buf_len(buf));7283 assert(elem_count == buf_len(buf));
7284 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);7284 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7285 for (size_t i = 0; i < elem_count; i += 1) {7285 for (size_t i = 0; i < elem_count; i += 1) {
7286 ConstExprValue *this_char = &const_val->data.x_array.data.s_none.elements[i];7286 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];
7287 this_char->special = ConstValSpecialStatic;7287 this_char->special = ConstValSpecialStatic;
7288 this_char->type = g->builtin_types.entry_u8;7288 this_char->type = g->builtin_types.entry_u8;
7289 bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(buf)[i]);7289 bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(buf)[i]);
...@@ -7541,12 +7541,12 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {...@@ -7541,12 +7541,12 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {
7541 return a == b;7541 return a == b;
7542}7542}
75437543
7544ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {7544ZigValue *get_builtin_value(CodeGen *codegen, const char *name) {
7545 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));7545 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
7546 resolve_top_level_decl(codegen, tld, nullptr, false);7546 resolve_top_level_decl(codegen, tld, nullptr, false);
7547 assert(tld->id == TldIdVar);7547 assert(tld->id == TldIdVar);
7548 TldVar *tld_var = (TldVar *)tld;7548 TldVar *tld_var = (TldVar *)tld;
7549 ConstExprValue *var_value = tld_var->var->const_value;7549 ZigValue *var_value = tld_var->var->const_value;
7550 assert(var_value != nullptr);7550 assert(var_value != nullptr);
7551 return var_value;7551 return var_value;
7552}7552}
...@@ -7733,9 +7733,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f...@@ -7733,9 +7733,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f
7733}7733}
77347734
7735Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,7735Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
7736 ConstExprValue *const_val, ZigType *wanted_type)7736 ZigValue *const_val, ZigType *wanted_type)
7737{7737{
7738 ConstExprValue ptr_val = {};7738 ZigValue ptr_val = {};
7739 ptr_val.special = ConstValSpecialStatic;7739 ptr_val.special = ConstValSpecialStatic;
7740 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);7740 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);
7741 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;7741 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;
src/analyze.hpp+53-53
...@@ -25,7 +25,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type,...@@ -25,7 +25,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type,
25 bool is_const, bool is_volatile, PtrLen ptr_len,25 bool is_const, bool is_volatile, PtrLen ptr_len,
26 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,26 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,
27 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field,27 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field,
28 ConstExprValue *sentinel);28 ZigValue *sentinel);
29uint64_t type_size(CodeGen *g, ZigType *type_entry);29uint64_t type_size(CodeGen *g, ZigType *type_entry);
30uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);30uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
31ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);31ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
...@@ -34,7 +34,7 @@ ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);...@@ -34,7 +34,7 @@ ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
34ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);34ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
35ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);35ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
36ZigType *get_optional_type(CodeGen *g, ZigType *child_type);36ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
37ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel);37ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel);
38ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);38ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
39ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,39ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
40 AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);40 AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);
...@@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope);...@@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope);
95ScopeTypeOf *get_scope_typeof(Scope *scope);95ScopeTypeOf *get_scope_typeof(Scope *scope);
96void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);96void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
97ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,97ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
98 bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type);98 bool is_const, ZigValue *init_value, Tld *src_tld, ZigType *var_type);
99ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);99ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);
101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);
...@@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);...@@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);
106void complete_enum(CodeGen *g, ZigType *enum_type);106void complete_enum(CodeGen *g, ZigType *enum_type);
107bool ir_get_var_is_comptime(ZigVar *var);107bool ir_get_var_is_comptime(ZigVar *var);
108bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b);108bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b);
109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);109void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max);
110void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);110void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
111111
112void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);112void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val);
113113
114ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent);114ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent);
115ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent);115ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent);
...@@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct...@@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct
124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
127void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);127void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);130void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint);
131ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);131ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint);
132132
133void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);133void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative);
134ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);134ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
135135
136void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);136void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x);
137ConstExprValue *create_const_signed(ZigType *type, int64_t x);137ZigValue *create_const_signed(ZigType *type, int64_t x);
138138
139void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142void init_const_float(ConstExprValue *const_val, ZigType *type, double value);142void init_const_float(ZigValue *const_val, ZigType *type, double value);
143ConstExprValue *create_const_float(ZigType *type, double value);143ZigValue *create_const_float(ZigType *type, double value);
144144
145void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);145void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag);
146ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);146ZigValue *create_const_enum(ZigType *type, const BigInt *tag);
147147
148void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149ConstExprValue *create_const_bool(CodeGen *g, bool value);149ZigValue *create_const_bool(CodeGen *g, bool value);
150150
151void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);151void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154void init_const_runtime(ConstExprValue *const_val, ZigType *type);154void init_const_runtime(ZigValue *const_val, ZigType *type);
155ConstExprValue *create_const_runtime(ZigType *type);155ZigValue *create_const_runtime(ZigType *type);
156156
157void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);
158ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);158ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const);
159159
160void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,160void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type,
161 size_t addr, bool is_const);161 size_t addr, bool is_const);
162ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,162ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
163 size_t addr, bool is_const);163 size_t addr, bool is_const);
164164
165void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,165void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
166 size_t elem_index, bool is_const, PtrLen ptr_len);166 size_t elem_index, bool is_const, PtrLen ptr_len);
167ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index,167ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index,
168 bool is_const, PtrLen ptr_len);168 bool is_const, PtrLen ptr_len);
169169
170void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,170void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
171 size_t start, size_t len, bool is_const);171 size_t start, size_t len, bool is_const);
172ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const);172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);174void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end);
175ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);175ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
176176
177void init_const_null(ConstExprValue *const_val, ZigType *type);177void init_const_null(ZigValue *const_val, ZigType *type);
178ConstExprValue *create_const_null(ZigType *type);178ZigValue *create_const_null(ZigType *type);
179179
180ConstExprValue *create_const_vals(size_t count);180ZigValue *create_const_vals(size_t count);
181ConstExprValue **alloc_const_vals_ptrs(size_t count);181ZigValue **alloc_const_vals_ptrs(size_t count);
182ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);182ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
183183
184TypeStructField **alloc_type_struct_fields(size_t count);184TypeStructField **alloc_type_struct_fields(size_t count);
185TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);185TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
186186
187ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);187ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
188void expand_undef_array(CodeGen *g, ConstExprValue *const_val);188void expand_undef_array(CodeGen *g, ZigValue *const_val);
189void expand_undef_struct(CodeGen *g, ConstExprValue *const_val);189void expand_undef_struct(CodeGen *g, ZigValue *const_val);
190void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);190void update_compile_var(CodeGen *g, Buf *name, ZigValue *value);
191191
192const char *type_id_name(ZigTypeId id);192const char *type_id_name(ZigTypeId id);
193ZigTypeId type_id_at_index(size_t index);193ZigTypeId type_id_at_index(size_t index);
...@@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);...@@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
201ZigType *get_align_amt_type(CodeGen *g);201ZigType *get_align_amt_type(CodeGen *g);
202ZigPackage *new_anonymous_package(void);202ZigPackage *new_anonymous_package(void);
203203
204Buf *const_value_to_buffer(ConstExprValue *const_val);204Buf *const_value_to_buffer(ZigValue *const_val);
205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);
206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);
207207
208208
209ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);209ZigValue *get_builtin_value(CodeGen *codegen, const char *name);
210ZigType *get_stack_trace_type(CodeGen *g);210ZigType *get_stack_trace_type(CodeGen *g);
211bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);211bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);
212212
...@@ -242,7 +242,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);...@@ -242,7 +242,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);
242OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);242OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);
243243
244Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,244Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
245 ConstExprValue *const_val, ZigType *wanted_type);245 ZigValue *const_val, ZigType *wanted_type);
246246
247void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);247void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
248Buf *type_bare_name(ZigType *t);248Buf *type_bare_name(ZigType *t);
...@@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa...@@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
256256
257void src_assert(bool ok, AstNode *source_node);257void src_assert(bool ok, AstNode *source_node);
258bool is_container(ZigType *type_entry);258bool is_container(ZigType *type_entry);
259ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,259ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
260 Buf *type_name, UndefAllowed undef);260 Buf *type_name, UndefAllowed undef);
261261
262void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);262void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);
263bool fn_is_async(ZigFn *fn);263bool fn_is_async(ZigFn *fn);
264264
265Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align);265Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align);
266Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val,266Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,
267 size_t *abi_size, size_t *size_in_bits);267 size_t *abi_size, size_t *size_in_bits);
268Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,268Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
269 ConstExprValue *parent_type_val, bool *is_zero_bits);269 ZigValue *parent_type_val, bool *is_zero_bits);
270ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);270ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);
271ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);271ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
272272
...@@ -276,5 +276,5 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,...@@ -276,5 +276,5 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
276 ZigType *var_type, const char *name_hint);276 ZigType *var_type, const char *name_hint);
277Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,277Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
278 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);278 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
279ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);279ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
280#endif280#endif
src/codegen.cpp+53-53
...@@ -185,11 +185,11 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {...@@ -185,11 +185,11 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {
185}185}
186186
187187
188static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);188static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name);
189static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name);189static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name);
190static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);190static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name);
191static void generate_error_name_table(CodeGen *g);191static void generate_error_name_table(CodeGen *g);
192static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val);192static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
193static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);193static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
194static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);194static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
195static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,195static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
...@@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {...@@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
945}945}
946946
947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
948 ConstExprValue *val = &g->panic_msg_vals[msg_id];948 ZigValue *val = &g->panic_msg_vals[msg_id];
949 if (!val->global_refs->llvm_global) {949 if (!val->global_refs->llvm_global) {
950950
951 Buf *buf_msg = panic_msg_buf(msg_id);951 Buf *buf_msg = panic_msg_buf(msg_id);
952 ConstExprValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;952 ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;
953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);
954954
955 render_const_val(g, val, "");955 render_const_val(g, val, "");
...@@ -3474,7 +3474,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,...@@ -3474,7 +3474,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
3474 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");3474 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");
3475}3475}
34763476
3477static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size_t len) {3477static bool value_is_all_undef_array(CodeGen *g, ZigValue *const_val, size_t len) {
3478 switch (const_val->data.x_array.special) {3478 switch (const_val->data.x_array.special) {
3479 case ConstArraySpecialUndef:3479 case ConstArraySpecialUndef:
3480 return true;3480 return true;
...@@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size...@@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size
3490 zig_unreachable();3490 zig_unreachable();
3491}3491}
34923492
3493static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {3493static bool value_is_all_undef(CodeGen *g, ZigValue *const_val) {
3494 Error err;3494 Error err;
3495 if (const_val->special == ConstValSpecialLazy &&3495 if (const_val->special == ConstValSpecialLazy &&
3496 (err = ir_resolve_lazy(g, nullptr, const_val)))3496 (err = ir_resolve_lazy(g, nullptr, const_val)))
...@@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {...@@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
6362 }6362 }
6363}6363}
63646364
6365static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index);6365static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index);
6366static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index);6366static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index);
6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val);6367static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val);
6368static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val);6368static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val);
6369static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val);6369static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val);
6370static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val);6370static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val);
63716371
6372static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent *parent) {6372static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *parent) {
6373 switch (parent->id) {6373 switch (parent->id) {
6374 case ConstParentIdNone:6374 case ConstParentIdNone:
6375 render_const_val(g, val, "");6375 render_const_val(g, val, "");
...@@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent...@@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent
6397 zig_unreachable();6397 zig_unreachable();
6398}6398}
63996399
6400static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index) {6400static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index) {
6401 expand_undef_array(g, array_const_val);6401 expand_undef_array(g, array_const_val);
6402 ConstParent *parent = &array_const_val->parent;6402 ConstParent *parent = &array_const_val->parent;
6403 LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent);6403 LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent);
...@@ -6423,7 +6423,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar...@@ -6423,7 +6423,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
6423 }6423 }
6424}6424}
64256425
6426static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index) {6426static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index) {
6427 ConstParent *parent = &struct_const_val->parent;6427 ConstParent *parent = &struct_const_val->parent;
6428 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);6428 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);
64296429
...@@ -6435,7 +6435,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s...@@ -6435,7 +6435,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s
6435 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6435 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6436}6436}
64376437
6438static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val) {6438static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val) {
6439 ConstParent *parent = &err_union_const_val->parent;6439 ConstParent *parent = &err_union_const_val->parent;
6440 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);6440 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);
64416441
...@@ -6447,7 +6447,7 @@ static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExpr...@@ -6447,7 +6447,7 @@ static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExpr
6447 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6447 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6448}6448}
64496449
6450static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val) {6450static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val) {
6451 ConstParent *parent = &err_union_const_val->parent;6451 ConstParent *parent = &err_union_const_val->parent;
6452 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);6452 LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent);
64536453
...@@ -6459,7 +6459,7 @@ static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstE...@@ -6459,7 +6459,7 @@ static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstE
6459 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6459 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6460}6460}
64616461
6462static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val) {6462static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val) {
6463 ConstParent *parent = &optional_const_val->parent;6463 ConstParent *parent = &optional_const_val->parent;
6464 LLVMValueRef base_ptr = gen_parent_ptr(g, optional_const_val, parent);6464 LLVMValueRef base_ptr = gen_parent_ptr(g, optional_const_val, parent);
64656465
...@@ -6471,7 +6471,7 @@ static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstEx...@@ -6471,7 +6471,7 @@ static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstEx
6471 return LLVMConstInBoundsGEP(base_ptr, indices, 2);6471 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
6472}6472}
64736473
6474static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val) {6474static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val) {
6475 ConstParent *parent = &union_const_val->parent;6475 ConstParent *parent = &union_const_val->parent;
6476 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);6476 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);
64776477
...@@ -6488,7 +6488,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un...@@ -6488,7 +6488,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
6488 return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1);6488 return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1);
6489}6489}
64906490
6491static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ConstExprValue *const_val) {6491static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ZigValue *const_val) {
6492 switch (const_val->special) {6492 switch (const_val->special) {
6493 case ConstValSpecialLazy:6493 case ConstValSpecialLazy:
6494 case ConstValSpecialRuntime:6494 case ConstValSpecialRuntime:
...@@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
6555 uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type);6555 uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type);
6556 size_t used_bits = 0;6556 size_t used_bits = 0;
6557 for (size_t i = 0; i < type_entry->data.array.len; i += 1) {6557 for (size_t i = 0; i < type_entry->data.array.len; i += 1) {
6558 ConstExprValue *elem_val = &const_val->data.x_array.data.s_none.elements[i];6558 ZigValue *elem_val = &const_val->data.x_array.data.s_none.elements[i];
6559 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val);6559 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val);
65606560
6561 if (is_big_endian) {6561 if (is_big_endian) {
...@@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu...@@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu
6616 return LLVMTypeOf(val) != get_llvm_type(g, type_entry);6616 return LLVMTypeOf(val) != get_llvm_type(g, type_entry);
6617}6617}
66186618
6619static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, const char *name) {6619static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const char *name) {
6620 switch (const_val->data.x_ptr.special) {6620 switch (const_val->data.x_ptr.special) {
6621 case ConstPtrSpecialInvalid:6621 case ConstPtrSpecialInvalid:
6622 case ConstPtrSpecialDiscard:6622 case ConstPtrSpecialDiscard:
...@@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6624 case ConstPtrSpecialRef:6624 case ConstPtrSpecialRef:
6625 {6625 {
6626 assert(const_val->global_refs != nullptr);6626 assert(const_val->global_refs != nullptr);
6627 ConstExprValue *pointee = const_val->data.x_ptr.data.ref.pointee;6627 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;
6628 render_const_val(g, pointee, "");6628 render_const_val(g, pointee, "");
6629 render_const_val_global(g, pointee, "");6629 render_const_val_global(g, pointee, "");
6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
...@@ -6634,11 +6634,11 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6634,11 +6634,11 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6634 case ConstPtrSpecialBaseArray:6634 case ConstPtrSpecialBaseArray:
6635 {6635 {
6636 assert(const_val->global_refs != nullptr);6636 assert(const_val->global_refs != nullptr);
6637 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;6637 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
6638 assert(array_const_val->type->id == ZigTypeIdArray);6638 assert(array_const_val->type->id == ZigTypeIdArray);
6639 if (!type_has_bits(array_const_val->type)) {6639 if (!type_has_bits(array_const_val->type)) {
6640 if (array_const_val->type->data.array.sentinel != nullptr) {6640 if (array_const_val->type->data.array.sentinel != nullptr) {
6641 ConstExprValue *pointee = array_const_val->type->data.array.sentinel;6641 ZigValue *pointee = array_const_val->type->data.array.sentinel;
6642 render_const_val(g, pointee, "");6642 render_const_val(g, pointee, "");
6643 render_const_val_global(g, pointee, "");6643 render_const_val_global(g, pointee, "");
6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
...@@ -6661,7 +6661,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6661,7 +6661,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6661 case ConstPtrSpecialBaseStruct:6661 case ConstPtrSpecialBaseStruct:
6662 {6662 {
6663 assert(const_val->global_refs != nullptr);6663 assert(const_val->global_refs != nullptr);
6664 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;6664 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
6665 assert(struct_const_val->type->id == ZigTypeIdStruct);6665 assert(struct_const_val->type->id == ZigTypeIdStruct);
6666 if (!type_has_bits(struct_const_val->type)) {6666 if (!type_has_bits(struct_const_val->type)) {
6667 // make this a null pointer6667 // make this a null pointer
...@@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6681 case ConstPtrSpecialBaseErrorUnionCode:6681 case ConstPtrSpecialBaseErrorUnionCode:
6682 {6682 {
6683 assert(const_val->global_refs != nullptr);6683 assert(const_val->global_refs != nullptr);
6684 ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;6684 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
6685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6686 if (!type_has_bits(err_union_const_val->type)) {6686 if (!type_has_bits(err_union_const_val->type)) {
6687 // make this a null pointer6687 // make this a null pointer
...@@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6698 case ConstPtrSpecialBaseErrorUnionPayload:6698 case ConstPtrSpecialBaseErrorUnionPayload:
6699 {6699 {
6700 assert(const_val->global_refs != nullptr);6700 assert(const_val->global_refs != nullptr);
6701 ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;6701 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
6702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6703 if (!type_has_bits(err_union_const_val->type)) {6703 if (!type_has_bits(err_union_const_val->type)) {
6704 // make this a null pointer6704 // make this a null pointer
...@@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6715 case ConstPtrSpecialBaseOptionalPayload:6715 case ConstPtrSpecialBaseOptionalPayload:
6716 {6716 {
6717 assert(const_val->global_refs != nullptr);6717 assert(const_val->global_refs != nullptr);
6718 ConstExprValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;6718 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
6719 assert(optional_const_val->type->id == ZigTypeIdOptional);6719 assert(optional_const_val->type->id == ZigTypeIdOptional);
6720 if (!type_has_bits(optional_const_val->type)) {6720 if (!type_has_bits(optional_const_val->type)) {
6721 // make this a null pointer6721 // make this a null pointer
...@@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6747 zig_unreachable();6747 zig_unreachable();
6748}6748}
67496749
6750static LLVMValueRef gen_const_val_err_set(CodeGen *g, ConstExprValue *const_val, const char *name) {6750static LLVMValueRef gen_const_val_err_set(CodeGen *g, ZigValue *const_val, const char *name) {
6751 uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value;6751 uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value;
6752 return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false);6752 return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false);
6753}6753}
67546754
6755static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {6755static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
6756 Error err;6756 Error err;
67576757
6758 ZigType *type_entry = const_val->type;6758 ZigType *type_entry = const_val->type;
...@@ -6864,7 +6864,7 @@ check: switch (const_val->special) {...@@ -6864,7 +6864,7 @@ check: switch (const_val->special) {
6864 }6864 }
68656865
6866 if (src_field_index + 1 == src_field_index_end) {6866 if (src_field_index + 1 == src_field_index_end) {
6867 ConstExprValue *field_val = const_val->data.x_struct.fields[src_field_index];6867 ZigValue *field_val = const_val->data.x_struct.fields[src_field_index];
6868 LLVMValueRef val = gen_const_val(g, field_val, "");6868 LLVMValueRef val = gen_const_val(g, field_val, "");
6869 fields[type_struct_field->gen_index] = val;6869 fields[type_struct_field->gen_index] = val;
6870 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);6870 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);
...@@ -6921,7 +6921,7 @@ check: switch (const_val->special) {...@@ -6921,7 +6921,7 @@ check: switch (const_val->special) {
6921 if (type_struct_field->gen_index == SIZE_MAX) {6921 if (type_struct_field->gen_index == SIZE_MAX) {
6922 continue;6922 continue;
6923 }6923 }
6924 ConstExprValue *field_val = const_val->data.x_struct.fields[i];6924 ZigValue *field_val = const_val->data.x_struct.fields[i];
6925 assert(field_val->type != nullptr);6925 assert(field_val->type != nullptr);
6926 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,6926 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
6927 type_struct_field->type_entry)))6927 type_struct_field->type_entry)))
...@@ -6970,7 +6970,7 @@ check: switch (const_val->special) {...@@ -6970,7 +6970,7 @@ check: switch (const_val->special) {
6970 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);6970 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
6971 bool make_unnamed_struct = false;6971 bool make_unnamed_struct = false;
6972 for (uint64_t i = 0; i < len; i += 1) {6972 for (uint64_t i = 0; i < len; i += 1) {
6973 ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];6973 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
6974 LLVMValueRef val = gen_const_val(g, elem_value, "");6974 LLVMValueRef val = gen_const_val(g, elem_value, "");
6975 values[i] = val;6975 values[i] = val;
6976 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);6976 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);
...@@ -7000,7 +7000,7 @@ check: switch (const_val->special) {...@@ -7000,7 +7000,7 @@ check: switch (const_val->special) {
7000 case ConstArraySpecialNone: {7000 case ConstArraySpecialNone: {
7001 LLVMValueRef *values = allocate<LLVMValueRef>(len);7001 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7002 for (uint64_t i = 0; i < len; i += 1) {7002 for (uint64_t i = 0; i < len; i += 1) {
7003 ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];7003 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
7004 values[i] = gen_const_val(g, elem_value, "");7004 values[i] = gen_const_val(g, elem_value, "");
7005 }7005 }
7006 return LLVMConstVector(values, len);7006 return LLVMConstVector(values, len);
...@@ -7036,7 +7036,7 @@ check: switch (const_val->special) {...@@ -7036,7 +7036,7 @@ check: switch (const_val->special) {
70367036
7037 LLVMValueRef union_value_ref;7037 LLVMValueRef union_value_ref;
7038 bool make_unnamed_struct;7038 bool make_unnamed_struct;
7039 ConstExprValue *payload_value = const_val->data.x_union.payload;7039 ZigValue *payload_value = const_val->data.x_union.payload;
7040 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {7040 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {
7041 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)7041 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)
7042 return LLVMGetUndef(get_llvm_type(g, type_entry));7042 return LLVMGetUndef(get_llvm_type(g, type_entry));
...@@ -7133,7 +7133,7 @@ check: switch (const_val->special) {...@@ -7133,7 +7133,7 @@ check: switch (const_val->special) {
7133 make_unnamed_struct = false;7133 make_unnamed_struct = false;
7134 } else {7134 } else {
7135 err_tag_value = LLVMConstNull(get_llvm_type(g, g->err_tag_type));7135 err_tag_value = LLVMConstNull(get_llvm_type(g, g->err_tag_type));
7136 ConstExprValue *payload_val = const_val->data.x_err_union.payload;7136 ZigValue *payload_val = const_val->data.x_err_union.payload;
7137 err_payload_value = gen_const_val(g, payload_val, "");7137 err_payload_value = gen_const_val(g, payload_val, "");
7138 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value);7138 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value);
7139 }7139 }
...@@ -7174,7 +7174,7 @@ check: switch (const_val->special) {...@@ -7174,7 +7174,7 @@ check: switch (const_val->special) {
7174 zig_unreachable();7174 zig_unreachable();
7175}7175}
71767176
7177static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {7177static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
7178 if (!const_val->global_refs)7178 if (!const_val->global_refs)
7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7180 if (!const_val->global_refs->llvm_value)7180 if (!const_val->global_refs->llvm_value)
...@@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *...@@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *
7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7185}7185}
71867186
7187static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name) {7187static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {
7188 if (!const_val->global_refs)7188 if (!const_val->global_refs)
7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);
71907190
...@@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) {
73247324
7325 if (var->var_type->id == ZigTypeIdComptimeFloat) {7325 if (var->var_type->id == ZigTypeIdComptimeFloat) {
7326 // Generate debug info for it but that's it.7326 // Generate debug info for it but that's it.
7327 ConstExprValue *const_val = var->const_value;7327 ZigValue *const_val = var->const_value;
7328 assert(const_val->special != ConstValSpecialRuntime);7328 assert(const_val->special != ConstValSpecialRuntime);
7329 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))7329 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
7330 zig_unreachable();7330 zig_unreachable();
...@@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) {
7332 zig_panic("TODO debug info for var with ptr casted value");7332 zig_panic("TODO debug info for var with ptr casted value");
7333 }7333 }
7334 ZigType *var_type = g->builtin_types.entry_f128;7334 ZigType *var_type = g->builtin_types.entry_f128;
7335 ConstExprValue coerced_value = {};7335 ZigValue coerced_value = {};
7336 coerced_value.special = ConstValSpecialStatic;7336 coerced_value.special = ConstValSpecialStatic;
7337 coerced_value.type = var_type;7337 coerced_value.type = var_type;
7338 coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);7338 coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
...@@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) {
73437343
7344 if (var->var_type->id == ZigTypeIdComptimeInt) {7344 if (var->var_type->id == ZigTypeIdComptimeInt) {
7345 // Generate debug info for it but that's it.7345 // Generate debug info for it but that's it.
7346 ConstExprValue *const_val = var->const_value;7346 ZigValue *const_val = var->const_value;
7347 assert(const_val->special != ConstValSpecialRuntime);7347 assert(const_val->special != ConstValSpecialRuntime);
7348 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))7348 if ((err = ir_resolve_lazy(g, var->decl_node, const_val)))
7349 zig_unreachable();7349 zig_unreachable();
...@@ -9080,13 +9080,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9080,13 +9080,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
90809080
9081 ZigType *fn_type = get_test_fn_type(g);9081 ZigType *fn_type = get_test_fn_type(g);
90829082
9083 ConstExprValue *test_fn_type_val = get_builtin_value(g, "TestFn");9083 ZigValue *test_fn_type_val = get_builtin_value(g, "TestFn");
9084 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);9084 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
9085 ZigType *struct_type = test_fn_type_val->data.x_type;9085 ZigType *struct_type = test_fn_type_val->data.x_type;
9086 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))9086 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
9087 zig_unreachable();9087 zig_unreachable();
90889088
9089 ConstExprValue *test_fn_array = create_const_vals(1);9089 ZigValue *test_fn_array = create_const_vals(1);
9090 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);9090 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
9091 test_fn_array->special = ConstValSpecialStatic;9091 test_fn_array->special = ConstValSpecialStatic;
9092 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);9092 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);
...@@ -9103,7 +9103,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9103,7 +9103,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9103 continue;9103 continue;
9104 }9104 }
91059105
9106 ConstExprValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];9106 ZigValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
9107 this_val->special = ConstValSpecialStatic;9107 this_val->special = ConstValSpecialStatic;
9108 this_val->type = struct_type;9108 this_val->type = struct_type;
9109 this_val->parent.id = ConstParentIdArray;9109 this_val->parent.id = ConstParentIdArray;
...@@ -9111,11 +9111,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9111,11 +9111,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9111 this_val->parent.data.p_array.elem_index = i;9111 this_val->parent.data.p_array.elem_index = i;
9112 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);9112 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
91139113
9114 ConstExprValue *name_field = this_val->data.x_struct.fields[0];9114 ZigValue *name_field = this_val->data.x_struct.fields[0];
9115 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;9115 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
9116 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);9116 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
91179117
9118 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];9118 ZigValue *fn_field = this_val->data.x_struct.fields[1];
9119 fn_field->type = fn_type;9119 fn_field->type = fn_type;
9120 fn_field->special = ConstValSpecialStatic;9120 fn_field->special = ConstValSpecialStatic;
9121 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;9121 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
...@@ -9124,7 +9124,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9124,7 +9124,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9124 }9124 }
9125 report_errors_and_maybe_exit(g);9125 report_errors_and_maybe_exit(g);
91269126
9127 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);9127 ZigValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
91289128
9129 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);9129 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
9130 assert(g->test_runner_package != nullptr);9130 assert(g->test_runner_package != nullptr);
...@@ -9221,7 +9221,7 @@ static void gen_root_source(CodeGen *g) {...@@ -9221,7 +9221,7 @@ static void gen_root_source(CodeGen *g) {
9221 report_errors_and_maybe_exit(g);9221 report_errors_and_maybe_exit(g);
9222 assert(builtin_tld->id == TldIdVar);9222 assert(builtin_tld->id == TldIdVar);
9223 TldVar *builtin_tld_var = (TldVar*)builtin_tld;9223 TldVar *builtin_tld_var = (TldVar*)builtin_tld;
9224 ConstExprValue *builtin_val = builtin_tld_var->var->const_value;9224 ZigValue *builtin_val = builtin_tld_var->var->const_value;
9225 assert(builtin_val->type->id == ZigTypeIdMetaType);9225 assert(builtin_val->type->id == ZigTypeIdMetaType);
9226 ZigType *builtin_type = builtin_val->data.x_type;9226 ZigType *builtin_type = builtin_val->data.x_type;
92279227
...@@ -9232,7 +9232,7 @@ static void gen_root_source(CodeGen *g) {...@@ -9232,7 +9232,7 @@ static void gen_root_source(CodeGen *g) {
9232 report_errors_and_maybe_exit(g);9232 report_errors_and_maybe_exit(g);
9233 assert(panic_tld->id == TldIdVar);9233 assert(panic_tld->id == TldIdVar);
9234 TldVar *panic_tld_var = (TldVar*)panic_tld;9234 TldVar *panic_tld_var = (TldVar*)panic_tld;
9235 ConstExprValue *panic_fn_val = panic_tld_var->var->const_value;9235 ZigValue *panic_fn_val = panic_tld_var->var->const_value;
9236 assert(panic_fn_val->type->id == ZigTypeIdFn);9236 assert(panic_fn_val->type->id == ZigTypeIdFn);
9237 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);9237 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);
9238 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;9238 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;
src/dump_analysis.cpp+4-4
...@@ -361,9 +361,9 @@ struct AnalDumpCtx {...@@ -361,9 +361,9 @@ struct AnalDumpCtx {
361};361};
362362
363static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);363static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);
364static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value);364static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value);
365365
366static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) {366static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) {
367 Error err;367 Error err;
368 if (value->type != ty) {368 if (value->type != ty) {
369 return;369 return;
...@@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) {...@@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) {
660 jw_string(jw, buf_ptr(file));660 jw_string(jw, buf_ptr(file));
661}661}
662662
663static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) {663static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) {
664 Error err;664 Error err;
665665
666 if (value->type != ty) {666 if (value->type != ty) {
...@@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const...@@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
1249 }1249 }
1250 scope = scope->parent;1250 scope = scope->parent;
1251 }1251 }
1252 ConstExprValue *result = entry->value;1252 ZigValue *result = entry->value;
12531253
1254 assert(fn != nullptr);1254 assert(fn != nullptr);
12551255
src/ir.cpp+409-409
...@@ -19,7 +19,7 @@...@@ -19,7 +19,7 @@
19#include <errno.h>19#include <errno.h>
2020
21struct IrExecContext {21struct IrExecContext {
22 ZigList<ConstExprValue *> mem_slot_list;22 ZigList<ZigValue *> mem_slot_list;
23};23};
2424
25struct IrBuilder {25struct IrBuilder {
...@@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
204static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);204static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);
205static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);205static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
206static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);206static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
207static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val);207static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
208static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);208static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
209static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,209static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
210 ConstExprValue *out_val, ConstExprValue *ptr_val);210 ZigValue *out_val, ZigValue *ptr_val);
211static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,211static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
212 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);212 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
213static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);213static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
214static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);214static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs);
215static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);215static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
216static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,216static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
217 ZigType *ptr_type);217 ZigType *ptr_type);
...@@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
244 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);244 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
245static ResultLoc *no_result_loc(void);245static ResultLoc *no_result_loc(void);
246246
247static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {247static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
248 assert(get_src_ptr_type(const_val->type) != nullptr);248 assert(get_src_ptr_type(const_val->type) != nullptr);
249 assert(const_val->special == ConstValSpecialStatic);249 assert(const_val->special == ConstValSpecialStatic);
250 ConstExprValue *result;250 ZigValue *result;
251251
252 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {252 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
253 case OnePossibleValueInvalid:253 case OnePossibleValueInvalid:
...@@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
265 result = const_val->data.x_ptr.data.ref.pointee;265 result = const_val->data.x_ptr.data.ref.pointee;
266 break;266 break;
267 case ConstPtrSpecialBaseArray: {267 case ConstPtrSpecialBaseArray: {
268 ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val;268 ZigValue *array_val = const_val->data.x_ptr.data.base_array.array_val;
269 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {269 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {
270 result = array_val->type->data.array.sentinel;270 result = array_val->type->data.array.sentinel;
271 } else {271 } else {
...@@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
275 break;275 break;
276 }276 }
277 case ConstPtrSpecialBaseStruct: {277 case ConstPtrSpecialBaseStruct: {
278 ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;278 ZigValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;
279 expand_undef_struct(g, struct_val);279 expand_undef_struct(g, struct_val);
280 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];280 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
281 break;281 break;
...@@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) {...@@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) {
317 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;317 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
318}318}
319319
320// This function returns true when you can change the type of a ConstExprValue and the320// This function returns true when you can change the type of a ZigValue and the
321// value remains meaningful.321// value remains meaningful.
322static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) {322static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) {
323 if (expected == actual)323 if (expected == actual)
...@@ -416,7 +416,7 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {...@@ -416,7 +416,7 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {
416 return exec->c_import_buf;416 return exec->c_import_buf;
417}417}
418418
419static bool value_is_comptime(ConstExprValue *const_val) {419static bool value_is_comptime(ZigValue *const_val) {
420 return const_val->special != ConstValSpecialRuntime;420 return const_val->special != ConstValSpecialRuntime;
421}421}
422422
...@@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) {...@@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) {
449}449}
450450
451ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {451ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
452 ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,452 ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,
453 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,453 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,
454 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);454 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);
455455
...@@ -8698,26 +8698,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) {...@@ -8698,26 +8698,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) {
8698// This function takes a comptime ptr and makes the child const value conform to the type8698// This function takes a comptime ptr and makes the child const value conform to the type
8699// described by the pointer.8699// described by the pointer.
8700static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,8700static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
8701 ConstExprValue *ptr_val)8701 ZigValue *ptr_val)
8702{8702{
8703 Error err;8703 Error err;
8704 assert(ptr_val->type->id == ZigTypeIdPointer);8704 assert(ptr_val->type->id == ZigTypeIdPointer);
8705 assert(ptr_val->special == ConstValSpecialStatic);8705 assert(ptr_val->special == ConstValSpecialStatic);
8706 ConstExprValue tmp = {};8706 ZigValue tmp = {};
8707 tmp.special = ConstValSpecialStatic;8707 tmp.special = ConstValSpecialStatic;
8708 tmp.type = ptr_val->type->data.pointer.child_type;8708 tmp.type = ptr_val->type->data.pointer.child_type;
8709 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))8709 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
8710 return err;8710 return err;
8711 ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);8711 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
8712 copy_const_val(child_val, &tmp, false);8712 copy_const_val(child_val, &tmp, false);
8713 return ErrorNone;8713 return ErrorNone;
8714}8714}
87158715
8716ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,8716ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
8717 AstNode *source_node)8717 AstNode *source_node)
8718{8718{
8719 Error err;8719 Error err;
8720 ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val);8720 ZigValue *val = const_ptr_pointee_unchecked(codegen, const_val);
8721 assert(val != nullptr);8721 assert(val != nullptr);
8722 assert(const_val->type->id == ZigTypeIdPointer);8722 assert(const_val->type->id == ZigTypeIdPointer);
8723 ZigType *expected_type = const_val->type->data.pointer.child_type;8723 ZigType *expected_type = const_val->type->data.pointer.child_type;
...@@ -8740,7 +8740,7 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal...@@ -8740,7 +8740,7 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
8740 return val;8740 return val;
8741}8741}
87428742
8743static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {8743static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
8744 IrBasicBlock *bb = exec->basic_block_list.at(0);8744 IrBasicBlock *bb = exec->basic_block_list.at(0);
8745 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {8745 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
8746 IrInstruction *instruction = bb->instruction_list.at(i);8746 IrInstruction *instruction = bb->instruction_list.at(i);
...@@ -8783,14 +8783,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so...@@ -8783,14 +8783,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
8783 return true;8783 return true;
8784}8784}
87858785
8786static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {8786static bool const_val_fits_in_num_lit(ZigValue *const_val, ZigType *num_lit_type) {
8787 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&8787 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
8788 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||8788 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
8789 (num_lit_type->id == ZigTypeIdComptimeInt &&8789 (num_lit_type->id == ZigTypeIdComptimeInt &&
8790 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));8790 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
8791}8791}
87928792
8793static bool float_has_fraction(ConstExprValue *const_val) {8793static bool float_has_fraction(ZigValue *const_val) {
8794 if (const_val->type->id == ZigTypeIdComptimeFloat) {8794 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8795 return bigfloat_has_fraction(&const_val->data.x_bigfloat);8795 return bigfloat_has_fraction(&const_val->data.x_bigfloat);
8796 } else if (const_val->type->id == ZigTypeIdFloat) {8796 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8818,7 +8818,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {...@@ -8818,7 +8818,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {
8818 }8818 }
8819}8819}
88208820
8821static void float_append_buf(Buf *buf, ConstExprValue *const_val) {8821static void float_append_buf(Buf *buf, ZigValue *const_val) {
8822 if (const_val->type->id == ZigTypeIdComptimeFloat) {8822 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8823 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);8823 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
8824 } else if (const_val->type->id == ZigTypeIdFloat) {8824 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8856,7 +8856,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {...@@ -8856,7 +8856,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
8856 }8856 }
8857}8857}
88588858
8859static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {8859static void float_init_bigint(BigInt *bigint, ZigValue *const_val) {
8860 if (const_val->type->id == ZigTypeIdComptimeFloat) {8860 if (const_val->type->id == ZigTypeIdComptimeFloat) {
8861 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);8861 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
8862 } else if (const_val->type->id == ZigTypeIdFloat) {8862 } else if (const_val->type->id == ZigTypeIdFloat) {
...@@ -8903,7 +8903,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {...@@ -8903,7 +8903,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
8903 }8903 }
8904}8904}
89058905
8906static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {8906static void float_init_bigfloat(ZigValue *dest_val, BigFloat *bigfloat) {
8907 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8907 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8908 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);8908 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
8909 } else if (dest_val->type->id == ZigTypeIdFloat) {8909 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8930,7 +8930,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {...@@ -8930,7 +8930,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
8930 }8930 }
8931}8931}
89328932
8933static void float_init_f16(ConstExprValue *dest_val, float16_t x) {8933static void float_init_f16(ZigValue *dest_val, float16_t x) {
8934 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8934 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8935 bigfloat_init_16(&dest_val->data.x_bigfloat, x);8935 bigfloat_init_16(&dest_val->data.x_bigfloat, x);
8936 } else if (dest_val->type->id == ZigTypeIdFloat) {8936 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8955,7 +8955,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {...@@ -8955,7 +8955,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
8955 }8955 }
8956}8956}
89578957
8958static void float_init_f32(ConstExprValue *dest_val, float x) {8958static void float_init_f32(ZigValue *dest_val, float x) {
8959 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8959 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8960 bigfloat_init_32(&dest_val->data.x_bigfloat, x);8960 bigfloat_init_32(&dest_val->data.x_bigfloat, x);
8961 } else if (dest_val->type->id == ZigTypeIdFloat) {8961 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -8984,7 +8984,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {...@@ -8984,7 +8984,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
8984 }8984 }
8985}8985}
89868986
8987static void float_init_f64(ConstExprValue *dest_val, double x) {8987static void float_init_f64(ZigValue *dest_val, double x) {
8988 if (dest_val->type->id == ZigTypeIdComptimeFloat) {8988 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
8989 bigfloat_init_64(&dest_val->data.x_bigfloat, x);8989 bigfloat_init_64(&dest_val->data.x_bigfloat, x);
8990 } else if (dest_val->type->id == ZigTypeIdFloat) {8990 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -9013,7 +9013,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {...@@ -9013,7 +9013,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
9013 }9013 }
9014}9014}
90159015
9016static void float_init_f128(ConstExprValue *dest_val, float128_t x) {9016static void float_init_f128(ZigValue *dest_val, float128_t x) {
9017 if (dest_val->type->id == ZigTypeIdComptimeFloat) {9017 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
9018 bigfloat_init_128(&dest_val->data.x_bigfloat, x);9018 bigfloat_init_128(&dest_val->data.x_bigfloat, x);
9019 } else if (dest_val->type->id == ZigTypeIdFloat) {9019 } else if (dest_val->type->id == ZigTypeIdFloat) {
...@@ -9046,7 +9046,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {...@@ -9046,7 +9046,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
9046 }9046 }
9047}9047}
90489048
9049static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {9049static void float_init_float(ZigValue *dest_val, ZigValue *src_val) {
9050 if (src_val->type->id == ZigTypeIdComptimeFloat) {9050 if (src_val->type->id == ZigTypeIdComptimeFloat) {
9051 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);9051 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
9052 } else if (src_val->type->id == ZigTypeIdFloat) {9052 } else if (src_val->type->id == ZigTypeIdFloat) {
...@@ -9071,7 +9071,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)...@@ -9071,7 +9071,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
9071 }9071 }
9072}9072}
90739073
9074static bool float_is_nan(ConstExprValue *op) {9074static bool float_is_nan(ZigValue *op) {
9075 if (op->type->id == ZigTypeIdComptimeFloat) {9075 if (op->type->id == ZigTypeIdComptimeFloat) {
9076 return bigfloat_is_nan(&op->data.x_bigfloat);9076 return bigfloat_is_nan(&op->data.x_bigfloat);
9077 } else if (op->type->id == ZigTypeIdFloat) {9077 } else if (op->type->id == ZigTypeIdFloat) {
...@@ -9092,7 +9092,7 @@ static bool float_is_nan(ConstExprValue *op) {...@@ -9092,7 +9092,7 @@ static bool float_is_nan(ConstExprValue *op) {
9092 }9092 }
9093}9093}
90949094
9095static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {9095static Cmp float_cmp(ZigValue *op1, ZigValue *op2) {
9096 assert(op1->type == op2->type);9096 assert(op1->type == op2->type);
9097 if (op1->type->id == ZigTypeIdComptimeFloat) {9097 if (op1->type->id == ZigTypeIdComptimeFloat) {
9098 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);9098 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
...@@ -9138,7 +9138,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {...@@ -9138,7 +9138,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
9138 }9138 }
9139}9139}
91409140
9141static Cmp float_cmp_zero(ConstExprValue *op) {9141static Cmp float_cmp_zero(ZigValue *op) {
9142 if (op->type->id == ZigTypeIdComptimeFloat) {9142 if (op->type->id == ZigTypeIdComptimeFloat) {
9143 return bigfloat_cmp_zero(&op->data.x_bigfloat);9143 return bigfloat_cmp_zero(&op->data.x_bigfloat);
9144 } else if (op->type->id == ZigTypeIdFloat) {9144 } else if (op->type->id == ZigTypeIdFloat) {
...@@ -9188,7 +9188,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {...@@ -9188,7 +9188,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
9188 }9188 }
9189}9189}
91909190
9191static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9191static void float_add(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9192 assert(op1->type == op2->type);9192 assert(op1->type == op2->type);
9193 out_val->type = op1->type;9193 out_val->type = op1->type;
9194 if (op1->type->id == ZigTypeIdComptimeFloat) {9194 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9215,7 +9215,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9215,7 +9215,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9215 }9215 }
9216}9216}
92179217
9218static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9218static void float_sub(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9219 assert(op1->type == op2->type);9219 assert(op1->type == op2->type);
9220 out_val->type = op1->type;9220 out_val->type = op1->type;
9221 if (op1->type->id == ZigTypeIdComptimeFloat) {9221 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9242,7 +9242,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9242,7 +9242,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9242 }9242 }
9243}9243}
92449244
9245static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9245static void float_mul(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9246 assert(op1->type == op2->type);9246 assert(op1->type == op2->type);
9247 out_val->type = op1->type;9247 out_val->type = op1->type;
9248 if (op1->type->id == ZigTypeIdComptimeFloat) {9248 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9269,7 +9269,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9269,7 +9269,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9269 }9269 }
9270}9270}
92719271
9272static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9272static void float_div(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9273 assert(op1->type == op2->type);9273 assert(op1->type == op2->type);
9274 out_val->type = op1->type;9274 out_val->type = op1->type;
9275 if (op1->type->id == ZigTypeIdComptimeFloat) {9275 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9296,7 +9296,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9296,7 +9296,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9296 }9296 }
9297}9297}
92989298
9299static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9299static void float_div_trunc(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9300 assert(op1->type == op2->type);9300 assert(op1->type == op2->type);
9301 out_val->type = op1->type;9301 out_val->type = op1->type;
9302 if (op1->type->id == ZigTypeIdComptimeFloat) {9302 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9325,7 +9325,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -9325,7 +9325,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
9325 }9325 }
9326}9326}
93279327
9328static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9328static void float_div_floor(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9329 assert(op1->type == op2->type);9329 assert(op1->type == op2->type);
9330 out_val->type = op1->type;9330 out_val->type = op1->type;
9331 if (op1->type->id == ZigTypeIdComptimeFloat) {9331 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9354,7 +9354,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -9354,7 +9354,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
9354 }9354 }
9355}9355}
93569356
9357static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9357static void float_rem(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9358 assert(op1->type == op2->type);9358 assert(op1->type == op2->type);
9359 out_val->type = op1->type;9359 out_val->type = op1->type;
9360 if (op1->type->id == ZigTypeIdComptimeFloat) {9360 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9399,7 +9399,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*...@@ -9399,7 +9399,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
9399 f128M_sub(a, c, c);9399 f128M_sub(a, c, c);
9400}9400}
94019401
9402static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {9402static void float_mod(ZigValue *out_val, ZigValue *op1, ZigValue *op2) {
9403 assert(op1->type == op2->type);9403 assert(op1->type == op2->type);
9404 out_val->type = op1->type;9404 out_val->type = op1->type;
9405 if (op1->type->id == ZigTypeIdComptimeFloat) {9405 if (op1->type->id == ZigTypeIdComptimeFloat) {
...@@ -9426,7 +9426,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -9426,7 +9426,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
9426 }9426 }
9427}9427}
94289428
9429static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {9429static void float_negate(ZigValue *out_val, ZigValue *op) {
9430 out_val->type = op->type;9430 out_val->type = op->type;
9431 if (op->type->id == ZigTypeIdComptimeFloat) {9431 if (op->type->id == ZigTypeIdComptimeFloat) {
9432 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);9432 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
...@@ -9457,7 +9457,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {...@@ -9457,7 +9457,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
9457 }9457 }
9458}9458}
94599459
9460void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {9460void float_write_ieee597(ZigValue *op, uint8_t *buf, bool is_big_endian) {
9461 if (op->type->id == ZigTypeIdFloat) {9461 if (op->type->id == ZigTypeIdFloat) {
9462 switch (op->type->data.floating.bit_count) {9462 switch (op->type->data.floating.bit_count) {
9463 case 16:9463 case 16:
...@@ -9480,7 +9480,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {...@@ -9480,7 +9480,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
9480 }9480 }
9481}9481}
94829482
9483void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {9483void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
9484 if (val->type->id == ZigTypeIdFloat) {9484 if (val->type->id == ZigTypeIdFloat) {
9485 switch (val->type->data.floating.bit_count) {9485 switch (val->type->data.floating.bit_count) {
9486 case 16:9486 case 16:
...@@ -9510,7 +9510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -9510,7 +9510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
9510 return false;9510 return false;
9511 }9511 }
95129512
9513 ConstExprValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);9513 ZigValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef);
9514 if (const_val == nullptr)9514 if (const_val == nullptr)
9515 return false;9515 return false;
95169516
...@@ -10984,9 +10984,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10984,9 +10984,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10984 }10984 }
10985}10985}
1098610986
10987static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {10987static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) {
10988 ConstGlobalRefs *global_refs = dest->global_refs;10988 ConstGlobalRefs *global_refs = dest->global_refs;
10989 memcpy(dest, src, sizeof(ConstExprValue));10989 memcpy(dest, src, sizeof(ZigValue));
10990 if (!same_global_refs) {10990 if (!same_global_refs) {
10991 dest->global_refs = global_refs;10991 dest->global_refs = global_refs;
10992 if (src->special != ConstValSpecialStatic)10992 if (src->special != ConstValSpecialStatic)
...@@ -11002,8 +11002,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -11002,8 +11002,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
1100211002
11003static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,11003static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
11004 CastOp cast_op,11004 CastOp cast_op,
11005 ConstExprValue *other_val, ZigType *other_type,11005 ZigValue *other_val, ZigType *other_type,
11006 ConstExprValue *const_val, ZigType *new_type)11006 ZigValue *const_val, ZigType *new_type)
11007{11007{
11008 const_val->special = other_val->special;11008 const_val->special = other_val->special;
1100911009
...@@ -11145,7 +11145,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -11145,7 +11145,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
11145 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));11145 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));
1114611146
11147 if (instr_is_comptime(value)) {11147 if (instr_is_comptime(value)) {
11148 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);11148 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);
11149 if (pointee == nullptr)11149 if (pointee == nullptr)
11150 return ira->codegen->invalid_instruction;11150 return ira->codegen->invalid_instruction;
11151 if (pointee->special != ConstValSpecialRuntime) {11151 if (pointee->special != ConstValSpecialRuntime) {
...@@ -11178,7 +11178,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -11178,7 +11178,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11178 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type));11178 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type));
1117911179
11180 if (instr_is_comptime(array_ptr)) {11180 if (instr_is_comptime(array_ptr)) {
11181 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node);11181 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node);
11182 if (pointee == nullptr)11182 if (pointee == nullptr)
11183 return ira->codegen->invalid_instruction;11183 return ira->codegen->invalid_instruction;
11184 if (pointee->special != ConstValSpecialRuntime) {11184 if (pointee->special != ConstValSpecialRuntime) {
...@@ -11443,13 +11443,13 @@ static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_in...@@ -11443,13 +11443,13 @@ static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_in
11443}11443}
1144411444
11445static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,11445static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
11446 ConstExprValue *pointee, ZigType *pointee_type,11446 ZigValue *pointee, ZigType *pointee_type,
11447 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)11447 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
11448{11448{
11449 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,11449 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
11450 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);11450 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
11451 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);11451 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);
11452 ConstExprValue *const_val = &const_instr->value;11452 ZigValue *const_val = &const_instr->value;
11453 const_val->data.x_ptr.special = ConstPtrSpecialRef;11453 const_val->data.x_ptr.special = ConstPtrSpecialRef;
11454 const_val->data.x_ptr.mut = ptr_mut;11454 const_val->data.x_ptr.mut = ptr_mut;
11455 const_val->data.x_ptr.data.ref.pointee = pointee;11455 const_val->data.x_ptr.data.ref.pointee = pointee;
...@@ -11457,7 +11457,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -11457,7 +11457,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
11457}11457}
1145811458
11459static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,11459static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11460 ConstExprValue *val, UndefAllowed undef_allowed)11460 ZigValue *val, UndefAllowed undef_allowed)
11461{11461{
11462 Error err;11462 Error err;
11463 for (;;) {11463 for (;;) {
...@@ -11490,7 +11490,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -11490,7 +11490,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
11490 }11490 }
11491}11491}
1149211492
11493static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {11493static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
11494 Error err;11494 Error err;
11495 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,11495 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
11496 &value->value, undef_allowed)))11496 &value->value, undef_allowed)))
...@@ -11500,7 +11500,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un...@@ -11500,7 +11500,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
11500 return &value->value;11500 return &value->value;
11501}11501}
1150211502
11503ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,11503ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
11504 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,11504 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
11505 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,11505 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
11506 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)11506 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
...@@ -11554,7 +11554,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -11554,7 +11554,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
11554 fprintf(stderr, "}\n");11554 fprintf(stderr, "}\n");
11555 }11555 }
1155611556
11557 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);11557 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
11558 if (type_is_invalid(result->type))11558 if (type_is_invalid(result->type))
11559 return &codegen->invalid_instruction->value;11559 return &codegen->invalid_instruction->value;
1156011560
...@@ -11574,7 +11574,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu...@@ -11574,7 +11574,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
11574 return nullptr;11574 return nullptr;
11575 }11575 }
1157611576
11577 ConstExprValue *const_val = ir_resolve_const(ira, err_value, UndefBad);11577 ZigValue *const_val = ir_resolve_const(ira, err_value, UndefBad);
11578 if (!const_val)11578 if (!const_val)
11579 return nullptr;11579 return nullptr;
1158011580
...@@ -11583,7 +11583,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu...@@ -11583,7 +11583,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
11583}11583}
1158411584
11585static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,11585static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
11586 ConstExprValue *val)11586 ZigValue *val)
11587{11587{
11588 Error err;11588 Error err;
11589 if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad)))11589 if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad)))
...@@ -11593,7 +11593,7 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN...@@ -11593,7 +11593,7 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
11593 return val->data.x_type;11593 return val->data.x_type;
11594}11594}
1159511595
11596static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {11596static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
11597 if (type_is_invalid(type_value->value.type))11597 if (type_is_invalid(type_value->value.type))
11598 return nullptr;11598 return nullptr;
1159911599
...@@ -11614,7 +11614,7 @@ static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_...@@ -11614,7 +11614,7 @@ static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_
11614}11614}
1161511615
11616static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {11616static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
11617 ConstExprValue *val = ir_resolve_type_lazy(ira, type_value);11617 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
11618 if (val == nullptr)11618 if (val == nullptr)
11619 return ira->codegen->builtin_types.entry_invalid;11619 return ira->codegen->builtin_types.entry_invalid;
1162011620
...@@ -11674,7 +11674,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour...@@ -11674,7 +11674,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
11674 return ira->codegen->builtin_types.entry_invalid;11674 return ira->codegen->builtin_types.entry_invalid;
11675 }11675 }
1167611676
11677 ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad);11677 ZigValue *const_val = ir_resolve_const(ira, type_value, UndefBad);
11678 if (!const_val)11678 if (!const_val)
11679 return ira->codegen->builtin_types.entry_invalid;11679 return ira->codegen->builtin_types.entry_invalid;
1168011680
...@@ -11703,7 +11703,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -11703,7 +11703,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
11703 return nullptr;11703 return nullptr;
11704 }11704 }
1170511705
11706 ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);11706 ZigValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);
11707 if (!const_val)11707 if (!const_val)
11708 return nullptr;11708 return nullptr;
1170911709
...@@ -11725,7 +11725,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -11725,7 +11725,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
11725 if (type_is_invalid(casted_payload->value.type))11725 if (type_is_invalid(casted_payload->value.type))
11726 return ira->codegen->invalid_instruction;11726 return ira->codegen->invalid_instruction;
1172711727
11728 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk);11728 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
11729 if (!val)11729 if (!val)
11730 return ira->codegen->invalid_instruction;11730 return ira->codegen->invalid_instruction;
1173111731
...@@ -11768,11 +11768,11 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -11768,11 +11768,11 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
11768 if (type_is_invalid(casted_payload->value.type))11768 if (type_is_invalid(casted_payload->value.type))
11769 return ira->codegen->invalid_instruction;11769 return ira->codegen->invalid_instruction;
1177011770
11771 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);11771 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
11772 if (!val)11772 if (!val)
11773 return ira->codegen->invalid_instruction;11773 return ira->codegen->invalid_instruction;
1177411774
11775 ConstExprValue *err_set_val = create_const_vals(1);11775 ZigValue *err_set_val = create_const_vals(1);
11776 err_set_val->type = err_set_type;11776 err_set_val->type = err_set_type;
11777 err_set_val->special = ConstValSpecialStatic;11777 err_set_val->special = ConstValSpecialStatic;
11778 err_set_val->data.x_err_set = nullptr;11778 err_set_val->data.x_err_set = nullptr;
...@@ -11809,7 +11809,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -11809,7 +11809,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
11809 assert(wanted_type->id == ZigTypeIdErrorSet);11809 assert(wanted_type->id == ZigTypeIdErrorSet);
1181011810
11811 if (instr_is_comptime(value)) {11811 if (instr_is_comptime(value)) {
11812 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11812 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11813 if (!val)11813 if (!val)
11814 return ira->codegen->invalid_instruction;11814 return ira->codegen->invalid_instruction;
1181511815
...@@ -11849,7 +11849,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc...@@ -11849,7 +11849,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
11849 IrInstruction *frame_ptr, ZigType *wanted_type)11849 IrInstruction *frame_ptr, ZigType *wanted_type)
11850{11850{
11851 if (instr_is_comptime(frame_ptr)) {11851 if (instr_is_comptime(frame_ptr)) {
11852 ConstExprValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);11852 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
11853 if (ptr_val == nullptr)11853 if (ptr_val == nullptr)
11854 return ira->codegen->invalid_instruction;11854 return ira->codegen->invalid_instruction;
1185511855
...@@ -11887,11 +11887,11 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -11887,11 +11887,11 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
11887 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);11887 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1188811888
11889 if (instr_is_comptime(casted_value)) {11889 if (instr_is_comptime(casted_value)) {
11890 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);11890 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
11891 if (!val)11891 if (!val)
11892 return ira->codegen->invalid_instruction;11892 return ira->codegen->invalid_instruction;
1189311893
11894 ConstExprValue *err_set_val = create_const_vals(1);11894 ZigValue *err_set_val = create_const_vals(1);
11895 err_set_val->special = ConstValSpecialStatic;11895 err_set_val->special = ConstValSpecialStatic;
11896 err_set_val->type = wanted_type->data.error_union.err_set_type;11896 err_set_val->type = wanted_type->data.error_union.err_set_type;
11897 err_set_val->data.x_err_set = val->data.x_err_set;11897 err_set_val->data.x_err_set = val->data.x_err_set;
...@@ -11926,7 +11926,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -11926,7 +11926,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
11926 assert(wanted_type->id == ZigTypeIdOptional);11926 assert(wanted_type->id == ZigTypeIdOptional);
11927 assert(instr_is_comptime(value));11927 assert(instr_is_comptime(value));
1192811928
11929 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11929 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11930 assert(val != nullptr);11930 assert(val != nullptr);
1193111931
11932 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11932 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
...@@ -11948,7 +11948,7 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction...@@ -11948,7 +11948,7 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
11948 assert(wanted_type->data.pointer.ptr_len == PtrLenC);11948 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
11949 assert(instr_is_comptime(value));11949 assert(instr_is_comptime(value));
1195011950
11951 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);11951 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
11952 assert(val != nullptr);11952 assert(val != nullptr);
1195311953
11954 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11954 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
...@@ -11969,7 +11969,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -11969,7 +11969,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
11969 return ira->codegen->invalid_instruction;11969 return ira->codegen->invalid_instruction;
1197011970
11971 if (instr_is_comptime(value)) {11971 if (instr_is_comptime(value)) {
11972 ConstExprValue *val = ir_resolve_const(ira, value, LazyOk);11972 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
11973 if (!val)11973 if (!val)
11974 return ira->codegen->invalid_instruction;11974 return ira->codegen->invalid_instruction;
11975 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,11975 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,
...@@ -12098,7 +12098,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12098,7 +12098,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12098 }12098 }
1209912099
12100 if (instr_is_comptime(enum_target)) {12100 if (instr_is_comptime(enum_target)) {
12101 ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad);12101 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
12102 if (!val)12102 if (!val)
12103 return ira->codegen->invalid_instruction;12103 return ira->codegen->invalid_instruction;
12104 IrInstruction *result = ir_const(ira, source_instr, tag_type);12104 IrInstruction *result = ir_const(ira, source_instr, tag_type);
...@@ -12120,7 +12120,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12120,7 +12120,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12120 assert(wanted_type == target->value.type->data.unionation.tag_type);12120 assert(wanted_type == target->value.type->data.unionation.tag_type);
1212112121
12122 if (instr_is_comptime(target)) {12122 if (instr_is_comptime(target)) {
12123 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12123 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12124 if (!val)12124 if (!val)
12125 return ira->codegen->invalid_instruction;12125 return ira->codegen->invalid_instruction;
12126 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12126 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
...@@ -12170,7 +12170,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12170,7 +12170,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12170 return ira->codegen->invalid_instruction;12170 return ira->codegen->invalid_instruction;
1217112171
12172 if (instr_is_comptime(target)) {12172 if (instr_is_comptime(target)) {
12173 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12173 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12174 if (!val)12174 if (!val)
12175 return ira->codegen->invalid_instruction;12175 return ira->codegen->invalid_instruction;
12176 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);12176 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
...@@ -12245,7 +12245,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12245,7 +12245,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12245 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);12245 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1224612246
12247 if (instr_is_comptime(target)) {12247 if (instr_is_comptime(target)) {
12248 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12248 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12249 if (!val)12249 if (!val)
12250 return ira->codegen->invalid_instruction;12250 return ira->codegen->invalid_instruction;
12251 if (wanted_type->id == ZigTypeIdInt) {12251 if (wanted_type->id == ZigTypeIdInt) {
...@@ -12313,7 +12313,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12313,7 +12313,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12313 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);12313 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
1231412314
12315 if (instr_is_comptime(target)) {12315 if (instr_is_comptime(target)) {
12316 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12316 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12317 if (!val)12317 if (!val)
12318 return ira->codegen->invalid_instruction;12318 return ira->codegen->invalid_instruction;
1231912319
...@@ -12343,7 +12343,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12343,7 +12343,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12343static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,12343static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
12344 IrInstruction *target, ZigType *wanted_type)12344 IrInstruction *target, ZigType *wanted_type)
12345{12345{
12346 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12346 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12347 if (!val)12347 if (!val)
12348 return ira->codegen->invalid_instruction;12348 return ira->codegen->invalid_instruction;
1234912349
...@@ -12366,7 +12366,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12366,7 +12366,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12366 assert(wanted_type->id == ZigTypeIdErrorSet);12366 assert(wanted_type->id == ZigTypeIdErrorSet);
1236712367
12368 if (instr_is_comptime(target)) {12368 if (instr_is_comptime(target)) {
12369 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12369 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12370 if (!val)12370 if (!val)
12371 return ira->codegen->invalid_instruction;12371 return ira->codegen->invalid_instruction;
1237212372
...@@ -12430,7 +12430,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12430,7 +12430,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12430 ZigType *err_type = target->value.type;12430 ZigType *err_type = target->value.type;
1243112431
12432 if (instr_is_comptime(target)) {12432 if (instr_is_comptime(target)) {
12433 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12433 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12434 if (!val)12434 if (!val)
12435 return ira->codegen->invalid_instruction;12435 return ira->codegen->invalid_instruction;
1243612436
...@@ -12511,16 +12511,16 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -12511,16 +12511,16 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
12511 assert(array_type->data.array.len == 1);12511 assert(array_type->data.array.len == 1);
1251212512
12513 if (instr_is_comptime(target)) {12513 if (instr_is_comptime(target)) {
12514 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);12514 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12515 if (!val)12515 if (!val)
12516 return ira->codegen->invalid_instruction;12516 return ira->codegen->invalid_instruction;
1251712517
12518 assert(val->type->id == ZigTypeIdPointer);12518 assert(val->type->id == ZigTypeIdPointer);
12519 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);12519 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
12520 if (pointee == nullptr)12520 if (pointee == nullptr)
12521 return ira->codegen->invalid_instruction;12521 return ira->codegen->invalid_instruction;
12522 if (pointee->special != ConstValSpecialRuntime) {12522 if (pointee->special != ConstValSpecialRuntime) {
12523 ConstExprValue *array_val = create_const_vals(1);12523 ZigValue *array_val = create_const_vals(1);
12524 array_val->special = ConstValSpecialStatic;12524 array_val->special = ConstValSpecialStatic;
12525 array_val->type = array_type;12525 array_val->type = array_type;
12526 array_val->data.x_array.special = ConstArraySpecialNone;12526 array_val->data.x_array.special = ConstArraySpecialNone;
...@@ -12724,7 +12724,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *...@@ -12724,7 +12724,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
12724 IrInstruction *array, ZigType *vector_type)12724 IrInstruction *array, ZigType *vector_type)
12725{12725{
12726 if (instr_is_comptime(array)) {12726 if (instr_is_comptime(array)) {
12727 // arrays and vectors have the same ConstExprValue representation12727 // arrays and vectors have the same ZigValue representation
12728 IrInstruction *result = ir_const(ira, source_instr, vector_type);12728 IrInstruction *result = ir_const(ira, source_instr, vector_type);
12729 copy_const_val(&result->value, &array->value, false);12729 copy_const_val(&result->value, &array->value, false);
12730 result->value.type = vector_type;12730 result->value.type = vector_type;
...@@ -12737,7 +12737,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -12737,7 +12737,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
12737 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)12737 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)
12738{12738{
12739 if (instr_is_comptime(vector)) {12739 if (instr_is_comptime(vector)) {
12740 // arrays and vectors have the same ConstExprValue representation12740 // arrays and vectors have the same ZigValue representation
12741 IrInstruction *result = ir_const(ira, source_instr, array_type);12741 IrInstruction *result = ir_const(ira, source_instr, array_type);
12742 copy_const_val(&result->value, &vector->value, false);12742 copy_const_val(&result->value, &vector->value, false);
12743 result->value.type = array_type;12743 result->value.type = array_type;
...@@ -13576,7 +13576,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13576,7 +13576,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13576 return ira->codegen->invalid_instruction;13576 return ira->codegen->invalid_instruction;
13577 }13577 }
13578 if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {13578 if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {
13579 ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);13579 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);
13580 if (child_type == ira->codegen->builtin_types.entry_var) {13580 if (child_type == ira->codegen->builtin_types.entry_var) {
13581 child_type = pointee->type;13581 child_type = pointee->type;
13582 }13582 }
...@@ -13637,7 +13637,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -13637,7 +13637,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
13637}13637}
1363813638
13639static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,13639static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13640 ConstExprValue *const_val, uint32_t *out)13640 ZigValue *const_val, uint32_t *out)
13641{13641{
13642 Error err;13642 Error err;
13643 if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad)))13643 if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad)))
...@@ -13696,7 +13696,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i...@@ -13696,7 +13696,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
13696 if (type_is_invalid(casted_value->value.type))13696 if (type_is_invalid(casted_value->value.type))
13697 return false;13697 return false;
1369813698
13699 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13699 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13700 if (!const_val)13700 if (!const_val)
13701 return false;13701 return false;
1370213702
...@@ -13716,7 +13716,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {...@@ -13716,7 +13716,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
13716 if (type_is_invalid(casted_value->value.type))13716 if (type_is_invalid(casted_value->value.type))
13717 return false;13717 return false;
1371813718
13719 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13719 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13720 if (!const_val)13720 if (!const_val)
13721 return false;13721 return false;
1372213722
...@@ -13736,7 +13736,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -13736,7 +13736,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
13736 if (type_is_invalid(value->value.type))13736 if (type_is_invalid(value->value.type))
13737 return false;13737 return false;
1373813738
13739 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");13739 ZigValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
13740 assert(atomic_order_val->type->id == ZigTypeIdMetaType);13740 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
13741 ZigType *atomic_order_type = atomic_order_val->data.x_type;13741 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1374213742
...@@ -13744,7 +13744,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -13744,7 +13744,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
13744 if (type_is_invalid(casted_value->value.type))13744 if (type_is_invalid(casted_value->value.type))
13745 return false;13745 return false;
1374613746
13747 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13747 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13748 if (!const_val)13748 if (!const_val)
13749 return false;13749 return false;
1375013750
...@@ -13756,7 +13756,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -13756,7 +13756,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
13756 if (type_is_invalid(value->value.type))13756 if (type_is_invalid(value->value.type))
13757 return false;13757 return false;
1375813758
13759 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");13759 ZigValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
13760 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);13760 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
13761 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;13761 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1376213762
...@@ -13764,7 +13764,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -13764,7 +13764,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
13764 if (type_is_invalid(casted_value->value.type))13764 if (type_is_invalid(casted_value->value.type))
13765 return false;13765 return false;
1376613766
13767 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13767 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13768 if (!const_val)13768 if (!const_val)
13769 return false;13769 return false;
1377013770
...@@ -13776,7 +13776,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -13776,7 +13776,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
13776 if (type_is_invalid(value->value.type))13776 if (type_is_invalid(value->value.type))
13777 return false;13777 return false;
1377813778
13779 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");13779 ZigValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
13780 assert(global_linkage_val->type->id == ZigTypeIdMetaType);13780 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
13781 ZigType *global_linkage_type = global_linkage_val->data.x_type;13781 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1378213782
...@@ -13784,7 +13784,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -13784,7 +13784,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
13784 if (type_is_invalid(casted_value->value.type))13784 if (type_is_invalid(casted_value->value.type))
13785 return false;13785 return false;
1378613786
13787 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13787 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13788 if (!const_val)13788 if (!const_val)
13789 return false;13789 return false;
1379013790
...@@ -13796,7 +13796,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -13796,7 +13796,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
13796 if (type_is_invalid(value->value.type))13796 if (type_is_invalid(value->value.type))
13797 return false;13797 return false;
1379813798
13799 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");13799 ZigValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
13800 assert(float_mode_val->type->id == ZigTypeIdMetaType);13800 assert(float_mode_val->type->id == ZigTypeIdMetaType);
13801 ZigType *float_mode_type = float_mode_val->data.x_type;13801 ZigType *float_mode_type = float_mode_val->data.x_type;
1380213802
...@@ -13804,7 +13804,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -13804,7 +13804,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
13804 if (type_is_invalid(casted_value->value.type))13804 if (type_is_invalid(casted_value->value.type))
13805 return false;13805 return false;
1380613806
13807 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13807 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13808 if (!const_val)13808 if (!const_val)
13809 return false;13809 return false;
1381013810
...@@ -13823,15 +13823,15 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13823,15 +13823,15 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13823 if (type_is_invalid(casted_value->value.type))13823 if (type_is_invalid(casted_value->value.type))
13824 return nullptr;13824 return nullptr;
1382513825
13826 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);13826 ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
13827 if (!const_val)13827 if (!const_val)
13828 return nullptr;13828 return nullptr;
1382913829
13830 ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];13830 ZigValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13831 ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index];13831 ZigValue *len_field = const_val->data.x_struct.fields[slice_len_index];
1383213832
13833 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);13833 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
13834 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;13834 ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
13835 expand_undef_array(ira->codegen, array_val);13835 expand_undef_array(ira->codegen, array_val);
13836 size_t len = bigint_as_usize(&len_field->data.x_bigint);13836 size_t len = bigint_as_usize(&len_field->data.x_bigint);
13837 if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) {13837 if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) {
...@@ -13841,7 +13841,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13841,7 +13841,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13841 buf_resize(result, len);13841 buf_resize(result, len);
13842 for (size_t i = 0; i < len; i += 1) {13842 for (size_t i = 0; i < len; i += 1) {
13843 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;13843 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];13844 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
13845 if (char_val->special == ConstValSpecialUndef) {13845 if (char_val->special == ConstValSpecialUndef) {
13846 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));13846 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
13847 return nullptr;13847 return nullptr;
...@@ -13934,11 +13934,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -13934,11 +13934,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
13934 return ira->codegen->invalid_instruction;13934 return ira->codegen->invalid_instruction;
1393513935
13936 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {13936 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
13937 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);13937 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
13938 if (op1_val == nullptr)13938 if (op1_val == nullptr)
13939 return ira->codegen->invalid_instruction;13939 return ira->codegen->invalid_instruction;
1394013940
13941 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);13941 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
13942 if (op2_val == nullptr)13942 if (op2_val == nullptr)
13943 return ira->codegen->invalid_instruction;13943 return ira->codegen->invalid_instruction;
1394413944
...@@ -13981,7 +13981,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {...@@ -13981,7 +13981,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
13981 }13981 }
13982}13982}
1398313983
13984static bool optional_value_is_null(ConstExprValue *val) {13984static bool optional_value_is_null(ZigValue *val) {
13985 assert(val->special == ConstValSpecialStatic);13985 assert(val->special == ConstValSpecialStatic);
13986 if (get_codegen_ptr_type(val->type) != nullptr) {13986 if (get_codegen_ptr_type(val->type) != nullptr) {
13987 if (val->data.x_ptr.special == ConstPtrSpecialNull) {13987 if (val->data.x_ptr.special == ConstPtrSpecialNull) {
...@@ -13999,7 +13999,7 @@ static bool optional_value_is_null(ConstExprValue *val) {...@@ -13999,7 +13999,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
13999}13999}
1400014000
14001static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,14001static 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,14002 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,
14003 bool one_possible_value) {14003 bool one_possible_value) {
14004 if (op1_val->special == ConstValSpecialUndef ||14004 if (op1_val->special == ConstValSpecialUndef ||
14005 op2_val->special == ConstValSpecialUndef)14005 op2_val->special == ConstValSpecialUndef)
...@@ -14052,7 +14052,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t...@@ -14052,7 +14052,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14052}14052}
1405314053
14054// Returns ErrorNotLazy when the value cannot be determined14054// Returns ErrorNotLazy when the value cannot be determined
14055static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *result) {14055static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
14056 Error err;14056 Error err;
1405714057
14058 switch (val->special) {14058 switch (val->special) {
...@@ -14124,7 +14124,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14124,7 +14124,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14124 zig_unreachable();14124 zig_unreachable();
14125 }14125 }
14126 if (instr_is_comptime(maybe_op)) {14126 if (instr_is_comptime(maybe_op)) {
14127 ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);14127 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
14128 if (!maybe_val)14128 if (!maybe_val)
14129 return ira->codegen->invalid_instruction;14129 return ira->codegen->invalid_instruction;
14130 bool is_null = optional_value_is_null(maybe_val);14130 bool is_null = optional_value_is_null(maybe_val);
...@@ -14159,7 +14159,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14159,7 +14159,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14159 zig_unreachable();14159 zig_unreachable();
14160 }14160 }
14161 if (instr_is_comptime(c_ptr_op)) {14161 if (instr_is_comptime(c_ptr_op)) {
14162 ConstExprValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);14162 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
14163 if (!c_ptr_val)14163 if (!c_ptr_val)
14164 return ira->codegen->invalid_instruction;14164 return ira->codegen->invalid_instruction;
14165 if (c_ptr_val->special == ConstValSpecialUndef)14165 if (c_ptr_val->special == ConstValSpecialUndef)
...@@ -14207,11 +14207,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14207,11 +14207,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14207 return ira->codegen->invalid_instruction;14207 return ira->codegen->invalid_instruction;
1420814208
14209 if (instr_is_comptime(casted_union)) {14209 if (instr_is_comptime(casted_union)) {
14210 ConstExprValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);14210 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
14211 if (!const_union_val)14211 if (!const_union_val)
14212 return ira->codegen->invalid_instruction;14212 return ira->codegen->invalid_instruction;
1421314213
14214 ConstExprValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);14214 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
14215 if (!const_enum_val)14215 if (!const_enum_val)
14216 return ira->codegen->invalid_instruction;14216 return ira->codegen->invalid_instruction;
1421714217
...@@ -14282,10 +14282,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14282,10 +14282,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14282 }14282 }
1428314283
14284 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {14284 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
14285 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);14285 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14286 if (op1_val == nullptr)14286 if (op1_val == nullptr)
14287 return ira->codegen->invalid_instruction;14287 return ira->codegen->invalid_instruction;
14288 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);14288 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
14289 if (op2_val == nullptr)14289 if (op2_val == nullptr)
14290 return ira->codegen->invalid_instruction;14290 return ira->codegen->invalid_instruction;
1429114291
...@@ -14430,10 +14430,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14430,10 +14430,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14430 }14430 }
14431never_mind_just_calculate_it_normally:14431never_mind_just_calculate_it_normally:
1443214432
14433 ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);14433 ZigValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
14434 if (op1_val == nullptr)14434 if (op1_val == nullptr)
14435 return ira->codegen->invalid_instruction;14435 return ira->codegen->invalid_instruction;
14436 ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);14436 ZigValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
14437 if (op2_val == nullptr)14437 if (op2_val == nullptr)
14438 return ira->codegen->invalid_instruction;14438 return ira->codegen->invalid_instruction;
14439 if (resolved_type->id != ZigTypeIdVector)14439 if (resolved_type->id != ZigTypeIdVector)
...@@ -14456,7 +14456,7 @@ never_mind_just_calculate_it_normally:...@@ -14456,7 +14456,7 @@ never_mind_just_calculate_it_normally:
1445614456
14457 // some comparisons with unsigned numbers can be evaluated14457 // some comparisons with unsigned numbers can be evaluated
14458 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {14458 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
14459 ConstExprValue *known_left_val;14459 ZigValue *known_left_val;
14460 IrBinOp flipped_op_id;14460 IrBinOp flipped_op_id;
14461 if (instr_is_comptime(casted_op1)) {14461 if (instr_is_comptime(casted_op1)) {
14462 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);14462 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);
...@@ -14504,7 +14504,7 @@ never_mind_just_calculate_it_normally:...@@ -14504,7 +14504,7 @@ never_mind_just_calculate_it_normally:
14504}14504}
1450514505
14506static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,14506static 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)14507 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
14508{14508{
14509 bool is_int;14509 bool is_int;
14510 bool is_float;14510 bool is_float;
...@@ -14646,7 +14646,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -14646,7 +14646,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
14646 }14646 }
14647 } else {14647 } else {
14648 float_div_trunc(out_val, op1_val, op2_val);14648 float_div_trunc(out_val, op1_val, op2_val);
14649 ConstExprValue remainder = {};14649 ZigValue remainder = {};
14650 float_rem(&remainder, op1_val, op2_val);14650 float_rem(&remainder, op1_val, op2_val);
14651 if (float_cmp_zero(&remainder) != CmpEQ) {14651 if (float_cmp_zero(&remainder) != CmpEQ) {
14652 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));14652 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));
...@@ -14684,10 +14684,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -14684,10 +14684,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
1468414684
14685// This works on operands that have already been checked to be comptime known.14685// This works on operands that have already been checked to be comptime known.
14686static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,14686static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,
14687 ZigType *type_entry, ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val)14687 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
14688{14688{
14689 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);14689 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);
14690 ConstExprValue *out_val = &result_instruction->value;14690 ZigValue *out_val = &result_instruction->value;
14691 if (type_entry->id == ZigTypeIdVector) {14691 if (type_entry->id == ZigTypeIdVector) {
14692 expand_undef_array(ira->codegen, op1_val);14692 expand_undef_array(ira->codegen, op1_val);
14693 expand_undef_array(ira->codegen, op2_val);14693 expand_undef_array(ira->codegen, op2_val);
...@@ -14696,9 +14696,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -14696,9 +14696,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
14696 size_t len = type_entry->data.vector.len;14696 size_t len = type_entry->data.vector.len;
14697 ZigType *scalar_type = type_entry->data.vector.elem_type;14697 ZigType *scalar_type = type_entry->data.vector.elem_type;
14698 for (size_t i = 0; i < len; i += 1) {14698 for (size_t i = 0; i < len; i += 1) {
14699 ConstExprValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i];14699 ZigValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i];
14700 ConstExprValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i];14700 ZigValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i];
14701 ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];14701 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
14702 assert(scalar_op1_val->type == scalar_type);14702 assert(scalar_op1_val->type == scalar_type);
14703 assert(scalar_op2_val->type == scalar_type);14703 assert(scalar_op2_val->type == scalar_type);
14704 assert(scalar_out_val->type == scalar_type);14704 assert(scalar_out_val->type == scalar_type);
...@@ -14788,11 +14788,11 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -14788,11 +14788,11 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
14788 }14788 }
1478914789
14790 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {14790 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
14791 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);14791 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14792 if (op1_val == nullptr)14792 if (op1_val == nullptr)
14793 return ira->codegen->invalid_instruction;14793 return ira->codegen->invalid_instruction;
1479414794
14795 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);14795 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
14796 if (op2_val == nullptr)14796 if (op2_val == nullptr)
14797 return ira->codegen->invalid_instruction;14797 return ira->codegen->invalid_instruction;
1479814798
...@@ -14896,8 +14896,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14896,8 +14896,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14896 return ira->codegen->invalid_instruction;14896 return ira->codegen->invalid_instruction;
1489714897
14898 // If either operand is undef, result is undef.14898 // If either operand is undef, result is undef.
14899 ConstExprValue *op1_val = nullptr;14899 ZigValue *op1_val = nullptr;
14900 ConstExprValue *op2_val = nullptr;14900 ZigValue *op2_val = nullptr;
14901 if (instr_is_comptime(op1)) {14901 if (instr_is_comptime(op1)) {
14902 op1_val = ir_resolve_const(ira, op1, UndefOk);14902 op1_val = ir_resolve_const(ira, op1, UndefOk);
14903 if (op1_val == nullptr)14903 if (op1_val == nullptr)
...@@ -14968,11 +14968,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14968,11 +14968,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14968 if (is_signed_div) {14968 if (is_signed_div) {
14969 bool ok = false;14969 bool ok = false;
14970 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {14970 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
14971 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);14971 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
14972 if (op1_val == nullptr)14972 if (op1_val == nullptr)
14973 return ira->codegen->invalid_instruction;14973 return ira->codegen->invalid_instruction;
1497414974
14975 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);14975 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
14976 if (op2_val == nullptr)14976 if (op2_val == nullptr)
14977 return ira->codegen->invalid_instruction;14977 return ira->codegen->invalid_instruction;
1497814978
...@@ -15006,12 +15006,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15006,12 +15006,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15006 if (is_signed_div && (is_int || is_float)) {15006 if (is_signed_div && (is_int || is_float)) {
15007 bool ok = false;15007 bool ok = false;
15008 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {15008 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15009 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);15009 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15010 if (op1_val == nullptr)15010 if (op1_val == nullptr)
15011 return ira->codegen->invalid_instruction;15011 return ira->codegen->invalid_instruction;
1501215012
15013 if (is_int) {15013 if (is_int) {
15014 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);15014 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15015 if (op2_val == nullptr)15015 if (op2_val == nullptr)
15016 return ira->codegen->invalid_instruction;15016 return ira->codegen->invalid_instruction;
1501715017
...@@ -15031,7 +15031,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15031,7 +15031,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15031 if (casted_op2 == ira->codegen->invalid_instruction)15031 if (casted_op2 == ira->codegen->invalid_instruction)
15032 return ira->codegen->invalid_instruction;15032 return ira->codegen->invalid_instruction;
1503315033
15034 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15034 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15035 if (op2_val == nullptr)15035 if (op2_val == nullptr)
15036 return ira->codegen->invalid_instruction;15036 return ira->codegen->invalid_instruction;
1503715037
...@@ -15040,8 +15040,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15040,8 +15040,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15040 // have a remainder function ambiguity problem15040 // have a remainder function ambiguity problem
15041 ok = true;15041 ok = true;
15042 } else {15042 } else {
15043 ConstExprValue rem_result = {};15043 ZigValue rem_result = {};
15044 ConstExprValue mod_result = {};15044 ZigValue mod_result = {};
15045 float_rem(&rem_result, op1_val, op2_val);15045 float_rem(&rem_result, op1_val, op2_val);
15046 float_mod(&mod_result, op1_val, op2_val);15046 float_mod(&mod_result, op1_val, op2_val);
15047 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;15047 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;
...@@ -15100,10 +15100,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15100,10 +15100,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15100 return ira->codegen->invalid_instruction;15100 return ira->codegen->invalid_instruction;
1510115101
15102 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {15102 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
15103 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);15103 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
15104 if (op1_val == nullptr)15104 if (op1_val == nullptr)
15105 return ira->codegen->invalid_instruction;15105 return ira->codegen->invalid_instruction;
15106 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15106 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15107 if (op2_val == nullptr)15107 if (op2_val == nullptr)
15108 return ira->codegen->invalid_instruction;15108 return ira->codegen->invalid_instruction;
1510915109
...@@ -15127,16 +15127,16 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15127,16 +15127,16 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15127 if (type_is_invalid(op2_type))15127 if (type_is_invalid(op2_type))
15128 return ira->codegen->invalid_instruction;15128 return ira->codegen->invalid_instruction;
1512915129
15130 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);15130 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15131 if (!op1_val)15131 if (!op1_val)
15132 return ira->codegen->invalid_instruction;15132 return ira->codegen->invalid_instruction;
1513315133
15134 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);15134 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15135 if (!op2_val)15135 if (!op2_val)
15136 return ira->codegen->invalid_instruction;15136 return ira->codegen->invalid_instruction;
1513715137
15138 ConstExprValue *sentinel1 = nullptr;15138 ZigValue *sentinel1 = nullptr;
15139 ConstExprValue *op1_array_val;15139 ZigValue *op1_array_val;
15140 size_t op1_array_index;15140 size_t op1_array_index;
15141 size_t op1_array_end;15141 size_t op1_array_end;
15142 ZigType *child_type;15142 ZigType *child_type;
...@@ -15159,11 +15159,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15159,11 +15159,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15159 } else if (is_slice(op1_type)) {15159 } else if (is_slice(op1_type)) {
15160 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;15160 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
15161 child_type = ptr_type->data.pointer.child_type;15161 child_type = ptr_type->data.pointer.child_type;
15162 ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];15162 ZigValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];
15163 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);15163 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
15164 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;15164 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
15165 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;15165 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];15166 ZigValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
15167 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);15167 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
15168 sentinel1 = ptr_type->data.pointer.sentinel;15168 sentinel1 = ptr_type->data.pointer.sentinel;
15169 } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle &&15169 } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle &&
...@@ -15183,8 +15183,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15183,8 +15183,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15183 return ira->codegen->invalid_instruction;15183 return ira->codegen->invalid_instruction;
15184 }15184 }
1518515185
15186 ConstExprValue *sentinel2 = nullptr;15186 ZigValue *sentinel2 = nullptr;
15187 ConstExprValue *op2_array_val;15187 ZigValue *op2_array_val;
15188 size_t op2_array_index;15188 size_t op2_array_index;
15189 size_t op2_array_end;15189 size_t op2_array_end;
15190 bool op2_type_valid;15190 bool op2_type_valid;
...@@ -15207,11 +15207,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15207,11 +15207,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15207 } else if (is_slice(op2_type)) {15207 } else if (is_slice(op2_type)) {
15208 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;15208 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
15209 op2_type_valid = ptr_type->data.pointer.child_type == child_type;15209 op2_type_valid = ptr_type->data.pointer.child_type == child_type;
15210 ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];15210 ZigValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];
15211 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);15211 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
15212 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;15212 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
15213 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;15213 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];15214 ZigValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
15215 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);15215 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
1521615216
15217 sentinel2 = ptr_type->data.pointer.sentinel;15217 sentinel2 = ptr_type->data.pointer.sentinel;
...@@ -15239,7 +15239,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15239,7 +15239,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15239 return ira->codegen->invalid_instruction;15239 return ira->codegen->invalid_instruction;
15240 }15240 }
1524115241
15242 ConstExprValue *sentinel;15242 ZigValue *sentinel;
15243 if (sentinel1 != nullptr && sentinel2 != nullptr) {15243 if (sentinel1 != nullptr && sentinel2 != nullptr) {
15244 // When there is a sentinel mismatch, no sentinel on the result. The type system15244 // When there is a sentinel mismatch, no sentinel on the result. The type system
15245 // will catch this if it is a problem.15245 // will catch this if it is a problem.
...@@ -15254,9 +15254,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15254,9 +15254,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1525415254
15255 // The type of result is populated in the following if blocks15255 // The type of result is populated in the following if blocks
15256 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);15256 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
15257 ConstExprValue *out_val = &result->value;15257 ZigValue *out_val = &result->value;
1525815258
15259 ConstExprValue *out_array_val;15259 ZigValue *out_array_val;
15260 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);15260 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
15261 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {15261 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15262 result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel);15262 result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel);
...@@ -15317,21 +15317,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15317,21 +15317,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1531715317
15318 size_t next_index = 0;15318 size_t next_index = 0;
15319 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {15319 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];15320 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15321 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);15321 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);
15322 elem_dest_val->parent.id = ConstParentIdArray;15322 elem_dest_val->parent.id = ConstParentIdArray;
15323 elem_dest_val->parent.data.p_array.array_val = out_array_val;15323 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15324 elem_dest_val->parent.data.p_array.elem_index = next_index;15324 elem_dest_val->parent.data.p_array.elem_index = next_index;
15325 }15325 }
15326 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {15326 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];15327 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15328 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);15328 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);
15329 elem_dest_val->parent.id = ConstParentIdArray;15329 elem_dest_val->parent.id = ConstParentIdArray;
15330 elem_dest_val->parent.data.p_array.array_val = out_array_val;15330 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15331 elem_dest_val->parent.data.p_array.elem_index = next_index;15331 elem_dest_val->parent.data.p_array.elem_index = next_index;
15332 }15332 }
15333 if (next_index < full_len) {15333 if (next_index < full_len) {
15334 ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15334 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15335 copy_const_val(elem_dest_val, sentinel, false);15335 copy_const_val(elem_dest_val, sentinel, false);
15336 elem_dest_val->parent.id = ConstParentIdArray;15336 elem_dest_val->parent.id = ConstParentIdArray;
15337 elem_dest_val->parent.data.p_array.array_val = out_array_val;15337 elem_dest_val->parent.data.p_array.array_val = out_array_val;
...@@ -15354,7 +15354,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15354,7 +15354,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1535415354
15355 bool want_ptr_to_array = false;15355 bool want_ptr_to_array = false;
15356 ZigType *array_type;15356 ZigType *array_type;
15357 ConstExprValue *array_val;15357 ZigValue *array_val;
15358 if (op1->value.type->id == ZigTypeIdArray) {15358 if (op1->value.type->id == ZigTypeIdArray) {
15359 array_type = op1->value.type;15359 array_type = op1->value.type;
15360 array_val = ir_resolve_const(ira, op1, UndefOk);15360 array_val = ir_resolve_const(ira, op1, UndefOk);
...@@ -15397,7 +15397,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15397,7 +15397,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15397 array_result = ir_const_undef(ira, &instruction->base, result_array_type);15397 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
15398 } else {15398 } else {
15399 array_result = ir_const(ira, &instruction->base, result_array_type);15399 array_result = ir_const(ira, &instruction->base, result_array_type);
15400 ConstExprValue *out_val = &array_result->value;15400 ZigValue *out_val = &array_result->value;
1540115401
15402 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {15402 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
15403 case OnePossibleValueInvalid:15403 case OnePossibleValueInvalid:
...@@ -15416,7 +15416,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15416,7 +15416,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15416 uint64_t i = 0;15416 uint64_t i = 0;
15417 for (uint64_t x = 0; x < mult_amt; x += 1) {15417 for (uint64_t x = 0; x < mult_amt; x += 1) {
15418 for (uint64_t y = 0; y < old_array_len; y += 1) {15418 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];15419 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15420 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);15420 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15421 elem_dest_val->parent.id = ConstParentIdArray;15421 elem_dest_val->parent.id = ConstParentIdArray;
15422 elem_dest_val->parent.data.p_array.array_val = out_val;15422 elem_dest_val->parent.data.p_array.array_val = out_val;
...@@ -15427,7 +15427,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15427,7 +15427,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15427 assert(i == new_array_len);15427 assert(i == new_array_len);
1542815428
15429 if (array_type->data.array.sentinel != nullptr) {15429 if (array_type->data.array.sentinel != nullptr) {
15430 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15430 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15431 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);15431 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);
15432 elem_dest_val->parent.id = ConstParentIdArray;15432 elem_dest_val->parent.id = ConstParentIdArray;
15433 elem_dest_val->parent.data.p_array.array_val = out_val;15433 elem_dest_val->parent.data.p_array.array_val = out_val;
...@@ -15570,7 +15570,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15570,7 +15570,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
15570 zig_unreachable();15570 zig_unreachable();
15571 }15571 }
1557215572
15573 ConstExprValue *init_val = nullptr;15573 ZigValue *init_val = nullptr;
15574 if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {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);15575 init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node);
15576 if (is_comptime_var) {15576 if (is_comptime_var) {
...@@ -15631,7 +15631,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15631,7 +15631,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
15631 new_var->owner_exec = var->owner_exec;15631 new_var->owner_exec = var->owner_exec;
15632 new_var->align_bytes = var->align_bytes;15632 new_var->align_bytes = var->align_bytes;
15633 if (var->mem_slot_index != SIZE_MAX) {15633 if (var->mem_slot_index != SIZE_MAX) {
15634 ConstExprValue *vals = create_const_vals(1);15634 ZigValue *vals = create_const_vals(1);
15635 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;15635 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;
15636 ira->exec_context.mem_slot_list.append(vals);15636 ira->exec_context.mem_slot_list.append(vals);
15637 }15637 }
...@@ -15687,7 +15687,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -15687,7 +15687,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1568715687
15688 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {15688 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
15689 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);15689 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);15690 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
15691 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);15691 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
1569215692
15693 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {15693 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
...@@ -15936,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -15936,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
15936 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);15936 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
15937 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {15937 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
15938 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);15938 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);
15939 ConstExprValue *out_val = &result->value;15939 ZigValue *out_val = &result->value;
15940 assert(get_codegen_ptr_type(optional_type) != nullptr);15940 assert(get_codegen_ptr_type(optional_type) != nullptr);
15941 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;15941 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
15942 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;15942 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
...@@ -15982,7 +15982,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -15982,7 +15982,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
15982{15982{
15983 Error err;15983 Error err;
1598415984
15985 ConstExprValue *pointee = create_const_vals(1);15985 ZigValue *pointee = create_const_vals(1);
15986 pointee->special = ConstValSpecialUndef;15986 pointee->special = ConstValSpecialUndef;
1598715987
15988 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);15988 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
...@@ -16063,7 +16063,7 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -16063,7 +16063,7 @@ static bool type_can_bit_cast(ZigType *t) {
16063}16063}
1606416064
16065static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {16065static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
16066 ConstExprValue *undef_child = create_const_vals(1);16066 ZigValue *undef_child = create_const_vals(1);
16067 undef_child->type = ptr->value.type->data.pointer.child_type;16067 undef_child->type = ptr->value.type->data.pointer.child_type;
16068 undef_child->special = ConstValSpecialUndef;16068 undef_child->special = ConstValSpecialUndef;
16069 ptr->value.special = ConstValSpecialStatic;16069 ptr->value.special = ConstValSpecialStatic;
...@@ -16676,7 +16676,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -16676,7 +16676,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
16676 casted_arg = arg;16676 casted_arg = arg;
16677 }16677 }
1667816678
16679 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);16679 ZigValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk);
16680 if (!arg_val)16680 if (!arg_val)
16681 return false;16681 return false;
1668216682
...@@ -16721,7 +16721,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16721,7 +16721,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16721 bool comptime_arg = param_decl_node->data.param_decl.is_comptime ||16721 bool comptime_arg = param_decl_node->data.param_decl.is_comptime ||
16722 casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;16722 casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;
1672316723
16724 ConstExprValue *arg_val;16724 ZigValue *arg_val;
1672516725
16726 if (comptime_arg) {16726 if (comptime_arg) {
16727 arg_part_of_generic_id = true;16727 arg_part_of_generic_id = true;
...@@ -16805,7 +16805,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -16805,7 +16805,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
16805 if (var->var_type == nullptr || type_is_invalid(var->var_type))16805 if (var->var_type == nullptr || type_is_invalid(var->var_type))
16806 return ira->codegen->invalid_instruction;16806 return ira->codegen->invalid_instruction;
1680716807
16808 ConstExprValue *mem_slot = nullptr;16808 ZigValue *mem_slot = nullptr;
1680916809
16810 bool comptime_var_mem = ir_get_var_is_comptime(var);16810 bool comptime_var_mem = ir_get_var_is_comptime(var);
16811 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;16811 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
...@@ -16865,7 +16865,7 @@ no_mem_slot:...@@ -16865,7 +16865,7 @@ no_mem_slot:
16865}16865}
1686616866
16867// This function is called when a comptime value becomes accessible at runtime.16867// 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) {16868static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) {
16869 ir_assert(value_is_comptime(val), source_instr);16869 ir_assert(value_is_comptime(val), source_instr);
16870 if (val->special == ConstValSpecialUndef)16870 if (val->special == ConstValSpecialUndef)
16871 return;16871 return;
...@@ -16921,17 +16921,17 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16921,17 +16921,17 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16921 casted_ptr->value.type = struct_ptr_type;16921 casted_ptr->value.type = struct_ptr_type;
16922 }16922 }
16923 if (instr_is_comptime(casted_ptr)) {16923 if (instr_is_comptime(casted_ptr)) {
16924 ConstExprValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);16924 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
16925 if (!ptr_val)16925 if (!ptr_val)
16926 return ira->codegen->invalid_instruction;16926 return ira->codegen->invalid_instruction;
16927 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {16927 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
16928 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,16928 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
16929 source_instr->source_node);16929 source_instr->source_node);
16930 struct_val->special = ConstValSpecialStatic;16930 struct_val->special = ConstValSpecialStatic;
16931 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,16931 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
16932 old_field_count, new_field_count);16932 old_field_count, new_field_count);
1693316933
16934 ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count];16934 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
16935 field_val->special = ConstValSpecialUndef;16935 field_val->special = ConstValSpecialUndef;
16936 field_val->type = field->type_entry;16936 field_val->type = field->type_entry;
16937 field_val->parent.id = ConstParentIdStruct;16937 field_val->parent.id = ConstParentIdStruct;
...@@ -16972,7 +16972,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16972,7 +16972,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16972 ptr->value.data.x_ptr.mut == ConstPtrMutInfer)16972 ptr->value.data.x_ptr.mut == ConstPtrMutInfer)
16973 {16973 {
16974 if (instr_is_comptime(value)) {16974 if (instr_is_comptime(value)) {
16975 ConstExprValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node);16975 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node);
16976 if (dest_val == nullptr)16976 if (dest_val == nullptr)
16977 return ira->codegen->invalid_instruction;16977 return ira->codegen->invalid_instruction;
16978 if (dest_val->special != ConstValSpecialRuntime) {16978 if (dest_val->special != ConstValSpecialRuntime) {
...@@ -16997,7 +16997,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16997,7 +16997,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16997 } else {16997 } else {
16998 ir_add_error(ira, source_instr,16998 ir_add_error(ira, source_instr,
16999 buf_sprintf("cannot store runtime value in compile time variable"));16999 buf_sprintf("cannot store runtime value in compile time variable"));
17000 ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);17000 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);
17001 dest_val->type = ira->codegen->builtin_types.entry_invalid;17001 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1700217002
17003 return ira->codegen->invalid_instruction;17003 return ira->codegen->invalid_instruction;
...@@ -17097,7 +17097,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17097,7 +17097,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1709717097
17098 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;17098 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
17099 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {17099 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
17100 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->child->value;17100 ZigValue *arg_tuple_value = &call_instruction->args[i]->child->value;
17101 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {17101 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
17102 call_param_count -= 1;17102 call_param_count -= 1;
17103 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -17103 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
...@@ -17207,7 +17207,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17207,7 +17207,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17207 }17207 }
1720817208
17209 bool cacheable = fn_eval_cacheable(exec_scope, return_type);17209 bool cacheable = fn_eval_cacheable(exec_scope, return_type);
17210 ConstExprValue *result = nullptr;17210 ZigValue *result = nullptr;
17211 if (cacheable) {17211 if (cacheable) {
17212 auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope);17212 auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope);
17213 if (entry)17213 if (entry)
...@@ -17392,7 +17392,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17392,7 +17392,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17392 first_var_arg = inst_fn_type_id.param_count;17392 first_var_arg = inst_fn_type_id.param_count;
17393 }17393 }
1739417394
17395 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,17395 ZigValue *var_args_val = create_const_arg_tuple(ira->codegen,
17396 first_var_arg, inst_fn_type_id.param_count);17396 first_var_arg, inst_fn_type_id.param_count);
17397 ZigVar *var = add_variable(ira->codegen, param_decl_node,17397 ZigVar *var = add_variable(ira->codegen, param_decl_node,
17398 impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type);17398 impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type);
...@@ -17400,7 +17400,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17400,7 +17400,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17400 }17400 }
1740117401
17402 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {17402 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {
17403 ConstExprValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope,17403 ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope,
17404 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),17404 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),
17405 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,17405 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
17406 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,17406 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
...@@ -17719,12 +17719,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -17719,12 +17719,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
17719// out_val->type must be the type to read the pointer as17719// out_val->type must be the type to read the pointer as
17720// if the type is different than the actual type then it does a comptime byte reinterpretation17720// if the type is different than the actual type then it does a comptime byte reinterpretation
17721static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,17721static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
17722 ConstExprValue *out_val, ConstExprValue *ptr_val)17722 ZigValue *out_val, ZigValue *ptr_val)
17723{17723{
17724 Error err;17724 Error err;
17725 assert(out_val->type != nullptr);17725 assert(out_val->type != nullptr);
1772617726
17727 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);17727 ZigValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);
17728 src_assert(pointee->type != nullptr, source_node);17728 src_assert(pointee->type != nullptr, source_node);
1772917729
17730 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))17730 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
...@@ -17765,7 +17765,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17765,7 +17765,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17765 return ErrorSemanticAnalyzeFail;17765 return ErrorSemanticAnalyzeFail;
17766 }17766 }
17767 case ConstPtrSpecialBaseArray: {17767 case ConstPtrSpecialBaseArray: {
17768 ConstExprValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val;17768 ZigValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val;
17769 assert(array_val->type->id == ZigTypeIdArray);17769 assert(array_val->type->id == ZigTypeIdArray);
17770 if (array_val->data.x_array.special != ConstArraySpecialNone)17770 if (array_val->data.x_array.special != ConstArraySpecialNone)
17771 zig_panic("TODO");17771 zig_panic("TODO");
...@@ -17782,7 +17782,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17782,7 +17782,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17782 Buf buf = BUF_INIT;17782 Buf buf = BUF_INIT;
17783 buf_resize(&buf, elem_count * elem_size);17783 buf_resize(&buf, elem_count * elem_size);
17784 for (size_t i = 0; i < elem_count; i += 1) {17784 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];17785 ZigValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i];
17786 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);17786 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);
17787 }17787 }
17788 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))17788 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))
...@@ -17818,7 +17818,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp...@@ -17818,7 +17818,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
17818}17818}
1781917819
17820static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,17820static 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)17821 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
17822{17822{
17823 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);17823 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
1782417824
...@@ -17872,20 +17872,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -17872,20 +17872,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
17872 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;17872 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
1787317873
17874 if (instr_is_comptime(value)) {17874 if (instr_is_comptime(value)) {
17875 ConstExprValue *operand_val = ir_resolve_const(ira, value, UndefBad);17875 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
17876 if (!operand_val)17876 if (!operand_val)
17877 return ira->codegen->invalid_instruction;17877 return ira->codegen->invalid_instruction;
1787817878
17879 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);17879 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);
17880 ConstExprValue *out_val = &result_instruction->value;17880 ZigValue *out_val = &result_instruction->value;
17881 if (expr_type->id == ZigTypeIdVector) {17881 if (expr_type->id == ZigTypeIdVector) {
17882 expand_undef_array(ira->codegen, operand_val);17882 expand_undef_array(ira->codegen, operand_val);
17883 out_val->special = ConstValSpecialUndef;17883 out_val->special = ConstValSpecialUndef;
17884 expand_undef_array(ira->codegen, out_val);17884 expand_undef_array(ira->codegen, out_val);
17885 size_t len = expr_type->data.vector.len;17885 size_t len = expr_type->data.vector.len;
17886 for (size_t i = 0; i < len; i += 1) {17886 for (size_t i = 0; i < len; i += 1) {
17887 ConstExprValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i];17887 ZigValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i];
17888 ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];17888 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
17889 assert(scalar_operand_val->type == scalar_type);17889 assert(scalar_operand_val->type == scalar_type);
17890 assert(scalar_out_val->type == scalar_type);17890 assert(scalar_out_val->type == scalar_type);
17891 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,17891 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,
...@@ -17923,7 +17923,7 @@ static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *inst...@@ -17923,7 +17923,7 @@ static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *inst
1792317923
17924 if (expr_type->id == ZigTypeIdInt) {17924 if (expr_type->id == ZigTypeIdInt) {
17925 if (instr_is_comptime(value)) {17925 if (instr_is_comptime(value)) {
17926 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);17926 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
17927 if (target_const_val == nullptr)17927 if (target_const_val == nullptr)
17928 return ira->codegen->invalid_instruction;17928 return ira->codegen->invalid_instruction;
1792917929
...@@ -18361,7 +18361,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18361,7 +18361,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18361 if (type_is_invalid(array_ptr->value.type))18361 if (type_is_invalid(array_ptr->value.type))
18362 return ira->codegen->invalid_instruction;18362 return ira->codegen->invalid_instruction;
1836318363
18364 ConstExprValue *orig_array_ptr_val = &array_ptr->value;18364 ZigValue *orig_array_ptr_val = &array_ptr->value;
1836518365
18366 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;18366 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;
18367 if (type_is_invalid(elem_index->value.type))18367 if (type_is_invalid(elem_index->value.type))
...@@ -18428,10 +18428,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18428,10 +18428,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18428 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,18428 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,
18429 elem_ptr_instruction->ptr_len);18429 elem_ptr_instruction->ptr_len);
18430 } else if (array_type->id == ZigTypeIdArgTuple) {18430 } else if (array_type->id == ZigTypeIdArgTuple) {
18431 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);18431 ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
18432 if (!ptr_val)18432 if (!ptr_val)
18433 return ira->codegen->invalid_instruction;18433 return ira->codegen->invalid_instruction;
18434 ConstExprValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);18434 ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);
18435 if (args_val == nullptr)18435 if (args_val == nullptr)
18436 return ira->codegen->invalid_instruction;18436 return ira->codegen->invalid_instruction;
18437 size_t start = args_val->data.x_arg_tuple.start_index;18437 size_t start = args_val->data.x_arg_tuple.start_index;
...@@ -18544,7 +18544,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18544,7 +18544,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18544 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||18544 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
18545 array_type->id == ZigTypeIdArray))18545 array_type->id == ZigTypeIdArray))
18546 {18546 {
18547 ConstExprValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,18547 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
18548 elem_ptr_instruction->base.source_node);18548 elem_ptr_instruction->base.source_node);
18549 if (array_ptr_val == nullptr)18549 if (array_ptr_val == nullptr)
18550 return ira->codegen->invalid_instruction;18550 return ira->codegen->invalid_instruction;
...@@ -18557,7 +18557,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18557,7 +18557,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18557 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);18557 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
18558 array_ptr_val->special = ConstValSpecialStatic;18558 array_ptr_val->special = ConstValSpecialStatic;
18559 for (size_t i = 0; i < array_type->data.array.len; i += 1) {18559 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];18560 ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
18561 elem_val->special = ConstValSpecialUndef;18561 elem_val->special = ConstValSpecialUndef;
18562 elem_val->type = array_type->data.array.child_type;18562 elem_val->type = array_type->data.array.child_type;
18563 elem_val->parent.id = ConstParentIdArray;18563 elem_val->parent.id = ConstParentIdArray;
...@@ -18576,14 +18576,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18576,14 +18576,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18576 return ira->codegen->invalid_instruction;18576 return ira->codegen->invalid_instruction;
18577 }18577 }
1857818578
18579 ConstExprValue *array_init_val = create_const_vals(1);18579 ZigValue *array_init_val = create_const_vals(1);
18580 array_init_val->special = ConstValSpecialStatic;18580 array_init_val->special = ConstValSpecialStatic;
18581 array_init_val->type = actual_array_type;18581 array_init_val->type = actual_array_type;
18582 array_init_val->data.x_array.special = ConstArraySpecialNone;18582 array_init_val->data.x_array.special = ConstArraySpecialNone;
18583 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);18583 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
18584 array_init_val->special = ConstValSpecialStatic;18584 array_init_val->special = ConstValSpecialStatic;
18585 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {18585 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];18586 ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];
18587 elem_val->special = ConstValSpecialUndef;18587 elem_val->special = ConstValSpecialUndef;
18588 elem_val->type = actual_array_type->data.array.child_type;18588 elem_val->type = actual_array_type->data.array.child_type;
18589 elem_val->parent.id = ConstParentIdArray;18589 elem_val->parent.id = ConstParentIdArray;
...@@ -18608,7 +18608,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18608,7 +18608,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18608 {18608 {
18609 if (array_type->id == ZigTypeIdPointer) {18609 if (array_type->id == ZigTypeIdPointer) {
18610 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);18610 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18611 ConstExprValue *out_val = &result->value;18611 ZigValue *out_val = &result->value;
18612 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;18612 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
18613 size_t new_index;18613 size_t new_index;
18614 size_t mem_size;18614 size_t mem_size;
...@@ -18619,7 +18619,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18619,7 +18619,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18619 zig_unreachable();18619 zig_unreachable();
18620 case ConstPtrSpecialRef:18620 case ConstPtrSpecialRef:
18621 if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) {18621 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;18622 ZigValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee;
18623 new_index = index;18623 new_index = index;
18624 ZigType *array_type = array_val->type;18624 ZigType *array_type = array_val->type;
18625 mem_size = array_type->data.array.len;18625 mem_size = array_type->data.array.len;
...@@ -18682,7 +18682,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18682,7 +18682,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18682 }18682 }
18683 return result;18683 return result;
18684 } else if (is_slice(array_type)) {18684 } else if (is_slice(array_type)) {
18685 ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];18685 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
18686 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);18686 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
18687 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {18687 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
18688 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,18688 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
...@@ -18691,9 +18691,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18691,9 +18691,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18691 result->value.type = return_type;18691 result->value.type = return_type;
18692 return result;18692 return result;
18693 }18693 }
18694 ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];18694 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
18695 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);18695 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18696 ConstExprValue *out_val = &result->value;18696 ZigValue *out_val = &result->value;
18697 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;18697 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
18698 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);18698 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
18699 uint64_t full_slice_len = slice_len +18699 uint64_t full_slice_len = slice_len +
...@@ -18757,7 +18757,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18757,7 +18757,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18757 } else {18757 } else {
18758 result = ir_const(ira, &elem_ptr_instruction->base, return_type);18758 result = ir_const(ira, &elem_ptr_instruction->base, return_type);
18759 }18759 }
18760 ConstExprValue *out_val = &result->value;18760 ZigValue *out_val = &result->value;
18761 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;18761 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
18762 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;18762 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
18763 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;18763 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
...@@ -18915,12 +18915,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18915,12 +18915,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18915 (uint32_t)host_int_bytes_for_result_type, false);18915 (uint32_t)host_int_bytes_for_result_type, false);
18916 }18916 }
18917 if (instr_is_comptime(struct_ptr)) {18917 if (instr_is_comptime(struct_ptr)) {
18918 ConstExprValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);18918 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
18919 if (!ptr_val)18919 if (!ptr_val)
18920 return ira->codegen->invalid_instruction;18920 return ira->codegen->invalid_instruction;
1892118921
18922 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {18922 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18923 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);18923 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
18924 if (struct_val == nullptr)18924 if (struct_val == nullptr)
18925 return ira->codegen->invalid_instruction;18925 return ira->codegen->invalid_instruction;
18926 if (type_is_invalid(struct_val->type))18926 if (type_is_invalid(struct_val->type))
...@@ -18929,7 +18929,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18929,7 +18929,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18929 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);18929 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
18930 struct_val->special = ConstValSpecialStatic;18930 struct_val->special = ConstValSpecialStatic;
18931 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {18931 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];18932 ZigValue *field_val = struct_val->data.x_struct.fields[i];
18933 field_val->special = ConstValSpecialUndef;18933 field_val->special = ConstValSpecialUndef;
18934 field_val->type = resolve_struct_field_type(ira->codegen,18934 field_val->type = resolve_struct_field_type(ira->codegen,
18935 struct_type->data.structure.fields[i]);18935 struct_type->data.structure.fields[i]);
...@@ -18947,7 +18947,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -18947,7 +18947,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
18947 } else {18947 } else {
18948 result = ir_const(ira, source_instr, ptr_type);18948 result = ir_const(ira, source_instr, ptr_type);
18949 }18949 }
18950 ConstExprValue *const_val = &result->value;18950 ZigValue *const_val = &result->value;
18951 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;18951 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
18952 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;18952 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
18953 const_val->data.x_ptr.data.base_struct.struct_val = struct_val;18953 const_val->data.x_ptr.data.base_struct.struct_val = struct_val;
...@@ -19044,20 +19044,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19044,20 +19044,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19044 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,19044 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
19045 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);19045 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
19046 if (instr_is_comptime(container_ptr)) {19046 if (instr_is_comptime(container_ptr)) {
19047 ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19047 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19048 if (!ptr_val)19048 if (!ptr_val)
19049 return ira->codegen->invalid_instruction;19049 return ira->codegen->invalid_instruction;
1905019050
19051 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&19051 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
19052 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {19052 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
19053 ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);19053 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
19054 if (union_val == nullptr)19054 if (union_val == nullptr)
19055 return ira->codegen->invalid_instruction;19055 return ira->codegen->invalid_instruction;
19056 if (type_is_invalid(union_val->type))19056 if (type_is_invalid(union_val->type))
19057 return ira->codegen->invalid_instruction;19057 return ira->codegen->invalid_instruction;
1905819058
19059 if (initializing) {19059 if (initializing) {
19060 ConstExprValue *payload_val = create_const_vals(1);19060 ZigValue *payload_val = create_const_vals(1);
19061 payload_val->special = ConstValSpecialUndef;19061 payload_val->special = ConstValSpecialUndef;
19062 payload_val->type = field_type;19062 payload_val->type = field_type;
19063 payload_val->parent.id = ConstParentIdUnion;19063 payload_val->parent.id = ConstParentIdUnion;
...@@ -19079,7 +19079,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19079,7 +19079,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19079 }19079 }
19080 }19080 }
1908119081
19082 ConstExprValue *payload_val = union_val->data.x_union.payload;19082 ZigValue *payload_val = union_val->data.x_union.payload;
1908319083
19084 IrInstruction *result;19084 IrInstruction *result;
19085 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {19085 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
...@@ -19090,7 +19090,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -19090,7 +19090,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
19090 } else {19090 } else {
19091 result = ir_const(ira, source_instr, ptr_type);19091 result = ir_const(ira, source_instr, ptr_type);
19092 }19092 }
19093 ConstExprValue *const_val = &result->value;19093 ZigValue *const_val = &result->value;
19094 const_val->data.x_ptr.special = ConstPtrSpecialRef;19094 const_val->data.x_ptr.special = ConstPtrSpecialRef;
19095 const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut;19095 const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut;
19096 const_val->data.x_ptr.data.ref.pointee = payload_val;19096 const_val->data.x_ptr.data.ref.pointee = payload_val;
...@@ -19236,7 +19236,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19236,7 +19236,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19236 }19236 }
19237 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {19237 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
19238 if (buf_eql_str(field_name, "len")) {19238 if (buf_eql_str(field_name, "len")) {
19239 ConstExprValue *len_val = create_const_vals(1);19239 ZigValue *len_val = create_const_vals(1);
19240 if (container_type->id == ZigTypeIdPointer) {19240 if (container_type->id == ZigTypeIdPointer) {
19241 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);19241 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
19242 } else {19242 } else {
...@@ -19255,17 +19255,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19255,17 +19255,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19255 return ira->codegen->invalid_instruction;19255 return ira->codegen->invalid_instruction;
19256 }19256 }
19257 } else if (container_type->id == ZigTypeIdArgTuple) {19257 } else if (container_type->id == ZigTypeIdArgTuple) {
19258 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19258 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19259 if (!container_ptr_val)19259 if (!container_ptr_val)
19260 return ira->codegen->invalid_instruction;19260 return ira->codegen->invalid_instruction;
1926119261
19262 assert(container_ptr->value.type->id == ZigTypeIdPointer);19262 assert(container_ptr->value.type->id == ZigTypeIdPointer);
19263 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);19263 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19264 if (child_val == nullptr)19264 if (child_val == nullptr)
19265 return ira->codegen->invalid_instruction;19265 return ira->codegen->invalid_instruction;
1926619266
19267 if (buf_eql_str(field_name, "len")) {19267 if (buf_eql_str(field_name, "len")) {
19268 ConstExprValue *len_val = create_const_vals(1);19268 ZigValue *len_val = create_const_vals(1);
19269 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;19269 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
19270 init_const_usize(ira->codegen, len_val, len);19270 init_const_usize(ira->codegen, len_val, len);
1927119271
...@@ -19281,12 +19281,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19281,12 +19281,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19281 return ira->codegen->invalid_instruction;19281 return ira->codegen->invalid_instruction;
19282 }19282 }
19283 } else if (container_type->id == ZigTypeIdMetaType) {19283 } else if (container_type->id == ZigTypeIdMetaType) {
19284 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);19284 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
19285 if (!container_ptr_val)19285 if (!container_ptr_val)
19286 return ira->codegen->invalid_instruction;19286 return ira->codegen->invalid_instruction;
1928719287
19288 assert(container_ptr->value.type->id == ZigTypeIdPointer);19288 assert(container_ptr->value.type->id == ZigTypeIdPointer);
19289 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);19289 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
19290 if (child_val == nullptr)19290 if (child_val == nullptr)
19291 return ira->codegen->invalid_instruction;19291 return ira->codegen->invalid_instruction;
19292 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,19292 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
...@@ -19382,7 +19382,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -19382,7 +19382,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
19382 }19382 }
19383 err_set_type = child_type;19383 err_set_type = child_type;
19384 }19384 }
19385 ConstExprValue *const_val = create_const_vals(1);19385 ZigValue *const_val = create_const_vals(1);
19386 const_val->special = ConstValSpecialStatic;19386 const_val->special = ConstValSpecialStatic;
19387 const_val->type = err_set_type;19387 const_val->type = err_set_type;
19388 const_val->data.x_err_set = err_entry;19388 const_val->data.x_err_set = err_entry;
...@@ -19850,7 +19850,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -19850,7 +19850,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
19850 if (type_is_invalid(child_type))19850 if (type_is_invalid(child_type))
19851 return ira->codegen->invalid_instruction;19851 return ira->codegen->invalid_instruction;
1985219852
19853 ConstExprValue *sentinel_val;19853 ZigValue *sentinel_val;
19854 if (array_type_instruction->sentinel != nullptr) {19854 if (array_type_instruction->sentinel != nullptr) {
19855 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;19855 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;
19856 if (type_is_invalid(uncasted_sentinel->value.type))19856 if (type_is_invalid(uncasted_sentinel->value.type))
...@@ -19928,7 +19928,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -19928,7 +19928,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
1992819928
19929 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {19929 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
19930 if (instr_is_comptime(value)) {19930 if (instr_is_comptime(value)) {
19931 ConstExprValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);19931 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
19932 if (c_ptr_val == nullptr)19932 if (c_ptr_val == nullptr)
19933 return ira->codegen->invalid_instruction;19933 return ira->codegen->invalid_instruction;
19934 if (c_ptr_val->special == ConstValSpecialUndef)19934 if (c_ptr_val->special == ConstValSpecialUndef)
...@@ -19945,7 +19945,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -19945,7 +19945,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
19945 return result;19945 return result;
19946 } else if (type_entry->id == ZigTypeIdOptional) {19946 } else if (type_entry->id == ZigTypeIdOptional) {
19947 if (instr_is_comptime(value)) {19947 if (instr_is_comptime(value)) {
19948 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefOk);19948 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
19949 if (maybe_val == nullptr)19949 if (maybe_val == nullptr)
19950 return ira->codegen->invalid_instruction;19950 return ira->codegen->invalid_instruction;
19951 if (maybe_val->special == ConstValSpecialUndef)19951 if (maybe_val->special == ConstValSpecialUndef)
...@@ -19983,7 +19983,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {...@@ -19983,7 +19983,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
19983 return g->builtin_types.entry_invalid;19983 return g->builtin_types.entry_invalid;
1998419984
19985 assert(value_is_comptime(&ptr->value));19985 assert(value_is_comptime(&ptr->value));
19986 ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value);19986 ZigValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value);
19987 return pointee->type;19987 return pointee->type;
19988}19988}
1998919989
...@@ -19996,11 +19996,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -19996,11 +19996,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
1999619996
19997 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {19997 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
19998 if (instr_is_comptime(base_ptr)) {19998 if (instr_is_comptime(base_ptr)) {
19999 ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad);19999 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
20000 if (!val)20000 if (!val)
20001 return ira->codegen->invalid_instruction;20001 return ira->codegen->invalid_instruction;
20002 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {20002 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20003 ConstExprValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);20003 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
20004 if (c_ptr_val == nullptr)20004 if (c_ptr_val == nullptr)
20005 return ira->codegen->invalid_instruction;20005 return ira->codegen->invalid_instruction;
20006 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||20006 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
...@@ -20034,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20034,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20034 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry);20034 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry);
2003520035
20036 if (instr_is_comptime(base_ptr)) {20036 if (instr_is_comptime(base_ptr)) {
20037 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);20037 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
20038 if (!ptr_val)20038 if (!ptr_val)
20039 return ira->codegen->invalid_instruction;20039 return ira->codegen->invalid_instruction;
20040 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {20040 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
20041 ConstExprValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);20041 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20042 if (optional_val == nullptr)20042 if (optional_val == nullptr)
20043 return ira->codegen->invalid_instruction;20043 return ira->codegen->invalid_instruction;
2004420044
...@@ -20048,7 +20048,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20048,7 +20048,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20048 return ira->codegen->invalid_instruction;20048 return ira->codegen->invalid_instruction;
20049 case OnePossibleValueNo:20049 case OnePossibleValueNo:
20050 if (!same_comptime_repr) {20050 if (!same_comptime_repr) {
20051 ConstExprValue *payload_val = create_const_vals(1);20051 ZigValue *payload_val = create_const_vals(1);
20052 payload_val->type = child_type;20052 payload_val->type = child_type;
20053 payload_val->special = ConstValSpecialUndef;20053 payload_val->special = ConstValSpecialUndef;
20054 payload_val->parent.id = ConstParentIdOptionalPayload;20054 payload_val->parent.id = ConstParentIdOptionalPayload;
...@@ -20059,7 +20059,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20059,7 +20059,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20059 }20059 }
20060 break;20060 break;
20061 case OnePossibleValueYes: {20061 case OnePossibleValueYes: {
20062 ConstExprValue *pointee = create_const_vals(1);20062 ZigValue *pointee = create_const_vals(1);
20063 pointee->special = ConstValSpecialStatic;20063 pointee->special = ConstValSpecialStatic;
20064 pointee->type = child_type;20064 pointee->type = child_type;
20065 pointee->parent.id = ConstParentIdOptionalPayload;20065 pointee->parent.id = ConstParentIdOptionalPayload;
...@@ -20084,7 +20084,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -20084,7 +20084,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
20084 } else {20084 } else {
20085 result = ir_const(ira, source_instr, result_type);20085 result = ir_const(ira, source_instr, result_type);
20086 }20086 }
20087 ConstExprValue *result_val = &result->value;20087 ZigValue *result_val = &result->value;
20088 result_val->data.x_ptr.special = ConstPtrSpecialRef;20088 result_val->data.x_ptr.special = ConstPtrSpecialRef;
20089 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;20089 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
20090 switch (type_has_one_possible_value(ira->codegen, child_type)) {20090 switch (type_has_one_possible_value(ira->codegen, child_type)) {
...@@ -20137,7 +20137,7 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt...@@ -20137,7 +20137,7 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt
20137 return ir_const_unsigned(ira, &instruction->base, 0);20137 return ir_const_unsigned(ira, &instruction->base, 0);
2013820138
20139 if (instr_is_comptime(op)) {20139 if (instr_is_comptime(op)) {
20140 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20140 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20141 if (val == nullptr)20141 if (val == nullptr)
20142 return ira->codegen->invalid_instruction;20142 return ira->codegen->invalid_instruction;
20143 if (val->special == ConstValSpecialUndef)20143 if (val->special == ConstValSpecialUndef)
...@@ -20166,7 +20166,7 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl...@@ -20166,7 +20166,7 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl
20166 return ir_const_unsigned(ira, &instruction->base, 0);20166 return ir_const_unsigned(ira, &instruction->base, 0);
2016720167
20168 if (instr_is_comptime(op)) {20168 if (instr_is_comptime(op)) {
20169 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20169 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20170 if (val == nullptr)20170 if (val == nullptr)
20171 return ira->codegen->invalid_instruction;20171 return ira->codegen->invalid_instruction;
20172 if (val->special == ConstValSpecialUndef)20172 if (val->special == ConstValSpecialUndef)
...@@ -20195,7 +20195,7 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc...@@ -20195,7 +20195,7 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
20195 return ir_const_unsigned(ira, &instruction->base, 0);20195 return ir_const_unsigned(ira, &instruction->base, 0);
2019620196
20197 if (instr_is_comptime(op)) {20197 if (instr_is_comptime(op)) {
20198 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);20198 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
20199 if (val == nullptr)20199 if (val == nullptr)
20200 return ira->codegen->invalid_instruction;20200 return ira->codegen->invalid_instruction;
20201 if (val->special == ConstValSpecialUndef)20201 if (val->special == ConstValSpecialUndef)
...@@ -20242,7 +20242,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -20242,7 +20242,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
20242 assert(tag_type->id == ZigTypeIdEnum);20242 assert(tag_type->id == ZigTypeIdEnum);
2024320243
20244 if (instr_is_comptime(value)) {20244 if (instr_is_comptime(value)) {
20245 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);20245 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
20246 if (!val)20246 if (!val)
20247 return ira->codegen->invalid_instruction;20247 return ira->codegen->invalid_instruction;
2024820248
...@@ -20280,7 +20280,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20280,7 +20280,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20280 return ira->codegen->invalid_instruction;20280 return ira->codegen->invalid_instruction;
2028120281
20282 if (is_comptime || instr_is_comptime(target_value)) {20282 if (is_comptime || instr_is_comptime(target_value)) {
20283 ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad);20283 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
20284 if (!target_val)20284 if (!target_val)
20285 return ir_unreach_error(ira);20285 return ir_unreach_error(ira);
2028620286
...@@ -20301,7 +20301,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20301,7 +20301,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20301 if (type_is_invalid(casted_case_value->value.type))20301 if (type_is_invalid(casted_case_value->value.type))
20302 return ir_unreach_error(ira);20302 return ir_unreach_error(ira);
2030320303
20304 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);20304 ZigValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
20305 if (!case_val)20305 if (!case_val)
20306 return ir_unreach_error(ira);20306 return ir_unreach_error(ira);
2030720307
...@@ -20388,7 +20388,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20388,7 +20388,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20388 }20388 }
2038920389
20390 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;20390 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
20391 ConstExprValue *pointee_val = nullptr;20391 ZigValue *pointee_val = nullptr;
20392 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {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);20393 pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node);
20394 if (pointee_val == nullptr)20394 if (pointee_val == nullptr)
...@@ -20521,7 +20521,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20521,7 +20521,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20521 if (type_is_invalid(first_casted_prong_value->value.type))20521 if (type_is_invalid(first_casted_prong_value->value.type))
20522 return ira->codegen->invalid_instruction;20522 return ira->codegen->invalid_instruction;
2052320523
20524 ConstExprValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);20524 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
20525 if (first_prong_val == nullptr)20525 if (first_prong_val == nullptr)
20526 return ira->codegen->invalid_instruction;20526 return ira->codegen->invalid_instruction;
2052720527
...@@ -20537,7 +20537,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20537,7 +20537,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20537 if (type_is_invalid(this_casted_prong_value->value.type))20537 if (type_is_invalid(this_casted_prong_value->value.type))
20538 return ira->codegen->invalid_instruction;20538 return ira->codegen->invalid_instruction;
2053920539
20540 ConstExprValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);20540 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
20541 if (this_prong == nullptr)20541 if (this_prong == nullptr)
20542 return ira->codegen->invalid_instruction;20542 return ira->codegen->invalid_instruction;
2054320543
...@@ -20560,18 +20560,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20560,18 +20560,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20560 }20560 }
2056120561
20562 if (instr_is_comptime(target_value_ptr)) {20562 if (instr_is_comptime(target_value_ptr)) {
20563 ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);20563 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
20564 if (!target_value_ptr)20564 if (!target_value_ptr)
20565 return ira->codegen->invalid_instruction;20565 return ira->codegen->invalid_instruction;
2056620566
20567 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);20567 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
20568 if (pointee_val == nullptr)20568 if (pointee_val == nullptr)
20569 return ira->codegen->invalid_instruction;20569 return ira->codegen->invalid_instruction;
2057020570
20571 IrInstruction *result = ir_const(ira, &instruction->base,20571 IrInstruction *result = ir_const(ira, &instruction->base,
20572 get_pointer_to_type(ira->codegen, first_field->type_entry,20572 get_pointer_to_type(ira->codegen, first_field->type_entry,
20573 target_val_ptr->type->data.pointer.is_const));20573 target_val_ptr->type->data.pointer.is_const));
20574 ConstExprValue *out_val = &result->value;20574 ZigValue *out_val = &result->value;
20575 out_val->data.x_ptr.special = ConstPtrSpecialRef;20575 out_val->data.x_ptr.special = ConstPtrSpecialRef;
20576 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;20576 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
20577 out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload;20577 out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload;
...@@ -21161,12 +21161,12 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -21161,12 +21161,12 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
21161 true, false, PtrLenUnknown, 0, 0, 0, false);21161 true, false, PtrLenUnknown, 0, 0, 0, false);
21162 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);21162 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
21163 if (instr_is_comptime(casted_value)) {21163 if (instr_is_comptime(casted_value)) {
21164 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);21164 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
21165 if (val == nullptr)21165 if (val == nullptr)
21166 return ira->codegen->invalid_instruction;21166 return ira->codegen->invalid_instruction;
21167 ErrorTableEntry *err = casted_value->value.data.x_err_set;21167 ErrorTableEntry *err = casted_value->value.data.x_err_set;
21168 if (!err->cached_error_name_val) {21168 if (!err->cached_error_name_val) {
21169 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;21169 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
21170 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);21170 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
21171 }21171 }
21172 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);21172 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
...@@ -21195,7 +21195,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns...@@ -21195,7 +21195,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
21195 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))21195 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))
21196 return ira->codegen->invalid_instruction;21196 return ira->codegen->invalid_instruction;
21197 TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint);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;21198 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
21199 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);21199 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21200 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);21200 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);
21201 return result;21201 return result;
...@@ -21272,7 +21272,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21272,7 +21272,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21272 parent_ptr_align, 0, 0, false);21272 parent_ptr_align, 0, 0, false);
2127321273
21274 if (instr_is_comptime(casted_field_ptr)) {21274 if (instr_is_comptime(casted_field_ptr)) {
21275 ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);21275 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
21276 if (!field_ptr_val)21276 if (!field_ptr_val)
21277 return ira->codegen->invalid_instruction;21277 return ira->codegen->invalid_instruction;
2127821278
...@@ -21291,7 +21291,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21291,7 +21291,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21291 }21291 }
2129221292
21293 IrInstruction *result = ir_const(ira, &instruction->base, result_type);21293 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
21294 ConstExprValue *out_val = &result->value;21294 ZigValue *out_val = &result->value;
21295 out_val->data.x_ptr.special = ConstPtrSpecialRef;21295 out_val->data.x_ptr.special = ConstPtrSpecialRef;
21296 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;21296 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
21297 out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut;21297 out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut;
...@@ -21390,7 +21390,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind...@@ -21390,7 +21390,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind
2139021390
21391static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {21391static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {
21392 Error err;21392 Error err;
21393 ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");21393 ZigValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
21394 assert(type_info_var->type->id == ZigTypeIdMetaType);21394 assert(type_info_var->type->id == ZigTypeIdMetaType);
21395 ZigType *type_info_type = type_info_var->data.x_type;21395 ZigType *type_info_type = type_info_var->data.x_type;
21396 assert(type_info_type->id == ZigTypeIdUnion);21396 assert(type_info_type->id == ZigTypeIdUnion);
...@@ -21423,7 +21423,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -21423,7 +21423,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
21423 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);21423 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
21424}21424}
2142521425
21426static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val,21426static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val,
21427 ScopeDecls *decls_scope)21427 ScopeDecls *decls_scope)
21428{21428{
21429 Error err;21429 Error err;
...@@ -21473,7 +21473,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21473,7 +21473,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21473 }21473 }
21474 }21474 }
2147521475
21476 ConstExprValue *declaration_array = create_const_vals(1);21476 ZigValue *declaration_array = create_const_vals(1);
21477 declaration_array->special = ConstValSpecialStatic;21477 declaration_array->special = ConstValSpecialStatic;
21478 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);21478 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
21479 declaration_array->data.x_array.special = ConstArraySpecialNone;21479 declaration_array->data.x_array.special = ConstArraySpecialNone;
...@@ -21494,13 +21494,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21494,13 +21494,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21494 continue;21494 continue;
21495 }21495 }
2149621496
21497 ConstExprValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];21497 ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];
2149821498
21499 declaration_val->special = ConstValSpecialStatic;21499 declaration_val->special = ConstValSpecialStatic;
21500 declaration_val->type = type_info_declaration_type;21500 declaration_val->type = type_info_declaration_type;
2150121501
21502 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);21502 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
21503 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;21503 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
21504 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);21504 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
21505 inner_fields[1]->special = ConstValSpecialStatic;21505 inner_fields[1]->special = ConstValSpecialStatic;
21506 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;21506 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
...@@ -21528,7 +21528,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21528,7 +21528,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21528 // 1: Data.Var: type21528 // 1: Data.Var: type
21529 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);21529 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2153021530
21531 ConstExprValue *payload = create_const_vals(1);21531 ZigValue *payload = create_const_vals(1);
21532 payload->special = ConstValSpecialStatic;21532 payload->special = ConstValSpecialStatic;
21533 payload->type = ira->codegen->builtin_types.entry_type;21533 payload->type = ira->codegen->builtin_types.entry_type;
21534 payload->data.x_type = var->const_value->type;21534 payload->data.x_type = var->const_value->type;
...@@ -21553,13 +21553,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21553,13 +21553,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2155321553
21554 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;21554 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2155521555
21556 ConstExprValue *fn_decl_val = create_const_vals(1);21556 ZigValue *fn_decl_val = create_const_vals(1);
21557 fn_decl_val->special = ConstValSpecialStatic;21557 fn_decl_val->special = ConstValSpecialStatic;
21558 fn_decl_val->type = type_info_fn_decl_type;21558 fn_decl_val->type = type_info_fn_decl_type;
21559 fn_decl_val->parent.id = ConstParentIdUnion;21559 fn_decl_val->parent.id = ConstParentIdUnion;
21560 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];21560 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2156121561
21562 ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9);21562 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9);
21563 fn_decl_val->data.x_struct.fields = fn_decl_fields;21563 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2156421564
21565 // fn_type: type21565 // fn_type: type
...@@ -21603,7 +21603,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21603,7 +21603,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21603 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));21603 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
21604 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {21604 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
21605 fn_decl_fields[6]->data.x_optional = create_const_vals(1);21605 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;21606 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
21607 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,21607 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
21608 buf_len(fn_node->lib_name), true);21608 buf_len(fn_node->lib_name), true);
21609 } else {21609 } else {
...@@ -21617,7 +21617,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21617,7 +21617,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21617 // arg_names: [][] const u821617 // arg_names: [][] const u8
21618 ensure_field_index(fn_decl_val->type, "arg_names", 8);21618 ensure_field_index(fn_decl_val->type, "arg_names", 8);
21619 size_t fn_arg_count = fn_entry->variable_list.length;21619 size_t fn_arg_count = fn_entry->variable_list.length;
21620 ConstExprValue *fn_arg_name_array = create_const_vals(1);21620 ZigValue *fn_arg_name_array = create_const_vals(1);
21621 fn_arg_name_array->special = ConstValSpecialStatic;21621 fn_arg_name_array->special = ConstValSpecialStatic;
21622 fn_arg_name_array->type = get_array_type(ira->codegen,21622 fn_arg_name_array->type = get_array_type(ira->codegen,
21623 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);21623 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
...@@ -21628,8 +21628,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21628,8 +21628,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2162821628
21629 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {21629 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
21630 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);21630 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];21631 ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
21632 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,21632 ZigValue *arg_name = create_const_str_lit(ira->codegen,
21633 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;21633 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
21634 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);21634 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
21635 fn_arg_name_val->parent.id = ConstParentIdArray;21635 fn_arg_name_val->parent.id = ConstParentIdArray;
...@@ -21649,7 +21649,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21649,7 +21649,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21649 // This is a type.21649 // This is a type.
21650 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);21650 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2165121651
21652 ConstExprValue *payload = create_const_vals(1);21652 ZigValue *payload = create_const_vals(1);
21653 payload->special = ConstValSpecialStatic;21653 payload->special = ConstValSpecialStatic;
21654 payload->type = ira->codegen->builtin_types.entry_type;21654 payload->type = ira->codegen->builtin_types.entry_type;
21655 payload->data.x_type = type_entry;21655 payload->data.x_type = type_entry;
...@@ -21695,7 +21695,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {...@@ -21695,7 +21695,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
21695 zig_unreachable();21695 zig_unreachable();
21696}21696}
2169721697
21698static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {21698static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
21699 Error err;21699 Error err;
21700 ZigType *attrs_type;21700 ZigType *attrs_type;
21701 BuiltinPtrSize size_enum_index;21701 BuiltinPtrSize size_enum_index;
...@@ -21715,11 +21715,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -21715,11 +21715,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
21715 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);21715 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
21716 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));21716 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));
2171721717
21718 ConstExprValue *result = create_const_vals(1);21718 ZigValue *result = create_const_vals(1);
21719 result->special = ConstValSpecialStatic;21719 result->special = ConstValSpecialStatic;
21720 result->type = type_info_pointer_type;21720 result->type = type_info_pointer_type;
2172121721
21722 ConstExprValue **fields = alloc_const_vals_ptrs(7);21722 ZigValue **fields = alloc_const_vals_ptrs(7);
21723 result->data.x_struct.fields = fields;21723 result->data.x_struct.fields = fields;
2172421724
21725 // size: Size21725 // size: Size
...@@ -21769,17 +21769,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -21769,17 +21769,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
21769 return result;21769 return result;
21770};21770};
2177121771
21772static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,21772static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEnumField *enum_field,
21773 ZigType *type_info_enum_field_type)21773 ZigType *type_info_enum_field_type)
21774{21774{
21775 enum_field_val->special = ConstValSpecialStatic;21775 enum_field_val->special = ConstValSpecialStatic;
21776 enum_field_val->type = type_info_enum_field_type;21776 enum_field_val->type = type_info_enum_field_type;
2177721777
21778 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);21778 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
21779 inner_fields[1]->special = ConstValSpecialStatic;21779 inner_fields[1]->special = ConstValSpecialStatic;
21780 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;21780 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2178121781
21782 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee;21782 ZigValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee;
21783 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);21783 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2178421784
21785 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);21785 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);
...@@ -21788,7 +21788,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,...@@ -21788,7 +21788,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
21788}21788}
2178921789
21790static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,21790static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
21791 ConstExprValue **out)21791 ZigValue **out)
21792{21792{
21793 Error err;21793 Error err;
21794 assert(type_entry != nullptr);21794 assert(type_entry != nullptr);
...@@ -21803,7 +21803,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21803,7 +21803,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21803 return ErrorNone;21803 return ErrorNone;
21804 }21804 }
2180521805
21806 ConstExprValue *result = nullptr;21806 ZigValue *result = nullptr;
21807 switch (type_entry->id) {21807 switch (type_entry->id) {
21808 case ZigTypeIdInvalid:21808 case ZigTypeIdInvalid:
21809 zig_unreachable();21809 zig_unreachable();
...@@ -21826,7 +21826,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21826,7 +21826,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21826 result->special = ConstValSpecialStatic;21826 result->special = ConstValSpecialStatic;
21827 result->type = ir_type_info_get_type(ira, "Int", nullptr);21827 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2182821828
21829 ConstExprValue **fields = alloc_const_vals_ptrs(2);21829 ZigValue **fields = alloc_const_vals_ptrs(2);
21830 result->data.x_struct.fields = fields;21830 result->data.x_struct.fields = fields;
2183121831
21832 // is_signed: bool21832 // is_signed: bool
...@@ -21848,7 +21848,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21848,7 +21848,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21848 result->special = ConstValSpecialStatic;21848 result->special = ConstValSpecialStatic;
21849 result->type = ir_type_info_get_type(ira, "Float", nullptr);21849 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2185021850
21851 ConstExprValue **fields = alloc_const_vals_ptrs(1);21851 ZigValue **fields = alloc_const_vals_ptrs(1);
21852 result->data.x_struct.fields = fields;21852 result->data.x_struct.fields = fields;
2185321853
21854 // bits: u821854 // bits: u8
...@@ -21872,7 +21872,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21872,7 +21872,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21872 result->special = ConstValSpecialStatic;21872 result->special = ConstValSpecialStatic;
21873 result->type = ir_type_info_get_type(ira, "Array", nullptr);21873 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2187421874
21875 ConstExprValue **fields = alloc_const_vals_ptrs(3);21875 ZigValue **fields = alloc_const_vals_ptrs(3);
21876 result->data.x_struct.fields = fields;21876 result->data.x_struct.fields = fields;
2187721877
21878 // len: usize21878 // len: usize
...@@ -21896,7 +21896,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21896,7 +21896,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21896 result->special = ConstValSpecialStatic;21896 result->special = ConstValSpecialStatic;
21897 result->type = ir_type_info_get_type(ira, "Vector", nullptr);21897 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2189821898
21899 ConstExprValue **fields = alloc_const_vals_ptrs(2);21899 ZigValue **fields = alloc_const_vals_ptrs(2);
21900 result->data.x_struct.fields = fields;21900 result->data.x_struct.fields = fields;
2190121901
21902 // len: usize21902 // len: usize
...@@ -21918,7 +21918,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21918,7 +21918,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21918 result->special = ConstValSpecialStatic;21918 result->special = ConstValSpecialStatic;
21919 result->type = ir_type_info_get_type(ira, "Optional", nullptr);21919 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2192021920
21921 ConstExprValue **fields = alloc_const_vals_ptrs(1);21921 ZigValue **fields = alloc_const_vals_ptrs(1);
21922 result->data.x_struct.fields = fields;21922 result->data.x_struct.fields = fields;
2192321923
21924 // child: type21924 // child: type
...@@ -21934,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21934,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21934 result->special = ConstValSpecialStatic;21934 result->special = ConstValSpecialStatic;
21935 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);21935 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2193621936
21937 ConstExprValue **fields = alloc_const_vals_ptrs(1);21937 ZigValue **fields = alloc_const_vals_ptrs(1);
21938 result->data.x_struct.fields = fields;21938 result->data.x_struct.fields = fields;
2193921939
21940 // child: ?type21940 // child: ?type
...@@ -21951,7 +21951,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21951,7 +21951,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21951 result->special = ConstValSpecialStatic;21951 result->special = ConstValSpecialStatic;
21952 result->type = ir_type_info_get_type(ira, "Enum", nullptr);21952 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2195321953
21954 ConstExprValue **fields = alloc_const_vals_ptrs(4);21954 ZigValue **fields = alloc_const_vals_ptrs(4);
21955 result->data.x_struct.fields = fields;21955 result->data.x_struct.fields = fields;
2195621956
21957 // layout: ContainerLayout21957 // layout: ContainerLayout
...@@ -21973,7 +21973,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21973,7 +21973,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21973 }21973 }
21974 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;21974 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
2197521975
21976 ConstExprValue *enum_field_array = create_const_vals(1);21976 ZigValue *enum_field_array = create_const_vals(1);
21977 enum_field_array->special = ConstValSpecialStatic;21977 enum_field_array->special = ConstValSpecialStatic;
21978 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);21978 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
21979 enum_field_array->data.x_array.special = ConstArraySpecialNone;21979 enum_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -21984,7 +21984,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21984,7 +21984,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21984 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)21984 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
21985 {21985 {
21986 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index];21986 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];21987 ZigValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index];
21988 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);21988 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);
21989 enum_field_val->parent.id = ConstParentIdArray;21989 enum_field_val->parent.id = ConstParentIdArray;
21990 enum_field_val->parent.data.p_array.array_val = enum_field_array;21990 enum_field_val->parent.data.p_array.array_val = enum_field_array;
...@@ -22017,11 +22017,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22017,11 +22017,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22017 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {22017 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
22018 zig_unreachable();22018 zig_unreachable();
22019 }22019 }
22020 ConstExprValue *slice_val = create_const_vals(1);22020 ZigValue *slice_val = create_const_vals(1);
22021 result->data.x_optional = slice_val;22021 result->data.x_optional = slice_val;
2202222022
22023 uint32_t error_count = type_entry->data.error_set.err_count;22023 uint32_t error_count = type_entry->data.error_set.err_count;
22024 ConstExprValue *error_array = create_const_vals(1);22024 ZigValue *error_array = create_const_vals(1);
22025 error_array->special = ConstValSpecialStatic;22025 error_array->special = ConstValSpecialStatic;
22026 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);22026 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
22027 error_array->data.x_array.special = ConstArraySpecialNone;22027 error_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22030,16 +22030,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22030,16 +22030,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22030 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);22030 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
22031 for (uint32_t error_index = 0; error_index < error_count; error_index++) {22031 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
22032 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];22032 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];22033 ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];
2203422034
22035 error_val->special = ConstValSpecialStatic;22035 error_val->special = ConstValSpecialStatic;
22036 error_val->type = type_info_error_type;22036 error_val->type = type_info_error_type;
2203722037
22038 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);22038 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
22039 inner_fields[1]->special = ConstValSpecialStatic;22039 inner_fields[1]->special = ConstValSpecialStatic;
22040 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;22040 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2204122041
22042 ConstExprValue *name = nullptr;22042 ZigValue *name = nullptr;
22043 if (error->cached_error_name_val != nullptr)22043 if (error->cached_error_name_val != nullptr)
22044 name = error->cached_error_name_val;22044 name = error->cached_error_name_val;
22045 if (name == nullptr)22045 if (name == nullptr)
...@@ -22061,7 +22061,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22061,7 +22061,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22061 result->special = ConstValSpecialStatic;22061 result->special = ConstValSpecialStatic;
22062 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);22062 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2206322063
22064 ConstExprValue **fields = alloc_const_vals_ptrs(2);22064 ZigValue **fields = alloc_const_vals_ptrs(2);
22065 result->data.x_struct.fields = fields;22065 result->data.x_struct.fields = fields;
2206622066
22067 // error_set: type22067 // error_set: type
...@@ -22084,7 +22084,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22084,7 +22084,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22084 result->special = ConstValSpecialStatic;22084 result->special = ConstValSpecialStatic;
22085 result->type = ir_type_info_get_type(ira, "Union", nullptr);22085 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2208622086
22087 ConstExprValue **fields = alloc_const_vals_ptrs(4);22087 ZigValue **fields = alloc_const_vals_ptrs(4);
22088 result->data.x_struct.fields = fields;22088 result->data.x_struct.fields = fields;
2208922089
22090 // layout: ContainerLayout22090 // layout: ContainerLayout
...@@ -22101,7 +22101,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22101,7 +22101,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22101 if (union_decl_node->data.container_decl.auto_enum ||22101 if (union_decl_node->data.container_decl.auto_enum ||
22102 union_decl_node->data.container_decl.init_arg_expr != nullptr)22102 union_decl_node->data.container_decl.init_arg_expr != nullptr)
22103 {22103 {
22104 ConstExprValue *tag_type = create_const_vals(1);22104 ZigValue *tag_type = create_const_vals(1);
22105 tag_type->special = ConstValSpecialStatic;22105 tag_type->special = ConstValSpecialStatic;
22106 tag_type->type = ira->codegen->builtin_types.entry_type;22106 tag_type->type = ira->codegen->builtin_types.entry_type;
22107 tag_type->data.x_type = type_entry->data.unionation.tag_type;22107 tag_type->data.x_type = type_entry->data.unionation.tag_type;
...@@ -22117,7 +22117,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22117,7 +22117,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22117 zig_unreachable();22117 zig_unreachable();
22118 uint32_t union_field_count = type_entry->data.unionation.src_field_count;22118 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
2211922119
22120 ConstExprValue *union_field_array = create_const_vals(1);22120 ZigValue *union_field_array = create_const_vals(1);
22121 union_field_array->special = ConstValSpecialStatic;22121 union_field_array->special = ConstValSpecialStatic;
22122 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);22122 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
22123 union_field_array->data.x_array.special = ConstArraySpecialNone;22123 union_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22129,12 +22129,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22129,12 +22129,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2212922129
22130 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {22130 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
22131 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];22131 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];22132 ZigValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index];
2213322133
22134 union_field_val->special = ConstValSpecialStatic;22134 union_field_val->special = ConstValSpecialStatic;
22135 union_field_val->type = type_info_union_field_type;22135 union_field_val->type = type_info_union_field_type;
2213622136
22137 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22137 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22138 inner_fields[1]->special = ConstValSpecialStatic;22138 inner_fields[1]->special = ConstValSpecialStatic;
22139 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);22139 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2214022140
...@@ -22149,7 +22149,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22149,7 +22149,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22149 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;22149 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
22150 inner_fields[2]->data.x_type = union_field->type_entry;22150 inner_fields[2]->data.x_type = union_field->type_entry;
2215122151
22152 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;22152 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
22153 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);22153 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2215422154
22155 union_field_val->data.x_struct.fields = inner_fields;22155 union_field_val->data.x_struct.fields = inner_fields;
...@@ -22180,7 +22180,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22180,7 +22180,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22180 result->special = ConstValSpecialStatic;22180 result->special = ConstValSpecialStatic;
22181 result->type = ir_type_info_get_type(ira, "Struct", nullptr);22181 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2218222182
22183 ConstExprValue **fields = alloc_const_vals_ptrs(3);22183 ZigValue **fields = alloc_const_vals_ptrs(3);
22184 result->data.x_struct.fields = fields;22184 result->data.x_struct.fields = fields;
2218522185
22186 // layout: ContainerLayout22186 // layout: ContainerLayout
...@@ -22197,7 +22197,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22197,7 +22197,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22197 }22197 }
22198 uint32_t struct_field_count = type_entry->data.structure.src_field_count;22198 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
2219922199
22200 ConstExprValue *struct_field_array = create_const_vals(1);22200 ZigValue *struct_field_array = create_const_vals(1);
22201 struct_field_array->special = ConstValSpecialStatic;22201 struct_field_array->special = ConstValSpecialStatic;
22202 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);22202 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
22203 struct_field_array->data.x_array.special = ConstArraySpecialNone;22203 struct_field_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22207,12 +22207,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22207,12 +22207,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2220722207
22208 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {22208 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
22209 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];22209 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];22210 ZigValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index];
2221122211
22212 struct_field_val->special = ConstValSpecialStatic;22212 struct_field_val->special = ConstValSpecialStatic;
22213 struct_field_val->type = type_info_struct_field_type;22213 struct_field_val->type = type_info_struct_field_type;
2221422214
22215 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22215 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22216 inner_fields[1]->special = ConstValSpecialStatic;22216 inner_fields[1]->special = ConstValSpecialStatic;
22217 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);22217 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2221822218
...@@ -22235,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22235,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22235 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;22235 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
22236 inner_fields[2]->data.x_type = struct_field->type_entry;22236 inner_fields[2]->data.x_type = struct_field->type_entry;
2223722237
22238 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;22238 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
22239 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);22239 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2224022240
22241 struct_field_val->data.x_struct.fields = inner_fields;22241 struct_field_val->data.x_struct.fields = inner_fields;
...@@ -22259,7 +22259,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22259,7 +22259,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22259 result->special = ConstValSpecialStatic;22259 result->special = ConstValSpecialStatic;
22260 result->type = ir_type_info_get_type(ira, "Fn", nullptr);22260 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2226122261
22262 ConstExprValue **fields = alloc_const_vals_ptrs(5);22262 ZigValue **fields = alloc_const_vals_ptrs(5);
22263 result->data.x_struct.fields = fields;22263 result->data.x_struct.fields = fields;
2226422264
22265 // calling_convention: TypeInfo.CallingConvention22265 // calling_convention: TypeInfo.CallingConvention
...@@ -22286,7 +22286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22286,7 +22286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22286 if (type_entry->data.fn.fn_type_id.return_type == nullptr)22286 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
22287 fields[3]->data.x_optional = nullptr;22287 fields[3]->data.x_optional = nullptr;
22288 else {22288 else {
22289 ConstExprValue *return_type = create_const_vals(1);22289 ZigValue *return_type = create_const_vals(1);
22290 return_type->special = ConstValSpecialStatic;22290 return_type->special = ConstValSpecialStatic;
22291 return_type->type = ira->codegen->builtin_types.entry_type;22291 return_type->type = ira->codegen->builtin_types.entry_type;
22292 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;22292 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
...@@ -22300,7 +22300,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22300,7 +22300,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22300 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -22300 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
22301 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);22301 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
2230222302
22303 ConstExprValue *fn_arg_array = create_const_vals(1);22303 ZigValue *fn_arg_array = create_const_vals(1);
22304 fn_arg_array->special = ConstValSpecialStatic;22304 fn_arg_array->special = ConstValSpecialStatic;
22305 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);22305 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
22306 fn_arg_array->data.x_array.special = ConstArraySpecialNone;22306 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
...@@ -22310,7 +22310,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22310,7 +22310,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2231022310
22311 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {22311 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
22312 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];22312 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];22313 ZigValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index];
2231422314
22315 fn_arg_val->special = ConstValSpecialStatic;22315 fn_arg_val->special = ConstValSpecialStatic;
22316 fn_arg_val->type = type_info_fn_arg_type;22316 fn_arg_val->type = type_info_fn_arg_type;
...@@ -22318,7 +22318,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22318,7 +22318,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22318 bool arg_is_generic = fn_param_info->type == nullptr;22318 bool arg_is_generic = fn_param_info->type == nullptr;
22319 if (arg_is_generic) assert(is_generic);22319 if (arg_is_generic) assert(is_generic);
2232022320
22321 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);22321 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
22322 inner_fields[0]->special = ConstValSpecialStatic;22322 inner_fields[0]->special = ConstValSpecialStatic;
22323 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;22323 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
22324 inner_fields[0]->data.x_bool = arg_is_generic;22324 inner_fields[0]->data.x_bool = arg_is_generic;
...@@ -22331,7 +22331,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -22331,7 +22331,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
22331 if (arg_is_generic)22331 if (arg_is_generic)
22332 inner_fields[2]->data.x_optional = nullptr;22332 inner_fields[2]->data.x_optional = nullptr;
22333 else {22333 else {
22334 ConstExprValue *arg_type = create_const_vals(1);22334 ZigValue *arg_type = create_const_vals(1);
22335 arg_type->special = ConstValSpecialStatic;22335 arg_type->special = ConstValSpecialStatic;
22336 arg_type->type = ira->codegen->builtin_types.entry_type;22336 arg_type->type = ira->codegen->builtin_types.entry_type;
22337 arg_type->data.x_type = fn_param_info->type;22337 arg_type->data.x_type = fn_param_info->type;
...@@ -22376,12 +22376,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22376,12 +22376,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2237622376
22377 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);22377 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2237822378
22379 ConstExprValue *payload;22379 ZigValue *payload;
22380 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))22380 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
22381 return ira->codegen->invalid_instruction;22381 return ira->codegen->invalid_instruction;
2238222382
22383 IrInstruction *result = ir_const(ira, &instruction->base, result_type);22383 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
22384 ConstExprValue *out_val = &result->value;22384 ZigValue *out_val = &result->value;
22385 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));22385 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
22386 out_val->data.x_union.payload = payload;22386 out_val->data.x_union.payload = payload;
2238722387
...@@ -22393,17 +22393,17 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22393,17 +22393,17 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
22393 return result;22393 return result;
22394}22394}
2239522395
22396static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22396static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22397{22397{
22398 ensure_field_index(struct_value->type, name, field_index);22398 ensure_field_index(struct_value->type, name, field_index);
22399 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);22399 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
22400 return struct_value->data.x_struct.fields[field_index];22400 return struct_value->data.x_struct.fields[field_index];
22401}22401}
2240222402
22403static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value,22403static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
22404 const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result)22404 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
22405{22405{
22406 ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index);22406 ZigValue *field_val = get_const_field(ira, struct_value, name, field_index);
22407 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);22407 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
22408 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,22408 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
22409 get_optional_type(ira->codegen, elem_type));22409 get_optional_type(ira->codegen, elem_type));
...@@ -22414,28 +22414,28 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst...@@ -22414,28 +22414,28 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
22414 return ErrorNone;22414 return ErrorNone;
22415}22415}
2241622416
22417static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22417static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22418{22418{
22419 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22419 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22420 assert(value->type == ira->codegen->builtin_types.entry_bool);22420 assert(value->type == ira->codegen->builtin_types.entry_bool);
22421 return value->data.x_bool;22421 return value->data.x_bool;
22422}22422}
2242322423
22424static BigInt *get_const_field_lit_int(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22424static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22425{22425{
22426 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22426 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22427 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);22427 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
22428 return &value->data.x_bigint;22428 return &value->data.x_bigint;
22429}22429}
2243022430
22431static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)22431static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22432{22432{
22433 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);22433 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22434 assert(value->type == ira->codegen->builtin_types.entry_type);22434 assert(value->type == ira->codegen->builtin_types.entry_type);
22435 return value->data.x_type;22435 return value->data.x_type;
22436}22436}
2243722437
22438static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) {22438static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) {
22439 Error err;22439 Error err;
22440 switch (tagTypeId) {22440 switch (tagTypeId) {
22441 case ZigTypeIdInvalid:22441 case ZigTypeIdInvalid:
...@@ -22474,12 +22474,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22474,12 +22474,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22474 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);22474 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
22475 assert(payload->special == ConstValSpecialStatic);22475 assert(payload->special == ConstValSpecialStatic);
22476 assert(payload->type == type_info_pointer_type);22476 assert(payload->type == type_info_pointer_type);
22477 ConstExprValue *size_value = get_const_field(ira, payload, "size", 0);22477 ZigValue *size_value = get_const_field(ira, payload, "size", 0);
22478 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));22478 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
22479 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);22479 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
22480 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);22480 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
22481 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);22481 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
22482 ConstExprValue *sentinel;22482 ZigValue *sentinel;
22483 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,22483 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
22484 elem_type, &sentinel)))22484 elem_type, &sentinel)))
22485 {22485 {
...@@ -22504,7 +22504,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22504,7 +22504,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22504 assert(payload->special == ConstValSpecialStatic);22504 assert(payload->special == ConstValSpecialStatic);
22505 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));22505 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
22506 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);22506 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
22507 ConstExprValue *sentinel;22507 ZigValue *sentinel;
22508 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,22508 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
22509 elem_type, &sentinel)))22509 elem_type, &sentinel)))
22510 {22510 {
...@@ -22556,7 +22556,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT...@@ -22556,7 +22556,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
22556 if (type_is_invalid(casted_ir->value.type))22556 if (type_is_invalid(casted_ir->value.type))
22557 return ira->codegen->invalid_instruction;22557 return ira->codegen->invalid_instruction;
2255822558
22559 ConstExprValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);22559 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);
22560 if (!type_info_value)22560 if (!type_info_value)
22561 return ira->codegen->invalid_instruction;22561 return ira->codegen->invalid_instruction;
22562 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));22562 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
...@@ -22574,7 +22574,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,...@@ -22574,7 +22574,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
22574 if (type_is_invalid(type_entry))22574 if (type_is_invalid(type_entry))
22575 return ira->codegen->invalid_instruction;22575 return ira->codegen->invalid_instruction;
2257622576
22577 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");22577 ZigValue *var_value = get_builtin_value(ira->codegen, "TypeId");
22578 assert(var_value->type->id == ZigTypeIdMetaType);22578 assert(var_value->type->id == ZigTypeIdMetaType);
22579 ZigType *result_type = var_value->data.x_type;22579 ZigType *result_type = var_value->data.x_type;
2258022580
...@@ -22628,7 +22628,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -22628,7 +22628,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2262822628
22629 // Execute the C import block like an inline function22629 // Execute the C import block like an inline function
22630 ZigType *void_type = ira->codegen->builtin_types.entry_void;22630 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,22631 ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
22632 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,22632 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
22633 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);22633 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
22634 if (type_is_invalid(cimport_result->type))22634 if (type_is_invalid(cimport_result->type))
...@@ -23043,7 +23043,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -23043,7 +23043,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
23043 }23043 }
2304423044
23045 if (instr_is_comptime(target)) {23045 if (instr_is_comptime(target)) {
23046 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);23046 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
23047 if (val == nullptr)23047 if (val == nullptr)
23048 return ira->codegen->invalid_instruction;23048 return ira->codegen->invalid_instruction;
2304923049
...@@ -23232,11 +23232,11 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23232,11 +23232,11 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23232 uint64_t known_len;23232 uint64_t known_len;
2323323233
23234 if (instr_is_comptime(casted_value)) {23234 if (instr_is_comptime(casted_value)) {
23235 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);23235 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
23236 if (!val)23236 if (!val)
23237 return ira->codegen->invalid_instruction;23237 return ira->codegen->invalid_instruction;
2323823238
23239 ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index];23239 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
23240 if (value_is_comptime(len_val)) {23240 if (value_is_comptime(len_val)) {
23241 known_len = bigint_as_u64(&len_val->data.x_bigint);23241 known_len = bigint_as_u64(&len_val->data.x_bigint);
23242 have_known_len = true;23242 have_known_len = true;
...@@ -23298,22 +23298,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -23298,22 +23298,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
23298 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);23298 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
2329923299
23300 if (instr_is_comptime(target)) {23300 if (instr_is_comptime(target)) {
23301 ConstExprValue *target_val = ir_resolve_const(ira, target, UndefBad);23301 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
23302 if (target_val == nullptr)23302 if (target_val == nullptr)
23303 return ira->codegen->invalid_instruction;23303 return ira->codegen->invalid_instruction;
2330423304
23305 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);23305 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
23306 result->value.data.x_struct.fields = alloc_const_vals_ptrs(2);23306 result->value.data.x_struct.fields = alloc_const_vals_ptrs(2);
2330723307
23308 ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index];23308 ZigValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index];
23309 ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];23309 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
23310 copy_const_val(ptr_val, target_ptr_val, false);23310 copy_const_val(ptr_val, target_ptr_val, false);
23311 ptr_val->type = dest_ptr_type;23311 ptr_val->type = dest_ptr_type;
2331223312
23313 ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index];23313 ZigValue *len_val = result->value.data.x_struct.fields[slice_len_index];
23314 len_val->special = ConstValSpecialStatic;23314 len_val->special = ConstValSpecialStatic;
23315 len_val->type = ira->codegen->builtin_types.entry_usize;23315 len_val->type = ira->codegen->builtin_types.entry_usize;
23316 ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];23316 ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
23317 ZigType *elem_type = src_ptr_type->data.pointer.child_type;23317 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
23318 BigInt elem_size_bigint;23318 BigInt elem_size_bigint;
23319 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));23319 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
...@@ -23539,14 +23539,14 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23539,14 +23539,14 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23539 return ira->codegen->invalid_instruction;23539 return ira->codegen->invalid_instruction;
23540 }23540 }
2354123541
23542 ConstExprValue *mask_val = ir_resolve_const(ira, mask, UndefOk);23542 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
23543 if (mask_val == nullptr)23543 if (mask_val == nullptr)
23544 return ira->codegen->invalid_instruction;23544 return ira->codegen->invalid_instruction;
2354523545
23546 expand_undef_array(ira->codegen, mask_val);23546 expand_undef_array(ira->codegen, mask_val);
2354723547
23548 for (uint32_t i = 0; i < len_mask; i += 1) {23548 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];23549 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
23550 if (mask_elem_val->special == ConstValSpecialUndef)23550 if (mask_elem_val->special == ConstValSpecialUndef)
23551 continue;23551 continue;
23552 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);23552 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
...@@ -23575,11 +23575,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23575,11 +23575,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2357523575
23576 ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type);23576 ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type);
23577 if (instr_is_comptime(a) && instr_is_comptime(b)) {23577 if (instr_is_comptime(a) && instr_is_comptime(b)) {
23578 ConstExprValue *a_val = ir_resolve_const(ira, a, UndefOk);23578 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
23579 if (a_val == nullptr)23579 if (a_val == nullptr)
23580 return ira->codegen->invalid_instruction;23580 return ira->codegen->invalid_instruction;
2358123581
23582 ConstExprValue *b_val = ir_resolve_const(ira, b, UndefOk);23582 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
23583 if (b_val == nullptr)23583 if (b_val == nullptr)
23584 return ira->codegen->invalid_instruction;23584 return ira->codegen->invalid_instruction;
2358523585
...@@ -23589,15 +23589,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23589,15 +23589,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23589 IrInstruction *result = ir_const(ira, source_instr, result_type);23589 IrInstruction *result = ir_const(ira, source_instr, result_type);
23590 result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask);23590 result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask);
23591 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {23591 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];23592 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
23593 ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];23593 ZigValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];
23594 if (mask_elem_val->special == ConstValSpecialUndef) {23594 if (mask_elem_val->special == ConstValSpecialUndef) {
23595 result_elem_val->special = ConstValSpecialUndef;23595 result_elem_val->special = ConstValSpecialUndef;
23596 continue;23596 continue;
23597 }23597 }
23598 int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint);23598 int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint);
23599 // We've already checked for and emitted compile errors for index out of bounds here.23599 // We've already checked for and emitted compile errors for index out of bounds here.
23600 ConstExprValue *src_elem_val = (v >= 0) ?23600 ZigValue *src_elem_val = (v >= 0) ?
23601 &a->value.data.x_array.data.s_none.elements[v] :23601 &a->value.data.x_array.data.s_none.elements[v] :
23602 &b->value.data.x_array.data.s_none.elements[~v];23602 &b->value.data.x_array.data.s_none.elements[~v];
23603 copy_const_val(result_elem_val, src_elem_val, false);23603 copy_const_val(result_elem_val, src_elem_val, false);
...@@ -23686,7 +23686,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -23686,7 +23686,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
23686 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type);23686 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type);
2368723687
23688 if (instr_is_comptime(scalar)) {23688 if (instr_is_comptime(scalar)) {
23689 ConstExprValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);23689 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
23690 if (scalar_val == nullptr)23690 if (scalar_val == nullptr)
23691 return ira->codegen->invalid_instruction;23691 return ira->codegen->invalid_instruction;
23692 if (scalar_val->special == ConstValSpecialUndef)23692 if (scalar_val->special == ConstValSpecialUndef)
...@@ -23715,7 +23715,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct...@@ -23715,7 +23715,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct
23715 return ira->codegen->invalid_instruction;23715 return ira->codegen->invalid_instruction;
2371623716
23717 if (instr_is_comptime(casted_value)) {23717 if (instr_is_comptime(casted_value)) {
23718 ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad);23718 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
23719 if (value == nullptr)23719 if (value == nullptr)
23720 return ira->codegen->invalid_instruction;23720 return ira->codegen->invalid_instruction;
2372123721
...@@ -23776,22 +23776,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23776,22 +23776,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23776 instr_is_comptime(casted_byte) &&23776 instr_is_comptime(casted_byte) &&
23777 instr_is_comptime(casted_count))23777 instr_is_comptime(casted_count))
23778 {23778 {
23779 ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);23779 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
23780 if (dest_ptr_val == nullptr)23780 if (dest_ptr_val == nullptr)
23781 return ira->codegen->invalid_instruction;23781 return ira->codegen->invalid_instruction;
2378223782
23783 ConstExprValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);23783 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
23784 if (byte_val == nullptr)23784 if (byte_val == nullptr)
23785 return ira->codegen->invalid_instruction;23785 return ira->codegen->invalid_instruction;
2378623786
23787 ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);23787 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
23788 if (count_val == nullptr)23788 if (count_val == nullptr)
23789 return ira->codegen->invalid_instruction;23789 return ira->codegen->invalid_instruction;
2379023790
23791 if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&23791 if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
23792 casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)23792 casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)
23793 {23793 {
23794 ConstExprValue *dest_elements;23794 ZigValue *dest_elements;
23795 size_t start;23795 size_t start;
23796 size_t bound_end;23796 size_t bound_end;
23797 switch (dest_ptr_val->data.x_ptr.special) {23797 switch (dest_ptr_val->data.x_ptr.special) {
...@@ -23805,7 +23805,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23805,7 +23805,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23805 break;23805 break;
23806 case ConstPtrSpecialBaseArray:23806 case ConstPtrSpecialBaseArray:
23807 {23807 {
23808 ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;23808 ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;
23809 expand_undef_array(ira->codegen, array_val);23809 expand_undef_array(ira->codegen, array_val);
23810 dest_elements = array_val->data.x_array.data.s_none.elements;23810 dest_elements = array_val->data.x_array.data.s_none.elements;
23811 start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;23811 start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -23912,22 +23912,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23912,22 +23912,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23912 instr_is_comptime(casted_src_ptr) &&23912 instr_is_comptime(casted_src_ptr) &&
23913 instr_is_comptime(casted_count))23913 instr_is_comptime(casted_count))
23914 {23914 {
23915 ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);23915 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
23916 if (dest_ptr_val == nullptr)23916 if (dest_ptr_val == nullptr)
23917 return ira->codegen->invalid_instruction;23917 return ira->codegen->invalid_instruction;
2391823918
23919 ConstExprValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);23919 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
23920 if (src_ptr_val == nullptr)23920 if (src_ptr_val == nullptr)
23921 return ira->codegen->invalid_instruction;23921 return ira->codegen->invalid_instruction;
2392223922
23923 ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);23923 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
23924 if (count_val == nullptr)23924 if (count_val == nullptr)
23925 return ira->codegen->invalid_instruction;23925 return ira->codegen->invalid_instruction;
2392623926
23927 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {23927 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
23928 size_t count = bigint_as_usize(&count_val->data.x_bigint);23928 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2392923929
23930 ConstExprValue *dest_elements;23930 ZigValue *dest_elements;
23931 size_t dest_start;23931 size_t dest_start;
23932 size_t dest_end;23932 size_t dest_end;
23933 switch (dest_ptr_val->data.x_ptr.special) {23933 switch (dest_ptr_val->data.x_ptr.special) {
...@@ -23941,7 +23941,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23941,7 +23941,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23941 break;23941 break;
23942 case ConstPtrSpecialBaseArray:23942 case ConstPtrSpecialBaseArray:
23943 {23943 {
23944 ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;23944 ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val;
23945 expand_undef_array(ira->codegen, array_val);23945 expand_undef_array(ira->codegen, array_val);
23946 dest_elements = array_val->data.x_array.data.s_none.elements;23946 dest_elements = array_val->data.x_array.data.s_none.elements;
23947 dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;23947 dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -23969,7 +23969,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23969,7 +23969,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23969 return ira->codegen->invalid_instruction;23969 return ira->codegen->invalid_instruction;
23970 }23970 }
2397123971
23972 ConstExprValue *src_elements;23972 ZigValue *src_elements;
23973 size_t src_start;23973 size_t src_start;
23974 size_t src_end;23974 size_t src_end;
2397523975
...@@ -23984,7 +23984,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23984,7 +23984,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23984 break;23984 break;
23985 case ConstPtrSpecialBaseArray:23985 case ConstPtrSpecialBaseArray:
23986 {23986 {
23987 ConstExprValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val;23987 ZigValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val;
23988 expand_undef_array(ira->codegen, array_val);23988 expand_undef_array(ira->codegen, array_val);
23989 src_elements = array_val->data.x_array.data.s_none.elements;23989 src_elements = array_val->data.x_array.data.s_none.elements;
23990 src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index;23990 src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index;
...@@ -24106,8 +24106,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24106,8 +24106,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24106 value_is_comptime(&casted_start->value) &&24106 value_is_comptime(&casted_start->value) &&
24107 (!end || value_is_comptime(&end->value)))24107 (!end || value_is_comptime(&end->value)))
24108 {24108 {
24109 ConstExprValue *array_val;24109 ZigValue *array_val;
24110 ConstExprValue *parent_ptr;24110 ZigValue *parent_ptr;
24111 size_t abs_offset;24111 size_t abs_offset;
24112 size_t rel_end;24112 size_t rel_end;
24113 bool ptr_is_undef = false;24113 bool ptr_is_undef = false;
...@@ -24193,7 +24193,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24193,7 +24193,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24193 zig_panic("TODO slice of null ptr");24193 zig_panic("TODO slice of null ptr");
24194 }24194 }
24195 } else if (is_slice(array_type)) {24195 } else if (is_slice(array_type)) {
24196 ConstExprValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);24196 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
24197 if (slice_ptr == nullptr)24197 if (slice_ptr == nullptr)
24198 return ira->codegen->invalid_instruction;24198 return ira->codegen->invalid_instruction;
2419924199
...@@ -24208,7 +24208,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24208,7 +24208,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24208 return ira->codegen->invalid_instruction;24208 return ira->codegen->invalid_instruction;
24209 }24209 }
2421024210
24211 ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];24211 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
2421224212
24213 switch (parent_ptr->data.x_ptr.special) {24213 switch (parent_ptr->data.x_ptr.special) {
24214 case ConstPtrSpecialInvalid:24214 case ConstPtrSpecialInvalid:
...@@ -24246,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24246,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24246 zig_unreachable();24246 zig_unreachable();
24247 }24247 }
2424824248
24249 ConstExprValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);24249 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
24250 if (!start_val)24250 if (!start_val)
24251 return ira->codegen->invalid_instruction;24251 return ira->codegen->invalid_instruction;
2425224252
...@@ -24258,7 +24258,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24258,7 +24258,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2425824258
24259 uint64_t end_scalar = rel_end;24259 uint64_t end_scalar = rel_end;
24260 if (end) {24260 if (end) {
24261 ConstExprValue *end_val = ir_resolve_const(ira, end, UndefBad);24261 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
24262 if (!end_val)24262 if (!end_val)
24263 return ira->codegen->invalid_instruction;24263 return ira->codegen->invalid_instruction;
24264 end_scalar = bigint_as_u64(&end_val->data.x_bigint);24264 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
...@@ -24279,10 +24279,10 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24279,10 +24279,10 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24279 }24279 }
2428024280
24281 IrInstruction *result = ir_const(ira, &instruction->base, return_type);24281 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
24282 ConstExprValue *out_val = &result->value;24282 ZigValue *out_val = &result->value;
24283 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);24283 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2428424284
24285 ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];24285 ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2428624286
24287 if (array_val) {24287 if (array_val) {
24288 size_t index = abs_offset + start_scalar;24288 size_t index = abs_offset + start_scalar;
...@@ -24329,7 +24329,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -24329,7 +24329,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
24329 zig_panic("TODO");24329 zig_panic("TODO");
24330 }24330 }
2433124331
24332 ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index];24332 ZigValue *len_val = out_val->data.x_struct.fields[slice_len_index];
24333 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);24333 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);
2433424334
24335 return result;24335 return result;
...@@ -24666,21 +24666,21 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24666,21 +24666,21 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24666 instr_is_comptime(casted_op2) &&24666 instr_is_comptime(casted_op2) &&
24667 instr_is_comptime(casted_result_ptr))24667 instr_is_comptime(casted_result_ptr))
24668 {24668 {
24669 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);24669 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
24670 if (op1_val == nullptr)24670 if (op1_val == nullptr)
24671 return ira->codegen->invalid_instruction;24671 return ira->codegen->invalid_instruction;
2467224672
24673 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);24673 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
24674 if (op2_val == nullptr)24674 if (op2_val == nullptr)
24675 return ira->codegen->invalid_instruction;24675 return ira->codegen->invalid_instruction;
2467624676
24677 ConstExprValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);24677 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
24678 if (result_val == nullptr)24678 if (result_val == nullptr)
24679 return ira->codegen->invalid_instruction;24679 return ira->codegen->invalid_instruction;
2468024680
24681 BigInt *op1_bigint = &op1_val->data.x_bigint;24681 BigInt *op1_bigint = &op1_val->data.x_bigint;
24682 BigInt *op2_bigint = &op2_val->data.x_bigint;24682 BigInt *op2_bigint = &op2_val->data.x_bigint;
24683 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,24683 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
24684 casted_result_ptr->source_node);24684 casted_result_ptr->source_node);
24685 if (pointee_val == nullptr)24685 if (pointee_val == nullptr)
24686 return ira->codegen->invalid_instruction;24686 return ira->codegen->invalid_instruction;
...@@ -24721,7 +24721,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24721,7 +24721,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24721}24721}
2472224722
24723static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,24723static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,
24724 ConstExprValue *op1, ConstExprValue *op2, ConstExprValue *op3, ConstExprValue *out_val) {24724 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
24725 if (float_type->id == ZigTypeIdComptimeFloat) {24725 if (float_type->id == ZigTypeIdComptimeFloat) {
24726 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,24726 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
24727 &op3->data.x_bigfloat.value);24727 &op3->data.x_bigfloat.value);
...@@ -24791,18 +24791,18 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24791,18 +24791,18 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24791 if (instr_is_comptime(casted_op1) &&24791 if (instr_is_comptime(casted_op1) &&
24792 instr_is_comptime(casted_op2) &&24792 instr_is_comptime(casted_op2) &&
24793 instr_is_comptime(casted_op3)) {24793 instr_is_comptime(casted_op3)) {
24794 ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);24794 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
24795 if (!op1_const)24795 if (!op1_const)
24796 return ira->codegen->invalid_instruction;24796 return ira->codegen->invalid_instruction;
24797 ConstExprValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);24797 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
24798 if (!op2_const)24798 if (!op2_const)
24799 return ira->codegen->invalid_instruction;24799 return ira->codegen->invalid_instruction;
24800 ConstExprValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);24800 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
24801 if (!op3_const)24801 if (!op3_const)
24802 return ira->codegen->invalid_instruction;24802 return ira->codegen->invalid_instruction;
2480324803
24804 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);24804 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
24805 ConstExprValue *out_val = &result->value;24805 ZigValue *out_val = &result->value;
2480624806
24807 if (expr_type->id == ZigTypeIdVector) {24807 if (expr_type->id == ZigTypeIdVector) {
24808 expand_undef_array(ira->codegen, op1_const);24808 expand_undef_array(ira->codegen, op1_const);
...@@ -24812,10 +24812,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24812,10 +24812,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24812 expand_undef_array(ira->codegen, out_val);24812 expand_undef_array(ira->codegen, out_val);
24813 size_t len = expr_type->data.vector.len;24813 size_t len = expr_type->data.vector.len;
24814 for (size_t i = 0; i < len; i += 1) {24814 for (size_t i = 0; i < len; i += 1) {
24815 ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];24815 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
24816 ConstExprValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i];24816 ZigValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i];
24817 ConstExprValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i];24817 ZigValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i];
24818 ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];24818 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
24819 assert(float_operand_op1->type == float_type);24819 assert(float_operand_op1->type == float_type);
24820 assert(float_operand_op2->type == float_type);24820 assert(float_operand_op2->type == float_type);
24821 assert(float_operand_op3->type == float_type);24821 assert(float_operand_op3->type == float_type);
...@@ -24856,7 +24856,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -24856,7 +24856,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
24856 return ira->codegen->invalid_instruction;24856 return ira->codegen->invalid_instruction;
24857 if (type_entry->id == ZigTypeIdErrorUnion) {24857 if (type_entry->id == ZigTypeIdErrorUnion) {
24858 if (instr_is_comptime(value)) {24858 if (instr_is_comptime(value)) {
24859 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);24859 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
24860 if (!err_union_val)24860 if (!err_union_val)
24861 return ira->codegen->invalid_instruction;24861 return ira->codegen->invalid_instruction;
2486224862
...@@ -24911,20 +24911,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -24911,20 +24911,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
24911 ptr_type->data.pointer.explicit_alignment, 0, 0, false);24911 ptr_type->data.pointer.explicit_alignment, 0, 0, false);
2491224912
24913 if (instr_is_comptime(base_ptr)) {24913 if (instr_is_comptime(base_ptr)) {
24914 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);24914 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
24915 if (!ptr_val)24915 if (!ptr_val)
24916 return ira->codegen->invalid_instruction;24916 return ira->codegen->invalid_instruction;
24917 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&24917 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
24918 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)24918 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
24919 {24919 {
24920 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);24920 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
24921 if (err_union_val == nullptr)24921 if (err_union_val == nullptr)
24922 return ira->codegen->invalid_instruction;24922 return ira->codegen->invalid_instruction;
2492324923
24924 if (initializing && err_union_val->special == ConstValSpecialUndef) {24924 if (initializing && err_union_val->special == ConstValSpecialUndef) {
24925 ConstExprValue *vals = create_const_vals(2);24925 ZigValue *vals = create_const_vals(2);
24926 ConstExprValue *err_set_val = &vals[0];24926 ZigValue *err_set_val = &vals[0];
24927 ConstExprValue *payload_val = &vals[1];24927 ZigValue *payload_val = &vals[1];
2492824928
24929 err_set_val->special = ConstValSpecialUndef;24929 err_set_val->special = ConstValSpecialUndef;
24930 err_set_val->type = err_set_type;24930 err_set_val->type = err_set_type;
...@@ -24951,7 +24951,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -24951,7 +24951,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
24951 } else {24951 } else {
24952 result = ir_const(ira, source_instr, result_type);24952 result = ir_const(ira, source_instr, result_type);
24953 }24953 }
24954 ConstExprValue *const_val = &result->value;24954 ZigValue *const_val = &result->value;
24955 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;24955 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;
24956 const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val;24956 const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val;
24957 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;24957 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
...@@ -25000,17 +25000,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -25000,17 +25000,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
25000 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,25000 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
25001 PtrLenSingle, 0, 0, 0, false);25001 PtrLenSingle, 0, 0, 0, false);
25002 if (instr_is_comptime(base_ptr)) {25002 if (instr_is_comptime(base_ptr)) {
25003 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);25003 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
25004 if (!ptr_val)25004 if (!ptr_val)
25005 return ira->codegen->invalid_instruction;25005 return ira->codegen->invalid_instruction;
25006 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {25006 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);25007 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
25008 if (err_union_val == nullptr)25008 if (err_union_val == nullptr)
25009 return ira->codegen->invalid_instruction;25009 return ira->codegen->invalid_instruction;
25010 if (initializing && err_union_val->special == ConstValSpecialUndef) {25010 if (initializing && err_union_val->special == ConstValSpecialUndef) {
25011 ConstExprValue *vals = create_const_vals(2);25011 ZigValue *vals = create_const_vals(2);
25012 ConstExprValue *err_set_val = &vals[0];25012 ZigValue *err_set_val = &vals[0];
25013 ConstExprValue *payload_val = &vals[1];25013 ZigValue *payload_val = &vals[1];
2501425014
25015 err_set_val->special = ConstValSpecialStatic;25015 err_set_val->special = ConstValSpecialStatic;
25016 err_set_val->type = type_entry->data.error_union.err_set_type;25016 err_set_val->type = type_entry->data.error_union.err_set_type;
...@@ -25289,11 +25289,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25289,11 +25289,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25289 if (type_is_invalid(casted_end_value->value.type))25289 if (type_is_invalid(casted_end_value->value.type))
25290 return ira->codegen->invalid_instruction;25290 return ira->codegen->invalid_instruction;
2529125291
25292 ConstExprValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);25292 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
25293 if (!start_val)25293 if (!start_val)
25294 return ira->codegen->invalid_instruction;25294 return ira->codegen->invalid_instruction;
2529525295
25296 ConstExprValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);25296 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
25297 if (!end_val)25297 if (!end_val)
25298 return ira->codegen->invalid_instruction;25298 return ira->codegen->invalid_instruction;
2529925299
...@@ -25329,7 +25329,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25329,7 +25329,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25329 if (type_is_invalid(casted_value->value.type))25329 if (type_is_invalid(casted_value->value.type))
25330 return ira->codegen->invalid_instruction;25330 return ira->codegen->invalid_instruction;
2533125331
25332 ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);25332 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
25333 if (!const_expr_val)25333 if (!const_expr_val)
25334 return ira->codegen->invalid_instruction;25334 return ira->codegen->invalid_instruction;
2533525335
...@@ -25443,7 +25443,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -25443,7 +25443,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
25443 }25443 }
2544425444
25445 if (instr_is_comptime(target)) {25445 if (instr_is_comptime(target)) {
25446 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);25446 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
25447 if (!val)25447 if (!val)
25448 return ira->codegen->invalid_instruction;25448 return ira->codegen->invalid_instruction;
2544925449
...@@ -25515,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25515,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25515 if (instr_is_comptime(ptr)) {25515 if (instr_is_comptime(ptr)) {
25516 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);25516 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);
25517 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;25517 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
25518 ConstExprValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);25518 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
25519 if (!val)25519 if (!val)
25520 return ira->codegen->invalid_instruction;25520 return ira->codegen->invalid_instruction;
2552125521
...@@ -25607,18 +25607,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct...@@ -25607,18 +25607,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct
25607 instruction->safety_check_on);25607 instruction->safety_check_on);
25608}25608}
2560925609
25610static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ConstExprValue *val, size_t len) {25610static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {
25611 size_t buf_i = 0;25611 size_t buf_i = 0;
25612 // TODO optimize the buf case25612 // TODO optimize the buf case
25613 expand_undef_array(codegen, val);25613 expand_undef_array(codegen, val);
25614 for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) {25614 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];25615 ZigValue *elem = &val->data.x_array.data.s_none.elements[elem_i];
25616 buf_write_value_bytes(codegen, &buf[buf_i], elem);25616 buf_write_value_bytes(codegen, &buf[buf_i], elem);
25617 buf_i += type_size(codegen, elem->type);25617 buf_i += type_size(codegen, elem->type);
25618 }25618 }
25619}25619}
2562025620
25621static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {25621static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) {
25622 if (val->special == ConstValSpecialUndef) {25622 if (val->special == ConstValSpecialUndef) {
25623 expand_undef_struct(codegen, val);25623 expand_undef_struct(codegen, val);
25624 val->special = ConstValSpecialStatic;25624 val->special = ConstValSpecialStatic;
...@@ -25679,7 +25679,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25679,7 +25679,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25679 TypeStructField *struct_field = val->type->data.structure.fields[field_i];25679 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
25680 if (struct_field->gen_index == SIZE_MAX)25680 if (struct_field->gen_index == SIZE_MAX)
25681 continue;25681 continue;
25682 ConstExprValue *field_val = val->data.x_struct.fields[field_i];25682 ZigValue *field_val = val->data.x_struct.fields[field_i];
25683 size_t offset = struct_field->offset;25683 size_t offset = struct_field->offset;
25684 buf_write_value_bytes(codegen, buf + offset, field_val);25684 buf_write_value_bytes(codegen, buf + offset, field_val);
25685 }25685 }
...@@ -25754,7 +25754,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -25754,7 +25754,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
25754}25754}
2575525755
25756static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf,25756static 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)25757 ZigValue *val, ZigType *elem_type, size_t len)
25758{25758{
25759 Error err;25759 Error err;
25760 uint64_t elem_size = type_size(codegen, elem_type);25760 uint64_t elem_size = type_size(codegen, elem_type);
...@@ -25763,7 +25763,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod...@@ -25763,7 +25763,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
25763 case ConstArraySpecialNone:25763 case ConstArraySpecialNone:
25764 val->data.x_array.data.s_none.elements = create_const_vals(len);25764 val->data.x_array.data.s_none.elements = create_const_vals(len);
25765 for (size_t i = 0; i < len; i++) {25765 for (size_t i = 0; i < len; i++) {
25766 ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i];25766 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];
25767 elem->special = ConstValSpecialStatic;25767 elem->special = ConstValSpecialStatic;
25768 elem->type = elem_type;25768 elem->type = elem_type;
25769 if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem)))25769 if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem)))
...@@ -25778,7 +25778,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod...@@ -25778,7 +25778,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
25778 zig_unreachable();25778 zig_unreachable();
25779}25779}
2578025780
25781static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) {25781static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val) {
25782 Error err;25782 Error err;
25783 src_assert(val->special == ConstValSpecialStatic, source_node);25783 src_assert(val->special == ConstValSpecialStatic, source_node);
25784 switch (val->type->id) {25784 switch (val->type->id) {
...@@ -25850,7 +25850,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25850,7 +25850,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25850 size_t src_field_count = val->type->data.structure.src_field_count;25850 size_t src_field_count = val->type->data.structure.src_field_count;
25851 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);25851 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
25852 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {25852 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];25853 ZigValue *field_val = val->data.x_struct.fields[field_i];
25854 field_val->special = ConstValSpecialStatic;25854 field_val->special = ConstValSpecialStatic;
25855 TypeStructField *struct_field = val->type->data.structure.fields[field_i];25855 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
25856 field_val->type = struct_field->type_entry;25856 field_val->type = struct_field->type_entry;
...@@ -25887,7 +25887,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -25887,7 +25887,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
25887 src_assert(field->gen_index != SIZE_MAX, source_node);25887 src_assert(field->gen_index != SIZE_MAX, source_node);
25888 if (field->gen_index != gen_i)25888 if (field->gen_index != gen_i)
25889 break;25889 break;
25890 ConstExprValue *field_val = val->data.x_struct.fields[src_i];25890 ZigValue *field_val = val->data.x_struct.fields[src_i];
25891 field_val->special = ConstValSpecialStatic;25891 field_val->special = ConstValSpecialStatic;
25892 field_val->type = field->type_entry;25892 field_val->type = field->type_entry;
25893 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);25893 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);
...@@ -25975,7 +25975,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25975,7 +25975,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
25975 }25975 }
2597625976
25977 if (instr_is_comptime(value)) {25977 if (instr_is_comptime(value)) {
25978 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);25978 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
25979 if (!val)25979 if (!val)
25980 return ira->codegen->invalid_instruction;25980 return ira->codegen->invalid_instruction;
2598125981
...@@ -26001,7 +26001,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -26001,7 +26001,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
26001 return ira->codegen->invalid_instruction;26001 return ira->codegen->invalid_instruction;
2600226002
26003 if (instr_is_comptime(casted_int)) {26003 if (instr_is_comptime(casted_int)) {
26004 ConstExprValue *val = ir_resolve_const(ira, casted_int, UndefBad);26004 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
26005 if (!val)26005 if (!val)
26006 return ira->codegen->invalid_instruction;26006 return ira->codegen->invalid_instruction;
2600726007
...@@ -26093,7 +26093,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru...@@ -26093,7 +26093,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
26093 }26093 }
2609426094
26095 if (instr_is_comptime(target)) {26095 if (instr_is_comptime(target)) {
26096 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);26096 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
26097 if (!val)26097 if (!val)
26098 return ira->codegen->invalid_instruction;26098 return ira->codegen->invalid_instruction;
26099 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {26099 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
...@@ -26506,7 +26506,7 @@ static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, I...@@ -26506,7 +26506,7 @@ static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, I
26506}26506}
2650726507
26508static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type,26508static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type,
26509 ConstExprValue *op, ConstExprValue *out_val) {26509 ZigValue *op, ZigValue *out_val) {
26510 assert(ira && source_instr && float_type && out_val && op);26510 assert(ira && source_instr && float_type && out_val && op);
26511 assert(float_type->id == ZigTypeIdFloat ||26511 assert(float_type->id == ZigTypeIdFloat ||
26512 float_type->id == ZigTypeIdComptimeFloat);26512 float_type->id == ZigTypeIdComptimeFloat);
...@@ -26719,12 +26719,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26719,12 +26719,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26719 return ira->codegen->invalid_instruction;26719 return ira->codegen->invalid_instruction;
26720 }26720 }
2672126721
26722 ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);26722 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
26723 if (!op1_const)26723 if (!op1_const)
26724 return ira->codegen->invalid_instruction;26724 return ira->codegen->invalid_instruction;
2672526725
26726 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);26726 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
26727 ConstExprValue *out_val = &result->value;26727 ZigValue *out_val = &result->value;
2672826728
26729 if (expr_type->id == ZigTypeIdVector) {26729 if (expr_type->id == ZigTypeIdVector) {
26730 expand_undef_array(ira->codegen, op1_const);26730 expand_undef_array(ira->codegen, op1_const);
...@@ -26732,8 +26732,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26732,8 +26732,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26732 expand_undef_array(ira->codegen, out_val);26732 expand_undef_array(ira->codegen, out_val);
26733 size_t len = expr_type->data.vector.len;26733 size_t len = expr_type->data.vector.len;
26734 for (size_t i = 0; i < len; i += 1) {26734 for (size_t i = 0; i < len; i += 1) {
26735 ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];26735 ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i];
26736 ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];26736 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
26737 assert(float_operand_op1->type == float_type);26737 assert(float_operand_op1->type == float_type);
26738 assert(float_out_val->type == float_type);26738 assert(float_out_val->type == float_type);
26739 ir_eval_float_op(ira, instruction, float_type,26739 ir_eval_float_op(ira, instruction, float_type,
...@@ -26796,7 +26796,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26796,7 +26796,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26796 }26796 }
2679726797
26798 if (instr_is_comptime(op)) {26798 if (instr_is_comptime(op)) {
26799 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);26799 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
26800 if (val == nullptr)26800 if (val == nullptr)
26801 return ira->codegen->invalid_instruction;26801 return ira->codegen->invalid_instruction;
26802 if (val->special == ConstValSpecialUndef)26802 if (val->special == ConstValSpecialUndef)
...@@ -26809,13 +26809,13 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26809,13 +26809,13 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26809 expand_undef_array(ira->codegen, val);26809 expand_undef_array(ira->codegen, val);
26810 result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);26810 result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
26811 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {26811 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];26812 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
26813 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,26813 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
26814 op_elem_val, UndefOk)))26814 op_elem_val, UndefOk)))
26815 {26815 {
26816 return ira->codegen->invalid_instruction;26816 return ira->codegen->invalid_instruction;
26817 }26817 }
26818 ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];26818 ZigValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i];
26819 result_elem_val->type = int_type;26819 result_elem_val->type = int_type;
26820 result_elem_val->special = op_elem_val->special;26820 result_elem_val->special = op_elem_val->special;
26821 if (op_elem_val->special == ConstValSpecialUndef)26821 if (op_elem_val->special == ConstValSpecialUndef)
...@@ -26857,7 +26857,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -26857,7 +26857,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
26857 }26857 }
2685826858
26859 if (instr_is_comptime(op)) {26859 if (instr_is_comptime(op)) {
26860 ConstExprValue *val = ir_resolve_const(ira, op, UndefOk);26860 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
26861 if (val == nullptr)26861 if (val == nullptr)
26862 return ira->codegen->invalid_instruction;26862 return ira->codegen->invalid_instruction;
26863 if (val->special == ConstValSpecialUndef)26863 if (val->special == ConstValSpecialUndef)
...@@ -27601,7 +27601,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -27601,7 +27601,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
27601 ira->new_irb.codegen = codegen;27601 ira->new_irb.codegen = codegen;
27602 ira->new_irb.exec = new_exec;27602 ira->new_irb.exec = new_exec;
2760327603
27604 ConstExprValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count);27604 ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count);
27605 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);27605 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);
27606 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {27606 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {
27607 ira->exec_context.mem_slot_list.items[i] = &vals[i];27607 ira->exec_context.mem_slot_list.items[i] = &vals[i];
...@@ -27947,7 +27947,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -27947,7 +27947,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
27947 return get_fn_type(ira->codegen, &fn_type_id);27947 return get_fn_type(ira->codegen, &fn_type_id);
27948}27948}
2794927949
27950static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {27950static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
27951 Error err;27951 Error err;
27952 if (val->special != ConstValSpecialLazy)27952 if (val->special != ConstValSpecialLazy)
27953 return ErrorNone;27953 return ErrorNone;
...@@ -28071,7 +28071,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28071,7 +28071,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28071 if (type_is_invalid(elem_type))28071 if (type_is_invalid(elem_type))
28072 return ErrorSemanticAnalyzeFail;28072 return ErrorSemanticAnalyzeFail;
2807328073
28074 ConstExprValue *sentinel_val;28074 ZigValue *sentinel_val;
28075 if (lazy_slice_type->sentinel != nullptr) {28075 if (lazy_slice_type->sentinel != nullptr) {
28076 if (type_is_invalid(lazy_slice_type->sentinel->value.type))28076 if (type_is_invalid(lazy_slice_type->sentinel->value.type))
28077 return ErrorSemanticAnalyzeFail;28077 return ErrorSemanticAnalyzeFail;
...@@ -28149,7 +28149,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28149,7 +28149,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28149 if (type_is_invalid(elem_type))28149 if (type_is_invalid(elem_type))
28150 return ErrorSemanticAnalyzeFail;28150 return ErrorSemanticAnalyzeFail;
2815128151
28152 ConstExprValue *sentinel_val;28152 ZigValue *sentinel_val;
28153 if (lazy_ptr_type->sentinel != nullptr) {28153 if (lazy_ptr_type->sentinel != nullptr) {
28154 if (type_is_invalid(lazy_ptr_type->sentinel->value.type))28154 if (type_is_invalid(lazy_ptr_type->sentinel->value.type))
28155 return ErrorSemanticAnalyzeFail;28155 return ErrorSemanticAnalyzeFail;
...@@ -28276,7 +28276,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28276,7 +28276,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28276 zig_unreachable();28276 zig_unreachable();
28277}28277}
2827828278
28279Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) {28279Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
28280 Error err;28280 Error err;
28281 if ((err = ir_resolve_lazy_raw(source_node, val))) {28281 if ((err = ir_resolve_lazy_raw(source_node, val))) {
28282 if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) {28282 if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) {
src/ir.hpp+3-3
...@@ -18,12 +18,12 @@ enum IrPass {...@@ -18,12 +18,12 @@ enum IrPass {
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
2020
21ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,21ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2525
26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val);26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2727
28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
29 ZigType *expected_type, AstNode *expected_type_source_node);29 ZigType *expected_type, AstNode *expected_type_source_node);
...@@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_...@@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_
31bool ir_has_side_effects(IrInstruction *instruction);31bool ir_has_side_effects(IrInstruction *instruction);
3232
33struct IrAnalyze;33struct IrAnalyze;
34ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,34ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
35 AstNode *source_node);35 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op, bool llvm_name);36const char *float_op_to_name(BuiltinFnId op, bool llvm_name);
3737
src/ir_print.cpp+2-2
...@@ -396,7 +396,7 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trail...@@ -396,7 +396,7 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trail
396 ir_instruction_type_str(instruction->id), type_name, ref_count);396 ir_instruction_type_str(instruction->id), type_name, ref_count);
397}397}
398398
399static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {399static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {
400 Buf buf = BUF_INIT;400 Buf buf = BUF_INIT;
401 buf_resize(&buf, 0);401 buf_resize(&buf, 0);
402 render_const_value(irp->codegen, &buf, const_val);402 render_const_value(irp->codegen, &buf, const_val);
...@@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,...@@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,
2576 ir_print_instruction(irp, instruction, false);2576 ir_print_instruction(irp, instruction, false);
2577}2577}
25782578
2579void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass) {2579void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {
2580 IrPrint ir_print = {};2580 IrPrint ir_print = {};
2581 IrPrint *irp = &ir_print;2581 IrPrint *irp = &ir_print;
2582 irp->pass = pass;2582 irp->pass = pass;
src/ir_print.hpp+1-1
...@@ -14,7 +14,7 @@...@@ -14,7 +14,7 @@
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass);17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);
1818
19const char* ir_instruction_type_str(IrInstructionId id);19const char* ir_instruction_type_str(IrInstructionId id);
2020