| ... | ... | @@ -1866,9 +1866,9 @@ fn resolveConstMaybeUndefVal( |
| 1866 | 1866 | reason: []const u8, |
| 1867 | 1867 | ) CompileError!Value { |
| 1868 | 1868 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { |
| 1869 | | switch (val.ip_index) { |
| 1869 | switch (val.toIntern()) { |
| 1870 | 1870 | .generic_poison => return error.GenericPoison, |
| 1871 | | else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) { |
| 1871 | else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) { |
| 1872 | 1872 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1873 | 1873 | else => return val, |
| 1874 | 1874 | }, |
| ... | ... | @@ -1887,10 +1887,10 @@ fn resolveConstValue( |
| 1887 | 1887 | reason: []const u8, |
| 1888 | 1888 | ) CompileError!Value { |
| 1889 | 1889 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1890 | | switch (val.ip_index) { |
| 1890 | switch (val.toIntern()) { |
| 1891 | 1891 | .generic_poison => return error.GenericPoison, |
| 1892 | 1892 | .undef => return sema.failWithUseOfUndef(block, src), |
| 1893 | | else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) { |
| 1893 | else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) { |
| 1894 | 1894 | .undef => return sema.failWithUseOfUndef(block, src), |
| 1895 | 1895 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1896 | 1896 | else => return val, |
| ... | ... | @@ -1930,7 +1930,7 @@ fn resolveMaybeUndefVal( |
| 1930 | 1930 | switch (val.ip_index) { |
| 1931 | 1931 | .generic_poison => return error.GenericPoison, |
| 1932 | 1932 | .none => return val, |
| 1933 | | else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) { |
| 1933 | else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) { |
| 1934 | 1934 | .variable => return null, |
| 1935 | 1935 | else => return val, |
| 1936 | 1936 | }, |
| ... | ... | @@ -1950,7 +1950,7 @@ fn resolveMaybeUndefValIntable( |
| 1950 | 1950 | while (true) switch (check.ip_index) { |
| 1951 | 1951 | .generic_poison => return error.GenericPoison, |
| 1952 | 1952 | .none => break, |
| 1953 | | else => switch (sema.mod.intern_pool.indexToKey(check.ip_index)) { |
| 1953 | else => switch (sema.mod.intern_pool.indexToKey(check.toIntern())) { |
| 1954 | 1954 | .variable => return null, |
| 1955 | 1955 | .ptr => |ptr| switch (ptr.addr) { |
| 1956 | 1956 | .decl, .mut_decl, .comptime_field => return null, |
| ... | ... | @@ -2007,7 +2007,6 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 2007 | 2007 | if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true; |
| 2008 | 2008 | return val; |
| 2009 | 2009 | }, |
| 2010 | | .const_ty => return air_datas[i].ty.toValue(), |
| 2011 | 2010 | .interned => return air_datas[i].interned.toValue(), |
| 2012 | 2011 | else => return null, |
| 2013 | 2012 | } |
| ... | ... | @@ -2490,7 +2489,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2490 | 2489 | }); |
| 2491 | 2490 | try sema.maybeQueueFuncBodyAnalysis(iac.data.decl_index); |
| 2492 | 2491 | return sema.addConstant(ptr_ty, (try sema.mod.intern(.{ .ptr = .{ |
| 2493 | | .ty = ptr_ty.ip_index, |
| 2492 | .ty = ptr_ty.toIntern(), |
| 2494 | 2493 | .addr = .{ .mut_decl = .{ |
| 2495 | 2494 | .decl = iac.data.decl_index, |
| 2496 | 2495 | .runtime_index = block.runtime_index, |
| ... | ... | @@ -2988,7 +2987,7 @@ fn zirEnumDecl( |
| 2988 | 2987 | if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) { |
| 2989 | 2988 | return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)}); |
| 2990 | 2989 | } |
| 2991 | | incomplete_enum.setTagType(&mod.intern_pool, ty.ip_index); |
| 2990 | incomplete_enum.setTagType(&mod.intern_pool, ty.toIntern()); |
| 2992 | 2991 | break :ty ty; |
| 2993 | 2992 | } else if (fields_len == 0) { |
| 2994 | 2993 | break :ty try mod.intType(.unsigned, 0); |
| ... | ... | @@ -2998,7 +2997,7 @@ fn zirEnumDecl( |
| 2998 | 2997 | } |
| 2999 | 2998 | }; |
| 3000 | 2999 | |
| 3001 | | if (small.nonexhaustive and int_tag_ty.ip_index != .comptime_int_type) { |
| 3000 | if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) { |
| 3002 | 3001 | if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) { |
| 3003 | 3002 | return sema.fail(block, src, "non-exhaustive enum specifies every value", .{}); |
| 3004 | 3003 | } |
| ... | ... | @@ -3051,7 +3050,7 @@ fn zirEnumDecl( |
| 3051 | 3050 | else => |e| return e, |
| 3052 | 3051 | }; |
| 3053 | 3052 | last_tag_val = tag_val; |
| 3054 | | if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.ip_index)) |other_index| { |
| 3053 | if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.toIntern())) |other_index| { |
| 3055 | 3054 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3056 | 3055 | .index = field_i, |
| 3057 | 3056 | .range = .value, |
| ... | ... | @@ -3071,7 +3070,7 @@ fn zirEnumDecl( |
| 3071 | 3070 | else |
| 3072 | 3071 | try mod.intValue(int_tag_ty, 0); |
| 3073 | 3072 | last_tag_val = tag_val; |
| 3074 | | if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.ip_index)) |other_index| { |
| 3073 | if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.toIntern())) |other_index| { |
| 3075 | 3074 | const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy; |
| 3076 | 3075 | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = other_index }).lazy; |
| 3077 | 3076 | const msg = msg: { |
| ... | ... | @@ -3742,7 +3741,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3742 | 3741 | |
| 3743 | 3742 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| 3744 | 3743 | sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{ |
| 3745 | | .ty = final_ptr_ty.ip_index, |
| 3744 | .ty = final_ptr_ty.toIntern(), |
| 3746 | 3745 | .addr = if (var_is_mut) .{ .mut_decl = .{ |
| 3747 | 3746 | .decl = decl_index, |
| 3748 | 3747 | .runtime_index = block.runtime_index, |
| ... | ... | @@ -3842,7 +3841,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3842 | 3841 | block.instructions.shrinkRetainingCapacity(search_index); |
| 3843 | 3842 | try sema.maybeQueueFuncBodyAnalysis(new_decl_index); |
| 3844 | 3843 | sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{ |
| 3845 | | .ty = final_elem_ty.ip_index, |
| 3844 | .ty = final_elem_ty.toIntern(), |
| 3846 | 3845 | .addr = .{ .decl = new_decl_index }, |
| 3847 | 3846 | } })).toValue(); |
| 3848 | 3847 | // if bitcast ty ref needs to be made const, make_ptr_const |
| ... | ... | @@ -4341,12 +4340,12 @@ fn validateUnionInit( |
| 4341 | 4340 | block.instructions.shrinkRetainingCapacity(first_block_index); |
| 4342 | 4341 | |
| 4343 | 4342 | var union_val = try mod.intern(.{ .un = .{ |
| 4344 | | .ty = union_ty.ip_index, |
| 4345 | | .tag = tag_val.ip_index, |
| 4346 | | .val = val.ip_index, |
| 4343 | .ty = union_ty.toIntern(), |
| 4344 | .tag = tag_val.toIntern(), |
| 4345 | .val = val.toIntern(), |
| 4347 | 4346 | } }); |
| 4348 | 4347 | if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{ |
| 4349 | | .ty = union_ty.ip_index, |
| 4348 | .ty = union_ty.toIntern(), |
| 4350 | 4349 | .val = union_val, |
| 4351 | 4350 | } }); |
| 4352 | 4351 | const union_init = try sema.addConstant(union_ty, union_val.toValue()); |
| ... | ... | @@ -4417,7 +4416,7 @@ fn validateStructInit( |
| 4417 | 4416 | if (field_ptr != 0) continue; |
| 4418 | 4417 | |
| 4419 | 4418 | const default_val = struct_ty.structFieldDefaultValue(i, mod); |
| 4420 | | if (default_val.ip_index == .unreachable_value) { |
| 4419 | if (default_val.toIntern() == .unreachable_value) { |
| 4421 | 4420 | if (struct_ty.isTuple(mod)) { |
| 4422 | 4421 | const template = "missing tuple field with index {d}"; |
| 4423 | 4422 | if (root_msg) |msg| { |
| ... | ... | @@ -4476,15 +4475,14 @@ fn validateStructInit( |
| 4476 | 4475 | |
| 4477 | 4476 | // We collect the comptime field values in case the struct initialization |
| 4478 | 4477 | // ends up being comptime-known. |
| 4479 | | const field_values = try sema.gpa.alloc(InternPool.Index, struct_ty.structFieldCount(mod)); |
| 4480 | | defer sema.gpa.free(field_values); |
| 4478 | const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod)); |
| 4481 | 4479 | |
| 4482 | 4480 | field: for (found_fields, 0..) |field_ptr, i| { |
| 4483 | 4481 | if (field_ptr != 0) { |
| 4484 | 4482 | // Determine whether the value stored to this pointer is comptime-known. |
| 4485 | 4483 | const field_ty = struct_ty.structFieldType(i, mod); |
| 4486 | 4484 | if (try sema.typeHasOnePossibleValue(field_ty)) |opv| { |
| 4487 | | field_values[i] = opv.ip_index; |
| 4485 | field_values[i] = opv.toIntern(); |
| 4488 | 4486 | continue; |
| 4489 | 4487 | } |
| 4490 | 4488 | |
| ... | ... | @@ -4549,7 +4547,7 @@ fn validateStructInit( |
| 4549 | 4547 | first_block_index = @min(first_block_index, block_index); |
| 4550 | 4548 | } |
| 4551 | 4549 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4552 | | field_values[i] = val.ip_index; |
| 4550 | field_values[i] = val.toIntern(); |
| 4553 | 4551 | } else if (require_comptime) { |
| 4554 | 4552 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| 4555 | 4553 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known"); |
| ... | ... | @@ -4563,7 +4561,7 @@ fn validateStructInit( |
| 4563 | 4561 | } |
| 4564 | 4562 | |
| 4565 | 4563 | const default_val = struct_ty.structFieldDefaultValue(i, mod); |
| 4566 | | if (default_val.ip_index == .unreachable_value) { |
| 4564 | if (default_val.toIntern() == .unreachable_value) { |
| 4567 | 4565 | if (struct_ty.isTuple(mod)) { |
| 4568 | 4566 | const template = "missing tuple field with index {d}"; |
| 4569 | 4567 | if (root_msg) |msg| { |
| ... | ... | @@ -4583,7 +4581,7 @@ fn validateStructInit( |
| 4583 | 4581 | } |
| 4584 | 4582 | continue; |
| 4585 | 4583 | } |
| 4586 | | field_values[i] = default_val.ip_index; |
| 4584 | field_values[i] = default_val.toIntern(); |
| 4587 | 4585 | } |
| 4588 | 4586 | |
| 4589 | 4587 | if (root_msg) |msg| { |
| ... | ... | @@ -4607,11 +4605,11 @@ fn validateStructInit( |
| 4607 | 4605 | |
| 4608 | 4606 | block.instructions.shrinkRetainingCapacity(first_block_index); |
| 4609 | 4607 | var struct_val = try mod.intern(.{ .aggregate = .{ |
| 4610 | | .ty = struct_ty.ip_index, |
| 4608 | .ty = struct_ty.toIntern(), |
| 4611 | 4609 | .storage = .{ .elems = field_values }, |
| 4612 | 4610 | } }); |
| 4613 | 4611 | if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{ |
| 4614 | | .ty = struct_ty.ip_index, |
| 4612 | .ty = struct_ty.toIntern(), |
| 4615 | 4613 | .val = struct_val, |
| 4616 | 4614 | } }); |
| 4617 | 4615 | const struct_init = try sema.addConstant(struct_ty, struct_val.toValue()); |
| ... | ... | @@ -4659,7 +4657,7 @@ fn zirValidateArrayInit( |
| 4659 | 4657 | var i = instrs.len; |
| 4660 | 4658 | while (i < array_len) : (i += 1) { |
| 4661 | 4659 | const default_val = array_ty.structFieldDefaultValue(i, mod); |
| 4662 | | if (default_val.ip_index == .unreachable_value) { |
| 4660 | if (default_val.toIntern() == .unreachable_value) { |
| 4663 | 4661 | const template = "missing tuple field with index {d}"; |
| 4664 | 4662 | if (root_msg) |msg| { |
| 4665 | 4663 | try sema.errNote(block, init_src, msg, template, .{i}); |
| ... | ... | @@ -4710,8 +4708,7 @@ fn zirValidateArrayInit( |
| 4710 | 4708 | // Collect the comptime element values in case the array literal ends up |
| 4711 | 4709 | // being comptime-known. |
| 4712 | 4710 | const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel(mod)); |
| 4713 | | const element_vals = try sema.gpa.alloc(InternPool.Index, array_len_s); |
| 4714 | | defer sema.gpa.free(element_vals); |
| 4711 | const element_vals = try sema.arena.alloc(InternPool.Index, array_len_s); |
| 4715 | 4712 | const opt_opv = try sema.typeHasOnePossibleValue(array_ty); |
| 4716 | 4713 | const air_tags = sema.air_instructions.items(.tag); |
| 4717 | 4714 | const air_datas = sema.air_instructions.items(.data); |
| ... | ... | @@ -4721,13 +4718,13 @@ fn zirValidateArrayInit( |
| 4721 | 4718 | |
| 4722 | 4719 | if (array_ty.isTuple(mod)) { |
| 4723 | 4720 | if (try array_ty.structFieldValueComptime(mod, i)) |opv| { |
| 4724 | | element_vals[i] = opv.ip_index; |
| 4721 | element_vals[i] = opv.toIntern(); |
| 4725 | 4722 | continue; |
| 4726 | 4723 | } |
| 4727 | 4724 | } else { |
| 4728 | 4725 | // Array has one possible value, so value is always comptime-known |
| 4729 | 4726 | if (opt_opv) |opv| { |
| 4730 | | element_vals[i] = opv.ip_index; |
| 4727 | element_vals[i] = opv.toIntern(); |
| 4731 | 4728 | continue; |
| 4732 | 4729 | } |
| 4733 | 4730 | } |
| ... | ... | @@ -4788,7 +4785,7 @@ fn zirValidateArrayInit( |
| 4788 | 4785 | first_block_index = @min(first_block_index, block_index); |
| 4789 | 4786 | } |
| 4790 | 4787 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4791 | | element_vals[i] = val.ip_index; |
| 4788 | element_vals[i] = val.toIntern(); |
| 4792 | 4789 | } else { |
| 4793 | 4790 | array_is_comptime = false; |
| 4794 | 4791 | } |
| ... | ... | @@ -4800,7 +4797,7 @@ fn zirValidateArrayInit( |
| 4800 | 4797 | |
| 4801 | 4798 | if (array_is_comptime) { |
| 4802 | 4799 | if (try sema.resolveDefinedValue(block, init_src, array_ptr)) |ptr_val| { |
| 4803 | | switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) { |
| 4800 | switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 4804 | 4801 | .ptr => |ptr| switch (ptr.addr) { |
| 4805 | 4802 | .comptime_field => return, // This store was validated by the individual elem ptrs. |
| 4806 | 4803 | else => {}, |
| ... | ... | @@ -4813,17 +4810,17 @@ fn zirValidateArrayInit( |
| 4813 | 4810 | // instead a single `store` to the array_ptr with a comptime struct value. |
| 4814 | 4811 | // Also to populate the sentinel value, if any. |
| 4815 | 4812 | if (array_ty.sentinel(mod)) |sentinel_val| { |
| 4816 | | element_vals[instrs.len] = sentinel_val.ip_index; |
| 4813 | element_vals[instrs.len] = sentinel_val.toIntern(); |
| 4817 | 4814 | } |
| 4818 | 4815 | |
| 4819 | 4816 | block.instructions.shrinkRetainingCapacity(first_block_index); |
| 4820 | 4817 | |
| 4821 | 4818 | var array_val = try mod.intern(.{ .aggregate = .{ |
| 4822 | | .ty = array_ty.ip_index, |
| 4819 | .ty = array_ty.toIntern(), |
| 4823 | 4820 | .storage = .{ .elems = element_vals }, |
| 4824 | 4821 | } }); |
| 4825 | 4822 | if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{ |
| 4826 | | .ty = array_ty.ip_index, |
| 4823 | .ty = array_ty.toIntern(), |
| 4827 | 4824 | .val = array_val, |
| 4828 | 4825 | } }); |
| 4829 | 4826 | const array_init = try sema.addConstant(array_ty, array_val.toValue()); |
| ... | ... | @@ -5144,41 +5141,26 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air |
| 5144 | 5141 | // expression of a variable declaration. |
| 5145 | 5142 | const mod = sema.mod; |
| 5146 | 5143 | const gpa = sema.gpa; |
| 5147 | | const string_bytes = &mod.string_literal_bytes; |
| 5148 | | const StringLiteralAdapter = Module.StringLiteralAdapter; |
| 5149 | | const StringLiteralContext = Module.StringLiteralContext; |
| 5150 | | try string_bytes.ensureUnusedCapacity(gpa, zir_bytes.len); |
| 5151 | | const gop = try mod.string_literal_table.getOrPutContextAdapted(gpa, zir_bytes, StringLiteralAdapter{ |
| 5152 | | .bytes = string_bytes, |
| 5153 | | }, StringLiteralContext{ |
| 5154 | | .bytes = string_bytes, |
| 5144 | const ty = try mod.arrayType(.{ |
| 5145 | .len = zir_bytes.len, |
| 5146 | .child = .u8_type, |
| 5147 | .sentinel = .zero_u8, |
| 5155 | 5148 | }); |
| 5149 | const val = try mod.intern(.{ .aggregate = .{ |
| 5150 | .ty = ty.toIntern(), |
| 5151 | .storage = .{ .bytes = zir_bytes }, |
| 5152 | } }); |
| 5153 | const gop = try mod.memoized_decls.getOrPut(gpa, val); |
| 5156 | 5154 | if (!gop.found_existing) { |
| 5157 | | gop.key_ptr.* = .{ |
| 5158 | | .index = @intCast(u32, string_bytes.items.len), |
| 5159 | | .len = @intCast(u32, zir_bytes.len), |
| 5160 | | }; |
| 5161 | | string_bytes.appendSliceAssumeCapacity(zir_bytes); |
| 5162 | | gop.value_ptr.* = .none; |
| 5163 | | } |
| 5164 | | const decl_index = gop.value_ptr.unwrap() orelse di: { |
| 5165 | 5155 | var anon_decl = try block.startAnonDecl(); |
| 5166 | 5156 | defer anon_decl.deinit(); |
| 5167 | 5157 | |
| 5168 | | const decl_index = try anon_decl.finish( |
| 5169 | | try Type.array(anon_decl.arena(), gop.key_ptr.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 5170 | | try Value.Tag.str_lit.create(anon_decl.arena(), gop.key_ptr.*), |
| 5171 | | 0, // default alignment |
| 5172 | | ); |
| 5173 | | |
| 5174 | | // Needed so that `Decl.clearValues` will additionally set the corresponding |
| 5175 | | // string literal table value back to `Decl.OptionalIndex.none`. |
| 5176 | | mod.declPtr(decl_index).owns_tv = true; |
| 5158 | const decl_index = try anon_decl.finish(ty, val.toValue(), 0); |
| 5177 | 5159 | |
| 5178 | | gop.value_ptr.* = decl_index.toOptional(); |
| 5179 | | break :di decl_index; |
| 5180 | | }; |
| 5181 | | return sema.analyzeDeclRef(decl_index); |
| 5160 | gop.key_ptr.* = val; |
| 5161 | gop.value_ptr.* = decl_index; |
| 5162 | } |
| 5163 | return sema.analyzeDeclRef(gop.value_ptr.*); |
| 5182 | 5164 | } |
| 5183 | 5165 | |
| 5184 | 5166 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6218,7 +6200,7 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { |
| 6218 | 6200 | const mod = sema.mod; |
| 6219 | 6201 | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; |
| 6220 | 6202 | if (func_val.isUndef(mod)) return null; |
| 6221 | | const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.ip_index)) { |
| 6203 | const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 6222 | 6204 | .extern_func => |extern_func| extern_func.decl, |
| 6223 | 6205 | .func => |func| mod.funcPtr(func.index).owner_decl, |
| 6224 | 6206 | .ptr => |ptr| switch (ptr.addr) { |
| ... | ... | @@ -6792,7 +6774,7 @@ fn analyzeCall( |
| 6792 | 6774 | if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err); |
| 6793 | 6775 | return err; |
| 6794 | 6776 | }; |
| 6795 | | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.ip_index)) { |
| 6777 | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 6796 | 6778 | .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 6797 | 6779 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 6798 | 6780 | }), |
| ... | ... | @@ -6996,7 +6978,7 @@ fn analyzeCall( |
| 6996 | 6978 | } |
| 6997 | 6979 | break :blk bare_return_type; |
| 6998 | 6980 | }; |
| 6999 | | new_fn_info.return_type = fn_ret_ty.ip_index; |
| 6981 | new_fn_info.return_type = fn_ret_ty.toIntern(); |
| 7000 | 6982 | const parent_fn_ret_ty = sema.fn_ret_ty; |
| 7001 | 6983 | sema.fn_ret_ty = fn_ret_ty; |
| 7002 | 6984 | defer sema.fn_ret_ty = parent_fn_ret_ty; |
| ... | ... | @@ -7289,7 +7271,7 @@ fn analyzeInlineCallArg( |
| 7289 | 7271 | if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err); |
| 7290 | 7272 | return err; |
| 7291 | 7273 | }; |
| 7292 | | switch (arg_val.ip_index) { |
| 7274 | switch (arg_val.toIntern()) { |
| 7293 | 7275 | .generic_poison, .generic_poison_type => { |
| 7294 | 7276 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| 7295 | 7277 | // parameter or return type. |
| ... | ... | @@ -7328,7 +7310,7 @@ fn analyzeInlineCallArg( |
| 7328 | 7310 | if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err); |
| 7329 | 7311 | return err; |
| 7330 | 7312 | }; |
| 7331 | | switch (arg_val.ip_index) { |
| 7313 | switch (arg_val.toIntern()) { |
| 7332 | 7314 | .generic_poison, .generic_poison_type => { |
| 7333 | 7315 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| 7334 | 7316 | // parameter or return type. |
| ... | ... | @@ -7426,7 +7408,7 @@ fn instantiateGenericCall( |
| 7426 | 7408 | const gpa = sema.gpa; |
| 7427 | 7409 | |
| 7428 | 7410 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); |
| 7429 | | const module_fn = mod.funcPtr(switch (mod.intern_pool.indexToKey(func_val.ip_index)) { |
| 7411 | const module_fn = mod.funcPtr(switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7430 | 7412 | .func => |function| function.index, |
| 7431 | 7413 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).getFunctionIndex(mod).unwrap().?, |
| 7432 | 7414 | else => unreachable, |
| ... | ... | @@ -7911,7 +7893,7 @@ fn resolveGenericInstantiationType( |
| 7911 | 7893 | } |
| 7912 | 7894 | |
| 7913 | 7895 | new_decl.val = (try mod.intern(.{ .func = .{ |
| 7914 | | .ty = new_decl.ty.ip_index, |
| 7896 | .ty = new_decl.ty.toIntern(), |
| 7915 | 7897 | .index = new_func, |
| 7916 | 7898 | } })).toValue(); |
| 7917 | 7899 | new_decl.@"align" = 0; |
| ... | ... | @@ -7932,7 +7914,7 @@ fn resolveGenericInstantiationType( |
| 7932 | 7914 | |
| 7933 | 7915 | fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void { |
| 7934 | 7916 | const mod = sema.mod; |
| 7935 | | const tuple = switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 7917 | const tuple = switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 7936 | 7918 | .anon_struct_type => |tuple| tuple, |
| 7937 | 7919 | else => return, |
| 7938 | 7920 | }; |
| ... | ... | @@ -7957,7 +7939,7 @@ fn emitDbgInline( |
| 7957 | 7939 | if (old_func == new_func) return; |
| 7958 | 7940 | |
| 7959 | 7941 | try sema.air_values.append(sema.gpa, (try sema.mod.intern(.{ .func = .{ |
| 7960 | | .ty = new_func_ty.ip_index, |
| 7942 | .ty = new_func_ty.toIntern(), |
| 7961 | 7943 | .index = new_func, |
| 7962 | 7944 | } })).toValue()); |
| 7963 | 7945 | _ = try block.addInst(.{ |
| ... | ... | @@ -8019,7 +8001,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8019 | 8001 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 8020 | 8002 | const vector_type = try mod.vectorType(.{ |
| 8021 | 8003 | .len = len, |
| 8022 | | .child = elem_type.ip_index, |
| 8004 | .child = elem_type.toIntern(), |
| 8023 | 8005 | }); |
| 8024 | 8006 | return sema.addType(vector_type); |
| 8025 | 8007 | } |
| ... | ... | @@ -8129,7 +8111,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8129 | 8111 | const kv = try sema.mod.getErrorValue(name); |
| 8130 | 8112 | const error_set_type = try mod.singleErrorSetType(kv.key); |
| 8131 | 8113 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 8132 | | .ty = error_set_type.ip_index, |
| 8114 | .ty = error_set_type.toIntern(), |
| 8133 | 8115 | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), |
| 8134 | 8116 | } })).toValue()); |
| 8135 | 8117 | } |
| ... | ... | @@ -8149,7 +8131,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8149 | 8131 | if (val.isUndef(mod)) { |
| 8150 | 8132 | return sema.addConstUndef(Type.err_int); |
| 8151 | 8133 | } |
| 8152 | | const err_name = mod.intern_pool.indexToKey(val.ip_index).err.name; |
| 8134 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 8153 | 8135 | return sema.addConstant(Type.err_int, try mod.intValue( |
| 8154 | 8136 | Type.err_int, |
| 8155 | 8137 | (try mod.getErrorValue(mod.intern_pool.stringToSlice(err_name))).value, |
| ... | ... | @@ -8240,7 +8222,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8240 | 8222 | return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)}); |
| 8241 | 8223 | |
| 8242 | 8224 | // Anything merged with anyerror is anyerror. |
| 8243 | | if (lhs_ty.ip_index == .anyerror_type or rhs_ty.ip_index == .anyerror_type) { |
| 8225 | if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) { |
| 8244 | 8226 | return Air.Inst.Ref.anyerror_type; |
| 8245 | 8227 | } |
| 8246 | 8228 | |
| ... | ... | @@ -8445,8 +8427,8 @@ fn analyzeOptionalPayloadPtr( |
| 8445 | 8427 | _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr); |
| 8446 | 8428 | } |
| 8447 | 8429 | return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{ |
| 8448 | | .ty = child_pointer.ip_index, |
| 8449 | | .addr = .{ .opt_payload = ptr_val.ip_index }, |
| 8430 | .ty = child_pointer.toIntern(), |
| 8431 | .addr = .{ .opt_payload = ptr_val.toIntern() }, |
| 8450 | 8432 | } })).toValue()); |
| 8451 | 8433 | } |
| 8452 | 8434 | if (try sema.pointerDeref(block, src, ptr_val, optional_ptr_ty)) |val| { |
| ... | ... | @@ -8455,8 +8437,8 @@ fn analyzeOptionalPayloadPtr( |
| 8455 | 8437 | } |
| 8456 | 8438 | // The same Value represents the pointer to the optional and the payload. |
| 8457 | 8439 | return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{ |
| 8458 | | .ty = child_pointer.ip_index, |
| 8459 | | .addr = .{ .opt_payload = ptr_val.ip_index }, |
| 8440 | .ty = child_pointer.toIntern(), |
| 8441 | .addr = .{ .opt_payload = ptr_val.toIntern() }, |
| 8460 | 8442 | } })).toValue()); |
| 8461 | 8443 | } |
| 8462 | 8444 | } |
| ... | ... | @@ -8565,7 +8547,7 @@ fn analyzeErrUnionPayload( |
| 8565 | 8547 | } |
| 8566 | 8548 | return sema.addConstant( |
| 8567 | 8549 | payload_ty, |
| 8568 | | mod.intern_pool.indexToKey(val.ip_index).error_union.val.payload.toValue(), |
| 8550 | mod.intern_pool.indexToKey(val.toIntern()).error_union.val.payload.toValue(), |
| 8569 | 8551 | ); |
| 8570 | 8552 | } |
| 8571 | 8553 | |
| ... | ... | @@ -8633,8 +8615,8 @@ fn analyzeErrUnionPayloadPtr( |
| 8633 | 8615 | _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand); |
| 8634 | 8616 | } |
| 8635 | 8617 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ |
| 8636 | | .ty = operand_pointer_ty.ip_index, |
| 8637 | | .addr = .{ .eu_payload = ptr_val.ip_index }, |
| 8618 | .ty = operand_pointer_ty.toIntern(), |
| 8619 | .addr = .{ .eu_payload = ptr_val.toIntern() }, |
| 8638 | 8620 | } })).toValue()); |
| 8639 | 8621 | } |
| 8640 | 8622 | if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| { |
| ... | ... | @@ -8642,8 +8624,8 @@ fn analyzeErrUnionPayloadPtr( |
| 8642 | 8624 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); |
| 8643 | 8625 | } |
| 8644 | 8626 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ |
| 8645 | | .ty = operand_pointer_ty.ip_index, |
| 8646 | | .addr = .{ .eu_payload = ptr_val.ip_index }, |
| 8627 | .ty = operand_pointer_ty.toIntern(), |
| 8628 | .addr = .{ .eu_payload = ptr_val.toIntern() }, |
| 8647 | 8629 | } })).toValue()); |
| 8648 | 8630 | } |
| 8649 | 8631 | } |
| ... | ... | @@ -8828,7 +8810,7 @@ fn resolveGenericBody( |
| 8828 | 8810 | }; |
| 8829 | 8811 | switch (err) { |
| 8830 | 8812 | error.GenericPoison => { |
| 8831 | | if (dest_ty.ip_index == .type_type) { |
| 8813 | if (dest_ty.toIntern() == .type_type) { |
| 8832 | 8814 | return Value.generic_poison_type; |
| 8833 | 8815 | } else { |
| 8834 | 8816 | return Value.generic_poison; |
| ... | ... | @@ -9183,7 +9165,7 @@ fn funcCommon( |
| 9183 | 9165 | |
| 9184 | 9166 | if (is_extern) { |
| 9185 | 9167 | return sema.addConstant(fn_ty, (try mod.intern(.{ .extern_func = .{ |
| 9186 | | .ty = fn_ty.ip_index, |
| 9168 | .ty = fn_ty.toIntern(), |
| 9187 | 9169 | .decl = sema.owner_decl_index, |
| 9188 | 9170 | .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString( |
| 9189 | 9171 | gpa, |
| ... | ... | @@ -9223,7 +9205,7 @@ fn funcCommon( |
| 9223 | 9205 | .is_noinline = is_noinline, |
| 9224 | 9206 | }; |
| 9225 | 9207 | return sema.addConstant(fn_ty, (try mod.intern(.{ .func = .{ |
| 9226 | | .ty = fn_ty.ip_index, |
| 9208 | .ty = fn_ty.toIntern(), |
| 9227 | 9209 | .index = new_func_index, |
| 9228 | 9210 | } })).toValue()); |
| 9229 | 9211 | } |
| ... | ... | @@ -10151,16 +10133,16 @@ fn zirSwitchCapture( |
| 10151 | 10133 | .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod), |
| 10152 | 10134 | }); |
| 10153 | 10135 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ |
| 10154 | | .ty = ptr_field_ty.ip_index, |
| 10136 | .ty = ptr_field_ty.toIntern(), |
| 10155 | 10137 | .addr = .{ .field = .{ |
| 10156 | | .base = union_val.ip_index, |
| 10138 | .base = union_val.toIntern(), |
| 10157 | 10139 | .index = field_index, |
| 10158 | 10140 | } }, |
| 10159 | 10141 | } })).toValue()); |
| 10160 | 10142 | } |
| 10161 | 10143 | return sema.addConstant( |
| 10162 | 10144 | field_ty, |
| 10163 | | mod.intern_pool.indexToKey(union_val.ip_index).un.val.toValue(), |
| 10145 | mod.intern_pool.indexToKey(union_val.toIntern()).un.val.toValue(), |
| 10164 | 10146 | ); |
| 10165 | 10147 | } |
| 10166 | 10148 | if (is_ref) { |
| ... | ... | @@ -10256,9 +10238,9 @@ fn zirSwitchCapture( |
| 10256 | 10238 | |
| 10257 | 10239 | if (try sema.resolveDefinedValue(block, operand_src, operand_ptr)) |op_ptr_val| { |
| 10258 | 10240 | return sema.addConstant(field_ty_ptr, (try mod.intern(.{ .ptr = .{ |
| 10259 | | .ty = field_ty_ptr.ip_index, |
| 10241 | .ty = field_ty_ptr.toIntern(), |
| 10260 | 10242 | .addr = .{ .field = .{ |
| 10261 | | .base = op_ptr_val.ip_index, |
| 10243 | .base = op_ptr_val.toIntern(), |
| 10262 | 10244 | .index = first_field_index, |
| 10263 | 10245 | } }, |
| 10264 | 10246 | } })).toValue()); |
| ... | ... | @@ -11502,7 +11484,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11502 | 11484 | cases_len += 1; |
| 11503 | 11485 | |
| 11504 | 11486 | const item_val = try mod.intern(.{ .err = .{ |
| 11505 | | .ty = operand_ty.ip_index, |
| 11487 | .ty = operand_ty.toIntern(), |
| 11506 | 11488 | .name = error_name_ip, |
| 11507 | 11489 | } }); |
| 11508 | 11490 | const item_ref = try sema.addConstant(operand_ty, item_val.toValue()); |
| ... | ... | @@ -11802,7 +11784,7 @@ fn validateSwitchItemError( |
| 11802 | 11784 | const ip = &sema.mod.intern_pool; |
| 11803 | 11785 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 11804 | 11786 | // TODO: Do i need to typecheck here? |
| 11805 | | const error_name = ip.stringToSlice(ip.indexToKey(item_tv.val.ip_index).err.name); |
| 11787 | const error_name = ip.stringToSlice(ip.indexToKey(item_tv.val.toIntern()).err.name); |
| 11806 | 11788 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev| |
| 11807 | 11789 | prev.value |
| 11808 | 11790 | else |
| ... | ... | @@ -12035,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12035 | 12017 | const ip = &mod.intern_pool; |
| 12036 | 12018 | |
| 12037 | 12019 | const has_field = hf: { |
| 12038 | | switch (ip.indexToKey(ty.ip_index)) { |
| 12020 | switch (ip.indexToKey(ty.toIntern())) { |
| 12039 | 12021 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 12040 | 12022 | .Slice => { |
| 12041 | 12023 | if (mem.eql(u8, field_name, "ptr")) break :hf true; |
| ... | ... | @@ -12160,17 +12142,23 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12160 | 12142 | var anon_decl = try block.startAnonDecl(); |
| 12161 | 12143 | defer anon_decl.deinit(); |
| 12162 | 12144 | |
| 12163 | | const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1]; |
| 12164 | | |
| 12165 | | // TODO instead of using `Value.Tag.bytes`, create a new value tag for pointing at |
| 12145 | // TODO instead of using `.bytes`, create a new value tag for pointing at |
| 12166 | 12146 | // a `*Module.EmbedFile`. The purpose of this would be: |
| 12167 | 12147 | // - If only the length is read and the bytes are not inspected by comptime code, |
| 12168 | 12148 | // there can be an optimization where the codegen backend does a copy_file_range |
| 12169 | 12149 | // into the final binary, and never loads the data into memory. |
| 12170 | 12150 | // - When a Decl is destroyed, it can free the `*Module.EmbedFile`. |
| 12151 | const ty = try mod.arrayType(.{ |
| 12152 | .len = embed_file.bytes.len, |
| 12153 | .child = .u8_type, |
| 12154 | .sentinel = .zero_u8, |
| 12155 | }); |
| 12171 | 12156 | embed_file.owner_decl = try anon_decl.finish( |
| 12172 | | try Type.array(anon_decl.arena(), embed_file.bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 12173 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes_including_null), |
| 12157 | ty, |
| 12158 | (try mod.intern(.{ .aggregate = .{ |
| 12159 | .ty = ty.toIntern(), |
| 12160 | .storage = .{ .bytes = embed_file.bytes }, |
| 12161 | } })).toValue(), |
| 12174 | 12162 | 0, // default alignment |
| 12175 | 12163 | ); |
| 12176 | 12164 | |
| ... | ... | @@ -12186,7 +12174,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R |
| 12186 | 12174 | const kv = try mod.getErrorValue(err_name); |
| 12187 | 12175 | const error_set_type = try mod.singleErrorSetType(kv.key); |
| 12188 | 12176 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 12189 | | .ty = error_set_type.ip_index, |
| 12177 | .ty = error_set_type.toIntern(), |
| 12190 | 12178 | .name = mod.intern_pool.getString(kv.key).unwrap().?, |
| 12191 | 12179 | } })).toValue()); |
| 12192 | 12180 | } |
| ... | ... | @@ -12597,15 +12585,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12597 | 12585 | return sema.addConstUndef(operand_type); |
| 12598 | 12586 | } else if (operand_type.zigTypeTag(mod) == .Vector) { |
| 12599 | 12587 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod)); |
| 12600 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 12588 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 12601 | 12589 | for (elems, 0..) |*elem, i| { |
| 12602 | 12590 | const elem_val = try val.elemValue(sema.mod, i); |
| 12603 | | elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod); |
| 12591 | elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod)).intern(scalar_type, mod); |
| 12604 | 12592 | } |
| 12605 | | return sema.addConstant( |
| 12606 | | operand_type, |
| 12607 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 12608 | | ); |
| 12593 | return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{ |
| 12594 | .ty = operand_type.toIntern(), |
| 12595 | .storage = .{ .elems = elems }, |
| 12596 | } })).toValue()); |
| 12609 | 12597 | } else { |
| 12610 | 12598 | const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod); |
| 12611 | 12599 | return sema.addConstant(operand_type, result_val); |
| ... | ... | @@ -12652,22 +12640,22 @@ fn analyzeTupleCat( |
| 12652 | 12640 | var runtime_src: ?LazySrcLoc = null; |
| 12653 | 12641 | var i: u32 = 0; |
| 12654 | 12642 | while (i < lhs_len) : (i += 1) { |
| 12655 | | types[i] = lhs_ty.structFieldType(i, mod).ip_index; |
| 12643 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); |
| 12656 | 12644 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); |
| 12657 | | values[i] = default_val.ip_index; |
| 12645 | values[i] = default_val.toIntern(); |
| 12658 | 12646 | const operand_src = lhs_src; // TODO better source location |
| 12659 | | if (default_val.ip_index == .unreachable_value) { |
| 12647 | if (default_val.toIntern() == .unreachable_value) { |
| 12660 | 12648 | runtime_src = operand_src; |
| 12661 | 12649 | values[i] = .none; |
| 12662 | 12650 | } |
| 12663 | 12651 | } |
| 12664 | 12652 | i = 0; |
| 12665 | 12653 | while (i < rhs_len) : (i += 1) { |
| 12666 | | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).ip_index; |
| 12654 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); |
| 12667 | 12655 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); |
| 12668 | | values[i + lhs_len] = default_val.ip_index; |
| 12656 | values[i + lhs_len] = default_val.toIntern(); |
| 12669 | 12657 | const operand_src = rhs_src; // TODO better source location |
| 12670 | | if (default_val.ip_index == .unreachable_value) { |
| 12658 | if (default_val.toIntern() == .unreachable_value) { |
| 12671 | 12659 | runtime_src = operand_src; |
| 12672 | 12660 | values[i + lhs_len] = .none; |
| 12673 | 12661 | } |
| ... | ... | @@ -12824,34 +12812,32 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12824 | 12812 | else |
| 12825 | 12813 | rhs_val; |
| 12826 | 12814 | |
| 12827 | | const final_len_including_sent = result_len + @boolToInt(res_sent_val != null); |
| 12828 | | const element_vals = try sema.arena.alloc(Value, final_len_including_sent); |
| 12815 | const element_vals = try sema.arena.alloc(InternPool.Index, result_len); |
| 12829 | 12816 | var elem_i: usize = 0; |
| 12830 | 12817 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 12831 | 12818 | const lhs_elem_i = elem_i; |
| 12832 | 12819 | const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i, mod) else lhs_info.elem_type; |
| 12833 | 12820 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; |
| 12834 | | const elem_val = if (elem_default_val.ip_index == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 12821 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 12835 | 12822 | const elem_val_inst = try sema.addConstant(elem_ty, elem_val); |
| 12836 | 12823 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 12837 | 12824 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); |
| 12838 | | element_vals[elem_i] = coerced_elem_val; |
| 12825 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 12839 | 12826 | } |
| 12840 | 12827 | while (elem_i < result_len) : (elem_i += 1) { |
| 12841 | 12828 | const rhs_elem_i = elem_i - lhs_len; |
| 12842 | 12829 | const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i, mod) else rhs_info.elem_type; |
| 12843 | 12830 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; |
| 12844 | | const elem_val = if (elem_default_val.ip_index == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 12831 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 12845 | 12832 | const elem_val_inst = try sema.addConstant(elem_ty, elem_val); |
| 12846 | 12833 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 12847 | 12834 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); |
| 12848 | | element_vals[elem_i] = coerced_elem_val; |
| 12849 | | } |
| 12850 | | if (res_sent_val) |sent_val| { |
| 12851 | | element_vals[result_len] = sent_val; |
| 12835 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 12852 | 12836 | } |
| 12853 | | const val = try Value.Tag.aggregate.create(sema.arena, element_vals); |
| 12854 | | return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null); |
| 12837 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ |
| 12838 | .ty = result_ty.toIntern(), |
| 12839 | .storage = .{ .elems = element_vals }, |
| 12840 | } })).toValue(), ptr_addrspace != null); |
| 12855 | 12841 | } else break :rs rhs_src; |
| 12856 | 12842 | } else lhs_src; |
| 12857 | 12843 | |
| ... | ... | @@ -12978,8 +12964,8 @@ fn analyzeTupleMul( |
| 12978 | 12964 | const opt_runtime_src = rs: { |
| 12979 | 12965 | var runtime_src: ?LazySrcLoc = null; |
| 12980 | 12966 | for (0..tuple_len) |i| { |
| 12981 | | types[i] = operand_ty.structFieldType(i, mod).ip_index; |
| 12982 | | values[i] = operand_ty.structFieldDefaultValue(i, mod).ip_index; |
| 12967 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); |
| 12968 | values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 12983 | 12969 | const operand_src = lhs_src; // TODO better source location |
| 12984 | 12970 | if (values[i] == .unreachable_value) { |
| 12985 | 12971 | runtime_src = operand_src; |
| ... | ... | @@ -13086,8 +13072,8 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13086 | 13072 | if (lhs_len == 1) { |
| 13087 | 13073 | const elem_val = try lhs_sub_val.elemValue(mod, 0); |
| 13088 | 13074 | break :v try mod.intern(.{ .aggregate = .{ |
| 13089 | | .ty = result_ty.ip_index, |
| 13090 | | .storage = .{ .repeated_elem = elem_val.ip_index }, |
| 13075 | .ty = result_ty.toIntern(), |
| 13076 | .storage = .{ .repeated_elem = elem_val.toIntern() }, |
| 13091 | 13077 | } }); |
| 13092 | 13078 | } |
| 13093 | 13079 | |
| ... | ... | @@ -13097,16 +13083,15 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13097 | 13083 | var lhs_i: usize = 0; |
| 13098 | 13084 | while (lhs_i < lhs_len) : (lhs_i += 1) { |
| 13099 | 13085 | const elem_val = try lhs_sub_val.elemValue(mod, lhs_i); |
| 13100 | | assert(elem_val.ip_index != .none); |
| 13101 | | element_vals[elem_i] = elem_val.ip_index; |
| 13086 | element_vals[elem_i] = elem_val.toIntern(); |
| 13102 | 13087 | elem_i += 1; |
| 13103 | 13088 | } |
| 13104 | 13089 | } |
| 13105 | 13090 | if (lhs_info.sentinel) |sent_val| { |
| 13106 | | element_vals[result_len] = sent_val.ip_index; |
| 13091 | element_vals[result_len] = sent_val.toIntern(); |
| 13107 | 13092 | } |
| 13108 | 13093 | break :v try mod.intern(.{ .aggregate = .{ |
| 13109 | | .ty = result_ty.ip_index, |
| 13094 | .ty = result_ty.toIntern(), |
| 13110 | 13095 | .storage = .{ .elems = element_vals }, |
| 13111 | 13096 | } }); |
| 13112 | 13097 | }; |
| ... | ... | @@ -13998,8 +13983,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13998 | 13983 | else => unreachable, |
| 13999 | 13984 | }; |
| 14000 | 13985 | const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{ |
| 14001 | | .ty = resolved_type.ip_index, |
| 14002 | | .storage = .{ .repeated_elem = scalar_zero.ip_index }, |
| 13986 | .ty = resolved_type.toIntern(), |
| 13987 | .storage = .{ .repeated_elem = scalar_zero.toIntern() }, |
| 14003 | 13988 | } })).toValue() else scalar_zero; |
| 14004 | 13989 | return sema.addConstant(resolved_type, zero_val); |
| 14005 | 13990 | } |
| ... | ... | @@ -14079,14 +14064,17 @@ fn intRem( |
| 14079 | 14064 | ) CompileError!Value { |
| 14080 | 14065 | const mod = sema.mod; |
| 14081 | 14066 | if (ty.zigTypeTag(mod) == .Vector) { |
| 14082 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 14067 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); |
| 14083 | 14068 | const scalar_ty = ty.scalarType(mod); |
| 14084 | 14069 | for (result_data, 0..) |*scalar, i| { |
| 14085 | 14070 | const lhs_elem = try lhs.elemValue(sema.mod, i); |
| 14086 | 14071 | const rhs_elem = try rhs.elemValue(sema.mod, i); |
| 14087 | | scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty); |
| 14072 | scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod); |
| 14088 | 14073 | } |
| 14089 | | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 14074 | return (try mod.intern(.{ .aggregate = .{ |
| 14075 | .ty = ty.toIntern(), |
| 14076 | .storage = .{ .elems = result_data }, |
| 14077 | } })).toValue(); |
| 14090 | 14078 | } |
| 14091 | 14079 | return sema.intRemScalar(lhs, rhs, ty); |
| 14092 | 14080 | } |
| ... | ... | @@ -14517,11 +14505,13 @@ fn zirOverflowArithmetic( |
| 14517 | 14505 | } |
| 14518 | 14506 | |
| 14519 | 14507 | if (result.inst == .none) { |
| 14520 | | const values = try sema.arena.alloc(Value, 2); |
| 14521 | | values[0] = result.wrapped; |
| 14522 | | values[1] = result.overflow_bit; |
| 14523 | | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 14524 | | return sema.addConstant(tuple_ty, tuple_val); |
| 14508 | return sema.addConstant(tuple_ty, (try mod.intern(.{ .aggregate = .{ |
| 14509 | .ty = tuple_ty.toIntern(), |
| 14510 | .storage = .{ .elems = &.{ |
| 14511 | result.wrapped.toIntern(), |
| 14512 | result.overflow_bit.toIntern(), |
| 14513 | } }, |
| 14514 | } })).toValue()); |
| 14525 | 14515 | } |
| 14526 | 14516 | |
| 14527 | 14517 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2); |
| ... | ... | @@ -14534,8 +14524,8 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value { |
| 14534 | 14524 | const mod = sema.mod; |
| 14535 | 14525 | if (ty.zigTypeTag(mod) != .Vector) return val; |
| 14536 | 14526 | const repeated = try mod.intern(.{ .aggregate = .{ |
| 14537 | | .ty = ty.ip_index, |
| 14538 | | .storage = .{ .repeated_elem = val.ip_index }, |
| 14527 | .ty = ty.toIntern(), |
| 14528 | .storage = .{ .repeated_elem = val.toIntern() }, |
| 14539 | 14529 | } }); |
| 14540 | 14530 | return repeated.toValue(); |
| 14541 | 14531 | } |
| ... | ... | @@ -14547,7 +14537,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type { |
| 14547 | 14537 | .child = .u1_type, |
| 14548 | 14538 | }) else Type.u1; |
| 14549 | 14539 | |
| 14550 | | const types = [2]InternPool.Index{ ty.ip_index, ov_ty.ip_index }; |
| 14540 | const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() }; |
| 14551 | 14541 | const values = [2]InternPool.Index{ .none, .none }; |
| 14552 | 14542 | const tuple_ty = try mod.intern(.{ .anon_struct_type = .{ |
| 14553 | 14543 | .types = &types, |
| ... | ... | @@ -15731,7 +15721,7 @@ fn zirClosureGet( |
| 15731 | 15721 | scope = scope.parent.?; |
| 15732 | 15722 | }; |
| 15733 | 15723 | |
| 15734 | | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and sema.func_index == .none) { |
| 15724 | if (tv.val.toIntern() == .unreachable_value and !block.is_typeof and sema.func_index == .none) { |
| 15735 | 15725 | const msg = msg: { |
| 15736 | 15726 | const name = name: { |
| 15737 | 15727 | const file = sema.owner_decl.getFileScope(mod); |
| ... | ... | @@ -15759,7 +15749,7 @@ fn zirClosureGet( |
| 15759 | 15749 | return sema.failWithOwnedErrorMsg(msg); |
| 15760 | 15750 | } |
| 15761 | 15751 | |
| 15762 | | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| 15752 | if (tv.val.toIntern() == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| 15763 | 15753 | const msg = msg: { |
| 15764 | 15754 | const name = name: { |
| 15765 | 15755 | const file = sema.owner_decl.getFileScope(mod); |
| ... | ... | @@ -15789,7 +15779,7 @@ fn zirClosureGet( |
| 15789 | 15779 | return sema.failWithOwnedErrorMsg(msg); |
| 15790 | 15780 | } |
| 15791 | 15781 | |
| 15792 | | if (tv.val.ip_index == .unreachable_value) { |
| 15782 | if (tv.val.toIntern() == .unreachable_value) { |
| 15793 | 15783 | assert(block.is_typeof); |
| 15794 | 15784 | // We need a dummy runtime instruction with the correct type. |
| 15795 | 15785 | return block.addTy(.alloc, tv.ty); |
| ... | ... | @@ -15840,10 +15830,17 @@ fn zirBuiltinSrc( |
| 15840 | 15830 | var anon_decl = try block.startAnonDecl(); |
| 15841 | 15831 | defer anon_decl.deinit(); |
| 15842 | 15832 | const name = mem.span(fn_owner_decl.name); |
| 15843 | | const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]); |
| 15833 | const new_decl_ty = try mod.arrayType(.{ |
| 15834 | .len = name.len, |
| 15835 | .child = .u8_type, |
| 15836 | .sentinel = .zero_u8, |
| 15837 | }); |
| 15844 | 15838 | const new_decl = try anon_decl.finish( |
| 15845 | | try Type.array(anon_decl.arena(), bytes.len - 1, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 15846 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes), |
| 15839 | new_decl_ty, |
| 15840 | (try mod.intern(.{ .aggregate = .{ |
| 15841 | .ty = new_decl_ty.toIntern(), |
| 15842 | .storage = .{ .bytes = name }, |
| 15843 | } })).toValue(), |
| 15847 | 15844 | 0, // default alignment |
| 15848 | 15845 | ); |
| 15849 | 15846 | break :blk try mod.intern(.{ .ptr = .{ |
| ... | ... | @@ -15857,9 +15854,17 @@ fn zirBuiltinSrc( |
| 15857 | 15854 | defer anon_decl.deinit(); |
| 15858 | 15855 | // The compiler must not call realpath anywhere. |
| 15859 | 15856 | const name = try fn_owner_decl.getFileScope(mod).fullPathZ(anon_decl.arena()); |
| 15857 | const new_decl_ty = try mod.arrayType(.{ |
| 15858 | .len = name.len, |
| 15859 | .child = .u8_type, |
| 15860 | .sentinel = .zero_u8, |
| 15861 | }); |
| 15860 | 15862 | const new_decl = try anon_decl.finish( |
| 15861 | | try Type.array(anon_decl.arena(), name.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 15862 | | try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]), |
| 15863 | new_decl_ty, |
| 15864 | (try mod.intern(.{ .aggregate = .{ |
| 15865 | .ty = new_decl_ty.toIntern(), |
| 15866 | .storage = .{ .bytes = name }, |
| 15867 | } })).toValue(), |
| 15863 | 15868 | 0, // default alignment |
| 15864 | 15869 | ); |
| 15865 | 15870 | break :blk try mod.intern(.{ .ptr = .{ |
| ... | ... | @@ -15877,13 +15882,13 @@ fn zirBuiltinSrc( |
| 15877 | 15882 | // line: u32, |
| 15878 | 15883 | try mod.intern(.{ .runtime_value = .{ |
| 15879 | 15884 | .ty = .u32_type, |
| 15880 | | .val = (try mod.intValue(Type.u32, extra.line + 1)).ip_index, |
| 15885 | .val = (try mod.intValue(Type.u32, extra.line + 1)).toIntern(), |
| 15881 | 15886 | } }), |
| 15882 | 15887 | // column: u32, |
| 15883 | | (try mod.intValue(Type.u32, extra.column + 1)).ip_index, |
| 15888 | (try mod.intValue(Type.u32, extra.column + 1)).toIntern(), |
| 15884 | 15889 | }; |
| 15885 | 15890 | return sema.addConstant(src_loc_ty, (try mod.intern(.{ .aggregate = .{ |
| 15886 | | .ty = src_loc_ty.ip_index, |
| 15891 | .ty = src_loc_ty.toIntern(), |
| 15887 | 15892 | .storage = .{ .elems = &fields }, |
| 15888 | 15893 | } })).toValue()); |
| 15889 | 15894 | } |
| ... | ... | @@ -15908,8 +15913,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15908 | 15913 | .Null, |
| 15909 | 15914 | .EnumLiteral, |
| 15910 | 15915 | => |type_info_tag| return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 15911 | | .ty = type_info_ty.ip_index, |
| 15912 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).ip_index, |
| 15916 | .ty = type_info_ty.toIntern(), |
| 15917 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).toIntern(), |
| 15913 | 15918 | .val = .void_value, |
| 15914 | 15919 | } })).toValue()), |
| 15915 | 15920 | .Fn => { |
| ... | ... | @@ -15941,8 +15946,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15941 | 15946 | const param_info_decl = mod.declPtr(param_info_decl_index); |
| 15942 | 15947 | const param_info_ty = param_info_decl.val.toType(); |
| 15943 | 15948 | |
| 15944 | | const param_vals = try gpa.alloc(InternPool.Index, info.param_types.len); |
| 15945 | | defer gpa.free(param_vals); |
| 15949 | const param_vals = try sema.arena.alloc(InternPool.Index, info.param_types.len); |
| 15946 | 15950 | for (param_vals, info.param_types, 0..) |*param_val, param_ty, i| { |
| 15947 | 15951 | const is_generic = param_ty == .generic_poison_type; |
| 15948 | 15952 | const param_ty_val = try mod.intern_pool.get(gpa, .{ .opt = .{ |
| ... | ... | @@ -15957,40 +15961,40 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15957 | 15961 | |
| 15958 | 15962 | const param_fields = .{ |
| 15959 | 15963 | // is_generic: bool, |
| 15960 | | Value.makeBool(is_generic).ip_index, |
| 15964 | Value.makeBool(is_generic).toIntern(), |
| 15961 | 15965 | // is_noalias: bool, |
| 15962 | | Value.makeBool(is_noalias).ip_index, |
| 15966 | Value.makeBool(is_noalias).toIntern(), |
| 15963 | 15967 | // type: ?type, |
| 15964 | 15968 | param_ty_val, |
| 15965 | 15969 | }; |
| 15966 | 15970 | param_val.* = try mod.intern(.{ .aggregate = .{ |
| 15967 | | .ty = param_info_ty.ip_index, |
| 15971 | .ty = param_info_ty.toIntern(), |
| 15968 | 15972 | .storage = .{ .elems = &param_fields }, |
| 15969 | 15973 | } }); |
| 15970 | 15974 | } |
| 15971 | 15975 | |
| 15972 | 15976 | const args_val = v: { |
| 15973 | 15977 | const args_slice_ty = try mod.ptrType(.{ |
| 15974 | | .elem_type = param_info_ty.ip_index, |
| 15978 | .elem_type = param_info_ty.toIntern(), |
| 15975 | 15979 | .size = .Slice, |
| 15976 | 15980 | .is_const = true, |
| 15977 | 15981 | }); |
| 15978 | 15982 | const new_decl = try params_anon_decl.finish( |
| 15979 | 15983 | try mod.arrayType(.{ |
| 15980 | 15984 | .len = param_vals.len, |
| 15981 | | .child = param_info_ty.ip_index, |
| 15985 | .child = param_info_ty.toIntern(), |
| 15982 | 15986 | .sentinel = .none, |
| 15983 | 15987 | }), |
| 15984 | 15988 | (try mod.intern(.{ .aggregate = .{ |
| 15985 | | .ty = args_slice_ty.ip_index, |
| 15989 | .ty = args_slice_ty.toIntern(), |
| 15986 | 15990 | .storage = .{ .elems = param_vals }, |
| 15987 | 15991 | } })).toValue(), |
| 15988 | 15992 | 0, // default alignment |
| 15989 | 15993 | ); |
| 15990 | 15994 | break :v try mod.intern(.{ .ptr = .{ |
| 15991 | | .ty = args_slice_ty.ip_index, |
| 15995 | .ty = args_slice_ty.toIntern(), |
| 15992 | 15996 | .addr = .{ .decl = new_decl }, |
| 15993 | | .len = (try mod.intValue(Type.usize, param_vals.len)).ip_index, |
| 15997 | .len = (try mod.intValue(Type.usize, param_vals.len)).toIntern(), |
| 15994 | 15998 | } }); |
| 15995 | 15999 | }; |
| 15996 | 16000 | |
| ... | ... | @@ -16003,43 +16007,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16003 | 16007 | |
| 16004 | 16008 | const field_values = .{ |
| 16005 | 16009 | // calling_convention: CallingConvention, |
| 16006 | | (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).ip_index, |
| 16010 | (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).toIntern(), |
| 16007 | 16011 | // alignment: comptime_int, |
| 16008 | | (try mod.intValue(Type.comptime_int, ty.abiAlignment(mod))).ip_index, |
| 16012 | (try mod.intValue(Type.comptime_int, ty.abiAlignment(mod))).toIntern(), |
| 16009 | 16013 | // is_generic: bool, |
| 16010 | | Value.makeBool(info.is_generic).ip_index, |
| 16014 | Value.makeBool(info.is_generic).toIntern(), |
| 16011 | 16015 | // is_var_args: bool, |
| 16012 | | Value.makeBool(info.is_var_args).ip_index, |
| 16016 | Value.makeBool(info.is_var_args).toIntern(), |
| 16013 | 16017 | // return_type: ?type, |
| 16014 | 16018 | ret_ty_opt, |
| 16015 | 16019 | // args: []const Fn.Param, |
| 16016 | 16020 | args_val, |
| 16017 | 16021 | }; |
| 16018 | 16022 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16019 | | .ty = type_info_ty.ip_index, |
| 16020 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).ip_index, |
| 16023 | .ty = type_info_ty.toIntern(), |
| 16024 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).toIntern(), |
| 16021 | 16025 | .val = try mod.intern(.{ .aggregate = .{ |
| 16022 | | .ty = fn_info_ty.ip_index, |
| 16026 | .ty = fn_info_ty.toIntern(), |
| 16023 | 16027 | .storage = .{ .elems = &field_values }, |
| 16024 | 16028 | } }), |
| 16025 | 16029 | } })).toValue()); |
| 16026 | 16030 | }, |
| 16027 | 16031 | .Int => { |
| 16032 | const int_info_decl_index = (try sema.namespaceLookup( |
| 16033 | block, |
| 16034 | src, |
| 16035 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16036 | "Int", |
| 16037 | )).?; |
| 16038 | try mod.declareDeclDependency(sema.owner_decl_index, int_info_decl_index); |
| 16039 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| 16040 | const int_info_decl = mod.declPtr(int_info_decl_index); |
| 16041 | const int_info_ty = int_info_decl.val.toType(); |
| 16042 | |
| 16028 | 16043 | const signedness_ty = try sema.getBuiltinType("Signedness"); |
| 16029 | 16044 | const info = ty.intInfo(mod); |
| 16030 | | const field_values = try sema.arena.alloc(Value, 2); |
| 16031 | | // signedness: Signedness, |
| 16032 | | field_values[0] = try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness)); |
| 16033 | | // bits: u16, |
| 16034 | | field_values[1] = try mod.intValue(Type.u16, info.bits); |
| 16035 | | |
| 16036 | | return sema.addConstant( |
| 16037 | | type_info_ty, |
| 16038 | | try Value.Tag.@"union".create(sema.arena, .{ |
| 16039 | | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int)), |
| 16040 | | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16041 | | }), |
| 16042 | | ); |
| 16045 | const field_values = .{ |
| 16046 | // signedness: Signedness, |
| 16047 | try (try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness))).intern(signedness_ty, mod), |
| 16048 | // bits: u16, |
| 16049 | (try mod.intValue(Type.u16, info.bits)).toIntern(), |
| 16050 | }; |
| 16051 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16052 | .ty = type_info_ty.toIntern(), |
| 16053 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int))).toIntern(), |
| 16054 | .val = try mod.intern(.{ .aggregate = .{ |
| 16055 | .ty = int_info_ty.toIntern(), |
| 16056 | .storage = .{ .elems = &field_values }, |
| 16057 | } }), |
| 16058 | } })).toValue()); |
| 16043 | 16059 | }, |
| 16044 | 16060 | .Float => { |
| 16045 | 16061 | const float_info_decl_index = (try sema.namespaceLookup( |
| ... | ... | @@ -16051,17 +16067,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16051 | 16067 | try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index); |
| 16052 | 16068 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| 16053 | 16069 | const float_info_decl = mod.declPtr(float_info_decl_index); |
| 16054 | | const float_ty = float_info_decl.val.toType(); |
| 16070 | const float_info_ty = float_info_decl.val.toType(); |
| 16055 | 16071 | |
| 16056 | 16072 | const field_vals = .{ |
| 16057 | 16073 | // bits: u16, |
| 16058 | | (try mod.intValue(Type.u16, ty.bitSize(mod))).ip_index, |
| 16074 | (try mod.intValue(Type.u16, ty.bitSize(mod))).toIntern(), |
| 16059 | 16075 | }; |
| 16060 | 16076 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16061 | | .ty = type_info_ty.ip_index, |
| 16062 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).ip_index, |
| 16077 | .ty = type_info_ty.toIntern(), |
| 16078 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).toIntern(), |
| 16063 | 16079 | .val = try mod.intern(.{ .aggregate = .{ |
| 16064 | | .ty = float_ty.ip_index, |
| 16080 | .ty = float_info_ty.toIntern(), |
| 16065 | 16081 | .storage = .{ .elems = &field_vals }, |
| 16066 | 16082 | } }), |
| 16067 | 16083 | } })).toValue()); |
| ... | ... | @@ -16099,80 +16115,121 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16099 | 16115 | break :t decl.val.toType(); |
| 16100 | 16116 | }; |
| 16101 | 16117 | |
| 16102 | | const field_values = try sema.arena.create([8]Value); |
| 16103 | | field_values.* = .{ |
| 16118 | const field_values = .{ |
| 16104 | 16119 | // size: Size, |
| 16105 | | try mod.enumValueFieldIndex(ptr_size_ty, @enumToInt(info.size)), |
| 16120 | try (try mod.enumValueFieldIndex(ptr_size_ty, @enumToInt(info.size))).intern(ptr_size_ty, mod), |
| 16106 | 16121 | // is_const: bool, |
| 16107 | | Value.makeBool(!info.mutable), |
| 16122 | Value.makeBool(!info.mutable).toIntern(), |
| 16108 | 16123 | // is_volatile: bool, |
| 16109 | | Value.makeBool(info.@"volatile"), |
| 16124 | Value.makeBool(info.@"volatile").toIntern(), |
| 16110 | 16125 | // alignment: comptime_int, |
| 16111 | | alignment, |
| 16126 | alignment.toIntern(), |
| 16112 | 16127 | // address_space: AddressSpace |
| 16113 | | try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")), |
| 16128 | try (try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace"))).intern(addrspace_ty, mod), |
| 16114 | 16129 | // child: type, |
| 16115 | | info.pointee_type.toValue(), |
| 16130 | info.pointee_type.toIntern(), |
| 16116 | 16131 | // is_allowzero: bool, |
| 16117 | | Value.makeBool(info.@"allowzero"), |
| 16132 | Value.makeBool(info.@"allowzero").toIntern(), |
| 16118 | 16133 | // sentinel: ?*const anyopaque, |
| 16119 | | try sema.optRefValue(block, info.pointee_type, info.sentinel), |
| 16134 | (try sema.optRefValue(block, info.pointee_type, info.sentinel)).toIntern(), |
| 16120 | 16135 | }; |
| 16121 | | |
| 16122 | | return sema.addConstant( |
| 16123 | | type_info_ty, |
| 16124 | | try Value.Tag.@"union".create(sema.arena, .{ |
| 16125 | | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer)), |
| 16126 | | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16127 | | }), |
| 16128 | | ); |
| 16136 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16137 | .ty = type_info_ty.toIntern(), |
| 16138 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer))).toIntern(), |
| 16139 | .val = try mod.intern(.{ .aggregate = .{ |
| 16140 | .ty = pointer_ty.toIntern(), |
| 16141 | .storage = .{ .elems = &field_values }, |
| 16142 | } }), |
| 16143 | } })).toValue()); |
| 16129 | 16144 | }, |
| 16130 | 16145 | .Array => { |
| 16131 | | const info = ty.arrayInfo(mod); |
| 16132 | | const field_values = try sema.arena.alloc(Value, 3); |
| 16133 | | // len: comptime_int, |
| 16134 | | field_values[0] = try mod.intValue(Type.comptime_int, info.len); |
| 16135 | | // child: type, |
| 16136 | | field_values[1] = info.elem_type.toValue(); |
| 16137 | | // sentinel: ?*const anyopaque, |
| 16138 | | field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel); |
| 16146 | const array_field_ty = t: { |
| 16147 | const array_field_ty_decl_index = (try sema.namespaceLookup( |
| 16148 | block, |
| 16149 | src, |
| 16150 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16151 | "Array", |
| 16152 | )).?; |
| 16153 | try mod.declareDeclDependency(sema.owner_decl_index, array_field_ty_decl_index); |
| 16154 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| 16155 | const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index); |
| 16156 | break :t array_field_ty_decl.val.toType(); |
| 16157 | }; |
| 16139 | 16158 | |
| 16140 | | return sema.addConstant( |
| 16141 | | type_info_ty, |
| 16142 | | try Value.Tag.@"union".create(sema.arena, .{ |
| 16143 | | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array)), |
| 16144 | | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16145 | | }), |
| 16146 | | ); |
| 16159 | const info = ty.arrayInfo(mod); |
| 16160 | const field_values = .{ |
| 16161 | // len: comptime_int, |
| 16162 | (try mod.intValue(Type.comptime_int, info.len)).toIntern(), |
| 16163 | // child: type, |
| 16164 | info.elem_type.toIntern(), |
| 16165 | // sentinel: ?*const anyopaque, |
| 16166 | (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(), |
| 16167 | }; |
| 16168 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16169 | .ty = type_info_ty.toIntern(), |
| 16170 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array))).toIntern(), |
| 16171 | .val = try mod.intern(.{ .aggregate = .{ |
| 16172 | .ty = array_field_ty.toIntern(), |
| 16173 | .storage = .{ .elems = &field_values }, |
| 16174 | } }), |
| 16175 | } })).toValue()); |
| 16147 | 16176 | }, |
| 16148 | 16177 | .Vector => { |
| 16149 | | const info = ty.arrayInfo(mod); |
| 16150 | | const field_values = try sema.arena.alloc(Value, 2); |
| 16151 | | // len: comptime_int, |
| 16152 | | field_values[0] = try mod.intValue(Type.comptime_int, info.len); |
| 16153 | | // child: type, |
| 16154 | | field_values[1] = info.elem_type.toValue(); |
| 16178 | const vector_field_ty = t: { |
| 16179 | const vector_field_ty_decl_index = (try sema.namespaceLookup( |
| 16180 | block, |
| 16181 | src, |
| 16182 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16183 | "Vector", |
| 16184 | )).?; |
| 16185 | try mod.declareDeclDependency(sema.owner_decl_index, vector_field_ty_decl_index); |
| 16186 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| 16187 | const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index); |
| 16188 | break :t vector_field_ty_decl.val.toType(); |
| 16189 | }; |
| 16155 | 16190 | |
| 16156 | | return sema.addConstant( |
| 16157 | | type_info_ty, |
| 16158 | | try Value.Tag.@"union".create(sema.arena, .{ |
| 16159 | | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector)), |
| 16160 | | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16161 | | }), |
| 16162 | | ); |
| 16191 | const info = ty.arrayInfo(mod); |
| 16192 | const field_values = .{ |
| 16193 | // len: comptime_int, |
| 16194 | (try mod.intValue(Type.comptime_int, info.len)).toIntern(), |
| 16195 | // child: type, |
| 16196 | info.elem_type.toIntern(), |
| 16197 | }; |
| 16198 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16199 | .ty = type_info_ty.toIntern(), |
| 16200 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector))).toIntern(), |
| 16201 | .val = try mod.intern(.{ .aggregate = .{ |
| 16202 | .ty = vector_field_ty.toIntern(), |
| 16203 | .storage = .{ .elems = &field_values }, |
| 16204 | } }), |
| 16205 | } })).toValue()); |
| 16163 | 16206 | }, |
| 16164 | 16207 | .Optional => { |
| 16165 | | const field_values = try sema.arena.alloc(Value, 1); |
| 16166 | | // child: type, |
| 16167 | | field_values[0] = ty.optionalChild(mod).toValue(); |
| 16208 | const optional_field_ty = t: { |
| 16209 | const optional_field_ty_decl_index = (try sema.namespaceLookup( |
| 16210 | block, |
| 16211 | src, |
| 16212 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16213 | "Optional", |
| 16214 | )).?; |
| 16215 | try mod.declareDeclDependency(sema.owner_decl_index, optional_field_ty_decl_index); |
| 16216 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| 16217 | const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index); |
| 16218 | break :t optional_field_ty_decl.val.toType(); |
| 16219 | }; |
| 16168 | 16220 | |
| 16169 | | return sema.addConstant( |
| 16170 | | type_info_ty, |
| 16171 | | try Value.Tag.@"union".create(sema.arena, .{ |
| 16172 | | .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Optional)), |
| 16173 | | .val = try Value.Tag.aggregate.create(sema.arena, field_values), |
| 16174 | | }), |
| 16175 | | ); |
| 16221 | const field_values = .{ |
| 16222 | // child: type, |
| 16223 | ty.optionalChild(mod).toIntern(), |
| 16224 | }; |
| 16225 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16226 | .ty = type_info_ty.toIntern(), |
| 16227 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector))).toIntern(), |
| 16228 | .val = try mod.intern(.{ .aggregate = .{ |
| 16229 | .ty = optional_field_ty.toIntern(), |
| 16230 | .storage = .{ .elems = &field_values }, |
| 16231 | } }), |
| 16232 | } })).toValue()); |
| 16176 | 16233 | }, |
| 16177 | 16234 | .ErrorSet => { |
| 16178 | 16235 | var fields_anon_decl = try block.startAnonDecl(); |
| ... | ... | @@ -16202,21 +16259,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16202 | 16259 | // Value can be zero-length slice otherwise |
| 16203 | 16260 | const error_field_vals = if (ty.isAnyError(mod)) null else blk: { |
| 16204 | 16261 | const names = ty.errorSetNames(mod); |
| 16205 | | const vals = try gpa.alloc(InternPool.Index, names.len); |
| 16206 | | defer gpa.free(vals); |
| 16262 | const vals = try sema.arena.alloc(InternPool.Index, names.len); |
| 16207 | 16263 | for (vals, names) |*field_val, name_ip| { |
| 16208 | 16264 | const name = mod.intern_pool.stringToSlice(name_ip); |
| 16209 | 16265 | const name_val = v: { |
| 16210 | 16266 | var anon_decl = try block.startAnonDecl(); |
| 16211 | 16267 | defer anon_decl.deinit(); |
| 16212 | | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 16268 | const new_decl_ty = try mod.arrayType(.{ |
| 16269 | .len = name.len, |
| 16270 | .child = .u8_type, |
| 16271 | .sentinel = .zero_u8, |
| 16272 | }); |
| 16213 | 16273 | const new_decl = try anon_decl.finish( |
| 16214 | | try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 16215 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 16274 | new_decl_ty, |
| 16275 | (try mod.intern(.{ .aggregate = .{ |
| 16276 | .ty = new_decl_ty.toIntern(), |
| 16277 | .storage = .{ .bytes = name }, |
| 16278 | } })).toValue(), |
| 16216 | 16279 | 0, // default alignment |
| 16217 | 16280 | ); |
| 16218 | 16281 | break :v try mod.intern(.{ .ptr = .{ |
| 16219 | | .ty = .slice_const_u8_type, |
| 16282 | .ty = .slice_const_u8_sentinel_0_type, |
| 16220 | 16283 | .addr = .{ .decl = new_decl }, |
| 16221 | 16284 | } }); |
| 16222 | 16285 | }; |
| ... | ... | @@ -16226,7 +16289,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16226 | 16289 | name_val, |
| 16227 | 16290 | }; |
| 16228 | 16291 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16229 | | .ty = error_field_ty.ip_index, |
| 16292 | .ty = error_field_ty.toIntern(), |
| 16230 | 16293 | .storage = .{ .elems = &error_field_fields }, |
| 16231 | 16294 | } }); |
| 16232 | 16295 | } |
| ... | ... | @@ -16236,39 +16299,39 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16236 | 16299 | |
| 16237 | 16300 | // Build our ?[]const Error value |
| 16238 | 16301 | const slice_errors_ty = try mod.ptrType(.{ |
| 16239 | | .elem_type = error_field_ty.ip_index, |
| 16302 | .elem_type = error_field_ty.toIntern(), |
| 16240 | 16303 | .size = .Slice, |
| 16241 | 16304 | .is_const = true, |
| 16242 | 16305 | }); |
| 16243 | | const opt_slice_errors_ty = try mod.optionalType(slice_errors_ty.ip_index); |
| 16306 | const opt_slice_errors_ty = try mod.optionalType(slice_errors_ty.toIntern()); |
| 16244 | 16307 | const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: { |
| 16245 | 16308 | const array_errors_ty = try mod.arrayType(.{ |
| 16246 | 16309 | .len = vals.len, |
| 16247 | | .child = error_field_ty.ip_index, |
| 16310 | .child = error_field_ty.toIntern(), |
| 16248 | 16311 | .sentinel = .none, |
| 16249 | 16312 | }); |
| 16250 | 16313 | const new_decl = try fields_anon_decl.finish( |
| 16251 | 16314 | array_errors_ty, |
| 16252 | 16315 | (try mod.intern(.{ .aggregate = .{ |
| 16253 | | .ty = array_errors_ty.ip_index, |
| 16316 | .ty = array_errors_ty.toIntern(), |
| 16254 | 16317 | .storage = .{ .elems = vals }, |
| 16255 | 16318 | } })).toValue(), |
| 16256 | 16319 | 0, // default alignment |
| 16257 | 16320 | ); |
| 16258 | 16321 | break :v try mod.intern(.{ .ptr = .{ |
| 16259 | | .ty = slice_errors_ty.ip_index, |
| 16322 | .ty = slice_errors_ty.toIntern(), |
| 16260 | 16323 | .addr = .{ .decl = new_decl }, |
| 16261 | 16324 | } }); |
| 16262 | 16325 | } else .none; |
| 16263 | 16326 | const errors_val = try mod.intern(.{ .opt = .{ |
| 16264 | | .ty = opt_slice_errors_ty.ip_index, |
| 16327 | .ty = opt_slice_errors_ty.toIntern(), |
| 16265 | 16328 | .val = errors_payload_val, |
| 16266 | 16329 | } }); |
| 16267 | 16330 | |
| 16268 | 16331 | // Construct Type{ .ErrorSet = errors_val } |
| 16269 | 16332 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16270 | | .ty = type_info_ty.ip_index, |
| 16271 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).ip_index, |
| 16333 | .ty = type_info_ty.toIntern(), |
| 16334 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).toIntern(), |
| 16272 | 16335 | .val = errors_val, |
| 16273 | 16336 | } })).toValue()); |
| 16274 | 16337 | }, |
| ... | ... | @@ -16288,22 +16351,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16288 | 16351 | |
| 16289 | 16352 | const field_values = .{ |
| 16290 | 16353 | // error_set: type, |
| 16291 | | ty.errorUnionSet(mod).ip_index, |
| 16354 | ty.errorUnionSet(mod).toIntern(), |
| 16292 | 16355 | // payload: type, |
| 16293 | | ty.errorUnionPayload(mod).ip_index, |
| 16356 | ty.errorUnionPayload(mod).toIntern(), |
| 16294 | 16357 | }; |
| 16295 | 16358 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16296 | | .ty = type_info_ty.ip_index, |
| 16297 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).ip_index, |
| 16359 | .ty = type_info_ty.toIntern(), |
| 16360 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).toIntern(), |
| 16298 | 16361 | .val = try mod.intern(.{ .aggregate = .{ |
| 16299 | | .ty = error_union_field_ty.ip_index, |
| 16362 | .ty = error_union_field_ty.toIntern(), |
| 16300 | 16363 | .storage = .{ .elems = &field_values }, |
| 16301 | 16364 | } }), |
| 16302 | 16365 | } })).toValue()); |
| 16303 | 16366 | }, |
| 16304 | 16367 | .Enum => { |
| 16305 | 16368 | // TODO: look into memoizing this result. |
| 16306 | | const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type; |
| 16369 | const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type; |
| 16307 | 16370 | |
| 16308 | 16371 | const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive); |
| 16309 | 16372 | |
| ... | ... | @@ -16323,23 +16386,28 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16323 | 16386 | break :t enum_field_ty_decl.val.toType(); |
| 16324 | 16387 | }; |
| 16325 | 16388 | |
| 16326 | | const enum_field_vals = try gpa.alloc(InternPool.Index, enum_type.names.len); |
| 16327 | | defer gpa.free(enum_field_vals); |
| 16328 | | |
| 16389 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); |
| 16329 | 16390 | for (enum_field_vals, 0..) |*field_val, i| { |
| 16330 | 16391 | const name_ip = enum_type.names[i]; |
| 16331 | 16392 | const name = mod.intern_pool.stringToSlice(name_ip); |
| 16332 | 16393 | const name_val = v: { |
| 16333 | 16394 | var anon_decl = try block.startAnonDecl(); |
| 16334 | 16395 | defer anon_decl.deinit(); |
| 16335 | | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 16396 | const new_decl_ty = try mod.arrayType(.{ |
| 16397 | .len = name.len, |
| 16398 | .child = .u8_type, |
| 16399 | .sentinel = .zero_u8, |
| 16400 | }); |
| 16336 | 16401 | const new_decl = try anon_decl.finish( |
| 16337 | | try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod), |
| 16338 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 16402 | new_decl_ty, |
| 16403 | (try mod.intern(.{ .aggregate = .{ |
| 16404 | .ty = new_decl_ty.toIntern(), |
| 16405 | .storage = .{ .bytes = name }, |
| 16406 | } })).toValue(), |
| 16339 | 16407 | 0, // default alignment |
| 16340 | 16408 | ); |
| 16341 | 16409 | break :v try mod.intern(.{ .ptr = .{ |
| 16342 | | .ty = .slice_const_u8_type, |
| 16410 | .ty = .slice_const_u8_sentinel_0_type, |
| 16343 | 16411 | .addr = .{ .decl = new_decl }, |
| 16344 | 16412 | } }); |
| 16345 | 16413 | }; |
| ... | ... | @@ -16348,10 +16416,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16348 | 16416 | // name: []const u8, |
| 16349 | 16417 | name_val, |
| 16350 | 16418 | // value: comptime_int, |
| 16351 | | (try mod.intValue(Type.comptime_int, i)).ip_index, |
| 16419 | (try mod.intValue(Type.comptime_int, i)).toIntern(), |
| 16352 | 16420 | }; |
| 16353 | 16421 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16354 | | .ty = enum_field_ty.ip_index, |
| 16422 | .ty = enum_field_ty.toIntern(), |
| 16355 | 16423 | .storage = .{ .elems = &enum_field_fields }, |
| 16356 | 16424 | } }); |
| 16357 | 16425 | } |
| ... | ... | @@ -16359,23 +16427,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16359 | 16427 | const fields_val = v: { |
| 16360 | 16428 | const fields_array_ty = try mod.arrayType(.{ |
| 16361 | 16429 | .len = enum_field_vals.len, |
| 16362 | | .child = enum_field_ty.ip_index, |
| 16430 | .child = enum_field_ty.toIntern(), |
| 16363 | 16431 | .sentinel = .none, |
| 16364 | 16432 | }); |
| 16365 | 16433 | const new_decl = try fields_anon_decl.finish( |
| 16366 | 16434 | fields_array_ty, |
| 16367 | 16435 | (try mod.intern(.{ .aggregate = .{ |
| 16368 | | .ty = fields_array_ty.ip_index, |
| 16436 | .ty = fields_array_ty.toIntern(), |
| 16369 | 16437 | .storage = .{ .elems = enum_field_vals }, |
| 16370 | 16438 | } })).toValue(), |
| 16371 | 16439 | 0, // default alignment |
| 16372 | 16440 | ); |
| 16373 | 16441 | break :v try mod.intern(.{ .ptr = .{ |
| 16374 | 16442 | .ty = (try mod.ptrType(.{ |
| 16375 | | .elem_type = enum_field_ty.ip_index, |
| 16443 | .elem_type = enum_field_ty.toIntern(), |
| 16376 | 16444 | .size = .Slice, |
| 16377 | 16445 | .is_const = true, |
| 16378 | | })).ip_index, |
| 16446 | })).toIntern(), |
| 16379 | 16447 | .addr = .{ .decl = new_decl }, |
| 16380 | 16448 | } }); |
| 16381 | 16449 | }; |
| ... | ... | @@ -16403,13 +16471,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16403 | 16471 | // decls: []const Declaration, |
| 16404 | 16472 | decls_val, |
| 16405 | 16473 | // is_exhaustive: bool, |
| 16406 | | is_exhaustive.ip_index, |
| 16474 | is_exhaustive.toIntern(), |
| 16407 | 16475 | }; |
| 16408 | 16476 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16409 | | .ty = type_info_ty.ip_index, |
| 16410 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).ip_index, |
| 16477 | .ty = type_info_ty.toIntern(), |
| 16478 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).toIntern(), |
| 16411 | 16479 | .val = try mod.intern(.{ .aggregate = .{ |
| 16412 | | .ty = type_enum_ty.ip_index, |
| 16480 | .ty = type_enum_ty.toIntern(), |
| 16413 | 16481 | .storage = .{ .elems = &field_values }, |
| 16414 | 16482 | } }), |
| 16415 | 16483 | } })).toValue()); |
| ... | ... | @@ -16460,14 +16528,21 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16460 | 16528 | const name_val = v: { |
| 16461 | 16529 | var anon_decl = try block.startAnonDecl(); |
| 16462 | 16530 | defer anon_decl.deinit(); |
| 16463 | | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 16531 | const new_decl_ty = try mod.arrayType(.{ |
| 16532 | .len = name.len, |
| 16533 | .child = .u8_type, |
| 16534 | .sentinel = .zero_u8, |
| 16535 | }); |
| 16464 | 16536 | const new_decl = try anon_decl.finish( |
| 16465 | | try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 16466 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 16537 | new_decl_ty, |
| 16538 | (try mod.intern(.{ .aggregate = .{ |
| 16539 | .ty = new_decl_ty.toIntern(), |
| 16540 | .storage = .{ .bytes = name }, |
| 16541 | } })).toValue(), |
| 16467 | 16542 | 0, // default alignment |
| 16468 | 16543 | ); |
| 16469 | 16544 | break :v try mod.intern(.{ .ptr = .{ |
| 16470 | | .ty = .slice_const_u8_type, |
| 16545 | .ty = .slice_const_u8_sentinel_0_type, |
| 16471 | 16546 | .addr = .{ .decl = new_decl }, |
| 16472 | 16547 | } }); |
| 16473 | 16548 | }; |
| ... | ... | @@ -16481,12 +16556,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16481 | 16556 | // name: []const u8, |
| 16482 | 16557 | name_val, |
| 16483 | 16558 | // type: type, |
| 16484 | | field.ty.ip_index, |
| 16559 | field.ty.toIntern(), |
| 16485 | 16560 | // alignment: comptime_int, |
| 16486 | | (try mod.intValue(Type.comptime_int, alignment)).ip_index, |
| 16561 | (try mod.intValue(Type.comptime_int, alignment)).toIntern(), |
| 16487 | 16562 | }; |
| 16488 | 16563 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16489 | | .ty = union_field_ty.ip_index, |
| 16564 | .ty = union_field_ty.toIntern(), |
| 16490 | 16565 | .storage = .{ .elems = &union_field_fields }, |
| 16491 | 16566 | } }); |
| 16492 | 16567 | } |
| ... | ... | @@ -16494,33 +16569,33 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16494 | 16569 | const fields_val = v: { |
| 16495 | 16570 | const array_fields_ty = try mod.arrayType(.{ |
| 16496 | 16571 | .len = union_field_vals.len, |
| 16497 | | .child = union_field_ty.ip_index, |
| 16572 | .child = union_field_ty.toIntern(), |
| 16498 | 16573 | .sentinel = .none, |
| 16499 | 16574 | }); |
| 16500 | 16575 | const new_decl = try fields_anon_decl.finish( |
| 16501 | 16576 | array_fields_ty, |
| 16502 | 16577 | (try mod.intern(.{ .aggregate = .{ |
| 16503 | | .ty = array_fields_ty.ip_index, |
| 16578 | .ty = array_fields_ty.toIntern(), |
| 16504 | 16579 | .storage = .{ .elems = union_field_vals }, |
| 16505 | 16580 | } })).toValue(), |
| 16506 | 16581 | 0, // default alignment |
| 16507 | 16582 | ); |
| 16508 | 16583 | break :v try mod.intern(.{ .ptr = .{ |
| 16509 | 16584 | .ty = (try mod.ptrType(.{ |
| 16510 | | .elem_type = union_field_ty.ip_index, |
| 16585 | .elem_type = union_field_ty.toIntern(), |
| 16511 | 16586 | .size = .Slice, |
| 16512 | 16587 | .is_const = true, |
| 16513 | | })).ip_index, |
| 16588 | })).toIntern(), |
| 16514 | 16589 | .addr = .{ .decl = new_decl }, |
| 16515 | | .len = (try mod.intValue(Type.usize, union_field_vals.len)).ip_index, |
| 16590 | .len = (try mod.intValue(Type.usize, union_field_vals.len)).toIntern(), |
| 16516 | 16591 | } }); |
| 16517 | 16592 | }; |
| 16518 | 16593 | |
| 16519 | 16594 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod)); |
| 16520 | 16595 | |
| 16521 | 16596 | const enum_tag_ty_val = try mod.intern(.{ .opt = .{ |
| 16522 | | .ty = (try mod.optionalType(.type_type)).ip_index, |
| 16523 | | .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.ip_index else .none, |
| 16597 | .ty = (try mod.optionalType(.type_type)).toIntern(), |
| 16598 | .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.toIntern() else .none, |
| 16524 | 16599 | } }); |
| 16525 | 16600 | |
| 16526 | 16601 | const container_layout_ty = t: { |
| ... | ... | @@ -16538,7 +16613,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16538 | 16613 | |
| 16539 | 16614 | const field_values = .{ |
| 16540 | 16615 | // layout: ContainerLayout, |
| 16541 | | (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index, |
| 16616 | (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(), |
| 16542 | 16617 | |
| 16543 | 16618 | // tag_type: ?type, |
| 16544 | 16619 | enum_tag_ty_val, |
| ... | ... | @@ -16548,10 +16623,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16548 | 16623 | decls_val, |
| 16549 | 16624 | }; |
| 16550 | 16625 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16551 | | .ty = type_info_ty.ip_index, |
| 16552 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).ip_index, |
| 16626 | .ty = type_info_ty.toIntern(), |
| 16627 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).toIntern(), |
| 16553 | 16628 | .val = try mod.intern(.{ .aggregate = .{ |
| 16554 | | .ty = type_union_ty.ip_index, |
| 16629 | .ty = type_union_ty.toIntern(), |
| 16555 | 16630 | .storage = .{ .elems = &field_values }, |
| 16556 | 16631 | } }), |
| 16557 | 16632 | } })).toValue()); |
| ... | ... | @@ -16595,7 +16670,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16595 | 16670 | var struct_field_vals: []InternPool.Index = &.{}; |
| 16596 | 16671 | defer gpa.free(struct_field_vals); |
| 16597 | 16672 | fv: { |
| 16598 | | const struct_type = switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) { |
| 16673 | const struct_type = switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 16599 | 16674 | .anon_struct_type => |tuple| { |
| 16600 | 16675 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len); |
| 16601 | 16676 | for ( |
| ... | ... | @@ -16611,16 +16686,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16611 | 16686 | // https://github.com/ziglang/zig/issues/15709 |
| 16612 | 16687 | @as([]const u8, mod.intern_pool.stringToSlice(tuple.names[i])) |
| 16613 | 16688 | else |
| 16614 | | try std.fmt.allocPrintZ(anon_decl.arena(), "{d}", .{i}); |
| 16689 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 16690 | const new_decl_ty = try mod.arrayType(.{ |
| 16691 | .len = bytes.len, |
| 16692 | .child = .u8_type, |
| 16693 | .sentinel = .zero_u8, |
| 16694 | }); |
| 16615 | 16695 | const new_decl = try anon_decl.finish( |
| 16616 | | try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod), |
| 16617 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes.ptr[0 .. bytes.len + 1]), |
| 16696 | new_decl_ty, |
| 16697 | (try mod.intern(.{ .aggregate = .{ |
| 16698 | .ty = new_decl_ty.toIntern(), |
| 16699 | .storage = .{ .bytes = bytes }, |
| 16700 | } })).toValue(), |
| 16618 | 16701 | 0, // default alignment |
| 16619 | 16702 | ); |
| 16620 | 16703 | break :v try mod.intern(.{ .ptr = .{ |
| 16621 | | .ty = .slice_const_u8_type, |
| 16704 | .ty = .slice_const_u8_sentinel_0_type, |
| 16622 | 16705 | .addr = .{ .decl = new_decl }, |
| 16623 | | .len = (try mod.intValue(Type.usize, bytes.len)).ip_index, |
| 16706 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), |
| 16624 | 16707 | } }); |
| 16625 | 16708 | }; |
| 16626 | 16709 | |
| ... | ... | @@ -16633,14 +16716,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16633 | 16716 | // type: type, |
| 16634 | 16717 | field_ty, |
| 16635 | 16718 | // default_value: ?*const anyopaque, |
| 16636 | | default_val_ptr.ip_index, |
| 16719 | default_val_ptr.toIntern(), |
| 16637 | 16720 | // is_comptime: bool, |
| 16638 | | Value.makeBool(is_comptime).ip_index, |
| 16721 | Value.makeBool(is_comptime).toIntern(), |
| 16639 | 16722 | // alignment: comptime_int, |
| 16640 | | (try mod.intValue(Type.comptime_int, field_ty.toType().abiAlignment(mod))).ip_index, |
| 16723 | (try mod.intValue(Type.comptime_int, field_ty.toType().abiAlignment(mod))).toIntern(), |
| 16641 | 16724 | }; |
| 16642 | 16725 | struct_field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16643 | | .ty = struct_field_ty.ip_index, |
| 16726 | .ty = struct_field_ty.toIntern(), |
| 16644 | 16727 | .storage = .{ .elems = &struct_field_fields }, |
| 16645 | 16728 | } }); |
| 16646 | 16729 | } |
| ... | ... | @@ -16660,20 +16743,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16660 | 16743 | const name_val = v: { |
| 16661 | 16744 | var anon_decl = try block.startAnonDecl(); |
| 16662 | 16745 | defer anon_decl.deinit(); |
| 16663 | | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 16746 | const new_decl_ty = try mod.arrayType(.{ |
| 16747 | .len = name.len, |
| 16748 | .child = .u8_type, |
| 16749 | .sentinel = .zero_u8, |
| 16750 | }); |
| 16664 | 16751 | const new_decl = try anon_decl.finish( |
| 16665 | | try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 16666 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 16752 | new_decl_ty, |
| 16753 | (try mod.intern(.{ .aggregate = .{ |
| 16754 | .ty = new_decl_ty.toIntern(), |
| 16755 | .storage = .{ .bytes = name }, |
| 16756 | } })).toValue(), |
| 16667 | 16757 | 0, // default alignment |
| 16668 | 16758 | ); |
| 16669 | 16759 | break :v try mod.intern(.{ .ptr = .{ |
| 16670 | | .ty = .slice_const_u8_type, |
| 16760 | .ty = .slice_const_u8_sentinel_0_type, |
| 16671 | 16761 | .addr = .{ .decl = new_decl }, |
| 16672 | | .len = (try mod.intValue(Type.usize, bytes.len)).ip_index, |
| 16762 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 16673 | 16763 | } }); |
| 16674 | 16764 | }; |
| 16675 | 16765 | |
| 16676 | | const opt_default_val = if (field.default_val.ip_index == .unreachable_value) |
| 16766 | const opt_default_val = if (field.default_val.toIntern() == .unreachable_value) |
| 16677 | 16767 | null |
| 16678 | 16768 | else |
| 16679 | 16769 | field.default_val; |
| ... | ... | @@ -16684,16 +16774,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16684 | 16774 | // name: []const u8, |
| 16685 | 16775 | name_val, |
| 16686 | 16776 | // type: type, |
| 16687 | | field.ty.ip_index, |
| 16777 | field.ty.toIntern(), |
| 16688 | 16778 | // default_value: ?*const anyopaque, |
| 16689 | | default_val_ptr.ip_index, |
| 16779 | default_val_ptr.toIntern(), |
| 16690 | 16780 | // is_comptime: bool, |
| 16691 | | Value.makeBool(field.is_comptime).ip_index, |
| 16781 | Value.makeBool(field.is_comptime).toIntern(), |
| 16692 | 16782 | // alignment: comptime_int, |
| 16693 | | (try mod.intValue(Type.comptime_int, alignment)).ip_index, |
| 16783 | (try mod.intValue(Type.comptime_int, alignment)).toIntern(), |
| 16694 | 16784 | }; |
| 16695 | 16785 | field_val.* = try mod.intern(.{ .aggregate = .{ |
| 16696 | | .ty = struct_field_ty.ip_index, |
| 16786 | .ty = struct_field_ty.toIntern(), |
| 16697 | 16787 | .storage = .{ .elems = &struct_field_fields }, |
| 16698 | 16788 | } }); |
| 16699 | 16789 | } |
| ... | ... | @@ -16702,37 +16792,37 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16702 | 16792 | const fields_val = v: { |
| 16703 | 16793 | const array_fields_ty = try mod.arrayType(.{ |
| 16704 | 16794 | .len = struct_field_vals.len, |
| 16705 | | .child = struct_field_ty.ip_index, |
| 16795 | .child = struct_field_ty.toIntern(), |
| 16706 | 16796 | .sentinel = .none, |
| 16707 | 16797 | }); |
| 16708 | 16798 | const new_decl = try fields_anon_decl.finish( |
| 16709 | 16799 | array_fields_ty, |
| 16710 | 16800 | (try mod.intern(.{ .aggregate = .{ |
| 16711 | | .ty = array_fields_ty.ip_index, |
| 16801 | .ty = array_fields_ty.toIntern(), |
| 16712 | 16802 | .storage = .{ .elems = struct_field_vals }, |
| 16713 | 16803 | } })).toValue(), |
| 16714 | 16804 | 0, // default alignment |
| 16715 | 16805 | ); |
| 16716 | 16806 | break :v try mod.intern(.{ .ptr = .{ |
| 16717 | 16807 | .ty = (try mod.ptrType(.{ |
| 16718 | | .elem_type = struct_field_ty.ip_index, |
| 16808 | .elem_type = struct_field_ty.toIntern(), |
| 16719 | 16809 | .size = .Slice, |
| 16720 | 16810 | .is_const = true, |
| 16721 | | })).ip_index, |
| 16811 | })).toIntern(), |
| 16722 | 16812 | .addr = .{ .decl = new_decl }, |
| 16723 | | .len = (try mod.intValue(Type.usize, struct_field_vals.len)).ip_index, |
| 16813 | .len = (try mod.intValue(Type.usize, struct_field_vals.len)).toIntern(), |
| 16724 | 16814 | } }); |
| 16725 | 16815 | }; |
| 16726 | 16816 | |
| 16727 | 16817 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespaceIndex(mod)); |
| 16728 | 16818 | |
| 16729 | 16819 | const backing_integer_val = try mod.intern(.{ .opt = .{ |
| 16730 | | .ty = (try mod.optionalType(.type_type)).ip_index, |
| 16820 | .ty = (try mod.optionalType(.type_type)).toIntern(), |
| 16731 | 16821 | .val = if (layout == .Packed) val: { |
| 16732 | 16822 | const struct_obj = mod.typeToStruct(struct_ty).?; |
| 16733 | 16823 | assert(struct_obj.haveLayout()); |
| 16734 | 16824 | assert(struct_obj.backing_int_ty.isInt(mod)); |
| 16735 | | break :val struct_obj.backing_int_ty.ip_index; |
| 16825 | break :val struct_obj.backing_int_ty.toIntern(); |
| 16736 | 16826 | } else .none, |
| 16737 | 16827 | } }); |
| 16738 | 16828 | |
| ... | ... | @@ -16751,7 +16841,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16751 | 16841 | |
| 16752 | 16842 | const field_values = [_]InternPool.Index{ |
| 16753 | 16843 | // layout: ContainerLayout, |
| 16754 | | (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index, |
| 16844 | (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(), |
| 16755 | 16845 | // backing_integer: ?type, |
| 16756 | 16846 | backing_integer_val, |
| 16757 | 16847 | // fields: []const StructField, |
| ... | ... | @@ -16759,13 +16849,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16759 | 16849 | // decls: []const Declaration, |
| 16760 | 16850 | decls_val, |
| 16761 | 16851 | // is_tuple: bool, |
| 16762 | | Value.makeBool(struct_ty.isTuple(mod)).ip_index, |
| 16852 | Value.makeBool(struct_ty.isTuple(mod)).toIntern(), |
| 16763 | 16853 | }; |
| 16764 | 16854 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16765 | | .ty = type_info_ty.ip_index, |
| 16766 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).ip_index, |
| 16855 | .ty = type_info_ty.toIntern(), |
| 16856 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).toIntern(), |
| 16767 | 16857 | .val = try mod.intern(.{ .aggregate = .{ |
| 16768 | | .ty = type_struct_ty.ip_index, |
| 16858 | .ty = type_struct_ty.toIntern(), |
| 16769 | 16859 | .storage = .{ .elems = &field_values }, |
| 16770 | 16860 | } }), |
| 16771 | 16861 | } })).toValue()); |
| ... | ... | @@ -16794,10 +16884,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16794 | 16884 | decls_val, |
| 16795 | 16885 | }; |
| 16796 | 16886 | return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{ |
| 16797 | | .ty = type_info_ty.ip_index, |
| 16798 | | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).ip_index, |
| 16887 | .ty = type_info_ty.toIntern(), |
| 16888 | .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).toIntern(), |
| 16799 | 16889 | .val = try mod.intern(.{ .aggregate = .{ |
| 16800 | | .ty = type_opaque_ty.ip_index, |
| 16890 | .ty = type_opaque_ty.toIntern(), |
| 16801 | 16891 | .storage = .{ .elems = &field_values }, |
| 16802 | 16892 | } }), |
| 16803 | 16893 | } })).toValue()); |
| ... | ... | @@ -16845,25 +16935,25 @@ fn typeInfoDecls( |
| 16845 | 16935 | |
| 16846 | 16936 | const array_decl_ty = try mod.arrayType(.{ |
| 16847 | 16937 | .len = decl_vals.items.len, |
| 16848 | | .child = declaration_ty.ip_index, |
| 16938 | .child = declaration_ty.toIntern(), |
| 16849 | 16939 | .sentinel = .none, |
| 16850 | 16940 | }); |
| 16851 | 16941 | const new_decl = try decls_anon_decl.finish( |
| 16852 | 16942 | array_decl_ty, |
| 16853 | 16943 | (try mod.intern(.{ .aggregate = .{ |
| 16854 | | .ty = array_decl_ty.ip_index, |
| 16944 | .ty = array_decl_ty.toIntern(), |
| 16855 | 16945 | .storage = .{ .elems = decl_vals.items }, |
| 16856 | 16946 | } })).toValue(), |
| 16857 | 16947 | 0, // default alignment |
| 16858 | 16948 | ); |
| 16859 | 16949 | return try mod.intern(.{ .ptr = .{ |
| 16860 | 16950 | .ty = (try mod.ptrType(.{ |
| 16861 | | .elem_type = declaration_ty.ip_index, |
| 16951 | .elem_type = declaration_ty.toIntern(), |
| 16862 | 16952 | .size = .Slice, |
| 16863 | 16953 | .is_const = true, |
| 16864 | | })).ip_index, |
| 16954 | })).toIntern(), |
| 16865 | 16955 | .addr = .{ .decl = new_decl }, |
| 16866 | | .len = (try mod.intValue(Type.usize, decl_vals.items.len)).ip_index, |
| 16956 | .len = (try mod.intValue(Type.usize, decl_vals.items.len)).toIntern(), |
| 16867 | 16957 | } }); |
| 16868 | 16958 | } |
| 16869 | 16959 | |
| ... | ... | @@ -16892,16 +16982,24 @@ fn typeInfoNamespaceDecls( |
| 16892 | 16982 | const name_val = v: { |
| 16893 | 16983 | var anon_decl = try block.startAnonDecl(); |
| 16894 | 16984 | defer anon_decl.deinit(); |
| 16895 | | const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0)); |
| 16985 | const name = mem.span(decl.name); |
| 16986 | const new_decl_ty = try mod.arrayType(.{ |
| 16987 | .len = name.len, |
| 16988 | .child = .u8_type, |
| 16989 | .sentinel = .zero_u8, |
| 16990 | }); |
| 16896 | 16991 | const new_decl = try anon_decl.finish( |
| 16897 | | try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 16898 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 16992 | new_decl_ty, |
| 16993 | (try mod.intern(.{ .aggregate = .{ |
| 16994 | .ty = new_decl_ty.toIntern(), |
| 16995 | .storage = .{ .bytes = name }, |
| 16996 | } })).toValue(), |
| 16899 | 16997 | 0, // default alignment |
| 16900 | 16998 | ); |
| 16901 | 16999 | break :v try mod.intern(.{ .ptr = .{ |
| 16902 | | .ty = .slice_const_u8_type, |
| 17000 | .ty = .slice_const_u8_sentinel_0_type, |
| 16903 | 17001 | .addr = .{ .decl = new_decl }, |
| 16904 | | .len = (try mod.intValue(Type.usize, bytes.len)).ip_index, |
| 17002 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 16905 | 17003 | } }); |
| 16906 | 17004 | }; |
| 16907 | 17005 | |
| ... | ... | @@ -16909,10 +17007,10 @@ fn typeInfoNamespaceDecls( |
| 16909 | 17007 | //name: []const u8, |
| 16910 | 17008 | name_val, |
| 16911 | 17009 | //is_pub: bool, |
| 16912 | | Value.makeBool(decl.is_pub).ip_index, |
| 17010 | Value.makeBool(decl.is_pub).toIntern(), |
| 16913 | 17011 | }; |
| 16914 | 17012 | try decl_vals.append(try mod.intern(.{ .aggregate = .{ |
| 16915 | | .ty = declaration_ty.ip_index, |
| 17013 | .ty = declaration_ty.toIntern(), |
| 16916 | 17014 | .storage = .{ .elems = &fields }, |
| 16917 | 17015 | } })); |
| 16918 | 17016 | } |
| ... | ... | @@ -16985,7 +17083,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi |
| 16985 | 17083 | const log2_elem_ty = try sema.log2IntType(block, elem_ty, src); |
| 16986 | 17084 | return mod.vectorType(.{ |
| 16987 | 17085 | .len = operand.vectorLen(mod), |
| 16988 | | .child = log2_elem_ty.ip_index, |
| 17086 | .child = log2_elem_ty.toIntern(), |
| 16989 | 17087 | }); |
| 16990 | 17088 | }, |
| 16991 | 17089 | else => {}, |
| ... | ... | @@ -17527,7 +17625,7 @@ fn zirRetErrValue( |
| 17527 | 17625 | const kv = try mod.getErrorValue(err_name); |
| 17528 | 17626 | const error_set_type = try mod.singleErrorSetType(err_name); |
| 17529 | 17627 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 17530 | | .ty = error_set_type.ip_index, |
| 17628 | .ty = error_set_type.toIntern(), |
| 17531 | 17629 | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), |
| 17532 | 17630 | } })).toValue()); |
| 17533 | 17631 | return sema.analyzeRet(block, result_inst, src); |
| ... | ... | @@ -17854,9 +17952,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17854 | 17952 | const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known"); |
| 17855 | 17953 | // Check if this happens to be the lazy alignment of our element type, in |
| 17856 | 17954 | // which case we can make this 0 without resolving it. |
| 17857 | | switch (mod.intern_pool.indexToKey(val.ip_index)) { |
| 17955 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 17858 | 17956 | .int => |int| switch (int.storage) { |
| 17859 | | .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.ip_index) break :blk .none, |
| 17957 | .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none, |
| 17860 | 17958 | else => {}, |
| 17861 | 17959 | }, |
| 17862 | 17960 | else => {}, |
| ... | ... | @@ -17985,7 +18083,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 17985 | 18083 | } |
| 17986 | 18084 | } |
| 17987 | 18085 | return sema.addConstant(obj_ty, (try mod.intern(.{ .aggregate = .{ |
| 17988 | | .ty = obj_ty.ip_index, |
| 18086 | .ty = obj_ty.toIntern(), |
| 17989 | 18087 | .storage = .{ .elems = &.{} }, |
| 17990 | 18088 | } })).toValue()); |
| 17991 | 18089 | } |
| ... | ... | @@ -18021,10 +18119,11 @@ fn unionInit( |
| 18021 | 18119 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 18022 | 18120 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| 18023 | 18121 | const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); |
| 18024 | | return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{ |
| 18025 | | .tag = tag_val, |
| 18026 | | .val = init_val, |
| 18027 | | })); |
| 18122 | return sema.addConstant(union_ty, (try mod.intern(.{ .un = .{ |
| 18123 | .ty = union_ty.toIntern(), |
| 18124 | .tag = try tag_val.intern(tag_ty, mod), |
| 18125 | .val = try init_val.intern(field.ty, mod), |
| 18126 | } })).toValue()); |
| 18028 | 18127 | } |
| 18029 | 18128 | |
| 18030 | 18129 | try sema.requireRuntimeBlock(block, init_src, null); |
| ... | ... | @@ -18125,12 +18224,12 @@ fn zirStructInit( |
| 18125 | 18224 | |
| 18126 | 18225 | const init_inst = try sema.resolveInst(item.data.init); |
| 18127 | 18226 | if (try sema.resolveMaybeUndefVal(init_inst)) |val| { |
| 18128 | | return sema.addConstantMaybeRef( |
| 18129 | | block, |
| 18130 | | resolved_ty, |
| 18131 | | try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }), |
| 18132 | | is_ref, |
| 18133 | | ); |
| 18227 | const field = resolved_ty.unionFields(mod).values()[field_index]; |
| 18228 | return sema.addConstantMaybeRef(block, resolved_ty, (try mod.intern(.{ .un = .{ |
| 18229 | .ty = resolved_ty.toIntern(), |
| 18230 | .tag = try tag_val.intern(tag_ty, mod), |
| 18231 | .val = try val.intern(field.ty, mod), |
| 18232 | } })).toValue(), is_ref); |
| 18134 | 18233 | } |
| 18135 | 18234 | |
| 18136 | 18235 | if (is_ref) { |
| ... | ... | @@ -18171,7 +18270,7 @@ fn finishStructInit( |
| 18171 | 18270 | var root_msg: ?*Module.ErrorMsg = null; |
| 18172 | 18271 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 18173 | 18272 | |
| 18174 | | switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) { |
| 18273 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 18175 | 18274 | .anon_struct_type => |anon_struct| { |
| 18176 | 18275 | for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| { |
| 18177 | 18276 | if (field_inits[i] != .none) continue; |
| ... | ... | @@ -18204,7 +18303,7 @@ fn finishStructInit( |
| 18204 | 18303 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 18205 | 18304 | if (field_inits[i] != .none) continue; |
| 18206 | 18305 | |
| 18207 | | if (field.default_val.ip_index == .unreachable_value) { |
| 18306 | if (field.default_val.toIntern() == .unreachable_value) { |
| 18208 | 18307 | const field_name = struct_obj.fields.keys()[i]; |
| 18209 | 18308 | const template = "missing struct field: {s}"; |
| 18210 | 18309 | const args = .{field_name}; |
| ... | ... | @@ -18250,7 +18349,7 @@ fn finishStructInit( |
| 18250 | 18349 | .intern(struct_ty.structFieldType(field_i, mod), mod); |
| 18251 | 18350 | } |
| 18252 | 18351 | const struct_val = try mod.intern(.{ .aggregate = .{ |
| 18253 | | .ty = struct_ty.ip_index, |
| 18352 | .ty = struct_ty.toIntern(), |
| 18254 | 18353 | .storage = .{ .elems = elems }, |
| 18255 | 18354 | } }); |
| 18256 | 18355 | return sema.addConstantMaybeRef(block, struct_ty, struct_val.toValue(), is_ref); |
| ... | ... | @@ -18331,7 +18430,7 @@ fn zirStructInitAnon( |
| 18331 | 18430 | gop.value_ptr.* = i; |
| 18332 | 18431 | |
| 18333 | 18432 | const init = try sema.resolveInst(item.data.init); |
| 18334 | | field_ty.* = sema.typeOf(init).ip_index; |
| 18433 | field_ty.* = sema.typeOf(init).toIntern(); |
| 18335 | 18434 | if (field_ty.toType().zigTypeTag(mod) == .Opaque) { |
| 18336 | 18435 | const msg = msg: { |
| 18337 | 18436 | const decl = sema.mod.declPtr(block.src_decl); |
| ... | ... | @@ -18464,15 +18563,19 @@ fn zirArrayInit( |
| 18464 | 18563 | } else null; |
| 18465 | 18564 | |
| 18466 | 18565 | const runtime_index = opt_runtime_index orelse { |
| 18467 | | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); |
| 18468 | | |
| 18469 | | for (resolved_args, 0..) |arg, i| { |
| 18566 | const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len); |
| 18567 | for (elem_vals, resolved_args, 0..) |*val, arg, i| { |
| 18568 | const elem_ty = if (array_ty.zigTypeTag(mod) == .Struct) |
| 18569 | array_ty.structFieldType(i, mod) |
| 18570 | else |
| 18571 | array_ty.elemType2(mod); |
| 18470 | 18572 | // We checked that all args are comptime above. |
| 18471 | | elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?; |
| 18573 | val.* = try ((sema.resolveMaybeUndefVal(arg) catch unreachable).?).intern(elem_ty, mod); |
| 18472 | 18574 | } |
| 18473 | | |
| 18474 | | const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals); |
| 18475 | | return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref); |
| 18575 | return sema.addConstantMaybeRef(block, array_ty, (try mod.intern(.{ .aggregate = .{ |
| 18576 | .ty = array_ty.toIntern(), |
| 18577 | .storage = .{ .elems = elem_vals }, |
| 18578 | } })).toValue(), is_ref); |
| 18476 | 18579 | }; |
| 18477 | 18580 | |
| 18478 | 18581 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| ... | ... | @@ -18548,7 +18651,7 @@ fn zirArrayInitAnon( |
| 18548 | 18651 | for (operands, 0..) |operand, i| { |
| 18549 | 18652 | const operand_src = src; // TODO better source location |
| 18550 | 18653 | const elem = try sema.resolveInst(operand); |
| 18551 | | types[i] = sema.typeOf(elem).ip_index; |
| 18654 | types[i] = sema.typeOf(elem).toIntern(); |
| 18552 | 18655 | if (types[i].toType().zigTypeTag(mod) == .Opaque) { |
| 18553 | 18656 | const msg = msg: { |
| 18554 | 18657 | const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| ... | ... | @@ -18560,7 +18663,7 @@ fn zirArrayInitAnon( |
| 18560 | 18663 | return sema.failWithOwnedErrorMsg(msg); |
| 18561 | 18664 | } |
| 18562 | 18665 | if (try sema.resolveMaybeUndefVal(elem)) |val| { |
| 18563 | | values[i] = val.ip_index; |
| 18666 | values[i] = val.toIntern(); |
| 18564 | 18667 | } else { |
| 18565 | 18668 | values[i] = .none; |
| 18566 | 18669 | runtime_src = operand_src; |
| ... | ... | @@ -18676,7 +18779,7 @@ fn fieldType( |
| 18676 | 18779 | const resolved_ty = try sema.resolveTypeFields(cur_ty); |
| 18677 | 18780 | cur_ty = resolved_ty; |
| 18678 | 18781 | switch (cur_ty.zigTypeTag(mod)) { |
| 18679 | | .Struct => switch (mod.intern_pool.indexToKey(cur_ty.ip_index)) { |
| 18782 | .Struct => switch (mod.intern_pool.indexToKey(cur_ty.toIntern())) { |
| 18680 | 18783 | .anon_struct_type => |anon_struct| { |
| 18681 | 18784 | const field_index = try sema.anonStructFieldIndex(block, cur_ty, field_name, field_src); |
| 18682 | 18785 | return sema.addType(anon_struct.types[field_index].toType()); |
| ... | ... | @@ -18698,7 +18801,7 @@ fn fieldType( |
| 18698 | 18801 | .Optional => { |
| 18699 | 18802 | // Struct/array init through optional requires the child type to not be a pointer. |
| 18700 | 18803 | // If the child of .optional is a pointer it'll error on the next loop. |
| 18701 | | cur_ty = mod.intern_pool.indexToKey(cur_ty.ip_index).opt_type.toType(); |
| 18804 | cur_ty = mod.intern_pool.indexToKey(cur_ty.toIntern()).opt_type.toType(); |
| 18702 | 18805 | continue; |
| 18703 | 18806 | }, |
| 18704 | 18807 | .ErrorUnion => { |
| ... | ... | @@ -18776,7 +18879,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18776 | 18879 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 18777 | 18880 | |
| 18778 | 18881 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { |
| 18779 | | const err_name = sema.mod.intern_pool.indexToKey(val.ip_index).err.name; |
| 18882 | const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 18780 | 18883 | const bytes = sema.mod.intern_pool.stringToSlice(err_name); |
| 18781 | 18884 | return sema.addStrLit(block, bytes); |
| 18782 | 18885 | } |
| ... | ... | @@ -18820,21 +18923,21 @@ fn zirUnaryMath( |
| 18820 | 18923 | const vec_len = operand_ty.vectorLen(mod); |
| 18821 | 18924 | const result_ty = try mod.vectorType(.{ |
| 18822 | 18925 | .len = vec_len, |
| 18823 | | .child = scalar_ty.ip_index, |
| 18926 | .child = scalar_ty.toIntern(), |
| 18824 | 18927 | }); |
| 18825 | 18928 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18826 | 18929 | if (val.isUndef(mod)) |
| 18827 | 18930 | return sema.addConstUndef(result_ty); |
| 18828 | 18931 | |
| 18829 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 18932 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 18830 | 18933 | for (elems, 0..) |*elem, i| { |
| 18831 | 18934 | const elem_val = try val.elemValue(sema.mod, i); |
| 18832 | | elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod); |
| 18935 | elem.* = try (try eval(elem_val, scalar_ty, sema.arena, sema.mod)).intern(scalar_ty, mod); |
| 18833 | 18936 | } |
| 18834 | | return sema.addConstant( |
| 18835 | | result_ty, |
| 18836 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 18837 | | ); |
| 18937 | return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{ |
| 18938 | .ty = result_ty.toIntern(), |
| 18939 | .storage = .{ .elems = elems }, |
| 18940 | } })).toValue()); |
| 18838 | 18941 | } |
| 18839 | 18942 | |
| 18840 | 18943 | try sema.requireRuntimeBlock(block, operand_src, null); |
| ... | ... | @@ -18867,7 +18970,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18867 | 18970 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 18868 | 18971 | .EnumLiteral => { |
| 18869 | 18972 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); |
| 18870 | | const tag_name = mod.intern_pool.indexToKey(val.ip_index).enum_literal; |
| 18973 | const tag_name = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 18871 | 18974 | const bytes = mod.intern_pool.stringToSlice(tag_name); |
| 18872 | 18975 | return sema.addStrLit(block, bytes); |
| 18873 | 18976 | }, |
| ... | ... | @@ -18956,7 +19059,7 @@ fn zirReify( |
| 18956 | 19059 | .AnyFrame => return sema.failWithUseOfAsync(block, src), |
| 18957 | 19060 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, |
| 18958 | 19061 | .Int => { |
| 18959 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19062 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 18960 | 19063 | const signedness_val = try union_val.val.fieldValue(mod, fields.getIndex("signedness").?); |
| 18961 | 19064 | const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?); |
| 18962 | 19065 | |
| ... | ... | @@ -18966,7 +19069,7 @@ fn zirReify( |
| 18966 | 19069 | return sema.addType(ty); |
| 18967 | 19070 | }, |
| 18968 | 19071 | .Vector => { |
| 18969 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19072 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 18970 | 19073 | const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?); |
| 18971 | 19074 | const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?); |
| 18972 | 19075 | |
| ... | ... | @@ -18977,12 +19080,12 @@ fn zirReify( |
| 18977 | 19080 | |
| 18978 | 19081 | const ty = try mod.vectorType(.{ |
| 18979 | 19082 | .len = len, |
| 18980 | | .child = child_ty.ip_index, |
| 19083 | .child = child_ty.toIntern(), |
| 18981 | 19084 | }); |
| 18982 | 19085 | return sema.addType(ty); |
| 18983 | 19086 | }, |
| 18984 | 19087 | .Float => { |
| 18985 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19088 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 18986 | 19089 | const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?); |
| 18987 | 19090 | |
| 18988 | 19091 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| ... | ... | @@ -18997,7 +19100,7 @@ fn zirReify( |
| 18997 | 19100 | return sema.addType(ty); |
| 18998 | 19101 | }, |
| 18999 | 19102 | .Pointer => { |
| 19000 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19103 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19001 | 19104 | const size_val = try union_val.val.fieldValue(mod, fields.getIndex("size").?); |
| 19002 | 19105 | const is_const_val = try union_val.val.fieldValue(mod, fields.getIndex("is_const").?); |
| 19003 | 19106 | const is_volatile_val = try union_val.val.fieldValue(mod, fields.getIndex("is_volatile").?); |
| ... | ... | @@ -19088,7 +19191,7 @@ fn zirReify( |
| 19088 | 19191 | return sema.addType(ty); |
| 19089 | 19192 | }, |
| 19090 | 19193 | .Array => { |
| 19091 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19194 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19092 | 19195 | const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?); |
| 19093 | 19196 | const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?); |
| 19094 | 19197 | const sentinel_val = try union_val.val.fieldValue(mod, fields.getIndex("sentinel").?); |
| ... | ... | @@ -19107,7 +19210,7 @@ fn zirReify( |
| 19107 | 19210 | return sema.addType(ty); |
| 19108 | 19211 | }, |
| 19109 | 19212 | .Optional => { |
| 19110 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19213 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19111 | 19214 | const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?); |
| 19112 | 19215 | |
| 19113 | 19216 | const child_ty = child_val.toType(); |
| ... | ... | @@ -19116,7 +19219,7 @@ fn zirReify( |
| 19116 | 19219 | return sema.addType(ty); |
| 19117 | 19220 | }, |
| 19118 | 19221 | .ErrorUnion => { |
| 19119 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19222 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19120 | 19223 | const error_set_val = try union_val.val.fieldValue(mod, fields.getIndex("error_set").?); |
| 19121 | 19224 | const payload_val = try union_val.val.fieldValue(mod, fields.getIndex("payload").?); |
| 19122 | 19225 | |
| ... | ... | @@ -19155,7 +19258,7 @@ fn zirReify( |
| 19155 | 19258 | return sema.addType(ty); |
| 19156 | 19259 | }, |
| 19157 | 19260 | .Struct => { |
| 19158 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19261 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19159 | 19262 | const layout_val = try union_val.val.fieldValue(mod, fields.getIndex("layout").?); |
| 19160 | 19263 | const backing_integer_val = try union_val.val.fieldValue(mod, fields.getIndex("backing_integer").?); |
| 19161 | 19264 | const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?); |
| ... | ... | @@ -19176,7 +19279,7 @@ fn zirReify( |
| 19176 | 19279 | return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_val, name_strategy, is_tuple_val.toBool(mod)); |
| 19177 | 19280 | }, |
| 19178 | 19281 | .Enum => { |
| 19179 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19282 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19180 | 19283 | const tag_type_val = try union_val.val.fieldValue(mod, fields.getIndex("tag_type").?); |
| 19181 | 19284 | const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?); |
| 19182 | 19285 | const decls_val = try union_val.val.fieldValue(mod, fields.getIndex("decls").?); |
| ... | ... | @@ -19517,7 +19620,7 @@ fn zirReify( |
| 19517 | 19620 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| 19518 | 19621 | }, |
| 19519 | 19622 | .Fn => { |
| 19520 | | const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod); |
| 19623 | const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod); |
| 19521 | 19624 | const calling_convention_val = try union_val.val.fieldValue(mod, fields.getIndex("calling_convention").?); |
| 19522 | 19625 | const alignment_val = try union_val.val.fieldValue(mod, fields.getIndex("alignment").?); |
| 19523 | 19626 | const is_generic_val = try union_val.val.fieldValue(mod, fields.getIndex("is_generic").?); |
| ... | ... | @@ -19571,7 +19674,7 @@ fn zirReify( |
| 19571 | 19674 | |
| 19572 | 19675 | const param_type_val = param_type_opt_val.optionalValue(mod) orelse |
| 19573 | 19676 | return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{}); |
| 19574 | | param_type.* = param_type_val.ip_index; |
| 19677 | param_type.* = param_type_val.toIntern(); |
| 19575 | 19678 | |
| 19576 | 19679 | if (arg_is_noalias) { |
| 19577 | 19680 | if (!param_type.toType().isPtrAtRuntime(mod)) { |
| ... | ... | @@ -19733,7 +19836,7 @@ fn reifyStruct( |
| 19733 | 19836 | opt_val; |
| 19734 | 19837 | break :blk try payload_val.copy(new_decl_arena_allocator); |
| 19735 | 19838 | } else Value.@"unreachable"; |
| 19736 | | if (is_comptime_val.toBool(mod) and default_val.ip_index == .unreachable_value) { |
| 19839 | if (is_comptime_val.toBool(mod) and default_val.toIntern() == .unreachable_value) { |
| 19737 | 19840 | return sema.fail(block, src, "comptime field without default initialization value", .{}); |
| 19738 | 19841 | } |
| 19739 | 19842 | |
| ... | ... | @@ -19956,9 +20059,17 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19956 | 20059 | |
| 19957 | 20060 | const bytes = try ty.nameAllocArena(anon_decl.arena(), mod); |
| 19958 | 20061 | |
| 20062 | const decl_ty = try mod.arrayType(.{ |
| 20063 | .len = bytes.len, |
| 20064 | .child = .u8_type, |
| 20065 | .sentinel = .zero_u8, |
| 20066 | }); |
| 19959 | 20067 | const new_decl = try anon_decl.finish( |
| 19960 | | try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 19961 | | try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]), |
| 20068 | decl_ty, |
| 20069 | (try mod.intern(.{ .aggregate = .{ |
| 20070 | .ty = decl_ty.toIntern(), |
| 20071 | .storage = .{ .bytes = bytes }, |
| 20072 | } })).toValue(), |
| 19962 | 20073 | 0, // default alignment |
| 19963 | 20074 | ); |
| 19964 | 20075 | |
| ... | ... | @@ -20125,8 +20236,8 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 20125 | 20236 | break :disjoint false; |
| 20126 | 20237 | } |
| 20127 | 20238 | |
| 20128 | | if (!ip.isInferredErrorSetType(dest_ty.ip_index) and |
| 20129 | | !ip.isInferredErrorSetType(operand_ty.ip_index)) |
| 20239 | if (!ip.isInferredErrorSetType(dest_ty.toIntern()) and |
| 20240 | !ip.isInferredErrorSetType(operand_ty.toIntern())) |
| 20130 | 20241 | { |
| 20131 | 20242 | break :disjoint true; |
| 20132 | 20243 | } |
| ... | ... | @@ -20157,7 +20268,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 20157 | 20268 | |
| 20158 | 20269 | if (maybe_operand_val) |val| { |
| 20159 | 20270 | if (!dest_ty.isAnyError(mod)) { |
| 20160 | | const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.ip_index).err.name); |
| 20271 | const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.toIntern()).err.name); |
| 20161 | 20272 | if (!dest_ty.errorSetHasField(error_name, mod)) { |
| 20162 | 20273 | const msg = msg: { |
| 20163 | 20274 | const msg = try sema.errMsg( |
| ... | ... | @@ -20257,11 +20368,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20257 | 20368 | if (dest_ty.zigTypeTag(mod) == .Optional) { |
| 20258 | 20369 | var dest_ptr_info = dest_ty.optionalChild(mod).ptrInfo(mod); |
| 20259 | 20370 | dest_ptr_info.@"align" = operand_align; |
| 20260 | | break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, sema.mod, dest_ptr_info), mod); |
| 20371 | break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, mod, dest_ptr_info), mod); |
| 20261 | 20372 | } else { |
| 20262 | 20373 | var dest_ptr_info = dest_ty.ptrInfo(mod); |
| 20263 | 20374 | dest_ptr_info.@"align" = operand_align; |
| 20264 | | break :blk try Type.ptr(sema.arena, sema.mod, dest_ptr_info); |
| 20375 | break :blk try Type.ptr(sema.arena, mod, dest_ptr_info); |
| 20265 | 20376 | } |
| 20266 | 20377 | }; |
| 20267 | 20378 | |
| ... | ... | @@ -20279,10 +20390,10 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20279 | 20390 | errdefer msg.destroy(sema.gpa); |
| 20280 | 20391 | |
| 20281 | 20392 | try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{ |
| 20282 | | operand_ty.fmt(sema.mod), operand_align, |
| 20393 | operand_ty.fmt(mod), operand_align, |
| 20283 | 20394 | }); |
| 20284 | 20395 | try sema.errNote(block, dest_ty_src, msg, "'{}' has alignment '{d}'", .{ |
| 20285 | | dest_ty.fmt(sema.mod), dest_align, |
| 20396 | dest_ty.fmt(mod), dest_align, |
| 20286 | 20397 | }); |
| 20287 | 20398 | |
| 20288 | 20399 | try sema.errNote(block, src, msg, "consider using '@alignCast'", .{}); |
| ... | ... | @@ -20296,11 +20407,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20296 | 20407 | return sema.failWithUseOfUndef(block, operand_src); |
| 20297 | 20408 | } |
| 20298 | 20409 | if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) { |
| 20299 | | return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); |
| 20410 | return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)}); |
| 20300 | 20411 | } |
| 20301 | 20412 | if (dest_ty.zigTypeTag(mod) == .Optional and sema.typeOf(ptr).zigTypeTag(mod) != .Optional) { |
| 20302 | 20413 | return sema.addConstant(dest_ty, (try mod.intern(.{ .opt = .{ |
| 20303 | | .ty = dest_ty.ip_index, |
| 20414 | .ty = dest_ty.toIntern(), |
| 20304 | 20415 | .val = operand_val.toIntern(), |
| 20305 | 20416 | } })).toValue()); |
| 20306 | 20417 | } |
| ... | ... | @@ -20335,7 +20446,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 20335 | 20446 | |
| 20336 | 20447 | var ptr_info = operand_ty.ptrInfo(mod); |
| 20337 | 20448 | ptr_info.mutable = true; |
| 20338 | | const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 20449 | const dest_ty = try Type.ptr(sema.arena, mod, ptr_info); |
| 20339 | 20450 | |
| 20340 | 20451 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 20341 | 20452 | return sema.addConstant(dest_ty, operand_val); |
| ... | ... | @@ -20356,7 +20467,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 20356 | 20467 | |
| 20357 | 20468 | var ptr_info = operand_ty.ptrInfo(mod); |
| 20358 | 20469 | ptr_info.@"volatile" = false; |
| 20359 | | const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 20470 | const dest_ty = try Type.ptr(sema.arena, mod, ptr_info); |
| 20360 | 20471 | |
| 20361 | 20472 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 20362 | 20473 | return sema.addConstant(dest_ty, operand_val); |
| ... | ... | @@ -20382,7 +20493,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20382 | 20493 | const dest_ty = if (is_vector) |
| 20383 | 20494 | try mod.vectorType(.{ |
| 20384 | 20495 | .len = operand_ty.vectorLen(mod), |
| 20385 | | .child = dest_scalar_ty.ip_index, |
| 20496 | .child = dest_scalar_ty.toIntern(), |
| 20386 | 20497 | }) |
| 20387 | 20498 | else |
| 20388 | 20499 | dest_scalar_ty; |
| ... | ... | @@ -20405,7 +20516,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20405 | 20516 | |
| 20406 | 20517 | if (operand_info.signedness != dest_info.signedness) { |
| 20407 | 20518 | return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{ |
| 20408 | | @tagName(dest_info.signedness), operand_ty.fmt(sema.mod), |
| 20519 | @tagName(dest_info.signedness), operand_ty.fmt(mod), |
| 20409 | 20520 | }); |
| 20410 | 20521 | } |
| 20411 | 20522 | if (operand_info.bits < dest_info.bits) { |
| ... | ... | @@ -20414,7 +20525,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20414 | 20525 | block, |
| 20415 | 20526 | src, |
| 20416 | 20527 | "destination type '{}' has more bits than source type '{}'", |
| 20417 | | .{ dest_ty.fmt(sema.mod), operand_ty.fmt(sema.mod) }, |
| 20528 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, |
| 20418 | 20529 | ); |
| 20419 | 20530 | errdefer msg.destroy(sema.gpa); |
| 20420 | 20531 | try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{ |
| ... | ... | @@ -20434,18 +20545,18 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20434 | 20545 | if (!is_vector) { |
| 20435 | 20546 | return sema.addConstant( |
| 20436 | 20547 | dest_ty, |
| 20437 | | try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod), |
| 20548 | try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, mod), |
| 20438 | 20549 | ); |
| 20439 | 20550 | } |
| 20440 | | const elems = try sema.arena.alloc(Value, operand_ty.vectorLen(mod)); |
| 20551 | const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(mod)); |
| 20441 | 20552 | for (elems, 0..) |*elem, i| { |
| 20442 | | const elem_val = try val.elemValue(sema.mod, i); |
| 20443 | | elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod); |
| 20553 | const elem_val = try val.elemValue(mod, i); |
| 20554 | elem.* = try (try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, mod)).intern(dest_scalar_ty, mod); |
| 20444 | 20555 | } |
| 20445 | | return sema.addConstant( |
| 20446 | | dest_ty, |
| 20447 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 20448 | | ); |
| 20556 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ |
| 20557 | .ty = dest_ty.toIntern(), |
| 20558 | .storage = .{ .elems = elems }, |
| 20559 | } })).toValue()); |
| 20449 | 20560 | } |
| 20450 | 20561 | |
| 20451 | 20562 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | ... | @@ -20466,7 +20577,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20466 | 20577 | |
| 20467 | 20578 | var ptr_info = ptr_ty.ptrInfo(mod); |
| 20468 | 20579 | ptr_info.@"align" = dest_align; |
| 20469 | | var dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 20580 | var dest_ty = try Type.ptr(sema.arena, mod, ptr_info); |
| 20470 | 20581 | if (ptr_ty.zigTypeTag(mod) == .Optional) { |
| 20471 | 20582 | dest_ty = try mod.optionalType(dest_ty.toIntern()); |
| 20472 | 20583 | } |
| ... | ... | @@ -20531,22 +20642,22 @@ fn zirBitCount( |
| 20531 | 20642 | const vec_len = operand_ty.vectorLen(mod); |
| 20532 | 20643 | const result_ty = try mod.vectorType(.{ |
| 20533 | 20644 | .len = vec_len, |
| 20534 | | .child = result_scalar_ty.ip_index, |
| 20645 | .child = result_scalar_ty.toIntern(), |
| 20535 | 20646 | }); |
| 20536 | 20647 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20537 | 20648 | if (val.isUndef(mod)) return sema.addConstUndef(result_ty); |
| 20538 | 20649 | |
| 20539 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 20650 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 20540 | 20651 | const scalar_ty = operand_ty.scalarType(mod); |
| 20541 | 20652 | for (elems, 0..) |*elem, i| { |
| 20542 | | const elem_val = try val.elemValue(sema.mod, i); |
| 20653 | const elem_val = try val.elemValue(mod, i); |
| 20543 | 20654 | const count = comptimeOp(elem_val, scalar_ty, mod); |
| 20544 | | elem.* = try mod.intValue(scalar_ty, count); |
| 20655 | elem.* = (try mod.intValue(scalar_ty, count)).toIntern(); |
| 20545 | 20656 | } |
| 20546 | | return sema.addConstant( |
| 20547 | | result_ty, |
| 20548 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 20549 | | ); |
| 20657 | return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{ |
| 20658 | .ty = result_ty.toIntern(), |
| 20659 | .storage = .{ .elems = elems }, |
| 20660 | } })).toValue()); |
| 20550 | 20661 | } else { |
| 20551 | 20662 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 20552 | 20663 | return block.addTyOp(air_tag, result_ty, operand); |
| ... | ... | @@ -20580,7 +20691,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20580 | 20691 | block, |
| 20581 | 20692 | operand_src, |
| 20582 | 20693 | "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits", |
| 20583 | | .{ scalar_ty.fmt(sema.mod), bits }, |
| 20694 | .{ scalar_ty.fmt(mod), bits }, |
| 20584 | 20695 | ); |
| 20585 | 20696 | } |
| 20586 | 20697 | |
| ... | ... | @@ -20605,15 +20716,15 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 20605 | 20716 | return sema.addConstUndef(operand_ty); |
| 20606 | 20717 | |
| 20607 | 20718 | const vec_len = operand_ty.vectorLen(mod); |
| 20608 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 20719 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 20609 | 20720 | for (elems, 0..) |*elem, i| { |
| 20610 | | const elem_val = try val.elemValue(sema.mod, i); |
| 20611 | | elem.* = try elem_val.byteSwap(operand_ty, mod, sema.arena); |
| 20721 | const elem_val = try val.elemValue(mod, i); |
| 20722 | elem.* = try (try elem_val.byteSwap(operand_ty, mod, sema.arena)).intern(scalar_ty, mod); |
| 20612 | 20723 | } |
| 20613 | | return sema.addConstant( |
| 20614 | | operand_ty, |
| 20615 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 20616 | | ); |
| 20724 | return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{ |
| 20725 | .ty = operand_ty.toIntern(), |
| 20726 | .storage = .{ .elems = elems }, |
| 20727 | } })).toValue()); |
| 20617 | 20728 | } else operand_src; |
| 20618 | 20729 | |
| 20619 | 20730 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | ... | @@ -20653,15 +20764,15 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20653 | 20764 | return sema.addConstUndef(operand_ty); |
| 20654 | 20765 | |
| 20655 | 20766 | const vec_len = operand_ty.vectorLen(mod); |
| 20656 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 20767 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 20657 | 20768 | for (elems, 0..) |*elem, i| { |
| 20658 | | const elem_val = try val.elemValue(sema.mod, i); |
| 20659 | | elem.* = try elem_val.bitReverse(scalar_ty, mod, sema.arena); |
| 20769 | const elem_val = try val.elemValue(mod, i); |
| 20770 | elem.* = try (try elem_val.bitReverse(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod); |
| 20660 | 20771 | } |
| 20661 | | return sema.addConstant( |
| 20662 | | operand_ty, |
| 20663 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 20664 | | ); |
| 20772 | return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{ |
| 20773 | .ty = operand_ty.toIntern(), |
| 20774 | .storage = .{ .elems = elems }, |
| 20775 | } })).toValue()); |
| 20665 | 20776 | } else operand_src; |
| 20666 | 20777 | |
| 20667 | 20778 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | ... | @@ -20699,7 +20810,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20699 | 20810 | .Struct => {}, |
| 20700 | 20811 | else => { |
| 20701 | 20812 | const msg = msg: { |
| 20702 | | const msg = try sema.errMsg(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(sema.mod)}); |
| 20813 | const msg = try sema.errMsg(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(mod)}); |
| 20703 | 20814 | errdefer msg.destroy(sema.gpa); |
| 20704 | 20815 | try sema.addDeclaredHereNote(msg, ty); |
| 20705 | 20816 | break :msg msg; |
| ... | ... | @@ -20738,7 +20849,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com |
| 20738 | 20849 | const mod = sema.mod; |
| 20739 | 20850 | switch (ty.zigTypeTag(mod)) { |
| 20740 | 20851 | .Struct, .Enum, .Union, .Opaque => return, |
| 20741 | | else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(sema.mod)}), |
| 20852 | else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(mod)}), |
| 20742 | 20853 | } |
| 20743 | 20854 | } |
| 20744 | 20855 | |
| ... | ... | @@ -20748,7 +20859,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr |
| 20748 | 20859 | switch (try ty.zigTypeTagOrPoison(mod)) { |
| 20749 | 20860 | .ComptimeInt => return true, |
| 20750 | 20861 | .Int => return false, |
| 20751 | | else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(sema.mod)}), |
| 20862 | else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(mod)}), |
| 20752 | 20863 | } |
| 20753 | 20864 | } |
| 20754 | 20865 | |
| ... | ... | @@ -20807,7 +20918,7 @@ fn checkPtrOperand( |
| 20807 | 20918 | block, |
| 20808 | 20919 | ty_src, |
| 20809 | 20920 | "expected pointer, found '{}'", |
| 20810 | | .{ty.fmt(sema.mod)}, |
| 20921 | .{ty.fmt(mod)}, |
| 20811 | 20922 | ); |
| 20812 | 20923 | errdefer msg.destroy(sema.gpa); |
| 20813 | 20924 | |
| ... | ... | @@ -20820,7 +20931,7 @@ fn checkPtrOperand( |
| 20820 | 20931 | .Optional => if (ty.isPtrLikeOptional(mod)) return, |
| 20821 | 20932 | else => {}, |
| 20822 | 20933 | } |
| 20823 | | return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(sema.mod)}); |
| 20934 | return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)}); |
| 20824 | 20935 | } |
| 20825 | 20936 | |
| 20826 | 20937 | fn checkPtrType( |
| ... | ... | @@ -20838,7 +20949,7 @@ fn checkPtrType( |
| 20838 | 20949 | block, |
| 20839 | 20950 | ty_src, |
| 20840 | 20951 | "expected pointer type, found '{}'", |
| 20841 | | .{ty.fmt(sema.mod)}, |
| 20952 | .{ty.fmt(mod)}, |
| 20842 | 20953 | ); |
| 20843 | 20954 | errdefer msg.destroy(sema.gpa); |
| 20844 | 20955 | |
| ... | ... | @@ -20851,7 +20962,7 @@ fn checkPtrType( |
| 20851 | 20962 | .Optional => if (ty.isPtrLikeOptional(mod)) return, |
| 20852 | 20963 | else => {}, |
| 20853 | 20964 | } |
| 20854 | | return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(sema.mod)}); |
| 20965 | return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)}); |
| 20855 | 20966 | } |
| 20856 | 20967 | |
| 20857 | 20968 | fn checkVectorElemType( |
| ... | ... | @@ -20865,7 +20976,7 @@ fn checkVectorElemType( |
| 20865 | 20976 | .Int, .Float, .Bool => return, |
| 20866 | 20977 | else => if (ty.isPtrAtRuntime(mod)) return, |
| 20867 | 20978 | } |
| 20868 | | return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(sema.mod)}); |
| 20979 | return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(mod)}); |
| 20869 | 20980 | } |
| 20870 | 20981 | |
| 20871 | 20982 | fn checkFloatType( |
| ... | ... | @@ -20877,7 +20988,7 @@ fn checkFloatType( |
| 20877 | 20988 | const mod = sema.mod; |
| 20878 | 20989 | switch (ty.zigTypeTag(mod)) { |
| 20879 | 20990 | .ComptimeInt, .ComptimeFloat, .Float => {}, |
| 20880 | | else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(sema.mod)}), |
| 20991 | else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(mod)}), |
| 20881 | 20992 | } |
| 20882 | 20993 | } |
| 20883 | 20994 | |
| ... | ... | @@ -20894,7 +21005,7 @@ fn checkNumericType( |
| 20894 | 21005 | .ComptimeFloat, .Float, .ComptimeInt, .Int => {}, |
| 20895 | 21006 | else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}), |
| 20896 | 21007 | }, |
| 20897 | | else => return sema.fail(block, ty_src, "expected number, found '{}'", .{ty.fmt(sema.mod)}), |
| 21008 | else => return sema.fail(block, ty_src, "expected number, found '{}'", .{ty.fmt(mod)}), |
| 20898 | 21009 | } |
| 20899 | 21010 | } |
| 20900 | 21011 | |
| ... | ... | @@ -20928,7 +21039,7 @@ fn checkAtomicPtrOperand( |
| 20928 | 21039 | block, |
| 20929 | 21040 | elem_ty_src, |
| 20930 | 21041 | "expected bool, integer, float, enum, or pointer type; found '{}'", |
| 20931 | | .{elem_ty.fmt(sema.mod)}, |
| 21042 | .{elem_ty.fmt(mod)}, |
| 20932 | 21043 | ), |
| 20933 | 21044 | }; |
| 20934 | 21045 | |
| ... | ... | @@ -20943,7 +21054,7 @@ fn checkAtomicPtrOperand( |
| 20943 | 21054 | const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) { |
| 20944 | 21055 | .Pointer => ptr_ty.ptrInfo(mod), |
| 20945 | 21056 | else => { |
| 20946 | | const wanted_ptr_ty = try Type.ptr(sema.arena, sema.mod, wanted_ptr_data); |
| 21057 | const wanted_ptr_ty = try Type.ptr(sema.arena, mod, wanted_ptr_data); |
| 20947 | 21058 | _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src); |
| 20948 | 21059 | unreachable; |
| 20949 | 21060 | }, |
| ... | ... | @@ -20953,7 +21064,7 @@ fn checkAtomicPtrOperand( |
| 20953 | 21064 | wanted_ptr_data.@"allowzero" = ptr_data.@"allowzero"; |
| 20954 | 21065 | wanted_ptr_data.@"volatile" = ptr_data.@"volatile"; |
| 20955 | 21066 | |
| 20956 | | const wanted_ptr_ty = try Type.ptr(sema.arena, sema.mod, wanted_ptr_data); |
| 21067 | const wanted_ptr_ty = try Type.ptr(sema.arena, mod, wanted_ptr_data); |
| 20957 | 21068 | const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src); |
| 20958 | 21069 | |
| 20959 | 21070 | return casted_ptr; |
| ... | ... | @@ -21016,12 +21127,12 @@ fn checkIntOrVector( |
| 21016 | 21127 | switch (try elem_ty.zigTypeTagOrPoison(mod)) { |
| 21017 | 21128 | .Int => return elem_ty, |
| 21018 | 21129 | else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{ |
| 21019 | | elem_ty.fmt(sema.mod), |
| 21130 | elem_ty.fmt(mod), |
| 21020 | 21131 | }), |
| 21021 | 21132 | } |
| 21022 | 21133 | }, |
| 21023 | 21134 | else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{ |
| 21024 | | operand_ty.fmt(sema.mod), |
| 21135 | operand_ty.fmt(mod), |
| 21025 | 21136 | }), |
| 21026 | 21137 | } |
| 21027 | 21138 | } |
| ... | ... | @@ -21040,12 +21151,12 @@ fn checkIntOrVectorAllowComptime( |
| 21040 | 21151 | switch (try elem_ty.zigTypeTagOrPoison(mod)) { |
| 21041 | 21152 | .Int, .ComptimeInt => return elem_ty, |
| 21042 | 21153 | else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{ |
| 21043 | | elem_ty.fmt(sema.mod), |
| 21154 | elem_ty.fmt(mod), |
| 21044 | 21155 | }), |
| 21045 | 21156 | } |
| 21046 | 21157 | }, |
| 21047 | 21158 | else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{ |
| 21048 | | operand_ty.fmt(sema.mod), |
| 21159 | operand_ty.fmt(mod), |
| 21049 | 21160 | }), |
| 21050 | 21161 | } |
| 21051 | 21162 | } |
| ... | ... | @@ -21054,7 +21165,7 @@ fn checkErrorSetType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Comp |
| 21054 | 21165 | const mod = sema.mod; |
| 21055 | 21166 | switch (ty.zigTypeTag(mod)) { |
| 21056 | 21167 | .ErrorSet => return, |
| 21057 | | else => return sema.fail(block, src, "expected error set type, found '{}'", .{ty.fmt(sema.mod)}), |
| 21168 | else => return sema.fail(block, src, "expected error set type, found '{}'", .{ty.fmt(mod)}), |
| 21058 | 21169 | } |
| 21059 | 21170 | } |
| 21060 | 21171 | |
| ... | ... | @@ -21142,7 +21253,7 @@ fn checkVectorizableBinaryOperands( |
| 21142 | 21253 | } else { |
| 21143 | 21254 | const msg = msg: { |
| 21144 | 21255 | const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{ |
| 21145 | | lhs_ty.fmt(sema.mod), rhs_ty.fmt(sema.mod), |
| 21256 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), |
| 21146 | 21257 | }); |
| 21147 | 21258 | errdefer msg.destroy(sema.gpa); |
| 21148 | 21259 | if (lhs_is_vector) { |
| ... | ... | @@ -21161,7 +21272,7 @@ fn checkVectorizableBinaryOperands( |
| 21161 | 21272 | fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { |
| 21162 | 21273 | if (base_src == .unneeded) return .unneeded; |
| 21163 | 21274 | const mod = sema.mod; |
| 21164 | | return mod.optionsSrc(sema.mod.declPtr(block.src_decl), base_src, wanted); |
| 21275 | return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted); |
| 21165 | 21276 | } |
| 21166 | 21277 | |
| 21167 | 21278 | fn resolveExportOptions( |
| ... | ... | @@ -21282,7 +21393,7 @@ fn zirCmpxchg( |
| 21282 | 21393 | block, |
| 21283 | 21394 | elem_ty_src, |
| 21284 | 21395 | "expected bool, integer, enum, or pointer type; found '{}'", |
| 21285 | | .{elem_ty.fmt(sema.mod)}, |
| 21396 | .{elem_ty.fmt(mod)}, |
| 21286 | 21397 | ); |
| 21287 | 21398 | } |
| 21288 | 21399 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| ... | ... | @@ -21322,8 +21433,8 @@ fn zirCmpxchg( |
| 21322 | 21433 | const ptr_ty = sema.typeOf(ptr); |
| 21323 | 21434 | const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src; |
| 21324 | 21435 | const result_val = try mod.intern(.{ .opt = .{ |
| 21325 | | .ty = result_ty.ip_index, |
| 21326 | | .val = if (stored_val.eql(expected_val, elem_ty, sema.mod)) blk: { |
| 21436 | .ty = result_ty.toIntern(), |
| 21437 | .val = if (stored_val.eql(expected_val, elem_ty, mod)) blk: { |
| 21327 | 21438 | try sema.storePtr(block, src, ptr, new_value); |
| 21328 | 21439 | break :blk .none; |
| 21329 | 21440 | } else stored_val.toIntern(), |
| ... | ... | @@ -21363,7 +21474,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 21363 | 21474 | try sema.checkVectorElemType(block, scalar_src, scalar_ty); |
| 21364 | 21475 | const vector_ty = try mod.vectorType(.{ |
| 21365 | 21476 | .len = len, |
| 21366 | | .child = scalar_ty.ip_index, |
| 21477 | .child = scalar_ty.toIntern(), |
| 21367 | 21478 | }); |
| 21368 | 21479 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { |
| 21369 | 21480 | if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty); |
| ... | ... | @@ -21489,7 +21600,7 @@ fn analyzeShuffle( |
| 21489 | 21600 | |
| 21490 | 21601 | const res_ty = try mod.vectorType(.{ |
| 21491 | 21602 | .len = mask_len, |
| 21492 | | .child = elem_ty.ip_index, |
| 21603 | .child = elem_ty.toIntern(), |
| 21493 | 21604 | }); |
| 21494 | 21605 | |
| 21495 | 21606 | var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) { |
| ... | ... | @@ -21516,11 +21627,11 @@ fn analyzeShuffle( |
| 21516 | 21627 | |
| 21517 | 21628 | const a_ty = try mod.vectorType(.{ |
| 21518 | 21629 | .len = a_len, |
| 21519 | | .child = elem_ty.ip_index, |
| 21630 | .child = elem_ty.toIntern(), |
| 21520 | 21631 | }); |
| 21521 | 21632 | const b_ty = try mod.vectorType(.{ |
| 21522 | 21633 | .len = b_len, |
| 21523 | | .child = elem_ty.ip_index, |
| 21634 | .child = elem_ty.toIntern(), |
| 21524 | 21635 | }); |
| 21525 | 21636 | |
| 21526 | 21637 | if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src); |
| ... | ... | @@ -21567,25 +21678,21 @@ fn analyzeShuffle( |
| 21567 | 21678 | |
| 21568 | 21679 | if (try sema.resolveMaybeUndefVal(a)) |a_val| { |
| 21569 | 21680 | if (try sema.resolveMaybeUndefVal(b)) |b_val| { |
| 21570 | | const values = try sema.arena.alloc(Value, mask_len); |
| 21571 | | |
| 21572 | | i = 0; |
| 21573 | | while (i < mask_len) : (i += 1) { |
| 21681 | const values = try sema.arena.alloc(InternPool.Index, mask_len); |
| 21682 | for (values) |*value| { |
| 21574 | 21683 | const mask_elem_val = try mask.elemValue(sema.mod, i); |
| 21575 | 21684 | if (mask_elem_val.isUndef(mod)) { |
| 21576 | | values[i] = Value.undef; |
| 21685 | value.* = try mod.intern(.{ .undef = elem_ty.toIntern() }); |
| 21577 | 21686 | continue; |
| 21578 | 21687 | } |
| 21579 | 21688 | const int = mask_elem_val.toSignedInt(mod); |
| 21580 | 21689 | const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int); |
| 21581 | | if (int >= 0) { |
| 21582 | | values[i] = try a_val.elemValue(sema.mod, unsigned); |
| 21583 | | } else { |
| 21584 | | values[i] = try b_val.elemValue(sema.mod, unsigned); |
| 21585 | | } |
| 21690 | values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod); |
| 21586 | 21691 | } |
| 21587 | | const res_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 21588 | | return sema.addConstant(res_ty, res_val); |
| 21692 | return sema.addConstant(res_ty, (try mod.intern(.{ .aggregate = .{ |
| 21693 | .ty = res_ty.toIntern(), |
| 21694 | .storage = .{ .elems = values }, |
| 21695 | } })).toValue()); |
| 21589 | 21696 | } |
| 21590 | 21697 | } |
| 21591 | 21698 | |
| ... | ... | @@ -21599,22 +21706,25 @@ fn analyzeShuffle( |
| 21599 | 21706 | const max_src = if (a_len > b_len) a_src else b_src; |
| 21600 | 21707 | const max_len = try sema.usizeCast(block, max_src, std.math.max(a_len, b_len)); |
| 21601 | 21708 | |
| 21602 | | const expand_mask_values = try sema.arena.alloc(Value, max_len); |
| 21709 | const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len); |
| 21603 | 21710 | i = 0; |
| 21604 | 21711 | while (i < min_len) : (i += 1) { |
| 21605 | | expand_mask_values[i] = try mod.intValue(Type.comptime_int, i); |
| 21712 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern(); |
| 21606 | 21713 | } |
| 21607 | 21714 | while (i < max_len) : (i += 1) { |
| 21608 | | expand_mask_values[i] = try mod.intValue(Type.comptime_int, -1); |
| 21715 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern(); |
| 21609 | 21716 | } |
| 21610 | | const expand_mask = try Value.Tag.aggregate.create(sema.arena, expand_mask_values); |
| 21717 | const expand_mask = try mod.intern(.{ .aggregate = .{ |
| 21718 | .ty = (try mod.vectorType(.{ .len = @intCast(u32, max_len), .child = .comptime_int_type })).toIntern(), |
| 21719 | .storage = .{ .elems = expand_mask_values }, |
| 21720 | } }); |
| 21611 | 21721 | |
| 21612 | 21722 | if (a_len < b_len) { |
| 21613 | 21723 | const undef = try sema.addConstUndef(a_ty); |
| 21614 | | a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask, @intCast(u32, max_len)); |
| 21724 | a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(u32, max_len)); |
| 21615 | 21725 | } else { |
| 21616 | 21726 | const undef = try sema.addConstUndef(b_ty); |
| 21617 | | b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask, @intCast(u32, max_len)); |
| 21727 | b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(u32, max_len)); |
| 21618 | 21728 | } |
| 21619 | 21729 | } |
| 21620 | 21730 | |
| ... | ... | @@ -21651,7 +21761,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21651 | 21761 | |
| 21652 | 21762 | const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) { |
| 21653 | 21763 | .Vector, .Array => pred_ty.arrayLen(mod), |
| 21654 | | else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(sema.mod)}), |
| 21764 | else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}), |
| 21655 | 21765 | }; |
| 21656 | 21766 | const vec_len = @intCast(u32, try sema.usizeCast(block, pred_src, vec_len_u64)); |
| 21657 | 21767 | |
| ... | ... | @@ -21663,7 +21773,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21663 | 21773 | |
| 21664 | 21774 | const vec_ty = try mod.vectorType(.{ |
| 21665 | 21775 | .len = vec_len, |
| 21666 | | .child = elem_ty.ip_index, |
| 21776 | .child = elem_ty.toIntern(), |
| 21667 | 21777 | }); |
| 21668 | 21778 | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); |
| 21669 | 21779 | const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src); |
| ... | ... | @@ -21681,21 +21791,17 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21681 | 21791 | if (maybe_b) |b_val| { |
| 21682 | 21792 | if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty); |
| 21683 | 21793 | |
| 21684 | | const elems = try sema.gpa.alloc(Value, vec_len); |
| 21794 | const elems = try sema.gpa.alloc(InternPool.Index, vec_len); |
| 21685 | 21795 | for (elems, 0..) |*elem, i| { |
| 21686 | | const pred_elem_val = try pred_val.elemValue(sema.mod, i); |
| 21796 | const pred_elem_val = try pred_val.elemValue(mod, i); |
| 21687 | 21797 | const should_choose_a = pred_elem_val.toBool(mod); |
| 21688 | | if (should_choose_a) { |
| 21689 | | elem.* = try a_val.elemValue(sema.mod, i); |
| 21690 | | } else { |
| 21691 | | elem.* = try b_val.elemValue(sema.mod, i); |
| 21692 | | } |
| 21798 | elem.* = try (try (if (should_choose_a) a_val else b_val).elemValue(mod, i)).intern(elem_ty, mod); |
| 21693 | 21799 | } |
| 21694 | 21800 | |
| 21695 | | return sema.addConstant( |
| 21696 | | vec_ty, |
| 21697 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 21698 | | ); |
| 21801 | return sema.addConstant(vec_ty, (try mod.intern(.{ .aggregate = .{ |
| 21802 | .ty = vec_ty.toIntern(), |
| 21803 | .storage = .{ .elems = elems }, |
| 21804 | } })).toValue()); |
| 21699 | 21805 | } else { |
| 21700 | 21806 | break :rs b_src; |
| 21701 | 21807 | } |
| ... | ... | @@ -22019,7 +22125,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 22019 | 22125 | const args = try sema.resolveInst(extra.args); |
| 22020 | 22126 | |
| 22021 | 22127 | const args_ty = sema.typeOf(args); |
| 22022 | | if (!args_ty.isTuple(mod) and args_ty.ip_index != .empty_struct_type) { |
| 22128 | if (!args_ty.isTuple(mod) and args_ty.toIntern() != .empty_struct_type) { |
| 22023 | 22129 | return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)}); |
| 22024 | 22130 | } |
| 22025 | 22131 | |
| ... | ... | @@ -22102,7 +22208,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22102 | 22208 | const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); |
| 22103 | 22209 | |
| 22104 | 22210 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { |
| 22105 | | const field = switch (mod.intern_pool.indexToKey(field_ptr_val.ip_index)) { |
| 22211 | const field = switch (mod.intern_pool.indexToKey(field_ptr_val.toIntern())) { |
| 22106 | 22212 | .ptr => |ptr| switch (ptr.addr) { |
| 22107 | 22213 | .field => |field| field, |
| 22108 | 22214 | else => null, |
| ... | ... | @@ -22244,16 +22350,16 @@ fn analyzeMinMax( |
| 22244 | 22350 | cur_minmax = try sema.addConstant(simd_op.result_ty, result_val); |
| 22245 | 22351 | continue; |
| 22246 | 22352 | }; |
| 22247 | | const elems = try sema.arena.alloc(Value, vec_len); |
| 22353 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 22248 | 22354 | for (elems, 0..) |*elem, i| { |
| 22249 | 22355 | const lhs_elem_val = try cur_val.elemValue(mod, i); |
| 22250 | 22356 | const rhs_elem_val = try operand_val.elemValue(mod, i); |
| 22251 | | elem.* = opFunc(lhs_elem_val, rhs_elem_val, mod); |
| 22357 | elem.* = try opFunc(lhs_elem_val, rhs_elem_val, mod).intern(simd_op.scalar_ty, mod); |
| 22252 | 22358 | } |
| 22253 | | cur_minmax = try sema.addConstant( |
| 22254 | | simd_op.result_ty, |
| 22255 | | try Value.Tag.aggregate.create(sema.arena, elems), |
| 22256 | | ); |
| 22359 | cur_minmax = try sema.addConstant(simd_op.result_ty, (try mod.intern(.{ .aggregate = .{ |
| 22360 | .ty = simd_op.result_ty.toIntern(), |
| 22361 | .storage = .{ .elems = elems }, |
| 22362 | } })).toValue()); |
| 22257 | 22363 | } else { |
| 22258 | 22364 | runtime_known.unset(operand_idx); |
| 22259 | 22365 | cur_minmax = try sema.addConstant(sema.typeOf(operand), uncasted_operand_val); |
| ... | ... | @@ -22292,7 +22398,7 @@ fn analyzeMinMax( |
| 22292 | 22398 | const refined_elem_ty = try mod.intFittingRange(cur_min, cur_max); |
| 22293 | 22399 | break :blk try mod.vectorType(.{ |
| 22294 | 22400 | .len = len, |
| 22295 | | .child = refined_elem_ty.ip_index, |
| 22401 | .child = refined_elem_ty.toIntern(), |
| 22296 | 22402 | }); |
| 22297 | 22403 | } else blk: { |
| 22298 | 22404 | if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats |
| ... | ... | @@ -22377,7 +22483,7 @@ fn analyzeMinMax( |
| 22377 | 22483 | const final_ty = if (is_vector) |
| 22378 | 22484 | try mod.vectorType(.{ |
| 22379 | 22485 | .len = unrefined_ty.vectorLen(mod), |
| 22380 | | .child = final_elem_ty.ip_index, |
| 22486 | .child = final_elem_ty.toIntern(), |
| 22381 | 22487 | }) |
| 22382 | 22488 | else |
| 22383 | 22489 | final_elem_ty; |
| ... | ... | @@ -22765,7 +22871,7 @@ fn zirVarExtended( |
| 22765 | 22871 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); |
| 22766 | 22872 | |
| 22767 | 22873 | return sema.addConstant(var_ty, (try mod.intern(.{ .variable = .{ |
| 22768 | | .ty = var_ty.ip_index, |
| 22874 | .ty = var_ty.toIntern(), |
| 22769 | 22875 | .init = init_val.toIntern(), |
| 22770 | 22876 | .decl = sema.owner_decl_index, |
| 22771 | 22877 | .lib_name = if (lib_name) |lname| (try mod.intern_pool.getOrPutString( |
| ... | ... | @@ -23239,7 +23345,7 @@ fn zirBuiltinExtern( |
| 23239 | 23345 | |
| 23240 | 23346 | { |
| 23241 | 23347 | const new_var = try mod.intern(.{ .variable = .{ |
| 23242 | | .ty = ty.ip_index, |
| 23348 | .ty = ty.toIntern(), |
| 23243 | 23349 | .init = .none, |
| 23244 | 23350 | .decl = sema.owner_decl_index, |
| 23245 | 23351 | .is_extern = true, |
| ... | ... | @@ -23264,7 +23370,7 @@ fn zirBuiltinExtern( |
| 23264 | 23370 | try sema.ensureDeclAnalyzed(new_decl_index); |
| 23265 | 23371 | |
| 23266 | 23372 | const ref = try mod.intern(.{ .ptr = .{ |
| 23267 | | .ty = (try mod.singleConstPtrType(ty)).ip_index, |
| 23373 | .ty = (try mod.singleConstPtrType(ty)).toIntern(), |
| 23268 | 23374 | .addr = .{ .decl = new_decl_index }, |
| 23269 | 23375 | } }); |
| 23270 | 23376 | return sema.addConstant(ty, ref.toValue()); |
| ... | ... | @@ -24207,7 +24313,7 @@ fn fieldVal( |
| 24207 | 24313 | switch (try child_type.zigTypeTagOrPoison(mod)) { |
| 24208 | 24314 | .ErrorSet => { |
| 24209 | 24315 | const name = try ip.getOrPutString(gpa, field_name); |
| 24210 | | switch (ip.indexToKey(child_type.ip_index)) { |
| 24316 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24211 | 24317 | .error_set_type => |error_set_type| blk: { |
| 24212 | 24318 | if (error_set_type.nameIndex(ip, name) != null) break :blk; |
| 24213 | 24319 | const msg = msg: { |
| ... | ... | @@ -24232,7 +24338,7 @@ fn fieldVal( |
| 24232 | 24338 | else |
| 24233 | 24339 | try mod.singleErrorSetTypeNts(name); |
| 24234 | 24340 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 24235 | | .ty = error_set_type.ip_index, |
| 24341 | .ty = error_set_type.toIntern(), |
| 24236 | 24342 | .name = name, |
| 24237 | 24343 | } })).toValue()); |
| 24238 | 24344 | }, |
| ... | ... | @@ -24376,9 +24482,9 @@ fn fieldPtr( |
| 24376 | 24482 | |
| 24377 | 24483 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
| 24378 | 24484 | return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{ |
| 24379 | | .ty = result_ty.ip_index, |
| 24485 | .ty = result_ty.toIntern(), |
| 24380 | 24486 | .addr = .{ .field = .{ |
| 24381 | | .base = val.ip_index, |
| 24487 | .base = val.toIntern(), |
| 24382 | 24488 | .index = Value.slice_ptr_index, |
| 24383 | 24489 | } }, |
| 24384 | 24490 | } })).toValue()); |
| ... | ... | @@ -24396,9 +24502,9 @@ fn fieldPtr( |
| 24396 | 24502 | |
| 24397 | 24503 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
| 24398 | 24504 | return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{ |
| 24399 | | .ty = result_ty.ip_index, |
| 24505 | .ty = result_ty.toIntern(), |
| 24400 | 24506 | .addr = .{ .field = .{ |
| 24401 | | .base = val.ip_index, |
| 24507 | .base = val.toIntern(), |
| 24402 | 24508 | .index = Value.slice_len_index, |
| 24403 | 24509 | } }, |
| 24404 | 24510 | } })).toValue()); |
| ... | ... | @@ -24429,7 +24535,7 @@ fn fieldPtr( |
| 24429 | 24535 | switch (child_type.zigTypeTag(mod)) { |
| 24430 | 24536 | .ErrorSet => { |
| 24431 | 24537 | const name = try ip.getOrPutString(gpa, field_name); |
| 24432 | | switch (ip.indexToKey(child_type.ip_index)) { |
| 24538 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24433 | 24539 | .error_set_type => |error_set_type| blk: { |
| 24434 | 24540 | if (error_set_type.nameIndex(ip, name) != null) { |
| 24435 | 24541 | break :blk; |
| ... | ... | @@ -24454,7 +24560,7 @@ fn fieldPtr( |
| 24454 | 24560 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24455 | 24561 | error_set_type, |
| 24456 | 24562 | (try mod.intern(.{ .err = .{ |
| 24457 | | .ty = error_set_type.ip_index, |
| 24563 | .ty = error_set_type.toIntern(), |
| 24458 | 24564 | .name = name, |
| 24459 | 24565 | } })).toValue(), |
| 24460 | 24566 | 0, // default alignment |
| ... | ... | @@ -24722,9 +24828,9 @@ fn finishFieldCallBind( |
| 24722 | 24828 | |
| 24723 | 24829 | if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| { |
| 24724 | 24830 | const pointer = try sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ |
| 24725 | | .ty = ptr_field_ty.ip_index, |
| 24831 | .ty = ptr_field_ty.toIntern(), |
| 24726 | 24832 | .addr = .{ .field = .{ |
| 24727 | | .base = struct_ptr_val.ip_index, |
| 24833 | .base = struct_ptr_val.toIntern(), |
| 24728 | 24834 | .index = field_index, |
| 24729 | 24835 | } }, |
| 24730 | 24836 | } })).toValue()); |
| ... | ... | @@ -24908,7 +25014,7 @@ fn structFieldPtrByIndex( |
| 24908 | 25014 | |
| 24909 | 25015 | if (field.is_comptime) { |
| 24910 | 25016 | const val = try mod.intern(.{ .ptr = .{ |
| 24911 | | .ty = ptr_field_ty.ip_index, |
| 25017 | .ty = ptr_field_ty.toIntern(), |
| 24912 | 25018 | .addr = .{ .comptime_field = try field.default_val.intern(field.ty, mod) }, |
| 24913 | 25019 | } }); |
| 24914 | 25020 | return sema.addConstant(ptr_field_ty, val.toValue()); |
| ... | ... | @@ -24916,7 +25022,7 @@ fn structFieldPtrByIndex( |
| 24916 | 25022 | |
| 24917 | 25023 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { |
| 24918 | 25024 | const val = try mod.intern(.{ .ptr = .{ |
| 24919 | | .ty = ptr_field_ty.ip_index, |
| 25025 | .ty = ptr_field_ty.toIntern(), |
| 24920 | 25026 | .addr = .{ .field = .{ |
| 24921 | 25027 | .base = try struct_ptr_val.intern(struct_ptr_ty, mod), |
| 24922 | 25028 | .index = field_index, |
| ... | ... | @@ -24942,7 +25048,7 @@ fn structFieldVal( |
| 24942 | 25048 | assert(unresolved_struct_ty.zigTypeTag(mod) == .Struct); |
| 24943 | 25049 | |
| 24944 | 25050 | const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty); |
| 24945 | | switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) { |
| 25051 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 24946 | 25052 | .struct_type => |struct_type| { |
| 24947 | 25053 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 24948 | 25054 | if (struct_obj.is_tuple) return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); |
| ... | ... | @@ -25116,9 +25222,9 @@ fn unionFieldPtr( |
| 25116 | 25222 | .Packed, .Extern => {}, |
| 25117 | 25223 | } |
| 25118 | 25224 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ |
| 25119 | | .ty = ptr_field_ty.ip_index, |
| 25225 | .ty = ptr_field_ty.toIntern(), |
| 25120 | 25226 | .addr = .{ .field = .{ |
| 25121 | | .base = union_ptr_val.ip_index, |
| 25227 | .base = union_ptr_val.toIntern(), |
| 25122 | 25228 | .index = field_index, |
| 25123 | 25229 | } }, |
| 25124 | 25230 | } })).toValue()); |
| ... | ... | @@ -25413,16 +25519,16 @@ fn tupleFieldPtr( |
| 25413 | 25519 | |
| 25414 | 25520 | if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| { |
| 25415 | 25521 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ |
| 25416 | | .ty = ptr_field_ty.ip_index, |
| 25417 | | .addr = .{ .comptime_field = default_val.ip_index }, |
| 25522 | .ty = ptr_field_ty.toIntern(), |
| 25523 | .addr = .{ .comptime_field = default_val.toIntern() }, |
| 25418 | 25524 | } })).toValue()); |
| 25419 | 25525 | } |
| 25420 | 25526 | |
| 25421 | 25527 | if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| { |
| 25422 | 25528 | return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{ |
| 25423 | | .ty = ptr_field_ty.ip_index, |
| 25529 | .ty = ptr_field_ty.toIntern(), |
| 25424 | 25530 | .addr = .{ .field = .{ |
| 25425 | | .base = tuple_ptr_val.ip_index, |
| 25531 | .base = tuple_ptr_val.toIntern(), |
| 25426 | 25532 | .index = field_index, |
| 25427 | 25533 | } }, |
| 25428 | 25534 | } })).toValue()); |
| ... | ... | @@ -25787,11 +25893,11 @@ fn coerceExtra( |
| 25787 | 25893 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| 25788 | 25894 | if (in_memory_result == .ok) { |
| 25789 | 25895 | if (maybe_inst_val) |val| { |
| 25790 | | if (val.ip_index == .none or val.ip_index == .null_value) { |
| 25896 | if (val.ip_index == .none) { |
| 25791 | 25897 | // Keep the comptime Value representation; take the new type. |
| 25792 | 25898 | return sema.addConstant(dest_ty, val); |
| 25793 | 25899 | } else { |
| 25794 | | const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.ip_index, dest_ty.ip_index); |
| 25900 | const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.toIntern(), dest_ty.toIntern()); |
| 25795 | 25901 | return sema.addConstant(dest_ty, new_val.toValue()); |
| 25796 | 25902 | } |
| 25797 | 25903 | } |
| ... | ... | @@ -25816,7 +25922,7 @@ fn coerceExtra( |
| 25816 | 25922 | // cast from ?*T and ?[*]T to ?*anyopaque |
| 25817 | 25923 | // but don't do it if the source type is a double pointer |
| 25818 | 25924 | if (dest_ty.isPtrLikeOptional(mod) and |
| 25819 | | dest_ty.elemType2(mod).ip_index == .anyopaque_type and |
| 25925 | dest_ty.elemType2(mod).toIntern() == .anyopaque_type and |
| 25820 | 25926 | inst_ty.isPtrAtRuntime(mod)) |
| 25821 | 25927 | anyopaque_check: { |
| 25822 | 25928 | if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :optional; |
| ... | ... | @@ -25954,7 +26060,7 @@ fn coerceExtra( |
| 25954 | 26060 | |
| 25955 | 26061 | // cast from *T and [*]T to *anyopaque |
| 25956 | 26062 | // but don't do it if the source type is a double pointer |
| 25957 | | if (dest_info.pointee_type.ip_index == .anyopaque_type and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: { |
| 26063 | if (dest_info.pointee_type.toIntern() == .anyopaque_type and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: { |
| 25958 | 26064 | if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer; |
| 25959 | 26065 | const elem_ty = inst_ty.elemType2(mod); |
| 25960 | 26066 | if (elem_ty.zigTypeTag(mod) == .Pointer or elem_ty.isPtrLikeOptional(mod)) { |
| ... | ... | @@ -26084,12 +26190,12 @@ fn coerceExtra( |
| 26084 | 26190 | // Optional slice is represented with a null pointer so |
| 26085 | 26191 | // we use a dummy pointer value with the required alignment. |
| 26086 | 26192 | return sema.addConstant(dest_ty, (try mod.intern(.{ .ptr = .{ |
| 26087 | | .ty = dest_ty.ip_index, |
| 26193 | .ty = dest_ty.toIntern(), |
| 26088 | 26194 | .addr = .{ .int = (if (dest_info.@"align" != 0) |
| 26089 | 26195 | try mod.intValue(Type.usize, dest_info.@"align") |
| 26090 | 26196 | else |
| 26091 | | try dest_info.pointee_type.lazyAbiAlignment(mod)).ip_index }, |
| 26092 | | .len = (try mod.intValue(Type.usize, 0)).ip_index, |
| 26197 | try dest_info.pointee_type.lazyAbiAlignment(mod)).toIntern() }, |
| 26198 | .len = (try mod.intValue(Type.usize, 0)).toIntern(), |
| 26093 | 26199 | } })).toValue()); |
| 26094 | 26200 | } |
| 26095 | 26201 | |
| ... | ... | @@ -26166,7 +26272,7 @@ fn coerceExtra( |
| 26166 | 26272 | if (!opts.report_err) return error.NotCoercible; |
| 26167 | 26273 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) }); |
| 26168 | 26274 | } |
| 26169 | | const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.ip_index, dest_ty.ip_index); |
| 26275 | const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.toIntern(), dest_ty.toIntern()); |
| 26170 | 26276 | return try sema.addConstant(dest_ty, new_val.toValue()); |
| 26171 | 26277 | } |
| 26172 | 26278 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| ... | ... | @@ -26258,7 +26364,7 @@ fn coerceExtra( |
| 26258 | 26364 | .EnumLiteral => { |
| 26259 | 26365 | // enum literal to enum |
| 26260 | 26366 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); |
| 26261 | | const string = mod.intern_pool.indexToKey(val.ip_index).enum_literal; |
| 26367 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 26262 | 26368 | const bytes = mod.intern_pool.stringToSlice(string); |
| 26263 | 26369 | const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse { |
| 26264 | 26370 | const msg = msg: { |
| ... | ... | @@ -26294,14 +26400,14 @@ fn coerceExtra( |
| 26294 | 26400 | .ErrorUnion => switch (inst_ty.zigTypeTag(mod)) { |
| 26295 | 26401 | .ErrorUnion => eu: { |
| 26296 | 26402 | if (maybe_inst_val) |inst_val| { |
| 26297 | | switch (inst_val.ip_index) { |
| 26403 | switch (inst_val.toIntern()) { |
| 26298 | 26404 | .undef => return sema.addConstUndef(dest_ty), |
| 26299 | | else => switch (mod.intern_pool.indexToKey(inst_val.ip_index)) { |
| 26405 | else => switch (mod.intern_pool.indexToKey(inst_val.toIntern())) { |
| 26300 | 26406 | .error_union => |error_union| switch (error_union.val) { |
| 26301 | 26407 | .err_name => |err_name| { |
| 26302 | 26408 | const error_set_ty = inst_ty.errorUnionSet(mod); |
| 26303 | 26409 | const error_set_val = try sema.addConstant(error_set_ty, (try mod.intern(.{ .err = .{ |
| 26304 | | .ty = error_set_ty.ip_index, |
| 26410 | .ty = error_set_ty.toIntern(), |
| 26305 | 26411 | .name = err_name, |
| 26306 | 26412 | } })).toValue()); |
| 26307 | 26413 | return sema.wrapErrorUnionSet(block, dest_ty, error_set_val, inst_src); |
| ... | ... | @@ -26597,7 +26703,7 @@ const InMemoryCoercionResult = union(enum) { |
| 26597 | 26703 | break; |
| 26598 | 26704 | }, |
| 26599 | 26705 | .array_sentinel => |sentinel| { |
| 26600 | | if (sentinel.actual.ip_index != .unreachable_value) { |
| 26706 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 26601 | 26707 | try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ |
| 26602 | 26708 | sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod), |
| 26603 | 26709 | }); |
| ... | ... | @@ -26724,7 +26830,7 @@ const InMemoryCoercionResult = union(enum) { |
| 26724 | 26830 | break; |
| 26725 | 26831 | }, |
| 26726 | 26832 | .ptr_sentinel => |sentinel| { |
| 26727 | | if (sentinel.actual.ip_index != .unreachable_value) { |
| 26833 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 26728 | 26834 | try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ |
| 26729 | 26835 | sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod), |
| 26730 | 26836 | }); |
| ... | ... | @@ -27016,9 +27122,9 @@ fn coerceInMemoryAllowedErrorSets( |
| 27016 | 27122 | const dst_ies = mod.inferredErrorSetPtr(dst_ies_index); |
| 27017 | 27123 | // We will make an effort to return `ok` without resolving either error set, to |
| 27018 | 27124 | // avoid unnecessary "unable to resolve error set" dependency loop errors. |
| 27019 | | switch (src_ty.ip_index) { |
| 27125 | switch (src_ty.toIntern()) { |
| 27020 | 27126 | .anyerror_type => {}, |
| 27021 | | else => switch (ip.indexToKey(src_ty.ip_index)) { |
| 27127 | else => switch (ip.indexToKey(src_ty.toIntern())) { |
| 27022 | 27128 | .inferred_error_set_type => |src_index| { |
| 27023 | 27129 | // If both are inferred error sets of functions, and |
| 27024 | 27130 | // the dest includes the source function, the coercion is OK. |
| ... | ... | @@ -27054,15 +27160,15 @@ fn coerceInMemoryAllowedErrorSets( |
| 27054 | 27160 | var missing_error_buf = std.ArrayList(InternPool.NullTerminatedString).init(gpa); |
| 27055 | 27161 | defer missing_error_buf.deinit(); |
| 27056 | 27162 | |
| 27057 | | switch (src_ty.ip_index) { |
| 27058 | | .anyerror_type => switch (ip.indexToKey(dest_ty.ip_index)) { |
| 27163 | switch (src_ty.toIntern()) { |
| 27164 | .anyerror_type => switch (ip.indexToKey(dest_ty.toIntern())) { |
| 27059 | 27165 | .inferred_error_set_type => unreachable, // Caught by dest_ty.isAnyError(mod) above. |
| 27060 | 27166 | .simple_type => unreachable, // filtered out above |
| 27061 | 27167 | .error_set_type => return .from_anyerror, |
| 27062 | 27168 | else => unreachable, |
| 27063 | 27169 | }, |
| 27064 | 27170 | |
| 27065 | | else => switch (ip.indexToKey(src_ty.ip_index)) { |
| 27171 | else => switch (ip.indexToKey(src_ty.toIntern())) { |
| 27066 | 27172 | .inferred_error_set_type => |src_index| { |
| 27067 | 27173 | const src_data = mod.inferredErrorSetPtr(src_index); |
| 27068 | 27174 | |
| ... | ... | @@ -27520,9 +27626,9 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref { |
| 27520 | 27626 | // allocations is relevant to this function, or why it would have |
| 27521 | 27627 | // different behavior depending on whether the types were inferred. |
| 27522 | 27628 | // Something seems wrong here. |
| 27523 | | if (prev_ptr_ty.ip_index == .none) { |
| 27524 | | if (prev_ptr_ty.ip_index == .inferred_alloc_mut_type) return null; |
| 27525 | | if (prev_ptr_ty.ip_index == .inferred_alloc_const_type) return null; |
| 27629 | switch (prev_ptr_ty.ip_index) { |
| 27630 | .inferred_alloc_mut_type, .inferred_alloc_const_type => return null, |
| 27631 | else => {}, |
| 27526 | 27632 | } |
| 27527 | 27633 | |
| 27528 | 27634 | const prev_ptr_child_ty = prev_ptr_ty.childType(mod); |
| ... | ... | @@ -27554,11 +27660,11 @@ fn storePtrVal( |
| 27554 | 27660 | ) !void { |
| 27555 | 27661 | const mod = sema.mod; |
| 27556 | 27662 | var mut_kit = try sema.beginComptimePtrMutation(block, src, ptr_val, operand_ty); |
| 27557 | | try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut); |
| 27663 | try sema.checkComptimeVarStore(block, src, mut_kit.mut_decl); |
| 27558 | 27664 | |
| 27559 | 27665 | switch (mut_kit.pointee) { |
| 27560 | 27666 | .direct => |val_ptr| { |
| 27561 | | if (mut_kit.decl_ref_mut.runtime_index == .comptime_field_ptr) { |
| 27667 | if (mut_kit.mut_decl.runtime_index == .comptime_field_ptr) { |
| 27562 | 27668 | if (!operand_val.eql(val_ptr.*, operand_ty, sema.mod)) { |
| 27563 | 27669 | // TODO use failWithInvalidComptimeFieldStore |
| 27564 | 27670 | return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{}); |
| ... | ... | @@ -27601,7 +27707,7 @@ fn storePtrVal( |
| 27601 | 27707 | } |
| 27602 | 27708 | |
| 27603 | 27709 | const ComptimePtrMutationKit = struct { |
| 27604 | | decl_ref_mut: InternPool.Key.Ptr.Addr.MutDecl, |
| 27710 | mut_decl: InternPool.Key.Ptr.Addr.MutDecl, |
| 27605 | 27711 | pointee: union(enum) { |
| 27606 | 27712 | /// The pointer type matches the actual comptime Value so a direct |
| 27607 | 27713 | /// modification is possible. |
| ... | ... | @@ -27627,12 +27733,12 @@ const ComptimePtrMutationKit = struct { |
| 27627 | 27733 | decl_arena: std.heap.ArenaAllocator = undefined, |
| 27628 | 27734 | |
| 27629 | 27735 | fn beginArena(self: *ComptimePtrMutationKit, mod: *Module) Allocator { |
| 27630 | | const decl = mod.declPtr(self.decl_ref_mut.decl); |
| 27736 | const decl = mod.declPtr(self.mut_decl.decl); |
| 27631 | 27737 | return decl.value_arena.?.acquire(mod.gpa, &self.decl_arena); |
| 27632 | 27738 | } |
| 27633 | 27739 | |
| 27634 | 27740 | fn finishArena(self: *ComptimePtrMutationKit, mod: *Module) void { |
| 27635 | | const decl = mod.declPtr(self.decl_ref_mut.decl); |
| 27741 | const decl = mod.declPtr(self.mut_decl.decl); |
| 27636 | 27742 | decl.value_arena.?.release(&self.decl_arena); |
| 27637 | 27743 | self.decl_arena = undefined; |
| 27638 | 27744 | } |
| ... | ... | @@ -27645,99 +27751,85 @@ fn beginComptimePtrMutation( |
| 27645 | 27751 | ptr_val: Value, |
| 27646 | 27752 | ptr_elem_ty: Type, |
| 27647 | 27753 | ) CompileError!ComptimePtrMutationKit { |
| 27648 | | if (true) unreachable; |
| 27649 | 27754 | const mod = sema.mod; |
| 27650 | | switch (ptr_val.tag()) { |
| 27651 | | .decl_ref_mut => { |
| 27652 | | const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data; |
| 27653 | | const decl = sema.mod.declPtr(decl_ref_mut.decl_index); |
| 27654 | | return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut); |
| 27755 | const ptr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr; |
| 27756 | switch (ptr.addr) { |
| 27757 | .decl => unreachable, // isComptimeMutablePtr has been checked already |
| 27758 | .mut_decl => |mut_decl| { |
| 27759 | const decl = mod.declPtr(mut_decl.decl); |
| 27760 | return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, mut_decl); |
| 27655 | 27761 | }, |
| 27656 | | .comptime_field_ptr => { |
| 27657 | | const payload = ptr_val.castTag(.comptime_field_ptr).?.data; |
| 27762 | .comptime_field => |comptime_field| { |
| 27658 | 27763 | const duped = try sema.arena.create(Value); |
| 27659 | | duped.* = payload.field_val; |
| 27660 | | return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{ |
| 27661 | | .decl_index = @intToEnum(Module.Decl.Index, 0), |
| 27764 | duped.* = comptime_field.toValue(); |
| 27765 | return sema.beginComptimePtrMutationInner(block, src, mod.intern_pool.typeOf(ptr_val.toIntern()).toType(), duped, ptr_elem_ty, .{ |
| 27766 | .decl = undefined, |
| 27662 | 27767 | .runtime_index = .comptime_field_ptr, |
| 27663 | 27768 | }); |
| 27664 | 27769 | }, |
| 27665 | | .elem_ptr => { |
| 27666 | | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; |
| 27667 | | var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty); |
| 27668 | | |
| 27669 | | switch (parent.pointee) { |
| 27670 | | .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) { |
| 27671 | | .Array, .Vector => { |
| 27672 | | const check_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27673 | | if (elem_ptr.index >= check_len) { |
| 27674 | | // TODO have the parent include the decl so we can say "declared here" |
| 27675 | | return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{ |
| 27676 | | elem_ptr.index, check_len, |
| 27677 | | }); |
| 27678 | | } |
| 27679 | | const elem_ty = parent.ty.childType(mod); |
| 27680 | | |
| 27681 | | // We might have a pointer to multiple elements of the array (e.g. a pointer |
| 27682 | | // to a sub-array). In this case, we just have to reinterpret the relevant |
| 27683 | | // bytes of the whole array rather than any single element. |
| 27684 | | const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty); |
| 27685 | | if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) { |
| 27686 | | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 27687 | | return .{ |
| 27688 | | .decl_ref_mut = parent.decl_ref_mut, |
| 27689 | | .pointee = .{ .reinterpret = .{ |
| 27690 | | .val_ptr = val_ptr, |
| 27691 | | .byte_offset = elem_abi_size * elem_ptr.index, |
| 27692 | | } }, |
| 27693 | | .ty = parent.ty, |
| 27694 | | }; |
| 27695 | | } |
| 27696 | | |
| 27697 | | switch (val_ptr.ip_index) { |
| 27698 | | .undef => { |
| 27699 | | // An array has been initialized to undefined at comptime and now we |
| 27700 | | // are for the first time setting an element. We must change the representation |
| 27701 | | // of the array from `undef` to `array`. |
| 27702 | | const arena = parent.beginArena(sema.mod); |
| 27703 | | defer parent.finishArena(sema.mod); |
| 27704 | | |
| 27705 | | const array_len_including_sentinel = |
| 27706 | | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| 27707 | | const elems = try arena.alloc(Value, array_len_including_sentinel); |
| 27708 | | @memset(elems, Value.undef); |
| 27709 | | |
| 27710 | | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27770 | else => unreachable, |
| 27771 | } |
| 27772 | if (true) unreachable; |
| 27773 | switch (ptr_val.toIntern()) { |
| 27774 | .none => switch (ptr_val.tag()) { |
| 27775 | .decl_ref_mut => { |
| 27776 | const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data; |
| 27777 | const decl = sema.mod.declPtr(decl_ref_mut.decl_index); |
| 27778 | return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut); |
| 27779 | }, |
| 27780 | .comptime_field_ptr => { |
| 27781 | const payload = ptr_val.castTag(.comptime_field_ptr).?.data; |
| 27782 | const duped = try sema.arena.create(Value); |
| 27783 | duped.* = payload.field_val; |
| 27784 | return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{ |
| 27785 | .decl_index = @intToEnum(Module.Decl.Index, 0), |
| 27786 | .runtime_index = .comptime_field_ptr, |
| 27787 | }); |
| 27788 | }, |
| 27789 | .elem_ptr => { |
| 27790 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; |
| 27791 | var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty); |
| 27792 | |
| 27793 | switch (parent.pointee) { |
| 27794 | .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) { |
| 27795 | .Array, .Vector => { |
| 27796 | const check_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27797 | if (elem_ptr.index >= check_len) { |
| 27798 | // TODO have the parent include the decl so we can say "declared here" |
| 27799 | return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{ |
| 27800 | elem_ptr.index, check_len, |
| 27801 | }); |
| 27802 | } |
| 27803 | const elem_ty = parent.ty.childType(mod); |
| 27804 | |
| 27805 | // We might have a pointer to multiple elements of the array (e.g. a pointer |
| 27806 | // to a sub-array). In this case, we just have to reinterpret the relevant |
| 27807 | // bytes of the whole array rather than any single element. |
| 27808 | const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty); |
| 27809 | if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) { |
| 27810 | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 27811 | return .{ |
| 27812 | .decl_ref_mut = parent.decl_ref_mut, |
| 27813 | .pointee = .{ .reinterpret = .{ |
| 27814 | .val_ptr = val_ptr, |
| 27815 | .byte_offset = elem_abi_size * elem_ptr.index, |
| 27816 | } }, |
| 27817 | .ty = parent.ty, |
| 27818 | }; |
| 27819 | } |
| 27711 | 27820 | |
| 27712 | | return beginComptimePtrMutationInner( |
| 27713 | | sema, |
| 27714 | | block, |
| 27715 | | src, |
| 27716 | | elem_ty, |
| 27717 | | &elems[elem_ptr.index], |
| 27718 | | ptr_elem_ty, |
| 27719 | | parent.decl_ref_mut, |
| 27720 | | ); |
| 27721 | | }, |
| 27722 | | .none => switch (val_ptr.tag()) { |
| 27723 | | .bytes => { |
| 27724 | | // An array is memory-optimized to store a slice of bytes, but we are about |
| 27725 | | // to modify an individual field and the representation has to change. |
| 27726 | | // If we wanted to avoid this, there would need to be special detection |
| 27727 | | // elsewhere to identify when writing a value to an array element that is stored |
| 27728 | | // using the `bytes` tag, and handle it without making a call to this function. |
| 27821 | switch (val_ptr.toIntern()) { |
| 27822 | .undef => { |
| 27823 | // An array has been initialized to undefined at comptime and now we |
| 27824 | // are for the first time setting an element. We must change the representation |
| 27825 | // of the array from `undef` to `array`. |
| 27729 | 27826 | const arena = parent.beginArena(sema.mod); |
| 27730 | 27827 | defer parent.finishArena(sema.mod); |
| 27731 | 27828 | |
| 27732 | | const bytes = val_ptr.castTag(.bytes).?.data; |
| 27733 | | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27734 | | // bytes.len may be one greater than dest_len because of the case when |
| 27735 | | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. |
| 27736 | | assert(bytes.len >= dest_len); |
| 27737 | | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 27738 | | for (elems, 0..) |*elem, i| { |
| 27739 | | elem.* = try mod.intValue(elem_ty, bytes[i]); |
| 27740 | | } |
| 27829 | const array_len_including_sentinel = |
| 27830 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| 27831 | const elems = try arena.alloc(Value, array_len_including_sentinel); |
| 27832 | @memset(elems, Value.undef); |
| 27741 | 27833 | |
| 27742 | 27834 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27743 | 27835 | |
| ... | ... | @@ -27751,392 +27843,383 @@ fn beginComptimePtrMutation( |
| 27751 | 27843 | parent.decl_ref_mut, |
| 27752 | 27844 | ); |
| 27753 | 27845 | }, |
| 27754 | | .str_lit => { |
| 27755 | | // An array is memory-optimized to store a slice of bytes, but we are about |
| 27756 | | // to modify an individual field and the representation has to change. |
| 27757 | | // If we wanted to avoid this, there would need to be special detection |
| 27758 | | // elsewhere to identify when writing a value to an array element that is stored |
| 27759 | | // using the `str_lit` tag, and handle it without making a call to this function. |
| 27760 | | const arena = parent.beginArena(sema.mod); |
| 27761 | | defer parent.finishArena(sema.mod); |
| 27762 | | |
| 27763 | | const str_lit = val_ptr.castTag(.str_lit).?.data; |
| 27764 | | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27765 | | const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; |
| 27766 | | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 27767 | | for (bytes, 0..) |byte, i| { |
| 27768 | | elems[i] = try mod.intValue(elem_ty, byte); |
| 27769 | | } |
| 27770 | | if (parent.ty.sentinel(mod)) |sent_val| { |
| 27771 | | assert(elems.len == bytes.len + 1); |
| 27772 | | elems[bytes.len] = sent_val; |
| 27773 | | } |
| 27774 | | |
| 27775 | | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27776 | | |
| 27777 | | return beginComptimePtrMutationInner( |
| 27846 | .none => switch (val_ptr.tag()) { |
| 27847 | .bytes => { |
| 27848 | // An array is memory-optimized to store a slice of bytes, but we are about |
| 27849 | // to modify an individual field and the representation has to change. |
| 27850 | // If we wanted to avoid this, there would need to be special detection |
| 27851 | // elsewhere to identify when writing a value to an array element that is stored |
| 27852 | // using the `bytes` tag, and handle it without making a call to this function. |
| 27853 | const arena = parent.beginArena(sema.mod); |
| 27854 | defer parent.finishArena(sema.mod); |
| 27855 | |
| 27856 | const bytes = val_ptr.castTag(.bytes).?.data; |
| 27857 | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27858 | // bytes.len may be one greater than dest_len because of the case when |
| 27859 | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. |
| 27860 | assert(bytes.len >= dest_len); |
| 27861 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 27862 | for (elems, 0..) |*elem, i| { |
| 27863 | elem.* = try mod.intValue(elem_ty, bytes[i]); |
| 27864 | } |
| 27865 | |
| 27866 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27867 | |
| 27868 | return beginComptimePtrMutationInner( |
| 27869 | sema, |
| 27870 | block, |
| 27871 | src, |
| 27872 | elem_ty, |
| 27873 | &elems[elem_ptr.index], |
| 27874 | ptr_elem_ty, |
| 27875 | parent.decl_ref_mut, |
| 27876 | ); |
| 27877 | }, |
| 27878 | .str_lit => { |
| 27879 | // An array is memory-optimized to store a slice of bytes, but we are about |
| 27880 | // to modify an individual field and the representation has to change. |
| 27881 | // If we wanted to avoid this, there would need to be special detection |
| 27882 | // elsewhere to identify when writing a value to an array element that is stored |
| 27883 | // using the `str_lit` tag, and handle it without making a call to this function. |
| 27884 | const arena = parent.beginArena(sema.mod); |
| 27885 | defer parent.finishArena(sema.mod); |
| 27886 | |
| 27887 | const str_lit = val_ptr.castTag(.str_lit).?.data; |
| 27888 | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| 27889 | const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; |
| 27890 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 27891 | for (bytes, 0..) |byte, i| { |
| 27892 | elems[i] = try mod.intValue(elem_ty, byte); |
| 27893 | } |
| 27894 | if (parent.ty.sentinel(mod)) |sent_val| { |
| 27895 | assert(elems.len == bytes.len + 1); |
| 27896 | elems[bytes.len] = sent_val; |
| 27897 | } |
| 27898 | |
| 27899 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27900 | |
| 27901 | return beginComptimePtrMutationInner( |
| 27902 | sema, |
| 27903 | block, |
| 27904 | src, |
| 27905 | elem_ty, |
| 27906 | &elems[elem_ptr.index], |
| 27907 | ptr_elem_ty, |
| 27908 | parent.decl_ref_mut, |
| 27909 | ); |
| 27910 | }, |
| 27911 | .repeated => { |
| 27912 | // An array is memory-optimized to store only a single element value, and |
| 27913 | // that value is understood to be the same for the entire length of the array. |
| 27914 | // However, now we want to modify an individual field and so the |
| 27915 | // representation has to change. If we wanted to avoid this, there would |
| 27916 | // need to be special detection elsewhere to identify when writing a value to an |
| 27917 | // array element that is stored using the `repeated` tag, and handle it |
| 27918 | // without making a call to this function. |
| 27919 | const arena = parent.beginArena(sema.mod); |
| 27920 | defer parent.finishArena(sema.mod); |
| 27921 | |
| 27922 | const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena); |
| 27923 | const array_len_including_sentinel = |
| 27924 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| 27925 | const elems = try arena.alloc(Value, array_len_including_sentinel); |
| 27926 | if (elems.len > 0) elems[0] = repeated_val; |
| 27927 | for (elems[1..]) |*elem| { |
| 27928 | elem.* = try repeated_val.copy(arena); |
| 27929 | } |
| 27930 | |
| 27931 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27932 | |
| 27933 | return beginComptimePtrMutationInner( |
| 27934 | sema, |
| 27935 | block, |
| 27936 | src, |
| 27937 | elem_ty, |
| 27938 | &elems[elem_ptr.index], |
| 27939 | ptr_elem_ty, |
| 27940 | parent.decl_ref_mut, |
| 27941 | ); |
| 27942 | }, |
| 27943 | |
| 27944 | .aggregate => return beginComptimePtrMutationInner( |
| 27778 | 27945 | sema, |
| 27779 | 27946 | block, |
| 27780 | 27947 | src, |
| 27781 | 27948 | elem_ty, |
| 27782 | | &elems[elem_ptr.index], |
| 27949 | &val_ptr.castTag(.aggregate).?.data[elem_ptr.index], |
| 27783 | 27950 | ptr_elem_ty, |
| 27784 | 27951 | parent.decl_ref_mut, |
| 27785 | | ); |
| 27952 | ), |
| 27953 | |
| 27954 | .the_only_possible_value => { |
| 27955 | const duped = try sema.arena.create(Value); |
| 27956 | duped.* = Value.initTag(.the_only_possible_value); |
| 27957 | return beginComptimePtrMutationInner( |
| 27958 | sema, |
| 27959 | block, |
| 27960 | src, |
| 27961 | elem_ty, |
| 27962 | duped, |
| 27963 | ptr_elem_ty, |
| 27964 | parent.decl_ref_mut, |
| 27965 | ); |
| 27966 | }, |
| 27967 | |
| 27968 | else => unreachable, |
| 27786 | 27969 | }, |
| 27787 | | .repeated => { |
| 27788 | | // An array is memory-optimized to store only a single element value, and |
| 27789 | | // that value is understood to be the same for the entire length of the array. |
| 27790 | | // However, now we want to modify an individual field and so the |
| 27791 | | // representation has to change. If we wanted to avoid this, there would |
| 27792 | | // need to be special detection elsewhere to identify when writing a value to an |
| 27793 | | // array element that is stored using the `repeated` tag, and handle it |
| 27794 | | // without making a call to this function. |
| 27795 | | const arena = parent.beginArena(sema.mod); |
| 27796 | | defer parent.finishArena(sema.mod); |
| 27970 | else => unreachable, |
| 27971 | } |
| 27972 | }, |
| 27973 | else => { |
| 27974 | if (elem_ptr.index != 0) { |
| 27975 | // TODO include a "declared here" note for the decl |
| 27976 | return sema.fail(block, src, "out of bounds comptime store of index {d}", .{ |
| 27977 | elem_ptr.index, |
| 27978 | }); |
| 27979 | } |
| 27980 | return beginComptimePtrMutationInner( |
| 27981 | sema, |
| 27982 | block, |
| 27983 | src, |
| 27984 | parent.ty, |
| 27985 | val_ptr, |
| 27986 | ptr_elem_ty, |
| 27987 | parent.decl_ref_mut, |
| 27988 | ); |
| 27989 | }, |
| 27990 | }, |
| 27991 | .reinterpret => |reinterpret| { |
| 27992 | if (!elem_ptr.elem_ty.hasWellDefinedLayout(mod)) { |
| 27993 | // Even though the parent value type has well-defined memory layout, our |
| 27994 | // pointer type does not. |
| 27995 | return ComptimePtrMutationKit{ |
| 27996 | .decl_ref_mut = parent.decl_ref_mut, |
| 27997 | .pointee = .bad_ptr_ty, |
| 27998 | .ty = elem_ptr.elem_ty, |
| 27999 | }; |
| 28000 | } |
| 27797 | 28001 | |
| 27798 | | const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena); |
| 27799 | | const array_len_including_sentinel = |
| 27800 | | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| 27801 | | const elems = try arena.alloc(Value, array_len_including_sentinel); |
| 27802 | | if (elems.len > 0) elems[0] = repeated_val; |
| 27803 | | for (elems[1..]) |*elem| { |
| 27804 | | elem.* = try repeated_val.copy(arena); |
| 27805 | | } |
| 28002 | const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty); |
| 28003 | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 28004 | return ComptimePtrMutationKit{ |
| 28005 | .decl_ref_mut = parent.decl_ref_mut, |
| 28006 | .pointee = .{ .reinterpret = .{ |
| 28007 | .val_ptr = reinterpret.val_ptr, |
| 28008 | .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index, |
| 28009 | } }, |
| 28010 | .ty = parent.ty, |
| 28011 | }; |
| 28012 | }, |
| 28013 | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28014 | } |
| 28015 | }, |
| 28016 | .field_ptr => { |
| 28017 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 28018 | const field_index = @intCast(u32, field_ptr.field_index); |
| 27806 | 28019 | |
| 27807 | | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 28020 | var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 28021 | switch (parent.pointee) { |
| 28022 | .direct => |val_ptr| switch (val_ptr.toIntern()) { |
| 28023 | .undef => { |
| 28024 | // A struct or union has been initialized to undefined at comptime and now we |
| 28025 | // are for the first time setting a field. We must change the representation |
| 28026 | // of the struct/union from `undef` to `struct`/`union`. |
| 28027 | const arena = parent.beginArena(sema.mod); |
| 28028 | defer parent.finishArena(sema.mod); |
| 28029 | |
| 28030 | switch (parent.ty.zigTypeTag(mod)) { |
| 28031 | .Struct => { |
| 28032 | const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 28033 | @memset(fields, Value.undef); |
| 28034 | |
| 28035 | val_ptr.* = try Value.Tag.aggregate.create(arena, fields); |
| 27808 | 28036 | |
| 27809 | 28037 | return beginComptimePtrMutationInner( |
| 27810 | 28038 | sema, |
| 27811 | 28039 | block, |
| 27812 | 28040 | src, |
| 27813 | | elem_ty, |
| 27814 | | &elems[elem_ptr.index], |
| 28041 | parent.ty.structFieldType(field_index, mod), |
| 28042 | &fields[field_index], |
| 27815 | 28043 | ptr_elem_ty, |
| 27816 | 28044 | parent.decl_ref_mut, |
| 27817 | 28045 | ); |
| 27818 | 28046 | }, |
| 28047 | .Union => { |
| 28048 | const payload = try arena.create(Value.Payload.Union); |
| 28049 | const tag_ty = parent.ty.unionTagTypeHypothetical(mod); |
| 28050 | payload.* = .{ .data = .{ |
| 28051 | .tag = try mod.enumValueFieldIndex(tag_ty, field_index), |
| 28052 | .val = Value.undef, |
| 28053 | } }; |
| 27819 | 28054 | |
| 27820 | | .aggregate => return beginComptimePtrMutationInner( |
| 27821 | | sema, |
| 27822 | | block, |
| 27823 | | src, |
| 27824 | | elem_ty, |
| 27825 | | &val_ptr.castTag(.aggregate).?.data[elem_ptr.index], |
| 27826 | | ptr_elem_ty, |
| 27827 | | parent.decl_ref_mut, |
| 27828 | | ), |
| 28055 | val_ptr.* = Value.initPayload(&payload.base); |
| 27829 | 28056 | |
| 27830 | | .the_only_possible_value => { |
| 27831 | | const duped = try sema.arena.create(Value); |
| 27832 | | duped.* = Value.initTag(.the_only_possible_value); |
| 27833 | 28057 | return beginComptimePtrMutationInner( |
| 27834 | 28058 | sema, |
| 27835 | 28059 | block, |
| 27836 | 28060 | src, |
| 27837 | | elem_ty, |
| 27838 | | duped, |
| 28061 | parent.ty.structFieldType(field_index, mod), |
| 28062 | &payload.data.val, |
| 27839 | 28063 | ptr_elem_ty, |
| 27840 | 28064 | parent.decl_ref_mut, |
| 27841 | 28065 | ); |
| 27842 | 28066 | }, |
| 27843 | | |
| 28067 | .Pointer => { |
| 28068 | assert(parent.ty.isSlice(mod)); |
| 28069 | val_ptr.* = try Value.Tag.slice.create(arena, .{ |
| 28070 | .ptr = Value.undef, |
| 28071 | .len = Value.undef, |
| 28072 | }); |
| 28073 | |
| 28074 | switch (field_index) { |
| 28075 | Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner( |
| 28076 | sema, |
| 28077 | block, |
| 28078 | src, |
| 28079 | parent.ty.slicePtrFieldType(mod), |
| 28080 | &val_ptr.castTag(.slice).?.data.ptr, |
| 28081 | ptr_elem_ty, |
| 28082 | parent.decl_ref_mut, |
| 28083 | ), |
| 28084 | Value.Payload.Slice.len_index => return beginComptimePtrMutationInner( |
| 28085 | sema, |
| 28086 | block, |
| 28087 | src, |
| 28088 | Type.usize, |
| 28089 | &val_ptr.castTag(.slice).?.data.len, |
| 28090 | ptr_elem_ty, |
| 28091 | parent.decl_ref_mut, |
| 28092 | ), |
| 28093 | |
| 28094 | else => unreachable, |
| 28095 | } |
| 28096 | }, |
| 27844 | 28097 | else => unreachable, |
| 27845 | | }, |
| 27846 | | else => unreachable, |
| 27847 | | } |
| 27848 | | }, |
| 27849 | | else => { |
| 27850 | | if (elem_ptr.index != 0) { |
| 27851 | | // TODO include a "declared here" note for the decl |
| 27852 | | return sema.fail(block, src, "out of bounds comptime store of index {d}", .{ |
| 27853 | | elem_ptr.index, |
| 27854 | | }); |
| 27855 | | } |
| 27856 | | return beginComptimePtrMutationInner( |
| 27857 | | sema, |
| 27858 | | block, |
| 27859 | | src, |
| 27860 | | parent.ty, |
| 27861 | | val_ptr, |
| 27862 | | ptr_elem_ty, |
| 27863 | | parent.decl_ref_mut, |
| 27864 | | ); |
| 27865 | | }, |
| 27866 | | }, |
| 27867 | | .reinterpret => |reinterpret| { |
| 27868 | | if (!elem_ptr.elem_ty.hasWellDefinedLayout(mod)) { |
| 27869 | | // Even though the parent value type has well-defined memory layout, our |
| 27870 | | // pointer type does not. |
| 27871 | | return ComptimePtrMutationKit{ |
| 27872 | | .decl_ref_mut = parent.decl_ref_mut, |
| 27873 | | .pointee = .bad_ptr_ty, |
| 27874 | | .ty = elem_ptr.elem_ty, |
| 27875 | | }; |
| 27876 | | } |
| 28098 | } |
| 28099 | }, |
| 28100 | .empty_struct => { |
| 28101 | const duped = try sema.arena.create(Value); |
| 28102 | duped.* = Value.initTag(.the_only_possible_value); |
| 28103 | return beginComptimePtrMutationInner( |
| 28104 | sema, |
| 28105 | block, |
| 28106 | src, |
| 28107 | parent.ty.structFieldType(field_index, mod), |
| 28108 | duped, |
| 28109 | ptr_elem_ty, |
| 28110 | parent.decl_ref_mut, |
| 28111 | ); |
| 28112 | }, |
| 28113 | .none => switch (val_ptr.tag()) { |
| 28114 | .aggregate => return beginComptimePtrMutationInner( |
| 28115 | sema, |
| 28116 | block, |
| 28117 | src, |
| 28118 | parent.ty.structFieldType(field_index, mod), |
| 28119 | &val_ptr.castTag(.aggregate).?.data[field_index], |
| 28120 | ptr_elem_ty, |
| 28121 | parent.decl_ref_mut, |
| 28122 | ), |
| 28123 | .repeated => { |
| 28124 | const arena = parent.beginArena(sema.mod); |
| 28125 | defer parent.finishArena(sema.mod); |
| 27877 | 28126 | |
| 27878 | | const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty); |
| 27879 | | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 27880 | | return ComptimePtrMutationKit{ |
| 27881 | | .decl_ref_mut = parent.decl_ref_mut, |
| 27882 | | .pointee = .{ .reinterpret = .{ |
| 27883 | | .val_ptr = reinterpret.val_ptr, |
| 27884 | | .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index, |
| 27885 | | } }, |
| 27886 | | .ty = parent.ty, |
| 27887 | | }; |
| 27888 | | }, |
| 27889 | | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 27890 | | } |
| 27891 | | }, |
| 27892 | | .field_ptr => { |
| 27893 | | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 27894 | | const field_index = @intCast(u32, field_ptr.field_index); |
| 27895 | | |
| 27896 | | var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 27897 | | switch (parent.pointee) { |
| 27898 | | .direct => |val_ptr| switch (val_ptr.ip_index) { |
| 27899 | | .undef => { |
| 27900 | | // A struct or union has been initialized to undefined at comptime and now we |
| 27901 | | // are for the first time setting a field. We must change the representation |
| 27902 | | // of the struct/union from `undef` to `struct`/`union`. |
| 27903 | | const arena = parent.beginArena(sema.mod); |
| 27904 | | defer parent.finishArena(sema.mod); |
| 27905 | | |
| 27906 | | switch (parent.ty.zigTypeTag(mod)) { |
| 27907 | | .Struct => { |
| 27908 | | const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 27909 | | @memset(fields, Value.undef); |
| 27910 | | |
| 27911 | | val_ptr.* = try Value.Tag.aggregate.create(arena, fields); |
| 28127 | const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 28128 | @memset(elems, val_ptr.castTag(.repeated).?.data); |
| 28129 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 27912 | 28130 | |
| 27913 | 28131 | return beginComptimePtrMutationInner( |
| 27914 | 28132 | sema, |
| 27915 | 28133 | block, |
| 27916 | 28134 | src, |
| 27917 | 28135 | parent.ty.structFieldType(field_index, mod), |
| 27918 | | &fields[field_index], |
| 28136 | &elems[field_index], |
| 27919 | 28137 | ptr_elem_ty, |
| 27920 | 28138 | parent.decl_ref_mut, |
| 27921 | 28139 | ); |
| 27922 | 28140 | }, |
| 27923 | | .Union => { |
| 27924 | | const payload = try arena.create(Value.Payload.Union); |
| 27925 | | const tag_ty = parent.ty.unionTagTypeHypothetical(mod); |
| 27926 | | payload.* = .{ .data = .{ |
| 27927 | | .tag = try mod.enumValueFieldIndex(tag_ty, field_index), |
| 27928 | | .val = Value.undef, |
| 27929 | | } }; |
| 28141 | .@"union" => { |
| 28142 | // We need to set the active field of the union. |
| 28143 | const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod); |
| 27930 | 28144 | |
| 27931 | | val_ptr.* = Value.initPayload(&payload.base); |
| 28145 | const payload = &val_ptr.castTag(.@"union").?.data; |
| 28146 | payload.tag = try mod.enumValueFieldIndex(union_tag_ty, field_index); |
| 27932 | 28147 | |
| 27933 | 28148 | return beginComptimePtrMutationInner( |
| 27934 | 28149 | sema, |
| 27935 | 28150 | block, |
| 27936 | 28151 | src, |
| 27937 | 28152 | parent.ty.structFieldType(field_index, mod), |
| 27938 | | &payload.data.val, |
| 28153 | &payload.val, |
| 27939 | 28154 | ptr_elem_ty, |
| 27940 | 28155 | parent.decl_ref_mut, |
| 27941 | 28156 | ); |
| 27942 | 28157 | }, |
| 27943 | | .Pointer => { |
| 27944 | | assert(parent.ty.isSlice(mod)); |
| 27945 | | val_ptr.* = try Value.Tag.slice.create(arena, .{ |
| 27946 | | .ptr = Value.undef, |
| 27947 | | .len = Value.undef, |
| 27948 | | }); |
| 28158 | .slice => switch (field_index) { |
| 28159 | Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner( |
| 28160 | sema, |
| 28161 | block, |
| 28162 | src, |
| 28163 | parent.ty.slicePtrFieldType(mod), |
| 28164 | &val_ptr.castTag(.slice).?.data.ptr, |
| 28165 | ptr_elem_ty, |
| 28166 | parent.decl_ref_mut, |
| 28167 | ), |
| 27949 | 28168 | |
| 27950 | | switch (field_index) { |
| 27951 | | Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner( |
| 27952 | | sema, |
| 27953 | | block, |
| 27954 | | src, |
| 27955 | | parent.ty.slicePtrFieldType(mod), |
| 27956 | | &val_ptr.castTag(.slice).?.data.ptr, |
| 27957 | | ptr_elem_ty, |
| 27958 | | parent.decl_ref_mut, |
| 27959 | | ), |
| 27960 | | Value.Payload.Slice.len_index => return beginComptimePtrMutationInner( |
| 27961 | | sema, |
| 27962 | | block, |
| 27963 | | src, |
| 27964 | | Type.usize, |
| 27965 | | &val_ptr.castTag(.slice).?.data.len, |
| 27966 | | ptr_elem_ty, |
| 27967 | | parent.decl_ref_mut, |
| 27968 | | ), |
| 28169 | Value.Payload.Slice.len_index => return beginComptimePtrMutationInner( |
| 28170 | sema, |
| 28171 | block, |
| 28172 | src, |
| 28173 | Type.usize, |
| 28174 | &val_ptr.castTag(.slice).?.data.len, |
| 28175 | ptr_elem_ty, |
| 28176 | parent.decl_ref_mut, |
| 28177 | ), |
| 27969 | 28178 | |
| 27970 | | else => unreachable, |
| 27971 | | } |
| 28179 | else => unreachable, |
| 27972 | 28180 | }, |
| 27973 | | else => unreachable, |
| 27974 | | } |
| 27975 | | }, |
| 27976 | | .empty_struct => { |
| 27977 | | const duped = try sema.arena.create(Value); |
| 27978 | | duped.* = Value.initTag(.the_only_possible_value); |
| 27979 | | return beginComptimePtrMutationInner( |
| 27980 | | sema, |
| 27981 | | block, |
| 27982 | | src, |
| 27983 | | parent.ty.structFieldType(field_index, mod), |
| 27984 | | duped, |
| 27985 | | ptr_elem_ty, |
| 27986 | | parent.decl_ref_mut, |
| 27987 | | ); |
| 27988 | | }, |
| 27989 | | .none => switch (val_ptr.tag()) { |
| 27990 | | .aggregate => return beginComptimePtrMutationInner( |
| 27991 | | sema, |
| 27992 | | block, |
| 27993 | | src, |
| 27994 | | parent.ty.structFieldType(field_index, mod), |
| 27995 | | &val_ptr.castTag(.aggregate).?.data[field_index], |
| 27996 | | ptr_elem_ty, |
| 27997 | | parent.decl_ref_mut, |
| 27998 | | ), |
| 27999 | | .repeated => { |
| 28000 | | const arena = parent.beginArena(sema.mod); |
| 28001 | | defer parent.finishArena(sema.mod); |
| 28002 | | |
| 28003 | | const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 28004 | | @memset(elems, val_ptr.castTag(.repeated).?.data); |
| 28005 | | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 28006 | | |
| 28007 | | return beginComptimePtrMutationInner( |
| 28008 | | sema, |
| 28009 | | block, |
| 28010 | | src, |
| 28011 | | parent.ty.structFieldType(field_index, mod), |
| 28012 | | &elems[field_index], |
| 28013 | | ptr_elem_ty, |
| 28014 | | parent.decl_ref_mut, |
| 28015 | | ); |
| 28016 | | }, |
| 28017 | | .@"union" => { |
| 28018 | | // We need to set the active field of the union. |
| 28019 | | const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod); |
| 28020 | | |
| 28021 | | const payload = &val_ptr.castTag(.@"union").?.data; |
| 28022 | | payload.tag = try mod.enumValueFieldIndex(union_tag_ty, field_index); |
| 28023 | | |
| 28024 | | return beginComptimePtrMutationInner( |
| 28025 | | sema, |
| 28026 | | block, |
| 28027 | | src, |
| 28028 | | parent.ty.structFieldType(field_index, mod), |
| 28029 | | &payload.val, |
| 28030 | | ptr_elem_ty, |
| 28031 | | parent.decl_ref_mut, |
| 28032 | | ); |
| 28033 | | }, |
| 28034 | | .slice => switch (field_index) { |
| 28035 | | Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner( |
| 28036 | | sema, |
| 28037 | | block, |
| 28038 | | src, |
| 28039 | | parent.ty.slicePtrFieldType(mod), |
| 28040 | | &val_ptr.castTag(.slice).?.data.ptr, |
| 28041 | | ptr_elem_ty, |
| 28042 | | parent.decl_ref_mut, |
| 28043 | | ), |
| 28044 | | |
| 28045 | | Value.Payload.Slice.len_index => return beginComptimePtrMutationInner( |
| 28046 | | sema, |
| 28047 | | block, |
| 28048 | | src, |
| 28049 | | Type.usize, |
| 28050 | | &val_ptr.castTag(.slice).?.data.len, |
| 28051 | | ptr_elem_ty, |
| 28052 | | parent.decl_ref_mut, |
| 28053 | | ), |
| 28054 | 28181 | |
| 28055 | 28182 | else => unreachable, |
| 28056 | 28183 | }, |
| 28057 | | |
| 28058 | 28184 | else => unreachable, |
| 28059 | 28185 | }, |
| 28060 | | else => unreachable, |
| 28061 | | }, |
| 28062 | | .reinterpret => |reinterpret| { |
| 28063 | | const field_offset_u64 = field_ptr.container_ty.structFieldOffset(field_index, mod); |
| 28064 | | const field_offset = try sema.usizeCast(block, src, field_offset_u64); |
| 28065 | | return ComptimePtrMutationKit{ |
| 28066 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28067 | | .pointee = .{ .reinterpret = .{ |
| 28068 | | .val_ptr = reinterpret.val_ptr, |
| 28069 | | .byte_offset = reinterpret.byte_offset + field_offset, |
| 28070 | | } }, |
| 28071 | | .ty = parent.ty, |
| 28072 | | }; |
| 28073 | | }, |
| 28074 | | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28075 | | } |
| 28076 | | }, |
| 28077 | | .eu_payload_ptr => { |
| 28078 | | const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data; |
| 28079 | | var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty); |
| 28080 | | switch (parent.pointee) { |
| 28081 | | .direct => |val_ptr| { |
| 28082 | | const payload_ty = parent.ty.errorUnionPayload(mod); |
| 28083 | | if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) { |
| 28084 | | return ComptimePtrMutationKit{ |
| 28085 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28086 | | .pointee = .{ .direct = &val_ptr.castTag(.eu_payload).?.data }, |
| 28087 | | .ty = payload_ty, |
| 28088 | | }; |
| 28089 | | } else { |
| 28090 | | // An error union has been initialized to undefined at comptime and now we |
| 28091 | | // are for the first time setting the payload. We must change the |
| 28092 | | // representation of the error union from `undef` to `opt_payload`. |
| 28093 | | const arena = parent.beginArena(sema.mod); |
| 28094 | | defer parent.finishArena(sema.mod); |
| 28095 | | |
| 28096 | | const payload = try arena.create(Value.Payload.SubValue); |
| 28097 | | payload.* = .{ |
| 28098 | | .base = .{ .tag = .eu_payload }, |
| 28099 | | .data = Value.undef, |
| 28100 | | }; |
| 28101 | | |
| 28102 | | val_ptr.* = Value.initPayload(&payload.base); |
| 28103 | | |
| 28186 | .reinterpret => |reinterpret| { |
| 28187 | const field_offset_u64 = field_ptr.container_ty.structFieldOffset(field_index, mod); |
| 28188 | const field_offset = try sema.usizeCast(block, src, field_offset_u64); |
| 28104 | 28189 | return ComptimePtrMutationKit{ |
| 28105 | 28190 | .decl_ref_mut = parent.decl_ref_mut, |
| 28106 | | .pointee = .{ .direct = &payload.data }, |
| 28107 | | .ty = payload_ty, |
| 28191 | .pointee = .{ .reinterpret = .{ |
| 28192 | .val_ptr = reinterpret.val_ptr, |
| 28193 | .byte_offset = reinterpret.byte_offset + field_offset, |
| 28194 | } }, |
| 28195 | .ty = parent.ty, |
| 28108 | 28196 | }; |
| 28109 | | } |
| 28110 | | }, |
| 28111 | | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28112 | | // Even though the parent value type has well-defined memory layout, our |
| 28113 | | // pointer type does not. |
| 28114 | | .reinterpret => return ComptimePtrMutationKit{ |
| 28115 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28116 | | .pointee = .bad_ptr_ty, |
| 28117 | | .ty = eu_ptr.container_ty, |
| 28118 | | }, |
| 28119 | | } |
| 28120 | | }, |
| 28121 | | .opt_payload_ptr => { |
| 28122 | | const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else { |
| 28123 | | return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod)); |
| 28124 | | }; |
| 28125 | | var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty); |
| 28126 | | switch (parent.pointee) { |
| 28127 | | .direct => |val_ptr| { |
| 28128 | | const payload_ty = parent.ty.optionalChild(mod); |
| 28129 | | switch (val_ptr.ip_index) { |
| 28130 | | .undef, .null_value => { |
| 28131 | | // An optional has been initialized to undefined at comptime and now we |
| 28197 | }, |
| 28198 | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28199 | } |
| 28200 | }, |
| 28201 | .eu_payload_ptr => { |
| 28202 | const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data; |
| 28203 | var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty); |
| 28204 | switch (parent.pointee) { |
| 28205 | .direct => |val_ptr| { |
| 28206 | const payload_ty = parent.ty.errorUnionPayload(mod); |
| 28207 | if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) { |
| 28208 | return ComptimePtrMutationKit{ |
| 28209 | .decl_ref_mut = parent.decl_ref_mut, |
| 28210 | .pointee = .{ .direct = &val_ptr.castTag(.eu_payload).?.data }, |
| 28211 | .ty = payload_ty, |
| 28212 | }; |
| 28213 | } else { |
| 28214 | // An error union has been initialized to undefined at comptime and now we |
| 28132 | 28215 | // are for the first time setting the payload. We must change the |
| 28133 | | // representation of the optional from `undef` to `opt_payload`. |
| 28216 | // representation of the error union from `undef` to `opt_payload`. |
| 28134 | 28217 | const arena = parent.beginArena(sema.mod); |
| 28135 | 28218 | defer parent.finishArena(sema.mod); |
| 28136 | 28219 | |
| 28137 | 28220 | const payload = try arena.create(Value.Payload.SubValue); |
| 28138 | 28221 | payload.* = .{ |
| 28139 | | .base = .{ .tag = .opt_payload }, |
| 28222 | .base = .{ .tag = .eu_payload }, |
| 28140 | 28223 | .data = Value.undef, |
| 28141 | 28224 | }; |
| 28142 | 28225 | |
| ... | ... | @@ -28147,39 +28230,84 @@ fn beginComptimePtrMutation( |
| 28147 | 28230 | .pointee = .{ .direct = &payload.data }, |
| 28148 | 28231 | .ty = payload_ty, |
| 28149 | 28232 | }; |
| 28150 | | }, |
| 28151 | | .none => switch (val_ptr.tag()) { |
| 28152 | | .opt_payload => return ComptimePtrMutationKit{ |
| 28153 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28154 | | .pointee = .{ .direct = &val_ptr.castTag(.opt_payload).?.data }, |
| 28155 | | .ty = payload_ty, |
| 28233 | } |
| 28234 | }, |
| 28235 | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28236 | // Even though the parent value type has well-defined memory layout, our |
| 28237 | // pointer type does not. |
| 28238 | .reinterpret => return ComptimePtrMutationKit{ |
| 28239 | .decl_ref_mut = parent.decl_ref_mut, |
| 28240 | .pointee = .bad_ptr_ty, |
| 28241 | .ty = eu_ptr.container_ty, |
| 28242 | }, |
| 28243 | } |
| 28244 | }, |
| 28245 | .opt_payload_ptr => { |
| 28246 | const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else { |
| 28247 | return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod)); |
| 28248 | }; |
| 28249 | var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty); |
| 28250 | switch (parent.pointee) { |
| 28251 | .direct => |val_ptr| { |
| 28252 | const payload_ty = parent.ty.optionalChild(mod); |
| 28253 | switch (val_ptr.toIntern()) { |
| 28254 | .undef, .null_value => { |
| 28255 | // An optional has been initialized to undefined at comptime and now we |
| 28256 | // are for the first time setting the payload. We must change the |
| 28257 | // representation of the optional from `undef` to `opt_payload`. |
| 28258 | const arena = parent.beginArena(sema.mod); |
| 28259 | defer parent.finishArena(sema.mod); |
| 28260 | |
| 28261 | const payload = try arena.create(Value.Payload.SubValue); |
| 28262 | payload.* = .{ |
| 28263 | .base = .{ .tag = .opt_payload }, |
| 28264 | .data = Value.undef, |
| 28265 | }; |
| 28266 | |
| 28267 | val_ptr.* = Value.initPayload(&payload.base); |
| 28268 | |
| 28269 | return ComptimePtrMutationKit{ |
| 28270 | .decl_ref_mut = parent.decl_ref_mut, |
| 28271 | .pointee = .{ .direct = &payload.data }, |
| 28272 | .ty = payload_ty, |
| 28273 | }; |
| 28156 | 28274 | }, |
| 28275 | .none => switch (val_ptr.tag()) { |
| 28276 | .opt_payload => return ComptimePtrMutationKit{ |
| 28277 | .decl_ref_mut = parent.decl_ref_mut, |
| 28278 | .pointee = .{ .direct = &val_ptr.castTag(.opt_payload).?.data }, |
| 28279 | .ty = payload_ty, |
| 28280 | }, |
| 28157 | 28281 | |
| 28282 | else => return ComptimePtrMutationKit{ |
| 28283 | .decl_ref_mut = parent.decl_ref_mut, |
| 28284 | .pointee = .{ .direct = val_ptr }, |
| 28285 | .ty = payload_ty, |
| 28286 | }, |
| 28287 | }, |
| 28158 | 28288 | else => return ComptimePtrMutationKit{ |
| 28159 | 28289 | .decl_ref_mut = parent.decl_ref_mut, |
| 28160 | 28290 | .pointee = .{ .direct = val_ptr }, |
| 28161 | 28291 | .ty = payload_ty, |
| 28162 | 28292 | }, |
| 28163 | | }, |
| 28164 | | else => return ComptimePtrMutationKit{ |
| 28165 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28166 | | .pointee = .{ .direct = val_ptr }, |
| 28167 | | .ty = payload_ty, |
| 28168 | | }, |
| 28169 | | } |
| 28170 | | }, |
| 28171 | | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28172 | | // Even though the parent value type has well-defined memory layout, our |
| 28173 | | // pointer type does not. |
| 28174 | | .reinterpret => return ComptimePtrMutationKit{ |
| 28175 | | .decl_ref_mut = parent.decl_ref_mut, |
| 28176 | | .pointee = .bad_ptr_ty, |
| 28177 | | .ty = opt_ptr.container_ty, |
| 28178 | | }, |
| 28179 | | } |
| 28293 | } |
| 28294 | }, |
| 28295 | .bad_decl_ty, .bad_ptr_ty => return parent, |
| 28296 | // Even though the parent value type has well-defined memory layout, our |
| 28297 | // pointer type does not. |
| 28298 | .reinterpret => return ComptimePtrMutationKit{ |
| 28299 | .decl_ref_mut = parent.decl_ref_mut, |
| 28300 | .pointee = .bad_ptr_ty, |
| 28301 | .ty = opt_ptr.container_ty, |
| 28302 | }, |
| 28303 | } |
| 28304 | }, |
| 28305 | .decl_ref => unreachable, // isComptimeMutablePtr has been checked already |
| 28306 | else => unreachable, |
| 28307 | }, |
| 28308 | else => switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr) { |
| 28309 | else => unreachable, |
| 28180 | 28310 | }, |
| 28181 | | .decl_ref => unreachable, // isComptimeMutablePtr has been checked already |
| 28182 | | else => unreachable, |
| 28183 | 28311 | } |
| 28184 | 28312 | } |
| 28185 | 28313 | |
| ... | ... | @@ -28190,13 +28318,13 @@ fn beginComptimePtrMutationInner( |
| 28190 | 28318 | decl_ty: Type, |
| 28191 | 28319 | decl_val: *Value, |
| 28192 | 28320 | ptr_elem_ty: Type, |
| 28193 | | decl_ref_mut: Value.Payload.DeclRefMut.Data, |
| 28321 | mut_decl: InternPool.Key.Ptr.Addr.MutDecl, |
| 28194 | 28322 | ) CompileError!ComptimePtrMutationKit { |
| 28195 | 28323 | const mod = sema.mod; |
| 28196 | 28324 | const target = mod.getTarget(); |
| 28197 | 28325 | const coerce_ok = (try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_ty, true, target, src, src)) == .ok; |
| 28198 | 28326 | |
| 28199 | | const decl = mod.declPtr(decl_ref_mut.decl_index); |
| 28327 | const decl = mod.declPtr(mut_decl.decl); |
| 28200 | 28328 | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 28201 | 28329 | const allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena); |
| 28202 | 28330 | defer decl.value_arena.?.release(&decl_arena); |
| ... | ... | @@ -28204,7 +28332,7 @@ fn beginComptimePtrMutationInner( |
| 28204 | 28332 | |
| 28205 | 28333 | if (coerce_ok) { |
| 28206 | 28334 | return ComptimePtrMutationKit{ |
| 28207 | | .decl_ref_mut = decl_ref_mut, |
| 28335 | .mut_decl = mut_decl, |
| 28208 | 28336 | .pointee = .{ .direct = decl_val }, |
| 28209 | 28337 | .ty = decl_ty, |
| 28210 | 28338 | }; |
| ... | ... | @@ -28215,7 +28343,7 @@ fn beginComptimePtrMutationInner( |
| 28215 | 28343 | const decl_elem_ty = decl_ty.childType(mod); |
| 28216 | 28344 | if ((try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_elem_ty, true, target, src, src)) == .ok) { |
| 28217 | 28345 | return ComptimePtrMutationKit{ |
| 28218 | | .decl_ref_mut = decl_ref_mut, |
| 28346 | .mut_decl = mut_decl, |
| 28219 | 28347 | .pointee = .{ .direct = decl_val }, |
| 28220 | 28348 | .ty = decl_ty, |
| 28221 | 28349 | }; |
| ... | ... | @@ -28224,20 +28352,20 @@ fn beginComptimePtrMutationInner( |
| 28224 | 28352 | |
| 28225 | 28353 | if (!decl_ty.hasWellDefinedLayout(mod)) { |
| 28226 | 28354 | return ComptimePtrMutationKit{ |
| 28227 | | .decl_ref_mut = decl_ref_mut, |
| 28228 | | .pointee = .{ .bad_decl_ty = {} }, |
| 28355 | .mut_decl = mut_decl, |
| 28356 | .pointee = .bad_decl_ty, |
| 28229 | 28357 | .ty = decl_ty, |
| 28230 | 28358 | }; |
| 28231 | 28359 | } |
| 28232 | 28360 | if (!ptr_elem_ty.hasWellDefinedLayout(mod)) { |
| 28233 | 28361 | return ComptimePtrMutationKit{ |
| 28234 | | .decl_ref_mut = decl_ref_mut, |
| 28235 | | .pointee = .{ .bad_ptr_ty = {} }, |
| 28362 | .mut_decl = mut_decl, |
| 28363 | .pointee = .bad_ptr_ty, |
| 28236 | 28364 | .ty = ptr_elem_ty, |
| 28237 | 28365 | }; |
| 28238 | 28366 | } |
| 28239 | 28367 | return ComptimePtrMutationKit{ |
| 28240 | | .decl_ref_mut = decl_ref_mut, |
| 28368 | .mut_decl = mut_decl, |
| 28241 | 28369 | .pointee = .{ .reinterpret = .{ |
| 28242 | 28370 | .val_ptr = decl_val, |
| 28243 | 28371 | .byte_offset = 0, |
| ... | ... | @@ -28282,7 +28410,7 @@ fn beginComptimePtrLoad( |
| 28282 | 28410 | const mod = sema.mod; |
| 28283 | 28411 | const target = mod.getTarget(); |
| 28284 | 28412 | |
| 28285 | | var deref: ComptimePtrLoadKit = switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) { |
| 28413 | var deref: ComptimePtrLoadKit = switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 28286 | 28414 | .ptr => |ptr| switch (ptr.addr) { |
| 28287 | 28415 | .decl, .mut_decl => blk: { |
| 28288 | 28416 | const decl_index = switch (ptr.addr) { |
| ... | ... | @@ -28319,7 +28447,7 @@ fn beginComptimePtrLoad( |
| 28319 | 28447 | (try sema.coerceInMemoryAllowed(block, container_ty, tv.ty, false, target, src, src)) == .ok or |
| 28320 | 28448 | (try sema.coerceInMemoryAllowed(block, tv.ty, container_ty, false, target, src, src)) == .ok; |
| 28321 | 28449 | if (coerce_in_mem_ok) { |
| 28322 | | const payload_val = switch (mod.intern_pool.indexToKey(tv.val.ip_index)) { |
| 28450 | const payload_val = switch (mod.intern_pool.indexToKey(tv.val.toIntern())) { |
| 28323 | 28451 | .error_union => |error_union| switch (error_union.val) { |
| 28324 | 28452 | .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}), |
| 28325 | 28453 | .payload => |payload| payload, |
| ... | ... | @@ -28462,7 +28590,7 @@ fn beginComptimePtrLoad( |
| 28462 | 28590 | }, |
| 28463 | 28591 | Value.slice_len_index => TypedValue{ |
| 28464 | 28592 | .ty = Type.usize, |
| 28465 | | .val = mod.intern_pool.indexToKey(tv.val.ip_index).ptr.len.toValue(), |
| 28593 | .val = mod.intern_pool.indexToKey(tv.val.toIntern()).ptr.len.toValue(), |
| 28466 | 28594 | }, |
| 28467 | 28595 | else => unreachable, |
| 28468 | 28596 | }; |
| ... | ... | @@ -28565,9 +28693,9 @@ fn coerceArrayPtrToSlice( |
| 28565 | 28693 | const ptr_array_ty = sema.typeOf(inst); |
| 28566 | 28694 | const array_ty = ptr_array_ty.childType(mod); |
| 28567 | 28695 | const slice_val = try mod.intern(.{ .ptr = .{ |
| 28568 | | .ty = dest_ty.ip_index, |
| 28569 | | .addr = mod.intern_pool.indexToKey(val.ip_index).ptr.addr, |
| 28570 | | .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).ip_index, |
| 28696 | .ty = dest_ty.toIntern(), |
| 28697 | .addr = mod.intern_pool.indexToKey(val.toIntern()).ptr.addr, |
| 28698 | .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(), |
| 28571 | 28699 | } }); |
| 28572 | 28700 | return sema.addConstant(dest_ty, slice_val.toValue()); |
| 28573 | 28701 | } |
| ... | ... | @@ -28643,7 +28771,7 @@ fn coerceCompatiblePtrs( |
| 28643 | 28771 | return sema.addConstant(dest_ty, (try mod.intern_pool.getCoerced( |
| 28644 | 28772 | sema.gpa, |
| 28645 | 28773 | try val.intern(inst_ty, mod), |
| 28646 | | dest_ty.ip_index, |
| 28774 | dest_ty.toIntern(), |
| 28647 | 28775 | )).toValue()); |
| 28648 | 28776 | } |
| 28649 | 28777 | try sema.requireRuntimeBlock(block, inst_src, null); |
| ... | ... | @@ -28840,7 +28968,7 @@ fn coerceAnonStructToUnion( |
| 28840 | 28968 | return sema.failWithOwnedErrorMsg(msg); |
| 28841 | 28969 | } |
| 28842 | 28970 | |
| 28843 | | const anon_struct = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type; |
| 28971 | const anon_struct = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type; |
| 28844 | 28972 | const field_name = mod.intern_pool.stringToSlice(anon_struct.names[0]); |
| 28845 | 28973 | const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty); |
| 28846 | 28974 | return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src); |
| ... | ... | @@ -28916,23 +29044,20 @@ fn coerceArrayLike( |
| 28916 | 29044 | return block.addBitCast(dest_ty, inst); |
| 28917 | 29045 | } |
| 28918 | 29046 | |
| 28919 | | const element_vals = try sema.arena.alloc(Value, dest_len); |
| 29047 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_len); |
| 28920 | 29048 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); |
| 28921 | 29049 | var runtime_src: ?LazySrcLoc = null; |
| 28922 | 29050 | |
| 28923 | | for (element_vals, 0..) |*elem, i| { |
| 28924 | | const index_ref = try sema.addConstant( |
| 28925 | | Type.usize, |
| 28926 | | try mod.intValue(Type.usize, i), |
| 28927 | | ); |
| 29051 | for (element_vals, element_refs, 0..) |*val, *ref, i| { |
| 29052 | const index_ref = try sema.addConstant(Type.usize, try mod.intValue(Type.usize, i)); |
| 28928 | 29053 | const src = inst_src; // TODO better source location |
| 28929 | 29054 | const elem_src = inst_src; // TODO better source location |
| 28930 | 29055 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true); |
| 28931 | 29056 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 28932 | | element_refs[i] = coerced; |
| 29057 | ref.* = coerced; |
| 28933 | 29058 | if (runtime_src == null) { |
| 28934 | 29059 | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 28935 | | elem.* = elem_val; |
| 29060 | val.* = try elem_val.intern(dest_elem_ty, mod); |
| 28936 | 29061 | } else { |
| 28937 | 29062 | runtime_src = elem_src; |
| 28938 | 29063 | } |
| ... | ... | @@ -28944,10 +29069,10 @@ fn coerceArrayLike( |
| 28944 | 29069 | return block.addAggregateInit(dest_ty, element_refs); |
| 28945 | 29070 | } |
| 28946 | 29071 | |
| 28947 | | return sema.addConstant( |
| 28948 | | dest_ty, |
| 28949 | | try Value.Tag.aggregate.create(sema.arena, element_vals), |
| 28950 | | ); |
| 29072 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ |
| 29073 | .ty = dest_ty.toIntern(), |
| 29074 | .storage = .{ .elems = element_vals }, |
| 29075 | } })).toValue()); |
| 28951 | 29076 | } |
| 28952 | 29077 | |
| 28953 | 29078 | /// If the lengths match, coerces element-wise. |
| ... | ... | @@ -28978,25 +29103,26 @@ fn coerceTupleToArray( |
| 28978 | 29103 | } |
| 28979 | 29104 | |
| 28980 | 29105 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(mod)); |
| 28981 | | const element_vals = try sema.arena.alloc(Value, dest_elems); |
| 29106 | const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems); |
| 28982 | 29107 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems); |
| 28983 | 29108 | const dest_elem_ty = dest_ty.childType(mod); |
| 28984 | 29109 | |
| 28985 | 29110 | var runtime_src: ?LazySrcLoc = null; |
| 28986 | | for (element_vals, 0..) |*elem, i_usize| { |
| 29111 | for (element_vals, element_refs, 0..) |*val, *ref, i_usize| { |
| 28987 | 29112 | const i = @intCast(u32, i_usize); |
| 28988 | 29113 | if (i_usize == inst_len) { |
| 28989 | | elem.* = dest_ty.sentinel(mod).?; |
| 28990 | | element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*); |
| 29114 | const sentinel_val = dest_ty.sentinel(mod).?; |
| 29115 | val.* = sentinel_val.toIntern(); |
| 29116 | ref.* = try sema.addConstant(dest_elem_ty, sentinel_val); |
| 28991 | 29117 | break; |
| 28992 | 29118 | } |
| 28993 | 29119 | const elem_src = inst_src; // TODO better source location |
| 28994 | 29120 | const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i); |
| 28995 | 29121 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 28996 | | element_refs[i] = coerced; |
| 29122 | ref.* = coerced; |
| 28997 | 29123 | if (runtime_src == null) { |
| 28998 | 29124 | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 28999 | | elem.* = elem_val; |
| 29125 | val.* = try elem_val.intern(dest_elem_ty, mod); |
| 29000 | 29126 | } else { |
| 29001 | 29127 | runtime_src = elem_src; |
| 29002 | 29128 | } |
| ... | ... | @@ -29008,10 +29134,10 @@ fn coerceTupleToArray( |
| 29008 | 29134 | return block.addAggregateInit(dest_ty, element_refs); |
| 29009 | 29135 | } |
| 29010 | 29136 | |
| 29011 | | return sema.addConstant( |
| 29012 | | dest_ty, |
| 29013 | | try Value.Tag.aggregate.create(sema.arena, element_vals), |
| 29014 | | ); |
| 29137 | return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{ |
| 29138 | .ty = dest_ty.toIntern(), |
| 29139 | .storage = .{ .elems = element_vals }, |
| 29140 | } })).toValue()); |
| 29015 | 29141 | } |
| 29016 | 29142 | |
| 29017 | 29143 | /// If the lengths match, coerces element-wise. |
| ... | ... | @@ -29079,7 +29205,7 @@ fn coerceTupleToStruct( |
| 29079 | 29205 | @memset(field_refs, .none); |
| 29080 | 29206 | |
| 29081 | 29207 | const inst_ty = sema.typeOf(inst); |
| 29082 | | const anon_struct = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type; |
| 29208 | const anon_struct = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type; |
| 29083 | 29209 | var runtime_src: ?LazySrcLoc = null; |
| 29084 | 29210 | for (0..anon_struct.types.len) |field_index_usize| { |
| 29085 | 29211 | const field_i = @intCast(u32, field_index_usize); |
| ... | ... | @@ -29105,8 +29231,7 @@ fn coerceTupleToStruct( |
| 29105 | 29231 | } |
| 29106 | 29232 | if (runtime_src == null) { |
| 29107 | 29233 | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 29108 | | assert(field_val.ip_index != .none); |
| 29109 | | field_vals[field_index] = field_val.ip_index; |
| 29234 | field_vals[field_index] = field_val.toIntern(); |
| 29110 | 29235 | } else { |
| 29111 | 29236 | runtime_src = field_src; |
| 29112 | 29237 | } |
| ... | ... | @@ -29123,7 +29248,7 @@ fn coerceTupleToStruct( |
| 29123 | 29248 | const field_name = fields.keys()[i]; |
| 29124 | 29249 | const field = fields.values()[i]; |
| 29125 | 29250 | const field_src = inst_src; // TODO better source location |
| 29126 | | if (field.default_val.ip_index == .unreachable_value) { |
| 29251 | if (field.default_val.toIntern() == .unreachable_value) { |
| 29127 | 29252 | const template = "missing struct field: {s}"; |
| 29128 | 29253 | const args = .{field_name}; |
| 29129 | 29254 | if (root_msg) |msg| { |
| ... | ... | @@ -29134,8 +29259,7 @@ fn coerceTupleToStruct( |
| 29134 | 29259 | continue; |
| 29135 | 29260 | } |
| 29136 | 29261 | if (runtime_src == null) { |
| 29137 | | assert(field.default_val.ip_index != .none); |
| 29138 | | field_vals[i] = field.default_val.ip_index; |
| 29262 | field_vals[i] = field.default_val.toIntern(); |
| 29139 | 29263 | } else { |
| 29140 | 29264 | field_ref.* = try sema.addConstant(field.ty, field.default_val); |
| 29141 | 29265 | } |
| ... | ... | @@ -29152,9 +29276,8 @@ fn coerceTupleToStruct( |
| 29152 | 29276 | return block.addAggregateInit(struct_ty, field_refs); |
| 29153 | 29277 | } |
| 29154 | 29278 | |
| 29155 | | assert(struct_ty.ip_index != .none); |
| 29156 | 29279 | const struct_val = try mod.intern(.{ .aggregate = .{ |
| 29157 | | .ty = struct_ty.ip_index, |
| 29280 | .ty = struct_ty.toIntern(), |
| 29158 | 29281 | .storage = .{ .elems = field_vals }, |
| 29159 | 29282 | } }); |
| 29160 | 29283 | errdefer mod.intern_pool.remove(struct_val); |
| ... | ... | @@ -29170,13 +29293,13 @@ fn coerceTupleToTuple( |
| 29170 | 29293 | inst_src: LazySrcLoc, |
| 29171 | 29294 | ) !Air.Inst.Ref { |
| 29172 | 29295 | const mod = sema.mod; |
| 29173 | | const dest_tuple = mod.intern_pool.indexToKey(tuple_ty.ip_index).anon_struct_type; |
| 29296 | const dest_tuple = mod.intern_pool.indexToKey(tuple_ty.toIntern()).anon_struct_type; |
| 29174 | 29297 | const field_vals = try sema.arena.alloc(InternPool.Index, dest_tuple.types.len); |
| 29175 | 29298 | const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len); |
| 29176 | 29299 | @memset(field_refs, .none); |
| 29177 | 29300 | |
| 29178 | 29301 | const inst_ty = sema.typeOf(inst); |
| 29179 | | const src_tuple = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type; |
| 29302 | const src_tuple = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type; |
| 29180 | 29303 | if (src_tuple.types.len > dest_tuple.types.len) return error.NotCoercible; |
| 29181 | 29304 | |
| 29182 | 29305 | var runtime_src: ?LazySrcLoc = null; |
| ... | ... | @@ -29209,7 +29332,7 @@ fn coerceTupleToTuple( |
| 29209 | 29332 | } |
| 29210 | 29333 | if (runtime_src == null) { |
| 29211 | 29334 | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 29212 | | field_vals[field_index] = field_val.ip_index; |
| 29335 | field_vals[field_index] = field_val.toIntern(); |
| 29213 | 29336 | } else { |
| 29214 | 29337 | runtime_src = field_src; |
| 29215 | 29338 | } |
| ... | ... | @@ -29269,7 +29392,7 @@ fn coerceTupleToTuple( |
| 29269 | 29392 | return sema.addConstant( |
| 29270 | 29393 | tuple_ty, |
| 29271 | 29394 | (try mod.intern(.{ .aggregate = .{ |
| 29272 | | .ty = tuple_ty.ip_index, |
| 29395 | .ty = tuple_ty.toIntern(), |
| 29273 | 29396 | .storage = .{ .elems = field_vals }, |
| 29274 | 29397 | } })).toValue(), |
| 29275 | 29398 | ); |
| ... | ... | @@ -29349,7 +29472,7 @@ fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value { |
| 29349 | 29472 | try sema.maybeQueueFuncBodyAnalysis(decl); |
| 29350 | 29473 | try mod.declareDeclDependency(sema.owner_decl_index, decl); |
| 29351 | 29474 | const result = try mod.intern(.{ .ptr = .{ |
| 29352 | | .ty = (try mod.singleConstPtrType(ty)).ip_index, |
| 29475 | .ty = (try mod.singleConstPtrType(ty)).toIntern(), |
| 29353 | 29476 | .addr = .{ .decl = decl }, |
| 29354 | 29477 | } }); |
| 29355 | 29478 | return result.toValue(); |
| ... | ... | @@ -29360,8 +29483,8 @@ fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value { |
| 29360 | 29483 | const val = opt_val orelse return Value.null; |
| 29361 | 29484 | const ptr_val = try sema.refValue(block, ty, val); |
| 29362 | 29485 | const result = try mod.intern(.{ .opt = .{ |
| 29363 | | .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).ip_index)).ip_index, |
| 29364 | | .val = ptr_val.ip_index, |
| 29486 | .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).toIntern())).toIntern(), |
| 29487 | .val = ptr_val.toIntern(), |
| 29365 | 29488 | } }); |
| 29366 | 29489 | return result.toValue(); |
| 29367 | 29490 | } |
| ... | ... | @@ -29382,7 +29505,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo |
| 29382 | 29505 | const decl = mod.declPtr(decl_index); |
| 29383 | 29506 | const decl_tv = try decl.typedValue(); |
| 29384 | 29507 | const ptr_ty = try mod.ptrType(.{ |
| 29385 | | .elem_type = decl_tv.ty.ip_index, |
| 29508 | .elem_type = decl_tv.ty.toIntern(), |
| 29386 | 29509 | .alignment = InternPool.Alignment.fromByteUnits(decl.@"align"), |
| 29387 | 29510 | .is_const = if (decl.getVariable(mod)) |variable| variable.is_const else false, |
| 29388 | 29511 | .address_space = decl.@"addrspace", |
| ... | ... | @@ -29391,7 +29514,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo |
| 29391 | 29514 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| 29392 | 29515 | } |
| 29393 | 29516 | return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{ |
| 29394 | | .ty = ptr_ty.ip_index, |
| 29517 | .ty = ptr_ty.toIntern(), |
| 29395 | 29518 | .addr = .{ .decl = decl_index }, |
| 29396 | 29519 | } })).toValue()); |
| 29397 | 29520 | } |
| ... | ... | @@ -29415,13 +29538,10 @@ fn analyzeRef( |
| 29415 | 29538 | const operand_ty = sema.typeOf(operand); |
| 29416 | 29539 | |
| 29417 | 29540 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 29418 | | switch (val.ip_index) { |
| 29419 | | .none => {}, |
| 29420 | | else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) { |
| 29421 | | .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl), |
| 29422 | | .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl), |
| 29423 | | else => {}, |
| 29424 | | }, |
| 29541 | switch (sema.mod.intern_pool.indexToKey(val.toIntern())) { |
| 29542 | .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl), |
| 29543 | .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl), |
| 29544 | else => {}, |
| 29425 | 29545 | } |
| 29426 | 29546 | var anon_decl = try block.startAnonDecl(); |
| 29427 | 29547 | defer anon_decl.deinit(); |
| ... | ... | @@ -29617,9 +29737,9 @@ fn analyzeIsNonErrComptimeOnly( |
| 29617 | 29737 | // exception if the error union error set is known to be empty, |
| 29618 | 29738 | // we allow the comparison but always make it comptime-known. |
| 29619 | 29739 | const set_ty = operand_ty.errorUnionSet(mod); |
| 29620 | | switch (set_ty.ip_index) { |
| 29740 | switch (set_ty.toIntern()) { |
| 29621 | 29741 | .anyerror_type => {}, |
| 29622 | | else => switch (mod.intern_pool.indexToKey(set_ty.ip_index)) { |
| 29742 | else => switch (mod.intern_pool.indexToKey(set_ty.toIntern())) { |
| 29623 | 29743 | .error_set_type => |error_set_type| { |
| 29624 | 29744 | if (error_set_type.names.len == 0) return Air.Inst.Ref.bool_true; |
| 29625 | 29745 | }, |
| ... | ... | @@ -30027,7 +30147,7 @@ fn analyzeSlice( |
| 30027 | 30147 | return sema.addConstant(return_ty, (try mod.intern_pool.getCoerced( |
| 30028 | 30148 | sema.gpa, |
| 30029 | 30149 | try new_ptr_val.intern(new_ptr_ty, mod), |
| 30030 | | return_ty.ip_index, |
| 30150 | return_ty.toIntern(), |
| 30031 | 30151 | )).toValue()); |
| 30032 | 30152 | } |
| 30033 | 30153 | |
| ... | ... | @@ -30546,8 +30666,8 @@ fn wrapOptional( |
| 30546 | 30666 | ) !Air.Inst.Ref { |
| 30547 | 30667 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 30548 | 30668 | return sema.addConstant(dest_ty, (try sema.mod.intern(.{ .opt = .{ |
| 30549 | | .ty = dest_ty.ip_index, |
| 30550 | | .val = val.ip_index, |
| 30669 | .ty = dest_ty.toIntern(), |
| 30670 | .val = val.toIntern(), |
| 30551 | 30671 | } })).toValue()); |
| 30552 | 30672 | } |
| 30553 | 30673 | |
| ... | ... | @@ -30567,8 +30687,8 @@ fn wrapErrorUnionPayload( |
| 30567 | 30687 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 30568 | 30688 | if (try sema.resolveMaybeUndefVal(coerced)) |val| { |
| 30569 | 30689 | return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{ |
| 30570 | | .ty = dest_ty.ip_index, |
| 30571 | | .val = .{ .payload = val.ip_index }, |
| 30690 | .ty = dest_ty.toIntern(), |
| 30691 | .val = .{ .payload = val.toIntern() }, |
| 30572 | 30692 | } })).toValue()); |
| 30573 | 30693 | } |
| 30574 | 30694 | try sema.requireRuntimeBlock(block, inst_src, null); |
| ... | ... | @@ -30588,17 +30708,17 @@ fn wrapErrorUnionSet( |
| 30588 | 30708 | const inst_ty = sema.typeOf(inst); |
| 30589 | 30709 | const dest_err_set_ty = dest_ty.errorUnionSet(mod); |
| 30590 | 30710 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 30591 | | switch (dest_err_set_ty.ip_index) { |
| 30711 | switch (dest_err_set_ty.toIntern()) { |
| 30592 | 30712 | .anyerror_type => {}, |
| 30593 | | else => switch (ip.indexToKey(dest_err_set_ty.ip_index)) { |
| 30713 | else => switch (ip.indexToKey(dest_err_set_ty.toIntern())) { |
| 30594 | 30714 | .error_set_type => |error_set_type| ok: { |
| 30595 | | const expected_name = mod.intern_pool.indexToKey(val.ip_index).err.name; |
| 30715 | const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 30596 | 30716 | if (error_set_type.nameIndex(ip, expected_name) != null) break :ok; |
| 30597 | 30717 | return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty); |
| 30598 | 30718 | }, |
| 30599 | 30719 | .inferred_error_set_type => |ies_index| ok: { |
| 30600 | 30720 | const ies = mod.inferredErrorSetPtr(ies_index); |
| 30601 | | const expected_name = mod.intern_pool.indexToKey(val.ip_index).err.name; |
| 30721 | const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 30602 | 30722 | |
| 30603 | 30723 | // We carefully do this in an order that avoids unnecessarily |
| 30604 | 30724 | // resolving the destination error set type. |
| ... | ... | @@ -31252,34 +31372,31 @@ pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileErro |
| 31252 | 31372 | /// Make it so that calling hash() and eql() on `val` will not assert due |
| 31253 | 31373 | /// to a type not having its layout resolved. |
| 31254 | 31374 | fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void { |
| 31255 | | switch (val.ip_index) { |
| 31256 | | .none => {}, |
| 31257 | | else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) { |
| 31258 | | .int => |int| switch (int.storage) { |
| 31259 | | .u64, .i64, .big_int => {}, |
| 31260 | | .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()), |
| 31261 | | }, |
| 31262 | | .ptr => |ptr| { |
| 31263 | | switch (ptr.addr) { |
| 31264 | | .decl, .mut_decl => {}, |
| 31265 | | .int => |int| try sema.resolveLazyValue(int.toValue()), |
| 31266 | | .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()), |
| 31267 | | .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()), |
| 31268 | | .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()), |
| 31269 | | } |
| 31270 | | if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue()); |
| 31271 | | }, |
| 31272 | | .aggregate => |aggregate| switch (aggregate.storage) { |
| 31273 | | .bytes => {}, |
| 31274 | | .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()), |
| 31275 | | .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()), |
| 31276 | | }, |
| 31277 | | .un => |un| { |
| 31278 | | try sema.resolveLazyValue(un.tag.toValue()); |
| 31279 | | try sema.resolveLazyValue(un.val.toValue()); |
| 31280 | | }, |
| 31281 | | else => {}, |
| 31375 | switch (sema.mod.intern_pool.indexToKey(val.toIntern())) { |
| 31376 | .int => |int| switch (int.storage) { |
| 31377 | .u64, .i64, .big_int => {}, |
| 31378 | .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()), |
| 31379 | }, |
| 31380 | .ptr => |ptr| { |
| 31381 | switch (ptr.addr) { |
| 31382 | .decl, .mut_decl => {}, |
| 31383 | .int => |int| try sema.resolveLazyValue(int.toValue()), |
| 31384 | .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()), |
| 31385 | .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()), |
| 31386 | .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()), |
| 31387 | } |
| 31388 | if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue()); |
| 31389 | }, |
| 31390 | .aggregate => |aggregate| switch (aggregate.storage) { |
| 31391 | .bytes => {}, |
| 31392 | .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()), |
| 31393 | .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()), |
| 31282 | 31394 | }, |
| 31395 | .un => |un| { |
| 31396 | try sema.resolveLazyValue(un.tag.toValue()); |
| 31397 | try sema.resolveLazyValue(un.val.toValue()); |
| 31398 | }, |
| 31399 | else => {}, |
| 31283 | 31400 | } |
| 31284 | 31401 | } |
| 31285 | 31402 | |
| ... | ... | @@ -31617,9 +31734,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 31617 | 31734 | pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31618 | 31735 | const mod = sema.mod; |
| 31619 | 31736 | |
| 31620 | | return switch (ty.ip_index) { |
| 31737 | return switch (ty.toIntern()) { |
| 31621 | 31738 | .empty_struct_type => false, |
| 31622 | | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 31739 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 31623 | 31740 | .int_type => false, |
| 31624 | 31741 | .ptr_type => |ptr_type| { |
| 31625 | 31742 | const child_ty = ptr_type.elem_type.toType(); |
| ... | ... | @@ -31776,7 +31893,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { |
| 31776 | 31893 | const child_ty = try sema.resolveTypeFields(ty.childType(mod)); |
| 31777 | 31894 | return sema.resolveTypeFully(child_ty); |
| 31778 | 31895 | }, |
| 31779 | | .Struct => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 31896 | .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 31780 | 31897 | .struct_type => return sema.resolveStructFully(ty), |
| 31781 | 31898 | .anon_struct_type => |tuple| { |
| 31782 | 31899 | for (tuple.types) |field_ty| { |
| ... | ... | @@ -31869,7 +31986,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void { |
| 31869 | 31986 | pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 31870 | 31987 | const mod = sema.mod; |
| 31871 | 31988 | |
| 31872 | | switch (ty.ip_index) { |
| 31989 | switch (ty.toIntern()) { |
| 31873 | 31990 | .var_args_param_type => unreachable, |
| 31874 | 31991 | |
| 31875 | 31992 | .none => unreachable, |
| ... | ... | @@ -31960,7 +32077,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 31960 | 32077 | .call_modifier_type => return sema.getBuiltinType("CallModifier"), |
| 31961 | 32078 | .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"), |
| 31962 | 32079 | |
| 31963 | | _ => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 32080 | _ => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 31964 | 32081 | .struct_type => |struct_type| { |
| 31965 | 32082 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty; |
| 31966 | 32083 | try sema.resolveTypeFieldsStruct(ty, struct_obj); |
| ... | ... | @@ -32605,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32605 | 32722 | } else { |
| 32606 | 32723 | // The provided type is the enum tag type. |
| 32607 | 32724 | union_obj.tag_ty = provided_ty; |
| 32608 | | const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.ip_index)) { |
| 32725 | const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.toIntern())) { |
| 32609 | 32726 | .enum_type => |x| x, |
| 32610 | 32727 | else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}), |
| 32611 | 32728 | }; |
| ... | ... | @@ -32698,7 +32815,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32698 | 32815 | |
| 32699 | 32816 | break :blk val; |
| 32700 | 32817 | }; |
| 32701 | | enum_field_vals[field_i] = copied_val.ip_index; |
| 32818 | enum_field_vals[field_i] = copied_val.toIntern(); |
| 32702 | 32819 | const gop = enum_field_vals_map.getOrPutAssumeCapacityContext(copied_val, .{ |
| 32703 | 32820 | .ty = int_tag_ty, |
| 32704 | 32821 | .mod = mod, |
| ... | ... | @@ -32960,7 +33077,7 @@ fn generateUnionTagTypeSimple( |
| 32960 | 33077 | .tag_ty = if (enum_field_names.len == 0) |
| 32961 | 33078 | .noreturn_type |
| 32962 | 33079 | else |
| 32963 | | (try mod.smallestUnsignedInt(enum_field_names.len - 1)).ip_index, |
| 33080 | (try mod.smallestUnsignedInt(enum_field_names.len - 1)).toIntern(), |
| 32964 | 33081 | .names = enum_field_names, |
| 32965 | 33082 | .values = &.{}, |
| 32966 | 33083 | .tag_mode = .auto, |
| ... | ... | @@ -33053,9 +33170,9 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 33053 | 33170 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 33054 | 33171 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33055 | 33172 | const mod = sema.mod; |
| 33056 | | return switch (ty.ip_index) { |
| 33173 | return switch (ty.toIntern()) { |
| 33057 | 33174 | .empty_struct_type => Value.empty_struct, |
| 33058 | | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 33175 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 33059 | 33176 | .int_type => |int_type| { |
| 33060 | 33177 | if (int_type.bits == 0) { |
| 33061 | 33178 | return try mod.intValue(ty, 0); |
| ... | ... | @@ -33074,13 +33191,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33074 | 33191 | |
| 33075 | 33192 | inline .array_type, .vector_type => |seq_type| { |
| 33076 | 33193 | if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{ |
| 33077 | | .ty = ty.ip_index, |
| 33194 | .ty = ty.toIntern(), |
| 33078 | 33195 | .storage = .{ .elems = &.{} }, |
| 33079 | 33196 | } })).toValue(); |
| 33080 | 33197 | if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| { |
| 33081 | 33198 | return (try mod.intern(.{ .aggregate = .{ |
| 33082 | | .ty = ty.ip_index, |
| 33083 | | .storage = .{ .repeated_elem = opv.ip_index }, |
| 33199 | .ty = ty.toIntern(), |
| 33200 | .storage = .{ .repeated_elem = opv.toIntern() }, |
| 33084 | 33201 | } })).toValue(); |
| 33085 | 33202 | } |
| 33086 | 33203 | return null; |
| ... | ... | @@ -33169,7 +33286,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33169 | 33286 | // This TODO is repeated in the redundant implementation of |
| 33170 | 33287 | // one-possible-value in type.zig. |
| 33171 | 33288 | const empty = try mod.intern(.{ .aggregate = .{ |
| 33172 | | .ty = ty.ip_index, |
| 33289 | .ty = ty.toIntern(), |
| 33173 | 33290 | .storage = .{ .elems = &.{} }, |
| 33174 | 33291 | } }); |
| 33175 | 33292 | return empty.toValue(); |
| ... | ... | @@ -33182,7 +33299,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33182 | 33299 | // In this case the struct has all comptime-known fields and |
| 33183 | 33300 | // therefore has one possible value. |
| 33184 | 33301 | return (try mod.intern(.{ .aggregate = .{ |
| 33185 | | .ty = ty.ip_index, |
| 33302 | .ty = ty.toIntern(), |
| 33186 | 33303 | .storage = .{ .elems = tuple.values }, |
| 33187 | 33304 | } })).toValue(); |
| 33188 | 33305 | }, |
| ... | ... | @@ -33208,9 +33325,9 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33208 | 33325 | const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse |
| 33209 | 33326 | return null; |
| 33210 | 33327 | const only = try mod.intern(.{ .un = .{ |
| 33211 | | .ty = resolved_ty.ip_index, |
| 33212 | | .tag = tag_val.ip_index, |
| 33213 | | .val = val_val.ip_index, |
| 33328 | .ty = resolved_ty.toIntern(), |
| 33329 | .tag = tag_val.toIntern(), |
| 33330 | .val = val_val.toIntern(), |
| 33214 | 33331 | } }); |
| 33215 | 33332 | return only.toValue(); |
| 33216 | 33333 | }, |
| ... | ... | @@ -33221,8 +33338,8 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33221 | 33338 | |
| 33222 | 33339 | if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| { |
| 33223 | 33340 | const only = try mod.intern(.{ .enum_tag = .{ |
| 33224 | | .ty = ty.ip_index, |
| 33225 | | .int = int_opv.ip_index, |
| 33341 | .ty = ty.toIntern(), |
| 33342 | .int = int_opv.toIntern(), |
| 33226 | 33343 | } }); |
| 33227 | 33344 | return only.toValue(); |
| 33228 | 33345 | } |
| ... | ... | @@ -33234,7 +33351,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33234 | 33351 | 1 => { |
| 33235 | 33352 | if (enum_type.values.len == 0) { |
| 33236 | 33353 | const only = try mod.intern(.{ .enum_tag = .{ |
| 33237 | | .ty = ty.ip_index, |
| 33354 | .ty = ty.toIntern(), |
| 33238 | 33355 | .int = try mod.intern(.{ .int = .{ |
| 33239 | 33356 | .ty = enum_type.tag_ty, |
| 33240 | 33357 | .storage = .{ .u64 = 0 }, |
| ... | ... | @@ -33285,21 +33402,13 @@ pub fn getTmpAir(sema: Sema) Air { |
| 33285 | 33402 | } |
| 33286 | 33403 | |
| 33287 | 33404 | pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |
| 33288 | | if (ty.ip_index != .none) { |
| 33289 | | if (@enumToInt(ty.ip_index) < Air.ref_start_index) |
| 33290 | | return @intToEnum(Air.Inst.Ref, @enumToInt(ty.ip_index)); |
| 33291 | | try sema.air_instructions.append(sema.gpa, .{ |
| 33292 | | .tag = .interned, |
| 33293 | | .data = .{ .interned = ty.ip_index }, |
| 33294 | | }); |
| 33295 | | return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 33296 | | } else { |
| 33297 | | try sema.air_instructions.append(sema.gpa, .{ |
| 33298 | | .tag = .const_ty, |
| 33299 | | .data = .{ .ty = ty }, |
| 33300 | | }); |
| 33301 | | return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 33302 | | } |
| 33405 | if (@enumToInt(ty.toIntern()) < Air.ref_start_index) |
| 33406 | return @intToEnum(Air.Inst.Ref, @enumToInt(ty.toIntern())); |
| 33407 | try sema.air_instructions.append(sema.gpa, .{ |
| 33408 | .tag = .interned, |
| 33409 | .data = .{ .interned = ty.toIntern() }, |
| 33410 | }); |
| 33411 | return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 33303 | 33412 | } |
| 33304 | 33413 | |
| 33305 | 33414 | fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -33313,12 +33422,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref { |
| 33313 | 33422 | |
| 33314 | 33423 | pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref { |
| 33315 | 33424 | const gpa = sema.gpa; |
| 33316 | | if (val.ip_index != .none and val.ip_index != .null_value) { |
| 33317 | | if (@enumToInt(val.ip_index) < Air.ref_start_index) |
| 33318 | | return @intToEnum(Air.Inst.Ref, @enumToInt(val.ip_index)); |
| 33425 | if (val.ip_index != .none) { |
| 33426 | if (@enumToInt(val.toIntern()) < Air.ref_start_index) |
| 33427 | return @intToEnum(Air.Inst.Ref, @enumToInt(val.toIntern())); |
| 33319 | 33428 | try sema.air_instructions.append(gpa, .{ |
| 33320 | 33429 | .tag = .interned, |
| 33321 | | .data = .{ .interned = val.ip_index }, |
| 33430 | .data = .{ .interned = val.toIntern() }, |
| 33322 | 33431 | }); |
| 33323 | 33432 | const result = Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 33324 | 33433 | // This assertion can be removed when the `ty` parameter is removed from |
| ... | ... | @@ -33417,7 +33526,7 @@ fn analyzeComptimeAlloc( |
| 33417 | 33526 | |
| 33418 | 33527 | try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 33419 | 33528 | return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{ |
| 33420 | | .ty = ptr_type.ip_index, |
| 33529 | .ty = ptr_type.toIntern(), |
| 33421 | 33530 | .addr = .{ .mut_decl = .{ |
| 33422 | 33531 | .decl = decl_index, |
| 33423 | 33532 | .runtime_index = block.runtime_index, |
| ... | ... | @@ -33589,7 +33698,7 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError |
| 33589 | 33698 | /// This logic must be kept in sync with `Type.isPtrLikeOptional`. |
| 33590 | 33699 | fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type { |
| 33591 | 33700 | const mod = sema.mod; |
| 33592 | | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 33701 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 33593 | 33702 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 33594 | 33703 | .Slice => null, |
| 33595 | 33704 | .C => ptr_type.elem_type.toType(), |
| ... | ... | @@ -33624,10 +33733,10 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type { |
| 33624 | 33733 | /// elsewhere in value.zig |
| 33625 | 33734 | pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 33626 | 33735 | const mod = sema.mod; |
| 33627 | | return switch (ty.ip_index) { |
| 33736 | return switch (ty.toIntern()) { |
| 33628 | 33737 | .empty_struct_type => false, |
| 33629 | 33738 | |
| 33630 | | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 33739 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 33631 | 33740 | .int_type => return false, |
| 33632 | 33741 | .ptr_type => |ptr_type| { |
| 33633 | 33742 | const child_ty = ptr_type.elem_type.toType(); |
| ... | ... | @@ -33873,7 +33982,7 @@ fn anonStructFieldIndex( |
| 33873 | 33982 | field_src: LazySrcLoc, |
| 33874 | 33983 | ) !u32 { |
| 33875 | 33984 | const mod = sema.mod; |
| 33876 | | const anon_struct = mod.intern_pool.indexToKey(struct_ty.ip_index).anon_struct_type; |
| 33985 | const anon_struct = mod.intern_pool.indexToKey(struct_ty.toIntern()).anon_struct_type; |
| 33877 | 33986 | for (anon_struct.names, 0..) |name, i| { |
| 33878 | 33987 | if (mem.eql(u8, mod.intern_pool.stringToSlice(name), field_name)) { |
| 33879 | 33988 | return @intCast(u32, i); |
| ... | ... | @@ -33891,14 +34000,17 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { |
| 33891 | 34000 | fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value { |
| 33892 | 34001 | const mod = sema.mod; |
| 33893 | 34002 | if (ty.zigTypeTag(mod) == .Vector) { |
| 33894 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34003 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); |
| 33895 | 34004 | const scalar_ty = ty.scalarType(mod); |
| 33896 | 34005 | for (result_data, 0..) |*scalar, i| { |
| 33897 | 34006 | const lhs_elem = try lhs.elemValue(mod, i); |
| 33898 | 34007 | const rhs_elem = try rhs.elemValue(mod, i); |
| 33899 | | scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem, scalar_ty); |
| 34008 | scalar.* = try (try sema.intAddScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod); |
| 33900 | 34009 | } |
| 33901 | | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 34010 | return (try mod.intern(.{ .aggregate = .{ |
| 34011 | .ty = ty.toIntern(), |
| 34012 | .storage = .{ .elems = result_data }, |
| 34013 | } })).toValue(); |
| 33902 | 34014 | } |
| 33903 | 34015 | return sema.intAddScalar(lhs, rhs, ty); |
| 33904 | 34016 | } |
| ... | ... | @@ -33945,14 +34057,17 @@ fn numberAddWrapScalar( |
| 33945 | 34057 | fn intSub(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value { |
| 33946 | 34058 | const mod = sema.mod; |
| 33947 | 34059 | if (ty.zigTypeTag(mod) == .Vector) { |
| 33948 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34060 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); |
| 33949 | 34061 | const scalar_ty = ty.scalarType(mod); |
| 33950 | 34062 | for (result_data, 0..) |*scalar, i| { |
| 33951 | 34063 | const lhs_elem = try lhs.elemValue(sema.mod, i); |
| 33952 | 34064 | const rhs_elem = try rhs.elemValue(sema.mod, i); |
| 33953 | | scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem, scalar_ty); |
| 34065 | scalar.* = try (try sema.intSubScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod); |
| 33954 | 34066 | } |
| 33955 | | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 34067 | return (try mod.intern(.{ .aggregate = .{ |
| 34068 | .ty = ty.toIntern(), |
| 34069 | .storage = .{ .elems = result_data }, |
| 34070 | } })).toValue(); |
| 33956 | 34071 | } |
| 33957 | 34072 | return sema.intSubScalar(lhs, rhs, ty); |
| 33958 | 34073 | } |
| ... | ... | @@ -34004,18 +34119,26 @@ fn intSubWithOverflow( |
| 34004 | 34119 | ) !Value.OverflowArithmeticResult { |
| 34005 | 34120 | const mod = sema.mod; |
| 34006 | 34121 | if (ty.zigTypeTag(mod) == .Vector) { |
| 34007 | | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34008 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34009 | | for (result_data, 0..) |*scalar, i| { |
| 34122 | const vec_len = ty.vectorLen(mod); |
| 34123 | const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len); |
| 34124 | const result_data = try sema.arena.alloc(InternPool.Index, vec_len); |
| 34125 | const scalar_ty = ty.scalarType(mod); |
| 34126 | for (overflowed_data, result_data, 0..) |*of, *scalar, i| { |
| 34010 | 34127 | const lhs_elem = try lhs.elemValue(sema.mod, i); |
| 34011 | 34128 | const rhs_elem = try rhs.elemValue(sema.mod, i); |
| 34012 | | const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod)); |
| 34013 | | overflowed_data[i] = of_math_result.overflow_bit; |
| 34014 | | scalar.* = of_math_result.wrapped_result; |
| 34129 | const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty); |
| 34130 | of.* = try of_math_result.overflow_bit.intern(Type.bool, mod); |
| 34131 | scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod); |
| 34015 | 34132 | } |
| 34016 | 34133 | return Value.OverflowArithmeticResult{ |
| 34017 | | .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data), |
| 34018 | | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 34134 | .overflow_bit = (try mod.intern(.{ .aggregate = .{ |
| 34135 | .ty = ty.toIntern(), |
| 34136 | .storage = .{ .elems = overflowed_data }, |
| 34137 | } })).toValue(), |
| 34138 | .wrapped_result = (try mod.intern(.{ .aggregate = .{ |
| 34139 | .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(), |
| 34140 | .storage = .{ .elems = result_data }, |
| 34141 | } })).toValue(), |
| 34019 | 34142 | }; |
| 34020 | 34143 | } |
| 34021 | 34144 | return sema.intSubWithOverflowScalar(lhs, rhs, ty); |
| ... | ... | @@ -34057,13 +34180,17 @@ fn floatToInt( |
| 34057 | 34180 | ) CompileError!Value { |
| 34058 | 34181 | const mod = sema.mod; |
| 34059 | 34182 | if (float_ty.zigTypeTag(mod) == .Vector) { |
| 34060 | | const elem_ty = float_ty.childType(mod); |
| 34061 | | const result_data = try sema.arena.alloc(Value, float_ty.vectorLen(mod)); |
| 34183 | const elem_ty = float_ty.scalarType(mod); |
| 34184 | const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(mod)); |
| 34185 | const scalar_ty = int_ty.scalarType(mod); |
| 34062 | 34186 | for (result_data, 0..) |*scalar, i| { |
| 34063 | 34187 | const elem_val = try val.elemValue(sema.mod, i); |
| 34064 | | scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod)); |
| 34188 | scalar.* = try (try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod))).intern(scalar_ty, mod); |
| 34065 | 34189 | } |
| 34066 | | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 34190 | return (try mod.intern(.{ .aggregate = .{ |
| 34191 | .ty = int_ty.toIntern(), |
| 34192 | .storage = .{ .elems = result_data }, |
| 34193 | } })).toValue(); |
| 34067 | 34194 | } |
| 34068 | 34195 | return sema.floatToIntScalar(block, src, val, float_ty, int_ty); |
| 34069 | 34196 | } |
| ... | ... | @@ -34139,16 +34266,16 @@ fn intFitsInType( |
| 34139 | 34266 | vector_index: ?*usize, |
| 34140 | 34267 | ) CompileError!bool { |
| 34141 | 34268 | const mod = sema.mod; |
| 34142 | | if (ty.ip_index == .comptime_int_type) return true; |
| 34269 | if (ty.toIntern() == .comptime_int_type) return true; |
| 34143 | 34270 | const info = ty.intInfo(mod); |
| 34144 | | switch (val.ip_index) { |
| 34271 | switch (val.toIntern()) { |
| 34145 | 34272 | .undef, |
| 34146 | 34273 | .zero, |
| 34147 | 34274 | .zero_usize, |
| 34148 | 34275 | .zero_u8, |
| 34149 | 34276 | => return true, |
| 34150 | 34277 | |
| 34151 | | else => switch (mod.intern_pool.indexToKey(val.ip_index)) { |
| 34278 | else => switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 34152 | 34279 | .variable, .extern_func, .func, .ptr => { |
| 34153 | 34280 | const target = mod.getTarget(); |
| 34154 | 34281 | const ptr_bits = target.ptrBitWidth(); |
| ... | ... | @@ -34219,12 +34346,12 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool { |
| 34219 | 34346 | /// Asserts the type is an enum. |
| 34220 | 34347 | fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool { |
| 34221 | 34348 | const mod = sema.mod; |
| 34222 | | const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type; |
| 34349 | const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type; |
| 34223 | 34350 | assert(enum_type.tag_mode != .nonexhaustive); |
| 34224 | 34351 | // The `tagValueIndex` function call below relies on the type being the integer tag type. |
| 34225 | 34352 | // `getCoerced` assumes the value will fit the new type. |
| 34226 | 34353 | if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false; |
| 34227 | | const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.ip_index, enum_type.tag_ty); |
| 34354 | const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.toIntern(), enum_type.tag_ty); |
| 34228 | 34355 | |
| 34229 | 34356 | return enum_type.tagValueIndex(&mod.intern_pool, int_coerced) != null; |
| 34230 | 34357 | } |
| ... | ... | @@ -34237,18 +34364,26 @@ fn intAddWithOverflow( |
| 34237 | 34364 | ) !Value.OverflowArithmeticResult { |
| 34238 | 34365 | const mod = sema.mod; |
| 34239 | 34366 | if (ty.zigTypeTag(mod) == .Vector) { |
| 34240 | | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34241 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34242 | | for (result_data, 0..) |*scalar, i| { |
| 34367 | const vec_len = ty.vectorLen(mod); |
| 34368 | const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len); |
| 34369 | const result_data = try sema.arena.alloc(InternPool.Index, vec_len); |
| 34370 | const scalar_ty = ty.scalarType(mod); |
| 34371 | for (overflowed_data, result_data, 0..) |*of, *scalar, i| { |
| 34243 | 34372 | const lhs_elem = try lhs.elemValue(sema.mod, i); |
| 34244 | 34373 | const rhs_elem = try rhs.elemValue(sema.mod, i); |
| 34245 | | const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod)); |
| 34246 | | overflowed_data[i] = of_math_result.overflow_bit; |
| 34247 | | scalar.* = of_math_result.wrapped_result; |
| 34374 | const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty); |
| 34375 | of.* = try of_math_result.overflow_bit.intern(Type.bool, mod); |
| 34376 | scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod); |
| 34248 | 34377 | } |
| 34249 | 34378 | return Value.OverflowArithmeticResult{ |
| 34250 | | .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data), |
| 34251 | | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 34379 | .overflow_bit = (try mod.intern(.{ .aggregate = .{ |
| 34380 | .ty = ty.toIntern(), |
| 34381 | .storage = .{ .elems = overflowed_data }, |
| 34382 | } })).toValue(), |
| 34383 | .wrapped_result = (try mod.intern(.{ .aggregate = .{ |
| 34384 | .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(), |
| 34385 | .storage = .{ .elems = result_data }, |
| 34386 | } })).toValue(), |
| 34252 | 34387 | }; |
| 34253 | 34388 | } |
| 34254 | 34389 | return sema.intAddWithOverflowScalar(lhs, rhs, ty); |
| ... | ... | @@ -34340,14 +34475,17 @@ fn compareVector( |
| 34340 | 34475 | ) !Value { |
| 34341 | 34476 | const mod = sema.mod; |
| 34342 | 34477 | assert(ty.zigTypeTag(mod) == .Vector); |
| 34343 | | const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod)); |
| 34478 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); |
| 34344 | 34479 | for (result_data, 0..) |*scalar, i| { |
| 34345 | 34480 | const lhs_elem = try lhs.elemValue(sema.mod, i); |
| 34346 | 34481 | const rhs_elem = try rhs.elemValue(sema.mod, i); |
| 34347 | 34482 | const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod)); |
| 34348 | | scalar.* = Value.makeBool(res_bool); |
| 34483 | scalar.* = try Value.makeBool(res_bool).intern(Type.bool, mod); |
| 34349 | 34484 | } |
| 34350 | | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 34485 | return (try mod.intern(.{ .aggregate = .{ |
| 34486 | .ty = (try mod.vectorType(.{ .len = ty.vectorLen(mod), .child = .u1_type })).toIntern(), |
| 34487 | .storage = .{ .elems = result_data }, |
| 34488 | } })).toValue(); |
| 34351 | 34489 | } |
| 34352 | 34490 | |
| 34353 | 34491 | /// Returns the type of a pointer to an element. |