| ... | @@ -11,9 +11,6 @@ gpa: Allocator, | ... | @@ -11,9 +11,6 @@ gpa: Allocator, |
| 11 | /// Points to the temporary arena allocator of the Sema. | 11 | /// Points to the temporary arena allocator of the Sema. |
| 12 | /// This arena will be cleared when the sema is destroyed. | 12 | /// This arena will be cleared when the sema is destroyed. |
| 13 | arena: Allocator, | 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 | code: Zir, | 14 | code: Zir, |
| 18 | air_instructions: std.MultiArrayList(Air.Inst) = .{}, | 15 | air_instructions: std.MultiArrayList(Air.Inst) = .{}, |
| 19 | air_extra: std.ArrayListUnmanaged(u32) = .{}, | 16 | air_extra: std.ArrayListUnmanaged(u32) = .{}, |
| ... | @@ -740,7 +737,6 @@ pub const Block = struct { | ... | @@ -740,7 +737,6 @@ pub const Block = struct { |
| 740 | // TODO: migrate Decl alignment to use `InternPool.Alignment` | 737 | // TODO: migrate Decl alignment to use `InternPool.Alignment` |
| 741 | new_decl.@"align" = @intCast(u32, alignment); | 738 | new_decl.@"align" = @intCast(u32, alignment); |
| 742 | errdefer sema.mod.abortAnonDecl(new_decl_index); | 739 | errdefer sema.mod.abortAnonDecl(new_decl_index); |
| 743 | try new_decl.finalizeNewArena(&wad.new_decl_arena); | | |
| 744 | wad.finished = true; | 740 | wad.finished = true; |
| 745 | try sema.mod.finalizeAnonDecl(new_decl_index); | 741 | try sema.mod.finalizeAnonDecl(new_decl_index); |
| 746 | return new_decl_index; | 742 | return new_decl_index; |
| ... | @@ -1825,6 +1821,20 @@ pub fn resolveConstString( | ... | @@ -1825,6 +1821,20 @@ pub fn resolveConstString( |
| 1825 | return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod); | 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 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { | 1838 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 1829 | const air_inst = try sema.resolveInst(zir_ref); | 1839 | const air_inst = try sema.resolveInst(zir_ref); |
| 1830 | assert(air_inst != .var_args_param_type); | 1840 | assert(air_inst != .var_args_param_type); |
| ... | @@ -1847,11 +1857,13 @@ fn analyzeAsType( | ... | @@ -1847,11 +1857,13 @@ fn analyzeAsType( |
| 1847 | | 1857 | |
| 1848 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { | 1858 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { |
| 1849 | const mod = sema.mod; | 1859 | const mod = sema.mod; |
| | 1860 | const gpa = sema.gpa; |
| | 1861 | const ip = &mod.intern_pool; |
| 1850 | if (!mod.backendSupportsFeature(.error_return_trace)) return; | 1862 | if (!mod.backendSupportsFeature(.error_return_trace)) return; |
| 1851 | | 1863 | |
| 1852 | assert(!block.is_comptime); | 1864 | assert(!block.is_comptime); |
| 1853 | var err_trace_block = block.makeSubBlock(); | 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 | const src: LazySrcLoc = .unneeded; | 1868 | const src: LazySrcLoc = .unneeded; |
| 1857 | | 1869 | |
| ... | @@ -1866,17 +1878,19 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -1866,17 +1878,19 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 1866 | const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty)); | 1878 | const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty)); |
| 1867 | | 1879 | |
| 1868 | // st.instruction_addresses = &addrs; | 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 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); | 1883 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); |
| 1871 | | 1884 | |
| 1872 | // st.index = 0; | 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 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); | 1888 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); |
| 1875 | | 1889 | |
| 1876 | // @errorReturnTrace() = &st; | 1890 | // @errorReturnTrace() = &st; |
| 1877 | _ = try err_trace_block.addUnOp(.set_err_return_trace, st_ptr); | 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 | /// May return Value Tags: `variable`, `undef`. | 1896 | /// May return Value Tags: `variable`, `undef`. |
| ... | @@ -2179,7 +2193,13 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError | ... | @@ -2179,7 +2193,13 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError |
| 2179 | return sema.failWithOwnedErrorMsg(msg); | 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 | const mod = sema.mod; | 2203 | const mod = sema.mod; |
| 2184 | const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType(mod) else object_ty; | 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,15 +2227,16 @@ fn failWithInvalidFieldAccess(sema: *Sema, block: *Block, src: LazySrcLoc, objec |
| 2207 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 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 | switch (ty.zigTypeTag(mod)) { | 2232 | switch (ty.zigTypeTag(mod)) { |
| 2212 | .Array => return mem.eql(u8, field_name, "len"), | 2233 | .Array => return ip.stringEqlSlice(field_name, "len"), |
| 2213 | .Pointer => { | 2234 | .Pointer => { |
| 2214 | const ptr_info = ty.ptrInfo(mod); | 2235 | const ptr_info = ty.ptrInfo(mod); |
| 2215 | if (ptr_info.size == .Slice) { | 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 | } else if (ptr_info.pointee_type.zigTypeTag(mod) == .Array) { | 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 | } else return false; | 2240 | } else return false; |
| 2220 | }, | 2241 | }, |
| 2221 | .Type, .Struct, .Union => return true, | 2242 | .Type, .Struct, .Union => return true, |
| ... | @@ -2308,19 +2329,19 @@ pub fn fail( | ... | @@ -2308,19 +2329,19 @@ pub fn fail( |
| 2308 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | 2329 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2309 | @setCold(true); | 2330 | @setCold(true); |
| 2310 | const gpa = sema.gpa; | 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 | if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; | 2335 | if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; |
| 2314 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; | 2336 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 2315 | wip_errors.init(gpa) catch unreachable; | 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 | std.debug.print("compile error during Sema:\n", .{}); | 2339 | std.debug.print("compile error during Sema:\n", .{}); |
| 2318 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; | 2340 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; |
| 2319 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); | 2341 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); |
| 2320 | crash_report.compilerPanic("unexpected compile error occurred", null, null); | 2342 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2321 | } | 2343 | } |
| 2322 | | 2344 | |
| 2323 | const mod = sema.mod; | | |
| 2324 | ref: { | 2345 | ref: { |
| 2325 | errdefer err_msg.destroy(gpa); | 2346 | errdefer err_msg.destroy(gpa); |
| 2326 | if (err_msg.src_loc.lazy == .unneeded) { | 2347 | if (err_msg.src_loc.lazy == .unneeded) { |
| ... | @@ -2330,9 +2351,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | ... | @@ -2330,9 +2351,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2330 | try mod.failed_files.ensureUnusedCapacity(gpa, 1); | 2351 | try mod.failed_files.ensureUnusedCapacity(gpa, 1); |
| 2331 | | 2352 | |
| 2332 | const max_references = blk: { | 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 | // Do not add multiple traces without explicit request. | 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 | break :blk default_reference_trace_len; | 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,13 +2371,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2350 | if (gop.found_existing) break; | 2371 | if (gop.found_existing) break; |
| 2351 | if (cur_reference_trace < max_references) { | 2372 | if (cur_reference_trace < max_references) { |
| 2352 | const decl = sema.mod.declPtr(ref.referencer); | 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 | referenced_by = ref.referencer; | 2379 | referenced_by = ref.referencer; |
| 2356 | } | 2380 | } |
| 2357 | if (sema.mod.comp.reference_trace == null and cur_reference_trace > 0) { | 2381 | if (sema.mod.comp.reference_trace == null and cur_reference_trace > 0) { |
| 2358 | try reference_stack.append(.{ | 2382 | try reference_stack.append(.{ |
| 2359 | .decl = null, | 2383 | .decl = .none, |
| 2360 | .src_loc = undefined, | 2384 | .src_loc = undefined, |
| 2361 | .hidden = 0, | 2385 | .hidden = 0, |
| 2362 | }); | 2386 | }); |
| ... | @@ -2795,7 +2819,6 @@ fn zirStructDecl( | ... | @@ -2795,7 +2819,6 @@ fn zirStructDecl( |
| 2795 | new_namespace.ty = struct_ty.toType(); | 2819 | new_namespace.ty = struct_ty.toType(); |
| 2796 | | 2820 | |
| 2797 | try sema.analyzeStructDecl(new_decl, inst, struct_index); | 2821 | try sema.analyzeStructDecl(new_decl, inst, struct_index); |
| 2798 | try new_decl.finalizeNewArena(&new_decl_arena); | | |
| 2799 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 2822 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 2800 | try mod.finalizeAnonDecl(new_decl_index); | 2823 | try mod.finalizeAnonDecl(new_decl_index); |
| 2801 | return decl_val; | 2824 | return decl_val; |
| ... | @@ -2812,6 +2835,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2812,6 +2835,7 @@ fn createAnonymousDeclTypeNamed( |
| 2812 | ) !Decl.Index { | 2835 | ) !Decl.Index { |
| 2813 | const mod = sema.mod; | 2836 | const mod = sema.mod; |
| 2814 | const gpa = sema.gpa; | 2837 | const gpa = sema.gpa; |
| | 2838 | const ip = &mod.intern_pool; |
| 2815 | const namespace = block.namespace; | 2839 | const namespace = block.namespace; |
| 2816 | const src_scope = block.wip_capture_scope; | 2840 | const src_scope = block.wip_capture_scope; |
| 2817 | const src_decl = mod.declPtr(block.src_decl); | 2841 | const src_decl = mod.declPtr(block.src_decl); |
| ... | @@ -2827,16 +2851,19 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2827,16 +2851,19 @@ fn createAnonymousDeclTypeNamed( |
| 2827 | // semantically analyzed. | 2851 | // semantically analyzed. |
| 2828 | // This name is also used as the key in the parent namespace so it cannot be | 2852 | // This name is also used as the key in the parent namespace so it cannot be |
| 2829 | // renamed. | 2853 | // renamed. |
| 2830 | const name = try std.fmt.allocPrintZ(gpa, "{s}__{s}_{d}", .{ | 2854 | |
| 2831 | src_decl.name, anon_prefix, @enumToInt(new_decl_index), | 2855 | // This ensureUnusedCapacity protects against the src_decl slice from being |
| 2832 | }); | 2856 | // reallocated during the call to `getOrPutStringFmt`. |
| 2833 | errdefer gpa.free(name); | 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 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2862 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2835 | return new_decl_index; | 2863 | return new_decl_index; |
| 2836 | }, | 2864 | }, |
| 2837 | .parent => { | 2865 | .parent => { |
| 2838 | const name = try gpa.dupeZ(u8, mem.sliceTo(sema.mod.declPtr(block.src_decl).name, 0)); | 2866 | const name = mod.declPtr(block.src_decl).name; |
| 2839 | errdefer gpa.free(name); | | |
| 2840 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2867 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2841 | return new_decl_index; | 2868 | return new_decl_index; |
| 2842 | }, | 2869 | }, |
| ... | @@ -2846,7 +2873,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2846,7 +2873,7 @@ fn createAnonymousDeclTypeNamed( |
| 2846 | | 2873 | |
| 2847 | var buf = std.ArrayList(u8).init(gpa); | 2874 | var buf = std.ArrayList(u8).init(gpa); |
| 2848 | defer buf.deinit(); | 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 | try buf.appendSlice("("); | 2877 | try buf.appendSlice("("); |
| 2851 | | 2878 | |
| 2852 | var arg_i: usize = 0; | 2879 | var arg_i: usize = 0; |
| ... | @@ -2871,8 +2898,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2871,8 +2898,7 @@ fn createAnonymousDeclTypeNamed( |
| 2871 | }; | 2898 | }; |
| 2872 | | 2899 | |
| 2873 | try buf.appendSlice(")"); | 2900 | try buf.appendSlice(")"); |
| 2874 | const name = try buf.toOwnedSliceSentinel(0); | 2901 | const name = try ip.getOrPutString(gpa, buf.items); |
| 2875 | errdefer gpa.free(name); | | |
| 2876 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2902 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2877 | return new_decl_index; | 2903 | return new_decl_index; |
| 2878 | }, | 2904 | }, |
| ... | @@ -2885,10 +2911,17 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2885,10 +2911,17 @@ fn createAnonymousDeclTypeNamed( |
| 2885 | .dbg_var_ptr, .dbg_var_val => { | 2911 | .dbg_var_ptr, .dbg_var_val => { |
| 2886 | if (zir_data[i].str_op.operand != ref) continue; | 2912 | if (zir_data[i].str_op.operand != ref) continue; |
| 2887 | | 2913 | |
| 2888 | const name = try std.fmt.allocPrintZ(gpa, "{s}.{s}", .{ | 2914 | // This ensureUnusedCapacity protects against the src_decl |
| 2889 | src_decl.name, zir_data[i].str_op.getStr(sema.code), | 2915 | // slice from being reallocated during the call to |
| 2890 | }); | 2916 | // `getOrPutStringFmt`. |
| 2891 | errdefer gpa.free(name); | 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 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2926 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2894 | return new_decl_index; | 2927 | return new_decl_index; |
| ... | @@ -3249,7 +3282,6 @@ fn zirUnionDecl( | ... | @@ -3249,7 +3282,6 @@ fn zirUnionDecl( |
| 3249 | | 3282 | |
| 3250 | _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); | 3283 | _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); |
| 3251 | | 3284 | |
| 3252 | try new_decl.finalizeNewArena(&new_decl_arena); | | |
| 3253 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 3285 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 3254 | try mod.finalizeAnonDecl(new_decl_index); | 3286 | try mod.finalizeAnonDecl(new_decl_index); |
| 3255 | return decl_val; | 3287 | return decl_val; |
| ... | @@ -3315,7 +3347,6 @@ fn zirOpaqueDecl( | ... | @@ -3315,7 +3347,6 @@ fn zirOpaqueDecl( |
| 3315 | | 3347 | |
| 3316 | extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); | 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 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 3350 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 3320 | try mod.finalizeAnonDecl(new_decl_index); | 3351 | try mod.finalizeAnonDecl(new_decl_index); |
| 3321 | return decl_val; | 3352 | return decl_val; |
| ... | @@ -3344,8 +3375,8 @@ fn zirErrorSetDecl( | ... | @@ -3344,8 +3375,8 @@ fn zirErrorSetDecl( |
| 3344 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string | 3375 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string |
| 3345 | const str_index = sema.code.extra[extra_index]; | 3376 | const str_index = sema.code.extra[extra_index]; |
| 3346 | const name = sema.code.nullTerminatedString(str_index); | 3377 | const name = sema.code.nullTerminatedString(str_index); |
| 3347 | const kv = try mod.getErrorValue(name); | 3378 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name); |
| 3348 | const name_ip = try mod.intern_pool.getOrPutString(gpa, kv.key); | 3379 | _ = try mod.getErrorValue(name_ip); |
| 3349 | const result = names.getOrPutAssumeCapacity(name_ip); | 3380 | const result = names.getOrPutAssumeCapacity(name_ip); |
| 3350 | assert(!result.found_existing); // verified in AstGen | 3381 | assert(!result.found_existing); // verified in AstGen |
| 3351 | } | 3382 | } |
| ... | @@ -3512,7 +3543,8 @@ fn indexablePtrLen( | ... | @@ -3512,7 +3543,8 @@ fn indexablePtrLen( |
| 3512 | const is_pointer_to = object_ty.isSinglePointer(mod); | 3543 | const is_pointer_to = object_ty.isSinglePointer(mod); |
| 3513 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; | 3544 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; |
| 3514 | try checkIndexable(sema, block, src, indexable_ty); | 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 | fn indexablePtrLenOrNone( | 3550 | fn indexablePtrLenOrNone( |
| ... | @@ -3525,7 +3557,8 @@ fn indexablePtrLenOrNone( | ... | @@ -3525,7 +3557,8 @@ fn indexablePtrLenOrNone( |
| 3525 | const operand_ty = sema.typeOf(operand); | 3557 | const operand_ty = sema.typeOf(operand); |
| 3526 | try checkMemOperand(sema, block, src, operand_ty); | 3558 | try checkMemOperand(sema, block, src, operand_ty); |
| 3527 | if (operand_ty.ptrSize(mod) == .Many) return .none; | 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 | fn zirAllocExtended( | 3564 | fn zirAllocExtended( |
| ... | @@ -4079,6 +4112,7 @@ fn zirFieldBasePtr( | ... | @@ -4079,6 +4112,7 @@ fn zirFieldBasePtr( |
| 4079 | fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4112 | fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4080 | const mod = sema.mod; | 4113 | const mod = sema.mod; |
| 4081 | const gpa = sema.gpa; | 4114 | const gpa = sema.gpa; |
| | 4115 | const ip = &mod.intern_pool; |
| 4082 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 4116 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 4083 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 4117 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 4084 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); | 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,7 +4156,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4122 | } | 4156 | } |
| 4123 | if (!object_ty.indexableHasLen(mod)) continue; | 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 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); | 4161 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); |
| 4128 | if (len == .none) { | 4162 | if (len == .none) { |
| ... | @@ -4308,6 +4342,7 @@ fn validateUnionInit( | ... | @@ -4308,6 +4342,7 @@ fn validateUnionInit( |
| 4308 | union_ptr: Air.Inst.Ref, | 4342 | union_ptr: Air.Inst.Ref, |
| 4309 | ) CompileError!void { | 4343 | ) CompileError!void { |
| 4310 | const mod = sema.mod; | 4344 | const mod = sema.mod; |
| | 4345 | const gpa = sema.gpa; |
| 4311 | | 4346 | |
| 4312 | if (instrs.len != 1) { | 4347 | if (instrs.len != 1) { |
| 4313 | const msg = msg: { | 4348 | const msg = msg: { |
| ... | @@ -4317,7 +4352,7 @@ fn validateUnionInit( | ... | @@ -4317,7 +4352,7 @@ fn validateUnionInit( |
| 4317 | "cannot initialize multiple union fields at once; unions can only have one active field", | 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 | for (instrs[1..]) |inst| { | 4357 | for (instrs[1..]) |inst| { |
| 4323 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 4358 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| ... | @@ -4341,7 +4376,7 @@ fn validateUnionInit( | ... | @@ -4341,7 +4376,7 @@ fn validateUnionInit( |
| 4341 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | 4376 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| 4342 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4377 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4343 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 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 | // Validate the field access but ignore the index since we want the tag enum field index. | 4380 | // Validate the field access but ignore the index since we want the tag enum field index. |
| 4346 | _ = try sema.unionFieldIndex(block, union_ty, field_name, field_src); | 4381 | _ = try sema.unionFieldIndex(block, union_ty, field_name, field_src); |
| 4347 | const air_tags = sema.air_instructions.items(.tag); | 4382 | const air_tags = sema.air_instructions.items(.tag); |
| ... | @@ -4444,6 +4479,7 @@ fn validateStructInit( | ... | @@ -4444,6 +4479,7 @@ fn validateStructInit( |
| 4444 | ) CompileError!void { | 4479 | ) CompileError!void { |
| 4445 | const mod = sema.mod; | 4480 | const mod = sema.mod; |
| 4446 | const gpa = sema.gpa; | 4481 | const gpa = sema.gpa; |
| | 4482 | const ip = &mod.intern_pool; |
| 4447 | | 4483 | |
| 4448 | // Maps field index to field_ptr index of where it was already initialized. | 4484 | // Maps field index to field_ptr index of where it was already initialized. |
| 4449 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount(mod)); | 4485 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount(mod)); |
| ... | @@ -4457,7 +4493,10 @@ fn validateStructInit( | ... | @@ -4457,7 +4493,10 @@ fn validateStructInit( |
| 4457 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4493 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4458 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4494 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4459 | struct_ptr_zir_ref = field_ptr_extra.lhs; | 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 | const field_index = if (struct_ty.isTuple(mod)) | 4500 | const field_index = if (struct_ty.isTuple(mod)) |
| 4462 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) | 4501 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) |
| 4463 | else | 4502 | else |
| ... | @@ -4504,7 +4543,7 @@ fn validateStructInit( | ... | @@ -4504,7 +4543,7 @@ fn validateStructInit( |
| 4504 | } | 4543 | } |
| 4505 | const field_name = struct_ty.structFieldName(i, mod); | 4544 | const field_name = struct_ty.structFieldName(i, mod); |
| 4506 | const template = "missing struct field: {s}"; | 4545 | const template = "missing struct field: {s}"; |
| 4507 | const args = .{field_name}; | 4546 | const args = .{ip.stringToSlice(field_name)}; |
| 4508 | if (root_msg) |msg| { | 4547 | if (root_msg) |msg| { |
| 4509 | try sema.errNote(block, init_src, msg, template, args); | 4548 | try sema.errNote(block, init_src, msg, template, args); |
| 4510 | } else { | 4549 | } else { |
| ... | @@ -4525,8 +4564,7 @@ fn validateStructInit( | ... | @@ -4525,8 +4564,7 @@ fn validateStructInit( |
| 4525 | | 4564 | |
| 4526 | if (root_msg) |msg| { | 4565 | if (root_msg) |msg| { |
| 4527 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 4566 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4528 | const fqn = try struct_obj.getFullyQualifiedName(mod); | 4567 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4529 | defer gpa.free(fqn); | | |
| 4530 | try mod.errNoteNonLazy( | 4568 | try mod.errNoteNonLazy( |
| 4531 | struct_obj.srcLoc(mod), | 4569 | struct_obj.srcLoc(mod), |
| 4532 | msg, | 4570 | msg, |
| ... | @@ -4649,7 +4687,7 @@ fn validateStructInit( | ... | @@ -4649,7 +4687,7 @@ fn validateStructInit( |
| 4649 | } | 4687 | } |
| 4650 | const field_name = struct_ty.structFieldName(i, mod); | 4688 | const field_name = struct_ty.structFieldName(i, mod); |
| 4651 | const template = "missing struct field: {s}"; | 4689 | const template = "missing struct field: {s}"; |
| 4652 | const args = .{field_name}; | 4690 | const args = .{ip.stringToSlice(field_name)}; |
| 4653 | if (root_msg) |msg| { | 4691 | if (root_msg) |msg| { |
| 4654 | try sema.errNote(block, init_src, msg, template, args); | 4692 | try sema.errNote(block, init_src, msg, template, args); |
| 4655 | } else { | 4693 | } else { |
| ... | @@ -4662,10 +4700,9 @@ fn validateStructInit( | ... | @@ -4662,10 +4700,9 @@ fn validateStructInit( |
| 4662 | | 4700 | |
| 4663 | if (root_msg) |msg| { | 4701 | if (root_msg) |msg| { |
| 4664 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 4702 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4665 | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); | 4703 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4666 | defer gpa.free(fqn); | | |
| 4667 | try sema.mod.errNoteNonLazy( | 4704 | try sema.mod.errNoteNonLazy( |
| 4668 | struct_obj.srcLoc(sema.mod), | 4705 | struct_obj.srcLoc(mod), |
| 4669 | msg, | 4706 | msg, |
| 4670 | "struct '{s}' declared here", | 4707 | "struct '{s}' declared here", |
| 4671 | .{fqn}, | 4708 | .{fqn}, |
| ... | @@ -4949,7 +4986,7 @@ fn failWithBadMemberAccess( | ... | @@ -4949,7 +4986,7 @@ fn failWithBadMemberAccess( |
| 4949 | block: *Block, | 4986 | block: *Block, |
| 4950 | agg_ty: Type, | 4987 | agg_ty: Type, |
| 4951 | field_src: LazySrcLoc, | 4988 | field_src: LazySrcLoc, |
| 4952 | field_name: []const u8, | 4989 | field_name_nts: InternPool.NullTerminatedString, |
| 4953 | ) CompileError { | 4990 | ) CompileError { |
| 4954 | const mod = sema.mod; | 4991 | const mod = sema.mod; |
| 4955 | const kw_name = switch (agg_ty.zigTypeTag(mod)) { | 4992 | const kw_name = switch (agg_ty.zigTypeTag(mod)) { |
| ... | @@ -4959,6 +4996,7 @@ fn failWithBadMemberAccess( | ... | @@ -4959,6 +4996,7 @@ fn failWithBadMemberAccess( |
| 4959 | .Enum => "enum", | 4996 | .Enum => "enum", |
| 4960 | else => unreachable, | 4997 | else => unreachable, |
| 4961 | }; | 4998 | }; |
| | 4999 | const field_name = mod.intern_pool.stringToSlice(field_name_nts); |
| 4962 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) { | 5000 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) { |
| 4963 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ | 5001 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ |
| 4964 | agg_ty.fmt(sema.mod), field_name, | 5002 | agg_ty.fmt(sema.mod), field_name, |
| ... | @@ -4980,22 +5018,23 @@ fn failWithBadStructFieldAccess( | ... | @@ -4980,22 +5018,23 @@ fn failWithBadStructFieldAccess( |
| 4980 | block: *Block, | 5018 | block: *Block, |
| 4981 | struct_obj: *Module.Struct, | 5019 | struct_obj: *Module.Struct, |
| 4982 | field_src: LazySrcLoc, | 5020 | field_src: LazySrcLoc, |
| 4983 | field_name: []const u8, | 5021 | field_name: InternPool.NullTerminatedString, |
| 4984 | ) CompileError { | 5022 | ) CompileError { |
| | 5023 | const mod = sema.mod; |
| 4985 | const gpa = sema.gpa; | 5024 | const gpa = sema.gpa; |
| | 5025 | const ip = &mod.intern_pool; |
| 4986 | | 5026 | |
| 4987 | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); | 5027 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 4988 | defer gpa.free(fqn); | | |
| 4989 | | 5028 | |
| 4990 | const msg = msg: { | 5029 | const msg = msg: { |
| 4991 | const msg = try sema.errMsg( | 5030 | const msg = try sema.errMsg( |
| 4992 | block, | 5031 | block, |
| 4993 | field_src, | 5032 | field_src, |
| 4994 | "no field named '{s}' in struct '{s}'", | 5033 | "no field named '{s}' in struct '{s}'", |
| 4995 | .{ field_name, fqn }, | 5034 | .{ ip.stringToSlice(field_name), fqn }, |
| 4996 | ); | 5035 | ); |
| 4997 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 5038 | break :msg msg; |
| 5000 | }; | 5039 | }; |
| 5001 | return sema.failWithOwnedErrorMsg(msg); | 5040 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -5006,22 +5045,23 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5006,22 +5045,23 @@ fn failWithBadUnionFieldAccess( |
| 5006 | block: *Block, | 5045 | block: *Block, |
| 5007 | union_obj: *Module.Union, | 5046 | union_obj: *Module.Union, |
| 5008 | field_src: LazySrcLoc, | 5047 | field_src: LazySrcLoc, |
| 5009 | field_name: []const u8, | 5048 | field_name: InternPool.NullTerminatedString, |
| 5010 | ) CompileError { | 5049 | ) CompileError { |
| | 5050 | const mod = sema.mod; |
| 5011 | const gpa = sema.gpa; | 5051 | const gpa = sema.gpa; |
| | 5052 | const ip = &mod.intern_pool; |
| 5012 | | 5053 | |
| 5013 | const fqn = try union_obj.getFullyQualifiedName(sema.mod); | 5054 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 5014 | defer gpa.free(fqn); | | |
| 5015 | | 5055 | |
| 5016 | const msg = msg: { | 5056 | const msg = msg: { |
| 5017 | const msg = try sema.errMsg( | 5057 | const msg = try sema.errMsg( |
| 5018 | block, | 5058 | block, |
| 5019 | field_src, | 5059 | field_src, |
| 5020 | "no field named '{s}' in union '{s}'", | 5060 | "no field named '{s}' in union '{s}'", |
| 5021 | .{ field_name, fqn }, | 5061 | .{ ip.stringToSlice(field_name), fqn }, |
| 5022 | ); | 5062 | ); |
| 5023 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 5065 | break :msg msg; |
| 5026 | }; | 5066 | }; |
| 5027 | return sema.failWithOwnedErrorMsg(msg); | 5067 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -5772,7 +5812,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5772,7 +5812,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5772 | const src = inst_data.src(); | 5812 | const src = inst_data.src(); |
| 5773 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5813 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5774 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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 | const decl_index = if (extra.namespace != .none) index_blk: { | 5816 | const decl_index = if (extra.namespace != .none) index_blk: { |
| 5777 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); | 5817 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); |
| 5778 | const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?; | 5818 | const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?; |
| ... | @@ -5875,19 +5915,14 @@ pub fn analyzeExport( | ... | @@ -5875,19 +5915,14 @@ pub fn analyzeExport( |
| 5875 | const new_export = try gpa.create(Export); | 5915 | const new_export = try gpa.create(Export); |
| 5876 | errdefer gpa.destroy(new_export); | 5916 | errdefer gpa.destroy(new_export); |
| 5877 | | 5917 | |
| 5878 | const symbol_name = try gpa.dupe(u8, borrowed_options.name); | 5918 | const symbol_name = try mod.intern_pool.getOrPutString(gpa, borrowed_options.name); |
| 5879 | errdefer gpa.free(symbol_name); | 5919 | const section = try mod.intern_pool.getOrPutStringOpt(gpa, borrowed_options.section); |
| 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); | | |
| 5883 | | 5920 | |
| 5884 | new_export.* = .{ | 5921 | new_export.* = .{ |
| 5885 | .options = .{ | 5922 | .name = symbol_name, |
| 5886 | .name = symbol_name, | 5923 | .linkage = borrowed_options.linkage, |
| 5887 | .linkage = borrowed_options.linkage, | 5924 | .section = section, |
| 5888 | .section = section, | 5925 | .visibility = borrowed_options.visibility, |
| 5889 | .visibility = borrowed_options.visibility, | | |
| 5890 | }, | | |
| 5891 | .src = src, | 5926 | .src = src, |
| 5892 | .owner_decl = sema.owner_decl_index, | 5927 | .owner_decl = sema.owner_decl_index, |
| 5893 | .src_decl = block.src_decl, | 5928 | .src_decl = block.src_decl, |
| ... | @@ -6121,23 +6156,25 @@ fn addDbgVar( | ... | @@ -6121,23 +6156,25 @@ fn addDbgVar( |
| 6121 | } | 6156 | } |
| 6122 | | 6157 | |
| 6123 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6158 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| | 6159 | const mod = sema.mod; |
| 6124 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 6160 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 6125 | const src = inst_data.src(); | 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 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); | 6163 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 6128 | try sema.addReferencedBy(block, src, decl_index); | 6164 | try sema.addReferencedBy(block, src, decl_index); |
| 6129 | return sema.analyzeDeclRef(decl_index); | 6165 | return sema.analyzeDeclRef(decl_index); |
| 6130 | } | 6166 | } |
| 6131 | | 6167 | |
| 6132 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6168 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| | 6169 | const mod = sema.mod; |
| 6133 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 6170 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 6134 | const src = inst_data.src(); | 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 | const decl = try sema.lookupIdentifier(block, src, decl_name); | 6173 | const decl = try sema.lookupIdentifier(block, src, decl_name); |
| 6137 | return sema.analyzeDeclVal(block, src, decl); | 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 | const mod = sema.mod; | 6178 | const mod = sema.mod; |
| 6142 | var namespace = block.namespace; | 6179 | var namespace = block.namespace; |
| 6143 | while (true) { | 6180 | while (true) { |
| ... | @@ -6156,7 +6193,7 @@ fn lookupInNamespace( | ... | @@ -6156,7 +6193,7 @@ fn lookupInNamespace( |
| 6156 | block: *Block, | 6193 | block: *Block, |
| 6157 | src: LazySrcLoc, | 6194 | src: LazySrcLoc, |
| 6158 | namespace_index: Namespace.Index, | 6195 | namespace_index: Namespace.Index, |
| 6159 | ident_name: []const u8, | 6196 | ident_name: InternPool.NullTerminatedString, |
| 6160 | observe_usingnamespace: bool, | 6197 | observe_usingnamespace: bool, |
| 6161 | ) CompileError!?Decl.Index { | 6198 | ) CompileError!?Decl.Index { |
| 6162 | const mod = sema.mod; | 6199 | const mod = sema.mod; |
| ... | @@ -6249,9 +6286,6 @@ fn lookupInNamespace( | ... | @@ -6249,9 +6286,6 @@ fn lookupInNamespace( |
| 6249 | return decl_index; | 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 | // TODO This dependency is too strong. Really, it should only be a dependency | 6289 | // TODO This dependency is too strong. Really, it should only be a dependency |
| 6256 | // on the non-existence of `ident_name` in the namespace. We can lessen the number of | 6290 | // on the non-existence of `ident_name` in the namespace. We can lessen the number of |
| 6257 | // outdated declarations by making this dependency more sophisticated. | 6291 | // outdated declarations by making this dependency more sophisticated. |
| ... | @@ -6276,10 +6310,12 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { | ... | @@ -6276,10 +6310,12 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { |
| 6276 | } | 6310 | } |
| 6277 | | 6311 | |
| 6278 | pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { | 6312 | pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { |
| | 6313 | const mod = sema.mod; |
| | 6314 | const gpa = sema.gpa; |
| 6279 | const src = sema.src; | 6315 | const src = sema.src; |
| 6280 | | 6316 | |
| 6281 | if (!sema.mod.backendSupportsFeature(.error_return_trace)) return .none; | 6317 | if (!mod.backendSupportsFeature(.error_return_trace)) return .none; |
| 6282 | if (!sema.mod.comp.bin_file.options.error_return_tracing) return .none; | 6318 | if (!mod.comp.bin_file.options.error_return_tracing) return .none; |
| 6283 | | 6319 | |
| 6284 | if (block.is_comptime) | 6320 | if (block.is_comptime) |
| 6285 | return .none; | 6321 | return .none; |
| ... | @@ -6292,7 +6328,8 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6292,7 +6328,8 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6292 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6328 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6293 | else => |e| return e, | 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 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6333 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6297 | else => |e| return e, | 6334 | else => |e| return e, |
| 6298 | }; | 6335 | }; |
| ... | @@ -6316,6 +6353,7 @@ fn popErrorReturnTrace( | ... | @@ -6316,6 +6353,7 @@ fn popErrorReturnTrace( |
| 6316 | saved_error_trace_index: Air.Inst.Ref, | 6353 | saved_error_trace_index: Air.Inst.Ref, |
| 6317 | ) CompileError!void { | 6354 | ) CompileError!void { |
| 6318 | const mod = sema.mod; | 6355 | const mod = sema.mod; |
| | 6356 | const gpa = sema.gpa; |
| 6319 | var is_non_error: ?bool = null; | 6357 | var is_non_error: ?bool = null; |
| 6320 | var is_non_error_inst: Air.Inst.Ref = undefined; | 6358 | var is_non_error_inst: Air.Inst.Ref = undefined; |
| 6321 | if (operand != .none) { | 6359 | if (operand != .none) { |
| ... | @@ -6332,13 +6370,14 @@ fn popErrorReturnTrace( | ... | @@ -6332,13 +6370,14 @@ fn popErrorReturnTrace( |
| 6332 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); | 6370 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6333 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); | 6371 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6334 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 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 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); | 6375 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6337 | } else if (is_non_error == null) { | 6376 | } else if (is_non_error == null) { |
| 6338 | // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need | 6377 | // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need |
| 6339 | // to pop any error trace that may have been propagated from our arguments. | 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 | const cond_block_inst = try block.addInstAsIndex(.{ | 6381 | const cond_block_inst = try block.addInstAsIndex(.{ |
| 6343 | .tag = .block, | 6382 | .tag = .block, |
| 6344 | .data = .{ | 6383 | .data = .{ |
| ... | @@ -6350,28 +6389,29 @@ fn popErrorReturnTrace( | ... | @@ -6350,28 +6389,29 @@ fn popErrorReturnTrace( |
| 6350 | }); | 6389 | }); |
| 6351 | | 6390 | |
| 6352 | var then_block = block.makeSubBlock(); | 6391 | var then_block = block.makeSubBlock(); |
| 6353 | defer then_block.instructions.deinit(sema.gpa); | 6392 | defer then_block.instructions.deinit(gpa); |
| 6354 | | 6393 | |
| 6355 | // If non-error, then pop the error return trace by restoring the index. | 6394 | // If non-error, then pop the error return trace by restoring the index. |
| 6356 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); | 6395 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6357 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); | 6396 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6358 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); | 6397 | const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty); |
| 6359 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); | 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 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); | 6401 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6362 | _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); | 6402 | _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); |
| 6363 | | 6403 | |
| 6364 | // Otherwise, do nothing | 6404 | // Otherwise, do nothing |
| 6365 | var else_block = block.makeSubBlock(); | 6405 | var else_block = block.makeSubBlock(); |
| 6366 | defer else_block.instructions.deinit(sema.gpa); | 6406 | defer else_block.instructions.deinit(gpa); |
| 6367 | _ = try else_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); | 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 | then_block.instructions.items.len + else_block.instructions.items.len + | 6410 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 6371 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block | 6411 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block |
| 6372 | | 6412 | |
| 6373 | const cond_br_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); | 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 | .operand = is_non_error_inst, | 6415 | .operand = is_non_error_inst, |
| 6376 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 6416 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 6377 | .then_body_len = @intCast(u32, then_block.instructions.items.len), | 6417 | .then_body_len = @intCast(u32, then_block.instructions.items.len), |
| ... | @@ -6414,7 +6454,7 @@ fn zirCall( | ... | @@ -6414,7 +6454,7 @@ fn zirCall( |
| 6414 | .direct => .{ .direct = try sema.resolveInst(extra.data.callee) }, | 6454 | .direct => .{ .direct = try sema.resolveInst(extra.data.callee) }, |
| 6415 | .field => blk: { | 6455 | .field => blk: { |
| 6416 | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); | 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 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 6458 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 6419 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); | 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,7 +6549,8 @@ fn zirCall( |
| 6509 | if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError(mod))) { | 6549 | if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError(mod))) { |
| 6510 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); | 6550 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6511 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); | 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 | // Insert a save instruction before the arg resolution + call instructions we just generated | 6555 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| 6515 | const save_inst = try block.insertInst(block_index, .{ | 6556 | const save_inst = try block.insertInst(block_index, .{ |
| ... | @@ -7436,9 +7477,10 @@ fn instantiateGenericCall( | ... | @@ -7436,9 +7477,10 @@ fn instantiateGenericCall( |
| 7436 | ) CompileError!Air.Inst.Ref { | 7477 | ) CompileError!Air.Inst.Ref { |
| 7437 | const mod = sema.mod; | 7478 | const mod = sema.mod; |
| 7438 | const gpa = sema.gpa; | 7479 | const gpa = sema.gpa; |
| | 7480 | const ip = &mod.intern_pool; |
| 7439 | | 7481 | |
| 7440 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); | 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 | .func => |function| function.index, | 7484 | .func => |function| function.index, |
| 7443 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?, | 7485 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?, |
| 7444 | else => unreachable, | 7486 | else => unreachable, |
| ... | @@ -7567,9 +7609,12 @@ fn instantiateGenericCall( | ... | @@ -7567,9 +7609,12 @@ fn instantiateGenericCall( |
| 7567 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); | 7609 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); |
| 7568 | const new_decl = mod.declPtr(new_decl_index); | 7610 | const new_decl = mod.declPtr(new_decl_index); |
| 7569 | // TODO better names for generic function instantiations | 7611 | // TODO better names for generic function instantiations |
| 7570 | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ | 7612 | // The ensureUnusedCapacity here protects against fn_owner_decl.name slice being |
| 7571 | fn_owner_decl.name, @enumToInt(new_decl_index), | 7613 | // reallocated during getOrPutStringFmt. |
| 7572 | }); | 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 | new_decl.name = decl_name; | 7618 | new_decl.name = decl_name; |
| 7574 | new_decl.src_line = fn_owner_decl.src_line; | 7619 | new_decl.src_line = fn_owner_decl.src_line; |
| 7575 | new_decl.is_pub = fn_owner_decl.is_pub; | 7620 | new_decl.is_pub = fn_owner_decl.is_pub; |
| ... | @@ -7590,12 +7635,8 @@ fn instantiateGenericCall( | ... | @@ -7590,12 +7635,8 @@ fn instantiateGenericCall( |
| 7590 | assert(new_decl.dependencies.keys().len == 0); | 7635 | assert(new_decl.dependencies.keys().len == 0); |
| 7591 | try mod.declareDeclDependencyType(new_decl_index, module_fn.owner_decl, .function_body); | 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 | const new_func = sema.resolveGenericInstantiationType( | 7638 | const new_func = sema.resolveGenericInstantiationType( |
| 7597 | block, | 7639 | block, |
| 7598 | new_decl_arena_allocator, | | |
| 7599 | fn_zir, | 7640 | fn_zir, |
| 7600 | new_decl, | 7641 | new_decl, |
| 7601 | new_decl_index, | 7642 | new_decl_index, |
| ... | @@ -7608,7 +7649,6 @@ fn instantiateGenericCall( | ... | @@ -7608,7 +7649,6 @@ fn instantiateGenericCall( |
| 7608 | bound_arg_src, | 7649 | bound_arg_src, |
| 7609 | ) catch |err| switch (err) { | 7650 | ) catch |err| switch (err) { |
| 7610 | error.GenericPoison, error.ComptimeReturn => { | 7651 | error.GenericPoison, error.ComptimeReturn => { |
| 7611 | new_decl_arena.deinit(); | | |
| 7612 | // Resolving the new function type below will possibly declare more decl dependencies | 7652 | // Resolving the new function type below will possibly declare more decl dependencies |
| 7613 | // and so we remove them all here in case of error. | 7653 | // and so we remove them all here in case of error. |
| 7614 | for (new_decl.dependencies.keys()) |dep_index| { | 7654 | for (new_decl.dependencies.keys()) |dep_index| { |
| ... | @@ -7623,10 +7663,6 @@ fn instantiateGenericCall( | ... | @@ -7623,10 +7663,6 @@ fn instantiateGenericCall( |
| 7623 | }, | 7663 | }, |
| 7624 | else => { | 7664 | else => { |
| 7625 | assert(mod.monomorphed_funcs.removeContext(new_module_func_index, .{ .mod = mod })); | 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 | // TODO look up the compile error that happened here and attach a note to it | 7666 | // TODO look up the compile error that happened here and attach a note to it |
| 7631 | // pointing here, at the generic instantiation callsite. | 7667 | // pointing here, at the generic instantiation callsite. |
| 7632 | if (sema.owner_func) |owner_func| { | 7668 | if (sema.owner_func) |owner_func| { |
| ... | @@ -7637,9 +7673,7 @@ fn instantiateGenericCall( | ... | @@ -7637,9 +7673,7 @@ fn instantiateGenericCall( |
| 7637 | return err; | 7673 | return err; |
| 7638 | }, | 7674 | }, |
| 7639 | }; | 7675 | }; |
| 7640 | errdefer new_decl_arena.deinit(); | | |
| 7641 | | 7676 | |
| 7642 | try new_decl.finalizeNewArena(&new_decl_arena); | | |
| 7643 | break :callee new_func; | 7677 | break :callee new_func; |
| 7644 | } else gop.key_ptr.*; | 7678 | } else gop.key_ptr.*; |
| 7645 | const callee = mod.funcPtr(callee_index); | 7679 | const callee = mod.funcPtr(callee_index); |
| ... | @@ -7729,7 +7763,6 @@ fn instantiateGenericCall( | ... | @@ -7729,7 +7763,6 @@ fn instantiateGenericCall( |
| 7729 | fn resolveGenericInstantiationType( | 7763 | fn resolveGenericInstantiationType( |
| 7730 | sema: *Sema, | 7764 | sema: *Sema, |
| 7731 | block: *Block, | 7765 | block: *Block, |
| 7732 | new_decl_arena_allocator: Allocator, | | |
| 7733 | fn_zir: Zir, | 7766 | fn_zir: Zir, |
| 7734 | new_decl: *Decl, | 7767 | new_decl: *Decl, |
| 7735 | new_decl_index: Decl.Index, | 7768 | new_decl_index: Decl.Index, |
| ... | @@ -7755,7 +7788,6 @@ fn resolveGenericInstantiationType( | ... | @@ -7755,7 +7788,6 @@ fn resolveGenericInstantiationType( |
| 7755 | .mod = mod, | 7788 | .mod = mod, |
| 7756 | .gpa = gpa, | 7789 | .gpa = gpa, |
| 7757 | .arena = sema.arena, | 7790 | .arena = sema.arena, |
| 7758 | .perm_arena = new_decl_arena_allocator, | | |
| 7759 | .code = fn_zir, | 7791 | .code = fn_zir, |
| 7760 | .owner_decl = new_decl, | 7792 | .owner_decl = new_decl, |
| 7761 | .owner_decl_index = new_decl_index, | 7793 | .owner_decl_index = new_decl_index, |
| ... | @@ -7764,7 +7796,8 @@ fn resolveGenericInstantiationType( | ... | @@ -7764,7 +7796,8 @@ fn resolveGenericInstantiationType( |
| 7764 | .fn_ret_ty = Type.void, | 7796 | .fn_ret_ty = Type.void, |
| 7765 | .owner_func = null, | 7797 | .owner_func = null, |
| 7766 | .owner_func_index = .none, | 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 | .comptime_args_fn_inst = module_fn.zir_body_inst, | 7801 | .comptime_args_fn_inst = module_fn.zir_body_inst, |
| 7769 | .preallocated_new_func = new_module_func.toOptional(), | 7802 | .preallocated_new_func = new_module_func.toOptional(), |
| 7770 | .is_generic_instantiation = true, | 7803 | .is_generic_instantiation = true, |
| ... | @@ -7931,10 +7964,6 @@ fn resolveGenericInstantiationType( | ... | @@ -7931,10 +7964,6 @@ fn resolveGenericInstantiationType( |
| 7931 | new_decl.owns_tv = true; | 7964 | new_decl.owns_tv = true; |
| 7932 | new_decl.analysis = .complete; | 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 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field | 7967 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field |
| 7939 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR | 7968 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR |
| 7940 | // parameters mapped appropriately. | 7969 | // parameters mapped appropriately. |
| ... | @@ -8134,13 +8163,13 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8134,13 +8163,13 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8134 | _ = block; | 8163 | _ = block; |
| 8135 | const mod = sema.mod; | 8164 | const mod = sema.mod; |
| 8136 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 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 | // Create an error set type with only this error value, and return the value. | 8168 | // Create an error set type with only this error value, and return the value. |
| 8139 | const kv = try sema.mod.getErrorValue(name); | 8169 | const error_set_type = try mod.singleErrorSetTypeNts(name); |
| 8140 | const error_set_type = try mod.singleErrorSetType(kv.key); | | |
| 8141 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 8170 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 8142 | .ty = error_set_type.toIntern(), | 8171 | .ty = error_set_type.toIntern(), |
| 8143 | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), | 8172 | .name = name, |
| 8144 | } })).toValue()); | 8173 | } })).toValue()); |
| 8145 | } | 8174 | } |
| 8146 | | 8175 | |
| ... | @@ -8162,7 +8191,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -8162,7 +8191,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8162 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; | 8191 | const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 8163 | return sema.addConstant(Type.err_int, try mod.intValue( | 8192 | return sema.addConstant(Type.err_int, try mod.intValue( |
| 8164 | Type.err_int, | 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,8 +8202,8 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8173 | switch (names.len) { | 8202 | switch (names.len) { |
| 8174 | 0 => return sema.addConstant(Type.err_int, try mod.intValue(Type.err_int, 0)), | 8203 | 0 => return sema.addConstant(Type.err_int, try mod.intValue(Type.err_int, 0)), |
| 8175 | 1 => { | 8204 | 1 => { |
| 8176 | const name = mod.intern_pool.stringToSlice(names[0]); | 8205 | const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(names[0]).?); |
| 8177 | return sema.addIntUnsigned(Type.err_int, mod.global_error_set.get(name).?); | 8206 | return sema.addIntUnsigned(Type.err_int, int); |
| 8178 | }, | 8207 | }, |
| 8179 | else => {}, | 8208 | else => {}, |
| 8180 | } | 8209 | } |
| ... | @@ -8197,11 +8226,11 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -8197,11 +8226,11 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 8197 | | 8226 | |
| 8198 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |value| { | 8227 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |value| { |
| 8199 | const int = try sema.usizeCast(block, operand_src, value.toUnsignedInt(mod)); | 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 | return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int}); | 8230 | return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int}); |
| 8202 | return sema.addConstant(Type.anyerror, (try mod.intern(.{ .err = .{ | 8231 | return sema.addConstant(Type.anyerror, (try mod.intern(.{ .err = .{ |
| 8203 | .ty = .anyerror_type, | 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 | } })).toValue()); | 8234 | } })).toValue()); |
| 8206 | } | 8235 | } |
| 8207 | try sema.requireRuntimeBlock(block, src, operand_src); | 8236 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -8917,7 +8946,7 @@ fn handleExternLibName( | ... | @@ -8917,7 +8946,7 @@ fn handleExternLibName( |
| 8917 | const FuncLinkSection = union(enum) { | 8946 | const FuncLinkSection = union(enum) { |
| 8918 | generic, | 8947 | generic, |
| 8919 | default, | 8948 | default, |
| 8920 | explicit: []const u8, | 8949 | explicit: InternPool.NullTerminatedString, |
| 8921 | }; | 8950 | }; |
| 8922 | | 8951 | |
| 8923 | fn funcCommon( | 8952 | fn funcCommon( |
| ... | @@ -9186,9 +9215,9 @@ fn funcCommon( | ... | @@ -9186,9 +9215,9 @@ fn funcCommon( |
| 9186 | }; | 9215 | }; |
| 9187 | | 9216 | |
| 9188 | sema.owner_decl.@"linksection" = switch (section) { | 9217 | sema.owner_decl.@"linksection" = switch (section) { |
| 9189 | .generic => undefined, | 9218 | .generic => .none, |
| 9190 | .default => null, | 9219 | .default => .none, |
| 9191 | .explicit => |section_name| try sema.perm_arena.dupeZ(u8, section_name), | 9220 | .explicit => |section_name| section_name.toOptional(), |
| 9192 | }; | 9221 | }; |
| 9193 | sema.owner_decl.@"align" = alignment orelse 0; | 9222 | sema.owner_decl.@"align" = alignment orelse 0; |
| 9194 | sema.owner_decl.@"addrspace" = address_space orelse .generic; | 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,11 +9601,12 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9572 | const tracy = trace(@src()); | 9601 | const tracy = trace(@src()); |
| 9573 | defer tracy.end(); | 9602 | defer tracy.end(); |
| 9574 | | 9603 | |
| | 9604 | const mod = sema.mod; |
| 9575 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9605 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9576 | const src = inst_data.src(); | 9606 | const src = inst_data.src(); |
| 9577 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 9607 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9578 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 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 | const object = try sema.resolveInst(extra.lhs); | 9610 | const object = try sema.resolveInst(extra.lhs); |
| 9581 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 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,11 +9615,12 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index, initializing: b |
| 9585 | const tracy = trace(@src()); | 9615 | const tracy = trace(@src()); |
| 9586 | defer tracy.end(); | 9616 | defer tracy.end(); |
| 9587 | | 9617 | |
| | 9618 | const mod = sema.mod; |
| 9588 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9619 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9589 | const src = inst_data.src(); | 9620 | const src = inst_data.src(); |
| 9590 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 9621 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9591 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 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 | const object_ptr = try sema.resolveInst(extra.lhs); | 9624 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9594 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, initializing); | 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,7 +9634,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9603 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9634 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9604 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 9635 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9605 | const object = try sema.resolveInst(extra.lhs); | 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 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 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,7 +9647,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9616 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9647 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9617 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 9648 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9618 | const object_ptr = try sema.resolveInst(extra.lhs); | 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 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); | 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,6 +10465,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10434 | | 10465 | |
| 10435 | const mod = sema.mod; | 10466 | const mod = sema.mod; |
| 10436 | const gpa = sema.gpa; | 10467 | const gpa = sema.gpa; |
| | 10468 | const ip = &mod.intern_pool; |
| 10437 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 10469 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 10438 | const src = inst_data.src(); | 10470 | const src = inst_data.src(); |
| 10439 | const src_node_offset = inst_data.src_node; | 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,7 +10637,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10605 | i, | 10637 | i, |
| 10606 | msg, | 10638 | msg, |
| 10607 | "unhandled enumeration value: '{s}'", | 10639 | "unhandled enumeration value: '{s}'", |
| 10608 | .{field_name}, | 10640 | .{ip.stringToSlice(field_name)}, |
| 10609 | ); | 10641 | ); |
| 10610 | } | 10642 | } |
| 10611 | try mod.errNoteNonLazy( | 10643 | try mod.errNoteNonLazy( |
| ... | @@ -10689,7 +10721,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10689,7 +10721,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10689 | errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa); | 10721 | errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa); |
| 10690 | | 10722 | |
| 10691 | for (operand_ty.errorSetNames(mod)) |error_name_ip| { | 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 | if (!seen_errors.contains(error_name) and special_prong != .@"else") { | 10725 | if (!seen_errors.contains(error_name) and special_prong != .@"else") { |
| 10694 | const msg = maybe_msg orelse blk: { | 10726 | const msg = maybe_msg orelse blk: { |
| 10695 | maybe_msg = try sema.errMsg( | 10727 | maybe_msg = try sema.errMsg( |
| ... | @@ -10758,7 +10790,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10758,7 +10790,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10758 | var names: Module.Fn.InferredErrorSet.NameMap = .{}; | 10790 | var names: Module.Fn.InferredErrorSet.NameMap = .{}; |
| 10759 | try names.ensureUnusedCapacity(sema.arena, error_names.len); | 10791 | try names.ensureUnusedCapacity(sema.arena, error_names.len); |
| 10760 | for (error_names) |error_name_ip| { | 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 | if (seen_errors.contains(error_name)) continue; | 10794 | if (seen_errors.contains(error_name)) continue; |
| 10763 | | 10795 | |
| 10764 | names.putAssumeCapacityNoClobber(error_name_ip, {}); | 10796 | names.putAssumeCapacityNoClobber(error_name_ip, {}); |
| ... | @@ -12062,7 +12094,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12062,7 +12094,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12062 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12094 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12063 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 12095 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12064 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); | 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 | const ty = try sema.resolveTypeFields(unresolved_ty); | 12098 | const ty = try sema.resolveTypeFields(unresolved_ty); |
| 12067 | const ip = &mod.intern_pool; | 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,19 +12102,17 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12070 | switch (ip.indexToKey(ty.toIntern())) { | 12102 | switch (ip.indexToKey(ty.toIntern())) { |
| 12071 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { | 12103 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 12072 | .Slice => { | 12104 | .Slice => { |
| 12073 | if (mem.eql(u8, field_name, "ptr")) break :hf true; | 12105 | if (ip.stringEqlSlice(field_name, "ptr")) break :hf true; |
| 12074 | if (mem.eql(u8, field_name, "len")) break :hf true; | 12106 | if (ip.stringEqlSlice(field_name, "len")) break :hf true; |
| 12075 | break :hf false; | 12107 | break :hf false; |
| 12076 | }, | 12108 | }, |
| 12077 | else => {}, | 12109 | else => {}, |
| 12078 | }, | 12110 | }, |
| 12079 | .anon_struct_type => |anon_struct| { | 12111 | .anon_struct_type => |anon_struct| { |
| 12080 | if (anon_struct.names.len != 0) { | 12112 | if (anon_struct.names.len != 0) { |
| 12081 | // If the string is not interned, then the field certainly is not present. | 12113 | break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null; |
| 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; | | |
| 12084 | } else { | 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 | break :hf field_index < ty.structFieldCount(mod); | 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,11 +12127,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12097 | break :hf union_obj.fields.contains(field_name); | 12127 | break :hf union_obj.fields.contains(field_name); |
| 12098 | }, | 12128 | }, |
| 12099 | .enum_type => |enum_type| { | 12129 | .enum_type => |enum_type| { |
| 12100 | // If the string is not interned, then the field certainly is not present. | 12130 | break :hf enum_type.nameIndex(ip, field_name) != null; |
| 12101 | const name_interned = ip.getString(field_name).unwrap() orelse break :hf false; | | |
| 12102 | break :hf enum_type.nameIndex(ip, name_interned) != 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 | else => {}, | 12133 | else => {}, |
| 12106 | } | 12134 | } |
| 12107 | return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{ | 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,7 +12151,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 12123 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12151 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12124 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 12152 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12125 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 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 | try sema.checkNamespaceType(block, lhs_src, container_type); | 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,14 +12246,12 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12218 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12246 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 12219 | const mod = sema.mod; | 12247 | const mod = sema.mod; |
| 12220 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 12248 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 12221 | const err_name = inst_data.get(sema.code); | 12249 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 12222 | | 12250 | _ = try mod.getErrorValue(name); |
| 12223 | // Return the error code from the function. | 12251 | const error_set_type = try mod.singleErrorSetTypeNts(name); |
| 12224 | const kv = try mod.getErrorValue(err_name); | | |
| 12225 | const error_set_type = try mod.singleErrorSetType(kv.key); | | |
| 12226 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 12252 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 12227 | .ty = error_set_type.toIntern(), | 12253 | .ty = error_set_type.toIntern(), |
| 12228 | .name = mod.intern_pool.getString(kv.key).unwrap().?, | 12254 | .name = name, |
| 12229 | } })).toValue()); | 12255 | } })).toValue()); |
| 12230 | } | 12256 | } |
| 12231 | | 12257 | |
| ... | @@ -15730,12 +15756,7 @@ fn zirThis( | ... | @@ -15730,12 +15756,7 @@ fn zirThis( |
| 15730 | return sema.analyzeDeclVal(block, src, this_decl_index); | 15756 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 15731 | } | 15757 | } |
| 15732 | | 15758 | |
| 15733 | fn zirClosureCapture( | 15759 | fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 15734 | sema: *Sema, | | |
| 15735 | block: *Block, | | |
| 15736 | inst: Zir.Inst.Index, | | |
| 15737 | ) CompileError!void { | | |
| 15738 | // TODO: Compile error when closed over values are modified | | |
| 15739 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 15760 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 15740 | // Closures are not necessarily constant values. For example, the | 15761 | // Closures are not necessarily constant values. For example, the |
| 15741 | // code might do something like this: | 15762 | // code might do something like this: |
| ... | @@ -15754,13 +15775,8 @@ fn zirClosureCapture( | ... | @@ -15754,13 +15775,8 @@ fn zirClosureCapture( |
| 15754 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, capture); | 15775 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, capture); |
| 15755 | } | 15776 | } |
| 15756 | | 15777 | |
| 15757 | fn zirClosureGet( | 15778 | fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15758 | sema: *Sema, | | |
| 15759 | block: *Block, | | |
| 15760 | inst: Zir.Inst.Index, | | |
| 15761 | ) CompileError!Air.Inst.Ref { | | |
| 15762 | const mod = sema.mod; | 15779 | const mod = sema.mod; |
| 15763 | // TODO CLOSURE: Test this with inline functions | | |
| 15764 | const inst_data = sema.code.instructions.items(.data)[inst].inst_node; | 15780 | const inst_data = sema.code.instructions.items(.data)[inst].inst_node; |
| 15765 | var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?; | 15781 | var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?; |
| 15766 | // Note: The target closure must be in this scope list. | 15782 | // Note: The target closure must be in this scope list. |
| ... | @@ -15896,7 +15912,7 @@ fn zirBuiltinSrc( | ... | @@ -15896,7 +15912,7 @@ fn zirBuiltinSrc( |
| 15896 | const func_name_val = blk: { | 15912 | const func_name_val = blk: { |
| 15897 | var anon_decl = try block.startAnonDecl(); | 15913 | var anon_decl = try block.startAnonDecl(); |
| 15898 | defer anon_decl.deinit(); | 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 | const new_decl_ty = try mod.arrayType(.{ | 15916 | const new_decl_ty = try mod.arrayType(.{ |
| 15901 | .len = name.len, | 15917 | .len = name.len, |
| 15902 | .child = .u8_type, | 15918 | .child = .u8_type, |
| ... | @@ -15965,6 +15981,7 @@ fn zirBuiltinSrc( | ... | @@ -15965,6 +15981,7 @@ fn zirBuiltinSrc( |
| 15965 | fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15981 | fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15966 | const mod = sema.mod; | 15982 | const mod = sema.mod; |
| 15967 | const gpa = sema.gpa; | 15983 | const gpa = sema.gpa; |
| | 15984 | const ip = &mod.intern_pool; |
| 15968 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 15985 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 15969 | const src = inst_data.src(); | 15986 | const src = inst_data.src(); |
| 15970 | const ty = try sema.resolveType(block, src, inst_data.operand); | 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,7 +16012,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15995 | block, | 16012 | block, |
| 15996 | src, | 16013 | src, |
| 15997 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16014 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 15998 | "Fn", | 16015 | try ip.getOrPutString(gpa, "Fn"), |
| 15999 | )).?; | 16016 | )).?; |
| 16000 | try mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index); | 16017 | try mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index); |
| 16001 | try sema.ensureDeclAnalyzed(fn_info_decl_index); | 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,7 +16023,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16006 | block, | 16023 | block, |
| 16007 | src, | 16024 | src, |
| 16008 | fn_info_ty.getNamespaceIndex(mod).unwrap().?, | 16025 | fn_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16009 | "Param", | 16026 | try ip.getOrPutString(gpa, "Param"), |
| 16010 | )).?; | 16027 | )).?; |
| 16011 | try mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index); | 16028 | try mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index); |
| 16012 | try sema.ensureDeclAnalyzed(param_info_decl_index); | 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,8 +16035,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16018 | const info = mod.typeToFunc(ty).?; | 16035 | const info = mod.typeToFunc(ty).?; |
| 16019 | const param_ty = info.param_types[i]; | 16036 | const param_ty = info.param_types[i]; |
| 16020 | const is_generic = param_ty == .generic_poison_type; | 16037 | const is_generic = param_ty == .generic_poison_type; |
| 16021 | const param_ty_val = try mod.intern_pool.get(gpa, .{ .opt = .{ | 16038 | const param_ty_val = try ip.get(gpa, .{ .opt = .{ |
| 16022 | .ty = try mod.intern_pool.get(gpa, .{ .opt_type = .type_type }), | 16039 | .ty = try ip.get(gpa, .{ .opt_type = .type_type }), |
| 16023 | .val = if (is_generic) .none else param_ty, | 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,7 +16087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16070 | | 16087 | |
| 16071 | const info = mod.typeToFunc(ty).?; | 16088 | const info = mod.typeToFunc(ty).?; |
| 16072 | const ret_ty_opt = try mod.intern(.{ .opt = .{ | 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 | .val = if (info.return_type == .generic_poison_type) .none else info.return_type, | 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,7 +16121,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16104 | block, | 16121 | block, |
| 16105 | src, | 16122 | src, |
| 16106 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16123 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16107 | "Int", | 16124 | try ip.getOrPutString(gpa, "Int"), |
| 16108 | )).?; | 16125 | )).?; |
| 16109 | try mod.declareDeclDependency(sema.owner_decl_index, int_info_decl_index); | 16126 | try mod.declareDeclDependency(sema.owner_decl_index, int_info_decl_index); |
| 16110 | try sema.ensureDeclAnalyzed(int_info_decl_index); | 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,7 +16150,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16133 | block, | 16150 | block, |
| 16134 | src, | 16151 | src, |
| 16135 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16152 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16136 | "Float", | 16153 | try ip.getOrPutString(gpa, "Float"), |
| 16137 | )).?; | 16154 | )).?; |
| 16138 | try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index); | 16155 | try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index); |
| 16139 | try sema.ensureDeclAnalyzed(float_info_decl_index); | 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,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16166 | block, | 16183 | block, |
| 16167 | src, | 16184 | src, |
| 16168 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, | 16185 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16169 | "Pointer", | 16186 | try ip.getOrPutString(gpa, "Pointer"), |
| 16170 | )).?; | 16187 | )).?; |
| 16171 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 16188 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16172 | try sema.ensureDeclAnalyzed(decl_index); | 16189 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | @@ -16178,7 +16195,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16178,7 +16195,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16178 | block, | 16195 | block, |
| 16179 | src, | 16196 | src, |
| 16180 | pointer_ty.getNamespaceIndex(mod).unwrap().?, | 16197 | pointer_ty.getNamespaceIndex(mod).unwrap().?, |
| 16181 | "Size", | 16198 | try ip.getOrPutString(gpa, "Size"), |
| 16182 | )).?; | 16199 | )).?; |
| 16183 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 16200 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16184 | try sema.ensureDeclAnalyzed(decl_index); | 16201 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | @@ -16219,7 +16236,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16219,7 +16236,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16219 | block, | 16236 | block, |
| 16220 | src, | 16237 | src, |
| 16221 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16238 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16222 | "Array", | 16239 | try ip.getOrPutString(gpa, "Array"), |
| 16223 | )).?; | 16240 | )).?; |
| 16224 | try mod.declareDeclDependency(sema.owner_decl_index, array_field_ty_decl_index); | 16241 | try mod.declareDeclDependency(sema.owner_decl_index, array_field_ty_decl_index); |
| 16225 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); | 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,7 +16268,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16251 | block, | 16268 | block, |
| 16252 | src, | 16269 | src, |
| 16253 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16270 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16254 | "Vector", | 16271 | try ip.getOrPutString(gpa, "Vector"), |
| 16255 | )).?; | 16272 | )).?; |
| 16256 | try mod.declareDeclDependency(sema.owner_decl_index, vector_field_ty_decl_index); | 16273 | try mod.declareDeclDependency(sema.owner_decl_index, vector_field_ty_decl_index); |
| 16257 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); | 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,7 +16298,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16281 | block, | 16298 | block, |
| 16282 | src, | 16299 | src, |
| 16283 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16300 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16284 | "Optional", | 16301 | try ip.getOrPutString(gpa, "Optional"), |
| 16285 | )).?; | 16302 | )).?; |
| 16286 | try mod.declareDeclDependency(sema.owner_decl_index, optional_field_ty_decl_index); | 16303 | try mod.declareDeclDependency(sema.owner_decl_index, optional_field_ty_decl_index); |
| 16287 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); | 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,7 +16329,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16312 | block, | 16329 | block, |
| 16313 | src, | 16330 | src, |
| 16314 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16331 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16315 | "Error", | 16332 | try ip.getOrPutString(gpa, "Error"), |
| 16316 | )).?; | 16333 | )).?; |
| 16317 | try mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index); | 16334 | try mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index); |
| 16318 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); | 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,7 +16349,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16332 | const names = ty.errorSetNames(mod); | 16349 | const names = ty.errorSetNames(mod); |
| 16333 | const vals = try sema.arena.alloc(InternPool.Index, names.len); | 16350 | const vals = try sema.arena.alloc(InternPool.Index, names.len); |
| 16334 | for (vals, names) |*field_val, name_ip| { | 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 | const name_val = v: { | 16353 | const name_val = v: { |
| 16337 | var anon_decl = try block.startAnonDecl(); | 16354 | var anon_decl = try block.startAnonDecl(); |
| 16338 | defer anon_decl.deinit(); | 16355 | defer anon_decl.deinit(); |
| ... | @@ -16415,7 +16432,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16415,7 +16432,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16415 | block, | 16432 | block, |
| 16416 | src, | 16433 | src, |
| 16417 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16434 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16418 | "ErrorUnion", | 16435 | try ip.getOrPutString(gpa, "ErrorUnion"), |
| 16419 | )).?; | 16436 | )).?; |
| 16420 | try mod.declareDeclDependency(sema.owner_decl_index, error_union_field_ty_decl_index); | 16437 | try mod.declareDeclDependency(sema.owner_decl_index, error_union_field_ty_decl_index); |
| 16421 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); | 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,7 +16457,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16440 | }, | 16457 | }, |
| 16441 | .Enum => { | 16458 | .Enum => { |
| 16442 | // TODO: look into memoizing this result. | 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 | const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive); | 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,7 +16469,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16452 | block, | 16469 | block, |
| 16453 | src, | 16470 | src, |
| 16454 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16471 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16455 | "EnumField", | 16472 | try ip.getOrPutString(gpa, "EnumField"), |
| 16456 | )).?; | 16473 | )).?; |
| 16457 | try mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index); | 16474 | try mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index); |
| 16458 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); | 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,8 +16479,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16462 | | 16479 | |
| 16463 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); | 16480 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); |
| 16464 | for (enum_field_vals, 0..) |*field_val, i| { | 16481 | for (enum_field_vals, 0..) |*field_val, i| { |
| 16465 | const name_ip = mod.intern_pool.indexToKey(ty.toIntern()).enum_type.names[i]; | 16482 | const name_ip = ip.indexToKey(ty.toIntern()).enum_type.names[i]; |
| 16466 | const name = mod.intern_pool.stringToSlice(name_ip); | 16483 | const name = ip.stringToSlice(name_ip); |
| 16467 | const name_val = v: { | 16484 | const name_val = v: { |
| 16468 | var anon_decl = try block.startAnonDecl(); | 16485 | var anon_decl = try block.startAnonDecl(); |
| 16469 | defer anon_decl.deinit(); | 16486 | defer anon_decl.deinit(); |
| ... | @@ -16532,7 +16549,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16532,7 +16549,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16532 | block, | 16549 | block, |
| 16533 | src, | 16550 | src, |
| 16534 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16551 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16535 | "Enum", | 16552 | try ip.getOrPutString(gpa, "Enum"), |
| 16536 | )).?; | 16553 | )).?; |
| 16537 | try mod.declareDeclDependency(sema.owner_decl_index, type_enum_ty_decl_index); | 16554 | try mod.declareDeclDependency(sema.owner_decl_index, type_enum_ty_decl_index); |
| 16538 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); | 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,7 +16587,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16570 | block, | 16587 | block, |
| 16571 | src, | 16588 | src, |
| 16572 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16589 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16573 | "Union", | 16590 | try ip.getOrPutString(gpa, "Union"), |
| 16574 | )).?; | 16591 | )).?; |
| 16575 | try mod.declareDeclDependency(sema.owner_decl_index, type_union_ty_decl_index); | 16592 | try mod.declareDeclDependency(sema.owner_decl_index, type_union_ty_decl_index); |
| 16576 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); | 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,7 +16600,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16583 | block, | 16600 | block, |
| 16584 | src, | 16601 | src, |
| 16585 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16602 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16586 | "UnionField", | 16603 | try ip.getOrPutString(gpa, "UnionField"), |
| 16587 | )).?; | 16604 | )).?; |
| 16588 | try mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index); | 16605 | try mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index); |
| 16589 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); | 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,7 +16618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16601 | | 16618 | |
| 16602 | for (union_field_vals, 0..) |*field_val, i| { | 16619 | for (union_field_vals, 0..) |*field_val, i| { |
| 16603 | const field = union_fields.values()[i]; | 16620 | const field = union_fields.values()[i]; |
| 16604 | const name = union_fields.keys()[i]; | 16621 | const name = ip.stringToSlice(union_fields.keys()[i]); |
| 16605 | const name_val = v: { | 16622 | const name_val = v: { |
| 16606 | var anon_decl = try block.startAnonDecl(); | 16623 | var anon_decl = try block.startAnonDecl(); |
| 16607 | defer anon_decl.deinit(); | 16624 | defer anon_decl.deinit(); |
| ... | @@ -16682,7 +16699,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16682,7 +16699,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16682 | block, | 16699 | block, |
| 16683 | src, | 16700 | src, |
| 16684 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, | 16701 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16685 | "ContainerLayout", | 16702 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 16686 | )).?; | 16703 | )).?; |
| 16687 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 16704 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16688 | try sema.ensureDeclAnalyzed(decl_index); | 16705 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | @@ -16721,7 +16738,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16721,7 +16738,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16721 | block, | 16738 | block, |
| 16722 | src, | 16739 | src, |
| 16723 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16740 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16724 | "Struct", | 16741 | try ip.getOrPutString(gpa, "Struct"), |
| 16725 | )).?; | 16742 | )).?; |
| 16726 | try mod.declareDeclDependency(sema.owner_decl_index, type_struct_ty_decl_index); | 16743 | try mod.declareDeclDependency(sema.owner_decl_index, type_struct_ty_decl_index); |
| 16727 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); | 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,7 +16751,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16734 | block, | 16751 | block, |
| 16735 | src, | 16752 | src, |
| 16736 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16753 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16737 | "StructField", | 16754 | try ip.getOrPutString(gpa, "StructField"), |
| 16738 | )).?; | 16755 | )).?; |
| 16739 | try mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index); | 16756 | try mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index); |
| 16740 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); | 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,11 +16766,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16749 | var struct_field_vals: []InternPool.Index = &.{}; | 16766 | var struct_field_vals: []InternPool.Index = &.{}; |
| 16750 | defer gpa.free(struct_field_vals); | 16767 | defer gpa.free(struct_field_vals); |
| 16751 | fv: { | 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 | .anon_struct_type => |tuple| { | 16770 | .anon_struct_type => |tuple| { |
| 16754 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len); | 16771 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len); |
| 16755 | for (struct_field_vals, 0..) |*struct_field_val, i| { | 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 | const field_ty = anon_struct_type.types[i]; | 16774 | const field_ty = anon_struct_type.types[i]; |
| 16758 | const field_val = anon_struct_type.values[i]; | 16775 | const field_val = anon_struct_type.values[i]; |
| 16759 | const name_val = v: { | 16776 | const name_val = v: { |
| ... | @@ -16761,7 +16778,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16761,7 +16778,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16761 | defer anon_decl.deinit(); | 16778 | defer anon_decl.deinit(); |
| 16762 | const bytes = if (tuple.names.len != 0) | 16779 | const bytes = if (tuple.names.len != 0) |
| 16763 | // https://github.com/ziglang/zig/issues/15709 | 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 | else | 16782 | else |
| 16766 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); | 16783 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 16767 | const new_decl_ty = try mod.arrayType(.{ | 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,7 +16832,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16815 | struct_field_vals, | 16832 | struct_field_vals, |
| 16816 | struct_obj.fields.keys(), | 16833 | struct_obj.fields.keys(), |
| 16817 | struct_obj.fields.values(), | 16834 | struct_obj.fields.values(), |
| 16818 | ) |*field_val, name, field| { | 16835 | ) |*field_val, name_nts, field| { |
| | 16836 | const name = ip.stringToSlice(name_nts); |
| 16819 | const name_val = v: { | 16837 | const name_val = v: { |
| 16820 | var anon_decl = try block.startAnonDecl(); | 16838 | var anon_decl = try block.startAnonDecl(); |
| 16821 | defer anon_decl.deinit(); | 16839 | defer anon_decl.deinit(); |
| ... | @@ -16838,10 +16856,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -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 | null | 16860 | null |
| 16843 | else | 16861 | else |
| 16844 | field.default_val; | 16862 | field.default_val.toValue(); |
| 16845 | const default_val_ptr = try sema.optRefValue(block, field.ty, opt_default_val); | 16863 | const default_val_ptr = try sema.optRefValue(block, field.ty, opt_default_val); |
| 16846 | const alignment = field.alignment(mod, layout); | 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,7 +16926,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16908 | block, | 16926 | block, |
| 16909 | src, | 16927 | src, |
| 16910 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, | 16928 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 16911 | "ContainerLayout", | 16929 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 16912 | )).?; | 16930 | )).?; |
| 16913 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 16931 | try mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 16914 | try sema.ensureDeclAnalyzed(decl_index); | 16932 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | @@ -16945,7 +16963,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16945,7 +16963,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16945 | block, | 16963 | block, |
| 16946 | src, | 16964 | src, |
| 16947 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 16965 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16948 | "Opaque", | 16966 | try ip.getOrPutString(gpa, "Opaque"), |
| 16949 | )).?; | 16967 | )).?; |
| 16950 | try mod.declareDeclDependency(sema.owner_decl_index, type_opaque_ty_decl_index); | 16968 | try mod.declareDeclDependency(sema.owner_decl_index, type_opaque_ty_decl_index); |
| 16951 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); | 16969 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| ... | @@ -16982,6 +17000,8 @@ fn typeInfoDecls( | ... | @@ -16982,6 +17000,8 @@ fn typeInfoDecls( |
| 16982 | opt_namespace: Module.Namespace.OptionalIndex, | 17000 | opt_namespace: Module.Namespace.OptionalIndex, |
| 16983 | ) CompileError!InternPool.Index { | 17001 | ) CompileError!InternPool.Index { |
| 16984 | const mod = sema.mod; | 17002 | const mod = sema.mod; |
| | 17003 | const gpa = sema.gpa; |
| | 17004 | |
| 16985 | var decls_anon_decl = try block.startAnonDecl(); | 17005 | var decls_anon_decl = try block.startAnonDecl(); |
| 16986 | defer decls_anon_decl.deinit(); | 17006 | defer decls_anon_decl.deinit(); |
| 16987 | | 17007 | |
| ... | @@ -16990,7 +17010,7 @@ fn typeInfoDecls( | ... | @@ -16990,7 +17010,7 @@ fn typeInfoDecls( |
| 16990 | block, | 17010 | block, |
| 16991 | src, | 17011 | src, |
| 16992 | type_info_ty.getNamespaceIndex(mod).unwrap().?, | 17012 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16993 | "Declaration", | 17013 | try mod.intern_pool.getOrPutString(gpa, "Declaration"), |
| 16994 | )).?; | 17014 | )).?; |
| 16995 | try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index); | 17015 | try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index); |
| 16996 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); | 17016 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| ... | @@ -16999,10 +17019,10 @@ fn typeInfoDecls( | ... | @@ -16999,10 +17019,10 @@ fn typeInfoDecls( |
| 16999 | }; | 17019 | }; |
| 17000 | try sema.queueFullTypeResolution(declaration_ty); | 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 | defer decl_vals.deinit(); | 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 | defer seen_namespaces.deinit(); | 17026 | defer seen_namespaces.deinit(); |
| 17007 | | 17027 | |
| 17008 | if (opt_namespace.unwrap()) |namespace_index| { | 17028 | if (opt_namespace.unwrap()) |namespace_index| { |
| ... | @@ -17061,7 +17081,7 @@ fn typeInfoNamespaceDecls( | ... | @@ -17061,7 +17081,7 @@ fn typeInfoNamespaceDecls( |
| 17061 | const name_val = v: { | 17081 | const name_val = v: { |
| 17062 | var anon_decl = try block.startAnonDecl(); | 17082 | var anon_decl = try block.startAnonDecl(); |
| 17063 | defer anon_decl.deinit(); | 17083 | defer anon_decl.deinit(); |
| 17064 | const name = mem.span(decl.name); | 17084 | const name = mod.intern_pool.stringToSlice(decl.name); |
| 17065 | const new_decl_ty = try mod.arrayType(.{ | 17085 | const new_decl_ty = try mod.arrayType(.{ |
| 17066 | .len = name.len, | 17086 | .len = name.len, |
| 17067 | .child = .u8_type, | 17087 | .child = .u8_type, |
| ... | @@ -17696,15 +17716,14 @@ fn zirRetErrValue( | ... | @@ -17696,15 +17716,14 @@ fn zirRetErrValue( |
| 17696 | ) CompileError!Zir.Inst.Index { | 17716 | ) CompileError!Zir.Inst.Index { |
| 17697 | const mod = sema.mod; | 17717 | const mod = sema.mod; |
| 17698 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 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 | const src = inst_data.src(); | 17721 | const src = inst_data.src(); |
| 17701 | | | |
| 17702 | // Return the error code from the function. | 17722 | // Return the error code from the function. |
| 17703 | const kv = try mod.getErrorValue(err_name); | 17723 | const error_set_type = try mod.singleErrorSetTypeNts(err_name); |
| 17704 | const error_set_type = try mod.singleErrorSetType(err_name); | | |
| 17705 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 17724 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 17706 | .ty = error_set_type.toIntern(), | 17725 | .ty = error_set_type.toIntern(), |
| 17707 | .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key), | 17726 | .name = err_name, |
| 17708 | } })).toValue()); | 17727 | } })).toValue()); |
| 17709 | return sema.analyzeRet(block, result_inst, src); | 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,7 +18196,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18177 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 18196 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 18178 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; | 18197 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 18179 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); | 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 | const init = try sema.resolveInst(extra.init); | 18200 | const init = try sema.resolveInst(extra.init); |
| 18182 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); | 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,7 +18208,7 @@ fn unionInit( |
| 18189 | init_src: LazySrcLoc, | 18208 | init_src: LazySrcLoc, |
| 18190 | union_ty: Type, | 18209 | union_ty: Type, |
| 18191 | union_ty_src: LazySrcLoc, | 18210 | union_ty_src: LazySrcLoc, |
| 18192 | field_name: []const u8, | 18211 | field_name: InternPool.NullTerminatedString, |
| 18193 | field_src: LazySrcLoc, | 18212 | field_src: LazySrcLoc, |
| 18194 | ) CompileError!Air.Inst.Ref { | 18213 | ) CompileError!Air.Inst.Ref { |
| 18195 | const mod = sema.mod; | 18214 | const mod = sema.mod; |
| ... | @@ -18257,7 +18276,7 @@ fn zirStructInit( | ... | @@ -18257,7 +18276,7 @@ fn zirStructInit( |
| 18257 | const field_type_data = zir_datas[item.data.field_type].pl_node; | 18276 | const field_type_data = zir_datas[item.data.field_type].pl_node; |
| 18258 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 18277 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 18259 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 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 | const field_index = if (resolved_ty.isTuple(mod)) | 18280 | const field_index = if (resolved_ty.isTuple(mod)) |
| 18262 | try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src) | 18281 | try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src) |
| 18263 | else | 18282 | else |
| ... | @@ -18298,7 +18317,7 @@ fn zirStructInit( | ... | @@ -18298,7 +18317,7 @@ fn zirStructInit( |
| 18298 | const field_type_data = zir_datas[item.data.field_type].pl_node; | 18317 | const field_type_data = zir_datas[item.data.field_type].pl_node; |
| 18299 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 18318 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 18300 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 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 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); | 18321 | const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src); |
| 18303 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); | 18322 | const tag_ty = resolved_ty.unionTagTypeHypothetical(mod); |
| 18304 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); | 18323 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?); |
| ... | @@ -18347,12 +18366,12 @@ fn finishStructInit( | ... | @@ -18347,12 +18366,12 @@ fn finishStructInit( |
| 18347 | is_ref: bool, | 18366 | is_ref: bool, |
| 18348 | ) CompileError!Air.Inst.Ref { | 18367 | ) CompileError!Air.Inst.Ref { |
| 18349 | const mod = sema.mod; | 18368 | const mod = sema.mod; |
| 18350 | const gpa = sema.gpa; | 18369 | const ip = &mod.intern_pool; |
| 18351 | | 18370 | |
| 18352 | var root_msg: ?*Module.ErrorMsg = null; | 18371 | var root_msg: ?*Module.ErrorMsg = null; |
| 18353 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); | 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 | .anon_struct_type => |anon_struct| { | 18375 | .anon_struct_type => |anon_struct| { |
| 18357 | for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| { | 18376 | for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| { |
| 18358 | if (field_inits[i] != .none) continue; | 18377 | if (field_inits[i] != .none) continue; |
| ... | @@ -18366,9 +18385,9 @@ fn finishStructInit( | ... | @@ -18366,9 +18385,9 @@ fn finishStructInit( |
| 18366 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 18385 | root_msg = try sema.errMsg(block, init_src, template, .{i}); |
| 18367 | } | 18386 | } |
| 18368 | } else { | 18387 | } else { |
| 18369 | const field_name = mod.intern_pool.stringToSlice(anon_struct.names[i]); | 18388 | const field_name = anon_struct.names[i]; |
| 18370 | const template = "missing struct field: {s}"; | 18389 | const template = "missing struct field: {s}"; |
| 18371 | const args = .{field_name}; | 18390 | const args = .{ip.stringToSlice(field_name)}; |
| 18372 | if (root_msg) |msg| { | 18391 | if (root_msg) |msg| { |
| 18373 | try sema.errNote(block, init_src, msg, template, args); | 18392 | try sema.errNote(block, init_src, msg, template, args); |
| 18374 | } else { | 18393 | } else { |
| ... | @@ -18385,17 +18404,17 @@ fn finishStructInit( | ... | @@ -18385,17 +18404,17 @@ fn finishStructInit( |
| 18385 | for (struct_obj.fields.values(), 0..) |field, i| { | 18404 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 18386 | if (field_inits[i] != .none) continue; | 18405 | if (field_inits[i] != .none) continue; |
| 18387 | | 18406 | |
| 18388 | if (field.default_val.toIntern() == .unreachable_value) { | 18407 | if (field.default_val == .none) { |
| 18389 | const field_name = struct_obj.fields.keys()[i]; | 18408 | const field_name = struct_obj.fields.keys()[i]; |
| 18390 | const template = "missing struct field: {s}"; | 18409 | const template = "missing struct field: {s}"; |
| 18391 | const args = .{field_name}; | 18410 | const args = .{ip.stringToSlice(field_name)}; |
| 18392 | if (root_msg) |msg| { | 18411 | if (root_msg) |msg| { |
| 18393 | try sema.errNote(block, init_src, msg, template, args); | 18412 | try sema.errNote(block, init_src, msg, template, args); |
| 18394 | } else { | 18413 | } else { |
| 18395 | root_msg = try sema.errMsg(block, init_src, template, args); | 18414 | root_msg = try sema.errMsg(block, init_src, template, args); |
| 18396 | } | 18415 | } |
| 18397 | } else { | 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,10 +18423,9 @@ fn finishStructInit( |
| 18404 | | 18423 | |
| 18405 | if (root_msg) |msg| { | 18424 | if (root_msg) |msg| { |
| 18406 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 18425 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 18407 | const fqn = try struct_obj.getFullyQualifiedName(sema.mod); | 18426 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); |
| 18408 | defer gpa.free(fqn); | 18427 | try mod.errNoteNonLazy( |
| 18409 | try sema.mod.errNoteNonLazy( | 18428 | struct_obj.srcLoc(mod), |
| 18410 | struct_obj.srcLoc(sema.mod), | | |
| 18411 | msg, | 18429 | msg, |
| 18412 | "struct '{s}' declared here", | 18430 | "struct '{s}' declared here", |
| 18413 | .{fqn}, | 18431 | .{fqn}, |
| ... | @@ -18826,11 +18844,13 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -18826,11 +18844,13 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 18826 | const ty_src = inst_data.src(); | 18844 | const ty_src = inst_data.src(); |
| 18827 | const field_src = inst_data.src(); | 18845 | const field_src = inst_data.src(); |
| 18828 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 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 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); | 18848 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 18831 | } | 18849 | } |
| 18832 | | 18850 | |
| 18833 | fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 18854 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 18835 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 18855 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 18836 | const ty_src = inst_data.src(); | 18856 | const ty_src = inst_data.src(); |
| ... | @@ -18843,7 +18863,8 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -18843,7 +18863,8 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18843 | error.GenericPoison => return Air.Inst.Ref.generic_poison_type, | 18863 | error.GenericPoison => return Air.Inst.Ref.generic_poison_type, |
| 18844 | else => |e| return e, | 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 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); | 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,7 +18872,7 @@ fn fieldType( |
| 18851 | sema: *Sema, | 18872 | sema: *Sema, |
| 18852 | block: *Block, | 18873 | block: *Block, |
| 18853 | aggregate_ty: Type, | 18874 | aggregate_ty: Type, |
| 18854 | field_name: []const u8, | 18875 | field_name: InternPool.NullTerminatedString, |
| 18855 | field_src: LazySrcLoc, | 18876 | field_src: LazySrcLoc, |
| 18856 | ty_src: LazySrcLoc, | 18877 | ty_src: LazySrcLoc, |
| 18857 | ) CompileError!Air.Inst.Ref { | 18878 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -19050,13 +19071,14 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19050,13 +19071,14 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19050 | const operand = try sema.resolveInst(inst_data.operand); | 19071 | const operand = try sema.resolveInst(inst_data.operand); |
| 19051 | const operand_ty = sema.typeOf(operand); | 19072 | const operand_ty = sema.typeOf(operand); |
| 19052 | const mod = sema.mod; | 19073 | const mod = sema.mod; |
| | 19074 | const ip = &mod.intern_pool; |
| 19053 | | 19075 | |
| 19054 | try sema.resolveTypeLayout(operand_ty); | 19076 | try sema.resolveTypeLayout(operand_ty); |
| 19055 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { | 19077 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 19056 | .EnumLiteral => { | 19078 | .EnumLiteral => { |
| 19057 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); | 19079 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); |
| 19058 | const tag_name = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; | 19080 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 19059 | const bytes = mod.intern_pool.stringToSlice(tag_name); | 19081 | const bytes = ip.stringToSlice(tag_name); |
| 19060 | return sema.addStrLit(block, bytes); | 19082 | return sema.addStrLit(block, bytes); |
| 19061 | }, | 19083 | }, |
| 19062 | .Enum => operand_ty, | 19084 | .Enum => operand_ty, |
| ... | @@ -19089,7 +19111,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19089,7 +19111,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19089 | const enum_decl = mod.declPtr(enum_decl_index); | 19111 | const enum_decl = mod.declPtr(enum_decl_index); |
| 19090 | const msg = msg: { | 19112 | const msg = msg: { |
| 19091 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{s}'", .{ | 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 | errdefer msg.destroy(sema.gpa); | 19116 | errdefer msg.destroy(sema.gpa); |
| 19095 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); | 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,7 +19120,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19098 | return sema.failWithOwnedErrorMsg(msg); | 19120 | return sema.failWithOwnedErrorMsg(msg); |
| 19099 | }; | 19121 | }; |
| 19100 | const field_name = enum_ty.enumFieldName(field_index, mod); | 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 | try sema.requireRuntimeBlock(block, src, operand_src); | 19125 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 19104 | if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) { | 19126 | if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) { |
| ... | @@ -19119,6 +19141,7 @@ fn zirReify( | ... | @@ -19119,6 +19141,7 @@ fn zirReify( |
| 19119 | ) CompileError!Air.Inst.Ref { | 19141 | ) CompileError!Air.Inst.Ref { |
| 19120 | const mod = sema.mod; | 19142 | const mod = sema.mod; |
| 19121 | const gpa = sema.gpa; | 19143 | const gpa = sema.gpa; |
| | 19144 | const ip = &mod.intern_pool; |
| 19122 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); | 19145 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); |
| 19123 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 19146 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 19124 | const src = LazySrcLoc.nodeOffset(extra.node); | 19147 | const src = LazySrcLoc.nodeOffset(extra.node); |
| ... | @@ -19127,11 +19150,10 @@ fn zirReify( | ... | @@ -19127,11 +19150,10 @@ fn zirReify( |
| 19127 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 19150 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 19128 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 19151 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 19129 | const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known"); | 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 | const target = mod.getTarget(); | 19154 | const target = mod.getTarget(); |
| 19132 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); | 19155 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); |
| 19133 | const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?; | 19156 | const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?; |
| 19134 | const ip = &mod.intern_pool; | | |
| 19135 | switch (@intToEnum(std.builtin.TypeId, tag_index)) { | 19157 | switch (@intToEnum(std.builtin.TypeId, tag_index)) { |
| 19136 | .Type => return Air.Inst.Ref.type_type, | 19158 | .Type => return Air.Inst.Ref.type_type, |
| 19137 | .Void => return Air.Inst.Ref.void_type, | 19159 | .Void => return Air.Inst.Ref.void_type, |
| ... | @@ -19145,8 +19167,14 @@ fn zirReify( | ... | @@ -19145,8 +19167,14 @@ fn zirReify( |
| 19145 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, | 19167 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, |
| 19146 | .Int => { | 19168 | .Int => { |
| 19147 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19170 | const signedness_val = try union_val.val.toValue().fieldValue( |
| 19149 | const bits_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("bits").?); | 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 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); | 19179 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| 19152 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); | 19180 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| ... | @@ -19155,8 +19183,12 @@ fn zirReify( | ... | @@ -19155,8 +19183,12 @@ fn zirReify( |
| 19155 | }, | 19183 | }, |
| 19156 | .Vector => { | 19184 | .Vector => { |
| 19157 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19186 | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19159 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); | 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 | const len = @intCast(u32, len_val.toUnsignedInt(mod)); | 19193 | const len = @intCast(u32, len_val.toUnsignedInt(mod)); |
| 19162 | const child_ty = child_val.toType(); | 19194 | const child_ty = child_val.toType(); |
| ... | @@ -19171,7 +19203,9 @@ fn zirReify( | ... | @@ -19171,7 +19203,9 @@ fn zirReify( |
| 19171 | }, | 19203 | }, |
| 19172 | .Float => { | 19204 | .Float => { |
| 19173 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); | 19210 | const bits = @intCast(u16, bits_val.toUnsignedInt(mod)); |
| 19177 | const ty = switch (bits) { | 19211 | const ty = switch (bits) { |
| ... | @@ -19186,14 +19220,30 @@ fn zirReify( | ... | @@ -19186,14 +19220,30 @@ fn zirReify( |
| 19186 | }, | 19220 | }, |
| 19187 | .Pointer => { | 19221 | .Pointer => { |
| 19188 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19223 | const size_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19190 | const is_const_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_const").?); | 19224 | try ip.getOrPutString(gpa, "size"), |
| 19191 | const is_volatile_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_volatile").?); | 19225 | ).?); |
| 19192 | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("alignment").?); | 19226 | const is_const_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19193 | const address_space_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("address_space").?); | 19227 | try ip.getOrPutString(gpa, "is_const"), |
| 19194 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); | 19228 | ).?); |
| 19195 | const is_allowzero_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_allowzero").?); | 19229 | const is_volatile_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19196 | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("sentinel").?); | 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 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { | 19248 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 19199 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 19249 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| ... | @@ -19279,9 +19329,15 @@ fn zirReify( | ... | @@ -19279,9 +19329,15 @@ fn zirReify( |
| 19279 | }, | 19329 | }, |
| 19280 | .Array => { | 19330 | .Array => { |
| 19281 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19332 | const len_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19283 | const child_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("child").?); | 19333 | try ip.getOrPutString(gpa, "len"), |
| 19284 | const sentinel_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("sentinel").?); | 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 | const len = len_val.toUnsignedInt(mod); | 19342 | const len = len_val.toUnsignedInt(mod); |
| 19287 | const child_ty = child_val.toType(); | 19343 | const child_ty = child_val.toType(); |
| ... | @@ -19298,7 +19354,9 @@ fn zirReify( | ... | @@ -19298,7 +19354,9 @@ fn zirReify( |
| 19298 | }, | 19354 | }, |
| 19299 | .Optional => { | 19355 | .Optional => { |
| 19300 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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 | const child_ty = child_val.toType(); | 19361 | const child_ty = child_val.toType(); |
| 19304 | | 19362 | |
| ... | @@ -19307,8 +19365,12 @@ fn zirReify( | ... | @@ -19307,8 +19365,12 @@ fn zirReify( |
| 19307 | }, | 19365 | }, |
| 19308 | .ErrorUnion => { | 19366 | .ErrorUnion => { |
| 19309 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19368 | const error_set_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19311 | const payload_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("payload").?); | 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 | const error_set_ty = error_set_val.toType(); | 19375 | const error_set_ty = error_set_val.toType(); |
| 19314 | const payload_ty = payload_val.toType(); | 19376 | const payload_ty = payload_val.toType(); |
| ... | @@ -19330,14 +19392,17 @@ fn zirReify( | ... | @@ -19330,14 +19392,17 @@ fn zirReify( |
| 19330 | for (0..len) |i| { | 19392 | for (0..len) |i| { |
| 19331 | const elem_val = try payload_val.elemValue(mod, i); | 19393 | const elem_val = try payload_val.elemValue(mod, i); |
| 19332 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); | 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); | 19399 | const name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19336 | const kv = try mod.getErrorValue(name_str); | 19400 | _ = try mod.getErrorValue(name); |
| 19337 | const name_ip = try mod.intern_pool.getOrPutString(gpa, kv.key); | 19401 | const gop = names.getOrPutAssumeCapacity(name); |
| 19338 | const gop = names.getOrPutAssumeCapacity(name_ip); | | |
| 19339 | if (gop.found_existing) { | 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,11 +19411,21 @@ fn zirReify( |
| 19346 | }, | 19411 | }, |
| 19347 | .Struct => { | 19412 | .Struct => { |
| 19348 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19414 | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19350 | const backing_integer_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("backing_integer").?); | 19415 | try ip.getOrPutString(gpa, "layout"), |
| 19351 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); | 19416 | ).?); |
| 19352 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); | 19417 | const backing_integer_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19353 | const is_tuple_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_tuple").?); | 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 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); | 19430 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| 19356 | | 19431 | |
| ... | @@ -19367,10 +19442,18 @@ fn zirReify( | ... | @@ -19367,10 +19442,18 @@ fn zirReify( |
| 19367 | }, | 19442 | }, |
| 19368 | .Enum => { | 19443 | .Enum => { |
| 19369 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19445 | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19371 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); | 19446 | try ip.getOrPutString(gpa, "tag_type"), |
| 19372 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); | 19447 | ).?); |
| 19373 | const is_exhaustive_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_exhaustive").?); | 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 | // Decls | 19458 | // Decls |
| 19376 | if (decls_val.sliceLen(mod) > 0) { | 19459 | if (decls_val.sliceLen(mod) > 0) { |
| ... | @@ -19396,7 +19479,7 @@ fn zirReify( | ... | @@ -19396,7 +19479,7 @@ fn zirReify( |
| 19396 | | 19479 | |
| 19397 | // Define our empty enum decl | 19480 | // Define our empty enum decl |
| 19398 | const fields_len = @intCast(u32, try sema.usizeCast(block, src, fields_val.sliceLen(mod))); | 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 | .decl = new_decl_index, | 19483 | .decl = new_decl_index, |
| 19401 | .namespace = .none, | 19484 | .namespace = .none, |
| 19402 | .fields_len = fields_len, | 19485 | .fields_len = fields_len, |
| ... | @@ -19407,35 +19490,36 @@ fn zirReify( | ... | @@ -19407,35 +19490,36 @@ fn zirReify( |
| 19407 | .explicit, | 19490 | .explicit, |
| 19408 | .tag_ty = int_tag_ty.toIntern(), | 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 | new_decl.val = incomplete_enum.index.toValue(); | 19495 | new_decl.val = incomplete_enum.index.toValue(); |
| 19413 | | 19496 | |
| 19414 | for (0..fields_len) |field_i| { | 19497 | for (0..fields_len) |field_i| { |
| 19415 | const elem_val = try fields_val.elemValue(mod, field_i); | 19498 | const elem_val = try fields_val.elemValue(mod, field_i); |
| 19416 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); | 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").?); | 19500 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19418 | const value_val = try elem_val.fieldValue(mod, elem_fields.getIndex("value").?); | 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( | 19507 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19421 | Type.slice_const_u8, | | |
| 19422 | sema.arena, | | |
| 19423 | mod, | | |
| 19424 | ); | | |
| 19425 | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); | | |
| 19426 | | 19508 | |
| 19427 | if (!try sema.intFitsInType(value_val, int_tag_ty, null)) { | 19509 | if (!try sema.intFitsInType(value_val, int_tag_ty, null)) { |
| 19428 | // TODO: better source location | 19510 | // TODO: better source location |
| 19429 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ | 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 | value_val.fmtValue(Type.comptime_int, mod), | 19513 | value_val.fmtValue(Type.comptime_int, mod), |
| 19432 | int_tag_ty.fmt(mod), | 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 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 19523 | errdefer msg.destroy(gpa); |
| 19440 | _ = other_index; // TODO: this note is incorrect | 19524 | _ = other_index; // TODO: this note is incorrect |
| 19441 | try sema.errNote(block, src, msg, "other field here", .{}); | 19525 | try sema.errNote(block, src, msg, "other field here", .{}); |
| ... | @@ -19444,7 +19528,7 @@ fn zirReify( | ... | @@ -19444,7 +19528,7 @@ fn zirReify( |
| 19444 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 19532 | const msg = msg: { |
| 19449 | const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{value_val.fmtValue(Type.comptime_int, mod)}); | 19533 | const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{value_val.fmtValue(Type.comptime_int, mod)}); |
| 19450 | errdefer msg.destroy(gpa); | 19534 | errdefer msg.destroy(gpa); |
| ... | @@ -19462,7 +19546,9 @@ fn zirReify( | ... | @@ -19462,7 +19546,9 @@ fn zirReify( |
| 19462 | }, | 19546 | }, |
| 19463 | .Opaque => { | 19547 | .Opaque => { |
| 19464 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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 | // Decls | 19553 | // Decls |
| 19468 | if (decls_val.sliceLen(mod) > 0) { | 19554 | if (decls_val.sliceLen(mod) > 0) { |
| ... | @@ -19496,22 +19582,29 @@ fn zirReify( | ... | @@ -19496,22 +19582,29 @@ fn zirReify( |
| 19496 | .decl = new_decl_index, | 19582 | .decl = new_decl_index, |
| 19497 | .namespace = new_namespace_index, | 19583 | .namespace = new_namespace_index, |
| 19498 | } }); | 19584 | } }); |
| 19499 | errdefer mod.intern_pool.remove(opaque_ty); | 19585 | errdefer ip.remove(opaque_ty); |
| 19500 | | 19586 | |
| 19501 | new_decl.val = opaque_ty.toValue(); | 19587 | new_decl.val = opaque_ty.toValue(); |
| 19502 | new_namespace.ty = opaque_ty.toType(); | 19588 | new_namespace.ty = opaque_ty.toType(); |
| 19503 | | 19589 | |
| 19504 | try new_decl.finalizeNewArena(&new_decl_arena); | | |
| 19505 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 19590 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 19506 | try mod.finalizeAnonDecl(new_decl_index); | 19591 | try mod.finalizeAnonDecl(new_decl_index); |
| 19507 | return decl_val; | 19592 | return decl_val; |
| 19508 | }, | 19593 | }, |
| 19509 | .Union => { | 19594 | .Union => { |
| 19510 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19596 | const layout_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19512 | const tag_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("tag_type").?); | 19597 | try ip.getOrPutString(gpa, "layout"), |
| 19513 | const fields_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("fields").?); | 19598 | ).?); |
| 19514 | const decls_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("decls").?); | 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 | // Decls | 19609 | // Decls |
| 19517 | if (decls_val.sliceLen(mod) > 0) { | 19610 | if (decls_val.sliceLen(mod) > 0) { |
| ... | @@ -19555,7 +19648,7 @@ fn zirReify( | ... | @@ -19555,7 +19648,7 @@ fn zirReify( |
| 19555 | const union_obj = mod.unionPtr(union_index); | 19648 | const union_obj = mod.unionPtr(union_index); |
| 19556 | errdefer mod.destroyUnion(union_index); | 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 | .index = union_index, | 19652 | .index = union_index, |
| 19560 | .runtime_tag = if (!tag_type_val.isNull(mod)) | 19653 | .runtime_tag = if (!tag_type_val.isNull(mod)) |
| 19561 | .tagged | 19654 | .tagged |
| ... | @@ -19566,7 +19659,7 @@ fn zirReify( | ... | @@ -19566,7 +19659,7 @@ fn zirReify( |
| 19566 | .ReleaseFast, .ReleaseSmall => .none, | 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 | new_decl.val = union_ty.toValue(); | 19664 | new_decl.val = union_ty.toValue(); |
| 19572 | new_namespace.ty = union_ty.toType(); | 19665 | new_namespace.ty = union_ty.toType(); |
| ... | @@ -19579,7 +19672,7 @@ fn zirReify( | ... | @@ -19579,7 +19672,7 @@ fn zirReify( |
| 19579 | if (tag_type_val.optionalValue(mod)) |payload_val| { | 19672 | if (tag_type_val.optionalValue(mod)) |payload_val| { |
| 19580 | union_obj.tag_ty = payload_val.toType(); | 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 | .enum_type => |x| x, | 19676 | .enum_type => |x| x, |
| 19584 | else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}), | 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,26 +19690,26 @@ fn zirReify( |
| 19597 | for (0..fields_len) |i| { | 19690 | for (0..fields_len) |i| { |
| 19598 | const elem_val = try fields_val.elemValue(mod, i); | 19691 | const elem_val = try fields_val.elemValue(mod, i); |
| 19599 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); | 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").?); | 19693 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19601 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); | 19694 | try ip.getOrPutString(gpa, "name"), |
| 19602 | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex("alignment").?); | 19695 | ).?); |
| 19603 | | 19696 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19604 | const field_name = try name_val.toAllocatedBytes( | 19697 | try ip.getOrPutString(gpa, "type"), |
| 19605 | Type.slice_const_u8, | 19698 | ).?); |
| 19606 | new_decl_arena_allocator, | 19699 | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19607 | mod, | 19700 | try ip.getOrPutString(gpa, "alignment"), |
| 19608 | ); | 19701 | ).?); |
| 19609 | | 19702 | |
| 19610 | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); | 19703 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19611 | | 19704 | |
| 19612 | if (enum_field_names.len != 0) { | 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 | if (explicit_enum_info) |tag_info| { | 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 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 19713 | errdefer msg.destroy(gpa); |
| 19621 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 19714 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 19622 | break :msg msg; | 19715 | break :msg msg; |
| ... | @@ -19632,7 +19725,7 @@ fn zirReify( | ... | @@ -19632,7 +19725,7 @@ fn zirReify( |
| 19632 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); | 19725 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); |
| 19633 | if (gop.found_existing) { | 19726 | if (gop.found_existing) { |
| 19634 | // TODO: better source location | 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 | const field_ty = type_val.toType(); | 19731 | const field_ty = type_val.toType(); |
| ... | @@ -19688,7 +19781,7 @@ fn zirReify( | ... | @@ -19688,7 +19781,7 @@ fn zirReify( |
| 19688 | for (tag_info.names, 0..) |field_name, field_index| { | 19781 | for (tag_info.names, 0..) |field_name, field_index| { |
| 19689 | if (explicit_tags_seen[field_index]) continue; | 19782 | if (explicit_tags_seen[field_index]) continue; |
| 19690 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ | 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 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 19787 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -19700,19 +19793,30 @@ fn zirReify( | ... | @@ -19700,19 +19793,30 @@ fn zirReify( |
| 19700 | union_obj.tag_ty = try sema.generateUnionTagTypeSimple(block, enum_field_names, null); | 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 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 19796 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 19705 | try mod.finalizeAnonDecl(new_decl_index); | 19797 | try mod.finalizeAnonDecl(new_decl_index); |
| 19706 | return decl_val; | 19798 | return decl_val; |
| 19707 | }, | 19799 | }, |
| 19708 | .Fn => { | 19800 | .Fn => { |
| 19709 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 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").?); | 19802 | const calling_convention_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19711 | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("alignment").?); | 19803 | try ip.getOrPutString(gpa, "calling_convention"), |
| 19712 | const is_generic_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_generic").?); | 19804 | ).?); |
| 19713 | const is_var_args_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("is_var_args").?); | 19805 | const alignment_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex( |
| 19714 | const return_type_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("return_type").?); | 19806 | try ip.getOrPutString(gpa, "alignment"), |
| 19715 | const params_val = try union_val.val.toValue().fieldValue(mod, fields.getIndex("params").?); | 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 | const is_generic = is_generic_val.toBool(); | 19821 | const is_generic = is_generic_val.toBool(); |
| 19718 | if (is_generic) { | 19822 | if (is_generic) { |
| ... | @@ -19746,9 +19850,15 @@ fn zirReify( | ... | @@ -19746,9 +19850,15 @@ fn zirReify( |
| 19746 | for (param_types, 0..) |*param_type, i| { | 19850 | for (param_types, 0..) |*param_type, i| { |
| 19747 | const elem_val = try params_val.elemValue(mod, i); | 19851 | const elem_val = try params_val.elemValue(mod, i); |
| 19748 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); | 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").?); | 19853 | const param_is_generic_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19750 | const param_is_noalias_val = try elem_val.fieldValue(mod, elem_fields.getIndex("is_noalias").?); | 19854 | try ip.getOrPutString(gpa, "is_generic"), |
| 19751 | const opt_param_type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); | 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 | if (param_is_generic_val.toBool()) { | 19863 | if (param_is_generic_val.toBool()) { |
| 19754 | return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{}); | 19864 | return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{}); |
| ... | @@ -19801,6 +19911,7 @@ fn reifyStruct( | ... | @@ -19801,6 +19911,7 @@ fn reifyStruct( |
| 19801 | ) CompileError!Air.Inst.Ref { | 19911 | ) CompileError!Air.Inst.Ref { |
| 19802 | const mod = sema.mod; | 19912 | const mod = sema.mod; |
| 19803 | const gpa = sema.gpa; | 19913 | const gpa = sema.gpa; |
| | 19914 | const ip = &mod.intern_pool; |
| 19804 | | 19915 | |
| 19805 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); | 19916 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19806 | errdefer new_decl_arena.deinit(); | 19917 | errdefer new_decl_arena.deinit(); |
| ... | @@ -19839,11 +19950,11 @@ fn reifyStruct( | ... | @@ -19839,11 +19950,11 @@ fn reifyStruct( |
| 19839 | const struct_obj = mod.structPtr(struct_index); | 19950 | const struct_obj = mod.structPtr(struct_index); |
| 19840 | errdefer mod.destroyStruct(struct_index); | 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 | .index = struct_index.toOptional(), | 19954 | .index = struct_index.toOptional(), |
| 19844 | .namespace = new_namespace_index.toOptional(), | 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 | new_decl.val = struct_ty.toValue(); | 19959 | new_decl.val = struct_ty.toValue(); |
| 19849 | new_namespace.ty = struct_ty.toType(); | 19960 | new_namespace.ty = struct_ty.toType(); |
| ... | @@ -19854,12 +19965,22 @@ fn reifyStruct( | ... | @@ -19854,12 +19965,22 @@ fn reifyStruct( |
| 19854 | var i: usize = 0; | 19965 | var i: usize = 0; |
| 19855 | while (i < fields_len) : (i += 1) { | 19966 | while (i < fields_len) : (i += 1) { |
| 19856 | const elem_val = try fields_val.elemValue(mod, i); | 19967 | const elem_val = try fields_val.elemValue(mod, i); |
| 19857 | const elem_fields = mod.intern_pool.typeOf(elem_val.toIntern()).toType().structFields(mod); | 19968 | const elem_fields = ip.typeOf(elem_val.toIntern()).toType().structFields(mod); |
| 19858 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex("name").?); | 19969 | const name_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19859 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex("type").?); | 19970 | try ip.getOrPutString(gpa, "name"), |
| 19860 | const default_value_val = try elem_val.fieldValue(mod, elem_fields.getIndex("default_value").?); | 19971 | ).?); |
| 19861 | const is_comptime_val = try elem_val.fieldValue(mod, elem_fields.getIndex("is_comptime").?); | 19972 | const type_val = try elem_val.fieldValue(mod, elem_fields.getIndex( |
| 19862 | const alignment_val = try elem_val.fieldValue(mod, elem_fields.getIndex("alignment").?); | 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 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { | 19985 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 19865 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 19986 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| ... | @@ -19874,19 +19995,15 @@ fn reifyStruct( | ... | @@ -19874,19 +19995,15 @@ fn reifyStruct( |
| 19874 | return sema.fail(block, src, "extern struct fields cannot be marked comptime", .{}); | 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( | 19998 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19878 | Type.slice_const_u8, | | |
| 19879 | new_decl_arena_allocator, | | |
| 19880 | mod, | | |
| 19881 | ); | | |
| 19882 | | 19999 | |
| 19883 | if (is_tuple) { | 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 | return sema.fail( | 20002 | return sema.fail( |
| 19886 | block, | 20003 | block, |
| 19887 | src, | 20004 | src, |
| 19888 | "tuple cannot have non-numeric field '{s}'", | 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,16 +20019,16 @@ fn reifyStruct( |
| 19902 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); | 20019 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 19903 | if (gop.found_existing) { | 20020 | if (gop.found_existing) { |
| 19904 | // TODO: better source location | 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 | const field_ty = type_val.toType(); | 20025 | const field_ty = type_val.toType(); |
| 19909 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| | 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 | 20027 | (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") | 20028 | return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern() |
| 19912 | else | 20029 | else |
| 19913 | Value.@"unreachable"; | 20030 | .none; |
| 19914 | if (is_comptime_val.toBool() and default_val.toIntern() == .unreachable_value) { | 20031 | if (is_comptime_val.toBool() and default_val == .none) { |
| 19915 | return sema.fail(block, src, "comptime field without default initialization value", .{}); | 20032 | return sema.fail(block, src, "comptime field without default initialization value", .{}); |
| 19916 | } | 20033 | } |
| 19917 | | 20034 | |
| ... | @@ -20000,7 +20117,6 @@ fn reifyStruct( | ... | @@ -20000,7 +20117,6 @@ fn reifyStruct( |
| 20000 | struct_obj.status = .have_layout; | 20117 | struct_obj.status = .have_layout; |
| 20001 | } | 20118 | } |
| 20002 | | 20119 | |
| 20003 | try new_decl.finalizeNewArena(&new_decl_arena); | | |
| 20004 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); | 20120 | const decl_val = sema.analyzeDeclVal(block, src, new_decl_index); |
| 20005 | try mod.finalizeAnonDecl(new_decl_index); | 20121 | try mod.finalizeAnonDecl(new_decl_index); |
| 20006 | return decl_val; | 20122 | return decl_val; |
| ... | @@ -20871,7 +20987,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -20871,7 +20987,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20871 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 20987 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 20872 | | 20988 | |
| 20873 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 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 | const mod = sema.mod; | 20992 | const mod = sema.mod; |
| 20877 | try sema.resolveTypeLayout(ty); | 20993 | try sema.resolveTypeLayout(ty); |
| ... | @@ -20889,7 +21005,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -20889,7 +21005,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20889 | } | 21005 | } |
| 20890 | | 21006 | |
| 20891 | const field_index = if (ty.isTuple(mod)) blk: { | 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 | return sema.fail(block, src, "no offset available for 'len' field of tuple", .{}); | 21009 | return sema.fail(block, src, "no offset available for 'len' field of tuple", .{}); |
| 20894 | } | 21010 | } |
| 20895 | break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src); | 21011 | break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src); |
| ... | @@ -21351,6 +21467,8 @@ fn resolveExportOptions( | ... | @@ -21351,6 +21467,8 @@ fn resolveExportOptions( |
| 21351 | zir_ref: Zir.Inst.Ref, | 21467 | zir_ref: Zir.Inst.Ref, |
| 21352 | ) CompileError!std.builtin.ExportOptions { | 21468 | ) CompileError!std.builtin.ExportOptions { |
| 21353 | const mod = sema.mod; | 21469 | const mod = sema.mod; |
| | 21470 | const gpa = sema.gpa; |
| | 21471 | const ip = &mod.intern_pool; |
| 21354 | const export_options_ty = try sema.getBuiltinType("ExportOptions"); | 21472 | const export_options_ty = try sema.getBuiltinType("ExportOptions"); |
| 21355 | const air_ref = try sema.resolveInst(zir_ref); | 21473 | const air_ref = try sema.resolveInst(zir_ref); |
| 21356 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 21474 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| ... | @@ -21360,16 +21478,16 @@ fn resolveExportOptions( | ... | @@ -21360,16 +21478,16 @@ fn resolveExportOptions( |
| 21360 | const section_src = sema.maybeOptionsSrc(block, src, "section"); | 21478 | const section_src = sema.maybeOptionsSrc(block, src, "section"); |
| 21361 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); | 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 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known"); | 21482 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known"); |
| 21365 | const name_ty = Type.slice_const_u8; | 21483 | const name_ty = Type.slice_const_u8; |
| 21366 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); | 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 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); | 21487 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); |
| 21370 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 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 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); | 21491 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); |
| 21374 | const section_ty = Type.slice_const_u8; | 21492 | const section_ty = Type.slice_const_u8; |
| 21375 | const section = if (section_opt_val.optionalValue(mod)) |section_val| | 21493 | const section = if (section_opt_val.optionalValue(mod)) |section_val| |
| ... | @@ -21377,7 +21495,7 @@ fn resolveExportOptions( | ... | @@ -21377,7 +21495,7 @@ fn resolveExportOptions( |
| 21377 | else | 21495 | else |
| 21378 | null; | 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 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); | 21499 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); |
| 21382 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); | 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,10 +22335,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22217 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 22335 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 22218 | | 22336 | |
| 22219 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); | 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 | const field_ptr = try sema.resolveInst(extra.field_ptr); | 22339 | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 22222 | const field_ptr_ty = sema.typeOf(field_ptr); | 22340 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 22223 | const mod = sema.mod; | 22341 | const mod = sema.mod; |
| | 22342 | const ip = &mod.intern_pool; |
| 22224 | | 22343 | |
| 22225 | if (parent_ty.zigTypeTag(mod) != .Struct and parent_ty.zigTypeTag(mod) != .Union) { | 22344 | if (parent_ty.zigTypeTag(mod) != .Struct and parent_ty.zigTypeTag(mod) != .Union) { |
| 22226 | return sema.fail(block, ty_src, "expected struct or union type, found '{}'", .{parent_ty.fmt(sema.mod)}); | 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,7 +22349,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22230 | const field_index = switch (parent_ty.zigTypeTag(mod)) { | 22349 | const field_index = switch (parent_ty.zigTypeTag(mod)) { |
| 22231 | .Struct => blk: { | 22350 | .Struct => blk: { |
| 22232 | if (parent_ty.isTuple(mod)) { | 22351 | if (parent_ty.isTuple(mod)) { |
| 22233 | if (mem.eql(u8, field_name, "len")) { | 22352 | if (ip.stringEqlSlice(field_name, "len")) { |
| 22234 | return sema.fail(block, src, "cannot get @fieldParentPtr of 'len' field of tuple", .{}); | 22353 | return sema.fail(block, src, "cannot get @fieldParentPtr of 'len' field of tuple", .{}); |
| 22235 | } | 22354 | } |
| 22236 | break :blk try sema.tupleFieldIndex(block, parent_ty, field_name, name_src); | 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,7 +22395,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22276 | const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); | 22395 | const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); |
| 22277 | | 22396 | |
| 22278 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { | 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 | .ptr => |ptr| switch (ptr.addr) { | 22399 | .ptr => |ptr| switch (ptr.addr) { |
| 22281 | .field => |field| field, | 22400 | .field => |field| field, |
| 22282 | else => null, | 22401 | else => null, |
| ... | @@ -22291,7 +22410,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -22291,7 +22410,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22291 | src, | 22410 | src, |
| 22292 | "field '{s}' has index '{d}' but pointer value is index '{d}' of struct '{}'", | 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 | field_index, | 22414 | field_index, |
| 22296 | field.index, | 22415 | field.index, |
| 22297 | parent_ty.fmt(sema.mod), | 22416 | parent_ty.fmt(sema.mod), |
| ... | @@ -22807,6 +22926,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -22807,6 +22926,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 22807 | | 22926 | |
| 22808 | fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 22927 | fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 22809 | const mod = sema.mod; | 22928 | const mod = sema.mod; |
| | 22929 | const gpa = sema.gpa; |
| | 22930 | const ip = &mod.intern_pool; |
| 22810 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 22931 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 22811 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22932 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22812 | const src = inst_data.src(); | 22933 | const src = inst_data.src(); |
| ... | @@ -22824,7 +22945,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -22824,7 +22945,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 22824 | const dest_elem_ty = dest_ptr_ty.elemType2(mod); | 22945 | const dest_elem_ty = dest_ptr_ty.elemType2(mod); |
| 22825 | | 22946 | |
| 22826 | const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: { | 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 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse | 22949 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse |
| 22829 | break :rs dest_src; | 22950 | break :rs dest_src; |
| 22830 | const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?; | 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,11 +23189,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23068 | if (val.isGenericPoison()) { | 23189 | if (val.isGenericPoison()) { |
| 23069 | break :blk FuncLinkSection{ .generic = {} }; | 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 | } else if (extra.data.bits.has_section_ref) blk: { | 23193 | } else if (extra.data.bits.has_section_ref) blk: { |
| 23073 | const section_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 23194 | const section_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 23074 | extra_index += 1; | 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 | error.GenericPoison => { | 23197 | error.GenericPoison => { |
| 23077 | break :blk FuncLinkSection{ .generic = {} }; | 23198 | break :blk FuncLinkSection{ .generic = {} }; |
| 23078 | }, | 23199 | }, |
| ... | @@ -23272,6 +23393,8 @@ fn resolvePrefetchOptions( | ... | @@ -23272,6 +23393,8 @@ fn resolvePrefetchOptions( |
| 23272 | zir_ref: Zir.Inst.Ref, | 23393 | zir_ref: Zir.Inst.Ref, |
| 23273 | ) CompileError!std.builtin.PrefetchOptions { | 23394 | ) CompileError!std.builtin.PrefetchOptions { |
| 23274 | const mod = sema.mod; | 23395 | const mod = sema.mod; |
| | 23396 | const gpa = sema.gpa; |
| | 23397 | const ip = &mod.intern_pool; |
| 23275 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); | 23398 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 23276 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); | 23399 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 23277 | | 23400 | |
| ... | @@ -23279,13 +23402,13 @@ fn resolvePrefetchOptions( | ... | @@ -23279,13 +23402,13 @@ fn resolvePrefetchOptions( |
| 23279 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); | 23402 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); |
| 23280 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); | 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 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known"); | 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 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known"); | 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 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); | 23412 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); |
| 23290 | | 23413 | |
| 23291 | return std.builtin.PrefetchOptions{ | 23414 | return std.builtin.PrefetchOptions{ |
| ... | @@ -23336,6 +23459,8 @@ fn resolveExternOptions( | ... | @@ -23336,6 +23459,8 @@ fn resolveExternOptions( |
| 23336 | zir_ref: Zir.Inst.Ref, | 23459 | zir_ref: Zir.Inst.Ref, |
| 23337 | ) CompileError!std.builtin.ExternOptions { | 23460 | ) CompileError!std.builtin.ExternOptions { |
| 23338 | const mod = sema.mod; | 23461 | const mod = sema.mod; |
| | 23462 | const gpa = sema.gpa; |
| | 23463 | const ip = &mod.intern_pool; |
| 23339 | const options_inst = try sema.resolveInst(zir_ref); | 23464 | const options_inst = try sema.resolveInst(zir_ref); |
| 23340 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); | 23465 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 23341 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); | 23466 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| ... | @@ -23345,18 +23470,18 @@ fn resolveExternOptions( | ... | @@ -23345,18 +23470,18 @@ fn resolveExternOptions( |
| 23345 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); | 23470 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); |
| 23346 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); | 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 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known"); | 23474 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known"); |
| 23350 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); | 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 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known"); | 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 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); | 23481 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); |
| 23357 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 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 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); | 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 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { | 23487 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { |
| ... | @@ -23425,7 +23550,7 @@ fn zirBuiltinExtern( | ... | @@ -23425,7 +23550,7 @@ fn zirBuiltinExtern( |
| 23425 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); | 23550 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); |
| 23426 | errdefer mod.destroyDecl(new_decl_index); | 23551 | errdefer mod.destroyDecl(new_decl_index); |
| 23427 | const new_decl = mod.declPtr(new_decl_index); | 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 | const new_var = try mod.intern(.{ .variable = .{ | 23556 | const new_var = try mod.intern(.{ .variable = .{ |
| ... | @@ -23444,7 +23569,7 @@ fn zirBuiltinExtern( | ... | @@ -23444,7 +23569,7 @@ fn zirBuiltinExtern( |
| 23444 | new_decl.ty = ty; | 23569 | new_decl.ty = ty; |
| 23445 | new_decl.val = new_var.toValue(); | 23570 | new_decl.val = new_var.toValue(); |
| 23446 | new_decl.@"align" = 0; | 23571 | new_decl.@"align" = 0; |
| 23447 | new_decl.@"linksection" = null; | 23572 | new_decl.@"linksection" = .none; |
| 23448 | new_decl.has_tv = true; | 23573 | new_decl.has_tv = true; |
| 23449 | new_decl.analysis = .complete; | 23574 | new_decl.analysis = .complete; |
| 23450 | new_decl.generation = mod.generation; | 23575 | new_decl.generation = mod.generation; |
| ... | @@ -24265,12 +24390,13 @@ fn safetyPanic( | ... | @@ -24265,12 +24390,13 @@ fn safetyPanic( |
| 24265 | panic_id: PanicId, | 24390 | panic_id: PanicId, |
| 24266 | ) CompileError!void { | 24391 | ) CompileError!void { |
| 24267 | const mod = sema.mod; | 24392 | const mod = sema.mod; |
| | 24393 | const gpa = sema.gpa; |
| 24268 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); | 24394 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 24269 | const msg_decl_index = (try sema.namespaceLookup( | 24395 | const msg_decl_index = (try sema.namespaceLookup( |
| 24270 | block, | 24396 | block, |
| 24271 | sema.src, | 24397 | sema.src, |
| 24272 | panic_messages_ty.getNamespaceIndex(mod).unwrap().?, | 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 | const msg_inst = try sema.analyzeDeclVal(block, sema.src, msg_decl_index); | 24402 | const msg_inst = try sema.analyzeDeclVal(block, sema.src, msg_decl_index); |
| ... | @@ -24302,14 +24428,13 @@ fn fieldVal( | ... | @@ -24302,14 +24428,13 @@ fn fieldVal( |
| 24302 | block: *Block, | 24428 | block: *Block, |
| 24303 | src: LazySrcLoc, | 24429 | src: LazySrcLoc, |
| 24304 | object: Air.Inst.Ref, | 24430 | object: Air.Inst.Ref, |
| 24305 | field_name: []const u8, | 24431 | field_name: InternPool.NullTerminatedString, |
| 24306 | field_name_src: LazySrcLoc, | 24432 | field_name_src: LazySrcLoc, |
| 24307 | ) CompileError!Air.Inst.Ref { | 24433 | ) CompileError!Air.Inst.Ref { |
| 24308 | // When editing this function, note that there is corresponding logic to be edited | 24434 | // When editing this function, note that there is corresponding logic to be edited |
| 24309 | // in `fieldPtr`. This function takes a value and returns a value. | 24435 | // in `fieldPtr`. This function takes a value and returns a value. |
| 24310 | | 24436 | |
| 24311 | const mod = sema.mod; | 24437 | const mod = sema.mod; |
| 24312 | const gpa = sema.gpa; | | |
| 24313 | const ip = &mod.intern_pool; | 24438 | const ip = &mod.intern_pool; |
| 24314 | const object_src = src; // TODO better source location | 24439 | const object_src = src; // TODO better source location |
| 24315 | const object_ty = sema.typeOf(object); | 24440 | const object_ty = sema.typeOf(object); |
| ... | @@ -24326,12 +24451,12 @@ fn fieldVal( | ... | @@ -24326,12 +24451,12 @@ fn fieldVal( |
| 24326 | | 24451 | |
| 24327 | switch (inner_ty.zigTypeTag(mod)) { | 24452 | switch (inner_ty.zigTypeTag(mod)) { |
| 24328 | .Array => { | 24453 | .Array => { |
| 24329 | if (mem.eql(u8, field_name, "len")) { | 24454 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24330 | return sema.addConstant( | 24455 | return sema.addConstant( |
| 24331 | Type.usize, | 24456 | Type.usize, |
| 24332 | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), | 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 | const ptr_info = object_ty.ptrInfo(mod); | 24460 | const ptr_info = object_ty.ptrInfo(mod); |
| 24336 | const result_ty = try Type.ptr(sema.arena, mod, .{ | 24461 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24337 | .pointee_type = ptr_info.pointee_type.childType(mod), | 24462 | .pointee_type = ptr_info.pointee_type.childType(mod), |
| ... | @@ -24352,20 +24477,20 @@ fn fieldVal( | ... | @@ -24352,20 +24477,20 @@ fn fieldVal( |
| 24352 | block, | 24477 | block, |
| 24353 | field_name_src, | 24478 | field_name_src, |
| 24354 | "no member named '{s}' in '{}'", | 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 | .Pointer => { | 24484 | .Pointer => { |
| 24360 | const ptr_info = inner_ty.ptrInfo(mod); | 24485 | const ptr_info = inner_ty.ptrInfo(mod); |
| 24361 | if (ptr_info.size == .Slice) { | 24486 | if (ptr_info.size == .Slice) { |
| 24362 | if (mem.eql(u8, field_name, "ptr")) { | 24487 | if (ip.stringEqlSlice(field_name, "ptr")) { |
| 24363 | const slice = if (is_pointer_to) | 24488 | const slice = if (is_pointer_to) |
| 24364 | try sema.analyzeLoad(block, src, object, object_src) | 24489 | try sema.analyzeLoad(block, src, object, object_src) |
| 24365 | else | 24490 | else |
| 24366 | object; | 24491 | object; |
| 24367 | return sema.analyzeSlicePtr(block, object_src, slice, inner_ty); | 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 | const slice = if (is_pointer_to) | 24494 | const slice = if (is_pointer_to) |
| 24370 | try sema.analyzeLoad(block, src, object, object_src) | 24495 | try sema.analyzeLoad(block, src, object, object_src) |
| 24371 | else | 24496 | else |
| ... | @@ -24376,7 +24501,7 @@ fn fieldVal( | ... | @@ -24376,7 +24501,7 @@ fn fieldVal( |
| 24376 | block, | 24501 | block, |
| 24377 | field_name_src, | 24502 | field_name_src, |
| 24378 | "no member named '{s}' in '{}'", | 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,13 +24517,12 @@ fn fieldVal( |
| 24392 | | 24517 | |
| 24393 | switch (try child_type.zigTypeTagOrPoison(mod)) { | 24518 | switch (try child_type.zigTypeTagOrPoison(mod)) { |
| 24394 | .ErrorSet => { | 24519 | .ErrorSet => { |
| 24395 | const name = try ip.getOrPutString(gpa, field_name); | | |
| 24396 | switch (ip.indexToKey(child_type.toIntern())) { | 24520 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24397 | .error_set_type => |error_set_type| blk: { | 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 | const msg = msg: { | 24523 | const msg = msg: { |
| 24400 | const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{ | 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 | errdefer msg.destroy(sema.gpa); | 24527 | errdefer msg.destroy(sema.gpa); |
| 24404 | try sema.addDeclaredHereNote(msg, child_type); | 24528 | try sema.addDeclaredHereNote(msg, child_type); |
| ... | @@ -24419,10 +24543,10 @@ fn fieldVal( | ... | @@ -24419,10 +24543,10 @@ fn fieldVal( |
| 24419 | const error_set_type = if (!child_type.isAnyError(mod)) | 24543 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24420 | child_type | 24544 | child_type |
| 24421 | else | 24545 | else |
| 24422 | try mod.singleErrorSetTypeNts(name); | 24546 | try mod.singleErrorSetTypeNts(field_name); |
| 24423 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 24547 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 24424 | .ty = error_set_type.toIntern(), | 24548 | .ty = error_set_type.toIntern(), |
| 24425 | .name = name, | 24549 | .name = field_name, |
| 24426 | } })).toValue()); | 24550 | } })).toValue()); |
| 24427 | }, | 24551 | }, |
| 24428 | .Union => { | 24552 | .Union => { |
| ... | @@ -24499,7 +24623,7 @@ fn fieldPtr( | ... | @@ -24499,7 +24623,7 @@ fn fieldPtr( |
| 24499 | block: *Block, | 24623 | block: *Block, |
| 24500 | src: LazySrcLoc, | 24624 | src: LazySrcLoc, |
| 24501 | object_ptr: Air.Inst.Ref, | 24625 | object_ptr: Air.Inst.Ref, |
| 24502 | field_name: []const u8, | 24626 | field_name: InternPool.NullTerminatedString, |
| 24503 | field_name_src: LazySrcLoc, | 24627 | field_name_src: LazySrcLoc, |
| 24504 | initializing: bool, | 24628 | initializing: bool, |
| 24505 | ) CompileError!Air.Inst.Ref { | 24629 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -24507,7 +24631,6 @@ fn fieldPtr( | ... | @@ -24507,7 +24631,6 @@ fn fieldPtr( |
| 24507 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 24631 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 24508 | | 24632 | |
| 24509 | const mod = sema.mod; | 24633 | const mod = sema.mod; |
| 24510 | const gpa = sema.gpa; | | |
| 24511 | const ip = &mod.intern_pool; | 24634 | const ip = &mod.intern_pool; |
| 24512 | const object_ptr_src = src; // TODO better source location | 24635 | const object_ptr_src = src; // TODO better source location |
| 24513 | const object_ptr_ty = sema.typeOf(object_ptr); | 24636 | const object_ptr_ty = sema.typeOf(object_ptr); |
| ... | @@ -24528,7 +24651,7 @@ fn fieldPtr( | ... | @@ -24528,7 +24651,7 @@ fn fieldPtr( |
| 24528 | | 24651 | |
| 24529 | switch (inner_ty.zigTypeTag(mod)) { | 24652 | switch (inner_ty.zigTypeTag(mod)) { |
| 24530 | .Array => { | 24653 | .Array => { |
| 24531 | if (mem.eql(u8, field_name, "len")) { | 24654 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24532 | var anon_decl = try block.startAnonDecl(); | 24655 | var anon_decl = try block.startAnonDecl(); |
| 24533 | defer anon_decl.deinit(); | 24656 | defer anon_decl.deinit(); |
| 24534 | return sema.analyzeDeclRef(try anon_decl.finish( | 24657 | return sema.analyzeDeclRef(try anon_decl.finish( |
| ... | @@ -24541,7 +24664,7 @@ fn fieldPtr( | ... | @@ -24541,7 +24664,7 @@ fn fieldPtr( |
| 24541 | block, | 24664 | block, |
| 24542 | field_name_src, | 24665 | field_name_src, |
| 24543 | "no member named '{s}' in '{}'", | 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,7 +24676,7 @@ fn fieldPtr( |
| 24553 | | 24676 | |
| 24554 | const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty; | 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 | const slice_ptr_ty = inner_ty.slicePtrFieldType(mod); | 24680 | const slice_ptr_ty = inner_ty.slicePtrFieldType(mod); |
| 24558 | | 24681 | |
| 24559 | const result_ty = try Type.ptr(sema.arena, mod, .{ | 24682 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| ... | @@ -24575,7 +24698,7 @@ fn fieldPtr( | ... | @@ -24575,7 +24698,7 @@ fn fieldPtr( |
| 24575 | try sema.requireRuntimeBlock(block, src, null); | 24698 | try sema.requireRuntimeBlock(block, src, null); |
| 24576 | | 24699 | |
| 24577 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); | 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 | const result_ty = try Type.ptr(sema.arena, mod, .{ | 24702 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24580 | .pointee_type = Type.usize, | 24703 | .pointee_type = Type.usize, |
| 24581 | .mutable = attr_ptr_ty.ptrIsMutable(mod), | 24704 | .mutable = attr_ptr_ty.ptrIsMutable(mod), |
| ... | @@ -24600,7 +24723,7 @@ fn fieldPtr( | ... | @@ -24600,7 +24723,7 @@ fn fieldPtr( |
| 24600 | block, | 24723 | block, |
| 24601 | field_name_src, | 24724 | field_name_src, |
| 24602 | "no member named '{s}' in '{}'", | 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,14 +24740,13 @@ fn fieldPtr( |
| 24617 | | 24740 | |
| 24618 | switch (child_type.zigTypeTag(mod)) { | 24741 | switch (child_type.zigTypeTag(mod)) { |
| 24619 | .ErrorSet => { | 24742 | .ErrorSet => { |
| 24620 | const name = try ip.getOrPutString(gpa, field_name); | | |
| 24621 | switch (ip.indexToKey(child_type.toIntern())) { | 24743 | switch (ip.indexToKey(child_type.toIntern())) { |
| 24622 | .error_set_type => |error_set_type| blk: { | 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 | break :blk; | 24746 | break :blk; |
| 24625 | } | 24747 | } |
| 24626 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ | 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 | .inferred_error_set_type => { | 24752 | .inferred_error_set_type => { |
| ... | @@ -24642,12 +24764,12 @@ fn fieldPtr( | ... | @@ -24642,12 +24764,12 @@ fn fieldPtr( |
| 24642 | const error_set_type = if (!child_type.isAnyError(mod)) | 24764 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24643 | child_type | 24765 | child_type |
| 24644 | else | 24766 | else |
| 24645 | try mod.singleErrorSetTypeNts(name); | 24767 | try mod.singleErrorSetTypeNts(field_name); |
| 24646 | return sema.analyzeDeclRef(try anon_decl.finish( | 24768 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24647 | error_set_type, | 24769 | error_set_type, |
| 24648 | (try mod.intern(.{ .err = .{ | 24770 | (try mod.intern(.{ .err = .{ |
| 24649 | .ty = error_set_type.toIntern(), | 24771 | .ty = error_set_type.toIntern(), |
| 24650 | .name = name, | 24772 | .name = field_name, |
| 24651 | } })).toValue(), | 24773 | } })).toValue(), |
| 24652 | 0, // default alignment | 24774 | 0, // default alignment |
| 24653 | )); | 24775 | )); |
| ... | @@ -24736,13 +24858,14 @@ fn fieldCallBind( | ... | @@ -24736,13 +24858,14 @@ fn fieldCallBind( |
| 24736 | block: *Block, | 24858 | block: *Block, |
| 24737 | src: LazySrcLoc, | 24859 | src: LazySrcLoc, |
| 24738 | raw_ptr: Air.Inst.Ref, | 24860 | raw_ptr: Air.Inst.Ref, |
| 24739 | field_name: []const u8, | 24861 | field_name: InternPool.NullTerminatedString, |
| 24740 | field_name_src: LazySrcLoc, | 24862 | field_name_src: LazySrcLoc, |
| 24741 | ) CompileError!ResolvedFieldCallee { | 24863 | ) CompileError!ResolvedFieldCallee { |
| 24742 | // When editing this function, note that there is corresponding logic to be edited | 24864 | // When editing this function, note that there is corresponding logic to be edited |
| 24743 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 24865 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 24744 | | 24866 | |
| 24745 | const mod = sema.mod; | 24867 | const mod = sema.mod; |
| | 24868 | const ip = &mod.intern_pool; |
| 24746 | const raw_ptr_src = src; // TODO better source location | 24869 | const raw_ptr_src = src; // TODO better source location |
| 24747 | const raw_ptr_ty = sema.typeOf(raw_ptr); | 24870 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 24748 | const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C)) | 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,18 +24894,18 @@ fn fieldCallBind( |
| 24771 | | 24894 | |
| 24772 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); | 24895 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 24773 | } else if (struct_ty.isTuple(mod)) { | 24896 | } else if (struct_ty.isTuple(mod)) { |
| 24774 | if (mem.eql(u8, field_name, "len")) { | 24897 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24775 | return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) }; | 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 | if (field_index >= struct_ty.structFieldCount(mod)) break :find_field; | 24901 | if (field_index >= struct_ty.structFieldCount(mod)) break :find_field; |
| 24779 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr); | 24902 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr); |
| 24780 | } else |_| {} | 24903 | } else |_| {} |
| 24781 | } else { | 24904 | } else { |
| 24782 | const max = struct_ty.structFieldCount(mod); | 24905 | const max = struct_ty.structFieldCount(mod); |
| 24783 | var i: u32 = 0; | 24906 | for (0..max) |i_usize| { |
| 24784 | while (i < max) : (i += 1) { | 24907 | const i = @intCast(u32, i_usize); |
| 24785 | if (mem.eql(u8, struct_ty.structFieldName(i, mod), field_name)) { | 24908 | if (field_name == struct_ty.structFieldName(i, mod)) { |
| 24786 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i, mod), i, object_ptr); | 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,12 +24999,12 @@ fn fieldCallBind( |
| 24876 | }; | 24999 | }; |
| 24877 | | 25000 | |
| 24878 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 25003 | errdefer msg.destroy(sema.gpa); |
| 24881 | try sema.addDeclaredHereNote(msg, concrete_ty); | 25004 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 24882 | if (found_decl) |decl_idx| { | 25005 | if (found_decl) |decl_idx| { |
| 24883 | const decl = mod.declPtr(decl_idx); | 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 | break :msg msg; | 25009 | break :msg msg; |
| 24887 | }; | 25010 | }; |
| ... | @@ -24933,7 +25056,7 @@ fn namespaceLookup( | ... | @@ -24933,7 +25056,7 @@ fn namespaceLookup( |
| 24933 | block: *Block, | 25056 | block: *Block, |
| 24934 | src: LazySrcLoc, | 25057 | src: LazySrcLoc, |
| 24935 | namespace: Namespace.Index, | 25058 | namespace: Namespace.Index, |
| 24936 | decl_name: []const u8, | 25059 | decl_name: InternPool.NullTerminatedString, |
| 24937 | ) CompileError!?Decl.Index { | 25060 | ) CompileError!?Decl.Index { |
| 24938 | const mod = sema.mod; | 25061 | const mod = sema.mod; |
| 24939 | const gpa = sema.gpa; | 25062 | const gpa = sema.gpa; |
| ... | @@ -24942,7 +25065,7 @@ fn namespaceLookup( | ... | @@ -24942,7 +25065,7 @@ fn namespaceLookup( |
| 24942 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { | 25065 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 24943 | const msg = msg: { | 25066 | const msg = msg: { |
| 24944 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ | 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 | errdefer msg.destroy(gpa); | 25070 | errdefer msg.destroy(gpa); |
| 24948 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); | 25071 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); |
| ... | @@ -24960,7 +25083,7 @@ fn namespaceLookupRef( | ... | @@ -24960,7 +25083,7 @@ fn namespaceLookupRef( |
| 24960 | block: *Block, | 25083 | block: *Block, |
| 24961 | src: LazySrcLoc, | 25084 | src: LazySrcLoc, |
| 24962 | namespace: Namespace.Index, | 25085 | namespace: Namespace.Index, |
| 24963 | decl_name: []const u8, | 25086 | decl_name: InternPool.NullTerminatedString, |
| 24964 | ) CompileError!?Air.Inst.Ref { | 25087 | ) CompileError!?Air.Inst.Ref { |
| 24965 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; | 25088 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 24966 | try sema.addReferencedBy(block, src, decl); | 25089 | try sema.addReferencedBy(block, src, decl); |
| ... | @@ -24972,7 +25095,7 @@ fn namespaceLookupVal( | ... | @@ -24972,7 +25095,7 @@ fn namespaceLookupVal( |
| 24972 | block: *Block, | 25095 | block: *Block, |
| 24973 | src: LazySrcLoc, | 25096 | src: LazySrcLoc, |
| 24974 | namespace: Namespace.Index, | 25097 | namespace: Namespace.Index, |
| 24975 | decl_name: []const u8, | 25098 | decl_name: InternPool.NullTerminatedString, |
| 24976 | ) CompileError!?Air.Inst.Ref { | 25099 | ) CompileError!?Air.Inst.Ref { |
| 24977 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; | 25100 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 24978 | return try sema.analyzeDeclVal(block, src, decl); | 25101 | return try sema.analyzeDeclVal(block, src, decl); |
| ... | @@ -24983,7 +25106,7 @@ fn structFieldPtr( | ... | @@ -24983,7 +25106,7 @@ fn structFieldPtr( |
| 24983 | block: *Block, | 25106 | block: *Block, |
| 24984 | src: LazySrcLoc, | 25107 | src: LazySrcLoc, |
| 24985 | struct_ptr: Air.Inst.Ref, | 25108 | struct_ptr: Air.Inst.Ref, |
| 24986 | field_name: []const u8, | 25109 | field_name: InternPool.NullTerminatedString, |
| 24987 | field_name_src: LazySrcLoc, | 25110 | field_name_src: LazySrcLoc, |
| 24988 | unresolved_struct_ty: Type, | 25111 | unresolved_struct_ty: Type, |
| 24989 | initializing: bool, | 25112 | initializing: bool, |
| ... | @@ -24995,7 +25118,7 @@ fn structFieldPtr( | ... | @@ -24995,7 +25118,7 @@ fn structFieldPtr( |
| 24995 | try sema.resolveStructLayout(struct_ty); | 25118 | try sema.resolveStructLayout(struct_ty); |
| 24996 | | 25119 | |
| 24997 | if (struct_ty.isTuple(mod)) { | 25120 | if (struct_ty.isTuple(mod)) { |
| 24998 | if (mem.eql(u8, field_name, "len")) { | 25121 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { |
| 24999 | const len_inst = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)); | 25122 | const len_inst = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)); |
| 25000 | return sema.analyzeRef(block, src, len_inst); | 25123 | return sema.analyzeRef(block, src, len_inst); |
| 25001 | } | 25124 | } |
| ... | @@ -25101,7 +25224,7 @@ fn structFieldPtrByIndex( | ... | @@ -25101,7 +25224,7 @@ fn structFieldPtrByIndex( |
| 25101 | if (field.is_comptime) { | 25224 | if (field.is_comptime) { |
| 25102 | const val = try mod.intern(.{ .ptr = .{ | 25225 | const val = try mod.intern(.{ .ptr = .{ |
| 25103 | .ty = ptr_field_ty.toIntern(), | 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 | return sema.addConstant(ptr_field_ty, val.toValue()); | 25229 | return sema.addConstant(ptr_field_ty, val.toValue()); |
| 25107 | } | 25230 | } |
| ... | @@ -25126,7 +25249,7 @@ fn structFieldVal( | ... | @@ -25126,7 +25249,7 @@ fn structFieldVal( |
| 25126 | block: *Block, | 25249 | block: *Block, |
| 25127 | src: LazySrcLoc, | 25250 | src: LazySrcLoc, |
| 25128 | struct_byval: Air.Inst.Ref, | 25251 | struct_byval: Air.Inst.Ref, |
| 25129 | field_name: []const u8, | 25252 | field_name: InternPool.NullTerminatedString, |
| 25130 | field_name_src: LazySrcLoc, | 25253 | field_name_src: LazySrcLoc, |
| 25131 | unresolved_struct_ty: Type, | 25254 | unresolved_struct_ty: Type, |
| 25132 | ) CompileError!Air.Inst.Ref { | 25255 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -25145,7 +25268,7 @@ fn structFieldVal( | ... | @@ -25145,7 +25268,7 @@ fn structFieldVal( |
| 25145 | const field = struct_obj.fields.values()[field_index]; | 25268 | const field = struct_obj.fields.values()[field_index]; |
| 25146 | | 25269 | |
| 25147 | if (field.is_comptime) { | 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 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { | 25274 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| ... | @@ -25176,12 +25299,12 @@ fn tupleFieldVal( | ... | @@ -25176,12 +25299,12 @@ fn tupleFieldVal( |
| 25176 | block: *Block, | 25299 | block: *Block, |
| 25177 | src: LazySrcLoc, | 25300 | src: LazySrcLoc, |
| 25178 | tuple_byval: Air.Inst.Ref, | 25301 | tuple_byval: Air.Inst.Ref, |
| 25179 | field_name: []const u8, | 25302 | field_name: InternPool.NullTerminatedString, |
| 25180 | field_name_src: LazySrcLoc, | 25303 | field_name_src: LazySrcLoc, |
| 25181 | tuple_ty: Type, | 25304 | tuple_ty: Type, |
| 25182 | ) CompileError!Air.Inst.Ref { | 25305 | ) CompileError!Air.Inst.Ref { |
| 25183 | const mod = sema.mod; | 25306 | const mod = sema.mod; |
| 25184 | if (mem.eql(u8, field_name, "len")) { | 25307 | if (mod.intern_pool.stringEqlSlice(field_name, "len")) { |
| 25185 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount(mod)); | 25308 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount(mod)); |
| 25186 | } | 25309 | } |
| 25187 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); | 25310 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); |
| ... | @@ -25193,11 +25316,12 @@ fn tupleFieldIndex( | ... | @@ -25193,11 +25316,12 @@ fn tupleFieldIndex( |
| 25193 | sema: *Sema, | 25316 | sema: *Sema, |
| 25194 | block: *Block, | 25317 | block: *Block, |
| 25195 | tuple_ty: Type, | 25318 | tuple_ty: Type, |
| 25196 | field_name: []const u8, | 25319 | field_name_ip: InternPool.NullTerminatedString, |
| 25197 | field_name_src: LazySrcLoc, | 25320 | field_name_src: LazySrcLoc, |
| 25198 | ) CompileError!u32 { | 25321 | ) CompileError!u32 { |
| 25199 | const mod = sema.mod; | 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 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { | 25325 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 25202 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; | 25326 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; |
| 25203 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ | 25327 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ |
| ... | @@ -25253,13 +25377,14 @@ fn unionFieldPtr( | ... | @@ -25253,13 +25377,14 @@ fn unionFieldPtr( |
| 25253 | block: *Block, | 25377 | block: *Block, |
| 25254 | src: LazySrcLoc, | 25378 | src: LazySrcLoc, |
| 25255 | union_ptr: Air.Inst.Ref, | 25379 | union_ptr: Air.Inst.Ref, |
| 25256 | field_name: []const u8, | 25380 | field_name: InternPool.NullTerminatedString, |
| 25257 | field_name_src: LazySrcLoc, | 25381 | field_name_src: LazySrcLoc, |
| 25258 | unresolved_union_ty: Type, | 25382 | unresolved_union_ty: Type, |
| 25259 | initializing: bool, | 25383 | initializing: bool, |
| 25260 | ) CompileError!Air.Inst.Ref { | 25384 | ) CompileError!Air.Inst.Ref { |
| 25261 | const arena = sema.arena; | 25385 | const arena = sema.arena; |
| 25262 | const mod = sema.mod; | 25386 | const mod = sema.mod; |
| | 25387 | const ip = &mod.intern_pool; |
| 25263 | | 25388 | |
| 25264 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); | 25389 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); |
| 25265 | | 25390 | |
| ... | @@ -25281,7 +25406,9 @@ fn unionFieldPtr( | ... | @@ -25281,7 +25406,9 @@ fn unionFieldPtr( |
| 25281 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 25406 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); |
| 25282 | errdefer msg.destroy(sema.gpa); | 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 | try sema.addDeclaredHereNote(msg, union_ty); | 25412 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25286 | break :msg msg; | 25413 | break :msg msg; |
| 25287 | }; | 25414 | }; |
| ... | @@ -25296,14 +25423,17 @@ fn unionFieldPtr( | ... | @@ -25296,14 +25423,17 @@ fn unionFieldPtr( |
| 25296 | if (union_val.isUndef(mod)) { | 25423 | if (union_val.isUndef(mod)) { |
| 25297 | return sema.failWithUseOfUndef(block, src); | 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 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); | 25427 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25301 | const tag_matches = un.tag == field_tag.toIntern(); | 25428 | const tag_matches = un.tag == field_tag.toIntern(); |
| 25302 | if (!tag_matches) { | 25429 | if (!tag_matches) { |
| 25303 | const msg = msg: { | 25430 | const msg = msg: { |
| 25304 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; | 25431 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25305 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 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 | errdefer msg.destroy(sema.gpa); | 25437 | errdefer msg.destroy(sema.gpa); |
| 25308 | try sema.addDeclaredHereNote(msg, union_ty); | 25438 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25309 | break :msg msg; | 25439 | break :msg msg; |
| ... | @@ -25345,11 +25475,12 @@ fn unionFieldVal( | ... | @@ -25345,11 +25475,12 @@ fn unionFieldVal( |
| 25345 | block: *Block, | 25475 | block: *Block, |
| 25346 | src: LazySrcLoc, | 25476 | src: LazySrcLoc, |
| 25347 | union_byval: Air.Inst.Ref, | 25477 | union_byval: Air.Inst.Ref, |
| 25348 | field_name: []const u8, | 25478 | field_name: InternPool.NullTerminatedString, |
| 25349 | field_name_src: LazySrcLoc, | 25479 | field_name_src: LazySrcLoc, |
| 25350 | unresolved_union_ty: Type, | 25480 | unresolved_union_ty: Type, |
| 25351 | ) CompileError!Air.Inst.Ref { | 25481 | ) CompileError!Air.Inst.Ref { |
| 25352 | const mod = sema.mod; | 25482 | const mod = sema.mod; |
| | 25483 | const ip = &mod.intern_pool; |
| 25353 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); | 25484 | assert(unresolved_union_ty.zigTypeTag(mod) == .Union); |
| 25354 | | 25485 | |
| 25355 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); | 25486 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); |
| ... | @@ -25361,7 +25492,7 @@ fn unionFieldVal( | ... | @@ -25361,7 +25492,7 @@ fn unionFieldVal( |
| 25361 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { | 25492 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { |
| 25362 | if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty); | 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 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); | 25496 | const field_tag = try mod.enumValueFieldIndex(union_obj.tag_ty, enum_field_index); |
| 25366 | const tag_matches = un.tag == field_tag.toIntern(); | 25497 | const tag_matches = un.tag == field_tag.toIntern(); |
| 25367 | switch (union_obj.layout) { | 25498 | switch (union_obj.layout) { |
| ... | @@ -25372,7 +25503,9 @@ fn unionFieldVal( | ... | @@ -25372,7 +25503,9 @@ fn unionFieldVal( |
| 25372 | const msg = msg: { | 25503 | const msg = msg: { |
| 25373 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; | 25504 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25374 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 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 | errdefer msg.destroy(sema.gpa); | 25509 | errdefer msg.destroy(sema.gpa); |
| 25377 | try sema.addDeclaredHereNote(msg, union_ty); | 25510 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25378 | break :msg msg; | 25511 | break :msg msg; |
| ... | @@ -26470,14 +26603,13 @@ fn coerceExtra( | ... | @@ -26470,14 +26603,13 @@ fn coerceExtra( |
| 26470 | // enum literal to enum | 26603 | // enum literal to enum |
| 26471 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 26604 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); |
| 26472 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; | 26605 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 26473 | const bytes = mod.intern_pool.stringToSlice(string); | 26606 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { |
| 26474 | const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse { | | |
| 26475 | const msg = msg: { | 26607 | const msg = msg: { |
| 26476 | const msg = try sema.errMsg( | 26608 | const msg = try sema.errMsg( |
| 26477 | block, | 26609 | block, |
| 26478 | inst_src, | 26610 | inst_src, |
| 26479 | "no field named '{s}' in enum '{}'", | 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 | errdefer msg.destroy(sema.gpa); | 26614 | errdefer msg.destroy(sema.gpa); |
| 26483 | try sema.addDeclaredHereNote(msg, dest_ty); | 26615 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | @@ -27876,10 +28008,7 @@ fn storePtrVal( | ... | @@ -27876,10 +28008,7 @@ fn storePtrVal( |
| 27876 | error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(mod)}), | 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); | 28011 | reinterpret.val_ptr.* = (try (try Value.readFromMemory(mut_kit.ty, mod, buffer, sema.arena)).intern(mut_kit.ty, mod)).toValue(); |
| 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(); | | |
| 27883 | }, | 28012 | }, |
| 27884 | .bad_decl_ty, .bad_ptr_ty => { | 28013 | .bad_decl_ty, .bad_ptr_ty => { |
| 27885 | // TODO show the decl declaration site in a note and explain whether the decl | 28014 | // TODO show the decl declaration site in a note and explain whether the decl |
| ... | @@ -27913,18 +28042,6 @@ const ComptimePtrMutationKit = struct { | ... | @@ -27913,18 +28042,6 @@ const ComptimePtrMutationKit = struct { |
| 27913 | bad_ptr_ty, | 28042 | bad_ptr_ty, |
| 27914 | }, | 28043 | }, |
| 27915 | ty: Type, | 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 | fn beginComptimePtrMutation( | 28047 | fn beginComptimePtrMutation( |
| ... | @@ -27966,10 +28083,8 @@ fn beginComptimePtrMutation( | ... | @@ -27966,10 +28083,8 @@ fn beginComptimePtrMutation( |
| 27966 | // An error union has been initialized to undefined at comptime and now we | 28083 | // An error union has been initialized to undefined at comptime and now we |
| 27967 | // are for the first time setting the payload. We must change the | 28084 | // are for the first time setting the payload. We must change the |
| 27968 | // representation of the error union from `undef` to `opt_payload`. | 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 | payload.* = .{ | 28088 | payload.* = .{ |
| 27974 | .base = .{ .tag = .eu_payload }, | 28089 | .base = .{ .tag = .eu_payload }, |
| 27975 | .data = (try mod.intern(.{ .undef = payload_ty.toIntern() })).toValue(), | 28090 | .data = (try mod.intern(.{ .undef = payload_ty.toIntern() })).toValue(), |
| ... | @@ -28019,10 +28134,8 @@ fn beginComptimePtrMutation( | ... | @@ -28019,10 +28134,8 @@ fn beginComptimePtrMutation( |
| 28019 | // An optional has been initialized to undefined at comptime and now we | 28134 | // An optional has been initialized to undefined at comptime and now we |
| 28020 | // are for the first time setting the payload. We must change the | 28135 | // are for the first time setting the payload. We must change the |
| 28021 | // representation of the optional from `undef` to `opt_payload`. | 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 | payload.* = .{ | 28139 | payload.* = .{ |
| 28027 | .base = .{ .tag = .opt_payload }, | 28140 | .base = .{ .tag = .opt_payload }, |
| 28028 | .data = payload_val.toValue(), | 28141 | .data = payload_val.toValue(), |
| ... | @@ -28088,8 +28201,7 @@ fn beginComptimePtrMutation( | ... | @@ -28088,8 +28201,7 @@ fn beginComptimePtrMutation( |
| 28088 | // If we wanted to avoid this, there would need to be special detection | 28201 | // If we wanted to avoid this, there would need to be special detection |
| 28089 | // elsewhere to identify when writing a value to an array element that is stored | 28202 | // elsewhere to identify when writing a value to an array element that is stored |
| 28090 | // using the `bytes` tag, and handle it without making a call to this function. | 28203 | // using the `bytes` tag, and handle it without making a call to this function. |
| 28091 | const arena = parent.beginArena(sema.mod); | 28204 | const arena = sema.arena; |
| 28092 | defer parent.finishArena(sema.mod); | | |
| 28093 | | 28205 | |
| 28094 | const bytes = val_ptr.castTag(.bytes).?.data; | 28206 | const bytes = val_ptr.castTag(.bytes).?.data; |
| 28095 | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); | 28207 | const dest_len = parent.ty.arrayLenIncludingSentinel(mod); |
| ... | @@ -28121,8 +28233,7 @@ fn beginComptimePtrMutation( | ... | @@ -28121,8 +28233,7 @@ fn beginComptimePtrMutation( |
| 28121 | // need to be special detection elsewhere to identify when writing a value to an | 28233 | // need to be special detection elsewhere to identify when writing a value to an |
| 28122 | // array element that is stored using the `repeated` tag, and handle it | 28234 | // array element that is stored using the `repeated` tag, and handle it |
| 28123 | // without making a call to this function. | 28235 | // without making a call to this function. |
| 28124 | const arena = parent.beginArena(sema.mod); | 28236 | const arena = sema.arena; |
| 28125 | defer parent.finishArena(sema.mod); | | |
| 28126 | | 28237 | |
| 28127 | const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena); | 28238 | const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena); |
| 28128 | const array_len_including_sentinel = | 28239 | const array_len_including_sentinel = |
| ... | @@ -28163,8 +28274,7 @@ fn beginComptimePtrMutation( | ... | @@ -28163,8 +28274,7 @@ fn beginComptimePtrMutation( |
| 28163 | // An array has been initialized to undefined at comptime and now we | 28274 | // An array has been initialized to undefined at comptime and now we |
| 28164 | // are for the first time setting an element. We must change the representation | 28275 | // are for the first time setting an element. We must change the representation |
| 28165 | // of the array from `undef` to `array`. | 28276 | // of the array from `undef` to `array`. |
| 28166 | const arena = parent.beginArena(sema.mod); | 28277 | const arena = sema.arena; |
| 28167 | defer parent.finishArena(sema.mod); | | |
| 28168 | | 28278 | |
| 28169 | const array_len_including_sentinel = | 28279 | const array_len_including_sentinel = |
| 28170 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); | 28280 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod)); |
| ... | @@ -28261,8 +28371,7 @@ fn beginComptimePtrMutation( | ... | @@ -28261,8 +28371,7 @@ fn beginComptimePtrMutation( |
| 28261 | parent.mut_decl, | 28371 | parent.mut_decl, |
| 28262 | ), | 28372 | ), |
| 28263 | .repeated => { | 28373 | .repeated => { |
| 28264 | const arena = parent.beginArena(sema.mod); | 28374 | const arena = sema.arena; |
| 28265 | defer parent.finishArena(sema.mod); | | |
| 28266 | | 28375 | |
| 28267 | const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod)); | 28376 | const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod)); |
| 28268 | @memset(elems, val_ptr.castTag(.repeated).?.data); | 28377 | @memset(elems, val_ptr.castTag(.repeated).?.data); |
| ... | @@ -28325,8 +28434,7 @@ fn beginComptimePtrMutation( | ... | @@ -28325,8 +28434,7 @@ fn beginComptimePtrMutation( |
| 28325 | // A struct or union has been initialized to undefined at comptime and now we | 28434 | // A struct or union has been initialized to undefined at comptime and now we |
| 28326 | // are for the first time setting a field. We must change the representation | 28435 | // are for the first time setting a field. We must change the representation |
| 28327 | // of the struct/union from `undef` to `struct`/`union`. | 28436 | // of the struct/union from `undef` to `struct`/`union`. |
| 28328 | const arena = parent.beginArena(sema.mod); | 28437 | const arena = sema.arena; |
| 28329 | defer parent.finishArena(sema.mod); | | |
| 28330 | | 28438 | |
| 28331 | switch (parent.ty.zigTypeTag(mod)) { | 28439 | switch (parent.ty.zigTypeTag(mod)) { |
| 28332 | .Struct => { | 28440 | .Struct => { |
| ... | @@ -28436,11 +28544,7 @@ fn beginComptimePtrMutationInner( | ... | @@ -28436,11 +28544,7 @@ fn beginComptimePtrMutationInner( |
| 28436 | const target = mod.getTarget(); | 28544 | const target = mod.getTarget(); |
| 28437 | const coerce_ok = (try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_ty, true, target, src, src)) == .ok; | 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); | 28547 | decl_val.* = try decl_val.unintern(sema.arena, mod); |
| 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); | | |
| 28444 | | 28548 | |
| 28445 | if (coerce_ok) { | 28549 | if (coerce_ok) { |
| 28446 | return ComptimePtrMutationKit{ | 28550 | return ComptimePtrMutationKit{ |
| ... | @@ -28928,6 +29032,7 @@ fn coerceEnumToUnion( | ... | @@ -28928,6 +29032,7 @@ fn coerceEnumToUnion( |
| 28928 | inst_src: LazySrcLoc, | 29032 | inst_src: LazySrcLoc, |
| 28929 | ) !Air.Inst.Ref { | 29033 | ) !Air.Inst.Ref { |
| 28930 | const mod = sema.mod; | 29034 | const mod = sema.mod; |
| | 29035 | const ip = &mod.intern_pool; |
| 28931 | const inst_ty = sema.typeOf(inst); | 29036 | const inst_ty = sema.typeOf(inst); |
| 28932 | | 29037 | |
| 28933 | const tag_ty = union_ty.unionTagType(mod) orelse { | 29038 | const tag_ty = union_ty.unionTagType(mod) orelse { |
| ... | @@ -28966,7 +29071,9 @@ fn coerceEnumToUnion( | ... | @@ -28966,7 +29071,9 @@ fn coerceEnumToUnion( |
| 28966 | errdefer msg.destroy(sema.gpa); | 29071 | errdefer msg.destroy(sema.gpa); |
| 28967 | | 29072 | |
| 28968 | const field_name = union_obj.fields.keys()[field_index]; | 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 | try sema.addDeclaredHereNote(msg, union_ty); | 29077 | try sema.addDeclaredHereNote(msg, union_ty); |
| 28971 | break :msg msg; | 29078 | break :msg msg; |
| 28972 | }; | 29079 | }; |
| ... | @@ -28976,11 +29083,14 @@ fn coerceEnumToUnion( | ... | @@ -28976,11 +29083,14 @@ fn coerceEnumToUnion( |
| 28976 | const msg = msg: { | 29083 | const msg = msg: { |
| 28977 | const field_name = union_obj.fields.keys()[field_index]; | 29084 | const field_name = union_obj.fields.keys()[field_index]; |
| 28978 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{ | 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 | errdefer msg.destroy(sema.gpa); | 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 | try sema.addDeclaredHereNote(msg, union_ty); | 29094 | try sema.addDeclaredHereNote(msg, union_ty); |
| 28985 | break :msg msg; | 29095 | break :msg msg; |
| 28986 | }; | 29096 | }; |
| ... | @@ -29049,7 +29159,10 @@ fn coerceEnumToUnion( | ... | @@ -29049,7 +29159,10 @@ fn coerceEnumToUnion( |
| 29049 | const field_name = field.key_ptr.*; | 29159 | const field_name = field.key_ptr.*; |
| 29050 | const field_ty = field.value_ptr.ty; | 29160 | const field_ty = field.value_ptr.ty; |
| 29051 | if (!(try sema.typeHasRuntimeBits(field_ty))) continue; | 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 | try sema.addDeclaredHereNote(msg, union_ty); | 29167 | try sema.addDeclaredHereNote(msg, union_ty); |
| 29055 | break :msg msg; | 29168 | break :msg msg; |
| ... | @@ -29068,11 +29181,11 @@ fn coerceAnonStructToUnion( | ... | @@ -29068,11 +29181,11 @@ fn coerceAnonStructToUnion( |
| 29068 | const mod = sema.mod; | 29181 | const mod = sema.mod; |
| 29069 | const inst_ty = sema.typeOf(inst); | 29182 | const inst_ty = sema.typeOf(inst); |
| 29070 | const field_info: union(enum) { | 29183 | const field_info: union(enum) { |
| 29071 | name: []const u8, | 29184 | name: InternPool.NullTerminatedString, |
| 29072 | count: usize, | 29185 | count: usize, |
| 29073 | } = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { | 29186 | } = switch (mod.intern_pool.indexToKey(inst_ty.toIntern())) { |
| 29074 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len == 1) | 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 | else | 29189 | else |
| 29077 | .{ .count = anon_struct_type.names.len }, | 29190 | .{ .count = anon_struct_type.names.len }, |
| 29078 | .struct_type => |struct_type| name: { | 29191 | .struct_type => |struct_type| name: { |
| ... | @@ -29335,6 +29448,7 @@ fn coerceTupleToStruct( | ... | @@ -29335,6 +29448,7 @@ fn coerceTupleToStruct( |
| 29335 | inst_src: LazySrcLoc, | 29448 | inst_src: LazySrcLoc, |
| 29336 | ) !Air.Inst.Ref { | 29449 | ) !Air.Inst.Ref { |
| 29337 | const mod = sema.mod; | 29450 | const mod = sema.mod; |
| | 29451 | const ip = &mod.intern_pool; |
| 29338 | const struct_ty = try sema.resolveTypeFields(dest_ty); | 29452 | const struct_ty = try sema.resolveTypeFields(dest_ty); |
| 29339 | | 29453 | |
| 29340 | if (struct_ty.isTupleOrAnonStruct(mod)) { | 29454 | if (struct_ty.isTupleOrAnonStruct(mod)) { |
| ... | @@ -29348,7 +29462,7 @@ fn coerceTupleToStruct( | ... | @@ -29348,7 +29462,7 @@ fn coerceTupleToStruct( |
| 29348 | | 29462 | |
| 29349 | const inst_ty = sema.typeOf(inst); | 29463 | const inst_ty = sema.typeOf(inst); |
| 29350 | var runtime_src: ?LazySrcLoc = null; | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, | 29466 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29353 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| | 29467 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29354 | struct_obj.fields.count() | 29468 | struct_obj.fields.count() |
| ... | @@ -29360,11 +29474,11 @@ fn coerceTupleToStruct( | ... | @@ -29360,11 +29474,11 @@ fn coerceTupleToStruct( |
| 29360 | const field_i = @intCast(u32, field_index_usize); | 29474 | const field_i = @intCast(u32, field_index_usize); |
| 29361 | const field_src = inst_src; // TODO better source location | 29475 | const field_src = inst_src; // TODO better source location |
| 29362 | // https://github.com/ziglang/zig/issues/15709 | 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 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) | 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 | else | 29480 | else |
| 29367 | try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}), | 29481 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), |
| 29368 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], | 29482 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], |
| 29369 | else => unreachable, | 29483 | else => unreachable, |
| 29370 | }; | 29484 | }; |
| ... | @@ -29378,7 +29492,7 @@ fn coerceTupleToStruct( | ... | @@ -29378,7 +29492,7 @@ fn coerceTupleToStruct( |
| 29378 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 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 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i); | 29496 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i); |
| 29383 | } | 29497 | } |
| 29384 | } | 29498 | } |
| ... | @@ -29401,9 +29515,9 @@ fn coerceTupleToStruct( | ... | @@ -29401,9 +29515,9 @@ fn coerceTupleToStruct( |
| 29401 | const field_name = fields.keys()[i]; | 29515 | const field_name = fields.keys()[i]; |
| 29402 | const field = fields.values()[i]; | 29516 | const field = fields.values()[i]; |
| 29403 | const field_src = inst_src; // TODO better source location | 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 | const template = "missing struct field: {s}"; | 29519 | const template = "missing struct field: {s}"; |
| 29406 | const args = .{field_name}; | 29520 | const args = .{ip.stringToSlice(field_name)}; |
| 29407 | if (root_msg) |msg| { | 29521 | if (root_msg) |msg| { |
| 29408 | try sema.errNote(block, field_src, msg, template, args); | 29522 | try sema.errNote(block, field_src, msg, template, args); |
| 29409 | } else { | 29523 | } else { |
| ... | @@ -29412,9 +29526,9 @@ fn coerceTupleToStruct( | ... | @@ -29412,9 +29526,9 @@ fn coerceTupleToStruct( |
| 29412 | continue; | 29526 | continue; |
| 29413 | } | 29527 | } |
| 29414 | if (runtime_src == null) { | 29528 | if (runtime_src == null) { |
| 29415 | field_vals[i] = field.default_val.toIntern(); | 29529 | field_vals[i] = field.default_val; |
| 29416 | } else { | 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,7 +29547,7 @@ fn coerceTupleToStruct( |
| 29433 | .ty = struct_ty.toIntern(), | 29547 | .ty = struct_ty.toIntern(), |
| 29434 | .storage = .{ .elems = field_vals }, | 29548 | .storage = .{ .elems = field_vals }, |
| 29435 | } }); | 29549 | } }); |
| 29436 | errdefer mod.intern_pool.remove(struct_val); | 29550 | errdefer ip.remove(struct_val); |
| 29437 | | 29551 | |
| 29438 | return sema.addConstant(struct_ty, struct_val.toValue()); | 29552 | return sema.addConstant(struct_ty, struct_val.toValue()); |
| 29439 | } | 29553 | } |
| ... | @@ -29446,7 +29560,8 @@ fn coerceTupleToTuple( | ... | @@ -29446,7 +29560,8 @@ fn coerceTupleToTuple( |
| 29446 | inst_src: LazySrcLoc, | 29560 | inst_src: LazySrcLoc, |
| 29447 | ) !Air.Inst.Ref { | 29561 | ) !Air.Inst.Ref { |
| 29448 | const mod = sema.mod; | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, | 29565 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29451 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| | 29566 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29452 | struct_obj.fields.count() | 29567 | struct_obj.fields.count() |
| ... | @@ -29459,7 +29574,7 @@ fn coerceTupleToTuple( | ... | @@ -29459,7 +29574,7 @@ fn coerceTupleToTuple( |
| 29459 | @memset(field_refs, .none); | 29574 | @memset(field_refs, .none); |
| 29460 | | 29575 | |
| 29461 | const inst_ty = sema.typeOf(inst); | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, | 29578 | .anon_struct_type => |anon_struct_type| anon_struct_type.types.len, |
| 29464 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| | 29579 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| |
| 29465 | struct_obj.fields.count() | 29580 | struct_obj.fields.count() |
| ... | @@ -29474,30 +29589,26 @@ fn coerceTupleToTuple( | ... | @@ -29474,30 +29589,26 @@ fn coerceTupleToTuple( |
| 29474 | const field_i = @intCast(u32, field_index_usize); | 29589 | const field_i = @intCast(u32, field_index_usize); |
| 29475 | const field_src = inst_src; // TODO better source location | 29590 | const field_src = inst_src; // TODO better source location |
| 29476 | // https://github.com/ziglang/zig/issues/15709 | 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 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) | 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 | else | 29595 | else |
| 29481 | try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}), | 29596 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}), |
| 29482 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], | 29597 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.keys()[field_i], |
| 29483 | else => unreachable, | 29598 | else => unreachable, |
| 29484 | }; | 29599 | }; |
| 29485 | | 29600 | |
| 29486 | if (mem.eql(u8, field_name, "len")) { | 29601 | if (ip.stringEqlSlice(field_name, "len")) |
| 29487 | return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{}); | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[field_index_usize].toType(), | 29605 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[field_index_usize].toType(), |
| 29492 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].ty, | 29606 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].ty, |
| 29493 | else => unreachable, | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.values[field_index_usize], | 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()) { | 29611 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[field_index_usize].default_val, |
| 29498 | .unreachable_value => .none, | | |
| 29499 | else => |default_val| default_val, | | |
| 29500 | }, | | |
| 29501 | else => unreachable, | 29612 | else => unreachable, |
| 29502 | }; | 29613 | }; |
| 29503 | | 29614 | |
| ... | @@ -29531,12 +29642,9 @@ fn coerceTupleToTuple( | ... | @@ -29531,12 +29642,9 @@ fn coerceTupleToTuple( |
| 29531 | for (field_refs, 0..) |*field_ref, i| { | 29642 | for (field_refs, 0..) |*field_ref, i| { |
| 29532 | if (field_ref.* != .none) continue; | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.values[i], | 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()) { | 29647 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].default_val, |
| 29537 | .unreachable_value => .none, | | |
| 29538 | else => |default_val| default_val, | | |
| 29539 | }, | | |
| 29540 | else => unreachable, | 29648 | else => unreachable, |
| 29541 | }; | 29649 | }; |
| 29542 | | 29650 | |
| ... | @@ -29552,7 +29660,7 @@ fn coerceTupleToTuple( | ... | @@ -29552,7 +29660,7 @@ fn coerceTupleToTuple( |
| 29552 | continue; | 29660 | continue; |
| 29553 | } | 29661 | } |
| 29554 | const template = "missing struct field: {s}"; | 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 | if (root_msg) |msg| { | 29664 | if (root_msg) |msg| { |
| 29557 | try sema.errNote(block, field_src, msg, template, args); | 29665 | try sema.errNote(block, field_src, msg, template, args); |
| 29558 | } else { | 29666 | } else { |
| ... | @@ -29563,7 +29671,7 @@ fn coerceTupleToTuple( | ... | @@ -29563,7 +29671,7 @@ fn coerceTupleToTuple( |
| 29563 | if (runtime_src == null) { | 29671 | if (runtime_src == null) { |
| 29564 | field_vals[i] = default_val; | 29672 | field_vals[i] = default_val; |
| 29565 | } else { | 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 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[i].toType(), | 29675 | .anon_struct_type => |anon_struct_type| anon_struct_type.types[i].toType(), |
| 29568 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].ty, | 29676 | .struct_type => |struct_type| mod.structPtrUnwrap(struct_type.index).?.fields.values()[i].ty, |
| 29569 | else => unreachable, | 29677 | else => unreachable, |
| ... | @@ -31803,15 +31911,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -31803,15 +31911,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 31803 | } | 31911 | } |
| 31804 | | 31912 | |
| 31805 | if (struct_obj.layout == .Auto and mod.backendSupportsFeature(.field_reordering)) { | 31913 | if (struct_obj.layout == .Auto and mod.backendSupportsFeature(.field_reordering)) { |
| 31806 | const optimized_order = if (struct_obj.owner_decl == sema.owner_decl_index) | 31914 | const optimized_order = try mod.tmp_hack_arena.allocator().alloc(u32, struct_obj.fields.count()); |
| 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 | }; | | |
| 31815 | | 31915 | |
| 31816 | for (struct_obj.fields.values(), 0..) |field, i| { | 31916 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 31817 | optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty)) | 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,9 +31952,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31852 | | 31952 | |
| 31853 | const decl_index = struct_obj.owner_decl; | 31953 | const decl_index = struct_obj.owner_decl; |
| 31854 | const decl = mod.declPtr(decl_index); | 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 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; | 31956 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 31860 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 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,7 +31977,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31880 | .mod = mod, | 31977 | .mod = mod, |
| 31881 | .gpa = gpa, | 31978 | .gpa = gpa, |
| 31882 | .arena = analysis_arena.allocator(), | 31979 | .arena = analysis_arena.allocator(), |
| 31883 | .perm_arena = decl_arena_allocator, | | |
| 31884 | .code = zir, | 31980 | .code = zir, |
| 31885 | .owner_decl = decl, | 31981 | .owner_decl = decl, |
| 31886 | .owner_decl_index = decl_index, | 31982 | .owner_decl_index = decl_index, |
| ... | @@ -31936,7 +32032,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31936,7 +32032,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31936 | .mod = mod, | 32032 | .mod = mod, |
| 31937 | .gpa = gpa, | 32033 | .gpa = gpa, |
| 31938 | .arena = undefined, | 32034 | .arena = undefined, |
| 31939 | .perm_arena = decl_arena_allocator, | | |
| 31940 | .code = zir, | 32035 | .code = zir, |
| 31941 | .owner_decl = decl, | 32036 | .owner_decl = decl, |
| 31942 | .owner_decl_index = decl_index, | 32037 | .owner_decl_index = decl_index, |
| ... | @@ -32581,6 +32676,7 @@ fn resolveInferredErrorSetTy( | ... | @@ -32581,6 +32676,7 @@ fn resolveInferredErrorSetTy( |
| 32581 | | 32676 | |
| 32582 | fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { | 32677 | fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { |
| 32583 | const gpa = mod.gpa; | 32678 | const gpa = mod.gpa; |
| | 32679 | const ip = &mod.intern_pool; |
| 32584 | const decl_index = struct_obj.owner_decl; | 32680 | const decl_index = struct_obj.owner_decl; |
| 32585 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; | 32681 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 32586 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 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,9 +32724,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32628 | } | 32724 | } |
| 32629 | | 32725 | |
| 32630 | const decl = mod.declPtr(decl_index); | 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 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 32728 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32636 | defer analysis_arena.deinit(); | 32729 | defer analysis_arena.deinit(); |
| ... | @@ -32642,7 +32735,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32642,7 +32735,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32642 | .mod = mod, | 32735 | .mod = mod, |
| 32643 | .gpa = gpa, | 32736 | .gpa = gpa, |
| 32644 | .arena = analysis_arena.allocator(), | 32737 | .arena = analysis_arena.allocator(), |
| 32645 | .perm_arena = decl_arena_allocator, | | |
| 32646 | .code = zir, | 32738 | .code = zir, |
| 32647 | .owner_decl = decl, | 32739 | .owner_decl = decl, |
| 32648 | .owner_decl_index = decl_index, | 32740 | .owner_decl_index = decl_index, |
| ... | @@ -32674,7 +32766,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32674,7 +32766,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32674 | } | 32766 | } |
| 32675 | | 32767 | |
| 32676 | struct_obj.fields = .{}; | 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 | const Field = struct { | 32771 | const Field = struct { |
| 32680 | type_body_len: u32 = 0, | 32772 | type_body_len: u32 = 0, |
| ... | @@ -32725,16 +32817,15 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32725,16 +32817,15 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32725 | extra_index += 1; | 32817 | extra_index += 1; |
| 32726 | | 32818 | |
| 32727 | // This string needs to outlive the ZIR code. | 32819 | // This string needs to outlive the ZIR code. |
| 32728 | const field_name = if (field_name_zir) |some| | 32820 | const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s| s else try std.fmt.allocPrint(sema.arena, "{d}", .{ |
| 32729 | try decl_arena_allocator.dupe(u8, some) | 32821 | field_i, |
| 32730 | else | 32822 | })); |
| 32731 | try std.fmt.allocPrint(decl_arena_allocator, "{d}", .{field_i}); | | |
| 32732 | | 32823 | |
| 32733 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); | 32824 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 32734 | if (gop.found_existing) { | 32825 | if (gop.found_existing) { |
| 32735 | const msg = msg: { | 32826 | const msg = msg: { |
| 32736 | const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy; | 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 | errdefer msg.destroy(gpa); | 32829 | errdefer msg.destroy(gpa); |
| 32739 | | 32830 | |
| 32740 | const prev_field_index = struct_obj.fields.getIndex(field_name).?; | 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,7 +32839,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32748 | gop.value_ptr.* = .{ | 32839 | gop.value_ptr.* = .{ |
| 32749 | .ty = Type.noreturn, | 32840 | .ty = Type.noreturn, |
| 32750 | .abi_align = 0, | 32841 | .abi_align = 0, |
| 32751 | .default_val = Value.@"unreachable", | 32842 | .default_val = .none, |
| 32752 | .is_comptime = is_comptime, | 32843 | .is_comptime = is_comptime, |
| 32753 | .offset = undefined, | 32844 | .offset = undefined, |
| 32754 | }; | 32845 | }; |
| ... | @@ -32917,7 +33008,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32917,7 +33008,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32917 | }).lazy; | 33008 | }).lazy; |
| 32918 | return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known"); | 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,6 +33026,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32935 | defer tracy.end(); | 33026 | defer tracy.end(); |
| 32936 | | 33027 | |
| 32937 | const gpa = mod.gpa; | 33028 | const gpa = mod.gpa; |
| | 33029 | const ip = &mod.intern_pool; |
| 32938 | const decl_index = union_obj.owner_decl; | 33030 | const decl_index = union_obj.owner_decl; |
| 32939 | const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir; | 33031 | const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir; |
| 32940 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; | 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,9 +33070,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32978 | extra_index += body.len; | 33070 | extra_index += body.len; |
| 32979 | | 33071 | |
| 32980 | const decl = mod.declPtr(decl_index); | 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 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 33074 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32986 | defer analysis_arena.deinit(); | 33075 | defer analysis_arena.deinit(); |
| ... | @@ -32992,7 +33081,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32992,7 +33081,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32992 | .mod = mod, | 33081 | .mod = mod, |
| 32993 | .gpa = gpa, | 33082 | .gpa = gpa, |
| 32994 | .arena = analysis_arena.allocator(), | 33083 | .arena = analysis_arena.allocator(), |
| 32995 | .perm_arena = decl_arena_allocator, | | |
| 32996 | .code = zir, | 33084 | .code = zir, |
| 32997 | .owner_decl = decl, | 33085 | .owner_decl = decl, |
| 32998 | .owner_decl_index = decl_index, | 33086 | .owner_decl_index = decl_index, |
| ... | @@ -33033,7 +33121,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33033,7 +33121,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33033 | try ct_decl.intern(mod); | 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 | var int_tag_ty: Type = undefined; | 33126 | var int_tag_ty: Type = undefined; |
| 33039 | var enum_field_names: []InternPool.NullTerminatedString = &.{}; | 33127 | var enum_field_names: []InternPool.NullTerminatedString = &.{}; |
| ... | @@ -33070,7 +33158,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33070,7 +33158,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33070 | } else { | 33158 | } else { |
| 33071 | // The provided type is the enum tag type. | 33159 | // The provided type is the enum tag type. |
| 33072 | union_obj.tag_ty = provided_ty; | 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 | .enum_type => |x| x, | 33162 | .enum_type => |x| x, |
| 33075 | else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}), | 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,10 +33262,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33174 | } | 33262 | } |
| 33175 | | 33263 | |
| 33176 | // This string needs to outlive the ZIR code. | 33264 | // This string needs to outlive the ZIR code. |
| 33177 | const field_name = try decl_arena_allocator.dupe(u8, field_name_zir); | 33265 | const field_name = try ip.getOrPutString(gpa, field_name_zir); |
| 33178 | const field_name_ip = try mod.intern_pool.getOrPutString(gpa, field_name); | | |
| 33179 | if (enum_field_names.len != 0) { | 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 | const field_ty: Type = if (!has_type) | 33270 | const field_ty: Type = if (!has_type) |
| ... | @@ -33205,7 +33292,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33205,7 +33292,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33205 | if (gop.found_existing) { | 33292 | if (gop.found_existing) { |
| 33206 | const msg = msg: { | 33293 | const msg = msg: { |
| 33207 | const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy; | 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 | errdefer msg.destroy(gpa); | 33298 | errdefer msg.destroy(gpa); |
| 33210 | | 33299 | |
| 33211 | const prev_field_index = union_obj.fields.getIndex(field_name).?; | 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,14 +33307,14 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33218 | } | 33307 | } |
| 33219 | | 33308 | |
| 33220 | if (explicit_enum_info) |tag_info| { | 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 | const msg = msg: { | 33311 | const msg = msg: { |
| 33223 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ | 33312 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ |
| 33224 | .index = field_i, | 33313 | .index = field_i, |
| 33225 | .range = .type, | 33314 | .range = .type, |
| 33226 | }).lazy; | 33315 | }).lazy; |
| 33227 | const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{s}' in enum '{}'", .{ | 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 | errdefer msg.destroy(sema.gpa); | 33319 | errdefer msg.destroy(sema.gpa); |
| 33231 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 33320 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -33317,7 +33406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33317,7 +33406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33317 | for (tag_info.names, 0..) |field_name, field_index| { | 33406 | for (tag_info.names, 0..) |field_name, field_index| { |
| 33318 | if (explicit_tags_seen[field_index]) continue; | 33407 | if (explicit_tags_seen[field_index]) continue; |
| 33319 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ | 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 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 33412 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -33345,14 +33434,22 @@ fn generateUnionTagTypeNumbered( | ... | @@ -33345,14 +33434,22 @@ fn generateUnionTagTypeNumbered( |
| 33345 | union_obj: *Module.Union, | 33434 | union_obj: *Module.Union, |
| 33346 | ) !Type { | 33435 | ) !Type { |
| 33347 | const mod = sema.mod; | 33436 | const mod = sema.mod; |
| | 33437 | const gpa = sema.gpa; |
| | 33438 | const ip = &mod.intern_pool; |
| 33348 | | 33439 | |
| 33349 | const src_decl = mod.declPtr(block.src_decl); | 33440 | const src_decl = mod.declPtr(block.src_decl); |
| 33350 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); | 33441 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33351 | errdefer mod.destroyDecl(new_decl_index); | 33442 | errdefer mod.destroyDecl(new_decl_index); |
| 33352 | const name = name: { | 33443 | const name = name: { |
| 33353 | const fqn = try union_obj.getFullyQualifiedName(mod); | 33444 | const prefix = "@typeInfo("; |
| 33354 | defer sema.gpa.free(fqn); | 33445 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 33355 | break :name try std.fmt.allocPrintZ(sema.gpa, "@typeInfo({s}).Union.tag_type.?", .{fqn}); | 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 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ | 33454 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33358 | .ty = Type.type, | 33455 | .ty = Type.type, |
| ... | @@ -33390,6 +33487,8 @@ fn generateUnionTagTypeSimple( | ... | @@ -33390,6 +33487,8 @@ fn generateUnionTagTypeSimple( |
| 33390 | maybe_union_obj: ?*Module.Union, | 33487 | maybe_union_obj: ?*Module.Union, |
| 33391 | ) !Type { | 33488 | ) !Type { |
| 33392 | const mod = sema.mod; | 33489 | const mod = sema.mod; |
| | 33490 | const gpa = sema.gpa; |
| | 33491 | const ip = &mod.intern_pool; |
| 33393 | | 33492 | |
| 33394 | const new_decl_index = new_decl_index: { | 33493 | const new_decl_index = new_decl_index: { |
| 33395 | const union_obj = maybe_union_obj orelse { | 33494 | const union_obj = maybe_union_obj orelse { |
| ... | @@ -33402,9 +33501,15 @@ fn generateUnionTagTypeSimple( | ... | @@ -33402,9 +33501,15 @@ fn generateUnionTagTypeSimple( |
| 33402 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); | 33501 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33403 | errdefer mod.destroyDecl(new_decl_index); | 33502 | errdefer mod.destroyDecl(new_decl_index); |
| 33404 | const name = name: { | 33503 | const name = name: { |
| 33405 | const fqn = try union_obj.getFullyQualifiedName(mod); | 33504 | const prefix = "@typeInfo("; |
| 33406 | defer sema.gpa.free(fqn); | 33505 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); |
| 33407 | break :name try std.fmt.allocPrintZ(sema.gpa, "@typeInfo({s}).Union.tag_type.?", .{fqn}); | 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 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ | 33514 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33410 | .ty = Type.type, | 33515 | .ty = Type.type, |
| ... | @@ -33436,7 +33541,9 @@ fn generateUnionTagTypeSimple( | ... | @@ -33436,7 +33541,9 @@ fn generateUnionTagTypeSimple( |
| 33436 | } | 33541 | } |
| 33437 | | 33542 | |
| 33438 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | 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 | defer wip_captures.deinit(); | 33547 | defer wip_captures.deinit(); |
| 33441 | | 33548 | |
| 33442 | var block: Block = .{ | 33549 | var block: Block = .{ |
| ... | @@ -33450,19 +33557,20 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | ... | @@ -33450,19 +33557,20 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 33450 | .is_comptime = true, | 33557 | .is_comptime = true, |
| 33451 | }; | 33558 | }; |
| 33452 | defer { | 33559 | defer { |
| 33453 | block.instructions.deinit(sema.gpa); | 33560 | block.instructions.deinit(gpa); |
| 33454 | block.params.deinit(sema.gpa); | 33561 | block.params.deinit(gpa); |
| 33455 | } | 33562 | } |
| 33456 | const src = LazySrcLoc.nodeOffset(0); | 33563 | const src = LazySrcLoc.nodeOffset(0); |
| 33457 | | 33564 | |
| 33458 | const mod = sema.mod; | 33565 | const mod = sema.mod; |
| | 33566 | const ip = &mod.intern_pool; |
| 33459 | const std_pkg = mod.main_pkg.table.get("std").?; | 33567 | const std_pkg = mod.main_pkg.table.get("std").?; |
| 33460 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; | 33568 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| 33461 | const opt_builtin_inst = (try sema.namespaceLookupRef( | 33569 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 33462 | &block, | 33570 | &block, |
| 33463 | src, | 33571 | src, |
| 33464 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, | 33572 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 33465 | "builtin", | 33573 | try ip.getOrPutString(gpa, "builtin"), |
| 33466 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); | 33574 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 33467 | const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src); | 33575 | const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src); |
| 33468 | const builtin_ty = sema.analyzeAsType(&block, src, builtin_inst) catch |err| switch (err) { | 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,7 +33581,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 33473 | &block, | 33581 | &block, |
| 33474 | src, | 33582 | src, |
| 33475 | builtin_ty.getNamespaceIndex(mod).unwrap().?, | 33583 | builtin_ty.getNamespaceIndex(mod).unwrap().?, |
| 33476 | name, | 33584 | try ip.getOrPutString(gpa, name), |
| 33477 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); | 33585 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 33478 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); | 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,7 +33716,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33608 | const field_vals = try sema.arena.alloc(InternPool.Index, s.fields.count()); | 33716 | const field_vals = try sema.arena.alloc(InternPool.Index, s.fields.count()); |
| 33609 | for (field_vals, s.fields.values(), 0..) |*field_val, field, i| { | 33717 | for (field_vals, s.fields.values(), 0..) |*field_val, field, i| { |
| 33610 | if (field.is_comptime) { | 33718 | if (field.is_comptime) { |
| 33611 | field_val.* = try field.default_val.intern(field.ty, mod); | 33719 | field_val.* = field.default_val; |
| 33612 | continue; | 33720 | continue; |
| 33613 | } | 33721 | } |
| 33614 | if (field.ty.eql(resolved_ty, sema.mod)) { | 33722 | if (field.ty.eql(resolved_ty, sema.mod)) { |
| ... | @@ -34287,7 +34395,7 @@ fn unionFieldIndex( | ... | @@ -34287,7 +34395,7 @@ fn unionFieldIndex( |
| 34287 | sema: *Sema, | 34395 | sema: *Sema, |
| 34288 | block: *Block, | 34396 | block: *Block, |
| 34289 | unresolved_union_ty: Type, | 34397 | unresolved_union_ty: Type, |
| 34290 | field_name: []const u8, | 34398 | field_name: InternPool.NullTerminatedString, |
| 34291 | field_src: LazySrcLoc, | 34399 | field_src: LazySrcLoc, |
| 34292 | ) !u32 { | 34400 | ) !u32 { |
| 34293 | const mod = sema.mod; | 34401 | const mod = sema.mod; |
| ... | @@ -34302,7 +34410,7 @@ fn structFieldIndex( | ... | @@ -34302,7 +34410,7 @@ fn structFieldIndex( |
| 34302 | sema: *Sema, | 34410 | sema: *Sema, |
| 34303 | block: *Block, | 34411 | block: *Block, |
| 34304 | unresolved_struct_ty: Type, | 34412 | unresolved_struct_ty: Type, |
| 34305 | field_name: []const u8, | 34413 | field_name: InternPool.NullTerminatedString, |
| 34306 | field_src: LazySrcLoc, | 34414 | field_src: LazySrcLoc, |
| 34307 | ) !u32 { | 34415 | ) !u32 { |
| 34308 | const mod = sema.mod; | 34416 | const mod = sema.mod; |
| ... | @@ -34321,19 +34429,17 @@ fn anonStructFieldIndex( | ... | @@ -34321,19 +34429,17 @@ fn anonStructFieldIndex( |
| 34321 | sema: *Sema, | 34429 | sema: *Sema, |
| 34322 | block: *Block, | 34430 | block: *Block, |
| 34323 | struct_ty: Type, | 34431 | struct_ty: Type, |
| 34324 | field_name: []const u8, | 34432 | field_name: InternPool.NullTerminatedString, |
| 34325 | field_src: LazySrcLoc, | 34433 | field_src: LazySrcLoc, |
| 34326 | ) !u32 { | 34434 | ) !u32 { |
| 34327 | const mod = sema.mod; | 34435 | const mod = sema.mod; |
| 34328 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { | 34436 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 34329 | .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| { | 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)) { | 34438 | if (name == field_name) return @intCast(u32, i); |
| 34331 | return @intCast(u32, i); | | |
| 34332 | } | | |
| 34333 | }, | 34439 | }, |
| 34334 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| { | 34440 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| { |
| 34335 | for (struct_obj.fields.keys(), 0..) |name, i| { | 34441 | for (struct_obj.fields.keys(), 0..) |name, i| { |
| 34336 | if (mem.eql(u8, name, field_name)) { | 34442 | if (name == field_name) { |
| 34337 | return @intCast(u32, i); | 34443 | return @intCast(u32, i); |
| 34338 | } | 34444 | } |
| 34339 | } | 34445 | } |
| ... | @@ -34341,7 +34447,7 @@ fn anonStructFieldIndex( | ... | @@ -34341,7 +34447,7 @@ fn anonStructFieldIndex( |
| 34341 | else => unreachable, | 34447 | else => unreachable, |
| 34342 | } | 34448 | } |
| 34343 | return sema.fail(block, field_src, "no field named '{s}' in anonymous struct '{}'", .{ | 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 | |