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 {...@@ -2275,8 +2275,6 @@ struct IrInstructionVarPtr {
2275 IrInstruction base;2275 IrInstruction base;
22762276
2277 VariableTableEntry *var;2277 VariableTableEntry *var;
2278 bool is_const;
2279 bool is_volatile;
2280};2278};
22812279
2282struct IrInstructionCall {2280struct IrInstructionCall {
src/ir.cpp+44-111
...@@ -104,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -104,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
104static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);104static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
105static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,105static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
106 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);106 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
108 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr);
109static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);108static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
110static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);109static 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...@@ -1000,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1000 return new_instruction;999 return new_instruction;
1001}1000}
10021001
1003static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,1002static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
1004 VariableTableEntry *var, bool is_const, bool is_volatile)
1005{
1006 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);1003 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
1007 instruction->var = var;1004 instruction->var = var;
1008 instruction->is_const = is_const;
1009 instruction->is_volatile = is_volatile;
10101005
1011 ir_ref_var(var);1006 ir_ref_var(var);
10121007
...@@ -3515,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3515,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
35153510
3516 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);3511 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3517 if (var) {3512 if (var) {
3518 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var,3513 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3519 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
3520 if (lval.is_ptr)3514 if (lval.is_ptr)
3521 return var_ptr;3515 return var_ptr;
3522 else3516 else
...@@ -5140,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5140,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51405134
5141 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);5135 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
5142 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value);5136 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
5145 AstNode *index_var_source_node;5139 AstNode *index_var_source_node;
5146 VariableTableEntry *index_var;5140 VariableTableEntry *index_var;
...@@ -5158,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5158,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5158 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);5152 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
5159 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);5153 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
5160 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero);5154 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
5164 IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond");5158 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...@@ -6387,7 +6381,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast
6387 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);6381 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);
6388 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);6382 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);
6389 ir_build_var_decl(irb, parent_scope, node, result_var, promise_result_type, nullptr, undefined_value);6383 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);
6391 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);6385 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);
6392 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);6386 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);
6393 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node,6387 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...@@ -6708,15 +6702,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6708 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);6702 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
6709 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa6703 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
6710 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);6704 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
6713 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);6707 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
6714 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);6708 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
6715 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,6709 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
6716 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));6710 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
6717 ir_build_var_decl(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value);6711 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,6712 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
6719 await_handle_var, false, false);
67206713
6721 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,6714 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
6722 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));6715 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...@@ -6856,7 +6849,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6856 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);6849 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
6857 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);6850 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);
6858 IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false);6851 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);
6860 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);6853 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);
6861 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);6854 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);
6862 size_t arg_count = 2;6855 size_t arg_count = 2;
...@@ -8958,35 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -8958,35 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
8958 ConstExprValue *pointee, TypeTableEntry *pointee_type,8951 ConstExprValue *pointee, TypeTableEntry *pointee_type,
8959 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)8952 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
8960{8953{
8961 // TODO remove this special case for types8954 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8962 if (pointee_type->id == TypeTableEntryIdMetaType) {8955 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8963 TypeTableEntry *type_entry = pointee->data.x_type;8956 IrInstruction *const_instr = ir_get_const(ira, instruction);
8964 if (type_entry->id == TypeTableEntryIdUnreachable) {8957 ConstExprValue *const_val = &const_instr->value;
8965 ir_add_error(ira, instruction, buf_sprintf("pointer to noreturn not allowed"));8958 const_val->type = ptr_type;
8966 return ira->codegen->invalid_instruction;8959 const_val->data.x_ptr.special = ConstPtrSpecialRef;
8967 }8960 const_val->data.x_ptr.mut = ptr_mut;
89688961 const_val->data.x_ptr.data.ref.pointee = pointee;
8969 IrInstruction *const_instr = ir_get_const(ira, instruction);8962 return const_instr;
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 }
8990}8963}
89918964
8992static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,8965static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
...@@ -9314,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -9314,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
9314 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);9287 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);
9315 if (!val)9288 if (!val)
9316 return ira->codegen->invalid_instruction;9289 return ira->codegen->invalid_instruction;
9317 bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true;
9318 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,9290 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,
9320 get_abi_alignment(ira->codegen, value->value.type));9292 get_abi_alignment(ira->codegen, value->value.type));
9321 }9293 }
93229294
...@@ -10245,21 +10217,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -10245,21 +10217,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
10245 source_instruction->source_node, ptr);10217 source_instruction->source_node, ptr);
10246 load_ptr_instruction->value.type = child_type;10218 load_ptr_instruction->value.type = child_type;
10247 return load_ptr_instruction;10219 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 }
10263 } else {10220 } else {
10264 ir_add_error_node(ira, source_instruction->source_node,10221 ir_add_error_node(ira, source_instruction->source_node,
10265 buf_sprintf("attempt to dereference non pointer type '%s'",10222 buf_sprintf("attempt to dereference non pointer type '%s'",
...@@ -11966,7 +11923,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i...@@ -11966,7 +11923,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
11966 {11923 {
11967 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;11924 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
11968 assert(coro_allocator_var != nullptr);11925 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);
11970 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);11927 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
11971 assert(result->value.type != nullptr);11928 assert(result->value.type != nullptr);
11972 return result;11929 return result;
...@@ -12147,7 +12104,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in...@@ -12147,7 +12104,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
12147}12104}
1214812105
12149static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,12106static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12150 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)12107 VariableTableEntry *var)
12151{12108{
12152 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {12109 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
12153 assert(ira->codegen->errors.length != 0);12110 assert(ira->codegen->errors.length != 0);
...@@ -12173,8 +12130,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -12173,8 +12130,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12173 }12130 }
12174 }12131 }
1217512132
12176 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;12133 bool is_const = var->src_is_const;
12177 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;12134 bool is_volatile = false;
12178 if (mem_slot != nullptr) {12135 if (mem_slot != nullptr) {
12179 switch (mem_slot->special) {12136 switch (mem_slot->special) {
12180 case ConstValSpecialRuntime:12137 case ConstValSpecialRuntime:
...@@ -12200,7 +12157,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -12200,7 +12157,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12200no_mem_slot:12157no_mem_slot:
1220112158
12202 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,12159 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);
12204 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,12161 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
12205 var->src_is_const, is_volatile, var->align_bytes, 0, 0);12162 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
12206 type_ensure_zero_bits_known(ira->codegen, var->value->type);12163 type_ensure_zero_bits_known(ira->codegen, var->value->type);
...@@ -12486,7 +12443,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -12486,7 +12443,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
12486 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));12443 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
12487 return ira->codegen->builtin_types.entry_invalid;12444 return ira->codegen->builtin_types.entry_invalid;
12488 }12445 }
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);
12490 if (type_is_invalid(arg_var_ptr_inst->value.type))12447 if (type_is_invalid(arg_var_ptr_inst->value.type))
12491 return ira->codegen->builtin_types.entry_invalid;12448 return ira->codegen->builtin_types.entry_invalid;
1249212449
...@@ -13120,17 +13077,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -13120,17 +13077,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
13120}13077}
1312113078
13122static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,13079static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13123 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)13080 VariableTableEntry *var)
13124{13081{
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);
13126 ir_link_new_instruction(result, instruction);13083 ir_link_new_instruction(result, instruction);
13127 return result->value.type;13084 return result->value.type;
13128}13085}
1312913086
13130static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {13087static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
13131 VariableTableEntry *var = var_ptr_instruction->var;13088 VariableTableEntry *var = var_ptr_instruction->var;
13132 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,13089 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
13133 var_ptr_instruction->is_volatile);
13134}13090}
1313513091
13136static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {13092static 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...@@ -13152,11 +13108,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
13152 return ira->codegen->builtin_types.entry_invalid;13108 return ira->codegen->builtin_types.entry_invalid;
1315313109
13154 TypeTableEntry *ptr_type = array_ptr->value.type;13110 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 }
13160 assert(ptr_type->id == TypeTableEntryIdPointer);13111 assert(ptr_type->id == TypeTableEntryIdPointer);
1316113112
13162 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;13113 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
...@@ -13218,8 +13169,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -13218,8 +13169,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
13218 bool is_const = true;13169 bool is_const = true;
13219 bool is_volatile = false;13170 bool is_volatile = false;
13220 if (var) {13171 if (var) {
13221 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,13172 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var);
13222 is_const, is_volatile);
13223 } else {13173 } else {
13224 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,13174 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,
13225 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile);13175 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...@@ -13603,7 +13553,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
13603 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);13553 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
13604 }13554 }
1360513555
13606 return ir_analyze_var_ptr(ira, source_instruction, var, false, false);13556 return ir_analyze_var_ptr(ira, source_instruction, var);
13607 }13557 }
13608 case TldIdFn:13558 case TldIdFn:
13609 {13559 {
...@@ -13652,14 +13602,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13652,14 +13602,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13652 if (type_is_invalid(container_ptr->value.type))13602 if (type_is_invalid(container_ptr->value.type))
13653 return ira->codegen->builtin_types.entry_invalid;13603 return ira->codegen->builtin_types.entry_invalid;
1365413604
13655 TypeTableEntry *container_type;13605 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
13656 if (container_ptr->value.type->id == TypeTableEntryIdPointer) {13606 assert(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 }
1366313607
13664 Buf *field_name = field_ptr_instruction->field_name_buffer;13608 Buf *field_name = field_ptr_instruction->field_name_buffer;
13665 if (!field_name) {13609 if (!field_name) {
...@@ -13732,17 +13676,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13732,17 +13676,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13732 if (!container_ptr_val)13676 if (!container_ptr_val)
13733 return ira->codegen->builtin_types.entry_invalid;13677 return ira->codegen->builtin_types.entry_invalid;
1373413678
13735 TypeTableEntry *child_type;13679 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
13736 if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {13680 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13737 TypeTableEntry *ptr_type = container_ptr_val->data.x_type;13681 TypeTableEntry *child_type = child_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 }
1374613682
13747 if (type_is_invalid(child_type)) {13683 if (type_is_invalid(child_type)) {
13748 return ira->codegen->builtin_types.entry_invalid;13684 return ira->codegen->builtin_types.entry_invalid;
...@@ -17337,8 +17273,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -17337,8 +17273,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
17337 if (array_type->data.array.len == 0 && byte_alignment == 0) {17273 if (array_type->data.array.len == 0 && byte_alignment == 0) {
17338 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);17274 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
17339 }17275 }
17276 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
17277 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
17340 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,17278 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,
17342 byte_alignment, 0, 0);17281 byte_alignment, 0, 0);
17343 return_type = get_slice_type(ira->codegen, slice_ptr_type);17282 return_type = get_slice_type(ira->codegen, slice_ptr_type);
17344 } else if (array_type->id == TypeTableEntryIdPointer) {17283 } else if (array_type->id == TypeTableEntryIdPointer) {
...@@ -17525,6 +17464,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -17525,6 +17464,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
17525 return ira->codegen->builtin_types.entry_invalid;17464 return ira->codegen->builtin_types.entry_invalid;
17526 TypeTableEntry *container_type = ir_resolve_type(ira, container);17465 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
17528 uint64_t result;17471 uint64_t result;
17529 if (type_is_invalid(container_type)) {17472 if (type_is_invalid(container_type)) {
17530 return ira->codegen->builtin_types.entry_invalid;17473 return ira->codegen->builtin_types.entry_invalid;
...@@ -17912,15 +17855,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -17912,15 +17855,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
17912 return ira->codegen->builtin_types.entry_invalid;17855 return ira->codegen->builtin_types.entry_invalid;
17913 TypeTableEntry *ptr_type = value->value.type;17856 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
17924 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.17858 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
17925 assert(ptr_type->id == TypeTableEntryIdPointer);17859 assert(ptr_type->id == TypeTableEntryIdPointer);
1792617860
...@@ -18697,8 +18631,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -18697,8 +18631,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
18697 TldVar *tld_var = (TldVar *)tld;18631 TldVar *tld_var = (TldVar *)tld;
18698 VariableTableEntry *var = tld_var->var;18632 VariableTableEntry *var = tld_var->var;
1869918633
18700 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var,18634 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
18701 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
18702 if (type_is_invalid(var_ptr->value.type))18635 if (type_is_invalid(var_ptr->value.type))
18703 return ira->codegen->builtin_types.entry_invalid;18636 return ira->codegen->builtin_types.entry_invalid;
1870418637
std/zig/parser_test.zig+2-2
...@@ -1298,8 +1298,8 @@ test "zig fmt: struct declaration" {...@@ -1298,8 +1298,8 @@ test "zig fmt: struct declaration" {
1298 \\ f1: u8,1298 \\ f1: u8,
1299 \\ pub f3: u8,1299 \\ pub f3: u8,
1300 \\1300 \\
1301 \\ fn method(self: &Self) Self {1301 \\ fn method(self: *Self) Self {
1302 \\ return *self;1302 \\ return self.*;
1303 \\ }1303 \\ }
1304 \\1304 \\
1305 \\ f2: u8,1305 \\ f2: u8,