authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-31 18:14:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-31 18:23:39-04:00
log2f614c42fe4f28e5adda8163bd50d6d3507d6353
tree72b3bd68556d1d39b8a5512c9c11ee10e94af32b
parentfcbb7426faac5e693ef195defe2d8d2a2eddadb1

ir: rip out special logic for using addr-of instruction for types

See #588

3 files changed, 46 insertions(+), 115 deletions(-)

src/all_types.hpp-2
......@@ -2275,8 +2275,6 @@ struct IrInstructionVarPtr {
22752275 IrInstruction base;
22762276
22772277 VariableTableEntry *var;
2278 bool is_const;
2279 bool is_volatile;
22802278};
22812279
22822280struct IrInstructionCall {
src/ir.cpp+44-111
......@@ -104,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
104104static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
105105static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
106106 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
108 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr);
107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
109108static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
110109static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
111110
......@@ -1000,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1000999 return new_instruction;
10011000}
10021001
1003static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1004 VariableTableEntry *var, bool is_const, bool is_volatile)
1005{
1002static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
10061003 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
10071004 instruction->var = var;
1008 instruction->is_const = is_const;
1009 instruction->is_volatile = is_volatile;
10101005
10111006 ir_ref_var(var);
10121007
......@@ -3515,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
35153510
35163511 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
35173512 if (var) {
3518 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var,
3519 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
3513 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
35203514 if (lval.is_ptr)
35213515 return var_ptr;
35223516 else
......@@ -5140,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51405134
51415135 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
51425136 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value);
5143 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var, false, false);
5137 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
51445138
51455139 AstNode *index_var_source_node;
51465140 VariableTableEntry *index_var;
......@@ -5158,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51585152 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
51595153 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
51605154 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero);
5161 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false, false);
5155 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);
51625156
51635157
51645158 IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond");
......@@ -6387,7 +6381,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast
63876381 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);
63886382 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);
63896383 ir_build_var_decl(irb, parent_scope, node, result_var, promise_result_type, nullptr, undefined_value);
6390 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var, false, false);
6384 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var);
63916385 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);
63926386 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);
63936387 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node,
......@@ -6708,15 +6702,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
67086702 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
67096703 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
67106704 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
6711 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var, false, false);
6705 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
67126706
67136707 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
67146708 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
67156709 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
67166710 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
67176711 ir_build_var_decl(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value);
6718 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node,
6719 await_handle_var, false, false);
6712 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
67206713
67216714 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
67226715 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));
......@@ -6856,7 +6849,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
68566849 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
68576850 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);
68586851 IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false);
6859 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var, true, false);
6852 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var);
68606853 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);
68616854 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);
68626855 size_t arg_count = 2;
......@@ -8958,35 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
89588951 ConstExprValue *pointee, TypeTableEntry *pointee_type,
89598952 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
89608953{
8961 // TODO remove this special case for types
8962 if (pointee_type->id == TypeTableEntryIdMetaType) {
8963 TypeTableEntry *type_entry = pointee->data.x_type;
8964 if (type_entry->id == TypeTableEntryIdUnreachable) {
8965 ir_add_error(ira, instruction, buf_sprintf("pointer to noreturn not allowed"));
8966 return ira->codegen->invalid_instruction;
8967 }
8968
8969 IrInstruction *const_instr = ir_get_const(ira, instruction);
8970 ConstExprValue *const_val = &const_instr->value;
8971 const_val->type = pointee_type;
8972 type_ensure_zero_bits_known(ira->codegen, type_entry);
8973 if (type_is_invalid(type_entry)) {
8974 return ira->codegen->invalid_instruction;
8975 }
8976 const_val->data.x_type = get_pointer_to_type_extra(ira->codegen, type_entry,
8977 ptr_is_const, ptr_is_volatile, get_abi_alignment(ira->codegen, type_entry), 0, 0);
8978 return const_instr;
8979 } else {
8980 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8981 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8982 IrInstruction *const_instr = ir_get_const(ira, instruction);
8983 ConstExprValue *const_val = &const_instr->value;
8984 const_val->type = ptr_type;
8985 const_val->data.x_ptr.special = ConstPtrSpecialRef;
8986 const_val->data.x_ptr.mut = ptr_mut;
8987 const_val->data.x_ptr.data.ref.pointee = pointee;
8988 return const_instr;
8989 }
8954 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8955 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8956 IrInstruction *const_instr = ir_get_const(ira, instruction);
8957 ConstExprValue *const_val = &const_instr->value;
8958 const_val->type = ptr_type;
8959 const_val->data.x_ptr.special = ConstPtrSpecialRef;
8960 const_val->data.x_ptr.mut = ptr_mut;
8961 const_val->data.x_ptr.data.ref.pointee = pointee;
8962 return const_instr;
89908963}
89918964
89928965static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
......@@ -9314,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
93149287 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);
93159288 if (!val)
93169289 return ira->codegen->invalid_instruction;
9317 bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true;
93189290 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,
9319 ConstPtrMutComptimeConst, final_is_const, is_volatile,
9291 ConstPtrMutComptimeConst, is_const, is_volatile,
93209292 get_abi_alignment(ira->codegen, value->value.type));
93219293 }
93229294
......@@ -10245,21 +10217,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1024510217 source_instruction->source_node, ptr);
1024610218 load_ptr_instruction->value.type = child_type;
1024710219 return load_ptr_instruction;
10248 } else if (type_entry->id == TypeTableEntryIdMetaType) {
10249 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad);
10250 if (!ptr_val)
10251 return ira->codegen->invalid_instruction;
10252
10253 TypeTableEntry *ptr_type = ptr_val->data.x_type;
10254 if (ptr_type->id == TypeTableEntryIdPointer) {
10255 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
10256 return ir_create_const_type(&ira->new_irb, source_instruction->scope,
10257 source_instruction->source_node, child_type);
10258 } else {
10259 ir_add_error(ira, source_instruction,
10260 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name)));
10261 return ira->codegen->invalid_instruction;
10262 }
1026310220 } else {
1026410221 ir_add_error_node(ira, source_instruction->source_node,
1026510222 buf_sprintf("attempt to dereference non pointer type '%s'",
......@@ -11966,7 +11923,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
1196611923 {
1196711924 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
1196811925 assert(coro_allocator_var != nullptr);
11969 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var, true, false);
11926 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
1197011927 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
1197111928 assert(result->value.type != nullptr);
1197211929 return result;
......@@ -12147,7 +12104,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
1214712104}
1214812105
1214912106static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12150 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
12107 VariableTableEntry *var)
1215112108{
1215212109 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
1215312110 assert(ira->codegen->errors.length != 0);
......@@ -12173,8 +12130,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1217312130 }
1217412131 }
1217512132
12176 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;
12177 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;
12133 bool is_const = var->src_is_const;
12134 bool is_volatile = false;
1217812135 if (mem_slot != nullptr) {
1217912136 switch (mem_slot->special) {
1218012137 case ConstValSpecialRuntime:
......@@ -12200,7 +12157,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1220012157no_mem_slot:
1220112158
1220212159 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
12203 instruction->scope, instruction->source_node, var, is_const, is_volatile);
12160 instruction->scope, instruction->source_node, var);
1220412161 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
1220512162 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
1220612163 type_ensure_zero_bits_known(ira->codegen, var->value->type);
......@@ -12486,7 +12443,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1248612443 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
1248712444 return ira->codegen->builtin_types.entry_invalid;
1248812445 }
12489 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var, true, false);
12446 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);
1249012447 if (type_is_invalid(arg_var_ptr_inst->value.type))
1249112448 return ira->codegen->builtin_types.entry_invalid;
1249212449
......@@ -13120,17 +13077,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
1312013077}
1312113078
1312213079static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13123 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
13080 VariableTableEntry *var)
1312413081{
13125 IrInstruction *result = ir_get_var_ptr(ira, instruction, var, is_const_ptr, is_volatile_ptr);
13082 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
1312613083 ir_link_new_instruction(result, instruction);
1312713084 return result->value.type;
1312813085}
1312913086
1313013087static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
1313113088 VariableTableEntry *var = var_ptr_instruction->var;
13132 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,
13133 var_ptr_instruction->is_volatile);
13089 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
1313413090}
1313513091
1313613092static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {
......@@ -13152,11 +13108,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1315213108 return ira->codegen->builtin_types.entry_invalid;
1315313109
1315413110 TypeTableEntry *ptr_type = array_ptr->value.type;
13155 if (ptr_type->id == TypeTableEntryIdMetaType) {
13156 ir_add_error(ira, &elem_ptr_instruction->base,
13157 buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name)));
13158 return ira->codegen->builtin_types.entry_invalid;
13159 }
1316013111 assert(ptr_type->id == TypeTableEntryIdPointer);
1316113112
1316213113 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
......@@ -13218,8 +13169,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1321813169 bool is_const = true;
1321913170 bool is_volatile = false;
1322013171 if (var) {
13221 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,
13222 is_const, is_volatile);
13172 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var);
1322313173 } else {
1322413174 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,
1322513175 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile);
......@@ -13603,7 +13553,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
1360313553 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
1360413554 }
1360513555
13606 return ir_analyze_var_ptr(ira, source_instruction, var, false, false);
13556 return ir_analyze_var_ptr(ira, source_instruction, var);
1360713557 }
1360813558 case TldIdFn:
1360913559 {
......@@ -13652,14 +13602,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1365213602 if (type_is_invalid(container_ptr->value.type))
1365313603 return ira->codegen->builtin_types.entry_invalid;
1365413604
13655 TypeTableEntry *container_type;
13656 if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
13657 container_type = container_ptr->value.type->data.pointer.child_type;
13658 } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
13659 container_type = container_ptr->value.type;
13660 } else {
13661 zig_unreachable();
13662 }
13605 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
13606 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
1366313607
1366413608 Buf *field_name = field_ptr_instruction->field_name_buffer;
1366513609 if (!field_name) {
......@@ -13732,17 +13676,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1373213676 if (!container_ptr_val)
1373313677 return ira->codegen->builtin_types.entry_invalid;
1373413678
13735 TypeTableEntry *child_type;
13736 if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
13737 TypeTableEntry *ptr_type = container_ptr_val->data.x_type;
13738 assert(ptr_type->id == TypeTableEntryIdPointer);
13739 child_type = ptr_type->data.pointer.child_type;
13740 } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
13741 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13742 child_type = child_val->data.x_type;
13743 } else {
13744 zig_unreachable();
13745 }
13679 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
13680 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13681 TypeTableEntry *child_type = child_val->data.x_type;
1374613682
1374713683 if (type_is_invalid(child_type)) {
1374813684 return ira->codegen->builtin_types.entry_invalid;
......@@ -17337,8 +17273,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1733717273 if (array_type->data.array.len == 0 && byte_alignment == 0) {
1733817274 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
1733917275 }
17276 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
17277 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
1734017278 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
17341 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
17279 ptr_type->data.pointer.is_const || is_comptime_const,
17280 ptr_type->data.pointer.is_volatile,
1734217281 byte_alignment, 0, 0);
1734317282 return_type = get_slice_type(ira->codegen, slice_ptr_type);
1734417283 } else if (array_type->id == TypeTableEntryIdPointer) {
......@@ -17525,6 +17464,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1752517464 return ira->codegen->builtin_types.entry_invalid;
1752617465 TypeTableEntry *container_type = ir_resolve_type(ira, container);
1752717466
17467 ensure_complete_type(ira->codegen, container_type);
17468 if (type_is_invalid(container_type))
17469 return ira->codegen->builtin_types.entry_invalid;
17470
1752817471 uint64_t result;
1752917472 if (type_is_invalid(container_type)) {
1753017473 return ira->codegen->builtin_types.entry_invalid;
......@@ -17912,15 +17855,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1791217855 return ira->codegen->builtin_types.entry_invalid;
1791317856 TypeTableEntry *ptr_type = value->value.type;
1791417857
17915 // Because we don't have Pointer Reform yet, we can't have a pointer to a 'type'.
17916 // Therefor, we have to check for type 'type' here, so we can output a correct error
17917 // without asserting the assert below.
17918 if (ptr_type->id == TypeTableEntryIdMetaType) {
17919 ir_add_error(ira, value,
17920 buf_sprintf("expected error union type, found '%s'", buf_ptr(&ptr_type->name)));
17921 return ira->codegen->builtin_types.entry_invalid;
17922 }
17923
1792417858 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
1792517859 assert(ptr_type->id == TypeTableEntryIdPointer);
1792617860
......@@ -18697,8 +18631,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
1869718631 TldVar *tld_var = (TldVar *)tld;
1869818632 VariableTableEntry *var = tld_var->var;
1869918633
18700 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var,
18701 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
18634 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
1870218635 if (type_is_invalid(var_ptr->value.type))
1870318636 return ira->codegen->builtin_types.entry_invalid;
1870418637
std/zig/parser_test.zig+2-2
......@@ -1298,8 +1298,8 @@ test "zig fmt: struct declaration" {
12981298 \\ f1: u8,
12991299 \\ pub f3: u8,
13001300 \\
1301 \\ fn method(self: &Self) Self {
1302 \\ return *self;
1301 \\ fn method(self: *Self) Self {
1302 \\ return self.*;
13031303 \\ }
13041304 \\
13051305 \\ f2: u8,