| ... | ... | @@ -11,9 +11,6 @@ gpa: Allocator, |
| 11 | 11 | /// Points to the temporary arena allocator of the Sema. |
| 12 | 12 | /// This arena will be cleared when the sema is destroyed. |
| 13 | 13 | arena: Allocator, |
| 14 | | /// Points to the arena allocator for the owner_decl. |
| 15 | | /// This arena will persist until the decl is invalidated. |
| 16 | | perm_arena: Allocator, |
| 17 | 14 | code: Zir, |
| 18 | 15 | air_instructions: std.MultiArrayList(Air.Inst) = .{}, |
| 19 | 16 | air_extra: std.ArrayListUnmanaged(u32) = .{}, |
| ... | ... | @@ -740,7 +737,6 @@ pub const Block = struct { |
| 740 | 737 | // TODO: migrate Decl alignment to use `InternPool.Alignment` |
| 741 | 738 | new_decl.@"align" = @intCast(u32, alignment); |
| 742 | 739 | errdefer sema.mod.abortAnonDecl(new_decl_index); |
| 743 | | try new_decl.finalizeNewArena(&wad.new_decl_arena); |
| 744 | 740 | wad.finished = true; |
| 745 | 741 | try sema.mod.finalizeAnonDecl(new_decl_index); |
| 746 | 742 | return new_decl_index; |
| ... | ... | @@ -1825,6 +1821,20 @@ pub fn resolveConstString( |
| 1825 | 1821 | return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod); |
| 1826 | 1822 | } |
| 1827 | 1823 | |
| 1824 | pub fn resolveConstStringIntern( |
| 1825 | sema: *Sema, |
| 1826 | block: *Block, |
| 1827 | src: LazySrcLoc, |
| 1828 | zir_ref: Zir.Inst.Ref, |
| 1829 | reason: []const u8, |
| 1830 | ) !InternPool.NullTerminatedString { |
| 1831 | const air_inst = try sema.resolveInst(zir_ref); |
| 1832 | const wanted_type = Type.slice_const_u8; |
| 1833 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 1834 | const val = try sema.resolveConstValue(block, src, coerced_inst, reason); |
| 1835 | return val.toIpString(wanted_type, sema.mod); |
| 1836 | } |
| 1837 | |
| 1828 | 1838 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 1829 | 1839 | const air_inst = try sema.resolveInst(zir_ref); |
| 1830 | 1840 | assert(air_inst != .var_args_param_type); |
| ... | ... | @@ -1847,11 +1857,13 @@ fn analyzeAsType( |
| 1847 | 1857 | |
| 1848 | 1858 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { |
| 1849 | 1859 | const mod = sema.mod; |
| 1860 | const gpa = sema.gpa; |
| 1861 | const ip = &mod.intern_pool; |
| 1850 | 1862 | if (!mod.backendSupportsFeature(.error_return_trace)) return; |
| 1851 | 1863 | |
| 1852 | 1864 | assert(!block.is_comptime); |
| 1853 | 1865 | var err_trace_block = block.makeSubBlock(); |
| 1854 | | defer err_trace_block.instructions.deinit(sema.gpa); |
| 1866 | defer err_trace_block.instructions.deinit(gpa); |
| 1855 | 1867 | |
| 1856 | 1868 | const src: LazySrcLoc = .unneeded; |
| 1857 | 1869 | |
| ... | ... | @@ -1866,17 +1878,19 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 1866 | 1878 | const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty)); |
| 1867 | 1879 | |
| 1868 | 1880 | // st.instruction_addresses = &addrs; |
| 1869 | | const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, "instruction_addresses", src, true); |
| 1881 | const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses"); |
| 1882 | const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true); |
| 1870 | 1883 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); |
| 1871 | 1884 | |
| 1872 | 1885 | // st.index = 0; |
| 1873 | | const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, "index", src, true); |
| 1886 | const index_field_name = try ip.getOrPutString(gpa, "index"); |
| 1887 | const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true); |
| 1874 | 1888 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); |
| 1875 | 1889 | |
| 1876 | 1890 | // @errorReturnTrace() = &st; |
| 1877 | 1891 | _ = try err_trace_block.addUnOp(.set_err_return_trace, st_ptr); |
| 1878 | 1892 | |
| 1879 | | try block.instructions.insertSlice(sema.gpa, last_arg_index, err_trace_block.instructions.items); |
| 1893 | try block.instructions.insertSlice(gpa, last_arg_index, err_trace_block.instructions.items); |
| 1880 | 1894 | } |
| 1881 | 1895 | |
| 1882 | 1896 | /// May return Value Tags: `variable`, `undef`. |
| ... | ... | @@ -2179,7 +2193,13 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError |
| 2179 | 2193 | return sema.failWithOwnedErrorMsg(msg); |
| 2180 | 2194 | } |
| 2181 | 2195 | |
| 2182 | | fn failWithInvalidFieldAccess(sema: *Sema, block: *Block, src: LazySrcLoc, object_ty: Type, field_name: []const u8) CompileError { |
| 2196 | fn failWithInvalidFieldAccess( |
| 2197 | sema: *Sema, |
| 2198 | block: *Block, |
| 2199 | src: LazySrcLoc, |
| 2200 | object_ty: Type, |
| 2201 | field_name: InternPool.NullTerminatedString, |
| 2202 | ) CompileError { |
| 2183 | 2203 | const mod = sema.mod; |
| 2184 | 2204 | const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType(mod) else object_ty; |
| 2185 | 2205 | |
| ... | ... | @@ -2207,15 +2227,16 @@ fn failWithInvalidFieldAccess(sema: *Sema, block: *Block, src: LazySrcLoc, objec |
| 2207 | 2227 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2208 | 2228 | } |
| 2209 | 2229 | |
| 2210 | | fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: []const u8) bool { |
| 2230 | fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool { |
| 2231 | const ip = &mod.intern_pool; |
| 2211 | 2232 | switch (ty.zigTypeTag(mod)) { |
| 2212 | | .Array => return mem.eql(u8, field_name, "len"), |
| 2233 | .Array => return ip.stringEqlSlice(field_name, "len"), |
| 2213 | 2234 | .Pointer => { |
| 2214 | 2235 | const ptr_info = ty.ptrInfo(mod); |
| 2215 | 2236 | if (ptr_info.size == .Slice) { |
| 2216 | | return mem.eql(u8, field_name, "ptr") or mem.eql(u8, field_name, "len"); |
| 2237 | return ip.stringEqlSlice(field_name, "ptr") or ip.stringEqlSlice(field_name, "len"); |
| 2217 | 2238 | } else if (ptr_info.pointee_type.zigTypeTag(mod) == .Array) { |
| 2218 | | return mem.eql(u8, field_name, "len"); |
| 2239 | return ip.stringEqlSlice(field_name, "len"); |
| 2219 | 2240 | } else return false; |
| 2220 | 2241 | }, |
| 2221 | 2242 | .Type, .Struct, .Union => return true, |
| ... | ... | @@ -2308,19 +2329,19 @@ pub fn fail( |
| 2308 | 2329 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2309 | 2330 | @setCold(true); |
| 2310 | 2331 | const gpa = sema.gpa; |
| 2332 | const mod = sema.mod; |
| 2311 | 2333 | |
| 2312 | | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { |
| 2334 | if (crash_report.is_enabled and mod.comp.debug_compile_errors) { |
| 2313 | 2335 | if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; |
| 2314 | 2336 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 2315 | 2337 | wip_errors.init(gpa) catch unreachable; |
| 2316 | | Compilation.addModuleErrorMsg(&wip_errors, err_msg.*) catch unreachable; |
| 2338 | Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable; |
| 2317 | 2339 | std.debug.print("compile error during Sema:\n", .{}); |
| 2318 | 2340 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; |
| 2319 | 2341 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); |
| 2320 | 2342 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2321 | 2343 | } |
| 2322 | 2344 | |
| 2323 | | const mod = sema.mod; |
| 2324 | 2345 | ref: { |
| 2325 | 2346 | errdefer err_msg.destroy(gpa); |
| 2326 | 2347 | if (err_msg.src_loc.lazy == .unneeded) { |
| ... | ... | @@ -2330,9 +2351,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2330 | 2351 | try mod.failed_files.ensureUnusedCapacity(gpa, 1); |
| 2331 | 2352 | |
| 2332 | 2353 | const max_references = blk: { |
| 2333 | | if (sema.mod.comp.reference_trace) |num| break :blk num; |
| 2354 | if (mod.comp.reference_trace) |num| break :blk num; |
| 2334 | 2355 | // Do not add multiple traces without explicit request. |
| 2335 | | if (sema.mod.failed_decls.count() != 0) break :ref; |
| 2356 | if (mod.failed_decls.count() != 0) break :ref; |
| 2336 | 2357 | break :blk default_reference_trace_len; |
| 2337 | 2358 | }; |
| 2338 | 2359 | |
| ... | ... | @@ -2350,13 +2371,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2350 | 2371 | if (gop.found_existing) break; |
| 2351 | 2372 | if (cur_reference_trace < max_references) { |
| 2352 | 2373 | const decl = sema.mod.declPtr(ref.referencer); |
| 2353 | | try reference_stack.append(.{ .decl = decl.name, .src_loc = ref.src.toSrcLoc(decl, mod) }); |
| 2374 | try reference_stack.append(.{ |
| 2375 | .decl = decl.name.toOptional(), |
| 2376 | .src_loc = ref.src.toSrcLoc(decl, mod), |
| 2377 | }); |
| 2354 | 2378 | } |
| 2355 | 2379 | referenced_by = ref.referencer; |
| 2356 | 2380 | } |
| 2357 | 2381 | if (sema.mod.comp.reference_trace == null and cur_reference_trace > 0) { |
| 2358 | 2382 | try reference_stack.append(.{ |
| 2359 | | .decl = null, |
| 2383 | .decl = .none, |
| 2360 | 2384 | .src_loc = undefined, |
| 2361 | 2385 | .hidden = 0, |
| 2362 | 2386 | }); |
| ... | ... | @@ -2795,7 +2819,6 @@ fn zirStructDecl( |
| 2795 | 2819 | new_namespace.ty = struct_ty.toType(); |
| 2796 | 2820 | |
| 2797 | 2821 | try sema.analyzeStructDecl(new_decl, inst, struct_index); |
| 2798 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2799 | 2822 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 2800 | 2823 | try mod.finalizeAnonDecl(new_decl_index); |
| 2801 | 2824 | return decl_val; |
| ... | ... | @@ -2812,6 +2835,7 @@ fn createAnonymousDeclTypeNamed( |
| 2812 | 2835 | ) !Decl.Index { |
| 2813 | 2836 | const mod = sema.mod; |
| 2814 | 2837 | const gpa = sema.gpa; |
| 2838 | const ip = &mod.intern_pool; |
| 2815 | 2839 | const namespace = block.namespace; |
| 2816 | 2840 | const src_scope = block.wip_capture_scope; |
| 2817 | 2841 | const src_decl = mod.declPtr(block.src_decl); |
| ... | ... | @@ -2827,16 +2851,19 @@ fn createAnonymousDeclTypeNamed( |
| 2827 | 2851 | // semantically analyzed. |
| 2828 | 2852 | // This name is also used as the key in the parent namespace so it cannot be |
| 2829 | 2853 | // renamed. |
| 2830 | | const name = try std.fmt.allocPrintZ(gpa, "{s}__{s}_{d}", .{ |
| 2831 | | src_decl.name, anon_prefix, @enumToInt(new_decl_index), |
| 2832 | | }); |
| 2833 | | errdefer gpa.free(name); |
| 2854 | |
| 2855 | // This ensureUnusedCapacity protects against the src_decl slice from being |
| 2856 | // reallocated during the call to `getOrPutStringFmt`. |
| 2857 | try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(src_decl.name).len + |
| 2858 | anon_prefix.len + 20); |
| 2859 | const name = ip.getOrPutStringFmt(gpa, "{s}__{s}_{d}", .{ |
| 2860 | ip.stringToSlice(src_decl.name), anon_prefix, @enumToInt(new_decl_index), |
| 2861 | }) catch unreachable; |
| 2834 | 2862 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2835 | 2863 | return new_decl_index; |
| 2836 | 2864 | }, |
| 2837 | 2865 | .parent => { |
| 2838 | | const name = try gpa.dupeZ(u8, mem.sliceTo(sema.mod.declPtr(block.src_decl).name, 0)); |
| 2839 | | errdefer gpa.free(name); |
| 2866 | const name = mod.declPtr(block.src_decl).name; |
| 2840 | 2867 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2841 | 2868 | return new_decl_index; |
| 2842 | 2869 | }, |
| ... | ... | @@ -2846,7 +2873,7 @@ fn createAnonymousDeclTypeNamed( |
| 2846 | 2873 | |
| 2847 | 2874 | var buf = std.ArrayList(u8).init(gpa); |
| 2848 | 2875 | defer buf.deinit(); |
| 2849 | | try buf.appendSlice(mem.sliceTo(sema.mod.declPtr(block.src_decl).name, 0)); |
| 2876 | try buf.appendSlice(ip.stringToSlice(mod.declPtr(block.src_decl).name)); |
| 2850 | 2877 | try buf.appendSlice("("); |
| 2851 | 2878 | |
| 2852 | 2879 | var arg_i: usize = 0; |
| ... | ... | @@ -2871,8 +2898,7 @@ fn createAnonymousDeclTypeNamed( |
| 2871 | 2898 | }; |
| 2872 | 2899 | |
| 2873 | 2900 | try buf.appendSlice(")"); |
| 2874 | | const name = try buf.toOwnedSliceSentinel(0); |
| 2875 | | errdefer gpa.free(name); |
| 2901 | const name = try ip.getOrPutString(gpa, buf.items); |
| 2876 | 2902 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2877 | 2903 | return new_decl_index; |
| 2878 | 2904 | }, |
| ... | ... | @@ -2885,10 +2911,17 @@ fn createAnonymousDeclTypeNamed( |
| 2885 | 2911 | .dbg_var_ptr, .dbg_var_val => { |
| 2886 | 2912 | if (zir_data[i].str_op.operand != ref) continue; |
| 2887 | 2913 | |
| 2888 | | const name = try std.fmt.allocPrintZ(gpa, "{s}.{s}", .{ |
| 2889 | | src_decl.name, zir_data[i].str_op.getStr(sema.code), |
| 2890 | | }); |
| 2891 | | errdefer gpa.free(name); |
| 2914 | // This ensureUnusedCapacity protects against the src_decl |
| 2915 | // slice from being reallocated during the call to |
| 2916 | // `getOrPutStringFmt`. |
| 2917 | const zir_str = zir_data[i].str_op.getStr(sema.code); |
| 2918 | try ip.string_bytes.ensureUnusedCapacity( |
| 2919 | gpa, |
| 2920 | ip.stringToSlice(src_decl.name).len + zir_str.len + 10, |
| 2921 | ); |
| 2922 | const name = ip.getOrPutStringFmt(gpa, "{s}.{s}", .{ |
| 2923 | ip.stringToSlice(src_decl.name), zir_str, |
| 2924 | }) catch unreachable; |
| 2892 | 2925 | |
| 2893 | 2926 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2894 | 2927 | return new_decl_index; |
| ... | ... | @@ -3249,7 +3282,6 @@ fn zirUnionDecl( |
| 3249 | 3282 | |
| 3250 | 3283 | _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); |
| 3251 | 3284 | |
| 3252 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 3253 | 3285 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 3254 | 3286 | try mod.finalizeAnonDecl(new_decl_index); |
| 3255 | 3287 | return decl_val; |
| ... | ... | @@ -3315,7 +3347,6 @@ fn zirOpaqueDecl( |
| 3315 | 3347 | |
| 3316 | 3348 | extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); |
| 3317 | 3349 | |
| 3318 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 3319 | 3350 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 3320 | 3351 | try mod.finalizeAnonDecl(new_decl_index); |
| 3321 | 3352 | return decl_val; |
| ... | ... | @@ -3344,8 +3375,8 @@ fn zirErrorSetDecl( |
| 3344 | 3375 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string |
| 3345 | 3376 | const str_index = sema.code.extra[extra_index]; |
| 3346 | 3377 | const name = sema.code.nullTerminatedString(str_index); |
| 3347 | | const kv = try mod.getErrorValue(name); |
| 3348 | | const name_ip = try mod.intern_pool.getOrPutString(gpa, kv.key); |
| 3378 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name); |
| 3379 | _ = try mod.getErrorValue(name_ip); |
| 3349 | 3380 | const result = names.getOrPutAssumeCapacity(name_ip); |
| 3350 | 3381 | assert(!result.found_existing); // verified in AstGen |
| 3351 | 3382 | } |
| ... | ... | @@ -3512,7 +3543,8 @@ fn indexablePtrLen( |
| 3512 | 3543 | const is_pointer_to = object_ty.isSinglePointer(mod); |
| 3513 | 3544 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; |
| 3514 | 3545 | try checkIndexable(sema, block, src, indexable_ty); |
| 3515 | | return sema.fieldVal(block, src, object, "len", src); |
| 3546 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len"); |
| 3547 | return sema.fieldVal(block, src, object, field_name, src); |
| 3516 | 3548 | } |
| 3517 | 3549 | |
| 3518 | 3550 | fn indexablePtrLenOrNone( |
| ... | ... | @@ -3525,7 +3557,8 @@ fn indexablePtrLenOrNone( |
| 3525 | 3557 | const operand_ty = sema.typeOf(operand); |
| 3526 | 3558 | try checkMemOperand(sema, block, src, operand_ty); |
| 3527 | 3559 | if (operand_ty.ptrSize(mod) == .Many) return .none; |
| 3528 | | return sema.fieldVal(block, src, operand, "len", src); |
| 3560 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len"); |
| 3561 | return sema.fieldVal(block, src, operand, field_name, src); |
| 3529 | 3562 | } |
| 3530 | 3563 | |
| 3531 | 3564 | fn zirAllocExtended( |
| ... | ... | @@ -4079,6 +4112,7 @@ fn zirFieldBasePtr( |
| 4079 | 4112 | fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4080 | 4113 | const mod = sema.mod; |
| 4081 | 4114 | const gpa = sema.gpa; |
| 4115 | const ip = &mod.intern_pool; |
| 4082 | 4116 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 4083 | 4117 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 4084 | 4118 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| ... | ... | @@ -4122,7 +4156,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4122 | 4156 | } |
| 4123 | 4157 | if (!object_ty.indexableHasLen(mod)) continue; |
| 4124 | 4158 | |
| 4125 | | break :l try sema.fieldVal(block, arg_src, object, "len", arg_src); |
| 4159 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len"), arg_src); |
| 4126 | 4160 | }; |
| 4127 | 4161 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); |
| 4128 | 4162 | if (len == .none) { |
| ... | ... | @@ -4308,6 +4342,7 @@ fn validateUnionInit( |
| 4308 | 4342 | union_ptr: Air.Inst.Ref, |
| 4309 | 4343 | ) CompileError!void { |
| 4310 | 4344 | const mod = sema.mod; |
| 4345 | const gpa = sema.gpa; |
| 4311 | 4346 | |
| 4312 | 4347 | if (instrs.len != 1) { |
| 4313 | 4348 | const msg = msg: { |
| ... | ... | @@ -4317,7 +4352,7 @@ fn validateUnionInit( |
| 4317 | 4352 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 4318 | 4353 | .{}, |
| 4319 | 4354 | ); |
| 4320 | | errdefer msg.destroy(sema.gpa); |
| 4355 | errdefer msg.destroy(gpa); |
| 4321 | 4356 | |
| 4322 | 4357 | for (instrs[1..]) |inst| { |
| 4323 | 4358 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| ... | ... | @@ -4341,7 +4376,7 @@ fn validateUnionInit( |
| 4341 | 4376 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| 4342 | 4377 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4343 | 4378 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4344 | | const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start); |
| 4379 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start)); |
| 4345 | 4380 | // Validate the field access but ignore the index since we want the tag enum field index. |
| 4346 | 4381 | _ = try sema.unionFieldIndex(block, union_ty, field_name, field_src); |
| 4347 | 4382 | const air_tags = sema.air_instructions.items(.tag); |
| ... | ... | @@ -4444,6 +4479,7 @@ fn validateStructInit( |
| 4444 | 4479 | ) CompileError!void { |
| 4445 | 4480 | const mod = sema.mod; |
| 4446 | 4481 | const gpa = sema.gpa; |
| 4482 | const ip = &mod.intern_pool; |
| 4447 | 4483 | |
| 4448 | 4484 | // Maps field index to field_ptr index of where it was already initialized. |
| 4449 | 4485 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount(mod)); |
| ... | ... | @@ -4457,7 +4493,10 @@ fn validateStructInit( |
| 4457 | 4493 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4458 | 4494 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4459 | 4495 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| 4460 | | const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start); |
| 4496 | const field_name = try ip.getOrPutString( |
| 4497 | gpa, |
| 4498 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), |
| 4499 | ); |
| 4461 | 4500 | const field_index = if (struct_ty.isTuple(mod)) |
| 4462 | 4501 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) |
| 4463 | 4502 | else |
| ... | ... | @@ -4504,7 +4543,7 @@ fn validateStructInit( |
| 4504 | 4543 | } |
| 4505 | 4544 | const field_name = struct_ty.structFieldName(i, mod); |
| 4506 | 4545 | const template = "missing struct field: {s}"; |
| 4507 | | const args = .{field_name}; |
| 4546 | const args = .{ip.stringToSlice(field_name)}; |
| 4508 | 4547 | if (root_msg) |msg| { |
| 4509 | 4548 | try sema.errNote(block, init_src, msg, template, args); |
| 4510 | 4549 | } else { |
| ... | ... | @@ -4525,8 +4564,7 @@ fn validateStructInit( |
| 4525 | 4564 | |
| 4526 | 4565 | if (root_msg) |msg| { |
| 4527 | 4566 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4528 | | const fqn = try struct_obj.getFullyQualifiedName(mod); |
| 4529 | | defer gpa.free(fqn); |
| 4567 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4530 | 4568 | try mod.errNoteNonLazy( |
| 4531 | 4569 | struct_obj.srcLoc(mod), |
| 4532 | 4570 | msg, |
| ... | ... | @@ -4649,7 +4687,7 @@ fn validateStructInit( |
| 4649 | 4687 | } |
| 4650 | 4688 | const field_name = struct_ty.structFieldName(i, mod); |
| 4651 | 4689 | const template = "missing struct field: {s}"; |
| 4652 | | const args = .{field_name}; |
| 4690 | const args = .{ip.stringToSlice(field_name)}; |
| 4653 | 4691 | if (root_msg) |msg| { |
| 4654 | 4692 | try sema.errNote(block, init_src, msg, template, args); |
| 4655 | 4693 | } else { |
| ... | ... | @@ -4662,10 +4700,9 @@ fn validateStructInit( |
| 4662 | 4700 | |
| 4663 | 4701 | if (root_msg) |msg| { |
| 4664 | 4702 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4665 | | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); |
| 4666 | | defer gpa.free(fqn); |
| 4703 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4667 | 4704 | try sema.mod.errNoteNonLazy( |
| 4668 | | struct_obj.srcLoc(sema.mod), |
| 4705 | struct_obj.srcLoc(mod), |
| 4669 | 4706 | msg, |
| 4670 | 4707 | "struct '{s}' declared here", |
| 4671 | 4708 | .{fqn}, |
| ... | ... | @@ -4949,7 +4986,7 @@ fn failWithBadMemberAccess( |
| 4949 | 4986 | block: *Block, |
| 4950 | 4987 | agg_ty: Type, |
| 4951 | 4988 | field_src: LazySrcLoc, |
| 4952 | | field_name: []const u8, |
| 4989 | field_name_nts: InternPool.NullTerminatedString, |
| 4953 | 4990 | ) CompileError { |
| 4954 | 4991 | const mod = sema.mod; |
| 4955 | 4992 | const kw_name = switch (agg_ty.zigTypeTag(mod)) { |
| ... | ... | @@ -4959,6 +4996,7 @@ fn failWithBadMemberAccess( |
| 4959 | 4996 | .Enum => "enum", |
| 4960 | 4997 | else => unreachable, |
| 4961 | 4998 | }; |
| 4999 | const field_name = mod.intern_pool.stringToSlice(field_name_nts); |
| 4962 | 5000 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) { |
| 4963 | 5001 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ |
| 4964 | 5002 | agg_ty.fmt(sema.mod), field_name, |
| ... | ... | @@ -4980,22 +5018,23 @@ fn failWithBadStructFieldAccess( |
| 4980 | 5018 | block: *Block, |
| 4981 | 5019 | struct_obj: *Module.Struct, |
| 4982 | 5020 | field_src: LazySrcLoc, |
| 4983 | | field_name: []const u8, |
| 5021 | field_name: InternPool.NullTerminatedString, |
| 4984 | 5022 | ) CompileError { |
| 5023 | const mod = sema.mod; |
| 4985 | 5024 | const gpa = sema.gpa; |
| 5025 | const ip = &mod.intern_pool; |
| 4986 | 5026 | |
| 4987 | | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); |
| 4988 | | defer gpa.free(fqn); |
| 5027 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4989 | 5028 | |
| 4990 | 5029 | const msg = msg: { |
| 4991 | 5030 | const msg = try sema.errMsg( |
| 4992 | 5031 | block, |
| 4993 | 5032 | field_src, |
| 4994 | 5033 | "no field named '{s}' in struct '{s}'", |
| 4995 | | .{ field_name, fqn }, |
| 5034 | .{ ip.stringToSlice(field_name), fqn }, |
| 4996 | 5035 | ); |
| 4997 | 5036 | errdefer msg.destroy(gpa); |
| 4998 | | try sema.mod.errNoteNonLazy(struct_obj.srcLoc(sema.mod), msg, "struct declared here", .{}); |
| 5037 | try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{}); |
| 4999 | 5038 | break :msg msg; |
| 5000 | 5039 | }; |
| 5001 | 5040 | return sema.failWithOwnedErrorMsg(msg); |
| ... | ... | @@ -5006,22 +5045,23 @@ fn failWithBadUnionFieldAccess( |
| 5006 | 5045 | block: *Block, |
| 5007 | 5046 | union_obj: *Module.Union, |
| 5008 | 5047 | field_src: LazySrcLoc, |
| 5009 | | field_name: []const u8, |
| 5048 | field_name: InternPool.NullTerminatedString, |
| 5010 | 5049 | ) CompileError { |
| 5050 | const mod = sema.mod; |
| 5011 | 5051 | const gpa = sema.gpa; |
| 5052 | const ip = &mod.intern_pool; |
| 5012 | 5053 | |
| 5013 | | const fqn = try union_obj.getFullyQualifiedName(sema.mod); |
| 5014 | | defer gpa.free(fqn); |
| 5054 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 5015 | 5055 | |
| 5016 | 5056 | const msg = msg: { |
| 5017 | 5057 | const msg = try sema.errMsg( |
| 5018 | 5058 | block, |
| 5019 | 5059 | field_src, |
| 5020 | 5060 | "no field named '{s}' in union '{s}'", |
| 5021 | | .{ field_name, fqn }, |
| 5061 | .{ ip.stringToSlice(field_name), fqn }, |
| 5022 | 5062 | ); |
| 5023 | 5063 | errdefer msg.destroy(gpa); |
| 5024 | | try sema.mod.errNoteNonLazy(union_obj.srcLoc(sema.mod), msg, "union declared here", .{}); |
| 5064 | try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{}); |
| 5025 | 5065 | break :msg msg; |
| 5026 | 5066 | }; |
| 5027 | 5067 | return sema.failWithOwnedErrorMsg(msg); |
| ... | ... | @@ -5772,7 +5812,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5772 | 5812 | const src = inst_data.src(); |
| 5773 | 5813 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5774 | 5814 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5775 | | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 5815 | const decl_name = try mod.intern_pool.getOrPutString(mod.gpa, sema.code.nullTerminatedString(extra.decl_name)); |
| 5776 | 5816 | const decl_index = if (extra.namespace != .none) index_blk: { |
| 5777 | 5817 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); |
| 5778 | 5818 | const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?; |
| ... | ... | @@ -5875,19 +5915,14 @@ pub fn analyzeExport( |
| 5875 | 5915 | const new_export = try gpa.create(Export); |
| 5876 | 5916 | errdefer gpa.destroy(new_export); |
| 5877 | 5917 | |
| 5878 | | const symbol_name = try gpa.dupe(u8, borrowed_options.name); |
| 5879 | | errdefer gpa.free(symbol_name); |
| 5880 | | |
| 5881 | | const section: ?[]const u8 = if (borrowed_options.section) |s| try gpa.dupe(u8, s) else null; |
| 5882 | | errdefer if (section) |s| gpa.free(s); |
| 5918 | const symbol_name = try mod.intern_pool.getOrPutString(gpa, borrowed_options.name); |
| 5919 | const section = try mod.intern_pool.getOrPutStringOpt(gpa, borrowed_options.section); |
| 5883 | 5920 | |
| 5884 | 5921 | new_export.* = .{ |
| 5885 | | .options = .{ |
| 5886 | | .name = symbol_name, |
| 5887 | | .linkage = borrowed_options.linkage, |
| 5888 | | .section = section, |
| 5889 | | .visibility = borrowed_options.visibility, |
| 5890 | | }, |
| 5922 | .name = symbol_name, |
| 5923 | .linkage = borrowed_options.linkage, |
| 5924 | .section = section, |
| 5925 | .visibility = borrowed_options.visibility, |
| 5891 | 5926 | .src = src, |
| 5892 | 5927 | .owner_decl = sema.owner_decl_index, |
| 5893 | 5928 | .src_decl = block.src_decl, |
| ... | ... | @@ -6121,23 +6156,25 @@ fn addDbgVar( |
| 6121 | 6156 | } |
| 6122 | 6157 | |
| 6123 | 6158 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6159 | const mod = sema.mod; |
| 6124 | 6160 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 6125 | 6161 | const src = inst_data.src(); |
| 6126 | | const decl_name = inst_data.get(sema.code); |
| 6162 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6127 | 6163 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 6128 | 6164 | try sema.addReferencedBy(block, src, decl_index); |
| 6129 | 6165 | return sema.analyzeDeclRef(decl_index); |
| 6130 | 6166 | } |
| 6131 | 6167 | |
| 6132 | 6168 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6169 | const mod = sema.mod; |
| 6133 | 6170 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 6134 | 6171 | const src = inst_data.src(); |
| 6135 | | const decl_name = inst_data.get(sema.code); |
| 6172 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6136 | 6173 | const decl = try sema.lookupIdentifier(block, src, decl_name); |
| 6137 | 6174 | return sema.analyzeDeclVal(block, src, decl); |
| 6138 | 6175 | } |
| 6139 | 6176 | |
| 6140 | | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !Decl.Index { |
| 6177 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !Decl.Index { |
| 6141 | 6178 | const mod = sema.mod; |
| 6142 | 6179 | var namespace = block.namespace; |
| 6143 | 6180 | while (true) { |
| ... | ... | @@ -6156,7 +6193,7 @@ fn lookupInNamespace( |
| 6156 | 6193 | block: *Block, |
| 6157 | 6194 | src: LazySrcLoc, |
| 6158 | 6195 | namespace_index: Namespace.Index, |
| 6159 | | ident_name: []const u8, |
| 6196 | ident_name: InternPool.NullTerminatedString, |
| 6160 | 6197 | observe_usingnamespace: bool, |
| 6161 | 6198 | ) CompileError!?Decl.Index { |
| 6162 | 6199 | const mod = sema.mod; |
| ... | ... | @@ -6249,9 +6286,6 @@ fn lookupInNamespace( |
| 6249 | 6286 | return decl_index; |
| 6250 | 6287 | } |
| 6251 | 6288 | |
| 6252 | | log.debug("{*} ({s}) depends on non-existence of '{s}' in {*} ({s})", .{ |
| 6253 | | sema.owner_decl, sema.owner_decl.name, ident_name, namespace_decl, namespace_decl.name, |
| 6254 | | }); |
| 6255 | 6289 | // TODO This dependency is too strong. Really, it should only be a dependency |
| 6256 | 6290 | // on the non-existence of `ident_name` in the namespace. We can lessen the number of |
| 6257 | 6291 | // outdated declarations by making this dependency more sophisticated. |
| ... | ... | @@ -6276,10 +6310,12 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { |
| 6276 | 6310 | } |
| 6277 | 6311 | |
| 6278 | 6312 | pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { |
| 6313 | const mod = sema.mod; |
| 6314 | const gpa = sema.gpa; |
| 6279 | 6315 | const src = sema.src; |
| 6280 | 6316 | |
| 6281 | | if (!sema.mod.backendSupportsFeature(.error_return_trace)) return .none; |
| 6282 | | if (!sema.mod.comp.bin_file.options.error_return_tracing) return .none; |
| 6317 | if (!mod.backendSupportsFeature(.error_return_trace)) return .none; |
| 6318 | if (!mod.comp.bin_file.options.error_return_tracing) return .none; |
| 6283 | 6319 | |
| 6284 | 6320 | if (block.is_comptime) |
| 6285 | 6321 | return .none; |
| ... | ... | @@ -6292,7 +6328,8 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6292 | 6328 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6293 | 6329 | else => |e| return e, |
| 6294 | 6330 | }; |
| 6295 | | const field_index = sema.structFieldIndex(block, stack_trace_ty, "index", src) catch |err| switch (err) { |
| 6331 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); |
| 6332 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, src) catch |err| switch (err) { |
| 6296 | 6333 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6297 | 6334 | else => |e| return e, |
| 6298 | 6335 | }; |
| ... | ... | @@ -6316,6 +6353,7 @@ fn popErrorReturnTrace( |
| 6316 | 6353 | saved_error_trace_index: Air.Inst.Ref, |
| 6317 | 6354 | ) CompileError!void { |
| 6318 | 6355 | const mod = sema.mod; |
| 6356 | const gpa = sema.gpa; |
| 6319 | 6357 | var is_non_error: ?bool = null; |
| 6320 | 6358 | var is_non_error_inst: Air.Inst.Ref = undefined; |
| 6321 | 6359 | if (operand != .none) { |
| ... | ... | @@ -6332,13 +6370,14 @@ fn popErrorReturnTrace( |
| 6332 | 6370 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6333 | 6371 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6334 | 6372 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6335 | | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, "index", src, stack_trace_ty, true); |
| 6373 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); |
| 6374 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6336 | 6375 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6337 | 6376 | } else if (is_non_error == null) { |
| 6338 | 6377 | // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need |
| 6339 | 6378 | // to pop any error trace that may have been propagated from our arguments. |
| 6340 | 6379 | |
| 6341 | | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Block).Struct.fields.len); |
| 6380 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len); |
| 6342 | 6381 | const cond_block_inst = try block.addInstAsIndex(.{ |
| 6343 | 6382 | .tag = .block, |
| 6344 | 6383 | .data = .{ |
| ... | ... | @@ -6350,28 +6389,29 @@ fn popErrorReturnTrace( |
| 6350 | 6389 | }); |
| 6351 | 6390 | |
| 6352 | 6391 | var then_block = block.makeSubBlock(); |
| 6353 | | defer then_block.instructions.deinit(sema.gpa); |
| 6392 | defer then_block.instructions.deinit(gpa); |
| 6354 | 6393 | |
| 6355 | 6394 | // If non-error, then pop the error return trace by restoring the index. |
| 6356 | 6395 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6357 | 6396 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6358 | 6397 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6359 | 6398 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6360 | | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, "index", src, stack_trace_ty, true); |
| 6399 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); |
| 6400 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6361 | 6401 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6362 | 6402 | _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); |
| 6363 | 6403 | |
| 6364 | 6404 | // Otherwise, do nothing |
| 6365 | 6405 | var else_block = block.makeSubBlock(); |
| 6366 | | defer else_block.instructions.deinit(sema.gpa); |
| 6406 | defer else_block.instructions.deinit(gpa); |
| 6367 | 6407 | _ = try else_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); |
| 6368 | 6408 | |
| 6369 | | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.CondBr).Struct.fields.len + |
| 6409 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + |
| 6370 | 6410 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 6371 | 6411 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block |
| 6372 | 6412 | |
| 6373 | 6413 | const cond_br_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| 6374 | | try sema.air_instructions.append(sema.gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 6414 | try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 6375 | 6415 | .operand = is_non_error_inst, |
| 6376 | 6416 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 6377 | 6417 | .then_body_len = @intCast(u32, then_block.instructions.items.len), |
| ... | ... | @@ -6414,7 +6454,7 @@ fn zirCall( |
| 6414 | 6454 | .direct => .{ .direct = try sema.resolveInst(extra.data.callee) }, |
| 6415 | 6455 | .field => blk: { |
| 6416 | 6456 | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); |
| 6417 | | const field_name = sema.code.nullTerminatedString(extra.data.field_name_start); |
| 6457 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.data.field_name_start)); |
| 6418 | 6458 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 6419 | 6459 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); |
| 6420 | 6460 | }, |
| ... | ... | @@ -6509,7 +6549,8 @@ fn zirCall( |
| 6509 | 6549 | if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError(mod))) { |
| 6510 | 6550 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6511 | 6551 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6512 | | const field_index = try sema.structFieldIndex(block, stack_trace_ty, "index", call_src); |
| 6552 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index"); |
| 6553 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); |
| 6513 | 6554 | |
| 6514 | 6555 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| 6515 | 6556 | const save_inst = try block.insertInst(block_index, .{ |
| ... | ... | @@ -7436,9 +7477,10 @@ fn instantiateGenericCall( |
| 7436 | 7477 | ) CompileError!Air.Inst.Ref { |
| 7437 | 7478 | const mod = sema.mod; |
| 7438 | 7479 | const gpa = sema.gpa; |
| 7480 | const ip = &mod.intern_pool; |
| 7439 | 7481 | |
| 7440 | 7482 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); |
| 7441 | | const module_fn = mod.funcPtr(switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7483 | const module_fn = mod.funcPtr(switch (ip.indexToKey(func_val.toIntern())) { |
| 7442 | 7484 | .func => |function| function.index, |
| 7443 | 7485 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?, |
| 7444 | 7486 | else => unreachable, |
| ... | ... | @@ -7567,9 +7609,12 @@ fn instantiateGenericCall( |
| 7567 | 7609 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); |
| 7568 | 7610 | const new_decl = mod.declPtr(new_decl_index); |
| 7569 | 7611 | // TODO better names for generic function instantiations |
| 7570 | | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| 7571 | | fn_owner_decl.name, @enumToInt(new_decl_index), |
| 7572 | | }); |
| 7612 | // The ensureUnusedCapacity here protects against fn_owner_decl.name slice being |
| 7613 | // reallocated during getOrPutStringFmt. |
| 7614 | try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(fn_owner_decl.name).len + 20); |
| 7615 | const decl_name = ip.getOrPutStringFmt(gpa, "{s}__anon_{d}", .{ |
| 7616 | ip.stringToSlice(fn_owner_decl.name), @enumToInt(new_decl_index), |
| 7617 | }) catch unreachable; |
| 7573 | 7618 | new_decl.name = decl_name; |
| 7574 | 7619 | new_decl.src_line = fn_owner_decl.src_line; |
| 7575 | 7620 | new_decl.is_pub = fn_owner_decl.is_pub; |
| ... | ... | @@ -7590,12 +7635,8 @@ fn instantiateGenericCall( |
| 7590 | 7635 | assert(new_decl.dependencies.keys().len == 0); |
| 7591 | 7636 | try mod.declareDeclDependencyType(new_decl_index, module_fn.owner_decl, .function_body); |
| 7592 | 7637 | |
| 7593 | | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); |
| 7594 | | const new_decl_arena_allocator = new_decl_arena.allocator(); |
| 7595 | | |
| 7596 | 7638 | const new_func = sema.resolveGenericInstantiationType( |
| 7597 | 7639 | block, |
| 7598 | | new_decl_arena_allocator, |
| 7599 | 7640 | fn_zir, |
| 7600 | 7641 | new_decl, |
| 7601 | 7642 | new_decl_index, |
| ... | ... | @@ -7608,7 +7649,6 @@ fn instantiateGenericCall( |
| 7608 | 7649 | bound_arg_src, |
| 7609 | 7650 | ) catch |err| switch (err) { |
| 7610 | 7651 | error.GenericPoison, error.ComptimeReturn => { |
| 7611 | | new_decl_arena.deinit(); |
| 7612 | 7652 | // Resolving the new function type below will possibly declare more decl dependencies |
| 7613 | 7653 | // and so we remove them all here in case of error. |
| 7614 | 7654 | for (new_decl.dependencies.keys()) |dep_index| { |
| ... | ... | @@ -7623,10 +7663,6 @@ fn instantiateGenericCall( |
| 7623 | 7663 | }, |
| 7624 | 7664 | else => { |
| 7625 | 7665 | assert(mod.monomorphed_funcs.removeContext(new_module_func_index, .{ .mod = mod })); |
| 7626 | | { |
| 7627 | | errdefer new_decl_arena.deinit(); |
| 7628 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 7629 | | } |
| 7630 | 7666 | // TODO look up the compile error that happened here and attach a note to it |
| 7631 | 7667 | // pointing here, at the generic instantiation callsite. |
| 7632 | 7668 | if (sema.owner_func) |owner_func| { |
| ... | ... | @@ -7637,9 +7673,7 @@ fn instantiateGenericCall( |
| 7637 | 7673 | return err; |
| 7638 | 7674 | }, |
| 7639 | 7675 | }; |
| 7640 | | errdefer new_decl_arena.deinit(); |
| 7641 | 7676 | |
| 7642 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 7643 | 7677 | break :callee new_func; |
| 7644 | 7678 | } else gop.key_ptr.*; |
| 7645 | 7679 | const callee = mod.funcPtr(callee_index); |
| ... | ... | @@ -7729,7 +7763,6 @@ fn instantiateGenericCall( |
| 7729 | 7763 | fn resolveGenericInstantiationType( |
| 7730 | 7764 | sema: *Sema, |
| 7731 | 7765 | block: *Block, |
| 7732 | | new_decl_arena_allocator: Allocator, |
| 7733 | 7766 | fn_zir: Zir, |
| 7734 | 7767 | new_decl: *Decl, |
| 7735 | 7768 | new_decl_index: Decl.Index, |
| ... | ... | @@ -7755,7 +7788,6 @@ fn resolveGenericInstantiationType( |
| 7755 | 7788 | .mod = mod, |
| 7756 | 7789 | .gpa = gpa, |
| 7757 | 7790 | .arena = sema.arena, |
| 7758 | | .perm_arena = new_decl_arena_allocator, |
| 7759 | 7791 | .code = fn_zir, |
| 7760 | 7792 | .owner_decl = new_decl, |
| 7761 | 7793 | .owner_decl_index = new_decl_index, |
| ... | ... | @@ -7764,7 +7796,8 @@ fn resolveGenericInstantiationType( |
| 7764 | 7796 | .fn_ret_ty = Type.void, |
| 7765 | 7797 | .owner_func = null, |
| 7766 | 7798 | .owner_func_index = .none, |
| 7767 | | .comptime_args = try new_decl_arena_allocator.alloc(TypedValue, uncasted_args.len), |
| 7799 | // TODO: fully migrate functions into InternPool |
| 7800 | .comptime_args = try mod.tmp_hack_arena.allocator().alloc(TypedValue, uncasted_args.len), |
| 7768 | 7801 | .comptime_args_fn_inst = module_fn.zir_body_inst, |
| 7769 | 7802 | .preallocated_new_func = new_module_func.toOptional(), |
| 7770 | 7803 | .is_generic_instantiation = true, |
| ... | ... | @@ -7931,10 +7964,6 @@ fn resolveGenericInstantiationType( |
| 7931 | 7964 | new_decl.owns_tv = true; |
| 7932 | 7965 | new_decl.analysis = .complete; |
| 7933 | 7966 | |
| 7934 | | log.debug("generic function '{s}' instantiated with type {}", .{ |
| 7935 | | new_decl.name, new_decl.ty.fmtDebug(), |
| 7936 | | }); |
| 7937 | | |
| 7938 | 7967 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field |
| 7939 | 7968 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR |
| 7940 | 7969 | // parameters mapped appropriately. |
| ... | ... | @@ -8134,13 +8163,13 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8134 | 8163 | _ = block; |
| 8135 | 8164 | const mod = sema.mod; |
| 8136 | 8165 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 8137 | | const name = inst_data.get(sema.code); |
| 8166 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 8167 | _ = try mod.getErrorValue(name); |
| 8138 | 8168 | // Create an error set type with only this error value, and return the value. |
| 8139 | | const kv = try sema.mod.getErrorValue(name); |
| 8140 | | const error_set_type = try mod.singleErrorSetType(kv.key); |
| 8169 | const error_set_type = try mod.singleErrorSetTypeNts(name); |
| 8141 | 8170 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 8142 | 8171 | .ty = error_set_type.toIntern(), |
| 8143 | | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), |
| 8172 | .name = name, |
| 8144 | 8173 | } })).toValue()); |
| 8145 | 8174 | } |
| 8146 | 8175 | |
| ... | ... | @@ -8162,7 +8191,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8162 | 8191 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 8163 | 8192 | return sema.addConstant(Type.err_int, try mod.intValue( |
| 8164 | 8193 | Type.err_int, |
| 8165 | | (try mod.getErrorValue(mod.intern_pool.stringToSlice(err_name))).value, |
| 8194 | try mod.getErrorValue(err_name), |
| 8166 | 8195 | )); |
| 8167 | 8196 | } |
| 8168 | 8197 | |
| ... | ... | @@ -8173,8 +8202,8 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8173 | 8202 | switch (names.len) { |
| 8174 | 8203 | 0 => return sema.addConstant(Type.err_int, try mod.intValue(Type.err_int, 0)), |
| 8175 | 8204 | 1 => { |
| 8176 | | const name = mod.intern_pool.stringToSlice(names[0]); |
| 8177 | | return sema.addIntUnsigned(Type.err_int, mod.global_error_set.get(name).?); |
| 8205 | const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(names[0]).?); |
| 8206 | return sema.addIntUnsigned(Type.err_int, int); |
| 8178 | 8207 | }, |
| 8179 | 8208 | else => {}, |
| 8180 | 8209 | } |
| ... | ... | @@ -8197,11 +8226,11 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8197 | 8226 | |
| 8198 | 8227 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |value| { |
| 8199 | 8228 | const int = try sema.usizeCast(block, operand_src, value.toUnsignedInt(mod)); |
| 8200 | | if (int > sema.mod.global_error_set.count() or int == 0) |
| 8229 | if (int > mod.global_error_set.count() or int == 0) |
| 8201 | 8230 | return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int}); |
| 8202 | 8231 | return sema.addConstant(Type.anyerror, (try mod.intern(.{ .err = .{ |
| 8203 | 8232 | .ty = .anyerror_type, |
| 8204 | | .name = mod.intern_pool.getString(sema.mod.error_name_list.items[int]).unwrap().?, |
| 8233 | .name = mod.global_error_set.keys()[int], |
| 8205 | 8234 | } })).toValue()); |
| 8206 | 8235 | } |
| 8207 | 8236 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | ... | @@ -8917,7 +8946,7 @@ fn handleExternLibName( |
| 8917 | 8946 | const FuncLinkSection = union(enum) { |
| 8918 | 8947 | generic, |
| 8919 | 8948 | default, |
| 8920 | | explicit: []const u8, |
| 8949 | explicit: InternPool.NullTerminatedString, |
| 8921 | 8950 | }; |
| 8922 | 8951 | |
| 8923 | 8952 | fn funcCommon( |
| ... | ... | @@ -9186,9 +9215,9 @@ fn funcCommon( |
| 9186 | 9215 | }; |
| 9187 | 9216 | |
| 9188 | 9217 | sema.owner_decl.@"linksection" = switch (section) { |
| 9189 | | .generic => undefined, |
| 9190 | | .default => null, |
| 9191 | | .explicit => |section_name| try sema.perm_arena.dupeZ(u8, section_name), |
| 9218 | .generic => .none, |
| 9219 | .default => .none, |
| 9220 | .explicit => |section_name| section_name.toOptional(), |
| 9192 | 9221 | }; |
| 9193 | 9222 | sema.owner_decl.@"align" = alignment orelse 0; |
| 9194 | 9223 | sema.owner_decl.@"addrspace" = address_space orelse .generic; |
| ... | ... | @@ -9572,11 +9601,12 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9572 | 9601 | const tracy = trace(@src()); |
| 9573 | 9602 | defer tracy.end(); |
| 9574 | 9603 | |
| 9604 | const mod = sema.mod; |
| 9575 | 9605 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9576 | 9606 | const src = inst_data.src(); |
| 9577 | 9607 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9578 | 9608 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 9579 | | const field_name = sema.code.nullTerminatedString(extra.field_name_start); |
| 9609 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); |
| 9580 | 9610 | const object = try sema.resolveInst(extra.lhs); |
| 9581 | 9611 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 9582 | 9612 | } |
| ... | ... | @@ -9585,11 +9615,12 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index, initializing: b |
| 9585 | 9615 | const tracy = trace(@src()); |
| 9586 | 9616 | defer tracy.end(); |
| 9587 | 9617 | |
| 9618 | const mod = sema.mod; |
| 9588 | 9619 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9589 | 9620 | const src = inst_data.src(); |
| 9590 | 9621 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9591 | 9622 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 9592 | | const field_name = sema.code.nullTerminatedString(extra.field_name_start); |
| 9623 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); |
| 9593 | 9624 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9594 | 9625 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, initializing); |
| 9595 | 9626 | } |
| ... | ... | @@ -9603,7 +9634,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9603 | 9634 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9604 | 9635 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9605 | 9636 | const object = try sema.resolveInst(extra.lhs); |
| 9606 | | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name, "field name must be comptime-known"); |
| 9637 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known"); |
| 9607 | 9638 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 9608 | 9639 | } |
| 9609 | 9640 | |
| ... | ... | @@ -9616,7 +9647,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9616 | 9647 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9617 | 9648 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9618 | 9649 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9619 | | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name, "field name must be comptime-known"); |
| 9650 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known"); |
| 9620 | 9651 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 9621 | 9652 | } |
| 9622 | 9653 | |
| ... | ... | @@ -10434,6 +10465,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10434 | 10465 | |
| 10435 | 10466 | const mod = sema.mod; |
| 10436 | 10467 | const gpa = sema.gpa; |
| 10468 | const ip = &mod.intern_pool; |
| 10437 | 10469 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 10438 | 10470 | const src = inst_data.src(); |
| 10439 | 10471 | const src_node_offset = inst_data.src_node; |
| ... | ... | @@ -10605,7 +10637,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10605 | 10637 | i, |
| 10606 | 10638 | msg, |
| 10607 | 10639 | "unhandled enumeration value: '{s}'", |
| 10608 | | .{field_name}, |
| 10640 | .{ip.stringToSlice(field_name)}, |
| 10609 | 10641 | ); |
| 10610 | 10642 | } |
| 10611 | 10643 | try mod.errNoteNonLazy( |
| ... | ... | @@ -10689,7 +10721,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10689 | 10721 | errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa); |
| 10690 | 10722 | |
| 10691 | 10723 | for (operand_ty.errorSetNames(mod)) |error_name_ip| { |
| 10692 | | const error_name = mod.intern_pool.stringToSlice(error_name_ip); |
| 10724 | const error_name = ip.stringToSlice(error_name_ip); |
| 10693 | 10725 | if (!seen_errors.contains(error_name) and special_prong != .@"else") { |
| 10694 | 10726 | const msg = maybe_msg orelse blk: { |
| 10695 | 10727 | maybe_msg = try sema.errMsg( |
| ... | ... | @@ -10758,7 +10790,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10758 | 10790 | var names: Module.Fn.InferredErrorSet.NameMap = .{}; |
| 10759 | 10791 | try names.ensureUnusedCapacity(sema.arena, error_names.len); |
| 10760 | 10792 | for (error_names) |error_name_ip| { |
| 10761 | | const error_name = mod.intern_pool.stringToSlice(error_name_ip); |
| 10793 | const error_name = ip.stringToSlice(error_name_ip); |
| 10762 | 10794 | if (seen_errors.contains(error_name)) continue; |
| 10763 | 10795 | |
| 10764 | 10796 | names.putAssumeCapacityNoClobber(error_name_ip, {}); |
| ... | ... | @@ -12062,7 +12094,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12062 | 12094 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12063 | 12095 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12064 | 12096 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 12065 | | const field_name = try sema.resolveConstString(block, name_src, extra.rhs, "field name must be comptime-known"); |
| 12097 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, "field name must be comptime-known"); |
| 12066 | 12098 | const ty = try sema.resolveTypeFields(unresolved_ty); |
| 12067 | 12099 | const ip = &mod.intern_pool; |
| 12068 | 12100 | |
| ... | ... | @@ -12070,19 +12102,17 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12070 | 12102 | switch (ip.indexToKey(ty.toIntern())) { |
| 12071 | 12103 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 12072 | 12104 | .Slice => { |
| 12073 | | if (mem.eql(u8, field_name, "ptr")) break :hf true; |
| 12074 | | if (mem.eql(u8, field_name, "len")) break :hf true; |
| 12105 | if (ip.stringEqlSlice(field_name, "ptr")) break :hf true; |
| 12106 | if (ip.stringEqlSlice(field_name, "len")) break :hf true; |
| 12075 | 12107 | break :hf false; |
| 12076 | 12108 | }, |
| 12077 | 12109 | else => {}, |
| 12078 | 12110 | }, |
| 12079 | 12111 | .anon_struct_type => |anon_struct| { |
| 12080 | 12112 | if (anon_struct.names.len != 0) { |
| 12081 | | // If the string is not interned, then the field certainly is not present. |
| 12082 | | const name_interned = ip.getString(field_name).unwrap() orelse break :hf false; |
| 12083 | | break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, name_interned) != null; |
| 12113 | break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null; |
| 12084 | 12114 | } else { |
| 12085 | | const field_index = std.fmt.parseUnsigned(u32, field_name, 10) catch break :hf false; |
| 12115 | const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch break :hf false; |
| 12086 | 12116 | break :hf field_index < ty.structFieldCount(mod); |
| 12087 | 12117 | } |
| 12088 | 12118 | }, |
| ... | ... | @@ -12097,11 +12127,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12097 | 12127 | break :hf union_obj.fields.contains(field_name); |
| 12098 | 12128 | }, |
| 12099 | 12129 | .enum_type => |enum_type| { |
| 12100 | | // If the string is not interned, then the field certainly is not present. |
| 12101 | | const name_interned = ip.getString(field_name).unwrap() orelse break :hf false; |
| 12102 | | break :hf enum_type.nameIndex(ip, name_interned) != null; |
| 12130 | break :hf enum_type.nameIndex(ip, field_name) != null; |
| 12103 | 12131 | }, |
| 12104 | | .array_type => break :hf mem.eql(u8, field_name, "len"), |
| 12132 | .array_type => break :hf ip.stringEqlSlice(field_name, "len"), |
| 12105 | 12133 | else => {}, |
| 12106 | 12134 | } |
| 12107 | 12135 | return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{ |
| ... | ... | @@ -12123,7 +12151,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 12123 | 12151 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12124 | 12152 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12125 | 12153 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 12126 | | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "decl name must be comptime-known"); |
| 12154 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "decl name must be comptime-known"); |
| 12127 | 12155 | |
| 12128 | 12156 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 12129 | 12157 | |
| ... | ... | @@ -12218,14 +12246,12 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12218 | 12246 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 12219 | 12247 | const mod = sema.mod; |
| 12220 | 12248 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 12221 | | const err_name = inst_data.get(sema.code); |
| 12222 | | |
| 12223 | | // Return the error code from the function. |
| 12224 | | const kv = try mod.getErrorValue(err_name); |
| 12225 | | const error_set_type = try mod.singleErrorSetType(kv.key); |
| 12249 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 12250 | _ = try mod.getErrorValue(name); |
| 12251 | const error_set_type = try mod.singleErrorSetTypeNts(name); |
| 12226 | 12252 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 12227 | 12253 | .ty = error_set_type.toIntern(), |
| 12228 | | .name = mod.intern_pool.getString(kv.key).unwrap().?, |
| 12254 | .name = name, |
| 12229 | 12255 | } })).toValue()); |
| 12230 | 12256 | } |
| 12231 | 12257 | |
| ... | ... | @@ -15730,12 +15756,7 @@ fn zirThis( |
| 15730 | 15756 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 15731 | 15757 | } |
| 15732 | 15758 | |
| 15733 | | fn zirClosureCapture( |
| 15734 | | sema: *Sema, |
| 15735 | | block: *Block, |
| 15736 | | inst: Zir.Inst.Index, |
| 15737 | | ) CompileError!void { |
| 15738 | | // TODO: Compile error when closed over values are modified |
| 15759 | fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 15739 | 15760 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 15740 | 15761 | // Closures are not necessarily constant values. For example, the |
| 15741 | 15762 | // code might do something like this: |
| ... | ... | @@ -15754,13 +15775,8 @@ fn zirClosureCapture( |
| 15754 | 15775 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, capture); |
| 15755 | 15776 | } |
| 15756 | 15777 | |
| 15757 | | fn zirClosureGet( |
| 15758 | | sema: *Sema, |
| 15759 | | block: *Block, |
| 15760 | | inst: Zir.Inst.Index, |
| 15761 | | ) CompileError!Air.Inst.Ref { |
| 15778 | fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15762 | 15779 | const mod = sema.mod; |
| 15763 | | // TODO CLOSURE: Test this with inline functions |
| 15764 | 15780 | const inst_data = sema.code.instructions.items(.data)[inst].inst_node; |
| 15765 | 15781 | var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?; |
| 15766 | 15782 | // Note: The target closure must be in this scope list. |
| ... | ... | @@ -15896,7 +15912,7 @@ fn zirBuiltinSrc( |
| 15896 | 15912 | const func_name_val = blk: { |
| 15897 | 15913 | var anon_decl = try block.startAnonDecl(); |
| 15898 | 15914 | defer anon_decl.deinit(); |
| 15899 | | const name = mem.span(fn_owner_decl.name); |
| 15915 | const name = mod.intern_pool.stringToSlice(fn_owner_decl.name); |
| 15900 | 15916 | const new_decl_ty = try mod.arrayType(.{ |
| 15901 | 15917 | .len = name.len, |
| 15902 | 15918 | .child = .u8_type, |
| ... | ... | @@ -15965,6 +15981,7 @@ fn zirBuiltinSrc( |
| 15965 | 15981 | fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15966 | 15982 | const mod = sema.mod; |
| 15967 | 15983 | const gpa = sema.gpa; |
| 15984 | const ip = &mod.intern_pool; |
| 15968 | 15985 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 15969 | 15986 | const src = inst_data.src(); |
| 15970 | 15987 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| ... | ... | @@ -15995,7 +16012,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15995 | 16012 | block, |
| 15996 | 16013 | src, |
| 15997 | 16014 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 15998 | | "Fn", |
| 16015 | try ip.getOrPutString(gpa, "Fn"), |
| 15999 | 16016 | )).?; |
| 16000 | 16017 | try mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index); |
| 16001 | 16018 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| ... | ... | @@ -16006,7 +16023,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16006 | 16023 | block, |
| 16007 | 16024 | src, |
| 16008 | 16025 | fn_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16009 | | "Param", |
| 16026 | try ip.getOrPutString(gpa, "Param"), |
| 16010 | 16027 | )).?; |
| 16011 | 16028 | try mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index); |
| 16012 | 16029 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| ... | ... | @@ -16018,8 +16035,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16018 | 16035 | const info = mod.typeToFunc(ty).?; |
| 16019 | 16036 | const param_ty = info.param_types[i]; |
| 16020 | 16037 | const is_generic = param_ty == .generic_poison_type; |
| 16021 | | const param_ty_val = try mod.intern_pool.get(gpa, .{ .opt = .{ |
| 16022 | | .ty = try mod.intern_pool.get(gpa, .{ .opt_type = .type_type }), |
| 16038 | const param_ty_val = try ip.get(gpa, .{ .opt = .{ |
| 16039 | .ty = try ip.get(gpa, .{ .opt_type = .type_type }), |
| 16023 | 16040 | .val = if (is_generic) .none else param_ty, |
| 16024 | 16041 | } }); |
| 16025 | 16042 | |
| ... | ... | @@ -16070,7 +16087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16070 | 16087 | |
| 16071 | 16088 | const info = mod.typeToFunc(ty).?; |
| 16072 | 16089 | const ret_ty_opt = try mod.intern(.{ .opt = .{ |
| 16073 | | .ty = try mod.intern_pool.get(gpa, .{ .opt_type = .type_type }), |
| 16090 | .ty = try ip.get(gpa, .{ .opt_type = .type_type }), |
| 16074 | 16091 | .val = if (info.return_type == .generic_poison_type) .none else info.return_type, |
| 16075 | 16092 | } }); |
| 16076 | 16093 | |
| ... | ... | @@ -16104,7 +16121,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16104 | 16121 | block, |
| 16105 | 16122 | src, |
| 16106 | 16123 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16107 | | "Int", |
| 16124 | try ip.getOrPutString(gpa, "Int"), |
| 16108 | 16125 | )).?; |
| 16109 | 16126 | try mod.declareDeclDependency(sema.owner_decl_index, int_info_decl_index); |
| 16110 | 16127 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| ... | ... | @@ -16133,7 +16150,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16133 | 16150 | block, |
| 16134 | 16151 | src, |
| 16135 | 16152 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16136 | | "Float", |
| 16153 | try ip.getOrPutString(gpa, "Float"), |
| 16137 | 16154 | )).?; |
| 16138 | 16155 | try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index); |
| 16139 | 16156 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| ... | ... | @@ -16166,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16166 | 16183 | block, |
| 16167 | 16184 | src, |
| 16168 | 16185 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16169 | | "Pointer", |
| 16186 | try ip.getOrPutString(gpa, "Pointer"), |
| 16170 | 16187 | )).?; |
| 16171 | 16188 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16172 | 16189 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -16178,7 +16195,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16178 | 16195 | block, |
| 16179 | 16196 | src, |
| 16180 | 16197 | pointer_ty.getNamespaceIndex(mod).unwrap().?, |
| 16181 | | "Size", |
| 16198 | try ip.getOrPutString(gpa, "Size"), |
| 16182 | 16199 | )).?; |
| 16183 | 16200 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16184 | 16201 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -16219,7 +16236,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16219 | 16236 | block, |
| 16220 | 16237 | src, |
| 16221 | 16238 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16222 | | "Array", |
| 16239 | try ip.getOrPutString(gpa, "Array"), |
| 16223 | 16240 | )).?; |
| 16224 | 16241 | try mod.declareDeclDependency(sema.owner_decl_index, array_field_ty_decl_index); |
| 16225 | 16242 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| ... | ... | @@ -16251,7 +16268,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16251 | 16268 | block, |
| 16252 | 16269 | src, |
| 16253 | 16270 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16254 | | "Vector", |
| 16271 | try ip.getOrPutString(gpa, "Vector"), |
| 16255 | 16272 | )).?; |
| 16256 | 16273 | try mod.declareDeclDependency(sema.owner_decl_index, vector_field_ty_decl_index); |
| 16257 | 16274 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| ... | ... | @@ -16281,7 +16298,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16281 | 16298 | block, |
| 16282 | 16299 | src, |
| 16283 | 16300 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16284 | | "Optional", |
| 16301 | try ip.getOrPutString(gpa, "Optional"), |
| 16285 | 16302 | )).?; |
| 16286 | 16303 | try mod.declareDeclDependency(sema.owner_decl_index, optional_field_ty_decl_index); |
| 16287 | 16304 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| ... | ... | @@ -16312,7 +16329,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16312 | 16329 | block, |
| 16313 | 16330 | src, |
| 16314 | 16331 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16315 | | "Error", |
| 16332 | try ip.getOrPutString(gpa, "Error"), |
| 16316 | 16333 | )).?; |
| 16317 | 16334 | try mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index); |
| 16318 | 16335 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| ... | ... | @@ -16332,7 +16349,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16332 | 16349 | const names = ty.errorSetNames(mod); |
| 16333 | 16350 | const vals = try sema.arena.alloc(InternPool.Index, names.len); |
| 16334 | 16351 | for (vals, names) |*field_val, name_ip| { |
| 16335 | | const name = mod.intern_pool.stringToSlice(name_ip); |
| 16352 | const name = ip.stringToSlice(name_ip); |
| 16336 | 16353 | const name_val = v: { |
| 16337 | 16354 | var anon_decl = try block.startAnonDecl(); |
| 16338 | 16355 | defer anon_decl.deinit(); |
| ... | ... | @@ -16415,7 +16432,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16415 | 16432 | block, |
| 16416 | 16433 | src, |
| 16417 | 16434 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16418 | | "ErrorUnion", |
| 16435 | try ip.getOrPutString(gpa, "ErrorUnion"), |
| 16419 | 16436 | )).?; |
| 16420 | 16437 | try mod.declareDeclDependency(sema.owner_decl_index, error_union_field_ty_decl_index); |
| 16421 | 16438 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); |
| ... | ... | @@ -16440,7 +16457,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16440 | 16457 | }, |
| 16441 | 16458 | .Enum => { |
| 16442 | 16459 | // TODO: look into memoizing this result. |
| 16443 | | const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type; |
| 16460 | const enum_type = ip.indexToKey(ty.toIntern()).enum_type; |
| 16444 | 16461 | |
| 16445 | 16462 | const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive); |
| 16446 | 16463 | |
| ... | ... | @@ -16452,7 +16469,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16452 | 16469 | block, |
| 16453 | 16470 | src, |
| 16454 | 16471 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16455 | | "EnumField", |
| 16472 | try ip.getOrPutString(gpa, "EnumField"), |
| 16456 | 16473 | )).?; |
| 16457 | 16474 | try mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index); |
| 16458 | 16475 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| ... | ... | @@ -16462,8 +16479,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16462 | 16479 | |
| 16463 | 16480 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); |
| 16464 | 16481 | for (enum_field_vals, 0..) |*field_val, i| { |
| 16465 | | const name_ip = mod.intern_pool.indexToKey(ty.toIntern()).enum_type.names[i]; |
| 16466 | | const name = mod.intern_pool.stringToSlice(name_ip); |
| 16482 | const name_ip = ip.indexToKey(ty.toIntern()).enum_type.names[i]; |
| 16483 | const name = ip.stringToSlice(name_ip); |
| 16467 | 16484 | const name_val = v: { |
| 16468 | 16485 | var anon_decl = try block.startAnonDecl(); |
| 16469 | 16486 | defer anon_decl.deinit(); |
| ... | ... | @@ -16532,7 +16549,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16532 | 16549 | block, |
| 16533 | 16550 | src, |
| 16534 | 16551 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16535 | | "Enum", |
| 16552 | try ip.getOrPutString(gpa, "Enum"), |
| 16536 | 16553 | )).?; |
| 16537 | 16554 | try mod.declareDeclDependency(sema.owner_decl_index, type_enum_ty_decl_index); |
| 16538 | 16555 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); |
| ... | ... | @@ -16570,7 +16587,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16570 | 16587 | block, |
| 16571 | 16588 | src, |
| 16572 | 16589 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16573 | | "Union", |
| 16590 | try ip.getOrPutString(gpa, "Union"), |
| 16574 | 16591 | )).?; |
| 16575 | 16592 | try mod.declareDeclDependency(sema.owner_decl_index, type_union_ty_decl_index); |
| 16576 | 16593 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); |
| ... | ... | @@ -16583,7 +16600,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16583 | 16600 | block, |
| 16584 | 16601 | src, |
| 16585 | 16602 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16586 | | "UnionField", |
| 16603 | try ip.getOrPutString(gpa, "UnionField"), |
| 16587 | 16604 | )).?; |
| 16588 | 16605 | try mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index); |
| 16589 | 16606 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| ... | ... | @@ -16601,7 +16618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16601 | 16618 | |
| 16602 | 16619 | for (union_field_vals, 0..) |*field_val, i| { |
| 16603 | 16620 | const field = union_fields.values()[i]; |
| 16604 | | const name = union_fields.keys()[i]; |
| 16621 | const name = ip.stringToSlice(union_fields.keys()[i]); |
| 16605 | 16622 | const name_val = v: { |
| 16606 | 16623 | var anon_decl = try block.startAnonDecl(); |
| 16607 | 16624 | defer anon_decl.deinit(); |
| ... | ... | @@ -16682,7 +16699,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16682 | 16699 | block, |
| 16683 | 16700 | src, |
| 16684 | 16701 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16685 | | "ContainerLayout", |
| 16702 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 16686 | 16703 | )).?; |
| 16687 | 16704 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16688 | 16705 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -16721,7 +16738,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16721 | 16738 | block, |
| 16722 | 16739 | src, |
| 16723 | 16740 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16724 | | "Struct", |
| 16741 | try ip.getOrPutString(gpa, "Struct"), |
| 16725 | 16742 | )).?; |
| 16726 | 16743 | try mod.declareDeclDependency(sema.owner_decl_index, type_struct_ty_decl_index); |
| 16727 | 16744 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); |
| ... | ... | @@ -16734,7 +16751,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16734 | 16751 | block, |
| 16735 | 16752 | src, |
| 16736 | 16753 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16737 | | "StructField", |
| 16754 | try ip.getOrPutString(gpa, "StructField"), |
| 16738 | 16755 | )).?; |
| 16739 | 16756 | try mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index); |
| 16740 | 16757 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| ... | ... | @@ -16749,11 +16766,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16749 | 16766 | var struct_field_vals: []InternPool.Index = &.{}; |
| 16750 | 16767 | defer gpa.free(struct_field_vals); |
| 16751 | 16768 | fv: { |
| 16752 | | const struct_type = switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 16769 | const struct_type = switch (ip.indexToKey(struct_ty.toIntern())) { |
| 16753 | 16770 | .anon_struct_type => |tuple| { |
| 16754 | 16771 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len); |
| 16755 | 16772 | for (struct_field_vals, 0..) |*struct_field_val, i| { |
| 16756 | | const anon_struct_type = mod.intern_pool.indexToKey(struct_ty.toIntern()).anon_struct_type; |
| 16773 | const anon_struct_type = ip.indexToKey(struct_ty.toIntern()).anon_struct_type; |
| 16757 | 16774 | const field_ty = anon_struct_type.types[i]; |
| 16758 | 16775 | const field_val = anon_struct_type.values[i]; |
| 16759 | 16776 | const name_val = v: { |
| ... | ... | @@ -16761,7 +16778,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16761 | 16778 | defer anon_decl.deinit(); |
| 16762 | 16779 | const bytes = if (tuple.names.len != 0) |
| 16763 | 16780 | // https://github.com/ziglang/zig/issues/15709 |
| 16764 | | @as([]const u8, mod.intern_pool.stringToSlice(tuple.names[i])) |
| 16781 | @as([]const u8, ip.stringToSlice(tuple.names[i])) |
| 16765 | 16782 | else |
| 16766 | 16783 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 16767 | 16784 | const new_decl_ty = try mod.arrayType(.{ |
| ... | ... | @@ -16815,7 +16832,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16815 | 16832 | struct_field_vals, |
| 16816 | 16833 | struct_obj.fields.keys(), |
| 16817 | 16834 | struct_obj.fields.values(), |
| 16818 | | ) |*field_val, name, field| { |
| 16835 | ) |*field_val, name_nts, field| { |
| 16836 | const name = ip.stringToSlice(name_nts); |
| 16819 | 16837 | const name_val = v: { |
| 16820 | 16838 | var anon_decl = try block.startAnonDecl(); |
| 16821 | 16839 | defer anon_decl.deinit(); |
| ... | ... | @@ -16838,10 +16856,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16838 | 16856 | } }); |
| 16839 | 16857 | }; |
| 16840 | 16858 | |
| 16841 | | const opt_default_val = if (field.default_val.toIntern() == .unreachable_value) |
| 16859 | const opt_default_val = if (field.default_val == .none) |
| 16842 | 16860 | null |
| 16843 | 16861 | else |
| 16844 | | field.default_val; |
| 16862 | field.default_val.toValue(); |
| 16845 | 16863 | const default_val_ptr = try sema.optRefValue(block, field.ty, opt_default_val); |
| 16846 | 16864 | const alignment = field.alignment(mod, layout); |
| 16847 | 16865 | |
| ... | ... | @@ -16908,7 +16926,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16908 | 16926 | block, |
| 16909 | 16927 | src, |
| 16910 | 16928 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16911 | | "ContainerLayout", |
| 16929 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 16912 | 16930 | )).?; |
| 16913 | 16931 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16914 | 16932 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -16945,7 +16963,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16945 | 16963 | block, |
| 16946 | 16964 | src, |
| 16947 | 16965 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16948 | | "Opaque", |
| 16966 | try ip.getOrPutString(gpa, "Opaque"), |
| 16949 | 16967 | )).?; |
| 16950 | 16968 | try mod.declareDeclDependency(sema.owner_decl_index, type_opaque_ty_decl_index); |
| 16951 | 16969 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| ... | ... | @@ -16982,6 +17000,8 @@ fn typeInfoDecls( |
| 16982 | 17000 | opt_namespace: Module.Namespace.OptionalIndex, |
| 16983 | 17001 | ) CompileError!InternPool.Index { |
| 16984 | 17002 | const mod = sema.mod; |
| 17003 | const gpa = sema.gpa; |
| 17004 | |
| 16985 | 17005 | var decls_anon_decl = try block.startAnonDecl(); |
| 16986 | 17006 | defer decls_anon_decl.deinit(); |
| 16987 | 17007 | |
| ... | ... | @@ -16990,7 +17010,7 @@ fn typeInfoDecls( |
| 16990 | 17010 | block, |
| 16991 | 17011 | src, |
| 16992 | 17012 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16993 | | "Declaration", |
| 17013 | try mod.intern_pool.getOrPutString(gpa, "Declaration"), |
| 16994 | 17014 | )).?; |
| 16995 | 17015 | try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index); |
| 16996 | 17016 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| ... | ... | @@ -16999,10 +17019,10 @@ fn typeInfoDecls( |
| 16999 | 17019 | }; |
| 17000 | 17020 | try sema.queueFullTypeResolution(declaration_ty); |
| 17001 | 17021 | |
| 17002 | | var decl_vals = std.ArrayList(InternPool.Index).init(sema.gpa); |
| 17022 | var decl_vals = std.ArrayList(InternPool.Index).init(gpa); |
| 17003 | 17023 | defer decl_vals.deinit(); |
| 17004 | 17024 | |
| 17005 | | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(sema.gpa); |
| 17025 | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa); |
| 17006 | 17026 | defer seen_namespaces.deinit(); |
| 17007 | 17027 | |
| 17008 | 17028 | if (opt_namespace.unwrap()) |namespace_index| { |
| ... | ... | @@ -17061,7 +17081,7 @@ fn typeInfoNamespaceDecls( |
| 17061 | 17081 | const name_val = v: { |
| 17062 | 17082 | var anon_decl = try block.startAnonDecl(); |
| 17063 | 17083 | defer anon_decl.deinit(); |
| 17064 | | const name = mem.span(decl.name); |
| 17084 | const name = mod.intern_pool.stringToSlice(decl.name); |
| 17065 | 17085 | const new_decl_ty = try mod.arrayType(.{ |
| 17066 | 17086 | .len = name.len, |
| 17067 | 17087 | .child = .u8_type, |
| ... | ... | @@ -17696,15 +17716,14 @@ fn zirRetErrValue( |
| 17696 | 17716 | ) CompileError!Zir.Inst.Index { |
| 17697 | 17717 | const mod = sema.mod; |
| 17698 | 17718 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 17699 | | const err_name = inst_data.get(sema.code); |
| 17719 | const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 17720 | _ = try mod.getErrorValue(err_name); |
| 17700 | 17721 | const src = inst_data.src(); |
| 17701 | | |
| 17702 | 17722 | // Return the error code from the function. |
| 17703 | | const kv = try mod.getErrorValue(err_name); |
| 17704 | | const error_set_type = try mod.singleErrorSetType(err_name); |
| 17723 | const error_set_type = try mod.singleErrorSetTypeNts(err_name); |
| 17705 | 17724 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 17706 | 17725 | .ty = error_set_type.toIntern(), |
| 17707 | | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), |
| 17726 | .name = err_name, |
| 17708 | 17727 | } })).toValue()); |
| 17709 | 17728 | return sema.analyzeRet(block, result_inst, src); |
| 17710 | 17729 | } |
| ... | ... | @@ -18177,7 +18196,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18177 | 18196 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 18178 | 18197 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 18179 | 18198 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); |
| 18180 | | const field_name = try sema.resolveConstString(block, field_src, extra.field_name, "name of field being initialized must be comptime-known"); |
| 18199 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "name of field being initialized must be comptime-known"); |
| 18181 | 18200 | const init = try sema.resolveInst(extra.init); |
| 18182 | 18201 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); |
| 18183 | 18202 | } |
| ... | ... | @@ -18189,7 +18208,7 @@ fn unionInit( |
| 18189 | 18208 | init_src: LazySrcLoc, |
| 18190 | 18209 | union_ty: Type, |
| 18191 | 18210 | union_ty_src: LazySrcLoc, |
| 18192 | | field_name: []const u8, |
| 18211 | field_name: InternPool.NullTerminatedString, |
| 18193 | 18212 | field_src: LazySrcLoc, |
| 18194 | 18213 | ) CompileError!Air.Inst.Ref { |
| 18195 | 18214 | const mod = sema.mod; |
| ... | ... | @@ -18257,7 +18276,7 @@ fn zirStructInit( |
| 18257 | 18276 | const field_type_data = zir_datas[item.data.field_type].pl_node; |
| 18258 | 18277 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 18259 | 18278 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 18260 | | const field_name = sema.code.nullTerminatedString(field_type_extra.name_start); |
| 18279 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| 18261 | 18280 | const field_index = if (resolved_ty.isTuple(mod)) |
| 18262 | 18281 | try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src) |
| 18263 | 18282 | else |
| ... | ... | @@ -18298,7 +18317,7 @@ fn zirStructInit( |
| 18298 | 18317 | const field_type_data = zir_datas[item.data.field_type].pl_node; |
| 18299 | 18318 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 18300 | 18319 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 18301 | | const field_name = sema.code.nullTerminatedString(field_type_extra.name_start); |
| 18320 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| 18302 | 18321 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); |
| 18303 | 18322 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); |
| 18304 | 18323 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| ... | ... | @@ -18347,12 +18366,12 @@ fn finishStructInit( |
| 18347 | 18366 | is_ref: bool, |
| 18348 | 18367 | ) CompileError!Air.Inst.Ref { |
| 18349 | 18368 | const mod = sema.mod; |
| 18350 | | const gpa = sema.gpa; |
| 18369 | const ip = &mod.intern_pool; |
| 18351 | 18370 | |
| 18352 | 18371 | var root_msg: ?*Module.ErrorMsg = null; |
| 18353 | 18372 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 18354 | 18373 | |
| 18355 | | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 18374 | switch (ip.indexToKey(struct_ty.toIntern())) { |
| 18356 | 18375 | .anon_struct_type => |anon_struct| { |
| 18357 | 18376 | for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| { |
| 18358 | 18377 | if (field_inits[i] != .none) continue; |
| ... | ... | @@ -18366,9 +18385,9 @@ fn finishStructInit( |
| 18366 | 18385 | root_msg = try sema.errMsg(block, init_src, template, .{i}); |
| 18367 | 18386 | } |
| 18368 | 18387 | } else { |
| 18369 | | const field_name = mod.intern_pool.stringToSlice(anon_struct.names[i]); |
| 18388 | const field_name = anon_struct.names[i]; |
| 18370 | 18389 | const template = "missing struct field: {s}"; |
| 18371 | | const args = .{field_name}; |
| 18390 | const args = .{ip.stringToSlice(field_name)}; |
| 18372 | 18391 | if (root_msg) |msg| { |
| 18373 | 18392 | try sema.errNote(block, init_src, msg, template, args); |
| 18374 | 18393 | } else { |
| ... | ... | @@ -18385,17 +18404,17 @@ fn finishStructInit( |
| 18385 | 18404 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 18386 | 18405 | if (field_inits[i] != .none) continue; |
| 18387 | 18406 | |
| 18388 | | if (field.default_val.toIntern() == .unreachable_value) { |
| 18407 | if (field.default_val == .none) { |
| 18389 | 18408 | const field_name = struct_obj.fields.keys()[i]; |
| 18390 | 18409 | const template = "missing struct field: {s}"; |
| 18391 | | const args = .{field_name}; |
| 18410 | const args = .{ip.stringToSlice(field_name)}; |
| 18392 | 18411 | if (root_msg) |msg| { |
| 18393 | 18412 | try sema.errNote(block, init_src, msg, template, args); |
| 18394 | 18413 | } else { |
| 18395 | 18414 | root_msg = try sema.errMsg(block, init_src, template, args); |
| 18396 | 18415 | } |
| 18397 | 18416 | } else { |
| 18398 | | field_inits[i] = try sema.addConstant(field.ty, field.default_val); |
| 18417 | field_inits[i] = try sema.addConstant(field.ty, field.default_val.toValue()); |
| 18399 | 18418 | } |
| 18400 | 18419 | } |
| 18401 | 18420 | }, |
| ... | ... | @@ -18404,10 +18423,9 @@ fn finishStructInit( |
| 18404 | 18423 | |
| 18405 | 18424 | if (root_msg) |msg| { |
| 18406 | 18425 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 18407 | | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); |
| 18408 | | defer gpa.free(fqn); |
| 18409 | | try sema.mod.errNoteNonLazy( |
| 18410 | | struct_obj.srcLoc(sema.mod), |
| 18426 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 18427 | try mod.errNoteNonLazy( |
| 18428 | struct_obj.srcLoc(mod), |
| 18411 | 18429 | msg, |
| 18412 | 18430 | "struct '{s}' declared here", |
| 18413 | 18431 | .{fqn}, |
| ... | ... | @@ -18826,11 +18844,13 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 18826 | 18844 | const ty_src = inst_data.src(); |
| 18827 | 18845 | const field_src = inst_data.src(); |
| 18828 | 18846 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 18829 | | const field_name = try sema.resolveConstString(block, field_src, extra.field_name, "field name must be comptime-known"); |
| 18847 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known"); |
| 18830 | 18848 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 18831 | 18849 | } |
| 18832 | 18850 | |
| 18833 | 18851 | fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 18852 | const mod = sema.mod; |
| 18853 | const ip = &mod.intern_pool; |
| 18834 | 18854 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 18835 | 18855 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 18836 | 18856 | const ty_src = inst_data.src(); |
| ... | ... | @@ -18843,7 +18863,8 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18843 | 18863 | error.GenericPoison => return Air.Inst.Ref.generic_poison_type, |
| 18844 | 18864 | else => |e| return e, |
| 18845 | 18865 | }; |
| 18846 | | const field_name = sema.code.nullTerminatedString(extra.name_start); |
| 18866 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); |
| 18867 | const field_name = try ip.getOrPutString(sema.gpa, zir_field_name); |
| 18847 | 18868 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); |
| 18848 | 18869 | } |
| 18849 | 18870 | |
| ... | ... | @@ -18851,7 +18872,7 @@ fn fieldType( |
| 18851 | 18872 | sema: *Sema, |
| 18852 | 18873 | block: *Block, |
| 18853 | 18874 | aggregate_ty: Type, |
| 18854 | | field_name: []const u8, |
| 18875 | field_name: InternPool.NullTerminatedString, |
| 18855 | 18876 | field_src: LazySrcLoc, |
| 18856 | 18877 | ty_src: LazySrcLoc, |
| 18857 | 18878 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -19050,13 +19071,14 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19050 | 19071 | const operand = try sema.resolveInst(inst_data.operand); |
| 19051 | 19072 | const operand_ty = sema.typeOf(operand); |
| 19052 | 19073 | const mod = sema.mod; |
| 19074 | const ip = &mod.intern_pool; |
| 19053 | 19075 | |
| 19054 | 19076 | try sema.resolveTypeLayout(operand_ty); |
| 19055 | 19077 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 19056 | 19078 | .EnumLiteral => { |
| 19057 | 19079 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); |
| 19058 | | const tag_name = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 19059 | | const bytes = mod.intern_pool.stringToSlice(tag_name); |
| 19080 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 19081 | const bytes = ip.stringToSlice(tag_name); |
| 19060 | 19082 | return sema.addStrLit(block, bytes); |
| 19061 | 19083 | }, |
| 19062 | 19084 | .Enum => operand_ty, |
| ... | ... | @@ -19089,7 +19111,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19089 | 19111 | const enum_decl = mod.declPtr(enum_decl_index); |
| 19090 | 19112 | const msg = msg: { |
| 19091 | 19113 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{s}'", .{ |
| 19092 | | val.fmtValue(enum_ty, sema.mod), enum_decl.name, |
| 19114 | val.fmtValue(enum_ty, sema.mod), ip.stringToSlice(enum_decl.name), |
| 19093 | 19115 | }); |
| 19094 | 19116 | errdefer msg.destroy(sema.gpa); |
| 19095 | 19117 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); |
| ... | ... | @@ -19098,7 +19120,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19098 | 19120 | return sema.failWithOwnedErrorMsg(msg); |
| 19099 | 19121 | }; |
| 19100 | 19122 | const field_name = enum_ty.enumFieldName(field_index, mod); |
| 19101 | | return sema.addStrLit(block, field_name); |
| 19123 | return sema.addStrLit(block, ip.stringToSlice(field_name)); |
| 19102 | 19124 | } |
| 19103 | 19125 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 19104 | 19126 | if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) { |
| ... | ... | @@ -19119,6 +19141,7 @@ fn zirReify( |
| 19119 | 19141 | ) CompileError!Air.Inst.Ref { |
| 19120 | 19142 | const mod = sema.mod; |
| 19121 | 19143 | const gpa = sema.gpa; |
| 19144 | const ip = &mod.intern_pool; |
| 19122 | 19145 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); |
| 19123 | 19146 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 19124 | 19147 | const src = LazySrcLoc.nodeOffset(extra.node); |
| ... | ... | @@ -19127,11 +19150,10 @@ fn zirReify( |
| 19127 | 19150 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 19128 | 19151 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 19129 | 19152 | const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known"); |
| 19130 | | const union_val = mod.intern_pool.indexToKey(val.toIntern()).un; |
| 19153 | const union_val = ip.indexToKey(val.toIntern()).un; |
| 19131 | 19154 | const target = mod.getTarget(); |
| 19132 | 19155 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); |
| 19133 | 19156 | const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?; |
| 19134 | | const ip = &mod.intern_pool; |
| 19135 | 19157 | switch (@intToEnum(std.builtin.TypeId, tag_index)) { |
| 19136 | 19158 | .Type => return Air.Inst.Ref.type_type, |
| 19137 | 19159 | .Void => return Air.Inst.Ref.void_type, |
| ... | ... | @@ -19145,8 +19167,14 @@ fn zirReify( |
| 19145 | 19167 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, |
| 19146 | 19168 | .Int => { |
| 19147 | 19169 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19148 | | const signedness_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("signedness").?); |
| 19149 | | const bits_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("bits").?); |
| 19170 | const signedness_val = try union_val.val.toValue().fieldValue( |
| 19171 | mod, |
| 19172 | fields.getIndex(try ip.getOrPutString(gpa, "signedness")).?, |
| 19173 | ); |
| 19174 | const bits_val = try union_val.val.toValue().fieldValue( |
| 19175 | mod, |
| 19176 | fields.getIndex(try ip.getOrPutString(gpa, "bits")).?, |
| 19177 | ); |
| 19150 | 19178 | |
| 19151 | 19179 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| 19152 | 19180 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| ... | ... | @@ -19155,8 +19183,12 @@ fn zirReify( |
| 19155 | 19183 | }, |
| 19156 | 19184 | .Vector => { |
| 19157 | 19185 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19158 | | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("len").?); |
| 19159 | | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); |
| 19186 | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19187 | try ip.getOrPutString(gpa, "len"), |
| 19188 | ).?); |
| 19189 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19190 | try ip.getOrPutString(gpa, "child"), |
| 19191 | ).?); |
| 19160 | 19192 | |
| 19161 | 19193 | const len = @intCast(u32, len_val.toUnsignedInt(mod)); |
| 19162 | 19194 | const child_ty = child_val.toType(); |
| ... | ... | @@ -19171,7 +19203,9 @@ fn zirReify( |
| 19171 | 19203 | }, |
| 19172 | 19204 | .Float => { |
| 19173 | 19205 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19174 | | const bits_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("bits").?); |
| 19206 | const bits_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19207 | try ip.getOrPutString(gpa, "bits"), |
| 19208 | ).?); |
| 19175 | 19209 | |
| 19176 | 19210 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| 19177 | 19211 | const ty = switch (bits) { |
| ... | ... | @@ -19186,14 +19220,30 @@ fn zirReify( |
| 19186 | 19220 | }, |
| 19187 | 19221 | .Pointer => { |
| 19188 | 19222 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19189 | | const size_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("size").?); |
| 19190 | | const is_const_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_const").?); |
| 19191 | | const is_volatile_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_volatile").?); |
| 19192 | | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("alignment").?); |
| 19193 | | const address_space_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("address_space").?); |
| 19194 | | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); |
| 19195 | | const is_allowzero_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_allowzero").?); |
| 19196 | | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("sentinel").?); |
| 19223 | const size_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19224 | try ip.getOrPutString(gpa, "size"), |
| 19225 | ).?); |
| 19226 | const is_const_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19227 | try ip.getOrPutString(gpa, "is_const"), |
| 19228 | ).?); |
| 19229 | const is_volatile_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19230 | try ip.getOrPutString(gpa, "is_volatile"), |
| 19231 | ).?); |
| 19232 | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19233 | try ip.getOrPutString(gpa, "alignment"), |
| 19234 | ).?); |
| 19235 | const address_space_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19236 | try ip.getOrPutString(gpa, "address_space"), |
| 19237 | ).?); |
| 19238 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19239 | try ip.getOrPutString(gpa, "child"), |
| 19240 | ).?); |
| 19241 | const is_allowzero_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19242 | try ip.getOrPutString(gpa, "is_allowzero"), |
| 19243 | ).?); |
| 19244 | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19245 | try ip.getOrPutString(gpa, "sentinel"), |
| 19246 | ).?); |
| 19197 | 19247 | |
| 19198 | 19248 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 19199 | 19249 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| ... | ... | @@ -19279,9 +19329,15 @@ fn zirReify( |
| 19279 | 19329 | }, |
| 19280 | 19330 | .Array => { |
| 19281 | 19331 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19282 | | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("len").?); |
| 19283 | | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); |
| 19284 | | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("sentinel").?); |
| 19332 | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19333 | try ip.getOrPutString(gpa, "len"), |
| 19334 | ).?); |
| 19335 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19336 | try ip.getOrPutString(gpa, "child"), |
| 19337 | ).?); |
| 19338 | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19339 | try ip.getOrPutString(gpa, "sentinel"), |
| 19340 | ).?); |
| 19285 | 19341 | |
| 19286 | 19342 | const len = len_val.toUnsignedInt(mod); |
| 19287 | 19343 | const child_ty = child_val.toType(); |
| ... | ... | @@ -19298,7 +19354,9 @@ fn zirReify( |
| 19298 | 19354 | }, |
| 19299 | 19355 | .Optional => { |
| 19300 | 19356 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19301 | | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); |
| 19357 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19358 | try ip.getOrPutString(gpa, "child"), |
| 19359 | ).?); |
| 19302 | 19360 | |
| 19303 | 19361 | const child_ty = child_val.toType(); |
| 19304 | 19362 | |
| ... | ... | @@ -19307,8 +19365,12 @@ fn zirReify( |
| 19307 | 19365 | }, |
| 19308 | 19366 | .ErrorUnion => { |
| 19309 | 19367 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19310 | | const error_set_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("error_set").?); |
| 19311 | | const payload_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("payload").?); |
| 19368 | const error_set_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19369 | try ip.getOrPutString(gpa, "error_set"), |
| 19370 | ).?); |
| 19371 | const payload_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19372 | try ip.getOrPutString(gpa, "payload"), |
| 19373 | ).?); |
| 19312 | 19374 | |
| 19313 | 19375 | const error_set_ty = error_set_val.toType(); |
| 19314 | 19376 | const payload_ty = payload_val.toType(); |
| ... | ... | @@ -19330,14 +19392,17 @@ fn zirReify( |
| 19330 | 19392 | for (0..len) |i| { |
| 19331 | 19393 | const elem_val = try payload_val.elemValue(mod, i); |
| 19332 | 19394 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19333 | | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex("name").?); |
| 19395 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19396 | try ip.getOrPutString(gpa, "name"), |
| 19397 | ).?); |
| 19334 | 19398 | |
| 19335 | | const name_str = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| 19336 | | const kv = try mod.getErrorValue(name_str); |
| 19337 | | const name_ip = try mod.intern_pool.getOrPutString(gpa, kv.key); |
| 19338 | | const gop = names.getOrPutAssumeCapacity(name_ip); |
| 19399 | const name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19400 | _ = try mod.getErrorValue(name); |
| 19401 | const gop = names.getOrPutAssumeCapacity(name); |
| 19339 | 19402 | if (gop.found_existing) { |
| 19340 | | return sema.fail(block, src, "duplicate error '{s}'", .{name_str}); |
| 19403 | return sema.fail(block, src, "duplicate error '{s}'", .{ |
| 19404 | ip.stringToSlice(name), |
| 19405 | }); |
| 19341 | 19406 | } |
| 19342 | 19407 | } |
| 19343 | 19408 | |
| ... | ... | @@ -19346,11 +19411,21 @@ fn zirReify( |
| 19346 | 19411 | }, |
| 19347 | 19412 | .Struct => { |
| 19348 | 19413 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19349 | | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("layout").?); |
| 19350 | | const backing_integer_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("backing_integer").?); |
| 19351 | | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); |
| 19352 | | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); |
| 19353 | | const is_tuple_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_tuple").?); |
| 19414 | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19415 | try ip.getOrPutString(gpa, "layout"), |
| 19416 | ).?); |
| 19417 | const backing_integer_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19418 | try ip.getOrPutString(gpa, "backing_integer"), |
| 19419 | ).?); |
| 19420 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19421 | try ip.getOrPutString(gpa, "fields"), |
| 19422 | ).?); |
| 19423 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19424 | try ip.getOrPutString(gpa, "decls"), |
| 19425 | ).?); |
| 19426 | const is_tuple_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19427 | try ip.getOrPutString(gpa, "is_tuple"), |
| 19428 | ).?); |
| 19354 | 19429 | |
| 19355 | 19430 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| 19356 | 19431 | |
| ... | ... | @@ -19367,10 +19442,18 @@ fn zirReify( |
| 19367 | 19442 | }, |
| 19368 | 19443 | .Enum => { |
| 19369 | 19444 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19370 | | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("tag_type").?); |
| 19371 | | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); |
| 19372 | | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); |
| 19373 | | const is_exhaustive_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_exhaustive").?); |
| 19445 | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19446 | try ip.getOrPutString(gpa, "tag_type"), |
| 19447 | ).?); |
| 19448 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19449 | try ip.getOrPutString(gpa, "fields"), |
| 19450 | ).?); |
| 19451 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19452 | try ip.getOrPutString(gpa, "decls"), |
| 19453 | ).?); |
| 19454 | const is_exhaustive_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19455 | try ip.getOrPutString(gpa, "is_exhaustive"), |
| 19456 | ).?); |
| 19374 | 19457 | |
| 19375 | 19458 | // Decls |
| 19376 | 19459 | if (decls_val.sliceLen(mod) > 0) { |
| ... | ... | @@ -19396,7 +19479,7 @@ fn zirReify( |
| 19396 | 19479 | |
| 19397 | 19480 | // Define our empty enum decl |
| 19398 | 19481 | const fields_len = @intCast(u32, try sema.usizeCast(block, src, fields_val.sliceLen(mod))); |
| 19399 | | const incomplete_enum = try mod.intern_pool.getIncompleteEnum(gpa, .{ |
| 19482 | const incomplete_enum = try ip.getIncompleteEnum(gpa, .{ |
| 19400 | 19483 | .decl = new_decl_index, |
| 19401 | 19484 | .namespace = .none, |
| 19402 | 19485 | .fields_len = fields_len, |
| ... | ... | @@ -19407,35 +19490,36 @@ fn zirReify( |
| 19407 | 19490 | .explicit, |
| 19408 | 19491 | .tag_ty = int_tag_ty.toIntern(), |
| 19409 | 19492 | }); |
| 19410 | | errdefer mod.intern_pool.remove(incomplete_enum.index); |
| 19493 | errdefer ip.remove(incomplete_enum.index); |
| 19411 | 19494 | |
| 19412 | 19495 | new_decl.val = incomplete_enum.index.toValue(); |
| 19413 | 19496 | |
| 19414 | 19497 | for (0..fields_len) |field_i| { |
| 19415 | 19498 | const elem_val = try fields_val.elemValue(mod, field_i); |
| 19416 | 19499 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19417 | | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex("name").?); |
| 19418 | | const value_val = try elem_val.fieldValue(mod, elem_fields.getIndex("value").?); |
| 19500 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19501 | try ip.getOrPutString(gpa, "name"), |
| 19502 | ).?); |
| 19503 | const value_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19504 | try ip.getOrPutString(gpa, "value"), |
| 19505 | ).?); |
| 19419 | 19506 | |
| 19420 | | const field_name = try name_val.toAllocatedBytes( |
| 19421 | | Type.slice_const_u8, |
| 19422 | | sema.arena, |
| 19423 | | mod, |
| 19424 | | ); |
| 19425 | | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); |
| 19507 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19426 | 19508 | |
| 19427 | 19509 | if (!try sema.intFitsInType(value_val, int_tag_ty, null)) { |
| 19428 | 19510 | // TODO: better source location |
| 19429 | 19511 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ |
| 19430 | | field_name, |
| 19512 | ip.stringToSlice(field_name), |
| 19431 | 19513 | value_val.fmtValue(Type.comptime_int, mod), |
| 19432 | 19514 | int_tag_ty.fmt(mod), |
| 19433 | 19515 | }); |
| 19434 | 19516 | } |
| 19435 | 19517 | |
| 19436 | | if (try incomplete_enum.addFieldName(&mod.intern_pool, gpa, field_name_ip)) |other_index| { |
| 19518 | if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| { |
| 19437 | 19519 | const msg = msg: { |
| 19438 | | const msg = try sema.errMsg(block, src, "duplicate enum field '{s}'", .{field_name}); |
| 19520 | const msg = try sema.errMsg(block, src, "duplicate enum field '{s}'", .{ |
| 19521 | ip.stringToSlice(field_name), |
| 19522 | }); |
| 19439 | 19523 | errdefer msg.destroy(gpa); |
| 19440 | 19524 | _ = other_index; // TODO: this note is incorrect |
| 19441 | 19525 | try sema.errNote(block, src, msg, "other field here", .{}); |
| ... | ... | @@ -19444,7 +19528,7 @@ fn zirReify( |
| 19444 | 19528 | return sema.failWithOwnedErrorMsg(msg); |
| 19445 | 19529 | } |
| 19446 | 19530 | |
| 19447 | | if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, (try mod.getCoerced(value_val, int_tag_ty)).toIntern())) |other| { |
| 19531 | if (try incomplete_enum.addFieldValue(ip, gpa, (try mod.getCoerced(value_val, int_tag_ty)).toIntern())) |other| { |
| 19448 | 19532 | const msg = msg: { |
| 19449 | 19533 | const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{value_val.fmtValue(Type.comptime_int, mod)}); |
| 19450 | 19534 | errdefer msg.destroy(gpa); |
| ... | ... | @@ -19462,7 +19546,9 @@ fn zirReify( |
| 19462 | 19546 | }, |
| 19463 | 19547 | .Opaque => { |
| 19464 | 19548 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19465 | | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); |
| 19549 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19550 | try ip.getOrPutString(gpa, "decls"), |
| 19551 | ).?); |
| 19466 | 19552 | |
| 19467 | 19553 | // Decls |
| 19468 | 19554 | if (decls_val.sliceLen(mod) > 0) { |
| ... | ... | @@ -19496,22 +19582,29 @@ fn zirReify( |
| 19496 | 19582 | .decl = new_decl_index, |
| 19497 | 19583 | .namespace = new_namespace_index, |
| 19498 | 19584 | } }); |
| 19499 | | errdefer mod.intern_pool.remove(opaque_ty); |
| 19585 | errdefer ip.remove(opaque_ty); |
| 19500 | 19586 | |
| 19501 | 19587 | new_decl.val = opaque_ty.toValue(); |
| 19502 | 19588 | new_namespace.ty = opaque_ty.toType(); |
| 19503 | 19589 | |
| 19504 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 19505 | 19590 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 19506 | 19591 | try mod.finalizeAnonDecl(new_decl_index); |
| 19507 | 19592 | return decl_val; |
| 19508 | 19593 | }, |
| 19509 | 19594 | .Union => { |
| 19510 | 19595 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19511 | | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("layout").?); |
| 19512 | | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("tag_type").?); |
| 19513 | | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); |
| 19514 | | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); |
| 19596 | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19597 | try ip.getOrPutString(gpa, "layout"), |
| 19598 | ).?); |
| 19599 | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19600 | try ip.getOrPutString(gpa, "tag_type"), |
| 19601 | ).?); |
| 19602 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19603 | try ip.getOrPutString(gpa, "fields"), |
| 19604 | ).?); |
| 19605 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19606 | try ip.getOrPutString(gpa, "decls"), |
| 19607 | ).?); |
| 19515 | 19608 | |
| 19516 | 19609 | // Decls |
| 19517 | 19610 | if (decls_val.sliceLen(mod) > 0) { |
| ... | ... | @@ -19555,7 +19648,7 @@ fn zirReify( |
| 19555 | 19648 | const union_obj = mod.unionPtr(union_index); |
| 19556 | 19649 | errdefer mod.destroyUnion(union_index); |
| 19557 | 19650 | |
| 19558 | | const union_ty = try mod.intern_pool.get(gpa, .{ .union_type = .{ |
| 19651 | const union_ty = try ip.get(gpa, .{ .union_type = .{ |
| 19559 | 19652 | .index = union_index, |
| 19560 | 19653 | .runtime_tag = if (!tag_type_val.isNull(mod)) |
| 19561 | 19654 | .tagged |
| ... | ... | @@ -19566,7 +19659,7 @@ fn zirReify( |
| 19566 | 19659 | .ReleaseFast, .ReleaseSmall => .none, |
| 19567 | 19660 | }, |
| 19568 | 19661 | } }); |
| 19569 | | errdefer mod.intern_pool.remove(union_ty); |
| 19662 | errdefer ip.remove(union_ty); |
| 19570 | 19663 | |
| 19571 | 19664 | new_decl.val = union_ty.toValue(); |
| 19572 | 19665 | new_namespace.ty = union_ty.toType(); |
| ... | ... | @@ -19579,7 +19672,7 @@ fn zirReify( |
| 19579 | 19672 | if (tag_type_val.optionalValue(mod)) |payload_val| { |
| 19580 | 19673 | union_obj.tag_ty = payload_val.toType(); |
| 19581 | 19674 | |
| 19582 | | const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.toIntern())) { |
| 19675 | const enum_type = switch (ip.indexToKey(union_obj.tag_ty.toIntern())) { |
| 19583 | 19676 | .enum_type => |x| x, |
| 19584 | 19677 | else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}), |
| 19585 | 19678 | }; |
| ... | ... | @@ -19597,26 +19690,26 @@ fn zirReify( |
| 19597 | 19690 | for (0..fields_len) |i| { |
| 19598 | 19691 | const elem_val = try fields_val.elemValue(mod, i); |
| 19599 | 19692 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19600 | | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex("name").?); |
| 19601 | | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); |
| 19602 | | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex("alignment").?); |
| 19603 | | |
| 19604 | | const field_name = try name_val.toAllocatedBytes( |
| 19605 | | Type.slice_const_u8, |
| 19606 | | new_decl_arena_allocator, |
| 19607 | | mod, |
| 19608 | | ); |
| 19609 | | |
| 19610 | | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); |
| 19693 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19694 | try ip.getOrPutString(gpa, "name"), |
| 19695 | ).?); |
| 19696 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19697 | try ip.getOrPutString(gpa, "type"), |
| 19698 | ).?); |
| 19699 | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19700 | try ip.getOrPutString(gpa, "alignment"), |
| 19701 | ).?); |
| 19702 | |
| 19703 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19611 | 19704 | |
| 19612 | 19705 | if (enum_field_names.len != 0) { |
| 19613 | | enum_field_names[i] = field_name_ip; |
| 19706 | enum_field_names[i] = field_name; |
| 19614 | 19707 | } |
| 19615 | 19708 | |
| 19616 | 19709 | if (explicit_enum_info) |tag_info| { |
| 19617 | | const enum_index = tag_info.nameIndex(&mod.intern_pool, field_name_ip) orelse { |
| 19710 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 19618 | 19711 | const msg = msg: { |
| 19619 | | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) }); |
| 19712 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod) }); |
| 19620 | 19713 | errdefer msg.destroy(gpa); |
| 19621 | 19714 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 19622 | 19715 | break :msg msg; |
| ... | ... | @@ -19632,7 +19725,7 @@ fn zirReify( |
| 19632 | 19725 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); |
| 19633 | 19726 | if (gop.found_existing) { |
| 19634 | 19727 | // TODO: better source location |
| 19635 | | return sema.fail(block, src, "duplicate union field {s}", .{field_name}); |
| 19728 | return sema.fail(block, src, "duplicate union field {s}", .{ip.stringToSlice(field_name)}); |
| 19636 | 19729 | } |
| 19637 | 19730 | |
| 19638 | 19731 | const field_ty = type_val.toType(); |
| ... | ... | @@ -19688,7 +19781,7 @@ fn zirReify( |
| 19688 | 19781 | for (tag_info.names, 0..) |field_name, field_index| { |
| 19689 | 19782 | if (explicit_tags_seen[field_index]) continue; |
| 19690 | 19783 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ |
| 19691 | | mod.intern_pool.stringToSlice(field_name), |
| 19784 | ip.stringToSlice(field_name), |
| 19692 | 19785 | }); |
| 19693 | 19786 | } |
| 19694 | 19787 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | ... | @@ -19700,19 +19793,30 @@ fn zirReify( |
| 19700 | 19793 | union_obj.tag_ty = try sema.generateUnionTagTypeSimple(block, enum_field_names, null); |
| 19701 | 19794 | } |
| 19702 | 19795 | |
| 19703 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 19704 | 19796 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 19705 | 19797 | try mod.finalizeAnonDecl(new_decl_index); |
| 19706 | 19798 | return decl_val; |
| 19707 | 19799 | }, |
| 19708 | 19800 | .Fn => { |
| 19709 | 19801 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 19710 | | const calling_convention_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("calling_convention").?); |
| 19711 | | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("alignment").?); |
| 19712 | | const is_generic_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_generic").?); |
| 19713 | | const is_var_args_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_var_args").?); |
| 19714 | | const return_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("return_type").?); |
| 19715 | | const params_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("params").?); |
| 19802 | const calling_convention_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19803 | try ip.getOrPutString(gpa, "calling_convention"), |
| 19804 | ).?); |
| 19805 | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19806 | try ip.getOrPutString(gpa, "alignment"), |
| 19807 | ).?); |
| 19808 | const is_generic_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19809 | try ip.getOrPutString(gpa, "is_generic"), |
| 19810 | ).?); |
| 19811 | const is_var_args_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19812 | try ip.getOrPutString(gpa, "is_var_args"), |
| 19813 | ).?); |
| 19814 | const return_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19815 | try ip.getOrPutString(gpa, "return_type"), |
| 19816 | ).?); |
| 19817 | const params_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19818 | try ip.getOrPutString(gpa, "params"), |
| 19819 | ).?); |
| 19716 | 19820 | |
| 19717 | 19821 | const is_generic = is_generic_val.toBool(); |
| 19718 | 19822 | if (is_generic) { |
| ... | ... | @@ -19746,9 +19850,15 @@ fn zirReify( |
| 19746 | 19850 | for (param_types, 0..) |*param_type, i| { |
| 19747 | 19851 | const elem_val = try params_val.elemValue(mod, i); |
| 19748 | 19852 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19749 | | const param_is_generic_val = try elem_val.fieldValue(mod, elem_fields.getIndex("is_generic").?); |
| 19750 | | const param_is_noalias_val = try elem_val.fieldValue(mod, elem_fields.getIndex("is_noalias").?); |
| 19751 | | const opt_param_type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); |
| 19853 | const param_is_generic_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19854 | try ip.getOrPutString(gpa, "is_generic"), |
| 19855 | ).?); |
| 19856 | const param_is_noalias_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19857 | try ip.getOrPutString(gpa, "is_noalias"), |
| 19858 | ).?); |
| 19859 | const opt_param_type_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19860 | try ip.getOrPutString(gpa, "type"), |
| 19861 | ).?); |
| 19752 | 19862 | |
| 19753 | 19863 | if (param_is_generic_val.toBool()) { |
| 19754 | 19864 | return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{}); |
| ... | ... | @@ -19801,6 +19911,7 @@ fn reifyStruct( |
| 19801 | 19911 | ) CompileError!Air.Inst.Ref { |
| 19802 | 19912 | const mod = sema.mod; |
| 19803 | 19913 | const gpa = sema.gpa; |
| 19914 | const ip = &mod.intern_pool; |
| 19804 | 19915 | |
| 19805 | 19916 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19806 | 19917 | errdefer new_decl_arena.deinit(); |
| ... | ... | @@ -19839,11 +19950,11 @@ fn reifyStruct( |
| 19839 | 19950 | const struct_obj = mod.structPtr(struct_index); |
| 19840 | 19951 | errdefer mod.destroyStruct(struct_index); |
| 19841 | 19952 | |
| 19842 | | const struct_ty = try mod.intern_pool.get(gpa, .{ .struct_type = .{ |
| 19953 | const struct_ty = try ip.get(gpa, .{ .struct_type = .{ |
| 19843 | 19954 | .index = struct_index.toOptional(), |
| 19844 | 19955 | .namespace = new_namespace_index.toOptional(), |
| 19845 | 19956 | } }); |
| 19846 | | errdefer mod.intern_pool.remove(struct_ty); |
| 19957 | errdefer ip.remove(struct_ty); |
| 19847 | 19958 | |
| 19848 | 19959 | new_decl.val = struct_ty.toValue(); |
| 19849 | 19960 | new_namespace.ty = struct_ty.toType(); |
| ... | ... | @@ -19854,12 +19965,22 @@ fn reifyStruct( |
| 19854 | 19965 | var i: usize = 0; |
| 19855 | 19966 | while (i < fields_len) : (i += 1) { |
| 19856 | 19967 | const elem_val = try fields_val.elemValue(mod, i); |
| 19857 | | const elem_fields = mod.intern_pool.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19858 | | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex("name").?); |
| 19859 | | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); |
| 19860 | | const default_value_val = try elem_val.fieldValue(mod, elem_fields.getIndex("default_value").?); |
| 19861 | | const is_comptime_val = try elem_val.fieldValue(mod, elem_fields.getIndex("is_comptime").?); |
| 19862 | | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex("alignment").?); |
| 19968 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19969 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19970 | try ip.getOrPutString(gpa, "name"), |
| 19971 | ).?); |
| 19972 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19973 | try ip.getOrPutString(gpa, "type"), |
| 19974 | ).?); |
| 19975 | const default_value_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19976 | try ip.getOrPutString(gpa, "default_value"), |
| 19977 | ).?); |
| 19978 | const is_comptime_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19979 | try ip.getOrPutString(gpa, "is_comptime"), |
| 19980 | ).?); |
| 19981 | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19982 | try ip.getOrPutString(gpa, "alignment"), |
| 19983 | ).?); |
| 19863 | 19984 | |
| 19864 | 19985 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 19865 | 19986 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| ... | ... | @@ -19874,19 +19995,15 @@ fn reifyStruct( |
| 19874 | 19995 | return sema.fail(block, src, "extern struct fields cannot be marked comptime", .{}); |
| 19875 | 19996 | } |
| 19876 | 19997 | |
| 19877 | | const field_name = try name_val.toAllocatedBytes( |
| 19878 | | Type.slice_const_u8, |
| 19879 | | new_decl_arena_allocator, |
| 19880 | | mod, |
| 19881 | | ); |
| 19998 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19882 | 19999 | |
| 19883 | 20000 | if (is_tuple) { |
| 19884 | | const field_index = std.fmt.parseUnsigned(u32, field_name, 10) catch { |
| 20001 | const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch { |
| 19885 | 20002 | return sema.fail( |
| 19886 | 20003 | block, |
| 19887 | 20004 | src, |
| 19888 | 20005 | "tuple cannot have non-numeric field '{s}'", |
| 19889 | | .{field_name}, |
| 20006 | .{ip.stringToSlice(field_name)}, |
| 19890 | 20007 | ); |
| 19891 | 20008 | }; |
| 19892 | 20009 | |
| ... | ... | @@ -19902,16 +20019,16 @@ fn reifyStruct( |
| 19902 | 20019 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 19903 | 20020 | if (gop.found_existing) { |
| 19904 | 20021 | // TODO: better source location |
| 19905 | | return sema.fail(block, src, "duplicate struct field {s}", .{field_name}); |
| 20022 | return sema.fail(block, src, "duplicate struct field {s}", .{ip.stringToSlice(field_name)}); |
| 19906 | 20023 | } |
| 19907 | 20024 | |
| 19908 | 20025 | const field_ty = type_val.toType(); |
| 19909 | 20026 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| |
| 19910 | | try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse |
| 19911 | | return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known") |
| 20027 | (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse |
| 20028 | return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern() |
| 19912 | 20029 | else |
| 19913 | | Value.@"unreachable"; |
| 19914 | | if (is_comptime_val.toBool() and default_val.toIntern() == .unreachable_value) { |
| 20030 | .none; |
| 20031 | if (is_comptime_val.toBool() and default_val == .none) { |
| 19915 | 20032 | return sema.fail(block, src, "comptime field without default initialization value", .{}); |
| 19916 | 20033 | } |
| 19917 | 20034 | |
| ... | ... | @@ -20000,7 +20117,6 @@ fn reifyStruct( |
| 20000 | 20117 | struct_obj.status = .have_layout; |
| 20001 | 20118 | } |
| 20002 | 20119 | |
| 20003 | | try new_decl.finalizeNewArena(&new_decl_arena); |
| 20004 | 20120 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 20005 | 20121 | try mod.finalizeAnonDecl(new_decl_index); |
| 20006 | 20122 | return decl_val; |
| ... | ... | @@ -20871,7 +20987,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20871 | 20987 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 20872 | 20988 | |
| 20873 | 20989 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| 20874 | | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime-known"); |
| 20990 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known"); |
| 20875 | 20991 | |
| 20876 | 20992 | const mod = sema.mod; |
| 20877 | 20993 | try sema.resolveTypeLayout(ty); |
| ... | ... | @@ -20889,7 +21005,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20889 | 21005 | } |
| 20890 | 21006 | |
| 20891 | 21007 | const field_index = if (ty.isTuple(mod)) blk: { |
| 20892 | | if (mem.eql(u8, field_name, "len")) { |
| 21008 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { |
| 20893 | 21009 | return sema.fail(block, src, "no offset available for 'len' field of tuple", .{}); |
| 20894 | 21010 | } |
| 20895 | 21011 | break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src); |
| ... | ... | @@ -21351,6 +21467,8 @@ fn resolveExportOptions( |
| 21351 | 21467 | zir_ref: Zir.Inst.Ref, |
| 21352 | 21468 | ) CompileError!std.builtin.ExportOptions { |
| 21353 | 21469 | const mod = sema.mod; |
| 21470 | const gpa = sema.gpa; |
| 21471 | const ip = &mod.intern_pool; |
| 21354 | 21472 | const export_options_ty = try sema.getBuiltinType("ExportOptions"); |
| 21355 | 21473 | const air_ref = try sema.resolveInst(zir_ref); |
| 21356 | 21474 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| ... | ... | @@ -21360,16 +21478,16 @@ fn resolveExportOptions( |
| 21360 | 21478 | const section_src = sema.maybeOptionsSrc(block, src, "section"); |
| 21361 | 21479 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 21362 | 21480 | |
| 21363 | | const name_operand = try sema.fieldVal(block, src, options, "name", name_src); |
| 21481 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 21364 | 21482 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known"); |
| 21365 | 21483 | const name_ty = Type.slice_const_u8; |
| 21366 | 21484 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); |
| 21367 | 21485 | |
| 21368 | | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", linkage_src); |
| 21486 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 21369 | 21487 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); |
| 21370 | 21488 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 21371 | 21489 | |
| 21372 | | const section_operand = try sema.fieldVal(block, src, options, "section", section_src); |
| 21490 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); |
| 21373 | 21491 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); |
| 21374 | 21492 | const section_ty = Type.slice_const_u8; |
| 21375 | 21493 | const section = if (section_opt_val.optionalValue(mod)) |section_val| |
| ... | ... | @@ -21377,7 +21495,7 @@ fn resolveExportOptions( |
| 21377 | 21495 | else |
| 21378 | 21496 | null; |
| 21379 | 21497 | |
| 21380 | | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", visibility_src); |
| 21498 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); |
| 21381 | 21499 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); |
| 21382 | 21500 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| 21383 | 21501 | |
| ... | ... | @@ -22217,10 +22335,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22217 | 22335 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 22218 | 22336 | |
| 22219 | 22337 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); |
| 22220 | | const field_name = try sema.resolveConstString(block, name_src, extra.field_name, "field name must be comptime-known"); |
| 22338 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, "field name must be comptime-known"); |
| 22221 | 22339 | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 22222 | 22340 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 22223 | 22341 | const mod = sema.mod; |
| 22342 | const ip = &mod.intern_pool; |
| 22224 | 22343 | |
| 22225 | 22344 | if (parent_ty.zigTypeTag(mod) != .Struct and parent_ty.zigTypeTag(mod) != .Union) { |
| 22226 | 22345 | return sema.fail(block, ty_src, "expected struct or union type, found '{}'", .{parent_ty.fmt(sema.mod)}); |
| ... | ... | @@ -22230,7 +22349,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22230 | 22349 | const field_index = switch (parent_ty.zigTypeTag(mod)) { |
| 22231 | 22350 | .Struct => blk: { |
| 22232 | 22351 | if (parent_ty.isTuple(mod)) { |
| 22233 | | if (mem.eql(u8, field_name, "len")) { |
| 22352 | if (ip.stringEqlSlice(field_name, "len")) { |
| 22234 | 22353 | return sema.fail(block, src, "cannot get @fieldParentPtr of 'len' field of tuple", .{}); |
| 22235 | 22354 | } |
| 22236 | 22355 | break :blk try sema.tupleFieldIndex(block, parent_ty, field_name, name_src); |
| ... | ... | @@ -22276,7 +22395,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22276 | 22395 | const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); |
| 22277 | 22396 | |
| 22278 | 22397 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { |
| 22279 | | const field = switch (mod.intern_pool.indexToKey(field_ptr_val.toIntern())) { |
| 22398 | const field = switch (ip.indexToKey(field_ptr_val.toIntern())) { |
| 22280 | 22399 | .ptr => |ptr| switch (ptr.addr) { |
| 22281 | 22400 | .field => |field| field, |
| 22282 | 22401 | else => null, |
| ... | ... | @@ -22291,7 +22410,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22291 | 22410 | src, |
| 22292 | 22411 | "field '{s}' has index '{d}' but pointer value is index '{d}' of struct '{}'", |
| 22293 | 22412 | .{ |
| 22294 | | field_name, |
| 22413 | ip.stringToSlice(field_name), |
| 22295 | 22414 | field_index, |
| 22296 | 22415 | field.index, |
| 22297 | 22416 | parent_ty.fmt(sema.mod), |
| ... | ... | @@ -22807,6 +22926,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 22807 | 22926 | |
| 22808 | 22927 | fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 22809 | 22928 | const mod = sema.mod; |
| 22929 | const gpa = sema.gpa; |
| 22930 | const ip = &mod.intern_pool; |
| 22810 | 22931 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 22811 | 22932 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22812 | 22933 | const src = inst_data.src(); |
| ... | ... | @@ -22824,7 +22945,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 22824 | 22945 | const dest_elem_ty = dest_ptr_ty.elemType2(mod); |
| 22825 | 22946 | |
| 22826 | 22947 | const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: { |
| 22827 | | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, "len", dest_src); |
| 22948 | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len"), dest_src); |
| 22828 | 22949 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse |
| 22829 | 22950 | break :rs dest_src; |
| 22830 | 22951 | const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?; |
| ... | ... | @@ -23068,11 +23189,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23068 | 23189 | if (val.isGenericPoison()) { |
| 23069 | 23190 | break :blk FuncLinkSection{ .generic = {} }; |
| 23070 | 23191 | } |
| 23071 | | break :blk FuncLinkSection{ .explicit = try val.toAllocatedBytes(ty, sema.arena, sema.mod) }; |
| 23192 | break :blk FuncLinkSection{ .explicit = try val.toIpString(ty, mod) }; |
| 23072 | 23193 | } else if (extra.data.bits.has_section_ref) blk: { |
| 23073 | 23194 | const section_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 23074 | 23195 | extra_index += 1; |
| 23075 | | const section_name = sema.resolveConstString(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) { |
| 23196 | const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) { |
| 23076 | 23197 | error.GenericPoison => { |
| 23077 | 23198 | break :blk FuncLinkSection{ .generic = {} }; |
| 23078 | 23199 | }, |
| ... | ... | @@ -23272,6 +23393,8 @@ fn resolvePrefetchOptions( |
| 23272 | 23393 | zir_ref: Zir.Inst.Ref, |
| 23273 | 23394 | ) CompileError!std.builtin.PrefetchOptions { |
| 23274 | 23395 | const mod = sema.mod; |
| 23396 | const gpa = sema.gpa; |
| 23397 | const ip = &mod.intern_pool; |
| 23275 | 23398 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 23276 | 23399 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 23277 | 23400 | |
| ... | ... | @@ -23279,13 +23402,13 @@ fn resolvePrefetchOptions( |
| 23279 | 23402 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); |
| 23280 | 23403 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 23281 | 23404 | |
| 23282 | | const rw = try sema.fieldVal(block, src, options, "rw", rw_src); |
| 23405 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); |
| 23283 | 23406 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known"); |
| 23284 | 23407 | |
| 23285 | | const locality = try sema.fieldVal(block, src, options, "locality", locality_src); |
| 23408 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); |
| 23286 | 23409 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known"); |
| 23287 | 23410 | |
| 23288 | | const cache = try sema.fieldVal(block, src, options, "cache", cache_src); |
| 23411 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); |
| 23289 | 23412 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); |
| 23290 | 23413 | |
| 23291 | 23414 | return std.builtin.PrefetchOptions{ |
| ... | ... | @@ -23336,6 +23459,8 @@ fn resolveExternOptions( |
| 23336 | 23459 | zir_ref: Zir.Inst.Ref, |
| 23337 | 23460 | ) CompileError!std.builtin.ExternOptions { |
| 23338 | 23461 | const mod = sema.mod; |
| 23462 | const gpa = sema.gpa; |
| 23463 | const ip = &mod.intern_pool; |
| 23339 | 23464 | const options_inst = try sema.resolveInst(zir_ref); |
| 23340 | 23465 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 23341 | 23466 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| ... | ... | @@ -23345,18 +23470,18 @@ fn resolveExternOptions( |
| 23345 | 23470 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); |
| 23346 | 23471 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 23347 | 23472 | |
| 23348 | | const name_ref = try sema.fieldVal(block, src, options, "name", name_src); |
| 23473 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 23349 | 23474 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known"); |
| 23350 | 23475 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| 23351 | 23476 | |
| 23352 | | const library_name_inst = try sema.fieldVal(block, src, options, "library_name", library_src); |
| 23477 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); |
| 23353 | 23478 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known"); |
| 23354 | 23479 | |
| 23355 | | const linkage_ref = try sema.fieldVal(block, src, options, "linkage", linkage_src); |
| 23480 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 23356 | 23481 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); |
| 23357 | 23482 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 23358 | 23483 | |
| 23359 | | const is_thread_local = try sema.fieldVal(block, src, options, "is_thread_local", thread_local_src); |
| 23484 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); |
| 23360 | 23485 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); |
| 23361 | 23486 | |
| 23362 | 23487 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { |
| ... | ... | @@ -23425,7 +23550,7 @@ fn zirBuiltinExtern( |
| 23425 | 23550 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); |
| 23426 | 23551 | errdefer mod.destroyDecl(new_decl_index); |
| 23427 | 23552 | const new_decl = mod.declPtr(new_decl_index); |
| 23428 | | new_decl.name = try sema.gpa.dupeZ(u8, options.name); |
| 23553 | new_decl.name = try mod.intern_pool.getOrPutString(sema.gpa, options.name); |
| 23429 | 23554 | |
| 23430 | 23555 | { |
| 23431 | 23556 | const new_var = try mod.intern(.{ .variable = .{ |
| ... | ... | @@ -23444,7 +23569,7 @@ fn zirBuiltinExtern( |
| 23444 | 23569 | new_decl.ty = ty; |
| 23445 | 23570 | new_decl.val = new_var.toValue(); |
| 23446 | 23571 | new_decl.@"align" = 0; |
| 23447 | | new_decl.@"linksection" = null; |
| 23572 | new_decl.@"linksection" = .none; |
| 23448 | 23573 | new_decl.has_tv = true; |
| 23449 | 23574 | new_decl.analysis = .complete; |
| 23450 | 23575 | new_decl.generation = mod.generation; |
| ... | ... | @@ -24265,12 +24390,13 @@ fn safetyPanic( |
| 24265 | 24390 | panic_id: PanicId, |
| 24266 | 24391 | ) CompileError!void { |
| 24267 | 24392 | const mod = sema.mod; |
| 24393 | const gpa = sema.gpa; |
| 24268 | 24394 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 24269 | 24395 | const msg_decl_index = (try sema.namespaceLookup( |
| 24270 | 24396 | block, |
| 24271 | 24397 | sema.src, |
| 24272 | 24398 | panic_messages_ty.getNamespaceIndex(mod).unwrap().?, |
| 24273 | | @tagName(panic_id), |
| 24399 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)), |
| 24274 | 24400 | )).?; |
| 24275 | 24401 | |
| 24276 | 24402 | const msg_inst = try sema.analyzeDeclVal(block, sema.src, msg_decl_index); |
| ... | ... | @@ -24302,14 +24428,13 @@ fn fieldVal( |
| 24302 | 24428 | block: *Block, |
| 24303 | 24429 | src: LazySrcLoc, |
| 24304 | 24430 | object: Air.Inst.Ref, |
| 24305 | | field_name: []const u8, |
| 24431 | field_name: InternPool.NullTerminatedString, |
| 24306 | 24432 | field_name_src: LazySrcLoc, |
| 24307 | 24433 | ) CompileError!Air.Inst.Ref { |
| 24308 | 24434 | // When editing this function, note that there is corresponding logic to be edited |
| 24309 | 24435 | // in `fieldPtr`. This function takes a value and returns a value. |
| 24310 | 24436 | |
| 24311 | 24437 | const mod = sema.mod; |
| 24312 | | const gpa = sema.gpa; |
| 24313 | 24438 | const ip = &mod.intern_pool; |
| 24314 | 24439 | const object_src = src; // TODO better source location |
| 24315 | 24440 | const object_ty = sema.typeOf(object); |
| ... | ... | @@ -24326,12 +24451,12 @@ fn fieldVal( |
| 24326 | 24451 | |
| 24327 | 24452 | switch (inner_ty.zigTypeTag(mod)) { |
| 24328 | 24453 | .Array => { |
| 24329 | | if (mem.eql(u8, field_name, "len")) { |
| 24454 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24330 | 24455 | return sema.addConstant( |
| 24331 | 24456 | Type.usize, |
| 24332 | 24457 | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), |
| 24333 | 24458 | ); |
| 24334 | | } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) { |
| 24459 | } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) { |
| 24335 | 24460 | const ptr_info = object_ty.ptrInfo(mod); |
| 24336 | 24461 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24337 | 24462 | .pointee_type = ptr_info.pointee_type.childType(mod), |
| ... | ... | @@ -24352,20 +24477,20 @@ fn fieldVal( |
| 24352 | 24477 | block, |
| 24353 | 24478 | field_name_src, |
| 24354 | 24479 | "no member named '{s}' in '{}'", |
| 24355 | | .{ field_name, object_ty.fmt(mod) }, |
| 24480 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, |
| 24356 | 24481 | ); |
| 24357 | 24482 | } |
| 24358 | 24483 | }, |
| 24359 | 24484 | .Pointer => { |
| 24360 | 24485 | const ptr_info = inner_ty.ptrInfo(mod); |
| 24361 | 24486 | if (ptr_info.size == .Slice) { |
| 24362 | | if (mem.eql(u8, field_name, "ptr")) { |
| 24487 | if (ip.stringEqlSlice(field_name, "ptr")) { |
| 24363 | 24488 | const slice = if (is_pointer_to) |
| 24364 | 24489 | try sema.analyzeLoad(block, src, object, object_src) |
| 24365 | 24490 | else |
| 24366 | 24491 | object; |
| 24367 | 24492 | return sema.analyzeSlicePtr(block, object_src, slice, inner_ty); |
| 24368 | | } else if (mem.eql(u8, field_name, "len")) { |
| 24493 | } else if (ip.stringEqlSlice(field_name, "len")) { |
| 24369 | 24494 | const slice = if (is_pointer_to) |
| 24370 | 24495 | try sema.analyzeLoad(block, src, object, object_src) |
| 24371 | 24496 | else |
| ... | ... | @@ -24376,7 +24501,7 @@ fn fieldVal( |
| 24376 | 24501 | block, |
| 24377 | 24502 | field_name_src, |
| 24378 | 24503 | "no member named '{s}' in '{}'", |
| 24379 | | .{ field_name, object_ty.fmt(mod) }, |
| 24504 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, |
| 24380 | 24505 | ); |
| 24381 | 24506 | } |
| 24382 | 24507 | } |
| ... | ... | @@ -24392,13 +24517,12 @@ fn fieldVal( |
| 24392 | 24517 | |
| 24393 | 24518 | switch (try child_type.zigTypeTagOrPoison(mod)) { |
| 24394 | 24519 | .ErrorSet => { |
| 24395 | | const name = try ip.getOrPutString(gpa, field_name); |
| 24396 | 24520 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24397 | 24521 | .error_set_type => |error_set_type| blk: { |
| 24398 | | if (error_set_type.nameIndex(ip, name) != null) break :blk; |
| 24522 | if (error_set_type.nameIndex(ip, field_name) != null) break :blk; |
| 24399 | 24523 | const msg = msg: { |
| 24400 | 24524 | const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{ |
| 24401 | | field_name, child_type.fmt(mod), |
| 24525 | ip.stringToSlice(field_name), child_type.fmt(mod), |
| 24402 | 24526 | }); |
| 24403 | 24527 | errdefer msg.destroy(sema.gpa); |
| 24404 | 24528 | try sema.addDeclaredHereNote(msg, child_type); |
| ... | ... | @@ -24419,10 +24543,10 @@ fn fieldVal( |
| 24419 | 24543 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24420 | 24544 | child_type |
| 24421 | 24545 | else |
| 24422 | | try mod.singleErrorSetTypeNts(name); |
| 24546 | try mod.singleErrorSetTypeNts(field_name); |
| 24423 | 24547 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 24424 | 24548 | .ty = error_set_type.toIntern(), |
| 24425 | | .name = name, |
| 24549 | .name = field_name, |
| 24426 | 24550 | } })).toValue()); |
| 24427 | 24551 | }, |
| 24428 | 24552 | .Union => { |
| ... | ... | @@ -24499,7 +24623,7 @@ fn fieldPtr( |
| 24499 | 24623 | block: *Block, |
| 24500 | 24624 | src: LazySrcLoc, |
| 24501 | 24625 | object_ptr: Air.Inst.Ref, |
| 24502 | | field_name: []const u8, |
| 24626 | field_name: InternPool.NullTerminatedString, |
| 24503 | 24627 | field_name_src: LazySrcLoc, |
| 24504 | 24628 | initializing: bool, |
| 24505 | 24629 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -24507,7 +24631,6 @@ fn fieldPtr( |
| 24507 | 24631 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 24508 | 24632 | |
| 24509 | 24633 | const mod = sema.mod; |
| 24510 | | const gpa = sema.gpa; |
| 24511 | 24634 | const ip = &mod.intern_pool; |
| 24512 | 24635 | const object_ptr_src = src; // TODO better source location |
| 24513 | 24636 | const object_ptr_ty = sema.typeOf(object_ptr); |
| ... | ... | @@ -24528,7 +24651,7 @@ fn fieldPtr( |
| 24528 | 24651 | |
| 24529 | 24652 | switch (inner_ty.zigTypeTag(mod)) { |
| 24530 | 24653 | .Array => { |
| 24531 | | if (mem.eql(u8, field_name, "len")) { |
| 24654 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24532 | 24655 | var anon_decl = try block.startAnonDecl(); |
| 24533 | 24656 | defer anon_decl.deinit(); |
| 24534 | 24657 | return sema.analyzeDeclRef(try anon_decl.finish( |
| ... | ... | @@ -24541,7 +24664,7 @@ fn fieldPtr( |
| 24541 | 24664 | block, |
| 24542 | 24665 | field_name_src, |
| 24543 | 24666 | "no member named '{s}' in '{}'", |
| 24544 | | .{ field_name, object_ty.fmt(mod) }, |
| 24667 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, |
| 24545 | 24668 | ); |
| 24546 | 24669 | } |
| 24547 | 24670 | }, |
| ... | ... | @@ -24553,7 +24676,7 @@ fn fieldPtr( |
| 24553 | 24676 | |
| 24554 | 24677 | const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty; |
| 24555 | 24678 | |
| 24556 | | if (mem.eql(u8, field_name, "ptr")) { |
| 24679 | if (ip.stringEqlSlice(field_name, "ptr")) { |
| 24557 | 24680 | const slice_ptr_ty = inner_ty.slicePtrFieldType(mod); |
| 24558 | 24681 | |
| 24559 | 24682 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| ... | ... | @@ -24575,7 +24698,7 @@ fn fieldPtr( |
| 24575 | 24698 | try sema.requireRuntimeBlock(block, src, null); |
| 24576 | 24699 | |
| 24577 | 24700 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); |
| 24578 | | } else if (mem.eql(u8, field_name, "len")) { |
| 24701 | } else if (ip.stringEqlSlice(field_name, "len")) { |
| 24579 | 24702 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24580 | 24703 | .pointee_type = Type.usize, |
| 24581 | 24704 | .mutable = attr_ptr_ty.ptrIsMutable(mod), |
| ... | ... | @@ -24600,7 +24723,7 @@ fn fieldPtr( |
| 24600 | 24723 | block, |
| 24601 | 24724 | field_name_src, |
| 24602 | 24725 | "no member named '{s}' in '{}'", |
| 24603 | | .{ field_name, object_ty.fmt(mod) }, |
| 24726 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, |
| 24604 | 24727 | ); |
| 24605 | 24728 | } |
| 24606 | 24729 | }, |
| ... | ... | @@ -24617,14 +24740,13 @@ fn fieldPtr( |
| 24617 | 24740 | |
| 24618 | 24741 | switch (child_type.zigTypeTag(mod)) { |
| 24619 | 24742 | .ErrorSet => { |
| 24620 | | const name = try ip.getOrPutString(gpa, field_name); |
| 24621 | 24743 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24622 | 24744 | .error_set_type => |error_set_type| blk: { |
| 24623 | | if (error_set_type.nameIndex(ip, name) != null) { |
| 24745 | if (error_set_type.nameIndex(ip, field_name) != null) { |
| 24624 | 24746 | break :blk; |
| 24625 | 24747 | } |
| 24626 | 24748 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 24627 | | field_name, child_type.fmt(mod), |
| 24749 | ip.stringToSlice(field_name), child_type.fmt(mod), |
| 24628 | 24750 | }); |
| 24629 | 24751 | }, |
| 24630 | 24752 | .inferred_error_set_type => { |
| ... | ... | @@ -24642,12 +24764,12 @@ fn fieldPtr( |
| 24642 | 24764 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24643 | 24765 | child_type |
| 24644 | 24766 | else |
| 24645 | | try mod.singleErrorSetTypeNts(name); |
| 24767 | try mod.singleErrorSetTypeNts(field_name); |
| 24646 | 24768 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24647 | 24769 | error_set_type, |
| 24648 | 24770 | (try mod.intern(.{ .err = .{ |
| 24649 | 24771 | .ty = error_set_type.toIntern(), |
| 24650 | | .name = name, |
| 24772 | .name = field_name, |
| 24651 | 24773 | } })).toValue(), |
| 24652 | 24774 | 0, // default alignment |
| 24653 | 24775 | )); |
| ... | ... | @@ -24736,13 +24858,14 @@ fn fieldCallBind( |
| 24736 | 24858 | block: *Block, |
| 24737 | 24859 | src: LazySrcLoc, |
| 24738 | 24860 | raw_ptr: Air.Inst.Ref, |
| 24739 | | field_name: []const u8, |
| 24861 | field_name: InternPool.NullTerminatedString, |
| 24740 | 24862 | field_name_src: LazySrcLoc, |
| 24741 | 24863 | ) CompileError!ResolvedFieldCallee { |
| 24742 | 24864 | // When editing this function, note that there is corresponding logic to be edited |
| 24743 | 24865 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 24744 | 24866 | |
| 24745 | 24867 | const mod = sema.mod; |
| 24868 | const ip = &mod.intern_pool; |
| 24746 | 24869 | const raw_ptr_src = src; // TODO better source location |
| 24747 | 24870 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 24748 | 24871 | const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C)) |
| ... | ... | @@ -24771,18 +24894,18 @@ fn fieldCallBind( |
| 24771 | 24894 | |
| 24772 | 24895 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 24773 | 24896 | } else if (struct_ty.isTuple(mod)) { |
| 24774 | | if (mem.eql(u8, field_name, "len")) { |
| 24897 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24775 | 24898 | return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) }; |
| 24776 | 24899 | } |
| 24777 | | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 24900 | if (std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10)) |field_index| { |
| 24778 | 24901 | if (field_index >= struct_ty.structFieldCount(mod)) break :find_field; |
| 24779 | 24902 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr); |
| 24780 | 24903 | } else |_| {} |
| 24781 | 24904 | } else { |
| 24782 | 24905 | const max = struct_ty.structFieldCount(mod); |
| 24783 | | var i: u32 = 0; |
| 24784 | | while (i < max) : (i += 1) { |
| 24785 | | if (mem.eql(u8, struct_ty.structFieldName(i, mod), field_name)) { |
| 24906 | for (0..max) |i_usize| { |
| 24907 | const i = @intCast(u32, i_usize); |
| 24908 | if (field_name == struct_ty.structFieldName(i, mod)) { |
| 24786 | 24909 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i, mod), i, object_ptr); |
| 24787 | 24910 | } |
| 24788 | 24911 | } |
| ... | ... | @@ -24876,12 +24999,12 @@ fn fieldCallBind( |
| 24876 | 24999 | }; |
| 24877 | 25000 | |
| 24878 | 25001 | const msg = msg: { |
| 24879 | | const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ field_name, concrete_ty.fmt(mod) }); |
| 25002 | const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ ip.stringToSlice(field_name), concrete_ty.fmt(mod) }); |
| 24880 | 25003 | errdefer msg.destroy(sema.gpa); |
| 24881 | 25004 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 24882 | 25005 | if (found_decl) |decl_idx| { |
| 24883 | 25006 | const decl = mod.declPtr(decl_idx); |
| 24884 | | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{field_name}); |
| 25007 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{ip.stringToSlice(field_name)}); |
| 24885 | 25008 | } |
| 24886 | 25009 | break :msg msg; |
| 24887 | 25010 | }; |
| ... | ... | @@ -24933,7 +25056,7 @@ fn namespaceLookup( |
| 24933 | 25056 | block: *Block, |
| 24934 | 25057 | src: LazySrcLoc, |
| 24935 | 25058 | namespace: Namespace.Index, |
| 24936 | | decl_name: []const u8, |
| 25059 | decl_name: InternPool.NullTerminatedString, |
| 24937 | 25060 | ) CompileError!?Decl.Index { |
| 24938 | 25061 | const mod = sema.mod; |
| 24939 | 25062 | const gpa = sema.gpa; |
| ... | ... | @@ -24942,7 +25065,7 @@ fn namespaceLookup( |
| 24942 | 25065 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 24943 | 25066 | const msg = msg: { |
| 24944 | 25067 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ |
| 24945 | | decl_name, |
| 25068 | mod.intern_pool.stringToSlice(decl_name), |
| 24946 | 25069 | }); |
| 24947 | 25070 | errdefer msg.destroy(gpa); |
| 24948 | 25071 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); |
| ... | ... | @@ -24960,7 +25083,7 @@ fn namespaceLookupRef( |
| 24960 | 25083 | block: *Block, |
| 24961 | 25084 | src: LazySrcLoc, |
| 24962 | 25085 | namespace: Namespace.Index, |
| 24963 | | decl_name: []const u8, |
| 25086 | decl_name: InternPool.NullTerminatedString, |
| 24964 | 25087 | ) CompileError!?Air.Inst.Ref { |
| 24965 | 25088 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 24966 | 25089 | try sema.addReferencedBy(block, src, decl); |
| ... | ... | @@ -24972,7 +25095,7 @@ fn namespaceLookupVal( |
| 24972 | 25095 | block: *Block, |
| 24973 | 25096 | src: LazySrcLoc, |
| 24974 | 25097 | namespace: Namespace.Index, |
| 24975 | | decl_name: []const u8, |
| 25098 | decl_name: InternPool.NullTerminatedString, |
| 24976 | 25099 | ) CompileError!?Air.Inst.Ref { |
| 24977 | 25100 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 24978 | 25101 | return try sema.analyzeDeclVal(block, src, decl); |
| ... | ... | @@ -24983,7 +25106,7 @@ fn structFieldPtr( |
| 24983 | 25106 | block: *Block, |
| 24984 | 25107 | src: LazySrcLoc, |
| 24985 | 25108 | struct_ptr: Air.Inst.Ref, |
| 24986 | | field_name: []const u8, |
| 25109 | field_name: InternPool.NullTerminatedString, |
| 24987 | 25110 | field_name_src: LazySrcLoc, |
| 24988 | 25111 | unresolved_struct_ty: Type, |
| 24989 | 25112 | initializing: bool, |
| ... | ... | @@ -24995,7 +25118,7 @@ fn structFieldPtr( |
| 24995 | 25118 | try sema.resolveStructLayout(struct_ty); |
| 24996 | 25119 | |
| 24997 | 25120 | if (struct_ty.isTuple(mod)) { |
| 24998 | | if (mem.eql(u8, field_name, "len")) { |
| 25121 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { |
| 24999 | 25122 | const len_inst = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)); |
| 25000 | 25123 | return sema.analyzeRef(block, src, len_inst); |
| 25001 | 25124 | } |
| ... | ... | @@ -25101,7 +25224,7 @@ fn structFieldPtrByIndex( |
| 25101 | 25224 | if (field.is_comptime) { |
| 25102 | 25225 | const val = try mod.intern(.{ .ptr = .{ |
| 25103 | 25226 | .ty = ptr_field_ty.toIntern(), |
| 25104 | | .addr = .{ .comptime_field = try field.default_val.intern(field.ty, mod) }, |
| 25227 | .addr = .{ .comptime_field = field.default_val }, |
| 25105 | 25228 | } }); |
| 25106 | 25229 | return sema.addConstant(ptr_field_ty, val.toValue()); |
| 25107 | 25230 | } |
| ... | ... | @@ -25126,7 +25249,7 @@ fn structFieldVal( |
| 25126 | 25249 | block: *Block, |
| 25127 | 25250 | src: LazySrcLoc, |
| 25128 | 25251 | struct_byval: Air.Inst.Ref, |
| 25129 | | field_name: []const u8, |
| 25252 | field_name: InternPool.NullTerminatedString, |
| 25130 | 25253 | field_name_src: LazySrcLoc, |
| 25131 | 25254 | unresolved_struct_ty: Type, |
| 25132 | 25255 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -25145,7 +25268,7 @@ fn structFieldVal( |
| 25145 | 25268 | const field = struct_obj.fields.values()[field_index]; |
| 25146 | 25269 | |
| 25147 | 25270 | if (field.is_comptime) { |
| 25148 | | return sema.addConstant(field.ty, field.default_val); |
| 25271 | return sema.addConstant(field.ty, field.default_val.toValue()); |
| 25149 | 25272 | } |
| 25150 | 25273 | |
| 25151 | 25274 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| ... | ... | @@ -25176,12 +25299,12 @@ fn tupleFieldVal( |
| 25176 | 25299 | block: *Block, |
| 25177 | 25300 | src: LazySrcLoc, |
| 25178 | 25301 | tuple_byval: Air.Inst.Ref, |
| 25179 | | field_name: []const u8, |
| 25302 | field_name: InternPool.NullTerminatedString, |
| 25180 | 25303 | field_name_src: LazySrcLoc, |
| 25181 | 25304 | tuple_ty: Type, |
| 25182 | 25305 | ) CompileError!Air.Inst.Ref { |
| 25183 | 25306 | const mod = sema.mod; |
| 25184 | | if (mem.eql(u8, field_name, "len")) { |
| 25307 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { |
| 25185 | 25308 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount(mod)); |
| 25186 | 25309 | } |
| 25187 | 25310 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); |
| ... | ... | @@ -25193,11 +25316,12 @@ fn tupleFieldIndex( |
| 25193 | 25316 | sema: *Sema, |
| 25194 | 25317 | block: *Block, |
| 25195 | 25318 | tuple_ty: Type, |
| 25196 | | field_name: []const u8, |
| 25319 | field_name_ip: InternPool.NullTerminatedString, |
| 25197 | 25320 | field_name_src: LazySrcLoc, |
| 25198 | 25321 | ) CompileError!u32 { |
| 25199 | 25322 | const mod = sema.mod; |
| 25200 | | assert(!mem.eql(u8, field_name, "len")); |
| 25323 | const field_name = mod.intern_pool.stringToSlice(field_name_ip); |
| 25324 | assert(!std.mem.eql(u8, field_name, "len")); |
| 25201 | 25325 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 25202 | 25326 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; |
| 25203 | 25327 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ |
| ... | ... | @@ -25253,13 +25377,14 @@ fn unionFieldPtr( |
| 25253 | 25377 | block: *Block, |
| 25254 | 25378 | src: LazySrcLoc, |
| 25255 | 25379 | union_ptr: Air.Inst.Ref, |
| 25256 | | field_name: []const u8, |
| 25380 | field_name: InternPool.NullTerminatedString, |
| 25257 | 25381 | field_name_src: LazySrcLoc, |
| 25258 | 25382 | unresolved_union_ty: Type, |
| 25259 | 25383 | initializing: bool, |
| 25260 | 25384 | ) CompileError!Air.Inst.Ref { |
| 25261 | 25385 | const arena = sema.arena; |
| 25262 | 25386 | const mod = sema.mod; |
| 25387 | const ip = &mod.intern_pool; |
| 25263 | 25388 | |
| 25264 | 25389 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); |
| 25265 | 25390 | |
| ... | ... | @@ -25281,7 +25406,9 @@ fn unionFieldPtr( |
| 25281 | 25406 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); |
| 25282 | 25407 | errdefer msg.destroy(sema.gpa); |
| 25283 | 25408 | |
| 25284 | | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{field_name}); |
| 25409 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ |
| 25410 | ip.stringToSlice(field_name), |
| 25411 | }); |
| 25285 | 25412 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25286 | 25413 | break :msg msg; |
| 25287 | 25414 | }; |
| ... | ... | @@ -25296,14 +25423,17 @@ fn unionFieldPtr( |
| 25296 | 25423 | if (union_val.isUndef(mod)) { |
| 25297 | 25424 | return sema.failWithUseOfUndef(block, src); |
| 25298 | 25425 | } |
| 25299 | | const un = mod.intern_pool.indexToKey(union_val.toIntern()).un; |
| 25426 | const un = ip.indexToKey(union_val.toIntern()).un; |
| 25300 | 25427 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25301 | 25428 | const tag_matches = un.tag == field_tag.toIntern(); |
| 25302 | 25429 | if (!tag_matches) { |
| 25303 | 25430 | const msg = msg: { |
| 25304 | 25431 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25305 | 25432 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25306 | | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); |
| 25433 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ |
| 25434 | ip.stringToSlice(field_name), |
| 25435 | ip.stringToSlice(active_field_name), |
| 25436 | }); |
| 25307 | 25437 | errdefer msg.destroy(sema.gpa); |
| 25308 | 25438 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25309 | 25439 | break :msg msg; |
| ... | ... | @@ -25345,11 +25475,12 @@ fn unionFieldVal( |
| 25345 | 25475 | block: *Block, |
| 25346 | 25476 | src: LazySrcLoc, |
| 25347 | 25477 | union_byval: Air.Inst.Ref, |
| 25348 | | field_name: []const u8, |
| 25478 | field_name: InternPool.NullTerminatedString, |
| 25349 | 25479 | field_name_src: LazySrcLoc, |
| 25350 | 25480 | unresolved_union_ty: Type, |
| 25351 | 25481 | ) CompileError!Air.Inst.Ref { |
| 25352 | 25482 | const mod = sema.mod; |
| 25483 | const ip = &mod.intern_pool; |
| 25353 | 25484 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); |
| 25354 | 25485 | |
| 25355 | 25486 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); |
| ... | ... | @@ -25361,7 +25492,7 @@ fn unionFieldVal( |
| 25361 | 25492 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { |
| 25362 | 25493 | if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty); |
| 25363 | 25494 | |
| 25364 | | const un = mod.intern_pool.indexToKey(union_val.toIntern()).un; |
| 25495 | const un = ip.indexToKey(union_val.toIntern()).un; |
| 25365 | 25496 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25366 | 25497 | const tag_matches = un.tag == field_tag.toIntern(); |
| 25367 | 25498 | switch (union_obj.layout) { |
| ... | ... | @@ -25372,7 +25503,9 @@ fn unionFieldVal( |
| 25372 | 25503 | const msg = msg: { |
| 25373 | 25504 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25374 | 25505 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25375 | | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); |
| 25506 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ |
| 25507 | ip.stringToSlice(field_name), ip.stringToSlice(active_field_name), |
| 25508 | }); |
| 25376 | 25509 | errdefer msg.destroy(sema.gpa); |
| 25377 | 25510 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25378 | 25511 | break :msg msg; |
| ... | ... | @@ -26470,14 +26603,13 @@ fn coerceExtra( |
| 26470 | 26603 | // enum literal to enum |
| 26471 | 26604 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); |
| 26472 | 26605 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 26473 | | const bytes = mod.intern_pool.stringToSlice(string); |
| 26474 | | const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse { |
| 26606 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { |
| 26475 | 26607 | const msg = msg: { |
| 26476 | 26608 | const msg = try sema.errMsg( |
| 26477 | 26609 | block, |
| 26478 | 26610 | inst_src, |
| 26479 | 26611 | "no field named '{s}' in enum '{}'", |
| 26480 | | .{ bytes, dest_ty.fmt(mod) }, |
| 26612 | .{ mod.intern_pool.stringToSlice(string), dest_ty.fmt(mod) }, |
| 26481 | 26613 | ); |
| 26482 | 26614 | errdefer msg.destroy(sema.gpa); |
| 26483 | 26615 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | ... | @@ -27876,10 +28008,7 @@ fn storePtrVal( |
| 27876 | 28008 | error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(mod)}), |
| 27877 | 28009 | }; |
| 27878 | 28010 | |
| 27879 | | const arena = mut_kit.beginArena(mod); |
| 27880 | | defer mut_kit.finishArena(mod); |
| 27881 | | |
| 27882 | | reinterpret.val_ptr.* = (try (try Value.readFromMemory(mut_kit.ty, mod, buffer, arena)).intern(mut_kit.ty, mod)).toValue(); |
| 28011 | reinterpret.val_ptr.* = (try (try Value.readFromMemory(mut_kit.ty, mod, buffer, sema.arena)).intern(mut_kit.ty, mod)).toValue(); |
| 27883 | 28012 | }, |
| 27884 | 28013 | .bad_decl_ty, .bad_ptr_ty => { |
| 27885 | 28014 | // TODO show the decl declaration site in a note and explain whether the decl |
| ... | ... | @@ -27913,18 +28042,6 @@ const ComptimePtrMutationKit = struct { |
| 27913 | 28042 | bad_ptr_ty, |
| 27914 | 28043 | }, |
| 27915 | 28044 | ty: Type, |
| 27916 | | decl_arena: std.heap.ArenaAllocator = undefined, |
| 27917 | | |
| 27918 | | fn beginArena(self: *ComptimePtrMutationKit, mod: *Module) Allocator { |
| 27919 | | const decl = mod.declPtr(self.mut_decl.decl); |
| 27920 | | return decl.value_arena.?.acquire(mod.gpa, &self.decl_arena); |
| 27921 | | } |
| 27922 | | |
| 27923 | | fn finishArena(self: *ComptimePtrMutationKit, mod: *Module) void { |
| 27924 | | const decl = mod.declPtr(self.mut_decl.decl); |
| 27925 | | decl.value_arena.?.release(&self.decl_arena); |
| 27926 | | self.decl_arena = undefined; |
| 27927 | | } |
| 27928 | 28045 | }; |
| 27929 | 28046 | |
| 27930 | 28047 | fn beginComptimePtrMutation( |
| ... | ... | @@ -27966,10 +28083,8 @@ fn beginComptimePtrMutation( |
| 27966 | 28083 | // An error union has been initialized to undefined at comptime and now we |
| 27967 | 28084 | // are for the first time setting the payload. We must change the |
| 27968 | 28085 | // representation of the error union from `undef` to `opt_payload`. |
| 27969 | | const arena = parent.beginArena(sema.mod); |
| 27970 | | defer parent.finishArena(sema.mod); |
| 27971 | 28086 | |
| 27972 | | const payload = try arena.create(Value.Payload.SubValue); |
| 28087 | const payload = try sema.arena.create(Value.Payload.SubValue); |
| 27973 | 28088 | payload.* = .{ |
| 27974 | 28089 | .base = .{ .tag = .eu_payload }, |
| 27975 | 28090 | .data = (try mod.intern(.{ .undef = payload_ty.toIntern() })).toValue(), |
| ... | ... | @@ -28019,10 +28134,8 @@ fn beginComptimePtrMutation( |
| 28019 | 28134 | // An optional has been initialized to undefined at comptime and now we |
| 28020 | 28135 | // are for the first time setting the payload. We must change the |
| 28021 | 28136 | // representation of the optional from `undef` to `opt_payload`. |
| 28022 | | const arena = parent.beginArena(sema.mod); |
| 28023 | | defer parent.finishArena(sema.mod); |
| 28024 | 28137 | |
| 28025 | | const payload = try arena.create(Value.Payload.SubValue); |
| 28138 | const payload = try sema.arena.create(Value.Payload.SubValue); |
| 28026 | 28139 | payload.* = .{ |
| 28027 | 28140 | .base = .{ .tag = .opt_payload }, |
| 28028 | 28141 | .data = payload_val.toValue(), |
| ... | ... | @@ -28088,8 +28201,7 @@ fn beginComptimePtrMutation( |
| 28088 | 28201 | // If we wanted to avoid this, there would need to be special detection |
| 28089 | 28202 | // elsewhere to identify when writing a value to an array element that is stored |
| 28090 | 28203 | // using the `bytes` tag, and handle it without making a call to this function. |
| 28091 | | const arena = parent.beginArena(sema.mod); |
| 28092 | | defer parent.finishArena(sema.mod); |
| 28204 | const arena = sema.arena; |
| 28093 | 28205 | |
| 28094 | 28206 | const bytes = val_ptr.castTag(.bytes).?.data; |
| 28095 | 28207 | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| ... | ... | @@ -28121,8 +28233,7 @@ fn beginComptimePtrMutation( |
| 28121 | 28233 | // need to be special detection elsewhere to identify when writing a value to an |
| 28122 | 28234 | // array element that is stored using the `repeated` tag, and handle it |
| 28123 | 28235 | // without making a call to this function. |
| 28124 | | const arena = parent.beginArena(sema.mod); |
| 28125 | | defer parent.finishArena(sema.mod); |
| 28236 | const arena = sema.arena; |
| 28126 | 28237 | |
| 28127 | 28238 | const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena); |
| 28128 | 28239 | const array_len_including_sentinel = |
| ... | ... | @@ -28163,8 +28274,7 @@ fn beginComptimePtrMutation( |
| 28163 | 28274 | // An array has been initialized to undefined at comptime and now we |
| 28164 | 28275 | // are for the first time setting an element. We must change the representation |
| 28165 | 28276 | // of the array from `undef` to `array`. |
| 28166 | | const arena = parent.beginArena(sema.mod); |
| 28167 | | defer parent.finishArena(sema.mod); |
| 28277 | const arena = sema.arena; |
| 28168 | 28278 | |
| 28169 | 28279 | const array_len_including_sentinel = |
| 28170 | 28280 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| ... | ... | @@ -28261,8 +28371,7 @@ fn beginComptimePtrMutation( |
| 28261 | 28371 | parent.mut_decl, |
| 28262 | 28372 | ), |
| 28263 | 28373 | .repeated => { |
| 28264 | | const arena = parent.beginArena(sema.mod); |
| 28265 | | defer parent.finishArena(sema.mod); |
| 28374 | const arena = sema.arena; |
| 28266 | 28375 | |
| 28267 | 28376 | const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 28268 | 28377 | @memset(elems, val_ptr.castTag(.repeated).?.data); |
| ... | ... | @@ -28325,8 +28434,7 @@ fn beginComptimePtrMutation( |
| 28325 | 28434 | // A struct or union has been initialized to undefined at comptime and now we |
| 28326 | 28435 | // are for the first time setting a field. We must change the representation |
| 28327 | 28436 | // of the struct/union from `undef` to `struct`/`union`. |
| 28328 | | const arena = parent.beginArena(sema.mod); |
| 28329 | | defer parent.finishArena(sema.mod); |
| 28437 | const arena = sema.arena; |
| 28330 | 28438 | |
| 28331 | 28439 | switch (parent.ty.zigTypeTag(mod)) { |
| 28332 | 28440 | .Struct => { |
| ... | ... | @@ -28436,11 +28544,7 @@ fn beginComptimePtrMutationInner( |
| 28436 | 28544 | const target = mod.getTarget(); |
| 28437 | 28545 | const coerce_ok = (try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_ty, true, target, src, src)) == .ok; |
| 28438 | 28546 | |
| 28439 | | const decl = mod.declPtr(mut_decl.decl); |
| 28440 | | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 28441 | | const allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena); |
| 28442 | | defer decl.value_arena.?.release(&decl_arena); |
| 28443 | | decl_val.* = try decl_val.unintern(allocator, mod); |
| 28547 | decl_val.* = try decl_val.unintern(sema.arena, mod); |
| 28444 | 28548 | |
| 28445 | 28549 | if (coerce_ok) { |
| 28446 | 28550 | return ComptimePtrMutationKit{ |
| ... | ... | @@ -28928,6 +29032,7 @@ fn coerceEnumToUnion( |
| 28928 | 29032 | inst_src: LazySrcLoc, |
| 28929 | 29033 | ) !Air.Inst.Ref { |
| 28930 | 29034 | const mod = sema.mod; |
| 29035 | const ip = &mod.intern_pool; |
| 28931 | 29036 | const inst_ty = sema.typeOf(inst); |
| 28932 | 29037 | |
| 28933 | 29038 | const tag_ty = union_ty.unionTagType(mod) orelse { |
| ... | ... | @@ -28966,7 +29071,9 @@ fn coerceEnumToUnion( |
| 28966 | 29071 | errdefer msg.destroy(sema.gpa); |
| 28967 | 29072 | |
| 28968 | 29073 | const field_name = union_obj.fields.keys()[field_index]; |
| 28969 | | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{field_name}); |
| 29074 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ |
| 29075 | ip.stringToSlice(field_name), |
| 29076 | }); |
| 28970 | 29077 | try sema.addDeclaredHereNote(msg, union_ty); |
| 28971 | 29078 | break :msg msg; |
| 28972 | 29079 | }; |
| ... | ... | @@ -28976,11 +29083,14 @@ fn coerceEnumToUnion( |
| 28976 | 29083 | const msg = msg: { |
| 28977 | 29084 | const field_name = union_obj.fields.keys()[field_index]; |
| 28978 | 29085 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{ |
| 28979 | | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), field_ty.fmt(sema.mod), field_name, |
| 29086 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), |
| 29087 | field_ty.fmt(sema.mod), ip.stringToSlice(field_name), |
| 28980 | 29088 | }); |
| 28981 | 29089 | errdefer msg.destroy(sema.gpa); |
| 28982 | 29090 | |
| 28983 | | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{field_name}); |
| 29091 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ |
| 29092 | ip.stringToSlice(field_name), |
| 29093 | }); |
| 28984 | 29094 | try sema.addDeclaredHereNote(msg, union_ty); |
| 28985 | 29095 | break :msg msg; |
| 28986 | 29096 | }; |
| ... | ... | @@ -29049,7 +29159,10 @@ fn coerceEnumToUnion( |
| 29049 | 29159 | const field_name = field.key_ptr.*; |
| 29050 | 29160 | const field_ty = field.value_ptr.ty; |
| 29051 | 29161 | if (!(try sema.typeHasRuntimeBits(field_ty))) continue; |
| 29052 | | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' has type '{}'", .{ field_name, field_ty.fmt(sema.mod) }); |
| 29162 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' has type '{}'", .{ |
| 29163 | ip.stringToSlice(field_name), |
| 29164 | field_ty.fmt(sema.mod), |
| 29165 | }); |
| 29053 | 29166 | } |
| 29054 | 29167 | try sema.addDeclaredHereNote(msg, union_ty); |
| 29055 | 29168 | break :msg msg; |
| ... | ... | @@ -29068,11 +29181,11 @@ fn coerceAnonStructToUnion( |
| 29068 | 29181 | const mod = sema.mod; |
| 29069 | 29182 | const inst_ty = sema.typeOf(inst); |
| 29070 | 29183 | const field_info: union(enum) { |
| 29071 | | name: []const u8, |
| 29184 | name: InternPool.NullTerminatedString, |
| 29072 | 29185 | count: usize, |
| 29073 | 29186 | } = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29074 | 29187 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len == 1) |
| 29075 | | .{ .name = mod.intern_pool.stringToSlice(anon_struct_type.names[0]) } |
| 29188 | .{ .name = anon_struct_type.names[0] } |
| 29076 | 29189 | else |
| 29077 | 29190 | .{ .count = anon_struct_type.names.len }, |
| 29078 | 29191 | .struct_type => |struct_type| name: { |
| ... | ... | @@ -29335,6 +29448,7 @@ fn coerceTupleToStruct( |
| 29335 | 29448 | inst_src: LazySrcLoc, |
| 29336 | 29449 | ) !Air.Inst.Ref { |
| 29337 | 29450 | const mod = sema.mod; |
| 29451 | const ip = &mod.intern_pool; |
| 29338 | 29452 | const struct_ty = try sema.resolveTypeFields(dest_ty); |
| 29339 | 29453 | |
| 29340 | 29454 | if (struct_ty.isTupleOrAnonStruct(mod)) { |
| ... | ... | @@ -29348,7 +29462,7 @@ fn coerceTupleToStruct( |
| 29348 | 29462 | |
| 29349 | 29463 | const inst_ty = sema.typeOf(inst); |
| 29350 | 29464 | var runtime_src: ?LazySrcLoc = null; |
| 29351 | | const field_count = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29465 | const field_count = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 29352 | 29466 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29353 | 29467 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29354 | 29468 | struct_obj.fields.count() |
| ... | ... | @@ -29360,11 +29474,11 @@ fn coerceTupleToStruct( |
| 29360 | 29474 | const field_i = @intCast(u32, field_index_usize); |
| 29361 | 29475 | const field_src = inst_src; // TODO better source location |
| 29362 | 29476 | // https://github.com/ziglang/zig/issues/15709 |
| 29363 | | const field_name: []const u8 = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29477 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 29364 | 29478 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 29365 | | mod.intern_pool.stringToSlice(anon_struct_type.names[field_i]) |
| 29479 | anon_struct_type.names[field_i] |
| 29366 | 29480 | else |
| 29367 | | try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}), |
| 29481 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), |
| 29368 | 29482 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], |
| 29369 | 29483 | else => unreachable, |
| 29370 | 29484 | }; |
| ... | ... | @@ -29378,7 +29492,7 @@ fn coerceTupleToStruct( |
| 29378 | 29492 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); |
| 29379 | 29493 | }; |
| 29380 | 29494 | |
| 29381 | | if (!init_val.eql(field.default_val, field.ty, sema.mod)) { |
| 29495 | if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) { |
| 29382 | 29496 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i); |
| 29383 | 29497 | } |
| 29384 | 29498 | } |
| ... | ... | @@ -29401,9 +29515,9 @@ fn coerceTupleToStruct( |
| 29401 | 29515 | const field_name = fields.keys()[i]; |
| 29402 | 29516 | const field = fields.values()[i]; |
| 29403 | 29517 | const field_src = inst_src; // TODO better source location |
| 29404 | | if (field.default_val.toIntern() == .unreachable_value) { |
| 29518 | if (field.default_val == .none) { |
| 29405 | 29519 | const template = "missing struct field: {s}"; |
| 29406 | | const args = .{field_name}; |
| 29520 | const args = .{ip.stringToSlice(field_name)}; |
| 29407 | 29521 | if (root_msg) |msg| { |
| 29408 | 29522 | try sema.errNote(block, field_src, msg, template, args); |
| 29409 | 29523 | } else { |
| ... | ... | @@ -29412,9 +29526,9 @@ fn coerceTupleToStruct( |
| 29412 | 29526 | continue; |
| 29413 | 29527 | } |
| 29414 | 29528 | if (runtime_src == null) { |
| 29415 | | field_vals[i] = field.default_val.toIntern(); |
| 29529 | field_vals[i] = field.default_val; |
| 29416 | 29530 | } else { |
| 29417 | | field_ref.* = try sema.addConstant(field.ty, field.default_val); |
| 29531 | field_ref.* = try sema.addConstant(field.ty, field.default_val.toValue()); |
| 29418 | 29532 | } |
| 29419 | 29533 | } |
| 29420 | 29534 | |
| ... | ... | @@ -29433,7 +29547,7 @@ fn coerceTupleToStruct( |
| 29433 | 29547 | .ty = struct_ty.toIntern(), |
| 29434 | 29548 | .storage = .{ .elems = field_vals }, |
| 29435 | 29549 | } }); |
| 29436 | | errdefer mod.intern_pool.remove(struct_val); |
| 29550 | errdefer ip.remove(struct_val); |
| 29437 | 29551 | |
| 29438 | 29552 | return sema.addConstant(struct_ty, struct_val.toValue()); |
| 29439 | 29553 | } |
| ... | ... | @@ -29446,7 +29560,8 @@ fn coerceTupleToTuple( |
| 29446 | 29560 | inst_src: LazySrcLoc, |
| 29447 | 29561 | ) !Air.Inst.Ref { |
| 29448 | 29562 | const mod = sema.mod; |
| 29449 | | const dest_field_count = switch (mod.intern_pool.indexToKey(tuple_ty.toIntern())) { |
| 29563 | const ip = &mod.intern_pool; |
| 29564 | const dest_field_count = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| 29450 | 29565 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29451 | 29566 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29452 | 29567 | struct_obj.fields.count() |
| ... | ... | @@ -29459,7 +29574,7 @@ fn coerceTupleToTuple( |
| 29459 | 29574 | @memset(field_refs, .none); |
| 29460 | 29575 | |
| 29461 | 29576 | const inst_ty = sema.typeOf(inst); |
| 29462 | | const src_field_count = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29577 | const src_field_count = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 29463 | 29578 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29464 | 29579 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29465 | 29580 | struct_obj.fields.count() |
| ... | ... | @@ -29474,30 +29589,26 @@ fn coerceTupleToTuple( |
| 29474 | 29589 | const field_i = @intCast(u32, field_index_usize); |
| 29475 | 29590 | const field_src = inst_src; // TODO better source location |
| 29476 | 29591 | // https://github.com/ziglang/zig/issues/15709 |
| 29477 | | const field_name: []const u8 = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29592 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| 29478 | 29593 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 29479 | | mod.intern_pool.stringToSlice(anon_struct_type.names[field_i]) |
| 29594 | anon_struct_type.names[field_i] |
| 29480 | 29595 | else |
| 29481 | | try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}), |
| 29596 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), |
| 29482 | 29597 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], |
| 29483 | 29598 | else => unreachable, |
| 29484 | 29599 | }; |
| 29485 | 29600 | |
| 29486 | | if (mem.eql(u8, field_name, "len")) { |
| 29601 | if (ip.stringEqlSlice(field_name, "len")) |
| 29487 | 29602 | return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{}); |
| 29488 | | } |
| 29489 | 29603 | |
| 29490 | | const field_ty = switch (mod.intern_pool.indexToKey(tuple_ty.toIntern())) { |
| 29604 | const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| 29491 | 29605 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[field_index_usize].toType(), |
| 29492 | 29606 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].ty, |
| 29493 | 29607 | else => unreachable, |
| 29494 | 29608 | }; |
| 29495 | | const default_val = switch (mod.intern_pool.indexToKey(tuple_ty.toIntern())) { |
| 29609 | const default_val = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| 29496 | 29610 | .anon_struct_type => |anon_struct_type| anon_struct_type.values[field_index_usize], |
| 29497 | | .struct_type => |struct_type| switch (mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].default_val.toIntern()) { |
| 29498 | | .unreachable_value => .none, |
| 29499 | | else => |default_val| default_val, |
| 29500 | | }, |
| 29611 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].default_val, |
| 29501 | 29612 | else => unreachable, |
| 29502 | 29613 | }; |
| 29503 | 29614 | |
| ... | ... | @@ -29531,12 +29642,9 @@ fn coerceTupleToTuple( |
| 29531 | 29642 | for (field_refs, 0..) |*field_ref, i| { |
| 29532 | 29643 | if (field_ref.* != .none) continue; |
| 29533 | 29644 | |
| 29534 | | const default_val = switch (mod.intern_pool.indexToKey(tuple_ty.toIntern())) { |
| 29645 | const default_val = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| 29535 | 29646 | .anon_struct_type => |anon_struct_type| anon_struct_type.values[i], |
| 29536 | | .struct_type => |struct_type| switch (mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].default_val.toIntern()) { |
| 29537 | | .unreachable_value => .none, |
| 29538 | | else => |default_val| default_val, |
| 29539 | | }, |
| 29647 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].default_val, |
| 29540 | 29648 | else => unreachable, |
| 29541 | 29649 | }; |
| 29542 | 29650 | |
| ... | ... | @@ -29552,7 +29660,7 @@ fn coerceTupleToTuple( |
| 29552 | 29660 | continue; |
| 29553 | 29661 | } |
| 29554 | 29662 | const template = "missing struct field: {s}"; |
| 29555 | | const args = .{tuple_ty.structFieldName(i, mod)}; |
| 29663 | const args = .{ip.stringToSlice(tuple_ty.structFieldName(i, mod))}; |
| 29556 | 29664 | if (root_msg) |msg| { |
| 29557 | 29665 | try sema.errNote(block, field_src, msg, template, args); |
| 29558 | 29666 | } else { |
| ... | ... | @@ -29563,7 +29671,7 @@ fn coerceTupleToTuple( |
| 29563 | 29671 | if (runtime_src == null) { |
| 29564 | 29672 | field_vals[i] = default_val; |
| 29565 | 29673 | } else { |
| 29566 | | const field_ty = switch (mod.intern_pool.indexToKey(tuple_ty.toIntern())) { |
| 29674 | const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) { |
| 29567 | 29675 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[i].toType(), |
| 29568 | 29676 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].ty, |
| 29569 | 29677 | else => unreachable, |
| ... | ... | @@ -31803,15 +31911,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 31803 | 31911 | } |
| 31804 | 31912 | |
| 31805 | 31913 | if (struct_obj.layout == .Auto and mod.backendSupportsFeature(.field_reordering)) { |
| 31806 | | const optimized_order = if (struct_obj.owner_decl == sema.owner_decl_index) |
| 31807 | | try sema.perm_arena.alloc(u32, struct_obj.fields.count()) |
| 31808 | | else blk: { |
| 31809 | | const decl = mod.declPtr(struct_obj.owner_decl); |
| 31810 | | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 31811 | | const decl_arena_allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena); |
| 31812 | | defer decl.value_arena.?.release(&decl_arena); |
| 31813 | | break :blk try decl_arena_allocator.alloc(u32, struct_obj.fields.count()); |
| 31814 | | }; |
| 31914 | const optimized_order = try mod.tmp_hack_arena.allocator().alloc(u32, struct_obj.fields.count()); |
| 31815 | 31915 | |
| 31816 | 31916 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 31817 | 31917 | optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty)) |
| ... | ... | @@ -31852,9 +31952,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31852 | 31952 | |
| 31853 | 31953 | const decl_index = struct_obj.owner_decl; |
| 31854 | 31954 | const decl = mod.declPtr(decl_index); |
| 31855 | | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 31856 | | const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena); |
| 31857 | | defer decl.value_arena.?.release(&decl_arena); |
| 31858 | 31955 | |
| 31859 | 31956 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 31860 | 31957 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| ... | ... | @@ -31880,7 +31977,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31880 | 31977 | .mod = mod, |
| 31881 | 31978 | .gpa = gpa, |
| 31882 | 31979 | .arena = analysis_arena.allocator(), |
| 31883 | | .perm_arena = decl_arena_allocator, |
| 31884 | 31980 | .code = zir, |
| 31885 | 31981 | .owner_decl = decl, |
| 31886 | 31982 | .owner_decl_index = decl_index, |
| ... | ... | @@ -31936,7 +32032,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31936 | 32032 | .mod = mod, |
| 31937 | 32033 | .gpa = gpa, |
| 31938 | 32034 | .arena = undefined, |
| 31939 | | .perm_arena = decl_arena_allocator, |
| 31940 | 32035 | .code = zir, |
| 31941 | 32036 | .owner_decl = decl, |
| 31942 | 32037 | .owner_decl_index = decl_index, |
| ... | ... | @@ -32581,6 +32676,7 @@ fn resolveInferredErrorSetTy( |
| 32581 | 32676 | |
| 32582 | 32677 | fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { |
| 32583 | 32678 | const gpa = mod.gpa; |
| 32679 | const ip = &mod.intern_pool; |
| 32584 | 32680 | const decl_index = struct_obj.owner_decl; |
| 32585 | 32681 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 32586 | 32682 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| ... | ... | @@ -32628,9 +32724,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32628 | 32724 | } |
| 32629 | 32725 | |
| 32630 | 32726 | const decl = mod.declPtr(decl_index); |
| 32631 | | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 32632 | | const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena); |
| 32633 | | defer decl.value_arena.?.release(&decl_arena); |
| 32634 | 32727 | |
| 32635 | 32728 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32636 | 32729 | defer analysis_arena.deinit(); |
| ... | ... | @@ -32642,7 +32735,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32642 | 32735 | .mod = mod, |
| 32643 | 32736 | .gpa = gpa, |
| 32644 | 32737 | .arena = analysis_arena.allocator(), |
| 32645 | | .perm_arena = decl_arena_allocator, |
| 32646 | 32738 | .code = zir, |
| 32647 | 32739 | .owner_decl = decl, |
| 32648 | 32740 | .owner_decl_index = decl_index, |
| ... | ... | @@ -32674,7 +32766,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32674 | 32766 | } |
| 32675 | 32767 | |
| 32676 | 32768 | struct_obj.fields = .{}; |
| 32677 | | try struct_obj.fields.ensureTotalCapacity(decl_arena_allocator, fields_len); |
| 32769 | try struct_obj.fields.ensureTotalCapacity(mod.tmp_hack_arena.allocator(), fields_len); |
| 32678 | 32770 | |
| 32679 | 32771 | const Field = struct { |
| 32680 | 32772 | type_body_len: u32 = 0, |
| ... | ... | @@ -32725,16 +32817,15 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32725 | 32817 | extra_index += 1; |
| 32726 | 32818 | |
| 32727 | 32819 | // This string needs to outlive the ZIR code. |
| 32728 | | const field_name = if (field_name_zir) |some| |
| 32729 | | try decl_arena_allocator.dupe(u8, some) |
| 32730 | | else |
| 32731 | | try std.fmt.allocPrint(decl_arena_allocator, "{d}", .{field_i}); |
| 32820 | const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s| s else try std.fmt.allocPrint(sema.arena, "{d}", .{ |
| 32821 | field_i, |
| 32822 | })); |
| 32732 | 32823 | |
| 32733 | 32824 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 32734 | 32825 | if (gop.found_existing) { |
| 32735 | 32826 | const msg = msg: { |
| 32736 | 32827 | const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy; |
| 32737 | | const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{field_name}); |
| 32828 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{ip.stringToSlice(field_name)}); |
| 32738 | 32829 | errdefer msg.destroy(gpa); |
| 32739 | 32830 | |
| 32740 | 32831 | const prev_field_index = struct_obj.fields.getIndex(field_name).?; |
| ... | ... | @@ -32748,7 +32839,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32748 | 32839 | gop.value_ptr.* = .{ |
| 32749 | 32840 | .ty = Type.noreturn, |
| 32750 | 32841 | .abi_align = 0, |
| 32751 | | .default_val = Value.@"unreachable", |
| 32842 | .default_val = .none, |
| 32752 | 32843 | .is_comptime = is_comptime, |
| 32753 | 32844 | .offset = undefined, |
| 32754 | 32845 | }; |
| ... | ... | @@ -32917,7 +33008,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32917 | 33008 | }).lazy; |
| 32918 | 33009 | return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known"); |
| 32919 | 33010 | }; |
| 32920 | | field.default_val = try default_val.copy(decl_arena_allocator); |
| 33011 | field.default_val = try default_val.intern(field.ty, mod); |
| 32921 | 33012 | } |
| 32922 | 33013 | } |
| 32923 | 33014 | } |
| ... | ... | @@ -32935,6 +33026,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32935 | 33026 | defer tracy.end(); |
| 32936 | 33027 | |
| 32937 | 33028 | const gpa = mod.gpa; |
| 33029 | const ip = &mod.intern_pool; |
| 32938 | 33030 | const decl_index = union_obj.owner_decl; |
| 32939 | 33031 | const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir; |
| 32940 | 33032 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; |
| ... | ... | @@ -32978,9 +33070,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32978 | 33070 | extra_index += body.len; |
| 32979 | 33071 | |
| 32980 | 33072 | const decl = mod.declPtr(decl_index); |
| 32981 | | var decl_arena: std.heap.ArenaAllocator = undefined; |
| 32982 | | const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena); |
| 32983 | | defer decl.value_arena.?.release(&decl_arena); |
| 32984 | 33073 | |
| 32985 | 33074 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32986 | 33075 | defer analysis_arena.deinit(); |
| ... | ... | @@ -32992,7 +33081,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32992 | 33081 | .mod = mod, |
| 32993 | 33082 | .gpa = gpa, |
| 32994 | 33083 | .arena = analysis_arena.allocator(), |
| 32995 | | .perm_arena = decl_arena_allocator, |
| 32996 | 33084 | .code = zir, |
| 32997 | 33085 | .owner_decl = decl, |
| 32998 | 33086 | .owner_decl_index = decl_index, |
| ... | ... | @@ -33033,7 +33121,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33033 | 33121 | try ct_decl.intern(mod); |
| 33034 | 33122 | } |
| 33035 | 33123 | |
| 33036 | | try union_obj.fields.ensureTotalCapacity(decl_arena_allocator, fields_len); |
| 33124 | try union_obj.fields.ensureTotalCapacity(mod.tmp_hack_arena.allocator(), fields_len); |
| 33037 | 33125 | |
| 33038 | 33126 | var int_tag_ty: Type = undefined; |
| 33039 | 33127 | var enum_field_names: []InternPool.NullTerminatedString = &.{}; |
| ... | ... | @@ -33070,7 +33158,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33070 | 33158 | } else { |
| 33071 | 33159 | // The provided type is the enum tag type. |
| 33072 | 33160 | union_obj.tag_ty = provided_ty; |
| 33073 | | const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.toIntern())) { |
| 33161 | const enum_type = switch (ip.indexToKey(union_obj.tag_ty.toIntern())) { |
| 33074 | 33162 | .enum_type => |x| x, |
| 33075 | 33163 | else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}), |
| 33076 | 33164 | }; |
| ... | ... | @@ -33174,10 +33262,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33174 | 33262 | } |
| 33175 | 33263 | |
| 33176 | 33264 | // This string needs to outlive the ZIR code. |
| 33177 | | const field_name = try decl_arena_allocator.dupe(u8, field_name_zir); |
| 33178 | | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); |
| 33265 | const field_name = try ip.getOrPutString(gpa, field_name_zir); |
| 33179 | 33266 | if (enum_field_names.len != 0) { |
| 33180 | | enum_field_names[field_i] = field_name_ip; |
| 33267 | enum_field_names[field_i] = field_name; |
| 33181 | 33268 | } |
| 33182 | 33269 | |
| 33183 | 33270 | const field_ty: Type = if (!has_type) |
| ... | ... | @@ -33205,7 +33292,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33205 | 33292 | if (gop.found_existing) { |
| 33206 | 33293 | const msg = msg: { |
| 33207 | 33294 | const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy; |
| 33208 | | const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{field_name}); |
| 33295 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{ |
| 33296 | ip.stringToSlice(field_name), |
| 33297 | }); |
| 33209 | 33298 | errdefer msg.destroy(gpa); |
| 33210 | 33299 | |
| 33211 | 33300 | const prev_field_index = union_obj.fields.getIndex(field_name).?; |
| ... | ... | @@ -33218,14 +33307,14 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33218 | 33307 | } |
| 33219 | 33308 | |
| 33220 | 33309 | if (explicit_enum_info) |tag_info| { |
| 33221 | | const enum_index = tag_info.nameIndex(&mod.intern_pool, field_name_ip) orelse { |
| 33310 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 33222 | 33311 | const msg = msg: { |
| 33223 | 33312 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ |
| 33224 | 33313 | .index = field_i, |
| 33225 | 33314 | .range = .type, |
| 33226 | 33315 | }).lazy; |
| 33227 | 33316 | const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{s}' in enum '{}'", .{ |
| 33228 | | field_name, union_obj.tag_ty.fmt(mod), |
| 33317 | ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod), |
| 33229 | 33318 | }); |
| 33230 | 33319 | errdefer msg.destroy(sema.gpa); |
| 33231 | 33320 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | ... | @@ -33317,7 +33406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33317 | 33406 | for (tag_info.names, 0..) |field_name, field_index| { |
| 33318 | 33407 | if (explicit_tags_seen[field_index]) continue; |
| 33319 | 33408 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ |
| 33320 | | mod.intern_pool.stringToSlice(field_name), |
| 33409 | ip.stringToSlice(field_name), |
| 33321 | 33410 | }); |
| 33322 | 33411 | } |
| 33323 | 33412 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | ... | @@ -33345,14 +33434,22 @@ fn generateUnionTagTypeNumbered( |
| 33345 | 33434 | union_obj: *Module.Union, |
| 33346 | 33435 | ) !Type { |
| 33347 | 33436 | const mod = sema.mod; |
| 33437 | const gpa = sema.gpa; |
| 33438 | const ip = &mod.intern_pool; |
| 33348 | 33439 | |
| 33349 | 33440 | const src_decl = mod.declPtr(block.src_decl); |
| 33350 | 33441 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33351 | 33442 | errdefer mod.destroyDecl(new_decl_index); |
| 33352 | 33443 | const name = name: { |
| 33353 | | const fqn = try union_obj.getFullyQualifiedName(mod); |
| 33354 | | defer sema.gpa.free(fqn); |
| 33355 | | break :name try std.fmt.allocPrintZ(sema.gpa, "@typeInfo({s}).Union.tag_type.?", .{fqn}); |
| 33444 | const prefix = "@typeInfo("; |
| 33445 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 33446 | const suffix = ").Union.tag_type.?"; |
| 33447 | const start = ip.string_bytes.items.len; |
| 33448 | try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len); |
| 33449 | ip.string_bytes.appendSliceAssumeCapacity(prefix); |
| 33450 | ip.string_bytes.appendSliceAssumeCapacity(fqn); |
| 33451 | ip.string_bytes.appendSliceAssumeCapacity(suffix); |
| 33452 | break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start); |
| 33356 | 33453 | }; |
| 33357 | 33454 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33358 | 33455 | .ty = Type.type, |
| ... | ... | @@ -33390,6 +33487,8 @@ fn generateUnionTagTypeSimple( |
| 33390 | 33487 | maybe_union_obj: ?*Module.Union, |
| 33391 | 33488 | ) !Type { |
| 33392 | 33489 | const mod = sema.mod; |
| 33490 | const gpa = sema.gpa; |
| 33491 | const ip = &mod.intern_pool; |
| 33393 | 33492 | |
| 33394 | 33493 | const new_decl_index = new_decl_index: { |
| 33395 | 33494 | const union_obj = maybe_union_obj orelse { |
| ... | ... | @@ -33402,9 +33501,15 @@ fn generateUnionTagTypeSimple( |
| 33402 | 33501 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33403 | 33502 | errdefer mod.destroyDecl(new_decl_index); |
| 33404 | 33503 | const name = name: { |
| 33405 | | const fqn = try union_obj.getFullyQualifiedName(mod); |
| 33406 | | defer sema.gpa.free(fqn); |
| 33407 | | break :name try std.fmt.allocPrintZ(sema.gpa, "@typeInfo({s}).Union.tag_type.?", .{fqn}); |
| 33504 | const prefix = "@typeInfo("; |
| 33505 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 33506 | const suffix = ").Union.tag_type.?"; |
| 33507 | const start = ip.string_bytes.items.len; |
| 33508 | try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len); |
| 33509 | ip.string_bytes.appendSliceAssumeCapacity(prefix); |
| 33510 | ip.string_bytes.appendSliceAssumeCapacity(fqn); |
| 33511 | ip.string_bytes.appendSliceAssumeCapacity(suffix); |
| 33512 | break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start); |
| 33408 | 33513 | }; |
| 33409 | 33514 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33410 | 33515 | .ty = Type.type, |
| ... | ... | @@ -33436,7 +33541,9 @@ fn generateUnionTagTypeSimple( |
| 33436 | 33541 | } |
| 33437 | 33542 | |
| 33438 | 33543 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 33439 | | var wip_captures = try WipCaptureScope.init(sema.gpa, sema.owner_decl.src_scope); |
| 33544 | const gpa = sema.gpa; |
| 33545 | |
| 33546 | var wip_captures = try WipCaptureScope.init(gpa, sema.owner_decl.src_scope); |
| 33440 | 33547 | defer wip_captures.deinit(); |
| 33441 | 33548 | |
| 33442 | 33549 | var block: Block = .{ |
| ... | ... | @@ -33450,19 +33557,20 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 33450 | 33557 | .is_comptime = true, |
| 33451 | 33558 | }; |
| 33452 | 33559 | defer { |
| 33453 | | block.instructions.deinit(sema.gpa); |
| 33454 | | block.params.deinit(sema.gpa); |
| 33560 | block.instructions.deinit(gpa); |
| 33561 | block.params.deinit(gpa); |
| 33455 | 33562 | } |
| 33456 | 33563 | const src = LazySrcLoc.nodeOffset(0); |
| 33457 | 33564 | |
| 33458 | 33565 | const mod = sema.mod; |
| 33566 | const ip = &mod.intern_pool; |
| 33459 | 33567 | const std_pkg = mod.main_pkg.table.get("std").?; |
| 33460 | 33568 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| 33461 | 33569 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 33462 | 33570 | &block, |
| 33463 | 33571 | src, |
| 33464 | 33572 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 33465 | | "builtin", |
| 33573 | try ip.getOrPutString(gpa, "builtin"), |
| 33466 | 33574 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 33467 | 33575 | const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src); |
| 33468 | 33576 | const builtin_ty = sema.analyzeAsType(&block, src, builtin_inst) catch |err| switch (err) { |
| ... | ... | @@ -33473,7 +33581,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 33473 | 33581 | &block, |
| 33474 | 33582 | src, |
| 33475 | 33583 | builtin_ty.getNamespaceIndex(mod).unwrap().?, |
| 33476 | | name, |
| 33584 | try ip.getOrPutString(gpa, name), |
| 33477 | 33585 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 33478 | 33586 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); |
| 33479 | 33587 | } |
| ... | ... | @@ -33608,7 +33716,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33608 | 33716 | const field_vals = try sema.arena.alloc(InternPool.Index, s.fields.count()); |
| 33609 | 33717 | for (field_vals, s.fields.values(), 0..) |*field_val, field, i| { |
| 33610 | 33718 | if (field.is_comptime) { |
| 33611 | | field_val.* = try field.default_val.intern(field.ty, mod); |
| 33719 | field_val.* = field.default_val; |
| 33612 | 33720 | continue; |
| 33613 | 33721 | } |
| 33614 | 33722 | if (field.ty.eql(resolved_ty, sema.mod)) { |
| ... | ... | @@ -34287,7 +34395,7 @@ fn unionFieldIndex( |
| 34287 | 34395 | sema: *Sema, |
| 34288 | 34396 | block: *Block, |
| 34289 | 34397 | unresolved_union_ty: Type, |
| 34290 | | field_name: []const u8, |
| 34398 | field_name: InternPool.NullTerminatedString, |
| 34291 | 34399 | field_src: LazySrcLoc, |
| 34292 | 34400 | ) !u32 { |
| 34293 | 34401 | const mod = sema.mod; |
| ... | ... | @@ -34302,7 +34410,7 @@ fn structFieldIndex( |
| 34302 | 34410 | sema: *Sema, |
| 34303 | 34411 | block: *Block, |
| 34304 | 34412 | unresolved_struct_ty: Type, |
| 34305 | | field_name: []const u8, |
| 34413 | field_name: InternPool.NullTerminatedString, |
| 34306 | 34414 | field_src: LazySrcLoc, |
| 34307 | 34415 | ) !u32 { |
| 34308 | 34416 | const mod = sema.mod; |
| ... | ... | @@ -34321,19 +34429,17 @@ fn anonStructFieldIndex( |
| 34321 | 34429 | sema: *Sema, |
| 34322 | 34430 | block: *Block, |
| 34323 | 34431 | struct_ty: Type, |
| 34324 | | field_name: []const u8, |
| 34432 | field_name: InternPool.NullTerminatedString, |
| 34325 | 34433 | field_src: LazySrcLoc, |
| 34326 | 34434 | ) !u32 { |
| 34327 | 34435 | const mod = sema.mod; |
| 34328 | 34436 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 34329 | 34437 | .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| { |
| 34330 | | if (mem.eql(u8, mod.intern_pool.stringToSlice(name), field_name)) { |
| 34331 | | return @intCast(u32, i); |
| 34332 | | } |
| 34438 | if (name == field_name) return @intCast(u32, i); |
| 34333 | 34439 | }, |
| 34334 | 34440 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| { |
| 34335 | 34441 | for (struct_obj.fields.keys(), 0..) |name, i| { |
| 34336 | | if (mem.eql(u8, name, field_name)) { |
| 34442 | if (name == field_name) { |
| 34337 | 34443 | return @intCast(u32, i); |
| 34338 | 34444 | } |
| 34339 | 34445 | } |
| ... | ... | @@ -34341,7 +34447,7 @@ fn anonStructFieldIndex( |
| 34341 | 34447 | else => unreachable, |
| 34342 | 34448 | } |
| 34343 | 34449 | return sema.fail(block, field_src, "no field named '{s}' in anonymous struct '{}'", .{ |
| 34344 | | field_name, struct_ty.fmt(sema.mod), |
| 34450 | mod.intern_pool.stringToSlice(field_name), struct_ty.fmt(sema.mod), |
| 34345 | 34451 | }); |
| 34346 | 34452 | } |
| 34347 | 34453 | |