| ... | @@ -2568,7 +2568,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2568,7 +2568,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2568 | }); | 2568 | }); |
| 2569 | try sema.maybeQueueFuncBodyAnalysis(decl_index); | 2569 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| 2570 | try sema.comptime_mutable_decls.append(decl_index); | 2570 | try sema.comptime_mutable_decls.append(decl_index); |
| 2571 | return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{ | 2571 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 2572 | .ty = ptr_ty.toIntern(), | 2572 | .ty = ptr_ty.toIntern(), |
| 2573 | .addr = .{ .mut_decl = .{ | 2573 | .addr = .{ .mut_decl = .{ |
| 2574 | .decl = decl_index, | 2574 | .decl = decl_index, |
| ... | @@ -2642,11 +2642,10 @@ fn coerceResultPtr( | ... | @@ -2642,11 +2642,10 @@ fn coerceResultPtr( |
| 2642 | | 2642 | |
| 2643 | if (trash_block.instructions.items.len == prev_trash_len) { | 2643 | if (trash_block.instructions.items.len == prev_trash_len) { |
| 2644 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { | 2644 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { |
| 2645 | return sema.addConstant(ptr_ty, ptr_val); | 2645 | return sema.addConstant(ptr_val); |
| 2646 | } | 2646 | } |
| 2647 | if (pointee_ty.eql(Type.null, sema.mod)) { | 2647 | if (pointee_ty.eql(Type.null, sema.mod)) { |
| 2648 | const opt_ty = sema.typeOf(new_ptr).childType(mod); | 2648 | const null_inst = try sema.addConstant(Value.null); |
| 2649 | const null_inst = try sema.addConstant(opt_ty, Value.null); | | |
| 2650 | _ = try block.addBinOp(.store, new_ptr, null_inst); | 2649 | _ = try block.addBinOp(.store, new_ptr, null_inst); |
| 2651 | return Air.Inst.Ref.void_value; | 2650 | return Air.Inst.Ref.void_value; |
| 2652 | } | 2651 | } |
| ... | @@ -2665,7 +2664,7 @@ fn coerceResultPtr( | ... | @@ -2665,7 +2664,7 @@ fn coerceResultPtr( |
| 2665 | }); | 2664 | }); |
| 2666 | | 2665 | |
| 2667 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { | 2666 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { |
| 2668 | return sema.addConstant(ptr_operand_ty, ptr_val); | 2667 | return sema.addConstant(ptr_val); |
| 2669 | } else { | 2668 | } else { |
| 2670 | return sema.bitCast(block, ptr_operand_ty, new_ptr, src, null); | 2669 | return sema.bitCast(block, ptr_operand_ty, new_ptr, src, null); |
| 2671 | } | 2670 | } |
| ... | @@ -2678,7 +2677,7 @@ fn coerceResultPtr( | ... | @@ -2678,7 +2677,7 @@ fn coerceResultPtr( |
| 2678 | .flags = .{ .address_space = addr_space }, | 2677 | .flags = .{ .address_space = addr_space }, |
| 2679 | }); | 2678 | }); |
| 2680 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { | 2679 | if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| { |
| 2681 | new_ptr = try sema.addConstant(ptr_operand_ty, try mod.getCoerced(ptr_val, ptr_operand_ty)); | 2680 | new_ptr = try sema.addConstant(try mod.getCoerced(ptr_val, ptr_operand_ty)); |
| 2682 | } else { | 2681 | } else { |
| 2683 | new_ptr = try sema.bitCast(block, ptr_operand_ty, new_ptr, src, null); | 2682 | new_ptr = try sema.bitCast(block, ptr_operand_ty, new_ptr, src, null); |
| 2684 | } | 2683 | } |
| ... | @@ -3690,7 +3689,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai | ... | @@ -3690,7 +3689,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai |
| 3690 | | 3689 | |
| 3691 | // Detect if a comptime value simply needs to have its type changed. | 3690 | // Detect if a comptime value simply needs to have its type changed. |
| 3692 | if (try sema.resolveMaybeUndefVal(alloc)) |val| { | 3691 | if (try sema.resolveMaybeUndefVal(alloc)) |val| { |
| 3693 | return sema.addConstant(const_ptr_ty, try mod.getCoerced(val, const_ptr_ty)); | 3692 | return sema.addConstant(try mod.getCoerced(val, const_ptr_ty)); |
| 3694 | } | 3693 | } |
| 3695 | | 3694 | |
| 3696 | return block.addBitCast(const_ptr_ty, alloc); | 3695 | return block.addBitCast(const_ptr_ty, alloc); |
| ... | @@ -4436,14 +4435,14 @@ fn validateUnionInit( | ... | @@ -4436,14 +4435,14 @@ fn validateUnionInit( |
| 4436 | .ty = union_ty.toIntern(), | 4435 | .ty = union_ty.toIntern(), |
| 4437 | .val = union_val, | 4436 | .val = union_val, |
| 4438 | } }); | 4437 | } }); |
| 4439 | const union_init = try sema.addConstant(union_ty, union_val.toValue()); | 4438 | const union_init = try sema.addConstant(union_val.toValue()); |
| 4440 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4439 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4441 | return; | 4440 | return; |
| 4442 | } else if (try sema.typeRequiresComptime(union_ty)) { | 4441 | } else if (try sema.typeRequiresComptime(union_ty)) { |
| 4443 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known"); | 4442 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known"); |
| 4444 | } | 4443 | } |
| 4445 | | 4444 | |
| 4446 | const new_tag = try sema.addConstant(tag_ty, tag_val); | 4445 | const new_tag = try sema.addConstant(tag_val); |
| 4447 | _ = try block.addBinOp(.set_union_tag, union_ptr, new_tag); | 4446 | _ = try block.addBinOp(.set_union_tag, union_ptr, new_tag); |
| 4448 | } | 4447 | } |
| 4449 | | 4448 | |
| ... | @@ -4534,8 +4533,7 @@ fn validateStructInit( | ... | @@ -4534,8 +4533,7 @@ fn validateStructInit( |
| 4534 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true) | 4533 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true) |
| 4535 | else | 4534 | else |
| 4536 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true); | 4535 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true); |
| 4537 | const field_ty = sema.typeOf(default_field_ptr).childType(mod); | 4536 | const init = try sema.addConstant(default_val); |
| 4538 | const init = try sema.addConstant(field_ty, default_val); | | |
| 4539 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); | 4537 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); |
| 4540 | } | 4538 | } |
| 4541 | | 4539 | |
| ... | @@ -4702,7 +4700,7 @@ fn validateStructInit( | ... | @@ -4702,7 +4700,7 @@ fn validateStructInit( |
| 4702 | .ty = struct_ty.toIntern(), | 4700 | .ty = struct_ty.toIntern(), |
| 4703 | .val = struct_val, | 4701 | .val = struct_val, |
| 4704 | } }); | 4702 | } }); |
| 4705 | const struct_init = try sema.addConstant(struct_ty, struct_val.toValue()); | 4703 | const struct_init = try sema.addConstant(struct_val.toValue()); |
| 4706 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); | 4704 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); |
| 4707 | return; | 4705 | return; |
| 4708 | } | 4706 | } |
| ... | @@ -4717,8 +4715,7 @@ fn validateStructInit( | ... | @@ -4717,8 +4715,7 @@ fn validateStructInit( |
| 4717 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true) | 4715 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true) |
| 4718 | else | 4716 | else |
| 4719 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true); | 4717 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true); |
| 4720 | const field_ty = sema.typeOf(default_field_ptr).childType(mod); | 4718 | const init = try sema.addConstant(field_values[i].toValue()); |
| 4721 | const init = try sema.addConstant(field_ty, field_values[i].toValue()); | | |
| 4722 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); | 4719 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); |
| 4723 | } | 4720 | } |
| 4724 | } | 4721 | } |
| ... | @@ -4785,7 +4782,7 @@ fn zirValidateArrayInit( | ... | @@ -4785,7 +4782,7 @@ fn zirValidateArrayInit( |
| 4785 | if (array_ty.sentinel(mod)) |sentinel_val| { | 4782 | if (array_ty.sentinel(mod)) |sentinel_val| { |
| 4786 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); | 4783 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); |
| 4787 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true); | 4784 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true); |
| 4788 | const sentinel = try sema.addConstant(array_ty.childType(mod), sentinel_val); | 4785 | const sentinel = try sema.addConstant(sentinel_val); |
| 4789 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); | 4786 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); |
| 4790 | } | 4787 | } |
| 4791 | return; | 4788 | return; |
| ... | @@ -4793,7 +4790,7 @@ fn zirValidateArrayInit( | ... | @@ -4793,7 +4790,7 @@ fn zirValidateArrayInit( |
| 4793 | | 4790 | |
| 4794 | // If the array has one possible value, the value is always comptime-known. | 4791 | // If the array has one possible value, the value is always comptime-known. |
| 4795 | if (try sema.typeHasOnePossibleValue(array_ty)) |array_opv| { | 4792 | if (try sema.typeHasOnePossibleValue(array_ty)) |array_opv| { |
| 4796 | const array_init = try sema.addConstant(array_ty, array_opv); | 4793 | const array_init = try sema.addConstant(array_opv); |
| 4797 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); | 4794 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); |
| 4798 | return; | 4795 | return; |
| 4799 | } | 4796 | } |
| ... | @@ -4910,7 +4907,7 @@ fn zirValidateArrayInit( | ... | @@ -4910,7 +4907,7 @@ fn zirValidateArrayInit( |
| 4910 | .ty = array_ty.toIntern(), | 4907 | .ty = array_ty.toIntern(), |
| 4911 | .val = array_val, | 4908 | .val = array_val, |
| 4912 | } }); | 4909 | } }); |
| 4913 | const array_init = try sema.addConstant(array_ty, array_val.toValue()); | 4910 | const array_init = try sema.addConstant(array_val.toValue()); |
| 4914 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); | 4911 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); |
| 4915 | } | 4912 | } |
| 4916 | } | 4913 | } |
| ... | @@ -5266,7 +5263,6 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -5266,7 +5263,6 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 5266 | @memcpy(mem.sliceAsBytes(limbs), limb_bytes); | 5263 | @memcpy(mem.sliceAsBytes(limbs), limb_bytes); |
| 5267 | | 5264 | |
| 5268 | return sema.addConstant( | 5265 | return sema.addConstant( |
| 5269 | Type.comptime_int, | | |
| 5270 | try mod.intValue_big(Type.comptime_int, .{ | 5266 | try mod.intValue_big(Type.comptime_int, .{ |
| 5271 | .limbs = limbs, | 5267 | .limbs = limbs, |
| 5272 | .positive = true, | 5268 | .positive = true, |
| ... | @@ -5278,7 +5274,6 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -5278,7 +5274,6 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 5278 | _ = block; | 5274 | _ = block; |
| 5279 | const number = sema.code.instructions.items(.data)[inst].float; | 5275 | const number = sema.code.instructions.items(.data)[inst].float; |
| 5280 | return sema.addConstant( | 5276 | return sema.addConstant( |
| 5281 | Type.comptime_float, | | |
| 5282 | try sema.mod.floatValue(Type.comptime_float, number), | 5277 | try sema.mod.floatValue(Type.comptime_float, number), |
| 5283 | ); | 5278 | ); |
| 5284 | } | 5279 | } |
| ... | @@ -5289,7 +5284,6 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -5289,7 +5284,6 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 5289 | const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; | 5284 | const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 5290 | const number = extra.get(); | 5285 | const number = extra.get(); |
| 5291 | return sema.addConstant( | 5286 | return sema.addConstant( |
| 5292 | Type.comptime_float, | | |
| 5293 | try sema.mod.floatValue(Type.comptime_float, number), | 5287 | try sema.mod.floatValue(Type.comptime_float, number), |
| 5294 | ); | 5288 | ); |
| 5295 | } | 5289 | } |
| ... | @@ -5553,7 +5547,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5553,7 +5547,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5553 | const file_root_decl_index = result.file.root_decl.unwrap().?; | 5547 | const file_root_decl_index = result.file.root_decl.unwrap().?; |
| 5554 | const file_root_decl = mod.declPtr(file_root_decl_index); | 5548 | const file_root_decl = mod.declPtr(file_root_decl_index); |
| 5555 | try mod.declareDeclDependency(sema.owner_decl_index, file_root_decl_index); | 5549 | try mod.declareDeclDependency(sema.owner_decl_index, file_root_decl_index); |
| 5556 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); | 5550 | return sema.addConstant(file_root_decl.val); |
| 5557 | } | 5551 | } |
| 5558 | | 5552 | |
| 5559 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 5553 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -6981,7 +6975,6 @@ fn analyzeCall( | ... | @@ -6981,7 +6975,6 @@ fn analyzeCall( |
| 6981 | } })) |memoized_call_index| { | 6975 | } })) |memoized_call_index| { |
| 6982 | const memoized_call = mod.intern_pool.indexToKey(memoized_call_index).memoized_call; | 6976 | const memoized_call = mod.intern_pool.indexToKey(memoized_call_index).memoized_call; |
| 6983 | break :res2 try sema.addConstant( | 6977 | break :res2 try sema.addConstant( |
| 6984 | mod.intern_pool.typeOf(memoized_call.result).toType(), | | |
| 6985 | memoized_call.result.toValue(), | 6978 | memoized_call.result.toValue(), |
| 6986 | ); | 6979 | ); |
| 6987 | } | 6980 | } |
| ... | @@ -7746,7 +7739,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7746,7 +7739,7 @@ fn resolveGenericInstantiationType( |
| 7746 | const arg = uncasted_args[arg_i]; | 7739 | const arg = uncasted_args[arg_i]; |
| 7747 | if (is_comptime) { | 7740 | if (is_comptime) { |
| 7748 | const arg_val = (try sema.resolveMaybeUndefVal(arg)).?; | 7741 | const arg_val = (try sema.resolveMaybeUndefVal(arg)).?; |
| 7749 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); | 7742 | const child_arg = try child_sema.addConstant(arg_val); |
| 7750 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); | 7743 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 7751 | } else if (is_anytype) { | 7744 | } else if (is_anytype) { |
| 7752 | const arg_ty = sema.typeOf(arg); | 7745 | const arg_ty = sema.typeOf(arg); |
| ... | @@ -7760,7 +7753,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7760,7 +7753,7 @@ fn resolveGenericInstantiationType( |
| 7760 | }, | 7753 | }, |
| 7761 | else => |e| return e, | 7754 | else => |e| return e, |
| 7762 | }; | 7755 | }; |
| 7763 | const child_arg = try child_sema.addConstant(arg_ty, arg_val); | 7756 | const child_arg = try child_sema.addConstant(arg_val); |
| 7764 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); | 7757 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 7765 | } else { | 7758 | } else { |
| 7766 | // We insert into the map an instruction which is runtime-known | 7759 | // We insert into the map an instruction which is runtime-known |
| ... | @@ -8087,7 +8080,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8087,7 +8080,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8087 | _ = try mod.getErrorValue(name); | 8080 | _ = try mod.getErrorValue(name); |
| 8088 | // Create an error set type with only this error value, and return the value. | 8081 | // Create an error set type with only this error value, and return the value. |
| 8089 | const error_set_type = try mod.singleErrorSetType(name); | 8082 | const error_set_type = try mod.singleErrorSetType(name); |
| 8090 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 8083 | return sema.addConstant((try mod.intern(.{ .err = .{ |
| 8091 | .ty = error_set_type.toIntern(), | 8084 | .ty = error_set_type.toIntern(), |
| 8092 | .name = name, | 8085 | .name = name, |
| 8093 | } })).toValue()); | 8086 | } })).toValue()); |
| ... | @@ -8109,7 +8102,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8109,7 +8102,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8109 | return sema.addConstUndef(Type.err_int); | 8102 | return sema.addConstUndef(Type.err_int); |
| 8110 | } | 8103 | } |
| 8111 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; | 8104 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 8112 | return sema.addConstant(Type.err_int, try mod.intValue( | 8105 | return sema.addConstant(try mod.intValue( |
| 8113 | Type.err_int, | 8106 | Type.err_int, |
| 8114 | try mod.getErrorValue(err_name), | 8107 | try mod.getErrorValue(err_name), |
| 8115 | )); | 8108 | )); |
| ... | @@ -8120,7 +8113,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8120,7 +8113,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8120 | if (!op_ty.isAnyError(mod)) { | 8113 | if (!op_ty.isAnyError(mod)) { |
| 8121 | const names = op_ty.errorSetNames(mod); | 8114 | const names = op_ty.errorSetNames(mod); |
| 8122 | switch (names.len) { | 8115 | switch (names.len) { |
| 8123 | 0 => return sema.addConstant(Type.err_int, try mod.intValue(Type.err_int, 0)), | 8116 | 0 => return sema.addConstant(try mod.intValue(Type.err_int, 0)), |
| 8124 | 1 => { | 8117 | 1 => { |
| 8125 | const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(names[0]).?); | 8118 | const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(names[0]).?); |
| 8126 | return sema.addIntUnsigned(Type.err_int, int); | 8119 | return sema.addIntUnsigned(Type.err_int, int); |
| ... | @@ -8148,7 +8141,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8148,7 +8141,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8148 | const int = try sema.usizeCast(block, operand_src, value.toUnsignedInt(mod)); | 8141 | const int = try sema.usizeCast(block, operand_src, value.toUnsignedInt(mod)); |
| 8149 | if (int > mod.global_error_set.count() or int == 0) | 8142 | if (int > mod.global_error_set.count() or int == 0) |
| 8150 | return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int}); | 8143 | return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int}); |
| 8151 | return sema.addConstant(Type.anyerror, (try mod.intern(.{ .err = .{ | 8144 | return sema.addConstant((try mod.intern(.{ .err = .{ |
| 8152 | .ty = .anyerror_type, | 8145 | .ty = .anyerror_type, |
| 8153 | .name = mod.global_error_set.keys()[int], | 8146 | .name = mod.global_error_set.keys()[int], |
| 8154 | } })).toValue()); | 8147 | } })).toValue()); |
| ... | @@ -8156,7 +8149,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8156,7 +8149,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8156 | try sema.requireRuntimeBlock(block, src, operand_src); | 8149 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 8157 | if (block.wantSafety()) { | 8150 | if (block.wantSafety()) { |
| 8158 | const is_lt_len = try block.addUnOp(.cmp_lt_errors_len, operand); | 8151 | const is_lt_len = try block.addUnOp(.cmp_lt_errors_len, operand); |
| 8159 | const zero_val = try sema.addConstant(Type.err_int, try mod.intValue(Type.err_int, 0)); | 8152 | const zero_val = try sema.addConstant(try mod.intValue(Type.err_int, 0)); |
| 8160 | const is_non_zero = try block.addBinOp(.cmp_neq, operand, zero_val); | 8153 | const is_non_zero = try block.addBinOp(.cmp_neq, operand, zero_val); |
| 8161 | const ok = try block.addBinOp(.bit_and, is_lt_len, is_non_zero); | 8154 | const ok = try block.addBinOp(.bit_and, is_lt_len, is_non_zero); |
| 8162 | try sema.addSafetyCheck(block, ok, .invalid_error_code); | 8155 | try sema.addSafetyCheck(block, ok, .invalid_error_code); |
| ... | @@ -8230,7 +8223,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8230,7 +8223,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8230 | const mod = sema.mod; | 8223 | const mod = sema.mod; |
| 8231 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 8224 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 8232 | const name = inst_data.get(sema.code); | 8225 | const name = inst_data.get(sema.code); |
| 8233 | return sema.addConstant(.{ .ip_index = .enum_literal_type }, (try mod.intern(.{ | 8226 | return sema.addConstant((try mod.intern(.{ |
| 8234 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name), | 8227 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name), |
| 8235 | })).toValue()); | 8228 | })).toValue()); |
| 8236 | } | 8229 | } |
| ... | @@ -8268,12 +8261,12 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8268,12 +8261,12 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8268 | const int_tag_ty = enum_tag_ty.intTagType(mod); | 8261 | const int_tag_ty = enum_tag_ty.intTagType(mod); |
| 8269 | | 8262 | |
| 8270 | if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| { | 8263 | if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| { |
| 8271 | return sema.addConstant(int_tag_ty, try mod.getCoerced(opv, int_tag_ty)); | 8264 | return sema.addConstant(try mod.getCoerced(opv, int_tag_ty)); |
| 8272 | } | 8265 | } |
| 8273 | | 8266 | |
| 8274 | if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| { | 8267 | if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| { |
| 8275 | const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod); | 8268 | const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod); |
| 8276 | return sema.addConstant(int_tag_ty, val); | 8269 | return sema.addConstant(val); |
| 8277 | } | 8270 | } |
| 8278 | | 8271 | |
| 8279 | try sema.requireRuntimeBlock(block, src, operand_src); | 8272 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -8299,7 +8292,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8299,7 +8292,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8299 | if (dest_ty.isNonexhaustiveEnum(mod)) { | 8292 | if (dest_ty.isNonexhaustiveEnum(mod)) { |
| 8300 | const int_tag_ty = dest_ty.intTagType(mod); | 8293 | const int_tag_ty = dest_ty.intTagType(mod); |
| 8301 | if (try sema.intFitsInType(int_val, int_tag_ty, null)) { | 8294 | if (try sema.intFitsInType(int_val, int_tag_ty, null)) { |
| 8302 | return sema.addConstant(dest_ty, try mod.getCoerced(int_val, dest_ty)); | 8295 | return sema.addConstant(try mod.getCoerced(int_val, dest_ty)); |
| 8303 | } | 8296 | } |
| 8304 | const msg = msg: { | 8297 | const msg = msg: { |
| 8305 | const msg = try sema.errMsg( | 8298 | const msg = try sema.errMsg( |
| ... | @@ -8331,11 +8324,11 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8331,11 +8324,11 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8331 | }; | 8324 | }; |
| 8332 | return sema.failWithOwnedErrorMsg(msg); | 8325 | return sema.failWithOwnedErrorMsg(msg); |
| 8333 | } | 8326 | } |
| 8334 | return sema.addConstant(dest_ty, try mod.getCoerced(int_val, dest_ty)); | 8327 | return sema.addConstant(try mod.getCoerced(int_val, dest_ty)); |
| 8335 | } | 8328 | } |
| 8336 | | 8329 | |
| 8337 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { | 8330 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { |
| 8338 | const result = try sema.addConstant(dest_ty, opv); | 8331 | const result = try sema.addConstant(opv); |
| 8339 | // The operand is runtime-known but the result is comptime-known. In | 8332 | // The operand is runtime-known but the result is comptime-known. In |
| 8340 | // this case we still need a safety check. | 8333 | // this case we still need a safety check. |
| 8341 | // TODO add a safety check here. we can't use is_named_enum_value - | 8334 | // TODO add a safety check here. we can't use is_named_enum_value - |
| ... | @@ -8405,7 +8398,7 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -8405,7 +8398,7 @@ fn analyzeOptionalPayloadPtr( |
| 8405 | // we need to emit a runtime instruction to do it. | 8398 | // we need to emit a runtime instruction to do it. |
| 8406 | _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr); | 8399 | _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr); |
| 8407 | } | 8400 | } |
| 8408 | return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{ | 8401 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 8409 | .ty = child_pointer.toIntern(), | 8402 | .ty = child_pointer.toIntern(), |
| 8410 | .addr = .{ .opt_payload = ptr_val.toIntern() }, | 8403 | .addr = .{ .opt_payload = ptr_val.toIntern() }, |
| 8411 | } })).toValue()); | 8404 | } })).toValue()); |
| ... | @@ -8415,7 +8408,7 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -8415,7 +8408,7 @@ fn analyzeOptionalPayloadPtr( |
| 8415 | return sema.fail(block, src, "unable to unwrap null", .{}); | 8408 | return sema.fail(block, src, "unable to unwrap null", .{}); |
| 8416 | } | 8409 | } |
| 8417 | // The same Value represents the pointer to the optional and the payload. | 8410 | // The same Value represents the pointer to the optional and the payload. |
| 8418 | return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{ | 8411 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 8419 | .ty = child_pointer.toIntern(), | 8412 | .ty = child_pointer.toIntern(), |
| 8420 | .addr = .{ .opt_payload = ptr_val.toIntern() }, | 8413 | .addr = .{ .opt_payload = ptr_val.toIntern() }, |
| 8421 | } })).toValue()); | 8414 | } })).toValue()); |
| ... | @@ -8474,7 +8467,7 @@ fn zirOptionalPayload( | ... | @@ -8474,7 +8467,7 @@ fn zirOptionalPayload( |
| 8474 | | 8467 | |
| 8475 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 8468 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 8476 | return if (val.optionalValue(mod)) |payload| | 8469 | return if (val.optionalValue(mod)) |payload| |
| 8477 | sema.addConstant(result_ty, payload) | 8470 | sema.addConstant(payload) |
| 8478 | else | 8471 | else |
| 8479 | sema.fail(block, src, "unable to unwrap null", .{}); | 8472 | sema.fail(block, src, "unable to unwrap null", .{}); |
| 8480 | } | 8473 | } |
| ... | @@ -8526,7 +8519,6 @@ fn analyzeErrUnionPayload( | ... | @@ -8526,7 +8519,6 @@ fn analyzeErrUnionPayload( |
| 8526 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); | 8519 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 8527 | } | 8520 | } |
| 8528 | return sema.addConstant( | 8521 | return sema.addConstant( |
| 8529 | payload_ty, | | |
| 8530 | mod.intern_pool.indexToKey(val.toIntern()).error_union.val.payload.toValue(), | 8522 | mod.intern_pool.indexToKey(val.toIntern()).error_union.val.payload.toValue(), |
| 8531 | ); | 8523 | ); |
| 8532 | } | 8524 | } |
| ... | @@ -8596,7 +8588,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -8596,7 +8588,7 @@ fn analyzeErrUnionPayloadPtr( |
| 8596 | try sema.requireRuntimeBlock(block, src, null); | 8588 | try sema.requireRuntimeBlock(block, src, null); |
| 8597 | _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand); | 8589 | _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand); |
| 8598 | } | 8590 | } |
| 8599 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ | 8591 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 8600 | .ty = operand_pointer_ty.toIntern(), | 8592 | .ty = operand_pointer_ty.toIntern(), |
| 8601 | .addr = .{ .eu_payload = ptr_val.toIntern() }, | 8593 | .addr = .{ .eu_payload = ptr_val.toIntern() }, |
| 8602 | } })).toValue()); | 8594 | } })).toValue()); |
| ... | @@ -8605,7 +8597,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -8605,7 +8597,7 @@ fn analyzeErrUnionPayloadPtr( |
| 8605 | if (val.getErrorName(mod).unwrap()) |name| { | 8597 | if (val.getErrorName(mod).unwrap()) |name| { |
| 8606 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); | 8598 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 8607 | } | 8599 | } |
| 8608 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ | 8600 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 8609 | .ty = operand_pointer_ty.toIntern(), | 8601 | .ty = operand_pointer_ty.toIntern(), |
| 8610 | .addr = .{ .eu_payload = ptr_val.toIntern() }, | 8602 | .addr = .{ .eu_payload = ptr_val.toIntern() }, |
| 8611 | } })).toValue()); | 8603 | } })).toValue()); |
| ... | @@ -8651,7 +8643,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air | ... | @@ -8651,7 +8643,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air |
| 8651 | const result_ty = operand_ty.errorUnionSet(mod); | 8643 | const result_ty = operand_ty.errorUnionSet(mod); |
| 8652 | | 8644 | |
| 8653 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 8645 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 8654 | return sema.addConstant(result_ty, (try mod.intern(.{ .err = .{ | 8646 | return sema.addConstant((try mod.intern(.{ .err = .{ |
| 8655 | .ty = result_ty.toIntern(), | 8647 | .ty = result_ty.toIntern(), |
| 8656 | .name = mod.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name, | 8648 | .name = mod.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name, |
| 8657 | } })).toValue()); | 8649 | } })).toValue()); |
| ... | @@ -8684,7 +8676,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8684,7 +8676,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8684 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { | 8676 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 8685 | if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| { | 8677 | if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| { |
| 8686 | assert(val.getErrorName(mod) != .none); | 8678 | assert(val.getErrorName(mod) != .none); |
| 8687 | return sema.addConstant(result_ty, val); | 8679 | return sema.addConstant(val); |
| 8688 | } | 8680 | } |
| 8689 | } | 8681 | } |
| 8690 | | 8682 | |
| ... | @@ -9148,7 +9140,7 @@ fn funcCommon( | ... | @@ -9148,7 +9140,7 @@ fn funcCommon( |
| 9148 | sema.owner_decl.@"addrspace" = address_space orelse .generic; | 9140 | sema.owner_decl.@"addrspace" = address_space orelse .generic; |
| 9149 | | 9141 | |
| 9150 | if (is_extern) { | 9142 | if (is_extern) { |
| 9151 | return sema.addConstant(fn_ty, (try mod.intern(.{ .extern_func = .{ | 9143 | return sema.addConstant((try mod.intern(.{ .extern_func = .{ |
| 9152 | .ty = fn_ty.toIntern(), | 9144 | .ty = fn_ty.toIntern(), |
| 9153 | .decl = sema.owner_decl_index, | 9145 | .decl = sema.owner_decl_index, |
| 9154 | .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString( | 9146 | .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString( |
| ... | @@ -9188,7 +9180,7 @@ fn funcCommon( | ... | @@ -9188,7 +9180,7 @@ fn funcCommon( |
| 9188 | .branch_quota = default_branch_quota, | 9180 | .branch_quota = default_branch_quota, |
| 9189 | .is_noinline = is_noinline, | 9181 | .is_noinline = is_noinline, |
| 9190 | }; | 9182 | }; |
| 9191 | return sema.addConstant(fn_ty, (try mod.intern(.{ .func = .{ | 9183 | return sema.addConstant((try mod.intern(.{ .func = .{ |
| 9192 | .ty = fn_ty.toIntern(), | 9184 | .ty = fn_ty.toIntern(), |
| 9193 | .index = new_func_index, | 9185 | .index = new_func_index, |
| 9194 | } })).toValue()); | 9186 | } })).toValue()); |
| ... | @@ -9376,7 +9368,7 @@ fn zirParam( | ... | @@ -9376,7 +9368,7 @@ fn zirParam( |
| 9376 | // In this case we are instantiating a generic function call with a non-comptime | 9368 | // In this case we are instantiating a generic function call with a non-comptime |
| 9377 | // non-anytype parameter that ended up being a one-possible-type. | 9369 | // non-anytype parameter that ended up being a one-possible-type. |
| 9378 | // We don't want the parameter to be part of the instantiated function type. | 9370 | // We don't want the parameter to be part of the instantiated function type. |
| 9379 | const result = try sema.addConstant(param_ty, opv); | 9371 | const result = try sema.addConstant(opv); |
| 9380 | sema.inst_map.putAssumeCapacity(inst, result); | 9372 | sema.inst_map.putAssumeCapacity(inst, result); |
| 9381 | return; | 9373 | return; |
| 9382 | } | 9374 | } |
| ... | @@ -9391,7 +9383,7 @@ fn zirParam( | ... | @@ -9391,7 +9383,7 @@ fn zirParam( |
| 9391 | if (is_comptime) { | 9383 | if (is_comptime) { |
| 9392 | // If this is a comptime parameter we can add a constant generic_poison | 9384 | // If this is a comptime parameter we can add a constant generic_poison |
| 9393 | // since this is also a generic parameter. | 9385 | // since this is also a generic parameter. |
| 9394 | const result = try sema.addConstant(Type.generic_poison, Value.generic_poison); | 9386 | const result = try sema.addConstant(Value.generic_poison); |
| 9395 | sema.inst_map.putAssumeCapacityNoClobber(inst, result); | 9387 | sema.inst_map.putAssumeCapacityNoClobber(inst, result); |
| 9396 | } else { | 9388 | } else { |
| 9397 | // Otherwise we need a dummy runtime instruction. | 9389 | // Otherwise we need a dummy runtime instruction. |
| ... | @@ -9514,7 +9506,6 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -9514,7 +9506,6 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9514 | } | 9506 | } |
| 9515 | if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| { | 9507 | if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| { |
| 9516 | return sema.addConstant( | 9508 | return sema.addConstant( |
| 9517 | Type.usize, | | |
| 9518 | try mod.intValue(Type.usize, (try ptr_val.getUnsignedIntAdvanced(mod, sema)).?), | 9509 | try mod.intValue(Type.usize, (try ptr_val.getUnsignedIntAdvanced(mod, sema)).?), |
| 9519 | ); | 9510 | ); |
| 9520 | } | 9511 | } |
| ... | @@ -9625,7 +9616,7 @@ fn intCast( | ... | @@ -9625,7 +9616,7 @@ fn intCast( |
| 9625 | if (wanted_bits == 0) { | 9616 | if (wanted_bits == 0) { |
| 9626 | const ok = if (is_vector) ok: { | 9617 | const ok = if (is_vector) ok: { |
| 9627 | const zeros = try sema.splat(operand_ty, try mod.intValue(operand_scalar_ty, 0)); | 9618 | const zeros = try sema.splat(operand_ty, try mod.intValue(operand_scalar_ty, 0)); |
| 9628 | const zero_inst = try sema.addConstant(operand_ty, zeros); | 9619 | const zero_inst = try sema.addConstant(zeros); |
| 9629 | const is_in_range = try block.addCmpVector(operand, zero_inst, .eq); | 9620 | const is_in_range = try block.addCmpVector(operand, zero_inst, .eq); |
| 9630 | const all_in_range = try block.addInst(.{ | 9621 | const all_in_range = try block.addInst(.{ |
| 9631 | .tag = .reduce, | 9622 | .tag = .reduce, |
| ... | @@ -9633,7 +9624,7 @@ fn intCast( | ... | @@ -9633,7 +9624,7 @@ fn intCast( |
| 9633 | }); | 9624 | }); |
| 9634 | break :ok all_in_range; | 9625 | break :ok all_in_range; |
| 9635 | } else ok: { | 9626 | } else ok: { |
| 9636 | const zero_inst = try sema.addConstant(operand_ty, try mod.intValue(operand_ty, 0)); | 9627 | const zero_inst = try sema.addConstant(try mod.intValue(operand_ty, 0)); |
| 9637 | const is_in_range = try block.addBinOp(.cmp_lte, operand, zero_inst); | 9628 | const is_in_range = try block.addBinOp(.cmp_lte, operand, zero_inst); |
| 9638 | break :ok is_in_range; | 9629 | break :ok is_in_range; |
| 9639 | }; | 9630 | }; |
| ... | @@ -9641,7 +9632,7 @@ fn intCast( | ... | @@ -9641,7 +9632,7 @@ fn intCast( |
| 9641 | } | 9632 | } |
| 9642 | } | 9633 | } |
| 9643 | | 9634 | |
| 9644 | return sema.addConstant(dest_ty, opv); | 9635 | return sema.addConstant(opv); |
| 9645 | } | 9636 | } |
| 9646 | | 9637 | |
| 9647 | try sema.requireRuntimeBlock(block, src, operand_src); | 9638 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -9658,7 +9649,7 @@ fn intCast( | ... | @@ -9658,7 +9649,7 @@ fn intCast( |
| 9658 | if (wanted_value_bits < actual_value_bits) { | 9649 | if (wanted_value_bits < actual_value_bits) { |
| 9659 | const dest_max_val_scalar = try dest_scalar_ty.maxIntScalar(mod, operand_scalar_ty); | 9650 | const dest_max_val_scalar = try dest_scalar_ty.maxIntScalar(mod, operand_scalar_ty); |
| 9660 | const dest_max_val = try sema.splat(operand_ty, dest_max_val_scalar); | 9651 | const dest_max_val = try sema.splat(operand_ty, dest_max_val_scalar); |
| 9661 | const dest_max = try sema.addConstant(operand_ty, dest_max_val); | 9652 | const dest_max = try sema.addConstant(dest_max_val); |
| 9662 | const diff = try block.addBinOp(.subwrap, dest_max, operand); | 9653 | const diff = try block.addBinOp(.subwrap, dest_max, operand); |
| 9663 | | 9654 | |
| 9664 | if (actual_info.signedness == .signed) { | 9655 | if (actual_info.signedness == .signed) { |
| ... | @@ -9674,7 +9665,7 @@ fn intCast( | ... | @@ -9674,7 +9665,7 @@ fn intCast( |
| 9674 | const range_minus_one = try dest_max_val.shl(one, unsigned_operand_ty, sema.arena, mod); | 9665 | const range_minus_one = try dest_max_val.shl(one, unsigned_operand_ty, sema.arena, mod); |
| 9675 | break :range_val try sema.intAdd(range_minus_one, one, unsigned_operand_ty, undefined); | 9666 | break :range_val try sema.intAdd(range_minus_one, one, unsigned_operand_ty, undefined); |
| 9676 | } else try mod.getCoerced(dest_max_val, unsigned_operand_ty); | 9667 | } else try mod.getCoerced(dest_max_val, unsigned_operand_ty); |
| 9677 | const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val); | 9668 | const dest_range = try sema.addConstant(dest_range_val); |
| 9678 | | 9669 | |
| 9679 | const ok = if (is_vector) ok: { | 9670 | const ok = if (is_vector) ok: { |
| 9680 | const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte); | 9671 | const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte); |
| ... | @@ -9715,7 +9706,7 @@ fn intCast( | ... | @@ -9715,7 +9706,7 @@ fn intCast( |
| 9715 | const ok = if (is_vector) ok: { | 9706 | const ok = if (is_vector) ok: { |
| 9716 | const scalar_zero = try mod.intValue(operand_scalar_ty, 0); | 9707 | const scalar_zero = try mod.intValue(operand_scalar_ty, 0); |
| 9717 | const zero_val = try sema.splat(operand_ty, scalar_zero); | 9708 | const zero_val = try sema.splat(operand_ty, scalar_zero); |
| 9718 | const zero_inst = try sema.addConstant(operand_ty, zero_val); | 9709 | const zero_inst = try sema.addConstant(zero_val); |
| 9719 | const is_in_range = try block.addCmpVector(operand, zero_inst, .gte); | 9710 | const is_in_range = try block.addCmpVector(operand, zero_inst, .gte); |
| 9720 | const all_in_range = try block.addInst(.{ | 9711 | const all_in_range = try block.addInst(.{ |
| 9721 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, | 9712 | .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, |
| ... | @@ -9726,7 +9717,7 @@ fn intCast( | ... | @@ -9726,7 +9717,7 @@ fn intCast( |
| 9726 | }); | 9717 | }); |
| 9727 | break :ok all_in_range; | 9718 | break :ok all_in_range; |
| 9728 | } else ok: { | 9719 | } else ok: { |
| 9729 | const zero_inst = try sema.addConstant(operand_ty, try mod.intValue(operand_ty, 0)); | 9720 | const zero_inst = try sema.addConstant(try mod.intValue(operand_ty, 0)); |
| 9730 | const is_in_range = try block.addBinOp(.cmp_gte, operand, zero_inst); | 9721 | const is_in_range = try block.addBinOp(.cmp_gte, operand, zero_inst); |
| 9731 | break :ok is_in_range; | 9722 | break :ok is_in_range; |
| 9732 | }; | 9723 | }; |
| ... | @@ -9916,7 +9907,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -9916,7 +9907,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9916 | } | 9907 | } |
| 9917 | | 9908 | |
| 9918 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { | 9909 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 9919 | return sema.addConstant(dest_ty, try operand_val.floatCast(dest_ty, mod)); | 9910 | return sema.addConstant(try operand_val.floatCast(dest_ty, mod)); |
| 9920 | } | 9911 | } |
| 9921 | if (dest_is_comptime_float) { | 9912 | if (dest_is_comptime_float) { |
| 9922 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{}); | 9913 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{}); |
| ... | @@ -10286,7 +10277,6 @@ const SwitchProngAnalysis = struct { | ... | @@ -10286,7 +10277,6 @@ const SwitchProngAnalysis = struct { |
| 10286 | }); | 10277 | }); |
| 10287 | if (try sema.resolveDefinedValue(block, sema.src, spa.operand_ptr)) |union_ptr| { | 10278 | if (try sema.resolveDefinedValue(block, sema.src, spa.operand_ptr)) |union_ptr| { |
| 10288 | return sema.addConstant( | 10279 | return sema.addConstant( |
| 10289 | ptr_field_ty, | | |
| 10290 | (try mod.intern(.{ .ptr = .{ | 10280 | (try mod.intern(.{ .ptr = .{ |
| 10291 | .ty = ptr_field_ty.toIntern(), | 10281 | .ty = ptr_field_ty.toIntern(), |
| 10292 | .addr = .{ .field = .{ | 10282 | .addr = .{ .field = .{ |
| ... | @@ -10300,7 +10290,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10300,7 +10290,7 @@ const SwitchProngAnalysis = struct { |
| 10300 | } else { | 10290 | } else { |
| 10301 | if (try sema.resolveDefinedValue(block, sema.src, spa.operand)) |union_val| { | 10291 | if (try sema.resolveDefinedValue(block, sema.src, spa.operand)) |union_val| { |
| 10302 | const tag_and_val = mod.intern_pool.indexToKey(union_val.toIntern()).un; | 10292 | const tag_and_val = mod.intern_pool.indexToKey(union_val.toIntern()).un; |
| 10303 | return sema.addConstant(field_ty, tag_and_val.val.toValue()); | 10293 | return sema.addConstant(tag_and_val.val.toValue()); |
| 10304 | } | 10294 | } |
| 10305 | return block.addStructFieldVal(spa.operand, field_index, field_ty); | 10295 | return block.addStructFieldVal(spa.operand, field_index, field_ty); |
| 10306 | } | 10296 | } |
| ... | @@ -10432,7 +10422,6 @@ const SwitchProngAnalysis = struct { | ... | @@ -10432,7 +10422,6 @@ const SwitchProngAnalysis = struct { |
| 10432 | if (try sema.resolveDefinedValue(block, operand_src, spa.operand_ptr)) |op_ptr_val| { | 10422 | if (try sema.resolveDefinedValue(block, operand_src, spa.operand_ptr)) |op_ptr_val| { |
| 10433 | if (op_ptr_val.isUndef(mod)) return sema.addConstUndef(capture_ptr_ty); | 10423 | if (op_ptr_val.isUndef(mod)) return sema.addConstUndef(capture_ptr_ty); |
| 10434 | return sema.addConstant( | 10424 | return sema.addConstant( |
| 10435 | capture_ptr_ty, | | |
| 10436 | (try mod.intern(.{ .ptr = .{ | 10425 | (try mod.intern(.{ .ptr = .{ |
| 10437 | .ty = capture_ptr_ty.toIntern(), | 10426 | .ty = capture_ptr_ty.toIntern(), |
| 10438 | .addr = .{ .field = .{ | 10427 | .addr = .{ .field = .{ |
| ... | @@ -10451,9 +10440,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10451,9 +10440,7 @@ const SwitchProngAnalysis = struct { |
| 10451 | if (operand_val.isUndef(mod)) return sema.addConstUndef(capture_ty); | 10440 | if (operand_val.isUndef(mod)) return sema.addConstUndef(capture_ty); |
| 10452 | const union_val = mod.intern_pool.indexToKey(operand_val.toIntern()).un; | 10441 | const union_val = mod.intern_pool.indexToKey(operand_val.toIntern()).un; |
| 10453 | if (union_val.tag.toValue().isUndef(mod)) return sema.addConstUndef(capture_ty); | 10442 | if (union_val.tag.toValue().isUndef(mod)) return sema.addConstUndef(capture_ty); |
| 10454 | const active_field_idx = @intCast(u32, operand_ty.unionTagFieldIndex(union_val.tag.toValue(), sema.mod).?); | 10443 | const uncoerced = try sema.addConstant(union_val.val.toValue()); |
| 10455 | const field_ty = union_obj.fields.values()[active_field_idx].ty; | | |
| 10456 | const uncoerced = try sema.addConstant(field_ty, union_val.val.toValue()); | | |
| 10457 | return sema.coerce(block, capture_ty, uncoerced, operand_src); | 10444 | return sema.coerce(block, capture_ty, uncoerced, operand_src); |
| 10458 | } | 10445 | } |
| 10459 | | 10446 | |
| ... | @@ -10644,7 +10631,7 @@ fn switchCond( | ... | @@ -10644,7 +10631,7 @@ fn switchCond( |
| 10644 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)}); | 10631 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)}); |
| 10645 | } | 10632 | } |
| 10646 | if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| { | 10633 | if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| { |
| 10647 | return sema.addConstant(operand_ty, opv); | 10634 | return sema.addConstant(opv); |
| 10648 | } | 10635 | } |
| 10649 | return operand; | 10636 | return operand; |
| 10650 | }, | 10637 | }, |
| ... | @@ -11614,7 +11601,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11614,7 +11601,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11614 | }) { | 11601 | }) { |
| 11615 | cases_len += 1; | 11602 | cases_len += 1; |
| 11616 | | 11603 | |
| 11617 | const item_ref = try sema.addConstant(operand_ty, item); | 11604 | const item_ref = try sema.addConstant(item); |
| 11618 | | 11605 | |
| 11619 | case_block.instructions.shrinkRetainingCapacity(0); | 11606 | case_block.instructions.shrinkRetainingCapacity(0); |
| 11620 | case_block.wip_capture_scope = child_block.wip_capture_scope; | 11607 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| ... | @@ -11862,7 +11849,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11862,7 +11849,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11862 | cases_len += 1; | 11849 | cases_len += 1; |
| 11863 | | 11850 | |
| 11864 | const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(u32, i)); | 11851 | const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(u32, i)); |
| 11865 | const item_ref = try sema.addConstant(operand_ty, item_val); | 11852 | const item_ref = try sema.addConstant(item_val); |
| 11866 | | 11853 | |
| 11867 | case_block.instructions.shrinkRetainingCapacity(0); | 11854 | case_block.instructions.shrinkRetainingCapacity(0); |
| 11868 | case_block.wip_capture_scope = child_block.wip_capture_scope; | 11855 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| ... | @@ -11912,7 +11899,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11912,7 +11899,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11912 | .ty = operand_ty.toIntern(), | 11899 | .ty = operand_ty.toIntern(), |
| 11913 | .name = error_name, | 11900 | .name = error_name, |
| 11914 | } }); | 11901 | } }); |
| 11915 | const item_ref = try sema.addConstant(operand_ty, item_val.toValue()); | 11902 | const item_ref = try sema.addConstant(item_val.toValue()); |
| 11916 | | 11903 | |
| 11917 | case_block.instructions.shrinkRetainingCapacity(0); | 11904 | case_block.instructions.shrinkRetainingCapacity(0); |
| 11918 | case_block.wip_capture_scope = child_block.wip_capture_scope; | 11905 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| ... | @@ -11943,7 +11930,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11943,7 +11930,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11943 | while (try it.next()) |cur| { | 11930 | while (try it.next()) |cur| { |
| 11944 | cases_len += 1; | 11931 | cases_len += 1; |
| 11945 | | 11932 | |
| 11946 | const item_ref = try sema.addConstant(operand_ty, cur.toValue()); | 11933 | const item_ref = try sema.addConstant(cur.toValue()); |
| 11947 | | 11934 | |
| 11948 | case_block.instructions.shrinkRetainingCapacity(0); | 11935 | case_block.instructions.shrinkRetainingCapacity(0); |
| 11949 | case_block.wip_capture_scope = child_block.wip_capture_scope; | 11936 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| ... | @@ -12221,7 +12208,7 @@ fn resolveSwitchItemVal( | ... | @@ -12221,7 +12208,7 @@ fn resolveSwitchItemVal( |
| 12221 | | 12208 | |
| 12222 | const val = try sema.resolveLazyValue(maybe_lazy); | 12209 | const val = try sema.resolveLazyValue(maybe_lazy); |
| 12223 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { | 12210 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { |
| 12224 | break :blk try sema.addConstant(coerce_ty, val); | 12211 | break :blk try sema.addConstant(val); |
| 12225 | } else item; | 12212 | } else item; |
| 12226 | | 12213 | |
| 12227 | return .{ .ref = new_item, .val = val.toIntern() }; | 12214 | return .{ .ref = new_item, .val = val.toIntern() }; |
| ... | @@ -12631,7 +12618,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12631,7 +12618,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12631 | const file_root_decl_index = result.file.root_decl.unwrap().?; | 12618 | const file_root_decl_index = result.file.root_decl.unwrap().?; |
| 12632 | const file_root_decl = mod.declPtr(file_root_decl_index); | 12619 | const file_root_decl = mod.declPtr(file_root_decl_index); |
| 12633 | try mod.declareDeclDependency(sema.owner_decl_index, file_root_decl_index); | 12620 | try mod.declareDeclDependency(sema.owner_decl_index, file_root_decl_index); |
| 12634 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); | 12621 | return sema.addConstant(file_root_decl.val); |
| 12635 | } | 12622 | } |
| 12636 | | 12623 | |
| 12637 | fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12624 | fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -12686,7 +12673,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R | ... | @@ -12686,7 +12673,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R |
| 12686 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 12673 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 12687 | _ = try mod.getErrorValue(name); | 12674 | _ = try mod.getErrorValue(name); |
| 12688 | const error_set_type = try mod.singleErrorSetType(name); | 12675 | const error_set_type = try mod.singleErrorSetType(name); |
| 12689 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 12676 | return sema.addConstant((try mod.intern(.{ .err = .{ |
| 12690 | .ty = error_set_type.toIntern(), | 12677 | .ty = error_set_type.toIntern(), |
| 12691 | .name = name, | 12678 | .name = name, |
| 12692 | } })).toValue()); | 12679 | } })).toValue()); |
| ... | @@ -12804,7 +12791,7 @@ fn zirShl( | ... | @@ -12804,7 +12791,7 @@ fn zirShl( |
| 12804 | else => unreachable, | 12791 | else => unreachable, |
| 12805 | }; | 12792 | }; |
| 12806 | | 12793 | |
| 12807 | return sema.addConstant(lhs_ty, val); | 12794 | return sema.addConstant(val); |
| 12808 | } else lhs_src; | 12795 | } else lhs_src; |
| 12809 | | 12796 | |
| 12810 | const new_rhs = if (air_tag == .shl_sat) rhs: { | 12797 | const new_rhs = if (air_tag == .shl_sat) rhs: { |
| ... | @@ -12813,7 +12800,6 @@ fn zirShl( | ... | @@ -12813,7 +12800,6 @@ fn zirShl( |
| 12813 | scalar_rhs_ty.intInfo(mod).bits > scalar_ty.intInfo(mod).bits) | 12800 | scalar_rhs_ty.intInfo(mod).bits > scalar_ty.intInfo(mod).bits) |
| 12814 | { | 12801 | { |
| 12815 | const max_int = try sema.addConstant( | 12802 | const max_int = try sema.addConstant( |
| 12816 | lhs_ty, | | |
| 12817 | try lhs_ty.maxInt(mod, lhs_ty), | 12803 | try lhs_ty.maxInt(mod, lhs_ty), |
| 12818 | ); | 12804 | ); |
| 12819 | const rhs_limited = try sema.analyzeMinMax(block, rhs_src, .min, &.{ rhs, max_int }, &.{ rhs_src, rhs_src }); | 12805 | const rhs_limited = try sema.analyzeMinMax(block, rhs_src, .min, &.{ rhs, max_int }, &.{ rhs_src, rhs_src }); |
| ... | @@ -12829,7 +12815,7 @@ fn zirShl( | ... | @@ -12829,7 +12815,7 @@ fn zirShl( |
| 12829 | if (!std.math.isPowerOfTwo(bit_count)) { | 12815 | if (!std.math.isPowerOfTwo(bit_count)) { |
| 12830 | const bit_count_val = try mod.intValue(scalar_rhs_ty, bit_count); | 12816 | const bit_count_val = try mod.intValue(scalar_rhs_ty, bit_count); |
| 12831 | const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: { | 12817 | const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: { |
| 12832 | const bit_count_inst = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, bit_count_val)); | 12818 | const bit_count_inst = try sema.addConstant(try sema.splat(rhs_ty, bit_count_val)); |
| 12833 | const lt = try block.addCmpVector(rhs, bit_count_inst, .lt); | 12819 | const lt = try block.addCmpVector(rhs, bit_count_inst, .lt); |
| 12834 | break :ok try block.addInst(.{ | 12820 | break :ok try block.addInst(.{ |
| 12835 | .tag = .reduce, | 12821 | .tag = .reduce, |
| ... | @@ -12839,7 +12825,7 @@ fn zirShl( | ... | @@ -12839,7 +12825,7 @@ fn zirShl( |
| 12839 | } }, | 12825 | } }, |
| 12840 | }); | 12826 | }); |
| 12841 | } else ok: { | 12827 | } else ok: { |
| 12842 | const bit_count_inst = try sema.addConstant(rhs_ty, bit_count_val); | 12828 | const bit_count_inst = try sema.addConstant(bit_count_val); |
| 12843 | break :ok try block.addBinOp(.cmp_lt, rhs, bit_count_inst); | 12829 | break :ok try block.addBinOp(.cmp_lt, rhs, bit_count_inst); |
| 12844 | }; | 12830 | }; |
| 12845 | try sema.addSafetyCheck(block, ok, .shift_rhs_too_big); | 12831 | try sema.addSafetyCheck(block, ok, .shift_rhs_too_big); |
| ... | @@ -12868,7 +12854,7 @@ fn zirShl( | ... | @@ -12868,7 +12854,7 @@ fn zirShl( |
| 12868 | }) | 12854 | }) |
| 12869 | else | 12855 | else |
| 12870 | ov_bit; | 12856 | ov_bit; |
| 12871 | const zero_ov = try sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); | 12857 | const zero_ov = try sema.addConstant(try mod.intValue(Type.u1, 0)); |
| 12872 | const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov); | 12858 | const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov); |
| 12873 | | 12859 | |
| 12874 | try sema.addSafetyCheck(block, no_ov, .shl_overflow); | 12860 | try sema.addSafetyCheck(block, no_ov, .shl_overflow); |
| ... | @@ -12961,7 +12947,7 @@ fn zirShr( | ... | @@ -12961,7 +12947,7 @@ fn zirShr( |
| 12961 | } | 12947 | } |
| 12962 | } | 12948 | } |
| 12963 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, mod); | 12949 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, mod); |
| 12964 | return sema.addConstant(lhs_ty, val); | 12950 | return sema.addConstant(val); |
| 12965 | } else { | 12951 | } else { |
| 12966 | break :rs lhs_src; | 12952 | break :rs lhs_src; |
| 12967 | } | 12953 | } |
| ... | @@ -12979,7 +12965,7 @@ fn zirShr( | ... | @@ -12979,7 +12965,7 @@ fn zirShr( |
| 12979 | const bit_count_val = try mod.intValue(rhs_ty.scalarType(mod), bit_count); | 12965 | const bit_count_val = try mod.intValue(rhs_ty.scalarType(mod), bit_count); |
| 12980 | | 12966 | |
| 12981 | const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: { | 12967 | const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: { |
| 12982 | const bit_count_inst = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, bit_count_val)); | 12968 | const bit_count_inst = try sema.addConstant(try sema.splat(rhs_ty, bit_count_val)); |
| 12983 | const lt = try block.addCmpVector(rhs, bit_count_inst, .lt); | 12969 | const lt = try block.addCmpVector(rhs, bit_count_inst, .lt); |
| 12984 | break :ok try block.addInst(.{ | 12970 | break :ok try block.addInst(.{ |
| 12985 | .tag = .reduce, | 12971 | .tag = .reduce, |
| ... | @@ -12989,7 +12975,7 @@ fn zirShr( | ... | @@ -12989,7 +12975,7 @@ fn zirShr( |
| 12989 | } }, | 12975 | } }, |
| 12990 | }); | 12976 | }); |
| 12991 | } else ok: { | 12977 | } else ok: { |
| 12992 | const bit_count_inst = try sema.addConstant(rhs_ty, bit_count_val); | 12978 | const bit_count_inst = try sema.addConstant(bit_count_val); |
| 12993 | break :ok try block.addBinOp(.cmp_lt, rhs, bit_count_inst); | 12979 | break :ok try block.addBinOp(.cmp_lt, rhs, bit_count_inst); |
| 12994 | }; | 12980 | }; |
| 12995 | try sema.addSafetyCheck(block, ok, .shift_rhs_too_big); | 12981 | try sema.addSafetyCheck(block, ok, .shift_rhs_too_big); |
| ... | @@ -13061,7 +13047,7 @@ fn zirBitwise( | ... | @@ -13061,7 +13047,7 @@ fn zirBitwise( |
| 13061 | .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, mod), | 13047 | .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, mod), |
| 13062 | else => unreachable, | 13048 | else => unreachable, |
| 13063 | }; | 13049 | }; |
| 13064 | return sema.addConstant(resolved_type, result_val); | 13050 | return sema.addConstant(result_val); |
| 13065 | } else { | 13051 | } else { |
| 13066 | break :runtime rhs_src; | 13052 | break :runtime rhs_src; |
| 13067 | } | 13053 | } |
| ... | @@ -13103,13 +13089,13 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13103,13 +13089,13 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13103 | const elem_val = try val.elemValue(mod, i); | 13089 | const elem_val = try val.elemValue(mod, i); |
| 13104 | elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, mod)).intern(scalar_type, mod); | 13090 | elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, mod)).intern(scalar_type, mod); |
| 13105 | } | 13091 | } |
| 13106 | return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{ | 13092 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 13107 | .ty = operand_type.toIntern(), | 13093 | .ty = operand_type.toIntern(), |
| 13108 | .storage = .{ .elems = elems }, | 13094 | .storage = .{ .elems = elems }, |
| 13109 | } })).toValue()); | 13095 | } })).toValue()); |
| 13110 | } else { | 13096 | } else { |
| 13111 | const result_val = try val.bitwiseNot(operand_type, sema.arena, mod); | 13097 | const result_val = try val.bitwiseNot(operand_type, sema.arena, mod); |
| 13112 | return sema.addConstant(operand_type, result_val); | 13098 | return sema.addConstant(result_val); |
| 13113 | } | 13099 | } |
| 13114 | } | 13100 | } |
| 13115 | | 13101 | |
| ... | @@ -13136,7 +13122,7 @@ fn analyzeTupleCat( | ... | @@ -13136,7 +13122,7 @@ fn analyzeTupleCat( |
| 13136 | const dest_fields = lhs_len + rhs_len; | 13122 | const dest_fields = lhs_len + rhs_len; |
| 13137 | | 13123 | |
| 13138 | if (dest_fields == 0) { | 13124 | if (dest_fields == 0) { |
| 13139 | return sema.addConstant(Type.empty_struct_literal, Value.empty_struct); | 13125 | return sema.addConstant(Value.empty_struct); |
| 13140 | } | 13126 | } |
| 13141 | if (lhs_len == 0) { | 13127 | if (lhs_len == 0) { |
| 13142 | return rhs; | 13128 | return rhs; |
| ... | @@ -13187,7 +13173,7 @@ fn analyzeTupleCat( | ... | @@ -13187,7 +13173,7 @@ fn analyzeTupleCat( |
| 13187 | .ty = tuple_ty, | 13173 | .ty = tuple_ty, |
| 13188 | .storage = .{ .elems = values }, | 13174 | .storage = .{ .elems = values }, |
| 13189 | } }); | 13175 | } }); |
| 13190 | return sema.addConstant(tuple_ty.toType(), tuple_val.toValue()); | 13176 | return sema.addConstant(tuple_val.toValue()); |
| 13191 | }; | 13177 | }; |
| 13192 | | 13178 | |
| 13193 | try sema.requireRuntimeBlock(block, src, runtime_src); | 13179 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -13258,9 +13244,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13258,9 +13244,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13258 | // coercing it to the peer-resolved element type. | 13244 | // coercing it to the peer-resolved element type. |
| 13259 | const res_sent_val: ?Value = s: { | 13245 | const res_sent_val: ?Value = s: { |
| 13260 | if (lhs_info.sentinel) |lhs_sent_val| { | 13246 | if (lhs_info.sentinel) |lhs_sent_val| { |
| 13261 | const lhs_sent = try sema.addConstant(lhs_info.elem_type, lhs_sent_val); | 13247 | const lhs_sent = try sema.addConstant(lhs_sent_val); |
| 13262 | if (rhs_info.sentinel) |rhs_sent_val| { | 13248 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 13263 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); | 13249 | const rhs_sent = try sema.addConstant(rhs_sent_val); |
| 13264 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 13250 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 13265 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 13251 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13266 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); | 13252 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); |
| ... | @@ -13277,7 +13263,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13277,7 +13263,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13277 | } | 13263 | } |
| 13278 | } else { | 13264 | } else { |
| 13279 | if (rhs_info.sentinel) |rhs_sent_val| { | 13265 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 13280 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); | 13266 | const rhs_sent = try sema.addConstant(rhs_sent_val); |
| 13281 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 13267 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13282 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); | 13268 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); |
| 13283 | break :s rhs_sent_casted_val; | 13269 | break :s rhs_sent_casted_val; |
| ... | @@ -13333,20 +13319,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13333,20 +13319,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13333 | var elem_i: usize = 0; | 13319 | var elem_i: usize = 0; |
| 13334 | while (elem_i < lhs_len) : (elem_i += 1) { | 13320 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 13335 | const lhs_elem_i = elem_i; | 13321 | const lhs_elem_i = elem_i; |
| 13336 | const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i, mod) else lhs_info.elem_type; | | |
| 13337 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; | 13322 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; |
| 13338 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; | 13323 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 13339 | const elem_val_inst = try sema.addConstant(elem_ty, elem_val); | 13324 | const elem_val_inst = try sema.addConstant(elem_val); |
| 13340 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); | 13325 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13341 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); | 13326 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); |
| 13342 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); | 13327 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13343 | } | 13328 | } |
| 13344 | while (elem_i < result_len) : (elem_i += 1) { | 13329 | while (elem_i < result_len) : (elem_i += 1) { |
| 13345 | const rhs_elem_i = elem_i - lhs_len; | 13330 | const rhs_elem_i = elem_i - lhs_len; |
| 13346 | const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i, mod) else rhs_info.elem_type; | | |
| 13347 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; | 13331 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; |
| 13348 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; | 13332 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 13349 | const elem_val_inst = try sema.addConstant(elem_ty, elem_val); | 13333 | const elem_val_inst = try sema.addConstant(elem_val); |
| 13350 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); | 13334 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13351 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); | 13335 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); |
| 13352 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); | 13336 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| ... | @@ -13388,7 +13372,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13388,7 +13372,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13388 | if (res_sent_val) |sent_val| { | 13372 | if (res_sent_val) |sent_val| { |
| 13389 | const elem_index = try sema.addIntUnsigned(Type.usize, result_len); | 13373 | const elem_index = try sema.addIntUnsigned(Type.usize, result_len); |
| 13390 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 13374 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 13391 | const init = try sema.addConstant(lhs_info.elem_type, try mod.getCoerced(sent_val, lhs_info.elem_type)); | 13375 | const init = try sema.addConstant(try mod.getCoerced(sent_val, lhs_info.elem_type)); |
| 13392 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); | 13376 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 13393 | } | 13377 | } |
| 13394 | | 13378 | |
| ... | @@ -13476,7 +13460,7 @@ fn analyzeTupleMul( | ... | @@ -13476,7 +13460,7 @@ fn analyzeTupleMul( |
| 13476 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); | 13460 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| 13477 | | 13461 | |
| 13478 | if (final_len == 0) { | 13462 | if (final_len == 0) { |
| 13479 | return sema.addConstant(Type.empty_struct_literal, Value.empty_struct); | 13463 | return sema.addConstant(Value.empty_struct); |
| 13480 | } | 13464 | } |
| 13481 | const types = try sema.arena.alloc(InternPool.Index, final_len); | 13465 | const types = try sema.arena.alloc(InternPool.Index, final_len); |
| 13482 | const values = try sema.arena.alloc(InternPool.Index, final_len); | 13466 | const values = try sema.arena.alloc(InternPool.Index, final_len); |
| ... | @@ -13510,7 +13494,7 @@ fn analyzeTupleMul( | ... | @@ -13510,7 +13494,7 @@ fn analyzeTupleMul( |
| 13510 | .ty = tuple_ty, | 13494 | .ty = tuple_ty, |
| 13511 | .storage = .{ .elems = values }, | 13495 | .storage = .{ .elems = values }, |
| 13512 | } }); | 13496 | } }); |
| 13513 | return sema.addConstant(tuple_ty.toType(), tuple_val.toValue()); | 13497 | return sema.addConstant(tuple_val.toValue()); |
| 13514 | }; | 13498 | }; |
| 13515 | | 13499 | |
| 13516 | try sema.requireRuntimeBlock(block, src, runtime_src); | 13500 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -13645,7 +13629,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13645,7 +13629,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13645 | if (lhs_info.sentinel) |sent_val| { | 13629 | if (lhs_info.sentinel) |sent_val| { |
| 13646 | const elem_index = try sema.addIntUnsigned(Type.usize, result_len); | 13630 | const elem_index = try sema.addIntUnsigned(Type.usize, result_len); |
| 13647 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 13631 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 13648 | const init = try sema.addConstant(lhs_info.elem_type, sent_val); | 13632 | const init = try sema.addConstant(sent_val); |
| 13649 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); | 13633 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 13650 | } | 13634 | } |
| 13651 | | 13635 | |
| ... | @@ -13689,13 +13673,13 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13689,13 +13673,13 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13689 | // We handle float negation here to ensure negative zero is represented in the bits. | 13673 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 13690 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 13674 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 13691 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty); | 13675 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty); |
| 13692 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, mod)); | 13676 | return sema.addConstant(try rhs_val.floatNeg(rhs_ty, sema.arena, mod)); |
| 13693 | } | 13677 | } |
| 13694 | try sema.requireRuntimeBlock(block, src, null); | 13678 | try sema.requireRuntimeBlock(block, src, null); |
| 13695 | return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs); | 13679 | return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs); |
| 13696 | } | 13680 | } |
| 13697 | | 13681 | |
| 13698 | const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); | 13682 | const lhs = try sema.addConstant(try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); |
| 13699 | return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src, true); | 13683 | return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src, true); |
| 13700 | } | 13684 | } |
| 13701 | | 13685 | |
| ... | @@ -13715,7 +13699,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -13715,7 +13699,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 13715 | else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)}), | 13699 | else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)}), |
| 13716 | } | 13700 | } |
| 13717 | | 13701 | |
| 13718 | const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); | 13702 | const lhs = try sema.addConstant(try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); |
| 13719 | return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src, true); | 13703 | return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src, true); |
| 13720 | } | 13704 | } |
| 13721 | | 13705 | |
| ... | @@ -13832,7 +13816,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13832,7 +13816,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13832 | else => unreachable, | 13816 | else => unreachable, |
| 13833 | }; | 13817 | }; |
| 13834 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 13818 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 13835 | return sema.addConstant(resolved_type, zero_val); | 13819 | return sema.addConstant(zero_val); |
| 13836 | } | 13820 | } |
| 13837 | } | 13821 | } |
| 13838 | } | 13822 | } |
| ... | @@ -13870,10 +13854,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13870,10 +13854,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13870 | if (overflow_idx) |vec_idx| { | 13854 | if (overflow_idx) |vec_idx| { |
| 13871 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); | 13855 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); |
| 13872 | } | 13856 | } |
| 13873 | return sema.addConstant(resolved_type, res); | 13857 | return sema.addConstant(res); |
| 13874 | } else { | 13858 | } else { |
| 13875 | return sema.addConstant( | 13859 | return sema.addConstant( |
| 13876 | resolved_type, | | |
| 13877 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod), | 13860 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod), |
| 13878 | ); | 13861 | ); |
| 13879 | } | 13862 | } |
| ... | @@ -13972,7 +13955,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13972,7 +13955,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13972 | else => unreachable, | 13955 | else => unreachable, |
| 13973 | }; | 13956 | }; |
| 13974 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 13957 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 13975 | return sema.addConstant(resolved_type, zero_val); | 13958 | return sema.addConstant(zero_val); |
| 13976 | } | 13959 | } |
| 13977 | } | 13960 | } |
| 13978 | } | 13961 | } |
| ... | @@ -13997,14 +13980,13 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13997,14 +13980,13 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13997 | if (overflow_idx) |vec_idx| { | 13980 | if (overflow_idx) |vec_idx| { |
| 13998 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); | 13981 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); |
| 13999 | } | 13982 | } |
| 14000 | return sema.addConstant(resolved_type, res); | 13983 | return sema.addConstant(res); |
| 14001 | } else { | 13984 | } else { |
| 14002 | const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod); | 13985 | const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod); |
| 14003 | if (!(modulus_val.compareAllWithZero(.eq, mod))) { | 13986 | if (!(modulus_val.compareAllWithZero(.eq, mod))) { |
| 14004 | return sema.fail(block, src, "exact division produced remainder", .{}); | 13987 | return sema.fail(block, src, "exact division produced remainder", .{}); |
| 14005 | } | 13988 | } |
| 14006 | return sema.addConstant( | 13989 | return sema.addConstant( |
| 14007 | resolved_type, | | |
| 14008 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod), | 13990 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod), |
| 14009 | ); | 13991 | ); |
| 14010 | } | 13992 | } |
| ... | @@ -14056,7 +14038,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14056,7 +14038,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14056 | }; | 14038 | }; |
| 14057 | if (resolved_type.zigTypeTag(mod) == .Vector) { | 14039 | if (resolved_type.zigTypeTag(mod) == .Vector) { |
| 14058 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 14040 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 14059 | const zero = try sema.addConstant(resolved_type, zero_val); | 14041 | const zero = try sema.addConstant(zero_val); |
| 14060 | const eql = try block.addCmpVector(remainder, zero, .eq); | 14042 | const eql = try block.addCmpVector(remainder, zero, .eq); |
| 14061 | break :ok try block.addInst(.{ | 14043 | break :ok try block.addInst(.{ |
| 14062 | .tag = .reduce, | 14044 | .tag = .reduce, |
| ... | @@ -14066,7 +14048,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14066,7 +14048,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14066 | } }, | 14048 | } }, |
| 14067 | }); | 14049 | }); |
| 14068 | } else { | 14050 | } else { |
| 14069 | const zero = try sema.addConstant(resolved_type, scalar_zero); | 14051 | const zero = try sema.addConstant(scalar_zero); |
| 14070 | const is_in_range = try block.addBinOp(.cmp_eq, remainder, zero); | 14052 | const is_in_range = try block.addBinOp(.cmp_eq, remainder, zero); |
| 14071 | break :ok is_in_range; | 14053 | break :ok is_in_range; |
| 14072 | } | 14054 | } |
| ... | @@ -14143,7 +14125,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14143,7 +14125,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14143 | else => unreachable, | 14125 | else => unreachable, |
| 14144 | }; | 14126 | }; |
| 14145 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 14127 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 14146 | return sema.addConstant(resolved_type, zero_val); | 14128 | return sema.addConstant(zero_val); |
| 14147 | } | 14129 | } |
| 14148 | } | 14130 | } |
| 14149 | } | 14131 | } |
| ... | @@ -14172,12 +14154,10 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14172,12 +14154,10 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14172 | if (maybe_rhs_val) |rhs_val| { | 14154 | if (maybe_rhs_val) |rhs_val| { |
| 14173 | if (is_int) { | 14155 | if (is_int) { |
| 14174 | return sema.addConstant( | 14156 | return sema.addConstant( |
| 14175 | resolved_type, | | |
| 14176 | try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, mod), | 14157 | try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, mod), |
| 14177 | ); | 14158 | ); |
| 14178 | } else { | 14159 | } else { |
| 14179 | return sema.addConstant( | 14160 | return sema.addConstant( |
| 14180 | resolved_type, | | |
| 14181 | try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, mod), | 14161 | try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, mod), |
| 14182 | ); | 14162 | ); |
| 14183 | } | 14163 | } |
| ... | @@ -14260,7 +14240,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14260,7 +14240,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14260 | else => unreachable, | 14240 | else => unreachable, |
| 14261 | }; | 14241 | }; |
| 14262 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 14242 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 14263 | return sema.addConstant(resolved_type, zero_val); | 14243 | return sema.addConstant(zero_val); |
| 14264 | } | 14244 | } |
| 14265 | } | 14245 | } |
| 14266 | } | 14246 | } |
| ... | @@ -14292,10 +14272,9 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14292,10 +14272,9 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14292 | if (overflow_idx) |vec_idx| { | 14272 | if (overflow_idx) |vec_idx| { |
| 14293 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); | 14273 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vec_idx); |
| 14294 | } | 14274 | } |
| 14295 | return sema.addConstant(resolved_type, res); | 14275 | return sema.addConstant(res); |
| 14296 | } else { | 14276 | } else { |
| 14297 | return sema.addConstant( | 14277 | return sema.addConstant( |
| 14298 | resolved_type, | | |
| 14299 | try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, mod), | 14278 | try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, mod), |
| 14300 | ); | 14279 | ); |
| 14301 | } | 14280 | } |
| ... | @@ -14353,11 +14332,11 @@ fn addDivIntOverflowSafety( | ... | @@ -14353,11 +14332,11 @@ fn addDivIntOverflowSafety( |
| 14353 | var ok: Air.Inst.Ref = .none; | 14332 | var ok: Air.Inst.Ref = .none; |
| 14354 | if (resolved_type.zigTypeTag(mod) == .Vector) { | 14333 | if (resolved_type.zigTypeTag(mod) == .Vector) { |
| 14355 | if (maybe_lhs_val == null) { | 14334 | if (maybe_lhs_val == null) { |
| 14356 | const min_int_ref = try sema.addConstant(resolved_type, min_int); | 14335 | const min_int_ref = try sema.addConstant(min_int); |
| 14357 | ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq); | 14336 | ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq); |
| 14358 | } | 14337 | } |
| 14359 | if (maybe_rhs_val == null) { | 14338 | if (maybe_rhs_val == null) { |
| 14360 | const neg_one_ref = try sema.addConstant(resolved_type, neg_one); | 14339 | const neg_one_ref = try sema.addConstant(neg_one); |
| 14361 | const rhs_ok = try block.addCmpVector(casted_rhs, neg_one_ref, .neq); | 14340 | const rhs_ok = try block.addCmpVector(casted_rhs, neg_one_ref, .neq); |
| 14362 | if (ok == .none) { | 14341 | if (ok == .none) { |
| 14363 | ok = rhs_ok; | 14342 | ok = rhs_ok; |
| ... | @@ -14375,11 +14354,11 @@ fn addDivIntOverflowSafety( | ... | @@ -14375,11 +14354,11 @@ fn addDivIntOverflowSafety( |
| 14375 | }); | 14354 | }); |
| 14376 | } else { | 14355 | } else { |
| 14377 | if (maybe_lhs_val == null) { | 14356 | if (maybe_lhs_val == null) { |
| 14378 | const min_int_ref = try sema.addConstant(resolved_type, min_int); | 14357 | const min_int_ref = try sema.addConstant(min_int); |
| 14379 | ok = try block.addBinOp(.cmp_neq, casted_lhs, min_int_ref); | 14358 | ok = try block.addBinOp(.cmp_neq, casted_lhs, min_int_ref); |
| 14380 | } | 14359 | } |
| 14381 | if (maybe_rhs_val == null) { | 14360 | if (maybe_rhs_val == null) { |
| 14382 | const neg_one_ref = try sema.addConstant(resolved_type, neg_one); | 14361 | const neg_one_ref = try sema.addConstant(neg_one); |
| 14383 | const rhs_ok = try block.addBinOp(.cmp_neq, casted_rhs, neg_one_ref); | 14362 | const rhs_ok = try block.addBinOp(.cmp_neq, casted_rhs, neg_one_ref); |
| 14384 | if (ok == .none) { | 14363 | if (ok == .none) { |
| 14385 | ok = rhs_ok; | 14364 | ok = rhs_ok; |
| ... | @@ -14414,7 +14393,7 @@ fn addDivByZeroSafety( | ... | @@ -14414,7 +14393,7 @@ fn addDivByZeroSafety( |
| 14414 | try mod.floatValue(resolved_type.scalarType(mod), 0.0); | 14393 | try mod.floatValue(resolved_type.scalarType(mod), 0.0); |
| 14415 | const ok = if (resolved_type.zigTypeTag(mod) == .Vector) ok: { | 14394 | const ok = if (resolved_type.zigTypeTag(mod) == .Vector) ok: { |
| 14416 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 14395 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 14417 | const zero = try sema.addConstant(resolved_type, zero_val); | 14396 | const zero = try sema.addConstant(zero_val); |
| 14418 | const ok = try block.addCmpVector(casted_rhs, zero, .neq); | 14397 | const ok = try block.addCmpVector(casted_rhs, zero, .neq); |
| 14419 | break :ok try block.addInst(.{ | 14398 | break :ok try block.addInst(.{ |
| 14420 | .tag = if (is_int) .reduce else .reduce_optimized, | 14399 | .tag = if (is_int) .reduce else .reduce_optimized, |
| ... | @@ -14424,7 +14403,7 @@ fn addDivByZeroSafety( | ... | @@ -14424,7 +14403,7 @@ fn addDivByZeroSafety( |
| 14424 | } }, | 14403 | } }, |
| 14425 | }); | 14404 | }); |
| 14426 | } else ok: { | 14405 | } else ok: { |
| 14427 | const zero = try sema.addConstant(resolved_type, scalar_zero); | 14406 | const zero = try sema.addConstant(scalar_zero); |
| 14428 | break :ok try block.addBinOp(if (is_int) .cmp_neq else .cmp_neq_optimized, casted_rhs, zero); | 14407 | break :ok try block.addBinOp(if (is_int) .cmp_neq else .cmp_neq_optimized, casted_rhs, zero); |
| 14429 | }; | 14408 | }; |
| 14430 | try sema.addSafetyCheck(block, ok, .divide_by_zero); | 14409 | try sema.addSafetyCheck(block, ok, .divide_by_zero); |
| ... | @@ -14505,7 +14484,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14505,7 +14484,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14505 | .ty = resolved_type.toIntern(), | 14484 | .ty = resolved_type.toIntern(), |
| 14506 | .storage = .{ .repeated_elem = scalar_zero.toIntern() }, | 14485 | .storage = .{ .repeated_elem = scalar_zero.toIntern() }, |
| 14507 | } })).toValue() else scalar_zero; | 14486 | } })).toValue() else scalar_zero; |
| 14508 | return sema.addConstant(resolved_type, zero_val); | 14487 | return sema.addConstant(zero_val); |
| 14509 | } | 14488 | } |
| 14510 | } else if (lhs_scalar_ty.isSignedInt(mod)) { | 14489 | } else if (lhs_scalar_ty.isSignedInt(mod)) { |
| 14511 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 14490 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| ... | @@ -14529,7 +14508,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14529,7 +14508,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14529 | { | 14508 | { |
| 14530 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 14509 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 14531 | } | 14510 | } |
| 14532 | return sema.addConstant(resolved_type, rem_result); | 14511 | return sema.addConstant(rem_result); |
| 14533 | } | 14512 | } |
| 14534 | break :rs lhs_src; | 14513 | break :rs lhs_src; |
| 14535 | } else if (rhs_scalar_ty.isSignedInt(mod)) { | 14514 | } else if (rhs_scalar_ty.isSignedInt(mod)) { |
| ... | @@ -14554,7 +14533,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14554,7 +14533,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14554 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 14533 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 14555 | } | 14534 | } |
| 14556 | return sema.addConstant( | 14535 | return sema.addConstant( |
| 14557 | resolved_type, | | |
| 14558 | try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod), | 14536 | try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod), |
| 14559 | ); | 14537 | ); |
| 14560 | } else { | 14538 | } else { |
| ... | @@ -14687,7 +14665,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14687,7 +14665,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14687 | } | 14665 | } |
| 14688 | if (maybe_lhs_val) |lhs_val| { | 14666 | if (maybe_lhs_val) |lhs_val| { |
| 14689 | return sema.addConstant( | 14667 | return sema.addConstant( |
| 14690 | resolved_type, | | |
| 14691 | try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod), | 14668 | try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod), |
| 14692 | ); | 14669 | ); |
| 14693 | } | 14670 | } |
| ... | @@ -14711,7 +14688,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14711,7 +14688,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14711 | } | 14688 | } |
| 14712 | if (maybe_rhs_val) |rhs_val| { | 14689 | if (maybe_rhs_val) |rhs_val| { |
| 14713 | return sema.addConstant( | 14690 | return sema.addConstant( |
| 14714 | resolved_type, | | |
| 14715 | try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod), | 14691 | try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod), |
| 14716 | ); | 14692 | ); |
| 14717 | } else break :rs rhs_src; | 14693 | } else break :rs rhs_src; |
| ... | @@ -14789,7 +14765,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14789,7 +14765,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14789 | } | 14765 | } |
| 14790 | if (maybe_lhs_val) |lhs_val| { | 14766 | if (maybe_lhs_val) |lhs_val| { |
| 14791 | return sema.addConstant( | 14767 | return sema.addConstant( |
| 14792 | resolved_type, | | |
| 14793 | try sema.intRem(resolved_type, lhs_val, rhs_val), | 14768 | try sema.intRem(resolved_type, lhs_val, rhs_val), |
| 14794 | ); | 14769 | ); |
| 14795 | } | 14770 | } |
| ... | @@ -14813,7 +14788,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -14813,7 +14788,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14813 | } | 14788 | } |
| 14814 | if (maybe_rhs_val) |rhs_val| { | 14789 | if (maybe_rhs_val) |rhs_val| { |
| 14815 | return sema.addConstant( | 14790 | return sema.addConstant( |
| 14816 | resolved_type, | | |
| 14817 | try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod), | 14791 | try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod), |
| 14818 | ); | 14792 | ); |
| 14819 | } else break :rs rhs_src; | 14793 | } else break :rs rhs_src; |
| ... | @@ -15025,7 +14999,7 @@ fn zirOverflowArithmetic( | ... | @@ -15025,7 +14999,7 @@ fn zirOverflowArithmetic( |
| 15025 | } | 14999 | } |
| 15026 | | 15000 | |
| 15027 | if (result.inst == .none) { | 15001 | if (result.inst == .none) { |
| 15028 | return sema.addConstant(tuple_ty, (try mod.intern(.{ .aggregate = .{ | 15002 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 15029 | .ty = tuple_ty.toIntern(), | 15003 | .ty = tuple_ty.toIntern(), |
| 15030 | .storage = .{ .elems = &.{ | 15004 | .storage = .{ .elems = &.{ |
| 15031 | result.wrapped.toIntern(), | 15005 | result.wrapped.toIntern(), |
| ... | @@ -15036,7 +15010,7 @@ fn zirOverflowArithmetic( | ... | @@ -15036,7 +15010,7 @@ fn zirOverflowArithmetic( |
| 15036 | | 15010 | |
| 15037 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2); | 15011 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2); |
| 15038 | element_refs[0] = result.inst; | 15012 | element_refs[0] = result.inst; |
| 15039 | element_refs[1] = try sema.addConstant(tuple_ty.structFieldType(1, mod), result.overflow_bit); | 15013 | element_refs[1] = try sema.addConstant(result.overflow_bit); |
| 15040 | return block.addAggregateInit(tuple_ty, element_refs); | 15014 | return block.addAggregateInit(tuple_ty, element_refs); |
| 15041 | } | 15015 | } |
| 15042 | | 15016 | |
| ... | @@ -15158,10 +15132,9 @@ fn analyzeArithmetic( | ... | @@ -15158,10 +15132,9 @@ fn analyzeArithmetic( |
| 15158 | if (overflow_idx) |vec_idx| { | 15132 | if (overflow_idx) |vec_idx| { |
| 15159 | return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vec_idx); | 15133 | return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vec_idx); |
| 15160 | } | 15134 | } |
| 15161 | return sema.addConstant(resolved_type, sum); | 15135 | return sema.addConstant(sum); |
| 15162 | } else { | 15136 | } else { |
| 15163 | return sema.addConstant( | 15137 | return sema.addConstant( |
| 15164 | resolved_type, | | |
| 15165 | try Value.floatAdd(lhs_val, rhs_val, resolved_type, sema.arena, mod), | 15138 | try Value.floatAdd(lhs_val, rhs_val, resolved_type, sema.arena, mod), |
| 15166 | ); | 15139 | ); |
| 15167 | } | 15140 | } |
| ... | @@ -15187,7 +15160,6 @@ fn analyzeArithmetic( | ... | @@ -15187,7 +15160,6 @@ fn analyzeArithmetic( |
| 15187 | } | 15160 | } |
| 15188 | if (maybe_lhs_val) |lhs_val| { | 15161 | if (maybe_lhs_val) |lhs_val| { |
| 15189 | return sema.addConstant( | 15162 | return sema.addConstant( |
| 15190 | resolved_type, | | |
| 15191 | try sema.numberAddWrapScalar(lhs_val, rhs_val, resolved_type), | 15163 | try sema.numberAddWrapScalar(lhs_val, rhs_val, resolved_type), |
| 15192 | ); | 15164 | ); |
| 15193 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 15165 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| ... | @@ -15215,7 +15187,7 @@ fn analyzeArithmetic( | ... | @@ -15215,7 +15187,7 @@ fn analyzeArithmetic( |
| 15215 | else | 15187 | else |
| 15216 | try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, mod); | 15188 | try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, mod); |
| 15217 | | 15189 | |
| 15218 | return sema.addConstant(resolved_type, val); | 15190 | return sema.addConstant(val); |
| 15219 | } else break :rs .{ .src = lhs_src, .air_tag = .add_sat }; | 15191 | } else break :rs .{ .src = lhs_src, .air_tag = .add_sat }; |
| 15220 | } else break :rs .{ .src = rhs_src, .air_tag = .add_sat }; | 15192 | } else break :rs .{ .src = rhs_src, .air_tag = .add_sat }; |
| 15221 | }, | 15193 | }, |
| ... | @@ -15255,10 +15227,9 @@ fn analyzeArithmetic( | ... | @@ -15255,10 +15227,9 @@ fn analyzeArithmetic( |
| 15255 | if (overflow_idx) |vec_idx| { | 15227 | if (overflow_idx) |vec_idx| { |
| 15256 | return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vec_idx); | 15228 | return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vec_idx); |
| 15257 | } | 15229 | } |
| 15258 | return sema.addConstant(resolved_type, diff); | 15230 | return sema.addConstant(diff); |
| 15259 | } else { | 15231 | } else { |
| 15260 | return sema.addConstant( | 15232 | return sema.addConstant( |
| 15261 | resolved_type, | | |
| 15262 | try Value.floatSub(lhs_val, rhs_val, resolved_type, sema.arena, mod), | 15233 | try Value.floatSub(lhs_val, rhs_val, resolved_type, sema.arena, mod), |
| 15263 | ); | 15234 | ); |
| 15264 | } | 15235 | } |
| ... | @@ -15284,7 +15255,6 @@ fn analyzeArithmetic( | ... | @@ -15284,7 +15255,6 @@ fn analyzeArithmetic( |
| 15284 | } | 15255 | } |
| 15285 | if (maybe_rhs_val) |rhs_val| { | 15256 | if (maybe_rhs_val) |rhs_val| { |
| 15286 | return sema.addConstant( | 15257 | return sema.addConstant( |
| 15287 | resolved_type, | | |
| 15288 | try sema.numberSubWrapScalar(lhs_val, rhs_val, resolved_type), | 15258 | try sema.numberSubWrapScalar(lhs_val, rhs_val, resolved_type), |
| 15289 | ); | 15259 | ); |
| 15290 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; | 15260 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| ... | @@ -15312,7 +15282,7 @@ fn analyzeArithmetic( | ... | @@ -15312,7 +15282,7 @@ fn analyzeArithmetic( |
| 15312 | else | 15282 | else |
| 15313 | try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, mod); | 15283 | try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, mod); |
| 15314 | | 15284 | |
| 15315 | return sema.addConstant(resolved_type, val); | 15285 | return sema.addConstant(val); |
| 15316 | } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat }; | 15286 | } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat }; |
| 15317 | } else break :rs .{ .src = lhs_src, .air_tag = .sub_sat }; | 15287 | } else break :rs .{ .src = lhs_src, .air_tag = .sub_sat }; |
| 15318 | }, | 15288 | }, |
| ... | @@ -15341,16 +15311,15 @@ fn analyzeArithmetic( | ... | @@ -15341,16 +15311,15 @@ fn analyzeArithmetic( |
| 15341 | if (maybe_lhs_val) |lhs_val| { | 15311 | if (maybe_lhs_val) |lhs_val| { |
| 15342 | if (!lhs_val.isUndef(mod)) { | 15312 | if (!lhs_val.isUndef(mod)) { |
| 15343 | if (lhs_val.isNan(mod)) { | 15313 | if (lhs_val.isNan(mod)) { |
| 15344 | return sema.addConstant(resolved_type, lhs_val); | 15314 | return sema.addConstant(lhs_val); |
| 15345 | } | 15315 | } |
| 15346 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) lz: { | 15316 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) lz: { |
| 15347 | if (maybe_rhs_val) |rhs_val| { | 15317 | if (maybe_rhs_val) |rhs_val| { |
| 15348 | if (rhs_val.isNan(mod)) { | 15318 | if (rhs_val.isNan(mod)) { |
| 15349 | return sema.addConstant(resolved_type, rhs_val); | 15319 | return sema.addConstant(rhs_val); |
| 15350 | } | 15320 | } |
| 15351 | if (rhs_val.isInf(mod)) { | 15321 | if (rhs_val.isInf(mod)) { |
| 15352 | return sema.addConstant( | 15322 | return sema.addConstant( |
| 15353 | resolved_type, | | |
| 15354 | try mod.floatValue(resolved_type, std.math.nan_f128), | 15323 | try mod.floatValue(resolved_type, std.math.nan_f128), |
| 15355 | ); | 15324 | ); |
| 15356 | } | 15325 | } |
| ... | @@ -15358,7 +15327,7 @@ fn analyzeArithmetic( | ... | @@ -15358,7 +15327,7 @@ fn analyzeArithmetic( |
| 15358 | break :lz; | 15327 | break :lz; |
| 15359 | } | 15328 | } |
| 15360 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15329 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15361 | return sema.addConstant(resolved_type, zero_val); | 15330 | return sema.addConstant(zero_val); |
| 15362 | } | 15331 | } |
| 15363 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15332 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15364 | return casted_rhs; | 15333 | return casted_rhs; |
| ... | @@ -15375,13 +15344,12 @@ fn analyzeArithmetic( | ... | @@ -15375,13 +15344,12 @@ fn analyzeArithmetic( |
| 15375 | } | 15344 | } |
| 15376 | } | 15345 | } |
| 15377 | if (rhs_val.isNan(mod)) { | 15346 | if (rhs_val.isNan(mod)) { |
| 15378 | return sema.addConstant(resolved_type, rhs_val); | 15347 | return sema.addConstant(rhs_val); |
| 15379 | } | 15348 | } |
| 15380 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) rz: { | 15349 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) rz: { |
| 15381 | if (maybe_lhs_val) |lhs_val| { | 15350 | if (maybe_lhs_val) |lhs_val| { |
| 15382 | if (lhs_val.isInf(mod)) { | 15351 | if (lhs_val.isInf(mod)) { |
| 15383 | return sema.addConstant( | 15352 | return sema.addConstant( |
| 15384 | resolved_type, | | |
| 15385 | try mod.floatValue(resolved_type, std.math.nan_f128), | 15353 | try mod.floatValue(resolved_type, std.math.nan_f128), |
| 15386 | ); | 15354 | ); |
| 15387 | } | 15355 | } |
| ... | @@ -15389,7 +15357,7 @@ fn analyzeArithmetic( | ... | @@ -15389,7 +15357,7 @@ fn analyzeArithmetic( |
| 15389 | break :rz; | 15357 | break :rz; |
| 15390 | } | 15358 | } |
| 15391 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15359 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15392 | return sema.addConstant(resolved_type, zero_val); | 15360 | return sema.addConstant(zero_val); |
| 15393 | } | 15361 | } |
| 15394 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15362 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15395 | return casted_lhs; | 15363 | return casted_lhs; |
| ... | @@ -15408,10 +15376,9 @@ fn analyzeArithmetic( | ... | @@ -15408,10 +15376,9 @@ fn analyzeArithmetic( |
| 15408 | if (overflow_idx) |vec_idx| { | 15376 | if (overflow_idx) |vec_idx| { |
| 15409 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx); | 15377 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx); |
| 15410 | } | 15378 | } |
| 15411 | return sema.addConstant(resolved_type, product); | 15379 | return sema.addConstant(product); |
| 15412 | } else { | 15380 | } else { |
| 15413 | return sema.addConstant( | 15381 | return sema.addConstant( |
| 15414 | resolved_type, | | |
| 15415 | try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, mod), | 15382 | try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, mod), |
| 15416 | ); | 15383 | ); |
| 15417 | } | 15384 | } |
| ... | @@ -15437,7 +15404,7 @@ fn analyzeArithmetic( | ... | @@ -15437,7 +15404,7 @@ fn analyzeArithmetic( |
| 15437 | if (!lhs_val.isUndef(mod)) { | 15404 | if (!lhs_val.isUndef(mod)) { |
| 15438 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 15405 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 15439 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15406 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15440 | return sema.addConstant(resolved_type, zero_val); | 15407 | return sema.addConstant(zero_val); |
| 15441 | } | 15408 | } |
| 15442 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15409 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15443 | return casted_rhs; | 15410 | return casted_rhs; |
| ... | @@ -15451,7 +15418,7 @@ fn analyzeArithmetic( | ... | @@ -15451,7 +15418,7 @@ fn analyzeArithmetic( |
| 15451 | } | 15418 | } |
| 15452 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 15419 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 15453 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15420 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15454 | return sema.addConstant(resolved_type, zero_val); | 15421 | return sema.addConstant(zero_val); |
| 15455 | } | 15422 | } |
| 15456 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15423 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15457 | return casted_lhs; | 15424 | return casted_lhs; |
| ... | @@ -15461,7 +15428,6 @@ fn analyzeArithmetic( | ... | @@ -15461,7 +15428,6 @@ fn analyzeArithmetic( |
| 15461 | return sema.addConstUndef(resolved_type); | 15428 | return sema.addConstUndef(resolved_type); |
| 15462 | } | 15429 | } |
| 15463 | return sema.addConstant( | 15430 | return sema.addConstant( |
| 15464 | resolved_type, | | |
| 15465 | try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, mod), | 15431 | try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, mod), |
| 15466 | ); | 15432 | ); |
| 15467 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 15433 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| ... | @@ -15486,7 +15452,7 @@ fn analyzeArithmetic( | ... | @@ -15486,7 +15452,7 @@ fn analyzeArithmetic( |
| 15486 | if (!lhs_val.isUndef(mod)) { | 15452 | if (!lhs_val.isUndef(mod)) { |
| 15487 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 15453 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 15488 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15454 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15489 | return sema.addConstant(resolved_type, zero_val); | 15455 | return sema.addConstant(zero_val); |
| 15490 | } | 15456 | } |
| 15491 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15457 | if (try sema.compareAll(lhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15492 | return casted_rhs; | 15458 | return casted_rhs; |
| ... | @@ -15499,7 +15465,7 @@ fn analyzeArithmetic( | ... | @@ -15499,7 +15465,7 @@ fn analyzeArithmetic( |
| 15499 | } | 15465 | } |
| 15500 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 15466 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 15501 | const zero_val = try sema.splat(resolved_type, scalar_zero); | 15467 | const zero_val = try sema.splat(resolved_type, scalar_zero); |
| 15502 | return sema.addConstant(resolved_type, zero_val); | 15468 | return sema.addConstant(zero_val); |
| 15503 | } | 15469 | } |
| 15504 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { | 15470 | if (try sema.compareAll(rhs_val, .eq, try sema.splat(resolved_type, scalar_one), resolved_type)) { |
| 15505 | return casted_lhs; | 15471 | return casted_lhs; |
| ... | @@ -15514,7 +15480,7 @@ fn analyzeArithmetic( | ... | @@ -15514,7 +15480,7 @@ fn analyzeArithmetic( |
| 15514 | else | 15480 | else |
| 15515 | try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, mod); | 15481 | try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, mod); |
| 15516 | | 15482 | |
| 15517 | return sema.addConstant(resolved_type, val); | 15483 | return sema.addConstant(val); |
| 15518 | } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat }; | 15484 | } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat }; |
| 15519 | } else break :rs .{ .src = rhs_src, .air_tag = .mul_sat }; | 15485 | } else break :rs .{ .src = rhs_src, .air_tag = .mul_sat }; |
| 15520 | }, | 15486 | }, |
| ... | @@ -15554,7 +15520,7 @@ fn analyzeArithmetic( | ... | @@ -15554,7 +15520,7 @@ fn analyzeArithmetic( |
| 15554 | }) | 15520 | }) |
| 15555 | else | 15521 | else |
| 15556 | ov_bit; | 15522 | ov_bit; |
| 15557 | const zero_ov = try sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); | 15523 | const zero_ov = try sema.addConstant(try mod.intValue(Type.u1, 0)); |
| 15558 | const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov); | 15524 | const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov); |
| 15559 | | 15525 | |
| 15560 | try sema.addSafetyCheck(block, no_ov, .integer_overflow); | 15526 | try sema.addSafetyCheck(block, no_ov, .integer_overflow); |
| ... | @@ -15638,13 +15604,13 @@ fn analyzePtrArithmetic( | ... | @@ -15638,13 +15604,13 @@ fn analyzePtrArithmetic( |
| 15638 | else => unreachable, | 15604 | else => unreachable, |
| 15639 | }; | 15605 | }; |
| 15640 | const new_ptr_val = try mod.ptrIntValue(new_ptr_ty, new_addr); | 15606 | const new_ptr_val = try mod.ptrIntValue(new_ptr_ty, new_addr); |
| 15641 | return sema.addConstant(new_ptr_ty, new_ptr_val); | 15607 | return sema.addConstant(new_ptr_val); |
| 15642 | } | 15608 | } |
| 15643 | if (air_tag == .ptr_sub) { | 15609 | if (air_tag == .ptr_sub) { |
| 15644 | return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{}); | 15610 | return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{}); |
| 15645 | } | 15611 | } |
| 15646 | const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, mod); | 15612 | const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, mod); |
| 15647 | return sema.addConstant(new_ptr_ty, new_ptr_val); | 15613 | return sema.addConstant(new_ptr_val); |
| 15648 | } else break :rs offset_src; | 15614 | } else break :rs offset_src; |
| 15649 | } else break :rs ptr_src; | 15615 | } else break :rs ptr_src; |
| 15650 | }; | 15616 | }; |
| ... | @@ -16055,12 +16021,8 @@ fn cmpSelf( | ... | @@ -16055,12 +16021,8 @@ fn cmpSelf( |
| 16055 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(Type.bool); | 16021 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 16056 | | 16022 | |
| 16057 | if (resolved_type.zigTypeTag(mod) == .Vector) { | 16023 | if (resolved_type.zigTypeTag(mod) == .Vector) { |
| 16058 | const result_ty = try mod.vectorType(.{ | | |
| 16059 | .len = resolved_type.vectorLen(mod), | | |
| 16060 | .child = .bool_type, | | |
| 16061 | }); | | |
| 16062 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type); | 16024 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type); |
| 16063 | return sema.addConstant(result_ty, cmp_val); | 16025 | return sema.addConstant(cmp_val); |
| 16064 | } | 16026 | } |
| 16065 | | 16027 | |
| 16066 | if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) { | 16028 | if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) { |
| ... | @@ -16156,7 +16118,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -16156,7 +16118,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16156 | if (val.isLazySize(mod)) { | 16118 | if (val.isLazySize(mod)) { |
| 16157 | try sema.queueFullTypeResolution(ty); | 16119 | try sema.queueFullTypeResolution(ty); |
| 16158 | } | 16120 | } |
| 16159 | return sema.addConstant(Type.comptime_int, val); | 16121 | return sema.addConstant(val); |
| 16160 | } | 16122 | } |
| 16161 | | 16123 | |
| 16162 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16124 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -16319,8 +16281,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -16319,8 +16281,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 16319 | return block.addTy(.alloc, ty_ip_index.toType()); | 16281 | return block.addTy(.alloc, ty_ip_index.toType()); |
| 16320 | }, | 16282 | }, |
| 16321 | .comptime_val => |val_ip_index| { | 16283 | .comptime_val => |val_ip_index| { |
| 16322 | const ty = mod.intern_pool.typeOf(val_ip_index).toType(); | 16284 | return sema.addConstant(val_ip_index.toValue()); |
| 16323 | return sema.addConstant(ty, val_ip_index.toValue()); | | |
| 16324 | }, | 16285 | }, |
| 16325 | } | 16286 | } |
| 16326 | } | 16287 | } |
| ... | @@ -16427,7 +16388,7 @@ fn zirBuiltinSrc( | ... | @@ -16427,7 +16388,7 @@ fn zirBuiltinSrc( |
| 16427 | // column: u32, | 16388 | // column: u32, |
| 16428 | (try mod.intValue(Type.u32, extra.column + 1)).toIntern(), | 16389 | (try mod.intValue(Type.u32, extra.column + 1)).toIntern(), |
| 16429 | }; | 16390 | }; |
| 16430 | return sema.addConstant(src_loc_ty, (try mod.intern(.{ .aggregate = .{ | 16391 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 16431 | .ty = src_loc_ty.toIntern(), | 16392 | .ty = src_loc_ty.toIntern(), |
| 16432 | .storage = .{ .elems = &fields }, | 16393 | .storage = .{ .elems = &fields }, |
| 16433 | } })).toValue()); | 16394 | } })).toValue()); |
| ... | @@ -16453,7 +16414,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16453,7 +16414,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16453 | .Undefined, | 16414 | .Undefined, |
| 16454 | .Null, | 16415 | .Null, |
| 16455 | .EnumLiteral, | 16416 | .EnumLiteral, |
| 16456 | => |type_info_tag| return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16417 | => |type_info_tag| return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16457 | .ty = type_info_ty.toIntern(), | 16418 | .ty = type_info_ty.toIntern(), |
| 16458 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(type_info_tag))).toIntern(), | 16419 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(type_info_tag))).toIntern(), |
| 16459 | .val = .void_value, | 16420 | .val = .void_value, |
| ... | @@ -16562,7 +16523,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16562,7 +16523,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16562 | // args: []const Fn.Param, | 16523 | // args: []const Fn.Param, |
| 16563 | args_val, | 16524 | args_val, |
| 16564 | }; | 16525 | }; |
| 16565 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16526 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16566 | .ty = type_info_ty.toIntern(), | 16527 | .ty = type_info_ty.toIntern(), |
| 16567 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Fn))).toIntern(), | 16528 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Fn))).toIntern(), |
| 16568 | .val = try mod.intern(.{ .aggregate = .{ | 16529 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16591,7 +16552,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16591,7 +16552,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16591 | // bits: u16, | 16552 | // bits: u16, |
| 16592 | (try mod.intValue(Type.u16, info.bits)).toIntern(), | 16553 | (try mod.intValue(Type.u16, info.bits)).toIntern(), |
| 16593 | }; | 16554 | }; |
| 16594 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16555 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16595 | .ty = type_info_ty.toIntern(), | 16556 | .ty = type_info_ty.toIntern(), |
| 16596 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Int))).toIntern(), | 16557 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Int))).toIntern(), |
| 16597 | .val = try mod.intern(.{ .aggregate = .{ | 16558 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16616,7 +16577,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16616,7 +16577,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16616 | // bits: u16, | 16577 | // bits: u16, |
| 16617 | (try mod.intValue(Type.u16, ty.bitSize(mod))).toIntern(), | 16578 | (try mod.intValue(Type.u16, ty.bitSize(mod))).toIntern(), |
| 16618 | }; | 16579 | }; |
| 16619 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16580 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16620 | .ty = type_info_ty.toIntern(), | 16581 | .ty = type_info_ty.toIntern(), |
| 16621 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Float))).toIntern(), | 16582 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Float))).toIntern(), |
| 16622 | .val = try mod.intern(.{ .aggregate = .{ | 16583 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16679,7 +16640,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16679,7 +16640,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16679 | else => info.sentinel.toValue(), | 16640 | else => info.sentinel.toValue(), |
| 16680 | })).toIntern(), | 16641 | })).toIntern(), |
| 16681 | }; | 16642 | }; |
| 16682 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16643 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16683 | .ty = type_info_ty.toIntern(), | 16644 | .ty = type_info_ty.toIntern(), |
| 16684 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Pointer))).toIntern(), | 16645 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Pointer))).toIntern(), |
| 16685 | .val = try mod.intern(.{ .aggregate = .{ | 16646 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16711,7 +16672,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16711,7 +16672,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16711 | // sentinel: ?*const anyopaque, | 16672 | // sentinel: ?*const anyopaque, |
| 16712 | (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(), | 16673 | (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(), |
| 16713 | }; | 16674 | }; |
| 16714 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16675 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16715 | .ty = type_info_ty.toIntern(), | 16676 | .ty = type_info_ty.toIntern(), |
| 16716 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Array))).toIntern(), | 16677 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Array))).toIntern(), |
| 16717 | .val = try mod.intern(.{ .aggregate = .{ | 16678 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16741,7 +16702,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16741,7 +16702,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16741 | // child: type, | 16702 | // child: type, |
| 16742 | info.elem_type.toIntern(), | 16703 | info.elem_type.toIntern(), |
| 16743 | }; | 16704 | }; |
| 16744 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16705 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16745 | .ty = type_info_ty.toIntern(), | 16706 | .ty = type_info_ty.toIntern(), |
| 16746 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Vector))).toIntern(), | 16707 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Vector))).toIntern(), |
| 16747 | .val = try mod.intern(.{ .aggregate = .{ | 16708 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16768,7 +16729,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16768,7 +16729,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16768 | // child: type, | 16729 | // child: type, |
| 16769 | ty.optionalChild(mod).toIntern(), | 16730 | ty.optionalChild(mod).toIntern(), |
| 16770 | }; | 16731 | }; |
| 16771 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16732 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16772 | .ty = type_info_ty.toIntern(), | 16733 | .ty = type_info_ty.toIntern(), |
| 16773 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Optional))).toIntern(), | 16734 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Optional))).toIntern(), |
| 16774 | .val = try mod.intern(.{ .aggregate = .{ | 16735 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -16877,7 +16838,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16877,7 +16838,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16877 | } }); | 16838 | } }); |
| 16878 | | 16839 | |
| 16879 | // Construct Type{ .ErrorSet = errors_val } | 16840 | // Construct Type{ .ErrorSet = errors_val } |
| 16880 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16841 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16881 | .ty = type_info_ty.toIntern(), | 16842 | .ty = type_info_ty.toIntern(), |
| 16882 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.ErrorSet))).toIntern(), | 16843 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.ErrorSet))).toIntern(), |
| 16883 | .val = errors_val, | 16844 | .val = errors_val, |
| ... | @@ -16903,7 +16864,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16903,7 +16864,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16903 | // payload: type, | 16864 | // payload: type, |
| 16904 | ty.errorUnionPayload(mod).toIntern(), | 16865 | ty.errorUnionPayload(mod).toIntern(), |
| 16905 | }; | 16866 | }; |
| 16906 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16867 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 16907 | .ty = type_info_ty.toIntern(), | 16868 | .ty = type_info_ty.toIntern(), |
| 16908 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.ErrorUnion))).toIntern(), | 16869 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.ErrorUnion))).toIntern(), |
| 16909 | .val = try mod.intern(.{ .aggregate = .{ | 16870 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -17029,7 +16990,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17029,7 +16990,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17029 | // is_exhaustive: bool, | 16990 | // is_exhaustive: bool, |
| 17030 | is_exhaustive.toIntern(), | 16991 | is_exhaustive.toIntern(), |
| 17031 | }; | 16992 | }; |
| 17032 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 16993 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 17033 | .ty = type_info_ty.toIntern(), | 16994 | .ty = type_info_ty.toIntern(), |
| 17034 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Enum))).toIntern(), | 16995 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Enum))).toIntern(), |
| 17035 | .val = try mod.intern(.{ .aggregate = .{ | 16996 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -17180,7 +17141,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17180,7 +17141,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17180 | // decls: []const Declaration, | 17141 | // decls: []const Declaration, |
| 17181 | decls_val, | 17142 | decls_val, |
| 17182 | }; | 17143 | }; |
| 17183 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 17144 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 17184 | .ty = type_info_ty.toIntern(), | 17145 | .ty = type_info_ty.toIntern(), |
| 17185 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Union))).toIntern(), | 17146 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Union))).toIntern(), |
| 17186 | .val = try mod.intern(.{ .aggregate = .{ | 17147 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -17409,7 +17370,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17409,7 +17370,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17409 | // is_tuple: bool, | 17370 | // is_tuple: bool, |
| 17410 | Value.makeBool(struct_ty.isTuple(mod)).toIntern(), | 17371 | Value.makeBool(struct_ty.isTuple(mod)).toIntern(), |
| 17411 | }; | 17372 | }; |
| 17412 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 17373 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 17413 | .ty = type_info_ty.toIntern(), | 17374 | .ty = type_info_ty.toIntern(), |
| 17414 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Struct))).toIntern(), | 17375 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Struct))).toIntern(), |
| 17415 | .val = try mod.intern(.{ .aggregate = .{ | 17376 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -17441,7 +17402,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17441,7 +17402,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17441 | // decls: []const Declaration, | 17402 | // decls: []const Declaration, |
| 17442 | decls_val, | 17403 | decls_val, |
| 17443 | }; | 17404 | }; |
| 17444 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ | 17405 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 17445 | .ty = type_info_ty.toIntern(), | 17406 | .ty = type_info_ty.toIntern(), |
| 17446 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Opaque))).toIntern(), | 17407 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.builtin.TypeId.Opaque))).toIntern(), |
| 17447 | .val = try mod.intern(.{ .aggregate = .{ | 17408 | .val = try mod.intern(.{ .aggregate = .{ |
| ... | @@ -18187,7 +18148,7 @@ fn zirRetErrValue( | ... | @@ -18187,7 +18148,7 @@ fn zirRetErrValue( |
| 18187 | const src = inst_data.src(); | 18148 | const src = inst_data.src(); |
| 18188 | // Return the error code from the function. | 18149 | // Return the error code from the function. |
| 18189 | const error_set_type = try mod.singleErrorSetType(err_name); | 18150 | const error_set_type = try mod.singleErrorSetType(err_name); |
| 18190 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 18151 | const result_inst = try sema.addConstant((try mod.intern(.{ .err = .{ |
| 18191 | .ty = error_set_type.toIntern(), | 18152 | .ty = error_set_type.toIntern(), |
| 18192 | .name = err_name, | 18153 | .name = err_name, |
| 18193 | } })).toValue()); | 18154 | } })).toValue()); |
| ... | @@ -18613,7 +18574,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -18613,7 +18574,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18613 | switch (obj_ty.zigTypeTag(mod)) { | 18574 | switch (obj_ty.zigTypeTag(mod)) { |
| 18614 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), | 18575 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), |
| 18615 | .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty), | 18576 | .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty), |
| 18616 | .Void => return sema.addConstant(obj_ty, Value.void), | 18577 | .Void => return sema.addConstant(Value.void), |
| 18617 | .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}), | 18578 | .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}), |
| 18618 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), | 18579 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), |
| 18619 | } | 18580 | } |
| ... | @@ -18649,7 +18610,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com | ... | @@ -18649,7 +18610,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 18649 | return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len}); | 18610 | return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len}); |
| 18650 | } | 18611 | } |
| 18651 | } | 18612 | } |
| 18652 | return sema.addConstant(obj_ty, (try mod.intern(.{ .aggregate = .{ | 18613 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 18653 | .ty = obj_ty.toIntern(), | 18614 | .ty = obj_ty.toIntern(), |
| 18654 | .storage = .{ .elems = &.{} }, | 18615 | .storage = .{ .elems = &.{} }, |
| 18655 | } })).toValue()); | 18616 | } })).toValue()); |
| ... | @@ -18686,7 +18647,7 @@ fn unionInit( | ... | @@ -18686,7 +18647,7 @@ fn unionInit( |
| 18686 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); | 18647 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 18687 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); | 18648 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| 18688 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); | 18649 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); |
| 18689 | return sema.addConstant(union_ty, (try mod.intern(.{ .un = .{ | 18650 | return sema.addConstant((try mod.intern(.{ .un = .{ |
| 18690 | .ty = union_ty.toIntern(), | 18651 | .ty = union_ty.toIntern(), |
| 18691 | .tag = try tag_val.intern(tag_ty, mod), | 18652 | .tag = try tag_val.intern(tag_ty, mod), |
| 18692 | .val = try init_val.intern(field.ty, mod), | 18653 | .val = try init_val.intern(field.ty, mod), |
| ... | @@ -18808,7 +18769,7 @@ fn zirStructInit( | ... | @@ -18808,7 +18769,7 @@ fn zirStructInit( |
| 18808 | const alloc = try block.addTy(.alloc, alloc_ty); | 18769 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 18809 | const field_ptr = try sema.unionFieldPtr(block, field_src, alloc, field_name, field_src, resolved_ty, true); | 18770 | const field_ptr = try sema.unionFieldPtr(block, field_src, alloc, field_name, field_src, resolved_ty, true); |
| 18810 | try sema.storePtr(block, src, field_ptr, init_inst); | 18771 | try sema.storePtr(block, src, field_ptr, init_inst); |
| 18811 | const new_tag = try sema.addConstant(resolved_ty.unionTagTypeHypothetical(mod), tag_val); | 18772 | const new_tag = try sema.addConstant(tag_val); |
| 18812 | _ = try block.addBinOp(.set_union_tag, alloc, new_tag); | 18773 | _ = try block.addBinOp(.set_union_tag, alloc, new_tag); |
| 18813 | return sema.makePtrConst(block, alloc); | 18774 | return sema.makePtrConst(block, alloc); |
| 18814 | } | 18775 | } |
| ... | @@ -18839,7 +18800,7 @@ fn finishStructInit( | ... | @@ -18839,7 +18800,7 @@ fn finishStructInit( |
| 18839 | | 18800 | |
| 18840 | switch (ip.indexToKey(struct_ty.toIntern())) { | 18801 | switch (ip.indexToKey(struct_ty.toIntern())) { |
| 18841 | .anon_struct_type => |anon_struct| { | 18802 | .anon_struct_type => |anon_struct| { |
| 18842 | for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| { | 18803 | for (anon_struct.values, 0..) |default_val, i| { |
| 18843 | if (field_inits[i] != .none) continue; | 18804 | if (field_inits[i] != .none) continue; |
| 18844 | | 18805 | |
| 18845 | if (default_val == .none) { | 18806 | if (default_val == .none) { |
| ... | @@ -18861,7 +18822,7 @@ fn finishStructInit( | ... | @@ -18861,7 +18822,7 @@ fn finishStructInit( |
| 18861 | } | 18822 | } |
| 18862 | } | 18823 | } |
| 18863 | } else { | 18824 | } else { |
| 18864 | field_inits[i] = try sema.addConstant(field_ty.toType(), default_val.toValue()); | 18825 | field_inits[i] = try sema.addConstant(default_val.toValue()); |
| 18865 | } | 18826 | } |
| 18866 | } | 18827 | } |
| 18867 | }, | 18828 | }, |
| ... | @@ -18880,7 +18841,7 @@ fn finishStructInit( | ... | @@ -18880,7 +18841,7 @@ fn finishStructInit( |
| 18880 | root_msg = try sema.errMsg(block, init_src, template, args); | 18841 | root_msg = try sema.errMsg(block, init_src, template, args); |
| 18881 | } | 18842 | } |
| 18882 | } else { | 18843 | } else { |
| 18883 | field_inits[i] = try sema.addConstant(field.ty, field.default_val.toValue()); | 18844 | field_inits[i] = try sema.addConstant(field.default_val.toValue()); |
| 18884 | } | 18845 | } |
| 18885 | } | 18846 | } |
| 18886 | }, | 18847 | }, |
| ... | @@ -19119,7 +19080,7 @@ fn zirArrayInit( | ... | @@ -19119,7 +19080,7 @@ fn zirArrayInit( |
| 19119 | } | 19080 | } |
| 19120 | | 19081 | |
| 19121 | if (sentinel_val) |some| { | 19082 | if (sentinel_val) |some| { |
| 19122 | resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(mod), some); | 19083 | resolved_args[resolved_args.len - 1] = try sema.addConstant(some); |
| 19123 | } | 19084 | } |
| 19124 | | 19085 | |
| 19125 | const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| { | 19086 | const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| { |
| ... | @@ -19288,7 +19249,7 @@ fn addConstantMaybeRef( | ... | @@ -19288,7 +19249,7 @@ fn addConstantMaybeRef( |
| 19288 | val: Value, | 19249 | val: Value, |
| 19289 | is_ref: bool, | 19250 | is_ref: bool, |
| 19290 | ) !Air.Inst.Ref { | 19251 | ) !Air.Inst.Ref { |
| 19291 | if (!is_ref) return sema.addConstant(ty, val); | 19252 | if (!is_ref) return sema.addConstant(val); |
| 19292 | | 19253 | |
| 19293 | var anon_decl = try block.startAnonDecl(); | 19254 | var anon_decl = try block.startAnonDecl(); |
| 19294 | defer anon_decl.deinit(); | 19255 | defer anon_decl.deinit(); |
| ... | @@ -19399,7 +19360,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { | ... | @@ -19399,7 +19360,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 19399 | { | 19360 | { |
| 19400 | return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty); | 19361 | return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty); |
| 19401 | } | 19362 | } |
| 19402 | return sema.addConstant(opt_ptr_stack_trace_ty, (try mod.intern(.{ .opt = .{ | 19363 | return sema.addConstant((try mod.intern(.{ .opt = .{ |
| 19403 | .ty = opt_ptr_stack_trace_ty.toIntern(), | 19364 | .ty = opt_ptr_stack_trace_ty.toIntern(), |
| 19404 | .val = .none, | 19365 | .val = .none, |
| 19405 | } })).toValue()); | 19366 | } })).toValue()); |
| ... | @@ -19426,7 +19387,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19426,7 +19387,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19426 | if (val.isLazyAlign(mod)) { | 19387 | if (val.isLazyAlign(mod)) { |
| 19427 | try sema.queueFullTypeResolution(ty); | 19388 | try sema.queueFullTypeResolution(ty); |
| 19428 | } | 19389 | } |
| 19429 | return sema.addConstant(Type.comptime_int, val); | 19390 | return sema.addConstant(val); |
| 19430 | } | 19391 | } |
| 19431 | | 19392 | |
| 19432 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19393 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -19435,8 +19396,8 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -19435,8 +19396,8 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19435 | const operand = try sema.resolveInst(inst_data.operand); | 19396 | const operand = try sema.resolveInst(inst_data.operand); |
| 19436 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 19397 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19437 | if (val.isUndef(mod)) return sema.addConstUndef(Type.u1); | 19398 | if (val.isUndef(mod)) return sema.addConstUndef(Type.u1); |
| 19438 | if (val.toBool()) return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 1)); | 19399 | if (val.toBool()) return sema.addConstant(try mod.intValue(Type.u1, 1)); |
| 19439 | return sema.addConstant(Type.u1, try mod.intValue(Type.u1, 0)); | 19400 | return sema.addConstant(try mod.intValue(Type.u1, 0)); |
| 19440 | } | 19401 | } |
| 19441 | return block.addUnOp(.int_from_bool, operand); | 19402 | return block.addUnOp(.int_from_bool, operand); |
| 19442 | } | 19403 | } |
| ... | @@ -19501,7 +19462,7 @@ fn zirUnaryMath( | ... | @@ -19501,7 +19462,7 @@ fn zirUnaryMath( |
| 19501 | const elem_val = try val.elemValue(sema.mod, i); | 19462 | const elem_val = try val.elemValue(sema.mod, i); |
| 19502 | elem.* = try (try eval(elem_val, scalar_ty, sema.arena, sema.mod)).intern(scalar_ty, mod); | 19463 | elem.* = try (try eval(elem_val, scalar_ty, sema.arena, sema.mod)).intern(scalar_ty, mod); |
| 19503 | } | 19464 | } |
| 19504 | return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{ | 19465 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 19505 | .ty = result_ty.toIntern(), | 19466 | .ty = result_ty.toIntern(), |
| 19506 | .storage = .{ .elems = elems }, | 19467 | .storage = .{ .elems = elems }, |
| 19507 | } })).toValue()); | 19468 | } })).toValue()); |
| ... | @@ -19515,7 +19476,7 @@ fn zirUnaryMath( | ... | @@ -19515,7 +19476,7 @@ fn zirUnaryMath( |
| 19515 | if (operand_val.isUndef(mod)) | 19476 | if (operand_val.isUndef(mod)) |
| 19516 | return sema.addConstUndef(operand_ty); | 19477 | return sema.addConstUndef(operand_ty); |
| 19517 | const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod); | 19478 | const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod); |
| 19518 | return sema.addConstant(operand_ty, result_val); | 19479 | return sema.addConstant(result_val); |
| 19519 | } | 19480 | } |
| 19520 | | 19481 | |
| 19521 | try sema.requireRuntimeBlock(block, operand_src, null); | 19482 | try sema.requireRuntimeBlock(block, operand_src, null); |
| ... | @@ -20762,7 +20723,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -20762,7 +20723,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20762 | | 20723 | |
| 20763 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20724 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20764 | const result_val = try sema.intFromFloat(block, operand_src, val, operand_ty, dest_ty); | 20725 | const result_val = try sema.intFromFloat(block, operand_src, val, operand_ty, dest_ty); |
| 20765 | return sema.addConstant(dest_ty, result_val); | 20726 | return sema.addConstant(result_val); |
| 20766 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 20727 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 20767 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known"); | 20728 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known"); |
| 20768 | } | 20729 | } |
| ... | @@ -20770,17 +20731,17 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -20770,17 +20731,17 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20770 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 20731 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| 20771 | if (dest_ty.intInfo(mod).bits == 0) { | 20732 | if (dest_ty.intInfo(mod).bits == 0) { |
| 20772 | if (block.wantSafety()) { | 20733 | if (block.wantSafety()) { |
| 20773 | const ok = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, 0.0))); | 20734 | const ok = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, try sema.addConstant(try mod.floatValue(operand_ty, 0.0))); |
| 20774 | try sema.addSafetyCheck(block, ok, .integer_part_out_of_bounds); | 20735 | try sema.addSafetyCheck(block, ok, .integer_part_out_of_bounds); |
| 20775 | } | 20736 | } |
| 20776 | return sema.addConstant(dest_ty, try mod.intValue(dest_ty, 0)); | 20737 | return sema.addConstant(try mod.intValue(dest_ty, 0)); |
| 20777 | } | 20738 | } |
| 20778 | const result = try block.addTyOp(if (block.float_mode == .Optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand); | 20739 | const result = try block.addTyOp(if (block.float_mode == .Optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand); |
| 20779 | if (block.wantSafety()) { | 20740 | if (block.wantSafety()) { |
| 20780 | const back = try block.addTyOp(.float_from_int, operand_ty, result); | 20741 | const back = try block.addTyOp(.float_from_int, operand_ty, result); |
| 20781 | const diff = try block.addBinOp(.sub, operand, back); | 20742 | const diff = try block.addBinOp(.sub, operand, back); |
| 20782 | const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, 1.0))); | 20743 | const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, try sema.addConstant(try mod.floatValue(operand_ty, 1.0))); |
| 20783 | const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, try sema.addConstant(operand_ty, try mod.floatValue(operand_ty, -1.0))); | 20744 | const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, try sema.addConstant(try mod.floatValue(operand_ty, -1.0))); |
| 20784 | const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg); | 20745 | const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg); |
| 20785 | try sema.addSafetyCheck(block, ok, .integer_part_out_of_bounds); | 20746 | try sema.addSafetyCheck(block, ok, .integer_part_out_of_bounds); |
| 20786 | } | 20747 | } |
| ... | @@ -20802,7 +20763,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -20802,7 +20763,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20802 | | 20763 | |
| 20803 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 20764 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20804 | const result_val = try val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, sema.mod, sema); | 20765 | const result_val = try val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, sema.mod, sema); |
| 20805 | return sema.addConstant(dest_ty, result_val); | 20766 | return sema.addConstant(result_val); |
| 20806 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 20767 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 20807 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); | 20768 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); |
| 20808 | } | 20769 | } |
| ... | @@ -20853,7 +20814,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -20853,7 +20814,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20853 | .Pointer => try mod.ptrIntValue(ptr_ty, addr), | 20814 | .Pointer => try mod.ptrIntValue(ptr_ty, addr), |
| 20854 | else => unreachable, | 20815 | else => unreachable, |
| 20855 | }; | 20816 | }; |
| 20856 | return sema.addConstant(ptr_ty, ptr_val); | 20817 | return sema.addConstant(ptr_val); |
| 20857 | } | 20818 | } |
| 20858 | | 20819 | |
| 20859 | try sema.requireRuntimeBlock(block, src, operand_src); | 20820 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -20865,7 +20826,6 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -20865,7 +20826,6 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20865 | | 20826 | |
| 20866 | if (ptr_align > 1) { | 20827 | if (ptr_align > 1) { |
| 20867 | const align_minus_1 = try sema.addConstant( | 20828 | const align_minus_1 = try sema.addConstant( |
| 20868 | Type.usize, | | |
| 20869 | try mod.intValue(Type.usize, ptr_align - 1), | 20829 | try mod.intValue(Type.usize, ptr_align - 1), |
| 20870 | ); | 20830 | ); |
| 20871 | const remainder = try block.addBinOp(.bit_and, operand_coerced, align_minus_1); | 20831 | const remainder = try block.addBinOp(.bit_and, operand_coerced, align_minus_1); |
| ... | @@ -20952,7 +20912,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -20952,7 +20912,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 20952 | } | 20912 | } |
| 20953 | } | 20913 | } |
| 20954 | | 20914 | |
| 20955 | return sema.addConstant(dest_ty, try mod.getCoerced(val, dest_ty)); | 20915 | return sema.addConstant(try mod.getCoerced(val, dest_ty)); |
| 20956 | } | 20916 | } |
| 20957 | | 20917 | |
| 20958 | try sema.requireRuntimeBlock(block, src, operand_src); | 20918 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -21074,7 +21034,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21074,7 +21034,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21074 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) { | 21034 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) { |
| 21075 | return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)}); | 21035 | return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)}); |
| 21076 | } | 21036 | } |
| 21077 | return sema.addConstant(aligned_dest_ty, try mod.getCoerced(operand_val, aligned_dest_ty)); | 21037 | return sema.addConstant(try mod.getCoerced(operand_val, aligned_dest_ty)); |
| 21078 | } | 21038 | } |
| 21079 | | 21039 | |
| 21080 | try sema.requireRuntimeBlock(block, src, null); | 21040 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -21108,7 +21068,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -21108,7 +21068,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 21108 | const dest_ty = try mod.ptrType(ptr_info); | 21068 | const dest_ty = try mod.ptrType(ptr_info); |
| 21109 | | 21069 | |
| 21110 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { | 21070 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 21111 | return sema.addConstant(dest_ty, try mod.getCoerced(operand_val, dest_ty)); | 21071 | return sema.addConstant(try mod.getCoerced(operand_val, dest_ty)); |
| 21112 | } | 21072 | } |
| 21113 | | 21073 | |
| 21114 | try sema.requireRuntimeBlock(block, src, null); | 21074 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -21129,7 +21089,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -21129,7 +21089,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 21129 | const dest_ty = try mod.ptrType(ptr_info); | 21089 | const dest_ty = try mod.ptrType(ptr_info); |
| 21130 | | 21090 | |
| 21131 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { | 21091 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 21132 | return sema.addConstant(dest_ty, operand_val); | 21092 | return sema.addConstant(operand_val); |
| 21133 | } | 21093 | } |
| 21134 | | 21094 | |
| 21135 | try sema.requireRuntimeBlock(block, src, null); | 21095 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -21164,13 +21124,13 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21164,13 +21124,13 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21164 | const dest_info = dest_scalar_ty.intInfo(mod); | 21124 | const dest_info = dest_scalar_ty.intInfo(mod); |
| 21165 | | 21125 | |
| 21166 | if (try sema.typeHasOnePossibleValue(dest_ty)) |val| { | 21126 | if (try sema.typeHasOnePossibleValue(dest_ty)) |val| { |
| 21167 | return sema.addConstant(dest_ty, val); | 21127 | return sema.addConstant(val); |
| 21168 | } | 21128 | } |
| 21169 | | 21129 | |
| 21170 | if (operand_scalar_ty.zigTypeTag(mod) != .ComptimeInt) { | 21130 | if (operand_scalar_ty.zigTypeTag(mod) != .ComptimeInt) { |
| 21171 | const operand_info = operand_ty.intInfo(mod); | 21131 | const operand_info = operand_ty.intInfo(mod); |
| 21172 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { | 21132 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 21173 | return sema.addConstant(operand_ty, val); | 21133 | return sema.addConstant(val); |
| 21174 | } | 21134 | } |
| 21175 | | 21135 | |
| 21176 | if (operand_info.signedness != dest_info.signedness) { | 21136 | if (operand_info.signedness != dest_info.signedness) { |
| ... | @@ -21202,7 +21162,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21202,7 +21162,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21202 | if (try sema.resolveMaybeUndefValIntable(operand)) |val| { | 21162 | if (try sema.resolveMaybeUndefValIntable(operand)) |val| { |
| 21203 | if (val.isUndef(mod)) return sema.addConstUndef(dest_ty); | 21163 | if (val.isUndef(mod)) return sema.addConstUndef(dest_ty); |
| 21204 | if (!is_vector) { | 21164 | if (!is_vector) { |
| 21205 | return sema.addConstant(dest_ty, try mod.getCoerced( | 21165 | return sema.addConstant(try mod.getCoerced( |
| 21206 | try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, mod), | 21166 | try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, mod), |
| 21207 | dest_ty, | 21167 | dest_ty, |
| 21208 | )); | 21168 | )); |
| ... | @@ -21212,7 +21172,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21212,7 +21172,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21212 | const elem_val = try val.elemValue(mod, i); | 21172 | const elem_val = try val.elemValue(mod, i); |
| 21213 | elem.* = try (try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, mod)).intern(dest_scalar_ty, mod); | 21173 | elem.* = try (try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, mod)).intern(dest_scalar_ty, mod); |
| 21214 | } | 21174 | } |
| 21215 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ | 21175 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 21216 | .ty = dest_ty.toIntern(), | 21176 | .ty = dest_ty.toIntern(), |
| 21217 | .storage = .{ .elems = elems }, | 21177 | .storage = .{ .elems = elems }, |
| 21218 | } })).toValue()); | 21178 | } })).toValue()); |
| ... | @@ -21248,7 +21208,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -21248,7 +21208,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21248 | return sema.fail(block, ptr_src, "pointer address 0x{X} is not aligned to {d} bytes", .{ addr, dest_align_bytes }); | 21208 | return sema.fail(block, ptr_src, "pointer address 0x{X} is not aligned to {d} bytes", .{ addr, dest_align_bytes }); |
| 21249 | } | 21209 | } |
| 21250 | } | 21210 | } |
| 21251 | return sema.addConstant(dest_ty, try mod.getCoerced(val, dest_ty)); | 21211 | return sema.addConstant(try mod.getCoerced(val, dest_ty)); |
| 21252 | } | 21212 | } |
| 21253 | | 21213 | |
| 21254 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); | 21214 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| ... | @@ -21256,7 +21216,6 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -21256,7 +21216,6 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21256 | try sema.typeHasRuntimeBits(ptr_info.child.toType())) | 21216 | try sema.typeHasRuntimeBits(ptr_info.child.toType())) |
| 21257 | { | 21217 | { |
| 21258 | const align_minus_1 = try sema.addConstant( | 21218 | const align_minus_1 = try sema.addConstant( |
| 21259 | Type.usize, | | |
| 21260 | try mod.intValue(Type.usize, dest_align.toByteUnitsOptional().? - 1), | 21219 | try mod.intValue(Type.usize, dest_align.toByteUnitsOptional().? - 1), |
| 21261 | ); | 21220 | ); |
| 21262 | const actual_ptr = if (ptr_ty.isSlice(mod)) | 21221 | const actual_ptr = if (ptr_ty.isSlice(mod)) |
| ... | @@ -21293,7 +21252,7 @@ fn zirBitCount( | ... | @@ -21293,7 +21252,7 @@ fn zirBitCount( |
| 21293 | const bits = operand_ty.intInfo(mod).bits; | 21252 | const bits = operand_ty.intInfo(mod).bits; |
| 21294 | | 21253 | |
| 21295 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { | 21254 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 21296 | return sema.addConstant(operand_ty, val); | 21255 | return sema.addConstant(val); |
| 21297 | } | 21256 | } |
| 21298 | | 21257 | |
| 21299 | const result_scalar_ty = try mod.smallestUnsignedInt(bits); | 21258 | const result_scalar_ty = try mod.smallestUnsignedInt(bits); |
| ... | @@ -21314,7 +21273,7 @@ fn zirBitCount( | ... | @@ -21314,7 +21273,7 @@ fn zirBitCount( |
| 21314 | const count = comptimeOp(elem_val, scalar_ty, mod); | 21273 | const count = comptimeOp(elem_val, scalar_ty, mod); |
| 21315 | elem.* = (try mod.intValue(result_scalar_ty, count)).toIntern(); | 21274 | elem.* = (try mod.intValue(result_scalar_ty, count)).toIntern(); |
| 21316 | } | 21275 | } |
| 21317 | return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{ | 21276 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 21318 | .ty = result_ty.toIntern(), | 21277 | .ty = result_ty.toIntern(), |
| 21319 | .storage = .{ .elems = elems }, | 21278 | .storage = .{ .elems = elems }, |
| 21320 | } })).toValue()); | 21279 | } })).toValue()); |
| ... | @@ -21355,7 +21314,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21355,7 +21314,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21355 | } | 21314 | } |
| 21356 | | 21315 | |
| 21357 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { | 21316 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 21358 | return sema.addConstant(operand_ty, val); | 21317 | return sema.addConstant(val); |
| 21359 | } | 21318 | } |
| 21360 | | 21319 | |
| 21361 | switch (operand_ty.zigTypeTag(mod)) { | 21320 | switch (operand_ty.zigTypeTag(mod)) { |
| ... | @@ -21363,7 +21322,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21363,7 +21322,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21363 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 21322 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 21364 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); | 21323 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); |
| 21365 | const result_val = try val.byteSwap(operand_ty, mod, sema.arena); | 21324 | const result_val = try val.byteSwap(operand_ty, mod, sema.arena); |
| 21366 | return sema.addConstant(operand_ty, result_val); | 21325 | return sema.addConstant(result_val); |
| 21367 | } else operand_src; | 21326 | } else operand_src; |
| 21368 | | 21327 | |
| 21369 | try sema.requireRuntimeBlock(block, src, runtime_src); | 21328 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -21380,7 +21339,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21380,7 +21339,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21380 | const elem_val = try val.elemValue(mod, i); | 21339 | const elem_val = try val.elemValue(mod, i); |
| 21381 | elem.* = try (try elem_val.byteSwap(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod); | 21340 | elem.* = try (try elem_val.byteSwap(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod); |
| 21382 | } | 21341 | } |
| 21383 | return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{ | 21342 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 21384 | .ty = operand_ty.toIntern(), | 21343 | .ty = operand_ty.toIntern(), |
| 21385 | .storage = .{ .elems = elems }, | 21344 | .storage = .{ .elems = elems }, |
| 21386 | } })).toValue()); | 21345 | } })).toValue()); |
| ... | @@ -21402,7 +21361,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -21402,7 +21361,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 21402 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); | 21361 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| 21403 | | 21362 | |
| 21404 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { | 21363 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 21405 | return sema.addConstant(operand_ty, val); | 21364 | return sema.addConstant(val); |
| 21406 | } | 21365 | } |
| 21407 | | 21366 | |
| 21408 | const mod = sema.mod; | 21367 | const mod = sema.mod; |
| ... | @@ -21411,7 +21370,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -21411,7 +21370,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 21411 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { | 21370 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 21412 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); | 21371 | if (val.isUndef(mod)) return sema.addConstUndef(operand_ty); |
| 21413 | const result_val = try val.bitReverse(operand_ty, mod, sema.arena); | 21372 | const result_val = try val.bitReverse(operand_ty, mod, sema.arena); |
| 21414 | return sema.addConstant(operand_ty, result_val); | 21373 | return sema.addConstant(result_val); |
| 21415 | } else operand_src; | 21374 | } else operand_src; |
| 21416 | | 21375 | |
| 21417 | try sema.requireRuntimeBlock(block, src, runtime_src); | 21376 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -21428,7 +21387,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -21428,7 +21387,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 21428 | const elem_val = try val.elemValue(mod, i); | 21387 | const elem_val = try val.elemValue(mod, i); |
| 21429 | elem.* = try (try elem_val.bitReverse(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod); | 21388 | elem.* = try (try elem_val.bitReverse(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod); |
| 21430 | } | 21389 | } |
| 21431 | return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{ | 21390 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 21432 | .ty = operand_ty.toIntern(), | 21391 | .ty = operand_ty.toIntern(), |
| 21433 | .storage = .{ .elems = elems }, | 21392 | .storage = .{ .elems = elems }, |
| 21434 | } })).toValue()); | 21393 | } })).toValue()); |
| ... | @@ -22081,7 +22040,7 @@ fn zirCmpxchg( | ... | @@ -22081,7 +22040,7 @@ fn zirCmpxchg( |
| 22081 | | 22040 | |
| 22082 | // special case zero bit types | 22041 | // special case zero bit types |
| 22083 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) { | 22042 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) { |
| 22084 | return sema.addConstant(result_ty, (try mod.intern(.{ .opt = .{ | 22043 | return sema.addConstant((try mod.intern(.{ .opt = .{ |
| 22085 | .ty = result_ty.toIntern(), | 22044 | .ty = result_ty.toIntern(), |
| 22086 | .val = .none, | 22045 | .val = .none, |
| 22087 | } })).toValue()); | 22046 | } })).toValue()); |
| ... | @@ -22104,7 +22063,7 @@ fn zirCmpxchg( | ... | @@ -22104,7 +22063,7 @@ fn zirCmpxchg( |
| 22104 | break :blk .none; | 22063 | break :blk .none; |
| 22105 | } else stored_val.toIntern(), | 22064 | } else stored_val.toIntern(), |
| 22106 | } }); | 22065 | } }); |
| 22107 | return sema.addConstant(result_ty, result_val.toValue()); | 22066 | return sema.addConstant(result_val.toValue()); |
| 22108 | } else break :rs new_value_src; | 22067 | } else break :rs new_value_src; |
| 22109 | } else break :rs expected_src; | 22068 | } else break :rs expected_src; |
| 22110 | } else ptr_src; | 22069 | } else ptr_src; |
| ... | @@ -22143,7 +22102,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -22143,7 +22102,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 22143 | }); | 22102 | }); |
| 22144 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { | 22103 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { |
| 22145 | if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty); | 22104 | if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty); |
| 22146 | return sema.addConstant(vector_ty, try sema.splat(vector_ty, scalar_val)); | 22105 | return sema.addConstant(try sema.splat(vector_ty, scalar_val)); |
| 22147 | } | 22106 | } |
| 22148 | | 22107 | |
| 22149 | try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src); | 22108 | try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src); |
| ... | @@ -22206,7 +22165,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -22206,7 +22165,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22206 | .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, mod), | 22165 | .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, mod), |
| 22207 | } | 22166 | } |
| 22208 | } | 22167 | } |
| 22209 | return sema.addConstant(scalar_ty, accum); | 22168 | return sema.addConstant(accum); |
| 22210 | } | 22169 | } |
| 22211 | | 22170 | |
| 22212 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 22171 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| ... | @@ -22353,7 +22312,7 @@ fn analyzeShuffle( | ... | @@ -22353,7 +22312,7 @@ fn analyzeShuffle( |
| 22353 | const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int); | 22312 | const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int); |
| 22354 | values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod); | 22313 | values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod); |
| 22355 | } | 22314 | } |
| 22356 | return sema.addConstant(res_ty, (try mod.intern(.{ .aggregate = .{ | 22315 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 22357 | .ty = res_ty.toIntern(), | 22316 | .ty = res_ty.toIntern(), |
| 22358 | .storage = .{ .elems = values }, | 22317 | .storage = .{ .elems = values }, |
| 22359 | } })).toValue()); | 22318 | } })).toValue()); |
| ... | @@ -22459,7 +22418,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -22459,7 +22418,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22459 | elem.* = try (try (if (should_choose_a) a_val else b_val).elemValue(mod, i)).intern(elem_ty, mod); | 22418 | elem.* = try (try (if (should_choose_a) a_val else b_val).elemValue(mod, i)).intern(elem_ty, mod); |
| 22460 | } | 22419 | } |
| 22461 | | 22420 | |
| 22462 | return sema.addConstant(vec_ty, (try mod.intern(.{ .aggregate = .{ | 22421 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 22463 | .ty = vec_ty.toIntern(), | 22422 | .ty = vec_ty.toIntern(), |
| 22464 | .storage = .{ .elems = elems }, | 22423 | .storage = .{ .elems = elems }, |
| 22465 | } })).toValue()); | 22424 | } })).toValue()); |
| ... | @@ -22521,12 +22480,12 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22521,12 +22480,12 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22521 | } | 22480 | } |
| 22522 | | 22481 | |
| 22523 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { | 22482 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { |
| 22524 | return sema.addConstant(elem_ty, val); | 22483 | return sema.addConstant(val); |
| 22525 | } | 22484 | } |
| 22526 | | 22485 | |
| 22527 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { | 22486 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 22528 | if (try sema.pointerDeref(block, ptr_src, ptr_val, sema.typeOf(ptr))) |elem_val| { | 22487 | if (try sema.pointerDeref(block, ptr_src, ptr_val, sema.typeOf(ptr))) |elem_val| { |
| 22529 | return sema.addConstant(elem_ty, elem_val); | 22488 | return sema.addConstant(elem_val); |
| 22530 | } | 22489 | } |
| 22531 | } | 22490 | } |
| 22532 | | 22491 | |
| ... | @@ -22579,7 +22538,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22579,7 +22538,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22579 | | 22538 | |
| 22580 | // special case zero bit types | 22539 | // special case zero bit types |
| 22581 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { | 22540 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { |
| 22582 | return sema.addConstant(elem_ty, val); | 22541 | return sema.addConstant(val); |
| 22583 | } | 22542 | } |
| 22584 | | 22543 | |
| 22585 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 22544 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| ... | @@ -22605,7 +22564,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -22605,7 +22564,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 22605 | // zig fmt: on | 22564 | // zig fmt: on |
| 22606 | }; | 22565 | }; |
| 22607 | try sema.storePtrVal(block, src, ptr_val, new_val, elem_ty); | 22566 | try sema.storePtrVal(block, src, ptr_val, new_val, elem_ty); |
| 22608 | return sema.addConstant(elem_ty, stored_val); | 22567 | return sema.addConstant(stored_val); |
| 22609 | } else break :rs ptr_src; | 22568 | } else break :rs ptr_src; |
| 22610 | } else ptr_src; | 22569 | } else ptr_src; |
| 22611 | | 22570 | |
| ... | @@ -22689,7 +22648,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -22689,7 +22648,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22689 | if (maybe_addend) |addend_val| { | 22648 | if (maybe_addend) |addend_val| { |
| 22690 | if (addend_val.isUndef(mod)) return sema.addConstUndef(ty); | 22649 | if (addend_val.isUndef(mod)) return sema.addConstUndef(ty); |
| 22691 | const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod); | 22650 | const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod); |
| 22692 | return sema.addConstant(ty, result_val); | 22651 | return sema.addConstant(result_val); |
| 22693 | } else { | 22652 | } else { |
| 22694 | break :rs addend_src; | 22653 | break :rs addend_src; |
| 22695 | } | 22654 | } |
| ... | @@ -22899,7 +22858,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -22899,7 +22858,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22899 | }; | 22858 | }; |
| 22900 | return sema.failWithOwnedErrorMsg(msg); | 22859 | return sema.failWithOwnedErrorMsg(msg); |
| 22901 | } | 22860 | } |
| 22902 | return sema.addConstant(result_ptr, field.base.toValue()); | 22861 | return sema.addConstant(field.base.toValue()); |
| 22903 | } | 22862 | } |
| 22904 | | 22863 | |
| 22905 | try sema.requireRuntimeBlock(block, src, ptr_src); | 22864 | try sema.requireRuntimeBlock(block, src, ptr_src); |
| ... | @@ -23057,7 +23016,7 @@ fn analyzeMinMax( | ... | @@ -23057,7 +23016,7 @@ fn analyzeMinMax( |
| 23057 | | 23016 | |
| 23058 | const vec_len = simd_op.len orelse { | 23017 | const vec_len = simd_op.len orelse { |
| 23059 | const result_val = opFunc(cur_val, operand_val, mod); | 23018 | const result_val = opFunc(cur_val, operand_val, mod); |
| 23060 | cur_minmax = try sema.addConstant(simd_op.result_ty, result_val); | 23019 | cur_minmax = try sema.addConstant(result_val); |
| 23061 | continue; | 23020 | continue; |
| 23062 | }; | 23021 | }; |
| 23063 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); | 23022 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| ... | @@ -23067,7 +23026,7 @@ fn analyzeMinMax( | ... | @@ -23067,7 +23026,7 @@ fn analyzeMinMax( |
| 23067 | const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, mod); | 23026 | const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, mod); |
| 23068 | elem.* = (try mod.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern(); | 23027 | elem.* = (try mod.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern(); |
| 23069 | } | 23028 | } |
| 23070 | cur_minmax = try sema.addConstant(simd_op.result_ty, (try mod.intern(.{ .aggregate = .{ | 23029 | cur_minmax = try sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 23071 | .ty = simd_op.result_ty.toIntern(), | 23030 | .ty = simd_op.result_ty.toIntern(), |
| 23072 | .storage = .{ .elems = elems }, | 23031 | .storage = .{ .elems = elems }, |
| 23073 | } })).toValue()); | 23032 | } })).toValue()); |
| ... | @@ -23384,7 +23343,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -23384,7 +23343,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 23384 | // Aliasing safety check. | 23343 | // Aliasing safety check. |
| 23385 | if (block.wantSafety()) { | 23344 | if (block.wantSafety()) { |
| 23386 | const len = if (len_val) |v| | 23345 | const len = if (len_val) |v| |
| 23387 | try sema.addConstant(Type.usize, v) | 23346 | try sema.addConstant(v) |
| 23388 | else if (dest_len != .none) | 23347 | else if (dest_len != .none) |
| 23389 | dest_len | 23348 | dest_len |
| 23390 | else | 23349 | else |
| ... | @@ -23584,7 +23543,7 @@ fn zirVarExtended( | ... | @@ -23584,7 +23543,7 @@ fn zirVarExtended( |
| 23584 | | 23543 | |
| 23585 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); | 23544 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); |
| 23586 | | 23545 | |
| 23587 | return sema.addConstant(var_ty, (try mod.intern(.{ .variable = .{ | 23546 | return sema.addConstant((try mod.intern(.{ .variable = .{ |
| 23588 | .ty = var_ty.toIntern(), | 23547 | .ty = var_ty.toIntern(), |
| 23589 | .init = init_val, | 23548 | .init = init_val, |
| 23590 | .decl = sema.owner_decl_index, | 23549 | .decl = sema.owner_decl_index, |
| ... | @@ -24092,7 +24051,7 @@ fn zirBuiltinExtern( | ... | @@ -24092,7 +24051,7 @@ fn zirBuiltinExtern( |
| 24092 | try mod.declareDeclDependency(sema.owner_decl_index, new_decl_index); | 24051 | try mod.declareDeclDependency(sema.owner_decl_index, new_decl_index); |
| 24093 | try sema.ensureDeclAnalyzed(new_decl_index); | 24052 | try sema.ensureDeclAnalyzed(new_decl_index); |
| 24094 | | 24053 | |
| 24095 | return sema.addConstant(ty, try mod.getCoerced((try mod.intern(.{ .ptr = .{ | 24054 | return sema.addConstant(try mod.getCoerced((try mod.intern(.{ .ptr = .{ |
| 24096 | .ty = switch (mod.intern_pool.indexToKey(ty.toIntern())) { | 24055 | .ty = switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 24097 | .ptr_type => ty.toIntern(), | 24056 | .ptr_type => ty.toIntern(), |
| 24098 | .opt_type => |child_type| child_type, | 24057 | .opt_type => |child_type| child_type, |
| ... | @@ -24736,13 +24695,13 @@ fn panicWithMsg( | ... | @@ -24736,13 +24695,13 @@ fn panicWithMsg( |
| 24736 | }, | 24695 | }, |
| 24737 | }); | 24696 | }); |
| 24738 | const opt_ptr_stack_trace_ty = try mod.optionalType(ptr_stack_trace_ty.toIntern()); | 24697 | const opt_ptr_stack_trace_ty = try mod.optionalType(ptr_stack_trace_ty.toIntern()); |
| 24739 | const null_stack_trace = try sema.addConstant(opt_ptr_stack_trace_ty, (try mod.intern(.{ .opt = .{ | 24698 | const null_stack_trace = try sema.addConstant((try mod.intern(.{ .opt = .{ |
| 24740 | .ty = opt_ptr_stack_trace_ty.toIntern(), | 24699 | .ty = opt_ptr_stack_trace_ty.toIntern(), |
| 24741 | .val = .none, | 24700 | .val = .none, |
| 24742 | } })).toValue()); | 24701 | } })).toValue()); |
| 24743 | | 24702 | |
| 24744 | const opt_usize_ty = try mod.optionalType(.usize_type); | 24703 | const opt_usize_ty = try mod.optionalType(.usize_type); |
| 24745 | const null_ret_addr = try sema.addConstant(opt_usize_ty, (try mod.intern(.{ .opt = .{ | 24704 | const null_ret_addr = try sema.addConstant((try mod.intern(.{ .opt = .{ |
| 24746 | .ty = opt_usize_ty.toIntern(), | 24705 | .ty = opt_usize_ty.toIntern(), |
| 24747 | .val = .none, | 24706 | .val = .none, |
| 24748 | } })).toValue()); | 24707 | } })).toValue()); |
| ... | @@ -24830,7 +24789,7 @@ fn panicSentinelMismatch( | ... | @@ -24830,7 +24789,7 @@ fn panicSentinelMismatch( |
| 24830 | assert(!parent_block.is_comptime); | 24789 | assert(!parent_block.is_comptime); |
| 24831 | const mod = sema.mod; | 24790 | const mod = sema.mod; |
| 24832 | const expected_sentinel_val = maybe_sentinel orelse return; | 24791 | const expected_sentinel_val = maybe_sentinel orelse return; |
| 24833 | const expected_sentinel = try sema.addConstant(sentinel_ty, expected_sentinel_val); | 24792 | const expected_sentinel = try sema.addConstant(expected_sentinel_val); |
| 24834 | | 24793 | |
| 24835 | const ptr_ty = sema.typeOf(ptr); | 24794 | const ptr_ty = sema.typeOf(ptr); |
| 24836 | const actual_sentinel = if (ptr_ty.isSlice(mod)) | 24795 | const actual_sentinel = if (ptr_ty.isSlice(mod)) |
| ... | @@ -24967,7 +24926,6 @@ fn fieldVal( | ... | @@ -24967,7 +24926,6 @@ fn fieldVal( |
| 24967 | .Array => { | 24926 | .Array => { |
| 24968 | if (ip.stringEqlSlice(field_name, "len")) { | 24927 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24969 | return sema.addConstant( | 24928 | return sema.addConstant( |
| 24970 | Type.usize, | | |
| 24971 | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), | 24929 | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), |
| 24972 | ); | 24930 | ); |
| 24973 | } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) { | 24931 | } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) { |
| ... | @@ -25059,7 +25017,7 @@ fn fieldVal( | ... | @@ -25059,7 +25017,7 @@ fn fieldVal( |
| 25059 | child_type | 25017 | child_type |
| 25060 | else | 25018 | else |
| 25061 | try mod.singleErrorSetType(field_name); | 25019 | try mod.singleErrorSetType(field_name); |
| 25062 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 25020 | return sema.addConstant((try mod.intern(.{ .err = .{ |
| 25063 | .ty = error_set_type.toIntern(), | 25021 | .ty = error_set_type.toIntern(), |
| 25064 | .name = field_name, | 25022 | .name = field_name, |
| 25065 | } })).toValue()); | 25023 | } })).toValue()); |
| ... | @@ -25075,7 +25033,6 @@ fn fieldVal( | ... | @@ -25075,7 +25033,6 @@ fn fieldVal( |
| 25075 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| { | 25033 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| { |
| 25076 | const field_index = @intCast(u32, field_index_usize); | 25034 | const field_index = @intCast(u32, field_index_usize); |
| 25077 | return sema.addConstant( | 25035 | return sema.addConstant( |
| 25078 | enum_ty, | | |
| 25079 | try mod.enumValueFieldIndex(enum_ty, field_index), | 25036 | try mod.enumValueFieldIndex(enum_ty, field_index), |
| 25080 | ); | 25037 | ); |
| 25081 | } | 25038 | } |
| ... | @@ -25092,7 +25049,7 @@ fn fieldVal( | ... | @@ -25092,7 +25049,7 @@ fn fieldVal( |
| 25092 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 25049 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 25093 | const field_index = @intCast(u32, field_index_usize); | 25050 | const field_index = @intCast(u32, field_index_usize); |
| 25094 | const enum_val = try mod.enumValueFieldIndex(child_type, field_index); | 25051 | const enum_val = try mod.enumValueFieldIndex(child_type, field_index); |
| 25095 | return sema.addConstant(child_type, enum_val); | 25052 | return sema.addConstant(enum_val); |
| 25096 | }, | 25053 | }, |
| 25097 | .Struct, .Opaque => { | 25054 | .Struct, .Opaque => { |
| 25098 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { | 25055 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | @@ -25204,7 +25161,7 @@ fn fieldPtr( | ... | @@ -25204,7 +25161,7 @@ fn fieldPtr( |
| 25204 | }); | 25161 | }); |
| 25205 | | 25162 | |
| 25206 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { | 25163 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
| 25207 | return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{ | 25164 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 25208 | .ty = result_ty.toIntern(), | 25165 | .ty = result_ty.toIntern(), |
| 25209 | .addr = .{ .field = .{ | 25166 | .addr = .{ .field = .{ |
| 25210 | .base = val.toIntern(), | 25167 | .base = val.toIntern(), |
| ... | @@ -25226,7 +25183,7 @@ fn fieldPtr( | ... | @@ -25226,7 +25183,7 @@ fn fieldPtr( |
| 25226 | }); | 25183 | }); |
| 25227 | | 25184 | |
| 25228 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { | 25185 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
| 25229 | return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{ | 25186 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 25230 | .ty = result_ty.toIntern(), | 25187 | .ty = result_ty.toIntern(), |
| 25231 | .addr = .{ .field = .{ | 25188 | .addr = .{ .field = .{ |
| 25232 | .base = val.toIntern(), | 25189 | .base = val.toIntern(), |
| ... | @@ -25554,12 +25511,12 @@ fn finishFieldCallBind( | ... | @@ -25554,12 +25511,12 @@ fn finishFieldCallBind( |
| 25554 | const container_ty = ptr_ty.childType(mod); | 25511 | const container_ty = ptr_ty.childType(mod); |
| 25555 | if (container_ty.zigTypeTag(mod) == .Struct) { | 25512 | if (container_ty.zigTypeTag(mod) == .Struct) { |
| 25556 | if (try container_ty.structFieldValueComptime(mod, field_index)) |default_val| { | 25513 | if (try container_ty.structFieldValueComptime(mod, field_index)) |default_val| { |
| 25557 | return .{ .direct = try sema.addConstant(field_ty, default_val) }; | 25514 | return .{ .direct = try sema.addConstant(default_val) }; |
| 25558 | } | 25515 | } |
| 25559 | } | 25516 | } |
| 25560 | | 25517 | |
| 25561 | if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| { | 25518 | if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| { |
| 25562 | const pointer = try sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ | 25519 | const pointer = try sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 25563 | .ty = ptr_field_ty.toIntern(), | 25520 | .ty = ptr_field_ty.toIntern(), |
| 25564 | .addr = .{ .field = .{ | 25521 | .addr = .{ .field = .{ |
| 25565 | .base = struct_ptr_val.toIntern(), | 25522 | .base = struct_ptr_val.toIntern(), |
| ... | @@ -25749,7 +25706,7 @@ fn structFieldPtrByIndex( | ... | @@ -25749,7 +25706,7 @@ fn structFieldPtrByIndex( |
| 25749 | .ty = ptr_field_ty.toIntern(), | 25706 | .ty = ptr_field_ty.toIntern(), |
| 25750 | .addr = .{ .comptime_field = field.default_val }, | 25707 | .addr = .{ .comptime_field = field.default_val }, |
| 25751 | } }); | 25708 | } }); |
| 25752 | return sema.addConstant(ptr_field_ty, val.toValue()); | 25709 | return sema.addConstant(val.toValue()); |
| 25753 | } | 25710 | } |
| 25754 | | 25711 | |
| 25755 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { | 25712 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { |
| ... | @@ -25760,7 +25717,7 @@ fn structFieldPtrByIndex( | ... | @@ -25760,7 +25717,7 @@ fn structFieldPtrByIndex( |
| 25760 | .index = field_index, | 25717 | .index = field_index, |
| 25761 | } }, | 25718 | } }, |
| 25762 | } }); | 25719 | } }); |
| 25763 | return sema.addConstant(ptr_field_ty, val.toValue()); | 25720 | return sema.addConstant(val.toValue()); |
| 25764 | } | 25721 | } |
| 25765 | | 25722 | |
| 25766 | try sema.requireRuntimeBlock(block, src, null); | 25723 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -25791,15 +25748,15 @@ fn structFieldVal( | ... | @@ -25791,15 +25748,15 @@ fn structFieldVal( |
| 25791 | const field = struct_obj.fields.values()[field_index]; | 25748 | const field = struct_obj.fields.values()[field_index]; |
| 25792 | | 25749 | |
| 25793 | if (field.is_comptime) { | 25750 | if (field.is_comptime) { |
| 25794 | return sema.addConstant(field.ty, field.default_val.toValue()); | 25751 | return sema.addConstant(field.default_val.toValue()); |
| 25795 | } | 25752 | } |
| 25796 | | 25753 | |
| 25797 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { | 25754 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| 25798 | if (struct_val.isUndef(mod)) return sema.addConstUndef(field.ty); | 25755 | if (struct_val.isUndef(mod)) return sema.addConstUndef(field.ty); |
| 25799 | if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| { | 25756 | if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| { |
| 25800 | return sema.addConstant(field.ty, opv); | 25757 | return sema.addConstant(opv); |
| 25801 | } | 25758 | } |
| 25802 | return sema.addConstant(field.ty, try struct_val.fieldValue(mod, field_index)); | 25759 | return sema.addConstant(try struct_val.fieldValue(mod, field_index)); |
| 25803 | } | 25760 | } |
| 25804 | | 25761 | |
| 25805 | try sema.requireRuntimeBlock(block, src, null); | 25762 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -25868,16 +25825,16 @@ fn tupleFieldValByIndex( | ... | @@ -25868,16 +25825,16 @@ fn tupleFieldValByIndex( |
| 25868 | const field_ty = tuple_ty.structFieldType(field_index, mod); | 25825 | const field_ty = tuple_ty.structFieldType(field_index, mod); |
| 25869 | | 25826 | |
| 25870 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_value| { | 25827 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_value| { |
| 25871 | return sema.addConstant(field_ty, default_value); | 25828 | return sema.addConstant(default_value); |
| 25872 | } | 25829 | } |
| 25873 | | 25830 | |
| 25874 | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { | 25831 | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { |
| 25875 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { | 25832 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { |
| 25876 | return sema.addConstant(field_ty, opv); | 25833 | return sema.addConstant(opv); |
| 25877 | } | 25834 | } |
| 25878 | return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) { | 25835 | return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) { |
| 25879 | .undef => sema.addConstUndef(field_ty), | 25836 | .undef => sema.addConstUndef(field_ty), |
| 25880 | .aggregate => |aggregate| sema.addConstant(field_ty, switch (aggregate.storage) { | 25837 | .aggregate => |aggregate| sema.addConstant(switch (aggregate.storage) { |
| 25881 | .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]), | 25838 | .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]), |
| 25882 | .elems => |elems| elems[field_index].toValue(), | 25839 | .elems => |elems| elems[field_index].toValue(), |
| 25883 | .repeated_elem => |elem| elem.toValue(), | 25840 | .repeated_elem => |elem| elem.toValue(), |
| ... | @@ -25887,7 +25844,7 @@ fn tupleFieldValByIndex( | ... | @@ -25887,7 +25844,7 @@ fn tupleFieldValByIndex( |
| 25887 | } | 25844 | } |
| 25888 | | 25845 | |
| 25889 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| { | 25846 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| { |
| 25890 | return sema.addConstant(field_ty, default_val); | 25847 | return sema.addConstant(default_val); |
| 25891 | } | 25848 | } |
| 25892 | | 25849 | |
| 25893 | try sema.requireRuntimeBlock(block, src, null); | 25850 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -25966,7 +25923,7 @@ fn unionFieldPtr( | ... | @@ -25966,7 +25923,7 @@ fn unionFieldPtr( |
| 25966 | }, | 25923 | }, |
| 25967 | .Packed, .Extern => {}, | 25924 | .Packed, .Extern => {}, |
| 25968 | } | 25925 | } |
| 25969 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ | 25926 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 25970 | .ty = ptr_field_ty.toIntern(), | 25927 | .ty = ptr_field_ty.toIntern(), |
| 25971 | .addr = .{ .field = .{ | 25928 | .addr = .{ .field = .{ |
| 25972 | .base = union_ptr_val.toIntern(), | 25929 | .base = union_ptr_val.toIntern(), |
| ... | @@ -25980,7 +25937,7 @@ fn unionFieldPtr( | ... | @@ -25980,7 +25937,7 @@ fn unionFieldPtr( |
| 25980 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) | 25937 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) |
| 25981 | { | 25938 | { |
| 25982 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); | 25939 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25983 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 25940 | const wanted_tag = try sema.addConstant(wanted_tag_val); |
| 25984 | // TODO would it be better if get_union_tag supported pointers to unions? | 25941 | // TODO would it be better if get_union_tag supported pointers to unions? |
| 25985 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); | 25942 | const union_val = try block.addTyOp(.load, union_ty, union_ptr); |
| 25986 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_val); | 25943 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_val); |
| ... | @@ -26021,7 +25978,7 @@ fn unionFieldVal( | ... | @@ -26021,7 +25978,7 @@ fn unionFieldVal( |
| 26021 | switch (union_obj.layout) { | 25978 | switch (union_obj.layout) { |
| 26022 | .Auto => { | 25979 | .Auto => { |
| 26023 | if (tag_matches) { | 25980 | if (tag_matches) { |
| 26024 | return sema.addConstant(field.ty, un.val.toValue()); | 25981 | return sema.addConstant(un.val.toValue()); |
| 26025 | } else { | 25982 | } else { |
| 26026 | const msg = msg: { | 25983 | const msg = msg: { |
| 26027 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; | 25984 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| ... | @@ -26038,11 +25995,11 @@ fn unionFieldVal( | ... | @@ -26038,11 +25995,11 @@ fn unionFieldVal( |
| 26038 | }, | 25995 | }, |
| 26039 | .Packed, .Extern => { | 25996 | .Packed, .Extern => { |
| 26040 | if (tag_matches) { | 25997 | if (tag_matches) { |
| 26041 | return sema.addConstant(field.ty, un.val.toValue()); | 25998 | return sema.addConstant(un.val.toValue()); |
| 26042 | } else { | 25999 | } else { |
| 26043 | const old_ty = union_ty.unionFieldType(un.tag.toValue(), mod); | 26000 | const old_ty = union_ty.unionFieldType(un.tag.toValue(), mod); |
| 26044 | if (try sema.bitCastVal(block, src, un.val.toValue(), old_ty, field.ty, 0)) |new_val| { | 26001 | if (try sema.bitCastVal(block, src, un.val.toValue(), old_ty, field.ty, 0)) |new_val| { |
| 26045 | return sema.addConstant(field.ty, new_val); | 26002 | return sema.addConstant(new_val); |
| 26046 | } | 26003 | } |
| 26047 | } | 26004 | } |
| 26048 | }, | 26005 | }, |
| ... | @@ -26054,7 +26011,7 @@ fn unionFieldVal( | ... | @@ -26054,7 +26011,7 @@ fn unionFieldVal( |
| 26054 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) | 26011 | union_ty.unionTagTypeSafety(mod) != null and union_obj.fields.count() > 1) |
| 26055 | { | 26012 | { |
| 26056 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); | 26013 | const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 26057 | const wanted_tag = try sema.addConstant(union_obj.tag_ty, wanted_tag_val); | 26014 | const wanted_tag = try sema.addConstant(wanted_tag_val); |
| 26058 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); | 26015 | const active_tag = try block.addTyOp(.get_union_tag, union_obj.tag_ty, union_byval); |
| 26059 | try sema.panicInactiveUnionField(block, active_tag, wanted_tag); | 26016 | try sema.panicInactiveUnionField(block, active_tag, wanted_tag); |
| 26060 | } | 26017 | } |
| ... | @@ -26128,7 +26085,7 @@ fn elemPtrOneLayerOnly( | ... | @@ -26128,7 +26085,7 @@ fn elemPtrOneLayerOnly( |
| 26128 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); | 26085 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); |
| 26129 | const result_ty = try sema.elemPtrType(indexable_ty, index); | 26086 | const result_ty = try sema.elemPtrType(indexable_ty, index); |
| 26130 | const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod); | 26087 | const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod); |
| 26131 | return sema.addConstant(result_ty, elem_ptr); | 26088 | return sema.addConstant(elem_ptr); |
| 26132 | }; | 26089 | }; |
| 26133 | const result_ty = try sema.elemPtrType(indexable_ty, null); | 26090 | const result_ty = try sema.elemPtrType(indexable_ty, null); |
| 26134 | | 26091 | |
| ... | @@ -26189,7 +26146,7 @@ fn elemVal( | ... | @@ -26189,7 +26146,7 @@ fn elemVal( |
| 26189 | const elem_ptr_ty = try mod.singleConstPtrType(elem_ty); | 26146 | const elem_ptr_ty = try mod.singleConstPtrType(elem_ty); |
| 26190 | const elem_ptr_val = try many_ptr_val.elemPtr(elem_ptr_ty, index, mod); | 26147 | const elem_ptr_val = try many_ptr_val.elemPtr(elem_ptr_ty, index, mod); |
| 26191 | if (try sema.pointerDeref(block, indexable_src, elem_ptr_val, elem_ptr_ty)) |elem_val| { | 26148 | if (try sema.pointerDeref(block, indexable_src, elem_ptr_val, elem_ptr_ty)) |elem_val| { |
| 26192 | return sema.addConstant(elem_ty, try mod.getCoerced(elem_val, elem_ty)); | 26149 | return sema.addConstant(try mod.getCoerced(elem_val, elem_ty)); |
| 26193 | } | 26150 | } |
| 26194 | break :rs indexable_src; | 26151 | break :rs indexable_src; |
| 26195 | }; | 26152 | }; |
| ... | @@ -26205,7 +26162,7 @@ fn elemVal( | ... | @@ -26205,7 +26162,7 @@ fn elemVal( |
| 26205 | const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent; | 26162 | const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent; |
| 26206 | const index = try sema.usizeCast(block, src, index_val.toUnsignedInt(mod)); | 26163 | const index = try sema.usizeCast(block, src, index_val.toUnsignedInt(mod)); |
| 26207 | if (index != inner_ty.arrayLen(mod)) break :arr_sent; | 26164 | if (index != inner_ty.arrayLen(mod)) break :arr_sent; |
| 26208 | return sema.addConstant(inner_ty.childType(mod), sentinel); | 26165 | return sema.addConstant(sentinel); |
| 26209 | } | 26166 | } |
| 26210 | const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety); | 26167 | const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety); |
| 26211 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); | 26168 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); |
| ... | @@ -26291,14 +26248,14 @@ fn tupleFieldPtr( | ... | @@ -26291,14 +26248,14 @@ fn tupleFieldPtr( |
| 26291 | }); | 26248 | }); |
| 26292 | | 26249 | |
| 26293 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| { | 26250 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| { |
| 26294 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ | 26251 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 26295 | .ty = ptr_field_ty.toIntern(), | 26252 | .ty = ptr_field_ty.toIntern(), |
| 26296 | .addr = .{ .comptime_field = default_val.toIntern() }, | 26253 | .addr = .{ .comptime_field = default_val.toIntern() }, |
| 26297 | } })).toValue()); | 26254 | } })).toValue()); |
| 26298 | } | 26255 | } |
| 26299 | | 26256 | |
| 26300 | if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| { | 26257 | if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| { |
| 26301 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ | 26258 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 26302 | .ty = ptr_field_ty.toIntern(), | 26259 | .ty = ptr_field_ty.toIntern(), |
| 26303 | .addr = .{ .field = .{ | 26260 | .addr = .{ .field = .{ |
| 26304 | .base = tuple_ptr_val.toIntern(), | 26261 | .base = tuple_ptr_val.toIntern(), |
| ... | @@ -26340,12 +26297,12 @@ fn tupleField( | ... | @@ -26340,12 +26297,12 @@ fn tupleField( |
| 26340 | const field_ty = tuple_ty.structFieldType(field_index, mod); | 26297 | const field_ty = tuple_ty.structFieldType(field_index, mod); |
| 26341 | | 26298 | |
| 26342 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_value| { | 26299 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_value| { |
| 26343 | return sema.addConstant(field_ty, default_value); // comptime field | 26300 | return sema.addConstant(default_value); // comptime field |
| 26344 | } | 26301 | } |
| 26345 | | 26302 | |
| 26346 | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { | 26303 | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { |
| 26347 | if (tuple_val.isUndef(mod)) return sema.addConstUndef(field_ty); | 26304 | if (tuple_val.isUndef(mod)) return sema.addConstUndef(field_ty); |
| 26348 | return sema.addConstant(field_ty, try tuple_val.fieldValue(mod, field_index)); | 26305 | return sema.addConstant(try tuple_val.fieldValue(mod, field_index)); |
| 26349 | } | 26306 | } |
| 26350 | | 26307 | |
| 26351 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src); | 26308 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src); |
| ... | @@ -26383,7 +26340,7 @@ fn elemValArray( | ... | @@ -26383,7 +26340,7 @@ fn elemValArray( |
| 26383 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); | 26340 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); |
| 26384 | if (array_sent) |s| { | 26341 | if (array_sent) |s| { |
| 26385 | if (index == array_len) { | 26342 | if (index == array_len) { |
| 26386 | return sema.addConstant(elem_ty, s); | 26343 | return sema.addConstant(s); |
| 26387 | } | 26344 | } |
| 26388 | } | 26345 | } |
| 26389 | if (index >= array_len_s) { | 26346 | if (index >= array_len_s) { |
| ... | @@ -26398,7 +26355,7 @@ fn elemValArray( | ... | @@ -26398,7 +26355,7 @@ fn elemValArray( |
| 26398 | if (maybe_index_val) |index_val| { | 26355 | if (maybe_index_val) |index_val| { |
| 26399 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); | 26356 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); |
| 26400 | const elem_val = try array_val.elemValue(mod, index); | 26357 | const elem_val = try array_val.elemValue(mod, index); |
| 26401 | return sema.addConstant(elem_ty, elem_val); | 26358 | return sema.addConstant(elem_val); |
| 26402 | } | 26359 | } |
| 26403 | } | 26360 | } |
| 26404 | | 26361 | |
| ... | @@ -26458,7 +26415,7 @@ fn elemPtrArray( | ... | @@ -26458,7 +26415,7 @@ fn elemPtrArray( |
| 26458 | } | 26415 | } |
| 26459 | if (offset) |index| { | 26416 | if (offset) |index| { |
| 26460 | const elem_ptr = try array_ptr_val.elemPtr(elem_ptr_ty, index, mod); | 26417 | const elem_ptr = try array_ptr_val.elemPtr(elem_ptr_ty, index, mod); |
| 26461 | return sema.addConstant(elem_ptr_ty, elem_ptr); | 26418 | return sema.addConstant(elem_ptr); |
| 26462 | } | 26419 | } |
| 26463 | } | 26420 | } |
| 26464 | | 26421 | |
| ... | @@ -26516,7 +26473,7 @@ fn elemValSlice( | ... | @@ -26516,7 +26473,7 @@ fn elemValSlice( |
| 26516 | const elem_ptr_ty = try sema.elemPtrType(slice_ty, index); | 26473 | const elem_ptr_ty = try sema.elemPtrType(slice_ty, index); |
| 26517 | const elem_ptr_val = try slice_val.elemPtr(elem_ptr_ty, index, mod); | 26474 | const elem_ptr_val = try slice_val.elemPtr(elem_ptr_ty, index, mod); |
| 26518 | if (try sema.pointerDeref(block, slice_src, elem_ptr_val, elem_ptr_ty)) |elem_val| { | 26475 | if (try sema.pointerDeref(block, slice_src, elem_ptr_val, elem_ptr_ty)) |elem_val| { |
| 26519 | return sema.addConstant(elem_ty, elem_val); | 26476 | return sema.addConstant(elem_val); |
| 26520 | } | 26477 | } |
| 26521 | runtime_src = slice_src; | 26478 | runtime_src = slice_src; |
| 26522 | } | 26479 | } |
| ... | @@ -26575,7 +26532,7 @@ fn elemPtrSlice( | ... | @@ -26575,7 +26532,7 @@ fn elemPtrSlice( |
| 26575 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); | 26532 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); |
| 26576 | } | 26533 | } |
| 26577 | const elem_ptr_val = try slice_val.elemPtr(elem_ptr_ty, index, mod); | 26534 | const elem_ptr_val = try slice_val.elemPtr(elem_ptr_ty, index, mod); |
| 26578 | return sema.addConstant(elem_ptr_ty, elem_ptr_val); | 26535 | return sema.addConstant(elem_ptr_val); |
| 26579 | } | 26536 | } |
| 26580 | } | 26537 | } |
| 26581 | | 26538 | |
| ... | @@ -26684,7 +26641,7 @@ fn coerceExtra( | ... | @@ -26684,7 +26641,7 @@ fn coerceExtra( |
| 26684 | | 26641 | |
| 26685 | // null to ?T | 26642 | // null to ?T |
| 26686 | if (inst_ty.zigTypeTag(mod) == .Null) { | 26643 | if (inst_ty.zigTypeTag(mod) == .Null) { |
| 26687 | return sema.addConstant(dest_ty, (try mod.intern(.{ .opt = .{ | 26644 | return sema.addConstant((try mod.intern(.{ .opt = .{ |
| 26688 | .ty = dest_ty.toIntern(), | 26645 | .ty = dest_ty.toIntern(), |
| 26689 | .val = .none, | 26646 | .val = .none, |
| 26690 | } })).toValue()); | 26647 | } })).toValue()); |
| ... | @@ -26856,7 +26813,7 @@ fn coerceExtra( | ... | @@ -26856,7 +26813,7 @@ fn coerceExtra( |
| 26856 | // coercion to C pointer | 26813 | // coercion to C pointer |
| 26857 | .C => switch (inst_ty.zigTypeTag(mod)) { | 26814 | .C => switch (inst_ty.zigTypeTag(mod)) { |
| 26858 | .Null => { | 26815 | .Null => { |
| 26859 | return sema.addConstant(dest_ty, try mod.getCoerced(Value.null, dest_ty)); | 26816 | return sema.addConstant(try mod.getCoerced(Value.null, dest_ty)); |
| 26860 | }, | 26817 | }, |
| 26861 | .ComptimeInt => { | 26818 | .ComptimeInt => { |
| 26862 | const addr = sema.coerceExtra(block, Type.usize, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) { | 26819 | const addr = sema.coerceExtra(block, Type.usize, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) { |
| ... | @@ -26960,7 +26917,7 @@ fn coerceExtra( | ... | @@ -26960,7 +26917,7 @@ fn coerceExtra( |
| 26960 | if (inst_child_ty.structFieldCount(mod) == 0) { | 26917 | if (inst_child_ty.structFieldCount(mod) == 0) { |
| 26961 | // Optional slice is represented with a null pointer so | 26918 | // Optional slice is represented with a null pointer so |
| 26962 | // we use a dummy pointer value with the required alignment. | 26919 | // we use a dummy pointer value with the required alignment. |
| 26963 | return sema.addConstant(dest_ty, (try mod.intern(.{ .ptr = .{ | 26920 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 26964 | .ty = dest_ty.toIntern(), | 26921 | .ty = dest_ty.toIntern(), |
| 26965 | .addr = .{ .int = (if (dest_info.flags.alignment != .none) | 26922 | .addr = .{ .int = (if (dest_info.flags.alignment != .none) |
| 26966 | try mod.intValue(Type.usize, dest_info.flags.alignment.toByteUnitsOptional().?) | 26923 | try mod.intValue(Type.usize, dest_info.flags.alignment.toByteUnitsOptional().?) |
| ... | @@ -27032,7 +26989,7 @@ fn coerceExtra( | ... | @@ -27032,7 +26989,7 @@ fn coerceExtra( |
| 27032 | ); | 26989 | ); |
| 27033 | } | 26990 | } |
| 27034 | const result_val = try sema.intFromFloat(block, inst_src, val, inst_ty, dest_ty); | 26991 | const result_val = try sema.intFromFloat(block, inst_src, val, inst_ty, dest_ty); |
| 27035 | return try sema.addConstant(dest_ty, result_val); | 26992 | return try sema.addConstant(result_val); |
| 27036 | }, | 26993 | }, |
| 27037 | .Int, .ComptimeInt => { | 26994 | .Int, .ComptimeInt => { |
| 27038 | if (is_undef) { | 26995 | if (is_undef) { |
| ... | @@ -27044,7 +27001,7 @@ fn coerceExtra( | ... | @@ -27044,7 +27001,7 @@ fn coerceExtra( |
| 27044 | if (!opts.report_err) return error.NotCoercible; | 27001 | if (!opts.report_err) return error.NotCoercible; |
| 27045 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(mod), val.fmtValue(inst_ty, mod) }); | 27002 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(mod), val.fmtValue(inst_ty, mod) }); |
| 27046 | } | 27003 | } |
| 27047 | return try sema.addConstant(dest_ty, try mod.getCoerced(val, dest_ty)); | 27004 | return try sema.addConstant(try mod.getCoerced(val, dest_ty)); |
| 27048 | } | 27005 | } |
| 27049 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 27006 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 27050 | if (!opts.report_err) return error.NotCoercible; | 27007 | if (!opts.report_err) return error.NotCoercible; |
| ... | @@ -27072,7 +27029,7 @@ fn coerceExtra( | ... | @@ -27072,7 +27029,7 @@ fn coerceExtra( |
| 27072 | .ComptimeFloat => { | 27029 | .ComptimeFloat => { |
| 27073 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 27030 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); |
| 27074 | const result_val = try val.floatCast(dest_ty, mod); | 27031 | const result_val = try val.floatCast(dest_ty, mod); |
| 27075 | return try sema.addConstant(dest_ty, result_val); | 27032 | return try sema.addConstant(result_val); |
| 27076 | }, | 27033 | }, |
| 27077 | .Float => { | 27034 | .Float => { |
| 27078 | if (is_undef) { | 27035 | if (is_undef) { |
| ... | @@ -27088,7 +27045,7 @@ fn coerceExtra( | ... | @@ -27088,7 +27045,7 @@ fn coerceExtra( |
| 27088 | .{ dest_ty.fmt(mod), val.fmtValue(inst_ty, mod) }, | 27045 | .{ dest_ty.fmt(mod), val.fmtValue(inst_ty, mod) }, |
| 27089 | ); | 27046 | ); |
| 27090 | } | 27047 | } |
| 27091 | return try sema.addConstant(dest_ty, result_val); | 27048 | return try sema.addConstant(result_val); |
| 27092 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 27049 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 27093 | if (!opts.report_err) return error.NotCoercible; | 27050 | if (!opts.report_err) return error.NotCoercible; |
| 27094 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); | 27051 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); |
| ... | @@ -27124,7 +27081,7 @@ fn coerceExtra( | ... | @@ -27124,7 +27081,7 @@ fn coerceExtra( |
| 27124 | // .{ dest_ty.fmt(mod), val }, | 27081 | // .{ dest_ty.fmt(mod), val }, |
| 27125 | // ); | 27082 | // ); |
| 27126 | //} | 27083 | //} |
| 27127 | return try sema.addConstant(dest_ty, result_val); | 27084 | return try sema.addConstant(result_val); |
| 27128 | }, | 27085 | }, |
| 27129 | .Undefined => { | 27086 | .Undefined => { |
| 27130 | return sema.addConstUndef(dest_ty); | 27087 | return sema.addConstUndef(dest_ty); |
| ... | @@ -27151,7 +27108,6 @@ fn coerceExtra( | ... | @@ -27151,7 +27108,6 @@ fn coerceExtra( |
| 27151 | return sema.failWithOwnedErrorMsg(msg); | 27108 | return sema.failWithOwnedErrorMsg(msg); |
| 27152 | }; | 27109 | }; |
| 27153 | return sema.addConstant( | 27110 | return sema.addConstant( |
| 27154 | dest_ty, | | |
| 27155 | try mod.enumValueFieldIndex(dest_ty, @intCast(u32, field_index)), | 27111 | try mod.enumValueFieldIndex(dest_ty, @intCast(u32, field_index)), |
| 27156 | ); | 27112 | ); |
| 27157 | }, | 27113 | }, |
| ... | @@ -27176,7 +27132,7 @@ fn coerceExtra( | ... | @@ -27176,7 +27132,7 @@ fn coerceExtra( |
| 27176 | .error_union => |error_union| switch (error_union.val) { | 27132 | .error_union => |error_union| switch (error_union.val) { |
| 27177 | .err_name => |err_name| { | 27133 | .err_name => |err_name| { |
| 27178 | const error_set_ty = inst_ty.errorUnionSet(mod); | 27134 | const error_set_ty = inst_ty.errorUnionSet(mod); |
| 27179 | const error_set_val = try sema.addConstant(error_set_ty, (try mod.intern(.{ .err = .{ | 27135 | const error_set_val = try sema.addConstant((try mod.intern(.{ .err = .{ |
| 27180 | .ty = error_set_ty.toIntern(), | 27136 | .ty = error_set_ty.toIntern(), |
| 27181 | .name = err_name, | 27137 | .name = err_name, |
| 27182 | } })).toValue()); | 27138 | } })).toValue()); |
| ... | @@ -27184,7 +27140,6 @@ fn coerceExtra( | ... | @@ -27184,7 +27140,6 @@ fn coerceExtra( |
| 27184 | }, | 27140 | }, |
| 27185 | .payload => |payload| { | 27141 | .payload => |payload| { |
| 27186 | const payload_val = try sema.addConstant( | 27142 | const payload_val = try sema.addConstant( |
| 27187 | inst_ty.errorUnionPayload(mod), | | |
| 27188 | payload.toValue(), | 27143 | payload.toValue(), |
| 27189 | ); | 27144 | ); |
| 27190 | return sema.wrapErrorUnionPayload(block, dest_ty, payload_val, inst_src) catch |err| switch (err) { | 27145 | return sema.wrapErrorUnionPayload(block, dest_ty, payload_val, inst_src) catch |err| switch (err) { |
| ... | @@ -27337,7 +27292,7 @@ fn coerceInMemory( | ... | @@ -27337,7 +27292,7 @@ fn coerceInMemory( |
| 27337 | val: Value, | 27292 | val: Value, |
| 27338 | dst_ty: Type, | 27293 | dst_ty: Type, |
| 27339 | ) CompileError!Air.Inst.Ref { | 27294 | ) CompileError!Air.Inst.Ref { |
| 27340 | return sema.addConstant(dst_ty, try sema.mod.getCoerced(val, dst_ty)); | 27295 | return sema.addConstant(try sema.mod.getCoerced(val, dst_ty)); |
| 27341 | } | 27296 | } |
| 27342 | | 27297 | |
| 27343 | const InMemoryCoercionResult = union(enum) { | 27298 | const InMemoryCoercionResult = union(enum) { |
| ... | @@ -29370,7 +29325,7 @@ fn bitCast( | ... | @@ -29370,7 +29325,7 @@ fn bitCast( |
| 29370 | | 29325 | |
| 29371 | if (try sema.resolveMaybeUndefVal(inst)) |val| { | 29326 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 29372 | if (try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0)) |result_val| { | 29327 | if (try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0)) |result_val| { |
| 29373 | return sema.addConstant(dest_ty, result_val); | 29328 | return sema.addConstant(result_val); |
| 29374 | } | 29329 | } |
| 29375 | } | 29330 | } |
| 29376 | try sema.requireRuntimeBlock(block, inst_src, operand_src); | 29331 | try sema.requireRuntimeBlock(block, inst_src, operand_src); |
| ... | @@ -29423,7 +29378,7 @@ fn coerceArrayPtrToSlice( | ... | @@ -29423,7 +29378,7 @@ fn coerceArrayPtrToSlice( |
| 29423 | }, | 29378 | }, |
| 29424 | .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(), | 29379 | .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(), |
| 29425 | } }); | 29380 | } }); |
| 29426 | return sema.addConstant(dest_ty, slice_val.toValue()); | 29381 | return sema.addConstant(slice_val.toValue()); |
| 29427 | } | 29382 | } |
| 29428 | try sema.requireRuntimeBlock(block, inst_src, null); | 29383 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 29429 | return block.addTyOp(.array_to_slice, dest_ty, inst); | 29384 | return block.addTyOp(.array_to_slice, dest_ty, inst); |
| ... | @@ -29491,7 +29446,6 @@ fn coerceCompatiblePtrs( | ... | @@ -29491,7 +29446,6 @@ fn coerceCompatiblePtrs( |
| 29491 | } | 29446 | } |
| 29492 | // The comptime Value representation is compatible with both types. | 29447 | // The comptime Value representation is compatible with both types. |
| 29493 | return sema.addConstant( | 29448 | return sema.addConstant( |
| 29494 | dest_ty, | | |
| 29495 | try mod.getCoerced((try val.intern(inst_ty, mod)).toValue(), dest_ty), | 29449 | try mod.getCoerced((try val.intern(inst_ty, mod)).toValue(), dest_ty), |
| 29496 | ); | 29450 | ); |
| 29497 | } | 29451 | } |
| ... | @@ -29590,7 +29544,7 @@ fn coerceEnumToUnion( | ... | @@ -29590,7 +29544,7 @@ fn coerceEnumToUnion( |
| 29590 | return sema.failWithOwnedErrorMsg(msg); | 29544 | return sema.failWithOwnedErrorMsg(msg); |
| 29591 | }; | 29545 | }; |
| 29592 | | 29546 | |
| 29593 | return sema.addConstant(union_ty, try mod.unionValue(union_ty, val, opv)); | 29547 | return sema.addConstant(try mod.unionValue(union_ty, val, opv)); |
| 29594 | } | 29548 | } |
| 29595 | | 29549 | |
| 29596 | try sema.requireRuntimeBlock(block, inst_src, null); | 29550 | try sema.requireRuntimeBlock(block, inst_src, null); |
| ... | @@ -29797,7 +29751,7 @@ fn coerceArrayLike( | ... | @@ -29797,7 +29751,7 @@ fn coerceArrayLike( |
| 29797 | var runtime_src: ?LazySrcLoc = null; | 29751 | var runtime_src: ?LazySrcLoc = null; |
| 29798 | | 29752 | |
| 29799 | for (element_vals, element_refs, 0..) |*val, *ref, i| { | 29753 | for (element_vals, element_refs, 0..) |*val, *ref, i| { |
| 29800 | const index_ref = try sema.addConstant(Type.usize, try mod.intValue(Type.usize, i)); | 29754 | const index_ref = try sema.addConstant(try mod.intValue(Type.usize, i)); |
| 29801 | const src = inst_src; // TODO better source location | 29755 | const src = inst_src; // TODO better source location |
| 29802 | const elem_src = inst_src; // TODO better source location | 29756 | const elem_src = inst_src; // TODO better source location |
| 29803 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true); | 29757 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true); |
| ... | @@ -29817,7 +29771,7 @@ fn coerceArrayLike( | ... | @@ -29817,7 +29771,7 @@ fn coerceArrayLike( |
| 29817 | return block.addAggregateInit(dest_ty, element_refs); | 29771 | return block.addAggregateInit(dest_ty, element_refs); |
| 29818 | } | 29772 | } |
| 29819 | | 29773 | |
| 29820 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ | 29774 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 29821 | .ty = dest_ty.toIntern(), | 29775 | .ty = dest_ty.toIntern(), |
| 29822 | .storage = .{ .elems = element_vals }, | 29776 | .storage = .{ .elems = element_vals }, |
| 29823 | } })).toValue()); | 29777 | } })).toValue()); |
| ... | @@ -29861,7 +29815,7 @@ fn coerceTupleToArray( | ... | @@ -29861,7 +29815,7 @@ fn coerceTupleToArray( |
| 29861 | if (i_usize == inst_len) { | 29815 | if (i_usize == inst_len) { |
| 29862 | const sentinel_val = dest_ty.sentinel(mod).?; | 29816 | const sentinel_val = dest_ty.sentinel(mod).?; |
| 29863 | val.* = sentinel_val.toIntern(); | 29817 | val.* = sentinel_val.toIntern(); |
| 29864 | ref.* = try sema.addConstant(dest_elem_ty, sentinel_val); | 29818 | ref.* = try sema.addConstant(sentinel_val); |
| 29865 | break; | 29819 | break; |
| 29866 | } | 29820 | } |
| 29867 | const elem_src = inst_src; // TODO better source location | 29821 | const elem_src = inst_src; // TODO better source location |
| ... | @@ -29882,7 +29836,7 @@ fn coerceTupleToArray( | ... | @@ -29882,7 +29836,7 @@ fn coerceTupleToArray( |
| 29882 | return block.addAggregateInit(dest_ty, element_refs); | 29836 | return block.addAggregateInit(dest_ty, element_refs); |
| 29883 | } | 29837 | } |
| 29884 | | 29838 | |
| 29885 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ | 29839 | return sema.addConstant((try mod.intern(.{ .aggregate = .{ |
| 29886 | .ty = dest_ty.toIntern(), | 29840 | .ty = dest_ty.toIntern(), |
| 29887 | .storage = .{ .elems = element_vals }, | 29841 | .storage = .{ .elems = element_vals }, |
| 29888 | } })).toValue()); | 29842 | } })).toValue()); |
| ... | @@ -30025,7 +29979,7 @@ fn coerceTupleToStruct( | ... | @@ -30025,7 +29979,7 @@ fn coerceTupleToStruct( |
| 30025 | if (runtime_src == null) { | 29979 | if (runtime_src == null) { |
| 30026 | field_vals[i] = field.default_val; | 29980 | field_vals[i] = field.default_val; |
| 30027 | } else { | 29981 | } else { |
| 30028 | field_ref.* = try sema.addConstant(field.ty, field.default_val.toValue()); | 29982 | field_ref.* = try sema.addConstant(field.default_val.toValue()); |
| 30029 | } | 29983 | } |
| 30030 | } | 29984 | } |
| 30031 | | 29985 | |
| ... | @@ -30047,7 +30001,7 @@ fn coerceTupleToStruct( | ... | @@ -30047,7 +30001,7 @@ fn coerceTupleToStruct( |
| 30047 | // TODO: figure out InternPool removals for incremental compilation | 30001 | // TODO: figure out InternPool removals for incremental compilation |
| 30048 | //errdefer ip.remove(struct_val); | 30002 | //errdefer ip.remove(struct_val); |
| 30049 | | 30003 | |
| 30050 | return sema.addConstant(struct_ty, struct_val.toValue()); | 30004 | return sema.addConstant(struct_val.toValue()); |
| 30051 | } | 30005 | } |
| 30052 | | 30006 | |
| 30053 | fn coerceTupleToTuple( | 30007 | fn coerceTupleToTuple( |
| ... | @@ -30169,12 +30123,7 @@ fn coerceTupleToTuple( | ... | @@ -30169,12 +30123,7 @@ fn coerceTupleToTuple( |
| 30169 | if (runtime_src == null) { | 30123 | if (runtime_src == null) { |
| 30170 | field_vals[i] = default_val; | 30124 | field_vals[i] = default_val; |
| 30171 | } else { | 30125 | } else { |
| 30172 | const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) { | 30126 | field_ref.* = try sema.addConstant(default_val.toValue()); |
| 30173 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[i].toType(), | | |
| 30174 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].ty, | | |
| 30175 | else => unreachable, | | |
| 30176 | }; | | |
| 30177 | field_ref.* = try sema.addConstant(field_ty, default_val.toValue()); | | |
| 30178 | } | 30127 | } |
| 30179 | } | 30128 | } |
| 30180 | | 30129 | |
| ... | @@ -30190,7 +30139,6 @@ fn coerceTupleToTuple( | ... | @@ -30190,7 +30139,6 @@ fn coerceTupleToTuple( |
| 30190 | } | 30139 | } |
| 30191 | | 30140 | |
| 30192 | return sema.addConstant( | 30141 | return sema.addConstant( |
| 30193 | tuple_ty, | | |
| 30194 | (try mod.intern(.{ .aggregate = .{ | 30142 | (try mod.intern(.{ .aggregate = .{ |
| 30195 | .ty = tuple_ty.toIntern(), | 30143 | .ty = tuple_ty.toIntern(), |
| 30196 | .storage = .{ .elems = field_vals }, | 30144 | .storage = .{ .elems = field_vals }, |
| ... | @@ -30316,7 +30264,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo | ... | @@ -30316,7 +30264,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo |
| 30316 | if (analyze_fn_body) { | 30264 | if (analyze_fn_body) { |
| 30317 | try sema.maybeQueueFuncBodyAnalysis(decl_index); | 30265 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| 30318 | } | 30266 | } |
| 30319 | return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{ | 30267 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 30320 | .ty = ptr_ty.toIntern(), | 30268 | .ty = ptr_ty.toIntern(), |
| 30321 | .addr = .{ .decl = decl_index }, | 30269 | .addr = .{ .decl = decl_index }, |
| 30322 | } })).toValue()); | 30270 | } })).toValue()); |
| ... | @@ -30391,12 +30339,12 @@ fn analyzeLoad( | ... | @@ -30391,12 +30339,12 @@ fn analyzeLoad( |
| 30391 | }; | 30339 | }; |
| 30392 | | 30340 | |
| 30393 | if (try sema.typeHasOnePossibleValue(elem_ty)) |opv| { | 30341 | if (try sema.typeHasOnePossibleValue(elem_ty)) |opv| { |
| 30394 | return sema.addConstant(elem_ty, opv); | 30342 | return sema.addConstant(opv); |
| 30395 | } | 30343 | } |
| 30396 | | 30344 | |
| 30397 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { | 30345 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 30398 | if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| { | 30346 | if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| { |
| 30399 | return sema.addConstant(elem_ty, try mod.getCoerced(elem_val, elem_ty)); | 30347 | return sema.addConstant(try mod.getCoerced(elem_val, elem_ty)); |
| 30400 | } | 30348 | } |
| 30401 | } | 30349 | } |
| 30402 | | 30350 | |
| ... | @@ -30427,7 +30375,7 @@ fn analyzeSlicePtr( | ... | @@ -30427,7 +30375,7 @@ fn analyzeSlicePtr( |
| 30427 | const result_ty = slice_ty.slicePtrFieldType(mod); | 30375 | const result_ty = slice_ty.slicePtrFieldType(mod); |
| 30428 | if (try sema.resolveMaybeUndefVal(slice)) |val| { | 30376 | if (try sema.resolveMaybeUndefVal(slice)) |val| { |
| 30429 | if (val.isUndef(mod)) return sema.addConstUndef(result_ty); | 30377 | if (val.isUndef(mod)) return sema.addConstUndef(result_ty); |
| 30430 | return sema.addConstant(result_ty, val.slicePtr(mod)); | 30378 | return sema.addConstant(val.slicePtr(mod)); |
| 30431 | } | 30379 | } |
| 30432 | try sema.requireRuntimeBlock(block, slice_src, null); | 30380 | try sema.requireRuntimeBlock(block, slice_src, null); |
| 30433 | return block.addTyOp(.slice_ptr, result_ty, slice); | 30381 | return block.addTyOp(.slice_ptr, result_ty, slice); |
| ... | @@ -30765,7 +30713,7 @@ fn analyzeSlice( | ... | @@ -30765,7 +30713,7 @@ fn analyzeSlice( |
| 30765 | break :e end; | 30713 | break :e end; |
| 30766 | } | 30714 | } |
| 30767 | | 30715 | |
| 30768 | break :e try sema.addConstant(Type.usize, len_val); | 30716 | break :e try sema.addConstant(len_val); |
| 30769 | } else if (slice_ty.isSlice(mod)) { | 30717 | } else if (slice_ty.isSlice(mod)) { |
| 30770 | if (!end_is_len) { | 30718 | if (!end_is_len) { |
| 30771 | const end = if (by_length) end: { | 30719 | const end = if (by_length) end: { |
| ... | @@ -30978,7 +30926,7 @@ fn analyzeSlice( | ... | @@ -30978,7 +30926,7 @@ fn analyzeSlice( |
| 30978 | }; | 30926 | }; |
| 30979 | | 30927 | |
| 30980 | if (!new_ptr_val.isUndef(mod)) { | 30928 | if (!new_ptr_val.isUndef(mod)) { |
| 30981 | return sema.addConstant(return_ty, try mod.getCoerced( | 30929 | return sema.addConstant(try mod.getCoerced( |
| 30982 | (try new_ptr_val.intern(new_ptr_ty, mod)).toValue(), | 30930 | (try new_ptr_val.intern(new_ptr_ty, mod)).toValue(), |
| 30983 | return_ty, | 30931 | return_ty, |
| 30984 | )); | 30932 | )); |
| ... | @@ -31466,7 +31414,7 @@ fn cmpVector( | ... | @@ -31466,7 +31414,7 @@ fn cmpVector( |
| 31466 | return sema.addConstUndef(result_ty); | 31414 | return sema.addConstUndef(result_ty); |
| 31467 | } | 31415 | } |
| 31468 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty); | 31416 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty); |
| 31469 | return sema.addConstant(result_ty, cmp_val); | 31417 | return sema.addConstant(cmp_val); |
| 31470 | } else { | 31418 | } else { |
| 31471 | break :src rhs_src; | 31419 | break :src rhs_src; |
| 31472 | } | 31420 | } |
| ... | @@ -31487,7 +31435,7 @@ fn wrapOptional( | ... | @@ -31487,7 +31435,7 @@ fn wrapOptional( |
| 31487 | inst_src: LazySrcLoc, | 31435 | inst_src: LazySrcLoc, |
| 31488 | ) !Air.Inst.Ref { | 31436 | ) !Air.Inst.Ref { |
| 31489 | if (try sema.resolveMaybeUndefVal(inst)) |val| { | 31437 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 31490 | return sema.addConstant(dest_ty, (try sema.mod.intern(.{ .opt = .{ | 31438 | return sema.addConstant((try sema.mod.intern(.{ .opt = .{ |
| 31491 | .ty = dest_ty.toIntern(), | 31439 | .ty = dest_ty.toIntern(), |
| 31492 | .val = val.toIntern(), | 31440 | .val = val.toIntern(), |
| 31493 | } })).toValue()); | 31441 | } })).toValue()); |
| ... | @@ -31508,7 +31456,7 @@ fn wrapErrorUnionPayload( | ... | @@ -31508,7 +31456,7 @@ fn wrapErrorUnionPayload( |
| 31508 | const dest_payload_ty = dest_ty.errorUnionPayload(mod); | 31456 | const dest_payload_ty = dest_ty.errorUnionPayload(mod); |
| 31509 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); | 31457 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 31510 | if (try sema.resolveMaybeUndefVal(coerced)) |val| { | 31458 | if (try sema.resolveMaybeUndefVal(coerced)) |val| { |
| 31511 | return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{ | 31459 | return sema.addConstant((try mod.intern(.{ .error_union = .{ |
| 31512 | .ty = dest_ty.toIntern(), | 31460 | .ty = dest_ty.toIntern(), |
| 31513 | .val = .{ .payload = try val.intern(dest_payload_ty, mod) }, | 31461 | .val = .{ .payload = try val.intern(dest_payload_ty, mod) }, |
| 31514 | } })).toValue()); | 31462 | } })).toValue()); |
| ... | @@ -31554,7 +31502,7 @@ fn wrapErrorUnionSet( | ... | @@ -31554,7 +31502,7 @@ fn wrapErrorUnionSet( |
| 31554 | else => unreachable, | 31502 | else => unreachable, |
| 31555 | }, | 31503 | }, |
| 31556 | } | 31504 | } |
| 31557 | return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{ | 31505 | return sema.addConstant((try mod.intern(.{ .error_union = .{ |
| 31558 | .ty = dest_ty.toIntern(), | 31506 | .ty = dest_ty.toIntern(), |
| 31559 | .val = .{ | 31507 | .val = .{ |
| 31560 | .err_name = mod.intern_pool.indexToKey(try val.intern(dest_err_set_ty, mod)).err.name, | 31508 | .err_name = mod.intern_pool.indexToKey(try val.intern(dest_err_set_ty, mod)).err.name, |
| ... | @@ -31576,10 +31524,10 @@ fn unionToTag( | ... | @@ -31576,10 +31524,10 @@ fn unionToTag( |
| 31576 | ) !Air.Inst.Ref { | 31524 | ) !Air.Inst.Ref { |
| 31577 | const mod = sema.mod; | 31525 | const mod = sema.mod; |
| 31578 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { | 31526 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { |
| 31579 | return sema.addConstant(enum_ty, opv); | 31527 | return sema.addConstant(opv); |
| 31580 | } | 31528 | } |
| 31581 | if (try sema.resolveMaybeUndefVal(un)) |un_val| { | 31529 | if (try sema.resolveMaybeUndefVal(un)) |un_val| { |
| 31582 | return sema.addConstant(enum_ty, un_val.unionTag(mod)); | 31530 | return sema.addConstant(un_val.unionTag(mod)); |
| 31583 | } | 31531 | } |
| 31584 | try sema.requireRuntimeBlock(block, un_src, null); | 31532 | try sema.requireRuntimeBlock(block, un_src, null); |
| 31585 | return block.addTyOp(.get_union_tag, enum_ty, un); | 31533 | return block.addTyOp(.get_union_tag, enum_ty, un); |
| ... | @@ -32921,8 +32869,7 @@ fn resolvePeerTypesInner( | ... | @@ -32921,8 +32869,7 @@ fn resolvePeerTypesInner( |
| 32921 | comptime_val = null; | 32869 | comptime_val = null; |
| 32922 | break; | 32870 | break; |
| 32923 | }; | 32871 | }; |
| 32924 | const uncoerced_field_ty = struct_ty.structFieldType(field_idx, mod); | 32872 | const uncoerced_field = try sema.addConstant(uncoerced_field_val); |
| 32925 | const uncoerced_field = try sema.addConstant(uncoerced_field_ty, uncoerced_field_val); | | |
| 32926 | const coerced_inst = sema.coerceExtra(block, field_ty.toType(), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) { | 32873 | const coerced_inst = sema.coerceExtra(block, field_ty.toType(), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) { |
| 32927 | // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway | 32874 | // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway |
| 32928 | error.NotCoercible => { | 32875 | error.NotCoercible => { |
| ... | @@ -35311,30 +35258,17 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { | ... | @@ -35311,30 +35258,17 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |
| 35311 | | 35258 | |
| 35312 | fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref { | 35259 | fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref { |
| 35313 | const mod = sema.mod; | 35260 | const mod = sema.mod; |
| 35314 | return sema.addConstant(ty, try mod.intValue(ty, int)); | 35261 | return sema.addConstant(try mod.intValue(ty, int)); |
| 35315 | } | 35262 | } |
| 35316 | | 35263 | |
| 35317 | fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref { | 35264 | fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref { |
| 35318 | return sema.addConstant(ty, (try sema.mod.intern(.{ .undef = ty.toIntern() })).toValue()); | 35265 | return sema.addConstant((try sema.mod.intern(.{ .undef = ty.toIntern() })).toValue()); |
| 35319 | } | 35266 | } |
| 35320 | | 35267 | |
| 35321 | pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref { | 35268 | pub fn addConstant(sema: *Sema, val: Value) SemaError!Air.Inst.Ref { |
| 35322 | const mod = sema.mod; | | |
| 35323 | const gpa = sema.gpa; | | |
| 35324 | | | |
| 35325 | // This assertion can be removed when the `ty` parameter is removed from | | |
| 35326 | // this function thanks to the InternPool transition being complete. | | |
| 35327 | if (std.debug.runtime_safety) { | | |
| 35328 | const val_ty = mod.intern_pool.typeOf(val.toIntern()); | | |
| 35329 | if (ty.toIntern() != val_ty) { | | |
| 35330 | std.debug.panic("addConstant type mismatch: '{}' vs '{}'\n", .{ | | |
| 35331 | ty.fmt(mod), val_ty.toType().fmt(mod), | | |
| 35332 | }); | | |
| 35333 | } | | |
| 35334 | } | | |
| 35335 | if (@intFromEnum(val.toIntern()) < Air.ref_start_index) | 35269 | if (@intFromEnum(val.toIntern()) < Air.ref_start_index) |
| 35336 | return @enumFromInt(Air.Inst.Ref, @intFromEnum(val.toIntern())); | 35270 | return @enumFromInt(Air.Inst.Ref, @intFromEnum(val.toIntern())); |
| 35337 | try sema.air_instructions.append(gpa, .{ | 35271 | try sema.air_instructions.append(sema.gpa, .{ |
| 35338 | .tag = .interned, | 35272 | .tag = .interned, |
| 35339 | .data = .{ .interned = val.toIntern() }, | 35273 | .data = .{ .interned = val.toIntern() }, |
| 35340 | }); | 35274 | }); |
| ... | @@ -35418,7 +35352,7 @@ fn analyzeComptimeAlloc( | ... | @@ -35418,7 +35352,7 @@ fn analyzeComptimeAlloc( |
| 35418 | | 35352 | |
| 35419 | try sema.comptime_mutable_decls.append(decl_index); | 35353 | try sema.comptime_mutable_decls.append(decl_index); |
| 35420 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 35354 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 35421 | return sema.addConstant(ptr_type, (try mod.intern(.{ .ptr = .{ | 35355 | return sema.addConstant((try mod.intern(.{ .ptr = .{ |
| 35422 | .ty = ptr_type.toIntern(), | 35356 | .ty = ptr_type.toIntern(), |
| 35423 | .addr = .{ .mut_decl = .{ | 35357 | .addr = .{ .mut_decl = .{ |
| 35424 | .decl = decl_index, | 35358 | .decl = decl_index, |