| ... | @@ -219,7 +219,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source | ... | @@ -219,7 +219,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 219 | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, | 219 | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 220 | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on); | 220 | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on); |
| 221 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); | 221 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); |
| 222 | static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs); | 222 | static void copy_const_val(ZigValue *dest, ZigValue *src); |
| 223 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); | 223 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 224 | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, | 224 | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 225 | ZigType *ptr_type); | 225 | ZigType *ptr_type); |
| ... | @@ -1165,7 +1165,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no | ... | @@ -1165,7 +1165,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no |
| 1165 | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); | 1165 | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 1166 | special_instruction->base.owner_bb = irb->current_basic_block; | 1166 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1167 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); | 1167 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 1168 | special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); | | |
| 1169 | return special_instruction; | 1168 | return special_instruction; |
| 1170 | } | 1169 | } |
| 1171 | | 1170 | |
| ... | @@ -8735,7 +8734,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast | ... | @@ -8735,7 +8734,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast |
| 8735 | if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val))) | 8734 | if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val))) |
| 8736 | return err; | 8735 | return err; |
| 8737 | ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); | 8736 | ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); |
| 8738 | copy_const_val(child_val, &tmp, false); | 8737 | copy_const_val(child_val, &tmp); |
| 8739 | return ErrorNone; | 8738 | return ErrorNone; |
| 8740 | } | 8739 | } |
| 8741 | | 8740 | |
| ... | @@ -11018,18 +11017,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -11018,18 +11017,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11018 | } | 11017 | } |
| 11019 | } | 11018 | } |
| 11020 | | 11019 | |
| 11021 | static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) { | 11020 | static void copy_const_val(ZigValue *dest, ZigValue *src) { |
| 11022 | ConstGlobalRefs *global_refs = dest->global_refs; | | |
| 11023 | memcpy(dest, src, sizeof(ZigValue)); | 11021 | memcpy(dest, src, sizeof(ZigValue)); |
| 11024 | if (!same_global_refs) { | 11022 | if (src->special != ConstValSpecialStatic) |
| 11025 | dest->global_refs = global_refs; | 11023 | return; |
| 11026 | if (src->special != ConstValSpecialStatic) | 11024 | if (dest->type->id == ZigTypeIdStruct) { |
| 11027 | return; | 11025 | dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count); |
| 11028 | if (dest->type->id == ZigTypeIdStruct) { | 11026 | for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) { |
| 11029 | dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count); | 11027 | copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i]); |
| 11030 | for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) { | | |
| 11031 | copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false); | | |
| 11032 | } | | |
| 11033 | } | 11028 | } |
| 11034 | } | 11029 | } |
| 11035 | } | 11030 | } |
| ... | @@ -11048,13 +11043,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -11048,13 +11043,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 11048 | case CastOpErrSet: | 11043 | case CastOpErrSet: |
| 11049 | case CastOpBitCast: | 11044 | case CastOpBitCast: |
| 11050 | zig_panic("TODO"); | 11045 | zig_panic("TODO"); |
| 11051 | case CastOpNoop: | 11046 | case CastOpNoop: { |
| 11052 | { | 11047 | copy_const_val(const_val, other_val); |
| 11053 | bool same_global_refs = other_val->special == ConstValSpecialStatic; | 11048 | const_val->type = new_type; |
| 11054 | copy_const_val(const_val, other_val, same_global_refs); | 11049 | break; |
| 11055 | const_val->type = new_type; | 11050 | } |
| 11056 | break; | | |
| 11057 | } | | |
| 11058 | case CastOpNumLitToConcrete: | 11051 | case CastOpNumLitToConcrete: |
| 11059 | if (other_val->type->id == ZigTypeIdComptimeFloat) { | 11052 | if (other_val->type->id == ZigTypeIdComptimeFloat) { |
| 11060 | assert(new_type->id == ZigTypeIdFloat); | 11053 | assert(new_type->id == ZigTypeIdFloat); |
| ... | @@ -11775,7 +11768,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so | ... | @@ -11775,7 +11768,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11775 | source_instr->scope, source_instr->source_node); | 11768 | source_instr->scope, source_instr->source_node); |
| 11776 | const_instruction->base.value->special = ConstValSpecialStatic; | 11769 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11777 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { | 11770 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| 11778 | copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); | 11771 | copy_const_val(const_instruction->base.value, val); |
| 11779 | } else { | 11772 | } else { |
| 11780 | const_instruction->base.value->data.x_optional = val; | 11773 | const_instruction->base.value->data.x_optional = val; |
| 11781 | } | 11774 | } |
| ... | @@ -12779,7 +12772,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * | ... | @@ -12779,7 +12772,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 12779 | if (instr_is_comptime(array)) { | 12772 | if (instr_is_comptime(array)) { |
| 12780 | // arrays and vectors have the same ZigValue representation | 12773 | // arrays and vectors have the same ZigValue representation |
| 12781 | IrInstruction *result = ir_const(ira, source_instr, vector_type); | 12774 | IrInstruction *result = ir_const(ira, source_instr, vector_type); |
| 12782 | copy_const_val(result->value, array->value, false); | 12775 | copy_const_val(result->value, array->value); |
| 12783 | result->value->type = vector_type; | 12776 | result->value->type = vector_type; |
| 12784 | return result; | 12777 | return result; |
| 12785 | } | 12778 | } |
| ... | @@ -12792,7 +12785,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * | ... | @@ -12792,7 +12785,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12792 | if (instr_is_comptime(vector)) { | 12785 | if (instr_is_comptime(vector)) { |
| 12793 | // arrays and vectors have the same ZigValue representation | 12786 | // arrays and vectors have the same ZigValue representation |
| 12794 | IrInstruction *result = ir_const(ira, source_instr, array_type); | 12787 | IrInstruction *result = ir_const(ira, source_instr, array_type); |
| 12795 | copy_const_val(result->value, vector->value, false); | 12788 | copy_const_val(result->value, vector->value); |
| 12796 | result->value->type = array_type; | 12789 | result->value->type = array_type; |
| 12797 | return result; | 12790 | return result; |
| 12798 | } | 12791 | } |
| ... | @@ -13080,7 +13073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -13080,7 +13073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13080 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { | 13073 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 13081 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); | 13074 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13082 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { | 13075 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13083 | copy_const_val(result->value, value->value, false); | 13076 | copy_const_val(result->value, value->value); |
| 13084 | result->value->type = wanted_type; | 13077 | result->value->type = wanted_type; |
| 13085 | } else { | 13078 | } else { |
| 13086 | float_init_bigint(&result->value->data.x_bigint, value->value); | 13079 | float_init_bigint(&result->value->data.x_bigint, value->value); |
| ... | @@ -13963,7 +13956,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio | ... | @@ -13963,7 +13956,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 13963 | | 13956 | |
| 13964 | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { | 13957 | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 13965 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); | 13958 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 13966 | copy_const_val(result->value, instruction->base.value, true); | 13959 | copy_const_val(result->value, instruction->base.value); |
| 13967 | return result; | 13960 | return result; |
| 13968 | } | 13961 | } |
| 13969 | | 13962 | |
| ... | @@ -14502,7 +14495,7 @@ never_mind_just_calculate_it_normally: | ... | @@ -14502,7 +14495,7 @@ never_mind_just_calculate_it_normally: |
| 14502 | &op1_val->data.x_array.data.s_none.elements[i], | 14495 | &op1_val->data.x_array.data.s_none.elements[i], |
| 14503 | &op2_val->data.x_array.data.s_none.elements[i], | 14496 | &op2_val->data.x_array.data.s_none.elements[i], |
| 14504 | bin_op_instruction, op_id, one_possible_value); | 14497 | bin_op_instruction, op_id, one_possible_value); |
| 14505 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false); | 14498 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value); |
| 14506 | } | 14499 | } |
| 14507 | return result; | 14500 | return result; |
| 14508 | } | 14501 | } |
| ... | @@ -15368,21 +15361,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i | ... | @@ -15368,21 +15361,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15368 | size_t next_index = 0; | 15361 | size_t next_index = 0; |
| 15369 | for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) { | 15362 | for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) { |
| 15370 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; | 15363 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15371 | copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false); | 15364 | copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]); |
| 15372 | elem_dest_val->parent.id = ConstParentIdArray; | 15365 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15373 | elem_dest_val->parent.data.p_array.array_val = out_array_val; | 15366 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| 15374 | elem_dest_val->parent.data.p_array.elem_index = next_index; | 15367 | elem_dest_val->parent.data.p_array.elem_index = next_index; |
| 15375 | } | 15368 | } |
| 15376 | for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) { | 15369 | for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) { |
| 15377 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; | 15370 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15378 | copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false); | 15371 | copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]); |
| 15379 | elem_dest_val->parent.id = ConstParentIdArray; | 15372 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15380 | elem_dest_val->parent.data.p_array.array_val = out_array_val; | 15373 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| 15381 | elem_dest_val->parent.data.p_array.elem_index = next_index; | 15374 | elem_dest_val->parent.data.p_array.elem_index = next_index; |
| 15382 | } | 15375 | } |
| 15383 | if (next_index < full_len) { | 15376 | if (next_index < full_len) { |
| 15384 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; | 15377 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15385 | copy_const_val(elem_dest_val, sentinel, false); | 15378 | copy_const_val(elem_dest_val, sentinel); |
| 15386 | elem_dest_val->parent.id = ConstParentIdArray; | 15379 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15387 | elem_dest_val->parent.data.p_array.array_val = out_array_val; | 15380 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| 15388 | elem_dest_val->parent.data.p_array.elem_index = next_index; | 15381 | elem_dest_val->parent.data.p_array.elem_index = next_index; |
| ... | @@ -15467,7 +15460,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -15467,7 +15460,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15467 | for (uint64_t x = 0; x < mult_amt; x += 1) { | 15460 | for (uint64_t x = 0; x < mult_amt; x += 1) { |
| 15468 | for (uint64_t y = 0; y < old_array_len; y += 1) { | 15461 | for (uint64_t y = 0; y < old_array_len; y += 1) { |
| 15469 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; | 15462 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15470 | copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false); | 15463 | copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]); |
| 15471 | elem_dest_val->parent.id = ConstParentIdArray; | 15464 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15472 | elem_dest_val->parent.data.p_array.array_val = out_val; | 15465 | elem_dest_val->parent.data.p_array.array_val = out_val; |
| 15473 | elem_dest_val->parent.data.p_array.elem_index = i; | 15466 | elem_dest_val->parent.data.p_array.elem_index = i; |
| ... | @@ -15478,7 +15471,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -15478,7 +15471,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15478 | | 15471 | |
| 15479 | if (array_type->data.array.sentinel != nullptr) { | 15472 | if (array_type->data.array.sentinel != nullptr) { |
| 15480 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; | 15473 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15481 | copy_const_val(elem_dest_val, array_type->data.array.sentinel, false); | 15474 | copy_const_val(elem_dest_val, array_type->data.array.sentinel); |
| 15482 | elem_dest_val->parent.id = ConstParentIdArray; | 15475 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15483 | elem_dest_val->parent.data.p_array.array_val = out_val; | 15476 | elem_dest_val->parent.data.p_array.array_val = out_val; |
| 15484 | elem_dest_val->parent.data.p_array.elem_index = i; | 15477 | elem_dest_val->parent.data.p_array.elem_index = i; |
| ... | @@ -15628,7 +15621,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -15628,7 +15621,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15628 | var->const_value = init_val; | 15621 | var->const_value = init_val; |
| 15629 | } else { | 15622 | } else { |
| 15630 | var->const_value = create_const_vals(1); | 15623 | var->const_value = create_const_vals(1); |
| 15631 | copy_const_val(var->const_value, init_val, false); | 15624 | copy_const_val(var->const_value, init_val); |
| 15632 | } | 15625 | } |
| 15633 | } | 15626 | } |
| 15634 | } | 15627 | } |
| ... | @@ -15738,7 +15731,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -15738,7 +15731,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15738 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { | 15731 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { |
| 15739 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); | 15732 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); |
| 15740 | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); | 15733 | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); |
| 15741 | copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const); | 15734 | copy_const_val(mem_slot, init_val); |
| 15742 | | 15735 | |
| 15743 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { | 15736 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| 15744 | return ir_const_void(ira, &decl_var_instruction->base); | 15737 | return ir_const_void(ira, &decl_var_instruction->base); |
| ... | @@ -16217,8 +16210,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -16217,8 +16210,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16217 | } | 16210 | } |
| 16218 | IrInstruction *alloca_gen; | 16211 | IrInstruction *alloca_gen; |
| 16219 | if (is_comptime && value != nullptr) { | 16212 | if (is_comptime && value != nullptr) { |
| 16220 | if (align > value->value->global_refs->align) { | 16213 | if (align > value->value->llvm_align) { |
| 16221 | value->value->global_refs->align = align; | 16214 | value->value->llvm_align = align; |
| 16222 | } | 16215 | } |
| 16223 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); | 16216 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 16224 | } else { | 16217 | } else { |
| ... | @@ -16782,7 +16775,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -16782,7 +16775,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16782 | arg_val = create_const_runtime(casted_arg->value->type); | 16775 | arg_val = create_const_runtime(casted_arg->value->type); |
| 16783 | } | 16776 | } |
| 16784 | if (arg_part_of_generic_id) { | 16777 | if (arg_part_of_generic_id) { |
| 16785 | copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true); | 16778 | copy_const_val(&generic_id->params[generic_id->param_count], arg_val); |
| 16786 | generic_id->param_count += 1; | 16779 | generic_id->param_count += 1; |
| 16787 | } | 16780 | } |
| 16788 | | 16781 | |
| ... | @@ -16963,7 +16956,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -16963,7 +16956,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16963 | IrInstruction *casted_ptr; | 16956 | IrInstruction *casted_ptr; |
| 16964 | if (instr_is_comptime(ptr)) { | 16957 | if (instr_is_comptime(ptr)) { |
| 16965 | casted_ptr = ir_const(ira, source_instr, struct_ptr_type); | 16958 | casted_ptr = ir_const(ira, source_instr, struct_ptr_type); |
| 16966 | copy_const_val(casted_ptr->value, ptr->value, false); | 16959 | copy_const_val(casted_ptr->value, ptr->value); |
| 16967 | casted_ptr->value->type = struct_ptr_type; | 16960 | casted_ptr->value->type = struct_ptr_type; |
| 16968 | } else { | 16961 | } else { |
| 16969 | casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope, | 16962 | casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope, |
| ... | @@ -17026,14 +17019,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -17026,14 +17019,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17026 | if (dest_val == nullptr) | 17019 | if (dest_val == nullptr) |
| 17027 | return ira->codegen->invalid_instruction; | 17020 | return ira->codegen->invalid_instruction; |
| 17028 | if (dest_val->special != ConstValSpecialRuntime) { | 17021 | if (dest_val->special != ConstValSpecialRuntime) { |
| 17029 | // TODO this allows a value stored to have the original value modified and then | 17022 | copy_const_val(dest_val, value->value); |
| 17030 | // have that affect what should be a copy. We need some kind of advanced copy-on-write | | |
| 17031 | // system to make these two tests pass at the same time: | | |
| 17032 | // * "string literal used as comptime slice is memoized" | | |
| 17033 | // * "comptime modification of const struct field" - except modified to avoid | | |
| 17034 | // ConstPtrMutComptimeVar, thus defeating the logic below. | | |
| 17035 | bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar; | | |
| 17036 | copy_const_val(dest_val, value->value, same_global_refs); | | |
| 17037 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && | 17023 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 17038 | !ira->new_irb.current_basic_block->must_be_comptime_source_instr) | 17024 | !ira->new_irb.current_basic_block->must_be_comptime_source_instr) |
| 17039 | { | 17025 | { |
| ... | @@ -17308,7 +17294,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -17308,7 +17294,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17308 | } | 17294 | } |
| 17309 | | 17295 | |
| 17310 | IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type); | 17296 | IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type); |
| 17311 | copy_const_val(new_instruction->value, result, true); | 17297 | copy_const_val(new_instruction->value, result); |
| 17312 | new_instruction->value->type = return_type; | 17298 | new_instruction->value->type = return_type; |
| 17313 | return ir_finish_anal(ira, new_instruction); | 17299 | return ir_finish_anal(ira, new_instruction); |
| 17314 | } | 17300 | } |
| ... | @@ -17465,7 +17451,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -17465,7 +17451,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17465 | nullptr, UndefBad); | 17451 | nullptr, UndefBad); |
| 17466 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, | 17452 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 17467 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); | 17453 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 17468 | copy_const_val(const_instruction->base.value, align_result, true); | 17454 | copy_const_val(const_instruction->base.value, align_result); |
| 17469 | | 17455 | |
| 17470 | uint32_t align_bytes = 0; | 17456 | uint32_t align_bytes = 0; |
| 17471 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); | 17457 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | @@ -17795,7 +17781,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source | ... | @@ -17795,7 +17781,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 17795 | | 17781 | |
| 17796 | if (dst_size <= src_size) { | 17782 | if (dst_size <= src_size) { |
| 17797 | if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) { | 17783 | if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) { |
| 17798 | copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar); | 17784 | copy_const_val(out_val, pointee); |
| 17799 | return ErrorNone; | 17785 | return ErrorNone; |
| 17800 | } | 17786 | } |
| 17801 | Buf buf = BUF_INIT; | 17787 | Buf buf = BUF_INIT; |
| ... | @@ -18158,7 +18144,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh | ... | @@ -18158,7 +18144,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18158 | | 18144 | |
| 18159 | if (value->value->special != ConstValSpecialRuntime) { | 18145 | if (value->value->special != ConstValSpecialRuntime) { |
| 18160 | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); | 18146 | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 18161 | copy_const_val(result->value, value->value, true); | 18147 | copy_const_val(result->value, value->value); |
| 18162 | return result; | 18148 | return result; |
| 18163 | } else { | 18149 | } else { |
| 18164 | return value; | 18150 | return value; |
| ... | @@ -18551,7 +18537,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -18551,7 +18537,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18551 | if (index == array_len && array_type->data.array.sentinel != nullptr) { | 18537 | if (index == array_len && array_type->data.array.sentinel != nullptr) { |
| 18552 | ZigType *elem_type = array_type->data.array.child_type; | 18538 | ZigType *elem_type = array_type->data.array.child_type; |
| 18553 | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); | 18539 | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); |
| 18554 | copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false); | 18540 | copy_const_val(sentinel_elem->value, array_type->data.array.sentinel); |
| 18555 | return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); | 18541 | return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); |
| 18556 | } | 18542 | } |
| 18557 | if (index >= array_len) { | 18543 | if (index >= array_len) { |
| ... | @@ -19042,7 +19028,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n | ... | @@ -19042,7 +19028,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 19042 | | 19028 | |
| 19043 | if (instr_is_comptime(container_ptr)) { | 19029 | if (instr_is_comptime(container_ptr)) { |
| 19044 | IrInstruction *result = ir_const(ira, source_instr, field_ptr_type); | 19030 | IrInstruction *result = ir_const(ira, source_instr, field_ptr_type); |
| 19045 | copy_const_val(result->value, container_ptr->value, false); | 19031 | copy_const_val(result->value, container_ptr->value); |
| 19046 | result->value->type = field_ptr_type; | 19032 | result->value->type = field_ptr_type; |
| 19047 | return result; | 19033 | return result; |
| 19048 | } | 19034 | } |
| ... | @@ -20474,7 +20460,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -20474,7 +20460,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20474 | case ZigTypeIdErrorSet: { | 20460 | case ZigTypeIdErrorSet: { |
| 20475 | if (pointee_val) { | 20461 | if (pointee_val) { |
| 20476 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); | 20462 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 20477 | copy_const_val(result->value, pointee_val, true); | 20463 | copy_const_val(result->value, pointee_val); |
| 20478 | result->value->type = target_type; | 20464 | result->value->type = target_type; |
| 20479 | return result; | 20465 | return result; |
| 20480 | } | 20466 | } |
| ... | @@ -20970,7 +20956,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -20970,7 +20956,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20970 | return ira->codegen->invalid_instruction; | 20956 | return ira->codegen->invalid_instruction; |
| 20971 | | 20957 | |
| 20972 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); | 20958 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 20973 | copy_const_val(runtime_inst->value, field->init_val, true); | 20959 | copy_const_val(runtime_inst->value, field->init_val); |
| 20974 | | 20960 | |
| 20975 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, | 20961 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 20976 | container_type, true); | 20962 | container_type, true); |
| ... | @@ -21228,7 +21214,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct | ... | @@ -21228,7 +21214,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 21228 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); | 21214 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 21229 | } | 21215 | } |
| 21230 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); | 21216 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 21231 | copy_const_val(result->value, err->cached_error_name_val, true); | 21217 | copy_const_val(result->value, err->cached_error_name_val); |
| 21232 | result->value->type = str_type; | 21218 | result->value->type = str_type; |
| 21233 | return result; | 21219 | return result; |
| 21234 | } | 21220 | } |
| ... | @@ -22665,7 +22651,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc | ... | @@ -22665,7 +22651,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc |
| 22665 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); | 22651 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 22666 | } | 22652 | } |
| 22667 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); | 22653 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 22668 | copy_const_val(result->value, type_entry->cached_const_name_val, true); | 22654 | copy_const_val(result->value, type_entry->cached_const_name_val); |
| 22669 | return result; | 22655 | return result; |
| 22670 | } | 22656 | } |
| 22671 | | 22657 | |
| ... | @@ -23365,7 +23351,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -23365,7 +23351,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23365 | | 23351 | |
| 23366 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; | 23352 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; |
| 23367 | ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; | 23353 | ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; |
| 23368 | copy_const_val(ptr_val, target_ptr_val, false); | 23354 | copy_const_val(ptr_val, target_ptr_val); |
| 23369 | ptr_val->type = dest_ptr_type; | 23355 | ptr_val->type = dest_ptr_type; |
| 23370 | | 23356 | |
| 23371 | ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index]; | 23357 | ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index]; |
| ... | @@ -23658,7 +23644,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s | ... | @@ -23658,7 +23644,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23658 | ZigValue *src_elem_val = (v >= 0) ? | 23644 | ZigValue *src_elem_val = (v >= 0) ? |
| 23659 | &a->value->data.x_array.data.s_none.elements[v] : | 23645 | &a->value->data.x_array.data.s_none.elements[v] : |
| 23660 | &b->value->data.x_array.data.s_none.elements[~v]; | 23646 | &b->value->data.x_array.data.s_none.elements[~v]; |
| 23661 | copy_const_val(result_elem_val, src_elem_val, false); | 23647 | copy_const_val(result_elem_val, src_elem_val); |
| 23662 | | 23648 | |
| 23663 | ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); | 23649 | ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); |
| 23664 | } | 23650 | } |
| ... | @@ -23753,7 +23739,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction | ... | @@ -23753,7 +23739,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23753 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); | 23739 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 23754 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); | 23740 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 23755 | for (uint32_t i = 0; i < len_int; i += 1) { | 23741 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 23756 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false); | 23742 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val); |
| 23757 | } | 23743 | } |
| 23758 | return result; | 23744 | return result; |
| 23759 | } | 23745 | } |
| ... | @@ -23894,7 +23880,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio | ... | @@ -23894,7 +23880,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23894 | } | 23880 | } |
| 23895 | | 23881 | |
| 23896 | for (size_t i = start; i < end; i += 1) { | 23882 | for (size_t i = start; i < end; i += 1) { |
| 23897 | copy_const_val(&dest_elements[i], byte_val, true); | 23883 | copy_const_val(&dest_elements[i], byte_val); |
| 23898 | } | 23884 | } |
| 23899 | | 23885 | |
| 23900 | return ir_const_void(ira, &instruction->base); | 23886 | return ir_const_void(ira, &instruction->base); |
| ... | @@ -24073,7 +24059,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio | ... | @@ -24073,7 +24059,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 24073 | // TODO check for noalias violations - this should be generalized to work for any function | 24059 | // TODO check for noalias violations - this should be generalized to work for any function |
| 24074 | | 24060 | |
| 24075 | for (size_t i = 0; i < count; i += 1) { | 24061 | for (size_t i = 0; i < count; i += 1) { |
| 24076 | copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i], true); | 24062 | copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]); |
| 24077 | } | 24063 | } |
| 24078 | | 24064 | |
| 24079 | return ir_const_void(ira, &instruction->base); | 24065 | return ir_const_void(ira, &instruction->base); |
| ... | @@ -25515,7 +25501,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 | ... | @@ -25515,7 +25501,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25515 | } | 25501 | } |
| 25516 | | 25502 | |
| 25517 | IrInstruction *result = ir_const(ira, target, result_type); | 25503 | IrInstruction *result = ir_const(ira, target, result_type); |
| 25518 | copy_const_val(result->value, val, true); | 25504 | copy_const_val(result->value, val); |
| 25519 | result->value->type = result_type; | 25505 | result->value->type = result_type; |
| 25520 | return result; | 25506 | return result; |
| 25521 | } | 25507 | } |
| ... | @@ -25597,7 +25583,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -25597,7 +25583,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25597 | } else { | 25583 | } else { |
| 25598 | result = ir_const(ira, source_instr, dest_type); | 25584 | result = ir_const(ira, source_instr, dest_type); |
| 25599 | } | 25585 | } |
| 25600 | copy_const_val(result->value, val, true); | 25586 | copy_const_val(result->value, val); |
| 25601 | result->value->type = dest_type; | 25587 | result->value->type = dest_type; |
| 25602 | | 25588 | |
| 25603 | // Keep the bigger alignment, it can only help- | 25589 | // Keep the bigger alignment, it can only help- |