diff options
| -rw-r--r-- | src/all_types.hpp | 93 | ||||
| -rw-r--r-- | src/analyze.cpp | 304 | ||||
| -rw-r--r-- | src/analyze.hpp | 106 | ||||
| -rw-r--r-- | src/bigint.cpp | 5 | ||||
| -rw-r--r-- | src/bigint.hpp | 1 | ||||
| -rw-r--r-- | src/codegen.cpp | 434 | ||||
| -rw-r--r-- | src/dump_analysis.cpp | 8 | ||||
| -rw-r--r-- | src/hash_map.hpp | 12 | ||||
| -rw-r--r-- | src/ir.cpp | 3326 | ||||
| -rw-r--r-- | src/ir.hpp | 6 | ||||
| -rw-r--r-- | src/ir_print.cpp | 12 | ||||
| -rw-r--r-- | src/ir_print.hpp | 2 | ||||
| -rw-r--r-- | src/memory_profiling.cpp | 9 | ||||
| -rw-r--r-- | src/memory_profiling.hpp | 8 | ||||
| -rw-r--r-- | src/util.cpp | 8 |
15 files changed, 2216 insertions, 2118 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 3b5a067ffc..cbe875113f 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -32,7 +32,7 @@ struct ErrorTableEntry; struct BuiltinFnEntry; struct TypeStructField; struct CodeGen; -struct ConstExprValue; +struct ZigValue; struct IrInstruction; struct IrInstructionCast; struct IrInstructionAllocaGen; @@ -130,38 +130,38 @@ struct ConstParent { union { struct { - ConstExprValue *array_val; + ZigValue *array_val; size_t elem_index; } p_array; struct { - ConstExprValue *struct_val; + ZigValue *struct_val; size_t field_index; } p_struct; struct { - ConstExprValue *err_union_val; + ZigValue *err_union_val; } p_err_union_code; struct { - ConstExprValue *err_union_val; + ZigValue *err_union_val; } p_err_union_payload; struct { - ConstExprValue *optional_val; + ZigValue *optional_val; } p_optional_payload; struct { - ConstExprValue *union_val; + ZigValue *union_val; } p_union; struct { - ConstExprValue *scalar_val; + ZigValue *scalar_val; } p_scalar; } data; }; struct ConstStructValue { - ConstExprValue **fields; + ZigValue **fields; }; struct ConstUnionValue { BigInt tag; - ConstExprValue *payload; + ZigValue *payload; }; enum ConstArraySpecial { @@ -174,7 +174,7 @@ struct ConstArrayValue { ConstArraySpecial special; union { struct { - ConstExprValue *elements; + ZigValue *elements; } s_none; Buf *s_buf; } data; @@ -235,24 +235,24 @@ struct ConstPtrValue { union { struct { - ConstExprValue *pointee; + ZigValue *pointee; } ref; struct { - ConstExprValue *array_val; + ZigValue *array_val; size_t elem_index; } base_array; struct { - ConstExprValue *struct_val; + ZigValue *struct_val; size_t field_index; } base_struct; struct { - ConstExprValue *err_union_val; + ZigValue *err_union_val; } base_err_union_code; struct { - ConstExprValue *err_union_val; + ZigValue *err_union_val; } base_err_union_payload; struct { - ConstExprValue *optional_val; + ZigValue *optional_val; } base_optional_payload; struct { uint64_t addr; @@ -264,8 +264,8 @@ struct ConstPtrValue { }; struct ConstErrValue { - ConstExprValue *error_set; - ConstExprValue *payload; + ZigValue *error_set; + ZigValue *payload; }; struct ConstBoundFnValue { @@ -406,7 +406,7 @@ struct LazyValueErrUnionType { Buf *type_name; }; -struct ConstExprValue { +struct ZigValue { ZigType *type; ConstValSpecial special; ConstParent parent; @@ -423,7 +423,7 @@ struct ConstExprValue { bool x_bool; ConstBoundFnValue x_bound_fn; ZigType *x_type; - ConstExprValue *x_optional; + ZigValue *x_optional; ConstErrValue x_err_union; ErrorTableEntry *x_err_set; BigInt x_enum_tag; @@ -443,8 +443,8 @@ struct ConstExprValue { } data; // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning - //ConstExprValue(const ConstExprValue &other) = delete; // plz zero initialize with {} - //ConstExprValue& operator= (const ConstExprValue &other) = delete; // use copy_const_val + //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {} + //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val }; enum ReturnKnowledge { @@ -525,7 +525,7 @@ struct TldCompTime { struct TldUsingNamespace { Tld base; - ConstExprValue *using_namespace_value; + ZigValue *using_namespace_value; }; struct TypeEnumField { @@ -538,7 +538,7 @@ struct TypeEnumField { struct TypeUnionField { Buf *name; ZigType *type_entry; // available after ResolveStatusSizeKnown - ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown + ZigValue *type_val; // available after ResolveStatusZeroBitsKnown TypeEnumField *enum_field; AstNode *decl_node; uint32_t gen_index; @@ -1171,7 +1171,7 @@ struct FnTypeParamInfo { struct GenericFnTypeId { CodeGen *codegen; ZigFn *fn_entry; - ConstExprValue *params; + ZigValue *params; size_t param_count; }; @@ -1213,7 +1213,7 @@ struct ZigTypePointer { // This can be null. If it is non-null, it means the pointer is terminated by this // sentinel value. This is most commonly used for C-style strings, with a 0 byte // to specify the length of the memory pointed to. - ConstExprValue *sentinel; + ZigValue *sentinel; PtrLen ptr_len; uint32_t explicit_alignment; // 0 means use ABI alignment @@ -1242,18 +1242,18 @@ struct ZigTypeFloat { struct ZigTypeArray { ZigType *child_type; uint64_t len; - ConstExprValue *sentinel; + ZigValue *sentinel; }; struct TypeStructField { Buf *name; ZigType *type_entry; // available after ResolveStatusSizeKnown - ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown + ZigValue *type_val; // available after ResolveStatusZeroBitsKnown size_t src_index; size_t gen_index; size_t offset; // byte offset from beginning of struct AstNode *decl_node; - ConstExprValue *init_val; // null and then memoized + ZigValue *init_val; // null and then memoized uint32_t bit_offset_in_host; // offset from the memory at gen_index uint32_t host_int_bytes; // size of host integer uint32_t align; @@ -1515,7 +1515,7 @@ struct ZigType { ZigType *any_frame_parent; // If we generate a constant name value for this type, we memoize it here. // The type of this is array - ConstExprValue *cached_const_name_val; + ZigValue *cached_const_name_val; OnePossibleValue one_possible_value; // Known after ResolveStatusAlignmentKnown. @@ -1771,7 +1771,7 @@ struct TypeId { CodeGen *codegen; ZigType *child_type; InferredStructField *inferred_struct_field; - ConstExprValue *sentinel; + ZigValue *sentinel; PtrLen ptr_len; uint32_t alignment; @@ -1787,7 +1787,7 @@ struct TypeId { CodeGen *codegen; ZigType *child_type; uint64_t size; - ConstExprValue *sentinel; + ZigValue *sentinel; } array; struct { bool is_signed; @@ -1960,13 +1960,13 @@ struct CodeGen { HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table; HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table; HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table; - HashMap<Scope *, ConstExprValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table; + HashMap<Scope *, ZigValue *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table; HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table; HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names; HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes; - HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table; - HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache; - HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> one_possible_values; + HashMap<Buf *, ZigValue *, buf_hash, buf_eql_buf> string_literals_table; + HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> type_info_cache; + HashMap<const ZigType *, ZigValue *, type_ptr_hash, type_ptr_eql> one_possible_values; ZigList<Tld *> resolve_queue; size_t resolve_queue_index; @@ -2021,6 +2021,13 @@ struct CodeGen { ZigType *entry_any_frame; } builtin_types; + struct { + ZigValue x_undefined; + ZigValue x_void; + ZigValue x_null; + ZigValue x_unreachable; + } intern_values; + ZigType *align_amt_type; ZigType *stack_trace_type; ZigType *err_tag_type; @@ -2043,9 +2050,9 @@ struct CodeGen { IrInstruction *invalid_instruction; IrInstruction *unreach_instruction; - ConstExprValue const_zero_byte; - ConstExprValue const_void_val; - ConstExprValue panic_msg_vals[PanicMsgIdCount]; + ZigValue const_zero_byte; + ZigValue const_void_val; + ZigValue panic_msg_vals[PanicMsgIdCount]; // The function definitions this module includes. ZigList<ZigFn *> fn_defs; @@ -2163,7 +2170,7 @@ struct CodeGen { struct ZigVar { const char *name; - ConstExprValue *const_value; + ZigValue *const_value; ZigType *var_type; LLVMValueRef value_ref; IrInstruction *is_comptime; @@ -2202,7 +2209,7 @@ struct ErrorTableEntry { ZigType *set_with_only_this_in_it; // If we generate a constant error name value for this error, we memoize it here. // The type of this is array - ConstExprValue *cached_error_name_val; + ZigValue *cached_error_name_val; }; enum ScopeId { @@ -2621,7 +2628,7 @@ struct IrInstruction { Scope *scope; AstNode *source_node; LLVMValueRef llvm_value; - ConstExprValue value; + ZigValue *value; uint32_t debug_id; // if ref_count is zero and the instruction has no side effects, // the instruction can be omitted in codegen diff --git a/src/analyze.cpp b/src/analyze.cpp index 70dfd4f181..e47b67a495 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -511,7 +511,7 @@ static void append_ptr_type_attrs(Buf *type_name, ZigType *ptr_type) { ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero, - uint32_t vector_index, InferredStructField *inferred_struct_field, ConstExprValue *sentinel) + uint32_t vector_index, InferredStructField *inferred_struct_field, ZigValue *sentinel) { assert(ptr_len != PtrLenC || allow_zero); assert(!type_is_invalid(child_type)); @@ -760,7 +760,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa return entry; } -ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel) { +ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel) { TypeId type_id = {}; type_id.id = ZigTypeIdArray; type_id.data.array.codegen = g; @@ -956,7 +956,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) { ZigType *get_stack_trace_type(CodeGen *g) { if (g->stack_trace_type == nullptr) { - ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); + ZigValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); assert(stack_trace_type_val->type->id == ZigTypeIdMetaType); 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 return entry; } -ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, +ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name, UndefAllowed undef) { size_t backward_branch_count = 0; @@ -1105,8 +1105,8 @@ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, Zig nullptr, nullptr, node, type_name, nullptr, nullptr, undef); } -Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type, - ConstExprValue *parent_type_val, bool *is_zero_bits) +Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type, + ZigValue *parent_type_val, bool *is_zero_bits) { Error err; if (type_val->special != ConstValSpecialLazy) { @@ -1134,7 +1134,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType * case LazyValueIdPtrType: { LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy); - if (parent_type_val == &lazy_ptr_type->elem_type->value) { + if (parent_type_val == lazy_ptr_type->elem_type->value) { // Does a struct which contains a pointer field to itself have bits? Yes. *is_zero_bits = false; return ErrorNone; @@ -1142,7 +1142,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType * if (parent_type_val == nullptr) { parent_type_val = type_val; } - return type_val_resolve_zero_bits(g, &lazy_ptr_type->elem_type->value, parent_type, + return type_val_resolve_zero_bits(g, lazy_ptr_type->elem_type->value, parent_type, parent_type_val, is_zero_bits); } } @@ -1160,7 +1160,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType * zig_unreachable(); } -Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool *is_opaque_type) { +Error type_val_resolve_is_opaque_type(CodeGen *g, ZigValue *type_val, bool *is_opaque_type) { if (type_val->special != ConstValSpecialLazy) { assert(type_val->special == ConstValSpecialStatic); 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 zig_unreachable(); } -static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val) { +static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ZigValue *type_val) { if (type_val->special != ConstValSpecialLazy) { return type_requires_comptime(g, type_val->data.x_type); } @@ -1197,21 +1197,21 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue zig_unreachable(); case LazyValueIdSliceType: { LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy); - return type_val_resolve_requires_comptime(g, &lazy_slice_type->elem_type->value); + return type_val_resolve_requires_comptime(g, lazy_slice_type->elem_type->value); } case LazyValueIdPtrType: { LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy); - return type_val_resolve_requires_comptime(g, &lazy_ptr_type->elem_type->value); + return type_val_resolve_requires_comptime(g, lazy_ptr_type->elem_type->value); } case LazyValueIdOptType: { LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy); - return type_val_resolve_requires_comptime(g, &lazy_opt_type->payload_type->value); + return type_val_resolve_requires_comptime(g, lazy_opt_type->payload_type->value); } case LazyValueIdFnType: { LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy); if (lazy_fn_type->is_generic) return ReqCompTimeYes; - switch (type_val_resolve_requires_comptime(g, &lazy_fn_type->return_type->value)) { + switch (type_val_resolve_requires_comptime(g, lazy_fn_type->return_type->value)) { case ReqCompTimeInvalid: return ReqCompTimeInvalid; case ReqCompTimeYes: @@ -1224,7 +1224,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i); bool param_is_var_args = param_node->data.param_decl.is_var_args; if (param_is_var_args) break; - switch (type_val_resolve_requires_comptime(g, &lazy_fn_type->param_types[i]->value)) { + switch (type_val_resolve_requires_comptime(g, lazy_fn_type->param_types[i]->value)) { case ReqCompTimeInvalid: return ReqCompTimeInvalid; case ReqCompTimeYes: @@ -1238,13 +1238,13 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue case LazyValueIdErrUnionType: { LazyValueErrUnionType *lazy_err_union_type = reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy); - return type_val_resolve_requires_comptime(g, &lazy_err_union_type->payload_type->value); + return type_val_resolve_requires_comptime(g, lazy_err_union_type->payload_type->value); } } zig_unreachable(); } -Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val, +Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val, size_t *abi_size, size_t *size_in_bits) { Error err; @@ -1267,7 +1267,7 @@ start_over: case LazyValueIdSliceType: { LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy); bool is_zero_bits; - if ((err = type_val_resolve_zero_bits(g, &lazy_slice_type->elem_type->value, nullptr, + if ((err = type_val_resolve_zero_bits(g, lazy_slice_type->elem_type->value, nullptr, nullptr, &is_zero_bits))) { return err; @@ -1284,7 +1284,7 @@ start_over: case LazyValueIdPtrType: { LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy); bool is_zero_bits; - if ((err = type_val_resolve_zero_bits(g, &lazy_ptr_type->elem_type->value, nullptr, + if ((err = type_val_resolve_zero_bits(g, lazy_ptr_type->elem_type->value, nullptr, nullptr, &is_zero_bits))) { return err; @@ -1311,7 +1311,7 @@ start_over: zig_unreachable(); } -Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align) { +Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align) { Error err; if (type_val->special != ConstValSpecialLazy) { assert(type_val->special == ConstValSpecialStatic); @@ -1337,13 +1337,13 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t return ErrorNone; case LazyValueIdOptType: { LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(type_val->data.x_lazy); - return type_val_resolve_abi_align(g, &lazy_opt_type->payload_type->value, abi_align); + return type_val_resolve_abi_align(g, lazy_opt_type->payload_type->value, abi_align); } case LazyValueIdErrUnionType: { LazyValueErrUnionType *lazy_err_union_type = reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy); uint32_t payload_abi_align; - if ((err = type_val_resolve_abi_align(g, &lazy_err_union_type->payload_type->value, + if ((err = type_val_resolve_abi_align(g, lazy_err_union_type->payload_type->value, &payload_abi_align))) { return err; @@ -1356,7 +1356,7 @@ Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t zig_unreachable(); } -static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ConstExprValue *type_val) { +static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ZigValue *type_val) { if (type_val->special != ConstValSpecialLazy) { return type_has_one_possible_value(g, type_val->data.x_type); } @@ -1384,13 +1384,13 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons case LazyValueIdErrUnionType: { LazyValueErrUnionType *lazy_err_union_type = reinterpret_cast<LazyValueErrUnionType *>(type_val->data.x_lazy); - switch (type_val_resolve_has_one_possible_value(g, &lazy_err_union_type->err_set_type->value)) { + switch (type_val_resolve_has_one_possible_value(g, lazy_err_union_type->err_set_type->value)) { case OnePossibleValueInvalid: return OnePossibleValueInvalid; case OnePossibleValueNo: return OnePossibleValueNo; case OnePossibleValueYes: - return type_val_resolve_has_one_possible_value(g, &lazy_err_union_type->payload_type->value); + return type_val_resolve_has_one_possible_value(g, lazy_err_union_type->payload_type->value); } } } @@ -1398,7 +1398,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons } ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { - ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, + ZigValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr, UndefBad); if (type_is_invalid(result->type)) 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 } static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) { - ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g), + ZigValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g), nullptr, UndefBad); if (type_is_invalid(align_result->type)) return false; @@ -1474,15 +1474,15 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, 0, 0, 0, false); ZigType *str_type = get_slice_type(g, ptr_type); - ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad); + ZigValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad); if (type_is_invalid(result_val->type)) return false; - ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index]; - ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index]; + ZigValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *len_field = result_val->data.x_struct.fields[slice_len_index]; assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray); - ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; if (array_val->data.x_array.special == ConstArraySpecialBuf) { *out_buffer = array_val->data.x_array.data.s_buf; return true; @@ -1493,7 +1493,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** buf_resize(result, len); for (size_t i = 0; i < len; i += 1) { size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; - ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; + ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; if (char_val->special == ConstValSpecialUndef) { add_node_error(g, node, buf_sprintf("use of undefined value")); return false; @@ -2621,7 +2621,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { if (tag_value != nullptr) { // A user-specified value is available - ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, + ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr, UndefBad); if (type_is_invalid(result->type)) { enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; @@ -2756,7 +2756,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { return ErrorSemanticAnalyzeFail; } - ConstExprValue *field_type_val; + ZigValue *field_type_val; if (decl_node->type == NodeTypeContainerDecl) { field_type_val = analyze_const_value(g, scope, 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) { return ErrorSemanticAnalyzeFail; } } else { - ConstExprValue *field_type_val = analyze_const_value(g, scope, + ZigValue *field_type_val = analyze_const_value(g, scope, field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef); if (type_is_invalid(field_type_val->type)) { union_type->data.unionation.resolve_status = ResolveStatusInvalid; @@ -3117,7 +3117,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { // In a second pass we will fill in the unspecified ones. if (tag_value != nullptr) { ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type; - ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, + ZigValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr, UndefBad); if (type_is_invalid(result->type)) { 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 tld->parent_scope = parent_scope; } -void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) { +void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) { Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name); resolve_top_level_decl(g, tld, tld->source_node, false); assert(tld->id == TldIdVar); @@ -3717,7 +3717,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry // Set name to nullptr to make the variable anonymous (not visible to programmer). // TODO merge with definition of add_local_var in ir.cpp ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, - bool is_const, ConstExprValue *const_value, Tld *src_tld, ZigType *var_type) + bool is_const, ZigValue *const_value, Tld *src_tld, ZigType *var_type) { Error err; assert(const_value != nullptr); @@ -3815,7 +3815,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { assert(!is_export || !is_extern); - ConstExprValue *init_value = nullptr; + ZigValue *init_value = nullptr; // TODO more validation for types that can't be used for export/extern variables ZigType *implicit_type = nullptr; @@ -3853,7 +3853,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { ZigType *type = explicit_type ? explicit_type : implicit_type; assert(type != nullptr); // should have been caught by the parser - ConstExprValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type); + ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type); tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol, is_const, init_val, &tld_var->base, type); @@ -3900,7 +3900,7 @@ static void add_symbols_from_container(CodeGen *g, TldUsingNamespace *src_using_ } } - ConstExprValue *use_expr = src_using_namespace->using_namespace_value; + ZigValue *use_expr = src_using_namespace->using_namespace_value; if (type_is_invalid(use_expr->type)) { dest_decls_scope->any_imports_failed = true; return; @@ -3977,7 +3977,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco using_namespace->base.resolution = TldResolutionResolving; assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace); - ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base, + ZigValue *result = analyze_const_value(g, &dest_decls_scope->base, using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type, nullptr, UndefBad); using_namespace->using_namespace_value = result; @@ -3985,7 +3985,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco if (type_is_invalid(result->type)) { dest_decls_scope->any_imports_failed = true; using_namespace->base.resolution = TldResolutionInvalid; - using_namespace->using_namespace_value = &g->invalid_instruction->value; + using_namespace->using_namespace_value = g->invalid_instruction->value; return; } @@ -3994,7 +3994,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name))); dest_decls_scope->any_imports_failed = true; using_namespace->base.resolution = TldResolutionInvalid; - using_namespace->using_namespace_value = &g->invalid_instruction->value; + using_namespace->using_namespace_value = g->invalid_instruction->value; return; } } @@ -5029,12 +5029,12 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) { return true; } -static uint32_t hash_const_val_error_set(ConstExprValue *const_val) { +static uint32_t hash_const_val_error_set(ZigValue *const_val) { assert(const_val->data.x_err_set != nullptr); return const_val->data.x_err_set->value ^ 2630160122; } -static uint32_t hash_const_val_ptr(ConstExprValue *const_val) { +static uint32_t hash_const_val_ptr(ZigValue *const_val) { uint32_t hash_val = 0; switch (const_val->data.x_ptr.mut) { case ConstPtrMutRuntimeVar: @@ -5095,7 +5095,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) { zig_unreachable(); } -static uint32_t hash_const_val(ConstExprValue *const_val) { +static uint32_t hash_const_val(ZigValue *const_val) { assert(const_val->special == ConstValSpecialStatic); switch (const_val->type->id) { case ZigTypeIdOpaque: @@ -5224,7 +5224,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) { uint32_t result = 0; result += hash_ptr(id->fn_entry); for (size_t i = 0; i < id->param_count; i += 1) { - ConstExprValue *generic_param = &id->params[i]; + ZigValue *generic_param = &id->params[i]; if (generic_param->special != ConstValSpecialRuntime) { result += hash_const_val(generic_param); result += hash_ptr(generic_param->type); @@ -5238,8 +5238,8 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) { if (a->fn_entry != b->fn_entry) return false; if (a->param_count != b->param_count) return false; for (size_t i = 0; i < a->param_count; i += 1) { - ConstExprValue *a_val = &a->params[i]; - ConstExprValue *b_val = &b->params[i]; + ZigValue *a_val = &a->params[i]; + ZigValue *b_val = &b->params[i]; if (a_val->type != b_val->type) return false; if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) { assert(a_val->special == ConstValSpecialStatic); @@ -5254,7 +5254,7 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) { return true; } -static bool can_mutate_comptime_var_state(ConstExprValue *value) { +static bool can_mutate_comptime_var_state(ZigValue *value) { assert(value != nullptr); switch (value->type->id) { case ZigTypeIdInvalid: @@ -5562,12 +5562,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { zig_unreachable(); } -ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) { +ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) { auto entry = g->one_possible_values.maybe_get(type_entry); if (entry != nullptr) { return entry->value; } - ConstExprValue *result = create_const_vals(1); + ZigValue *result = create_const_vals(1); result->type = type_entry; result->special = ConstValSpecialStatic; g->one_possible_values.put(type_entry, result); @@ -5637,15 +5637,15 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) { zig_unreachable(); } -void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { +void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) { auto entry = g->string_literals_table.maybe_get(str); if (entry != nullptr) { - memcpy(const_val, entry->value, sizeof(ConstExprValue)); + memcpy(const_val, entry->value, sizeof(ZigValue)); return; } // first we build the underlying array - ConstExprValue *array_val = create_const_vals(1); + ZigValue *array_val = create_const_vals(1); array_val->special = ConstValSpecialStatic; array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte); array_val->data.x_array.special = ConstArraySpecialBuf; @@ -5661,71 +5661,71 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { g->string_literals_table.put(str, const_val); } -ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_str_lit(CodeGen *g, Buf *str) { + ZigValue *const_val = create_const_vals(1); init_const_str_lit(g, const_val, str); return const_val; } -void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) { +void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_bigint(&const_val->data.x_bigint, bigint); } -ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) { + ZigValue *const_val = create_const_vals(1); init_const_bigint(const_val, type, bigint); return const_val; } -void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) { +void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_unsigned(&const_val->data.x_bigint, x); const_val->data.x_bigint.is_negative = negative; } -ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) { + ZigValue *const_val = create_const_vals(1); init_const_unsigned_negative(const_val, type, x, negative); return const_val; } -void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x) { +void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) { return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false); } -ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) { +ZigValue *create_const_usize(CodeGen *g, uint64_t x) { return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false); } -void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) { +void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_signed(&const_val->data.x_bigint, x); } -ConstExprValue *create_const_signed(ZigType *type, int64_t x) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_signed(ZigType *type, int64_t x) { + ZigValue *const_val = create_const_vals(1); init_const_signed(const_val, type, x); return const_val; } -void init_const_null(ConstExprValue *const_val, ZigType *type) { +void init_const_null(ZigValue *const_val, ZigType *type) { const_val->special = ConstValSpecialStatic; const_val->type = type; const_val->data.x_optional = nullptr; } -ConstExprValue *create_const_null(ZigType *type) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_null(ZigType *type) { + ZigValue *const_val = create_const_vals(1); init_const_null(const_val, type); return const_val; } -void init_const_float(ConstExprValue *const_val, ZigType *type, double value) { +void init_const_float(ZigValue *const_val, ZigType *type, double value) { const_val->special = ConstValSpecialStatic; const_val->type = type; if (type->id == ZigTypeIdComptimeFloat) { @@ -5752,61 +5752,61 @@ void init_const_float(ConstExprValue *const_val, ZigType *type, double value) { } } -ConstExprValue *create_const_float(ZigType *type, double value) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_float(ZigType *type, double value) { + ZigValue *const_val = create_const_vals(1); init_const_float(const_val, type, value); return const_val; } -void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) { +void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_bigint(&const_val->data.x_enum_tag, tag); } -ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_enum(ZigType *type, const BigInt *tag) { + ZigValue *const_val = create_const_vals(1); init_const_enum(const_val, type, tag); return const_val; } -void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value) { +void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) { const_val->special = ConstValSpecialStatic; const_val->type = g->builtin_types.entry_bool; const_val->data.x_bool = value; } -ConstExprValue *create_const_bool(CodeGen *g, bool value) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_bool(CodeGen *g, bool value) { + ZigValue *const_val = create_const_vals(1); init_const_bool(g, const_val, value); return const_val; } -void init_const_runtime(ConstExprValue *const_val, ZigType *type) { +void init_const_runtime(ZigValue *const_val, ZigType *type) { const_val->special = ConstValSpecialRuntime; const_val->type = type; } -ConstExprValue *create_const_runtime(ZigType *type) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_runtime(ZigType *type) { + ZigValue *const_val = create_const_vals(1); init_const_runtime(const_val, type); return const_val; } -void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) { +void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) { const_val->special = ConstValSpecialStatic; const_val->type = g->builtin_types.entry_type; const_val->data.x_type = type_value; } -ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_type(CodeGen *g, ZigType *type_value) { + ZigValue *const_val = create_const_vals(1); init_const_type(g, const_val, type_value); return const_val; } -void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, +void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val, size_t start, size_t len, bool is_const) { assert(array_val->type->id == ZigTypeIdArray); @@ -5823,13 +5823,13 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len); } -ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) { + ZigValue *const_val = create_const_vals(1); init_const_slice(g, const_val, array_val, start, len, is_const); return const_val; } -void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, +void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val, size_t elem_index, bool is_const, PtrLen ptr_len) { assert(array_val->type->id == ZigTypeIdArray); @@ -5843,28 +5843,28 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue const_val->data.x_ptr.data.base_array.elem_index = elem_index; } -ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index, bool is_const, +ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const, PtrLen ptr_len) { - ConstExprValue *const_val = create_const_vals(1); + ZigValue *const_val = create_const_vals(1); init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len); return const_val; } -void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const) { +void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const) { const_val->special = ConstValSpecialStatic; const_val->type = get_pointer_to_type(g, pointee_val->type, is_const); const_val->data.x_ptr.special = ConstPtrSpecialRef; const_val->data.x_ptr.data.ref.pointee = pointee_val; } -ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) { + ZigValue *const_val = create_const_vals(1); init_const_ptr_ref(g, const_val, pointee_val, is_const); return const_val; } -void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type, +void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type, size_t addr, bool is_const) { const_val->special = ConstValSpecialStatic; @@ -5873,47 +5873,47 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigTy const_val->data.x_ptr.data.hard_coded_addr.addr = addr; } -ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, +ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, size_t addr, bool is_const) { - ConstExprValue *const_val = create_const_vals(1); + ZigValue *const_val = create_const_vals(1); init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const); return const_val; } -void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end) { +void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end) { const_val->special = ConstValSpecialStatic; const_val->type = g->builtin_types.entry_arg_tuple; const_val->data.x_arg_tuple.start_index = arg_index_start; const_val->data.x_arg_tuple.end_index = arg_index_end; } -ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) { - ConstExprValue *const_val = create_const_vals(1); +ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) { + ZigValue *const_val = create_const_vals(1); init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end); return const_val; } -ConstExprValue *create_const_vals(size_t count) { +ZigValue *create_const_vals(size_t count) { ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs"); - ConstExprValue *vals = allocate<ConstExprValue>(count, "ConstExprValue"); + ZigValue *vals = allocate<ZigValue>(count, "ZigValue"); for (size_t i = 0; i < count; i += 1) { vals[i].global_refs = &global_refs[i]; } return vals; } -ConstExprValue **alloc_const_vals_ptrs(size_t count) { +ZigValue **alloc_const_vals_ptrs(size_t count) { return realloc_const_vals_ptrs(nullptr, 0, count); } -ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count) { +ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count) { assert(new_count >= old_count); size_t new_item_count = new_count - old_count; - ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*"); - ConstExprValue *vals = create_const_vals(new_item_count); + ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*"); + ZigValue *vals = create_const_vals(new_item_count); for (size_t i = old_count; i < new_count; i += 1) { result[i] = &vals[i - old_count]; } @@ -6106,7 +6106,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { alloca_gen->base.id = IrInstructionIdAllocaGen; alloca_gen->base.source_node = fn->proto_node; alloca_gen->base.scope = fn->child_scope; - alloca_gen->base.value.type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); + alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue"); + alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); alloca_gen->base.ref_count = 1; alloca_gen->name_hint = ""; fn->alloca_gen_list.append(alloca_gen); @@ -6173,7 +6174,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { call->frame_result_loc = all_calls_alloca; } if (largest_call_frame_type != nullptr) { - all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false); + all_calls_alloca->value->type = get_pointer_to_type(g, largest_call_frame_type, false); } // Since this frame is async, an await might represent a suspend point, and @@ -6184,7 +6185,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { IrInstructionAwaitGen *await = fn->await_list.at(i); // TODO If this is a noasync await, it doesn't suspend // https://github.com/ziglang/zig/issues/3157 - if (await->base.value.special != ConstValSpecialRuntime) { + if (await->base.value->special != ConstValSpecialRuntime) { // Known at comptime. No spill, no suspend. continue; } @@ -6211,10 +6212,10 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { } if (await->base.ref_count == 0) continue; - if (!type_has_bits(await->base.value.type)) + if (!type_has_bits(await->base.value->type)) continue; await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn, - await->base.value.type, ""); + await->base.value->type, ""); } for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) { IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i); @@ -6239,17 +6240,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { // This instruction does its own spilling specially, or otherwise doesn't need it. continue; } - if (instruction->value.special != ConstValSpecialRuntime) + if (instruction->value->special != ConstValSpecialRuntime) continue; if (instruction->ref_count == 0) continue; - if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) + if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown))) return ErrorSemanticAnalyzeFail; - if (!type_has_bits(instruction->value.type)) + if (!type_has_bits(instruction->value->type)) continue; if (scope_needs_spill(instruction->scope)) { instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node, - fn, instruction->value.type, ""); + fn, instruction->value->type, ""); } } } @@ -6301,15 +6302,15 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) { IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i); instruction->field_index = SIZE_MAX; - ZigType *ptr_type = instruction->base.value.type; + ZigType *ptr_type = instruction->base.value->type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *child_type = ptr_type->data.pointer.child_type; if (!type_has_bits(child_type)) continue; if (instruction->base.ref_count == 0) continue; - if (instruction->base.value.special != ConstValSpecialRuntime) { - if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special != + if (instruction->base.value->special != ConstValSpecialRuntime) { + if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special != ConstValSpecialRuntime) { continue; @@ -6446,17 +6447,17 @@ bool ir_get_var_is_comptime(ZigVar *var) { // When the is_comptime field references an instruction that has to get analyzed, this // is the value. if (var->is_comptime->child != nullptr) { - assert(var->is_comptime->child->value.type->id == ZigTypeIdBool); - return var->is_comptime->child->value.data.x_bool; + assert(var->is_comptime->child->value->type->id == ZigTypeIdBool); + return var->is_comptime->child->value->data.x_bool; } // As an optimization, is_comptime values which are constant are allowed // to be omitted from analysis. In this case, there is no child instruction // and we simply look at the unanalyzed const parent instruction. - assert(var->is_comptime->value.type->id == ZigTypeIdBool); - return var->is_comptime->value.data.x_bool; + assert(var->is_comptime->value->type->id == ZigTypeIdBool); + return var->is_comptime->value->data.x_bool; } -bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) { +bool const_values_equal_ptr(ZigValue *a, ZigValue *b) { if (a->data.x_ptr.special != b->data.x_ptr.special) return false; switch (a->data.x_ptr.special) { @@ -6527,7 +6528,7 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) { zig_unreachable(); } -static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprValue *b, size_t len) { +static bool const_values_equal_array(CodeGen *g, ZigValue *a, ZigValue *b, size_t len) { assert(a->data.x_array.special != ConstArraySpecialUndef); assert(b->data.x_array.special != ConstArraySpecialUndef); if (a->data.x_array.special == ConstArraySpecialBuf && @@ -6538,8 +6539,8 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal expand_undef_array(g, a); expand_undef_array(g, b); - ConstExprValue *a_elems = a->data.x_array.data.s_none.elements; - ConstExprValue *b_elems = b->data.x_array.data.s_none.elements; + ZigValue *a_elems = a->data.x_array.data.s_none.elements; + ZigValue *b_elems = b->data.x_array.data.s_none.elements; for (size_t i = 0; i < len; i += 1) { if (!const_values_equal(g, &a_elems[i], &b_elems[i])) @@ -6549,7 +6550,7 @@ static bool const_values_equal_array(CodeGen *g, ConstExprValue *a, ConstExprVal return true; } -bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) { +bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) { if (a->type->id != b->type->id) return false; assert(a->special == ConstValSpecialStatic); assert(b->special == ConstValSpecialStatic); @@ -6623,8 +6624,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) { } case ZigTypeIdStruct: for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) { - ConstExprValue *field_a = a->data.x_struct.fields[i]; - ConstExprValue *field_b = b->data.x_struct.fields[i]; + ZigValue *field_a = a->data.x_struct.fields[i]; + ZigValue *field_b = b->data.x_struct.fields[i]; if (!const_values_equal(g, field_a, field_b)) return false; } @@ -6695,7 +6696,7 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool } } -void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) { +void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max) { if (type_entry->id == ZigTypeIdInt) { const_val->special = ConstValSpecialStatic; eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max); @@ -6709,7 +6710,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v } } -static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) { +static void render_const_val_ptr(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) { if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) { buf_append_buf(buf, &type_entry->name); return; @@ -6752,7 +6753,7 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val zig_unreachable(); } -static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) { +static void render_const_val_err_set(CodeGen *g, Buf *buf, ZigValue *const_val, ZigType *type_entry) { if (const_val->data.x_err_set == nullptr) { buf_append_str(buf, "null"); } else { @@ -6760,7 +6761,7 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const } } -static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstExprValue *const_val, uint64_t start, uint64_t len) { +static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValue *const_val, uint64_t start, uint64_t len) { ConstArrayValue *array = &const_val->data.x_array; switch (array->special) { case ConstArraySpecialUndef: @@ -6784,7 +6785,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx return; } case ConstArraySpecialNone: { - ConstExprValue *base = &array->data.s_none.elements[start]; + ZigValue *base = &array->data.s_none.elements[start]; assert(start + len <= const_val->type->data.array.len); buf_appendf(buf, "%s{", buf_ptr(type_name)); @@ -6799,7 +6800,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstEx zig_unreachable(); } -void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { +void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) { switch (const_val->special) { case ConstValSpecialRuntime: buf_appendf(buf, "(runtime value)"); @@ -6927,17 +6928,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { case ZigTypeIdStruct: { if (is_slice(type_entry)) { - ConstExprValue *len_val = const_val->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = const_val->data.x_struct.fields[slice_len_index]; size_t len = bigint_as_usize(&len_val->data.x_bigint); - ConstExprValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index]; if (ptr_val->special == ConstValSpecialUndef) { assert(len == 0); buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name)); return; } assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); - ConstExprValue *array = ptr_val->data.x_ptr.data.base_array.array_val; + ZigValue *array = ptr_val->data.x_ptr.data.base_array.array_val; size_t start = ptr_val->data.x_ptr.data.base_array.elem_index; render_const_val_array(g, buf, &type_entry->name, array, start, len); @@ -7206,7 +7207,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) { zig_unreachable(); } -static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { +static void init_const_undefined(CodeGen *g, ZigValue *const_val) { Error err; ZigType *wanted_type = const_val->type; if (wanted_type->id == ZigTypeIdArray) { @@ -7221,7 +7222,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { size_t field_count = wanted_type->data.structure.src_field_count; const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count); for (size_t i = 0; i < field_count; i += 1) { - ConstExprValue *field_val = const_val->data.x_struct.fields[i]; + ZigValue *field_val = const_val->data.x_struct.fields[i]; field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]); assert(field_val->type); init_const_undefined(g, field_val); @@ -7234,14 +7235,14 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { } } -void expand_undef_struct(CodeGen *g, ConstExprValue *const_val) { +void expand_undef_struct(CodeGen *g, ZigValue *const_val) { if (const_val->special == ConstValSpecialUndef) { init_const_undefined(g, const_val); } } // Canonicalize the array value as ConstArraySpecialNone -void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { +void expand_undef_array(CodeGen *g, ZigValue *const_val) { size_t elem_count; ZigType *elem_type; if (const_val->type->id == ZigTypeIdArray) { @@ -7264,7 +7265,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { const_val->data.x_array.special = ConstArraySpecialNone; const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count); for (size_t i = 0; i < elem_count; i += 1) { - ConstExprValue *element_val = &const_val->data.x_array.data.s_none.elements[i]; + ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i]; element_val->type = elem_type; init_const_undefined(g, element_val); element_val->parent.id = ConstParentIdArray; @@ -7283,7 +7284,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { assert(elem_count == buf_len(buf)); const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count); for (size_t i = 0; i < elem_count; i += 1) { - ConstExprValue *this_char = &const_val->data.x_array.data.s_none.elements[i]; + ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i]; this_char->special = ConstValSpecialStatic; this_char->type = g->builtin_types.entry_u8; bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(buf)[i]); @@ -7541,12 +7542,12 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) { return a == b; } -ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { +ZigValue *get_builtin_value(CodeGen *codegen, const char *name) { Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name)); resolve_top_level_decl(codegen, tld, nullptr, false); assert(tld->id == TldIdVar); TldVar *tld_var = (TldVar *)tld; - ConstExprValue *var_value = tld_var->var->const_value; + ZigValue *var_value = tld_var->var->const_value; assert(var_value != nullptr); return var_value; } @@ -7733,9 +7734,9 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f } Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, - ConstExprValue *const_val, ZigType *wanted_type) + ZigValue *const_val, ZigType *wanted_type) { - ConstExprValue ptr_val = {}; + ZigValue ptr_val = {}; ptr_val.special = ConstValSpecialStatic; ptr_val.type = get_pointer_to_type(codegen, wanted_type, true); ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst; @@ -9113,7 +9114,8 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, alloca_gen->base.id = IrInstructionIdAllocaGen; alloca_gen->base.source_node = source_node; alloca_gen->base.scope = scope; - alloca_gen->base.value.type = get_pointer_to_type(g, var_type, false); + alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue"); + alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false); alloca_gen->base.ref_count = 1; alloca_gen->name_hint = name_hint; fn->alloca_gen_list.append(alloca_gen); diff --git a/src/analyze.hpp b/src/analyze.hpp index fcf993eac4..afcadd8289 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -25,7 +25,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count, bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field, - ConstExprValue *sentinel); + ZigValue *sentinel); uint64_t type_size(CodeGen *g, ZigType *type_entry); uint64_t type_size_bits(CodeGen *g, ZigType *type_entry); ZigType *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); ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type); ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id); ZigType *get_optional_type(CodeGen *g, ZigType *child_type); -ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ConstExprValue *sentinel); +ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel); ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout); @@ -95,7 +95,7 @@ ZigType *get_scope_import(Scope *scope); ScopeTypeOf *get_scope_typeof(Scope *scope); void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope); ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, - bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type); + bool is_const, ZigValue *init_value, Tld *src_tld, ZigType *var_type); ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type); ZigFn *create_fn(CodeGen *g, AstNode *proto_node); @@ -105,11 +105,11 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index); Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status); void complete_enum(CodeGen *g, ZigType *enum_type); bool ir_get_var_is_comptime(ZigVar *var); -bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b); -void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max); +bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b); +void eval_min_max_value(CodeGen *g, ZigType *type_entry, ZigValue *const_val, bool is_max); void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max); -void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val); +void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val); ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent); ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent); @@ -124,70 +124,70 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent); ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent); -void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str); -ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str); +void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str); +ZigValue *create_const_str_lit(CodeGen *g, Buf *str); -void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint); -ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint); +void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint); +ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint); -void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative); -ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative); +void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative); +ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative); -void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x); -ConstExprValue *create_const_signed(ZigType *type, int64_t x); +void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x); +ZigValue *create_const_signed(ZigType *type, int64_t x); -void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x); -ConstExprValue *create_const_usize(CodeGen *g, uint64_t x); +void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x); +ZigValue *create_const_usize(CodeGen *g, uint64_t x); -void init_const_float(ConstExprValue *const_val, ZigType *type, double value); -ConstExprValue *create_const_float(ZigType *type, double value); +void init_const_float(ZigValue *const_val, ZigType *type, double value); +ZigValue *create_const_float(ZigType *type, double value); -void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag); -ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag); +void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag); +ZigValue *create_const_enum(ZigType *type, const BigInt *tag); -void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value); -ConstExprValue *create_const_bool(CodeGen *g, bool value); +void init_const_bool(CodeGen *g, ZigValue *const_val, bool value); +ZigValue *create_const_bool(CodeGen *g, bool value); -void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value); -ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value); +void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value); +ZigValue *create_const_type(CodeGen *g, ZigType *type_value); -void init_const_runtime(ConstExprValue *const_val, ZigType *type); -ConstExprValue *create_const_runtime(ZigType *type); +void init_const_runtime(ZigValue *const_val, ZigType *type); +ZigValue *create_const_runtime(ZigType *type); -void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const); -ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const); +void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const); +ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const); -void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type, +void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *pointee_type, size_t addr, bool is_const); -ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, +ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, size_t addr, bool is_const); -void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, +void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val, size_t elem_index, bool is_const, PtrLen ptr_len); -ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index, +ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const, PtrLen ptr_len); -void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, +void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val, size_t start, size_t len, bool is_const); -ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const); +ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const); -void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end); -ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end); +void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end); +ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end); -void init_const_null(ConstExprValue *const_val, ZigType *type); -ConstExprValue *create_const_null(ZigType *type); +void init_const_null(ZigValue *const_val, ZigType *type); +ZigValue *create_const_null(ZigType *type); -ConstExprValue *create_const_vals(size_t count); -ConstExprValue **alloc_const_vals_ptrs(size_t count); -ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count); +ZigValue *create_const_vals(size_t count); +ZigValue **alloc_const_vals_ptrs(size_t count); +ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count); TypeStructField **alloc_type_struct_fields(size_t count); TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count); ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); -void expand_undef_array(CodeGen *g, ConstExprValue *const_val); -void expand_undef_struct(CodeGen *g, ConstExprValue *const_val); -void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); +void expand_undef_array(CodeGen *g, ZigValue *const_val); +void expand_undef_struct(CodeGen *g, ZigValue *const_val); +void update_compile_var(CodeGen *g, Buf *name, ZigValue *value); const char *type_id_name(ZigTypeId id); ZigTypeId type_id_at_index(size_t index); @@ -201,12 +201,12 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry); ZigType *get_align_amt_type(CodeGen *g); ZigPackage *new_anonymous_package(void); -Buf *const_value_to_buffer(ConstExprValue *const_val); +Buf *const_value_to_buffer(ZigValue *const_val); void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc); void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage); -ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name); +ZigValue *get_builtin_value(CodeGen *codegen, const char *name); ZigType *get_stack_trace_type(CodeGen *g); bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node); @@ -242,7 +242,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry); OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry); Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, - ConstExprValue *const_val, ZigType *wanted_type); + ZigValue *const_val, ZigType *wanted_type); void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn); Buf *type_bare_name(ZigType *t); @@ -256,17 +256,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa void src_assert(bool ok, AstNode *source_node); bool is_container(ZigType *type_entry); -ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, +ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name, UndefAllowed undef); void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn); bool fn_is_async(ZigFn *fn); -Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align); -Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ConstExprValue *type_val, +Error type_val_resolve_abi_align(CodeGen *g, ZigValue *type_val, uint32_t *abi_align); +Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val, size_t *abi_size, size_t *size_in_bits); -Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type, - ConstExprValue *parent_type_val, bool *is_zero_bits); +Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type, + ZigValue *parent_type_val, bool *is_zero_bits); ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field); ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field); @@ -276,5 +276,5 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigType *var_type, const char *name_hint); Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str, ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path); -ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry); +ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry); #endif diff --git a/src/bigint.cpp b/src/bigint.cpp index b227b3b4f7..6c74b5f64a 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -195,6 +195,11 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) { memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count); } +void bigint_deinit(BigInt *bi) { + if (bi->digit_count > 1) + deallocate<uint64_t>(bi->data.digits, bi->digit_count); +} + void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) { float128_t zero; ui32_to_f128M(0, &zero); diff --git a/src/bigint.hpp b/src/bigint.hpp index 276ccd64f9..483adaba54 100644 --- a/src/bigint.hpp +++ b/src/bigint.hpp @@ -34,6 +34,7 @@ void bigint_init_signed(BigInt *dest, int64_t x); void bigint_init_bigint(BigInt *dest, const BigInt *src); void bigint_init_bigfloat(BigInt *dest, const BigFloat *op); void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative); +void bigint_deinit(BigInt *bi); // panics if number won't fit uint64_t bigint_as_u64(const BigInt *bigint); diff --git a/src/codegen.cpp b/src/codegen.cpp index 6f68bad322..30ac5af4a1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -185,11 +185,11 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) { } -static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name); -static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name); -static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name); +static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name); +static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name); +static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name); static void generate_error_name_table(CodeGen *g); -static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val); +static bool value_is_all_undef(CodeGen *g, ZigValue *const_val); static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr); static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment); static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr, @@ -945,11 +945,11 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) { } static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) { - ConstExprValue *val = &g->panic_msg_vals[msg_id]; + ZigValue *val = &g->panic_msg_vals[msg_id]; if (!val->global_refs->llvm_global) { Buf *buf_msg = panic_msg_buf(msg_id); - ConstExprValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee; + ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee; init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true); render_const_val(g, val, ""); @@ -1700,37 +1700,37 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) { static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { Error err; - if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) { + if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown))) { codegen_report_errors_and_exit(g); } - if (!type_has_bits(instruction->value.type)) + if (!type_has_bits(instruction->value->type)) return nullptr; if (!instruction->llvm_value) { if (instruction->id == IrInstructionIdAwaitGen) { IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction); if (await->result_loc != nullptr) { return get_handle_value(g, ir_llvm_value(g, await->result_loc), - await->result_loc->value.type->data.pointer.child_type, await->result_loc->value.type); + await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type); } } if (instruction->spill != nullptr) { - ZigType *ptr_type = instruction->spill->value.type; + ZigType *ptr_type = instruction->spill->value->type; ir_assert(ptr_type->id == ZigTypeIdPointer, instruction); return get_handle_value(g, ir_llvm_value(g, instruction->spill), - ptr_type->data.pointer.child_type, instruction->spill->value.type); + ptr_type->data.pointer.child_type, instruction->spill->value->type); } - ir_assert(instruction->value.special != ConstValSpecialRuntime, instruction); - assert(instruction->value.type); - render_const_val(g, &instruction->value, ""); + ir_assert(instruction->value->special != ConstValSpecialRuntime, instruction); + assert(instruction->value->type); + render_const_val(g, instruction->value, ""); // we might have to do some pointer casting here due to the way union // values are rendered with a type other than the one we expect - if (handle_is_ptr(instruction->value.type)) { - render_const_val_global(g, &instruction->value, ""); - ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true); - instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, get_llvm_type(g, ptr_type), ""); + if (handle_is_ptr(instruction->value->type)) { + render_const_val_global(g, instruction->value, ""); + ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true); + instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_global, get_llvm_type(g, ptr_type), ""); } else { - instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, - get_llvm_type(g, instruction->value.type), ""); + instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_value, + get_llvm_type(g, instruction->value->type), ""); } assert(instruction->llvm_value); } @@ -1791,7 +1791,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ if (src_i >= fn_walk->data.call.inst->arg_count) return false; IrInstruction *arg = fn_walk->data.call.inst->args[src_i]; - ty = arg->value.type; + ty = arg->value->type; source_node = arg->source_node; val = ir_llvm_value(g, arg); break; @@ -2029,7 +2029,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { bool is_var_args = fn_walk->data.call.is_var_args; for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) { IrInstruction *param_instruction = instruction->args[call_i]; - ZigType *param_type = param_instruction->value.type; + ZigType *param_type = param_instruction->value->type; if (is_var_args || type_has_bits(param_type)) { LLVMValueRef param_value = ir_llvm_value(g, param_instruction); assert(param_value); @@ -2345,13 +2345,13 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) { LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type; - ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value.type : nullptr; + ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr; bool operand_has_bits = (operand_type != nullptr) && type_has_bits(operand_type); ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type; bool ret_type_has_bits = type_has_bits(ret_type); if (operand_has_bits && instruction->operand != nullptr) { - bool need_store = instruction->operand->value.special != ConstValSpecialRuntime || !handle_is_ptr(ret_type); + bool need_store = instruction->operand->value->special != ConstValSpecialRuntime || !handle_is_ptr(ret_type); if (need_store) { // It didn't get written to the result ptr. We do that now. ZigType *ret_ptr_type = get_pointer_to_type(g, ret_type, true); @@ -2448,9 +2448,9 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns return nullptr; } assert(g->cur_ret_ptr); - ir_assert(instruction->operand->value.special != ConstValSpecialRuntime, &instruction->base); + ir_assert(instruction->operand->value->special != ConstValSpecialRuntime, &instruction->base); LLVMValueRef value = ir_llvm_value(g, instruction->operand); - ZigType *return_type = instruction->operand->value.type; + ZigType *return_type = instruction->operand->value->type; gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value); LLVMBuildRetVoid(g->builder); } else if (g->cur_fn->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync && @@ -2784,7 +2784,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, IrInstruction *op1 = bin_op_instruction->op1; IrInstruction *op2 = bin_op_instruction->op2; - ZigType *operand_type = op1->value.type; + ZigType *operand_type = op1->value->type; ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type; bool want_runtime_safety = bin_op_instruction->safety_check_on && @@ -2884,7 +2884,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, case IrBinOpBitShiftLeftExact: { assert(scalar_type->id == ZigTypeIdInt); - LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value); + LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value->type, scalar_type, op2_value); bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy); if (is_sloppy) { return LLVMBuildShl(g->builder, op1_value, op2_casted, ""); @@ -2900,7 +2900,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, case IrBinOpBitShiftRightExact: { assert(scalar_type->id == ZigTypeIdInt); - LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value); + LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value->type, scalar_type, op2_value); bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy); if (is_sloppy) { if (scalar_type->data.integral.is_signed) { @@ -2990,8 +2990,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable, IrInstructionResizeSlice *instruction) { - ZigType *actual_type = instruction->operand->value.type; - ZigType *wanted_type = instruction->base.value.type; + ZigType *actual_type = instruction->operand->value->type; + ZigType *wanted_type = instruction->base.value->type; LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand); assert(expr_val); @@ -3058,8 +3058,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, IrInstructionCast *cast_instruction) { - ZigType *actual_type = cast_instruction->value->value.type; - ZigType *wanted_type = cast_instruction->base.value.type; + ZigType *actual_type = cast_instruction->value->value->type; + ZigType *wanted_type = cast_instruction->base.value->type; LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value); assert(expr_val); @@ -3136,8 +3136,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable, IrInstructionPtrOfArrayToSlice *instruction) { - ZigType *actual_type = instruction->operand->value.type; - ZigType *slice_type = instruction->base.value.type; + ZigType *actual_type = instruction->operand->value->type; + ZigType *slice_type = instruction->base.value->type; ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index; size_t len_index = slice_type->data.structure.fields[slice_len_index]->gen_index; @@ -3173,7 +3173,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable, IrInstructionPtrCastGen *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; if (!type_has_bits(wanted_type)) { return nullptr; } @@ -3199,8 +3199,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable, IrInstructionBitCastGen *instruction) { - ZigType *wanted_type = instruction->base.value.type; - ZigType *actual_type = instruction->operand->value.type; + ZigType *wanted_type = instruction->base.value->type; + ZigType *actual_type = instruction->operand->value->type; LLVMValueRef value = ir_llvm_value(g, instruction->operand); bool wanted_is_ptr = handle_is_ptr(wanted_type); @@ -3223,7 +3223,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable, IrInstructionWidenOrShorten *instruction) { - ZigType *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value->type; // TODO instead of this logic, use the Noop instruction to change the type from // enum_tag to the underlying int type ZigType *int_type; @@ -3234,11 +3234,11 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa } LLVMValueRef target_val = ir_llvm_value(g, instruction->target); return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), int_type, - instruction->base.value.type, target_val); + instruction->base.value->type, target_val); } static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); if (!ptr_allows_addr_zero(wanted_type) && ir_want_runtime_safety(g, &instruction->base)) { LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(target_val)); @@ -3256,19 +3256,19 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I } static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), ""); } static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdEnum); ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), - instruction->target->value.type, tag_int_type, target_val); + instruction->target->value->type, tag_int_type, target_val); if (ir_want_runtime_safety(g, &instruction->base)) { LLVMBasicBlockRef bad_value_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadValue"); @@ -3289,10 +3289,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, } static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdErrorSet); - ZigType *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value->type; assert(actual_type->id == ZigTypeIdInt); assert(!actual_type->data.integral.is_signed); @@ -3306,11 +3306,11 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I } static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdInt); assert(!wanted_type->data.integral.is_signed); - ZigType *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value->type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); if (actual_type->id == ZigTypeIdErrorSet) { @@ -3360,7 +3360,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) { IrUnOp op_id = un_op_instruction->op_id; LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value); - ZigType *operand_type = un_op_instruction->value->value.type; + ZigType *operand_type = un_op_instruction->value->value->type; ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type; switch (op_id) { @@ -3419,12 +3419,12 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrI static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtrGen *instruction) { - ZigType *child_type = instruction->base.value.type; + ZigType *child_type = instruction->base.value->type; if (!type_has_bits(child_type)) return nullptr; LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); - ZigType *ptr_type = instruction->ptr->value.type; + ZigType *ptr_type = instruction->ptr->value->type; assert(ptr_type->id == ZigTypeIdPointer); ir_assert(ptr_type->data.pointer.vector_index != VECTOR_INDEX_RUNTIME, &instruction->base); @@ -3474,7 +3474,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), ""); } -static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size_t len) { +static bool value_is_all_undef_array(CodeGen *g, ZigValue *const_val, size_t len) { switch (const_val->data.x_array.special) { case ConstArraySpecialUndef: return true; @@ -3490,7 +3490,7 @@ static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size zig_unreachable(); } -static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) { +static bool value_is_all_undef(CodeGen *g, ZigValue *const_val) { Error err; if (const_val->special == ConstValSpecialLazy && (err = ir_resolve_lazy(g, nullptr, const_val))) @@ -3622,7 +3622,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) { Error err; - ZigType *ptr_type = instruction->ptr->value.type; + ZigType *ptr_type = instruction->ptr->value->type; assert(ptr_type->id == ZigTypeIdPointer); bool ptr_type_has_bits; if ((err = type_has_bits2(g, ptr_type, &ptr_type_has_bits))) @@ -3639,13 +3639,13 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir return nullptr; } - bool have_init_expr = !value_is_all_undef(g, &instruction->value->value); + bool have_init_expr = !value_is_all_undef(g, instruction->value->value); if (have_init_expr) { LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); LLVMValueRef value = ir_llvm_value(g, instruction->value); gen_assign_raw(g, ptr, ptr_type, value); } else if (ir_want_runtime_safety(g, &instruction->base)) { - gen_undef_init(g, get_ptr_align(g, ptr_type), instruction->value->value.type, + gen_undef_init(g, get_ptr_align(g, ptr_type), instruction->value->value->type, ir_llvm_value(g, instruction->ptr)); } return nullptr; @@ -3658,14 +3658,14 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut LLVMValueRef index = ir_llvm_value(g, instruction->index); LLVMValueRef value = ir_llvm_value(g, instruction->value); - LLVMValueRef loaded_vector = gen_load(g, vector_ptr, instruction->vector_ptr->value.type, ""); + LLVMValueRef loaded_vector = gen_load(g, vector_ptr, instruction->vector_ptr->value->type, ""); LLVMValueRef modified_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, index, ""); - gen_store(g, modified_vector, vector_ptr, instruction->vector_ptr->value.type); + gen_store(g, modified_vector, vector_ptr, instruction->vector_ptr->value->type); return nullptr; } static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) { - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return ir_llvm_value(g, &instruction->base); ZigVar *var = instruction->var; if (type_has_bits(var->var_type)) { @@ -3679,7 +3679,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable, IrInstructionReturnPtr *instruction) { - if (!type_has_bits(instruction->base.value.type)) + if (!type_has_bits(instruction->base.value->type)) return nullptr; ir_assert(g->cur_ret_ptr != nullptr, &instruction->base); return g->cur_ret_ptr; @@ -3687,7 +3687,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) { LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr); - ZigType *array_ptr_type = instruction->array_ptr->value.type; + ZigType *array_ptr_type = instruction->array_ptr->value->type; assert(array_ptr_type->id == ZigTypeIdPointer); ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index); @@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI if (child_type->id == ZigTypeIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { - ZigType *ptr_type = instruction->base.value.type; + ZigType *ptr_type = instruction->base.value->type; size_t host_int_bytes = ptr_type->data.pointer.host_int_bytes; if (host_int_bytes != 0) { uint32_t size_in_bits = type_size_bits(g, ptr_type->data.pointer.child_type); @@ -3941,7 +3941,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr } else { assert(instruction->fn_ref); fn_val = ir_llvm_value(g, instruction->fn_ref); - fn_type = instruction->fn_ref->value.type; + fn_type = instruction->fn_ref->value->type; callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync; } @@ -3975,8 +3975,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), ""); } } else { - if (instruction->new_stack->value.type->id == ZigTypeIdPointer && - instruction->new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) + if (instruction->new_stack->value->type->id == ZigTypeIdPointer && + instruction->new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) { frame_result_loc = ir_llvm_value(g, instruction->new_stack); } else { @@ -4189,7 +4189,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr gen_resume(g, fn_val, frame_result_loc, ResumeIdCall); if (instruction->new_stack != nullptr) { return LLVMBuildBitCast(g->builder, frame_result_loc, - get_llvm_type(g, instruction->base.value.type), ""); + get_llvm_type(g, instruction->base.value->type), ""); } return nullptr; } else if (instruction->modifier == CallModifierNoAsync && !fn_is_async(g->cur_fn)) { @@ -4214,7 +4214,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr LLVMPositionBuilderAtEnd(g->builder, ok_block); } - ZigType *result_type = instruction->base.value.type; + ZigType *result_type = instruction->base.value->type; ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true); return gen_await_early_return(g, &instruction->base, frame_result_loc, result_type, ptr_result_type, result_loc, true); @@ -4285,7 +4285,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr return result_loc; } else if (handle_is_ptr(src_return_type)) { LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc); - LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value.type)); + LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value->type)); return result_loc; } else if (!callee_is_async && instruction->modifier == CallModifierAsync) { LLVMBuildStore(g->builder, result, ret_ptr); @@ -4300,12 +4300,12 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa { Error err; - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return nullptr; LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr); // not necessarily a pointer. could be ZigTypeIdStruct - ZigType *struct_ptr_type = instruction->struct_ptr->value.type; + ZigType *struct_ptr_type = instruction->struct_ptr->value->type; TypeStructField *field = instruction->field; if (!type_has_bits(field->type_entry)) @@ -4324,7 +4324,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa ir_assert(field->gen_index != SIZE_MAX, &instruction->base); LLVMValueRef field_ptr_val = LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, ""); - ZigType *res_type = instruction->base.value.type; + ZigType *res_type = instruction->base.value->type; ir_assert(res_type->id == ZigTypeIdPointer, &instruction->base); if (res_type->data.pointer.host_int_bytes != 0) { // We generate packed structs with get_llvm_type_of_n_bytes, which is @@ -4340,10 +4340,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable, IrInstructionUnionFieldPtr *instruction) { - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return nullptr; - ZigType *union_ptr_type = instruction->union_ptr->value.type; + ZigType *union_ptr_type = instruction->union_ptr->value->type; assert(union_ptr_type->id == ZigTypeIdPointer); ZigType *union_type = union_ptr_type->data.pointer.child_type; assert(union_type->id == ZigTypeIdUnion); @@ -4528,7 +4528,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru buf_append_char(&constraint_buf, ','); } - ZigType *const type = ir_input->value.type; + ZigType *const type = ir_input->value->type; LLVMTypeRef type_ref = get_llvm_type(g, type); LLVMValueRef value_ref = ir_llvm_value(g, ir_input); // Handle integers of non pot bitsize by widening them. @@ -4558,7 +4558,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru if (instruction->return_count == 0) { ret_type = LLVMVoidType(); } else { - ret_type = get_llvm_type(g, instruction->base.value.type); + ret_type = get_llvm_type(g, instruction->base.value->type); } LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false); @@ -4588,16 +4588,16 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable, IrInstructionTestNonNull *instruction) { - return gen_non_null_bit(g, instruction->value->value.type, ir_llvm_value(g, instruction->value)); + return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value)); } static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable, IrInstructionOptionalUnwrapPtr *instruction) { - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return nullptr; - ZigType *ptr_type = instruction->base_ptr->value.type; + ZigType *ptr_type = instruction->base_ptr->value->type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *maybe_type = ptr_type->data.pointer.child_type; assert(maybe_type->id == ZigTypeIdOptional); @@ -4695,7 +4695,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn } static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) { - ZigType *int_type = instruction->op->value.type; + ZigType *int_type = instruction->op->value->type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz); LLVMValueRef operand = ir_llvm_value(g, instruction->op); LLVMValueRef params[] { @@ -4703,11 +4703,11 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru LLVMConstNull(LLVMInt1Type()), }; LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, ""); - return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int); + return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); } static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) { - ZigType *int_type = instruction->op->value.type; + ZigType *int_type = instruction->op->value->type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz); LLVMValueRef operand = ir_llvm_value(g, instruction->op); LLVMValueRef params[] { @@ -4715,12 +4715,12 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru LLVMConstNull(LLVMInt1Type()), }; LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, params, 2, ""); - return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int); + return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); } static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) { - uint64_t len_a = instruction->a->value.type->data.vector.len; - uint64_t len_mask = instruction->mask->value.type->data.vector.len; + uint64_t len_a = instruction->a->value->type->data.vector.len; + uint64_t len_mask = instruction->mask->value->type->data.vector.len; // LLVM uses integers larger than the length of the first array to // index into the second array. This was deemed unnecessarily fragile @@ -4730,10 +4730,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl IrInstruction *mask = instruction->mask; LLVMValueRef *values = allocate<LLVMValueRef>(len_mask); for (uint64_t i = 0; i < len_mask; i++) { - if (mask->value.data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) { + if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) { values[i] = LLVMGetUndef(LLVMInt32Type()); } else { - int32_t v = bigint_as_signed(&mask->value.data.x_array.data.s_none.elements[i].data.x_bigint); + int32_t v = bigint_as_signed(&mask->value->data.x_array.data.s_none.elements[i].data.x_bigint); uint32_t index_val = (v >= 0) ? (uint32_t)v : (uint32_t)~v + (uint32_t)len_a; values[i] = LLVMConstInt(LLVMInt32Type(), index_val, false); } @@ -4749,10 +4749,10 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl } static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) { - ZigType *result_type = instruction->base.value.type; + ZigType *result_type = instruction->base.value->type; ir_assert(result_type->id == ZigTypeIdVector, &instruction->base); uint32_t len = result_type->data.vector.len; - LLVMTypeRef op_llvm_type = LLVMVectorType(get_llvm_type(g, instruction->scalar->value.type), 1); + LLVMTypeRef op_llvm_type = LLVMVectorType(get_llvm_type(g, instruction->scalar->value->type), 1); LLVMTypeRef mask_llvm_type = LLVMVectorType(LLVMInt32Type(), len); LLVMValueRef undef_vector = LLVMGetUndef(op_llvm_type); LLVMValueRef op_vector = LLVMBuildInsertElement(g->builder, undef_vector, @@ -4761,11 +4761,11 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst } static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) { - ZigType *int_type = instruction->op->value.type; + ZigType *int_type = instruction->op->value->type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount); LLVMValueRef operand = ir_llvm_value(g, instruction->op); LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, ""); - return gen_widen_or_shorten(g, false, int_type, instruction->base.value.type, wrong_size_int); + return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); } static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) { @@ -4781,14 +4781,14 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir } static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) { - if (!type_has_bits(instruction->base.value.type)) + if (!type_has_bits(instruction->base.value->type)) return nullptr; LLVMTypeRef phi_type; - if (handle_is_ptr(instruction->base.value.type)) { - phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value.type), 0); + if (handle_is_ptr(instruction->base.value->type)) { + phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0); } else { - phi_type = get_llvm_type(g, instruction->base.value.type); + phi_type = get_llvm_type(g, instruction->base.value->type); } LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, ""); @@ -4803,11 +4803,11 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru } static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) { - if (!type_has_bits(instruction->base.value.type)) { + if (!type_has_bits(instruction->base.value->type)) { return nullptr; } LLVMValueRef value = ir_llvm_value(g, instruction->operand); - if (handle_is_ptr(instruction->operand->value.type)) { + if (handle_is_ptr(instruction->operand->value->type)) { return value; } else { LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); @@ -4940,7 +4940,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) { static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable, IrInstructionTagName *instruction) { - ZigType *enum_type = instruction->target->value.type; + ZigType *enum_type = instruction->target->value->type; assert(enum_type->id == ZigTypeIdEnum); LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); @@ -4953,7 +4953,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable, IrInstructionFieldParentPtr *instruction) { - ZigType *container_ptr_type = instruction->base.value.type; + ZigType *container_ptr_type = instruction->base.value->type; assert(container_ptr_type->id == ZigTypeIdPointer); ZigType *container_type = container_ptr_type->data.pointer.child_type; @@ -4986,7 +4986,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I return target_val; } - ZigType *target_type = instruction->base.value.type; + ZigType *target_type = instruction->base.value->type; uint32_t align_bytes; LLVMValueRef ptr_val; @@ -5089,7 +5089,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val, success_order, failure_order, instruction->is_weak); - ZigType *optional_type = instruction->base.value.type; + ZigType *optional_type = instruction->base.value->type; assert(optional_type->id == ZigTypeIdOptional); ZigType *child_type = optional_type->data.maybe.child_type; @@ -5100,7 +5100,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn } // When the cmpxchg is discarded, the result location will have no bits. - if (!type_has_bits(instruction->result_loc->value.type)) { + if (!type_has_bits(instruction->result_loc->value->type)) { return nullptr; } @@ -5127,8 +5127,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) { LLVMValueRef target_val = ir_llvm_value(g, instruction->target); - ZigType *dest_type = instruction->base.value.type; - ZigType *src_type = instruction->target->value.type; + ZigType *dest_type = instruction->base.value->type; + ZigType *src_type = instruction->target->value->type; if (dest_type == src_type) { // no-op return target_val; @@ -5147,10 +5147,10 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); - ZigType *ptr_type = instruction->dest_ptr->value.type; + ZigType *ptr_type = instruction->dest_ptr->value->type; assert(ptr_type->id == ZigTypeIdPointer); - bool val_is_undef = value_is_all_undef(g, &instruction->byte->value); + bool val_is_undef = value_is_all_undef(g, instruction->byte->value); LLVMValueRef fill_char; if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) { fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false); @@ -5176,8 +5176,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, ""); - ZigType *dest_ptr_type = instruction->dest_ptr->value.type; - ZigType *src_ptr_type = instruction->src_ptr->value.type; + ZigType *dest_ptr_type = instruction->dest_ptr->value->type; + ZigType *src_ptr_type = instruction->src_ptr->value->type; assert(dest_ptr_type->id == ZigTypeIdPointer); assert(src_ptr_type->id == ZigTypeIdPointer); @@ -5190,7 +5190,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) { LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr); - ZigType *array_ptr_type = instruction->ptr->value.type; + ZigType *array_ptr_type = instruction->ptr->value->type; assert(array_ptr_type->id == ZigTypeIdPointer); ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type); @@ -5213,7 +5213,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst end_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, array_type->data.array.len, false); } if (want_runtime_safety) { - if (instruction->start->value.special == ConstValSpecialRuntime || instruction->end) { + if (instruction->start->value->special == ConstValSpecialRuntime || instruction->end) { add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); } if (instruction->end) { @@ -5255,13 +5255,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst } if (type_has_bits(array_type)) { - size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index]->gen_index; + size_t gen_ptr_index = instruction->base.value->type->data.structure.fields[slice_ptr_index]->gen_index; LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, ""); LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); } - size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index]->gen_index; + size_t gen_len_index = instruction->base.value->type->data.structure.fields[slice_len_index]->gen_index; LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, ""); LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); gen_store_untyped(g, len_value, len_field_ptr, 0, false); @@ -5375,8 +5375,8 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp LLVMValueRef op2 = ir_llvm_value(g, instruction->op2); LLVMValueRef ptr_result = ir_llvm_value(g, instruction->result_ptr); - LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, instruction->op2->value.type, - instruction->op1->value.type, op2); + LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, instruction->op2->value->type, + instruction->op1->value->type, op2); LLVMValueRef result = LLVMBuildShl(g->builder, op1, op2_casted, ""); LLVMValueRef orig_val; @@ -5387,7 +5387,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp } LLVMValueRef overflow_bit = LLVMBuildICmp(g->builder, LLVMIntNE, op1, orig_val, ""); - gen_store(g, result, ptr_result, instruction->result_ptr->value.type); + gen_store(g, result, ptr_result, instruction->result_ptr->value->type); return overflow_bit; } @@ -5425,13 +5425,13 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, ""); LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); - gen_store(g, result, ptr_result, instruction->result_ptr->value.type); + gen_store(g, result, ptr_result, instruction->result_ptr->value->type); return overflow_bit; } static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) { - ZigType *err_union_type = instruction->err_union->value.type; + ZigType *err_union_type = instruction->err_union->value->type; ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union); @@ -5450,10 +5450,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) { - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return nullptr; - ZigType *ptr_type = instruction->err_union_ptr->value.type; + ZigType *ptr_type = instruction->err_union_ptr->value->type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *err_union_type = ptr_type->data.pointer.child_type; ZigType *payload_type = err_union_type->data.error_union.payload_type; @@ -5470,14 +5470,14 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) { - if (instruction->base.value.special != ConstValSpecialRuntime) + if (instruction->base.value->special != ConstValSpecialRuntime) return nullptr; bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) && g->errors_by_index.length > 1; - if (!want_safety && !type_has_bits(instruction->base.value.type)) + if (!want_safety && !type_has_bits(instruction->base.value->type)) return nullptr; - ZigType *ptr_type = instruction->value->value.type; + ZigType *ptr_type = instruction->value->value->type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *err_union_type = ptr_type->data.pointer.child_type; ZigType *payload_type = err_union_type->data.error_union.payload_type; @@ -5521,7 +5521,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu } static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdOptional); @@ -5548,7 +5548,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, ""); - // child_type and instruction->value->value.type may differ by constness + // child_type and instruction->value->value->type may differ by constness gen_assign_raw(g, val_ptr, get_pointer_to_type(g, child_type, false), payload_val); LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_null_index, ""); gen_store_untyped(g, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr, 0, false); @@ -5557,7 +5557,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable } static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdErrorUnion); @@ -5577,7 +5577,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable } static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) { - ZigType *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value->type; assert(wanted_type->id == ZigTypeIdErrorUnion); @@ -5608,7 +5608,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa } static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) { - ZigType *union_type = instruction->value->value.type; + ZigType *union_type = instruction->value->value->type; ZigType *tag_type = union_type->data.unionation.tag_type; if (!type_has_bits(tag_type)) @@ -5636,7 +5636,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable, IrInstructionAtomicRmw *instruction) { bool is_signed; - ZigType *operand_type = instruction->operand->value.type; + ZigType *operand_type = instruction->operand->value->type; if (operand_type->id == ZigTypeIdInt) { is_signed = operand_type->data.integral.is_signed; } else { @@ -5665,7 +5665,7 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable, { LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering); LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); - LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value.type, ""); + LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, ""); LLVMSetOrdering(load_inst, ordering); return load_inst; } @@ -5676,15 +5676,15 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable, LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering); LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); LLVMValueRef value = ir_llvm_value(g, instruction->value); - LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value.type); + LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type); LLVMSetOrdering(store_inst, ordering); return nullptr; } static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) { LLVMValueRef op = ir_llvm_value(g, instruction->op1); - assert(instruction->base.value.type->id == ZigTypeIdFloat); - LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFloatOp, instruction->op); + assert(instruction->base.value->type->id == ZigTypeIdFloat); + LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->op); return LLVMBuildCall(g->builder, fn_val, &op, 1, ""); } @@ -5692,9 +5692,9 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn LLVMValueRef op1 = ir_llvm_value(g, instruction->op1); LLVMValueRef op2 = ir_llvm_value(g, instruction->op2); LLVMValueRef op3 = ir_llvm_value(g, instruction->op3); - assert(instruction->base.value.type->id == ZigTypeIdFloat || - instruction->base.value.type->id == ZigTypeIdVector); - LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd); + assert(instruction->base.value->type->id == ZigTypeIdFloat || + instruction->base.value->type->id == ZigTypeIdVector); + LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd); LLVMValueRef args[3] = { op1, op2, @@ -5705,7 +5705,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) { LLVMValueRef op = ir_llvm_value(g, instruction->op); - ZigType *expr_type = instruction->base.value.type; + ZigType *expr_type = instruction->base.value->type; bool is_vector = expr_type->id == ZigTypeIdVector; ZigType *int_type = is_vector ? expr_type->data.vector.elem_type : expr_type; assert(int_type->id == ZigTypeIdInt); @@ -5739,16 +5739,16 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) { LLVMValueRef op = ir_llvm_value(g, instruction->op); - ZigType *int_type = instruction->base.value.type; + ZigType *int_type = instruction->base.value->type; assert(int_type->id == ZigTypeIdInt); - LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value.type, BuiltinFnIdBitReverse); + LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value->type, BuiltinFnIdBitReverse); return LLVMBuildCall(g->builder, fn_val, &op, 1, ""); } static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable, IrInstructionVectorToArray *instruction) { - ZigType *array_type = instruction->base.value.type; + ZigType *array_type = instruction->base.value->type; assert(array_type->id == ZigTypeIdArray); assert(handle_is_ptr(array_type)); LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); @@ -5758,8 +5758,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab bool bitcast_ok = elem_type->size_in_bits == elem_type->abi_size * 8; if (bitcast_ok) { LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, result_loc, - LLVMPointerType(get_llvm_type(g, instruction->vector->value.type), 0), ""); - uint32_t alignment = get_ptr_align(g, instruction->result_loc->value.type); + LLVMPointerType(get_llvm_type(g, instruction->vector->value->type), 0), ""); + uint32_t alignment = get_ptr_align(g, instruction->result_loc->value->type); gen_store_untyped(g, vector, casted_ptr, alignment, false); } else { // If the ABI size of the element type is not evenly divisible by size_in_bits, a simple bitcast @@ -5767,7 +5767,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type; LLVMTypeRef u32_type_ref = LLVMInt32Type(); LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false); - for (uintptr_t i = 0; i < instruction->vector->value.type->data.vector.len; i++) { + for (uintptr_t i = 0; i < instruction->vector->value->type->data.vector.len; i++) { LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false); LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false); LLVMValueRef indexes[] = { zero, index_usize }; @@ -5782,7 +5782,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable, IrInstructionArrayToVector *instruction) { - ZigType *vector_type = instruction->base.value.type; + ZigType *vector_type = instruction->base.value->type; assert(vector_type->id == ZigTypeIdVector); assert(!handle_is_ptr(vector_type)); LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array); @@ -5793,7 +5793,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab if (bitcast_ok) { LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, array_ptr, LLVMPointerType(vector_type_ref, 0), ""); - ZigType *array_type = instruction->array->value.type; + ZigType *array_type = instruction->array->value->type; assert(array_type->id == ZigTypeIdArray); uint32_t alignment = get_abi_alignment(g, array_type->data.array.child_type); return gen_load_untyped(g, casted_ptr, alignment, false, ""); @@ -5804,7 +5804,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab LLVMTypeRef u32_type_ref = LLVMInt32Type(); LLVMValueRef zero = LLVMConstInt(usize_type_ref, 0, false); LLVMValueRef vector = LLVMGetUndef(vector_type_ref); - for (uintptr_t i = 0; i < instruction->base.value.type->data.vector.len; i++) { + for (uintptr_t i = 0; i < instruction->base.value->type->data.vector.len; i++) { LLVMValueRef index_usize = LLVMConstInt(usize_type_ref, i, false); LLVMValueRef index_u32 = LLVMConstInt(u32_type_ref, i, false); LLVMValueRef indexes[] = { zero, index_usize }; @@ -5820,7 +5820,7 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable, IrInstructionAssertZero *instruction) { LLVMValueRef target = ir_llvm_value(g, instruction->target); - ZigType *int_type = instruction->target->value.type; + ZigType *int_type = instruction->target->value->type; if (ir_want_runtime_safety(g, &instruction->base)) { return gen_assert_zero(g, target, int_type); } @@ -5831,7 +5831,7 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab IrInstructionAssertNonNull *instruction) { LLVMValueRef target = ir_llvm_value(g, instruction->target); - ZigType *target_type = instruction->target->value.type; + ZigType *target_type = instruction->target->value->type; if (target_type->id == ZigTypeIdPointer) { assert(target_type->data.pointer.ptr_len == PtrLenC); @@ -5917,7 +5917,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type; LLVMValueRef zero = LLVMConstNull(usize_type_ref); LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame); - ZigType *result_type = instruction->base.value.type; + ZigType *result_type = instruction->base.value->type; ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true); LLVMValueRef result_loc = (instruction->result_loc == nullptr) ? @@ -6000,7 +6000,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) { LLVMValueRef frame = ir_llvm_value(g, instruction->frame); - ZigType *frame_type = instruction->frame->value.type; + ZigType *frame_type = instruction->frame->value->type; assert(frame_type->id == ZigTypeIdAnyFrame); gen_resume(g, nullptr, frame, ResumeIdManual); @@ -6354,7 +6354,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) { instruction->llvm_value = ir_render_instruction(g, executable, instruction); if (instruction->spill != nullptr) { LLVMValueRef spill_ptr = ir_llvm_value(g, instruction->spill); - gen_assign_raw(g, spill_ptr, instruction->spill->value.type, instruction->llvm_value); + gen_assign_raw(g, spill_ptr, instruction->spill->value->type, instruction->llvm_value); instruction->llvm_value = nullptr; } } @@ -6362,14 +6362,14 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) { } } -static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index); -static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index); -static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val); -static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val); -static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val); -static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val); +static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index); +static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index); +static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val); +static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val); +static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val); +static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val); -static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent *parent) { +static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *parent) { switch (parent->id) { case ConstParentIdNone: render_const_val(g, val, ""); @@ -6397,7 +6397,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent zig_unreachable(); } -static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *array_const_val, size_t index) { +static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ZigValue *array_const_val, size_t index) { expand_undef_array(g, array_const_val); ConstParent *parent = &array_const_val->parent; 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 } } -static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index) { +static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ZigValue *struct_const_val, size_t field_index) { ConstParent *parent = &struct_const_val->parent; LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent); @@ -6435,7 +6435,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s return LLVMConstInBoundsGEP(base_ptr, indices, 2); } -static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExprValue *err_union_const_val) { +static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ZigValue *err_union_const_val) { ConstParent *parent = &err_union_const_val->parent; LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent); @@ -6447,7 +6447,7 @@ static LLVMValueRef gen_const_ptr_err_union_code_recursive(CodeGen *g, ConstExpr return LLVMConstInBoundsGEP(base_ptr, indices, 2); } -static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstExprValue *err_union_const_val) { +static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ZigValue *err_union_const_val) { ConstParent *parent = &err_union_const_val->parent; LLVMValueRef base_ptr = gen_parent_ptr(g, err_union_const_val, parent); @@ -6459,7 +6459,7 @@ static LLVMValueRef gen_const_ptr_err_union_payload_recursive(CodeGen *g, ConstE return LLVMConstInBoundsGEP(base_ptr, indices, 2); } -static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstExprValue *optional_const_val) { +static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ZigValue *optional_const_val) { ConstParent *parent = &optional_const_val->parent; LLVMValueRef base_ptr = gen_parent_ptr(g, optional_const_val, parent); @@ -6471,7 +6471,7 @@ static LLVMValueRef gen_const_ptr_optional_payload_recursive(CodeGen *g, ConstEx return LLVMConstInBoundsGEP(base_ptr, indices, 2); } -static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *union_const_val) { +static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ZigValue *union_const_val) { ConstParent *parent = &union_const_val->parent; LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent); @@ -6488,7 +6488,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un return LLVMConstInBoundsGEP(base_ptr, indices, (union_payload_index != SIZE_MAX) ? 2 : 1); } -static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ConstExprValue *const_val) { +static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, ZigValue *const_val) { switch (const_val->special) { case ConstValSpecialLazy: case ConstValSpecialRuntime: @@ -6555,7 +6555,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con uint32_t packed_bits_size = type_size_bits(g, type_entry->data.array.child_type); size_t used_bits = 0; for (size_t i = 0; i < type_entry->data.array.len; i += 1) { - ConstExprValue *elem_val = &const_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_val = &const_val->data.x_array.data.s_none.elements[i]; LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, elem_val); if (is_big_endian) { @@ -6616,7 +6616,7 @@ static bool is_llvm_value_unnamed_type(CodeGen *g, ZigType *type_entry, LLVMValu return LLVMTypeOf(val) != get_llvm_type(g, type_entry); } -static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, const char *name) { +static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const char *name) { switch (const_val->data.x_ptr.special) { case ConstPtrSpecialInvalid: case ConstPtrSpecialDiscard: @@ -6624,7 +6624,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con case ConstPtrSpecialRef: { assert(const_val->global_refs != nullptr); - ConstExprValue *pointee = const_val->data.x_ptr.data.ref.pointee; + ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee; render_const_val(g, pointee, ""); render_const_val_global(g, pointee, ""); 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 case ConstPtrSpecialBaseArray: { assert(const_val->global_refs != nullptr); - ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val; assert(array_const_val->type->id == ZigTypeIdArray); if (!type_has_bits(array_const_val->type)) { if (array_const_val->type->data.array.sentinel != nullptr) { - ConstExprValue *pointee = array_const_val->type->data.array.sentinel; + ZigValue *pointee = array_const_val->type->data.array.sentinel; render_const_val(g, pointee, ""); render_const_val_global(g, pointee, ""); 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 case ConstPtrSpecialBaseStruct: { assert(const_val->global_refs != nullptr); - ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val; + ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val; assert(struct_const_val->type->id == ZigTypeIdStruct); if (!type_has_bits(struct_const_val->type)) { // make this a null pointer @@ -6681,7 +6681,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con case ConstPtrSpecialBaseErrorUnionCode: { assert(const_val->global_refs != nullptr); - ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val; + ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val; assert(err_union_const_val->type->id == ZigTypeIdErrorUnion); if (!type_has_bits(err_union_const_val->type)) { // make this a null pointer @@ -6698,7 +6698,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con case ConstPtrSpecialBaseErrorUnionPayload: { assert(const_val->global_refs != nullptr); - ConstExprValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val; + ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val; assert(err_union_const_val->type->id == ZigTypeIdErrorUnion); if (!type_has_bits(err_union_const_val->type)) { // make this a null pointer @@ -6715,7 +6715,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con case ConstPtrSpecialBaseOptionalPayload: { assert(const_val->global_refs != nullptr); - ConstExprValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val; + ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val; assert(optional_const_val->type->id == ZigTypeIdOptional); if (!type_has_bits(optional_const_val->type)) { // make this a null pointer @@ -6747,12 +6747,12 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con zig_unreachable(); } -static LLVMValueRef gen_const_val_err_set(CodeGen *g, ConstExprValue *const_val, const char *name) { +static LLVMValueRef gen_const_val_err_set(CodeGen *g, ZigValue *const_val, const char *name) { uint64_t value = (const_val->data.x_err_set == nullptr) ? 0 : const_val->data.x_err_set->value; return LLVMConstInt(get_llvm_type(g, g->builtin_types.entry_global_error_set), value, false); } -static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) { +static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name) { Error err; ZigType *type_entry = const_val->type; @@ -6864,7 +6864,7 @@ check: switch (const_val->special) { } if (src_field_index + 1 == src_field_index_end) { - ConstExprValue *field_val = const_val->data.x_struct.fields[src_field_index]; + ZigValue *field_val = const_val->data.x_struct.fields[src_field_index]; LLVMValueRef val = gen_const_val(g, field_val, ""); fields[type_struct_field->gen_index] = val; 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) { if (type_struct_field->gen_index == SIZE_MAX) { continue; } - ConstExprValue *field_val = const_val->data.x_struct.fields[i]; + ZigValue *field_val = const_val->data.x_struct.fields[i]; assert(field_val->type != nullptr); if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val, type_struct_field->type_entry))) @@ -6970,7 +6970,7 @@ check: switch (const_val->special) { LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type); bool make_unnamed_struct = false; for (uint64_t i = 0; i < len; i += 1) { - ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; LLVMValueRef val = gen_const_val(g, elem_value, ""); values[i] = val; 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) { case ConstArraySpecialNone: { LLVMValueRef *values = allocate<LLVMValueRef>(len); for (uint64_t i = 0; i < len; i += 1) { - ConstExprValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; values[i] = gen_const_val(g, elem_value, ""); } return LLVMConstVector(values, len); @@ -7036,7 +7036,7 @@ check: switch (const_val->special) { LLVMValueRef union_value_ref; bool make_unnamed_struct; - ConstExprValue *payload_value = const_val->data.x_union.payload; + ZigValue *payload_value = const_val->data.x_union.payload; if (payload_value == nullptr || !type_has_bits(payload_value->type)) { if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) return LLVMGetUndef(get_llvm_type(g, type_entry)); @@ -7133,7 +7133,7 @@ check: switch (const_val->special) { make_unnamed_struct = false; } else { err_tag_value = LLVMConstNull(get_llvm_type(g, g->err_tag_type)); - ConstExprValue *payload_val = const_val->data.x_err_union.payload; + ZigValue *payload_val = const_val->data.x_err_union.payload; err_payload_value = gen_const_val(g, payload_val, ""); make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_val->type, err_payload_value); } @@ -7174,7 +7174,7 @@ check: switch (const_val->special) { zig_unreachable(); } -static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) { +static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) { if (!const_val->global_refs) const_val->global_refs = allocate<ConstGlobalRefs>(1); if (!const_val->global_refs->llvm_value) @@ -7184,7 +7184,7 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char * LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value); } -static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name) { +static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) { if (!const_val->global_refs) const_val->global_refs = allocate<ConstGlobalRefs>(1); @@ -7324,7 +7324,7 @@ static void do_code_gen(CodeGen *g) { if (var->var_type->id == ZigTypeIdComptimeFloat) { // Generate debug info for it but that's it. - ConstExprValue *const_val = var->const_value; + ZigValue *const_val = var->const_value; assert(const_val->special != ConstValSpecialRuntime); if ((err = ir_resolve_lazy(g, var->decl_node, const_val))) zig_unreachable(); @@ -7332,7 +7332,7 @@ static void do_code_gen(CodeGen *g) { zig_panic("TODO debug info for var with ptr casted value"); } ZigType *var_type = g->builtin_types.entry_f128; - ConstExprValue coerced_value = {}; + ZigValue coerced_value = {}; coerced_value.special = ConstValSpecialStatic; coerced_value.type = var_type; coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat); @@ -7343,7 +7343,7 @@ static void do_code_gen(CodeGen *g) { if (var->var_type->id == ZigTypeIdComptimeInt) { // Generate debug info for it but that's it. - ConstExprValue *const_val = var->const_value; + ZigValue *const_val = var->const_value; assert(const_val->special != ConstValSpecialRuntime); if ((err = ir_resolve_lazy(g, var->decl_node, const_val))) zig_unreachable(); @@ -7514,12 +7514,12 @@ static void do_code_gen(CodeGen *g) { call->frame_result_loc = all_calls_alloca; } if (largest_call_frame_type != nullptr) { - all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false); + all_calls_alloca->value->type = get_pointer_to_type(g, largest_call_frame_type, false); } // allocate temporary stack data for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) { IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i); - ZigType *ptr_type = instruction->base.value.type; + ZigType *ptr_type = instruction->base.value->type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *child_type = ptr_type->data.pointer.child_type; if (type_resolve(g, child_type, ResolveStatusSizeKnown)) @@ -7528,8 +7528,8 @@ static void do_code_gen(CodeGen *g) { continue; if (instruction->base.ref_count == 0) continue; - if (instruction->base.value.special != ConstValSpecialRuntime) { - if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special != + if (instruction->base.value->special != ConstValSpecialRuntime) { + if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special != ConstValSpecialRuntime) { continue; @@ -8008,6 +8008,33 @@ static void define_builtin_types(CodeGen *g) { } } +static void define_intern_values(CodeGen *g) { + { + auto& value = g->intern_values.x_undefined; + value.type = g->builtin_types.entry_undef; + value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined"); + value.special = ConstValSpecialStatic; + } + { + auto& value = g->intern_values.x_void; + value.type = g->builtin_types.entry_void; + value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void"); + value.special = ConstValSpecialStatic; + } + { + auto& value = g->intern_values.x_null; + value.type = g->builtin_types.entry_null; + value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null"); + value.special = ConstValSpecialStatic; + } + { + auto& value = g->intern_values.x_unreachable; + value.type = g->builtin_types.entry_unreachable; + value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable"); + value.special = ConstValSpecialStatic; + } +} + static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) { BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1); buf_init_from_str(&builtin_fn->name, name); @@ -8629,15 +8656,18 @@ static void init(CodeGen *g) { g->dummy_di_file = nullptr; define_builtin_types(g); + define_intern_values(g); IrInstruction *sentinel_instructions = allocate<IrInstruction>(2); g->invalid_instruction = &sentinel_instructions[0]; - g->invalid_instruction->value.type = g->builtin_types.entry_invalid; - g->invalid_instruction->value.global_refs = allocate<ConstGlobalRefs>(1); + g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue"); + g->invalid_instruction->value->type = g->builtin_types.entry_invalid; + g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1); g->unreach_instruction = &sentinel_instructions[1]; - g->unreach_instruction->value.type = g->builtin_types.entry_unreachable; - g->unreach_instruction->value.global_refs = allocate<ConstGlobalRefs>(1); + g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue"); + g->unreach_instruction->value->type = g->builtin_types.entry_unreachable; + g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1); g->const_void_val.special = ConstValSpecialStatic; g->const_void_val.type = g->builtin_types.entry_void; @@ -9080,13 +9110,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { ZigType *fn_type = get_test_fn_type(g); - ConstExprValue *test_fn_type_val = get_builtin_value(g, "TestFn"); + ZigValue *test_fn_type_val = get_builtin_value(g, "TestFn"); assert(test_fn_type_val->type->id == ZigTypeIdMetaType); ZigType *struct_type = test_fn_type_val->data.x_type; if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown))) zig_unreachable(); - ConstExprValue *test_fn_array = create_const_vals(1); + ZigValue *test_fn_array = create_const_vals(1); test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr); test_fn_array->special = ConstValSpecialStatic; test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length); @@ -9103,7 +9133,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { continue; } - ConstExprValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i]; + ZigValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i]; this_val->special = ConstValSpecialStatic; this_val->type = struct_type; this_val->parent.id = ConstParentIdArray; @@ -9111,11 +9141,11 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { this_val->parent.data.p_array.elem_index = i; this_val->data.x_struct.fields = alloc_const_vals_ptrs(2); - ConstExprValue *name_field = this_val->data.x_struct.fields[0]; - ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee; + ZigValue *name_field = this_val->data.x_struct.fields[0]; + ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee; init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true); - ConstExprValue *fn_field = this_val->data.x_struct.fields[1]; + ZigValue *fn_field = this_val->data.x_struct.fields[1]; fn_field->type = fn_type; fn_field->special = ConstValSpecialStatic; fn_field->data.x_ptr.special = ConstPtrSpecialFunction; @@ -9124,7 +9154,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { } report_errors_and_maybe_exit(g); - ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true); + ZigValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true); update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice); assert(g->test_runner_package != nullptr); @@ -9221,7 +9251,7 @@ static void gen_root_source(CodeGen *g) { report_errors_and_maybe_exit(g); assert(builtin_tld->id == TldIdVar); TldVar *builtin_tld_var = (TldVar*)builtin_tld; - ConstExprValue *builtin_val = builtin_tld_var->var->const_value; + ZigValue *builtin_val = builtin_tld_var->var->const_value; assert(builtin_val->type->id == ZigTypeIdMetaType); ZigType *builtin_type = builtin_val->data.x_type; @@ -9232,7 +9262,7 @@ static void gen_root_source(CodeGen *g) { report_errors_and_maybe_exit(g); assert(panic_tld->id == TldIdVar); TldVar *panic_tld_var = (TldVar*)panic_tld; - ConstExprValue *panic_fn_val = panic_tld_var->var->const_value; + ZigValue *panic_fn_val = panic_tld_var->var->const_value; assert(panic_fn_val->type->id == ZigTypeIdFn); assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction); g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry; diff --git a/src/dump_analysis.cpp b/src/dump_analysis.cpp index 98bbcc6a42..832035afb2 100644 --- a/src/dump_analysis.cpp +++ b/src/dump_analysis.cpp @@ -361,9 +361,9 @@ struct AnalDumpCtx { }; static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty); -static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value); +static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value); -static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) { +static void anal_dump_poke_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) { Error err; if (value->type != ty) { return; @@ -660,7 +660,7 @@ static void anal_dump_file(AnalDumpCtx *ctx, Buf *file) { jw_string(jw, buf_ptr(file)); } -static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ConstExprValue *value) { +static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty, ZigValue *value) { Error err; if (value->type != ty) { @@ -1249,7 +1249,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const } scope = scope->parent; } - ConstExprValue *result = entry->value; + ZigValue *result = entry->value; assert(fn != nullptr); diff --git a/src/hash_map.hpp b/src/hash_map.hpp index 51ec352eda..e819ea1c10 100644 --- a/src/hash_map.hpp +++ b/src/hash_map.hpp @@ -23,10 +23,10 @@ public: } struct Entry { - bool used; - int distance_from_start_index; K key; V value; + bool used; + int distance_from_start_index; }; void clear() { @@ -187,10 +187,10 @@ private: if (distance_from_start_index > _max_distance_from_start_index) _max_distance_from_start_index = distance_from_start_index; *entry = { - true, - distance_from_start_index, key, value, + true, + distance_from_start_index, }; key = tmp.key; value = tmp.value; @@ -208,10 +208,10 @@ private: if (distance_from_start_index > _max_distance_from_start_index) _max_distance_from_start_index = distance_from_start_index; *entry = { - true, - distance_from_start_index, key, value, + true, + distance_from_start_index, }; return; } diff --git a/src/ir.cpp b/src/ir.cpp index 017f6b489f..f4bcfb6330 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -19,7 +19,7 @@ #include <errno.h> struct IrExecContext { - ZigList<ConstExprValue *> mem_slot_list; + ZigList<ZigValue *> mem_slot_list; }; struct IrBuilder { @@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction * static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc); static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); -static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val); -static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); +static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val); +static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, - ConstExprValue *out_val, ConstExprValue *ptr_val); + ZigValue *out_val, ZigValue *ptr_val); static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on); -static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); -static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs); +static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); +static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs); static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *ptr_type); @@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); static ResultLoc *no_result_loc(void); -static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { +static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) { assert(get_src_ptr_type(const_val->type) != nullptr); assert(const_val->special == ConstValSpecialStatic); - ConstExprValue *result; + ZigValue *result; switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) { case OnePossibleValueInvalid: @@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c result = const_val->data.x_ptr.data.ref.pointee; break; case ConstPtrSpecialBaseArray: { - ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = const_val->data.x_ptr.data.base_array.array_val; if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) { result = array_val->type->data.array.sentinel; } else { @@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c break; } case ConstPtrSpecialBaseStruct: { - ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val; + ZigValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val; expand_undef_struct(g, struct_val); result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index]; break; @@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) { return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; } -// This function returns true when you can change the type of a ConstExprValue and the +// This function returns true when you can change the type of a ZigValue and the // value remains meaningful. static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) { if (expected == actual) @@ -416,16 +416,16 @@ static Buf *exec_c_import_buf(IrExecutable *exec) { return exec->c_import_buf; } -static bool value_is_comptime(ConstExprValue *const_val) { +static bool value_is_comptime(ZigValue *const_val) { return const_val->special != ConstValSpecialRuntime; } static bool instr_is_comptime(IrInstruction *instruction) { - return value_is_comptime(&instruction->value); + return value_is_comptime(instruction->value); } static bool instr_is_unreachable(IrInstruction *instruction) { - return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; + return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable; } static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) { @@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) { } ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { - ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, + ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad); @@ -1156,7 +1156,24 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no special_instruction->base.source_node = source_node; special_instruction->base.debug_id = exec_next_debug_id(irb->exec); special_instruction->base.owner_bb = irb->current_basic_block; - special_instruction->base.value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); + special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); + special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); + return special_instruction; +} + +template<typename T> +static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) { + const char *name = nullptr; +#ifdef ZIG_ENABLE_MEM_PROFILE + T *dummy = nullptr; + name = ir_instruction_type_str(ir_instruction_id(dummy)); +#endif + T *special_instruction = allocate<T>(1, name); + special_instruction->base.id = ir_instruction_id(special_instruction); + special_instruction->base.scope = scope; + special_instruction->base.source_node = source_node; + special_instruction->base.debug_id = exec_next_debug_id(irb->exec); + special_instruction->base.owner_bb = irb->current_basic_block; return special_instruction; } @@ -1184,8 +1201,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) { IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); - cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; - cond_br_instruction->base.value.special = ConstValSpecialStatic; + cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; + cond_br_instruction->base.value->special = ConstValSpecialStatic; cond_br_instruction->condition = condition; cond_br_instruction->then_block = then_block; cond_br_instruction->else_block = else_block; @@ -1203,8 +1220,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou IrInstruction *operand) { IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); - return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; - return_instruction->base.value.special = ConstValSpecialStatic; + return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; + return_instruction->base.value->special = ConstValSpecialStatic; return_instruction->operand = operand; if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); @@ -1213,55 +1230,64 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou } static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { - IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_void; - const_instruction->base.value.special = ConstValSpecialStatic; +#ifdef ZIG_ENABLE_MEM_PROFILE + memprof_intern_count.x_void += 1; +#endif + IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); + ir_instruction_append(irb->current_basic_block, &const_instruction->base); + const_instruction->base.value = &irb->codegen->intern_values.x_void; return &const_instruction->base; } static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { - IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.special = ConstValSpecialUndef; - const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef; +#ifdef ZIG_ENABLE_MEM_PROFILE + memprof_intern_count.x_undefined += 1; +#endif + IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); + ir_instruction_append(irb->current_basic_block, &const_instruction->base); + const_instruction->base.value = &irb->codegen->intern_values.x_undefined; return &const_instruction->base; } static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; - const_instruction->base.value.special = ConstValSpecialStatic; - bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); + const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; + const_instruction->base.value->special = ConstValSpecialStatic; + bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); return &const_instruction->base; } static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; - const_instruction->base.value.special = ConstValSpecialStatic; - bigint_init_bigint(&const_instruction->base.value.data.x_bigint, bigint); + const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; + const_instruction->base.value->special = ConstValSpecialStatic; + bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint); return &const_instruction->base; } static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_float; - const_instruction->base.value.special = ConstValSpecialStatic; - bigfloat_init_bigfloat(&const_instruction->base.value.data.x_bigfloat, bigfloat); + const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float; + const_instruction->base.value->special = ConstValSpecialStatic; + bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat); return &const_instruction->base; } static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { - IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_null; - const_instruction->base.value.special = ConstValSpecialStatic; +#ifdef ZIG_ENABLE_MEM_PROFILE + memprof_intern_count.x_null += 1; +#endif + IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); + ir_instruction_append(irb->current_basic_block, &const_instruction->base); + const_instruction->base.value = &irb->codegen->intern_values.x_null; return &const_instruction->base; } static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize; - const_instruction->base.value.special = ConstValSpecialStatic; - bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); + const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize; + const_instruction->base.value->special = ConstValSpecialStatic; + bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); return &const_instruction->base; } @@ -1269,9 +1295,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode ZigType *type_entry) { IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_type = type_entry; + const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_type = type_entry; return &const_instruction->base; } @@ -1285,35 +1311,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = fn_entry->type_entry; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry; - const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst; - const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction; + const_instruction->base.value->type = fn_entry->type_entry; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry; + const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst; + const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction; return &const_instruction->base; } static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_type = import; + const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_type = import; return &const_instruction->base; } static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_bool = value; + const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_bool = value; return &const_instruction->base; } static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_enum_literal; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_enum_literal = name; + const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_enum_literal = name; return &const_instruction->base; } @@ -1321,19 +1347,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN ZigFn *fn_entry, IrInstruction *first_arg) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); - const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_bound_fn.fn = fn_entry; - const_instruction->base.value.data.x_bound_fn.first_arg = first_arg; + const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry); + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_bound_fn.fn = fn_entry; + const_instruction->base.value->data.x_bound_fn.first_arg = first_arg; return &const_instruction->base; } static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); - init_const_str_lit(irb->codegen, &const_instruction->base.value, str); + init_const_str_lit(irb->codegen, const_instruction->base.value, str); return &const_instruction->base; } + static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str); ir_instruction_append(irb->current_basic_block, instruction); @@ -1388,7 +1415,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ty; + instruction->base.value->type = ty; return &instruction->base; } @@ -1513,7 +1540,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so { IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - call_instruction->base.value.type = return_type; + call_instruction->base.value->type = return_type; call_instruction->fn_entry = fn_entry; call_instruction->fn_ref = fn_ref; call_instruction->fn_inline = fn_inline; @@ -1558,8 +1585,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source IrBasicBlock *dest_block, IrInstruction *is_comptime) { IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node); - br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; - br_instruction->base.value.special = ConstValSpecialStatic; + br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; + br_instruction->base.value->special = ConstValSpecialStatic; br_instruction->dest_block = dest_block; br_instruction->is_comptime = is_comptime; @@ -1659,8 +1686,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { IrInstructionUnreachable *unreachable_instruction = ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); - unreachable_instruction->base.value.special = ConstValSpecialStatic; - unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; + unreachable_instruction->base.value->special = ConstValSpecialStatic; + unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; return &unreachable_instruction->base; } @@ -1668,8 +1695,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A IrInstruction *ptr, IrInstruction *value) { IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); - instruction->base.value.special = ConstValSpecialStatic; - instruction->base.value.type = irb->codegen->builtin_types.entry_void; + instruction->base.value->special = ConstValSpecialStatic; + instruction->base.value->type = irb->codegen->builtin_types.entry_void; instruction->ptr = ptr; instruction->value = value; @@ -1684,7 +1711,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction * { IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - inst->base.value.type = ira->codegen->builtin_types.entry_void; + inst->base.value->type = ira->codegen->builtin_types.entry_void; inst->vector_ptr = vector_ptr; inst->index = index; inst->value = value; @@ -1700,8 +1727,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) { IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node); - decl_var_instruction->base.value.special = ConstValSpecialStatic; - decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void; + decl_var_instruction->base.value->special = ConstValSpecialStatic; + decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void; decl_var_instruction->var = var; decl_var_instruction->align_value = align_value; decl_var_instruction->ptr = ptr; @@ -1717,8 +1744,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc { IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - decl_var_instruction->base.value.special = ConstValSpecialStatic; - decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void; + decl_var_instruction->base.value->special = ConstValSpecialStatic; + decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void; decl_var_instruction->var = var; decl_var_instruction->var_ptr = var_ptr; @@ -1732,7 +1759,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc { IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ty; + instruction->base.value->type = ty; instruction->operand = operand; instruction->result_loc = result_loc; @@ -1747,8 +1774,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou { IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( irb, scope, source_node); - export_instruction->base.value.special = ConstValSpecialStatic; - export_instruction->base.value.type = irb->codegen->builtin_types.entry_void; + export_instruction->base.value->special = ConstValSpecialStatic; + export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; export_instruction->name = name; export_instruction->target = target; export_instruction->linkage = linkage; @@ -1925,7 +1952,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour { IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_ty; + instruction->base.value->type = result_ty; instruction->operand = operand; instruction->result_loc = result_loc; @@ -1940,7 +1967,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s { IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->operand = operand; instruction->result_loc = result_loc; @@ -1955,7 +1982,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour { IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->operand = operand; instruction->result_loc = result_loc; @@ -2025,8 +2052,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A IrInstruction *switch_prongs_void) { IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); - instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; - instruction->base.value.special = ConstValSpecialStatic; + instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; + instruction->base.value->special = ConstValSpecialStatic; instruction->target_value = target_value; instruction->else_block = else_block; instruction->case_count = case_count; @@ -2122,7 +2149,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins { IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->operand = operand; instruction->result_loc = result_loc; @@ -2237,7 +2264,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source { IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->ptr = ptr; instruction->cmp_value = cmp_value; instruction->new_value = new_value; @@ -2482,7 +2509,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i { IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->scalar = scalar; ir_ref_instruction(scalar, ira->new_irb.current_basic_block); @@ -2495,7 +2522,7 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i { IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = slice_type; + instruction->base.value->type = slice_type; instruction->ptr = ptr; instruction->start = start; instruction->end = end; @@ -2709,7 +2736,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc { IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ira->codegen->builtin_types.entry_bool; + instruction->base.value->type = ira->codegen->builtin_types.entry_bool; instruction->err_union = err_union; ir_ref_instruction(err_union, ira->new_irb.current_basic_block); @@ -2792,7 +2819,7 @@ static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *sourc { IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ptr_type; + instruction->base.value->type = ptr_type; instruction->ptr = ptr; instruction->safety_check_on = safety_check_on; @@ -2806,7 +2833,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc { IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ty; + instruction->base.value->type = ty; instruction->ptr = ptr; instruction->result_loc = result_loc; @@ -2845,7 +2872,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc { IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ty; + instruction->base.value->type = ty; instruction->operand = operand; ir_ref_instruction(operand, ira->new_irb.current_basic_block); @@ -2997,8 +3024,8 @@ static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *s static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node); - instruction->base.value.special = ConstValSpecialStatic; - instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; + instruction->base.value->special = ConstValSpecialStatic; + instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; instruction->msg = msg; ir_ref_instruction(msg, irb->current_basic_block); @@ -3328,7 +3355,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so { IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->vector = vector; instruction->result_loc = result_loc; @@ -3343,7 +3370,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi { IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->operand = operand; instruction->result_loc = result_loc; @@ -3358,7 +3385,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so { IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->array = array; ir_ref_instruction(array, ira->new_irb.current_basic_block); @@ -3371,7 +3398,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source { IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ira->codegen->builtin_types.entry_void; + instruction->base.value->type = ira->codegen->builtin_types.entry_void; instruction->target = target; ir_ref_instruction(target, ira->new_irb.current_basic_block); @@ -3384,7 +3411,7 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so { IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = ira->codegen->builtin_types.entry_void; + instruction->base.value->type = ira->codegen->builtin_types.entry_void; instruction->target = target; ir_ref_instruction(target, ira->new_irb.current_basic_block); @@ -3433,7 +3460,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) { IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node); - instruction->base.value.type = irb->codegen->builtin_types.entry_void; + instruction->base.value->type = irb->codegen->builtin_types.entry_void; return instruction; } @@ -3442,7 +3469,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN IrInstructionSuspendBegin *begin) { IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node); - instruction->base.value.type = irb->codegen->builtin_types.entry_void; + instruction->base.value->type = irb->codegen->builtin_types.entry_void; instruction->begin = begin; ir_ref_instruction(&begin->base, irb->current_basic_block); @@ -3467,7 +3494,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * { IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = result_type; + instruction->base.value->type = result_type; instruction->frame = frame; instruction->result_loc = result_loc; @@ -3479,7 +3506,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) { IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node); - instruction->base.value.type = irb->codegen->builtin_types.entry_void; + instruction->base.value->type = irb->codegen->builtin_types.entry_void; instruction->frame = frame; ir_ref_instruction(frame, irb->current_basic_block); @@ -3491,8 +3518,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop IrInstruction *operand, SpillId spill_id) { IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node); - instruction->base.value.special = ConstValSpecialStatic; - instruction->base.value.type = irb->codegen->builtin_types.entry_void; + instruction->base.value->special = ConstValSpecialStatic; + instruction->base.value->type = irb->codegen->builtin_types.entry_void; instruction->operand = operand; instruction->spill_id = spill_id; @@ -3517,7 +3544,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction { IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>( &ira->new_irb, source_instruction->scope, source_instruction->source_node); - instruction->base.value.type = vector->value.type->data.vector.elem_type; + instruction->base.value->type = vector->value->type->data.vector.elem_type; instruction->vector = vector; instruction->index = index; @@ -3588,8 +3615,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o Scope *defer_expr_scope = defer_node->data.defer.expr_scope; IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); if (defer_expr_value != irb->codegen->invalid_instruction) { - if (defer_expr_value->value.type != nullptr && - defer_expr_value->value.type->id == ZigTypeIdUnreachable) + if (defer_expr_value->value->type != nullptr && + defer_expr_value->value->type->id == ZigTypeIdUnreachable) { is_noreturn = true; } else { @@ -4411,7 +4438,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); tld_var->base.resolution = TldResolutionInvalid; tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, - &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); + g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); scope_decls->decl_table.put(var_name, &tld_var->base); } @@ -4424,10 +4451,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, if (buf_eql_str(variable_name, "_")) { if (lval == LValPtr) { IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); - const_instruction->base.value.type = get_pointer_to_type(irb->codegen, + const_instruction->base.value->type = get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_void, false); - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard; return &const_instruction->base; } else { add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); @@ -8698,26 +8725,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) { // This function takes a comptime ptr and makes the child const value conform to the type // described by the pointer. static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, - ConstExprValue *ptr_val) + ZigValue *ptr_val) { Error err; assert(ptr_val->type->id == ZigTypeIdPointer); assert(ptr_val->special == ConstValSpecialStatic); - ConstExprValue tmp = {}; + ZigValue tmp = {}; tmp.special = ConstValSpecialStatic; tmp.type = ptr_val->type->data.pointer.child_type; if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val))) return err; - ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); + ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); copy_const_val(child_val, &tmp, false); return ErrorNone; } -ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val, +ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val, AstNode *source_node) { Error err; - ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val); + ZigValue *val = const_ptr_pointee_unchecked(codegen, const_val); assert(val != nullptr); assert(const_val->type->id == ZigTypeIdPointer); ZigType *expected_type = const_val->type->data.pointer.child_type; @@ -8740,19 +8767,19 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal return val; } -static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { +static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { IrBasicBlock *bb = exec->basic_block_list.at(0); for (size_t i = 0; i < bb->instruction_list.length; i += 1) { IrInstruction *instruction = bb->instruction_list.at(i); if (instruction->id == IrInstructionIdReturn) { IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; IrInstruction *operand = ret_inst->operand; - if (operand->value.special == ConstValSpecialRuntime) { + if (operand->value->special == ConstValSpecialRuntime) { exec_add_error_node(codegen, exec, operand->source_node, buf_sprintf("unable to evaluate constant expression")); - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; } - return &operand->value; + return operand->value; } else if (ir_has_side_effects(instruction)) { if (instr_is_comptime(instruction)) { switch (instruction->id) { @@ -8769,7 +8796,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec } exec_add_error_node(codegen, exec, instruction->source_node, buf_sprintf("unable to evaluate constant expression")); - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; } } zig_unreachable(); @@ -8783,14 +8810,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so return true; } -static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { +static bool const_val_fits_in_num_lit(ZigValue *const_val, ZigType *num_lit_type) { return ((num_lit_type->id == ZigTypeIdComptimeFloat && (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) || (num_lit_type->id == ZigTypeIdComptimeInt && (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt))); } -static bool float_has_fraction(ConstExprValue *const_val) { +static bool float_has_fraction(ZigValue *const_val) { if (const_val->type->id == ZigTypeIdComptimeFloat) { return bigfloat_has_fraction(&const_val->data.x_bigfloat); } else if (const_val->type->id == ZigTypeIdFloat) { @@ -8818,7 +8845,7 @@ static bool float_has_fraction(ConstExprValue *const_val) { } } -static void float_append_buf(Buf *buf, ConstExprValue *const_val) { +static void float_append_buf(Buf *buf, ZigValue *const_val) { if (const_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_append_buf(buf, &const_val->data.x_bigfloat); } else if (const_val->type->id == ZigTypeIdFloat) { @@ -8856,7 +8883,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) { } } -static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { +static void float_init_bigint(BigInt *bigint, ZigValue *const_val) { if (const_val->type->id == ZigTypeIdComptimeFloat) { bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); } else if (const_val->type->id == ZigTypeIdFloat) { @@ -8903,7 +8930,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { } } -static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { +static void float_init_bigfloat(ZigValue *dest_val, BigFloat *bigfloat) { if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); } else if (dest_val->type->id == ZigTypeIdFloat) { @@ -8930,7 +8957,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { } } -static void float_init_f16(ConstExprValue *dest_val, float16_t x) { +static void float_init_f16(ZigValue *dest_val, float16_t x) { if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_16(&dest_val->data.x_bigfloat, x); } else if (dest_val->type->id == ZigTypeIdFloat) { @@ -8955,7 +8982,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { } } -static void float_init_f32(ConstExprValue *dest_val, float x) { +static void float_init_f32(ZigValue *dest_val, float x) { if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_32(&dest_val->data.x_bigfloat, x); } else if (dest_val->type->id == ZigTypeIdFloat) { @@ -8984,7 +9011,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) { } } -static void float_init_f64(ConstExprValue *dest_val, double x) { +static void float_init_f64(ZigValue *dest_val, double x) { if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_64(&dest_val->data.x_bigfloat, x); } else if (dest_val->type->id == ZigTypeIdFloat) { @@ -9013,7 +9040,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) { } } -static void float_init_f128(ConstExprValue *dest_val, float128_t x) { +static void float_init_f128(ZigValue *dest_val, float128_t x) { if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_128(&dest_val->data.x_bigfloat, x); } else if (dest_val->type->id == ZigTypeIdFloat) { @@ -9046,7 +9073,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) { } } -static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { +static void float_init_float(ZigValue *dest_val, ZigValue *src_val) { if (src_val->type->id == ZigTypeIdComptimeFloat) { float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); } else if (src_val->type->id == ZigTypeIdFloat) { @@ -9071,7 +9098,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) } } -static bool float_is_nan(ConstExprValue *op) { +static bool float_is_nan(ZigValue *op) { if (op->type->id == ZigTypeIdComptimeFloat) { return bigfloat_is_nan(&op->data.x_bigfloat); } else if (op->type->id == ZigTypeIdFloat) { @@ -9092,7 +9119,7 @@ static bool float_is_nan(ConstExprValue *op) { } } -static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { +static Cmp float_cmp(ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); if (op1->type->id == ZigTypeIdComptimeFloat) { return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); @@ -9138,7 +9165,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { } } -static Cmp float_cmp_zero(ConstExprValue *op) { +static Cmp float_cmp_zero(ZigValue *op) { if (op->type->id == ZigTypeIdComptimeFloat) { return bigfloat_cmp_zero(&op->data.x_bigfloat); } else if (op->type->id == ZigTypeIdFloat) { @@ -9188,7 +9215,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) { } } -static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_add(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9215,7 +9242,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal } } -static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_sub(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9242,7 +9269,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal } } -static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_mul(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9269,7 +9296,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal } } -static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_div(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9296,7 +9323,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal } } -static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_div_trunc(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9325,7 +9352,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE } } -static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_div_floor(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9354,7 +9381,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE } } -static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_rem(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9399,7 +9426,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t* f128M_sub(a, c, c); } -static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { +static void float_mod(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; if (op1->type->id == ZigTypeIdComptimeFloat) { @@ -9426,7 +9453,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal } } -static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { +static void float_negate(ZigValue *out_val, ZigValue *op) { out_val->type = op->type; if (op->type->id == ZigTypeIdComptimeFloat) { bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); @@ -9457,7 +9484,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { } } -void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { +void float_write_ieee597(ZigValue *op, uint8_t *buf, bool is_big_endian) { if (op->type->id == ZigTypeIdFloat) { switch (op->type->data.floating.bit_count) { case 16: @@ -9480,7 +9507,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { } } -void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { +void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) { if (val->type->id == ZigTypeIdFloat) { switch (val->type->data.floating.bit_count) { case 16: @@ -9510,7 +9537,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc return false; } - ConstExprValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef); + ZigValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef); if (const_val == nullptr) return false; @@ -10217,13 +10244,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT size_t i = 0; for (;;) { prev_inst = instructions[i]; - if (type_is_invalid(prev_inst->value.type)) { + if (type_is_invalid(prev_inst->value->type)) { return ira->codegen->builtin_types.entry_invalid; } - if (prev_inst->value.type->id == ZigTypeIdUnreachable) { + if (prev_inst->value->type->id == ZigTypeIdUnreachable) { i += 1; if (i == instruction_count) { - return prev_inst->value.type; + return prev_inst->value->type; } continue; } @@ -10232,14 +10259,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT ErrorTableEntry **errors = nullptr; size_t errors_count = 0; ZigType *err_set_type = nullptr; - if (prev_inst->value.type->id == ZigTypeIdErrorSet) { - if (!resolve_inferred_error_set(ira->codegen, prev_inst->value.type, prev_inst->source_node)) { + if (prev_inst->value->type->id == ZigTypeIdErrorSet) { + if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } - if (type_is_global_error_set(prev_inst->value.type)) { + if (type_is_global_error_set(prev_inst->value->type)) { err_set_type = ira->codegen->builtin_types.entry_global_error_set; } else { - err_set_type = prev_inst->value.type; + err_set_type = prev_inst->value->type; update_errors_helper(ira->codegen, &errors, &errors_count); for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { @@ -10250,12 +10277,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull); + bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); bool convert_to_const_slice = false; for (; i < instruction_count; i += 1) { IrInstruction *cur_inst = instructions[i]; - ZigType *cur_type = cur_inst->value.type; - ZigType *prev_type = prev_inst->value.type; + ZigType *cur_type = cur_inst->value->type; + ZigType *prev_type = prev_inst->value->type; if (type_is_invalid(cur_type)) { return cur_type; @@ -10559,20 +10586,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) { - TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal); + TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value->data.x_enum_literal); if (field != nullptr) { continue; } } if (is_tagged_union(prev_type) && cur_type->id == ZigTypeIdEnumLiteral) { - TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value.data.x_enum_literal); + TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value->data.x_enum_literal); if (field != nullptr) { continue; } } if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) { - TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal); + TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value->data.x_enum_literal); if (field != nullptr) { prev_inst = cur_inst; continue; @@ -10580,7 +10607,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } if (is_tagged_union(cur_type) && prev_type->id == ZigTypeIdEnumLiteral) { - TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value.data.x_enum_literal); + TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value->data.x_enum_literal); if (field != nullptr) { prev_inst = cur_inst; continue; @@ -10906,9 +10933,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT free(errors); if (convert_to_const_slice) { - if (prev_inst->value.type->id == ZigTypeIdArray) { + if (prev_inst->value->type->id == ZigTypeIdArray) { ZigType *ptr_type = get_pointer_to_type_extra( - ira->codegen, prev_inst->value.type->data.array.child_type, + ira->codegen, prev_inst->value->type->data.array.child_type, true, false, PtrLenUnknown, 0, 0, 0, false); ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); @@ -10917,12 +10944,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } else { return slice_type; } - } else if (prev_inst->value.type->id == ZigTypeIdPointer) { - ZigType *array_type = prev_inst->value.type->data.pointer.child_type; + } else if (prev_inst->value->type->id == ZigTypeIdPointer) { + ZigType *array_type = prev_inst->value->type->data.pointer.child_type; src_assert(array_type->id == ZigTypeIdArray, source_node); ZigType *ptr_type = get_pointer_to_type_extra2( ira->codegen, array_type->data.array.child_type, - prev_inst->value.type->data.pointer.is_const, false, + prev_inst->value->type->data.pointer.is_const, false, PtrLenUnknown, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel); @@ -10936,10 +10963,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT zig_unreachable(); } } else if (err_set_type != nullptr) { - if (prev_inst->value.type->id == ZigTypeIdErrorSet) { + if (prev_inst->value->type->id == ZigTypeIdErrorSet) { return err_set_type; - } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { - ZigType *payload_type = prev_inst->value.type->data.error_union.payload_type; + } else if (prev_inst->value->type->id == ZigTypeIdErrorUnion) { + ZigType *payload_type = prev_inst->value->type->data.error_union.payload_type; if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown))) return ira->codegen->builtin_types.entry_invalid; return get_error_union_type(ira->codegen, err_set_type, payload_type); @@ -10949,44 +10976,44 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT return ira->codegen->builtin_types.entry_invalid; return get_error_union_type(ira->codegen, err_set_type, payload_type); } else { - if (prev_inst->value.type->id == ZigTypeIdComptimeInt || - prev_inst->value.type->id == ZigTypeIdComptimeFloat) + if (prev_inst->value->type->id == ZigTypeIdComptimeInt || + prev_inst->value->type->id == ZigTypeIdComptimeFloat) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make error union out of number literal")); return ira->codegen->builtin_types.entry_invalid; - } else if (prev_inst->value.type->id == ZigTypeIdNull) { + } else if (prev_inst->value->type->id == ZigTypeIdNull) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make error union out of null literal")); return ira->codegen->builtin_types.entry_invalid; } else { - if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) + if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) return ira->codegen->builtin_types.entry_invalid; - return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); + return get_error_union_type(ira->codegen, err_set_type, prev_inst->value->type); } } - } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { - if (prev_inst->value.type->id == ZigTypeIdComptimeInt || - prev_inst->value.type->id == ZigTypeIdComptimeFloat) + } else if (any_are_null && prev_inst->value->type->id != ZigTypeIdNull) { + if (prev_inst->value->type->id == ZigTypeIdComptimeInt || + prev_inst->value->type->id == ZigTypeIdComptimeFloat) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make maybe out of number literal")); return ira->codegen->builtin_types.entry_invalid; - } else if (prev_inst->value.type->id == ZigTypeIdOptional) { - return prev_inst->value.type; + } else if (prev_inst->value->type->id == ZigTypeIdOptional) { + return prev_inst->value->type; } else { - if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) + if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) return ira->codegen->builtin_types.entry_invalid; - return get_optional_type(ira->codegen, prev_inst->value.type); + return get_optional_type(ira->codegen, prev_inst->value->type); } } else { - return prev_inst->value.type; + return prev_inst->value->type; } } -static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) { +static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) { ConstGlobalRefs *global_refs = dest->global_refs; - memcpy(dest, src, sizeof(ConstExprValue)); + memcpy(dest, src, sizeof(ZigValue)); if (!same_global_refs) { dest->global_refs = global_refs; if (src->special != ConstValSpecialStatic) @@ -11002,8 +11029,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, CastOp cast_op, - ConstExprValue *other_val, ZigType *other_type, - ConstExprValue *const_val, ZigType *new_type) + ZigValue *other_val, ZigType *other_type, + ZigValue *const_val, ZigType *new_type) { const_val->special = other_val->special; @@ -11106,25 +11133,31 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, old_instruction->scope, old_instruction->source_node); IrInstruction *new_instruction = &const_instruction->base; - new_instruction->value.type = ty; - new_instruction->value.special = ConstValSpecialStatic; + new_instruction->value->type = ty; + new_instruction->value->special = ConstValSpecialStatic; return new_instruction; } +static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) { + IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb, + old_instruction->scope, old_instruction->source_node); + return &const_instruction->base; +} + static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type, CastOp cast_op) { if (instr_is_comptime(value) || !type_has_bits(wanted_type)) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, &value->value, value->value.type, - &result->value, wanted_type)) + if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type, + result->value, wanted_type)) { return ira->codegen->invalid_instruction; } return result; } else { IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } } @@ -11132,35 +11165,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(value->value.type->id == ZigTypeIdPointer); + assert(value->value->type->id == ZigTypeIdPointer); Error err; - if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type, + if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { return ira->codegen->invalid_instruction; } - wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type)); + wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type)); if (instr_is_comptime(value)) { - ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node); + ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node); if (pointee == nullptr) return ira->codegen->invalid_instruction; if (pointee->special != ConstValSpecialRuntime) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.data.x_ptr.special = ConstPtrSpecialBaseArray; - result->value.data.x_ptr.mut = value->value.data.x_ptr.mut; - result->value.data.x_ptr.data.base_array.array_val = pointee; - result->value.data.x_ptr.data.base_array.elem_index = 0; + result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; + result->value->data.x_ptr.mut = value->value->data.x_ptr.mut; + result->value->data.x_ptr.data.base_array.array_val = pointee; + result->value->data.x_ptr.data.base_array.elem_index = 0; return result; } } IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpBitCast); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -11169,28 +11202,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc { Error err; - if ((err = type_resolve(ira->codegen, array_ptr->value.type->data.pointer.child_type, + if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { return ira->codegen->invalid_instruction; } - wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type)); + wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); if (instr_is_comptime(array_ptr)) { - ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node); + ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); if (pointee == nullptr) return ira->codegen->invalid_instruction; if (pointee->special != ConstValSpecialRuntime) { - assert(array_ptr->value.type->id == ZigTypeIdPointer); - ZigType *array_type = array_ptr->value.type->data.pointer.child_type; + assert(array_ptr->value->type->id == ZigTypeIdPointer); + ZigType *array_type = array_ptr->value->type->data.pointer.child_type; assert(is_slice(wanted_type)); bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; IrInstruction *result = ir_const(ira, source_instr, wanted_type); - init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const); - result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value.data.x_ptr.mut; - result->value.type = wanted_type; + init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); + result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; + result->value->type = wanted_type; return result; } } @@ -11198,7 +11231,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc if (result_loc == nullptr) result_loc = no_result_loc(); IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); @@ -11403,53 +11436,61 @@ static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruc } static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { - if (instruction->value.type->id == ZigTypeIdUnreachable) + if (instruction->value->type->id == ZigTypeIdUnreachable) ir_finish_bb(ira); return instruction; } static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); - result->value.data.x_type = ty; + result->value->data.x_type = ty; return result; } static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) { IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); - result->value.data.x_bool = value; + result->value->data.x_bool = value; return result; } static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { IrInstruction *result = ir_const(ira, source_instruction, ty); - result->value.special = ConstValSpecialUndef; + result->value->special = ConstValSpecialUndef; return result; } static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) { - IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable); - result->value.special = ConstValSpecialStatic; +#ifdef ZIG_ENABLE_MEM_PROFILE + memprof_intern_count.x_unreachable += 1; +#endif + IrInstruction *result = ir_const_noval(ira, source_instruction); + result->value = &ira->codegen->intern_values.x_unreachable; return result; } static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) { - return ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_void); +#ifdef ZIG_ENABLE_MEM_PROFILE + memprof_intern_count.x_void += 1; +#endif + IrInstruction *result = ir_const_noval(ira, source_instruction); + result->value = &ira->codegen->intern_values.x_void; + return result; } static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); - bigint_init_unsigned(&result->value.data.x_bigint, value); + bigint_init_unsigned(&result->value->data.x_bigint, value); return result; } static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, - ConstExprValue *pointee, ZigType *pointee_type, + ZigValue *pointee, ZigType *pointee_type, ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) { ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); - ConstExprValue *const_val = &const_instr->value; + ZigValue *const_val = const_instr->value; const_val->data.x_ptr.special = ConstPtrSpecialRef; const_val->data.x_ptr.mut = ptr_mut; const_val->data.x_ptr.data.ref.pointee = pointee; @@ -11457,7 +11498,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio } static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, - ConstExprValue *val, UndefAllowed undef_allowed) + ZigValue *val, UndefAllowed undef_allowed) { Error err; for (;;) { @@ -11490,17 +11531,17 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode } } -static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { +static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { Error err; if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, - &value->value, undef_allowed))) + value->value, undef_allowed))) { return nullptr; } - return &value->value; + return value->value; } -ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, +ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) @@ -11508,7 +11549,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod Error err; if (expected_type != nullptr && type_is_invalid(expected_type)) - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; IrExecutable *ir_executable = allocate<IrExecutable>(1); ir_executable->source_node = source_node; @@ -11522,7 +11563,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod if (ir_executable->first_err_trace_msg != nullptr) { codegen->trace_err = ir_executable->first_err_trace_msg; - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; } if (codegen->verbose_ir) { @@ -11545,7 +11586,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod analyzed_executable->begin_scope = scope; ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); if (type_is_invalid(result_type)) { - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; } if (codegen->verbose_ir) { @@ -11554,27 +11595,27 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod fprintf(stderr, "}\n"); } - ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable); + ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); if (type_is_invalid(result->type)) - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) - return &codegen->invalid_instruction->value; + return codegen->invalid_instruction->value; return result; } static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { - if (type_is_invalid(err_value->value.type)) + if (type_is_invalid(err_value->value->type)) return nullptr; - if (err_value->value.type->id != ZigTypeIdErrorSet) { + if (err_value->value->type->id != ZigTypeIdErrorSet) { ir_add_error(ira, err_value, - buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value.type->name))); + buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); return nullptr; } - ConstExprValue *const_val = ir_resolve_const(ira, err_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, err_value, UndefBad); if (!const_val) return nullptr; @@ -11583,7 +11624,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu } static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, - ConstExprValue *val) + ZigValue *val) { Error err; if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad))) @@ -11593,28 +11634,28 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN return val->data.x_type; } -static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { - if (type_is_invalid(type_value->value.type)) +static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { + if (type_is_invalid(type_value->value->type)) return nullptr; - if (type_value->value.type->id != ZigTypeIdMetaType) { + if (type_value->value->type->id != ZigTypeIdMetaType) { ir_add_error(ira, type_value, - buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); + buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); return nullptr; } Error err; if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, - &type_value->value, LazyOk))) + type_value->value, LazyOk))) { return nullptr; } - return &type_value->value; + return type_value->value; } static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { - ConstExprValue *val = ir_resolve_type_lazy(ira, type_value); + ZigValue *val = ir_resolve_type_lazy(ira, type_value); if (val == nullptr) return ira->codegen->builtin_types.entry_invalid; @@ -11663,18 +11704,18 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { } static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) { - if (type_is_invalid(type_value->value.type)) + if (type_is_invalid(type_value->value->type)) return ira->codegen->builtin_types.entry_invalid; - if (type_value->value.type->id != ZigTypeIdMetaType) { + if (type_value->value->type->id != ZigTypeIdMetaType) { ErrorMsg *msg = ir_add_error(ira, type_value, - buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value.type->name))); + buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); add_error_note(ira->codegen, msg, op_source->source_node, buf_sprintf("`||` merges error sets; `or` performs boolean OR")); return ira->codegen->builtin_types.entry_invalid; } - ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, type_value, UndefBad); if (!const_val) return ira->codegen->builtin_types.entry_invalid; @@ -11694,16 +11735,16 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { if (fn_value == ira->codegen->invalid_instruction) return nullptr; - if (type_is_invalid(fn_value->value.type)) + if (type_is_invalid(fn_value->value->type)) return nullptr; - if (fn_value->value.type->id != ZigTypeIdFn) { + if (fn_value->value->type->id != ZigTypeIdFn) { ir_add_error_node(ira, fn_value->source_node, - buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); + buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); return nullptr; } - ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, fn_value, UndefBad); if (!const_val) return nullptr; @@ -11722,22 +11763,22 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so if (instr_is_comptime(value)) { ZigType *payload_type = wanted_type->data.maybe.child_type; IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); - if (type_is_invalid(casted_payload->value.type)) + if (type_is_invalid(casted_payload->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk); + ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); if (!val) return ira->codegen->invalid_instruction; IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.special = ConstValSpecialStatic; + const_instruction->base.value->special = ConstValSpecialStatic; if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { - copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); + copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); } else { - const_instruction->base.value.data.x_optional = val; + const_instruction->base.value->data.x_optional = val; } - const_instruction->base.value.type = wanted_type; + const_instruction->base.value->type = wanted_type; return &const_instruction->base; } @@ -11747,12 +11788,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so IrInstruction *result_loc_inst = nullptr; if (result_loc != nullptr) { result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } } IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); - result->value.data.rh_maybe = RuntimeHintOptionalNonNull; + result->value->data.rh_maybe = RuntimeHintOptionalNonNull; return result; } @@ -11765,24 +11806,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction ZigType *err_set_type = wanted_type->data.error_union.err_set_type; if (instr_is_comptime(value)) { IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); - if (type_is_invalid(casted_payload->value.type)) + if (type_is_invalid(casted_payload->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); + ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); if (!val) return ira->codegen->invalid_instruction; - ConstExprValue *err_set_val = create_const_vals(1); + ZigValue *err_set_val = create_const_vals(1); err_set_val->type = err_set_type; err_set_val->special = ConstValSpecialStatic; err_set_val->data.x_err_set = nullptr; IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.type = wanted_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_err_union.error_set = err_set_val; - const_instruction->base.value.data.x_err_union.payload = val; + const_instruction->base.value->type = wanted_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_err_union.error_set = err_set_val; + const_instruction->base.value->data.x_err_union.payload = val; return &const_instruction->base; } @@ -11790,7 +11831,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction if (handle_is_ptr(wanted_type)) { if (result_loc == nullptr) result_loc = no_result_loc(); result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } } else { @@ -11798,18 +11839,18 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction } IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); - result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; + result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; return result; } static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(value->value.type->id == ZigTypeIdErrorSet); + assert(value->value->type->id == ZigTypeIdErrorSet); assert(wanted_type->id == ZigTypeIdErrorSet); if (instr_is_comptime(value)) { - ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); + ZigValue *val = ir_resolve_const(ira, value, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -11834,14 +11875,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.type = wanted_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_err_set = val->data.x_err_set; + const_instruction->base.value->type = wanted_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_err_set = val->data.x_err_set; return &const_instruction->base; } IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -11849,7 +11890,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc IrInstruction *frame_ptr, ZigType *wanted_type) { if (instr_is_comptime(frame_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); if (ptr_val == nullptr) return ira->codegen->invalid_instruction; @@ -11861,7 +11902,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, frame_ptr, CastOpBitCast); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -11874,7 +11915,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpBitCast); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -11887,21 +11928,21 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); if (instr_is_comptime(casted_value)) { - ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); if (!val) return ira->codegen->invalid_instruction; - ConstExprValue *err_set_val = create_const_vals(1); + ZigValue *err_set_val = create_const_vals(1); err_set_val->special = ConstValSpecialStatic; err_set_val->type = wanted_type->data.error_union.err_set_type; err_set_val->data.x_err_set = val->data.x_err_set; IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.type = wanted_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_err_union.error_set = err_set_val; - const_instruction->base.value.data.x_err_union.payload = nullptr; + const_instruction->base.value->type = wanted_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_err_union.error_set = err_set_val; + const_instruction->base.value->data.x_err_union.payload = nullptr; return &const_instruction->base; } @@ -11909,7 +11950,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so if (handle_is_ptr(wanted_type)) { if (result_loc == nullptr) result_loc = no_result_loc(); result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } } else { @@ -11918,7 +11959,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); - result->value.data.rh_error_union = RuntimeHintErrorUnionError; + result->value->data.rh_error_union = RuntimeHintErrorUnionError; return result; } @@ -11926,17 +11967,17 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so assert(wanted_type->id == ZigTypeIdOptional); assert(instr_is_comptime(value)); - ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); + ZigValue *val = ir_resolve_const(ira, value, UndefBad); assert(val != nullptr); IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialStatic; + result->value->special = ConstValSpecialStatic; if (get_codegen_ptr_type(wanted_type) != nullptr) { - result->value.data.x_ptr.special = ConstPtrSpecialNull; + result->value->data.x_ptr.special = ConstPtrSpecialNull; } else if (is_opt_err_set(wanted_type)) { - result->value.data.x_err_set = nullptr; + result->value->data.x_err_set = nullptr; } else { - result->value.data.x_optional = nullptr; + result->value->data.x_optional = nullptr; } return result; } @@ -11948,12 +11989,12 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction assert(wanted_type->data.pointer.ptr_len == PtrLenC); assert(instr_is_comptime(value)); - ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); + ZigValue *val = ir_resolve_const(ira, value, UndefBad); assert(val != nullptr); IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.data.x_ptr.special = ConstPtrSpecialNull; - result->value.data.x_ptr.mut = ConstPtrMutComptimeConst; + result->value->data.x_ptr.special = ConstPtrSpecialNull; + result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; return result; } @@ -11962,36 +12003,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi { Error err; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; - if ((err = type_resolve(ira->codegen, value->value.type, ResolveStatusZeroBitsKnown))) + if ((err = type_resolve(ira->codegen, value->value->type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; if (instr_is_comptime(value)) { - ConstExprValue *val = ir_resolve_const(ira, value, LazyOk); + ZigValue *val = ir_resolve_const(ira, value, LazyOk); if (!val) return ira->codegen->invalid_instruction; - return ir_get_const_ptr(ira, source_instruction, val, value->value.type, + return ir_get_const_ptr(ira, source_instruction, val, value->value->type, ConstPtrMutComptimeConst, is_const, is_volatile, 0); } - ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type, is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; IrInstruction *result_loc; - if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { - result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, + if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { + result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, false, true); } else { result_loc = nullptr; } IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); - new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; + new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; return new_instruction; } @@ -12004,39 +12045,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s IrInstruction *array_ptr = nullptr; IrInstruction *array; - if (array_arg->value.type->id == ZigTypeIdPointer) { + if (array_arg->value->type->id == ZigTypeIdPointer) { array = ir_get_deref(ira, source_instr, array_arg, nullptr); array_ptr = array_arg; } else { array = array_arg; } - ZigType *array_type = array->value.type; + ZigType *array_type = array->value->type; assert(array_type->id == ZigTypeIdArray); if (instr_is_comptime(array) || array_type->data.array.len == 0) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true); - result->value.type = wanted_type; + init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true); + result->value->type = wanted_type; return result; } IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); - init_const_usize(ira->codegen, &start->value, 0); + init_const_usize(ira->codegen, start->value, 0); IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); - init_const_usize(ira->codegen, &end->value, array_type->data.array.len); + init_const_usize(ira->codegen, end->value, array_type->data.array.len); if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); if (result_loc == nullptr) result_loc = no_result_loc(); IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst); - result->value.data.rh_slice.id = RuntimeHintSliceIdLen; - result->value.data.rh_slice.len = array_type->data.array.len; + result->value->data.rh_slice.id = RuntimeHintSliceIdLen; + result->value->data.rh_slice.len = array_type->data.array.len; return result; } @@ -12065,19 +12106,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour IrInstruction *enum_target; ZigType *enum_type; - if (target->value.type->id == ZigTypeIdUnion) { - enum_type = ir_resolve_union_tag_type(ira, target, target->value.type); + if (target->value->type->id == ZigTypeIdUnion) { + enum_type = ir_resolve_union_tag_type(ira, target, target->value->type); if (type_is_invalid(enum_type)) return ira->codegen->invalid_instruction; enum_target = ir_implicit_cast(ira, target, enum_type); - if (type_is_invalid(enum_target->value.type)) + if (type_is_invalid(enum_target->value->type)) return ira->codegen->invalid_instruction; - } else if (target->value.type->id == ZigTypeIdEnum) { + } else if (target->value->type->id == ZigTypeIdEnum) { enum_target = target; - enum_type = target->value.type; + enum_type = target->value->type; } else { ir_add_error(ira, target, - buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); + buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -12092,41 +12133,41 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour enum_type->data.enumeration.src_field_count == 1) { IrInstruction *result = ir_const(ira, source_instr, tag_type); - init_const_bigint(&result->value, tag_type, + init_const_bigint(result->value, tag_type, &enum_type->data.enumeration.fields[0].value); return result; } if (instr_is_comptime(enum_target)) { - ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad); + ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad); if (!val) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, source_instr, tag_type); - init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag); + init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); return result; } IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, source_instr->source_node, enum_target); - result->value.type = tag_type; + result->value->type = tag_type; return result; } static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(target->value.type->id == ZigTypeIdUnion); + assert(target->value->type->id == ZigTypeIdUnion); assert(wanted_type->id == ZigTypeIdEnum); - assert(wanted_type == target->value.type->data.unionation.tag_type); + assert(wanted_type == target->value->type->data.unionation.tag_type); if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialStatic; - result->value.type = wanted_type; - bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_union.tag); + result->value->special = ConstValSpecialStatic; + result->value->type = wanted_type; + bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); return result; } @@ -12135,16 +12176,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou wanted_type->data.enumeration.src_field_count == 1) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialStatic; - result->value.type = wanted_type; - TypeEnumField *enum_field = target->value.type->data.unionation.fields[0].enum_field; - bigint_init_bigint(&result->value.data.x_enum_tag, &enum_field->value); + result->value->special = ConstValSpecialStatic; + result->value->type = wanted_type; + TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; + bigint_init_bigint(&result->value->data.x_enum_tag, &enum_field->value); return result; } IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, target); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12152,7 +12193,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc IrInstruction *target, ZigType *wanted_type) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialUndef; + result->value->special = ConstValSpecialUndef; return result; } @@ -12166,11 +12207,11 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so return ira->codegen->invalid_instruction; IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); @@ -12201,12 +12242,12 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so } IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialStatic; - result->value.type = wanted_type; - bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag); - result->value.data.x_union.payload = create_const_vals(1); - result->value.data.x_union.payload->special = ConstValSpecialStatic; - result->value.data.x_union.payload->type = field_type; + result->value->special = ConstValSpecialStatic; + result->value->type = wanted_type; + bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); + result->value->data.x_union.payload = create_const_vals(1); + result->value->data.x_union.payload->special = ConstValSpecialStatic; + result->value->data.x_union.payload->type = field_type; return result; } @@ -12214,7 +12255,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so // and in fact it's a noop cast because the union value is just the enum value if (wanted_type->data.unionation.gen_field_count == 0) { IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12245,7 +12286,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; if (wanted_type->id == ZigTypeIdInt) { @@ -12259,16 +12300,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction { ir_add_error(ira, source_instr, buf_sprintf("cast from '%s' to '%s' truncates bits", - buf_ptr(&target->value.type->name), buf_ptr(&wanted_type->name))); + buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name))); return ira->codegen->invalid_instruction; } } IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.type = wanted_type; + result->value->type = wanted_type; if (wanted_type->id == ZigTypeIdInt) { - bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); + bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); } else { - float_init_float(&result->value, val); + float_init_float(result->value, val); } return result; } @@ -12278,16 +12319,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction // the target is zero. if (!type_has_bits(wanted_type)) { assert(wanted_type->id == ZigTypeIdInt); - assert(type_has_bits(target->value.type)); + assert(type_has_bits(target->value->type)); ir_build_assert_zero(ira, source_instr, target); IrInstruction *result = ir_const_unsigned(ira, source_instr, 0); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, source_instr->source_node, target); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12297,7 +12338,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour Error err; assert(wanted_type->id == ZigTypeIdEnum); - ZigType *actual_type = target->value.type; + ZigType *actual_type = target->value->type; if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) return ira->codegen->invalid_instruction; @@ -12313,7 +12354,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt); if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -12330,28 +12371,28 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour } IrInstruction *result = ir_const(ira, source_instr, wanted_type); - bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_bigint); + bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); return result; } IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, source_instr->source_node, nullptr, target); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, source_instr, wanted_type); if (wanted_type->id == ZigTypeIdComptimeFloat) { - float_init_float(&result->value, val); + float_init_float(result->value, val); } else if (wanted_type->id == ZigTypeIdComptimeInt) { - bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); + bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); } else { zig_unreachable(); } @@ -12361,12 +12402,12 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(target->value.type->id == ZigTypeIdInt); - assert(!target->value.type->data.integral.is_signed); + assert(target->value->type->id == ZigTypeIdInt); + assert(!target->value->type->data.integral.is_signed); assert(wanted_type->id == ZigTypeIdErrorSet); if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -12389,7 +12430,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc } size_t index = bigint_as_usize(&val->data.x_bigint); - result->value.data.x_err_set = ira->codegen->errors_by_index.at(index); + result->value->data.x_err_set = ira->codegen->errors_by_index.at(index); return result; } else { ErrorTableEntry *err = nullptr; @@ -12412,13 +12453,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc return ira->codegen->invalid_instruction; } - result->value.data.x_err_set = err; + result->value->data.x_err_set = err; return result; } } IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12427,10 +12468,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc { assert(wanted_type->id == ZigTypeIdInt); - ZigType *err_type = target->value.type; + ZigType *err_type = target->value->type; if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -12444,11 +12485,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc } else { zig_unreachable(); } - result->value.type = wanted_type; + result->value->type = wanted_type; uint64_t err_value = err ? err->value : 0; - bigint_init_unsigned(&result->value.data.x_bigint, err_value); + bigint_init_unsigned(&result->value->data.x_bigint, err_value); - if (!bigint_fits_in_bits(&result->value.data.x_bigint, + if (!bigint_fits_in_bits(&result->value->data.x_bigint, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) { ir_add_error_node(ira, source_instr->source_node, @@ -12474,12 +12515,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc } if (err_set_type->data.error_set.err_count == 0) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - bigint_init_unsigned(&result->value.data.x_bigint, 0); + bigint_init_unsigned(&result->value->data.x_bigint, 0); return result; } else if (err_set_type->data.error_set.err_count == 1) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; - bigint_init_unsigned(&result->value.data.x_bigint, err->value); + bigint_init_unsigned(&result->value->data.x_bigint, err->value); return result; } } @@ -12493,7 +12534,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc } IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12502,25 +12543,25 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou { assert(wanted_type->id == ZigTypeIdPointer); Error err; - if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown))) + if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) return ira->codegen->invalid_instruction; - assert((wanted_type->data.pointer.is_const && target->value.type->data.pointer.is_const) || !target->value.type->data.pointer.is_const); - wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type)); + assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const); + wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type)); ZigType *array_type = wanted_type->data.pointer.child_type; assert(array_type->id == ZigTypeIdArray); assert(array_type->data.array.len == 1); if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; assert(val->type->id == ZigTypeIdPointer); - ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); + ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); if (pointee == nullptr) return ira->codegen->invalid_instruction; if (pointee->special != ConstValSpecialRuntime) { - ConstExprValue *array_val = create_const_vals(1); + ZigValue *array_val = create_const_vals(1); array_val->special = ConstValSpecialStatic; array_val->type = array_type; array_val->data.x_array.special = ConstArraySpecialNone; @@ -12530,11 +12571,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.type = wanted_type; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef; - const_instruction->base.value.data.x_ptr.data.ref.pointee = array_val; - const_instruction->base.value.data.x_ptr.mut = val->data.x_ptr.mut; + const_instruction->base.value->type = wanted_type; + const_instruction->base.value->special = ConstValSpecialStatic; + const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef; + const_instruction->base.value->data.x_ptr.data.ref.pointee = array_val; + const_instruction->base.value->data.x_ptr.mut = val->data.x_ptr.mut; return &const_instruction->base; } } @@ -12542,7 +12583,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou // pointer to array and pointer to single item are represented the same way at runtime IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpBitCast); - result->value.type = wanted_type; + result->value->type = wanted_type; return result; } @@ -12724,10 +12765,10 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * IrInstruction *array, ZigType *vector_type) { if (instr_is_comptime(array)) { - // arrays and vectors have the same ConstExprValue representation + // arrays and vectors have the same ZigValue representation IrInstruction *result = ir_const(ira, source_instr, vector_type); - copy_const_val(&result->value, &array->value, false); - result->value.type = vector_type; + copy_const_val(result->value, array->value, false); + result->value->type = vector_type; return result; } return ir_build_array_to_vector(ira, source_instr, array, vector_type); @@ -12737,10 +12778,10 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc) { if (instr_is_comptime(vector)) { - // arrays and vectors have the same ConstExprValue representation + // arrays and vectors have the same ZigValue representation IrInstruction *result = ir_const(ira, source_instr, array_type); - copy_const_val(&result->value, &vector->value, false); - result->value.type = array_type; + copy_const_val(result->value, vector->value, false); + result->value->type = array_type; return result; } if (result_loc == nullptr) { @@ -12748,7 +12789,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * } IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); @@ -12761,23 +12802,23 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou if (instr_is_comptime(integer)) { unsigned_integer = integer; } else { - assert(integer->value.type->id == ZigTypeIdInt); + assert(integer->value->type->id == ZigTypeIdInt); - if (integer->value.type->data.integral.bit_count > + if (integer->value->type->data.integral.bit_count > ira->codegen->builtin_types.entry_usize->data.integral.bit_count) { ir_add_error(ira, source_instr, buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", - buf_ptr(&integer->value.type->name), + buf_ptr(&integer->value->type->name), buf_ptr(&dest_type->name))); return ira->codegen->invalid_instruction; } - if (integer->value.type->data.integral.is_signed) { + if (integer->value->type->data.integral.is_signed) { ZigType *unsigned_int_type = get_int_type(ira->codegen, false, - integer->value.type->data.integral.bit_count); + integer->value->type->data.integral.bit_count); unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); - if (type_is_invalid(unsigned_integer->value.type)) + if (type_is_invalid(unsigned_integer->value->type)) return ira->codegen->invalid_instruction; } else { unsigned_integer = integer; @@ -12807,16 +12848,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; - TypeEnumField *field = find_enum_type_field(enum_type, value->value.data.x_enum_literal); + TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); if (field == nullptr) { ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", - buf_ptr(&enum_type->name), buf_ptr(value->value.data.x_enum_literal))); + buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); return ira->codegen->invalid_instruction; } IrInstruction *result = ir_const(ira, source_instr, enum_type); - bigint_init_bigint(&result->value.data.x_enum_tag, &field->value); + bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); return result; } @@ -12885,7 +12926,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst { IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, - struct_operand->value.type, false); + struct_operand->value->type, false); return ir_get_deref(ira, source_instr, field_ptr, nullptr); } @@ -12893,7 +12934,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst ZigType *wanted_type, IrInstruction *value) { Error err; - ZigType *actual_type = value->value.type; + ZigType *actual_type = value->value->type; AstNode *source_node = source_instr->source_node; if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { @@ -12915,13 +12956,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } if (const_cast_result.id == ConstCastResultIdFnCC) { - ir_assert(value->value.type->id == ZigTypeIdFn, source_instr); + ir_assert(value->value->type->id == ZigTypeIdFn, source_instr); // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok. if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync && actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified) { - ir_assert(value->value.data.x_ptr.special == ConstPtrSpecialFunction, source_instr); - ZigFn *fn = value->value.data.x_ptr.data.fn.fn_entry; + ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); + ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry; if (fn->inferred_async_node == nullptr) { fn->inferred_async_node = source_instr->source_node; } @@ -12963,7 +13004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst { IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); } @@ -12999,11 +13040,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst actual_type->id == ZigTypeIdComptimeFloat) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) + if (type_is_invalid(cast2->value->type)) return ira->codegen->invalid_instruction; return cast2; @@ -13018,29 +13059,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) { - if (value->value.special == ConstValSpecialUndef) { + if (value->value->special == ConstValSpecialUndef) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); - result->value.special = ConstValSpecialUndef; + result->value->special = ConstValSpecialUndef; return result; } if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { - copy_const_val(&result->value, &value->value, false); - result->value.type = wanted_type; + copy_const_val(result->value, value->value, false); + result->value->type = wanted_type; } else { - float_init_bigint(&result->value.data.x_bigint, &value->value); + float_init_bigint(&result->value->data.x_bigint, value->value); } return result; } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { IrInstruction *result = ir_const(ira, source_instr, wanted_type); if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { BigFloat bf; - bigfloat_init_bigint(&bf, &value->value.data.x_bigint); - float_init_bigfloat(&result->value, &bf); + bigfloat_init_bigint(&bf, &value->value->data.x_bigint); + float_init_bigfloat(result->value, &bf); } else { - float_init_float(&result->value, &value->value); + float_init_float(result->value, value->value); } return result; } @@ -13102,11 +13143,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst source_node, false).id == ConstCastResultIdOk) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) + if (type_is_invalid(cast2->value->type)) return ira->codegen->invalid_instruction; return cast2; @@ -13121,11 +13162,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst actual_type->data.pointer.child_type->id == ZigTypeIdArray) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) + if (type_is_invalid(cast2->value->type)) return ira->codegen->invalid_instruction; return cast2; @@ -13202,11 +13243,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst if (ok_align) { if (wanted_type->id == ZigTypeIdErrorUnion) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) + if (type_is_invalid(cast2->value->type)) return ira->codegen->invalid_instruction; return cast2; @@ -13309,11 +13350,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst source_node, false).id == ConstCastResultIdOk) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); - if (type_is_invalid(cast1->value.type)) + if (type_is_invalid(cast1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) + if (type_is_invalid(cast2->value->type)) return ira->codegen->invalid_instruction; return cast2; @@ -13529,13 +13570,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou assert(value); assert(value != ira->codegen->invalid_instruction); assert(!expected_type || !type_is_invalid(expected_type)); - assert(value->value.type); - assert(!type_is_invalid(value->value.type)); + assert(value->value->type); + assert(!type_is_invalid(value->value->type)); if (expected_type == nullptr) return value; // anything will do - if (expected_type == value->value.type) + if (expected_type == value->value->type) return value; // match - if (value->value.type->id == ZigTypeIdUnreachable) + if (value->value->type->id == ZigTypeIdUnreachable) return value; return ir_analyze_cast(ira, value_source_instr, expected_type, value); @@ -13549,7 +13590,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc ResultLoc *result_loc) { Error err; - ZigType *ptr_type = ptr->value.type; + ZigType *ptr_type = ptr->value->type; if (type_is_invalid(ptr_type)) return ira->codegen->invalid_instruction; @@ -13571,24 +13612,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc break; } if (instr_is_comptime(ptr)) { - if (ptr->value.special == ConstValSpecialUndef) { + if (ptr->value->special == ConstValSpecialUndef) { ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); return ira->codegen->invalid_instruction; } - if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { - ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); + if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { + ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); if (child_type == ira->codegen->builtin_types.entry_var) { child_type = pointee->type; } if (pointee->special != ConstValSpecialRuntime) { IrInstruction *result = ir_const(ira, source_instruction, child_type); - if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, &result->value, - &ptr->value))) + if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, + ptr->value))) { return ira->codegen->invalid_instruction; } - result->value.type = child_type; + result->value->type = child_type; return result; } } @@ -13626,7 +13667,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc if (result_loc == nullptr) result_loc = no_result_loc(); result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, false, true); - if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { + if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { return result_loc_inst; } } else { @@ -13637,7 +13678,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc } static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, - ConstExprValue *const_val, uint32_t *out) + ZigValue *const_val, uint32_t *out) { Error err; if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad))) @@ -13660,15 +13701,15 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode } static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; // Look for this pattern: `*align(@alignOf(T)) T`. // This can be resolved to be `*out = 0` without resolving any alignment. - if (elem_type != nullptr && value->value.special == ConstValSpecialLazy && - value->value.data.x_lazy->id == LazyValueIdAlignOf) + if (elem_type != nullptr && value->value->special == ConstValSpecialLazy && + value->value->data.x_lazy->id == LazyValueIdAlignOf) { - LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value.data.x_lazy); + LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value->data.x_lazy); ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type); if (type_is_invalid(lazy_elem_type)) @@ -13681,22 +13722,22 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem } IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, - &casted_value->value, out); + casted_value->value, out); } static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13709,14 +13750,14 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out } static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13733,18 +13774,18 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) } static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; - ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); + ZigValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); assert(atomic_order_val->type->id == ZigTypeIdMetaType); ZigType *atomic_order_type = atomic_order_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13753,18 +13794,18 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic } static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; - ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); + ZigValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType); ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13773,18 +13814,18 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi } static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; - ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); + ZigValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); assert(global_linkage_val->type->id == ZigTypeIdMetaType); ZigType *global_linkage_type = global_linkage_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13793,18 +13834,18 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob } static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return false; - ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); + ZigValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); assert(float_mode_val->type->id == ZigTypeIdMetaType); ZigType *float_mode_type = float_mode_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return false; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return false; @@ -13813,25 +13854,25 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod } static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return nullptr; ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, 0, 0, 0, false); ZigType *str_type = get_slice_type(ira->codegen, ptr_type); IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return nullptr; - ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_val) return nullptr; - ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index]; - ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index]; + ZigValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *len_field = const_val->data.x_struct.fields[slice_len_index]; assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray); - ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; expand_undef_array(ira->codegen, array_val); size_t len = bigint_as_usize(&len_field->data.x_bigint); if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) { @@ -13841,7 +13882,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { buf_resize(result, len); for (size_t i = 0; i < len; i += 1) { size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; - ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; + ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; if (char_val->special == ConstValSpecialUndef) { ir_add_error(ira, casted_value, buf_sprintf("use of undefined value")); return nullptr; @@ -13858,7 +13899,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze IrInstructionAddImplicitReturnType *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ir_unreach_error(ira); if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) { @@ -13870,11 +13911,11 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { IrInstruction *operand = instruction->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return ir_unreach_error(ira); IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); - if (type_is_invalid(casted_operand->value.type)) { + if (type_is_invalid(casted_operand->value->type)) { AstNode *source_node = ira->explicit_return_type_source_node; if (source_node != nullptr) { ErrorMsg *msg = ira->codegen->errors.last(); @@ -13890,13 +13931,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio // result location mechanism took care of it. IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } - if (casted_operand->value.special == ConstValSpecialRuntime && - casted_operand->value.type->id == ZigTypeIdPointer && - casted_operand->value.data.rh_ptr == RuntimeHintPtrStack) + if (casted_operand->value->special == ConstValSpecialRuntime && + casted_operand->value->type->id == ZigTypeIdPointer && + casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) { ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable")); return ir_unreach_error(ira); @@ -13904,23 +13945,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_operand); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - copy_const_val(&result->value, &instruction->base.value, true); + copy_const_val(result->value, instruction->base.value, true); return result; } static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = bin_op_instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; ZigType *bool_type = ira->codegen->builtin_types.entry_bool; @@ -13934,16 +13975,16 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; - assert(casted_op1->value.type->id == ZigTypeIdBool); - assert(casted_op2->value.type->id == ZigTypeIdBool); + assert(casted_op1->value->type->id == ZigTypeIdBool); + assert(casted_op2->value->type->id == ZigTypeIdBool); bool result_bool; if (bin_op_instruction->op_id == IrBinOpBoolOr) { result_bool = op1_val->data.x_bool || op2_val->data.x_bool; @@ -13958,7 +13999,7 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); - result->value.type = bool_type; + result->value->type = bool_type; return result; } @@ -13981,7 +14022,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { } } -static bool optional_value_is_null(ConstExprValue *val) { +static bool optional_value_is_null(ZigValue *val) { assert(val->special == ConstValSpecialStatic); if (get_codegen_ptr_type(val->type) != nullptr) { if (val->data.x_ptr.special == ConstPtrSpecialNull) { @@ -13999,7 +14040,7 @@ static bool optional_value_is_null(ConstExprValue *val) { } static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, - ConstExprValue *op1_val, ConstExprValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, + ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, bool one_possible_value) { if (op1_val->special == ConstValSpecialUndef || op2_val->special == ConstValSpecialUndef) @@ -14052,7 +14093,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t } // Returns ErrorNotLazy when the value cannot be determined -static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *result) { +static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { Error err; switch (val->special) { @@ -14079,7 +14120,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *resul LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); IrAnalyze *ira = lazy_size_of->ira; bool is_zero_bits; - if ((err = type_val_resolve_zero_bits(ira->codegen, &lazy_size_of->target_type->value, + if ((err = type_val_resolve_zero_bits(ira->codegen, lazy_size_of->target_type->value, nullptr, nullptr, &is_zero_bits))) { return err; @@ -14098,33 +14139,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * Error err; IrInstruction *op1 = bin_op_instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = bin_op_instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; AstNode *source_node = bin_op_instruction->base.source_node; IrBinOp op_id = bin_op_instruction->op_id; bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); - if (is_equality_cmp && op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { + if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) { return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq)); } else if (is_equality_cmp && - ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || - (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional))) + ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || + (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) { IrInstruction *maybe_op; - if (op1->value.type->id == ZigTypeIdNull) { + if (op1->value->type->id == ZigTypeIdNull) { maybe_op = op2; - } else if (op2->value.type->id == ZigTypeIdNull) { + } else if (op2->value->type->id == ZigTypeIdNull) { maybe_op = op1; } else { zig_unreachable(); } if (instr_is_comptime(maybe_op)) { - ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); + ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); if (!maybe_val) return ira->codegen->invalid_instruction; bool is_null = optional_value_is_null(maybe_val); @@ -14134,32 +14175,32 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, source_node, maybe_op); - is_non_null->value.type = ira->codegen->builtin_types.entry_bool; + is_non_null->value->type = ira->codegen->builtin_types.entry_bool; if (op_id == IrBinOpCmpEq) { IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, is_non_null); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } else { return is_non_null; } } else if (is_equality_cmp && - ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer && - op2->value.type->data.pointer.ptr_len == PtrLenC) || - (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer && - op1->value.type->data.pointer.ptr_len == PtrLenC))) + ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdPointer && + op2->value->type->data.pointer.ptr_len == PtrLenC) || + (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer && + op1->value->type->data.pointer.ptr_len == PtrLenC))) { IrInstruction *c_ptr_op; - if (op1->value.type->id == ZigTypeIdNull) { + if (op1->value->type->id == ZigTypeIdNull) { c_ptr_op = op2; - } else if (op2->value.type->id == ZigTypeIdNull) { + } else if (op2->value->type->id == ZigTypeIdNull) { c_ptr_op = op1; } else { zig_unreachable(); } if (instr_is_comptime(c_ptr_op)) { - ConstExprValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); + ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); if (!c_ptr_val) return ira->codegen->invalid_instruction; if (c_ptr_val->special == ConstValSpecialUndef) @@ -14172,46 +14213,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * } IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, source_node, c_ptr_op); - is_non_null->value.type = ira->codegen->builtin_types.entry_bool; + is_non_null->value->type = ira->codegen->builtin_types.entry_bool; if (op_id == IrBinOpCmpEq) { IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, is_non_null); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } else { return is_non_null; } - } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) { - ZigType *non_null_type = (op1->value.type->id == ZigTypeIdNull) ? op2->value.type : op1->value.type; + } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) { + ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", buf_ptr(&non_null_type->name))); return ira->codegen->invalid_instruction; } else if (is_equality_cmp && ( - (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) || - (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion))) + (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) || + (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion))) { // Support equality comparison between a union's tag value and a enum literal - IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2; - IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1; + IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; + IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; - ZigType *tag_type = union_val->value.type->data.unionation.tag_type; + ZigType *tag_type = union_val->value->type->data.unionation.tag_type; assert(tag_type != nullptr); IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type); - if (type_is_invalid(casted_union->value.type)) + if (type_is_invalid(casted_union->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type); - if (type_is_invalid(casted_val->value.type)) + if (type_is_invalid(casted_val->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_union)) { - ConstExprValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); + ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); if (!const_union_val) return ira->codegen->invalid_instruction; - ConstExprValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); + ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); if (!const_enum_val) return ira->codegen->invalid_instruction; @@ -14224,17 +14265,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op_id, casted_union, casted_val, bin_op_instruction->safety_check_on); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } - if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { + if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) { if (!is_equality_cmp) { ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); return ira->codegen->invalid_instruction; } - ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); + ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node); if (type_is_invalid(intersect_type)) { return ira->codegen->invalid_instruction; } @@ -14247,7 +14288,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * // (and make it comptime known) // this is a function which is evaluated at comptime and returns an inferred error set will have an empty // error set. - if (op1->value.type->data.error_set.err_count == 0 || op2->value.type->data.error_set.err_count == 0) { + if (op1->value->type->data.error_set.err_count == 0 || op2->value->type->data.error_set.err_count == 0) { bool are_equal = false; bool answer; if (op_id == IrBinOpCmpEq) { @@ -14264,10 +14305,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * if (intersect_type->data.error_set.err_count == 0) { ir_add_error_node(ira, source_node, buf_sprintf("error sets '%s' and '%s' have no common errors", - buf_ptr(&op1->value.type->name), buf_ptr(&op2->value.type->name))); + buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } - if (op1->value.type->data.error_set.err_count == 1 && op2->value.type->data.error_set.err_count == 1) { + if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) { bool are_equal = true; bool answer; if (op_id == IrBinOpCmpEq) { @@ -14282,10 +14323,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * } if (instr_is_comptime(op1) && instr_is_comptime(op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; @@ -14305,7 +14346,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op_id, op1, op2, bin_op_instruction->safety_check_on); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } @@ -14390,12 +14431,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * // Before resolving the values, we special case comparisons against zero. These can often be done // without resolving lazy values, preventing potential dependency loops. Cmp op1_cmp_zero; - if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op1->value, &op1_cmp_zero))) { + if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op1->value, &op1_cmp_zero))) { if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; return ira->codegen->invalid_instruction; } Cmp op2_cmp_zero; - if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op2->value, &op2_cmp_zero))) { + if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op2->value, &op2_cmp_zero))) { if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; return ira->codegen->invalid_instruction; } @@ -14430,33 +14471,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * } never_mind_just_calculate_it_normally: - ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; if (resolved_type->id != ZigTypeIdVector) return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value); IrInstruction *result = ir_const(ira, &bin_op_instruction->base, get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); - result->value.data.x_array.data.s_none.elements = + result->value->data.x_array.data.s_none.elements = create_const_vals(resolved_type->data.vector.len); - expand_undef_array(ira->codegen, &result->value); + expand_undef_array(ira->codegen, result->value); for (size_t i = 0;i < resolved_type->data.vector.len;i++) { IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, &op1_val->data.x_array.data.s_none.elements[i], &op2_val->data.x_array.data.s_none.elements[i], bin_op_instruction, op_id, one_possible_value); - copy_const_val(&result->value.data.x_array.data.s_none.elements[i], &cur_res->value, false); + copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false); } return result; } // some comparisons with unsigned numbers can be evaluated if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) { - ConstExprValue *known_left_val; + ZigValue *known_left_val; IrBinOp flipped_op_id; if (instr_is_comptime(casted_op1)) { known_left_val = ir_resolve_const(ira, casted_op1, UndefBad); @@ -14495,16 +14536,16 @@ never_mind_just_calculate_it_normally: bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); if (resolved_type->id == ZigTypeIdVector) { - result->value.type = get_vector_type(ira->codegen, resolved_type->data.vector.len, + result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool); } else { - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; } return result; } static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, - ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) + ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) { bool is_int; bool is_float; @@ -14646,7 +14687,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in } } else { float_div_trunc(out_val, op1_val, op2_val); - ConstExprValue remainder = {}; + ZigValue remainder = {}; float_rem(&remainder, op1_val, op2_val); if (float_cmp_zero(&remainder) != CmpEQ) { return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder")); @@ -14684,10 +14725,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in // This works on operands that have already been checked to be comptime known. static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr, - ZigType *type_entry, ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val) + ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) { IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry); - ConstExprValue *out_val = &result_instruction->value; + ZigValue *out_val = result_instruction->value; if (type_entry->id == ZigTypeIdVector) { expand_undef_array(ira->codegen, op1_val); expand_undef_array(ira->codegen, op2_val); @@ -14696,9 +14737,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i size_t len = type_entry->data.vector.len; ZigType *scalar_type = type_entry->data.vector.elem_type; for (size_t i = 0; i < len; i += 1) { - ConstExprValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i]; - ConstExprValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i]; - ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i]; + ZigValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i]; + ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; assert(scalar_op1_val->type == scalar_type); assert(scalar_op2_val->type == scalar_type); assert(scalar_out_val->type == scalar_type); @@ -14722,52 +14763,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; - if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { + if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, bin_op_instruction->op1, buf_sprintf("bit shifting operation expected integer type, found '%s'", - buf_ptr(&op1->value.type->name))); + buf_ptr(&op1->value->type->name))); return ira->codegen->invalid_instruction; } IrInstruction *op2 = bin_op_instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; - if (op2->value.type->id != ZigTypeIdInt && op2->value.type->id != ZigTypeIdComptimeInt) { + if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, bin_op_instruction->op2, buf_sprintf("shift amount has to be an integer type, but found '%s'", - buf_ptr(&op2->value.type->name))); + buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } IrInstruction *casted_op2; IrBinOp op_id = bin_op_instruction->op_id; - if (op1->value.type->id == ZigTypeIdComptimeInt) { + if (op1->value->type->id == ZigTypeIdComptimeInt) { casted_op2 = op2; if (op_id == IrBinOpBitShiftLeftLossy) { op_id = IrBinOpBitShiftLeftExact; } - if (casted_op2->value.data.x_bigint.is_negative) { + if (casted_op2->value->data.x_bigint.is_negative) { Buf *val_buf = buf_alloc(); - bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10); + bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10); ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); return ira->codegen->invalid_instruction; } } else { ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, - op1->value.type->data.integral.bit_count - 1); + op1->value->type->data.integral.bit_count - 1); if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && - op2->value.type->id == ZigTypeIdComptimeInt) { - if (!bigint_fits_in_bits(&op2->value.data.x_bigint, + op2->value->type->id == ZigTypeIdComptimeInt) { + if (!bigint_fits_in_bits(&op2->value->data.x_bigint, shift_amt_type->data.integral.bit_count, - op2->value.data.x_bigint.is_negative)) { + op2->value->data.x_bigint.is_negative)) { Buf *val_buf = buf_alloc(); - bigint_append_buf(val_buf, &op2->value.data.x_bigint, 10); + bigint_append_buf(val_buf, &op2->value->data.x_bigint, 10); ErrorMsg* msg = ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("RHS of shift is too large for LHS type")); @@ -14788,30 +14829,30 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b } if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; - return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value.type, op1_val, op_id, op2_val); - } else if (op1->value.type->id == ZigTypeIdComptimeInt) { + return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val); + } else if (op1->value->type->id == ZigTypeIdComptimeInt) { ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); return ira->codegen->invalid_instruction; - } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) { + } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) { IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope, - bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop); - result->value.type = op1->value.type; + bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop); + result->value->type = op1->value->type; return result; } IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op_id, op1, casted_op2, bin_op_instruction->safety_check_on); - result->value.type = op1->value.type; + result->value->type = op1->value->type; return result; } @@ -14880,42 +14921,42 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp Error err; IrInstruction *op1 = instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; IrBinOp op_id = instruction->op_id; // look for pointer math - if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) { + if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) { IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); - if (type_is_invalid(casted_op2->value.type)) + if (type_is_invalid(casted_op2->value->type)) return ira->codegen->invalid_instruction; // If either operand is undef, result is undef. - ConstExprValue *op1_val = nullptr; - ConstExprValue *op2_val = nullptr; + ZigValue *op1_val = nullptr; + ZigValue *op2_val = nullptr; if (instr_is_comptime(op1)) { op1_val = ir_resolve_const(ira, op1, UndefOk); if (op1_val == nullptr) return ira->codegen->invalid_instruction; if (op1_val->special == ConstValSpecialUndef) - return ir_const_undef(ira, &instruction->base, op1->value.type); + return ir_const_undef(ira, &instruction->base, op1->value->type); } if (instr_is_comptime(casted_op2)) { op2_val = ir_resolve_const(ira, casted_op2, UndefOk); if (op2_val == nullptr) return ira->codegen->invalid_instruction; if (op2_val->special == ConstValSpecialUndef) - return ir_const_undef(ira, &instruction->base, op1->value.type); + return ir_const_undef(ira, &instruction->base, op1->value->type); } if (op2_val != nullptr && op1_val != nullptr && - (op1->value.data.x_ptr.special == ConstPtrSpecialHardCodedAddr || - op1->value.data.x_ptr.special == ConstPtrSpecialNull)) + (op1->value->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || + op1->value->data.x_ptr.special == ConstPtrSpecialNull)) { uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ? 0 : op1_val->data.x_ptr.data.hard_coded_addr.addr; @@ -14935,15 +14976,15 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp zig_unreachable(); } IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type); - result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; - result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; - result->value.data.x_ptr.data.hard_coded_addr.addr = new_addr; + result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; + result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; + result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; return result; } IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, op_id, op1, casted_op2, true); - result->value.type = op1->value.type; + result->value->type = op1->value->type; return result; } @@ -14958,21 +14999,21 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || resolved_type->id == ZigTypeIdFloat || (resolved_type->id == ZigTypeIdComptimeFloat && - ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != - (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || + ((bigfloat_cmp_zero(&op1->value->data.x_bigfloat) != CmpGT) != + (bigfloat_cmp_zero(&op2->value->data.x_bigfloat) != CmpGT))) || (resolved_type->id == ZigTypeIdComptimeInt && - ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != - (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) + ((bigint_cmp_zero(&op1->value->data.x_bigint) != CmpGT) != + (bigint_cmp_zero(&op2->value->data.x_bigint) != CmpGT))) ); if (op_id == IrBinOpDivUnspecified && is_int) { if (is_signed_div) { bool ok = false; if (instr_is_comptime(op1) && instr_is_comptime(op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; @@ -14995,8 +15036,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp if (!ok) { ir_add_error(ira, &instruction->base, buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", - buf_ptr(&op1->value.type->name), - buf_ptr(&op2->value.type->name))); + buf_ptr(&op1->value->type->name), + buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } } else { @@ -15006,16 +15047,16 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp if (is_signed_div && (is_int || is_float)) { bool ok = false; if (instr_is_comptime(op1) && instr_is_comptime(op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; if (is_int) { - ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; - if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) { + if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) { // the division by zero error will be caught later, but we don't // have a remainder function ambiguity problem ok = true; @@ -15031,17 +15072,17 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp if (casted_op2 == ira->codegen->invalid_instruction) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; - if (float_cmp_zero(&casted_op2->value) == CmpEQ) { + if (float_cmp_zero(casted_op2->value) == CmpEQ) { // the division by zero error will be caught later, but we don't // have a remainder function ambiguity problem ok = true; } else { - ConstExprValue rem_result = {}; - ConstExprValue mod_result = {}; + ZigValue rem_result = {}; + ZigValue mod_result = {}; float_rem(&rem_result, op1_val, op2_val); float_mod(&mod_result, op1_val, op2_val); ok = float_cmp(&rem_result, &mod_result) == CmpEQ; @@ -15051,8 +15092,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp if (!ok) { ir_add_error(ira, &instruction->base, buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", - buf_ptr(&op1->value.type->name), - buf_ptr(&op2->value.type->name))); + buf_ptr(&op1->value->type->name), + buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } } @@ -15076,8 +15117,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp AstNode *source_node = instruction->base.source_node; ir_add_error_node(ira, source_node, buf_sprintf("invalid operands to binary expression: '%s' and '%s'", - buf_ptr(&op1->value.type->name), - buf_ptr(&op2->value.type->name))); + buf_ptr(&op1->value->type->name), + buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } @@ -15100,10 +15141,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { - ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; @@ -15112,31 +15153,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on); - result->value.type = resolved_type; + result->value->type = resolved_type; return result; } static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { IrInstruction *op1 = instruction->op1->child; - ZigType *op1_type = op1->value.type; + ZigType *op1_type = op1->value->type; if (type_is_invalid(op1_type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = instruction->op2->child; - ZigType *op2_type = op2->value.type; + ZigType *op2_type = op2->value->type; if (type_is_invalid(op2_type)) return ira->codegen->invalid_instruction; - ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); if (!op1_val) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); if (!op2_val) return ira->codegen->invalid_instruction; - ConstExprValue *sentinel1 = nullptr; - ConstExprValue *op1_array_val; + ZigValue *sentinel1 = nullptr; + ZigValue *op1_array_val; size_t op1_array_index; size_t op1_array_end; ZigType *child_type; @@ -15159,11 +15200,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i } else if (is_slice(op1_type)) { ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry; child_type = ptr_type->data.pointer.child_type; - ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val; op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index; - ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = op1_val->data.x_struct.fields[slice_len_index]; op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint); sentinel1 = ptr_type->data.pointer.sentinel; } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle && @@ -15178,13 +15219,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i op1_array_end = array_type->data.array.len; sentinel1 = array_type->data.array.sentinel; } else { - ir_add_error(ira, op1, - buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name))); + ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); return ira->codegen->invalid_instruction; } - ConstExprValue *sentinel2 = nullptr; - ConstExprValue *op2_array_val; + ZigValue *sentinel2 = nullptr; + ZigValue *op2_array_val; size_t op2_array_index; size_t op2_array_end; bool op2_type_valid; @@ -15207,11 +15247,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i } else if (is_slice(op2_type)) { ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry; op2_type_valid = ptr_type->data.pointer.child_type == child_type; - ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val; op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index; - ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = op2_val->data.x_struct.fields[slice_len_index]; op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint); sentinel2 = ptr_type->data.pointer.sentinel; @@ -15229,17 +15269,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i sentinel2 = array_type->data.array.sentinel; } else { ir_add_error(ira, op2, - buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name))); + buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } if (!op2_type_valid) { ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", buf_ptr(&child_type->name), - buf_ptr(&op2->value.type->name))); + buf_ptr(&op2->value->type->name))); return ira->codegen->invalid_instruction; } - ConstExprValue *sentinel; + ZigValue *sentinel; if (sentinel1 != nullptr && sentinel2 != nullptr) { // When there is a sentinel mismatch, no sentinel on the result. The type system // will catch this if it is a problem. @@ -15254,13 +15294,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i // The type of result is populated in the following if blocks IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; - ConstExprValue *out_array_val; + ZigValue *out_array_val; size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { - result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel); - + result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel); out_array_val = out_val; } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) { out_array_val = create_const_vals(1); @@ -15274,7 +15313,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel); - result->value.type = get_slice_type(ira->codegen, ptr_type); + result->value->type = get_slice_type(ira->codegen, ptr_type); out_array_val = create_const_vals(1); out_array_val->special = ConstValSpecialStatic; out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); @@ -15291,9 +15330,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic; bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len); } else { - result->value.type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, + result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel); - out_array_val = create_const_vals(1); out_array_val->special = ConstValSpecialStatic; out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); @@ -15317,21 +15355,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i size_t next_index = 0; for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) { - ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; + ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false); elem_dest_val->parent.id = ConstParentIdArray; elem_dest_val->parent.data.p_array.array_val = out_array_val; elem_dest_val->parent.data.p_array.elem_index = next_index; } for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) { - ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; + ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false); elem_dest_val->parent.id = ConstParentIdArray; elem_dest_val->parent.data.p_array.array_val = out_array_val; elem_dest_val->parent.data.p_array.elem_index = next_index; } if (next_index < full_len) { - ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; + ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; copy_const_val(elem_dest_val, sentinel, false); elem_dest_val->parent.id = ConstParentIdArray; elem_dest_val->parent.data.p_array.array_val = out_array_val; @@ -15345,34 +15383,34 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { IrInstruction *op1 = instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; bool want_ptr_to_array = false; ZigType *array_type; - ConstExprValue *array_val; - if (op1->value.type->id == ZigTypeIdArray) { - array_type = op1->value.type; + ZigValue *array_val; + if (op1->value->type->id == ZigTypeIdArray) { + array_type = op1->value->type; array_val = ir_resolve_const(ira, op1, UndefOk); if (array_val == nullptr) return ira->codegen->invalid_instruction; - } else if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenSingle && - op1->value.type->data.pointer.child_type->id == ZigTypeIdArray) + } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle && + op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) { - array_type = op1->value.type->data.pointer.child_type; + array_type = op1->value->type->data.pointer.child_type; IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr); - if (type_is_invalid(array_inst->value.type)) + if (type_is_invalid(array_inst->value->type)) return ira->codegen->invalid_instruction; array_val = ir_resolve_const(ira, array_inst, UndefOk); if (array_val == nullptr) return ira->codegen->invalid_instruction; want_ptr_to_array = true; } else { - ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); + ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); return ira->codegen->invalid_instruction; } @@ -15397,7 +15435,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * array_result = ir_const_undef(ira, &instruction->base, result_array_type); } else { array_result = ir_const(ira, &instruction->base, result_array_type); - ConstExprValue *out_val = &array_result->value; + ZigValue *out_val = array_result->value; switch (type_has_one_possible_value(ira->codegen, result_array_type)) { case OnePossibleValueInvalid: @@ -15416,7 +15454,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * uint64_t i = 0; for (uint64_t x = 0; x < mult_amt; x += 1) { for (uint64_t y = 0; y < old_array_len; y += 1) { - ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false); elem_dest_val->parent.id = ConstParentIdArray; elem_dest_val->parent.data.p_array.array_val = out_val; @@ -15427,7 +15465,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * assert(i == new_array_len); if (array_type->data.array.sentinel != nullptr) { - ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; copy_const_val(elem_dest_val, array_type->data.array.sentinel, false); elem_dest_val->parent.id = ConstParentIdArray; elem_dest_val->parent.data.p_array.array_val = out_val; @@ -15554,25 +15592,25 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruction *var_ptr = decl_var_instruction->ptr->child; // if this is null, a compiler error happened and did not initialize the variable. // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. - if (var_ptr == nullptr || type_is_invalid(var_ptr->value.type)) { + if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) { ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base); var->var_type = ira->codegen->builtin_types.entry_invalid; return ira->codegen->invalid_instruction; } // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. - ir_assert(var_ptr->value.type->id == ZigTypeIdPointer, &decl_var_instruction->base); + ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base); - ZigType *result_type = var_ptr->value.type->data.pointer.child_type; + ZigType *result_type = var_ptr->value->type->data.pointer.child_type; if (type_is_invalid(result_type)) { result_type = ira->codegen->builtin_types.entry_invalid; } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) { zig_unreachable(); } - ConstExprValue *init_val = nullptr; - if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { - init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node); + ZigValue *init_val = nullptr; + if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { + init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node); if (is_comptime_var) { if (var->gen_is_const) { var->const_value = init_val; @@ -15631,7 +15669,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, new_var->owner_exec = var->owner_exec; new_var->align_bytes = var->align_bytes; if (var->mem_slot_index != SIZE_MAX) { - ConstExprValue *vals = create_const_vals(1); + ZigValue *vals = create_const_vals(1); new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; ira->exec_context.mem_slot_list.append(vals); } @@ -15665,29 +15703,29 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, if (init_val != nullptr && value_is_comptime(init_val)) { // Resolve ConstPtrMutInfer if (var->gen_is_const) { - var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeConst; + var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeConst; } else if (is_comptime_var) { - var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; + var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; } else { // we need a runtime ptr but we have a comptime val. // since it's a comptime val there are no instructions for it. // we memcpy the init value here IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); - if (type_is_invalid(deref->value.type)) { + if (type_is_invalid(deref->value->type)) { var->var_type = ira->codegen->builtin_types.entry_invalid; return ira->codegen->invalid_instruction; } // If this assertion trips, something is wrong with the IR instructions, because // we expected the above deref to return a constant value, but it created a runtime // instruction. - assert(deref->value.special != ConstValSpecialRuntime); - var_ptr->value.special = ConstValSpecialRuntime; + assert(deref->value->special != ConstValSpecialRuntime); + var_ptr->value->special = ConstValSpecialRuntime; ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); } if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); - ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); + ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const); if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { @@ -15718,7 +15756,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio } IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) { + if (type_is_invalid(target->value->type)) { return ira->codegen->invalid_instruction; } @@ -15748,13 +15786,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio } bool want_var_export = false; - switch (target->value.type->id) { + switch (target->value->type->id) { case ZigTypeIdInvalid: case ZigTypeIdUnreachable: zig_unreachable(); case ZigTypeIdFn: { - assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); - ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; + assert(target->value->data.x_ptr.special == ConstPtrSpecialFunction); + ZigFn *fn_entry = target->value->data.x_ptr.data.fn.fn_entry; tld_fn->fn_entry = fn_entry; CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; switch (cc) { @@ -15778,51 +15816,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio } } break; case ZigTypeIdStruct: - if (is_slice(target->value.type)) { + if (is_slice(target->value->type)) { ir_add_error(ira, target, - buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); - } else if (target->value.type->data.structure.layout != ContainerLayoutExtern) { + buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); + } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported struct value must be declared extern")); - add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); + add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); } else { want_var_export = true; } break; case ZigTypeIdUnion: - if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { + if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported union value must be declared extern")); - add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); + add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); } else { want_var_export = true; } break; case ZigTypeIdEnum: - if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { + if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported enum value must be declared extern")); - add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); + add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); } else { want_var_export = true; } break; case ZigTypeIdArray: { bool ok_type; - if ((err = type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type, &ok_type))) + if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) return ira->codegen->invalid_instruction; if (!ok_type) { ir_add_error(ira, target, buf_sprintf("array element type '%s' not extern-compatible", - buf_ptr(&target->value.type->data.array.child_type->name))); + buf_ptr(&target->value->type->data.array.child_type->name))); } else { want_var_export = true; } break; } case ZigTypeIdMetaType: { - ZigType *type_value = target->value.data.x_type; + ZigType *type_value = target->value->data.x_type; switch (type_value->id) { case ZigTypeIdInvalid: zig_unreachable(); @@ -15898,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdVector: - zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); + zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name)); case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -15906,7 +15944,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: ir_add_error(ira, target, - buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); + buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); break; } @@ -15936,7 +15974,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { IrInstruction *result = ir_const(ira, &instruction->base, optional_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; assert(get_codegen_ptr_type(optional_type) != nullptr); out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; out_val->data.x_ptr.data.hard_coded_addr.addr = 0; @@ -15944,13 +15982,13 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, } IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, instruction->base.source_node, instruction->optional); - new_instruction->value.type = optional_type; + new_instruction->value->type = optional_type; return new_instruction; } else { assert(ira->codegen->have_err_ret_tracing); IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, instruction->base.source_node, instruction->optional); - new_instruction->value.type = ptr_to_stack_trace_type; + new_instruction->value->type = ptr_to_stack_trace_type; return new_instruction; } } @@ -15959,11 +15997,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstructionErrorUnion *instruction) { IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1); lazy_err_union_type->ira = ira; - result->value.data.x_lazy = &lazy_err_union_type->base; + result->value->data.x_lazy = &lazy_err_union_type->base; lazy_err_union_type->base.id = LazyValueIdErrUnionType; lazy_err_union_type->err_set_type = instruction->err_set->child; @@ -15982,14 +16020,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in { Error err; - ConstExprValue *pointee = create_const_vals(1); + ZigValue *pointee = create_const_vals(1); pointee->special = ConstValSpecialUndef; IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); - result->base.value.special = ConstValSpecialStatic; - result->base.value.data.x_ptr.special = ConstPtrSpecialRef; - result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; - result->base.value.data.x_ptr.data.ref.pointee = pointee; + result->base.value->special = ConstValSpecialStatic; + result->base.value->data.x_ptr.special = ConstPtrSpecialRef; + result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; + result->base.value->data.x_ptr.data.ref.pointee = pointee; bool var_type_has_bits; if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits))) @@ -16004,10 +16042,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in return ira->codegen->invalid_instruction; } } - assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid); + assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid); pointee->type = var_type; - result->base.value.type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, + result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, PtrLenSingle, align, 0, 0, false); ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); @@ -16031,7 +16069,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe case ResultLocIdCast: return nullptr; case ResultLocIdInstruction: - return result_loc->source_instruction->child->value.type; + return result_loc->source_instruction->child->value->type; case ResultLocIdReturn: return ira->explicit_return_type; case ResultLocIdPeer: @@ -16063,13 +16101,13 @@ static bool type_can_bit_cast(ZigType *t) { } static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { - ConstExprValue *undef_child = create_const_vals(1); - undef_child->type = ptr->value.type->data.pointer.child_type; + ZigValue *undef_child = create_const_vals(1); + undef_child->type = ptr->value->type->data.pointer.child_type; undef_child->special = ConstValSpecialUndef; - ptr->value.special = ConstValSpecialStatic; - ptr->value.data.x_ptr.mut = ConstPtrMutInfer; - ptr->value.data.x_ptr.special = ConstPtrSpecialRef; - ptr->value.data.x_ptr.data.ref.pointee = undef_child; + ptr->value->special = ConstValSpecialStatic; + ptr->value->data.x_ptr.mut = ConstPtrMutInfer; + ptr->value->data.x_ptr.special = ConstPtrSpecialRef; + ptr->value->data.x_ptr.data.ref.pointee = undef_child; } static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) { @@ -16105,7 +16143,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) { IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); - alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, + alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, PtrLenSingle, 0, 0, 0, false); set_up_result_loc_for_inferred_comptime(&alloca_gen->base); ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); @@ -16158,7 +16196,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) return ira->codegen->invalid_instruction; bool is_comptime = force_comptime || (value != nullptr && - value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); + value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); if (alloca_src->base.child == nullptr || is_comptime) { uint32_t align = 0; @@ -16167,8 +16205,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe } IrInstruction *alloca_gen; if (is_comptime && value != nullptr) { - if (align > value->value.global_refs->align) { - value->value.global_refs->align = align; + if (align > value->value->global_refs->align) { + value->value->global_refs->align = align; } alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); } else { @@ -16191,7 +16229,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe } case ResultLocIdReturn: { if (!non_null_comptime) { - bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; + bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; if (is_comptime) return nullptr; } @@ -16222,8 +16260,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe value_type, value, force_runtime, non_null_comptime, true); result_peer->suspend_pos.basic_block_index = SIZE_MAX; result_peer->suspend_pos.instruction_index = SIZE_MAX; - if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || - parent_result_loc->value.type->id == ZigTypeIdUnreachable) + if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || + parent_result_loc->value->type->id == ZigTypeIdUnreachable) { return parent_result_loc; } @@ -16270,19 +16308,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); - if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || - parent_result_loc->value.type->id == ZigTypeIdUnreachable) + if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || + parent_result_loc->value->type->id == ZigTypeIdUnreachable) { return parent_result_loc; } // because is_comptime is false, we mark this a runtime pointer - parent_result_loc->value.special = ConstValSpecialRuntime; + parent_result_loc->value->special = ConstValSpecialRuntime; result_loc->written = true; result_loc->resolved_loc = parent_result_loc; return result_loc->resolved_loc; } case ResultLocIdCast: { - if (value != nullptr && value->value.special != ConstValSpecialRuntime) + if (value != nullptr && value->value->special != ConstValSpecialRuntime) return nullptr; ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); @@ -16313,19 +16351,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe casted_value = nullptr; } - if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) { + if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) { return casted_value; } bool old_parent_result_loc_written = result_cast->parent->written; IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, dest_type, casted_value, force_runtime, non_null_comptime, true); - if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || - parent_result_loc->value.type->id == ZigTypeIdUnreachable) + if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || + parent_result_loc->value->type->id == ZigTypeIdUnreachable) { return parent_result_loc; } - ZigType *parent_ptr_type = parent_result_loc->value.type; + ZigType *parent_ptr_type = parent_result_loc->value->type; assert(parent_ptr_type->id == ZigTypeIdPointer); if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) @@ -16358,7 +16396,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe { // we also need to check that this cast is OK. ConstCastOnly const_cast_result = types_match_const_cast_only(ira, - parent_result_loc->value.type, ptr_type, + parent_result_loc->value->type, ptr_type, result_cast->base.source_instruction->source_node, false); if (const_cast_result.id == ConstCastResultIdInvalid) return ira->codegen->invalid_instruction; @@ -16413,18 +16451,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe bitcasted_value = nullptr; } - if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) { + if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { return bitcasted_value; } IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, dest_type, bitcasted_value, force_runtime, non_null_comptime, true); - if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || - parent_result_loc->value.type->id == ZigTypeIdUnreachable) + if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || + parent_result_loc->value->type->id == ZigTypeIdUnreachable) { return parent_result_loc; } - ZigType *parent_ptr_type = parent_result_loc->value.type; + ZigType *parent_ptr_type = parent_result_loc->value->type; assert(parent_ptr_type->id == ZigTypeIdPointer); if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) @@ -16454,24 +16492,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s { if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && instr_is_comptime(result_loc_pass1->source_instruction) && - result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer && - result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard) + result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer && + result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard) { result_loc_pass1 = no_result_loc(); } IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, value, force_runtime, non_null_comptime); - if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) + if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) return result_loc; if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && - result_loc_pass1->written && result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) + result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; } - ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr); - ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type; + ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); + ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && value_type->id != ZigTypeIdNull) { @@ -16544,18 +16582,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), implicit_elem_type, nullptr, false, true, true); if (result_loc != nullptr && - (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) + (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { return result_loc; } - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; return result_loc; } IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); - result->value.special = ConstValSpecialUndef; + result->value->special = ConstValSpecialUndef; IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); - ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; + ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; return ptr; } @@ -16605,9 +16643,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal { ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base); IrInstruction *ret_ptr_uncasted = call_instruction->args[call_instruction->arg_count]->child; - if (type_is_invalid(ret_ptr_uncasted->value.type)) + if (type_is_invalid(ret_ptr_uncasted->value->type)) return ira->codegen->invalid_instruction; - if (ret_ptr_uncasted->value.type->id == ZigTypeIdVoid) { + if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { // Result location will be inside the async frame. return nullptr; } @@ -16632,7 +16670,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc if (casted_new_stack != nullptr) { ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type; IrInstruction *ret_ptr = get_async_call_result_loc(ira, call_instruction, fn_ret_type); - if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value.type)) + if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) return ira->codegen->invalid_instruction; ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); @@ -16645,11 +16683,11 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, frame_type, nullptr, true, true, false); - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return ira->codegen->invalid_instruction; return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count, casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack, @@ -16670,13 +16708,13 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node return false; casted_arg = ir_implicit_cast(ira, arg, param_type); - if (type_is_invalid(casted_arg->value.type)) + if (type_is_invalid(casted_arg->value->type)) return false; } else { casted_arg = arg; } - ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk); + ZigValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk); if (!arg_val) return false; @@ -16710,7 +16748,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod return false; casted_arg = ir_implicit_cast(ira, arg, param_type); - if (type_is_invalid(casted_arg->value.type)) + if (type_is_invalid(casted_arg->value->type)) return false; } else { arg_part_of_generic_id = true; @@ -16719,9 +16757,9 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod } bool comptime_arg = param_decl_node->data.param_decl.is_comptime || - casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat; + casted_arg->value->type->id == ZigTypeIdComptimeInt || casted_arg->value->type->id == ZigTypeIdComptimeFloat; - ConstExprValue *arg_val; + ZigValue *arg_val; if (comptime_arg) { arg_part_of_generic_id = true; @@ -16729,7 +16767,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod if (!arg_val) return false; } else { - arg_val = create_const_runtime(casted_arg->value.type); + arg_val = create_const_runtime(casted_arg->value->type); } if (arg_part_of_generic_id) { copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true); @@ -16745,8 +16783,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod var->shadowable = !comptime_arg; *next_proto_i += 1; - } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || - casted_arg->value.type->id == ZigTypeIdComptimeFloat) + } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || + casted_arg->value->type->id == ZigTypeIdComptimeFloat) { ir_add_error(ira, casted_arg, buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); @@ -16754,10 +16792,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod } if (!comptime_arg) { - switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) { + switch (type_requires_comptime(ira->codegen, casted_arg->value->type)) { case ReqCompTimeYes: ir_add_error(ira, casted_arg, - buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name))); + buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value->type->name))); return false; case ReqCompTimeInvalid: return false; @@ -16767,7 +16805,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod casted_args[fn_type_id->param_count] = casted_arg; FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count]; - param_info->type = casted_arg->value.type; + param_info->type = casted_arg->value->type; param_info->is_noalias = param_decl_node->data.param_decl.is_noalias; impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node; fn_type_id->param_count += 1; @@ -16805,7 +16843,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, if (var->var_type == nullptr || type_is_invalid(var->var_type)) return ira->codegen->invalid_instruction; - ConstExprValue *mem_slot = nullptr; + ZigValue *mem_slot = nullptr; bool comptime_var_mem = ir_get_var_is_comptime(var); bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; @@ -16813,7 +16851,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, IrInstruction *result = ir_build_var_ptr(&ira->new_irb, instruction->scope, instruction->source_node, var); - result->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, + result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); if (linkage_makes_it_runtime) @@ -16846,10 +16884,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, assert(!comptime_var_mem); ptr_mut = ConstPtrMutRuntimeVar; } - result->value.special = ConstValSpecialStatic; - result->value.data.x_ptr.mut = ptr_mut; - result->value.data.x_ptr.special = ConstPtrSpecialRef; - result->value.data.x_ptr.data.ref.pointee = mem_slot; + result->value->special = ConstValSpecialStatic; + result->value->data.x_ptr.mut = ptr_mut; + result->value->data.x_ptr.special = ConstPtrSpecialRef; + result->value->data.x_ptr.data.ref.pointee = mem_slot; return result; } } @@ -16859,13 +16897,13 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, no_mem_slot: bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); - result->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; + result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; return result; } // This function is called when a comptime value becomes accessible at runtime. -static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *val) { +static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) { ir_assert(value_is_comptime(val), source_instr); if (val->special == ConstValSpecialUndef) return; @@ -16881,11 +16919,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) { - assert(ptr->value.type->id == ZigTypeIdPointer); + assert(ptr->value->type->id == ZigTypeIdPointer); - if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { - if (uncasted_value->value.type->id == ZigTypeIdErrorUnion || - uncasted_value->value.type->id == ZigTypeIdErrorSet) + if (ptr->value->data.x_ptr.special == ConstPtrSpecialDiscard) { + if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || + uncasted_value->value->type->id == ZigTypeIdErrorSet) { ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); return ira->codegen->invalid_instruction; @@ -16893,7 +16931,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source return ir_const_void(ira, source_instr); } - InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field; + InferredStructField *isf = ptr->value->type->data.pointer.inferred_struct_field; if (allow_write_through_const && isf != nullptr) { // Now it's time to add the field to the struct type. uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; @@ -16904,7 +16942,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; field->name = isf->field_name; - field->type_entry = uncasted_value->value.type; + field->type_entry = uncasted_value->value->type; field->type_val = create_const_type(ira->codegen, field->type_entry); field->src_index = old_field_count; field->decl_node = uncasted_value->source_node; @@ -16913,25 +16951,25 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source IrInstruction *casted_ptr; if (instr_is_comptime(ptr)) { casted_ptr = ir_const(ira, source_instr, struct_ptr_type); - copy_const_val(&casted_ptr->value, &ptr->value, false); - casted_ptr->value.type = struct_ptr_type; + copy_const_val(casted_ptr->value, ptr->value, false); + casted_ptr->value->type = struct_ptr_type; } else { casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, struct_ptr_type, ptr, CastOpNoop); - casted_ptr->value.type = struct_ptr_type; + casted_ptr->value->type = struct_ptr_type; } if (instr_is_comptime(casted_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { - ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, + ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); struct_val->special = ConstValSpecialStatic; struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, old_field_count, new_field_count); - ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count]; + ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; field_val->special = ConstValSpecialUndef; field_val->type = field->type_entry; field_val->parent.id = ConstParentIdStruct; @@ -16944,12 +16982,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source isf->inferred_struct_type, true); } - if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) { + if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); return ira->codegen->invalid_instruction; } - ZigType *child_type = ptr->value.type->data.pointer.child_type; + ZigType *child_type = ptr->value->type->data.pointer.child_type; IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type); if (value == ira->codegen->invalid_instruction) return ira->codegen->invalid_instruction; @@ -16963,16 +17001,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source break; } - if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { - if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) { + if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { + if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); return ira->codegen->invalid_instruction; } - if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar || - ptr->value.data.x_ptr.mut == ConstPtrMutInfer) + if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar || + ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { if (instr_is_comptime(value)) { - ConstExprValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node); + ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); if (dest_val == nullptr) return ira->codegen->invalid_instruction; if (dest_val->special != ConstValSpecialRuntime) { @@ -16982,9 +17020,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source // * "string literal used as comptime slice is memoized" // * "comptime modification of const struct field" - except modified to avoid // ConstPtrMutComptimeVar, thus defeating the logic below. - bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar; - copy_const_val(dest_val, &value->value, same_global_refs); - if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar && + bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar; + copy_const_val(dest_val, value->value, same_global_refs); + if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && !ira->new_irb.current_basic_block->must_be_comptime_source_instr) { ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; @@ -16992,12 +17030,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source return ir_const_void(ira, source_instr); } } - if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { - ptr->value.special = ConstValSpecialRuntime; + if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { + ptr->value->special = ConstValSpecialRuntime; } else { ir_add_error(ira, source_instr, buf_sprintf("cannot store runtime value in compile time variable")); - ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); + ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); dest_val->type = ira->codegen->builtin_types.entry_invalid; return ira->codegen->invalid_instruction; @@ -17009,7 +17047,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source case ReqCompTimeInvalid: return ira->codegen->invalid_instruction; case ReqCompTimeYes: - switch (type_has_one_possible_value(ira->codegen, ptr->value.type)) { + switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) { case OnePossibleValueInvalid: return ira->codegen->invalid_instruction; case OnePossibleValueNo: @@ -17025,7 +17063,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source } if (instr_is_comptime(value)) { - mark_comptime_value_escape(ira, source_instr, &value->value); + mark_comptime_value_escape(ira, source_instr, value->value); } // If this is a store to a pointer with a runtime-known vector index, @@ -17034,7 +17072,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source // explaining why it is impossible for this store to work. Which is that // the pointer address is of the vector; without the element index being known // we cannot properly perform the insertion. - if (ptr->value.type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { + if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { if (ptr->id == IrInstructionIdElemPtr) { IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, @@ -17042,7 +17080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source } ir_add_error(ira, ptr, buf_sprintf("unable to determine vector element index of type '%s'", - buf_ptr(&ptr->value.type->name))); + buf_ptr(&ptr->value->type->name))); return ira->codegen->invalid_instruction; } @@ -17058,12 +17096,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall return nullptr; IrInstruction *new_stack = call_instruction->new_stack->child; - if (type_is_invalid(new_stack->value.type)) + if (type_is_invalid(new_stack->value->type)) return ira->codegen->invalid_instruction; if (call_instruction->is_async_call_builtin && - fn_entry != nullptr && new_stack->value.type->id == ZigTypeIdPointer && - new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) + fn_entry != nullptr && new_stack->value->type->id == ZigTypeIdPointer && + new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) { ZigType *needed_frame_type = get_pointer_to_type(ira->codegen, get_fn_frame_type(ira->codegen, fn_entry), false); @@ -17097,7 +17135,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; for (size_t i = 0; i < call_instruction->arg_count; i += 1) { - ConstExprValue *arg_tuple_value = &call_instruction->args[i]->child->value; + ZigValue *arg_tuple_value = call_instruction->args[i]->child->value; if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { call_param_count -= 1; call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - @@ -17152,7 +17190,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c size_t next_proto_i = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); + assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { @@ -17163,11 +17201,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } IrInstruction *first_arg; - if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { + if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { first_arg = first_arg_ptr; } else { first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); - if (type_is_invalid(first_arg->value.type)) + if (type_is_invalid(first_arg->value->type)) return ira->codegen->invalid_instruction; } @@ -17184,7 +17222,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { IrInstruction *old_arg = call_instruction->args[call_i]->child; - if (type_is_invalid(old_arg->value.type)) + if (type_is_invalid(old_arg->value->type)) return ira->codegen->invalid_instruction; if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) @@ -17207,7 +17245,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } bool cacheable = fn_eval_cacheable(exec_scope, return_type); - ConstExprValue *result = nullptr; + ZigValue *result = nullptr; if (cacheable) { auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope); if (entry) @@ -17250,8 +17288,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type); - copy_const_val(&new_instruction->value, result, true); - new_instruction->value.type = return_type; + copy_const_val(new_instruction->value, result, true); + new_instruction->value->type = return_type; return ir_finish_anal(ira, new_instruction); } @@ -17266,11 +17304,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c size_t new_fn_arg_count = first_arg_1_or_0; for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { IrInstruction *arg = call_instruction->args[call_i]->child; - if (type_is_invalid(arg->value.type)) + if (type_is_invalid(arg->value->type)) return ira->codegen->invalid_instruction; - if (arg->value.type->id == ZigTypeIdArgTuple) { - new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; + if (arg->value->type->id == ZigTypeIdArgTuple) { + new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index; } else { new_fn_arg_count += 1; } @@ -17299,7 +17337,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c size_t next_proto_i = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); + assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { @@ -17310,11 +17348,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } IrInstruction *first_arg; - if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { + if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { first_arg = first_arg_ptr; } else { first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); - if (type_is_invalid(first_arg->value.type)) + if (type_is_invalid(first_arg->value->type)) return ira->codegen->invalid_instruction; } @@ -17332,12 +17370,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c assert(parent_fn_entry); for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { IrInstruction *arg = call_instruction->args[call_i]->child; - if (type_is_invalid(arg->value.type)) + if (type_is_invalid(arg->value->type)) return ira->codegen->invalid_instruction; - if (arg->value.type->id == ZigTypeIdArgTuple) { - for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; - arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) + if (arg->value->type->id == ZigTypeIdArgTuple) { + for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index; + arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) { AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); assert(param_decl_node->type == NodeTypeParamDecl); @@ -17354,11 +17392,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c return ira->codegen->invalid_instruction; } IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); - if (type_is_invalid(arg_var_ptr_inst->value.type)) + if (type_is_invalid(arg_var_ptr_inst->value->type)) return ira->codegen->invalid_instruction; IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr); - if (type_is_invalid(arg_tuple_arg->value.type)) + if (type_is_invalid(arg_tuple_arg->value->type)) return ira->codegen->invalid_instruction; if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope, @@ -17392,7 +17430,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c first_var_arg = inst_fn_type_id.param_count; } - ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, + ZigValue *var_args_val = create_const_arg_tuple(ira->codegen, first_var_arg, inst_fn_type_id.param_count); ZigVar *var = add_variable(ira->codegen, param_decl_node, impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type); @@ -17400,14 +17438,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } if (fn_proto_node->data.fn_proto.align_expr != nullptr) { - ConstExprValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, + ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen), ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, nullptr, UndefBad); IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); - copy_const_val(&const_instruction->base.value, align_result, true); + copy_const_val(const_instruction->base.value, align_result, true); uint32_t align_bytes = 0; ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); @@ -17468,7 +17506,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, impl_fn); - if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) + if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) return ira->codegen->invalid_instruction; size_t impl_param_count = impl_fn_type_id->param_count; @@ -17483,17 +17521,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, impl_fn_type_id->return_type, nullptr, true, true, false); if (result_loc != nullptr) { - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } - if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { + if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { ir_reset_result(call_instruction->result_loc); result_loc = nullptr; } } } else if (call_instruction->is_async_call_builtin) { result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type); - if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) + if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) return ira->codegen->invalid_instruction; } else { result_loc = nullptr; @@ -17530,7 +17568,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); size_t next_arg_index = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); + assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); ZigType *param_type = fn_type_id->param_info[next_arg_index].type; if (type_is_invalid(param_type)) @@ -17538,17 +17576,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c IrInstruction *first_arg; if (param_type->id == ZigTypeIdPointer && - handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) + handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { first_arg = first_arg_ptr; } else { first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); - if (type_is_invalid(first_arg->value.type)) + if (type_is_invalid(first_arg->value->type)) return ira->codegen->invalid_instruction; } IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); - if (type_is_invalid(casted_arg->value.type)) + if (type_is_invalid(casted_arg->value->type)) return ira->codegen->invalid_instruction; casted_args[next_arg_index] = casted_arg; @@ -17556,12 +17594,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { IrInstruction *old_arg = call_instruction->args[call_i]->child; - if (type_is_invalid(old_arg->value.type)) + if (type_is_invalid(old_arg->value->type)) return ira->codegen->invalid_instruction; - if (old_arg->value.type->id == ZigTypeIdArgTuple) { - for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index; - arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) + if (old_arg->value->type->id == ZigTypeIdArgTuple) { + for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index; + arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) { ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); if (arg_var == nullptr) { @@ -17570,11 +17608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c return ira->codegen->invalid_instruction; } IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var); - if (type_is_invalid(arg_var_ptr_inst->value.type)) + if (type_is_invalid(arg_var_ptr_inst->value->type)) return ira->codegen->invalid_instruction; IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr); - if (type_is_invalid(arg_tuple_arg->value.type)) + if (type_is_invalid(arg_tuple_arg->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_arg; @@ -17583,7 +17621,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c if (type_is_invalid(param_type)) return ira->codegen->invalid_instruction; casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type); - if (type_is_invalid(casted_arg->value.type)) + if (type_is_invalid(casted_arg->value->type)) return ira->codegen->invalid_instruction; } else { casted_arg = arg_tuple_arg; @@ -17599,7 +17637,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c if (type_is_invalid(param_type)) return ira->codegen->invalid_instruction; casted_arg = ir_implicit_cast(ira, old_arg, param_type); - if (type_is_invalid(casted_arg->value.type)) + if (type_is_invalid(casted_arg->value->type)) return ira->codegen->invalid_instruction; } else { casted_arg = old_arg; @@ -17623,7 +17661,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c } IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, fn_entry); - if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) + if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) return ira->codegen->invalid_instruction; if (call_instruction->modifier == CallModifierAsync) { @@ -17645,17 +17683,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, return_type, nullptr, true, true, false); if (result_loc != nullptr) { - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } - if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { + if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { ir_reset_result(call_instruction->result_loc); result_loc = nullptr; } } } else if (call_instruction->is_async_call_builtin) { result_loc = get_async_call_result_loc(ira, call_instruction, return_type); - if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) + if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) return ira->codegen->invalid_instruction; } else { result_loc = nullptr; @@ -17672,14 +17710,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) { IrInstruction *fn_ref = call_instruction->fn_ref->child; - if (type_is_invalid(fn_ref->value.type)) + if (type_is_invalid(fn_ref->value->type)) return ira->codegen->invalid_instruction; bool is_comptime = call_instruction->is_comptime || ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); if (is_comptime || instr_is_comptime(fn_ref)) { - if (fn_ref->value.type->id == ZigTypeIdMetaType) { + if (fn_ref->value->type->id == ZigTypeIdMetaType) { ZigType *ty = ir_resolve_type(ira, fn_ref); if (ty == nullptr) return ira->codegen->invalid_instruction; @@ -17688,30 +17726,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC add_error_note(ira->codegen, msg, call_instruction->base.source_node, buf_sprintf("use @as builtin for type coercion")); return ira->codegen->invalid_instruction; - } else if (fn_ref->value.type->id == ZigTypeIdFn) { + } else if (fn_ref->value->type->id == ZigTypeIdFn) { ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); - ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; + ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type, fn_ref, nullptr, is_comptime, call_instruction->fn_inline); - } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { - assert(fn_ref->value.special == ConstValSpecialStatic); - ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; - IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; + } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { + assert(fn_ref->value->special == ConstValSpecialStatic); + ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn; + IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); } else { ir_add_error_node(ira, fn_ref->source_node, - buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); + buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); return ira->codegen->invalid_instruction; } } - if (fn_ref->value.type->id == ZigTypeIdFn) { - return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, + if (fn_ref->value->type->id == ZigTypeIdFn) { + return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value->type, fn_ref, nullptr, false, call_instruction->fn_inline); } else { ir_add_error_node(ira, fn_ref->source_node, - buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); + buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); return ira->codegen->invalid_instruction; } } @@ -17719,12 +17757,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC // out_val->type must be the type to read the pointer as // if the type is different than the actual type then it does a comptime byte reinterpretation static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, - ConstExprValue *out_val, ConstExprValue *ptr_val) + ZigValue *out_val, ZigValue *ptr_val) { Error err; assert(out_val->type != nullptr); - ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val); + ZigValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val); src_assert(pointee->type != nullptr, source_node); if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown))) @@ -17765,7 +17803,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source return ErrorSemanticAnalyzeFail; } case ConstPtrSpecialBaseArray: { - ConstExprValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val; assert(array_val->type->id == ZigTypeIdArray); if (array_val->data.x_array.special != ConstArraySpecialNone) zig_panic("TODO"); @@ -17782,7 +17820,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source Buf buf = BUF_INIT; buf_resize(&buf, elem_count * elem_size); for (size_t i = 0; i < elem_count; i += 1) { - ConstExprValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i]; + ZigValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i]; buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val); } if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val))) @@ -17803,11 +17841,11 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) { IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1); lazy_opt_type->ira = ira; - result->value.data.x_lazy = &lazy_opt_type->base; + result->value->data.x_lazy = &lazy_opt_type->base; lazy_opt_type->base.id = LazyValueIdOptType; lazy_opt_type->payload_type = instruction->value->child; @@ -17818,7 +17856,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp } static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type, - ConstExprValue *operand_val, ConstExprValue *scalar_out_val, bool is_wrap_op) + ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op) { bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat); @@ -17854,7 +17892,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { IrInstruction *value = instruction->value->child; - ZigType *expr_type = value->value.type; + ZigType *expr_type = value->value->type; if (type_is_invalid(expr_type)) return ira->codegen->invalid_instruction; @@ -17872,20 +17910,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; if (instr_is_comptime(value)) { - ConstExprValue *operand_val = ir_resolve_const(ira, value, UndefBad); + ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad); if (!operand_val) return ira->codegen->invalid_instruction; IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type); - ConstExprValue *out_val = &result_instruction->value; + ZigValue *out_val = result_instruction->value; if (expr_type->id == ZigTypeIdVector) { expand_undef_array(ira->codegen, operand_val); out_val->special = ConstValSpecialUndef; expand_undef_array(ira->codegen, out_val); size_t len = expr_type->data.vector.len; for (size_t i = 0; i < len; i += 1) { - ConstExprValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i]; - ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i]; + ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; assert(scalar_operand_val->type == scalar_type); assert(scalar_out_val->type == scalar_type); ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type, @@ -17911,31 +17949,31 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, instruction->op_id, value); - result->value.type = expr_type; + result->value->type = expr_type; return result; } static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { IrInstruction *value = instruction->value->child; - ZigType *expr_type = value->value.type; + ZigType *expr_type = value->value->type; if (type_is_invalid(expr_type)) return ira->codegen->invalid_instruction; if (expr_type->id == ZigTypeIdInt) { if (instr_is_comptime(value)) { - ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); + ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad); if (target_const_val == nullptr) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, expr_type); - bigint_not(&result->value.data.x_bigint, &target_const_val->data.x_bigint, + bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint, expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); return result; } IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, IrUnOpBinNot, value); - result->value.type = expr_type; + result->value->type = expr_type; return result; } @@ -17956,9 +17994,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction return ir_analyze_negation(ira, instruction); case IrUnOpDereference: { IrInstruction *ptr = instruction->value->child; - if (type_is_invalid(ptr->value.type)) + if (type_is_invalid(ptr->value->type)) return ira->codegen->invalid_instruction; - ZigType *ptr_type = ptr->value.type; + ZigType *ptr_type = ptr->value->type; if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("index syntax required for unknown-length pointer type '%s'", @@ -17971,9 +18009,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction return ira->codegen->invalid_instruction; // If the result needs to be an lvalue, type check it - if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { + if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) { ir_add_error(ira, &instruction->base, - buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); + buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); return ira->codegen->invalid_instruction; } @@ -18016,13 +18054,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr IrInstruction *result = ir_build_br(&ira->new_irb, br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { IrInstruction *condition = cond_br_instruction->condition->child; - if (type_is_invalid(condition->value.type)) + if (type_is_invalid(condition->value->type)) return ir_unreach_error(ira); bool is_comptime; @@ -18031,7 +18069,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi ZigType *bool_type = ira->codegen->builtin_types.entry_bool; IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); - if (type_is_invalid(casted_condition->value.type)) + if (type_is_invalid(casted_condition->value->type)) return ir_unreach_error(ira); if (is_comptime || instr_is_comptime(casted_condition)) { @@ -18053,7 +18091,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi IrInstruction *result = ir_build_br(&ira->new_irb, cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } @@ -18072,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi IrInstruction *result = ir_build_cond_br(&ira->new_irb, cond_br_instruction->base.scope, cond_br_instruction->base.source_node, casted_condition, new_then_block, new_else_block, nullptr); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } @@ -18081,7 +18119,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, { IrInstruction *result = ir_build_unreachable(&ira->new_irb, unreachable_instruction->base.scope, unreachable_instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } @@ -18094,13 +18132,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh if (predecessor != ira->const_predecessor_bb) continue; IrInstruction *value = phi_instruction->incoming_values[i]->child; - assert(value->value.type); - if (type_is_invalid(value->value.type)) + assert(value->value->type); + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; - if (value->value.special != ConstValSpecialRuntime) { + if (value->value->special != ConstValSpecialRuntime) { IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); - copy_const_val(&result->value, &value->value, true); + copy_const_val(result->value, value->value, true); return result; } else { return value; @@ -18126,7 +18164,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh } else { instructions[i] = ir_const(ira, this_peer->base.source_instruction, this_peer->base.implicit_elem_type); - instructions[i]->value.special = ConstValSpecialRuntime; + instructions[i]->value->special = ConstValSpecialRuntime; } } else { instructions[i] = gen_instruction; @@ -18147,7 +18185,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, peer_parent->resolved_type, nullptr, false, false, true); if (parent_result_loc != nullptr && - (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) + (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) { return parent_result_loc; } @@ -18160,7 +18198,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh if (instrs_to_move.length != 0) { IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb; IrInstruction *branch_instruction = predecessor->instruction_list.pop(); - ir_assert(branch_instruction->value.type->id == ZigTypeIdUnreachable, &phi_instruction->base); + ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base); while (instrs_to_move.length != 0) { predecessor->instruction_list.append(instrs_to_move.pop()); } @@ -18197,10 +18235,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh IrInstruction *old_value = phi_instruction->incoming_values[i]; assert(old_value); IrInstruction *new_value = old_value->child; - if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) + if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) continue; - if (type_is_invalid(new_value->value.type)) + if (type_is_invalid(new_value->value->type)) return ira->codegen->invalid_instruction; @@ -18212,7 +18250,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh if (new_incoming_blocks.length == 0) { IrInstruction *result = ir_build_unreachable(&ira->new_irb, phi_instruction->base.scope, phi_instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } @@ -18233,7 +18271,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh if (type_is_invalid(resolved_type)) return ira->codegen->invalid_instruction; } else { - ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type; + ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); resolved_type = resolved_loc_ptr_type->data.pointer.child_type; } @@ -18281,14 +18319,14 @@ skip_resolve_peer_types: IrInstruction *branch_instruction = predecessor->instruction_list.pop(); ir_set_cursor_at_end(&ira->new_irb, predecessor); IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type); - if (type_is_invalid(casted_value->value.type)) { + if (type_is_invalid(casted_value->value->type)) { return ira->codegen->invalid_instruction; } new_incoming_values.items[i] = casted_value; predecessor->instruction_list.append(branch_instruction); - if (all_stack_ptrs && (casted_value->value.special != ConstValSpecialRuntime || - casted_value->value.data.rh_ptr != RuntimeHintPtrStack)) + if (all_stack_ptrs && (casted_value->value->special != ConstValSpecialRuntime || + casted_value->value->data.rh_ptr != RuntimeHintPtrStack)) { all_stack_ptrs = false; } @@ -18298,11 +18336,11 @@ skip_resolve_peer_types: IrInstruction *result = ir_build_phi(&ira->new_irb, phi_instruction->base.scope, phi_instruction->base.source_node, new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr); - result->value.type = resolved_type; + result->value->type = resolved_type; if (all_stack_ptrs) { - assert(result->value.special == ConstValSpecialRuntime); - result->value.data.rh_ptr = RuntimeHintPtrStack; + assert(result->value->special == ConstValSpecialRuntime); + result->value->data.rh_ptr = RuntimeHintPtrStack; } return result; @@ -18358,13 +18396,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { Error err; IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; - if (type_is_invalid(array_ptr->value.type)) + if (type_is_invalid(array_ptr->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *orig_array_ptr_val = &array_ptr->value; + ZigValue *orig_array_ptr_val = array_ptr->value; IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; - if (type_is_invalid(elem_index->value.type)) + if (type_is_invalid(elem_index->value->type)) return ira->codegen->invalid_instruction; ZigType *ptr_type = orig_array_ptr_val->type; @@ -18428,10 +18466,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry, elem_ptr_instruction->ptr_len); } else if (array_type->id == ZigTypeIdArgTuple) { - ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; - ConstExprValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node); + ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node); if (args_val == nullptr) return ira->codegen->invalid_instruction; size_t start = args_val->data.x_arg_tuple.start_index; @@ -18471,7 +18509,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base); Buf *field_name = buf_alloc(); - bigint_append_buf(field_name, &casted_elem_index->value.data.x_bigint, 10); + bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10); return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base, array_ptr, array_type); } else { @@ -18487,13 +18525,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct bool safety_check_on = elem_ptr_instruction->safety_check_on; if (instr_is_comptime(casted_elem_index)) { - uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint); + uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint); if (array_type->id == ZigTypeIdArray) { uint64_t array_len = array_type->data.array.len; if (index == array_len && array_type->data.array.sentinel != nullptr) { ZigType *elem_type = array_type->data.array.child_type; IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); - copy_const_val(&sentinel_elem->value, array_type->data.array.sentinel, false); + copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false); return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); } if (index >= array_len) { @@ -18544,7 +18582,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) { - ConstExprValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, + ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, elem_ptr_instruction->base.source_node); if (array_ptr_val == nullptr) return ira->codegen->invalid_instruction; @@ -18557,7 +18595,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len); array_ptr_val->special = ConstValSpecialStatic; for (size_t i = 0; i < array_type->data.array.len; i += 1) { - ConstExprValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i]; elem_val->special = ConstValSpecialUndef; elem_val->type = array_type->data.array.child_type; elem_val->parent.id = ConstParentIdArray; @@ -18565,8 +18603,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct elem_val->parent.data.p_array.elem_index = i; } } else if (is_slice(array_type)) { - ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); - ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type; + ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); + ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; if (type_is_invalid(actual_array_type)) return ira->codegen->invalid_instruction; @@ -18576,14 +18614,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; } - ConstExprValue *array_init_val = create_const_vals(1); + ZigValue *array_init_val = create_const_vals(1); array_init_val->special = ConstValSpecialStatic; array_init_val->type = actual_array_type; array_init_val->data.x_array.special = ConstArraySpecialNone; array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len); array_init_val->special = ConstValSpecialStatic; for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) { - ConstExprValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i]; + ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i]; elem_val->special = ConstValSpecialUndef; elem_val->type = actual_array_type->data.array.child_type; elem_val->parent.id = ConstParentIdArray; @@ -18608,7 +18646,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct { if (array_type->id == ZigTypeIdPointer) { IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; size_t new_index; size_t mem_size; @@ -18619,7 +18657,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct zig_unreachable(); case ConstPtrSpecialRef: if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) { - ConstExprValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee; + ZigValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee; new_index = index; ZigType *array_type = array_val->type; mem_size = array_type->data.array.len; @@ -18682,18 +18720,18 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct } return result; } else if (is_slice(array_type)) { - ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base); if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len, nullptr); - result->value.type = return_type; + result->value->type = return_type; return result; } - ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; + ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); uint64_t full_slice_len = slice_len + @@ -18752,12 +18790,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len, nullptr); - result->value.type = return_type; - result->value.special = ConstValSpecialStatic; + result->value->type = return_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, &elem_ptr_instruction->base, return_type); } - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; @@ -18814,7 +18852,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, elem_ptr_instruction->ptr_len, nullptr); - result->value.type = return_type; + result->value->type = return_type; return result; } @@ -18892,8 +18930,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction case OnePossibleValueNo: break; } - bool is_const = struct_ptr->value.type->data.pointer.is_const; - bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile; + bool is_const = struct_ptr->value->type->data.pointer.is_const; + bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile; ZigType *ptr_type; if (struct_type->data.structure.is_inferred) { ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, @@ -18904,9 +18942,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown; if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status))) return ira->codegen->invalid_instruction; - assert(struct_ptr->value.type->id == ZigTypeIdPointer); - uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host; - uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes; + assert(struct_ptr->value->type->id == ZigTypeIdPointer); + uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host; + uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes; uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ? get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes; ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, @@ -18915,12 +18953,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction (uint32_t)host_int_bytes_for_result_type, false); } if (instr_is_comptime(struct_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { - ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); + ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); if (struct_val == nullptr) return ira->codegen->invalid_instruction; if (type_is_invalid(struct_val->type)) @@ -18929,7 +18967,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count); struct_val->special = ConstValSpecialStatic; for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { - ConstExprValue *field_val = struct_val->data.x_struct.fields[i]; + ZigValue *field_val = struct_val->data.x_struct.fields[i]; field_val->special = ConstValSpecialUndef; field_val->type = resolve_struct_field_type(ira->codegen, struct_type->data.structure.fields[i]); @@ -18942,12 +18980,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, struct_ptr, field); - result->value.type = ptr_type; - result->value.special = ConstValSpecialStatic; + result->value->type = ptr_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, source_instr, ptr_type); } - ConstExprValue *const_val = &result->value; + ZigValue *const_val = result->value; const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; const_val->data.x_ptr.data.base_struct.struct_val = struct_val; @@ -18957,7 +18995,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction } IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, struct_ptr, field); - result->value.type = ptr_type; + result->value->type = ptr_type; return result; } @@ -18970,7 +19008,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n // the field type will then be available, and the field will be added to the inferred // struct. - ZigType *container_ptr_type = container_ptr->value.type; + ZigType *container_ptr_type = container_ptr->value->type; ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr); InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField"); @@ -18984,14 +19022,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n if (instr_is_comptime(container_ptr)) { IrInstruction *result = ir_const(ira, source_instr, field_ptr_type); - copy_const_val(&result->value, &container_ptr->value, false); - result->value.type = field_ptr_type; + copy_const_val(result->value, container_ptr->value, false); + result->value->type = field_ptr_type; return result; } IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop); - result->value.type = field_ptr_type; + result->value->type = field_ptr_type; return result; } @@ -19011,7 +19049,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; - assert(container_ptr->value.type->id == ZigTypeIdPointer); + assert(container_ptr->value->type->id == ZigTypeIdPointer); if (bare_type->id == ZigTypeIdStruct) { TypeStructField *field = find_struct_type_field(bare_type, field_name); if (field != nullptr) { @@ -19028,8 +19066,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ } if (bare_type->id == ZigTypeIdUnion) { - bool is_const = container_ptr->value.type->data.pointer.is_const; - bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; + bool is_const = container_ptr->value->type->data.pointer.is_const; + bool is_volatile = container_ptr->value->type->data.pointer.is_volatile; TypeUnionField *field = find_union_type_field(bare_type, field_name); if (field == nullptr) { @@ -19044,20 +19082,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); if (instr_is_comptime(container_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { - ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); + ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); if (union_val == nullptr) return ira->codegen->invalid_instruction; if (type_is_invalid(union_val->type)) return ira->codegen->invalid_instruction; if (initializing) { - ConstExprValue *payload_val = create_const_vals(1); + ZigValue *payload_val = create_const_vals(1); payload_val->special = ConstValSpecialUndef; payload_val->type = field_type; payload_val->parent.id = ConstParentIdUnion; @@ -19079,20 +19117,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ } } - ConstExprValue *payload_val = union_val->data.x_union.payload; + ZigValue *payload_val = union_val->data.x_union.payload; IrInstruction *result; if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field, true, initializing); - result->value.type = ptr_type; - result->value.special = ConstValSpecialStatic; + result->value->type = ptr_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, source_instr, ptr_type); } - ConstExprValue *const_val = &result->value; + ZigValue *const_val = result->value; const_val->data.x_ptr.special = ConstPtrSpecialRef; - const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut; + const_val->data.x_ptr.mut = container_ptr->value->data.x_ptr.mut; const_val->data.x_ptr.data.ref.pointee = payload_val; return result; } @@ -19100,7 +19138,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field, true, initializing); - result->value.type = ptr_type; + result->value->type = ptr_type; return result; } @@ -19205,10 +19243,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { Error err; IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; - if (type_is_invalid(container_ptr->value.type)) + if (type_is_invalid(container_ptr->value->type)) return ira->codegen->invalid_instruction; - ZigType *container_type = container_ptr->value.type->data.pointer.child_type; + ZigType *container_type = container_ptr->value->type->data.pointer.child_type; Buf *field_name = field_ptr_instruction->field_name_buffer; if (!field_name) { @@ -19224,7 +19262,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc if (type_is_invalid(container_type)) { return ira->codegen->invalid_instruction; } else if (is_slice(container_type) || is_container_ref(container_type)) { - assert(container_ptr->value.type->id == ZigTypeIdPointer); + assert(container_ptr->value->type->id == ZigTypeIdPointer); if (container_type->id == ZigTypeIdPointer) { ZigType *bare_type = container_ref_type(container_type); IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr); @@ -19236,7 +19274,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc } } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { if (buf_eql_str(field_name, "len")) { - ConstExprValue *len_val = create_const_vals(1); + ZigValue *len_val = create_const_vals(1); if (container_type->id == ZigTypeIdPointer) { init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); } else { @@ -19255,17 +19293,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc return ira->codegen->invalid_instruction; } } else if (container_type->id == ZigTypeIdArgTuple) { - ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); + ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!container_ptr_val) return ira->codegen->invalid_instruction; - assert(container_ptr->value.type->id == ZigTypeIdPointer); - ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); + assert(container_ptr->value->type->id == ZigTypeIdPointer); + ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); if (child_val == nullptr) return ira->codegen->invalid_instruction; if (buf_eql_str(field_name, "len")) { - ConstExprValue *len_val = create_const_vals(1); + ZigValue *len_val = create_const_vals(1); size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; init_const_usize(ira->codegen, len_val, len); @@ -19281,12 +19319,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc return ira->codegen->invalid_instruction; } } else if (container_type->id == ZigTypeIdMetaType) { - ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); + ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!container_ptr_val) return ira->codegen->invalid_instruction; - assert(container_ptr->value.type->id == ZigTypeIdPointer); - ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); + assert(container_ptr->value->type->id == ZigTypeIdPointer); + ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); if (child_val == nullptr) return ira->codegen->invalid_instruction; if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, @@ -19382,7 +19420,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc } err_set_type = child_type; } - ConstExprValue *const_val = create_const_vals(1); + ZigValue *const_val = create_const_vals(1); const_val->special = ConstValSpecialStatic; const_val->type = err_set_type; const_val->data.x_err_set = err_entry; @@ -19567,11 +19605,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) { IrInstruction *ptr = instruction->ptr->child; - if (type_is_invalid(ptr->value.type)) + if (type_is_invalid(ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); @@ -19579,14 +19617,14 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { IrInstruction *ptr = instruction->ptr->child; - if (type_is_invalid(ptr->value.type)) + if (type_is_invalid(ptr->value->type)) return ira->codegen->invalid_instruction; return ir_get_deref(ira, &instruction->base, ptr, nullptr); } static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { IrInstruction *expr_value = typeof_instruction->value->child; - ZigType *type_entry = expr_value->value.type; + ZigType *type_entry = expr_value->value->type; if (type_is_invalid(type_entry)) return ira->codegen->invalid_instruction; return ir_const_type(ira, &typeof_instruction->base, type_entry); @@ -19749,11 +19787,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstructionSliceType *slice_type_instruction) { IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1); lazy_slice_type->ira = ira; - result->value.data.x_lazy = &lazy_slice_type->base; + result->value->data.x_lazy = &lazy_slice_type->base; lazy_slice_type->base.id = LazyValueIdSliceType; if (slice_type_instruction->align_value != nullptr) { @@ -19812,14 +19850,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { IrInstruction *const input_value = asm_instruction->input_list[i]->child; - if (type_is_invalid(input_value->value.type)) + if (type_is_invalid(input_value->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(input_value) && - (input_value->value.type->id == ZigTypeIdComptimeInt || - input_value->value.type->id == ZigTypeIdComptimeFloat)) { + (input_value->value->type->id == ZigTypeIdComptimeInt || + input_value->value->type->id == ZigTypeIdComptimeFloat)) { ir_add_error_node(ira, input_value->source_node, - buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name))); + buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); return ira->codegen->invalid_instruction; } @@ -19831,7 +19869,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len, input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, asm_instruction->has_side_effects); - result->value.type = return_type; + result->value->type = return_type; return result; } @@ -19850,13 +19888,13 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, if (type_is_invalid(child_type)) return ira->codegen->invalid_instruction; - ConstExprValue *sentinel_val; + ZigValue *sentinel_val; if (array_type_instruction->sentinel != nullptr) { IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child; - if (type_is_invalid(uncasted_sentinel->value.type)) + if (type_is_invalid(uncasted_sentinel->value->type)) return ira->codegen->invalid_instruction; IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type); - if (type_is_invalid(sentinel->value.type)) + if (type_is_invalid(sentinel->value->type)) return ira->codegen->invalid_instruction; sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); if (sentinel_val == nullptr) @@ -19909,11 +19947,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) { IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1); lazy_size_of->ira = ira; - result->value.data.x_lazy = &lazy_size_of->base; + result->value->data.x_lazy = &lazy_size_of->base; lazy_size_of->base.id = LazyValueIdSizeOf; lazy_size_of->target_type = instruction->type_value->child; @@ -19924,11 +19962,11 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi } static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) { - ZigType *type_entry = value->value.type; + ZigType *type_entry = value->value->type; if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { if (instr_is_comptime(value)) { - ConstExprValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); + ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); if (c_ptr_val == nullptr) return ira->codegen->invalid_instruction; if (c_ptr_val->special == ConstValSpecialUndef) @@ -19941,11 +19979,11 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, source_inst->scope, source_inst->source_node, value); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } else if (type_entry->id == ZigTypeIdOptional) { if (instr_is_comptime(value)) { - ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefOk); + ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk); if (maybe_val == nullptr) return ira->codegen->invalid_instruction; if (maybe_val->special == ConstValSpecialUndef) @@ -19956,7 +19994,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, source_inst->scope, source_inst->source_node, value); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } else if (type_entry->id == ZigTypeIdNull) { return ir_const_bool(ira, source_inst, false); @@ -19967,23 +20005,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_test_non_null(ira, &instruction->base, value); } static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { - ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr); - ZigType *elem_type = ptr->value.type->data.pointer.child_type; + ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); + ZigType *elem_type = ptr->value->type->data.pointer.child_type; if (elem_type != g->builtin_types.entry_var) return elem_type; - if (ir_resolve_lazy(g, ptr->source_node, &ptr->value)) + if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) return g->builtin_types.entry_invalid; - assert(value_is_comptime(&ptr->value)); - ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value); + assert(value_is_comptime(ptr->value)); + ZigValue *pointee = const_ptr_pointee_unchecked(g, ptr->value); return pointee->type; } @@ -19996,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) { if (instr_is_comptime(base_ptr)) { - ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad); + ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad); if (!val) return ira->codegen->invalid_instruction; if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { - ConstExprValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); + ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); if (c_ptr_val == nullptr) return ira->codegen->invalid_instruction; bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || @@ -20028,17 +20066,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr ZigType *child_type = type_entry->data.maybe.child_type; ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, - base_ptr->value.type->data.pointer.is_const, base_ptr->value.type->data.pointer.is_volatile, + base_ptr->value->type->data.pointer.is_const, base_ptr->value->type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false); bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry); if (instr_is_comptime(base_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { - ConstExprValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); + ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); if (optional_val == nullptr) return ira->codegen->invalid_instruction; @@ -20048,7 +20086,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr return ira->codegen->invalid_instruction; case OnePossibleValueNo: if (!same_comptime_repr) { - ConstExprValue *payload_val = create_const_vals(1); + ZigValue *payload_val = create_const_vals(1); payload_val->type = child_type; payload_val->special = ConstValSpecialUndef; payload_val->parent.id = ConstParentIdOptionalPayload; @@ -20059,7 +20097,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr } break; case OnePossibleValueYes: { - ConstExprValue *pointee = create_const_vals(1); + ZigValue *pointee = create_const_vals(1); pointee->special = ConstValSpecialStatic; pointee->type = child_type; pointee->parent.id = ConstParentIdOptionalPayload; @@ -20079,12 +20117,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr, false, initializing); - result->value.type = result_type; - result->value.special = ConstValSpecialStatic; + result->value->type = result_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, source_instr, result_type); } - ConstExprValue *result_val = &result->value; + ZigValue *result_val = result->value; result_val->data.x_ptr.special = ConstPtrSpecialRef; result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; switch (type_has_one_possible_value(ira->codegen, child_type)) { @@ -20109,7 +20147,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr, safety_check_on, initializing); - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -20117,7 +20155,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, IrInstructionOptionalUnwrapPtr *instruction) { IrInstruction *base_ptr = instruction->base_ptr->child; - if (type_is_invalid(base_ptr->value.type)) + if (type_is_invalid(base_ptr->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr, @@ -20130,26 +20168,26 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt return ira->codegen->invalid_instruction; IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); - if (type_is_invalid(op->value.type)) + if (type_is_invalid(op->value->type)) return ira->codegen->invalid_instruction; if (int_type->data.integral.bit_count == 0) return ir_const_unsigned(ira, &instruction->base, 0); if (instr_is_comptime(op)) { - ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); + ZigValue *val = ir_resolve_const(ira, op, UndefOk); if (val == nullptr) return ira->codegen->invalid_instruction; if (val->special == ConstValSpecialUndef) return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); - size_t result_usize = bigint_ctz(&op->value.data.x_bigint, int_type->data.integral.bit_count); + size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count); return ir_const_unsigned(ira, &instruction->base, result_usize); } ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, op); - result->value.type = return_type; + result->value->type = return_type; return result; } @@ -20159,26 +20197,26 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl return ira->codegen->invalid_instruction; IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); - if (type_is_invalid(op->value.type)) + if (type_is_invalid(op->value->type)) return ira->codegen->invalid_instruction; if (int_type->data.integral.bit_count == 0) return ir_const_unsigned(ira, &instruction->base, 0); if (instr_is_comptime(op)) { - ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); + ZigValue *val = ir_resolve_const(ira, op, UndefOk); if (val == nullptr) return ira->codegen->invalid_instruction; if (val->special == ConstValSpecialUndef) return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); - size_t result_usize = bigint_clz(&op->value.data.x_bigint, int_type->data.integral.bit_count); + size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count); return ir_const_unsigned(ira, &instruction->base, result_usize); } ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, op); - result->value.type = return_type; + result->value->type = return_type; return result; } @@ -20188,14 +20226,14 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc return ira->codegen->invalid_instruction; IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); - if (type_is_invalid(op->value.type)) + if (type_is_invalid(op->value->type)) return ira->codegen->invalid_instruction; if (int_type->data.integral.bit_count == 0) return ir_const_unsigned(ira, &instruction->base, 0); if (instr_is_comptime(op)) { - ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); + ZigValue *val = ir_resolve_const(ira, op, UndefOk); if (val == nullptr) return ira->codegen->invalid_instruction; if (val->special == ConstValSpecialUndef) @@ -20212,50 +20250,50 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, op); - result->value.type = return_type; + result->value->type = return_type; return result; } static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; - if (value->value.type->id == ZigTypeIdEnum) { + if (value->value->type->id == ZigTypeIdEnum) { return value; } - if (value->value.type->id != ZigTypeIdUnion) { + if (value->value->type->id != ZigTypeIdUnion) { ir_add_error(ira, value, - buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); + buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); return ira->codegen->invalid_instruction; } - if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { + if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); - if (value->value.type->data.unionation.decl_node != nullptr) { - add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node, + if (value->value->type->data.unionation.decl_node != nullptr) { + add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, buf_sprintf("declared here")); } return ira->codegen->invalid_instruction; } - ZigType *tag_type = value->value.type->data.unionation.tag_type; + ZigType *tag_type = value->value->type->data.unionation.tag_type; assert(tag_type->id == ZigTypeIdEnum); if (instr_is_comptime(value)) { - ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); + ZigValue *val = ir_resolve_const(ira, value, UndefBad); if (!val) return ira->codegen->invalid_instruction; IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, source_instr->scope, source_instr->source_node); - const_instruction->base.value.type = tag_type; - const_instruction->base.value.special = ConstValSpecialStatic; - bigint_init_bigint(&const_instruction->base.value.data.x_enum_tag, &val->data.x_union.tag); + const_instruction->base.value->type = tag_type; + const_instruction->base.value->special = ConstValSpecialStatic; + bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag); return &const_instruction->base; } IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value); - result->value.type = tag_type; + result->value->type = tag_type; return result; } @@ -20263,11 +20301,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, IrInstructionSwitchBr *switch_br_instruction) { IrInstruction *target_value = switch_br_instruction->target_value->child; - if (type_is_invalid(target_value->value.type)) + if (type_is_invalid(target_value->value->type)) return ir_unreach_error(ira); if (switch_br_instruction->switch_prongs_void != nullptr) { - if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value.type)) { + if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value->type)) { return ir_unreach_error(ira); } } @@ -20280,7 +20318,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, return ira->codegen->invalid_instruction; if (is_comptime || instr_is_comptime(target_value)) { - ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad); + ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad); if (!target_val) return ir_unreach_error(ira); @@ -20288,20 +20326,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, for (size_t i = 0; i < case_count; i += 1) { IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; IrInstruction *case_value = old_case->value->child; - if (type_is_invalid(case_value->value.type)) + if (type_is_invalid(case_value->value->type)) return ir_unreach_error(ira); - if (case_value->value.type->id == ZigTypeIdEnum) { + if (case_value->value->type->id == ZigTypeIdEnum) { case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); - if (type_is_invalid(case_value->value.type)) + if (type_is_invalid(case_value->value->type)) return ir_unreach_error(ira); } - IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type); - if (type_is_invalid(casted_case_value->value.type)) + IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); + if (type_is_invalid(casted_case_value->value->type)) return ir_unreach_error(ira); - ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); + ZigValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); if (!case_val) return ir_unreach_error(ira); @@ -20318,7 +20356,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, IrInstruction *result = ir_build_br(&ira->new_irb, switch_br_instruction->base.scope, switch_br_instruction->base.source_node, new_dest_block, nullptr); - result->value.type = ira->codegen->builtin_types.entry_unreachable; + result->value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, result); } } @@ -20338,17 +20376,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, IrInstruction *old_value = old_case->value; IrInstruction *new_value = old_value->child; - if (type_is_invalid(new_value->value.type)) + if (type_is_invalid(new_value->value->type)) continue; - if (new_value->value.type->id == ZigTypeIdEnum) { + if (new_value->value->type->id == ZigTypeIdEnum) { new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); - if (type_is_invalid(new_value->value.type)) + if (type_is_invalid(new_value->value->type)) continue; } - IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type); - if (type_is_invalid(casted_new_value->value.type)) + IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); + if (type_is_invalid(casted_new_value->value->type)) continue; if (!ir_resolve_const(ira, casted_new_value, UndefBad)) @@ -20368,7 +20406,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb, switch_br_instruction->base.scope, switch_br_instruction->base.source_node, target_value, new_else_block, case_count, cases, nullptr, nullptr); - switch_br->base.value.type = ira->codegen->builtin_types.entry_unreachable; + switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable; return ir_finish_anal(ira, &switch_br->base); } @@ -20377,20 +20415,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, { Error err; IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; - if (type_is_invalid(target_value_ptr->value.type)) + if (type_is_invalid(target_value_ptr->value->type)) return ira->codegen->invalid_instruction; - if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { + if (target_value_ptr->value->type->id == ZigTypeIdMetaType) { assert(instr_is_comptime(target_value_ptr)); - ZigType *ptr_type = target_value_ptr->value.data.x_type; + ZigType *ptr_type = target_value_ptr->value->data.x_type; assert(ptr_type->id == ZigTypeIdPointer); return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); } - ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; - ConstExprValue *pointee_val = nullptr; - if (instr_is_comptime(target_value_ptr) && target_value_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { - pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node); + ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; + ZigValue *pointee_val = nullptr; + if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { + pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node); if (pointee_val == nullptr) return ira->codegen->invalid_instruction; @@ -20416,13 +20454,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, case ZigTypeIdErrorSet: { if (pointee_val) { IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); - copy_const_val(&result->value, pointee_val, true); - result->value.type = target_type; + copy_const_val(result->value, pointee_val, true); + result->value->type = target_type; return result; } IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); - result->value.type = target_type; + result->value->type = target_type; return result; } case ZigTypeIdUnion: { @@ -20441,22 +20479,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, assert(tag_type->id == ZigTypeIdEnum); if (pointee_val) { IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); - bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_union.tag); + bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); return result; } if (tag_type->data.enumeration.src_field_count == 1) { IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; - bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); + bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); return result; } IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); - union_value->value.type = target_type; + union_value->value->type = target_type; IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, union_value); - union_tag_inst->value.type = tag_type; + union_tag_inst->value->type = tag_type; return union_tag_inst; } case ZigTypeIdEnum: { @@ -20465,18 +20503,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, if (target_type->data.enumeration.src_field_count < 2) { TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); - bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); + bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); return result; } if (pointee_val) { IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); - bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_enum_tag); + bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); return result; } IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); - enum_value->value.type = target_type; + enum_value->value->type = target_type; return enum_value; } case ZigTypeIdErrorUnion: @@ -20501,12 +20539,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { IrInstruction *target_value_ptr = instruction->target_value_ptr->child; - if (type_is_invalid(target_value_ptr->value.type)) + if (type_is_invalid(target_value_ptr->value->type)) return ira->codegen->invalid_instruction; - ZigType *ref_type = target_value_ptr->value.type; + ZigType *ref_type = target_value_ptr->value->type; assert(ref_type->id == ZigTypeIdPointer); - ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; + ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; if (target_type->id == ZigTypeIdUnion) { ZigType *enum_type = target_type->data.unionation.tag_type; assert(enum_type != nullptr); @@ -20514,14 +20552,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru assert(instruction->prongs_len > 0); IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; - if (type_is_invalid(first_prong_value->value.type)) + if (type_is_invalid(first_prong_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); - if (type_is_invalid(first_casted_prong_value->value.type)) + if (type_is_invalid(first_casted_prong_value->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); + ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); if (first_prong_val == nullptr) return ira->codegen->invalid_instruction; @@ -20530,14 +20568,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru ErrorMsg *invalid_payload_msg = nullptr; for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) { IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child; - if (type_is_invalid(this_prong_inst->value.type)) + if (type_is_invalid(this_prong_inst->value->type)) return ira->codegen->invalid_instruction; IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); - if (type_is_invalid(this_casted_prong_value->value.type)) + if (type_is_invalid(this_casted_prong_value->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); + ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); if (this_prong == nullptr) return ira->codegen->invalid_instruction; @@ -20560,18 +20598,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru } if (instr_is_comptime(target_value_ptr)) { - ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); + ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); if (!target_value_ptr) return ira->codegen->invalid_instruction; - ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); + ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); if (pointee_val == nullptr) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, get_pointer_to_type(ira->codegen, first_field->type_entry, target_val_ptr->type->data.pointer.is_const)); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; out_val->data.x_ptr.special = ConstPtrSpecialRef; out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload; @@ -20580,8 +20618,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false); - result->value.type = get_pointer_to_type(ira->codegen, first_field->type_entry, - target_value_ptr->value.type->data.pointer.is_const); + result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry, + target_value_ptr->value->type->data.pointer.is_const); return result; } else if (target_type->id == ZigTypeIdErrorSet) { // construct an error set from the prong values @@ -20624,12 +20662,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, IrInstructionSwitchElseVar *instruction) { IrInstruction *target_value_ptr = instruction->target_value_ptr->child; - if (type_is_invalid(target_value_ptr->value.type)) + if (type_is_invalid(target_value_ptr->value->type)) return ira->codegen->invalid_instruction; - ZigType *ref_type = target_value_ptr->value.type; + ZigType *ref_type = target_value_ptr->value->type; assert(ref_type->id == ZigTypeIdPointer); - ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; + ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; if (target_type->id == ZigTypeIdErrorSet) { // make a new set that has the other cases removed if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) { @@ -20645,12 +20683,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) { IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; IrInstruction *case_expr = br_case->value->child; - if (case_expr->value.type->id == ZigTypeIdErrorSet) { + if (case_expr->value->type->id == ZigTypeIdErrorSet) { ErrorTableEntry *err = ir_resolve_error(ira, case_expr); if (err == nullptr) return ira->codegen->invalid_instruction; errors[err->value] = err; - } else if (case_expr->value.type->id == ZigTypeIdMetaType) { + } else if (case_expr->value->type->id == ZigTypeIdMetaType) { ZigType *err_set_type = ir_resolve_type(ira, case_expr); if (type_is_invalid(err_set_type)) return ira->codegen->invalid_instruction; @@ -20742,7 +20780,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { IrInstruction *value = ref_instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); } @@ -20768,13 +20806,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc if (type_is_invalid(type_field->type_entry)) return ira->codegen->invalid_instruction; - if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { + if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { if (instr_is_comptime(field_result_loc) && - field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) + field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { // nothing } else { - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; } } @@ -20803,7 +20841,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc } IrInstructionContainerInitFieldsField *field = &fields[0]; IrInstruction *field_result_loc = field->result_loc->child; - if (type_is_invalid(field_result_loc->value.type)) + if (type_is_invalid(field_result_loc->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name, @@ -20850,7 +20888,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc IrInstructionContainerInitFieldsField *field = &fields[i]; IrInstruction *field_result_loc = field->result_loc->child; - if (type_is_invalid(field_result_loc->value.type)) + if (type_is_invalid(field_result_loc->value->type)) return ira->codegen->invalid_instruction; TypeStructField *type_field = find_struct_type_field(container_type, field->name); @@ -20874,7 +20912,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc field_assign_nodes[field_index] = field->source_node; if (instr_is_comptime(field_result_loc) && - field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) + field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { const_ptrs.append(field_result_loc); } else { @@ -20912,12 +20950,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc return ira->codegen->invalid_instruction; IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); - copy_const_val(&runtime_inst->value, field->init_val, true); + copy_const_val(runtime_inst->value, field->init_val, true); IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, container_type, true); ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); - if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { + if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { const_ptrs.append(field_ptr); } else { first_non_const_instruction = result_loc; @@ -20926,13 +20964,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc if (any_missing) return ira->codegen->invalid_instruction; - if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { + if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { if (const_ptrs.length != actual_field_count) { - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; for (size_t i = 0; i < const_ptrs.length; i += 1) { IrInstruction *field_result_loc = const_ptrs.at(i); IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); - field_result_loc->value.special = ConstValSpecialRuntime; + field_result_loc->value->special = ConstValSpecialRuntime; ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); } } @@ -20954,11 +20992,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, { ir_assert(instruction->result_loc != nullptr, &instruction->base); IrInstruction *result_loc = instruction->result_loc->child; - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return result_loc; - ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); + ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); - ZigType *container_type = result_loc->value.type->data.pointer.child_type; + ZigType *container_type = result_loc->value->type->data.pointer.child_type; size_t elem_count = instruction->item_count; @@ -20980,7 +21018,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, if (container_type->id == ZigTypeIdStruct && elem_count == 0) { ir_assert(instruction->result_loc != nullptr, &instruction->base); IrInstruction *result_loc = instruction->result_loc->child; - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return result_loc; return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc); } @@ -21041,13 +21079,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, for (size_t i = 0; i < elem_count; i += 1) { IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child; - if (type_is_invalid(elem_result_loc->value.type)) + if (type_is_invalid(elem_result_loc->value->type)) return ira->codegen->invalid_instruction; - assert(elem_result_loc->value.type->id == ZigTypeIdPointer); + assert(elem_result_loc->value->type->id == ZigTypeIdPointer); if (instr_is_comptime(elem_result_loc) && - elem_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) + elem_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { const_ptrs.append(elem_result_loc); } else { @@ -21055,14 +21093,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, } } - if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { + if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { if (const_ptrs.length != elem_count) { - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; for (size_t i = 0; i < const_ptrs.length; i += 1) { IrInstruction *elem_result_loc = const_ptrs.at(i); - assert(elem_result_loc->value.special == ConstValSpecialStatic); + assert(elem_result_loc->value->special == ConstValSpecialStatic); IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); - elem_result_loc->value.special = ConstValSpecialRuntime; + elem_result_loc->value->special = ConstValSpecialRuntime; ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); } } @@ -21078,7 +21116,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, return ira->codegen->invalid_instruction; } - ZigType *result_elem_type = result_loc->value.type->data.pointer.child_type; + ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; if (is_slice(result_elem_type)) { ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", @@ -21095,11 +21133,11 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir { ir_assert(instruction->result_loc != nullptr, &instruction->base); IrInstruction *result_loc = instruction->result_loc->child; - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return result_loc; - ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); - ZigType *container_type = result_loc->value.type->data.pointer.child_type; + ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); + ZigType *container_type = result_loc->value->type->data.pointer.child_type; return ir_analyze_container_init_fields(ira, &instruction->base, container_type, instruction->field_count, instruction->fields, result_loc); @@ -21123,15 +21161,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr fprintf(stderr, "| "); for (size_t i = 0; i < instruction->msg_count; i += 1) { IrInstruction *msg = instruction->msg_list[i]->child; - if (type_is_invalid(msg->value.type)) + if (type_is_invalid(msg->value->type)) return ira->codegen->invalid_instruction; buf_resize(&buf, 0); - if (msg->value.special == ConstValSpecialLazy) { + if (msg->value->special == ConstValSpecialLazy) { // Resolve any lazy value that's passed, we need its value - if (ir_resolve_lazy(ira->codegen, msg->source_node, &msg->value)) + if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value)) return ira->codegen->invalid_instruction; } - render_const_value(ira->codegen, &buf, &msg->value); + render_const_value(ira->codegen, &buf, msg->value); const char *comma_str = (i != 0) ? ", " : ""; fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf)); } @@ -21150,28 +21188,28 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return ira->codegen->invalid_instruction; ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, 0, 0, 0, false); ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); if (instr_is_comptime(casted_value)) { - ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); if (val == nullptr) return ira->codegen->invalid_instruction; - ErrorTableEntry *err = casted_value->value.data.x_err_set; + ErrorTableEntry *err = casted_value->value->data.x_err_set; if (!err->cached_error_name_val) { - ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; + ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); } IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - copy_const_val(&result->value, err->cached_error_name_val, true); - result->value.type = str_type; + copy_const_val(result->value, err->cached_error_name_val, true); + result->value->type = str_type; return result; } @@ -21179,25 +21217,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_err_name(&ira->new_irb, instruction->base.scope, instruction->base.source_node, value); - result->value.type = str_type; + result->value->type = str_type; return result; } static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { Error err; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - assert(target->value.type->id == ZigTypeIdEnum); + assert(target->value->type->id == ZigTypeIdEnum); if (instr_is_comptime(target)) { - if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) + if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; - TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); - ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; + TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); + ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true); + init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true); return result; } @@ -21207,7 +21245,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, 0, 0, 0, false); - result->value.type = get_slice_type(ira->codegen, u8_ptr_type); + result->value->type = get_slice_type(ira->codegen, u8_ptr_type); return result; } @@ -21226,7 +21264,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, return ira->codegen->invalid_instruction; IrInstruction *field_ptr = instruction->field_ptr->child; - if (type_is_invalid(field_ptr->value.type)) + if (type_is_invalid(field_ptr->value->type)) return ira->codegen->invalid_instruction; if (container_type->id != ZigTypeIdStruct) { @@ -21246,9 +21284,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, return ira->codegen->invalid_instruction; } - if (field_ptr->value.type->id != ZigTypeIdPointer) { + if (field_ptr->value->type->id != ZigTypeIdPointer) { ir_add_error(ira, field_ptr, - buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); + buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); return ira->codegen->invalid_instruction; } @@ -21257,22 +21295,22 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, - field_ptr->value.type->data.pointer.is_const, - field_ptr->value.type->data.pointer.is_volatile, + field_ptr->value->type->data.pointer.is_const, + field_ptr->value->type->data.pointer.is_volatile, PtrLenSingle, field_ptr_align, 0, 0, false); IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); - if (type_is_invalid(casted_field_ptr->value.type)) + if (type_is_invalid(casted_field_ptr->value->type)) return ira->codegen->invalid_instruction; ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, - casted_field_ptr->value.type->data.pointer.is_const, - casted_field_ptr->value.type->data.pointer.is_volatile, + casted_field_ptr->value->type->data.pointer.is_const, + casted_field_ptr->value->type->data.pointer.is_volatile, PtrLenSingle, parent_ptr_align, 0, 0, false); if (instr_is_comptime(casted_field_ptr)) { - ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); + ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); if (!field_ptr_val) return ira->codegen->invalid_instruction; @@ -21291,7 +21329,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, } IrInstruction *result = ir_const(ira, &instruction->base, result_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; out_val->data.x_ptr.special = ConstPtrSpecialRef; out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut; @@ -21300,7 +21338,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -21350,7 +21388,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstructionByteOffsetOf *instruction) { IrInstruction *type_value = instruction->type_value->child; - if (type_is_invalid(type_value->value.type)) + if (type_is_invalid(type_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *field_name_value = instruction->field_name->child; @@ -21366,7 +21404,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstructionBitOffsetOf *instruction) { IrInstruction *type_value = instruction->type_value->child; - if (type_is_invalid(type_value->value.type)) + if (type_is_invalid(type_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *field_name_value = instruction->field_name->child; size_t byte_offset = 0; @@ -21390,7 +21428,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { Error err; - ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); + ZigValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); assert(type_info_var->type->id == ZigTypeIdMetaType); ZigType *type_info_type = type_info_var->data.x_type; assert(type_info_type->id == ZigTypeIdUnion); @@ -21423,7 +21461,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); } -static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val, +static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val, ScopeDecls *decls_scope) { Error err; @@ -21473,7 +21511,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr } } - ConstExprValue *declaration_array = create_const_vals(1); + ZigValue *declaration_array = create_const_vals(1); declaration_array->special = ConstValSpecialStatic; declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr); declaration_array->data.x_array.special = ConstArraySpecialNone; @@ -21494,13 +21532,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr continue; } - ConstExprValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index]; + ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index]; declaration_val->special = ConstValSpecialStatic; declaration_val->type = type_info_declaration_type; - ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); - ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee; + ZigValue **inner_fields = alloc_const_vals_ptrs(3); + ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true); inner_fields[1]->special = ConstValSpecialStatic; inner_fields[1]->type = ira->codegen->builtin_types.entry_bool; @@ -21528,7 +21566,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr // 1: Data.Var: type bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1); - ConstExprValue *payload = create_const_vals(1); + ZigValue *payload = create_const_vals(1); payload->special = ConstValSpecialStatic; payload->type = ira->codegen->builtin_types.entry_type; payload->data.x_type = var->const_value->type; @@ -21553,13 +21591,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto; - ConstExprValue *fn_decl_val = create_const_vals(1); + ZigValue *fn_decl_val = create_const_vals(1); fn_decl_val->special = ConstValSpecialStatic; fn_decl_val->type = type_info_fn_decl_type; fn_decl_val->parent.id = ConstParentIdUnion; fn_decl_val->parent.data.p_union.union_val = inner_fields[2]; - ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9); + ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9); fn_decl_val->data.x_struct.fields = fn_decl_fields; // fn_type: type @@ -21603,7 +21641,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) { fn_decl_fields[6]->data.x_optional = create_const_vals(1); - ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee; + ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true); } else { @@ -21617,7 +21655,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr // arg_names: [][] const u8 ensure_field_index(fn_decl_val->type, "arg_names", 8); size_t fn_arg_count = fn_entry->variable_list.length; - ConstExprValue *fn_arg_name_array = create_const_vals(1); + ZigValue *fn_arg_name_array = create_const_vals(1); fn_arg_name_array->special = ConstValSpecialStatic; fn_arg_name_array->type = get_array_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr); @@ -21628,8 +21666,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index); - ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index]; - ConstExprValue *arg_name = create_const_str_lit(ira->codegen, + ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index]; + ZigValue *arg_name = create_const_str_lit(ira->codegen, buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true); fn_arg_name_val->parent.id = ConstParentIdArray; @@ -21649,7 +21687,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr // This is a type. bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0); - ConstExprValue *payload = create_const_vals(1); + ZigValue *payload = create_const_vals(1); payload->special = ConstValSpecialStatic; payload->type = ira->codegen->builtin_types.entry_type; payload->data.x_type = type_entry; @@ -21695,7 +21733,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) { zig_unreachable(); } -static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { +static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { Error err; ZigType *attrs_type; BuiltinPtrSize size_enum_index; @@ -21715,11 +21753,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown)); - ConstExprValue *result = create_const_vals(1); + ZigValue *result = create_const_vals(1); result->special = ConstValSpecialStatic; result->type = type_info_pointer_type; - ConstExprValue **fields = alloc_const_vals_ptrs(7); + ZigValue **fields = alloc_const_vals_ptrs(7); result->data.x_struct.fields = fields; // size: Size @@ -21769,17 +21807,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty return result; }; -static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field, +static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEnumField *enum_field, ZigType *type_info_enum_field_type) { enum_field_val->special = ConstValSpecialStatic; enum_field_val->type = type_info_enum_field_type; - ConstExprValue **inner_fields = alloc_const_vals_ptrs(2); + ZigValue **inner_fields = alloc_const_vals_ptrs(2); inner_fields[1]->special = ConstValSpecialStatic; inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; - ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee; + ZigValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true); bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value); @@ -21788,7 +21826,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, } static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, - ConstExprValue **out) + ZigValue **out) { Error err; assert(type_entry != nullptr); @@ -21803,7 +21841,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr return ErrorNone; } - ConstExprValue *result = nullptr; + ZigValue *result = nullptr; switch (type_entry->id) { case ZigTypeIdInvalid: zig_unreachable(); @@ -21826,7 +21864,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Int", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(2); + ZigValue **fields = alloc_const_vals_ptrs(2); result->data.x_struct.fields = fields; // is_signed: bool @@ -21848,7 +21886,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Float", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(1); + ZigValue **fields = alloc_const_vals_ptrs(1); result->data.x_struct.fields = fields; // bits: u8 @@ -21872,7 +21910,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Array", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(3); + ZigValue **fields = alloc_const_vals_ptrs(3); result->data.x_struct.fields = fields; // len: usize @@ -21896,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Vector", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(2); + ZigValue **fields = alloc_const_vals_ptrs(2); result->data.x_struct.fields = fields; // len: usize @@ -21918,7 +21956,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Optional", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(1); + ZigValue **fields = alloc_const_vals_ptrs(1); result->data.x_struct.fields = fields; // child: type @@ -21934,7 +21972,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(1); + ZigValue **fields = alloc_const_vals_ptrs(1); result->data.x_struct.fields = fields; // child: ?type @@ -21951,7 +21989,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Enum", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(4); + ZigValue **fields = alloc_const_vals_ptrs(4); result->data.x_struct.fields = fields; // layout: ContainerLayout @@ -21973,7 +22011,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr } uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; - ConstExprValue *enum_field_array = create_const_vals(1); + ZigValue *enum_field_array = create_const_vals(1); enum_field_array->special = ConstValSpecialStatic; enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr); enum_field_array->data.x_array.special = ConstArraySpecialNone; @@ -21984,7 +22022,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++) { TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index]; - ConstExprValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index]; + ZigValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index]; make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type); enum_field_val->parent.id = ConstParentIdArray; enum_field_val->parent.data.p_array.array_val = enum_field_array; @@ -22017,11 +22055,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) { zig_unreachable(); } - ConstExprValue *slice_val = create_const_vals(1); + ZigValue *slice_val = create_const_vals(1); result->data.x_optional = slice_val; uint32_t error_count = type_entry->data.error_set.err_count; - ConstExprValue *error_array = create_const_vals(1); + ZigValue *error_array = create_const_vals(1); error_array->special = ConstValSpecialStatic; error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr); error_array->data.x_array.special = ConstArraySpecialNone; @@ -22030,16 +22068,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false); for (uint32_t error_index = 0; error_index < error_count; error_index++) { ErrorTableEntry *error = type_entry->data.error_set.errors[error_index]; - ConstExprValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; + ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; error_val->special = ConstValSpecialStatic; error_val->type = type_info_error_type; - ConstExprValue **inner_fields = alloc_const_vals_ptrs(2); + ZigValue **inner_fields = alloc_const_vals_ptrs(2); inner_fields[1]->special = ConstValSpecialStatic; inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; - ConstExprValue *name = nullptr; + ZigValue *name = nullptr; if (error->cached_error_name_val != nullptr) name = error->cached_error_name_val; if (name == nullptr) @@ -22061,7 +22099,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(2); + ZigValue **fields = alloc_const_vals_ptrs(2); result->data.x_struct.fields = fields; // error_set: type @@ -22084,7 +22122,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Union", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(4); + ZigValue **fields = alloc_const_vals_ptrs(4); result->data.x_struct.fields = fields; // layout: ContainerLayout @@ -22101,7 +22139,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr if (union_decl_node->data.container_decl.auto_enum || union_decl_node->data.container_decl.init_arg_expr != nullptr) { - ConstExprValue *tag_type = create_const_vals(1); + ZigValue *tag_type = create_const_vals(1); tag_type->special = ConstValSpecialStatic; tag_type->type = ira->codegen->builtin_types.entry_type; tag_type->data.x_type = type_entry->data.unionation.tag_type; @@ -22117,7 +22155,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr zig_unreachable(); uint32_t union_field_count = type_entry->data.unionation.src_field_count; - ConstExprValue *union_field_array = create_const_vals(1); + ZigValue *union_field_array = create_const_vals(1); union_field_array->special = ConstValSpecialStatic; union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr); union_field_array->data.x_array.special = ConstArraySpecialNone; @@ -22129,12 +22167,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; - ConstExprValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index]; + ZigValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index]; union_field_val->special = ConstValSpecialStatic; union_field_val->type = type_info_union_field_type; - ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); + ZigValue **inner_fields = alloc_const_vals_ptrs(3); inner_fields[1]->special = ConstValSpecialStatic; inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type); @@ -22149,7 +22187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr inner_fields[2]->type = ira->codegen->builtin_types.entry_type; inner_fields[2]->data.x_type = union_field->type_entry; - ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee; + ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true); union_field_val->data.x_struct.fields = inner_fields; @@ -22180,7 +22218,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Struct", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(3); + ZigValue **fields = alloc_const_vals_ptrs(3); result->data.x_struct.fields = fields; // layout: ContainerLayout @@ -22197,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr } uint32_t struct_field_count = type_entry->data.structure.src_field_count; - ConstExprValue *struct_field_array = create_const_vals(1); + ZigValue *struct_field_array = create_const_vals(1); struct_field_array->special = ConstValSpecialStatic; struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr); struct_field_array->data.x_array.special = ConstArraySpecialNone; @@ -22207,12 +22245,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index]; - ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; + ZigValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; struct_field_val->special = ConstValSpecialStatic; struct_field_val->type = type_info_struct_field_type; - ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); + ZigValue **inner_fields = alloc_const_vals_ptrs(3); inner_fields[1]->special = ConstValSpecialStatic; inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int); @@ -22235,7 +22273,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr inner_fields[2]->type = ira->codegen->builtin_types.entry_type; inner_fields[2]->data.x_type = struct_field->type_entry; - ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; + ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true); struct_field_val->data.x_struct.fields = inner_fields; @@ -22259,7 +22297,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Fn", nullptr); - ConstExprValue **fields = alloc_const_vals_ptrs(5); + ZigValue **fields = alloc_const_vals_ptrs(5); result->data.x_struct.fields = fields; // calling_convention: TypeInfo.CallingConvention @@ -22286,7 +22324,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr if (type_entry->data.fn.fn_type_id.return_type == nullptr) fields[3]->data.x_optional = nullptr; else { - ConstExprValue *return_type = create_const_vals(1); + ZigValue *return_type = create_const_vals(1); return_type->special = ConstValSpecialStatic; return_type->type = ira->codegen->builtin_types.entry_type; return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; @@ -22300,7 +22338,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); - ConstExprValue *fn_arg_array = create_const_vals(1); + ZigValue *fn_arg_array = create_const_vals(1); fn_arg_array->special = ConstValSpecialStatic; fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr); fn_arg_array->data.x_array.special = ConstArraySpecialNone; @@ -22310,7 +22348,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; - ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index]; + ZigValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index]; fn_arg_val->special = ConstValSpecialStatic; fn_arg_val->type = type_info_fn_arg_type; @@ -22318,7 +22356,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr bool arg_is_generic = fn_param_info->type == nullptr; if (arg_is_generic) assert(is_generic); - ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); + ZigValue **inner_fields = alloc_const_vals_ptrs(3); inner_fields[0]->special = ConstValSpecialStatic; inner_fields[0]->type = ira->codegen->builtin_types.entry_bool; inner_fields[0]->data.x_bool = arg_is_generic; @@ -22331,7 +22369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr if (arg_is_generic) inner_fields[2]->data.x_optional = nullptr; else { - ConstExprValue *arg_type = create_const_vals(1); + ZigValue *arg_type = create_const_vals(1); arg_type->special = ConstValSpecialStatic; arg_type->type = ira->codegen->builtin_types.entry_type; arg_type->data.x_type = fn_param_info->type; @@ -22376,12 +22414,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); - ConstExprValue *payload; + ZigValue *payload; if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload))) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, result_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); out_val->data.x_union.payload = payload; @@ -22393,49 +22431,49 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, return result; } -static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) +static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) { ensure_field_index(struct_value->type, name, field_index); assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic); return struct_value->data.x_struct.fields[field_index]; } -static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value, - const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result) +static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value, + const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) { - ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index); + ZigValue *field_val = get_const_field(ira, struct_value, name, field_index); IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type); IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, get_optional_type(ira->codegen, elem_type)); - if (type_is_invalid(casted_field_inst->value.type)) + if (type_is_invalid(casted_field_inst->value->type)) return ErrorSemanticAnalyzeFail; - *result = casted_field_inst->value.data.x_optional; + *result = casted_field_inst->value->data.x_optional; return ErrorNone; } -static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) +static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) { - ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, struct_value, name, field_index); assert(value->type == ira->codegen->builtin_types.entry_bool); return value->data.x_bool; } -static BigInt *get_const_field_lit_int(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) +static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) { - ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, struct_value, name, field_index); assert(value->type == ira->codegen->builtin_types.entry_num_lit_int); return &value->data.x_bigint; } -static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) +static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) { - ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, struct_value, name, field_index); assert(value->type == ira->codegen->builtin_types.entry_type); return value->data.x_type; } -static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) { +static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) { Error err; switch (tagTypeId) { case ZigTypeIdInvalid: @@ -22474,12 +22512,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); assert(payload->special == ConstValSpecialStatic); assert(payload->type == type_info_pointer_type); - ConstExprValue *size_value = get_const_field(ira, payload, "size", 0); + ZigValue *size_value = get_const_field(ira, payload, "size", 0); assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4); - ConstExprValue *sentinel; + ZigValue *sentinel; if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, elem_type, &sentinel))) { @@ -22504,7 +22542,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1); - ConstExprValue *sentinel; + ZigValue *sentinel; if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, elem_type, &sentinel))) { @@ -22549,14 +22587,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) { IrInstruction *type_info_ir = instruction->type_info->child; - if (type_is_invalid(type_info_ir->value.type)) + if (type_is_invalid(type_info_ir->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr)); - if (type_is_invalid(casted_ir->value.type)) + if (type_is_invalid(casted_ir->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); + ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); if (!type_info_value) return ira->codegen->invalid_instruction; ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag)); @@ -22574,12 +22612,12 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, if (type_is_invalid(type_entry)) return ira->codegen->invalid_instruction; - ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); + ZigValue *var_value = get_builtin_value(ira->codegen, "TypeId"); assert(var_value->type->id == ZigTypeIdMetaType); ZigType *result_type = var_value->data.x_type; IrInstruction *result = ir_const(ira, &instruction->base, result_type); - bigint_init_unsigned(&result->value.data.x_enum_tag, type_id_index(type_entry)); + bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry)); return result; } @@ -22607,7 +22645,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); } IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - copy_const_val(&result->value, type_entry->cached_const_name_val, true); + copy_const_val(result->value, type_entry->cached_const_name_val, true); return result; } @@ -22628,7 +22666,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct // Execute the C import block like an inline function ZigType *void_type = ira->codegen->builtin_types.entry_void; - ConstExprValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, + ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); if (type_is_invalid(cimport_result->type)) @@ -22796,7 +22834,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { IrInstruction *name_value = instruction->name->child; - if (type_is_invalid(name_value->value.type)) + if (type_is_invalid(name_value->value->type)) return ira->codegen->invalid_instruction; Buf *include_name = ir_resolve_str(ira, name_value); @@ -22814,7 +22852,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { IrInstruction *name = instruction->name->child; - if (type_is_invalid(name->value.type)) + if (type_is_invalid(name->value->type)) return ira->codegen->invalid_instruction; Buf *define_name = ir_resolve_str(ira, name); @@ -22822,12 +22860,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; Buf *define_value = nullptr; // The second parameter is either a string or void (equivalent to "") - if (value->value.type->id != ZigTypeIdVoid) { + if (value->value->type->id != ZigTypeIdVoid) { define_value = ir_resolve_str(ira, value); if (!define_value) return ira->codegen->invalid_instruction; @@ -22845,7 +22883,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { IrInstruction *name = instruction->name->child; - if (type_is_invalid(name->value.type)) + if (type_is_invalid(name->value->type)) return ira->codegen->invalid_instruction; Buf *undef_name = ir_resolve_str(ira, name); @@ -22863,7 +22901,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { IrInstruction *name = instruction->name->child; - if (type_is_invalid(name->value.type)) + if (type_is_invalid(name->value->type)) return ira->codegen->invalid_instruction; Buf *rel_file_path = ir_resolve_str(ira, name); @@ -22898,7 +22936,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru ZigType *result_type = get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr); IrInstruction *result = ir_const(ira, &instruction->base, result_type); - init_const_str_lit(ira->codegen, &result->value, file_contents); + init_const_str_lit(ira->codegen, result->value, file_contents); return result; } @@ -22908,25 +22946,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi return ira->codegen->invalid_instruction; IrInstruction *ptr = instruction->ptr->child; - if (type_is_invalid(ptr->value.type)) + if (type_is_invalid(ptr->value->type)) return ira->codegen->invalid_instruction; // TODO let this be volatile ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); - if (type_is_invalid(casted_ptr->value.type)) + if (type_is_invalid(casted_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *cmp_value = instruction->cmp_value->child; - if (type_is_invalid(cmp_value->value.type)) + if (type_is_invalid(cmp_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *new_value = instruction->new_value->child; - if (type_is_invalid(new_value->value.type)) + if (type_is_invalid(new_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *success_order_value = instruction->success_order_value->child; - if (type_is_invalid(success_order_value->value.type)) + if (type_is_invalid(success_order_value->value->type)) return ira->codegen->invalid_instruction; AtomicOrder success_order; @@ -22934,7 +22972,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi return ira->codegen->invalid_instruction; IrInstruction *failure_order_value = instruction->failure_order_value->child; - if (type_is_invalid(failure_order_value->value.type)) + if (type_is_invalid(failure_order_value->value->type)) return ira->codegen->invalid_instruction; AtomicOrder failure_order; @@ -22942,11 +22980,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi return ira->codegen->invalid_instruction; IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); - if (type_is_invalid(casted_cmp_value->value.type)) + if (type_is_invalid(casted_cmp_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); - if (type_is_invalid(casted_new_value->value.type)) + if (type_is_invalid(casted_new_value->value->type)) return ira->codegen->invalid_instruction; if (success_order < AtomicOrderMonotonic) { @@ -22970,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi return ira->codegen->invalid_instruction; } - if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar && + if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { zig_panic("TODO compile-time execution of cmpxchg"); } @@ -22980,7 +23018,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi if (handle_is_ptr(result_type)) { result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, result_type, nullptr, true, false, true); - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } } else { @@ -22994,7 +23032,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { IrInstruction *order_value = instruction->order_value->child; - if (type_is_invalid(order_value->value.type)) + if (type_is_invalid(order_value->value->type)) return ira->codegen->invalid_instruction; AtomicOrder order; @@ -23009,7 +23047,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction IrInstruction *result = ir_build_fence(&ira->new_irb, instruction->base.scope, instruction->base.source_node, order_value, order); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } @@ -23027,7 +23065,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct } IrInstruction *target = instruction->target->child; - ZigType *src_type = target->value.type; + ZigType *src_type = target->value->type; if (type_is_invalid(src_type)) return ira->codegen->invalid_instruction; @@ -23043,19 +23081,19 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct } if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (val == nullptr) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, dest_type); - bigint_truncate(&result->value.data.x_bigint, &val->data.x_bigint, + bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); return result; } if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { IrInstruction *result = ir_const(ira, &instruction->base, dest_type); - bigint_init_unsigned(&result->value.data.x_bigint, 0); + bigint_init_unsigned(&result->value->data.x_bigint, 0); return result; } @@ -23071,7 +23109,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, instruction->base.source_node, dest_type_value, target); - new_instruction->value.type = dest_type; + new_instruction->value->type = dest_type; return new_instruction; } @@ -23086,12 +23124,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct } IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { + if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", - buf_ptr(&target->value.type->name))); + buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23120,15 +23158,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru } IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id == ZigTypeIdComptimeInt || - target->value.type->id == ZigTypeIdComptimeFloat) + if (target->value->type->id == ZigTypeIdComptimeInt || + target->value->type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { CastOp op; - if (target->value.type->id == ZigTypeIdComptimeInt) { + if (target->value->type->id == ZigTypeIdComptimeInt) { op = CastOpIntToFloat; } else { op = CastOpNumLitToConcrete; @@ -23139,9 +23177,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru } } - if (target->value.type->id != ZigTypeIdFloat) { + if (target->value->type->id != ZigTypeIdFloat) { ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", - buf_ptr(&target->value.type->name))); + buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23160,12 +23198,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst } IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id != ZigTypeIdErrorSet) { + if (target->value->type->id != ZigTypeIdErrorSet) { ir_add_error(ira, instruction->target, - buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); + buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23180,20 +23218,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru return ira->codegen->invalid_instruction; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; bool src_ptr_const; bool src_ptr_volatile; uint32_t src_ptr_align; - if (target->value.type->id == ZigTypeIdPointer) { - src_ptr_const = target->value.type->data.pointer.is_const; - src_ptr_volatile = target->value.type->data.pointer.is_volatile; + if (target->value->type->id == ZigTypeIdPointer) { + src_ptr_const = target->value->type->data.pointer.is_const; + src_ptr_volatile = target->value->type->data.pointer.is_volatile; - if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) + if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align))) return ira->codegen->invalid_instruction; - } else if (is_slice(target->value.type)) { - ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; + } else if (is_slice(target->value->type)) { + ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; src_ptr_const = src_ptr_type->data.pointer.is_const; src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; @@ -23203,10 +23241,10 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru src_ptr_const = true; src_ptr_volatile = false; - if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown))) + if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown))) return ira->codegen->invalid_instruction; - src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); + src_ptr_align = get_abi_alignment(ira->codegen, target->value->type); } if (src_ptr_align != 0) { @@ -23225,18 +23263,18 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return ira->codegen->invalid_instruction; bool have_known_len = false; uint64_t known_len; if (instr_is_comptime(casted_value)) { - ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); if (!val) return ira->codegen->invalid_instruction; - ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = val->data.x_struct.fields[slice_len_index]; if (value_is_comptime(len_val)) { known_len = bigint_as_u64(&len_val->data.x_bigint); have_known_len = true; @@ -23245,12 +23283,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, dest_slice_type, nullptr, true, false, true); - if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { + if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { return result_loc; } - if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) { - known_len = casted_value->value.data.rh_slice.len; + if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) { + known_len = casted_value->value->data.rh_slice.len; have_known_len = true; } @@ -23277,16 +23315,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct Error err; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (!is_slice(target->value.type)) { + if (!is_slice(target->value->type)) { ir_add_error(ira, instruction->target, - buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name))); + buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } - ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; + ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; uint32_t alignment; if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) @@ -23298,22 +23336,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); if (instr_is_comptime(target)) { - ConstExprValue *target_val = ir_resolve_const(ira, target, UndefBad); + ZigValue *target_val = ir_resolve_const(ira, target, UndefBad); if (target_val == nullptr) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type); - result->value.data.x_struct.fields = alloc_const_vals_ptrs(2); + result->value->data.x_struct.fields = alloc_const_vals_ptrs(2); - ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index]; - ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; + ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; copy_const_val(ptr_val, target_ptr_val, false); ptr_val->type = dest_ptr_type; - ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index]; + ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index]; len_val->special = ConstValSpecialStatic; len_val->type = ira->codegen->builtin_types.entry_usize; - ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index]; + ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index]; ZigType *elem_type = src_ptr_type->data.pointer.child_type; BigInt elem_size_bigint; bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type)); @@ -23324,7 +23362,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, dest_slice_type, nullptr, true, false, true); - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } @@ -23351,12 +23389,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst return ira->codegen->invalid_instruction; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { + if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", - buf_ptr(&target->value.type->name))); + buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23369,16 +23407,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst return ira->codegen->invalid_instruction; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id == ZigTypeIdComptimeInt) { + if (target->value->type->id == ZigTypeIdComptimeInt) { return ir_implicit_cast(ira, target, dest_type); } - if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { + if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) { ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", - buf_ptr(&target->value.type->name))); + buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23387,15 +23425,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_target; - if (target->value.type->id == ZigTypeIdErrorSet) { + if (target->value->type->id == ZigTypeIdErrorSet) { casted_target = target; } else { casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); - if (type_is_invalid(casted_target->value.type)) + if (type_is_invalid(casted_target->value->type)) return ira->codegen->invalid_instruction; } @@ -23404,11 +23442,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); - if (type_is_invalid(casted_target->value.type)) + if (type_is_invalid(casted_target->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); @@ -23416,12 +23454,12 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; - if (target->value.type->id != ZigTypeIdBool) { + if (target->value->type->id != ZigTypeIdBool) { ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", - buf_ptr(&target->value.type->name))); + buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23472,48 +23510,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s ir_assert(is_valid_vector_elem_type(scalar_type), source_instr); uint32_t len_mask; - if (mask->value.type->id == ZigTypeIdVector) { - len_mask = mask->value.type->data.vector.len; - } else if (mask->value.type->id == ZigTypeIdArray) { - len_mask = mask->value.type->data.array.len; + if (mask->value->type->id == ZigTypeIdVector) { + len_mask = mask->value->type->data.vector.len; + } else if (mask->value->type->id == ZigTypeIdArray) { + len_mask = mask->value->type->data.array.len; } else { ir_add_error(ira, mask, buf_sprintf("expected vector or array, found '%s'", - buf_ptr(&mask->value.type->name))); + buf_ptr(&mask->value->type->name))); return ira->codegen->invalid_instruction; } mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask, ira->codegen->builtin_types.entry_i32)); - if (type_is_invalid(mask->value.type)) + if (type_is_invalid(mask->value->type)) return ira->codegen->invalid_instruction; uint32_t len_a; - if (a->value.type->id == ZigTypeIdVector) { - len_a = a->value.type->data.vector.len; - } else if (a->value.type->id == ZigTypeIdArray) { - len_a = a->value.type->data.array.len; - } else if (a->value.type->id == ZigTypeIdUndefined) { + if (a->value->type->id == ZigTypeIdVector) { + len_a = a->value->type->data.vector.len; + } else if (a->value->type->id == ZigTypeIdArray) { + len_a = a->value->type->data.array.len; + } else if (a->value->type->id == ZigTypeIdUndefined) { len_a = UINT32_MAX; } else { ir_add_error(ira, a, buf_sprintf("expected vector or array with element type '%s', found '%s'", buf_ptr(&scalar_type->name), - buf_ptr(&a->value.type->name))); + buf_ptr(&a->value->type->name))); return ira->codegen->invalid_instruction; } uint32_t len_b; - if (b->value.type->id == ZigTypeIdVector) { - len_b = b->value.type->data.vector.len; - } else if (b->value.type->id == ZigTypeIdArray) { - len_b = b->value.type->data.array.len; - } else if (b->value.type->id == ZigTypeIdUndefined) { + if (b->value->type->id == ZigTypeIdVector) { + len_b = b->value->type->data.vector.len; + } else if (b->value->type->id == ZigTypeIdArray) { + len_b = b->value->type->data.array.len; + } else if (b->value->type->id == ZigTypeIdUndefined) { len_b = UINT32_MAX; } else { ir_add_error(ira, b, buf_sprintf("expected vector or array with element type '%s', found '%s'", buf_ptr(&scalar_type->name), - buf_ptr(&b->value.type->name))); + buf_ptr(&b->value->type->name))); return ira->codegen->invalid_instruction; } @@ -23526,7 +23564,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); } else { a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); - if (type_is_invalid(a->value.type)) + if (type_is_invalid(a->value->type)) return ira->codegen->invalid_instruction; } @@ -23535,18 +23573,18 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); } else { b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); - if (type_is_invalid(b->value.type)) + if (type_is_invalid(b->value->type)) return ira->codegen->invalid_instruction; } - ConstExprValue *mask_val = ir_resolve_const(ira, mask, UndefOk); + ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk); if (mask_val == nullptr) return ira->codegen->invalid_instruction; expand_undef_array(ira->codegen, mask_val); for (uint32_t i = 0; i < len_mask; i += 1) { - ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; + ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; if (mask_elem_val->special == ConstValSpecialUndef) continue; int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint); @@ -23559,12 +23597,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s v = (uint32_t)~v_i32; chosen_operand = b; } - if (v >= chosen_operand->value.type->data.vector.len) { + if (v >= chosen_operand->value->type->data.vector.len) { ErrorMsg *msg = ir_add_error(ira, mask, buf_sprintf("mask index '%u' has out-of-bounds selection", i)); add_error_note(ira->codegen, msg, chosen_operand->source_node, buf_sprintf("selected index '%u' out of bounds of %s", v, - buf_ptr(&chosen_operand->value.type->name))); + buf_ptr(&chosen_operand->value->type->name))); if (chosen_operand == a && v < len_a + len_b) { add_error_note(ira->codegen, msg, b->source_node, buf_create_from_str("selections from the second vector are specified with negative numbers")); @@ -23575,11 +23613,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type); if (instr_is_comptime(a) && instr_is_comptime(b)) { - ConstExprValue *a_val = ir_resolve_const(ira, a, UndefOk); + ZigValue *a_val = ir_resolve_const(ira, a, UndefOk); if (a_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *b_val = ir_resolve_const(ira, b, UndefOk); + ZigValue *b_val = ir_resolve_const(ira, b, UndefOk); if (b_val == nullptr) return ira->codegen->invalid_instruction; @@ -23587,24 +23625,24 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s expand_undef_array(ira->codegen, b_val); IrInstruction *result = ir_const(ira, source_instr, result_type); - result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask); + result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask); for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { - ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; - ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; + ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; + ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; if (mask_elem_val->special == ConstValSpecialUndef) { result_elem_val->special = ConstValSpecialUndef; continue; } int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint); // We've already checked for and emitted compile errors for index out of bounds here. - ConstExprValue *src_elem_val = (v >= 0) ? - &a->value.data.x_array.data.s_none.elements[v] : - &b->value.data.x_array.data.s_none.elements[~v]; + ZigValue *src_elem_val = (v >= 0) ? + &a->value->data.x_array.data.s_none.elements[v] : + &b->value->data.x_array.data.s_none.elements[~v]; copy_const_val(result_elem_val, src_elem_val, false); ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); } - result->value.special = ConstValSpecialStatic; + result->value->special = ConstValSpecialStatic; return result; } @@ -23620,12 +23658,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s IrInstruction *expand_mask = ir_const(ira, mask, get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); - expand_mask->value.data.x_array.data.s_none.elements = create_const_vals(len_max); + expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max); uint32_t i = 0; for (; i < len_min; i += 1) - bigint_init_unsigned(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, i); + bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i); for (; i < len_max; i += 1) - bigint_init_signed(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, -1); + bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); IrInstruction *undef = ir_const_undef(ira, source_instr, get_vector_type(ira->codegen, len_min, scalar_type)); @@ -23640,7 +23678,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb, source_instr->scope, source_instr->source_node, nullptr, a, b, mask); - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -23650,15 +23688,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn return ira->codegen->invalid_instruction; IrInstruction *a = instruction->a->child; - if (type_is_invalid(a->value.type)) + if (type_is_invalid(a->value->type)) return ira->codegen->invalid_instruction; IrInstruction *b = instruction->b->child; - if (type_is_invalid(b->value.type)) + if (type_is_invalid(b->value->type)) return ira->codegen->invalid_instruction; IrInstruction *mask = instruction->mask->child; - if (type_is_invalid(mask->value.type)) + if (type_is_invalid(mask->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask); @@ -23668,11 +23706,11 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction Error err; IrInstruction *len = instruction->len->child; - if (type_is_invalid(len->value.type)) + if (type_is_invalid(len->value->type)) return ira->codegen->invalid_instruction; IrInstruction *scalar = instruction->scalar->child; - if (type_is_invalid(scalar->value.type)) + if (type_is_invalid(scalar->value->type)) return ira->codegen->invalid_instruction; uint64_t len_u64; @@ -23680,22 +23718,22 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction return ira->codegen->invalid_instruction; uint32_t len_int = len_u64; - if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value.type))) + if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type))) return ira->codegen->invalid_instruction; - ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type); + ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); if (instr_is_comptime(scalar)) { - ConstExprValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); + ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); if (scalar_val == nullptr) return ira->codegen->invalid_instruction; if (scalar_val->special == ConstValSpecialUndef) return ir_const_undef(ira, &instruction->base, return_type); IrInstruction *result = ir_const(ira, &instruction->base, return_type); - result->value.data.x_array.data.s_none.elements = create_const_vals(len_int); + result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); for (uint32_t i = 0; i < len_int; i += 1) { - copy_const_val(&result->value.data.x_array.data.s_none.elements[i], scalar_val, false); + copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false); } return result; } @@ -23705,17 +23743,17 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; ZigType *bool_type = ira->codegen->builtin_types.entry_bool; IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_value)) { - ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad); if (value == nullptr) return ira->codegen->invalid_instruction; @@ -23724,7 +23762,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_value); - result->value.type = bool_type; + result->value->type = bool_type; return result; } @@ -23732,18 +23770,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio Error err; IrInstruction *dest_ptr = instruction->dest_ptr->child; - if (type_is_invalid(dest_ptr->value.type)) + if (type_is_invalid(dest_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *byte_value = instruction->byte->child; - if (type_is_invalid(byte_value->value.type)) + if (type_is_invalid(byte_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *count_value = instruction->count->child; - if (type_is_invalid(count_value->value.type)) + if (type_is_invalid(count_value->value->type)) return ira->codegen->invalid_instruction; - ZigType *dest_uncasted_type = dest_ptr->value.type; + ZigType *dest_uncasted_type = dest_ptr->value->type; bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && dest_uncasted_type->data.pointer.is_volatile; @@ -23760,15 +23798,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio PtrLenUnknown, dest_align, 0, 0, false); IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); - if (type_is_invalid(casted_dest_ptr->value.type)) + if (type_is_invalid(casted_dest_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); - if (type_is_invalid(casted_byte->value.type)) + if (type_is_invalid(casted_byte->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); - if (type_is_invalid(casted_count->value.type)) + if (type_is_invalid(casted_count->value->type)) return ira->codegen->invalid_instruction; // TODO test this at comptime with u8 and non-u8 types @@ -23776,22 +23814,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio instr_is_comptime(casted_byte) && instr_is_comptime(casted_count)) { - ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); + ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); if (dest_ptr_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); + ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); if (byte_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); + ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); if (count_val == nullptr) return ira->codegen->invalid_instruction; - if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr && - casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) + if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && + casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { - ConstExprValue *dest_elements; + ZigValue *dest_elements; size_t start; size_t bound_end; switch (dest_ptr_val->data.x_ptr.special) { @@ -23805,7 +23843,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio break; case ConstPtrSpecialBaseArray: { - ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; expand_undef_array(ira->codegen, array_val); dest_elements = array_val->data.x_array.data.s_none.elements; start = dest_ptr_val->data.x_ptr.data.base_array.elem_index; @@ -23845,7 +23883,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_byte, casted_count); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } @@ -23853,20 +23891,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio Error err; IrInstruction *dest_ptr = instruction->dest_ptr->child; - if (type_is_invalid(dest_ptr->value.type)) + if (type_is_invalid(dest_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *src_ptr = instruction->src_ptr->child; - if (type_is_invalid(src_ptr->value.type)) + if (type_is_invalid(src_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *count_value = instruction->count->child; - if (type_is_invalid(count_value->value.type)) + if (type_is_invalid(count_value->value->type)) return ira->codegen->invalid_instruction; ZigType *u8 = ira->codegen->builtin_types.entry_u8; - ZigType *dest_uncasted_type = dest_ptr->value.type; - ZigType *src_uncasted_type = src_ptr->value.type; + ZigType *dest_uncasted_type = dest_ptr->value->type; + ZigType *src_uncasted_type = src_ptr->value->type; bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && dest_uncasted_type->data.pointer.is_volatile; bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && @@ -23895,15 +23933,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio PtrLenUnknown, src_align, 0, 0, false); IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); - if (type_is_invalid(casted_dest_ptr->value.type)) + if (type_is_invalid(casted_dest_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); - if (type_is_invalid(casted_src_ptr->value.type)) + if (type_is_invalid(casted_src_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); - if (type_is_invalid(casted_count->value.type)) + if (type_is_invalid(casted_count->value->type)) return ira->codegen->invalid_instruction; // TODO test this at comptime with u8 and non-u8 types @@ -23912,22 +23950,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio instr_is_comptime(casted_src_ptr) && instr_is_comptime(casted_count)) { - ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); + ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); if (dest_ptr_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); + ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); if (src_ptr_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); + ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); if (count_val == nullptr) return ira->codegen->invalid_instruction; if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { size_t count = bigint_as_usize(&count_val->data.x_bigint); - ConstExprValue *dest_elements; + ZigValue *dest_elements; size_t dest_start; size_t dest_end; switch (dest_ptr_val->data.x_ptr.special) { @@ -23941,7 +23979,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio break; case ConstPtrSpecialBaseArray: { - ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; expand_undef_array(ira->codegen, array_val); dest_elements = array_val->data.x_array.data.s_none.elements; dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index; @@ -23969,7 +24007,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio return ira->codegen->invalid_instruction; } - ConstExprValue *src_elements; + ZigValue *src_elements; size_t src_start; size_t src_end; @@ -23984,7 +24022,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio break; case ConstPtrSpecialBaseArray: { - ConstExprValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val; + ZigValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val; expand_undef_array(ira->codegen, array_val); src_elements = array_val->data.x_array.data.s_none.elements; src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index; @@ -24024,35 +24062,35 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_src_ptr, casted_count); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) { IrInstruction *ptr_ptr = instruction->ptr->child; - if (type_is_invalid(ptr_ptr->value.type)) + if (type_is_invalid(ptr_ptr->value->type)) return ira->codegen->invalid_instruction; - ZigType *ptr_ptr_type = ptr_ptr->value.type; + ZigType *ptr_ptr_type = ptr_ptr->value->type; assert(ptr_ptr_type->id == ZigTypeIdPointer); ZigType *array_type = ptr_ptr_type->data.pointer.child_type; IrInstruction *start = instruction->start->child; - if (type_is_invalid(start->value.type)) + if (type_is_invalid(start->value->type)) return ira->codegen->invalid_instruction; ZigType *usize = ira->codegen->builtin_types.entry_usize; IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); - if (type_is_invalid(casted_start->value.type)) + if (type_is_invalid(casted_start->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end; if (instruction->end) { end = instruction->end->child; - if (type_is_invalid(end->value.type)) + if (type_is_invalid(end->value->type)) return ira->codegen->invalid_instruction; end = ir_implicit_cast(ira, end, usize); - if (type_is_invalid(end->value.type)) + if (type_is_invalid(end->value->type)) return ira->codegen->invalid_instruction; } else { end = nullptr; @@ -24061,8 +24099,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction ZigType *return_type; if (array_type->id == ZigTypeIdArray) { - bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && - ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; + bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic && + ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, ptr_ptr_type->data.pointer.is_const || is_comptime_const, ptr_ptr_type->data.pointer.is_volatile, @@ -24103,11 +24141,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction } if (instr_is_comptime(ptr_ptr) && - value_is_comptime(&casted_start->value) && - (!end || value_is_comptime(&end->value))) + value_is_comptime(casted_start->value) && + (!end || value_is_comptime(end->value))) { - ConstExprValue *array_val; - ConstExprValue *parent_ptr; + ZigValue *array_val; + ZigValue *parent_ptr; size_t abs_offset; size_t rel_end; bool ptr_is_undef = false; @@ -24117,7 +24155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction if (array_type->id == ZigTypeIdPointer) { ZigType *child_array_type = array_type->data.pointer.child_type; assert(child_array_type->id == ZigTypeIdArray); - parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); + parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); if (parent_ptr == nullptr) return ira->codegen->invalid_instruction; @@ -24136,7 +24174,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction abs_offset = 0; } } else { - array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); + array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); if (array_val == nullptr) return ira->codegen->invalid_instruction; rel_end = array_type->data.array.len; @@ -24145,7 +24183,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction } } else if (array_type->id == ZigTypeIdPointer) { assert(array_type->data.pointer.ptr_len == PtrLenUnknown); - parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); + parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); if (parent_ptr == nullptr) return ira->codegen->invalid_instruction; @@ -24193,7 +24231,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction zig_panic("TODO slice of null ptr"); } } else if (is_slice(array_type)) { - ConstExprValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); + ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); if (slice_ptr == nullptr) return ira->codegen->invalid_instruction; @@ -24208,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction return ira->codegen->invalid_instruction; } - ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; switch (parent_ptr->data.x_ptr.special) { case ConstPtrSpecialInvalid: @@ -24246,7 +24284,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction zig_unreachable(); } - ConstExprValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); + ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); if (!start_val) return ira->codegen->invalid_instruction; @@ -24258,7 +24296,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction uint64_t end_scalar = rel_end; if (end) { - ConstExprValue *end_val = ir_resolve_const(ira, end, UndefBad); + ZigValue *end_val = ir_resolve_const(ira, end, UndefBad); if (!end_val) return ira->codegen->invalid_instruction; end_scalar = bigint_as_u64(&end_val->data.x_bigint); @@ -24279,17 +24317,17 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction } IrInstruction *result = ir_const(ira, &instruction->base, return_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; out_val->data.x_struct.fields = alloc_const_vals_ptrs(2); - ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index]; + ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index]; if (array_val) { size_t index = abs_offset + start_scalar; bool is_const = slice_is_const(return_type); init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); if (array_type->id == ZigTypeIdArray) { - ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; + ptr_val->data.x_ptr.mut = ptr_ptr->value->data.x_ptr.mut; } else if (is_slice(array_type)) { ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; } else if (array_type->id == ZigTypeIdPointer) { @@ -24329,7 +24367,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction zig_panic("TODO"); } - ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index]; + ZigValue *len_val = out_val->data.x_struct.fields[slice_len_index]; init_const_usize(ira->codegen, len_val, end_scalar - start_scalar); return result; @@ -24337,7 +24375,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, return_type, nullptr, true, false, true); - if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { + if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { return result_loc; } return ir_build_slice_gen(ira, &instruction->base, return_type, @@ -24347,7 +24385,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { Error err; IrInstruction *container = instruction->container->child; - if (type_is_invalid(container->value.type)) + if (type_is_invalid(container->value->type)) return ira->codegen->invalid_instruction; ZigType *container_type = ir_resolve_type(ira, container); @@ -24448,7 +24486,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr TypeStructField *field = container_type->data.structure.fields[member_index]; IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - init_const_str_lit(ira->codegen, &result->value, field->name); + init_const_str_lit(ira->codegen, result->value, field->name); return result; } else if (container_type->id == ZigTypeIdEnum) { if (member_index >= container_type->data.enumeration.src_field_count) { @@ -24460,7 +24498,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - init_const_str_lit(ira->codegen, &result->value, field->name); + init_const_str_lit(ira->codegen, result->value, field->name); return result; } else if (container_type->id == ZigTypeIdUnion) { if (member_index >= container_type->data.unionation.src_field_count) { @@ -24472,7 +24510,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr TypeUnionField *field = &container_type->data.unionation.fields[member_index]; IrInstruction *result = ir_const(ira, &instruction->base, nullptr); - init_const_str_lit(ira->codegen, &result->value, field->name); + init_const_str_lit(ira->codegen, result->value, field->name); return result; } else { ir_add_error(ira, container_type_value, @@ -24512,21 +24550,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { IrInstruction *result = ir_build_breakpoint(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { IrInstruction *result = ir_build_return_address(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_usize; + result->value->type = ira->codegen->builtin_types.entry_usize; return result; } static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { IrInstruction *result = ir_build_frame_address(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_usize; + result->value->type = ira->codegen->builtin_types.entry_usize; return result; } @@ -24542,7 +24580,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - result->value.type = ptr_frame_type; + result->value->type = ptr_frame_type; return result; } @@ -24563,12 +24601,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) { IrInstruction *fn = instruction->fn->child; - if (type_is_invalid(fn->value.type)) + if (type_is_invalid(fn->value->type)) return ira->codegen->invalid_instruction; - if (fn->value.type->id != ZigTypeIdFn) { + if (fn->value->type->id != ZigTypeIdFn) { ir_add_error(ira, fn, - buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value.type->name))); + buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); return ira->codegen->invalid_instruction; } @@ -24576,7 +24614,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, instruction->base.source_node, fn); - result->value.type = ira->codegen->builtin_types.entry_usize; + result->value->type = ira->codegen->builtin_types.entry_usize; return result; } @@ -24587,11 +24625,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct // field: []align(@alignOf(Node)) Node, // }; IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1); lazy_align_of->ira = ira; - result->value.data.x_lazy = &lazy_align_of->base; + result->value->data.x_lazy = &lazy_align_of->base; lazy_align_of->base.id = LazyValueIdAlignOf; lazy_align_of->target_type = instruction->type_value->child; @@ -24605,7 +24643,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr Error err; IrInstruction *type_value = instruction->type_value->child; - if (type_is_invalid(type_value->value.type)) + if (type_is_invalid(type_value->value->type)) return ira->codegen->invalid_instruction; ZigType *dest_type = ir_resolve_type(ira, type_value); @@ -24619,15 +24657,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr } IrInstruction *op1 = instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); - if (type_is_invalid(casted_op1->value.type)) + if (type_is_invalid(casted_op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op2; @@ -24638,20 +24676,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr } else { casted_op2 = ir_implicit_cast(ira, op2, dest_type); } - if (type_is_invalid(casted_op2->value.type)) + if (type_is_invalid(casted_op2->value->type)) return ira->codegen->invalid_instruction; IrInstruction *result_ptr = instruction->result_ptr->child; - if (type_is_invalid(result_ptr->value.type)) + if (type_is_invalid(result_ptr->value->type)) return ira->codegen->invalid_instruction; ZigType *expected_ptr_type; - if (result_ptr->value.type->id == ZigTypeIdPointer) { + if (result_ptr->value->type->id == ZigTypeIdPointer) { uint32_t alignment; - if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment))) + if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment))) return ira->codegen->invalid_instruction; expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, - false, result_ptr->value.type->data.pointer.is_volatile, + false, result_ptr->value->type->data.pointer.is_volatile, PtrLenSingle, alignment, 0, 0, false); } else { @@ -24659,28 +24697,28 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr } IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); - if (type_is_invalid(casted_result_ptr->value.type)) + if (type_is_invalid(casted_result_ptr->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2) && instr_is_comptime(casted_result_ptr)) { - ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); if (op1_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); if (op2_val == nullptr) return ira->codegen->invalid_instruction; - ConstExprValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); + ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); if (result_val == nullptr) return ira->codegen->invalid_instruction; BigInt *op1_bigint = &op1_val->data.x_bigint; BigInt *op2_bigint = &op2_val->data.x_bigint; - ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, + ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, casted_result_ptr->source_node); if (pointee_val == nullptr) return ira->codegen->invalid_instruction; @@ -24716,12 +24754,12 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr IrInstruction *result = ir_build_overflow_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); - result->value.type = ira->codegen->builtin_types.entry_bool; + result->value->type = ira->codegen->builtin_types.entry_bool; return result; } static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type, - ConstExprValue *op1, ConstExprValue *op2, ConstExprValue *op3, ConstExprValue *out_val) { + ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) { if (float_type->id == ZigTypeIdComptimeFloat) { f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value, &op3->data.x_bigfloat.value); @@ -24749,7 +24787,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) { IrInstruction *type_value = instruction->type_value->child; - if (type_is_invalid(type_value->value.type)) + if (type_is_invalid(type_value->value->type)) return ira->codegen->invalid_instruction; ZigType *expr_type = ir_resolve_type(ira, type_value); @@ -24765,44 +24803,44 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi } IrInstruction *op1 = instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type); - if (type_is_invalid(casted_op1->value.type)) + if (type_is_invalid(casted_op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op2 = instruction->op2->child; - if (type_is_invalid(op2->value.type)) + if (type_is_invalid(op2->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type); - if (type_is_invalid(casted_op2->value.type)) + if (type_is_invalid(casted_op2->value->type)) return ira->codegen->invalid_instruction; IrInstruction *op3 = instruction->op3->child; - if (type_is_invalid(op3->value.type)) + if (type_is_invalid(op3->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type); - if (type_is_invalid(casted_op3->value.type)) + if (type_is_invalid(casted_op3->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2) && instr_is_comptime(casted_op3)) { - ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); if (!op1_const) return ira->codegen->invalid_instruction; - ConstExprValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); + ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); if (!op2_const) return ira->codegen->invalid_instruction; - ConstExprValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); + ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); if (!op3_const) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, expr_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; if (expr_type->id == ZigTypeIdVector) { expand_undef_array(ira->codegen, op1_const); @@ -24812,10 +24850,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi expand_undef_array(ira->codegen, out_val); size_t len = expr_type->data.vector.len; for (size_t i = 0; i < len; i += 1) { - ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; - ConstExprValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i]; - ConstExprValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i]; - ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; + ZigValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i]; + ZigValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i]; + ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; assert(float_operand_op1->type == float_type); assert(float_operand_op2->type == float_type); assert(float_operand_op3->type == float_type); @@ -24835,13 +24873,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi IrInstruction *result = ir_build_mul_add(&ira->new_irb, instruction->base.scope, instruction->base.source_node, type_value, casted_op1, casted_op2, casted_op3); - result->value.type = expr_type; + result->value->type = expr_type; return result; } static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { IrInstruction *base_ptr = instruction->base_ptr->child; - if (type_is_invalid(base_ptr->value.type)) + if (type_is_invalid(base_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *value; @@ -24851,12 +24889,12 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); } - ZigType *type_entry = value->value.type; + ZigType *type_entry = value->value->type; if (type_is_invalid(type_entry)) return ira->codegen->invalid_instruction; if (type_entry->id == ZigTypeIdErrorUnion) { if (instr_is_comptime(value)) { - ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); + ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad); if (!err_union_val) return ira->codegen->invalid_instruction; @@ -24890,7 +24928,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *base_ptr, bool initializing) { - ZigType *ptr_type = base_ptr->value.type; + ZigType *ptr_type = base_ptr->value->type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. assert(ptr_type->id == ZigTypeIdPointer); @@ -24911,20 +24949,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * ptr_type->data.pointer.explicit_alignment, 0, 0, false); if (instr_is_comptime(base_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { - ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); + ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); if (err_union_val == nullptr) return ira->codegen->invalid_instruction; if (initializing && err_union_val->special == ConstValSpecialUndef) { - ConstExprValue *vals = create_const_vals(2); - ConstExprValue *err_set_val = &vals[0]; - ConstExprValue *payload_val = &vals[1]; + ZigValue *vals = create_const_vals(2); + ZigValue *err_set_val = &vals[0]; + ZigValue *payload_val = &vals[1]; err_set_val->special = ConstValSpecialUndef; err_set_val->type = err_set_type; @@ -24946,12 +24984,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr); - result->value.type = result_type; - result->value.special = ConstValSpecialStatic; + result->value->type = result_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, source_instr, result_type); } - ConstExprValue *const_val = &result->value; + ZigValue *const_val = result->value; const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode; const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val; const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; @@ -24961,7 +24999,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr); - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -24969,7 +25007,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstructionUnwrapErrCode *instruction) { IrInstruction *base_ptr = instruction->err_union_ptr->child; - if (type_is_invalid(base_ptr->value.type)) + if (type_is_invalid(base_ptr->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false); } @@ -24977,7 +25015,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *base_ptr, bool safety_check_on, bool initializing) { - ZigType *ptr_type = base_ptr->value.type; + ZigType *ptr_type = base_ptr->value->type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. assert(ptr_type->id == ZigTypeIdPointer); @@ -25000,17 +25038,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false); if (instr_is_comptime(base_ptr)) { - ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); + ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); if (!ptr_val) return ira->codegen->invalid_instruction; if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { - ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); + ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); if (err_union_val == nullptr) return ira->codegen->invalid_instruction; if (initializing && err_union_val->special == ConstValSpecialUndef) { - ConstExprValue *vals = create_const_vals(2); - ConstExprValue *err_set_val = &vals[0]; - ConstExprValue *payload_val = &vals[1]; + ZigValue *vals = create_const_vals(2); + ZigValue *err_set_val = &vals[0]; + ZigValue *payload_val = &vals[1]; err_set_val->special = ConstValSpecialStatic; err_set_val->type = type_entry->data.error_union.err_set_type; @@ -25036,14 +25074,14 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr, safety_check_on, initializing); - result->value.type = result_type; - result->value.special = ConstValSpecialStatic; + result->value->type = result_type; + result->value->special = ConstValSpecialStatic; } else { result = ir_const(ira, source_instr, result_type); } - result->value.data.x_ptr.special = ConstPtrSpecialRef; - result->value.data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; - result->value.data.x_ptr.mut = ptr_val->data.x_ptr.mut; + result->value->data.x_ptr.special = ConstPtrSpecialRef; + result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; + result->value->data.x_ptr.mut = ptr_val->data.x_ptr.mut; return result; } } @@ -25051,7 +25089,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, source_instr->source_node, base_ptr, safety_check_on, initializing); - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -25060,7 +25098,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, { assert(instruction->value->child); IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false); @@ -25071,11 +25109,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct assert(proto_node->type == NodeTypeFnProto); IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1); lazy_fn_type->ira = ira; - result->value.data.x_lazy = &lazy_fn_type->base; + result->value->data.x_lazy = &lazy_fn_type->base; lazy_fn_type->base.id = LazyValueIdFnType; if (proto_node->data.fn_proto.auto_err_set) { @@ -25110,7 +25148,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct } IrInstruction *param_type_value = instruction->param_types[param_index]->child; - if (type_is_invalid(param_type_value->value.type)) + if (type_is_invalid(param_type_value->value->type)) return ira->codegen->invalid_instruction; if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr) return ira->codegen->invalid_instruction; @@ -25132,7 +25170,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); @@ -25142,7 +25180,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstructionCheckSwitchProngs *instruction) { IrInstruction *target_value = instruction->target_value->child; - ZigType *switch_type = target_value->value.type; + ZigType *switch_type = target_value->value->type; if (type_is_invalid(switch_type)) return ira->codegen->invalid_instruction; @@ -25154,25 +25192,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; IrInstruction *start_value_uncasted = range->start->child; - if (type_is_invalid(start_value_uncasted->value.type)) + if (type_is_invalid(start_value_uncasted->value->type)) return ira->codegen->invalid_instruction; IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); - if (type_is_invalid(start_value->value.type)) + if (type_is_invalid(start_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end_value_uncasted = range->end->child; - if (type_is_invalid(end_value_uncasted->value.type)) + if (type_is_invalid(end_value_uncasted->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); - if (type_is_invalid(end_value->value.type)) + if (type_is_invalid(end_value->value->type)) return ira->codegen->invalid_instruction; BigInt start_index; - bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); + bigint_init_bigint(&start_index, &start_value->value->data.x_enum_tag); - assert(end_value->value.type->id == ZigTypeIdEnum); + assert(end_value->value->type->id == ZigTypeIdEnum); BigInt end_index; - bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); + bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); BigInt field_index; bigint_init_bigint(&field_index, &start_index); @@ -25218,24 +25256,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; IrInstruction *start_value_uncasted = range->start->child; - if (type_is_invalid(start_value_uncasted->value.type)) + if (type_is_invalid(start_value_uncasted->value->type)) return ira->codegen->invalid_instruction; IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); - if (type_is_invalid(start_value->value.type)) + if (type_is_invalid(start_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end_value_uncasted = range->end->child; - if (type_is_invalid(end_value_uncasted->value.type)) + if (type_is_invalid(end_value_uncasted->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); - if (type_is_invalid(end_value->value.type)) + if (type_is_invalid(end_value->value->type)) return ira->codegen->invalid_instruction; - ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); - uint32_t start_index = start_value->value.data.x_err_set->value; + ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); + uint32_t start_index = start_value->value->data.x_err_set->value; - ir_assert(end_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); - uint32_t end_index = end_value->value.data.x_err_set->value; + ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); + uint32_t end_index = end_value->value->data.x_err_set->value; if (start_index != end_index) { ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); @@ -25276,24 +25314,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; IrInstruction *start_value = range->start->child; - if (type_is_invalid(start_value->value.type)) + if (type_is_invalid(start_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); - if (type_is_invalid(casted_start_value->value.type)) + if (type_is_invalid(casted_start_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *end_value = range->end->child; - if (type_is_invalid(end_value->value.type)) + if (type_is_invalid(end_value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); - if (type_is_invalid(casted_end_value->value.type)) + if (type_is_invalid(casted_end_value->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); + ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); if (!start_val) return ira->codegen->invalid_instruction; - ConstExprValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); + ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); if (!end_val) return ira->codegen->invalid_instruction; @@ -25326,10 +25364,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstruction *value = range->start->child; IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return ira->codegen->invalid_instruction; - ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); + ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); if (!const_expr_val) return ira->codegen->invalid_instruction; @@ -25362,7 +25400,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * IrInstructionCheckStatementIsVoid *instruction) { IrInstruction *statement_value = instruction->statement_value->child; - ZigType *statement_type = statement_value->value.type; + ZigType *statement_type = statement_value->value->type; if (type_is_invalid(statement_type)) return ira->codegen->invalid_instruction; @@ -25375,7 +25413,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { IrInstruction *msg = instruction->msg->child; - if (type_is_invalid(msg->value.type)) + if (type_is_invalid(msg->value->type)) return ir_unreach_error(ira); if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) { @@ -25387,7 +25425,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction true, false, PtrLenUnknown, 0, 0, 0, false); ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); - if (type_is_invalid(casted_msg->value.type)) + if (type_is_invalid(casted_msg->value->type)) return ir_unreach_error(ira); IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, @@ -25398,7 +25436,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { Error err; - ZigType *target_type = target->value.type; + ZigType *target_type = target->value->type; assert(!type_is_invalid(target_type)); ZigType *result_type; @@ -25443,7 +25481,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 } if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -25457,8 +25495,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 } IrInstruction *result = ir_const(ira, target, result_type); - copy_const_val(&result->value, val, true); - result->value.type = result_type; + copy_const_val(result->value, val, true); + result->value->type = result_type; return result; } @@ -25468,7 +25506,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 } else { result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop); } - result->value.type = result_type; + result->value->type = result_type; return result; } @@ -25477,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ { Error err; - ZigType *src_type = ptr->value.type; + ZigType *src_type = ptr->value->type; assert(!type_is_invalid(src_type)); if (src_type == dest_type) { @@ -25515,7 +25553,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ if (instr_is_comptime(ptr)) { bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type); UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; - ConstExprValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); + ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); if (!val) return ira->codegen->invalid_instruction; @@ -25531,7 +25569,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ } IrInstruction *result; - if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { + if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) @@ -25539,8 +25577,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ } else { result = ir_const(ira, source_instr, dest_type); } - copy_const_val(&result->value, val, true); - result->value.type = dest_type; + copy_const_val(result->value, val, true); + result->value->type = dest_type; // Keep the bigger alignment, it can only help- // unless the target is zero bits. @@ -25584,7 +25622,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ IrInstruction *result; if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); - if (type_is_invalid(result->value.type)) + if (type_is_invalid(result->value->type)) return ira->codegen->invalid_instruction; } else { result = casted_ptr; @@ -25599,7 +25637,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; IrInstruction *ptr = instruction->ptr->child; - ZigType *src_type = ptr->value.type; + ZigType *src_type = ptr->value->type; if (type_is_invalid(src_type)) return ira->codegen->invalid_instruction; @@ -25607,18 +25645,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct instruction->safety_check_on); } -static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ConstExprValue *val, size_t len) { +static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { size_t buf_i = 0; // TODO optimize the buf case expand_undef_array(codegen, val); for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) { - ConstExprValue *elem = &val->data.x_array.data.s_none.elements[elem_i]; + ZigValue *elem = &val->data.x_array.data.s_none.elements[elem_i]; buf_write_value_bytes(codegen, &buf[buf_i], elem); buf_i += type_size(codegen, elem->type); } } -static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { +static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) { if (val->special == ConstValSpecialUndef) { expand_undef_struct(codegen, val); val->special = ConstValSpecialStatic; @@ -25679,7 +25717,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue TypeStructField *struct_field = val->type->data.structure.fields[field_i]; if (struct_field->gen_index == SIZE_MAX) continue; - ConstExprValue *field_val = val->data.x_struct.fields[field_i]; + ZigValue *field_val = val->data.x_struct.fields[field_i]; size_t offset = struct_field->offset; buf_write_value_bytes(codegen, buf + offset, field_val); } @@ -25754,7 +25792,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue } static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, - ConstExprValue *val, ZigType *elem_type, size_t len) + ZigValue *val, ZigType *elem_type, size_t len) { Error err; uint64_t elem_size = type_size(codegen, elem_type); @@ -25763,7 +25801,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod case ConstArraySpecialNone: val->data.x_array.data.s_none.elements = create_const_vals(len); for (size_t i = 0; i < len; i++) { - ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i]; + ZigValue *elem = &val->data.x_array.data.s_none.elements[i]; elem->special = ConstValSpecialStatic; elem->type = elem_type; if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem))) @@ -25778,7 +25816,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod zig_unreachable(); } -static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) { +static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val) { Error err; src_assert(val->special == ConstValSpecialStatic, source_node); switch (val->type->id) { @@ -25850,7 +25888,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou size_t src_field_count = val->type->data.structure.src_field_count; val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count); for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { - ConstExprValue *field_val = val->data.x_struct.fields[field_i]; + ZigValue *field_val = val->data.x_struct.fields[field_i]; field_val->special = ConstValSpecialStatic; TypeStructField *struct_field = val->type->data.structure.fields[field_i]; field_val->type = struct_field->type_entry; @@ -25887,7 +25925,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou src_assert(field->gen_index != SIZE_MAX, source_node); if (field->gen_index != gen_i) break; - ConstExprValue *field_val = val->data.x_struct.fields[src_i]; + ZigValue *field_val = val->data.x_struct.fields[src_i]; field_val->special = ConstValSpecialStatic; field_val->type = field->type_entry; uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry); @@ -25941,7 +25979,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ { Error err; - ZigType *src_type = value->value.type; + ZigType *src_type = value->value->type; ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr); ir_assert(type_can_bit_cast(src_type), source_instr); ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr); @@ -25975,14 +26013,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ } if (instr_is_comptime(value)) { - ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); + ZigValue *val = ir_resolve_const(ira, value, UndefBad); if (!val) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, source_instr, dest_type); uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); buf_write_value_bytes(ira->codegen, buf, val); - if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, &result->value))) + if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) return ira->codegen->invalid_instruction; return result; } @@ -25997,11 +26035,11 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc ir_assert(type_has_bits(ptr_type), source_instr); IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); - if (type_is_invalid(casted_int->value.type)) + if (type_is_invalid(casted_int->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_int)) { - ConstExprValue *val = ir_resolve_const(ira, casted_int, UndefBad); + ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad); if (!val) return ira->codegen->invalid_instruction; @@ -26013,15 +26051,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc } IrInstruction *result = ir_const(ira, source_instr, ptr_type); - result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; - result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; - result->value.data.x_ptr.data.hard_coded_addr.addr = addr; + result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; + result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; + result->value->data.x_ptr.data.hard_coded_addr.addr = addr; return result; } IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, nullptr, casted_int); - result->value.type = ptr_type; + result->value->type = ptr_type; return result; } @@ -26048,7 +26086,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type); @@ -26058,7 +26096,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstructionDeclRef *instruction) { IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); - if (type_is_invalid(ref_instruction->value.type)) { + if (type_is_invalid(ref_instruction->value->type)) { return ira->codegen->invalid_instruction; } @@ -26072,51 +26110,51 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { Error err; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; ZigType *usize = ira->codegen->builtin_types.entry_usize; // We check size explicitly so we can use get_src_ptr_type here. - if (get_src_ptr_type(target->value.type) == nullptr) { + if (get_src_ptr_type(target->value->type) == nullptr) { ir_add_error(ira, target, - buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); + buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); return ira->codegen->invalid_instruction; } - if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) + if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; - if (!type_has_bits(target->value.type)) { + if (!type_has_bits(target->value->type)) { ir_add_error(ira, target, buf_sprintf("pointer to size 0 type has no address")); return ira->codegen->invalid_instruction; } if (instr_is_comptime(target)) { - ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); + ZigValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { IrInstruction *result = ir_const(ira, &instruction->base, usize); - bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); - result->value.type = usize; + bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); + result->value->type = usize; return result; } } IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, instruction->base.source_node, target); - result->value.type = usize; + result->value->type = usize; return result; } static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); - result->value.special = ConstValSpecialLazy; + result->value->special = ConstValSpecialLazy; LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1); lazy_ptr_type->ira = ira; - result->value.data.x_lazy = &lazy_ptr_type->base; + result->value->data.x_lazy = &lazy_ptr_type->base; lazy_ptr_type->base.id = LazyValueIdPtrType; if (instruction->sentinel != nullptr) { @@ -26147,15 +26185,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; ZigType *elem_type = nullptr; - if (is_slice(target->value.type)) { - ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; + if (is_slice(target->value->type)) { + ZigType *slice_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; elem_type = slice_ptr_type->data.pointer.child_type; - } else if (target->value.type->id == ZigTypeIdPointer) { - elem_type = target->value.type->data.pointer.child_type; + } else if (target->value->type->id == ZigTypeIdPointer) { + elem_type = target->value->type->data.pointer.child_type; } uint32_t align_bytes; @@ -26164,7 +26202,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru return ira->codegen->invalid_instruction; IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); - if (type_is_invalid(result->value.type)) + if (type_is_invalid(result->value->type)) return ira->codegen->invalid_instruction; return result; @@ -26350,13 +26388,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru return ira->codegen->invalid_instruction; IrInstruction *ptr_inst = instruction->ptr->child; - if (type_is_invalid(ptr_inst->value.type)) + if (type_is_invalid(ptr_inst->value->type)) return ira->codegen->invalid_instruction; // TODO let this be volatile ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); - if (type_is_invalid(casted_ptr->value.type)) + if (type_is_invalid(casted_ptr->value->type)) return ira->codegen->invalid_instruction; AtomicRmwOp op; @@ -26375,11 +26413,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru } IrInstruction *operand = instruction->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); - if (type_is_invalid(casted_operand->value.type)) + if (type_is_invalid(casted_operand->value->type)) return ira->codegen->invalid_instruction; AtomicOrder ordering; @@ -26395,7 +26433,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru } } - if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) + if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) { zig_panic("TODO compile-time execution of atomicRmw"); } @@ -26403,7 +26441,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, op, ordering); - result->value.type = operand_type; + result->value->type = operand_type; return result; } @@ -26413,12 +26451,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr return ira->codegen->invalid_instruction; IrInstruction *ptr_inst = instruction->ptr->child; - if (type_is_invalid(ptr_inst->value.type)) + if (type_is_invalid(ptr_inst->value->type)) return ira->codegen->invalid_instruction; ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); - if (type_is_invalid(casted_ptr->value.type)) + if (type_is_invalid(casted_ptr->value->type)) return ira->codegen->invalid_instruction; AtomicOrder ordering; @@ -26438,13 +26476,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr if (instr_is_comptime(casted_ptr)) { IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr); - ir_assert(result->value.type != nullptr, &instruction->base); + ir_assert(result->value->type != nullptr, &instruction->base); return result; } IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); - result->value.type = operand_type; + result->value->type = operand_type; return result; } @@ -26454,20 +26492,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst return ira->codegen->invalid_instruction; IrInstruction *ptr_inst = instruction->ptr->child; - if (type_is_invalid(ptr_inst->value.type)) + if (type_is_invalid(ptr_inst->value->type)) return ira->codegen->invalid_instruction; ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); - if (type_is_invalid(casted_ptr->value.type)) + if (type_is_invalid(casted_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type); - if (type_is_invalid(casted_value->value.type)) + if (type_is_invalid(casted_value->value->type)) return ira->codegen->invalid_instruction; @@ -26488,25 +26526,25 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - result->value.type = ira->codegen->builtin_types.entry_void; + result->value->type = ira->codegen->builtin_types.entry_void; return result; } static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type, - ConstExprValue *op, ConstExprValue *out_val) { + ZigValue *op, ZigValue *out_val) { assert(ira && source_instr && float_type && out_val && op); assert(float_type->id == ZigTypeIdFloat || float_type->id == ZigTypeIdComptimeFloat); @@ -26687,7 +26725,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) { IrInstruction *type = instruction->type->child; - if (type_is_invalid(type->value.type)) + if (type_is_invalid(type->value->type)) return ira->codegen->invalid_instruction; ZigType *expr_type = ir_resolve_type(ira, type); @@ -26702,11 +26740,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct } IrInstruction *op1 = instruction->op1->child; - if (type_is_invalid(op1->value.type)) + if (type_is_invalid(op1->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type); - if (type_is_invalid(casted_op1->value.type)) + if (type_is_invalid(casted_op1->value->type)) return ira->codegen->invalid_instruction; if (instr_is_comptime(casted_op1)) { @@ -26719,12 +26757,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; } - ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); + ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); if (!op1_const) return ira->codegen->invalid_instruction; IrInstruction *result = ir_const(ira, &instruction->base, expr_type); - ConstExprValue *out_val = &result->value; + ZigValue *out_val = result->value; if (expr_type->id == ZigTypeIdVector) { expand_undef_array(ira->codegen, op1_const); @@ -26732,8 +26770,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct expand_undef_array(ira->codegen, out_val); size_t len = expr_type->data.vector.len; for (size_t i = 0; i < len; i += 1) { - ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; - ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; + ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; + ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; assert(float_operand_op1->type == float_type); assert(float_out_val->type == float_type); ir_eval_float_op(ira, instruction, float_type, @@ -26752,7 +26790,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, casted_op1, instruction->op); - result->value.type = expr_type; + result->value->type = expr_type; return result; } @@ -26764,16 +26802,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction return ira->codegen->invalid_instruction; IrInstruction *uncasted_op = instruction->op->child; - if (type_is_invalid(uncasted_op->value.type)) + if (type_is_invalid(uncasted_op->value->type)) return ira->codegen->invalid_instruction; uint32_t vector_len; // UINT32_MAX means not a vector - if (uncasted_op->value.type->id == ZigTypeIdArray && - is_valid_vector_elem_type(uncasted_op->value.type->data.array.child_type)) + if (uncasted_op->value->type->id == ZigTypeIdArray && + is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type)) { - vector_len = uncasted_op->value.type->data.array.len; - } else if (uncasted_op->value.type->id == ZigTypeIdVector) { - vector_len = uncasted_op->value.type->data.vector.len; + vector_len = uncasted_op->value->type->data.array.len; + } else if (uncasted_op->value->type->id == ZigTypeIdVector) { + vector_len = uncasted_op->value->type->data.vector.len; } else { vector_len = UINT32_MAX; } @@ -26782,7 +26820,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type; IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type); - if (type_is_invalid(op->value.type)) + if (type_is_invalid(op->value->type)) return ira->codegen->invalid_instruction; if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0) @@ -26796,7 +26834,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction } if (instr_is_comptime(op)) { - ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); + ZigValue *val = ir_resolve_const(ira, op, UndefOk); if (val == nullptr) return ira->codegen->invalid_instruction; if (val->special == ConstValSpecialUndef) @@ -26807,28 +26845,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction uint8_t *buf = allocate_nonzero<uint8_t>(buf_size); if (is_vector) { expand_undef_array(ira->codegen, val); - result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); + result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { - ConstExprValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; + ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, op_elem_val, UndefOk))) { return ira->codegen->invalid_instruction; } - ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; + ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; result_elem_val->type = int_type; result_elem_val->special = op_elem_val->special; if (op_elem_val->special == ConstValSpecialUndef) continue; bigint_write_twos_complement(&op_elem_val->data.x_bigint, buf, int_type->data.integral.bit_count, true); - bigint_read_twos_complement(&result->value.data.x_array.data.s_none.elements[i].data.x_bigint, + bigint_read_twos_complement(&result->value->data.x_array.data.s_none.elements[i].data.x_bigint, buf, int_type->data.integral.bit_count, false, int_type->data.integral.is_signed); } } else { bigint_write_twos_complement(&val->data.x_bigint, buf, int_type->data.integral.bit_count, true); - bigint_read_twos_complement(&result->value.data.x_bigint, buf, int_type->data.integral.bit_count, false, + bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false, int_type->data.integral.is_signed); } free(buf); @@ -26837,7 +26875,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, op); - result->value.type = op_type; + result->value->type = op_type; return result; } @@ -26847,17 +26885,17 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr return ira->codegen->invalid_instruction; IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); - if (type_is_invalid(op->value.type)) + if (type_is_invalid(op->value->type)) return ira->codegen->invalid_instruction; if (int_type->data.integral.bit_count == 0) { IrInstruction *result = ir_const(ira, &instruction->base, int_type); - bigint_init_unsigned(&result->value.data.x_bigint, 0); + bigint_init_unsigned(&result->value->data.x_bigint, 0); return result; } if (instr_is_comptime(op)) { - ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); + ZigValue *val = ir_resolve_const(ira, op, UndefOk); if (val == nullptr) return ira->codegen->invalid_instruction; if (val->special == ConstValSpecialUndef) @@ -26881,7 +26919,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr } } - bigint_read_twos_complement(&result->value.data.x_bigint, + bigint_read_twos_complement(&result->value->data.x_bigint, result_buf, int_type->data.integral.bit_count, ira->codegen->is_big_endian, @@ -26892,14 +26930,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope, instruction->base.source_node, nullptr, op); - result->value.type = int_type; + result->value->type = int_type; return result; } static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_enum_to_int(ira, &instruction->base, target); @@ -26924,11 +26962,11 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr ZigType *tag_type = dest_type->data.enumeration.tag_int_type; IrInstruction *target = instruction->target->child; - if (type_is_invalid(target->value.type)) + if (type_is_invalid(target->value->type)) return ira->codegen->invalid_instruction; IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); - if (type_is_invalid(casted_target->value.type)) + if (type_is_invalid(casted_target->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); @@ -26995,33 +27033,33 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { IrInstruction *value = instruction->value->child; - if (type_is_invalid(value->value.type)) + if (type_is_invalid(value->value->type)) return ira->codegen->invalid_instruction; bool was_written = instruction->result_loc->written; IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, - value->value.type, value, false, false, true); + value->value->type, value, false, false, true); if (result_loc != nullptr) { - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return ira->codegen->invalid_instruction; - if (result_loc->value.type->id == ZigTypeIdUnreachable) + if (result_loc->value->type->id == ZigTypeIdUnreachable) return result_loc; if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, instruction->result_loc->allow_write_through_const); - if (type_is_invalid(store_ptr->value.type)) { + if (type_is_invalid(store_ptr->value->type)) { return ira->codegen->invalid_instruction; } } - if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer && + if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer && instruction->result_loc->id != ResultLocIdPeer) { if (instr_is_comptime(value)) { - result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst; + result_loc->value->data.x_ptr.mut = ConstPtrMutComptimeConst; } else { - result_loc->value.special = ConstValSpecialRuntime; + result_loc->value->special = ConstValSpecialRuntime; } } } @@ -27031,12 +27069,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { IrInstruction *operand = instruction->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return operand; IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, - &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true); - if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) + &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); + if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) return result_loc; if (instruction->result_loc_cast->parent->gen_instruction != nullptr) { @@ -27051,12 +27089,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { IrInstruction *operand = instruction->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return operand; IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, - &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false, true); - if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) + &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); + if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) return result_loc; if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { @@ -27084,11 +27122,11 @@ static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *i return ira->codegen->invalid_instruction; IrInstruction *field_result_loc = instruction->field_result_loc->child; - if (type_is_invalid(field_result_loc->value.type)) + if (type_is_invalid(field_result_loc->value->type)) return ira->codegen->invalid_instruction; IrInstruction *result_loc = instruction->result_loc->child; - if (type_is_invalid(result_loc->value.type)) + if (type_is_invalid(result_loc->value->type)) return ira->codegen->invalid_instruction; return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node, @@ -27105,7 +27143,7 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstructionSuspendFinish *instruction) { IrInstruction *begin_base = instruction->begin->base.child; - if (type_is_invalid(begin_base->value.type)) + if (type_is_invalid(begin_base->value->type)) return ira->codegen->invalid_instruction; ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base); IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base); @@ -27123,44 +27161,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *frame_ptr, ZigFn **target_fn) { - if (type_is_invalid(frame_ptr->value.type)) + if (type_is_invalid(frame_ptr->value->type)) return ira->codegen->invalid_instruction; *target_fn = nullptr; ZigType *result_type; IrInstruction *frame; - if (frame_ptr->value.type->id == ZigTypeIdPointer && - frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && - frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) + if (frame_ptr->value->type->id == ZigTypeIdPointer && + frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && + frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) { - ZigFn *func = frame_ptr->value.type->data.pointer.child_type->data.frame.fn; + ZigFn *func = frame_ptr->value->type->data.pointer.child_type->data.frame.fn; result_type = func->type_entry->data.fn.fn_type_id.return_type; *target_fn = func; frame = frame_ptr; } else { frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr); - if (frame->value.type->id == ZigTypeIdPointer && - frame->value.type->data.pointer.ptr_len == PtrLenSingle && - frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) + if (frame->value->type->id == ZigTypeIdPointer && + frame->value->type->data.pointer.ptr_len == PtrLenSingle && + frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) { - ZigFn *func = frame->value.type->data.pointer.child_type->data.frame.fn; + ZigFn *func = frame->value->type->data.pointer.child_type->data.frame.fn; result_type = func->type_entry->data.fn.fn_type_id.return_type; *target_fn = func; - } else if (frame->value.type->id != ZigTypeIdAnyFrame || - frame->value.type->data.any_frame.result_type == nullptr) + } else if (frame->value->type->id != ZigTypeIdAnyFrame || + frame->value->type->data.any_frame.result_type == nullptr) { ir_add_error(ira, source_instr, - buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value.type->name))); + buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); return ira->codegen->invalid_instruction; } else { - result_type = frame->value.type->data.any_frame.result_type; + result_type = frame->value->type->data.any_frame.result_type; } } ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type); IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); - if (type_is_invalid(casted_frame->value.type)) + if (type_is_invalid(casted_frame->value->type)) return ira->codegen->invalid_instruction; return casted_frame; @@ -27168,14 +27206,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) { IrInstruction *operand = instruction->frame->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return ira->codegen->invalid_instruction; ZigFn *target_fn; IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn); - if (type_is_invalid(frame->value.type)) + if (type_is_invalid(frame->value->type)) return ira->codegen->invalid_instruction; - ZigType *result_type = frame->value.type->data.any_frame.result_type; + ZigType *result_type = frame->value->type->data.any_frame.result_type; ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); ir_assert(fn_entry != nullptr, &instruction->base); @@ -27195,7 +27233,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction if (type_has_bits(result_type)) { result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, result_type, nullptr, true, true, true); - if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) + if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) return result_loc; } else { result_loc = nullptr; @@ -27209,13 +27247,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) { IrInstruction *frame_ptr = instruction->frame->child; - if (type_is_invalid(frame_ptr->value.type)) + if (type_is_invalid(frame_ptr->value->type)) return ira->codegen->invalid_instruction; IrInstruction *frame; - if (frame_ptr->value.type->id == ZigTypeIdPointer && - frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && - frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) + if (frame_ptr->value->type->id == ZigTypeIdPointer && + frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && + frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) { frame = frame_ptr; } else { @@ -27224,7 +27262,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); - if (type_is_invalid(casted_frame->value.type)) + if (type_is_invalid(casted_frame->value->type)) return ira->codegen->invalid_instruction; return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame); @@ -27235,10 +27273,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr return ir_const_void(ira, &instruction->base); IrInstruction *operand = instruction->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return ira->codegen->invalid_instruction; - if (!type_has_bits(operand->value.type)) + if (!type_has_bits(operand->value->type)) return ir_const_void(ira, &instruction->base); ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base); @@ -27251,10 +27289,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) { IrInstruction *operand = instruction->begin->operand->child; - if (type_is_invalid(operand->value.type)) + if (type_is_invalid(operand->value->type)) return ira->codegen->invalid_instruction; - if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value.type)) + if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type)) return operand; ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base); @@ -27262,7 +27300,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin); - result->value.type = operand->value.type; + result->value->type = operand->value->type; return result; } @@ -27601,7 +27639,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ ira->new_irb.codegen = codegen; ira->new_irb.exec = new_exec; - ConstExprValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); + ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { ira->exec_context.mem_slot_list.items[i] = &vals[i]; @@ -27628,10 +27666,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ } IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); if (new_instruction != nullptr) { - ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); + ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction); old_instruction->child = new_instruction; - if (type_is_invalid(new_instruction->value.type)) { + if (type_is_invalid(new_instruction->value->type)) { if (new_exec->first_err_trace_msg != nullptr) { ira->codegen->trace_err = new_exec->first_err_trace_msg; } else { @@ -27648,7 +27686,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ } // unreachable instructions do their own control flow. - if (new_instruction->value.type->id == ZigTypeIdUnreachable) + if (new_instruction->value->type->id == ZigTypeIdUnreachable) continue; } @@ -27947,7 +27985,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La return get_fn_type(ira->codegen, &fn_type_id); } -static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { +static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { Error err; if (val->special != ConstValSpecialLazy) return ErrorNone; @@ -27958,8 +27996,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy); IrAnalyze *ira = lazy_align_of->ira; - if (lazy_align_of->target_type->value.special == ConstValSpecialStatic) { - switch (lazy_align_of->target_type->value.data.x_type->id) { + if (lazy_align_of->target_type->value->special == ConstValSpecialStatic) { + switch (lazy_align_of->target_type->value->data.x_type->id) { case ZigTypeIdInvalid: zig_unreachable(); case ZigTypeIdMetaType: @@ -27975,7 +28013,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { case ZigTypeIdOpaque: ir_add_error(ira, lazy_align_of->target_type, buf_sprintf("no align available for type '%s'", - buf_ptr(&lazy_align_of->target_type->value.data.x_type->name))); + buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); return ErrorSemanticAnalyzeFail; case ZigTypeIdBool: case ZigTypeIdInt: @@ -27997,7 +28035,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { } uint32_t align_in_bytes; - if ((err = type_val_resolve_abi_align(ira->codegen, &lazy_align_of->target_type->value, + if ((err = type_val_resolve_abi_align(ira->codegen, lazy_align_of->target_type->value, &align_in_bytes))) { return err; @@ -28012,8 +28050,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); IrAnalyze *ira = lazy_size_of->ira; - if (lazy_size_of->target_type->value.special == ConstValSpecialStatic) { - switch (lazy_size_of->target_type->value.data.x_type->id) { + if (lazy_size_of->target_type->value->special == ConstValSpecialStatic) { + switch (lazy_size_of->target_type->value->data.x_type->id) { case ZigTypeIdInvalid: // handled above zig_unreachable(); case ZigTypeIdUnreachable: @@ -28024,7 +28062,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { case ZigTypeIdOpaque: ir_add_error(ira, lazy_size_of->target_type, buf_sprintf("no size available for type '%s'", - buf_ptr(&lazy_size_of->target_type->value.data.x_type->name))); + buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); return ErrorSemanticAnalyzeFail; case ZigTypeIdMetaType: case ZigTypeIdEnumLiteral: @@ -28052,7 +28090,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { size_t abi_size; size_t size_in_bits; - if ((err = type_val_resolve_abi_size(ira->codegen, source_node, &lazy_size_of->target_type->value, + if ((err = type_val_resolve_abi_size(ira->codegen, source_node, lazy_size_of->target_type->value, &abi_size, &size_in_bits))) { return err; @@ -28071,12 +28109,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { if (type_is_invalid(elem_type)) return ErrorSemanticAnalyzeFail; - ConstExprValue *sentinel_val; + ZigValue *sentinel_val; if (lazy_slice_type->sentinel != nullptr) { - if (type_is_invalid(lazy_slice_type->sentinel->value.type)) + if (type_is_invalid(lazy_slice_type->sentinel->value->type)) return ErrorSemanticAnalyzeFail; IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); - if (type_is_invalid(sentinel->value.type)) + if (type_is_invalid(sentinel->value->type)) return ErrorSemanticAnalyzeFail; sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); if (sentinel_val == nullptr) @@ -28149,12 +28187,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { if (type_is_invalid(elem_type)) return ErrorSemanticAnalyzeFail; - ConstExprValue *sentinel_val; + ZigValue *sentinel_val; if (lazy_ptr_type->sentinel != nullptr) { - if (type_is_invalid(lazy_ptr_type->sentinel->value.type)) + if (type_is_invalid(lazy_ptr_type->sentinel->value->type)) return ErrorSemanticAnalyzeFail; IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); - if (type_is_invalid(sentinel->value.type)) + if (type_is_invalid(sentinel->value->type)) return ErrorSemanticAnalyzeFail; sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); if (sentinel_val == nullptr) @@ -28276,7 +28314,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { zig_unreachable(); } -Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) { +Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { Error err; if ((err = ir_resolve_lazy_raw(source_node, val))) { if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) { diff --git a/src/ir.hpp b/src/ir.hpp index d3ec33aef6..75bc9df27b 100644 --- a/src/ir.hpp +++ b/src/ir.hpp @@ -18,12 +18,12 @@ enum IrPass { bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable); bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry); -ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, +ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef); -Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val); +Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val); ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable, ZigType *expected_type, AstNode *expected_type_source_node); @@ -31,7 +31,7 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_ bool ir_has_side_effects(IrInstruction *instruction); struct IrAnalyze; -ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val, +ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val, AstNode *source_node); const char *float_op_to_name(BuiltinFnId op, bool llvm_name); diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 03224d8037..c3733311b6 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -389,14 +389,14 @@ static void ir_print_indent(IrPrint *irp) { static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) { ir_print_indent(irp); const char mark = trailing ? ':' : '#'; - const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)"; + const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)"; const char *ref_count = ir_has_side_effects(instruction) ? "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count)); fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id, ir_instruction_type_str(instruction->id), type_name, ref_count); } -static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { +static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) { Buf buf = BUF_INIT; buf_resize(&buf, 0); render_const_value(irp->codegen, &buf, const_val); @@ -417,8 +417,8 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) return; } - if (instruction->value.special != ConstValSpecialRuntime) { - ir_print_const_value(irp, &instruction->value); + if (instruction->value->special != ConstValSpecialRuntime) { + ir_print_const_value(irp, instruction->value); } else { ir_print_var_instruction(irp, instruction); } @@ -438,7 +438,7 @@ static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) { } static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) { - ir_print_const_value(irp, &const_instruction->base.value); + ir_print_const_value(irp, const_instruction->base.value); } static const char *ir_bin_op_id_str(IrBinOp op_id) { @@ -2576,7 +2576,7 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, ir_print_instruction(irp, instruction, false); } -void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass) { +void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) { IrPrint ir_print = {}; IrPrint *irp = &ir_print; irp->pass = pass; diff --git a/src/ir_print.hpp b/src/ir_print.hpp index 64af959f53..d8b0b56c29 100644 --- a/src/ir_print.hpp +++ b/src/ir_print.hpp @@ -14,7 +14,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass); void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass); -void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass); +void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass); const char* ir_instruction_type_str(IrInstructionId id); diff --git a/src/memory_profiling.cpp b/src/memory_profiling.cpp index 494ffae117..7457ba9f3f 100644 --- a/src/memory_profiling.cpp +++ b/src/memory_profiling.cpp @@ -6,6 +6,8 @@ #ifdef ZIG_ENABLE_MEM_PROFILE +MemprofInternCount memprof_intern_count; + static bool str_eql_str(const char *a, const char *b) { return strcmp(a, b) == 0; } @@ -29,7 +31,6 @@ ZigList<const char *> unknown_names = {}; HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {}; bool table_active = false; - static const char *get_default_name(const char *name_or_null, size_t type_size) { if (name_or_null != nullptr) return name_or_null; if (type_size >= unknown_names.length) { @@ -134,6 +135,12 @@ void memprof_dump_stats(FILE *file) { list.deinit(); table_active = true; + + fprintf(stderr, "\n"); + fprintf(stderr, "undefined: interned %zu times\n", memprof_intern_count.x_undefined); + fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void); + fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null); + fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable); } #endif diff --git a/src/memory_profiling.hpp b/src/memory_profiling.hpp index 6d43d81e3c..56321564d0 100644 --- a/src/memory_profiling.hpp +++ b/src/memory_profiling.hpp @@ -13,6 +13,14 @@ #include <stddef.h> #include <stdio.h> +struct MemprofInternCount { + size_t x_undefined; + size_t x_void; + size_t x_null; + size_t x_unreachable; +}; +extern MemprofInternCount memprof_intern_count; + void memprof_init(void); void memprof_alloc(const char *name, size_t item_count, size_t type_size); diff --git a/src/util.cpp b/src/util.cpp index d3dc57e098..56f1de9839 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -121,18 +121,18 @@ SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) { void zig_pretty_print_bytes(FILE *f, double n) { if (n > 1024.0 * 1024.0 * 1024.0) { - fprintf(f, "%.02f GiB", n / 1024.0 / 1024.0 / 1024.0); + fprintf(f, "%.03f GiB", n / 1024.0 / 1024.0 / 1024.0); return; } if (n > 1024.0 * 1024.0) { - fprintf(f, "%.02f MiB", n / 1024.0 / 1024.0); + fprintf(f, "%.03f MiB", n / 1024.0 / 1024.0); return; } if (n > 1024.0) { - fprintf(f, "%.02f KiB", n / 1024.0); + fprintf(f, "%.03f KiB", n / 1024.0); return; } - fprintf(f, "%.02f bytes", n ); + fprintf(f, "%.03f bytes", n ); return; } |
