authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-25 04:15:23-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-25 04:15:23-05:00
logf47dea2a2ee5e2351736fa416d82c1ed38bfe0f1
treedb58b40ab7bc848c6fdbf19007c8d303fb0d7185
parent6f91fb4c37a676002ccb68b78bea8044ba44b7e2

IR: support compile time global pointer reinterpret

this required moving the place we store types to ConstExprValue

9 files changed, 1090 insertions(+), 938 deletions(-)

src/all_types.hpp+12-12
......@@ -131,6 +131,7 @@ enum RuntimeHintMaybe {
131131};
132132
133133struct ConstExprValue {
134 TypeTableEntry *type;
134135 ConstValSpecial special;
135136 bool depends_on_compile_var;
136137 LLVMValueRef llvm_value;
......@@ -429,8 +430,6 @@ enum CastOp {
429430 CastOpPtrToInt,
430431 CastOpIntToPtr,
431432 CastOpWidenOrShorten,
432 CastOpToUnknownSizeArray,
433 CastOpPointerReinterpret,
434433 CastOpErrToInt,
435434 CastOpIntToFloat,
436435 CastOpFloatToInt,
......@@ -749,14 +748,9 @@ struct FnTypeParamInfo {
749748 TypeTableEntry *type;
750749};
751750
752struct GenericParamValue {
753 TypeTableEntry *type;
754 ConstExprValue *value;
755};
756
757751struct GenericFnTypeId {
758752 FnTableEntry *fn_entry;
759 GenericParamValue *params;
753 ConstExprValue *params;
760754 size_t param_count;
761755};
762756
......@@ -1238,7 +1232,7 @@ struct CodeGen {
12381232// TODO after merging IR branch, we can probably delete some of these fields
12391233struct VariableTableEntry {
12401234 Buf name;
1241 TypeTableEntry *type;
1235 ConstExprValue value;
12421236 LLVMValueRef value_ref;
12431237 bool src_is_const;
12441238 bool gen_is_const;
......@@ -1254,7 +1248,6 @@ struct VariableTableEntry {
12541248 bool shadowable;
12551249 size_t mem_slot_index;
12561250 size_t ref_count;
1257 ConstExprValue *value;
12581251 bool is_extern;
12591252};
12601253
......@@ -1460,14 +1453,14 @@ enum IrInstructionId {
14601453 IrInstructionIdFnProto,
14611454 IrInstructionIdTestComptime,
14621455 IrInstructionIdInitEnum,
1456 IrInstructionIdPointerReinterpret,
14631457};
14641458
14651459struct IrInstruction {
14661460 IrInstructionId id;
14671461 Scope *scope;
14681462 AstNode *source_node;
1469 ConstExprValue static_value;
1470 TypeTableEntry *type_entry;
1463 ConstExprValue value;
14711464 size_t debug_id;
14721465 LLVMValueRef llvm_value;
14731466 // if ref_count is zero, instruction can be omitted in codegen
......@@ -1986,6 +1979,7 @@ struct IrInstructionSlice {
19861979 IrInstruction *start;
19871980 IrInstruction *end;
19881981 bool is_const;
1982 bool safety_check_on;
19891983 LLVMValueRef tmp_ptr;
19901984};
19911985
......@@ -2096,6 +2090,12 @@ struct IrInstructionInitEnum {
20962090 LLVMValueRef tmp_ptr;
20972091};
20982092
2093struct IrInstructionPointerReinterpret {
2094 IrInstruction base;
2095
2096 IrInstruction *ptr;
2097};
2098
20992099enum LValPurpose {
21002100 LValPurposeNone,
21012101 LValPurposeAssign,
src/analyze.cpp+176-62
......@@ -876,11 +876,11 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod
876876
877877TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
878878 IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);
879 if (result->type_entry->id == TypeTableEntryIdInvalid)
879 if (result->value.type->id == TypeTableEntryIdInvalid)
880880 return g->builtin_types.entry_invalid;
881881
882 assert(result->static_value.special != ConstValSpecialRuntime);
883 return result->static_value.data.x_type;
882 assert(result->value.special != ConstValSpecialRuntime);
883 return result->value.data.x_type;
884884}
885885
886886static TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
......@@ -1708,41 +1708,42 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
17081708// Set name to nullptr to make the variable anonymous (not visible to programmer).
17091709// TODO merge with definition of add_local_var in ir.cpp
17101710VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
1711 TypeTableEntry *type_entry, bool is_const, ConstExprValue *init_value)
1711 bool is_const, ConstExprValue *value)
17121712{
1713 assert(value);
1714
17131715 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
1714 variable_entry->type = type_entry;
1716 variable_entry->value = *value;
17151717 variable_entry->parent_scope = parent_scope;
17161718 variable_entry->shadowable = false;
17171719 variable_entry->mem_slot_index = SIZE_MAX;
1718 variable_entry->value = init_value;
17191720 variable_entry->src_arg_index = SIZE_MAX;
17201721
17211722 assert(name);
17221723
17231724 buf_init_from_buf(&variable_entry->name, name);
17241725
1725 if (type_entry->id != TypeTableEntryIdInvalid) {
1726 if (value->type->id != TypeTableEntryIdInvalid) {
17261727 VariableTableEntry *existing_var = find_variable(g, parent_scope, name);
17271728 if (existing_var && !existing_var->shadowable) {
17281729 ErrorMsg *msg = add_node_error(g, source_node,
17291730 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
17301731 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
1731 variable_entry->type = g->builtin_types.entry_invalid;
1732 variable_entry->value.type = g->builtin_types.entry_invalid;
17321733 } else {
17331734 auto primitive_table_entry = g->primitive_type_table.maybe_get(name);
17341735 if (primitive_table_entry) {
17351736 TypeTableEntry *type = primitive_table_entry->value;
17361737 add_node_error(g, source_node,
17371738 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
1738 variable_entry->type = g->builtin_types.entry_invalid;
1739 variable_entry->value.type = g->builtin_types.entry_invalid;
17391740 } else {
17401741 Tld *tld = find_decl(parent_scope, name);
17411742 if (tld && tld->id != TldIdVar) {
17421743 ErrorMsg *msg = add_node_error(g, source_node,
17431744 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
17441745 add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here"));
1745 variable_entry->type = g->builtin_types.entry_invalid;
1746 variable_entry->value.type = g->builtin_types.entry_invalid;
17461747 }
17471748 }
17481749 }
......@@ -1789,7 +1790,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
17891790 } else if (var_decl->expr) {
17901791 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);
17911792 assert(init_value);
1792 implicit_type = init_value->type_entry;
1793 implicit_type = init_value->value.type;
17931794
17941795 if (implicit_type->id == TypeTableEntryIdUnreachable) {
17951796 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
......@@ -1807,7 +1808,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
18071808 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));
18081809 implicit_type = g->builtin_types.entry_invalid;
18091810 }
1810 assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->static_value.special != ConstValSpecialRuntime);
1811 assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime);
18111812 } else if (!is_extern) {
18121813 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
18131814 implicit_type = g->builtin_types.entry_invalid;
......@@ -1816,8 +1817,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
18161817 TypeTableEntry *type = explicit_type ? explicit_type : implicit_type;
18171818 assert(type != nullptr); // should have been caught by the parser
18181819
1819 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope,
1820 var_decl->symbol, type, is_const, &init_value->static_value);
1820 ConstExprValue *init_val = init_value ? &init_value->value : create_const_runtime(type);
1821
1822 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol, is_const, init_val);
18211823 tld_var->var->is_extern = is_extern;
18221824
18231825 g->global_vars.append(tld_var->var);
......@@ -2231,7 +2233,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
22312233 buf_sprintf("byvalue types not yet supported on extern function parameters"));
22322234 }
22332235
2234 VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope, param_decl->name, param_type, true, nullptr);
2236 VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
2237 param_decl->name, true, create_const_runtime(param_type));
22352238 var->src_arg_index = i;
22362239 fn_table_entry->child_scope = var->child_scope;
22372240
......@@ -2287,14 +2290,14 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
22872290
22882291static void add_symbols_from_import(CodeGen *g, AstNode *dst_use_node) {
22892292 IrInstruction *use_target_value = dst_use_node->data.use.value;
2290 if (use_target_value->type_entry->id == TypeTableEntryIdInvalid) {
2293 if (use_target_value->value.type->id == TypeTableEntryIdInvalid) {
22912294 dst_use_node->owner->any_imports_failed = true;
22922295 return;
22932296 }
22942297
22952298 dst_use_node->data.use.resolution = TldResolutionOk;
22962299
2297 ConstExprValue *const_val = &use_target_value->static_value;
2300 ConstExprValue *const_val = &use_target_value->value;
22982301 assert(const_val->special != ConstValSpecialRuntime);
22992302
23002303 ImportTableEntry *target_import = const_val->data.x_import;
......@@ -2351,7 +2354,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
23512354 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
23522355 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
23532356
2354 if (result->type_entry->id == TypeTableEntryIdInvalid)
2357 if (result->value.type->id == TypeTableEntryIdInvalid)
23552358 node->owner->any_imports_failed = true;
23562359
23572360 node->data.use.value = result;
......@@ -2620,8 +2623,9 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
26202623 return true;
26212624}
26222625
2623static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val) {
2624 switch (type->id) {
2626static uint32_t hash_const_val(ConstExprValue *const_val) {
2627 assert(const_val->special == ConstValSpecialStatic);
2628 switch (const_val->type->id) {
26252629 case TypeTableEntryIdBool:
26262630 return const_val->data.x_bool ? 127863866 : 215080464;
26272631 case TypeTableEntryIdMetaType:
......@@ -2630,6 +2634,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
26302634 return 4149439618;
26312635 case TypeTableEntryIdInt:
26322636 case TypeTableEntryIdNumLitInt:
2637 case TypeTableEntryIdEnumTag:
26332638 return ((uint32_t)(bignum_to_twos_complement(&const_val->data.x_bignum) % UINT32_MAX)) * 1331471175;
26342639 case TypeTableEntryIdFloat:
26352640 case TypeTableEntryIdNumLitFloat:
......@@ -2651,8 +2656,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
26512656 return 2709806591;
26522657 case TypeTableEntryIdMaybe:
26532658 if (const_val->data.x_maybe) {
2654 TypeTableEntry *child_type = type->data.maybe.child_type;
2655 return hash_const_val(child_type, const_val->data.x_maybe) * 1992916303;
2659 return hash_const_val(const_val->data.x_maybe) * 1992916303;
26562660 } else {
26572661 return 4016830364;
26582662 }
......@@ -2673,8 +2677,6 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
26732677 return hash_ptr(const_val->data.x_import);
26742678 case TypeTableEntryIdBlock:
26752679 return hash_ptr(const_val->data.x_block);
2676 case TypeTableEntryIdEnumTag:
2677 return 983996406 + hash_const_val(type->data.enum_tag.int_type, const_val);
26782680 case TypeTableEntryIdBoundFn:
26792681 case TypeTableEntryIdInvalid:
26802682 case TypeTableEntryIdUnreachable:
......@@ -2688,9 +2690,9 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
26882690 uint32_t result = 0;
26892691 result += hash_ptr(id->fn_entry);
26902692 for (size_t i = 0; i < id->param_count; i += 1) {
2691 GenericParamValue *generic_param = &id->params[i];
2692 if (generic_param->value) {
2693 result += hash_const_val(generic_param->type, generic_param->value);
2693 ConstExprValue *generic_param = &id->params[i];
2694 if (generic_param->special != ConstValSpecialRuntime) {
2695 result += hash_const_val(generic_param);
26942696 result += hash_ptr(generic_param->type);
26952697 }
26962698 }
......@@ -2702,17 +2704,17 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
27022704 if (a->fn_entry != b->fn_entry) return false;
27032705 assert(a->param_count == b->param_count);
27042706 for (size_t i = 0; i < a->param_count; i += 1) {
2705 GenericParamValue *a_val = &a->params[i];
2706 GenericParamValue *b_val = &b->params[i];
2707 ConstExprValue *a_val = &a->params[i];
2708 ConstExprValue *b_val = &b->params[i];
27072709 if (a_val->type != b_val->type) return false;
2708 if (a_val->value && b_val->value) {
2709 assert(a_val->value->special == ConstValSpecialStatic);
2710 assert(b_val->value->special == ConstValSpecialStatic);
2711 if (!const_values_equal(a_val->value, b_val->value, a_val->type)) {
2710 if (a_val->special != ConstValSpecialRuntime && b_val->special != ConstValSpecialRuntime) {
2711 assert(a_val->special == ConstValSpecialStatic);
2712 assert(b_val->special == ConstValSpecialStatic);
2713 if (!const_values_equal(a_val, b_val)) {
27122714 return false;
27132715 }
27142716 } else {
2715 assert(!a_val->value && !b_val->value);
2717 assert(a_val->special == ConstValSpecialRuntime && b_val->special == ConstValSpecialRuntime);
27162718 }
27172719 }
27182720 return true;
......@@ -2723,7 +2725,7 @@ uint32_t fn_eval_hash(Scope* scope) {
27232725 while (scope) {
27242726 if (scope->id == ScopeIdVarDecl) {
27252727 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
2726 result += hash_const_val(var_scope->var->type, var_scope->var->value);
2728 result += hash_const_val(&var_scope->var->value);
27272729 } else if (scope->id == ScopeIdFnDef) {
27282730 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
27292731 result += hash_ptr(fn_scope->fn_entry);
......@@ -2745,9 +2747,9 @@ bool fn_eval_eql(Scope *a, Scope *b) {
27452747 if (a->id == ScopeIdVarDecl) {
27462748 ScopeVarDecl *a_var_scope = (ScopeVarDecl *)a;
27472749 ScopeVarDecl *b_var_scope = (ScopeVarDecl *)b;
2748 if (a_var_scope->var->type != b_var_scope->var->type)
2750 if (a_var_scope->var->value.type != b_var_scope->var->value.type)
27492751 return false;
2750 if (!const_values_equal(a_var_scope->var->value, b_var_scope->var->value, a_var_scope->var->type))
2752 if (!const_values_equal(&a_var_scope->var->value, &b_var_scope->var->value))
27512753 return false;
27522754 } else if (a->id == ScopeIdFnDef) {
27532755 ScopeFnDef *a_fn_scope = (ScopeFnDef *)a;
......@@ -2865,77 +2867,187 @@ uint64_t get_memcpy_align(CodeGen *g, TypeTableEntry *type_entry) {
28652867 return LLVMABISizeOfType(g->target_data_ref, first_type_in_mem->type_ref);
28662868}
28672869
2868void init_const_str_lit(ConstExprValue *const_val, Buf *str) {
2870void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
28692871 const_val->special = ConstValSpecialStatic;
2872 const_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str));
28702873 const_val->data.x_array.elements = allocate<ConstExprValue>(buf_len(str));
28712874 const_val->data.x_array.size = buf_len(str);
28722875
28732876 for (size_t i = 0; i < buf_len(str); i += 1) {
28742877 ConstExprValue *this_char = &const_val->data.x_array.elements[i];
28752878 this_char->special = ConstValSpecialStatic;
2879 this_char->type = g->builtin_types.entry_u8;
28762880 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);
28772881 }
28782882}
28792883
2880ConstExprValue *create_const_str_lit(Buf *str) {
2884ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {
2885 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2886 init_const_str_lit(g, const_val, str);
2887 return const_val;
2888}
2889
2890void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
2891 // first we build the underlying array
2892 size_t len_with_null = buf_len(str) + 1;
2893 ConstExprValue *array_val = allocate<ConstExprValue>(1);
2894 array_val->special = ConstValSpecialStatic;
2895 array_val->type = get_array_type(g, g->builtin_types.entry_u8, len_with_null);
2896 array_val->data.x_array.elements = allocate<ConstExprValue>(len_with_null);
2897 array_val->data.x_array.size = len_with_null;
2898 for (size_t i = 0; i < buf_len(str); i += 1) {
2899 ConstExprValue *this_char = &array_val->data.x_array.elements[i];
2900 this_char->special = ConstValSpecialStatic;
2901 this_char->type = g->builtin_types.entry_u8;
2902 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);
2903 }
2904 ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1];
2905 null_char->special = ConstValSpecialStatic;
2906 null_char->type = g->builtin_types.entry_u8;
2907 bignum_init_unsigned(&null_char->data.x_bignum, 0);
2908
2909 // then make the pointer point to it
2910 const_val->special = ConstValSpecialStatic;
2911 const_val->type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
2912 const_val->data.x_ptr.base_ptr = array_val;
2913 const_val->data.x_ptr.index = 0;
2914 const_val->data.x_ptr.special = ConstPtrSpecialCStr;
2915}
2916ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {
28812917 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2882 init_const_str_lit(const_val, str);
2918 init_const_c_str_lit(g, const_val, str);
28832919 return const_val;
28842920}
28852921
2886void init_const_unsigned_negative(ConstExprValue *const_val, uint64_t x, bool negative) {
2922void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative) {
28872923 const_val->special = ConstValSpecialStatic;
2924 const_val->type = type;
28882925 bignum_init_unsigned(&const_val->data.x_bignum, x);
28892926 const_val->data.x_bignum.is_negative = negative;
28902927}
28912928
2892ConstExprValue *create_const_unsigned_negative(uint64_t x, bool negative) {
2929ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative) {
28932930 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2894 init_const_unsigned_negative(const_val, x, negative);
2931 init_const_unsigned_negative(const_val, type, x, negative);
28952932 return const_val;
28962933}
28972934
2898void init_const_signed(ConstExprValue *const_val, int64_t x) {
2935void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x) {
2936 return init_const_unsigned_negative(const_val, g->builtin_types.entry_usize, x, false);
2937}
2938
2939ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {
2940 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
2941}
2942
2943void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x) {
28992944 const_val->special = ConstValSpecialStatic;
2945 const_val->type = type;
29002946 bignum_init_signed(&const_val->data.x_bignum, x);
29012947}
29022948
2903ConstExprValue *create_const_signed(int64_t x) {
2949ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) {
29042950 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2905 init_const_signed(const_val, x);
2951 init_const_signed(const_val, type, x);
29062952 return const_val;
29072953}
29082954
2909void init_const_float(ConstExprValue *const_val, double value) {
2955void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) {
29102956 const_val->special = ConstValSpecialStatic;
2957 const_val->type = type;
29112958 bignum_init_float(&const_val->data.x_bignum, value);
29122959}
29132960
2914ConstExprValue *create_const_float(double value) {
2961ConstExprValue *create_const_float(TypeTableEntry *type, double value) {
29152962 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2916 init_const_float(const_val, value);
2963 init_const_float(const_val, type, value);
29172964 return const_val;
29182965}
29192966
2920void init_const_enum_tag(ConstExprValue *const_val, uint64_t tag) {
2967void init_const_enum_tag(ConstExprValue *const_val, TypeTableEntry *type, uint64_t tag) {
29212968 const_val->special = ConstValSpecialStatic;
2969 const_val->type = type;
29222970 const_val->data.x_enum.tag = tag;
29232971}
29242972
2925ConstExprValue *create_const_enum_tag(uint64_t tag) {
2973ConstExprValue *create_const_enum_tag(TypeTableEntry *type, uint64_t tag) {
29262974 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2927 init_const_enum_tag(const_val, tag);
2975 init_const_enum_tag(const_val, type, tag);
29282976 return const_val;
29292977}
29302978
2931void init_const_bool(ConstExprValue *const_val, bool value) {
2979void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value) {
29322980 const_val->special = ConstValSpecialStatic;
2981 const_val->type = g->builtin_types.entry_bool;
29332982 const_val->data.x_bool = value;
29342983}
29352984
2936ConstExprValue *create_const_bool(bool value) {
2985ConstExprValue *create_const_bool(CodeGen *g, bool value) {
2986 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2987 init_const_bool(g, const_val, value);
2988 return const_val;
2989}
2990
2991void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type) {
2992 const_val->special = ConstValSpecialRuntime;
2993 const_val->type = type;
2994}
2995
2996ConstExprValue *create_const_runtime(TypeTableEntry *type) {
29372997 ConstExprValue *const_val = allocate<ConstExprValue>(1);
2938 init_const_bool(const_val, value);
2998 init_const_runtime(const_val, type);
2999 return const_val;
3000}
3001
3002void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value) {
3003 const_val->special = ConstValSpecialStatic;
3004 const_val->type = g->builtin_types.entry_type;
3005 const_val->data.x_type = type_value;
3006}
3007
3008ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
3009 ConstExprValue *const_val = allocate<ConstExprValue>(1);
3010 init_const_type(g, const_val, type_value);
3011 return const_val;
3012}
3013
3014void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
3015 size_t start, size_t len, bool is_const)
3016{
3017 assert(array_val->type->id == TypeTableEntryIdArray);
3018
3019 const_val->special = ConstValSpecialStatic;
3020 const_val->type = get_slice_type(g, array_val->type->data.array.child_type, is_const);
3021 const_val->data.x_struct.fields = allocate<ConstExprValue>(2);
3022
3023 init_const_ptr(g, &const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const);
3024 init_const_usize(g, &const_val->data.x_struct.fields[slice_len_index], len);
3025}
3026
3027ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {
3028 ConstExprValue *const_val = allocate<ConstExprValue>(1);
3029 init_const_slice(g, const_val, array_val, start, len, is_const);
3030 return const_val;
3031}
3032
3033void init_const_ptr(CodeGen *g, ConstExprValue *const_val, ConstExprValue *base_ptr, size_t index, bool is_const) {
3034 TypeTableEntry *child_type;
3035 if (index == SIZE_MAX) {
3036 child_type = base_ptr->type;
3037 } else {
3038 assert(base_ptr->type->id == TypeTableEntryIdArray);
3039 child_type = base_ptr->type->data.array.child_type;
3040 }
3041
3042 const_val->special = ConstValSpecialStatic;
3043 const_val->type = get_pointer_to_type(g, child_type, is_const);
3044 const_val->data.x_ptr.base_ptr = base_ptr;
3045 const_val->data.x_ptr.index = index;
3046}
3047
3048ConstExprValue *create_const_ptr(CodeGen *g, ConstExprValue *base_ptr, size_t index, bool is_const) {
3049 ConstExprValue *const_val = allocate<ConstExprValue>(1);
3050 init_const_ptr(g, const_val, base_ptr, index, is_const);
29393051 return const_val;
29403052}
29413053
......@@ -2956,18 +3068,21 @@ bool ir_get_var_is_comptime(VariableTableEntry *var) {
29563068 if (!var->is_comptime)
29573069 return false;
29583070 if (var->is_comptime->other)
2959 return var->is_comptime->other->static_value.data.x_bool;
2960 return var->is_comptime->static_value.data.x_bool;
3071 return var->is_comptime->other->value.data.x_bool;
3072 return var->is_comptime->value.data.x_bool;
29613073}
29623074
2963bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *type_entry) {
2964 switch (type_entry->id) {
3075bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
3076 assert(a->type == b->type);
3077 assert(a->special == ConstValSpecialStatic);
3078 assert(b->special == ConstValSpecialStatic);
3079 switch (a->type->id) {
29653080 case TypeTableEntryIdEnum:
29663081 {
29673082 ConstEnumValue *enum1 = &a->data.x_enum;
29683083 ConstEnumValue *enum2 = &b->data.x_enum;
29693084 if (enum1->tag == enum2->tag) {
2970 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum1->tag];
3085 TypeEnumField *enum_field = &a->type->data.enumeration.fields[enum1->tag];
29713086 if (type_has_bits(enum_field->type_entry)) {
29723087 zig_panic("TODO const expr analyze enum special value for equality");
29733088 } else {
......@@ -2990,9 +3105,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *ty
29903105 case TypeTableEntryIdFloat:
29913106 case TypeTableEntryIdNumLitFloat:
29923107 case TypeTableEntryIdNumLitInt:
2993 return bignum_cmp_eq(&a->data.x_bignum, &b->data.x_bignum);
29943108 case TypeTableEntryIdEnumTag:
2995 return const_values_equal(a, b, type_entry->data.enum_tag.int_type);
3109 return bignum_cmp_eq(&a->data.x_bignum, &b->data.x_bignum);
29963110 case TypeTableEntryIdPointer:
29973111 zig_panic("TODO");
29983112 case TypeTableEntryIdArray:
src/analyze.hpp+34-14
......@@ -66,7 +66,7 @@ FnTableEntry *scope_fn_entry(Scope *scope);
6666ImportTableEntry *get_scope_import(Scope *scope);
6767void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
6868VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
69 TypeTableEntry *type_entry, bool is_const, ConstExprValue *init_value);
69 bool is_const, ConstExprValue *init_value);
7070TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
7171FnTableEntry *create_fn(AstNode *proto_node);
7272FnTableEntry *create_fn_raw(FnInline inline_value, bool internal_linkage);
......@@ -77,7 +77,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry);
7777void ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry);
7878void complete_enum(CodeGen *g, TypeTableEntry *enum_type);
7979bool ir_get_var_is_comptime(VariableTableEntry *var);
80bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *type_entry);
80bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
8181void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max);
8282
8383ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
......@@ -88,22 +88,42 @@ Scope *create_loop_scope(AstNode *node, Scope *parent);
8888ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry);
8989ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import);
9090
91void init_const_str_lit(ConstExprValue *const_val, Buf *str);
92ConstExprValue *create_const_str_lit(Buf *str);
91void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
92ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
9393
94void init_const_unsigned_negative(ConstExprValue *const_val, uint64_t x, bool negative);
95ConstExprValue *create_const_unsigned_negative(uint64_t x, bool negative);
94void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
95ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
9696
97void init_const_signed(ConstExprValue *const_val, int64_t x);
98ConstExprValue *create_const_signed(int64_t x);
97void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative);
98ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative);
9999
100void init_const_float(ConstExprValue *const_val, double value);
101ConstExprValue *create_const_float(double value);
100void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x);
101ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x);
102102
103void init_const_enum_tag(ConstExprValue *const_val, uint64_t tag);
104ConstExprValue *create_const_enum_tag(uint64_t tag);
103void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);
104ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
105105
106void init_const_bool(ConstExprValue *const_val, bool value);
107ConstExprValue *create_const_bool(bool value);
106void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value);
107ConstExprValue *create_const_float(TypeTableEntry *type, double value);
108
109void init_const_enum_tag(ConstExprValue *const_val, TypeTableEntry *type, uint64_t tag);
110ConstExprValue *create_const_enum_tag(TypeTableEntry *type, uint64_t tag);
111
112void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
113ConstExprValue *create_const_bool(CodeGen *g, bool value);
114
115void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value);
116ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value);
117
118void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type);
119ConstExprValue *create_const_runtime(TypeTableEntry *type);
120
121void init_const_ptr(CodeGen *g, ConstExprValue *const_val, ConstExprValue *base_ptr, size_t index, bool is_const);
122ConstExprValue *create_const_ptr(CodeGen *g, ConstExprValue *const_val, ConstExprValue *base_ptr,
123 size_t index, bool is_const);
124
125void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
126 size_t start, size_t len, bool is_const);
127ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const);
108128
109129#endif
src/codegen.cpp+179-193
......@@ -225,8 +225,8 @@ void codegen_set_rdynamic(CodeGen *g, bool rdynamic) {
225225 g->linker_rdynamic = rdynamic;
226226}
227227
228static void render_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val);
229static void render_const_val_global(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val);
228static void render_const_val(CodeGen *g, ConstExprValue *const_val);
229static void render_const_val_global(CodeGen *g, ConstExprValue *const_val);
230230
231231static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
232232 if (fn_table_entry->llvm_value)
......@@ -645,18 +645,14 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, LLVMValueRef src, LLVMValueRef
645645 return LLVMBuildCall(g->builder, g->memcpy_fn_val, params, 5, "");
646646}
647647
648static LLVMValueRef gen_assign_raw(CodeGen *g,
649 LLVMValueRef target_ref, LLVMValueRef value,
650 TypeTableEntry *op1_type, TypeTableEntry *op2_type)
648static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef target_ref, LLVMValueRef value,
649 TypeTableEntry *child_type)
651650{
652 if (!type_has_bits(op1_type)) {
651 if (!type_has_bits(child_type))
653652 return nullptr;
654 }
655 if (handle_is_ptr(op1_type)) {
656 assert(op1_type == op2_type);
657653
658 return gen_struct_memcpy(g, value, target_ref, op1_type);
659 }
654 if (handle_is_ptr(child_type))
655 return gen_struct_memcpy(g, value, target_ref, child_type);
660656
661657 LLVMBuildStore(g->builder, value, target_ref);
662658 return nullptr;
......@@ -671,17 +667,17 @@ static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
671667}
672668
673669static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
674 if (!type_has_bits(instruction->type_entry))
670 if (!type_has_bits(instruction->value.type))
675671 return nullptr;
676672 if (!instruction->llvm_value) {
677 assert(instruction->static_value.special != ConstValSpecialRuntime);
678 assert(instruction->type_entry);
679 render_const_val(g, instruction->type_entry, &instruction->static_value);
680 if (handle_is_ptr(instruction->type_entry)) {
681 render_const_val_global(g, instruction->type_entry, &instruction->static_value);
682 instruction->llvm_value = instruction->static_value.llvm_global;
673 assert(instruction->value.special != ConstValSpecialRuntime);
674 assert(instruction->value.type);
675 render_const_val(g, &instruction->value);
676 if (handle_is_ptr(instruction->value.type)) {
677 render_const_val_global(g, &instruction->value);
678 instruction->llvm_value = instruction->value.llvm_global;
683679 } else {
684 instruction->llvm_value = instruction->static_value.llvm_value;
680 instruction->llvm_value = instruction->value.llvm_value;
685681 }
686682 assert(instruction->llvm_value);
687683 }
......@@ -690,7 +686,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
690686
691687static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {
692688 LLVMValueRef value = ir_llvm_value(g, return_instruction->value);
693 TypeTableEntry *return_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
689 TypeTableEntry *return_type = return_instruction->value->value.type;
694690 bool is_extern = g->cur_fn->type_entry->data.fn.fn_type_id.is_extern;
695691 if (handle_is_ptr(return_type)) {
696692 if (is_extern) {
......@@ -698,7 +694,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
698694 LLVMBuildRet(g->builder, by_val_value);
699695 } else {
700696 assert(g->cur_ret_ptr);
701 gen_assign_raw(g, g->cur_ret_ptr, value, return_type, return_instruction->value->type_entry);
697 gen_assign_raw(g, g->cur_ret_ptr, value, return_type);
702698 LLVMBuildRetVoid(g->builder);
703699 }
704700 } else {
......@@ -809,7 +805,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
809805 IrInstruction *op1 = bin_op_instruction->op1;
810806 IrInstruction *op2 = bin_op_instruction->op2;
811807
812 assert(op1->type_entry == op2->type_entry);
808 assert(op1->value.type == op2->value.type);
813809
814810 bool want_debug_safety = bin_op_instruction->safety_check_on &&
815811 ir_want_debug_safety(g, &bin_op_instruction->base);
......@@ -831,22 +827,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
831827 case IrBinOpCmpGreaterThan:
832828 case IrBinOpCmpLessOrEq:
833829 case IrBinOpCmpGreaterOrEq:
834 if (op1->type_entry->id == TypeTableEntryIdFloat) {
830 if (op1->value.type->id == TypeTableEntryIdFloat) {
835831 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
836832 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
837 } else if (op1->type_entry->id == TypeTableEntryIdInt) {
838 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, op1->type_entry->data.integral.is_signed);
833 } else if (op1->value.type->id == TypeTableEntryIdInt) {
834 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, op1->value.type->data.integral.is_signed);
839835 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
840 } else if (op1->type_entry->id == TypeTableEntryIdEnum) {
841 if (op1->type_entry->data.enumeration.gen_field_count == 0) {
836 } else if (op1->value.type->id == TypeTableEntryIdEnum) {
837 if (op1->value.type->data.enumeration.gen_field_count == 0) {
842838 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
843839 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
844840 } else {
845841 zig_unreachable();
846842 }
847 } else if (op1->type_entry->id == TypeTableEntryIdPureError ||
848 op1->type_entry->id == TypeTableEntryIdPointer ||
849 op1->type_entry->id == TypeTableEntryIdBool)
843 } else if (op1->value.type->id == TypeTableEntryIdPureError ||
844 op1->value.type->id == TypeTableEntryIdPointer ||
845 op1->value.type->id == TypeTableEntryIdBool)
850846 {
851847 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
852848 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
......@@ -855,15 +851,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
855851 }
856852 case IrBinOpAdd:
857853 case IrBinOpAddWrap:
858 if (op1->type_entry->id == TypeTableEntryIdFloat) {
854 if (op1->value.type->id == TypeTableEntryIdFloat) {
859855 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
860 } else if (op1->type_entry->id == TypeTableEntryIdInt) {
856 } else if (op1->value.type->id == TypeTableEntryIdInt) {
861857 bool is_wrapping = (op_id == IrBinOpAddWrap);
862858 if (is_wrapping) {
863859 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
864860 } else if (want_debug_safety) {
865 return gen_overflow_op(g, op1->type_entry, AddSubMulAdd, op1_value, op2_value);
866 } else if (op1->type_entry->data.integral.is_signed) {
861 return gen_overflow_op(g, op1->value.type, AddSubMulAdd, op1_value, op2_value);
862 } else if (op1->value.type->data.integral.is_signed) {
867863 return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, "");
868864 } else {
869865 return LLVMBuildNUWAdd(g->builder, op1_value, op2_value, "");
......@@ -880,36 +876,36 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
880876 case IrBinOpBitShiftLeft:
881877 case IrBinOpBitShiftLeftWrap:
882878 {
883 assert(op1->type_entry->id == TypeTableEntryIdInt);
879 assert(op1->value.type->id == TypeTableEntryIdInt);
884880 bool is_wrapping = (op_id == IrBinOpBitShiftLeftWrap);
885881 if (is_wrapping) {
886882 return LLVMBuildShl(g->builder, op1_value, op2_value, "");
887883 } else if (want_debug_safety) {
888 return gen_overflow_shl_op(g, op1->type_entry, op1_value, op2_value);
889 } else if (op1->type_entry->data.integral.is_signed) {
884 return gen_overflow_shl_op(g, op1->value.type, op1_value, op2_value);
885 } else if (op1->value.type->data.integral.is_signed) {
890886 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_value, "");
891887 } else {
892888 return ZigLLVMBuildNUWShl(g->builder, op1_value, op2_value, "");
893889 }
894890 }
895891 case IrBinOpBitShiftRight:
896 assert(op1->type_entry->id == TypeTableEntryIdInt);
897 if (op1->type_entry->data.integral.is_signed) {
892 assert(op1->value.type->id == TypeTableEntryIdInt);
893 if (op1->value.type->data.integral.is_signed) {
898894 return LLVMBuildAShr(g->builder, op1_value, op2_value, "");
899895 } else {
900896 return LLVMBuildLShr(g->builder, op1_value, op2_value, "");
901897 }
902898 case IrBinOpSub:
903899 case IrBinOpSubWrap:
904 if (op1->type_entry->id == TypeTableEntryIdFloat) {
900 if (op1->value.type->id == TypeTableEntryIdFloat) {
905901 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
906 } else if (op1->type_entry->id == TypeTableEntryIdInt) {
902 } else if (op1->value.type->id == TypeTableEntryIdInt) {
907903 bool is_wrapping = (op_id == IrBinOpSubWrap);
908904 if (is_wrapping) {
909905 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
910906 } else if (want_debug_safety) {
911 return gen_overflow_op(g, op1->type_entry, AddSubMulSub, op1_value, op2_value);
912 } else if (op1->type_entry->data.integral.is_signed) {
907 return gen_overflow_op(g, op1->value.type, AddSubMulSub, op1_value, op2_value);
908 } else if (op1->value.type->data.integral.is_signed) {
913909 return LLVMBuildNSWSub(g->builder, op1_value, op2_value, "");
914910 } else {
915911 return LLVMBuildNUWSub(g->builder, op1_value, op2_value, "");
......@@ -919,15 +915,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
919915 }
920916 case IrBinOpMult:
921917 case IrBinOpMultWrap:
922 if (op1->type_entry->id == TypeTableEntryIdFloat) {
918 if (op1->value.type->id == TypeTableEntryIdFloat) {
923919 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
924 } else if (op1->type_entry->id == TypeTableEntryIdInt) {
920 } else if (op1->value.type->id == TypeTableEntryIdInt) {
925921 bool is_wrapping = (op_id == IrBinOpMultWrap);
926922 if (is_wrapping) {
927923 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
928924 } else if (want_debug_safety) {
929 return gen_overflow_op(g, op1->type_entry, AddSubMulMul, op1_value, op2_value);
930 } else if (op1->type_entry->data.integral.is_signed) {
925 return gen_overflow_op(g, op1->value.type, AddSubMulMul, op1_value, op2_value);
926 } else if (op1->value.type->data.integral.is_signed) {
931927 return LLVMBuildNSWMul(g->builder, op1_value, op2_value, "");
932928 } else {
933929 return LLVMBuildNUWMul(g->builder, op1_value, op2_value, "");
......@@ -936,13 +932,13 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
936932 zig_unreachable();
937933 }
938934 case IrBinOpDiv:
939 return gen_div(g, want_debug_safety, op1_value, op2_value, op1->type_entry, false);
935 return gen_div(g, want_debug_safety, op1_value, op2_value, op1->value.type, false);
940936 case IrBinOpMod:
941 if (op1->type_entry->id == TypeTableEntryIdFloat) {
937 if (op1->value.type->id == TypeTableEntryIdFloat) {
942938 return LLVMBuildFRem(g->builder, op1_value, op2_value, "");
943939 } else {
944 assert(op1->type_entry->id == TypeTableEntryIdInt);
945 if (op1->type_entry->data.integral.is_signed) {
940 assert(op1->value.type->id == TypeTableEntryIdInt);
941 if (op1->value.type->data.integral.is_signed) {
946942 return LLVMBuildSRem(g->builder, op1_value, op2_value, "");
947943 } else {
948944 return LLVMBuildURem(g->builder, op1_value, op2_value, "");
......@@ -955,8 +951,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
955951static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
956952 IrInstructionCast *cast_instruction)
957953{
958 TypeTableEntry *actual_type = cast_instruction->value->type_entry;
959 TypeTableEntry *wanted_type = cast_instruction->base.type_entry;
954 TypeTableEntry *actual_type = cast_instruction->value->value.type;
955 TypeTableEntry *wanted_type = cast_instruction->base.value.type;
960956 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
961957 assert(expr_val);
962958
......@@ -977,35 +973,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
977973 return LLVMBuildPtrToInt(g->builder, expr_val, wanted_type->type_ref, "");
978974 case CastOpIntToPtr:
979975 return LLVMBuildIntToPtr(g->builder, expr_val, wanted_type->type_ref, "");
980 case CastOpPointerReinterpret:
981 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");
982976 case CastOpWidenOrShorten:
983977 return gen_widen_or_shorten(g, ir_want_debug_safety(g, &cast_instruction->base),
984978 actual_type, wanted_type, expr_val);
985 case CastOpToUnknownSizeArray:
986 {
987 assert(cast_instruction->tmp_ptr);
988 assert(wanted_type->id == TypeTableEntryIdStruct);
989 assert(wanted_type->data.structure.is_slice);
990
991 TypeTableEntry *pointer_type = wanted_type->data.structure.fields[0].type_entry;
992
993
994 size_t ptr_index = wanted_type->data.structure.fields[0].gen_index;
995 if (ptr_index != SIZE_MAX) {
996 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, ptr_index, "");
997 LLVMValueRef expr_bitcast = LLVMBuildBitCast(g->builder, expr_val, pointer_type->type_ref, "");
998 LLVMBuildStore(g->builder, expr_bitcast, ptr_ptr);
999 }
1000
1001 size_t len_index = wanted_type->data.structure.fields[1].gen_index;
1002 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, len_index, "");
1003 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
1004 actual_type->data.array.len, false);
1005 LLVMBuildStore(g->builder, len_val, len_ptr);
1006
1007 return cast_instruction->tmp_ptr;
1008 }
1009979 case CastOpResizeSlice:
1010980 {
1011981 assert(cast_instruction->tmp_ptr);
......@@ -1123,6 +1093,15 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
11231093 zig_unreachable();
11241094}
11251095
1096static LLVMValueRef ir_render_pointer_reinterpret(CodeGen *g, IrExecutable *executable,
1097 IrInstructionPointerReinterpret *instruction)
1098{
1099 TypeTableEntry *wanted_type = instruction->base.value.type;
1100 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
1101 return LLVMBuildBitCast(g->builder, ptr, wanted_type->type_ref, "");
1102}
1103
1104
11261105static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
11271106 IrInstructionUnreachable *unreachable_instruction)
11281107{
......@@ -1152,7 +1131,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
11521131static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
11531132 IrUnOp op_id = un_op_instruction->op_id;
11541133 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
1155 TypeTableEntry *expr_type = un_op_instruction->value->type_entry;
1134 TypeTableEntry *expr_type = un_op_instruction->value->value.type;
11561135
11571136 switch (op_id) {
11581137 case IrUnOpInvalid:
......@@ -1213,7 +1192,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12131192{
12141193 VariableTableEntry *var = decl_var_instruction->var;
12151194
1216 if (!type_has_bits(var->type))
1195 if (!type_has_bits(var->value.type))
12171196 return nullptr;
12181197
12191198 if (var->ref_count == 0)
......@@ -1224,22 +1203,23 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12241203 bool have_init_expr = false;
12251204 bool want_zeroes = false;
12261205
1227 ConstExprValue *const_val = &init_value->static_value;
1206 ConstExprValue *const_val = &init_value->value;
12281207 if (const_val->special == ConstValSpecialRuntime || const_val->special == ConstValSpecialStatic)
12291208 have_init_expr = true;
12301209 if (const_val->special == ConstValSpecialZeroes)
12311210 want_zeroes = true;
12321211
12331212 if (have_init_expr) {
1234 gen_assign_raw(g, var->value_ref, ir_llvm_value(g, init_value), var->type, init_value->type_entry);
1213 assert(var->value.type == init_value->value.type);
1214 gen_assign_raw(g, var->value_ref, ir_llvm_value(g, init_value), var->value.type);
12351215 } else {
12361216 bool ignore_uninit = false;
12371217 // handle runtime stack allocation
12381218 bool want_safe = ir_want_debug_safety(g, &decl_var_instruction->base);
12391219 if (!ignore_uninit && (want_safe || want_zeroes)) {
12401220 TypeTableEntry *usize = g->builtin_types.entry_usize;
1241 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->type->type_ref);
1242 uint64_t align_bytes = get_memcpy_align(g, var->type);
1221 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value.type->type_ref);
1222 uint64_t align_bytes = get_memcpy_align(g, var->value.type);
12431223
12441224 // memset uninitialized memory to 0xa
12451225 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);
......@@ -1265,16 +1245,16 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12651245
12661246static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) {
12671247 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
1268 return get_handle_value(g, ptr, instruction->base.type_entry);
1248 return get_handle_value(g, ptr, instruction->base.value.type);
12691249}
12701250
12711251static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
12721252 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
12731253 LLVMValueRef value = ir_llvm_value(g, instruction->value);
12741254
1275 assert(instruction->ptr->type_entry->id == TypeTableEntryIdPointer);
1276 TypeTableEntry *op1_type = instruction->ptr->type_entry->data.pointer.child_type;
1277 TypeTableEntry *op2_type = instruction->value->type_entry;
1255 assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);
1256 TypeTableEntry *op1_type = instruction->ptr->value.type->data.pointer.child_type;
1257 TypeTableEntry *op2_type = instruction->value->value.type;
12781258
12791259 if (!type_has_bits(op1_type)) {
12801260 return nullptr;
......@@ -1290,7 +1270,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
12901270
12911271static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
12921272 VariableTableEntry *var = instruction->var;
1293 if (type_has_bits(var->type)) {
1273 if (type_has_bits(var->value.type)) {
12941274 assert(var->value_ref);
12951275 return var->value_ref;
12961276 } else {
......@@ -1300,7 +1280,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
13001280
13011281static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
13021282 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
1303 TypeTableEntry *array_ptr_type = instruction->array_ptr->type_entry;
1283 TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type;
13041284 assert(array_ptr_type->id == TypeTableEntryIdPointer);
13051285 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
13061286 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type);
......@@ -1361,7 +1341,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
13611341 } else {
13621342 assert(instruction->fn_ref);
13631343 fn_val = ir_llvm_value(g, instruction->fn_ref);
1364 fn_type = instruction->fn_ref->type_entry;
1344 fn_type = instruction->fn_ref->value.type;
13651345 }
13661346
13671347 TypeTableEntry *src_return_type = fn_type->data.fn.fn_type_id.return_type;
......@@ -1377,7 +1357,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
13771357 }
13781358 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
13791359 IrInstruction *param_instruction = instruction->args[call_i];
1380 TypeTableEntry *param_type = param_instruction->type_entry;
1360 TypeTableEntry *param_type = param_instruction->value.type;
13811361 if (is_var_args || type_has_bits(param_type)) {
13821362 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
13831363 assert(param_value);
......@@ -1526,7 +1506,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
15261506 buf_append_char(&constraint_buf, ',');
15271507 }
15281508
1529 param_types[param_index] = ir_input->type_entry->type_ref;
1509 param_types[param_index] = ir_input->value.type->type_ref;
15301510 param_values[param_index] = ir_llvm_value(g, ir_input);
15311511 }
15321512 for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) {
......@@ -1541,7 +1521,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
15411521 if (instruction->return_count == 0) {
15421522 ret_type = LLVMVoidType();
15431523 } else {
1544 ret_type = instruction->base.type_entry->type_ref;
1524 ret_type = instruction->base.value.type->type_ref;
15451525 }
15461526 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, input_and_output_count, false);
15471527
......@@ -1565,13 +1545,13 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLV
15651545static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,
15661546 IrInstructionTestNonNull *instruction)
15671547{
1568 return gen_non_null_bit(g, instruction->value->type_entry, ir_llvm_value(g, instruction->value));
1548 return gen_non_null_bit(g, instruction->value->value.type, ir_llvm_value(g, instruction->value));
15691549}
15701550
15711551static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
15721552 IrInstructionUnwrapMaybe *instruction)
15731553{
1574 TypeTableEntry *ptr_type = instruction->value->type_entry;
1554 TypeTableEntry *ptr_type = instruction->value->value.type;
15751555 assert(ptr_type->id == TypeTableEntryIdPointer);
15761556 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
15771557 assert(maybe_type->id == TypeTableEntryIdMaybe);
......@@ -1617,7 +1597,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
16171597}
16181598
16191599static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
1620 TypeTableEntry *int_type = instruction->base.type_entry;
1600 TypeTableEntry *int_type = instruction->base.value.type;
16211601 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
16221602 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
16231603 LLVMValueRef params[] {
......@@ -1628,7 +1608,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
16281608}
16291609
16301610static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
1631 TypeTableEntry *int_type = instruction->base.type_entry;
1611 TypeTableEntry *int_type = instruction->base.value.type;
16321612 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
16331613 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
16341614 LLVMValueRef params[] {
......@@ -1650,14 +1630,14 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
16501630}
16511631
16521632static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {
1653 if (!type_has_bits(instruction->base.type_entry))
1633 if (!type_has_bits(instruction->base.value.type))
16541634 return nullptr;
16551635
16561636 LLVMTypeRef phi_type;
1657 if (handle_is_ptr(instruction->base.type_entry)) {
1658 phi_type = LLVMPointerType(instruction->base.type_entry->type_ref, 0);
1637 if (handle_is_ptr(instruction->base.value.type)) {
1638 phi_type = LLVMPointerType(instruction->base.value.type->type_ref, 0);
16591639 } else {
1660 phi_type = instruction->base.type_entry->type_ref;
1640 phi_type = instruction->base.value.type->type_ref;
16611641 }
16621642
16631643 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
......@@ -1673,7 +1653,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
16731653
16741654static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRef *instruction) {
16751655 LLVMValueRef value = ir_llvm_value(g, instruction->value);
1676 if (handle_is_ptr(instruction->value->type_entry)) {
1656 if (handle_is_ptr(instruction->value->value.type)) {
16771657 return value;
16781658 } else {
16791659 assert(instruction->tmp_ptr);
......@@ -1741,17 +1721,17 @@ static LLVMValueRef ir_render_div_exact(CodeGen *g, IrExecutable *executable, Ir
17411721 LLVMValueRef op2_val = ir_llvm_value(g, instruction->op2);
17421722
17431723 bool want_debug_safety = ir_want_debug_safety(g, &instruction->base);
1744 return gen_div(g, want_debug_safety, op1_val, op2_val, instruction->base.type_entry, true);
1724 return gen_div(g, want_debug_safety, op1_val, op2_val, instruction->base.value.type, true);
17451725}
17461726
17471727static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
1748 TypeTableEntry *dest_type = get_underlying_type(instruction->base.type_entry);
1728 TypeTableEntry *dest_type = get_underlying_type(instruction->base.value.type);
17491729 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
17501730 return LLVMBuildTrunc(g->builder, target_val, dest_type->type_ref, "");
17511731}
17521732
17531733static LLVMValueRef ir_render_alloca(CodeGen *g, IrExecutable *executable, IrInstructionAlloca *instruction) {
1754 TypeTableEntry *slice_type = get_underlying_type(instruction->base.type_entry);
1734 TypeTableEntry *slice_type = get_underlying_type(instruction->base.value.type);
17551735 TypeTableEntry *ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry;
17561736 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
17571737 LLVMValueRef size_val = ir_llvm_value(g, instruction->count);
......@@ -1814,12 +1794,14 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
18141794}
18151795
18161796static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSlice *instruction) {
1817 TypeTableEntry *array_type = get_underlying_type(instruction->ptr->type_entry);
1797 assert(instruction->tmp_ptr);
1798
1799 TypeTableEntry *array_type = get_underlying_type(instruction->ptr->value.type);
18181800
18191801 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
18201802 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->ptr);
18211803
1822 bool want_debug_safety = ir_want_debug_safety(g, &instruction->base);
1804 bool want_debug_safety = instruction->safety_check_on && ir_want_debug_safety(g, &instruction->base);
18231805
18241806 if (array_type->id == TypeTableEntryIdArray) {
18251807 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
......@@ -1997,7 +1979,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
19971979}
19981980
19991981static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {
2000 TypeTableEntry *err_union_type = get_underlying_type(instruction->value->type_entry);
1982 TypeTableEntry *err_union_type = get_underlying_type(instruction->value->value.type);
20011983 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
20021984 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);
20031985
......@@ -2014,7 +1996,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
20141996}
20151997
20161998static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
2017 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->type_entry);
1999 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
20182000 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
20192001 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
20202002 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
......@@ -2029,7 +2011,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
20292011}
20302012
20312013static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
2032 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->type_entry);
2014 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
20332015 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
20342016 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
20352017 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
......@@ -2063,7 +2045,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
20632045}
20642046
20652047static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionMaybeWrap *instruction) {
2066 TypeTableEntry *wanted_type = instruction->base.type_entry;
2048 TypeTableEntry *wanted_type = instruction->base.value.type;
20672049
20682050 assert(wanted_type->id == TypeTableEntryIdMaybe);
20692051
......@@ -2079,7 +2061,8 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
20792061 assert(instruction->tmp_ptr);
20802062
20812063 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, maybe_child_index, "");
2082 gen_assign_raw(g, val_ptr, payload_val, child_type, instruction->value->type_entry);
2064 assert(child_type == instruction->value->value.type);
2065 gen_assign_raw(g, val_ptr, payload_val, child_type);
20832066 LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, maybe_null_index, "");
20842067 LLVMBuildStore(g->builder, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr);
20852068
......@@ -2087,7 +2070,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
20872070}
20882071
20892072static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
2090 TypeTableEntry *wanted_type = instruction->base.type_entry;
2073 TypeTableEntry *wanted_type = instruction->base.value.type;
20912074
20922075 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
20932076
......@@ -2106,7 +2089,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
21062089}
21072090
21082091static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
2109 TypeTableEntry *wanted_type = instruction->base.type_entry;
2092 TypeTableEntry *wanted_type = instruction->base.value.type;
21102093
21112094 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
21122095
......@@ -2125,13 +2108,14 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
21252108 LLVMBuildStore(g->builder, ok_err_val, err_tag_ptr);
21262109
21272110 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_payload_index, "");
2128 gen_assign_raw(g, payload_ptr, payload_val, child_type, instruction->value->type_entry);
2111 assert(child_type == instruction->value->value.type);
2112 gen_assign_raw(g, payload_ptr, payload_val, child_type);
21292113
21302114 return instruction->tmp_ptr;
21312115}
21322116
21332117static LLVMValueRef ir_render_enum_tag(CodeGen *g, IrExecutable *executable, IrInstructionEnumTag *instruction) {
2134 TypeTableEntry *enum_type = instruction->value->type_entry;
2118 TypeTableEntry *enum_type = instruction->value->value.type;
21352119 TypeTableEntry *tag_type = enum_type->data.enumeration.tag_type;
21362120 if (!type_has_bits(tag_type))
21372121 return nullptr;
......@@ -2165,7 +2149,7 @@ static LLVMValueRef ir_render_init_enum(CodeGen *g, IrExecutable *executable, Ir
21652149 LLVMValueRef bitcasted_union_field_ptr = LLVMBuildBitCast(g->builder, union_field_ptr,
21662150 LLVMPointerType(union_val_type->type_ref, 0), "");
21672151
2168 gen_assign_raw(g, bitcasted_union_field_ptr, new_union_val, union_val_type, union_val_type);
2152 gen_assign_raw(g, bitcasted_union_field_ptr, new_union_val, union_val_type);
21692153 }
21702154
21712155 return tmp_struct_ptr;
......@@ -2180,7 +2164,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
21802164
21812165 LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, type_struct_field->gen_index, "");
21822166 LLVMValueRef value = ir_llvm_value(g, field->value);
2183 gen_assign_raw(g, field_ptr, value, type_struct_field->type_entry, type_struct_field->type_entry);
2167 gen_assign_raw(g, field_ptr, value, type_struct_field->type_entry);
21842168 }
21852169 return instruction->tmp_ptr;
21862170}
......@@ -2323,6 +2307,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
23232307 return ir_render_init_enum(g, executable, (IrInstructionInitEnum *)instruction);
23242308 case IrInstructionIdStructInit:
23252309 return ir_render_struct_init(g, executable, (IrInstructionStructInit *)instruction);
2310 case IrInstructionIdPointerReinterpret:
2311 return ir_render_pointer_reinterpret(g, executable, (IrInstructionPointerReinterpret *)instruction);
23262312 case IrInstructionIdSwitchVar:
23272313 zig_panic("TODO render switch var instruction to LLVM");
23282314 case IrInstructionIdContainerInitList:
......@@ -2350,37 +2336,40 @@ static void ir_render(CodeGen *g, FnTableEntry *fn_entry) {
23502336 }
23512337}
23522338
2353static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val) {
2339static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
2340 TypeTableEntry *canon_type = get_underlying_type(const_val->type);
2341
23542342 switch (const_val->special) {
23552343 case ConstValSpecialRuntime:
23562344 zig_unreachable();
23572345 case ConstValSpecialUndef:
2358 return LLVMGetUndef(type_entry->type_ref);
2346 return LLVMGetUndef(canon_type->type_ref);
23592347 case ConstValSpecialZeroes:
2360 return LLVMConstNull(type_entry->type_ref);
2348 return LLVMConstNull(canon_type->type_ref);
23612349 case ConstValSpecialStatic:
23622350 break;
23632351
23642352 }
23652353
2366 switch (type_entry->id) {
2354 switch (canon_type->id) {
23672355 case TypeTableEntryIdTypeDecl:
2368 return gen_const_val(g, type_entry->data.type_decl.canonical_type, const_val);
2356 zig_unreachable();
23692357 case TypeTableEntryIdInt:
2370 return LLVMConstInt(type_entry->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false);
2358 case TypeTableEntryIdEnumTag:
2359 return LLVMConstInt(canon_type->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false);
23712360 case TypeTableEntryIdPureError:
23722361 assert(const_val->data.x_pure_err);
23732362 return LLVMConstInt(g->builtin_types.entry_pure_error->type_ref,
23742363 const_val->data.x_pure_err->value, false);
23752364 case TypeTableEntryIdFloat:
23762365 if (const_val->data.x_bignum.kind == BigNumKindFloat) {
2377 return LLVMConstReal(type_entry->type_ref, const_val->data.x_bignum.data.x_float);
2366 return LLVMConstReal(canon_type->type_ref, const_val->data.x_bignum.data.x_float);
23782367 } else {
23792368 int64_t x = const_val->data.x_bignum.data.x_uint;
23802369 if (const_val->data.x_bignum.is_negative) {
23812370 x = -x;
23822371 }
2383 return LLVMConstReal(type_entry->type_ref, x);
2372 return LLVMConstReal(canon_type->type_ref, x);
23842373 }
23852374 case TypeTableEntryIdBool:
23862375 if (const_val->data.x_bool) {
......@@ -2390,12 +2379,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
23902379 }
23912380 case TypeTableEntryIdMaybe:
23922381 {
2393 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
2382 TypeTableEntry *child_type = canon_type->data.maybe.child_type;
23942383 if (child_type->id == TypeTableEntryIdPointer ||
23952384 child_type->id == TypeTableEntryIdFn)
23962385 {
23972386 if (const_val->data.x_maybe) {
2398 return gen_const_val(g, child_type, const_val->data.x_maybe);
2387 return gen_const_val(g, const_val->data.x_maybe);
23992388 } else {
24002389 return LLVMConstNull(child_type->type_ref);
24012390 }
......@@ -2403,7 +2392,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
24032392 LLVMValueRef child_val;
24042393 LLVMValueRef maybe_val;
24052394 if (const_val->data.x_maybe) {
2406 child_val = gen_const_val(g, child_type, const_val->data.x_maybe);
2395 child_val = gen_const_val(g, const_val->data.x_maybe);
24072396 maybe_val = LLVMConstAllOnes(LLVMInt1Type());
24082397 } else {
24092398 child_val = LLVMConstNull(child_type->type_ref);
......@@ -2418,17 +2407,16 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
24182407 }
24192408 case TypeTableEntryIdStruct:
24202409 {
2421 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
2422 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
2423 TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];
2410 LLVMValueRef *fields = allocate<LLVMValueRef>(canon_type->data.structure.gen_field_count);
2411 for (uint32_t i = 0; i < canon_type->data.structure.src_field_count; i += 1) {
2412 TypeStructField *type_struct_field = &canon_type->data.structure.fields[i];
24242413 if (type_struct_field->gen_index == SIZE_MAX) {
24252414 continue;
24262415 }
2427 fields[type_struct_field->gen_index] = gen_const_val(g, type_struct_field->type_entry,
2428 &const_val->data.x_struct.fields[i]);
2416 fields[type_struct_field->gen_index] = gen_const_val(g, &const_val->data.x_struct.fields[i]);
24292417 }
2430 return LLVMConstNamedStruct(type_entry->type_ref, fields,
2431 type_entry->data.structure.gen_field_count);
2418 return LLVMConstNamedStruct(canon_type->type_ref, fields,
2419 canon_type->data.structure.gen_field_count);
24322420 }
24332421 case TypeTableEntryIdUnion:
24342422 {
......@@ -2436,24 +2424,24 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
24362424 }
24372425 case TypeTableEntryIdArray:
24382426 {
2439 TypeTableEntry *child_type = type_entry->data.array.child_type;
2440 uint64_t len = type_entry->data.array.len;
2427 TypeTableEntry *child_type = canon_type->data.array.child_type;
2428 uint64_t len = canon_type->data.array.len;
24412429 LLVMValueRef *values = allocate<LLVMValueRef>(len);
24422430 for (uint64_t i = 0; i < len; i += 1) {
24432431 ConstExprValue *elem_value = &const_val->data.x_array.elements[i];
2444 values[i] = gen_const_val(g, child_type, elem_value);
2432 values[i] = gen_const_val(g, elem_value);
24452433 }
24462434 return LLVMConstArray(child_type->type_ref, values, len);
24472435 }
24482436 case TypeTableEntryIdEnum:
24492437 {
2450 LLVMTypeRef tag_type_ref = type_entry->data.enumeration.tag_type->type_ref;
2438 LLVMTypeRef tag_type_ref = canon_type->data.enumeration.tag_type->type_ref;
24512439 LLVMValueRef tag_value = LLVMConstInt(tag_type_ref, const_val->data.x_enum.tag, false);
2452 if (type_entry->data.enumeration.gen_field_count == 0) {
2440 if (canon_type->data.enumeration.gen_field_count == 0) {
24532441 return tag_value;
24542442 } else {
2455 TypeTableEntry *union_type = type_entry->data.enumeration.union_type;
2456 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[const_val->data.x_enum.tag];
2443 TypeTableEntry *union_type = canon_type->data.enumeration.union_type;
2444 TypeEnumField *enum_field = &canon_type->data.enumeration.fields[const_val->data.x_enum.tag];
24572445 assert(enum_field->value == const_val->data.x_enum.tag);
24582446 LLVMValueRef union_value;
24592447 if (type_has_bits(enum_field->type_entry)) {
......@@ -2463,8 +2451,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
24632451 enum_field->type_entry->type_ref);
24642452 uint64_t pad_bytes = union_type_bytes - field_type_bytes;
24652453
2466 LLVMValueRef correctly_typed_value = gen_const_val(g, enum_field->type_entry,
2467 const_val->data.x_enum.payload);
2454 LLVMValueRef correctly_typed_value = gen_const_val(g, const_val->data.x_enum.payload);
24682455 if (pad_bytes == 0) {
24692456 union_value = correctly_typed_value;
24702457 } else {
......@@ -2481,29 +2468,31 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
24812468 tag_value,
24822469 union_value,
24832470 };
2484 return LLVMConstNamedStruct(type_entry->type_ref, fields, 2);
2471 return LLVMConstNamedStruct(canon_type->type_ref, fields, 2);
24852472 }
24862473 }
24872474 case TypeTableEntryIdFn:
24882475 return fn_llvm_value(g, const_val->data.x_fn);
24892476 case TypeTableEntryIdPointer:
24902477 {
2491 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
2492
2493 render_const_val_global(g, type_entry, const_val);
2478 render_const_val_global(g, const_val);
24942479 size_t index = const_val->data.x_ptr.index;
24952480 if (index == SIZE_MAX) {
2496 render_const_val(g, child_type, const_val->data.x_ptr.base_ptr);
2497 render_const_val_global(g, child_type, const_val->data.x_ptr.base_ptr);
2498 const_val->llvm_value = const_val->data.x_ptr.base_ptr->llvm_global;
2499 render_const_val_global(g, type_entry, const_val);
2481 render_const_val(g, const_val->data.x_ptr.base_ptr);
2482 render_const_val_global(g, const_val->data.x_ptr.base_ptr);
2483 ConstExprValue *other_val = const_val->data.x_ptr.base_ptr;
2484 if (other_val->type == const_val->type->data.pointer.child_type) {
2485 const_val->llvm_value = other_val->llvm_global;
2486 } else {
2487 const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref);
2488 }
2489 render_const_val_global(g, const_val);
25002490 return const_val->llvm_value;
25012491 } else {
25022492 ConstExprValue *array_const_val = const_val->data.x_ptr.base_ptr;
2503 TypeTableEntry *array_type = get_array_type(g, child_type,
2504 array_const_val->data.x_array.size);
2505 render_const_val(g, array_type, array_const_val);
2506 render_const_val_global(g, array_type, array_const_val);
2493 assert(array_const_val->type->id == TypeTableEntryIdArray);
2494 render_const_val(g, array_const_val);
2495 render_const_val_global(g, array_const_val);
25072496 TypeTableEntry *usize = g->builtin_types.entry_usize;
25082497 LLVMValueRef indices[] = {
25092498 LLVMConstNull(usize->type_ref),
......@@ -2511,13 +2500,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
25112500 };
25122501 LLVMValueRef ptr_val = LLVMConstInBoundsGEP(array_const_val->llvm_global, indices, 2);
25132502 const_val->llvm_value = ptr_val;
2514 render_const_val_global(g, type_entry, const_val);
2503 render_const_val_global(g, const_val);
25152504 return ptr_val;
25162505 }
25172506 }
25182507 case TypeTableEntryIdErrorUnion:
25192508 {
2520 TypeTableEntry *child_type = type_entry->data.error.child_type;
2509 TypeTableEntry *child_type = canon_type->data.error.child_type;
25212510 if (!type_has_bits(child_type)) {
25222511 uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0;
25232512 return LLVMConstInt(g->err_tag_type->type_ref, value, false);
......@@ -2529,7 +2518,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
25292518 err_payload_value = LLVMConstNull(child_type->type_ref);
25302519 } else {
25312520 err_tag_value = LLVMConstNull(g->err_tag_type->type_ref);
2532 err_payload_value = gen_const_val(g, child_type, const_val->data.x_err_union.payload);
2521 err_payload_value = gen_const_val(g, const_val->data.x_err_union.payload);
25332522 }
25342523 LLVMValueRef fields[] = {
25352524 err_tag_value,
......@@ -2540,8 +2529,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
25402529 }
25412530 case TypeTableEntryIdVoid:
25422531 return nullptr;
2543 case TypeTableEntryIdEnumTag:
2544 return gen_const_val(g, type_entry->data.enum_tag.int_type, const_val);
25452532 case TypeTableEntryIdInvalid:
25462533 case TypeTableEntryIdMetaType:
25472534 case TypeTableEntryIdUnreachable:
......@@ -2559,17 +2546,17 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
25592546 zig_unreachable();
25602547}
25612548
2562static void render_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val) {
2549static void render_const_val(CodeGen *g, ConstExprValue *const_val) {
25632550 if (!const_val->llvm_value)
2564 const_val->llvm_value = gen_const_val(g, type_entry, const_val);
2551 const_val->llvm_value = gen_const_val(g, const_val);
25652552
25662553 if (const_val->llvm_global)
25672554 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
25682555}
25692556
2570static void render_const_val_global(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val) {
2557static void render_const_val_global(CodeGen *g, ConstExprValue *const_val) {
25712558 if (!const_val->llvm_global) {
2572 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_entry->type_ref, "");
2559 LLVMValueRef global_value = LLVMAddGlobal(g->module, const_val->type->type_ref, "");
25732560 LLVMSetLinkage(global_value, LLVMInternalLinkage);
25742561 LLVMSetGlobalConstant(global_value, true);
25752562 LLVMSetUnnamedAddr(global_value, true);
......@@ -2717,9 +2704,9 @@ static void do_code_gen(CodeGen *g) {
27172704 for (size_t i = 0; i < g->global_vars.length; i += 1) {
27182705 VariableTableEntry *var = g->global_vars.at(i);
27192706
2720 if (var->type->id == TypeTableEntryIdNumLitFloat) {
2707 if (var->value.type->id == TypeTableEntryIdNumLitFloat) {
27212708 // Generate debug info for it but that's it.
2722 ConstExprValue *const_val = var->value;
2709 ConstExprValue *const_val = &var->value;
27232710 assert(const_val->special != ConstValSpecialRuntime);
27242711 TypeTableEntry *var_type = g->builtin_types.entry_f64;
27252712 LLVMValueRef init_val = LLVMConstReal(var_type->type_ref, const_val->data.x_bignum.data.x_float);
......@@ -2727,9 +2714,9 @@ static void do_code_gen(CodeGen *g) {
27272714 continue;
27282715 }
27292716
2730 if (var->type->id == TypeTableEntryIdNumLitInt) {
2717 if (var->value.type->id == TypeTableEntryIdNumLitInt) {
27312718 // Generate debug info for it but that's it.
2732 ConstExprValue *const_val = var->value;
2719 ConstExprValue *const_val = &var->value;
27332720 assert(const_val->special != ConstValSpecialRuntime);
27342721 TypeTableEntry *var_type = const_val->data.x_bignum.is_negative ?
27352722 g->builtin_types.entry_isize : g->builtin_types.entry_usize;
......@@ -2739,27 +2726,26 @@ static void do_code_gen(CodeGen *g) {
27392726 continue;
27402727 }
27412728
2742 if (!type_has_bits(var->type)) {
2729 if (!type_has_bits(var->value.type))
27432730 continue;
2744 }
27452731
27462732 assert(var->decl_node);
27472733 assert(var->decl_node->type == NodeTypeVariableDeclaration);
27482734
27492735 LLVMValueRef global_value;
27502736 if (var->is_extern) {
2751 global_value = LLVMAddGlobal(g->module, var->type->type_ref, buf_ptr(&var->name));
2737 global_value = LLVMAddGlobal(g->module, var->value.type->type_ref, buf_ptr(&var->name));
27522738
27532739 // TODO debug info for the extern variable
27542740
27552741 LLVMSetLinkage(global_value, LLVMExternalLinkage);
27562742 } else {
2757 render_const_val(g, var->type, var->value);
2758 render_const_val_global(g, var->type, var->value);
2759 global_value = var->value->llvm_global;
2743 render_const_val(g, &var->value);
2744 render_const_val_global(g, &var->value);
2745 global_value = var->value.llvm_global;
27602746 // TODO debug info for function pointers
2761 if (var->gen_is_const && var->type->id != TypeTableEntryIdFn) {
2762 gen_global_var(g, var, var->value->llvm_value, var->type);
2747 if (var->gen_is_const && var->value.type->id != TypeTableEntryIdFn) {
2748 gen_global_var(g, var, var->value.llvm_value, var->value.type);
27632749 }
27642750 }
27652751
......@@ -2890,15 +2876,15 @@ static void do_code_gen(CodeGen *g) {
28902876 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
28912877 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
28922878 LLVMValueRef *slot;
2893 TypeTableEntry *slot_type = instruction->type_entry;
2879 TypeTableEntry *slot_type = instruction->value.type;
28942880 if (instruction->id == IrInstructionIdCast) {
28952881 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
28962882 slot = &cast_instruction->tmp_ptr;
28972883 } else if (instruction->id == IrInstructionIdRef) {
28982884 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;
28992885 slot = &ref_instruction->tmp_ptr;
2900 assert(instruction->type_entry->id == TypeTableEntryIdPointer);
2901 slot_type = instruction->type_entry->data.pointer.child_type;
2886 assert(instruction->value.type->id == TypeTableEntryIdPointer);
2887 slot_type = instruction->value.type->data.pointer.child_type;
29022888 } else if (instruction->id == IrInstructionIdContainerInitList) {
29032889 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
29042890 slot = &container_init_list_instruction->tmp_ptr;
......@@ -2938,33 +2924,33 @@ static void do_code_gen(CodeGen *g) {
29382924 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
29392925 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
29402926
2941 if (!type_has_bits(var->type)) {
2927 if (!type_has_bits(var->value.type)) {
29422928 continue;
29432929 }
29442930 if (ir_get_var_is_comptime(var))
29452931 continue;
29462932
29472933 if (var->src_arg_index == SIZE_MAX) {
2948 var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name));
2934 var->value_ref = LLVMBuildAlloca(g->builder, var->value.type->type_ref, buf_ptr(&var->name));
29492935
29502936
2951 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
2937 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->value.type->type_ref);
29522938 LLVMSetAlignment(var->value_ref, align_bytes);
29532939
29542940 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
29552941 buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
2956 var->type->di_type, !g->strip_debug_symbols, 0);
2942 var->value.type->di_type, !g->strip_debug_symbols, 0);
29572943
29582944 } else {
29592945 assert(var->gen_arg_index != SIZE_MAX);
29602946 TypeTableEntry *gen_type;
2961 if (handle_is_ptr(var->type)) {
2947 if (handle_is_ptr(var->value.type)) {
29622948 gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type;
29632949 var->value_ref = LLVMGetParam(fn, var->gen_arg_index);
29642950 } else {
2965 gen_type = var->type;
2966 var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name));
2967 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->type->type_ref);
2951 gen_type = var->value.type;
2952 var->value_ref = LLVMBuildAlloca(g->builder, var->value.type->type_ref, buf_ptr(&var->name));
2953 unsigned align_bytes = ZigLLVMGetPrefTypeAlignment(g->target_data_ref, var->value.type->type_ref);
29682954 LLVMSetAlignment(var->value_ref, align_bytes);
29692955 }
29702956 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
......@@ -2991,7 +2977,7 @@ static void do_code_gen(CodeGen *g) {
29912977 assert(variable);
29922978 assert(variable->value_ref);
29932979
2994 if (!handle_is_ptr(variable->type)) {
2980 if (!handle_is_ptr(variable->value.type)) {
29952981 clear_debug_source_node(g);
29962982 LLVMBuildStore(g->builder, LLVMGetParam(fn, variable->gen_arg_index), variable->value_ref);
29972983 }
......@@ -3627,7 +3613,7 @@ static void init(CodeGen *g, Buf *source_path) {
36273613 define_builtin_fns(g);
36283614
36293615 g->invalid_instruction = allocate<IrInstruction>(1);
3630 g->invalid_instruction->type_entry = g->builtin_types.entry_invalid;
3616 g->invalid_instruction->value.type = g->builtin_types.entry_invalid;
36313617}
36323618
36333619void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source_code) {
src/ir.cpp+620-588
......@@ -48,6 +48,7 @@ static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
4848static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope,
4949 LValPurpose lval);
5050static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
51static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);
5152
5253ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) {
5354 assert(const_val->special == ConstValSpecialStatic);
......@@ -93,7 +94,7 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {
9394}
9495
9596static bool instr_is_comptime(IrInstruction *instruction) {
96 return instruction->static_value.special != ConstValSpecialRuntime;
97 return instruction->value.special != ConstValSpecialRuntime;
9798}
9899
99100static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {
......@@ -450,6 +451,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionInitEnum *) {
450451 return IrInstructionIdInitEnum;
451452}
452453
454static constexpr IrInstructionId ir_instruction_id(IrInstructionPointerReinterpret *) {
455 return IrInstructionIdPointerReinterpret;
456}
457
453458template<typename T>
454459static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) {
455460 T *special_instruction = allocate<T>(1);
......@@ -485,8 +490,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so
485490 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)
486491{
487492 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);
488 cond_br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable;
489 cond_br_instruction->base.static_value.special = ConstValSpecialStatic;
493 cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
494 cond_br_instruction->base.value.special = ConstValSpecialStatic;
490495 cond_br_instruction->condition = condition;
491496 cond_br_instruction->then_block = then_block;
492497 cond_br_instruction->else_block = else_block;
......@@ -511,8 +516,8 @@ static IrInstruction *ir_build_cond_br_from(IrBuilder *irb, IrInstruction *old_i
511516
512517static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *return_value) {
513518 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);
514 return_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable;
515 return_instruction->base.static_value.special = ConstValSpecialStatic;
519 return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
520 return_instruction->base.value.special = ConstValSpecialStatic;
516521 return_instruction->value = return_value;
517522
518523 ir_ref_instruction(return_value);
......@@ -533,55 +538,55 @@ static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *sou
533538{
534539 assert(type_entry);
535540 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node);
536 const_instruction->base.type_entry = type_entry;
537 const_instruction->base.static_value.special = ConstValSpecialStatic;
538 const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var;
541 const_instruction->base.value.type = type_entry;
542 const_instruction->base.value.special = ConstValSpecialStatic;
543 const_instruction->base.value.depends_on_compile_var = depends_on_compile_var;
539544 return &const_instruction->base;
540545}
541546
542547static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {
543548 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
544 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_void;
545 const_instruction->base.static_value.special = ConstValSpecialStatic;
549 const_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
550 const_instruction->base.value.special = ConstValSpecialStatic;
546551 return &const_instruction->base;
547552}
548553
549554static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {
550555 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
551 const_instruction->base.static_value.special = ConstValSpecialUndef;
552 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_undef;
556 const_instruction->base.value.special = ConstValSpecialUndef;
557 const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef;
553558 return &const_instruction->base;
554559}
555560
556561static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
557562 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
558 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_num_lit_int;
559 const_instruction->base.static_value.special = ConstValSpecialStatic;
560 bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value);
563 const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int;
564 const_instruction->base.value.special = ConstValSpecialStatic;
565 bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, value);
561566 return &const_instruction->base;
562567}
563568
564569static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) {
565570 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
566 const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ?
571 const_instruction->base.value.type = (bignum->kind == BigNumKindInt) ?
567572 irb->codegen->builtin_types.entry_num_lit_int : irb->codegen->builtin_types.entry_num_lit_float;
568 const_instruction->base.static_value.special = ConstValSpecialStatic;
569 const_instruction->base.static_value.data.x_bignum = *bignum;
573 const_instruction->base.value.special = ConstValSpecialStatic;
574 const_instruction->base.value.data.x_bignum = *bignum;
570575 return &const_instruction->base;
571576}
572577
573578static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {
574579 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
575 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_null;
576 const_instruction->base.static_value.special = ConstValSpecialStatic;
580 const_instruction->base.value.type = irb->codegen->builtin_types.entry_null;
581 const_instruction->base.value.special = ConstValSpecialStatic;
577582 return &const_instruction->base;
578583}
579584
580585static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
581586 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
582 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_usize;
583 const_instruction->base.static_value.special = ConstValSpecialStatic;
584 bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value);
587 const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize;
588 const_instruction->base.value.special = ConstValSpecialStatic;
589 bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, value);
585590 return &const_instruction->base;
586591}
587592
......@@ -589,9 +594,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
589594 TypeTableEntry *type_entry)
590595{
591596 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node);
592 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_type;
593 const_instruction->base.static_value.special = ConstValSpecialStatic;
594 const_instruction->base.static_value.data.x_type = type_entry;
597 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
598 const_instruction->base.value.special = ConstValSpecialStatic;
599 const_instruction->base.value.data.x_type = type_entry;
595600 return &const_instruction->base;
596601}
597602
......@@ -605,17 +610,17 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode
605610
606611static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) {
607612 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
608 const_instruction->base.type_entry = fn_entry->type_entry;
609 const_instruction->base.static_value.special = ConstValSpecialStatic;
610 const_instruction->base.static_value.data.x_fn = fn_entry;
613 const_instruction->base.value.type = fn_entry->type_entry;
614 const_instruction->base.value.special = ConstValSpecialStatic;
615 const_instruction->base.value.data.x_fn = fn_entry;
611616 return &const_instruction->base;
612617}
613618
614619static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) {
615620 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
616 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_namespace;
617 const_instruction->base.static_value.special = ConstValSpecialStatic;
618 const_instruction->base.static_value.data.x_import = import;
621 const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace;
622 const_instruction->base.value.special = ConstValSpecialStatic;
623 const_instruction->base.value.data.x_import = import;
619624 return &const_instruction->base;
620625}
621626
......@@ -623,17 +628,17 @@ static IrInstruction *ir_build_const_scope(IrBuilder *irb, Scope *parent_scope,
623628 Scope *target_scope)
624629{
625630 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, parent_scope, source_node);
626 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block;
627 const_instruction->base.static_value.special = ConstValSpecialStatic;
628 const_instruction->base.static_value.data.x_block = target_scope;
631 const_instruction->base.value.type = irb->codegen->builtin_types.entry_block;
632 const_instruction->base.value.special = ConstValSpecialStatic;
633 const_instruction->base.value.data.x_block = target_scope;
629634 return &const_instruction->base;
630635}
631636
632637static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
633638 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
634 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_bool;
635 const_instruction->base.static_value.special = ConstValSpecialStatic;
636 const_instruction->base.static_value.data.x_bool = value;
639 const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool;
640 const_instruction->base.value.special = ConstValSpecialStatic;
641 const_instruction->base.value.data.x_bool = value;
637642 return &const_instruction->base;
638643}
639644
......@@ -641,21 +646,17 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN
641646 FnTableEntry *fn_entry, IrInstruction *first_arg, bool depends_on_compile_var)
642647{
643648 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
644 const_instruction->base.type_entry = get_bound_fn_type(irb->codegen, fn_entry);
645 const_instruction->base.static_value.special = ConstValSpecialStatic;
646 const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var;
647 const_instruction->base.static_value.data.x_bound_fn.fn = fn_entry;
648 const_instruction->base.static_value.data.x_bound_fn.first_arg = first_arg;
649 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);
650 const_instruction->base.value.special = ConstValSpecialStatic;
651 const_instruction->base.value.depends_on_compile_var = depends_on_compile_var;
652 const_instruction->base.value.data.x_bound_fn.fn = fn_entry;
653 const_instruction->base.value.data.x_bound_fn.first_arg = first_arg;
649654 return &const_instruction->base;
650655}
651656
652657static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
653658 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node);
654 TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8;
655 TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str));
656 const_instruction->base.type_entry = type_entry;
657 ConstExprValue *const_val = &const_instruction->base.static_value;
658 init_const_str_lit(const_val, str);
659 init_const_str_lit(irb->codegen, &const_instruction->base.value, str);
659660
660661 return &const_instruction->base;
661662}
......@@ -666,32 +667,8 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNo
666667}
667668
668669static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
669 // first we build the underlying array
670 size_t len_with_null = buf_len(str) + 1;
671 ConstExprValue *array_val = allocate<ConstExprValue>(1);
672 array_val->special = ConstValSpecialStatic;
673 array_val->data.x_array.elements = allocate<ConstExprValue>(len_with_null);
674 array_val->data.x_array.size = len_with_null;
675 for (size_t i = 0; i < buf_len(str); i += 1) {
676 ConstExprValue *this_char = &array_val->data.x_array.elements[i];
677 this_char->special = ConstValSpecialStatic;
678 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);
679 }
680 ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1];
681 null_char->special = ConstValSpecialStatic;
682 bignum_init_unsigned(&null_char->data.x_bignum, 0);
683
684 // then make the pointer point to it
685670 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
686 TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8;
687 TypeTableEntry *type_entry = get_pointer_to_type(irb->codegen, u8_type, true);
688 const_instruction->base.type_entry = type_entry;
689 ConstExprValue *ptr_val = &const_instruction->base.static_value;
690 ptr_val->special = ConstValSpecialStatic;
691 ptr_val->data.x_ptr.base_ptr = array_val;
692 ptr_val->data.x_ptr.index = 0;
693 ptr_val->data.x_ptr.special = ConstPtrSpecialCStr;
694
671 init_const_c_str_lit(irb->codegen, &const_instruction->base.value, str);
695672 return &const_instruction->base;
696673}
697674
......@@ -870,8 +847,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source
870847 IrBasicBlock *dest_block, IrInstruction *is_comptime)
871848{
872849 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb->exec, scope, source_node);
873 br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable;
874 br_instruction->base.static_value.special = ConstValSpecialStatic;
850 br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
851 br_instruction->base.value.special = ConstValSpecialStatic;
875852 br_instruction->dest_block = dest_block;
876853 br_instruction->is_comptime = is_comptime;
877854
......@@ -983,8 +960,8 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o
983960static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
984961 IrInstructionUnreachable *unreachable_instruction =
985962 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
986 unreachable_instruction->base.static_value.special = ConstValSpecialStatic;
987 unreachable_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable;
963 unreachable_instruction->base.value.special = ConstValSpecialStatic;
964 unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
988965 return &unreachable_instruction->base;
989966}
990967
......@@ -998,8 +975,8 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *
998975 IrInstruction *ptr, IrInstruction *value)
999976{
1000977 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);
1001 instruction->base.static_value.special = ConstValSpecialStatic;
1002 instruction->base.type_entry = irb->codegen->builtin_types.entry_void;
978 instruction->base.value.special = ConstValSpecialStatic;
979 instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1003980 instruction->ptr = ptr;
1004981 instruction->value = value;
1005982
......@@ -1022,8 +999,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
1022999 VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value)
10231000{
10241001 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);
1025 decl_var_instruction->base.static_value.special = ConstValSpecialStatic;
1026 decl_var_instruction->base.type_entry = irb->codegen->builtin_types.entry_void;
1002 decl_var_instruction->base.value.special = ConstValSpecialStatic;
1003 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
10271004 decl_var_instruction->var = var;
10281005 decl_var_instruction->var_type = var_type;
10291006 decl_var_instruction->init_value = init_value;
......@@ -1302,8 +1279,8 @@ static IrInstruction *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *
13021279 IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime)
13031280{
13041281 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);
1305 instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable;
1306 instruction->base.static_value.special = ConstValSpecialStatic;
1282 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
1283 instruction->base.value.special = ConstValSpecialStatic;
13071284 instruction->target_value = target_value;
13081285 instruction->else_block = else_block;
13091286 instruction->case_count = case_count;
......@@ -1682,13 +1659,14 @@ static IrInstruction *ir_build_memcpy_from(IrBuilder *irb, IrInstruction *old_in
16821659}
16831660
16841661static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *source_node,
1685 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const)
1662 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const, bool safety_check_on)
16861663{
16871664 IrInstructionSlice *instruction = ir_build_instruction<IrInstructionSlice>(irb, scope, source_node);
16881665 instruction->ptr = ptr;
16891666 instruction->start = start;
16901667 instruction->end = end;
16911668 instruction->is_const = is_const;
1669 instruction->safety_check_on = safety_check_on;
16921670
16931671 ir_ref_instruction(ptr);
16941672 ir_ref_instruction(start);
......@@ -1698,9 +1676,10 @@ static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *sour
16981676}
16991677
17001678static IrInstruction *ir_build_slice_from(IrBuilder *irb, IrInstruction *old_instruction,
1701 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const)
1679 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool is_const, bool safety_check_on)
17021680{
1703 IrInstruction *new_instruction = ir_build_slice(irb, old_instruction->scope, old_instruction->source_node, ptr, start, end, is_const);
1681 IrInstruction *new_instruction = ir_build_slice(irb, old_instruction->scope,
1682 old_instruction->source_node, ptr, start, end, is_const, safety_check_on);
17041683 ir_link_new_instruction(new_instruction, old_instruction);
17051684 return new_instruction;
17061685}
......@@ -1892,6 +1871,18 @@ static IrInstruction *ir_build_init_enum_from(IrBuilder *irb, IrInstruction *old
18921871 return new_instruction;
18931872}
18941873
1874static IrInstruction *ir_build_pointer_reinterpret(IrBuilder *irb, Scope *scope, AstNode *source_node,
1875 IrInstruction *ptr)
1876{
1877 IrInstructionPointerReinterpret *instruction = ir_build_instruction<IrInstructionPointerReinterpret>(
1878 irb, scope, source_node);
1879 instruction->ptr = ptr;
1880
1881 ir_ref_instruction(ptr);
1882
1883 return &instruction->base;
1884}
1885
18951886static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
18961887 results[ReturnKindUnconditional] = 0;
18971888 results[ReturnKindError] = 0;
......@@ -2088,21 +2079,21 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
20882079 ErrorMsg *msg = add_node_error(codegen, node,
20892080 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
20902081 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
2091 variable_entry->type = codegen->builtin_types.entry_invalid;
2082 variable_entry->value.type = codegen->builtin_types.entry_invalid;
20922083 } else {
20932084 auto primitive_table_entry = codegen->primitive_type_table.maybe_get(name);
20942085 if (primitive_table_entry) {
20952086 TypeTableEntry *type = primitive_table_entry->value;
20962087 add_node_error(codegen, node,
20972088 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
2098 variable_entry->type = codegen->builtin_types.entry_invalid;
2089 variable_entry->value.type = codegen->builtin_types.entry_invalid;
20992090 } else {
21002091 Tld *tld = find_decl(parent_scope, name);
21012092 if (tld && tld->id != TldIdVar) {
21022093 ErrorMsg *msg = add_node_error(codegen, node,
21032094 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
21042095 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here"));
2105 variable_entry->type = codegen->builtin_types.entry_invalid;
2096 variable_entry->value.type = codegen->builtin_types.entry_invalid;
21062097 }
21072098 }
21082099 }
......@@ -3275,7 +3266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
32753266 // is inside var->child_scope
32763267
32773268 if (!is_extern && !variable_declaration->expr) {
3278 var->type = irb->codegen->builtin_types.entry_invalid;
3269 var->value.type = irb->codegen->builtin_types.entry_invalid;
32793270 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));
32803271 return irb->codegen->invalid_instruction;
32813272 }
......@@ -3988,7 +3979,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node)
39883979 end_value = nullptr;
39893980 }
39903981
3991 return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, slice_expr->is_const);
3982 return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, slice_expr->is_const, true);
39923983}
39933984
39943985static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
......@@ -4348,7 +4339,7 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
43484339 if (instruction->id == IrInstructionIdReturn) {
43494340 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
43504341 IrInstruction *value = ret_inst->value;
4351 assert(value->static_value.special != ConstValSpecialRuntime);
4342 assert(value->value.special != ConstValSpecialRuntime);
43524343 return value;
43534344 } else if (ir_has_side_effects(instruction)) {
43544345 return nullptr;
......@@ -4372,7 +4363,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
43724363 return false;
43734364 }
43744365
4375 ConstExprValue *const_val = &instruction->static_value;
4366 ConstExprValue *const_val = &instruction->value;
43764367 assert(const_val->special != ConstValSpecialRuntime);
43774368 if (other_type_underlying->id == TypeTableEntryIdFloat) {
43784369 return true;
......@@ -4514,15 +4505,15 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
45144505static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {
45154506 assert(instruction_count >= 1);
45164507 IrInstruction *prev_inst = instructions[0];
4517 if (prev_inst->type_entry->id == TypeTableEntryIdInvalid) {
4508 if (prev_inst->value.type->id == TypeTableEntryIdInvalid) {
45184509 return ira->codegen->builtin_types.entry_invalid;
45194510 }
4520 bool any_are_pure_error = (prev_inst->type_entry->id == TypeTableEntryIdPureError);
4521 bool any_are_null = (prev_inst->type_entry->id == TypeTableEntryIdNullLit);
4511 bool any_are_pure_error = (prev_inst->value.type->id == TypeTableEntryIdPureError);
4512 bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNullLit);
45224513 for (size_t i = 1; i < instruction_count; i += 1) {
45234514 IrInstruction *cur_inst = instructions[i];
4524 TypeTableEntry *cur_type = cur_inst->type_entry;
4525 TypeTableEntry *prev_type = prev_inst->type_entry;
4515 TypeTableEntry *cur_type = cur_inst->value.type;
4516 TypeTableEntry *prev_type = prev_inst->value.type;
45264517 if (cur_type->id == TypeTableEntryIdInvalid) {
45274518 return cur_type;
45284519 } else if (prev_type->id == TypeTableEntryIdUnreachable) {
......@@ -4598,32 +4589,32 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
45984589 return ira->codegen->builtin_types.entry_invalid;
45994590 }
46004591 }
4601 if (any_are_pure_error && prev_inst->type_entry->id != TypeTableEntryIdPureError) {
4602 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
4603 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
4592 if (any_are_pure_error && prev_inst->value.type->id != TypeTableEntryIdPureError) {
4593 if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt ||
4594 prev_inst->value.type->id == TypeTableEntryIdNumLitFloat)
46044595 {
46054596 ir_add_error_node(ira, source_node,
46064597 buf_sprintf("unable to make error union out of number literal"));
46074598 return ira->codegen->builtin_types.entry_invalid;
4608 } else if (prev_inst->type_entry->id == TypeTableEntryIdNullLit) {
4599 } else if (prev_inst->value.type->id == TypeTableEntryIdNullLit) {
46094600 ir_add_error_node(ira, source_node,
46104601 buf_sprintf("unable to make error union out of null literal"));
46114602 return ira->codegen->builtin_types.entry_invalid;
46124603 } else {
4613 return get_error_type(ira->codegen, prev_inst->type_entry);
4604 return get_error_type(ira->codegen, prev_inst->value.type);
46144605 }
4615 } else if (any_are_null && prev_inst->type_entry->id != TypeTableEntryIdNullLit) {
4616 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
4617 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
4606 } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNullLit) {
4607 if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt ||
4608 prev_inst->value.type->id == TypeTableEntryIdNumLitFloat)
46184609 {
46194610 ir_add_error_node(ira, source_node,
46204611 buf_sprintf("unable to make maybe out of number literal"));
46214612 return ira->codegen->builtin_types.entry_invalid;
46224613 } else {
4623 return get_maybe_type(ira->codegen, prev_inst->type_entry);
4614 return get_maybe_type(ira->codegen, prev_inst->value.type);
46244615 }
46254616 } else {
4626 return prev_inst->type_entry;
4617 return prev_inst->value.type;
46274618 }
46284619}
46294620
......@@ -4649,9 +4640,7 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
46494640 case CastOpNoop:
46504641 case CastOpWidenOrShorten:
46514642 *const_val = *other_val;
4652 break;
4653 case CastOpPointerReinterpret:
4654 zig_panic("TODO compile time pointer reinterpret");
4643 const_val->type = new_type;
46554644 break;
46564645 case CastOpPtrToInt:
46574646 case CastOpIntToPtr:
......@@ -4659,24 +4648,6 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
46594648 case CastOpBytesToSlice:
46604649 // can't do it
46614650 break;
4662 case CastOpToUnknownSizeArray:
4663 {
4664 assert(other_type->id == TypeTableEntryIdArray);
4665 assert(other_val->data.x_array.size == other_type->data.array.len);
4666
4667 const_val->data.x_struct.fields = allocate<ConstExprValue>(2);
4668 ConstExprValue *ptr_field = &const_val->data.x_struct.fields[slice_ptr_index];
4669 ConstExprValue *len_field = &const_val->data.x_struct.fields[slice_len_index];
4670
4671 ptr_field->special = ConstValSpecialStatic;
4672 ptr_field->data.x_ptr.base_ptr = other_val;
4673
4674 len_field->special = ConstValSpecialStatic;
4675 bignum_init_unsigned(&len_field->data.x_bignum, other_type->data.array.len);
4676
4677 const_val->special = ConstValSpecialStatic;
4678 break;
4679 }
46804651 case CastOpErrToInt:
46814652 {
46824653 uint64_t value;
......@@ -4722,14 +4693,15 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
47224693static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
47234694 TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca)
47244695{
4725 if (value->static_value.special != ConstValSpecialRuntime) {
4726 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, false);
4727 eval_const_expr_implicit_cast(cast_op, &value->static_value, value->type_entry,
4728 &result->static_value, wanted_type);
4696 if (value->value.special != ConstValSpecialRuntime) {
4697 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
4698 source_instr->source_node, wanted_type, false);
4699 eval_const_expr_implicit_cast(cast_op, &value->value, value->value.type,
4700 &result->value, wanted_type);
47294701 return result;
47304702 } else {
47314703 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
4732 result->type_entry = wanted_type;
4704 result->value.type = wanted_type;
47334705 if (need_alloca) {
47344706 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
47354707 if (fn_entry)
......@@ -4861,7 +4833,7 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in
48614833 new_instruction = &const_instruction->base;
48624834 }
48634835 ir_link_new_instruction(new_instruction, old_instruction);
4864 ConstExprValue *const_val = &new_instruction->static_value;
4836 ConstExprValue *const_val = &new_instruction->value;
48654837 const_val->special = ConstValSpecialStatic;
48664838 const_val->depends_on_compile_var = depends_on_compile_var;
48674839 return const_val;
......@@ -4906,15 +4878,15 @@ enum UndefAllowed {
49064878};
49074879
49084880static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
4909 switch (value->static_value.special) {
4881 switch (value->value.special) {
49104882 case ConstValSpecialStatic:
4911 return &value->static_value;
4883 return &value->value;
49124884 case ConstValSpecialRuntime:
49134885 ir_add_error(ira, value, buf_sprintf("unable to evaluate constant expression"));
49144886 return nullptr;
49154887 case ConstValSpecialUndef:
49164888 if (undef_allowed == UndefOk) {
4917 return &value->static_value;
4889 return &value->value;
49184890 } else {
49194891 ir_add_error(ira, value, buf_sprintf("use of undefined value"));
49204892 return nullptr;
......@@ -4979,12 +4951,12 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
49794951}
49804952
49814953static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
4982 if (type_value->type_entry->id == TypeTableEntryIdInvalid)
4954 if (type_value->value.type->id == TypeTableEntryIdInvalid)
49834955 return ira->codegen->builtin_types.entry_invalid;
49844956
4985 if (type_value->type_entry->id != TypeTableEntryIdMetaType) {
4957 if (type_value->value.type->id != TypeTableEntryIdMetaType) {
49864958 ir_add_error(ira, type_value,
4987 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->type_entry->name)));
4959 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
49884960 return ira->codegen->builtin_types.entry_invalid;
49894961 }
49904962
......@@ -4999,12 +4971,12 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
49994971 if (fn_value == ira->codegen->invalid_instruction)
50004972 return nullptr;
50014973
5002 if (fn_value->type_entry->id == TypeTableEntryIdInvalid)
4974 if (fn_value->value.type->id == TypeTableEntryIdInvalid)
50034975 return nullptr;
50044976
5005 if (fn_value->type_entry->id != TypeTableEntryIdFn) {
4977 if (fn_value->value.type->id != TypeTableEntryIdFn) {
50064978 ir_add_error_node(ira, fn_value->source_node,
5007 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->type_entry->name)));
4979 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));
50084980 return nullptr;
50094981 }
50104982
......@@ -5019,47 +4991,88 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
50194991 assert(wanted_type->id == TypeTableEntryIdMaybe);
50204992
50214993 if (instr_is_comptime(value)) {
5022 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
4994 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
4995 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
4996 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)
4997 return ira->codegen->invalid_instruction;
4998
4999 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
50235000 if (!val)
50245001 return ira->codegen->invalid_instruction;
50255002
50265003 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
50275004 source_instr->scope, source_instr->source_node);
5028 const_instruction->base.type_entry = wanted_type;
5029 const_instruction->base.static_value.special = ConstValSpecialStatic;
5030 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
5031 const_instruction->base.static_value.data.x_maybe = &value->static_value;
5005 const_instruction->base.value.type = wanted_type;
5006 const_instruction->base.value.special = ConstValSpecialStatic;
5007 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
5008 const_instruction->base.value.data.x_maybe = val;
50325009 return &const_instruction->base;
50335010 }
50345011
50355012 IrInstruction *result = ir_build_maybe_wrap(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
5036 result->type_entry = wanted_type;
5037 result->static_value.data.rh_maybe = RuntimeHintMaybeNonNull;
5013 result->value.type = wanted_type;
5014 result->value.data.rh_maybe = RuntimeHintMaybeNonNull;
50385015 ir_add_alloca(ira, result, wanted_type);
50395016 return result;
50405017}
50415018
5042static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
5019static IrInstruction *ir_analyze_pointer_reinterpret(IrAnalyze *ira, IrInstruction *source_instr,
5020 IrInstruction *ptr, TypeTableEntry *wanted_type)
5021{
5022 assert(wanted_type->id == TypeTableEntryIdPointer);
5023
5024 if (ptr->value.type->id != TypeTableEntryIdPointer) {
5025 ir_add_error(ira, ptr,
5026 buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name)));
5027 return ira->codegen->invalid_instruction;
5028 }
5029
5030 if (instr_is_comptime(ptr)) {
5031 ConstExprValue *val = ir_resolve_const(ira, ptr, UndefOk);
5032 if (!val)
5033 return ira->codegen->invalid_instruction;
5034
5035 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
5036 source_instr->scope, source_instr->source_node);
5037 const_instruction->base.value = *val;
5038 const_instruction->base.value.type = wanted_type;
5039 return &const_instruction->base;
5040 }
5041
5042 IrInstruction *result = ir_build_pointer_reinterpret(&ira->new_irb, source_instr->scope,
5043 source_instr->source_node, ptr);
5044 result->value.type = wanted_type;
5045 return result;
5046}
5047
5048static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
5049 IrInstruction *value, TypeTableEntry *wanted_type)
5050{
50435051 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
50445052
50455053 if (instr_is_comptime(value)) {
5046 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
5054 TypeTableEntry *payload_type = wanted_type->data.error.child_type;
5055 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
5056 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)
5057 return ira->codegen->invalid_instruction;
5058
5059 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
50475060 if (!val)
50485061 return ira->codegen->invalid_instruction;
50495062
50505063 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
50515064 source_instr->scope, source_instr->source_node);
5052 const_instruction->base.type_entry = wanted_type;
5053 const_instruction->base.static_value.special = ConstValSpecialStatic;
5054 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
5055 const_instruction->base.static_value.data.x_err_union.err = nullptr;
5056 const_instruction->base.static_value.data.x_err_union.payload = val;
5065 const_instruction->base.value.type = wanted_type;
5066 const_instruction->base.value.special = ConstValSpecialStatic;
5067 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
5068 const_instruction->base.value.data.x_err_union.err = nullptr;
5069 const_instruction->base.value.data.x_err_union.payload = val;
50575070 return &const_instruction->base;
50585071 }
50595072
50605073 IrInstruction *result = ir_build_err_wrap_payload(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
5061 result->type_entry = wanted_type;
5062 result->static_value.data.rh_error_union = RuntimeHintErrorUnionNonError;
5074 result->value.type = wanted_type;
5075 result->value.data.rh_error_union = RuntimeHintErrorUnionNonError;
50635076 ir_add_alloca(ira, result, wanted_type);
50645077 return result;
50655078}
......@@ -5074,17 +5087,17 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
50745087
50755088 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
50765089 source_instr->scope, source_instr->source_node);
5077 const_instruction->base.type_entry = wanted_type;
5078 const_instruction->base.static_value.special = ConstValSpecialStatic;
5079 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
5080 const_instruction->base.static_value.data.x_err_union.err = val->data.x_pure_err;
5081 const_instruction->base.static_value.data.x_err_union.payload = nullptr;
5090 const_instruction->base.value.type = wanted_type;
5091 const_instruction->base.value.special = ConstValSpecialStatic;
5092 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
5093 const_instruction->base.value.data.x_err_union.err = val->data.x_pure_err;
5094 const_instruction->base.value.data.x_err_union.payload = nullptr;
50825095 return &const_instruction->base;
50835096 }
50845097
50855098 IrInstruction *result = ir_build_err_wrap_code(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
5086 result->type_entry = wanted_type;
5087 result->static_value.data.rh_error_union = RuntimeHintErrorUnionError;
5099 result->value.type = wanted_type;
5100 result->value.data.rh_error_union = RuntimeHintErrorUnionError;
50885101 ir_add_alloca(ira, result, wanted_type);
50895102 return result;
50905103}
......@@ -5097,11 +5110,11 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
50975110
50985111 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
50995112 source_instr->scope, source_instr->source_node);
5100 const_instruction->base.type_entry = wanted_type;
5101 const_instruction->base.static_value.special = ConstValSpecialStatic;
5102 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
5103 const_instruction->base.static_value.data.x_ptr.base_ptr = val;
5104 const_instruction->base.static_value.data.x_ptr.index = SIZE_MAX;
5113 const_instruction->base.value.type = wanted_type;
5114 const_instruction->base.value.special = ConstValSpecialStatic;
5115 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
5116 const_instruction->base.value.data.x_ptr.base_ptr = val;
5117 const_instruction->base.value.data.x_ptr.index = SIZE_MAX;
51055118 return &const_instruction->base;
51065119 }
51075120
......@@ -5130,17 +5143,48 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
51305143 assert(val);
51315144
51325145 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, source_instr->scope, source_instr->source_node);
5133 const_instruction->base.type_entry = wanted_type;
5134 const_instruction->base.static_value.special = ConstValSpecialStatic;
5135 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
5136 const_instruction->base.static_value.data.x_maybe = nullptr;
5146 const_instruction->base.value.type = wanted_type;
5147 const_instruction->base.value.special = ConstValSpecialStatic;
5148 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
5149 const_instruction->base.value.data.x_maybe = nullptr;
51375150 return &const_instruction->base;
51385151}
51395152
5153static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
5154 IrInstruction *array, TypeTableEntry *wanted_type)
5155{
5156 assert(is_slice(wanted_type));
5157
5158 TypeTableEntry *array_type = array->value.type;
5159 assert(array_type->id == TypeTableEntryIdArray);
5160
5161 if (instr_is_comptime(array)) {
5162 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
5163 source_instr->source_node, wanted_type, false);
5164 init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true);
5165 return result;
5166 }
5167
5168 IrInstruction *start = ir_create_const(&ira->new_irb, source_instr->scope,
5169 source_instr->source_node, ira->codegen->builtin_types.entry_usize, false);
5170 init_const_usize(ira->codegen, &start->value, 0);
5171
5172 IrInstruction *end = ir_create_const(&ira->new_irb, source_instr->scope,
5173 source_instr->source_node, ira->codegen->builtin_types.entry_usize, false);
5174 init_const_usize(ira->codegen, &end->value, array_type->data.array.len);
5175
5176 IrInstruction *result = ir_build_slice(&ira->new_irb, source_instr->scope,
5177 source_instr->source_node, array, start, end, true, false);
5178 TypeTableEntry *child_type = array_type->data.array.child_type;
5179 result->value.type = get_slice_type(ira->codegen, child_type, true);
5180 ir_add_alloca(ira, result, result->value.type);
5181 return result;
5182}
5183
51405184static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
51415185 TypeTableEntry *wanted_type, IrInstruction *value)
51425186{
5143 TypeTableEntry *actual_type = value->type_entry;
5187 TypeTableEntry *actual_type = value->value.type;
51445188 TypeTableEntry *wanted_type_canon = get_underlying_type(wanted_type);
51455189 TypeTableEntry *actual_type_canon = get_underlying_type(actual_type);
51465190
......@@ -5213,7 +5257,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
52135257 wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type,
52145258 actual_type->data.array.child_type))
52155259 {
5216 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpToUnknownSizeArray, true);
5260 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
52175261 }
52185262
52195263 // explicit cast from []T to []u8 or []u8 to []T
......@@ -5251,7 +5295,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
52515295 if ((actual_type->id == TypeTableEntryIdPointer || actual_type->id == TypeTableEntryIdFn) &&
52525296 (wanted_type->id == TypeTableEntryIdPointer || wanted_type->id == TypeTableEntryIdFn))
52535297 {
5254 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpPointerReinterpret, false);
5298 return ir_analyze_pointer_reinterpret(ira, source_instr, value, wanted_type);
52555299 }
52565300
52575301 // explicit cast from maybe pointer to another maybe pointer
......@@ -5262,7 +5306,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
52625306 (wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer ||
52635307 wanted_type->data.maybe.child_type->id == TypeTableEntryIdFn))
52645308 {
5265 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpPointerReinterpret, false);
5309 return ir_analyze_pointer_reinterpret(ira, source_instr, value, wanted_type);
52665310 }
52675311
52685312 // explicit cast from child type of maybe type to maybe type
......@@ -5394,22 +5438,22 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
53945438 assert(value);
53955439 assert(value != ira->codegen->invalid_instruction);
53965440 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
5397 assert(value->type_entry);
5398 assert(value->type_entry->id != TypeTableEntryIdInvalid);
5441 assert(value->value.type);
5442 assert(value->value.type->id != TypeTableEntryIdInvalid);
53995443 if (expected_type == nullptr)
54005444 return value; // anything will do
5401 if (expected_type == value->type_entry)
5445 if (expected_type == value->value.type)
54025446 return value; // match
5403 if (value->type_entry->id == TypeTableEntryIdUnreachable)
5447 if (value->value.type->id == TypeTableEntryIdUnreachable)
54045448 return value;
54055449
5406 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->type_entry, value);
5450 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->value.type, value);
54075451 switch (result) {
54085452 case ImplicitCastMatchResultNo:
54095453 ir_add_error(ira, value,
54105454 buf_sprintf("expected type '%s', found '%s'",
54115455 buf_ptr(&expected_type->name),
5412 buf_ptr(&value->type_entry->name)));
5456 buf_ptr(&value->value.type->name)));
54135457 return ira->codegen->invalid_instruction;
54145458
54155459 case ImplicitCastMatchResultYes:
......@@ -5422,23 +5466,23 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
54225466}
54235467
54245468static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
5425 TypeTableEntry *type_entry = ptr->type_entry;
5469 TypeTableEntry *type_entry = ptr->value.type;
54265470 if (type_entry->id == TypeTableEntryIdInvalid) {
54275471 return ira->codegen->invalid_instruction;
54285472 } else if (type_entry->id == TypeTableEntryIdPointer) {
54295473 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
5430 if (ptr->static_value.special != ConstValSpecialRuntime) {
5431 ConstExprValue *pointee = const_ptr_pointee(&ptr->static_value);
5474 if (ptr->value.special != ConstValSpecialRuntime) {
5475 ConstExprValue *pointee = const_ptr_pointee(&ptr->value);
54325476 if (pointee->special != ConstValSpecialRuntime) {
54335477 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
54345478 source_instruction->source_node, child_type, pointee->depends_on_compile_var);
5435 result->static_value = *pointee;
5479 result->value = *pointee;
54365480 return result;
54375481 }
54385482 }
54395483 // TODO if the instruction is a get pointer instruction we can skip it
54405484 IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr);
5441 load_ptr_instruction->type_entry = child_type;
5485 load_ptr_instruction->value.type = child_type;
54425486 return load_ptr_instruction;
54435487 } else if (type_entry->id == TypeTableEntryIdMetaType) {
54445488 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad);
......@@ -5465,18 +5509,18 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
54655509static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
54665510 bool is_const)
54675511{
5468 if (value->type_entry->id == TypeTableEntryIdInvalid)
5512 if (value->value.type->id == TypeTableEntryIdInvalid)
54695513 return ira->codegen->builtin_types.entry_invalid;
54705514
54715515 if (instr_is_comptime(value)) {
54725516 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
54735517 if (!val)
54745518 return ira->codegen->builtin_types.entry_invalid;
5475 return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry,
5519 return ir_analyze_const_ptr(ira, source_instruction, val, value->value.type,
54765520 false, ConstPtrSpecialNone, is_const);
54775521 }
54785522
5479 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, value->type_entry, true);
5523 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, value->value.type, true);
54805524 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
54815525 assert(fn_entry);
54825526 IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value, is_const);
......@@ -5485,11 +5529,11 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
54855529}
54865530
54875531static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
5488 if (value->type_entry->id == TypeTableEntryIdInvalid)
5532 if (value->value.type->id == TypeTableEntryIdInvalid)
54895533 return false;
54905534
54915535 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);
5492 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5536 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
54935537 return false;
54945538
54955539 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -5501,11 +5545,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
55015545}
55025546
55035547static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
5504 if (value->type_entry->id == TypeTableEntryIdInvalid)
5548 if (value->value.type->id == TypeTableEntryIdInvalid)
55055549 return false;
55065550
55075551 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
5508 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5552 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
55095553 return false;
55105554
55115555 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -5517,11 +5561,11 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
55175561}
55185562
55195563static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
5520 if (value->type_entry->id == TypeTableEntryIdInvalid)
5564 if (value->value.type->id == TypeTableEntryIdInvalid)
55215565 return false;
55225566
55235567 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
5524 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5568 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
55255569 return false;
55265570
55275571 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -5533,12 +5577,12 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
55335577}
55345578
55355579static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
5536 if (value->type_entry->id == TypeTableEntryIdInvalid)
5580 if (value->value.type->id == TypeTableEntryIdInvalid)
55375581 return nullptr;
55385582
55395583 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
55405584 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
5541 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5585 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
55425586 return nullptr;
55435587
55445588 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -5567,7 +5611,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
55675611 IrInstructionReturn *return_instruction)
55685612{
55695613 IrInstruction *value = return_instruction->value->other;
5570 if (value->type_entry->id == TypeTableEntryIdInvalid)
5614 if (value->value.type->id == TypeTableEntryIdInvalid)
55715615 return ir_unreach_error(ira);
55725616 ira->implicit_return_type_list.append(value);
55735617
......@@ -5580,19 +5624,19 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
55805624}
55815625
55825626static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
5583 bool depends_on_compile_var = const_instruction->base.static_value.depends_on_compile_var;
5627 bool depends_on_compile_var = const_instruction->base.value.depends_on_compile_var;
55845628 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base, depends_on_compile_var);
5585 *out_val = const_instruction->base.static_value;
5586 return const_instruction->base.type_entry;
5629 *out_val = const_instruction->base.value;
5630 return const_instruction->base.value.type;
55875631}
55885632
55895633static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
55905634 IrInstruction *op1 = bin_op_instruction->op1->other;
5591 if (op1->type_entry->id == TypeTableEntryIdInvalid)
5635 if (op1->value.type->id == TypeTableEntryIdInvalid)
55925636 return ira->codegen->builtin_types.entry_invalid;
55935637
55945638 IrInstruction *op2 = bin_op_instruction->op2->other;
5595 if (op2->type_entry->id == TypeTableEntryIdInvalid)
5639 if (op2->value.type->id == TypeTableEntryIdInvalid)
55965640 return ira->codegen->builtin_types.entry_invalid;
55975641
55985642 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
......@@ -5605,14 +5649,14 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
56055649 if (casted_op2 == ira->codegen->invalid_instruction)
56065650 return ira->codegen->builtin_types.entry_invalid;
56075651
5608 ConstExprValue *op1_val = &casted_op1->static_value;
5609 ConstExprValue *op2_val = &casted_op2->static_value;
5652 ConstExprValue *op1_val = &casted_op1->value;
5653 ConstExprValue *op2_val = &casted_op2->value;
56105654 if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {
56115655 bool depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var;
56125656 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base, depends_on_compile_var);
56135657
5614 assert(casted_op1->type_entry->id == TypeTableEntryIdBool);
5615 assert(casted_op2->type_entry->id == TypeTableEntryIdBool);
5658 assert(casted_op1->value.type->id == TypeTableEntryIdBool);
5659 assert(casted_op2->value.type->id == TypeTableEntryIdBool);
56165660 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
56175661 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;
56185662 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {
......@@ -5701,8 +5745,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
57015745 if (casted_op2 == ira->codegen->invalid_instruction)
57025746 return ira->codegen->builtin_types.entry_invalid;
57035747
5704 ConstExprValue *op1_val = &casted_op1->static_value;
5705 ConstExprValue *op2_val = &casted_op2->static_value;
5748 ConstExprValue *op1_val = &casted_op1->value;
5749 ConstExprValue *op2_val = &casted_op2->value;
57065750 if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {
57075751 bool type_can_gt_lt_cmp = (resolved_type->id == TypeTableEntryIdNumLitFloat ||
57085752 resolved_type->id == TypeTableEntryIdNumLitInt ||
......@@ -5729,7 +5773,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
57295773
57305774 answer = bignum_cmp(&op1_val->data.x_bignum, &op2_val->data.x_bignum);
57315775 } else {
5732 bool are_equal = const_values_equal(op1_val, op2_val, resolved_type);
5776 bool are_equal = const_values_equal(op1_val, op2_val);
57335777 if (op_id == IrBinOpCmpEq) {
57345778 answer = are_equal;
57355779 } else if (op_id == IrBinOpCmpNotEq) {
......@@ -5872,8 +5916,8 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
58725916 AstNode *source_node = bin_op_instruction->base.source_node;
58735917 ir_add_error_node(ira, source_node,
58745918 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
5875 buf_ptr(&op1->type_entry->name),
5876 buf_ptr(&op2->type_entry->name)));
5919 buf_ptr(&op1->value.type->name),
5920 buf_ptr(&op2->value.type->name)));
58775921 return ira->codegen->builtin_types.entry_invalid;
58785922 }
58795923
......@@ -5886,10 +5930,10 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
58865930 return ira->codegen->builtin_types.entry_invalid;
58875931
58885932
5889 if (casted_op1->static_value.special != ConstValSpecialRuntime && casted_op2->static_value.special != ConstValSpecialRuntime) {
5890 ConstExprValue *op1_val = &casted_op1->static_value;
5891 ConstExprValue *op2_val = &casted_op2->static_value;
5892 ConstExprValue *out_val = &bin_op_instruction->base.static_value;
5933 if (casted_op1->value.special != ConstValSpecialRuntime && casted_op2->value.special != ConstValSpecialRuntime) {
5934 ConstExprValue *op1_val = &casted_op1->value;
5935 ConstExprValue *op2_val = &casted_op2->value;
5936 ConstExprValue *out_val = &bin_op_instruction->base.value;
58935937
58945938 bin_op_instruction->base.other = &bin_op_instruction->base;
58955939
......@@ -5919,12 +5963,12 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
59195963
59205964static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
59215965 IrInstruction *op1 = instruction->op1->other;
5922 TypeTableEntry *op1_canon_type = get_underlying_type(op1->type_entry);
5966 TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type);
59235967 if (op1_canon_type->id == TypeTableEntryIdInvalid)
59245968 return ira->codegen->builtin_types.entry_invalid;
59255969
59265970 IrInstruction *op2 = instruction->op2->other;
5927 TypeTableEntry *op2_canon_type = get_underlying_type(op2->type_entry);
5971 TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type);
59285972 if (op2_canon_type->id == TypeTableEntryIdInvalid)
59295973 return ira->codegen->builtin_types.entry_invalid;
59305974
......@@ -5955,7 +5999,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
59555999 op1_array_end = op1_array_val->data.x_array.size - 1;
59566000 } else {
59576001 ir_add_error(ira, op1,
5958 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->type_entry->name)));
6002 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
59596003 // TODO if meta_type is type decl, add note pointing to type decl declaration
59606004 return ira->codegen->builtin_types.entry_invalid;
59616005 }
......@@ -5967,7 +6011,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
59676011 if (op2_canon_type->data.array.child_type != child_type) {
59686012 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
59696013 buf_ptr(&child_type->name),
5970 buf_ptr(&op2->type_entry->name)));
6014 buf_ptr(&op2->value.type->name)));
59716015 return ira->codegen->builtin_types.entry_invalid;
59726016 }
59736017 op2_array_val = op2_val;
......@@ -5980,7 +6024,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
59806024 if (child_type != ira->codegen->builtin_types.entry_u8) {
59816025 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
59826026 buf_ptr(&child_type->name),
5983 buf_ptr(&op2->type_entry->name)));
6027 buf_ptr(&op2->value.type->name)));
59846028 return ira->codegen->builtin_types.entry_invalid;
59856029 }
59866030 op2_array_val = op2_val->data.x_ptr.base_ptr;
......@@ -5988,12 +6032,12 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
59886032 op2_array_end = op2_array_val->data.x_array.size - 1;
59896033 } else {
59906034 ir_add_error(ira, op2,
5991 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->type_entry->name)));
6035 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
59926036 // TODO if meta_type is type decl, add note pointing to type decl declaration
59936037 return ira->codegen->builtin_types.entry_invalid;
59946038 }
59956039
5996 bool depends_on_compile_var = op1->static_value.depends_on_compile_var || op2->static_value.depends_on_compile_var;
6040 bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var;
59976041 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
59986042
59996043 TypeTableEntry *result_type;
......@@ -6008,6 +6052,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
60086052
60096053 out_array_val = allocate<ConstExprValue>(1);
60106054 out_array_val->special = ConstValSpecialStatic;
6055 out_array_val->type = result_type;
60116056 out_val->data.x_ptr.base_ptr = out_array_val;
60126057 out_val->data.x_ptr.index = 0;
60136058 out_val->data.x_ptr.special = ConstPtrSpecialCStr;
......@@ -6026,8 +6071,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
60266071 }
60276072 if (next_index < new_len) {
60286073 ConstExprValue *null_byte = &out_array_val->data.x_array.elements[next_index];
6029 null_byte->special = ConstValSpecialStatic;
6030 bignum_init_unsigned(&null_byte->data.x_bignum, 0);
6074 init_const_unsigned_negative(null_byte, child_type, 0, false);
60316075 next_index += 1;
60326076 }
60336077 assert(next_index == new_len);
......@@ -6037,11 +6081,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
60376081
60386082static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
60396083 IrInstruction *op1 = instruction->op1->other;
6040 if (op1->type_entry->id == TypeTableEntryIdInvalid)
6084 if (op1->value.type->id == TypeTableEntryIdInvalid)
60416085 return ira->codegen->builtin_types.entry_invalid;
60426086
60436087 IrInstruction *op2 = instruction->op2->other;
6044 if (op2->type_entry->id == TypeTableEntryIdInvalid)
6088 if (op2->value.type->id == TypeTableEntryIdInvalid)
60456089 return ira->codegen->builtin_types.entry_invalid;
60466090
60476091 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);
......@@ -6052,9 +6096,9 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
60526096 if (!ir_resolve_usize(ira, op2, &mult_amt))
60536097 return ira->codegen->builtin_types.entry_invalid;
60546098
6055 TypeTableEntry *array_canon_type = get_underlying_type(op1->type_entry);
6099 TypeTableEntry *array_canon_type = get_underlying_type(op1->value.type);
60566100 if (array_canon_type->id != TypeTableEntryIdArray) {
6057 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->type_entry->name)));
6101 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
60586102 // TODO if meta_type is type decl, add note pointing to type decl declaration
60596103 return ira->codegen->builtin_types.entry_invalid;
60606104 }
......@@ -6068,7 +6112,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
60686112 return ira->codegen->builtin_types.entry_invalid;
60696113 }
60706114
6071 bool depends_on_compile_var = op1->static_value.depends_on_compile_var || op2->static_value.depends_on_compile_var;
6115 bool depends_on_compile_var = op1->value.depends_on_compile_var || op2->value.depends_on_compile_var;
60726116 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
60736117
60746118 uint64_t new_array_len = array_len.data.x_uint;
......@@ -6130,9 +6174,9 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
61306174 VariableTableEntry *var = decl_var_instruction->var;
61316175
61326176 IrInstruction *init_value = decl_var_instruction->init_value->other;
6133 if (init_value->type_entry->id == TypeTableEntryIdInvalid) {
6134 var->type = ira->codegen->builtin_types.entry_invalid;
6135 return var->type;
6177 if (init_value->value.type->id == TypeTableEntryIdInvalid) {
6178 var->value.type = ira->codegen->builtin_types.entry_invalid;
6179 return var->value.type;
61366180 }
61376181
61386182 AstNodeVariableDeclaration *variable_declaration = &var->decl_node->data.variable_declaration;
......@@ -6148,15 +6192,15 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
61486192 TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);
61496193 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
61506194 if (explicit_type->id == TypeTableEntryIdInvalid) {
6151 var->type = ira->codegen->builtin_types.entry_invalid;
6152 return var->type;
6195 var->value.type = ira->codegen->builtin_types.entry_invalid;
6196 return var->value.type;
61536197 }
61546198 }
61556199
61566200 AstNode *source_node = decl_var_instruction->base.source_node;
61576201
61586202 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
6159 TypeTableEntry *result_type = get_underlying_type(casted_init_value->type_entry);
6203 TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type);
61606204 switch (result_type->id) {
61616205 case TypeTableEntryIdTypeDecl:
61626206 zig_unreachable();
......@@ -6165,7 +6209,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
61656209 break;
61666210 case TypeTableEntryIdNumLitFloat:
61676211 case TypeTableEntryIdNumLitInt:
6168 if (is_export || is_extern || casted_init_value->static_value.special == ConstValSpecialRuntime) {
6212 if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) {
61696213 ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type"));
61706214 result_type = ira->codegen->builtin_types.entry_invalid;
61716215 }
......@@ -6180,7 +6224,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
61806224 break;
61816225 case TypeTableEntryIdMetaType:
61826226 case TypeTableEntryIdNamespace:
6183 if (casted_init_value->static_value.special == ConstValSpecialRuntime) {
6227 if (casted_init_value->value.special == ConstValSpecialRuntime) {
61846228 ir_add_error_node(ira, source_node,
61856229 buf_sprintf("variable of type '%s' must be constant", buf_ptr(&result_type->name)));
61866230 result_type = ira->codegen->builtin_types.entry_invalid;
......@@ -6206,16 +6250,16 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
62066250 break;
62076251 }
62086252
6209 var->type = result_type;
6210 assert(var->type);
6253 var->value.type = result_type;
6254 assert(var->value.type);
62116255
62126256 bool is_comptime = ir_get_var_is_comptime(var);
62136257
6214 if (casted_init_value->static_value.special != ConstValSpecialRuntime) {
6258 if (casted_init_value->value.special != ConstValSpecialRuntime) {
62156259 if (var->mem_slot_index != SIZE_MAX) {
62166260 assert(var->mem_slot_index < ira->exec_context.mem_slot_count);
62176261 ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];
6218 *mem_slot = casted_init_value->static_value;
6262 *mem_slot = casted_init_value->value;
62196263
62206264 if (is_comptime) {
62216265 ir_build_const_from(ira, &decl_var_instruction->base, false);
......@@ -6225,7 +6269,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
62256269 } else if (is_comptime) {
62266270 ir_add_error(ira, &decl_var_instruction->base,
62276271 buf_sprintf("cannot store runtime value in compile time variable"));
6228 var->type = ira->codegen->builtin_types.entry_invalid;
6272 var->value.type = ira->codegen->builtin_types.entry_invalid;
62296273 return ira->codegen->builtin_types.entry_invalid;
62306274 }
62316275
......@@ -6249,7 +6293,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
62496293 return false;
62506294
62516295 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);
6252 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
6296 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
62536297 return false;
62546298
62556299 ConstExprValue *first_arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
......@@ -6258,7 +6302,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
62586302
62596303 Buf *param_name = param_decl_node->data.param_decl.name;
62606304 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
6261 *exec_scope, param_name, casted_arg->type_entry, true, first_arg_val);
6305 *exec_scope, param_name, true, first_arg_val);
62626306 *exec_scope = var->child_scope;
62636307 *next_proto_i += 1;
62646308
......@@ -6278,7 +6322,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
62786322 return false;
62796323
62806324 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);
6281 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
6325 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
62826326 return false;
62836327
62846328 bool inline_arg = param_decl_node->data.param_decl.is_inline;
......@@ -6294,24 +6338,22 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
62946338 // needs to know that it depends on compile time variable data.
62956339 arg_val->depends_on_compile_var = true;
62966340 } else {
6297 arg_val = nullptr;
6341 arg_val = create_const_runtime(casted_arg->value.type);
62986342 }
62996343
63006344 Buf *param_name = param_decl_node->data.param_decl.name;
63016345 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
6302 *child_scope, param_name, casted_arg->type_entry, true, arg_val);
6346 *child_scope, param_name, true, arg_val);
63036347 *child_scope = var->child_scope;
63046348
63056349 if (inline_arg || is_var_type) {
6306 GenericParamValue *generic_param = &generic_id->params[generic_id->param_count];
6307 generic_param->type = casted_arg->type_entry;
6308 generic_param->value = arg_val;
6350 generic_id->params[generic_id->param_count] = *arg_val;
63096351 generic_id->param_count += 1;
63106352 }
63116353 if (!inline_arg) {
6312 if (type_requires_comptime(var->type)) {
6354 if (type_requires_comptime(var->value.type)) {
63136355 ir_add_error(ira, arg,
6314 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&var->type->name)));
6356 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&var->value.type->name)));
63156357 return false;
63166358 }
63176359
......@@ -6319,7 +6361,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
63196361
63206362 casted_args[fn_type_id->param_count] = casted_arg;
63216363 FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count];
6322 param_info->type = casted_arg->type_entry;
6364 param_info->type = casted_arg->value.type;
63236365 param_info->is_noalias = param_decl_node->data.param_decl.is_noalias;
63246366 impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node;
63256367 fn_type_id->param_count += 1;
......@@ -6376,7 +6418,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
63766418 size_t next_proto_i = 0;
63776419 if (first_arg_ptr) {
63786420 IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
6379 if (first_arg->type_entry->id == TypeTableEntryIdInvalid)
6421 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
63806422 return ira->codegen->builtin_types.entry_invalid;
63816423
63826424 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))
......@@ -6385,7 +6427,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
63856427
63866428 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
63876429 IrInstruction *old_arg = call_instruction->args[call_i]->other;
6388 if (old_arg->type_entry->id == TypeTableEntryIdInvalid)
6430 if (old_arg->value.type->id == TypeTableEntryIdInvalid)
63896431 return ira->codegen->builtin_types.entry_invalid;
63906432
63916433 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
......@@ -6408,15 +6450,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
64086450 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
64096451 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
64106452 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);
6411 if (result->type_entry->id == TypeTableEntryIdInvalid)
6453 if (result->value.type->id == TypeTableEntryIdInvalid)
64126454 return ira->codegen->builtin_types.entry_invalid;
64136455
64146456 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);
64156457 }
64166458
64176459 ConstExprValue *out_val = ir_build_const_from(ira, &call_instruction->base,
6418 result->static_value.depends_on_compile_var);
6419 *out_val = result->static_value;
6460 result->value.depends_on_compile_var);
6461 *out_val = result->value;
64206462 return ir_finish_anal(ira, return_type);
64216463 }
64226464
......@@ -6441,12 +6483,12 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
64416483 GenericFnTypeId *generic_id = allocate<GenericFnTypeId>(1);
64426484 generic_id->fn_entry = fn_entry;
64436485 generic_id->param_count = 0;
6444 generic_id->params = allocate<GenericParamValue>(src_param_count);
6486 generic_id->params = allocate<ConstExprValue>(src_param_count);
64456487 size_t next_proto_i = 0;
64466488
64476489 if (first_arg_ptr) {
64486490 IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
6449 if (first_arg->type_entry->id == TypeTableEntryIdInvalid)
6491 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
64506492 return ira->codegen->builtin_types.entry_invalid;
64516493
64526494 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,
......@@ -6457,7 +6499,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
64576499 }
64586500 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
64596501 IrInstruction *arg = call_instruction->args[call_i]->other;
6460 if (arg->type_entry->id == TypeTableEntryIdInvalid)
6502 if (arg->value.type->id == TypeTableEntryIdInvalid)
64616503 return ira->codegen->builtin_types.entry_invalid;
64626504
64636505 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
......@@ -6513,7 +6555,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
65136555 size_t next_arg_index = 0;
65146556 if (first_arg_ptr) {
65156557 IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
6516 if (first_arg->type_entry->id == TypeTableEntryIdInvalid)
6558 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
65176559 return ira->codegen->builtin_types.entry_invalid;
65186560
65196561 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
......@@ -6521,7 +6563,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
65216563 return ira->codegen->builtin_types.entry_invalid;
65226564
65236565 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
6524 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
6566 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
65256567 return ira->codegen->builtin_types.entry_invalid;
65266568
65276569 casted_args[next_arg_index] = casted_arg;
......@@ -6529,7 +6571,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
65296571 }
65306572 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
65316573 IrInstruction *old_arg = call_instruction->args[call_i]->other;
6532 if (old_arg->type_entry->id == TypeTableEntryIdInvalid)
6574 if (old_arg->value.type->id == TypeTableEntryIdInvalid)
65336575 return ira->codegen->builtin_types.entry_invalid;
65346576 IrInstruction *casted_arg;
65356577 if (next_arg_index < src_param_count) {
......@@ -6537,7 +6579,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
65376579 if (param_type->id == TypeTableEntryIdInvalid)
65386580 return ira->codegen->builtin_types.entry_invalid;
65396581 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
6540 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
6582 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
65416583 return ira->codegen->builtin_types.entry_invalid;
65426584 } else {
65436585 casted_arg = old_arg;
......@@ -6562,13 +6604,13 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
65626604
65636605static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
65646606 IrInstruction *fn_ref = call_instruction->fn_ref->other;
6565 if (fn_ref->type_entry->id == TypeTableEntryIdInvalid)
6607 if (fn_ref->value.type->id == TypeTableEntryIdInvalid)
65666608 return ira->codegen->builtin_types.entry_invalid;
65676609
65686610 bool is_inline = call_instruction->is_inline || ir_should_inline(&ira->new_irb);
65696611
6570 if (is_inline || fn_ref->static_value.special != ConstValSpecialRuntime) {
6571 if (fn_ref->type_entry->id == TypeTableEntryIdMetaType) {
6612 if (is_inline || fn_ref->value.special != ConstValSpecialRuntime) {
6613 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
65726614 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);
65736615 if (dest_type->id == TypeTableEntryIdInvalid)
65746616 return ira->codegen->builtin_types.entry_invalid;
......@@ -6584,34 +6626,34 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
65846626 IrInstruction *arg = call_instruction->args[0]->other;
65856627
65866628 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg);
6587 if (cast_instruction->type_entry->id == TypeTableEntryIdInvalid)
6629 if (cast_instruction->value.type->id == TypeTableEntryIdInvalid)
65886630 return ira->codegen->builtin_types.entry_invalid;
65896631
65906632 ir_link_new_instruction(cast_instruction, &call_instruction->base);
6591 return ir_finish_anal(ira, cast_instruction->type_entry);
6592 } else if (fn_ref->type_entry->id == TypeTableEntryIdFn) {
6633 return ir_finish_anal(ira, cast_instruction->value.type);
6634 } else if (fn_ref->value.type->id == TypeTableEntryIdFn) {
65936635 FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);
65946636 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
65956637 fn_ref, nullptr, is_inline);
6596 } else if (fn_ref->type_entry->id == TypeTableEntryIdBoundFn) {
6597 assert(fn_ref->static_value.special == ConstValSpecialStatic);
6598 FnTableEntry *fn_table_entry = fn_ref->static_value.data.x_bound_fn.fn;
6599 IrInstruction *first_arg_ptr = fn_ref->static_value.data.x_bound_fn.first_arg;
6638 } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {
6639 assert(fn_ref->value.special == ConstValSpecialStatic);
6640 FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
6641 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;
66006642 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
66016643 nullptr, first_arg_ptr, is_inline);
66026644 } else {
66036645 ir_add_error_node(ira, fn_ref->source_node,
6604 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
6646 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name)));
66056647 return ira->codegen->builtin_types.entry_invalid;
66066648 }
66076649 }
66086650
6609 if (fn_ref->type_entry->id == TypeTableEntryIdFn) {
6610 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->type_entry,
6651 if (fn_ref->value.type->id == TypeTableEntryIdFn) {
6652 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
66116653 fn_ref, nullptr, false);
66126654 } else {
66136655 ir_add_error_node(ira, fn_ref->source_node,
6614 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
6656 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name)));
66156657 return ira->codegen->builtin_types.entry_invalid;
66166658 }
66176659}
......@@ -6620,10 +6662,6 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
66206662 assert(un_op_instruction->op_id == IrUnOpError);
66216663 IrInstruction *value = un_op_instruction->value->other;
66226664
6623 TypeTableEntry *type_entry = value->type_entry;
6624 if (type_entry->id == TypeTableEntryIdInvalid)
6625 return ira->codegen->builtin_types.entry_invalid;
6626
66276665 TypeTableEntry *meta_type = ir_resolve_type(ira, value);
66286666 TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type);
66296667 switch (underlying_meta_type->id) {
......@@ -6648,7 +6686,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
66486686 case TypeTableEntryIdEnumTag:
66496687 {
66506688 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,
6651 value->static_value.depends_on_compile_var);
6689 value->value.depends_on_compile_var);
66526690 TypeTableEntry *result_type = get_error_type(ira->codegen, meta_type);
66536691 out_val->data.x_type = result_type;
66546692 return ira->codegen->builtin_types.entry_type;
......@@ -6674,7 +6712,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
66746712static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
66756713 IrInstruction *value = un_op_instruction->value->other;
66766714
6677 TypeTableEntry *ptr_type = value->type_entry;
6715 TypeTableEntry *ptr_type = value->value.type;
66786716 TypeTableEntry *child_type;
66796717 if (ptr_type->id == TypeTableEntryIdInvalid) {
66806718 return ira->codegen->builtin_types.entry_invalid;
......@@ -6690,9 +6728,9 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
66906728 // this dereference is always an rvalue because in the IR gen we identify lvalue and emit
66916729 // one of the ptr instructions
66926730
6693 if (value->static_value.special != ConstValSpecialRuntime) {
6731 if (value->value.special != ConstValSpecialRuntime) {
66946732 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, false);
6695 ConstExprValue *pointee = const_ptr_pointee(&value->static_value);
6733 ConstExprValue *pointee = const_ptr_pointee(&value->value);
66966734 *out_val = *pointee;
66976735 return child_type;
66986736 }
......@@ -6735,7 +6773,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
67356773 case TypeTableEntryIdEnumTag:
67366774 {
67376775 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base,
6738 value->static_value.depends_on_compile_var);
6776 value->value.depends_on_compile_var);
67396777 out_val->data.x_type = get_maybe_type(ira->codegen, type_entry);
67406778 return ira->codegen->builtin_types.entry_type;
67416779 }
......@@ -6750,7 +6788,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
67506788
67516789static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
67526790 IrInstruction *value = un_op_instruction->value->other;
6753 TypeTableEntry *expr_type = value->type_entry;
6791 TypeTableEntry *expr_type = value->value.type;
67546792 if (expr_type->id == TypeTableEntryIdInvalid)
67556793 return ira->codegen->builtin_types.entry_invalid;
67566794
......@@ -6765,7 +6803,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
67656803 if (!target_const_val)
67666804 return ira->codegen->builtin_types.entry_invalid;
67676805
6768 bool depends_on_compile_var = value->static_value.depends_on_compile_var;
6806 bool depends_on_compile_var = value->value.depends_on_compile_var;
67696807 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var);
67706808 bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum);
67716809 if (expr_type->id == TypeTableEntryIdFloat ||
......@@ -6846,7 +6884,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
68466884
68476885static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
68486886 IrInstruction *condition = cond_br_instruction->condition->other;
6849 if (condition->type_entry->id == TypeTableEntryIdInvalid)
6887 if (condition->value.type->id == TypeTableEntryIdInvalid)
68506888 return ir_unreach_error(ira);
68516889
68526890 bool is_comptime;
......@@ -6891,18 +6929,18 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
68916929 if (predecessor != ira->const_predecessor_bb)
68926930 continue;
68936931 IrInstruction *value = phi_instruction->incoming_values[i]->other;
6894 assert(value->type_entry);
6895 if (value->type_entry->id == TypeTableEntryIdInvalid)
6932 assert(value->value.type);
6933 if (value->value.type->id == TypeTableEntryIdInvalid)
68966934 return ira->codegen->builtin_types.entry_invalid;
68976935
6898 if (value->static_value.special != ConstValSpecialRuntime) {
6936 if (value->value.special != ConstValSpecialRuntime) {
68996937 ConstExprValue *out_val = ir_build_const_from(ira, &phi_instruction->base,
6900 value->static_value.depends_on_compile_var);
6901 *out_val = value->static_value;
6938 value->value.depends_on_compile_var);
6939 *out_val = value->value;
69026940 } else {
69036941 phi_instruction->base.other = value;
69046942 }
6905 return value->type_entry;
6943 return value->value.type;
69066944 }
69076945 zig_unreachable();
69086946 }
......@@ -6919,10 +6957,10 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
69196957 IrInstruction *old_value = phi_instruction->incoming_values[i];
69206958 assert(old_value);
69216959 IrInstruction *new_value = old_value->other;
6922 if (!new_value || new_value->type_entry->id == TypeTableEntryIdUnreachable)
6960 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable)
69236961 continue;
69246962
6925 if (new_value->type_entry->id == TypeTableEntryIdInvalid)
6963 if (new_value->value.type->id == TypeTableEntryIdInvalid)
69266964 return ira->codegen->builtin_types.entry_invalid;
69276965
69286966
......@@ -6935,7 +6973,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
69356973 if (new_incoming_blocks.length == 1) {
69366974 IrInstruction *first_value = new_incoming_values.at(0);
69376975 phi_instruction->base.other = first_value;
6938 return first_value->type_entry;
6976 return first_value->value.type;
69396977 }
69406978
69416979 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node,
......@@ -6973,16 +7011,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
69737011}
69747012
69757013static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var) {
6976 assert(var->type);
6977 if (var->type->id == TypeTableEntryIdInvalid)
6978 return var->type;
7014 assert(var->value.type);
7015 if (var->value.type->id == TypeTableEntryIdInvalid)
7016 return var->value.type;
69797017
69807018 bool is_comptime = ir_get_var_is_comptime(var);
69817019
69827020 ConstExprValue *mem_slot = nullptr;
69837021 FnTableEntry *fn_entry = scope_fn_entry(var->parent_scope);
6984 if (var->src_is_const && var->value) {
6985 mem_slot = var->value;
7022 if (var->src_is_const && var->value.special == ConstValSpecialStatic) {
7023 mem_slot = &var->value;
69867024 assert(mem_slot->special != ConstValSpecialRuntime);
69877025 } else if (fn_entry) {
69887026 // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing.
......@@ -6992,10 +7030,10 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
69927030
69937031 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {
69947032 ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone;
6995 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->type, false, ptr_special, var->src_is_const);
7033 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, var->src_is_const);
69967034 } else {
69977035 ir_build_var_ptr_from(&ira->new_irb, instruction, var);
6998 return get_pointer_to_type(ira->codegen, var->type, var->src_is_const);
7036 return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const);
69997037 }
70007038}
70017039
......@@ -7006,15 +7044,15 @@ static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstruct
70067044
70077045static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
70087046 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
7009 if (array_ptr->type_entry->id == TypeTableEntryIdInvalid)
7047 if (array_ptr->value.type->id == TypeTableEntryIdInvalid)
70107048 return ira->codegen->builtin_types.entry_invalid;
70117049
70127050 IrInstruction *elem_index = elem_ptr_instruction->elem_index->other;
7013 if (elem_index->type_entry->id == TypeTableEntryIdInvalid)
7051 if (elem_index->value.type->id == TypeTableEntryIdInvalid)
70147052 return ira->codegen->builtin_types.entry_invalid;
70157053
70167054 // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.
7017 TypeTableEntry *ptr_type = array_ptr->type_entry;
7055 TypeTableEntry *ptr_type = array_ptr->value.type;
70187056 assert(ptr_type->id == TypeTableEntryIdPointer);
70197057
70207058 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
......@@ -7045,8 +7083,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
70457083 return ira->codegen->builtin_types.entry_invalid;
70467084
70477085 bool safety_check_on = elem_ptr_instruction->safety_check_on;
7048 if (casted_elem_index->static_value.special != ConstValSpecialRuntime) {
7049 uint64_t index = casted_elem_index->static_value.data.x_bignum.data.x_uint;
7086 if (casted_elem_index->value.special != ConstValSpecialRuntime) {
7087 uint64_t index = casted_elem_index->value.data.x_bignum.data.x_uint;
70507088 if (array_type->id == TypeTableEntryIdArray) {
70517089 uint64_t array_len = array_type->data.array.len;
70527090 if (index >= array_len) {
......@@ -7059,12 +7097,12 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
70597097 }
70607098
70617099 ConstExprValue *array_ptr_val;
7062 if (array_ptr->static_value.special != ConstValSpecialRuntime &&
7063 (array_ptr_val = const_ptr_pointee(&array_ptr->static_value)) &&
7100 if (array_ptr->value.special != ConstValSpecialRuntime &&
7101 (array_ptr_val = const_ptr_pointee(&array_ptr->value)) &&
70647102 array_ptr_val->special != ConstValSpecialRuntime)
70657103 {
70667104 bool depends_on_compile_var = array_ptr_val->depends_on_compile_var ||
7067 casted_elem_index->static_value.depends_on_compile_var;
7105 casted_elem_index->value.depends_on_compile_var;
70687106 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base, depends_on_compile_var);
70697107 if (array_type->id == TypeTableEntryIdPointer) {
70707108 size_t offset = array_ptr_val->data.x_ptr.index;
......@@ -7136,7 +7174,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
71367174 return ira->codegen->builtin_types.entry_invalid;
71377175 TldFn *tld_fn = (TldFn *)tld;
71387176 FnTableEntry *fn_entry = tld_fn->fn_entry;
7139 bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var;
7177 bool depends_on_compile_var = container_ptr->value.depends_on_compile_var;
71407178 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,
71417179 field_ptr_instruction->base.source_node, fn_entry, container_ptr, depends_on_compile_var);
71427180 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value, true);
......@@ -7206,6 +7244,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
72067244 // the same one every time
72077245 ConstExprValue *const_val = allocate<ConstExprValue>(1);
72087246 const_val->special = ConstValSpecialStatic;
7247 const_val->type = fn_entry->type_entry;
72097248 const_val->data.x_fn = fn_entry;
72107249
72117250 bool ptr_is_const = true;
......@@ -7221,6 +7260,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
72217260 // the same one every time
72227261 ConstExprValue *const_val = allocate<ConstExprValue>(1);
72237262 const_val->special = ConstValSpecialStatic;
7263 const_val->type = ira->codegen->builtin_types.entry_type;
72247264 const_val->data.x_type = tld_typedef->type_entry;
72257265
72267266 bool ptr_is_const = true;
......@@ -7233,26 +7273,26 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
72337273
72347274static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
72357275 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
7236 if (container_ptr->type_entry->id == TypeTableEntryIdInvalid)
7276 if (container_ptr->value.type->id == TypeTableEntryIdInvalid)
72377277 return ira->codegen->builtin_types.entry_invalid;
72387278
72397279 TypeTableEntry *container_type;
7240 if (container_ptr->type_entry->id == TypeTableEntryIdPointer) {
7241 container_type = container_ptr->type_entry->data.pointer.child_type;
7242 } else if (container_ptr->type_entry->id == TypeTableEntryIdMetaType) {
7243 container_type = container_ptr->type_entry;
7280 if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
7281 container_type = container_ptr->value.type->data.pointer.child_type;
7282 } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
7283 container_type = container_ptr->value.type;
72447284 } else {
72457285 zig_unreachable();
72467286 }
72477287
7248 bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var;
7288 bool depends_on_compile_var = container_ptr->value.depends_on_compile_var;
72497289 Buf *field_name = field_ptr_instruction->field_name;
72507290 AstNode *source_node = field_ptr_instruction->base.source_node;
72517291
72527292 if (container_type->id == TypeTableEntryIdInvalid) {
72537293 return container_type;
72547294 } else if (is_container_ref(container_type)) {
7255 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);
7295 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
72567296 if (container_type->id == TypeTableEntryIdPointer) {
72577297 TypeTableEntry *bare_type = container_ref_type(container_type);
72587298 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
......@@ -7263,8 +7303,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
72637303 } else if (container_type->id == TypeTableEntryIdArray) {
72647304 if (buf_eql_str(field_name, "len")) {
72657305 ConstExprValue *len_val = allocate<ConstExprValue>(1);
7266 len_val->special = ConstValSpecialStatic;
7267 bignum_init_unsigned(&len_val->data.x_bignum, container_type->data.array.len);
7306 init_const_usize(ira->codegen, len_val, container_type->data.array.len);
72687307
72697308 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
72707309 bool ptr_is_const = true;
......@@ -7282,11 +7321,11 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
72827321 return ira->codegen->builtin_types.entry_invalid;
72837322
72847323 TypeTableEntry *child_type;
7285 if (container_ptr->type_entry->id == TypeTableEntryIdMetaType) {
7324 if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
72867325 TypeTableEntry *ptr_type = container_ptr_val->data.x_type;
72877326 assert(ptr_type->id == TypeTableEntryIdPointer);
72887327 child_type = ptr_type->data.pointer.child_type;
7289 } else if (container_ptr->type_entry->id == TypeTableEntryIdPointer) {
7328 } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
72907329 ConstExprValue *child_val = const_ptr_pointee(container_ptr_val);
72917330 child_type = child_val->data.x_type;
72927331 } else {
......@@ -7303,14 +7342,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
73037342 if (field->type_entry->id == TypeTableEntryIdVoid) {
73047343 bool ptr_is_const = true;
73057344 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
7306 create_const_enum_tag(field->value), child_type, depends_on_compile_var,
7345 create_const_enum_tag(child_type, field->value), child_type, depends_on_compile_var,
73077346 ConstPtrSpecialNone, ptr_is_const);
73087347 } else {
73097348 bool ptr_is_const = true;
73107349 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
7311 create_const_unsigned_negative(field->value, false),
7312 child_type->data.enumeration.tag_type, depends_on_compile_var,
7313 ConstPtrSpecialNone, ptr_is_const);
7350 create_const_unsigned_negative(child_type->data.enumeration.tag_type, field->value, false),
7351 child_type->data.enumeration.tag_type, depends_on_compile_var,
7352 ConstPtrSpecialNone, ptr_is_const);
73147353 }
73157354 }
73167355 }
......@@ -7329,6 +7368,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
73297368 if (err_table_entry) {
73307369 ConstExprValue *const_val = allocate<ConstExprValue>(1);
73317370 const_val->special = ConstValSpecialStatic;
7371 const_val->type = child_type;
73327372 const_val->data.x_pure_err = err_table_entry->value;
73337373
73347374 bool ptr_is_const = true;
......@@ -7343,13 +7383,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
73437383 if (buf_eql_str(field_name, "bit_count")) {
73447384 bool ptr_is_const = true;
73457385 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
7346 create_const_unsigned_negative(child_type->data.integral.bit_count, false),
7386 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
7387 child_type->data.integral.bit_count, false),
73477388 ira->codegen->builtin_types.entry_num_lit_int, depends_on_compile_var,
73487389 ConstPtrSpecialNone, ptr_is_const);
73497390 } else if (buf_eql_str(field_name, "is_signed")) {
73507391 bool ptr_is_const = true;
73517392 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
7352 create_const_bool(child_type->data.integral.is_signed),
7393 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
73537394 ira->codegen->builtin_types.entry_bool, depends_on_compile_var,
73547395 ConstPtrSpecialNone, ptr_is_const);
73557396 } else {
......@@ -7364,7 +7405,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
73647405 return ira->codegen->builtin_types.entry_invalid;
73657406 }
73667407 } else if (container_type->id == TypeTableEntryIdNamespace) {
7367 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);
7408 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
73687409 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
73697410 if (!container_ptr_val)
73707411 return ira->codegen->builtin_types.entry_invalid;
......@@ -7414,30 +7455,30 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
74147455 IrInstruction *ptr = load_ptr_instruction->ptr->other;
74157456 IrInstruction *result = ir_get_deref(ira, &load_ptr_instruction->base, ptr);
74167457 ir_link_new_instruction(result, &load_ptr_instruction->base);
7417 assert(result->type_entry);
7418 return result->type_entry;
7458 assert(result->value.type);
7459 return result->value.type;
74197460}
74207461
74217462static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
74227463 IrInstruction *ptr = store_ptr_instruction->ptr->other;
7423 if (ptr->type_entry->id == TypeTableEntryIdInvalid)
7424 return ptr->type_entry;
7464 if (ptr->value.type->id == TypeTableEntryIdInvalid)
7465 return ptr->value.type;
74257466
74267467 IrInstruction *value = store_ptr_instruction->value->other;
7427 if (value->type_entry->id == TypeTableEntryIdInvalid)
7428 return value->type_entry;
7468 if (value->value.type->id == TypeTableEntryIdInvalid)
7469 return value->value.type;
74297470
7430 TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type;
7471 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
74317472 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
74327473 if (casted_value == ira->codegen->invalid_instruction)
74337474 return ira->codegen->builtin_types.entry_invalid;
74347475
7435 if (ptr->static_value.special != ConstValSpecialRuntime) {
7436 bool is_inline = (ptr->static_value.data.x_ptr.special == ConstPtrSpecialInline);
7437 if (casted_value->static_value.special != ConstValSpecialRuntime) {
7438 ConstExprValue *dest_val = const_ptr_pointee(&ptr->static_value);
7476 if (ptr->value.special != ConstValSpecialRuntime) {
7477 bool is_inline = (ptr->value.data.x_ptr.special == ConstPtrSpecialInline);
7478 if (casted_value->value.special != ConstValSpecialRuntime) {
7479 ConstExprValue *dest_val = const_ptr_pointee(&ptr->value);
74397480 if (dest_val->special != ConstValSpecialRuntime) {
7440 *dest_val = casted_value->static_value;
7481 *dest_val = casted_value->value;
74417482 return ir_analyze_void(ira, &store_ptr_instruction->base);
74427483 }
74437484 }
......@@ -7448,11 +7489,11 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
74487489 }
74497490 }
74507491
7451 if (ptr->static_value.special != ConstValSpecialRuntime) {
7492 if (ptr->value.special != ConstValSpecialRuntime) {
74527493 // This memory location is transforming from known at compile time to known at runtime.
74537494 // We must emit our own var ptr instruction.
74547495 // TODO can we delete this code now that we have inline var?
7455 ptr->static_value.special = ConstValSpecialRuntime;
7496 ptr->value.special = ConstValSpecialRuntime;
74567497 IrInstruction *new_ptr_inst;
74577498 if (ptr->id == IrInstructionIdVarPtr) {
74587499 IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr;
......@@ -7469,7 +7510,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
74697510 } else {
74707511 zig_unreachable();
74717512 }
7472 new_ptr_inst->type_entry = ptr->type_entry;
7513 new_ptr_inst->value.type = ptr->value.type;
74737514 ir_build_store_ptr(&ira->new_irb, store_ptr_instruction->base.scope,
74747515 store_ptr_instruction->base.source_node, new_ptr_inst, casted_value);
74757516 return ir_analyze_void(ira, &store_ptr_instruction->base);
......@@ -7481,7 +7522,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
74817522
74827523static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
74837524 IrInstruction *expr_value = typeof_instruction->value->other;
7484 TypeTableEntry *type_entry = expr_value->type_entry;
7525 TypeTableEntry *type_entry = expr_value->value.type;
74857526 switch (type_entry->id) {
74867527 case TypeTableEntryIdInvalid:
74877528 return type_entry;
......@@ -7547,7 +7588,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
75477588 }
75487589
75497590 ConstExprValue *out_val = ir_build_const_from(ira, &to_ptr_type_instruction->base,
7550 type_value->static_value.depends_on_compile_var);
7591 type_value->value.depends_on_compile_var);
75517592 out_val->data.x_type = ptr_type;
75527593 return ira->codegen->builtin_types.entry_type;
75537594}
......@@ -7568,7 +7609,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
75687609 }
75697610
75707611 ConstExprValue *out_val = ir_build_const_from(ira, &ptr_type_child_instruction->base,
7571 type_value->static_value.depends_on_compile_var);
7612 type_value->value.depends_on_compile_var);
75727613 out_val->data.x_type = type_entry->data.pointer.child_type;
75737614 return ira->codegen->builtin_types.entry_type;
75747615}
......@@ -7631,7 +7672,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
76317672 IrInstructionSetDebugSafety *set_debug_safety_instruction)
76327673{
76337674 IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;
7634 TypeTableEntry *target_type = target_instruction->type_entry;
7675 TypeTableEntry *target_type = target_instruction->value.type;
76357676 if (target_type->id == TypeTableEntryIdInvalid)
76367677 return ira->codegen->builtin_types.entry_invalid;
76377678 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
......@@ -7694,7 +7735,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
76947735 IrInstructionSliceType *slice_type_instruction)
76957736{
76967737 IrInstruction *child_type = slice_type_instruction->child_type->other;
7697 if (child_type->type_entry->id == TypeTableEntryIdInvalid)
7738 if (child_type->value.type->id == TypeTableEntryIdInvalid)
76987739 return ira->codegen->builtin_types.entry_invalid;
76997740 bool is_const = slice_type_instruction->is_const;
77007741
......@@ -7736,7 +7777,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
77367777 {
77377778 TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const);
77387779 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base,
7739 child_type->static_value.depends_on_compile_var);
7780 child_type->value.depends_on_compile_var);
77407781 out_val->data.x_type = result_type;
77417782 return ira->codegen->builtin_types.entry_type;
77427783 }
......@@ -7770,7 +7811,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
77707811
77717812 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
77727813 input_list[i] = asm_instruction->input_list[i]->other;
7773 if (input_list[i]->type_entry->id == TypeTableEntryIdInvalid)
7814 if (input_list[i]->value.type->id == TypeTableEntryIdInvalid)
77747815 return ira->codegen->builtin_types.entry_invalid;
77757816 }
77767817
......@@ -7825,8 +7866,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
78257866 case TypeTableEntryIdEnumTag:
78267867 {
78277868 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
7828 bool depends_on_compile_var = child_type_value->static_value.depends_on_compile_var ||
7829 size_value->static_value.depends_on_compile_var;
7869 bool depends_on_compile_var = child_type_value->value.depends_on_compile_var ||
7870 size_value->value.depends_on_compile_var;
78307871 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base,
78317872 depends_on_compile_var);
78327873 out_val->data.x_type = result_type;
......@@ -7927,10 +7968,10 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
79277968
79287969static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
79297970 IrInstruction *value = instruction->value->other;
7930 if (value->type_entry->id == TypeTableEntryIdInvalid)
7971 if (value->value.type->id == TypeTableEntryIdInvalid)
79317972 return ira->codegen->builtin_types.entry_invalid;
79327973
7933 TypeTableEntry *type_entry = value->type_entry;
7974 TypeTableEntry *type_entry = value->value.type;
79347975
79357976 if (type_entry->id == TypeTableEntryIdMaybe) {
79367977 if (instr_is_comptime(value)) {
......@@ -7961,11 +8002,11 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
79618002 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)
79628003{
79638004 IrInstruction *value = unwrap_maybe_instruction->value->other;
7964 if (value->type_entry->id == TypeTableEntryIdInvalid)
8005 if (value->value.type->id == TypeTableEntryIdInvalid)
79658006 return ira->codegen->builtin_types.entry_invalid;
79668007
79678008 // This will be a pointer type because test null IR instruction operates on a pointer to a thing.
7968 TypeTableEntry *ptr_type = value->type_entry;
8009 TypeTableEntry *ptr_type = value->value.type;
79698010 assert(ptr_type->id == TypeTableEntryIdPointer);
79708011
79718012 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
......@@ -8008,59 +8049,59 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
80088049
80098050static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
80108051 IrInstruction *value = ctz_instruction->value->other;
8011 if (value->type_entry->id == TypeTableEntryIdInvalid) {
8052 if (value->value.type->id == TypeTableEntryIdInvalid) {
80128053 return ira->codegen->builtin_types.entry_invalid;
8013 } else if (value->type_entry->id == TypeTableEntryIdInt) {
8014 if (value->static_value.special != ConstValSpecialRuntime) {
8015 uint32_t result = bignum_ctz(&value->static_value.data.x_bignum,
8016 value->type_entry->data.integral.bit_count);
8017 bool depends_on_compile_var = value->static_value.depends_on_compile_var;
8054 } else if (value->value.type->id == TypeTableEntryIdInt) {
8055 if (value->value.special != ConstValSpecialRuntime) {
8056 uint32_t result = bignum_ctz(&value->value.data.x_bignum,
8057 value->value.type->data.integral.bit_count);
8058 bool depends_on_compile_var = value->value.depends_on_compile_var;
80188059 ConstExprValue *out_val = ir_build_const_from(ira, &ctz_instruction->base,
80198060 depends_on_compile_var);
80208061 bignum_init_unsigned(&out_val->data.x_bignum, result);
8021 return value->type_entry;
8062 return value->value.type;
80228063 }
80238064
80248065 ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value);
8025 return value->type_entry;
8066 return value->value.type;
80268067 } else {
80278068 ir_add_error_node(ira, ctz_instruction->base.source_node,
8028 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
8069 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
80298070 return ira->codegen->builtin_types.entry_invalid;
80308071 }
80318072}
80328073
80338074static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
80348075 IrInstruction *value = clz_instruction->value->other;
8035 if (value->type_entry->id == TypeTableEntryIdInvalid) {
8076 if (value->value.type->id == TypeTableEntryIdInvalid) {
80368077 return ira->codegen->builtin_types.entry_invalid;
8037 } else if (value->type_entry->id == TypeTableEntryIdInt) {
8038 if (value->static_value.special != ConstValSpecialRuntime) {
8039 uint32_t result = bignum_clz(&value->static_value.data.x_bignum,
8040 value->type_entry->data.integral.bit_count);
8041 bool depends_on_compile_var = value->static_value.depends_on_compile_var;
8078 } else if (value->value.type->id == TypeTableEntryIdInt) {
8079 if (value->value.special != ConstValSpecialRuntime) {
8080 uint32_t result = bignum_clz(&value->value.data.x_bignum,
8081 value->value.type->data.integral.bit_count);
8082 bool depends_on_compile_var = value->value.depends_on_compile_var;
80428083 ConstExprValue *out_val = ir_build_const_from(ira, &clz_instruction->base,
80438084 depends_on_compile_var);
80448085 bignum_init_unsigned(&out_val->data.x_bignum, result);
8045 return value->type_entry;
8086 return value->value.type;
80468087 }
80478088
80488089 ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value);
8049 return value->type_entry;
8090 return value->value.type;
80508091 } else {
80518092 ir_add_error_node(ira, clz_instruction->base.source_node,
8052 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
8093 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
80538094 return ira->codegen->builtin_types.entry_invalid;
80548095 }
80558096}
80568097
80578098static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
8058 if (value->type_entry->id == TypeTableEntryIdInvalid)
8099 if (value->value.type->id == TypeTableEntryIdInvalid)
80598100 return ira->codegen->invalid_instruction;
80608101
8061 if (value->type_entry->id != TypeTableEntryIdEnum) {
8102 if (value->value.type->id != TypeTableEntryIdEnum) {
80628103 ir_add_error(ira, source_instr,
8063 buf_sprintf("expected enum type, found '%s'", buf_ptr(&value->type_entry->name)));
8104 buf_sprintf("expected enum type, found '%s'", buf_ptr(&value->value.type->name)));
80648105 return ira->codegen->invalid_instruction;
80658106 }
80668107
......@@ -8071,10 +8112,10 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_
80718112
80728113 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec,
80738114 source_instr->scope, source_instr->source_node);
8074 const_instruction->base.type_entry = value->type_entry->data.enumeration.tag_type;
8075 const_instruction->base.static_value.special = ConstValSpecialStatic;
8076 const_instruction->base.static_value.depends_on_compile_var = val->depends_on_compile_var;
8077 bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, val->data.x_enum.tag);
8115 const_instruction->base.value.type = value->value.type->data.enumeration.tag_type;
8116 const_instruction->base.value.special = ConstValSpecialStatic;
8117 const_instruction->base.value.depends_on_compile_var = val->depends_on_compile_var;
8118 bignum_init_unsigned(&const_instruction->base.value.data.x_bignum, val->data.x_enum.tag);
80788119 return &const_instruction->base;
80798120 }
80808121
......@@ -8085,7 +8126,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
80858126 IrInstructionSwitchBr *switch_br_instruction)
80868127{
80878128 IrInstruction *target_value = switch_br_instruction->target_value->other;
8088 if (target_value->type_entry->id == TypeTableEntryIdInvalid)
8129 if (target_value->value.type->id == TypeTableEntryIdInvalid)
80898130 return ir_unreach_error(ira);
80908131
80918132 size_t case_count = switch_br_instruction->case_count;
......@@ -8103,24 +8144,24 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
81038144 for (size_t i = 0; i < case_count; i += 1) {
81048145 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
81058146 IrInstruction *case_value = old_case->value->other;
8106 if (case_value->type_entry->id == TypeTableEntryIdInvalid)
8147 if (case_value->value.type->id == TypeTableEntryIdInvalid)
81078148 return ir_unreach_error(ira);
81088149
8109 if (case_value->type_entry->id == TypeTableEntryIdEnum) {
8150 if (case_value->value.type->id == TypeTableEntryIdEnum) {
81108151 case_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, case_value);
8111 if (case_value->type_entry->id == TypeTableEntryIdInvalid)
8152 if (case_value->value.type->id == TypeTableEntryIdInvalid)
81128153 return ir_unreach_error(ira);
81138154 }
81148155
8115 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->type_entry);
8116 if (casted_case_value->type_entry->id == TypeTableEntryIdInvalid)
8156 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);
8157 if (casted_case_value->value.type->id == TypeTableEntryIdInvalid)
81178158 return ir_unreach_error(ira);
81188159
81198160 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
81208161 if (!case_val)
81218162 return ir_unreach_error(ira);
81228163
8123 if (const_values_equal(target_val, case_val, target_value->type_entry)) {
8164 if (const_values_equal(target_val, case_val)) {
81248165 old_dest_block = old_case->block;
81258166 break;
81268167 }
......@@ -8144,17 +8185,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
81448185
81458186 IrInstruction *old_value = old_case->value;
81468187 IrInstruction *new_value = old_value->other;
8147 if (new_value->type_entry->id == TypeTableEntryIdInvalid)
8188 if (new_value->value.type->id == TypeTableEntryIdInvalid)
81488189 continue;
81498190
8150 if (new_value->type_entry->id == TypeTableEntryIdEnum) {
8191 if (new_value->value.type->id == TypeTableEntryIdEnum) {
81518192 new_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, new_value);
8152 if (new_value->type_entry->id == TypeTableEntryIdInvalid)
8193 if (new_value->value.type->id == TypeTableEntryIdInvalid)
81538194 continue;
81548195 }
81558196
8156 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->type_entry);
8157 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)
8197 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);
8198 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)
81588199 continue;
81598200
81608201 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
......@@ -8173,15 +8214,15 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
81738214 IrInstructionSwitchTarget *switch_target_instruction)
81748215{
81758216 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other;
8176 if (target_value_ptr->type_entry->id == TypeTableEntryIdInvalid)
8217 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)
81778218 return ira->codegen->builtin_types.entry_invalid;
81788219
8179 assert(target_value_ptr->type_entry->id == TypeTableEntryIdPointer);
8180 TypeTableEntry *target_type = target_value_ptr->type_entry->data.pointer.child_type;
8181 bool depends_on_compile_var = target_value_ptr->static_value.depends_on_compile_var;
8220 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
8221 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
8222 bool depends_on_compile_var = target_value_ptr->value.depends_on_compile_var;
81828223 ConstExprValue *pointee_val = nullptr;
8183 if (target_value_ptr->static_value.special != ConstValSpecialRuntime) {
8184 pointee_val = const_ptr_pointee(&target_value_ptr->static_value);
8224 if (target_value_ptr->value.special != ConstValSpecialRuntime) {
8225 pointee_val = const_ptr_pointee(&target_value_ptr->value);
81858226 if (pointee_val->special == ConstValSpecialRuntime)
81868227 pointee_val = nullptr;
81878228 }
......@@ -8206,6 +8247,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
82068247 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base,
82078248 depends_on_compile_var);
82088249 *out_val = *pointee_val;
8250 out_val->type = target_type;
82098251 return target_type;
82108252 }
82118253
......@@ -8223,7 +8265,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
82238265
82248266 IrInstruction *enum_value = ir_build_load_ptr(&ira->new_irb, switch_target_instruction->base.scope,
82258267 switch_target_instruction->base.source_node, target_value_ptr);
8226 enum_value->type_entry = target_type;
8268 enum_value->value.type = target_type;
82278269 ir_build_enum_tag_from(&ira->new_irb, &switch_target_instruction->base, enum_value);
82288270 return tag_type;
82298271 }
......@@ -8251,24 +8293,24 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
82518293
82528294static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
82538295 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
8254 if (target_value_ptr->type_entry->id == TypeTableEntryIdInvalid)
8296 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)
82558297 return ira->codegen->builtin_types.entry_invalid;
82568298
82578299 IrInstruction *prong_value = instruction->prong_value->other;
8258 if (prong_value->type_entry->id == TypeTableEntryIdInvalid)
8300 if (prong_value->value.type->id == TypeTableEntryIdInvalid)
82598301 return ira->codegen->builtin_types.entry_invalid;
82608302
8261 assert(target_value_ptr->type_entry->id == TypeTableEntryIdPointer);
8262 TypeTableEntry *target_type = target_value_ptr->type_entry->data.pointer.child_type;
8303 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
8304 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
82638305 if (target_type->id == TypeTableEntryIdEnum) {
82648306 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);
82658307 if (!prong_val)
82668308 return ira->codegen->builtin_types.entry_invalid;
82678309
82688310 TypeEnumField *field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint];
8269 if (prong_value->type_entry->id == TypeTableEntryIdEnumTag) {
8311 if (prong_value->value.type->id == TypeTableEntryIdEnumTag) {
82708312 field = &target_type->data.enumeration.fields[prong_val->data.x_bignum.data.x_uint];
8271 } else if (prong_value->type_entry->id == TypeTableEntryIdEnum) {
8313 } else if (prong_value->value.type->id == TypeTableEntryIdEnum) {
82728314 field = &target_type->data.enumeration.fields[prong_val->data.x_enum.tag];
82738315 } else {
82748316 zig_unreachable();
......@@ -8280,7 +8322,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
82808322
82818323 ir_build_enum_field_ptr_from(&ira->new_irb, &instruction->base, target_value_ptr, field);
82828324 return get_pointer_to_type(ira->codegen, field->type_entry,
8283 target_value_ptr->type_entry->data.pointer.is_const);
8325 target_value_ptr->value.type->data.pointer.is_const);
82848326 } else {
82858327 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
82868328 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
......@@ -8293,14 +8335,14 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc
82938335 IrInstruction *value = enum_tag_instruction->value->other;
82948336 IrInstruction *new_instruction = ir_analyze_enum_tag(ira, &enum_tag_instruction->base, value);
82958337 ir_link_new_instruction(new_instruction, &enum_tag_instruction->base);
8296 return new_instruction->type_entry;
8338 return new_instruction->value.type;
82978339}
82988340
82998341static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira,
83008342 IrInstructionStaticEval *static_eval_instruction)
83018343{
83028344 IrInstruction *value = static_eval_instruction->value->other;
8303 if (value->type_entry->id == TypeTableEntryIdInvalid)
8345 if (value->value.type->id == TypeTableEntryIdInvalid)
83048346 return ira->codegen->builtin_types.entry_invalid;
83058347
83068348 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -8309,7 +8351,7 @@ static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira,
83098351
83108352 ConstExprValue *out_val = ir_build_const_from(ira, &static_eval_instruction->base, val->depends_on_compile_var);
83118353 *out_val = *val;
8312 return value->type_entry;
8354 return value->value.type;
83138355}
83148356
83158357static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
......@@ -8317,7 +8359,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
83178359 Buf *import_target_str = ir_resolve_str(ira, name_value);
83188360 if (!import_target_str)
83198361 return ira->codegen->builtin_types.entry_invalid;
8320 bool depends_on_compile_var = name_value->static_value.depends_on_compile_var;
8362 bool depends_on_compile_var = name_value->value.depends_on_compile_var;
83218363
83228364 AstNode *source_node = import_instruction->base.source_node;
83238365 ImportTableEntry *import = source_node->owner;
......@@ -8390,16 +8432,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
83908432 IrInstructionArrayLen *array_len_instruction)
83918433{
83928434 IrInstruction *array_value = array_len_instruction->array_value->other;
8393 TypeTableEntry *canon_type = get_underlying_type(array_value->type_entry);
8435 TypeTableEntry *canon_type = get_underlying_type(array_value->value.type);
83948436 if (canon_type->id == TypeTableEntryIdInvalid) {
83958437 return ira->codegen->builtin_types.entry_invalid;
83968438 } else if (canon_type->id == TypeTableEntryIdArray) {
8397 bool depends_on_compile_var = array_value->static_value.depends_on_compile_var;
8439 bool depends_on_compile_var = array_value->value.depends_on_compile_var;
83988440 return ir_analyze_const_usize(ira, &array_len_instruction->base,
83998441 canon_type->data.array.len, depends_on_compile_var);
84008442 } else if (is_slice(canon_type)) {
8401 if (array_value->static_value.special != ConstValSpecialRuntime) {
8402 ConstExprValue *len_val = &array_value->static_value.data.x_struct.fields[slice_len_index];
8443 if (array_value->value.special != ConstValSpecialRuntime) {
8444 ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index];
84038445 if (len_val->special != ConstValSpecialRuntime) {
84048446 bool depends_on_compile_var = len_val->depends_on_compile_var;
84058447 return ir_analyze_const_usize(ira, &array_len_instruction->base,
......@@ -8409,12 +8451,12 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
84098451 TypeStructField *field = &canon_type->data.structure.fields[slice_len_index];
84108452 IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope,
84118453 array_len_instruction->base.source_node, array_value, field);
8412 len_ptr->type_entry = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true);
8454 len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true);
84138455 ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr);
84148456 return ira->codegen->builtin_types.entry_usize;
84158457 } else {
84168458 ir_add_error_node(ira, array_len_instruction->base.source_node,
8417 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->type_entry->name)));
8459 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name)));
84188460 // TODO if this is a typedecl, add error note showing the declaration of the type decl
84198461 return ira->codegen->builtin_types.entry_invalid;
84208462 }
......@@ -8444,13 +8486,14 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
84448486
84458487 ConstExprValue const_val = {};
84468488 const_val.special = ConstValSpecialStatic;
8489 const_val.type = container_type;
84478490 const_val.depends_on_compile_var = depends_on_compile_var;
84488491 const_val.data.x_struct.fields = allocate<ConstExprValue>(actual_field_count);
84498492 for (size_t i = 0; i < instr_field_count; i += 1) {
84508493 IrInstructionContainerInitFieldsField *field = &fields[i];
84518494
84528495 IrInstruction *field_value = field->value->other;
8453 if (field_value->type_entry->id == TypeTableEntryIdInvalid)
8496 if (field_value->value.type->id == TypeTableEntryIdInvalid)
84548497 return ira->codegen->builtin_types.entry_invalid;
84558498
84568499 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
......@@ -8481,7 +8524,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
84818524 new_fields[field_index].type_struct_field = type_field;
84828525
84838526 if (const_val.special == ConstValSpecialStatic) {
8484 if (is_comptime || casted_field_value->static_value.special != ConstValSpecialRuntime) {
8527 if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime) {
84858528 ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk);
84868529 if (!field_val)
84878530 return ira->codegen->builtin_types.entry_invalid;
......@@ -8529,16 +8572,16 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
85298572 IrInstructionContainerInitList *instruction)
85308573{
85318574 IrInstruction *container_type_value = instruction->container_type->other;
8532 if (container_type_value->type_entry->id == TypeTableEntryIdInvalid)
8575 if (container_type_value->value.type->id == TypeTableEntryIdInvalid)
85338576 return ira->codegen->builtin_types.entry_invalid;
85348577
85358578 size_t elem_count = instruction->item_count;
8536 if (container_type_value->type_entry->id == TypeTableEntryIdMetaType) {
8579 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {
85378580 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
85388581 if (container_type->id == TypeTableEntryIdInvalid)
85398582 return ira->codegen->builtin_types.entry_invalid;
85408583
8541 bool depends_on_compile_var = container_type_value->static_value.depends_on_compile_var;
8584 bool depends_on_compile_var = container_type_value->value.depends_on_compile_var;
85428585
85438586 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
85448587 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
......@@ -8547,9 +8590,11 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
85478590 TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
85488591 assert(pointer_type->id == TypeTableEntryIdPointer);
85498592 TypeTableEntry *child_type = pointer_type->data.pointer.child_type;
8593 TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
85508594
85518595 ConstExprValue const_val = {};
85528596 const_val.special = ConstValSpecialStatic;
8597 const_val.type = fixed_size_array_type;
85538598 const_val.depends_on_compile_var = depends_on_compile_var;
85548599 const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count);
85558600 const_val.data.x_array.size = elem_count;
......@@ -8562,7 +8607,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
85628607
85638608 for (size_t i = 0; i < elem_count; i += 1) {
85648609 IrInstruction *arg_value = instruction->items[i]->other;
8565 if (arg_value->type_entry->id == TypeTableEntryIdInvalid)
8610 if (arg_value->value.type->id == TypeTableEntryIdInvalid)
85668611 return ira->codegen->builtin_types.entry_invalid;
85678612
85688613 IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type);
......@@ -8572,7 +8617,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
85728617 new_items[i] = casted_arg;
85738618
85748619 if (const_val.special == ConstValSpecialStatic) {
8575 if (is_comptime || casted_arg->static_value.special != ConstValSpecialRuntime) {
8620 if (is_comptime || casted_arg->value.special != ConstValSpecialRuntime) {
85768621 ConstExprValue *elem_val = ir_resolve_const(ira, casted_arg, UndefBad);
85778622 if (!elem_val)
85788623 return ira->codegen->builtin_types.entry_invalid;
......@@ -8586,7 +8631,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
85868631 }
85878632 }
85888633
8589 TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
85908634 if (const_val.special == ConstValSpecialStatic) {
85918635 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, const_val.depends_on_compile_var);
85928636 *out_val = const_val;
......@@ -8619,7 +8663,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
86198663 buf_ptr(&container_type->name)));
86208664 return ira->codegen->builtin_types.entry_invalid;
86218665 }
8622 } else if (container_type_value->type_entry->id == TypeTableEntryIdEnumTag) {
8666 } else if (container_type_value->value.type->id == TypeTableEntryIdEnumTag) {
86238667 if (elem_count != 1) {
86248668 ir_add_error(ira, &instruction->base, buf_sprintf("enum initialization requires exactly one element"));
86258669 return ira->codegen->builtin_types.entry_invalid;
......@@ -8628,7 +8672,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
86288672 if (!tag_value)
86298673 return ira->codegen->builtin_types.entry_invalid;
86308674
8631 TypeTableEntry *enum_type = container_type_value->type_entry->data.enum_tag.enum_type;
8675 TypeTableEntry *enum_type = container_type_value->value.type->data.enum_tag.enum_type;
86328676
86338677 uint64_t tag_uint = tag_value->data.x_bignum.data.x_uint;
86348678 TypeEnumField *field = &enum_type->data.enumeration.fields[tag_uint];
......@@ -8645,7 +8689,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
86458689 if (!init_val)
86468690 return ira->codegen->builtin_types.entry_invalid;
86478691 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,
8648 casted_init_value->static_value.depends_on_compile_var);
8692 casted_init_value->value.depends_on_compile_var);
86498693 out_val->data.x_enum.tag = tag_uint;
86508694 out_val->data.x_enum.payload = init_val;
86518695 return enum_type;
......@@ -8657,7 +8701,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
86578701 return enum_type;
86588702 } else {
86598703 ir_add_error(ira, container_type_value,
8660 buf_sprintf("expected type, found '%s'", buf_ptr(&container_type_value->type_entry->name)));
8704 buf_sprintf("expected type, found '%s'", buf_ptr(&container_type_value->value.type->name)));
86618705 return ira->codegen->builtin_types.entry_invalid;
86628706 }
86638707}
......@@ -8668,7 +8712,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i
86688712 if (container_type->id == TypeTableEntryIdInvalid)
86698713 return ira->codegen->builtin_types.entry_invalid;
86708714
8671 bool depends_on_compile_var = container_type_value->static_value.depends_on_compile_var;
8715 bool depends_on_compile_var = container_type_value->value.depends_on_compile_var;
86728716
86738717 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
86748718 instruction->field_count, instruction->fields, depends_on_compile_var);
......@@ -8678,7 +8722,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
86788722 IrInstruction *target_type_value, bool is_max)
86798723{
86808724 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
8681 bool depends_on_compile_var = target_type_value->static_value.depends_on_compile_var;
8725 bool depends_on_compile_var = target_type_value->value.depends_on_compile_var;
86828726 TypeTableEntry *canon_type = get_underlying_type(target_type);
86838727 switch (canon_type->id) {
86848728 case TypeTableEntryIdInvalid:
......@@ -8763,35 +8807,22 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
87638807
87648808static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
87658809 IrInstruction *value = instruction->value->other;
8766 if (value->type_entry->id == TypeTableEntryIdInvalid)
8810 if (value->value.type->id == TypeTableEntryIdInvalid)
87678811 return ira->codegen->builtin_types.entry_invalid;
87688812
8769 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->type_entry);
8770 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
8813 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type);
8814 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
87718815 return ira->codegen->builtin_types.entry_invalid;
87728816
87738817 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
8774 if (casted_value->static_value.special == ConstValSpecialStatic) {
8775 ErrorTableEntry *err = casted_value->static_value.data.x_pure_err;
8818 if (casted_value->value.special == ConstValSpecialStatic) {
8819 ErrorTableEntry *err = casted_value->value.data.x_pure_err;
87768820 if (!err->cached_error_name_val) {
8777 err->cached_error_name_val = allocate<ConstExprValue>(1);
8778 err->cached_error_name_val->special = ConstValSpecialStatic;
8779 err->cached_error_name_val->data.x_struct.fields = allocate<ConstExprValue>(2);
8780
8781 ConstExprValue *array_val = allocate<ConstExprValue>(1);
8782 init_const_str_lit(array_val, &err->name);
8783
8784 ConstExprValue *ptr_val = &err->cached_error_name_val->data.x_struct.fields[slice_ptr_index];
8785 ptr_val->special = ConstValSpecialStatic;
8786 ptr_val->data.x_ptr.base_ptr = array_val;
8787 ptr_val->data.x_ptr.index = 0;
8788
8789 ConstExprValue *len_val = &err->cached_error_name_val->data.x_struct.fields[slice_len_index];
8790 len_val->special = ConstValSpecialStatic;
8791 bignum_init_unsigned(&len_val->data.x_bignum, buf_len(&err->name));
8821 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name);
8822 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
87928823 }
87938824 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,
8794 casted_value->static_value.depends_on_compile_var);
8825 casted_value->value.depends_on_compile_var);
87958826 *out_val = *err->cached_error_name_val;
87968827 return str_type;
87978828 }
......@@ -8813,7 +8844,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
88138844 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
88148845 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
88158846 &cimport_scope->buf, block_node, nullptr, nullptr);
8816 if (result->type_entry->id == TypeTableEntryIdInvalid)
8847 if (result->value.type->id == TypeTableEntryIdInvalid)
88178848 return ira->codegen->builtin_types.entry_invalid;
88188849
88198850 find_libc_include_path(ira->codegen);
......@@ -8855,7 +8886,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
88558886
88568887static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
88578888 IrInstruction *name_value = instruction->name->other;
8858 if (name_value->type_entry->id == TypeTableEntryIdInvalid)
8889 if (name_value->value.type->id == TypeTableEntryIdInvalid)
88598890 return ira->codegen->builtin_types.entry_invalid;
88608891
88618892 Buf *include_name = ir_resolve_str(ira, name_value);
......@@ -8874,7 +8905,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
88748905
88758906static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
88768907 IrInstruction *name = instruction->name->other;
8877 if (name->type_entry->id == TypeTableEntryIdInvalid)
8908 if (name->value.type->id == TypeTableEntryIdInvalid)
88788909 return ira->codegen->builtin_types.entry_invalid;
88798910
88808911 Buf *define_name = ir_resolve_str(ira, name);
......@@ -8882,7 +8913,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
88828913 return ira->codegen->builtin_types.entry_invalid;
88838914
88848915 IrInstruction *value = instruction->value->other;
8885 if (value->type_entry->id == TypeTableEntryIdInvalid)
8916 if (value->value.type->id == TypeTableEntryIdInvalid)
88868917 return ira->codegen->builtin_types.entry_invalid;
88878918
88888919 Buf *define_value = ir_resolve_str(ira, value);
......@@ -8901,7 +8932,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
89018932
89028933static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
89038934 IrInstruction *name = instruction->name->other;
8904 if (name->type_entry->id == TypeTableEntryIdInvalid)
8935 if (name->value.type->id == TypeTableEntryIdInvalid)
89058936 return ira->codegen->builtin_types.entry_invalid;
89068937
89078938 Buf *undef_name = ir_resolve_str(ira, name);
......@@ -8920,7 +8951,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
89208951
89218952static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
89228953 IrInstruction *name = instruction->name->other;
8923 if (name->type_entry->id == TypeTableEntryIdInvalid)
8954 if (name->value.type->id == TypeTableEntryIdInvalid)
89248955 return ira->codegen->builtin_types.entry_invalid;
89258956
89268957 Buf *rel_file_path = ir_resolve_str(ira, name);
......@@ -8953,26 +8984,26 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
89538984
89548985 bool depends_on_compile_var = true;
89558986 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
8956 init_const_str_lit(out_val, &file_contents);
8987 init_const_str_lit(ira->codegen, out_val, &file_contents);
89578988
89588989 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(&file_contents));
89598990}
89608991
89618992static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
89628993 IrInstruction *ptr = instruction->ptr->other;
8963 if (ptr->type_entry->id == TypeTableEntryIdInvalid)
8994 if (ptr->value.type->id == TypeTableEntryIdInvalid)
89648995 return ira->codegen->builtin_types.entry_invalid;
89658996
89668997 IrInstruction *cmp_value = instruction->cmp_value->other;
8967 if (cmp_value->type_entry->id == TypeTableEntryIdInvalid)
8998 if (cmp_value->value.type->id == TypeTableEntryIdInvalid)
89688999 return ira->codegen->builtin_types.entry_invalid;
89699000
89709001 IrInstruction *new_value = instruction->new_value->other;
8971 if (new_value->type_entry->id == TypeTableEntryIdInvalid)
9002 if (new_value->value.type->id == TypeTableEntryIdInvalid)
89729003 return ira->codegen->builtin_types.entry_invalid;
89739004
89749005 IrInstruction *success_order_value = instruction->success_order_value->other;
8975 if (success_order_value->type_entry->id == TypeTableEntryIdInvalid)
9006 if (success_order_value->value.type->id == TypeTableEntryIdInvalid)
89769007 return ira->codegen->builtin_types.entry_invalid;
89779008
89789009 AtomicOrder success_order;
......@@ -8980,27 +9011,27 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
89809011 return ira->codegen->builtin_types.entry_invalid;
89819012
89829013 IrInstruction *failure_order_value = instruction->failure_order_value->other;
8983 if (failure_order_value->type_entry->id == TypeTableEntryIdInvalid)
9014 if (failure_order_value->value.type->id == TypeTableEntryIdInvalid)
89849015 return ira->codegen->builtin_types.entry_invalid;
89859016
89869017 AtomicOrder failure_order;
89879018 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
89889019 return ira->codegen->builtin_types.entry_invalid;
89899020
8990 if (ptr->type_entry->id != TypeTableEntryIdPointer) {
9021 if (ptr->value.type->id != TypeTableEntryIdPointer) {
89919022 ir_add_error(ira, instruction->ptr,
8992 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr->type_entry->name)));
9023 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr->value.type->name)));
89939024 return ira->codegen->builtin_types.entry_invalid;
89949025 }
89959026
8996 TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type;
9027 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
89979028
89989029 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);
8999 if (casted_cmp_value->type_entry->id == TypeTableEntryIdInvalid)
9030 if (casted_cmp_value->value.type->id == TypeTableEntryIdInvalid)
90009031 return ira->codegen->builtin_types.entry_invalid;
90019032
90029033 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type);
9003 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)
9034 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)
90049035 return ira->codegen->builtin_types.entry_invalid;
90059036
90069037 if (success_order < AtomicOrderMonotonic) {
......@@ -9031,7 +9062,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
90319062
90329063static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
90339064 IrInstruction *order_value = instruction->order_value->other;
9034 if (order_value->type_entry->id == TypeTableEntryIdInvalid)
9065 if (order_value->value.type->id == TypeTableEntryIdInvalid)
90359066 return ira->codegen->builtin_types.entry_invalid;
90369067
90379068 AtomicOrder order;
......@@ -9044,11 +9075,11 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
90449075
90459076static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstructionDivExact *instruction) {
90469077 IrInstruction *op1 = instruction->op1->other;
9047 if (op1->type_entry->id == TypeTableEntryIdInvalid)
9078 if (op1->value.type->id == TypeTableEntryIdInvalid)
90489079 return ira->codegen->builtin_types.entry_invalid;
90499080
90509081 IrInstruction *op2 = instruction->op2->other;
9051 if (op2->type_entry->id == TypeTableEntryIdInvalid)
9082 if (op2->value.type->id == TypeTableEntryIdInvalid)
90529083 return ira->codegen->builtin_types.entry_invalid;
90539084
90549085
......@@ -9070,15 +9101,15 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
90709101 }
90719102
90729103 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type);
9073 if (casted_op1->type_entry->id == TypeTableEntryIdInvalid)
9104 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)
90749105 return ira->codegen->builtin_types.entry_invalid;
90759106
90769107 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type);
9077 if (casted_op2->type_entry->id == TypeTableEntryIdInvalid)
9108 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)
90789109 return ira->codegen->builtin_types.entry_invalid;
90799110
9080 if (casted_op1->static_value.special == ConstValSpecialStatic &&
9081 casted_op2->static_value.special == ConstValSpecialStatic)
9111 if (casted_op1->value.special == ConstValSpecialStatic &&
9112 casted_op2->value.special == ConstValSpecialStatic)
90829113 {
90839114 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
90849115 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
......@@ -9101,8 +9132,8 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
91019132 return ira->codegen->builtin_types.entry_invalid;
91029133 }
91039134
9104 bool depends_on_compile_var = casted_op1->static_value.depends_on_compile_var ||
9105 casted_op2->static_value.depends_on_compile_var;
9135 bool depends_on_compile_var = casted_op1->value.depends_on_compile_var ||
9136 casted_op2->value.depends_on_compile_var;
91069137 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
91079138 bignum_div(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum);
91089139 return result_type;
......@@ -9129,7 +9160,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
91299160 }
91309161
91319162 IrInstruction *target = instruction->target->other;
9132 TypeTableEntry *src_type = target->type_entry;
9163 TypeTableEntry *src_type = target->value.type;
91339164 TypeTableEntry *canon_src_type = get_underlying_type(src_type);
91349165 if (canon_src_type->id == TypeTableEntryIdInvalid)
91359166 return ira->codegen->builtin_types.entry_invalid;
......@@ -9154,10 +9185,10 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
91549185 return ira->codegen->builtin_types.entry_invalid;
91559186 }
91569187
9157 if (target->static_value.special == ConstValSpecialStatic) {
9158 bool depends_on_compile_var = dest_type_value->static_value.depends_on_compile_var || target->static_value.depends_on_compile_var;
9188 if (target->value.special == ConstValSpecialStatic) {
9189 bool depends_on_compile_var = dest_type_value->value.depends_on_compile_var || target->value.depends_on_compile_var;
91599190 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
9160 bignum_init_bignum(&out_val->data.x_bignum, &target->static_value.data.x_bignum);
9191 bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum);
91619192 bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count);
91629193 return dest_type;
91639194 }
......@@ -9177,8 +9208,8 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
91779208 if (!ir_resolve_usize(ira, bit_count_value, &bit_count))
91789209 return ira->codegen->builtin_types.entry_invalid;
91799210
9180 bool depends_on_compile_var = is_signed_value->static_value.depends_on_compile_var ||
9181 bit_count_value->static_value.depends_on_compile_var;
9211 bool depends_on_compile_var = is_signed_value->value.depends_on_compile_var ||
9212 bit_count_value->value.depends_on_compile_var;
91829213
91839214 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
91849215 out_val->data.x_type = get_int_type(ira->codegen, is_signed, bit_count);
......@@ -9187,19 +9218,19 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
91879218
91889219static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
91899220 IrInstruction *value = instruction->value->other;
9190 if (value->type_entry->id == TypeTableEntryIdInvalid)
9221 if (value->value.type->id == TypeTableEntryIdInvalid)
91919222 return ira->codegen->builtin_types.entry_invalid;
91929223
91939224 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
91949225
91959226 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
9196 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
9227 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
91979228 return ira->codegen->builtin_types.entry_invalid;
91989229
9199 if (casted_value->static_value.special != ConstValSpecialRuntime) {
9200 bool depends_on_compile_var = casted_value->static_value.depends_on_compile_var;
9230 if (casted_value->value.special != ConstValSpecialRuntime) {
9231 bool depends_on_compile_var = casted_value->value.depends_on_compile_var;
92019232 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
9202 out_val->data.x_bool = !casted_value->static_value.data.x_bool;
9233 out_val->data.x_bool = !casted_value->value.data.x_bool;
92039234 return bool_type;
92049235 }
92059236
......@@ -9209,11 +9240,11 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
92099240
92109241static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructionAlloca *instruction) {
92119242 IrInstruction *type_value = instruction->type_value->other;
9212 if (type_value->type_entry->id == TypeTableEntryIdInvalid)
9243 if (type_value->value.type->id == TypeTableEntryIdInvalid)
92139244 return ira->codegen->builtin_types.entry_invalid;
92149245
92159246 IrInstruction *count_value = instruction->count->other;
9216 if (count_value->type_entry->id == TypeTableEntryIdInvalid)
9247 if (count_value->value.type->id == TypeTableEntryIdInvalid)
92179248 return ira->codegen->builtin_types.entry_invalid;
92189249
92199250 TypeTableEntry *child_type = ir_resolve_type(ira, type_value);
......@@ -9234,15 +9265,15 @@ static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructi
92349265
92359266static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
92369267 IrInstruction *dest_ptr = instruction->dest_ptr->other;
9237 if (dest_ptr->type_entry->id == TypeTableEntryIdInvalid)
9268 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)
92389269 return ira->codegen->builtin_types.entry_invalid;
92399270
92409271 IrInstruction *byte_value = instruction->byte->other;
9241 if (byte_value->type_entry->id == TypeTableEntryIdInvalid)
9272 if (byte_value->value.type->id == TypeTableEntryIdInvalid)
92429273 return ira->codegen->builtin_types.entry_invalid;
92439274
92449275 IrInstruction *count_value = instruction->count->other;
9245 if (count_value->type_entry->id == TypeTableEntryIdInvalid)
9276 if (count_value->value.type->id == TypeTableEntryIdInvalid)
92469277 return ira->codegen->builtin_types.entry_invalid;
92479278
92489279 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
......@@ -9250,22 +9281,22 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
92509281 TypeTableEntry *u8_ptr = get_pointer_to_type(ira->codegen, u8, false);
92519282
92529283 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
9253 if (casted_dest_ptr->type_entry->id == TypeTableEntryIdInvalid)
9284 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)
92549285 return ira->codegen->builtin_types.entry_invalid;
92559286
92569287 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
9257 if (casted_byte->type_entry->id == TypeTableEntryIdInvalid)
9288 if (casted_byte->value.type->id == TypeTableEntryIdInvalid)
92589289 return ira->codegen->builtin_types.entry_invalid;
92599290
92609291 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
9261 if (casted_count->type_entry->id == TypeTableEntryIdInvalid)
9292 if (casted_count->value.type->id == TypeTableEntryIdInvalid)
92629293 return ira->codegen->builtin_types.entry_invalid;
92639294
9264 if (casted_dest_ptr->static_value.special == ConstValSpecialStatic &&
9265 casted_byte->static_value.special == ConstValSpecialStatic &&
9266 casted_count->static_value.special == ConstValSpecialStatic)
9295 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
9296 casted_byte->value.special == ConstValSpecialStatic &&
9297 casted_count->value.special == ConstValSpecialStatic)
92679298 {
9268 ConstExprValue *dest_ptr_val = &casted_dest_ptr->static_value;
9299 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;
92699300
92709301 ConstExprValue *dest_elements;
92719302 size_t start;
......@@ -9281,14 +9312,14 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
92819312 bound_end = array_val->data.x_array.size;
92829313 }
92839314
9284 size_t count = casted_count->static_value.data.x_bignum.data.x_uint;
9315 size_t count = casted_count->value.data.x_bignum.data.x_uint;
92859316 size_t end = start + count;
92869317 if (end > bound_end) {
92879318 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
92889319 return ira->codegen->builtin_types.entry_invalid;
92899320 }
92909321
9291 ConstExprValue *byte_val = &casted_byte->static_value;
9322 ConstExprValue *byte_val = &casted_byte->value;
92929323 for (size_t i = start; i < end; i += 1) {
92939324 dest_elements[i] = *byte_val;
92949325 }
......@@ -9303,15 +9334,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
93039334
93049335static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
93059336 IrInstruction *dest_ptr = instruction->dest_ptr->other;
9306 if (dest_ptr->type_entry->id == TypeTableEntryIdInvalid)
9337 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)
93079338 return ira->codegen->builtin_types.entry_invalid;
93089339
93099340 IrInstruction *src_ptr = instruction->src_ptr->other;
9310 if (src_ptr->type_entry->id == TypeTableEntryIdInvalid)
9341 if (src_ptr->value.type->id == TypeTableEntryIdInvalid)
93119342 return ira->codegen->builtin_types.entry_invalid;
93129343
93139344 IrInstruction *count_value = instruction->count->other;
9314 if (count_value->type_entry->id == TypeTableEntryIdInvalid)
9345 if (count_value->value.type->id == TypeTableEntryIdInvalid)
93159346 return ira->codegen->builtin_types.entry_invalid;
93169347
93179348 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
......@@ -9320,24 +9351,24 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
93209351 TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
93219352
93229353 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
9323 if (casted_dest_ptr->type_entry->id == TypeTableEntryIdInvalid)
9354 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)
93249355 return ira->codegen->builtin_types.entry_invalid;
93259356
93269357 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
9327 if (casted_src_ptr->type_entry->id == TypeTableEntryIdInvalid)
9358 if (casted_src_ptr->value.type->id == TypeTableEntryIdInvalid)
93289359 return ira->codegen->builtin_types.entry_invalid;
93299360
93309361 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
9331 if (casted_count->type_entry->id == TypeTableEntryIdInvalid)
9362 if (casted_count->value.type->id == TypeTableEntryIdInvalid)
93329363 return ira->codegen->builtin_types.entry_invalid;
93339364
9334 if (casted_dest_ptr->static_value.special == ConstValSpecialStatic &&
9335 casted_src_ptr->static_value.special == ConstValSpecialStatic &&
9336 casted_count->static_value.special == ConstValSpecialStatic)
9365 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
9366 casted_src_ptr->value.special == ConstValSpecialStatic &&
9367 casted_count->value.special == ConstValSpecialStatic)
93379368 {
9338 size_t count = casted_count->static_value.data.x_bignum.data.x_uint;
9369 size_t count = casted_count->value.data.x_bignum.data.x_uint;
93399370
9340 ConstExprValue *dest_ptr_val = &casted_dest_ptr->static_value;
9371 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;
93419372 ConstExprValue *dest_elements;
93429373 size_t dest_start;
93439374 size_t dest_end;
......@@ -9357,7 +9388,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
93579388 return ira->codegen->builtin_types.entry_invalid;
93589389 }
93599390
9360 ConstExprValue *src_ptr_val = &casted_src_ptr->static_value;
9391 ConstExprValue *src_ptr_val = &casted_src_ptr->value;
93619392 ConstExprValue *src_elements;
93629393 size_t src_start;
93639394 size_t src_end;
......@@ -9393,31 +9424,31 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
93939424
93949425static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
93959426 IrInstruction *ptr = instruction->ptr->other;
9396 if (ptr->type_entry->id == TypeTableEntryIdInvalid)
9427 if (ptr->value.type->id == TypeTableEntryIdInvalid)
93979428 return ira->codegen->builtin_types.entry_invalid;
93989429
93999430 IrInstruction *start = instruction->start->other;
9400 if (start->type_entry->id == TypeTableEntryIdInvalid)
9431 if (start->value.type->id == TypeTableEntryIdInvalid)
94019432 return ira->codegen->builtin_types.entry_invalid;
94029433
94039434 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
94049435 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
9405 if (casted_start->type_entry->id == TypeTableEntryIdInvalid)
9436 if (casted_start->value.type->id == TypeTableEntryIdInvalid)
94069437 return ira->codegen->builtin_types.entry_invalid;
94079438
94089439 IrInstruction *end;
94099440 if (instruction->end) {
94109441 end = instruction->end->other;
9411 if (end->type_entry->id == TypeTableEntryIdInvalid)
9442 if (end->value.type->id == TypeTableEntryIdInvalid)
94129443 return ira->codegen->builtin_types.entry_invalid;
94139444 end = ir_implicit_cast(ira, end, usize);
9414 if (end->type_entry->id == TypeTableEntryIdInvalid)
9445 if (end->value.type->id == TypeTableEntryIdInvalid)
94159446 return ira->codegen->builtin_types.entry_invalid;
94169447 } else {
94179448 end = nullptr;
94189449 }
94199450
9420 TypeTableEntry *array_type = get_underlying_type(ptr->type_entry);
9451 TypeTableEntry *array_type = get_underlying_type(ptr->value.type);
94219452
94229453 TypeTableEntry *return_type;
94239454
......@@ -9435,38 +9466,38 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
94359466 instruction->is_const);
94369467 } else {
94379468 ir_add_error(ira, &instruction->base,
9438 buf_sprintf("slice of non-array type '%s'", buf_ptr(&ptr->type_entry->name)));
9469 buf_sprintf("slice of non-array type '%s'", buf_ptr(&ptr->value.type->name)));
94399470 // TODO if this is a typedecl, add error note showing the declaration of the type decl
94409471 return ira->codegen->builtin_types.entry_invalid;
94419472 }
94429473
9443 if (ptr->static_value.special == ConstValSpecialStatic &&
9444 casted_start->static_value.special == ConstValSpecialStatic &&
9445 (!end || end->static_value.special == ConstValSpecialStatic))
9474 if (ptr->value.special == ConstValSpecialStatic &&
9475 casted_start->value.special == ConstValSpecialStatic &&
9476 (!end || end->value.special == ConstValSpecialStatic))
94469477 {
94479478 bool depends_on_compile_var =
9448 ptr->static_value.depends_on_compile_var ||
9449 casted_start->static_value.depends_on_compile_var ||
9450 (end ? end->static_value.depends_on_compile_var : false);
9479 ptr->value.depends_on_compile_var ||
9480 casted_start->value.depends_on_compile_var ||
9481 (end ? end->value.depends_on_compile_var : false);
94519482
94529483 ConstExprValue *base_ptr;
94539484 size_t abs_offset;
94549485 size_t rel_end;
94559486 if (array_type->id == TypeTableEntryIdArray) {
9456 base_ptr = &ptr->static_value;
9487 base_ptr = &ptr->value;
94579488 abs_offset = 0;
94589489 rel_end = array_type->data.array.len;
94599490 } else if (array_type->id == TypeTableEntryIdPointer) {
9460 base_ptr = ptr->static_value.data.x_ptr.base_ptr;
9461 abs_offset = ptr->static_value.data.x_ptr.index;
9491 base_ptr = ptr->value.data.x_ptr.base_ptr;
9492 abs_offset = ptr->value.data.x_ptr.index;
94629493 if (abs_offset == SIZE_MAX) {
94639494 rel_end = 1;
94649495 } else {
94659496 rel_end = base_ptr->data.x_array.size - abs_offset;
94669497 }
94679498 } else if (is_slice(array_type)) {
9468 ConstExprValue *ptr_val = &ptr->static_value.data.x_struct.fields[slice_ptr_index];
9469 ConstExprValue *len_val = &ptr->static_value.data.x_struct.fields[slice_len_index];
9499 ConstExprValue *ptr_val = &ptr->value.data.x_struct.fields[slice_ptr_index];
9500 ConstExprValue *len_val = &ptr->value.data.x_struct.fields[slice_len_index];
94709501 base_ptr = ptr_val->data.x_ptr.base_ptr;
94719502 abs_offset = ptr_val->data.x_ptr.index;
94729503
......@@ -9479,7 +9510,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
94799510 zig_unreachable();
94809511 }
94819512
9482 uint64_t start_scalar = casted_start->static_value.data.x_bignum.data.x_uint;
9513 uint64_t start_scalar = casted_start->value.data.x_bignum.data.x_uint;
94839514 if (start_scalar > rel_end) {
94849515 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
94859516 return ira->codegen->builtin_types.entry_invalid;
......@@ -9487,7 +9518,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
94879518
94889519 uint64_t end_scalar;
94899520 if (end) {
9490 end_scalar = end->static_value.data.x_bignum.data.x_uint;
9521 end_scalar = end->value.data.x_bignum.data.x_uint;
94919522 } else {
94929523 end_scalar = rel_end;
94939524 }
......@@ -9504,18 +9535,17 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
95049535 out_val->data.x_struct.fields = allocate<ConstExprValue>(2);
95059536
95069537 ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index];
9507 ptr_val->special = ConstValSpecialStatic;
9508 ptr_val->data.x_ptr.base_ptr = base_ptr;
9509 ptr_val->data.x_ptr.index = (abs_offset != SIZE_MAX) ? (abs_offset + start_scalar) : SIZE_MAX;
9538 size_t index = (abs_offset != SIZE_MAX) ? (abs_offset + start_scalar) : SIZE_MAX;
9539 init_const_ptr(ira->codegen, ptr_val, base_ptr, index, instruction->is_const);
95109540
95119541 ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index];
9512 len_val->special = ConstValSpecialStatic;
9513 bignum_init_unsigned(&len_val->data.x_bignum, rel_end);
9542 init_const_usize(ira->codegen, len_val, rel_end);
95149543
95159544 return return_type;
95169545 }
95179546
9518 IrInstruction *new_instruction = ir_build_slice_from(&ira->new_irb, &instruction->base, ptr, casted_start, end, instruction->is_const);
9547 IrInstruction *new_instruction = ir_build_slice_from(&ira->new_irb, &instruction->base, ptr,
9548 casted_start, end, instruction->is_const, instruction->safety_check_on);
95199549 ir_add_alloca(ira, new_instruction, return_type);
95209550
95219551 return return_type;
......@@ -9523,7 +9553,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
95239553
95249554static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
95259555 IrInstruction *container = instruction->container->other;
9526 if (container->type_entry->id == TypeTableEntryIdInvalid)
9556 if (container->value.type->id == TypeTableEntryIdInvalid)
95279557 return ira->codegen->builtin_types.entry_invalid;
95289558 TypeTableEntry *container_type = ir_resolve_type(ira, container);
95299559 TypeTableEntry *canon_type = get_underlying_type(container_type);
......@@ -9542,7 +9572,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
95429572 return ira->codegen->builtin_types.entry_invalid;
95439573 }
95449574
9545 bool depends_on_compile_var = container->static_value.depends_on_compile_var;
9575 bool depends_on_compile_var = container->value.depends_on_compile_var;
95469576 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
95479577 bignum_init_unsigned(&out_val->data.x_bignum, result);
95489578 return ira->codegen->builtin_types.entry_num_lit_int;
......@@ -9571,7 +9601,7 @@ static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIn
95719601
95729602static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
95739603 IrInstruction *type_value = instruction->type_value->other;
9574 if (type_value->type_entry->id == TypeTableEntryIdInvalid)
9604 if (type_value->value.type->id == TypeTableEntryIdInvalid)
95759605 return ira->codegen->builtin_types.entry_invalid;
95769606 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
95779607
......@@ -9583,7 +9613,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
95839613 return ira->codegen->builtin_types.entry_invalid;
95849614 } else {
95859615 uint64_t align_in_bytes = LLVMABISizeOfType(ira->codegen->target_data_ref, type_entry->type_ref);
9586 bool depends_on_compile_var = type_value->static_value.depends_on_compile_var;
9616 bool depends_on_compile_var = type_value->value.depends_on_compile_var;
95879617 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
95889618 bignum_init_unsigned(&out_val->data.x_bignum, align_in_bytes);
95899619 return ira->codegen->builtin_types.entry_num_lit_int;
......@@ -9592,7 +9622,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
95929622
95939623static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
95949624 IrInstruction *type_value = instruction->type_value->other;
9595 if (type_value->type_entry->id == TypeTableEntryIdInvalid)
9625 if (type_value->value.type->id == TypeTableEntryIdInvalid)
95969626 return ira->codegen->builtin_types.entry_invalid;
95979627 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
95989628 TypeTableEntry *canon_type = get_underlying_type(dest_type);
......@@ -9607,41 +9637,41 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
96079637 }
96089638
96099639 IrInstruction *op1 = instruction->op1->other;
9610 if (op1->type_entry->id == TypeTableEntryIdInvalid)
9640 if (op1->value.type->id == TypeTableEntryIdInvalid)
96119641 return ira->codegen->builtin_types.entry_invalid;
96129642
96139643 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
9614 if (casted_op1->type_entry->id == TypeTableEntryIdInvalid)
9644 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)
96159645 return ira->codegen->builtin_types.entry_invalid;
96169646
96179647 IrInstruction *op2 = instruction->op2->other;
9618 if (op2->type_entry->id == TypeTableEntryIdInvalid)
9648 if (op2->value.type->id == TypeTableEntryIdInvalid)
96199649 return ira->codegen->builtin_types.entry_invalid;
96209650
96219651 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
9622 if (casted_op2->type_entry->id == TypeTableEntryIdInvalid)
9652 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)
96239653 return ira->codegen->builtin_types.entry_invalid;
96249654
96259655 IrInstruction *result_ptr = instruction->result_ptr->other;
9626 if (result_ptr->type_entry->id == TypeTableEntryIdInvalid)
9656 if (result_ptr->value.type->id == TypeTableEntryIdInvalid)
96279657 return ira->codegen->builtin_types.entry_invalid;
96289658
96299659 TypeTableEntry *expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
96309660 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
9631 if (casted_result_ptr->type_entry->id == TypeTableEntryIdInvalid)
9661 if (casted_result_ptr->value.type->id == TypeTableEntryIdInvalid)
96329662 return ira->codegen->builtin_types.entry_invalid;
96339663
9634 if (casted_op1->static_value.special == ConstValSpecialStatic &&
9635 casted_op2->static_value.special == ConstValSpecialStatic &&
9636 casted_result_ptr->static_value.special == ConstValSpecialStatic)
9664 if (casted_op1->value.special == ConstValSpecialStatic &&
9665 casted_op2->value.special == ConstValSpecialStatic &&
9666 casted_result_ptr->value.special == ConstValSpecialStatic)
96379667 {
9638 bool depends_on_compile_var = type_value->static_value.depends_on_compile_var ||
9639 casted_op1->static_value.depends_on_compile_var || casted_op2->static_value.depends_on_compile_var ||
9640 casted_result_ptr->static_value.depends_on_compile_var;
9668 bool depends_on_compile_var = type_value->value.depends_on_compile_var ||
9669 casted_op1->value.depends_on_compile_var || casted_op2->value.depends_on_compile_var ||
9670 casted_result_ptr->value.depends_on_compile_var;
96419671 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
9642 BigNum *op1_bignum = &casted_op1->static_value.data.x_bignum;
9643 BigNum *op2_bignum = &casted_op2->static_value.data.x_bignum;
9644 ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->static_value);
9672 BigNum *op1_bignum = &casted_op1->value.data.x_bignum;
9673 BigNum *op2_bignum = &casted_op2->value.data.x_bignum;
9674 ConstExprValue *pointee_val = const_ptr_pointee(&casted_result_ptr->value);
96459675 BigNum *dest_bignum = &pointee_val->data.x_bignum;
96469676 switch (instruction->op) {
96479677 case IrOverflowOpAdd:
......@@ -9674,10 +9704,10 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
96749704
96759705static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
96769706 IrInstruction *value = instruction->value->other;
9677 if (value->type_entry->id == TypeTableEntryIdInvalid)
9707 if (value->value.type->id == TypeTableEntryIdInvalid)
96789708 return ira->codegen->builtin_types.entry_invalid;
96799709
9680 TypeTableEntry *non_canon_type = value->type_entry;
9710 TypeTableEntry *non_canon_type = value->value.type;
96819711
96829712 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
96839713 if (canon_type->id == TypeTableEntryIdInvalid) {
......@@ -9713,9 +9743,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
97139743 IrInstructionUnwrapErrCode *instruction)
97149744{
97159745 IrInstruction *value = instruction->value->other;
9716 if (value->type_entry->id == TypeTableEntryIdInvalid)
9746 if (value->value.type->id == TypeTableEntryIdInvalid)
97179747 return ira->codegen->builtin_types.entry_invalid;
9718 TypeTableEntry *ptr_type = value->type_entry;
9748 TypeTableEntry *ptr_type = value->value.type;
97199749
97209750 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
97219751 assert(ptr_type->id == TypeTableEntryIdPointer);
......@@ -9756,9 +9786,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
97569786 IrInstructionUnwrapErrPayload *instruction)
97579787{
97589788 IrInstruction *value = instruction->value->other;
9759 if (value->type_entry->id == TypeTableEntryIdInvalid)
9789 if (value->value.type->id == TypeTableEntryIdInvalid)
97609790 return ira->codegen->builtin_types.entry_invalid;
9761 TypeTableEntry *ptr_type = value->type_entry;
9791 TypeTableEntry *ptr_type = value->value.type;
97629792
97639793 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
97649794 assert(ptr_type->id == TypeTableEntryIdPointer);
......@@ -9824,14 +9854,14 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
98249854 if (param_info->type->id == TypeTableEntryIdInvalid)
98259855 return ira->codegen->builtin_types.entry_invalid;
98269856
9827 depends_on_compile_var = depends_on_compile_var || param_type_value->static_value.depends_on_compile_var;
9857 depends_on_compile_var = depends_on_compile_var || param_type_value->value.depends_on_compile_var;
98289858 }
98299859
98309860 IrInstruction *return_type_value = instruction->return_type->other;
98319861 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
98329862 if (fn_type_id.return_type->id == TypeTableEntryIdInvalid)
98339863 return ira->codegen->builtin_types.entry_invalid;
9834 depends_on_compile_var = depends_on_compile_var || return_type_value->static_value.depends_on_compile_var;
9864 depends_on_compile_var = depends_on_compile_var || return_type_value->value.depends_on_compile_var;
98359865
98369866 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
98379867 out_val->data.x_type = get_fn_type(ira->codegen, &fn_type_id);
......@@ -9840,7 +9870,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
98409870
98419871static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
98429872 IrInstruction *value = instruction->value->other;
9843 if (value->type_entry->id == TypeTableEntryIdInvalid)
9873 if (value->value.type->id == TypeTableEntryIdInvalid)
98449874 return ira->codegen->builtin_types.entry_invalid;
98459875
98469876 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, false);
......@@ -9851,6 +9881,11 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn
98519881static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
98529882 switch (instruction->id) {
98539883 case IrInstructionIdInvalid:
9884 case IrInstructionIdPointerReinterpret:
9885 case IrInstructionIdStructInit:
9886 case IrInstructionIdStructFieldPtr:
9887 case IrInstructionIdEnumFieldPtr:
9888 case IrInstructionIdInitEnum:
98549889 zig_unreachable();
98559890 case IrInstructionIdReturn:
98569891 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);
......@@ -9996,10 +10031,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
999610031 case IrInstructionIdErrWrapCode:
999710032 case IrInstructionIdErrWrapPayload:
999810033 case IrInstructionIdCast:
9999 case IrInstructionIdStructFieldPtr:
10000 case IrInstructionIdEnumFieldPtr:
10001 case IrInstructionIdStructInit:
10002 case IrInstructionIdInitEnum:
1000310034 zig_panic("TODO analyze more instructions");
1000410035 }
1000510036 zig_unreachable();
......@@ -10007,9 +10038,9 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1000710038
1000810039static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
1000910040 TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
10010 instruction->type_entry = instruction_type;
10041 instruction->value.type = instruction_type;
1001110042 if (instruction->other) {
10012 instruction->other->type_entry = instruction_type;
10043 instruction->other->value.type = instruction_type;
1001310044 } else {
1001410045 assert(instruction_type->id == TypeTableEntryIdInvalid ||
1001510046 instruction_type->id == TypeTableEntryIdUnreachable);
......@@ -10156,6 +10187,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
1015610187 case IrInstructionIdFnProto:
1015710188 case IrInstructionIdTestComptime:
1015810189 case IrInstructionIdInitEnum:
10190 case IrInstructionIdPointerReinterpret:
1015910191 return false;
1016010192 case IrInstructionIdAsm:
1016110193 {
src/ir_print.cpp+35-29
......@@ -5,6 +5,7 @@
55 * See http://opensource.org/licenses/MIT
66 */
77
8#include "analyze.hpp"
89#include "ir.hpp"
910#include "ir_print.hpp"
1011
......@@ -24,13 +25,13 @@ static void ir_print_indent(IrPrint *irp) {
2425
2526static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) {
2627 ir_print_indent(irp);
27 const char *type_name = instruction->type_entry ? buf_ptr(&instruction->type_entry->name) : "(unknown)";
28 const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)";
2829 const char *ref_count = ir_has_side_effects(instruction) ?
2930 "-" : buf_ptr(buf_sprintf("%zu", instruction->ref_count));
3031 fprintf(irp->f, "#%-3zu| %-12s| %-2s| ", instruction->debug_id, type_name, ref_count);
3132}
3233
33static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, ConstExprValue *const_val) {
34static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
3435 switch (const_val->special) {
3536 case ConstValSpecialRuntime:
3637 zig_unreachable();
......@@ -43,9 +44,12 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
4344 case ConstValSpecialStatic:
4445 break;
4546 }
46 switch (type_entry->id) {
47 assert(const_val->type);
48
49 TypeTableEntry *canon_type = get_underlying_type(const_val->type);
50 switch (canon_type->id) {
4751 case TypeTableEntryIdTypeDecl:
48 return ir_print_const_value(irp, type_entry->data.type_decl.canonical_type, const_val);
52 zig_unreachable();
4953 case TypeTableEntryIdInvalid:
5054 fprintf(irp->f, "(invalid)");
5155 return;
......@@ -94,7 +98,7 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
9498 }
9599 case TypeTableEntryIdPointer:
96100 fprintf(irp->f, "&");
97 ir_print_const_value(irp, type_entry->data.pointer.child_type, const_ptr_pointee(const_val));
101 ir_print_const_value(irp, const_ptr_pointee(const_val));
98102 return;
99103 case TypeTableEntryIdFn:
100104 {
......@@ -110,14 +114,13 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
110114 }
111115 case TypeTableEntryIdArray:
112116 {
113 uint64_t len = type_entry->data.array.len;
114 fprintf(irp->f, "%s{", buf_ptr(&type_entry->name));
117 uint64_t len = canon_type->data.array.len;
118 fprintf(irp->f, "%s{", buf_ptr(&canon_type->name));
115119 for (uint64_t i = 0; i < len; i += 1) {
116120 if (i != 0)
117121 fprintf(irp->f, ",");
118122 ConstExprValue *child_value = &const_val->data.x_array.elements[i];
119 TypeTableEntry *child_type = type_entry->data.array.child_type;
120 ir_print_const_value(irp, child_type, child_value);
123 ir_print_const_value(irp, child_value);
121124 }
122125 fprintf(irp->f, "}");
123126 return;
......@@ -135,7 +138,7 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
135138 case TypeTableEntryIdMaybe:
136139 {
137140 if (const_val->data.x_maybe) {
138 ir_print_const_value(irp, type_entry->data.maybe.child_type, const_val->data.x_maybe);
141 ir_print_const_value(irp, const_val->data.x_maybe);
139142 } else {
140143 fprintf(irp->f, "null");
141144 }
......@@ -160,22 +163,22 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
160163 }
161164 case TypeTableEntryIdStruct:
162165 {
163 fprintf(irp->f, "(struct %s constant)", buf_ptr(&type_entry->name));
166 fprintf(irp->f, "(struct %s constant)", buf_ptr(&canon_type->name));
164167 return;
165168 }
166169 case TypeTableEntryIdEnum:
167170 {
168 fprintf(irp->f, "(enum %s constant)", buf_ptr(&type_entry->name));
171 fprintf(irp->f, "(enum %s constant)", buf_ptr(&canon_type->name));
169172 return;
170173 }
171174 case TypeTableEntryIdErrorUnion:
172175 {
173 fprintf(irp->f, "(error union %s constant)", buf_ptr(&type_entry->name));
176 fprintf(irp->f, "(error union %s constant)", buf_ptr(&canon_type->name));
174177 return;
175178 }
176179 case TypeTableEntryIdUnion:
177180 {
178 fprintf(irp->f, "(union %s constant)", buf_ptr(&type_entry->name));
181 fprintf(irp->f, "(union %s constant)", buf_ptr(&canon_type->name));
179182 return;
180183 }
181184 case TypeTableEntryIdPureError:
......@@ -185,7 +188,7 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
185188 }
186189 case TypeTableEntryIdEnumTag:
187190 {
188 TypeTableEntry *enum_type = type_entry->data.enum_tag.enum_type;
191 TypeTableEntry *enum_type = canon_type->data.enum_tag.enum_type;
189192 TypeEnumField *field = &enum_type->data.enumeration.fields[const_val->data.x_bignum.data.x_uint];
190193 fprintf(irp->f, "%s.%s", buf_ptr(&enum_type->name), buf_ptr(field->name));
191194 return;
......@@ -194,19 +197,13 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
194197 zig_unreachable();
195198}
196199
197static void ir_print_const_instruction(IrPrint *irp, IrInstruction *instruction) {
198 TypeTableEntry *type_entry = instruction->type_entry;
199 ConstExprValue *const_val = &instruction->static_value;
200 ir_print_const_value(irp, type_entry, const_val);
201}
202
203200static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
204201 fprintf(irp->f, "#%zu", instruction->debug_id);
205202}
206203
207204static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
208 if (instruction->static_value.special != ConstValSpecialRuntime) {
209 ir_print_const_instruction(irp, instruction);
205 if (instruction->value.special != ConstValSpecialRuntime) {
206 ir_print_const_value(irp, &instruction->value);
210207 } else {
211208 ir_print_var_instruction(irp, instruction);
212209 }
......@@ -223,7 +220,7 @@ static void ir_print_return(IrPrint *irp, IrInstructionReturn *return_instructio
223220}
224221
225222static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
226 ir_print_const_instruction(irp, &const_instruction->base);
223 ir_print_const_value(irp, &const_instruction->base.value);
227224}
228225
229226static const char *ir_bin_op_id_str(IrBinOp op_id) {
......@@ -925,6 +922,12 @@ static void ir_print_init_enum(IrPrint *irp, IrInstructionInitEnum *instruction)
925922 fprintf(irp->f, "}");
926923}
927924
925static void ir_print_pointer_reinterpret(IrPrint *irp, IrInstructionPointerReinterpret *instruction) {
926 fprintf(irp->f, "(%s)(", buf_ptr(&instruction->base.value.type->name));
927 ir_print_other_instruction(irp, instruction->ptr);
928 fprintf(irp->f, ")");
929}
930
928931static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
929932 ir_print_prefix(irp, instruction);
930933 switch (instruction->id) {
......@@ -1164,6 +1167,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
11641167 case IrInstructionIdInitEnum:
11651168 ir_print_init_enum(irp, (IrInstructionInitEnum *)instruction);
11661169 break;
1170 case IrInstructionIdPointerReinterpret:
1171 ir_print_pointer_reinterpret(irp, (IrInstructionPointerReinterpret *)instruction);
1172 break;
11671173 }
11681174 fprintf(irp->f, "\n");
11691175}
......@@ -1188,14 +1194,14 @@ void ir_print(FILE *f, IrExecutable *executable, int indent_size) {
11881194static void print_tld_var(IrPrint *irp, TldVar *tld_var) {
11891195 const char *const_or_var = tld_var->var->src_is_const ? "const" : "var";
11901196 fprintf(irp->f, "%s %s", const_or_var, buf_ptr(tld_var->base.name));
1191 bool omit_type = (tld_var->var->type->id == TypeTableEntryIdNumLitFloat ||
1192 tld_var->var->type->id == TypeTableEntryIdNumLitInt);
1197 bool omit_type = (tld_var->var->value.type->id == TypeTableEntryIdNumLitFloat ||
1198 tld_var->var->value.type->id == TypeTableEntryIdNumLitInt);
11931199 if (!omit_type) {
1194 fprintf(irp->f, ": %s", buf_ptr(&tld_var->var->type->name));
1200 fprintf(irp->f, ": %s", buf_ptr(&tld_var->var->value.type->name));
11951201 }
1196 if (tld_var->var->value) {
1202 if (tld_var->var->value.special != ConstValSpecialRuntime) {
11971203 fprintf(irp->f, " = ");
1198 ir_print_const_value(irp, tld_var->var->type, tld_var->var->value);
1204 ir_print_const_value(irp, &tld_var->var->value);
11991205 }
12001206 fprintf(irp->f, ";\n");
12011207}
src/parseh.cpp+23-23
......@@ -124,51 +124,52 @@ static void parseh_init_tld(Context *c, Tld *tld, TldId id, Buf *name) {
124124 tld->resolution = TldResolutionOk;
125125}
126126
127static TldVar *create_global_var(Context *c, Buf *name, TypeTableEntry *var_type, ConstExprValue *var_value, bool is_const) {
127static TldVar *create_global_var(Context *c, Buf *name, ConstExprValue *var_value, bool is_const) {
128128 TldVar *tld_var = allocate<TldVar>(1);
129129 parseh_init_tld(c, &tld_var->base, TldIdVar, name);
130 tld_var->var = add_variable(c->codegen, c->source_node, &c->import->decls_scope->base, name, var_type, is_const, var_value);
130 tld_var->var = add_variable(c->codegen, c->source_node, &c->import->decls_scope->base, name, is_const, var_value);
131131 return tld_var;
132132}
133133
134134static Tld *create_global_char_lit_var(Context *c, Buf *name, uint8_t value) {
135 TldVar *tld_var = create_global_var(c, name, c->codegen->builtin_types.entry_u8,
136 create_const_unsigned_negative(value, false), true);
135 ConstExprValue *var_val = create_const_unsigned_negative(c->codegen->builtin_types.entry_u8, value, false);
136 TldVar *tld_var = create_global_var(c, name, var_val, true);
137137 return &tld_var->base;
138138}
139139
140140static Tld *create_global_str_lit_var(Context *c, Buf *name, Buf *value) {
141 TypeTableEntry *str_type = get_array_type(c->codegen, c->codegen->builtin_types.entry_u8, buf_len(value));
142 TldVar *tld_var = create_global_var(c, name, str_type, create_const_str_lit(value), true);
141 TldVar *tld_var = create_global_var(c, name, create_const_str_lit(c->codegen, value), true);
143142 return &tld_var->base;
144143}
145144
146145static Tld *create_global_num_lit_unsigned_negative(Context *c, Buf *name, uint64_t x, bool negative) {
147 TldVar *tld_var = create_global_var(c, name, c->codegen->builtin_types.entry_num_lit_int,
148 create_const_unsigned_negative(x, negative), true);
146 ConstExprValue *var_val = create_const_unsigned_negative(c->codegen->builtin_types.entry_num_lit_int, x, negative);
147 TldVar *tld_var = create_global_var(c, name, var_val, true);
149148 return &tld_var->base;
150149}
151150
152151static Tld *create_global_num_lit_float(Context *c, Buf *name, double value) {
153 TldVar *tld_var = create_global_var(c, name, c->codegen->builtin_types.entry_num_lit_float,
154 create_const_float(value), true);
152 ConstExprValue *var_val = create_const_float(c->codegen->builtin_types.entry_num_lit_float, value);
153 TldVar *tld_var = create_global_var(c, name, var_val, true);
155154 return &tld_var->base;
156155}
157156
158static ConstExprValue *create_const_num_lit_ap(Context *c, const Decl *source_decl, const llvm::APSInt &aps_int) {
157static ConstExprValue *create_const_int_ap(Context *c, TypeTableEntry *type, const Decl *source_decl,
158 const llvm::APSInt &aps_int)
159{
159160 if (aps_int.isSigned()) {
160161 if (aps_int > INT64_MAX || aps_int < INT64_MIN) {
161162 emit_warning(c, source_decl, "integer overflow\n");
162163 return nullptr;
163164 } else {
164 return create_const_signed(aps_int.getExtValue());
165 return create_const_signed(type, aps_int.getExtValue());
165166 }
166167 } else {
167168 if (aps_int > INT64_MAX) {
168169 emit_warning(c, source_decl, "integer overflow\n");
169170 return nullptr;
170171 } else {
171 return create_const_unsigned_negative(aps_int.getExtValue(), false);
172 return create_const_unsigned_negative(type, aps_int.getExtValue(), false);
172173 }
173174 }
174175}
......@@ -176,19 +177,18 @@ static ConstExprValue *create_const_num_lit_ap(Context *c, const Decl *source_de
176177static Tld *create_global_num_lit_ap(Context *c, const Decl *source_decl, Buf *name,
177178 const llvm::APSInt &aps_int)
178179{
179 ConstExprValue *const_value = create_const_num_lit_ap(c, source_decl, aps_int);
180 ConstExprValue *const_value = create_const_int_ap(c, c->codegen->builtin_types.entry_num_lit_int,
181 source_decl, aps_int);
180182 if (!const_value)
181183 return nullptr;
182 TldVar *tld_var = create_global_var(c, name, c->codegen->builtin_types.entry_num_lit_int, const_value, true);
184 TldVar *tld_var = create_global_var(c, name, const_value, true);
183185 return &tld_var->base;
184186}
185187
186188
187189static Tld *add_const_type(Context *c, Buf *name, TypeTableEntry *type_entry) {
188 ConstExprValue *var_value = allocate<ConstExprValue>(1);
189 var_value->special = ConstValSpecialStatic;
190 var_value->data.x_type = type_entry;
191 TldVar *tld_var = create_global_var(c, name, c->codegen->builtin_types.entry_type, var_value, true);
190 ConstExprValue *var_value = create_const_type(c->codegen, type_entry);
191 TldVar *tld_var = create_global_var(c, name, var_value, true);
192192 add_global(c, &tld_var->base);
193193
194194 c->global_type_table.put(name, type_entry);
......@@ -1025,7 +1025,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
10251025 "ignoring variable '%s' - int initializer for non int type\n", buf_ptr(name));
10261026 return;
10271027 }
1028 init_value = create_const_num_lit_ap(c, var_decl, ap_value->getInt());
1028 init_value = create_const_int_ap(c, var_type, var_decl, ap_value->getInt());
10291029 if (!init_value)
10301030 return;
10311031
......@@ -1047,13 +1047,13 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
10471047 return;
10481048 }
10491049
1050 TldVar *tld_var = create_global_var(c, name, var_type, init_value, true);
1050 TldVar *tld_var = create_global_var(c, name, init_value, true);
10511051 add_global(c, &tld_var->base);
10521052 return;
10531053 }
10541054
10551055 if (is_extern) {
1056 TldVar *tld_var = create_global_var(c, name, var_type, nullptr, is_const);
1056 TldVar *tld_var = create_global_var(c, name, create_const_runtime(var_type), is_const);
10571057 tld_var->var->is_extern = true;
10581058 add_global(c, &tld_var->base);
10591059 return;
......@@ -1199,7 +1199,7 @@ static void process_symbol_macros(Context *c) {
11991199 // variable is non-null and calls it.
12001200 if (existing_tld->id == TldIdVar) {
12011201 TldVar *tld_var = (TldVar *)existing_tld;
1202 TypeTableEntry *var_type = tld_var->var->type;
1202 TypeTableEntry *var_type = tld_var->var->value.type;
12031203 if (var_type->id == TypeTableEntryIdMaybe && !tld_var->var->src_is_const) {
12041204 TypeTableEntry *child_type = var_type->data.maybe.child_type;
12051205 if (child_type->id == TypeTableEntryIdFn) {
test/cases3/misc.zig+10-1
......@@ -261,6 +261,16 @@ fn typeEquality() {
261261 assert(&const u8 != &u8);
262262}
263263
264
265const global_a: i32 = 1234;
266const global_b: &const i32 = &global_a;
267const global_c: &const f32 = (&const f32)(global_b);
268fn compileTimeGlobalReinterpret() {
269 @setFnTest(this);
270 const d = (&const i32)(global_c);
271 assert(*d == 1234);
272}
273
264274// TODO import from std.str
265275pub fn memeql(a: []const u8, b: []const u8) -> bool {
266276 sliceEql(u8, a, b)
......@@ -288,7 +298,6 @@ pub fn cstrcmp(a: &const u8, b: &const u8) -> i8 {
288298 };
289299}
290300
291
292301// TODO const assert = @import("std").debug.assert;
293302fn assert(ok: bool) {
294303 if (!ok)
test/self_hosted.zig+1-16
......@@ -9,27 +9,12 @@ const test_enum_with_members = @import("cases/enum_with_members.zig");
99
1010
1111fn explicitCastMaybePointers() {
12 @setFnTest(this, true);
12 @setFnTest(this);
1313
1414 const a: ?&i32 = undefined;
1515 const b: ?&f32 = (?&f32)(a);
1616}
1717
18
19fn multilineCString() {
20 @setFnTest(this);
21
22 const s1 =
23 c\\one
24 c\\two)
25 c\\three
26 ;
27 const s2 = c"one\ntwo)\nthree";
28 assert(cstr.cmp(s1, s2) == 0);
29}
30
31
32
3318fn genericMallocFree() {
3419 @setFnTest(this, true);
3520