| ... | ... | @@ -195,7 +195,7 @@ pub const Block = struct { |
| 195 | 195 | try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{}); |
| 196 | 196 | }, |
| 197 | 197 | .comptime_ret_ty => |rt| { |
| 198 | | const src_loc = if (try sema.funcDeclSrc(rt.block, rt.func_src, rt.func)) |capture| blk: { |
| 198 | const src_loc = if (try sema.funcDeclSrc(rt.func)) |capture| blk: { |
| 199 | 199 | var src_loc = capture; |
| 200 | 200 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 201 | 201 | break :blk src_loc; |
| ... | ... | @@ -579,10 +579,9 @@ pub const Block = struct { |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | | pub fn startAnonDecl(block: *Block, src: LazySrcLoc) !WipAnonDecl { |
| 582 | pub fn startAnonDecl(block: *Block) !WipAnonDecl { |
| 583 | 583 | return WipAnonDecl{ |
| 584 | 584 | .block = block, |
| 585 | | .src = src, |
| 586 | 585 | .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa), |
| 587 | 586 | .finished = false, |
| 588 | 587 | }; |
| ... | ... | @@ -590,7 +589,6 @@ pub const Block = struct { |
| 590 | 589 | |
| 591 | 590 | pub const WipAnonDecl = struct { |
| 592 | 591 | block: *Block, |
| 593 | | src: LazySrcLoc, |
| 594 | 592 | new_decl_arena: std.heap.ArenaAllocator, |
| 595 | 593 | finished: bool, |
| 596 | 594 | |
| ... | ... | @@ -610,7 +608,7 @@ pub const Block = struct { |
| 610 | 608 | const sema = wad.block.sema; |
| 611 | 609 | // Do this ahead of time because `createAnonymousDecl` depends on calling |
| 612 | 610 | // `type.hasRuntimeBits()`. |
| 613 | | _ = try sema.typeHasRuntimeBits(wad.block, wad.src, ty); |
| 611 | _ = try sema.typeHasRuntimeBits(ty); |
| 614 | 612 | const new_decl_index = try sema.mod.createAnonymousDecl(wad.block, .{ |
| 615 | 613 | .ty = ty, |
| 616 | 614 | .val = val, |
| ... | ... | @@ -995,7 +993,7 @@ fn analyzeBodyInner( |
| 995 | 993 | .shl_exact => try sema.zirShl(block, inst, .shl_exact), |
| 996 | 994 | .shl_sat => try sema.zirShl(block, inst, .shl_sat), |
| 997 | 995 | |
| 998 | | .ret_ptr => try sema.zirRetPtr(block, inst), |
| 996 | .ret_ptr => try sema.zirRetPtr(block), |
| 999 | 997 | .ret_type => try sema.addType(sema.fn_ret_ty), |
| 1000 | 998 | |
| 1001 | 999 | // Instructions that we know to *always* be noreturn based solely on their tag. |
| ... | ... | @@ -1023,7 +1021,7 @@ fn analyzeBodyInner( |
| 1023 | 1021 | .this => try sema.zirThis( block, extended), |
| 1024 | 1022 | .ret_addr => try sema.zirRetAddr( block, extended), |
| 1025 | 1023 | .builtin_src => try sema.zirBuiltinSrc( block, extended), |
| 1026 | | .error_return_trace => try sema.zirErrorReturnTrace( block, extended), |
| 1024 | .error_return_trace => try sema.zirErrorReturnTrace( block), |
| 1027 | 1025 | .frame => try sema.zirFrame( block, extended), |
| 1028 | 1026 | .frame_address => try sema.zirFrameAddress( block, extended), |
| 1029 | 1027 | .alloc => try sema.zirAllocExtended( block, extended), |
| ... | ... | @@ -1031,7 +1029,7 @@ fn analyzeBodyInner( |
| 1031 | 1029 | .@"asm" => try sema.zirAsm( block, extended, false), |
| 1032 | 1030 | .asm_expr => try sema.zirAsm( block, extended, true), |
| 1033 | 1031 | .typeof_peer => try sema.zirTypeofPeer( block, extended), |
| 1034 | | .compile_log => try sema.zirCompileLog( block, extended), |
| 1032 | .compile_log => try sema.zirCompileLog( extended), |
| 1035 | 1033 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| 1036 | 1034 | .sub_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| 1037 | 1035 | .mul_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| ... | ... | @@ -1746,8 +1744,8 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 1746 | 1744 | const addrs_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, addr_arr_ty)); |
| 1747 | 1745 | |
| 1748 | 1746 | // var st: StackTrace = undefined; |
| 1749 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(&err_trace_block, src, "StackTrace"); |
| 1750 | | const stack_trace_ty = try sema.resolveTypeFields(&err_trace_block, src, unresolved_stack_trace_ty); |
| 1747 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 1748 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 1751 | 1749 | const st_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty)); |
| 1752 | 1750 | |
| 1753 | 1751 | // st.instruction_addresses = &addrs; |
| ... | ... | @@ -1774,7 +1772,7 @@ fn resolveValue( |
| 1774 | 1772 | air_ref: Air.Inst.Ref, |
| 1775 | 1773 | reason: []const u8, |
| 1776 | 1774 | ) CompileError!Value { |
| 1777 | | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { |
| 1775 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1778 | 1776 | if (val.tag() == .generic_poison) return error.GenericPoison; |
| 1779 | 1777 | return val; |
| 1780 | 1778 | } |
| ... | ... | @@ -1790,7 +1788,7 @@ fn resolveConstMaybeUndefVal( |
| 1790 | 1788 | inst: Air.Inst.Ref, |
| 1791 | 1789 | reason: []const u8, |
| 1792 | 1790 | ) CompileError!Value { |
| 1793 | | if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| { |
| 1791 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { |
| 1794 | 1792 | switch (val.tag()) { |
| 1795 | 1793 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1796 | 1794 | .generic_poison => return error.GenericPoison, |
| ... | ... | @@ -1809,7 +1807,7 @@ fn resolveConstValue( |
| 1809 | 1807 | air_ref: Air.Inst.Ref, |
| 1810 | 1808 | reason: []const u8, |
| 1811 | 1809 | ) CompileError!Value { |
| 1812 | | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { |
| 1810 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1813 | 1811 | switch (val.tag()) { |
| 1814 | 1812 | .undef => return sema.failWithUseOfUndef(block, src), |
| 1815 | 1813 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| ... | ... | @@ -1828,7 +1826,7 @@ fn resolveDefinedValue( |
| 1828 | 1826 | src: LazySrcLoc, |
| 1829 | 1827 | air_ref: Air.Inst.Ref, |
| 1830 | 1828 | ) CompileError!?Value { |
| 1831 | | if (try sema.resolveMaybeUndefVal(block, src, air_ref)) |val| { |
| 1829 | if (try sema.resolveMaybeUndefVal(air_ref)) |val| { |
| 1832 | 1830 | if (val.isUndef()) { |
| 1833 | 1831 | if (block.is_typeof) return null; |
| 1834 | 1832 | return sema.failWithUseOfUndef(block, src); |
| ... | ... | @@ -1843,11 +1841,9 @@ fn resolveDefinedValue( |
| 1843 | 1841 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 1844 | 1842 | fn resolveMaybeUndefVal( |
| 1845 | 1843 | sema: *Sema, |
| 1846 | | block: *Block, |
| 1847 | | src: LazySrcLoc, |
| 1848 | 1844 | inst: Air.Inst.Ref, |
| 1849 | 1845 | ) CompileError!?Value { |
| 1850 | | const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) orelse return null; |
| 1846 | const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null; |
| 1851 | 1847 | switch (val.tag()) { |
| 1852 | 1848 | .variable => return null, |
| 1853 | 1849 | .generic_poison => return error.GenericPoison, |
| ... | ... | @@ -1861,11 +1857,9 @@ fn resolveMaybeUndefVal( |
| 1861 | 1857 | /// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`. |
| 1862 | 1858 | fn resolveMaybeUndefValIntable( |
| 1863 | 1859 | sema: *Sema, |
| 1864 | | block: *Block, |
| 1865 | | src: LazySrcLoc, |
| 1866 | 1860 | inst: Air.Inst.Ref, |
| 1867 | 1861 | ) CompileError!?Value { |
| 1868 | | const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) orelse return null; |
| 1862 | const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null; |
| 1869 | 1863 | var check = val; |
| 1870 | 1864 | while (true) switch (check.tag()) { |
| 1871 | 1865 | .variable, .decl_ref, .decl_ref_mut, .comptime_field_ptr => return null, |
| ... | ... | @@ -1874,21 +1868,16 @@ fn resolveMaybeUndefValIntable( |
| 1874 | 1868 | .eu_payload_ptr, .opt_payload_ptr => check = check.cast(Value.Payload.PayloadPtr).?.data.container_ptr, |
| 1875 | 1869 | .generic_poison => return error.GenericPoison, |
| 1876 | 1870 | else => { |
| 1877 | | try sema.resolveLazyValue(block, src, val); |
| 1871 | try sema.resolveLazyValue(val); |
| 1878 | 1872 | return val; |
| 1879 | 1873 | }, |
| 1880 | 1874 | }; |
| 1881 | 1875 | } |
| 1882 | 1876 | |
| 1883 | 1877 | /// Returns all Value tags including `variable` and `undef`. |
| 1884 | | fn resolveMaybeUndefValAllowVariables( |
| 1885 | | sema: *Sema, |
| 1886 | | block: *Block, |
| 1887 | | src: LazySrcLoc, |
| 1888 | | inst: Air.Inst.Ref, |
| 1889 | | ) CompileError!?Value { |
| 1878 | fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 1890 | 1879 | var make_runtime = false; |
| 1891 | | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, src, inst, &make_runtime)) |val| { |
| 1880 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(inst, &make_runtime)) |val| { |
| 1892 | 1881 | if (make_runtime) return null; |
| 1893 | 1882 | return val; |
| 1894 | 1883 | } |
| ... | ... | @@ -1898,8 +1887,6 @@ fn resolveMaybeUndefValAllowVariables( |
| 1898 | 1887 | /// Returns all Value tags including `variable`, `undef` and `runtime_value`. |
| 1899 | 1888 | fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 1900 | 1889 | sema: *Sema, |
| 1901 | | block: *Block, |
| 1902 | | src: LazySrcLoc, |
| 1903 | 1890 | inst: Air.Inst.Ref, |
| 1904 | 1891 | make_runtime: *bool, |
| 1905 | 1892 | ) CompileError!?Value { |
| ... | ... | @@ -1910,7 +1897,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 1910 | 1897 | } |
| 1911 | 1898 | i -= Air.Inst.Ref.typed_value_map.len; |
| 1912 | 1899 | |
| 1913 | | if (try sema.typeHasOnePossibleValue(block, src, sema.typeOf(inst))) |opv| { |
| 1900 | if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| { |
| 1914 | 1901 | return opv; |
| 1915 | 1902 | } |
| 1916 | 1903 | const air_tags = sema.air_instructions.items(.tag); |
| ... | ... | @@ -2209,7 +2196,7 @@ pub fn resolveAlign( |
| 2209 | 2196 | zir_ref: Zir.Inst.Ref, |
| 2210 | 2197 | ) !u32 { |
| 2211 | 2198 | const air_ref = try sema.resolveInst(zir_ref); |
| 2212 | | return analyzeAsAlign(sema, block, src, air_ref); |
| 2199 | return sema.analyzeAsAlign(block, src, air_ref); |
| 2213 | 2200 | } |
| 2214 | 2201 | |
| 2215 | 2202 | fn resolveInt( |
| ... | ... | @@ -2221,7 +2208,7 @@ fn resolveInt( |
| 2221 | 2208 | reason: []const u8, |
| 2222 | 2209 | ) !u64 { |
| 2223 | 2210 | const air_ref = try sema.resolveInst(zir_ref); |
| 2224 | | return analyzeAsInt(sema, block, src, air_ref, dest_ty, reason); |
| 2211 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); |
| 2225 | 2212 | } |
| 2226 | 2213 | |
| 2227 | 2214 | fn analyzeAsInt( |
| ... | ... | @@ -2235,7 +2222,7 @@ fn analyzeAsInt( |
| 2235 | 2222 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| 2236 | 2223 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 2237 | 2224 | const target = sema.mod.getTarget(); |
| 2238 | | return (try val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?; |
| 2225 | return (try val.getUnsignedIntAdvanced(target, sema)).?; |
| 2239 | 2226 | } |
| 2240 | 2227 | |
| 2241 | 2228 | // Returns a compile error if the value has tag `variable`. See `resolveInstValue` for |
| ... | ... | @@ -2317,7 +2304,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2317 | 2304 | const iac = ptr_val.castTag(.inferred_alloc_comptime).?; |
| 2318 | 2305 | // There will be only one coerce_result_ptr because we are running at comptime. |
| 2319 | 2306 | // The alloc will turn into a Decl. |
| 2320 | | var anon_decl = try block.startAnonDecl(src); |
| 2307 | var anon_decl = try block.startAnonDecl(); |
| 2321 | 2308 | defer anon_decl.deinit(); |
| 2322 | 2309 | iac.data.decl_index = try anon_decl.finish( |
| 2323 | 2310 | try pointee_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -2325,7 +2312,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2325 | 2312 | iac.data.alignment, |
| 2326 | 2313 | ); |
| 2327 | 2314 | if (iac.data.alignment != 0) { |
| 2328 | | try sema.resolveTypeLayout(block, src, pointee_ty); |
| 2315 | try sema.resolveTypeLayout(pointee_ty); |
| 2329 | 2316 | } |
| 2330 | 2317 | const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 2331 | 2318 | .pointee_type = pointee_ty, |
| ... | ... | @@ -2355,7 +2342,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2355 | 2342 | |
| 2356 | 2343 | const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr)); |
| 2357 | 2344 | const dummy_operand = try trash_block.addBitCast(pointee_ty, .void_value); |
| 2358 | | return coerceResultPtr(sema, block, src, ptr, dummy_ptr, dummy_operand, &trash_block); |
| 2345 | return sema.coerceResultPtr(block, src, ptr, dummy_ptr, dummy_operand, &trash_block); |
| 2359 | 2346 | } |
| 2360 | 2347 | |
| 2361 | 2348 | fn coerceResultPtr( |
| ... | ... | @@ -2386,7 +2373,7 @@ fn coerceResultPtr( |
| 2386 | 2373 | const trash_inst = trash_block.instructions.items[trash_block.instructions.items.len - 1]; |
| 2387 | 2374 | if (air_tags[trash_inst] != .store) { |
| 2388 | 2375 | // no store instruction is generated for zero sized types |
| 2389 | | assert((try sema.typeHasOnePossibleValue(block, src, pointee_ty)) != null); |
| 2376 | assert((try sema.typeHasOnePossibleValue(pointee_ty)) != null); |
| 2390 | 2377 | } else { |
| 2391 | 2378 | trash_block.instructions.items.len -= 1; |
| 2392 | 2379 | assert(trash_inst == sema.air_instructions.len - 1); |
| ... | ... | @@ -2876,7 +2863,7 @@ fn zirEnumDecl( |
| 2876 | 2863 | } |
| 2877 | 2864 | } else if (any_values) { |
| 2878 | 2865 | const tag_val = if (last_tag_val) |val| |
| 2879 | | try sema.intAdd(block, src, val, Value.one, enum_obj.tag_ty) |
| 2866 | try sema.intAdd(val, Value.one, enum_obj.tag_ty) |
| 2880 | 2867 | else |
| 2881 | 2868 | Value.zero; |
| 2882 | 2869 | last_tag_val = tag_val; |
| ... | ... | @@ -2905,7 +2892,7 @@ fn zirEnumDecl( |
| 2905 | 2892 | last_tag_val = Value.initPayload(&tag_val_buf.base); |
| 2906 | 2893 | } |
| 2907 | 2894 | |
| 2908 | | if (!(try sema.intFitsInType(block, src, last_tag_val.?, enum_obj.tag_ty, null))) { |
| 2895 | if (!(try sema.intFitsInType(last_tag_val.?, enum_obj.tag_ty, null))) { |
| 2909 | 2896 | const tree = try sema.getAstTree(block); |
| 2910 | 2897 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2911 | 2898 | const msg = try sema.errMsg(block, field_src, "enumeration value '{}' too large for type '{}'", .{ |
| ... | ... | @@ -3113,16 +3100,13 @@ fn zirErrorSetDecl( |
| 3113 | 3100 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| 3114 | 3101 | } |
| 3115 | 3102 | |
| 3116 | | fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3103 | fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 3117 | 3104 | const tracy = trace(@src()); |
| 3118 | 3105 | defer tracy.end(); |
| 3119 | 3106 | |
| 3120 | | const inst_data = sema.code.instructions.items(.data)[inst].node; |
| 3121 | | const src = LazySrcLoc.nodeOffset(inst_data); |
| 3122 | | |
| 3123 | 3107 | if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) { |
| 3124 | | const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty); |
| 3125 | | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); |
| 3108 | const fn_ret_ty = try sema.resolveTypeFields(sema.fn_ret_ty); |
| 3109 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0); |
| 3126 | 3110 | } |
| 3127 | 3111 | |
| 3128 | 3112 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -3287,7 +3271,6 @@ fn zirAllocExtended( |
| 3287 | 3271 | extended: Zir.Inst.Extended.InstData, |
| 3288 | 3272 | ) CompileError!Air.Inst.Ref { |
| 3289 | 3273 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 3290 | | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 3291 | 3274 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; |
| 3292 | 3275 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; |
| 3293 | 3276 | const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small); |
| ... | ... | @@ -3314,7 +3297,7 @@ fn zirAllocExtended( |
| 3314 | 3297 | |
| 3315 | 3298 | if (block.is_comptime or small.is_comptime) { |
| 3316 | 3299 | if (small.has_type) { |
| 3317 | | return sema.analyzeComptimeAlloc(block, var_ty, alignment, ty_src); |
| 3300 | return sema.analyzeComptimeAlloc(block, var_ty, alignment); |
| 3318 | 3301 | } else { |
| 3319 | 3302 | return sema.addConstant( |
| 3320 | 3303 | inferred_alloc_ty, |
| ... | ... | @@ -3331,7 +3314,7 @@ fn zirAllocExtended( |
| 3331 | 3314 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 3332 | 3315 | } |
| 3333 | 3316 | const target = sema.mod.getTarget(); |
| 3334 | | try sema.resolveTypeLayout(block, src, var_ty); |
| 3317 | try sema.resolveTypeLayout(var_ty); |
| 3335 | 3318 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 3336 | 3319 | .pointee_type = var_ty, |
| 3337 | 3320 | .@"align" = alignment, |
| ... | ... | @@ -3360,12 +3343,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3360 | 3343 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3361 | 3344 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3362 | 3345 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3363 | | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); |
| 3346 | return sema.analyzeComptimeAlloc(block, var_ty, 0); |
| 3364 | 3347 | } |
| 3365 | 3348 | |
| 3366 | 3349 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3367 | 3350 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3368 | | const src = inst_data.src(); |
| 3369 | 3351 | const alloc = try sema.resolveInst(inst_data.operand); |
| 3370 | 3352 | const alloc_ty = sema.typeOf(alloc); |
| 3371 | 3353 | |
| ... | ... | @@ -3406,13 +3388,13 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3406 | 3388 | } |
| 3407 | 3389 | |
| 3408 | 3390 | const store_op = air_datas[store_inst].bin_op; |
| 3409 | | const store_val = (try sema.resolveMaybeUndefVal(block, src, store_op.rhs)) orelse break :ct; |
| 3391 | const store_val = (try sema.resolveMaybeUndefVal(store_op.rhs)) orelse break :ct; |
| 3410 | 3392 | if (store_op.lhs != alloc) break :ct; |
| 3411 | 3393 | |
| 3412 | 3394 | // Remove all the unnecessary runtime instructions. |
| 3413 | 3395 | block.instructions.shrinkRetainingCapacity(search_index); |
| 3414 | 3396 | |
| 3415 | | var anon_decl = try block.startAnonDecl(src); |
| 3397 | var anon_decl = try block.startAnonDecl(); |
| 3416 | 3398 | defer anon_decl.deinit(); |
| 3417 | 3399 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 3418 | 3400 | try elem_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -3425,7 +3407,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3425 | 3407 | const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 3426 | 3408 | |
| 3427 | 3409 | // Detect if a comptime value simply needs to have its type changed. |
| 3428 | | if (try sema.resolveMaybeUndefVal(block, inst_data.src(), alloc)) |val| { |
| 3410 | if (try sema.resolveMaybeUndefVal(alloc)) |val| { |
| 3429 | 3411 | return sema.addConstant(const_ptr_ty, val); |
| 3430 | 3412 | } |
| 3431 | 3413 | |
| ... | ... | @@ -3457,7 +3439,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3457 | 3439 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3458 | 3440 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3459 | 3441 | if (block.is_comptime) { |
| 3460 | | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); |
| 3442 | return sema.analyzeComptimeAlloc(block, var_ty, 0); |
| 3461 | 3443 | } |
| 3462 | 3444 | const target = sema.mod.getTarget(); |
| 3463 | 3445 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | ... | @@ -3476,7 +3458,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 3476 | 3458 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3477 | 3459 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3478 | 3460 | if (block.is_comptime) { |
| 3479 | | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); |
| 3461 | return sema.analyzeComptimeAlloc(block, var_ty, 0); |
| 3480 | 3462 | } |
| 3481 | 3463 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 3482 | 3464 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -3641,12 +3623,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3641 | 3623 | } else unreachable; // TODO shouldn't need this |
| 3642 | 3624 | |
| 3643 | 3625 | const store_op = air_datas[store_inst].bin_op; |
| 3644 | | const store_val = (try sema.resolveMaybeUndefVal(block, src, store_op.rhs)) orelse break :ct; |
| 3626 | const store_val = (try sema.resolveMaybeUndefVal(store_op.rhs)) orelse break :ct; |
| 3645 | 3627 | if (store_op.lhs != Air.indexToRef(bitcast_inst)) break :ct; |
| 3646 | 3628 | if (air_datas[bitcast_inst].ty_op.operand != Air.indexToRef(const_inst)) break :ct; |
| 3647 | 3629 | |
| 3648 | 3630 | const new_decl_index = d: { |
| 3649 | | var anon_decl = try block.startAnonDecl(src); |
| 3631 | var anon_decl = try block.startAnonDecl(); |
| 3650 | 3632 | defer anon_decl.deinit(); |
| 3651 | 3633 | const new_decl_index = try anon_decl.finish( |
| 3652 | 3634 | try final_elem_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -3668,7 +3650,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3668 | 3650 | // Unless the block is comptime, `alloc_inferred` always produces |
| 3669 | 3651 | // a runtime constant. The final inferred type needs to be |
| 3670 | 3652 | // fully resolved so it can be lowered in codegen. |
| 3671 | | try sema.resolveTypeFully(block, ty_src, final_elem_ty); |
| 3653 | try sema.resolveTypeFully(final_elem_ty); |
| 3672 | 3654 | |
| 3673 | 3655 | return; |
| 3674 | 3656 | } |
| ... | ... | @@ -3714,7 +3696,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3714 | 3696 | defer bitcast_block.instructions.deinit(gpa); |
| 3715 | 3697 | |
| 3716 | 3698 | trash_block.instructions.shrinkRetainingCapacity(empty_trash_count); |
| 3717 | | const sub_ptr = try coerceResultPtr(sema, &bitcast_block, src, ptr, dummy_ptr, peer_inst_list[i], &trash_block); |
| 3699 | const sub_ptr = try sema.coerceResultPtr(&bitcast_block, src, ptr, dummy_ptr, peer_inst_list[i], &trash_block); |
| 3718 | 3700 | |
| 3719 | 3701 | assert(bitcast_block.instructions.items.len > 0); |
| 3720 | 3702 | // If only one instruction is produced then we can replace the bitcast |
| ... | ... | @@ -3997,7 +3979,7 @@ fn validateUnionInit( |
| 3997 | 3979 | } else { |
| 3998 | 3980 | first_block_index = @min(first_block_index, block_index); |
| 3999 | 3981 | } |
| 4000 | | init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, init_src, bin_op.rhs, &make_runtime); |
| 3982 | init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime); |
| 4001 | 3983 | break; |
| 4002 | 3984 | } |
| 4003 | 3985 | |
| ... | ... | @@ -4073,7 +4055,7 @@ fn validateStructInit( |
| 4073 | 4055 | if ((is_comptime or block.is_comptime) and |
| 4074 | 4056 | (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null) |
| 4075 | 4057 | { |
| 4076 | | try sema.resolveStructLayout(block, init_src, struct_ty); |
| 4058 | try sema.resolveStructLayout(struct_ty); |
| 4077 | 4059 | // In this case the only thing we need to do is evaluate the implicit |
| 4078 | 4060 | // store instructions for default field values, and report any missing fields. |
| 4079 | 4061 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. |
| ... | ... | @@ -4143,12 +4125,9 @@ fn validateStructInit( |
| 4143 | 4125 | |
| 4144 | 4126 | field: for (found_fields) |field_ptr, i| { |
| 4145 | 4127 | if (field_ptr != 0) { |
| 4146 | | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| 4147 | | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4148 | | |
| 4149 | 4128 | // Determine whether the value stored to this pointer is comptime-known. |
| 4150 | 4129 | const field_ty = struct_ty.structFieldType(i); |
| 4151 | | if (try sema.typeHasOnePossibleValue(block, field_src, field_ty)) |opv| { |
| 4130 | if (try sema.typeHasOnePossibleValue(field_ty)) |opv| { |
| 4152 | 4131 | field_values[i] = opv; |
| 4153 | 4132 | continue; |
| 4154 | 4133 | } |
| ... | ... | @@ -4210,7 +4189,7 @@ fn validateStructInit( |
| 4210 | 4189 | } else { |
| 4211 | 4190 | first_block_index = @min(first_block_index, block_index); |
| 4212 | 4191 | } |
| 4213 | | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, field_src, bin_op.rhs, &make_runtime)) |val| { |
| 4192 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4214 | 4193 | field_values[i] = val; |
| 4215 | 4194 | } else { |
| 4216 | 4195 | struct_is_comptime = false; |
| ... | ... | @@ -4271,7 +4250,7 @@ fn validateStructInit( |
| 4271 | 4250 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); |
| 4272 | 4251 | return; |
| 4273 | 4252 | } |
| 4274 | | try sema.resolveStructLayout(block, init_src, struct_ty); |
| 4253 | try sema.resolveStructLayout(struct_ty); |
| 4275 | 4254 | |
| 4276 | 4255 | // Our task is to insert `store` instructions for all the default field values. |
| 4277 | 4256 | for (found_fields) |field_ptr, i| { |
| ... | ... | @@ -4352,14 +4331,11 @@ fn zirValidateArrayInit( |
| 4352 | 4331 | // being comptime-known. |
| 4353 | 4332 | const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel()); |
| 4354 | 4333 | const element_vals = try sema.arena.alloc(Value, array_len_s); |
| 4355 | | const opt_opv = try sema.typeHasOnePossibleValue(block, init_src, array_ty); |
| 4334 | const opt_opv = try sema.typeHasOnePossibleValue(array_ty); |
| 4356 | 4335 | const air_tags = sema.air_instructions.items(.tag); |
| 4357 | 4336 | const air_datas = sema.air_instructions.items(.data); |
| 4358 | 4337 | |
| 4359 | 4338 | outer: for (instrs) |elem_ptr, i| { |
| 4360 | | const elem_ptr_data = sema.code.instructions.items(.data)[elem_ptr].pl_node; |
| 4361 | | const elem_src = LazySrcLoc.nodeOffset(elem_ptr_data.src_node); |
| 4362 | | |
| 4363 | 4339 | // Determine whether the value stored to this pointer is comptime-known. |
| 4364 | 4340 | |
| 4365 | 4341 | if (array_ty.isTuple()) { |
| ... | ... | @@ -4427,7 +4403,7 @@ fn zirValidateArrayInit( |
| 4427 | 4403 | } else { |
| 4428 | 4404 | first_block_index = @min(first_block_index, block_index); |
| 4429 | 4405 | } |
| 4430 | | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, elem_src, bin_op.rhs, &make_runtime)) |val| { |
| 4406 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4431 | 4407 | element_vals[i] = val; |
| 4432 | 4408 | } else { |
| 4433 | 4409 | array_is_comptime = false; |
| ... | ... | @@ -4465,7 +4441,6 @@ fn zirValidateArrayInit( |
| 4465 | 4441 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4466 | 4442 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4467 | 4443 | const src = inst_data.src(); |
| 4468 | | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 4469 | 4444 | const operand = try sema.resolveInst(inst_data.operand); |
| 4470 | 4445 | const operand_ty = sema.typeOf(operand); |
| 4471 | 4446 | |
| ... | ... | @@ -4478,11 +4453,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4478 | 4453 | } |
| 4479 | 4454 | |
| 4480 | 4455 | const elem_ty = operand_ty.elemType2(); |
| 4481 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 4456 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 4482 | 4457 | if (val.isUndef()) { |
| 4483 | 4458 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 4484 | 4459 | } |
| 4485 | | } else if (!(try sema.validateRunTimeType(block, src, elem_ty, false))) { |
| 4460 | } else if (!(try sema.validateRunTimeType(elem_ty, false))) { |
| 4486 | 4461 | const msg = msg: { |
| 4487 | 4462 | const msg = try sema.errMsg( |
| 4488 | 4463 | block, |
| ... | ... | @@ -4689,9 +4664,9 @@ fn storeToInferredAllocComptime( |
| 4689 | 4664 | const operand_ty = sema.typeOf(operand); |
| 4690 | 4665 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 4691 | 4666 | // The alloc will turn into a Decl. |
| 4692 | | if (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) |operand_val| store: { |
| 4667 | if (try sema.resolveMaybeUndefValAllowVariables(operand)) |operand_val| store: { |
| 4693 | 4668 | if (operand_val.tag() == .variable) break :store; |
| 4694 | | var anon_decl = try block.startAnonDecl(src); |
| 4669 | var anon_decl = try block.startAnonDecl(); |
| 4695 | 4670 | defer anon_decl.deinit(); |
| 4696 | 4671 | iac.data.decl_index = try anon_decl.finish( |
| 4697 | 4672 | try operand_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -4788,7 +4763,7 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air |
| 4788 | 4763 | gop.value_ptr.* = .none; |
| 4789 | 4764 | } |
| 4790 | 4765 | const decl_index = gop.value_ptr.unwrap() orelse di: { |
| 4791 | | var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded); |
| 4766 | var anon_decl = try block.startAnonDecl(); |
| 4792 | 4767 | defer anon_decl.deinit(); |
| 4793 | 4768 | |
| 4794 | 4769 | const decl_index = try anon_decl.finish( |
| ... | ... | @@ -4869,7 +4844,6 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 4869 | 4844 | |
| 4870 | 4845 | fn zirCompileLog( |
| 4871 | 4846 | sema: *Sema, |
| 4872 | | block: *Block, |
| 4873 | 4847 | extended: Zir.Inst.Extended.InstData, |
| 4874 | 4848 | ) CompileError!Air.Inst.Ref { |
| 4875 | 4849 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); |
| ... | ... | @@ -4878,7 +4852,6 @@ fn zirCompileLog( |
| 4878 | 4852 | |
| 4879 | 4853 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 4880 | 4854 | const src_node = extra.data.src_node; |
| 4881 | | const src = LazySrcLoc.nodeOffset(src_node); |
| 4882 | 4855 | const args = sema.code.refSlice(extra.end, extended.small); |
| 4883 | 4856 | |
| 4884 | 4857 | for (args) |arg_ref, i| { |
| ... | ... | @@ -4886,8 +4859,8 @@ fn zirCompileLog( |
| 4886 | 4859 | |
| 4887 | 4860 | const arg = try sema.resolveInst(arg_ref); |
| 4888 | 4861 | const arg_ty = sema.typeOf(arg); |
| 4889 | | if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| { |
| 4890 | | try sema.resolveLazyValue(block, src, val); |
| 4862 | if (try sema.resolveMaybeUndefVal(arg)) |val| { |
| 4863 | try sema.resolveLazyValue(val); |
| 4891 | 4864 | try writer.print("@as({}, {})", .{ |
| 4892 | 4865 | arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod), |
| 4893 | 4866 | }); |
| ... | ... | @@ -5207,7 +5180,7 @@ fn analyzeBlockBody( |
| 5207 | 5180 | // TODO add note "missing else causes void value" |
| 5208 | 5181 | |
| 5209 | 5182 | const type_src = src; // TODO: better source location |
| 5210 | | const valid_rt = try sema.validateRunTimeType(child_block, type_src, resolved_ty, false); |
| 5183 | const valid_rt = try sema.validateRunTimeType(resolved_ty, false); |
| 5211 | 5184 | if (!valid_rt) { |
| 5212 | 5185 | const msg = msg: { |
| 5213 | 5186 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); |
| ... | ... | @@ -5352,7 +5325,7 @@ pub fn analyzeExport( |
| 5352 | 5325 | try mod.ensureDeclAnalyzed(exported_decl_index); |
| 5353 | 5326 | const exported_decl = mod.declPtr(exported_decl_index); |
| 5354 | 5327 | |
| 5355 | | if (!try sema.validateExternType(block, src, exported_decl.ty, .other)) { |
| 5328 | if (!try sema.validateExternType(exported_decl.ty, .other)) { |
| 5356 | 5329 | const msg = msg: { |
| 5357 | 5330 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)}); |
| 5358 | 5331 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -5581,10 +5554,10 @@ fn addDbgVar( |
| 5581 | 5554 | const operand_ty = sema.typeOf(operand); |
| 5582 | 5555 | switch (air_tag) { |
| 5583 | 5556 | .dbg_var_ptr => { |
| 5584 | | if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty.childType()))) return; |
| 5557 | if (!(try sema.typeHasRuntimeBits(operand_ty.childType()))) return; |
| 5585 | 5558 | }, |
| 5586 | 5559 | .dbg_var_val => { |
| 5587 | | if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return; |
| 5560 | if (!(try sema.typeHasRuntimeBits(operand_ty))) return; |
| 5588 | 5561 | }, |
| 5589 | 5562 | else => unreachable, |
| 5590 | 5563 | } |
| ... | ... | @@ -5746,8 +5719,8 @@ fn lookupInNamespace( |
| 5746 | 5719 | return null; |
| 5747 | 5720 | } |
| 5748 | 5721 | |
| 5749 | | fn funcDeclSrc(sema: *Sema, block: *Block, src: LazySrcLoc, func_inst: Air.Inst.Ref) !?Module.SrcLoc { |
| 5750 | | const func_val = (try sema.resolveMaybeUndefVal(block, src, func_inst)) orelse return null; |
| 5722 | fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?Module.SrcLoc { |
| 5723 | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; |
| 5751 | 5724 | if (func_val.isUndef()) return null; |
| 5752 | 5725 | const owner_decl_index = switch (func_val.tag()) { |
| 5753 | 5726 | .extern_fn => func_val.castTag(.extern_fn).?.data.owner_decl, |
| ... | ... | @@ -5769,11 +5742,11 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 5769 | 5742 | if (block.is_comptime) |
| 5770 | 5743 | return .none; |
| 5771 | 5744 | |
| 5772 | | const unresolved_stack_trace_ty = sema.getBuiltinType(block, src, "StackTrace") catch |err| switch (err) { |
| 5745 | const unresolved_stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) { |
| 5773 | 5746 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 5774 | 5747 | else => |e| return e, |
| 5775 | 5748 | }; |
| 5776 | | const stack_trace_ty = sema.resolveTypeFields(block, src, unresolved_stack_trace_ty) catch |err| switch (err) { |
| 5749 | const stack_trace_ty = sema.resolveTypeFields(unresolved_stack_trace_ty) catch |err| switch (err) { |
| 5777 | 5750 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 5778 | 5751 | else => |e| return e, |
| 5779 | 5752 | }; |
| ... | ... | @@ -5812,8 +5785,8 @@ fn popErrorReturnTrace( |
| 5812 | 5785 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or |
| 5813 | 5786 | // the result is comptime-known to be a non-error. Either way, pop unconditionally. |
| 5814 | 5787 | |
| 5815 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 5816 | | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 5788 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 5789 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 5817 | 5790 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 5818 | 5791 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 5819 | 5792 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, "index", src, stack_trace_ty, true); |
| ... | ... | @@ -5837,8 +5810,8 @@ fn popErrorReturnTrace( |
| 5837 | 5810 | defer then_block.instructions.deinit(sema.gpa); |
| 5838 | 5811 | |
| 5839 | 5812 | // If non-error, then pop the error return trace by restoring the index. |
| 5840 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 5841 | | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 5813 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 5814 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 5842 | 5815 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 5843 | 5816 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 5844 | 5817 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, "index", src, stack_trace_ty, true); |
| ... | ... | @@ -5934,7 +5907,7 @@ fn zirCall( |
| 5934 | 5907 | break :check_args; |
| 5935 | 5908 | } |
| 5936 | 5909 | |
| 5937 | | const decl_src = try sema.funcDeclSrc(block, func_src, func); |
| 5910 | const decl_src = try sema.funcDeclSrc(func); |
| 5938 | 5911 | const member_str = if (bound_arg_src != null) "member function " else ""; |
| 5939 | 5912 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 5940 | 5913 | const msg = msg: { |
| ... | ... | @@ -6017,8 +5990,8 @@ fn zirCall( |
| 6017 | 5990 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only |
| 6018 | 5991 | // need to clean-up our own trace if we were passed to a non-error-handling expression. |
| 6019 | 5992 | if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError())) { |
| 6020 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, call_src, "StackTrace"); |
| 6021 | | const stack_trace_ty = try sema.resolveTypeFields(block, call_src, unresolved_stack_trace_ty); |
| 5993 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 5994 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6022 | 5995 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, "index", call_src); |
| 6023 | 5996 | |
| 6024 | 5997 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| ... | ... | @@ -6145,7 +6118,7 @@ fn analyzeCall( |
| 6145 | 6118 | const func_ty_info = func_ty.fnInfo(); |
| 6146 | 6119 | const cc = func_ty_info.cc; |
| 6147 | 6120 | if (cc == .Naked) { |
| 6148 | | const decl_src = try sema.funcDeclSrc(block, func_src, func); |
| 6121 | const decl_src = try sema.funcDeclSrc(func); |
| 6149 | 6122 | const msg = msg: { |
| 6150 | 6123 | const msg = try sema.errMsg( |
| 6151 | 6124 | block, |
| ... | ... | @@ -6677,7 +6650,7 @@ fn analyzeInlineCallArg( |
| 6677 | 6650 | // Needed so that lazy values do not trigger |
| 6678 | 6651 | // assertion due to type not being resolved |
| 6679 | 6652 | // when the hash function is called. |
| 6680 | | try sema.resolveLazyValue(arg_block, arg_src, arg_val); |
| 6653 | try sema.resolveLazyValue(arg_val); |
| 6681 | 6654 | }, |
| 6682 | 6655 | } |
| 6683 | 6656 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | ... | @@ -6687,7 +6660,7 @@ fn analyzeInlineCallArg( |
| 6687 | 6660 | }; |
| 6688 | 6661 | } else if (zir_tags[inst] == .param_comptime or try sema.typeRequiresComptime(param_ty)) { |
| 6689 | 6662 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| 6690 | | } else if (try sema.resolveMaybeUndefVal(arg_block, arg_src, casted_arg)) |val| { |
| 6663 | } else if (try sema.resolveMaybeUndefVal(casted_arg)) |val| { |
| 6691 | 6664 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6692 | 6665 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); |
| 6693 | 6666 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); |
| ... | ... | @@ -6719,7 +6692,7 @@ fn analyzeInlineCallArg( |
| 6719 | 6692 | // Needed so that lazy values do not trigger |
| 6720 | 6693 | // assertion due to type not being resolved |
| 6721 | 6694 | // when the hash function is called. |
| 6722 | | try sema.resolveLazyValue(arg_block, arg_src, arg_val); |
| 6695 | try sema.resolveLazyValue(arg_val); |
| 6723 | 6696 | }, |
| 6724 | 6697 | } |
| 6725 | 6698 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | ... | @@ -6729,7 +6702,7 @@ fn analyzeInlineCallArg( |
| 6729 | 6702 | }; |
| 6730 | 6703 | } else if (zir_tags[inst] == .param_anytype_comptime or try sema.typeRequiresComptime(param_ty)) { |
| 6731 | 6704 | try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg); |
| 6732 | | } else if (try sema.resolveMaybeUndefVal(arg_block, arg_src, uncasted_arg)) |val| { |
| 6705 | } else if (try sema.resolveMaybeUndefVal(uncasted_arg)) |val| { |
| 6733 | 6706 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6734 | 6707 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); |
| 6735 | 6708 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); |
| ... | ... | @@ -6750,7 +6723,7 @@ fn analyzeCallArg( |
| 6750 | 6723 | param_ty: Type, |
| 6751 | 6724 | uncasted_arg: Air.Inst.Ref, |
| 6752 | 6725 | ) !Air.Inst.Ref { |
| 6753 | | try sema.resolveTypeFully(block, arg_src, param_ty); |
| 6726 | try sema.resolveTypeFully(param_ty); |
| 6754 | 6727 | return sema.coerce(block, param_ty, uncasted_arg, arg_src); |
| 6755 | 6728 | } |
| 6756 | 6729 | |
| ... | ... | @@ -6773,14 +6746,14 @@ fn analyzeGenericCallArg( |
| 6773 | 6746 | try sema.queueFullTypeResolution(param_ty); |
| 6774 | 6747 | runtime_args[runtime_i.*] = casted_arg; |
| 6775 | 6748 | runtime_i.* += 1; |
| 6776 | | } else if (try sema.typeHasOnePossibleValue(block, arg_src, comptime_arg.ty)) |_| { |
| 6749 | } else if (try sema.typeHasOnePossibleValue(comptime_arg.ty)) |_| { |
| 6777 | 6750 | _ = try sema.coerce(block, comptime_arg.ty, uncasted_arg, arg_src); |
| 6778 | 6751 | } |
| 6779 | 6752 | } |
| 6780 | 6753 | |
| 6781 | 6754 | fn analyzeGenericCallArgVal(sema: *Sema, block: *Block, arg_src: LazySrcLoc, uncasted_arg: Air.Inst.Ref) !Value { |
| 6782 | 6755 | const arg_val = try sema.resolveValue(block, arg_src, uncasted_arg, "parameter is comptime"); |
| 6783 | | try sema.resolveLazyValue(block, arg_src, arg_val); |
| 6756 | try sema.resolveLazyValue(arg_val); |
| 6784 | 6757 | return arg_val; |
| 6785 | 6758 | } |
| 6786 | 6759 | |
| ... | ... | @@ -7032,7 +7005,7 @@ fn instantiateGenericCall( |
| 7032 | 7005 | } |
| 7033 | 7006 | const arg = uncasted_args[arg_i]; |
| 7034 | 7007 | if (is_comptime) { |
| 7035 | | if (try sema.resolveMaybeUndefVal(block, .unneeded, arg)) |arg_val| { |
| 7008 | if (try sema.resolveMaybeUndefVal(arg)) |arg_val| { |
| 7036 | 7009 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); |
| 7037 | 7010 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 7038 | 7011 | } else { |
| ... | ... | @@ -7105,11 +7078,7 @@ fn instantiateGenericCall( |
| 7105 | 7078 | } |
| 7106 | 7079 | |
| 7107 | 7080 | if (is_comptime) { |
| 7108 | | const arg_val = (child_sema.resolveMaybeUndefValAllowVariables( |
| 7109 | | &child_block, |
| 7110 | | .unneeded, |
| 7111 | | arg, |
| 7112 | | ) catch unreachable).?; |
| 7081 | const arg_val = (child_sema.resolveMaybeUndefValAllowVariables(arg) catch unreachable).?; |
| 7113 | 7082 | child_sema.comptime_args[arg_i] = .{ |
| 7114 | 7083 | .ty = copied_arg_ty, |
| 7115 | 7084 | .val = try arg_val.copy(new_decl_arena_allocator), |
| ... | ... | @@ -7240,7 +7209,7 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 7240 | 7209 | for (tuple.values) |field_val, i| { |
| 7241 | 7210 | try sema.resolveTupleLazyValues(block, src, tuple.types[i]); |
| 7242 | 7211 | if (field_val.tag() == .unreachable_value) continue; |
| 7243 | | try sema.resolveLazyValue(block, src, field_val); |
| 7212 | try sema.resolveLazyValue(field_val); |
| 7244 | 7213 | } |
| 7245 | 7214 | } |
| 7246 | 7215 | |
| ... | ... | @@ -7429,7 +7398,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 7429 | 7398 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 7430 | 7399 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 7431 | 7400 | |
| 7432 | | if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| { |
| 7401 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 7433 | 7402 | if (val.isUndef()) { |
| 7434 | 7403 | return sema.addConstUndef(Type.err_int); |
| 7435 | 7404 | } |
| ... | ... | @@ -7601,11 +7570,11 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7601 | 7570 | var int_tag_type_buffer: Type.Payload.Bits = undefined; |
| 7602 | 7571 | const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena); |
| 7603 | 7572 | |
| 7604 | | if (try sema.typeHasOnePossibleValue(block, src, enum_tag_ty)) |opv| { |
| 7573 | if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| { |
| 7605 | 7574 | return sema.addConstant(int_tag_ty, opv); |
| 7606 | 7575 | } |
| 7607 | 7576 | |
| 7608 | | if (try sema.resolveMaybeUndefVal(block, operand_src, enum_tag)) |enum_tag_val| { |
| 7577 | if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| { |
| 7609 | 7578 | var buffer: Value.Payload.U64 = undefined; |
| 7610 | 7579 | const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer); |
| 7611 | 7580 | return sema.addConstant(int_tag_ty, try val.copy(sema.arena)); |
| ... | ... | @@ -7629,14 +7598,14 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7629 | 7598 | } |
| 7630 | 7599 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); |
| 7631 | 7600 | |
| 7632 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { |
| 7601 | if (try sema.resolveMaybeUndefVal(operand)) |int_val| { |
| 7633 | 7602 | if (dest_ty.isNonexhaustiveEnum()) { |
| 7634 | 7603 | return sema.addConstant(dest_ty, int_val); |
| 7635 | 7604 | } |
| 7636 | 7605 | if (int_val.isUndef()) { |
| 7637 | 7606 | return sema.failWithUseOfUndef(block, operand_src); |
| 7638 | 7607 | } |
| 7639 | | if (!(try sema.enumHasInt(block, src, dest_ty, int_val))) { |
| 7608 | if (!(try sema.enumHasInt(dest_ty, int_val))) { |
| 7640 | 7609 | const msg = msg: { |
| 7641 | 7610 | const msg = try sema.errMsg( |
| 7642 | 7611 | block, |
| ... | ... | @@ -7653,7 +7622,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7653 | 7622 | return sema.addConstant(dest_ty, int_val); |
| 7654 | 7623 | } |
| 7655 | 7624 | |
| 7656 | | if (try sema.typeHasOnePossibleValue(block, operand_src, dest_ty)) |opv| { |
| 7625 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { |
| 7657 | 7626 | const result = try sema.addConstant(dest_ty, opv); |
| 7658 | 7627 | // The operand is runtime-known but the result is comptime-known. In |
| 7659 | 7628 | // this case we still need a safety check. |
| ... | ... | @@ -8355,7 +8324,7 @@ fn funcCommon( |
| 8355 | 8324 | }; |
| 8356 | 8325 | return sema.failWithOwnedErrorMsg(msg); |
| 8357 | 8326 | } |
| 8358 | | if (!Type.fnCallingConventionAllowsZigTypes(cc_workaround) and !try sema.validateExternType(block, ret_ty_src, return_type, .ret_ty)) { |
| 8327 | if (!Type.fnCallingConventionAllowsZigTypes(cc_workaround) and !try sema.validateExternType(return_type, .ret_ty)) { |
| 8359 | 8328 | const msg = msg: { |
| 8360 | 8329 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ |
| 8361 | 8330 | return_type.fmt(sema.mod), @tagName(cc_workaround), |
| ... | ... | @@ -8459,8 +8428,8 @@ fn funcCommon( |
| 8459 | 8428 | if (!is_generic and sema.wantErrorReturnTracing(return_type)) { |
| 8460 | 8429 | // Make sure that StackTrace's fields are resolved so that the backend can |
| 8461 | 8430 | // lower this fn type. |
| 8462 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, ret_ty_src, "StackTrace"); |
| 8463 | | _ = try sema.resolveTypeFields(block, ret_ty_src, unresolved_stack_trace_ty); |
| 8431 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 8432 | _ = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 8464 | 8433 | } |
| 8465 | 8434 | |
| 8466 | 8435 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ |
| ... | ... | @@ -8583,7 +8552,7 @@ fn analyzeParameter( |
| 8583 | 8552 | }; |
| 8584 | 8553 | return sema.failWithOwnedErrorMsg(msg); |
| 8585 | 8554 | } |
| 8586 | | if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) { |
| 8555 | if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(param.ty, .param_ty)) { |
| 8587 | 8556 | const msg = msg: { |
| 8588 | 8557 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ |
| 8589 | 8558 | param.ty.fmt(sema.mod), @tagName(cc), |
| ... | ... | @@ -8693,7 +8662,7 @@ fn zirParam( |
| 8693 | 8662 | } |
| 8694 | 8663 | |
| 8695 | 8664 | if (sema.preallocated_new_func != null) { |
| 8696 | | if (try sema.typeHasOnePossibleValue(block, src, param_ty)) |opv| { |
| 8665 | if (try sema.typeHasOnePossibleValue(param_ty)) |opv| { |
| 8697 | 8666 | // In this case we are instantiating a generic function call with a non-comptime |
| 8698 | 8667 | // non-anytype parameter that ended up being a one-possible-type. |
| 8699 | 8668 | // We don't want the parameter to be part of the instantiated function type. |
| ... | ... | @@ -8733,7 +8702,6 @@ fn zirParamAnytype( |
| 8733 | 8702 | comptime_syntax: bool, |
| 8734 | 8703 | ) CompileError!void { |
| 8735 | 8704 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 8736 | | const src = inst_data.src(); |
| 8737 | 8705 | const param_name = inst_data.get(sema.code); |
| 8738 | 8706 | |
| 8739 | 8707 | if (sema.inst_map.get(inst)) |air_ref| { |
| ... | ... | @@ -8743,7 +8711,7 @@ fn zirParamAnytype( |
| 8743 | 8711 | // function type of the function instruction in this block. |
| 8744 | 8712 | return; |
| 8745 | 8713 | } |
| 8746 | | if (null != try sema.typeHasOnePossibleValue(block, src, param_ty)) { |
| 8714 | if (null != try sema.typeHasOnePossibleValue(param_ty)) { |
| 8747 | 8715 | return; |
| 8748 | 8716 | } |
| 8749 | 8717 | // The map is already populated but we do need to add a runtime parameter. |
| ... | ... | @@ -8829,7 +8797,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8829 | 8797 | if (!ptr_ty.isPtrAtRuntime()) { |
| 8830 | 8798 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}); |
| 8831 | 8799 | } |
| 8832 | | if (try sema.resolveMaybeUndefValIntable(block, ptr_src, ptr)) |ptr_val| { |
| 8800 | if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| { |
| 8833 | 8801 | return sema.addConstant(Type.usize, ptr_val); |
| 8834 | 8802 | } |
| 8835 | 8803 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| ... | ... | @@ -8942,7 +8910,7 @@ fn intCast( |
| 8942 | 8910 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src); |
| 8943 | 8911 | const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); |
| 8944 | 8912 | |
| 8945 | | if (try sema.isComptimeKnown(block, operand_src, operand)) { |
| 8913 | if (try sema.isComptimeKnown(operand)) { |
| 8946 | 8914 | return sema.coerce(block, dest_ty, operand, operand_src); |
| 8947 | 8915 | } else if (dest_scalar_ty.zigTypeTag() == .ComptimeInt) { |
| 8948 | 8916 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{}); |
| ... | ... | @@ -8951,7 +8919,7 @@ fn intCast( |
| 8951 | 8919 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src); |
| 8952 | 8920 | const is_vector = dest_ty.zigTypeTag() == .Vector; |
| 8953 | 8921 | |
| 8954 | | if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| { |
| 8922 | if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| { |
| 8955 | 8923 | // requirement: intCast(u0, input) iff input == 0 |
| 8956 | 8924 | if (runtime_safety and block.wantSafety()) { |
| 8957 | 8925 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | ... | @@ -9012,7 +8980,7 @@ fn intCast( |
| 9012 | 8980 | // range to account for negative values. |
| 9013 | 8981 | const dest_range_val = if (wanted_info.signedness == .signed) range_val: { |
| 9014 | 8982 | const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, target); |
| 9015 | | break :range_val try sema.intAdd(block, operand_src, range_minus_one, Value.one, unsigned_operand_ty); |
| 8983 | break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty); |
| 9016 | 8984 | } else dest_max_val; |
| 9017 | 8985 | const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val); |
| 9018 | 8986 | |
| ... | ... | @@ -9254,7 +9222,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9254 | 9222 | ), |
| 9255 | 9223 | } |
| 9256 | 9224 | |
| 9257 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| { |
| 9225 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 9258 | 9226 | return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target)); |
| 9259 | 9227 | } |
| 9260 | 9228 | if (dest_is_comptime_float) { |
| ... | ... | @@ -9415,7 +9383,7 @@ fn zirSwitchCapture( |
| 9415 | 9383 | return block.addStructFieldVal(operand_ptr, field_index, field_ty); |
| 9416 | 9384 | } |
| 9417 | 9385 | } else if (is_ref) { |
| 9418 | | return sema.addConstantMaybeRef(block, operand_src, operand_ty, item_val, true); |
| 9386 | return sema.addConstantMaybeRef(block, operand_ty, item_val, true); |
| 9419 | 9387 | } else { |
| 9420 | 9388 | return block.inline_case_capture; |
| 9421 | 9389 | } |
| ... | ... | @@ -9616,14 +9584,14 @@ fn zirSwitchCond( |
| 9616 | 9584 | if (operand_ty.isSlice()) { |
| 9617 | 9585 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}); |
| 9618 | 9586 | } |
| 9619 | | if ((try sema.typeHasOnePossibleValue(block, operand_src, operand_ty))) |opv| { |
| 9587 | if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| { |
| 9620 | 9588 | return sema.addConstant(operand_ty, opv); |
| 9621 | 9589 | } |
| 9622 | 9590 | return operand; |
| 9623 | 9591 | }, |
| 9624 | 9592 | |
| 9625 | 9593 | .Union => { |
| 9626 | | const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty); |
| 9594 | const union_ty = try sema.resolveTypeFields(operand_ty); |
| 9627 | 9595 | const enum_ty = union_ty.unionTagType() orelse { |
| 9628 | 9596 | const msg = msg: { |
| 9629 | 9597 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); |
| ... | ... | @@ -10336,8 +10304,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10336 | 10304 | // Validation above ensured these will succeed. |
| 10337 | 10305 | const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, "") catch unreachable; |
| 10338 | 10306 | const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last, "") catch unreachable; |
| 10339 | | if ((try sema.compareAll(block, src, operand_val, .gte, first_tv.val, operand_ty)) and |
| 10340 | | (try sema.compareAll(block, src, operand_val, .lte, last_tv.val, operand_ty))) |
| 10307 | if ((try sema.compareAll(operand_val, .gte, first_tv.val, operand_ty)) and |
| 10308 | (try sema.compareAll(operand_val, .lte, last_tv.val, operand_ty))) |
| 10341 | 10309 | { |
| 10342 | 10310 | if (is_inline) child_block.inline_case_capture = operand; |
| 10343 | 10311 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| ... | ... | @@ -10487,7 +10455,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10487 | 10455 | |
| 10488 | 10456 | while (item.compareAll(.lte, item_last, operand_ty, sema.mod)) : ({ |
| 10489 | 10457 | // Previous validation has resolved any possible lazy values. |
| 10490 | | item = try sema.intAddScalar(block, .unneeded, item, Value.one); |
| 10458 | item = try sema.intAddScalar(item, Value.one); |
| 10491 | 10459 | }) { |
| 10492 | 10460 | cases_len += 1; |
| 10493 | 10461 | |
| ... | ... | @@ -10766,7 +10734,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10766 | 10734 | } |
| 10767 | 10735 | }, |
| 10768 | 10736 | .Int => { |
| 10769 | | var it = try RangeSetUnhandledIterator.init(sema, block, special_prong_src, operand_ty, range_set); |
| 10737 | var it = try RangeSetUnhandledIterator.init(sema, operand_ty, range_set); |
| 10770 | 10738 | while (try it.next()) |cur| { |
| 10771 | 10739 | cases_len += 1; |
| 10772 | 10740 | |
| ... | ... | @@ -10909,8 +10877,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10909 | 10877 | |
| 10910 | 10878 | const RangeSetUnhandledIterator = struct { |
| 10911 | 10879 | sema: *Sema, |
| 10912 | | block: *Block, |
| 10913 | | src: LazySrcLoc, |
| 10914 | 10880 | ty: Type, |
| 10915 | 10881 | cur: Value, |
| 10916 | 10882 | max: Value, |
| ... | ... | @@ -10918,15 +10884,13 @@ const RangeSetUnhandledIterator = struct { |
| 10918 | 10884 | range_i: usize = 0, |
| 10919 | 10885 | first: bool = true, |
| 10920 | 10886 | |
| 10921 | | fn init(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator { |
| 10887 | fn init(sema: *Sema, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator { |
| 10922 | 10888 | const target = sema.mod.getTarget(); |
| 10923 | 10889 | const min = try ty.minInt(sema.arena, target); |
| 10924 | 10890 | const max = try ty.maxInt(sema.arena, target); |
| 10925 | 10891 | |
| 10926 | 10892 | return RangeSetUnhandledIterator{ |
| 10927 | 10893 | .sema = sema, |
| 10928 | | .block = block, |
| 10929 | | .src = src, |
| 10930 | 10894 | .ty = ty, |
| 10931 | 10895 | .cur = min, |
| 10932 | 10896 | .max = max, |
| ... | ... | @@ -10937,7 +10901,7 @@ const RangeSetUnhandledIterator = struct { |
| 10937 | 10901 | fn next(it: *RangeSetUnhandledIterator) !?Value { |
| 10938 | 10902 | while (it.range_i < it.ranges.len) : (it.range_i += 1) { |
| 10939 | 10903 | if (!it.first) { |
| 10940 | | it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty); |
| 10904 | it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty); |
| 10941 | 10905 | } |
| 10942 | 10906 | it.first = false; |
| 10943 | 10907 | if (it.cur.compareAll(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) { |
| ... | ... | @@ -10946,7 +10910,7 @@ const RangeSetUnhandledIterator = struct { |
| 10946 | 10910 | it.cur = it.ranges[it.range_i].last; |
| 10947 | 10911 | } |
| 10948 | 10912 | if (!it.first) { |
| 10949 | | it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty); |
| 10913 | it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty); |
| 10950 | 10914 | } |
| 10951 | 10915 | it.first = false; |
| 10952 | 10916 | if (it.cur.compareAll(.lte, it.max, it.ty, it.sema.mod)) { |
| ... | ... | @@ -11199,8 +11163,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11199 | 11163 | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; |
| 11200 | 11164 | const src = inst_data.src(); |
| 11201 | 11165 | |
| 11202 | | const panic_fn = try sema.getBuiltin(block, src, "panicUnwrapError"); |
| 11203 | | const err_return_trace = try sema.getErrorReturnTrace(block, src); |
| 11166 | const panic_fn = try sema.getBuiltin("panicUnwrapError"); |
| 11167 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11204 | 11168 | const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; |
| 11205 | 11169 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11206 | 11170 | return true; |
| ... | ... | @@ -11210,8 +11174,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11210 | 11174 | const src = inst_data.src(); |
| 11211 | 11175 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 11212 | 11176 | |
| 11213 | | const panic_fn = try sema.getBuiltin(block, src, "panic"); |
| 11214 | | const err_return_trace = try sema.getErrorReturnTrace(block, src); |
| 11177 | const panic_fn = try sema.getBuiltin("panic"); |
| 11178 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11215 | 11179 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; |
| 11216 | 11180 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11217 | 11181 | return true; |
| ... | ... | @@ -11272,7 +11236,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 11272 | 11236 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 11273 | 11237 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 11274 | 11238 | const field_name = try sema.resolveConstString(block, name_src, extra.rhs, "field name must be comptime-known"); |
| 11275 | | const ty = try sema.resolveTypeFields(block, ty_src, unresolved_ty); |
| 11239 | const ty = try sema.resolveTypeFields(unresolved_ty); |
| 11276 | 11240 | |
| 11277 | 11241 | const has_field = hf: { |
| 11278 | 11242 | if (ty.isSlice()) { |
| ... | ... | @@ -11315,7 +11279,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11315 | 11279 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 11316 | 11280 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "decl name must be comptime-known"); |
| 11317 | 11281 | |
| 11318 | | try checkNamespaceType(sema, block, lhs_src, container_type); |
| 11282 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 11319 | 11283 | |
| 11320 | 11284 | const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false; |
| 11321 | 11285 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| ... | ... | @@ -11390,7 +11354,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 11390 | 11354 | }, |
| 11391 | 11355 | }; |
| 11392 | 11356 | |
| 11393 | | var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded); |
| 11357 | var anon_decl = try block.startAnonDecl(); |
| 11394 | 11358 | defer anon_decl.deinit(); |
| 11395 | 11359 | |
| 11396 | 11360 | const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1]; |
| ... | ... | @@ -11451,15 +11415,15 @@ fn zirShl( |
| 11451 | 11415 | // TODO coerce rhs if air_tag is not shl_sat |
| 11452 | 11416 | const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty); |
| 11453 | 11417 | |
| 11454 | | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); |
| 11455 | | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); |
| 11418 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 11419 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 11456 | 11420 | |
| 11457 | 11421 | if (maybe_rhs_val) |rhs_val| { |
| 11458 | 11422 | if (rhs_val.isUndef()) { |
| 11459 | 11423 | return sema.addConstUndef(sema.typeOf(lhs)); |
| 11460 | 11424 | } |
| 11461 | 11425 | // If rhs is 0, return lhs without doing any calculations. |
| 11462 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 11426 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 11463 | 11427 | return lhs; |
| 11464 | 11428 | } |
| 11465 | 11429 | if (scalar_ty.zigTypeTag() != .ComptimeInt and air_tag != .shl_sat) { |
| ... | ... | @@ -11620,15 +11584,15 @@ fn zirShr( |
| 11620 | 11584 | const target = sema.mod.getTarget(); |
| 11621 | 11585 | const scalar_ty = lhs_ty.scalarType(); |
| 11622 | 11586 | |
| 11623 | | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); |
| 11624 | | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); |
| 11587 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 11588 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 11625 | 11589 | |
| 11626 | 11590 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { |
| 11627 | 11591 | if (rhs_val.isUndef()) { |
| 11628 | 11592 | return sema.addConstUndef(lhs_ty); |
| 11629 | 11593 | } |
| 11630 | 11594 | // If rhs is 0, return lhs without doing any calculations. |
| 11631 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 11595 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 11632 | 11596 | return lhs; |
| 11633 | 11597 | } |
| 11634 | 11598 | if (scalar_ty.zigTypeTag() != .ComptimeInt) { |
| ... | ... | @@ -11662,7 +11626,7 @@ fn zirShr( |
| 11662 | 11626 | if (air_tag == .shr_exact) { |
| 11663 | 11627 | // Detect if any ones would be shifted out. |
| 11664 | 11628 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target); |
| 11665 | | if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 11629 | if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) { |
| 11666 | 11630 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); |
| 11667 | 11631 | } |
| 11668 | 11632 | } |
| ... | ... | @@ -11759,8 +11723,8 @@ fn zirBitwise( |
| 11759 | 11723 | const runtime_src = runtime: { |
| 11760 | 11724 | // TODO: ask the linker what kind of relocations are available, and |
| 11761 | 11725 | // in some cases emit a Value that means "this decl's address AND'd with this operand". |
| 11762 | | if (try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs)) |lhs_val| { |
| 11763 | | if (try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs)) |rhs_val| { |
| 11726 | if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| { |
| 11727 | if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| { |
| 11764 | 11728 | const result_val = switch (air_tag) { |
| 11765 | 11729 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target), |
| 11766 | 11730 | .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target), |
| ... | ... | @@ -11799,7 +11763,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 11799 | 11763 | }); |
| 11800 | 11764 | } |
| 11801 | 11765 | |
| 11802 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 11766 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 11803 | 11767 | if (val.isUndef()) { |
| 11804 | 11768 | return sema.addConstUndef(operand_type); |
| 11805 | 11769 | } else if (operand_type.zigTypeTag() == .Vector) { |
| ... | ... | @@ -11946,7 +11910,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 11946 | 11910 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 11947 | 11911 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); |
| 11948 | 11912 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); |
| 11949 | | if (try sema.valuesEqual(block, src, lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| 11913 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| 11950 | 11914 | break :s lhs_sent_casted_val; |
| 11951 | 11915 | } else { |
| 11952 | 11916 | break :s null; |
| ... | ... | @@ -12019,7 +11983,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12019 | 11983 | element_vals[result_len] = sent_val; |
| 12020 | 11984 | } |
| 12021 | 11985 | const val = try Value.Tag.aggregate.create(sema.arena, element_vals); |
| 12022 | | return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null); |
| 11986 | return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null); |
| 12023 | 11987 | } else break :rs rhs_src; |
| 12024 | 11988 | } else lhs_src; |
| 12025 | 11989 | |
| ... | ... | @@ -12238,7 +12202,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12238 | 12202 | } |
| 12239 | 12203 | break :v try Value.Tag.aggregate.create(sema.arena, element_vals); |
| 12240 | 12204 | }; |
| 12241 | | return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null); |
| 12205 | return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null); |
| 12242 | 12206 | } |
| 12243 | 12207 | |
| 12244 | 12208 | try sema.requireRuntimeBlock(block, src, lhs_src); |
| ... | ... | @@ -12310,7 +12274,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12310 | 12274 | |
| 12311 | 12275 | if (rhs_scalar_ty.isAnyFloat()) { |
| 12312 | 12276 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 12313 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| 12277 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 12314 | 12278 | if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty); |
| 12315 | 12279 | const target = sema.mod.getTarget(); |
| 12316 | 12280 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target)); |
| ... | ... | @@ -12406,8 +12370,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12406 | 12370 | |
| 12407 | 12371 | const mod = sema.mod; |
| 12408 | 12372 | const target = mod.getTarget(); |
| 12409 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 12410 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 12373 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12374 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12411 | 12375 | |
| 12412 | 12376 | if ((lhs_ty.zigTypeTag() == .ComptimeFloat and rhs_ty.zigTypeTag() == .ComptimeInt) or |
| 12413 | 12377 | (lhs_ty.zigTypeTag() == .ComptimeInt and rhs_ty.zigTypeTag() == .ComptimeFloat)) |
| ... | ... | @@ -12455,7 +12419,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12455 | 12419 | .Int, .ComptimeInt, .ComptimeFloat => { |
| 12456 | 12420 | if (maybe_lhs_val) |lhs_val| { |
| 12457 | 12421 | if (!lhs_val.isUndef()) { |
| 12458 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 12422 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 12459 | 12423 | const zero_val = if (is_vector) b: { |
| 12460 | 12424 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12461 | 12425 | } else Value.zero; |
| ... | ... | @@ -12467,7 +12431,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12467 | 12431 | if (rhs_val.isUndef()) { |
| 12468 | 12432 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12469 | 12433 | } |
| 12470 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 12434 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 12471 | 12435 | return sema.failWithDivideByZero(block, rhs_src); |
| 12472 | 12436 | } |
| 12473 | 12437 | // TODO: if the RHS is one, return the LHS directly |
| ... | ... | @@ -12481,7 +12445,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12481 | 12445 | if (lhs_val.isUndef()) { |
| 12482 | 12446 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12483 | 12447 | if (maybe_rhs_val) |rhs_val| { |
| 12484 | | if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12448 | if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12485 | 12449 | return sema.addConstUndef(resolved_type); |
| 12486 | 12450 | } |
| 12487 | 12451 | } |
| ... | ... | @@ -12494,7 +12458,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12494 | 12458 | if (is_int) { |
| 12495 | 12459 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12496 | 12460 | var vector_index: usize = undefined; |
| 12497 | | if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) { |
| 12461 | if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) { |
| 12498 | 12462 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12499 | 12463 | } |
| 12500 | 12464 | return sema.addConstant(resolved_type, res); |
| ... | ... | @@ -12566,8 +12530,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12566 | 12530 | |
| 12567 | 12531 | const mod = sema.mod; |
| 12568 | 12532 | const target = mod.getTarget(); |
| 12569 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 12570 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 12533 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12534 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12571 | 12535 | |
| 12572 | 12536 | const runtime_src = rs: { |
| 12573 | 12537 | // For integers: |
| ... | ... | @@ -12590,7 +12554,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12590 | 12554 | if (lhs_val.isUndef()) { |
| 12591 | 12555 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12592 | 12556 | } else { |
| 12593 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 12557 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 12594 | 12558 | const zero_val = if (is_vector) b: { |
| 12595 | 12559 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12596 | 12560 | } else Value.zero; |
| ... | ... | @@ -12602,7 +12566,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12602 | 12566 | if (rhs_val.isUndef()) { |
| 12603 | 12567 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12604 | 12568 | } |
| 12605 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 12569 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 12606 | 12570 | return sema.failWithDivideByZero(block, rhs_src); |
| 12607 | 12571 | } |
| 12608 | 12572 | // TODO: if the RHS is one, return the LHS directly |
| ... | ... | @@ -12616,7 +12580,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12616 | 12580 | } |
| 12617 | 12581 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12618 | 12582 | var vector_index: usize = undefined; |
| 12619 | | if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) { |
| 12583 | if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) { |
| 12620 | 12584 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12621 | 12585 | } |
| 12622 | 12586 | return sema.addConstant(resolved_type, res); |
| ... | ... | @@ -12731,8 +12695,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12731 | 12695 | |
| 12732 | 12696 | const mod = sema.mod; |
| 12733 | 12697 | const target = mod.getTarget(); |
| 12734 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 12735 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 12698 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12699 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12736 | 12700 | |
| 12737 | 12701 | const runtime_src = rs: { |
| 12738 | 12702 | // For integers: |
| ... | ... | @@ -12756,7 +12720,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12756 | 12720 | // If the lhs is undefined, result is undefined. |
| 12757 | 12721 | if (maybe_lhs_val) |lhs_val| { |
| 12758 | 12722 | if (!lhs_val.isUndef()) { |
| 12759 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 12723 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 12760 | 12724 | const zero_val = if (is_vector) b: { |
| 12761 | 12725 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12762 | 12726 | } else Value.zero; |
| ... | ... | @@ -12768,7 +12732,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12768 | 12732 | if (rhs_val.isUndef()) { |
| 12769 | 12733 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12770 | 12734 | } |
| 12771 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 12735 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 12772 | 12736 | return sema.failWithDivideByZero(block, rhs_src); |
| 12773 | 12737 | } |
| 12774 | 12738 | // TODO: if the RHS is one, return the LHS directly |
| ... | ... | @@ -12777,7 +12741,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12777 | 12741 | if (lhs_val.isUndef()) { |
| 12778 | 12742 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12779 | 12743 | if (maybe_rhs_val) |rhs_val| { |
| 12780 | | if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12744 | if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12781 | 12745 | return sema.addConstUndef(resolved_type); |
| 12782 | 12746 | } |
| 12783 | 12747 | } |
| ... | ... | @@ -12848,8 +12812,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12848 | 12812 | |
| 12849 | 12813 | const mod = sema.mod; |
| 12850 | 12814 | const target = mod.getTarget(); |
| 12851 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 12852 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 12815 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12816 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12853 | 12817 | |
| 12854 | 12818 | const runtime_src = rs: { |
| 12855 | 12819 | // For integers: |
| ... | ... | @@ -12873,7 +12837,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12873 | 12837 | // If the lhs is undefined, result is undefined. |
| 12874 | 12838 | if (maybe_lhs_val) |lhs_val| { |
| 12875 | 12839 | if (!lhs_val.isUndef()) { |
| 12876 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 12840 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 12877 | 12841 | const zero_val = if (is_vector) b: { |
| 12878 | 12842 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12879 | 12843 | } else Value.zero; |
| ... | ... | @@ -12885,7 +12849,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12885 | 12849 | if (rhs_val.isUndef()) { |
| 12886 | 12850 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12887 | 12851 | } |
| 12888 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 12852 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 12889 | 12853 | return sema.failWithDivideByZero(block, rhs_src); |
| 12890 | 12854 | } |
| 12891 | 12855 | } |
| ... | ... | @@ -12893,7 +12857,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12893 | 12857 | if (lhs_val.isUndef()) { |
| 12894 | 12858 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12895 | 12859 | if (maybe_rhs_val) |rhs_val| { |
| 12896 | | if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12860 | if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) { |
| 12897 | 12861 | return sema.addConstUndef(resolved_type); |
| 12898 | 12862 | } |
| 12899 | 12863 | } |
| ... | ... | @@ -12906,7 +12870,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12906 | 12870 | if (is_int) { |
| 12907 | 12871 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12908 | 12872 | var vector_index: usize = undefined; |
| 12909 | | if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) { |
| 12873 | if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) { |
| 12910 | 12874 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12911 | 12875 | } |
| 12912 | 12876 | return sema.addConstant(resolved_type, res); |
| ... | ... | @@ -13092,8 +13056,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13092 | 13056 | |
| 13093 | 13057 | const mod = sema.mod; |
| 13094 | 13058 | const target = mod.getTarget(); |
| 13095 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 13096 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 13059 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13060 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13097 | 13061 | |
| 13098 | 13062 | const runtime_src = rs: { |
| 13099 | 13063 | // For integers: |
| ... | ... | @@ -13114,7 +13078,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13114 | 13078 | if (lhs_val.isUndef()) { |
| 13115 | 13079 | return sema.failWithUseOfUndef(block, lhs_src); |
| 13116 | 13080 | } |
| 13117 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13081 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13118 | 13082 | const zero_val = if (is_vector) b: { |
| 13119 | 13083 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13120 | 13084 | } else Value.zero; |
| ... | ... | @@ -13127,18 +13091,18 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13127 | 13091 | if (rhs_val.isUndef()) { |
| 13128 | 13092 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13129 | 13093 | } |
| 13130 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13094 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13131 | 13095 | return sema.failWithDivideByZero(block, rhs_src); |
| 13132 | 13096 | } |
| 13133 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) { |
| 13097 | if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema))) { |
| 13134 | 13098 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); |
| 13135 | 13099 | } |
| 13136 | 13100 | if (maybe_lhs_val) |lhs_val| { |
| 13137 | | const rem_result = try sema.intRem(block, resolved_type, lhs_val, lhs_src, rhs_val, rhs_src); |
| 13101 | const rem_result = try sema.intRem(resolved_type, lhs_val, rhs_val); |
| 13138 | 13102 | // If this answer could possibly be different by doing `intMod`, |
| 13139 | 13103 | // we must emit a compile error. Otherwise, it's OK. |
| 13140 | | if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src))) and |
| 13141 | | !(try rem_result.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) |
| 13104 | if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema)) and |
| 13105 | !(try rem_result.compareAllWithZeroAdvanced(.eq, sema))) |
| 13142 | 13106 | { |
| 13143 | 13107 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 13144 | 13108 | } |
| ... | ... | @@ -13156,14 +13120,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13156 | 13120 | if (rhs_val.isUndef()) { |
| 13157 | 13121 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13158 | 13122 | } |
| 13159 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13123 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13160 | 13124 | return sema.failWithDivideByZero(block, rhs_src); |
| 13161 | 13125 | } |
| 13162 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) { |
| 13126 | if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema))) { |
| 13163 | 13127 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); |
| 13164 | 13128 | } |
| 13165 | 13129 | if (maybe_lhs_val) |lhs_val| { |
| 13166 | | if (lhs_val.isUndef() or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) { |
| 13130 | if (lhs_val.isUndef() or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema))) { |
| 13167 | 13131 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 13168 | 13132 | } |
| 13169 | 13133 | return sema.addConstant( |
| ... | ... | @@ -13190,38 +13154,32 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13190 | 13154 | |
| 13191 | 13155 | fn intRem( |
| 13192 | 13156 | sema: *Sema, |
| 13193 | | block: *Block, |
| 13194 | 13157 | ty: Type, |
| 13195 | 13158 | lhs: Value, |
| 13196 | | lhs_src: LazySrcLoc, |
| 13197 | 13159 | rhs: Value, |
| 13198 | | rhs_src: LazySrcLoc, |
| 13199 | 13160 | ) CompileError!Value { |
| 13200 | 13161 | if (ty.zigTypeTag() == .Vector) { |
| 13201 | 13162 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 13202 | 13163 | for (result_data) |*scalar, i| { |
| 13203 | | scalar.* = try sema.intRemScalar(block, lhs.indexVectorlike(i), lhs_src, rhs.indexVectorlike(i), rhs_src); |
| 13164 | scalar.* = try sema.intRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i)); |
| 13204 | 13165 | } |
| 13205 | 13166 | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 13206 | 13167 | } |
| 13207 | | return sema.intRemScalar(block, lhs, lhs_src, rhs, rhs_src); |
| 13168 | return sema.intRemScalar(lhs, rhs); |
| 13208 | 13169 | } |
| 13209 | 13170 | |
| 13210 | 13171 | fn intRemScalar( |
| 13211 | 13172 | sema: *Sema, |
| 13212 | | block: *Block, |
| 13213 | 13173 | lhs: Value, |
| 13214 | | lhs_src: LazySrcLoc, |
| 13215 | 13174 | rhs: Value, |
| 13216 | | rhs_src: LazySrcLoc, |
| 13217 | 13175 | ) CompileError!Value { |
| 13218 | 13176 | const target = sema.mod.getTarget(); |
| 13219 | 13177 | // TODO is this a performance issue? maybe we should try the operation without |
| 13220 | 13178 | // resorting to BigInt first. |
| 13221 | 13179 | var lhs_space: Value.BigIntSpace = undefined; |
| 13222 | 13180 | var rhs_space: Value.BigIntSpace = undefined; |
| 13223 | | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, lhs_src)); |
| 13224 | | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, rhs_src)); |
| 13181 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 13182 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 13225 | 13183 | const limbs_q = try sema.arena.alloc( |
| 13226 | 13184 | math.big.Limb, |
| 13227 | 13185 | lhs_bigint.limbs.len, |
| ... | ... | @@ -13274,8 +13232,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13274 | 13232 | |
| 13275 | 13233 | const mod = sema.mod; |
| 13276 | 13234 | const target = mod.getTarget(); |
| 13277 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 13278 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 13235 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13236 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13279 | 13237 | |
| 13280 | 13238 | const runtime_src = rs: { |
| 13281 | 13239 | // For integers: |
| ... | ... | @@ -13299,7 +13257,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13299 | 13257 | if (rhs_val.isUndef()) { |
| 13300 | 13258 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13301 | 13259 | } |
| 13302 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13260 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13303 | 13261 | return sema.failWithDivideByZero(block, rhs_src); |
| 13304 | 13262 | } |
| 13305 | 13263 | if (maybe_lhs_val) |lhs_val| { |
| ... | ... | @@ -13318,7 +13276,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13318 | 13276 | if (rhs_val.isUndef()) { |
| 13319 | 13277 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13320 | 13278 | } |
| 13321 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13279 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13322 | 13280 | return sema.failWithDivideByZero(block, rhs_src); |
| 13323 | 13281 | } |
| 13324 | 13282 | } |
| ... | ... | @@ -13377,8 +13335,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13377 | 13335 | |
| 13378 | 13336 | const mod = sema.mod; |
| 13379 | 13337 | const target = mod.getTarget(); |
| 13380 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 13381 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 13338 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13339 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13382 | 13340 | |
| 13383 | 13341 | const runtime_src = rs: { |
| 13384 | 13342 | // For integers: |
| ... | ... | @@ -13402,13 +13360,13 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13402 | 13360 | if (rhs_val.isUndef()) { |
| 13403 | 13361 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13404 | 13362 | } |
| 13405 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13363 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13406 | 13364 | return sema.failWithDivideByZero(block, rhs_src); |
| 13407 | 13365 | } |
| 13408 | 13366 | if (maybe_lhs_val) |lhs_val| { |
| 13409 | 13367 | return sema.addConstant( |
| 13410 | 13368 | resolved_type, |
| 13411 | | try sema.intRem(block, resolved_type, lhs_val, lhs_src, rhs_val, rhs_src), |
| 13369 | try sema.intRem(resolved_type, lhs_val, rhs_val), |
| 13412 | 13370 | ); |
| 13413 | 13371 | } |
| 13414 | 13372 | break :rs lhs_src; |
| ... | ... | @@ -13421,7 +13379,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13421 | 13379 | if (rhs_val.isUndef()) { |
| 13422 | 13380 | return sema.failWithUseOfUndef(block, rhs_src); |
| 13423 | 13381 | } |
| 13424 | | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) { |
| 13382 | if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) { |
| 13425 | 13383 | return sema.failWithDivideByZero(block, rhs_src); |
| 13426 | 13384 | } |
| 13427 | 13385 | } |
| ... | ... | @@ -13480,8 +13438,8 @@ fn zirOverflowArithmetic( |
| 13480 | 13438 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)}); |
| 13481 | 13439 | } |
| 13482 | 13440 | |
| 13483 | | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); |
| 13484 | | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); |
| 13441 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 13442 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 13485 | 13443 | |
| 13486 | 13444 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); |
| 13487 | 13445 | const ov_ty = tuple_ty.tupleFields().types[1]; |
| ... | ... | @@ -13500,12 +13458,12 @@ fn zirOverflowArithmetic( |
| 13500 | 13458 | // to the result, even if it is undefined.. |
| 13501 | 13459 | // Otherwise, if either of the argument is undefined, undefined is returned. |
| 13502 | 13460 | if (maybe_lhs_val) |lhs_val| { |
| 13503 | | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13461 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13504 | 13462 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; |
| 13505 | 13463 | } |
| 13506 | 13464 | } |
| 13507 | 13465 | if (maybe_rhs_val) |rhs_val| { |
| 13508 | | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13466 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13509 | 13467 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13510 | 13468 | } |
| 13511 | 13469 | } |
| ... | ... | @@ -13515,7 +13473,7 @@ fn zirOverflowArithmetic( |
| 13515 | 13473 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; |
| 13516 | 13474 | } |
| 13517 | 13475 | |
| 13518 | | const result = try sema.intAddWithOverflow(block, src, lhs_val, rhs_val, dest_ty); |
| 13476 | const result = try sema.intAddWithOverflow(lhs_val, rhs_val, dest_ty); |
| 13519 | 13477 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); |
| 13520 | 13478 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); |
| 13521 | 13479 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; |
| ... | ... | @@ -13528,14 +13486,14 @@ fn zirOverflowArithmetic( |
| 13528 | 13486 | if (maybe_rhs_val) |rhs_val| { |
| 13529 | 13487 | if (rhs_val.isUndef()) { |
| 13530 | 13488 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; |
| 13531 | | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13489 | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13532 | 13490 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13533 | 13491 | } else if (maybe_lhs_val) |lhs_val| { |
| 13534 | 13492 | if (lhs_val.isUndef()) { |
| 13535 | 13493 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; |
| 13536 | 13494 | } |
| 13537 | 13495 | |
| 13538 | | const result = try sema.intSubWithOverflow(block, src, lhs_val, rhs_val, dest_ty); |
| 13496 | const result = try sema.intSubWithOverflow(lhs_val, rhs_val, dest_ty); |
| 13539 | 13497 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); |
| 13540 | 13498 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); |
| 13541 | 13499 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; |
| ... | ... | @@ -13548,9 +13506,9 @@ fn zirOverflowArithmetic( |
| 13548 | 13506 | // Otherwise, if either of the arguments is undefined, both results are undefined. |
| 13549 | 13507 | if (maybe_lhs_val) |lhs_val| { |
| 13550 | 13508 | if (!lhs_val.isUndef()) { |
| 13551 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13509 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13552 | 13510 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13553 | | } else if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, dest_ty)) { |
| 13511 | } else if (try sema.compareAll(lhs_val, .eq, Value.one, dest_ty)) { |
| 13554 | 13512 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; |
| 13555 | 13513 | } |
| 13556 | 13514 | } |
| ... | ... | @@ -13558,9 +13516,9 @@ fn zirOverflowArithmetic( |
| 13558 | 13516 | |
| 13559 | 13517 | if (maybe_rhs_val) |rhs_val| { |
| 13560 | 13518 | if (!rhs_val.isUndef()) { |
| 13561 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13519 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13562 | 13520 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; |
| 13563 | | } else if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, dest_ty)) { |
| 13521 | } else if (try sema.compareAll(rhs_val, .eq, Value.one, dest_ty)) { |
| 13564 | 13522 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13565 | 13523 | } |
| 13566 | 13524 | } |
| ... | ... | @@ -13584,12 +13542,12 @@ fn zirOverflowArithmetic( |
| 13584 | 13542 | // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred. |
| 13585 | 13543 | // Oterhwise if either of the arguments is undefined, both results are undefined. |
| 13586 | 13544 | if (maybe_lhs_val) |lhs_val| { |
| 13587 | | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13545 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13588 | 13546 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13589 | 13547 | } |
| 13590 | 13548 | } |
| 13591 | 13549 | if (maybe_rhs_val) |rhs_val| { |
| 13592 | | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13550 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13593 | 13551 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13594 | 13552 | } |
| 13595 | 13553 | } |
| ... | ... | @@ -13697,7 +13655,7 @@ fn analyzeArithmetic( |
| 13697 | 13655 | .{@tagName(zir_tag)}, |
| 13698 | 13656 | ), |
| 13699 | 13657 | }; |
| 13700 | | return analyzePtrArithmetic(sema, block, src, lhs, rhs, air_tag, lhs_src, rhs_src); |
| 13658 | return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src); |
| 13701 | 13659 | }, |
| 13702 | 13660 | }; |
| 13703 | 13661 | |
| ... | ... | @@ -13719,8 +13677,8 @@ fn analyzeArithmetic( |
| 13719 | 13677 | |
| 13720 | 13678 | const mod = sema.mod; |
| 13721 | 13679 | const target = mod.getTarget(); |
| 13722 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); |
| 13723 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); |
| 13680 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13681 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13724 | 13682 | const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: { |
| 13725 | 13683 | switch (zir_tag) { |
| 13726 | 13684 | .add => { |
| ... | ... | @@ -13732,7 +13690,7 @@ fn analyzeArithmetic( |
| 13732 | 13690 | // overflow (max_int), causing illegal behavior. |
| 13733 | 13691 | // For floats: either operand being undef makes the result undef. |
| 13734 | 13692 | if (maybe_lhs_val) |lhs_val| { |
| 13735 | | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13693 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13736 | 13694 | return casted_rhs; |
| 13737 | 13695 | } |
| 13738 | 13696 | } |
| ... | ... | @@ -13744,7 +13702,7 @@ fn analyzeArithmetic( |
| 13744 | 13702 | return sema.addConstUndef(resolved_type); |
| 13745 | 13703 | } |
| 13746 | 13704 | } |
| 13747 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13705 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13748 | 13706 | return casted_lhs; |
| 13749 | 13707 | } |
| 13750 | 13708 | } |
| ... | ... | @@ -13759,9 +13717,9 @@ fn analyzeArithmetic( |
| 13759 | 13717 | } |
| 13760 | 13718 | if (maybe_rhs_val) |rhs_val| { |
| 13761 | 13719 | if (is_int) { |
| 13762 | | const sum = try sema.intAdd(block, src, lhs_val, rhs_val, resolved_type); |
| 13720 | const sum = try sema.intAdd(lhs_val, rhs_val, resolved_type); |
| 13763 | 13721 | var vector_index: usize = undefined; |
| 13764 | | if (!(try sema.intFitsInType(block, src, sum, resolved_type, &vector_index))) { |
| 13722 | if (!(try sema.intFitsInType(sum, resolved_type, &vector_index))) { |
| 13765 | 13723 | return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vector_index); |
| 13766 | 13724 | } |
| 13767 | 13725 | return sema.addConstant(resolved_type, sum); |
| ... | ... | @@ -13779,7 +13737,7 @@ fn analyzeArithmetic( |
| 13779 | 13737 | // If either of the operands are zero, the other operand is returned. |
| 13780 | 13738 | // If either of the operands are undefined, the result is undefined. |
| 13781 | 13739 | if (maybe_lhs_val) |lhs_val| { |
| 13782 | | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13740 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13783 | 13741 | return casted_rhs; |
| 13784 | 13742 | } |
| 13785 | 13743 | } |
| ... | ... | @@ -13788,13 +13746,13 @@ fn analyzeArithmetic( |
| 13788 | 13746 | if (rhs_val.isUndef()) { |
| 13789 | 13747 | return sema.addConstUndef(resolved_type); |
| 13790 | 13748 | } |
| 13791 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13749 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13792 | 13750 | return casted_lhs; |
| 13793 | 13751 | } |
| 13794 | 13752 | if (maybe_lhs_val) |lhs_val| { |
| 13795 | 13753 | return sema.addConstant( |
| 13796 | 13754 | resolved_type, |
| 13797 | | try sema.numberAddWrap(block, src, lhs_val, rhs_val, resolved_type), |
| 13755 | try sema.numberAddWrapScalar(lhs_val, rhs_val, resolved_type), |
| 13798 | 13756 | ); |
| 13799 | 13757 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| 13800 | 13758 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| ... | ... | @@ -13804,7 +13762,7 @@ fn analyzeArithmetic( |
| 13804 | 13762 | // If either of the operands are zero, then the other operand is returned. |
| 13805 | 13763 | // If either of the operands are undefined, the result is undefined. |
| 13806 | 13764 | if (maybe_lhs_val) |lhs_val| { |
| 13807 | | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 13765 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13808 | 13766 | return casted_rhs; |
| 13809 | 13767 | } |
| 13810 | 13768 | } |
| ... | ... | @@ -13812,12 +13770,12 @@ fn analyzeArithmetic( |
| 13812 | 13770 | if (rhs_val.isUndef()) { |
| 13813 | 13771 | return sema.addConstUndef(resolved_type); |
| 13814 | 13772 | } |
| 13815 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13773 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13816 | 13774 | return casted_lhs; |
| 13817 | 13775 | } |
| 13818 | 13776 | if (maybe_lhs_val) |lhs_val| { |
| 13819 | 13777 | const val = if (scalar_tag == .ComptimeInt) |
| 13820 | | try sema.intAdd(block, src, lhs_val, rhs_val, resolved_type) |
| 13778 | try sema.intAdd(lhs_val, rhs_val, resolved_type) |
| 13821 | 13779 | else |
| 13822 | 13780 | try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target); |
| 13823 | 13781 | |
| ... | ... | @@ -13841,7 +13799,7 @@ fn analyzeArithmetic( |
| 13841 | 13799 | return sema.addConstUndef(resolved_type); |
| 13842 | 13800 | } |
| 13843 | 13801 | } |
| 13844 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13802 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13845 | 13803 | return casted_lhs; |
| 13846 | 13804 | } |
| 13847 | 13805 | } |
| ... | ... | @@ -13856,9 +13814,9 @@ fn analyzeArithmetic( |
| 13856 | 13814 | } |
| 13857 | 13815 | if (maybe_rhs_val) |rhs_val| { |
| 13858 | 13816 | if (is_int) { |
| 13859 | | const diff = try sema.intSub(block, src, lhs_val, rhs_val, resolved_type); |
| 13817 | const diff = try sema.intSub(lhs_val, rhs_val, resolved_type); |
| 13860 | 13818 | var vector_index: usize = undefined; |
| 13861 | | if (!(try sema.intFitsInType(block, src, diff, resolved_type, &vector_index))) { |
| 13819 | if (!(try sema.intFitsInType(diff, resolved_type, &vector_index))) { |
| 13862 | 13820 | return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vector_index); |
| 13863 | 13821 | } |
| 13864 | 13822 | return sema.addConstant(resolved_type, diff); |
| ... | ... | @@ -13879,7 +13837,7 @@ fn analyzeArithmetic( |
| 13879 | 13837 | if (rhs_val.isUndef()) { |
| 13880 | 13838 | return sema.addConstUndef(resolved_type); |
| 13881 | 13839 | } |
| 13882 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13840 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13883 | 13841 | return casted_lhs; |
| 13884 | 13842 | } |
| 13885 | 13843 | } |
| ... | ... | @@ -13891,7 +13849,7 @@ fn analyzeArithmetic( |
| 13891 | 13849 | if (maybe_rhs_val) |rhs_val| { |
| 13892 | 13850 | return sema.addConstant( |
| 13893 | 13851 | resolved_type, |
| 13894 | | try sema.numberSubWrap(block, src, lhs_val, rhs_val, resolved_type), |
| 13852 | try sema.numberSubWrapScalar(lhs_val, rhs_val, resolved_type), |
| 13895 | 13853 | ); |
| 13896 | 13854 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| 13897 | 13855 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| ... | ... | @@ -13904,7 +13862,7 @@ fn analyzeArithmetic( |
| 13904 | 13862 | if (rhs_val.isUndef()) { |
| 13905 | 13863 | return sema.addConstUndef(resolved_type); |
| 13906 | 13864 | } |
| 13907 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13865 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13908 | 13866 | return casted_lhs; |
| 13909 | 13867 | } |
| 13910 | 13868 | } |
| ... | ... | @@ -13914,7 +13872,7 @@ fn analyzeArithmetic( |
| 13914 | 13872 | } |
| 13915 | 13873 | if (maybe_rhs_val) |rhs_val| { |
| 13916 | 13874 | const val = if (scalar_tag == .ComptimeInt) |
| 13917 | | try sema.intSub(block, src, lhs_val, rhs_val, resolved_type) |
| 13875 | try sema.intSub(lhs_val, rhs_val, resolved_type) |
| 13918 | 13876 | else |
| 13919 | 13877 | try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target); |
| 13920 | 13878 | |
| ... | ... | @@ -13933,13 +13891,13 @@ fn analyzeArithmetic( |
| 13933 | 13891 | // For floats: either operand being undef makes the result undef. |
| 13934 | 13892 | if (maybe_lhs_val) |lhs_val| { |
| 13935 | 13893 | if (!lhs_val.isUndef()) { |
| 13936 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13894 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13937 | 13895 | const zero_val = if (is_vector) b: { |
| 13938 | 13896 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13939 | 13897 | } else Value.zero; |
| 13940 | 13898 | return sema.addConstant(resolved_type, zero_val); |
| 13941 | 13899 | } |
| 13942 | | if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) { |
| 13900 | if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) { |
| 13943 | 13901 | return casted_rhs; |
| 13944 | 13902 | } |
| 13945 | 13903 | } |
| ... | ... | @@ -13953,13 +13911,13 @@ fn analyzeArithmetic( |
| 13953 | 13911 | return sema.addConstUndef(resolved_type); |
| 13954 | 13912 | } |
| 13955 | 13913 | } |
| 13956 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13914 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13957 | 13915 | const zero_val = if (is_vector) b: { |
| 13958 | 13916 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13959 | 13917 | } else Value.zero; |
| 13960 | 13918 | return sema.addConstant(resolved_type, zero_val); |
| 13961 | 13919 | } |
| 13962 | | if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) { |
| 13920 | if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) { |
| 13963 | 13921 | return casted_lhs; |
| 13964 | 13922 | } |
| 13965 | 13923 | if (maybe_lhs_val) |lhs_val| { |
| ... | ... | @@ -13973,7 +13931,7 @@ fn analyzeArithmetic( |
| 13973 | 13931 | if (is_int) { |
| 13974 | 13932 | const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target); |
| 13975 | 13933 | var vector_index: usize = undefined; |
| 13976 | | if (!(try sema.intFitsInType(block, src, product, resolved_type, &vector_index))) { |
| 13934 | if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) { |
| 13977 | 13935 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index); |
| 13978 | 13936 | } |
| 13979 | 13937 | return sema.addConstant(resolved_type, product); |
| ... | ... | @@ -13993,13 +13951,13 @@ fn analyzeArithmetic( |
| 13993 | 13951 | // If either of the operands are undefined, result is undefined. |
| 13994 | 13952 | if (maybe_lhs_val) |lhs_val| { |
| 13995 | 13953 | if (!lhs_val.isUndef()) { |
| 13996 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13954 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13997 | 13955 | const zero_val = if (is_vector) b: { |
| 13998 | 13956 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13999 | 13957 | } else Value.zero; |
| 14000 | 13958 | return sema.addConstant(resolved_type, zero_val); |
| 14001 | 13959 | } |
| 14002 | | if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) { |
| 13960 | if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) { |
| 14003 | 13961 | return casted_rhs; |
| 14004 | 13962 | } |
| 14005 | 13963 | } |
| ... | ... | @@ -14009,13 +13967,13 @@ fn analyzeArithmetic( |
| 14009 | 13967 | if (rhs_val.isUndef()) { |
| 14010 | 13968 | return sema.addConstUndef(resolved_type); |
| 14011 | 13969 | } |
| 14012 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13970 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14013 | 13971 | const zero_val = if (is_vector) b: { |
| 14014 | 13972 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14015 | 13973 | } else Value.zero; |
| 14016 | 13974 | return sema.addConstant(resolved_type, zero_val); |
| 14017 | 13975 | } |
| 14018 | | if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) { |
| 13976 | if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) { |
| 14019 | 13977 | return casted_lhs; |
| 14020 | 13978 | } |
| 14021 | 13979 | if (maybe_lhs_val) |lhs_val| { |
| ... | ... | @@ -14036,13 +13994,13 @@ fn analyzeArithmetic( |
| 14036 | 13994 | // If either of the operands are undefined, result is undefined. |
| 14037 | 13995 | if (maybe_lhs_val) |lhs_val| { |
| 14038 | 13996 | if (!lhs_val.isUndef()) { |
| 14039 | | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 13997 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14040 | 13998 | const zero_val = if (is_vector) b: { |
| 14041 | 13999 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14042 | 14000 | } else Value.zero; |
| 14043 | 14001 | return sema.addConstant(resolved_type, zero_val); |
| 14044 | 14002 | } |
| 14045 | | if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) { |
| 14003 | if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) { |
| 14046 | 14004 | return casted_rhs; |
| 14047 | 14005 | } |
| 14048 | 14006 | } |
| ... | ... | @@ -14051,13 +14009,13 @@ fn analyzeArithmetic( |
| 14051 | 14009 | if (rhs_val.isUndef()) { |
| 14052 | 14010 | return sema.addConstUndef(resolved_type); |
| 14053 | 14011 | } |
| 14054 | | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { |
| 14012 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 14055 | 14013 | const zero_val = if (is_vector) b: { |
| 14056 | 14014 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14057 | 14015 | } else Value.zero; |
| 14058 | 14016 | return sema.addConstant(resolved_type, zero_val); |
| 14059 | 14017 | } |
| 14060 | | if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) { |
| 14018 | if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) { |
| 14061 | 14019 | return casted_lhs; |
| 14062 | 14020 | } |
| 14063 | 14021 | if (maybe_lhs_val) |lhs_val| { |
| ... | ... | @@ -14135,7 +14093,7 @@ fn analyzePtrArithmetic( |
| 14135 | 14093 | // coerce to isize instead of usize. |
| 14136 | 14094 | const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src); |
| 14137 | 14095 | const target = sema.mod.getTarget(); |
| 14138 | | const opt_ptr_val = try sema.resolveMaybeUndefVal(block, ptr_src, ptr); |
| 14096 | const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr); |
| 14139 | 14097 | const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); |
| 14140 | 14098 | const ptr_ty = sema.typeOf(ptr); |
| 14141 | 14099 | const ptr_info = ptr_ty.ptrInfo().data; |
| ... | ... | @@ -14183,7 +14141,7 @@ fn analyzePtrArithmetic( |
| 14183 | 14141 | |
| 14184 | 14142 | const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(target)); |
| 14185 | 14143 | if (offset_int == 0) return ptr; |
| 14186 | | if (try ptr_val.getUnsignedIntAdvanced(target, sema.kit(block, ptr_src))) |addr| { |
| 14144 | if (try ptr_val.getUnsignedIntAdvanced(target, sema)) |addr| { |
| 14187 | 14145 | const elem_size = elem_ty.abiSize(target); |
| 14188 | 14146 | const new_addr = switch (air_tag) { |
| 14189 | 14147 | .ptr_add => addr + elem_size * offset_int, |
| ... | ... | @@ -14438,8 +14396,8 @@ fn zirCmpEq( |
| 14438 | 14396 | |
| 14439 | 14397 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { |
| 14440 | 14398 | const runtime_src: LazySrcLoc = src: { |
| 14441 | | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lval| { |
| 14442 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rval| { |
| 14399 | if (try sema.resolveMaybeUndefVal(lhs)) |lval| { |
| 14400 | if (try sema.resolveMaybeUndefVal(rhs)) |rval| { |
| 14443 | 14401 | if (lval.isUndef() or rval.isUndef()) { |
| 14444 | 14402 | return sema.addConstUndef(Type.bool); |
| 14445 | 14403 | } |
| ... | ... | @@ -14485,7 +14443,7 @@ fn analyzeCmpUnionTag( |
| 14485 | 14443 | tag_src: LazySrcLoc, |
| 14486 | 14444 | op: std.math.CompareOperator, |
| 14487 | 14445 | ) CompileError!Air.Inst.Ref { |
| 14488 | | const union_ty = try sema.resolveTypeFields(block, un_src, sema.typeOf(un)); |
| 14446 | const union_ty = try sema.resolveTypeFields(sema.typeOf(un)); |
| 14489 | 14447 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 14490 | 14448 | const msg = msg: { |
| 14491 | 14449 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| ... | ... | @@ -14500,7 +14458,7 @@ fn analyzeCmpUnionTag( |
| 14500 | 14458 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); |
| 14501 | 14459 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); |
| 14502 | 14460 | |
| 14503 | | if (try sema.resolveMaybeUndefVal(block, tag_src, coerced_tag)) |enum_val| { |
| 14461 | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { |
| 14504 | 14462 | if (enum_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14505 | 14463 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); |
| 14506 | 14464 | if (field_ty.zigTypeTag() == .NoReturn) { |
| ... | ... | @@ -14598,18 +14556,18 @@ fn cmpSelf( |
| 14598 | 14556 | ) CompileError!Air.Inst.Ref { |
| 14599 | 14557 | const resolved_type = sema.typeOf(casted_lhs); |
| 14600 | 14558 | const runtime_src: LazySrcLoc = src: { |
| 14601 | | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { |
| 14559 | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { |
| 14602 | 14560 | if (lhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14603 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { |
| 14561 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 14604 | 14562 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14605 | 14563 | |
| 14606 | 14564 | if (resolved_type.zigTypeTag() == .Vector) { |
| 14607 | 14565 | const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.@"bool"); |
| 14608 | | const cmp_val = try sema.compareVector(block, lhs_src, lhs_val, op, rhs_val, resolved_type); |
| 14566 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type); |
| 14609 | 14567 | return sema.addConstant(result_ty, cmp_val); |
| 14610 | 14568 | } |
| 14611 | 14569 | |
| 14612 | | if (try sema.compareAll(block, lhs_src, lhs_val, op, rhs_val, resolved_type)) { |
| 14570 | if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) { |
| 14613 | 14571 | return Air.Inst.Ref.bool_true; |
| 14614 | 14572 | } else { |
| 14615 | 14573 | return Air.Inst.Ref.bool_false; |
| ... | ... | @@ -14625,7 +14583,7 @@ fn cmpSelf( |
| 14625 | 14583 | // For bools, we still check the other operand, because we can lower |
| 14626 | 14584 | // bool eq/neq more efficiently. |
| 14627 | 14585 | if (resolved_type.zigTypeTag() == .Bool) { |
| 14628 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { |
| 14586 | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 14629 | 14587 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14630 | 14588 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src); |
| 14631 | 14589 | } |
| ... | ... | @@ -14710,7 +14668,6 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14710 | 14668 | |
| 14711 | 14669 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14712 | 14670 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 14713 | | const src = inst_data.src(); |
| 14714 | 14671 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 14715 | 14672 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 14716 | 14673 | switch (operand_ty.zigTypeTag()) { |
| ... | ... | @@ -14746,7 +14703,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 14746 | 14703 | => {}, |
| 14747 | 14704 | } |
| 14748 | 14705 | const target = sema.mod.getTarget(); |
| 14749 | | const bit_size = try operand_ty.bitSizeAdvanced(target, sema.kit(block, src)); |
| 14706 | const bit_size = try operand_ty.bitSizeAdvanced(target, sema); |
| 14750 | 14707 | return sema.addIntUnsigned(Type.comptime_int, bit_size); |
| 14751 | 14708 | } |
| 14752 | 14709 | |
| ... | ... | @@ -14767,14 +14724,13 @@ fn zirClosureCapture( |
| 14767 | 14724 | ) CompileError!void { |
| 14768 | 14725 | // TODO: Compile error when closed over values are modified |
| 14769 | 14726 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 14770 | | const src = inst_data.src(); |
| 14771 | 14727 | // Closures are not necessarily constant values. For example, the |
| 14772 | 14728 | // code might do something like this: |
| 14773 | 14729 | // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; } |
| 14774 | 14730 | // ...in which case the closure_capture instruction has access to a runtime |
| 14775 | 14731 | // value only. In such case we preserve the type and use a dummy runtime value. |
| 14776 | 14732 | const operand = try sema.resolveInst(inst_data.operand); |
| 14777 | | const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) orelse |
| 14733 | const val = (try sema.resolveMaybeUndefValAllowVariables(operand)) orelse |
| 14778 | 14734 | Value.initTag(.unreachable_value); |
| 14779 | 14735 | |
| 14780 | 14736 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, .{ |
| ... | ... | @@ -14913,7 +14869,7 @@ fn zirBuiltinSrc( |
| 14913 | 14869 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); |
| 14914 | 14870 | |
| 14915 | 14871 | const func_name_val = blk: { |
| 14916 | | var anon_decl = try block.startAnonDecl(src); |
| 14872 | var anon_decl = try block.startAnonDecl(); |
| 14917 | 14873 | defer anon_decl.deinit(); |
| 14918 | 14874 | const name = std.mem.span(fn_owner_decl.name); |
| 14919 | 14875 | const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]); |
| ... | ... | @@ -14926,7 +14882,7 @@ fn zirBuiltinSrc( |
| 14926 | 14882 | }; |
| 14927 | 14883 | |
| 14928 | 14884 | const file_name_val = blk: { |
| 14929 | | var anon_decl = try block.startAnonDecl(src); |
| 14885 | var anon_decl = try block.startAnonDecl(); |
| 14930 | 14886 | defer anon_decl.deinit(); |
| 14931 | 14887 | const relative_path = try fn_owner_decl.getFileScope().fullPath(sema.arena); |
| 14932 | 14888 | const absolute_path = std.fs.realpathAlloc(sema.arena, relative_path) catch |err| { |
| ... | ... | @@ -14952,7 +14908,7 @@ fn zirBuiltinSrc( |
| 14952 | 14908 | field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1); |
| 14953 | 14909 | |
| 14954 | 14910 | return sema.addConstant( |
| 14955 | | try sema.getBuiltinType(block, src, "SourceLocation"), |
| 14911 | try sema.getBuiltinType("SourceLocation"), |
| 14956 | 14912 | try Value.Tag.aggregate.create(sema.arena, field_values), |
| 14957 | 14913 | ); |
| 14958 | 14914 | } |
| ... | ... | @@ -14961,7 +14917,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14961 | 14917 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 14962 | 14918 | const src = inst_data.src(); |
| 14963 | 14919 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 14964 | | const type_info_ty = try sema.getBuiltinType(block, src, "Type"); |
| 14920 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 14965 | 14921 | const target = sema.mod.getTarget(); |
| 14966 | 14922 | |
| 14967 | 14923 | switch (ty.zigTypeTag()) { |
| ... | ... | @@ -15032,7 +14988,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15032 | 14988 | // TODO: look into memoizing this result. |
| 15033 | 14989 | const info = ty.fnInfo(); |
| 15034 | 14990 | |
| 15035 | | var params_anon_decl = try block.startAnonDecl(src); |
| 14991 | var params_anon_decl = try block.startAnonDecl(); |
| 15036 | 14992 | defer params_anon_decl.deinit(); |
| 15037 | 14993 | |
| 15038 | 14994 | const param_vals = try params_anon_decl.arena().alloc(Value, info.param_types.len); |
| ... | ... | @@ -15187,7 +15143,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15187 | 15143 | // is_allowzero: bool, |
| 15188 | 15144 | Value.makeBool(info.@"allowzero"), |
| 15189 | 15145 | // sentinel: ?*const anyopaque, |
| 15190 | | try sema.optRefValue(block, src, info.pointee_type, info.sentinel), |
| 15146 | try sema.optRefValue(block, info.pointee_type, info.sentinel), |
| 15191 | 15147 | }; |
| 15192 | 15148 | |
| 15193 | 15149 | return sema.addConstant( |
| ... | ... | @@ -15206,7 +15162,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15206 | 15162 | // child: type, |
| 15207 | 15163 | field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type); |
| 15208 | 15164 | // sentinel: ?*const anyopaque, |
| 15209 | | field_values[2] = try sema.optRefValue(block, src, info.elem_type, info.sentinel); |
| 15165 | field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel); |
| 15210 | 15166 | |
| 15211 | 15167 | return sema.addConstant( |
| 15212 | 15168 | type_info_ty, |
| ... | ... | @@ -15246,7 +15202,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15246 | 15202 | ); |
| 15247 | 15203 | }, |
| 15248 | 15204 | .ErrorSet => { |
| 15249 | | var fields_anon_decl = try block.startAnonDecl(src); |
| 15205 | var fields_anon_decl = try block.startAnonDecl(); |
| 15250 | 15206 | defer fields_anon_decl.deinit(); |
| 15251 | 15207 | |
| 15252 | 15208 | // Get the Error type |
| ... | ... | @@ -15278,7 +15234,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15278 | 15234 | for (vals) |*field_val, i| { |
| 15279 | 15235 | const name = names[i]; |
| 15280 | 15236 | const name_val = v: { |
| 15281 | | var anon_decl = try block.startAnonDecl(src); |
| 15237 | var anon_decl = try block.startAnonDecl(); |
| 15282 | 15238 | defer anon_decl.deinit(); |
| 15283 | 15239 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15284 | 15240 | const new_decl = try anon_decl.finish( |
| ... | ... | @@ -15357,7 +15313,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15357 | 15313 | |
| 15358 | 15314 | const is_exhaustive = Value.makeBool(!ty.isNonexhaustiveEnum()); |
| 15359 | 15315 | |
| 15360 | | var fields_anon_decl = try block.startAnonDecl(src); |
| 15316 | var fields_anon_decl = try block.startAnonDecl(); |
| 15361 | 15317 | defer fields_anon_decl.deinit(); |
| 15362 | 15318 | |
| 15363 | 15319 | const enum_field_ty = t: { |
| ... | ... | @@ -15389,7 +15345,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15389 | 15345 | |
| 15390 | 15346 | const name = enum_fields.keys()[i]; |
| 15391 | 15347 | const name_val = v: { |
| 15392 | | var anon_decl = try block.startAnonDecl(src); |
| 15348 | var anon_decl = try block.startAnonDecl(); |
| 15393 | 15349 | defer anon_decl.deinit(); |
| 15394 | 15350 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15395 | 15351 | const new_decl = try anon_decl.finish( |
| ... | ... | @@ -15456,7 +15412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15456 | 15412 | .Union => { |
| 15457 | 15413 | // TODO: look into memoizing this result. |
| 15458 | 15414 | |
| 15459 | | var fields_anon_decl = try block.startAnonDecl(src); |
| 15415 | var fields_anon_decl = try block.startAnonDecl(); |
| 15460 | 15416 | defer fields_anon_decl.deinit(); |
| 15461 | 15417 | |
| 15462 | 15418 | const union_field_ty = t: { |
| ... | ... | @@ -15473,8 +15429,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15473 | 15429 | break :t try union_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena()); |
| 15474 | 15430 | }; |
| 15475 | 15431 | |
| 15476 | | const union_ty = try sema.resolveTypeFields(block, src, ty); |
| 15477 | | try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout |
| 15432 | const union_ty = try sema.resolveTypeFields(ty); |
| 15433 | try sema.resolveTypeLayout(ty); // Getting alignment requires type layout |
| 15478 | 15434 | const layout = union_ty.containerLayout(); |
| 15479 | 15435 | |
| 15480 | 15436 | const union_fields = union_ty.unionFields(); |
| ... | ... | @@ -15484,7 +15440,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15484 | 15440 | const field = union_fields.values()[i]; |
| 15485 | 15441 | const name = union_fields.keys()[i]; |
| 15486 | 15442 | const name_val = v: { |
| 15487 | | var anon_decl = try block.startAnonDecl(src); |
| 15443 | var anon_decl = try block.startAnonDecl(); |
| 15488 | 15444 | defer anon_decl.deinit(); |
| 15489 | 15445 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15490 | 15446 | const new_decl = try anon_decl.finish( |
| ... | ... | @@ -15497,7 +15453,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15497 | 15453 | |
| 15498 | 15454 | const union_field_fields = try fields_anon_decl.arena().create([3]Value); |
| 15499 | 15455 | const alignment = switch (layout) { |
| 15500 | | .Auto, .Extern => try sema.unionFieldAlignment(block, src, field), |
| 15456 | .Auto, .Extern => try sema.unionFieldAlignment(field), |
| 15501 | 15457 | .Packed => 0, |
| 15502 | 15458 | }; |
| 15503 | 15459 | |
| ... | ... | @@ -15564,7 +15520,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15564 | 15520 | .Struct => { |
| 15565 | 15521 | // TODO: look into memoizing this result. |
| 15566 | 15522 | |
| 15567 | | var fields_anon_decl = try block.startAnonDecl(src); |
| 15523 | var fields_anon_decl = try block.startAnonDecl(); |
| 15568 | 15524 | defer fields_anon_decl.deinit(); |
| 15569 | 15525 | |
| 15570 | 15526 | const struct_field_ty = t: { |
| ... | ... | @@ -15580,8 +15536,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15580 | 15536 | var buffer: Value.ToTypeBuffer = undefined; |
| 15581 | 15537 | break :t try struct_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena()); |
| 15582 | 15538 | }; |
| 15583 | | const struct_ty = try sema.resolveTypeFields(block, src, ty); |
| 15584 | | try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout |
| 15539 | const struct_ty = try sema.resolveTypeFields(ty); |
| 15540 | try sema.resolveTypeLayout(ty); // Getting alignment requires type layout |
| 15585 | 15541 | const layout = struct_ty.containerLayout(); |
| 15586 | 15542 | |
| 15587 | 15543 | const struct_field_vals = fv: { |
| ... | ... | @@ -15592,7 +15548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15592 | 15548 | for (struct_field_vals) |*struct_field_val, i| { |
| 15593 | 15549 | const field_ty = field_types[i]; |
| 15594 | 15550 | const name_val = v: { |
| 15595 | | var anon_decl = try block.startAnonDecl(src); |
| 15551 | var anon_decl = try block.startAnonDecl(); |
| 15596 | 15552 | defer anon_decl.deinit(); |
| 15597 | 15553 | const bytes = if (struct_ty.castTag(.anon_struct)) |payload| |
| 15598 | 15554 | try anon_decl.arena().dupeZ(u8, payload.data.names[i]) |
| ... | ... | @@ -15613,7 +15569,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15613 | 15569 | const field_val = tuple.values[i]; |
| 15614 | 15570 | const is_comptime = field_val.tag() != .unreachable_value; |
| 15615 | 15571 | const opt_default_val = if (is_comptime) field_val else null; |
| 15616 | | const default_val_ptr = try sema.optRefValue(block, src, field_ty, opt_default_val); |
| 15572 | const default_val_ptr = try sema.optRefValue(block, field_ty, opt_default_val); |
| 15617 | 15573 | struct_field_fields.* = .{ |
| 15618 | 15574 | // name: []const u8, |
| 15619 | 15575 | name_val, |
| ... | ... | @@ -15637,7 +15593,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15637 | 15593 | const field = struct_fields.values()[i]; |
| 15638 | 15594 | const name = struct_fields.keys()[i]; |
| 15639 | 15595 | const name_val = v: { |
| 15640 | | var anon_decl = try block.startAnonDecl(src); |
| 15596 | var anon_decl = try block.startAnonDecl(); |
| 15641 | 15597 | defer anon_decl.deinit(); |
| 15642 | 15598 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15643 | 15599 | const new_decl = try anon_decl.finish( |
| ... | ... | @@ -15656,7 +15612,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15656 | 15612 | null |
| 15657 | 15613 | else |
| 15658 | 15614 | field.default_val; |
| 15659 | | const default_val_ptr = try sema.optRefValue(block, src, field.ty, opt_default_val); |
| 15615 | const default_val_ptr = try sema.optRefValue(block, field.ty, opt_default_val); |
| 15660 | 15616 | const alignment = field.alignment(target, layout); |
| 15661 | 15617 | |
| 15662 | 15618 | struct_field_fields.* = .{ |
| ... | ... | @@ -15736,7 +15692,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15736 | 15692 | .Opaque => { |
| 15737 | 15693 | // TODO: look into memoizing this result. |
| 15738 | 15694 | |
| 15739 | | const opaque_ty = try sema.resolveTypeFields(block, src, ty); |
| 15695 | const opaque_ty = try sema.resolveTypeFields(ty); |
| 15740 | 15696 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace()); |
| 15741 | 15697 | |
| 15742 | 15698 | const field_values = try sema.arena.create([1]Value); |
| ... | ... | @@ -15766,7 +15722,7 @@ fn typeInfoDecls( |
| 15766 | 15722 | type_info_ty: Type, |
| 15767 | 15723 | opt_namespace: ?*Module.Namespace, |
| 15768 | 15724 | ) CompileError!Value { |
| 15769 | | var decls_anon_decl = try block.startAnonDecl(src); |
| 15725 | var decls_anon_decl = try block.startAnonDecl(); |
| 15770 | 15726 | defer decls_anon_decl.deinit(); |
| 15771 | 15727 | |
| 15772 | 15728 | const declaration_ty = t: { |
| ... | ... | @@ -15790,7 +15746,7 @@ fn typeInfoDecls( |
| 15790 | 15746 | const decl_index = opt_namespace.?.decls.keys()[i]; |
| 15791 | 15747 | const decl = sema.mod.declPtr(decl_index); |
| 15792 | 15748 | const name_val = v: { |
| 15793 | | var anon_decl = try block.startAnonDecl(src); |
| 15749 | var anon_decl = try block.startAnonDecl(); |
| 15794 | 15750 | defer anon_decl.deinit(); |
| 15795 | 15751 | const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0)); |
| 15796 | 15752 | const new_decl = try anon_decl.finish( |
| ... | ... | @@ -15971,7 +15927,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 15971 | 15927 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 15972 | 15928 | |
| 15973 | 15929 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| 15974 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 15930 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 15975 | 15931 | return if (val.isUndef()) |
| 15976 | 15932 | sema.addConstUndef(Type.bool) |
| 15977 | 15933 | else if (val.toBool()) |
| ... | ... | @@ -16044,7 +16000,7 @@ fn zirBoolBr( |
| 16044 | 16000 | _ = try rhs_block.addBr(block_inst, rhs_result); |
| 16045 | 16001 | } |
| 16046 | 16002 | |
| 16047 | | const result = finishCondBr(sema, parent_block, &child_block, &then_block, &else_block, lhs, block_inst); |
| 16003 | const result = sema.finishCondBr(parent_block, &child_block, &then_block, &else_block, lhs, block_inst); |
| 16048 | 16004 | if (!sema.typeOf(rhs_result).isNoReturn()) { |
| 16049 | 16005 | if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { |
| 16050 | 16006 | if (is_bool_or and rhs_val.toBool()) { |
| ... | ... | @@ -16119,7 +16075,7 @@ fn zirIsNonNullPtr( |
| 16119 | 16075 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16120 | 16076 | const src = inst_data.src(); |
| 16121 | 16077 | const ptr = try sema.resolveInst(inst_data.operand); |
| 16122 | | if ((try sema.resolveMaybeUndefVal(block, src, ptr)) == null) { |
| 16078 | if ((try sema.resolveMaybeUndefVal(ptr)) == null) { |
| 16123 | 16079 | return block.addUnOp(.is_non_null_ptr, ptr); |
| 16124 | 16080 | } |
| 16125 | 16081 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| ... | ... | @@ -16449,7 +16405,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 16449 | 16405 | |
| 16450 | 16406 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 16451 | 16407 | const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr); |
| 16452 | | return retWithErrTracing(sema, block, src, is_non_err, .ret_load, ret_ptr); |
| 16408 | return sema.retWithErrTracing(block, src, is_non_err, .ret_load, ret_ptr); |
| 16453 | 16409 | } |
| 16454 | 16410 | |
| 16455 | 16411 | _ = try block.addUnOp(.ret_load, ret_ptr); |
| ... | ... | @@ -16473,11 +16429,11 @@ fn retWithErrTracing( |
| 16473 | 16429 | else => true, |
| 16474 | 16430 | }; |
| 16475 | 16431 | const gpa = sema.gpa; |
| 16476 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 16477 | | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 16432 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 16433 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 16478 | 16434 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 16479 | 16435 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 16480 | | const return_err_fn = try sema.getBuiltin(block, src, "returnError"); |
| 16436 | const return_err_fn = try sema.getBuiltin("returnError"); |
| 16481 | 16437 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 16482 | 16438 | |
| 16483 | 16439 | if (!need_check) { |
| ... | ... | @@ -16635,13 +16591,13 @@ fn analyzeRet( |
| 16635 | 16591 | return always_noreturn; |
| 16636 | 16592 | } |
| 16637 | 16593 | |
| 16638 | | try sema.resolveTypeLayout(block, src, sema.fn_ret_ty); |
| 16594 | try sema.resolveTypeLayout(sema.fn_ret_ty); |
| 16639 | 16595 | |
| 16640 | 16596 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 16641 | 16597 | // Avoid adding a frame to the error return trace in case the value is comptime-known |
| 16642 | 16598 | // to be not an error. |
| 16643 | 16599 | const is_non_err = try sema.analyzeIsNonErr(block, src, operand); |
| 16644 | | return retWithErrTracing(sema, block, src, is_non_err, .ret, operand); |
| 16600 | return sema.retWithErrTracing(block, src, is_non_err, .ret, operand); |
| 16645 | 16601 | } |
| 16646 | 16602 | |
| 16647 | 16603 | _ = try block.addUnOp(.ret, operand); |
| ... | ... | @@ -16720,7 +16676,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16720 | 16676 | break :blk 0; |
| 16721 | 16677 | } |
| 16722 | 16678 | } |
| 16723 | | const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(target, sema.kit(block, align_src))).?); |
| 16679 | const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(target, sema)).?); |
| 16724 | 16680 | try sema.validateAlign(block, align_src, abi_align); |
| 16725 | 16681 | break :blk abi_align; |
| 16726 | 16682 | } else 0; |
| ... | ... | @@ -16752,8 +16708,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16752 | 16708 | const elem_ty = if (abi_align == 0) |
| 16753 | 16709 | unresolved_elem_ty |
| 16754 | 16710 | else t: { |
| 16755 | | const elem_ty = try sema.resolveTypeFields(block, elem_ty_src, unresolved_elem_ty); |
| 16756 | | try sema.resolveTypeLayout(block, elem_ty_src, elem_ty); |
| 16711 | const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty); |
| 16712 | try sema.resolveTypeLayout(elem_ty); |
| 16757 | 16713 | break :t elem_ty; |
| 16758 | 16714 | }; |
| 16759 | 16715 | |
| ... | ... | @@ -16772,7 +16728,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16772 | 16728 | } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) { |
| 16773 | 16729 | return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{}); |
| 16774 | 16730 | } else if (inst_data.size == .C) { |
| 16775 | | if (!try sema.validateExternType(block, elem_ty_src, elem_ty, .other)) { |
| 16731 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 16776 | 16732 | const msg = msg: { |
| 16777 | 16733 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); |
| 16778 | 16734 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -16831,7 +16787,7 @@ fn structInitEmpty( |
| 16831 | 16787 | ) CompileError!Air.Inst.Ref { |
| 16832 | 16788 | const gpa = sema.gpa; |
| 16833 | 16789 | // This logic must be synchronized with that in `zirStructInit`. |
| 16834 | | const struct_ty = try sema.resolveTypeFields(block, dest_src, obj_ty); |
| 16790 | const struct_ty = try sema.resolveTypeFields(obj_ty); |
| 16835 | 16791 | |
| 16836 | 16792 | // The init values to use for the struct instance. |
| 16837 | 16793 | const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount()); |
| ... | ... | @@ -16884,7 +16840,7 @@ fn unionInit( |
| 16884 | 16840 | const field = union_ty.unionFields().values()[field_index]; |
| 16885 | 16841 | const init = try sema.coerce(block, field.ty, uncasted_init, init_src); |
| 16886 | 16842 | |
| 16887 | | if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| { |
| 16843 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 16888 | 16844 | const tag_ty = union_ty.unionTagTypeHypothetical(); |
| 16889 | 16845 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name).?); |
| 16890 | 16846 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| ... | ... | @@ -16916,7 +16872,7 @@ fn zirStructInit( |
| 16916 | 16872 | const first_field_type_data = zir_datas[first_item.field_type].pl_node; |
| 16917 | 16873 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; |
| 16918 | 16874 | const resolved_ty = try sema.resolveType(block, src, first_field_type_extra.container_type); |
| 16919 | | try sema.resolveTypeLayout(block, src, resolved_ty); |
| 16875 | try sema.resolveTypeLayout(resolved_ty); |
| 16920 | 16876 | |
| 16921 | 16877 | if (resolved_ty.zigTypeTag() == .Struct) { |
| 16922 | 16878 | // This logic must be synchronized with that in `zirStructInitEmpty`. |
| ... | ... | @@ -16962,7 +16918,7 @@ fn zirStructInit( |
| 16962 | 16918 | found_fields[field_index] = item.data.field_type; |
| 16963 | 16919 | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| 16964 | 16920 | if (!is_packed) if (resolved_ty.structFieldValueComptime(field_index)) |default_value| { |
| 16965 | | const init_val = (try sema.resolveMaybeUndefVal(block, field_src, field_inits[field_index])) orelse { |
| 16921 | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { |
| 16966 | 16922 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); |
| 16967 | 16923 | }; |
| 16968 | 16924 | |
| ... | ... | @@ -16990,10 +16946,9 @@ fn zirStructInit( |
| 16990 | 16946 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| 16991 | 16947 | |
| 16992 | 16948 | const init_inst = try sema.resolveInst(item.data.init); |
| 16993 | | if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| { |
| 16949 | if (try sema.resolveMaybeUndefVal(init_inst)) |val| { |
| 16994 | 16950 | return sema.addConstantMaybeRef( |
| 16995 | 16951 | block, |
| 16996 | | src, |
| 16997 | 16952 | resolved_ty, |
| 16998 | 16953 | try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }), |
| 16999 | 16954 | is_ref, |
| ... | ... | @@ -17107,7 +17062,7 @@ fn finishStructInit( |
| 17107 | 17062 | } |
| 17108 | 17063 | |
| 17109 | 17064 | const is_comptime = for (field_inits) |field_init| { |
| 17110 | | if (!(try sema.isComptimeKnown(block, dest_src, field_init))) { |
| 17065 | if (!(try sema.isComptimeKnown(field_init))) { |
| 17111 | 17066 | break false; |
| 17112 | 17067 | } |
| 17113 | 17068 | } else true; |
| ... | ... | @@ -17115,14 +17070,14 @@ fn finishStructInit( |
| 17115 | 17070 | if (is_comptime) { |
| 17116 | 17071 | const values = try sema.arena.alloc(Value, field_inits.len); |
| 17117 | 17072 | for (field_inits) |field_init, i| { |
| 17118 | | values[i] = (sema.resolveMaybeUndefVal(block, dest_src, field_init) catch unreachable).?; |
| 17073 | values[i] = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?; |
| 17119 | 17074 | } |
| 17120 | 17075 | const struct_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 17121 | | return sema.addConstantMaybeRef(block, dest_src, struct_ty, struct_val, is_ref); |
| 17076 | return sema.addConstantMaybeRef(block, struct_ty, struct_val, is_ref); |
| 17122 | 17077 | } |
| 17123 | 17078 | |
| 17124 | 17079 | if (is_ref) { |
| 17125 | | try sema.resolveStructLayout(block, dest_src, struct_ty); |
| 17080 | try sema.resolveStructLayout(struct_ty); |
| 17126 | 17081 | const target = sema.mod.getTarget(); |
| 17127 | 17082 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 17128 | 17083 | .pointee_type = struct_ty, |
| ... | ... | @@ -17197,8 +17152,7 @@ fn zirStructInitAnon( |
| 17197 | 17152 | }; |
| 17198 | 17153 | return sema.failWithOwnedErrorMsg(msg); |
| 17199 | 17154 | } |
| 17200 | | const init_src = src; // TODO better source location |
| 17201 | | if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| { |
| 17155 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 17202 | 17156 | values[i] = init_val; |
| 17203 | 17157 | } else { |
| 17204 | 17158 | values[i] = Value.initTag(.unreachable_value); |
| ... | ... | @@ -17216,7 +17170,7 @@ fn zirStructInitAnon( |
| 17216 | 17170 | |
| 17217 | 17171 | const runtime_index = opt_runtime_index orelse { |
| 17218 | 17172 | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 17219 | | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); |
| 17173 | return sema.addConstantMaybeRef(block, tuple_ty, tuple_val, is_ref); |
| 17220 | 17174 | }; |
| 17221 | 17175 | |
| 17222 | 17176 | sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) { |
| ... | ... | @@ -17303,7 +17257,7 @@ fn zirArrayInit( |
| 17303 | 17257 | |
| 17304 | 17258 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { |
| 17305 | 17259 | const arg_src = src; // TODO better source location |
| 17306 | | const comptime_known = try sema.isComptimeKnown(block, arg_src, arg); |
| 17260 | const comptime_known = try sema.isComptimeKnown(arg); |
| 17307 | 17261 | if (!comptime_known) break arg_src; |
| 17308 | 17262 | } else null; |
| 17309 | 17263 | |
| ... | ... | @@ -17312,11 +17266,11 @@ fn zirArrayInit( |
| 17312 | 17266 | |
| 17313 | 17267 | for (resolved_args) |arg, i| { |
| 17314 | 17268 | // We checked that all args are comptime above. |
| 17315 | | elem_vals[i] = (sema.resolveMaybeUndefVal(block, src, arg) catch unreachable).?; |
| 17269 | elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?; |
| 17316 | 17270 | } |
| 17317 | 17271 | |
| 17318 | 17272 | const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals); |
| 17319 | | return sema.addConstantMaybeRef(block, src, array_ty, array_val, is_ref); |
| 17273 | return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref); |
| 17320 | 17274 | }; |
| 17321 | 17275 | |
| 17322 | 17276 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | ... | @@ -17395,7 +17349,7 @@ fn zirArrayInitAnon( |
| 17395 | 17349 | }; |
| 17396 | 17350 | return sema.failWithOwnedErrorMsg(msg); |
| 17397 | 17351 | } |
| 17398 | | if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| { |
| 17352 | if (try sema.resolveMaybeUndefVal(elem)) |val| { |
| 17399 | 17353 | values[i] = val; |
| 17400 | 17354 | } else { |
| 17401 | 17355 | values[i] = Value.initTag(.unreachable_value); |
| ... | ... | @@ -17412,7 +17366,7 @@ fn zirArrayInitAnon( |
| 17412 | 17366 | |
| 17413 | 17367 | const runtime_src = opt_runtime_src orelse { |
| 17414 | 17368 | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 17415 | | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); |
| 17369 | return sema.addConstantMaybeRef(block, tuple_ty, tuple_val, is_ref); |
| 17416 | 17370 | }; |
| 17417 | 17371 | |
| 17418 | 17372 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | ... | @@ -17451,14 +17405,13 @@ fn zirArrayInitAnon( |
| 17451 | 17405 | fn addConstantMaybeRef( |
| 17452 | 17406 | sema: *Sema, |
| 17453 | 17407 | block: *Block, |
| 17454 | | src: LazySrcLoc, |
| 17455 | 17408 | ty: Type, |
| 17456 | 17409 | val: Value, |
| 17457 | 17410 | is_ref: bool, |
| 17458 | 17411 | ) !Air.Inst.Ref { |
| 17459 | 17412 | if (!is_ref) return sema.addConstant(ty, val); |
| 17460 | 17413 | |
| 17461 | | var anon_decl = try block.startAnonDecl(src); |
| 17414 | var anon_decl = try block.startAnonDecl(); |
| 17462 | 17415 | defer anon_decl.deinit(); |
| 17463 | 17416 | const decl = try anon_decl.finish( |
| 17464 | 17417 | try ty.copy(anon_decl.arena()), |
| ... | ... | @@ -17499,7 +17452,7 @@ fn fieldType( |
| 17499 | 17452 | ) CompileError!Air.Inst.Ref { |
| 17500 | 17453 | var cur_ty = aggregate_ty; |
| 17501 | 17454 | while (true) { |
| 17502 | | const resolved_ty = try sema.resolveTypeFields(block, ty_src, cur_ty); |
| 17455 | const resolved_ty = try sema.resolveTypeFields(cur_ty); |
| 17503 | 17456 | cur_ty = resolved_ty; |
| 17504 | 17457 | switch (cur_ty.zigTypeTag()) { |
| 17505 | 17458 | .Struct => { |
| ... | ... | @@ -17538,18 +17491,13 @@ fn fieldType( |
| 17538 | 17491 | } |
| 17539 | 17492 | } |
| 17540 | 17493 | |
| 17541 | | fn zirErrorReturnTrace( |
| 17542 | | sema: *Sema, |
| 17543 | | block: *Block, |
| 17544 | | extended: Zir.Inst.Extended.InstData, |
| 17545 | | ) CompileError!Air.Inst.Ref { |
| 17546 | | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); |
| 17547 | | return sema.getErrorReturnTrace(block, src); |
| 17494 | fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 17495 | return sema.getErrorReturnTrace(block); |
| 17548 | 17496 | } |
| 17549 | 17497 | |
| 17550 | | fn getErrorReturnTrace(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!Air.Inst.Ref { |
| 17551 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 17552 | | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 17498 | fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 17499 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 17500 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 17553 | 17501 | const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 17554 | 17502 | |
| 17555 | 17503 | // TODO implement this feature in all the backends and then delete this check. |
| ... | ... | @@ -17592,9 +17540,8 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17592 | 17540 | |
| 17593 | 17541 | fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17594 | 17542 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 17595 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 17596 | 17543 | const operand = try sema.resolveInst(inst_data.operand); |
| 17597 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 17544 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 17598 | 17545 | if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1)); |
| 17599 | 17546 | const bool_ints = [2]Air.Inst.Ref{ .zero, .one }; |
| 17600 | 17547 | return bool_ints[@boolToInt(val.toBool())]; |
| ... | ... | @@ -17650,7 +17597,7 @@ fn zirUnaryMath( |
| 17650 | 17597 | const scalar_ty = operand_ty.scalarType(); |
| 17651 | 17598 | const vec_len = operand_ty.vectorLen(); |
| 17652 | 17599 | const result_ty = try Type.vector(sema.arena, vec_len, scalar_ty); |
| 17653 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 17600 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 17654 | 17601 | if (val.isUndef()) |
| 17655 | 17602 | return sema.addConstUndef(result_ty); |
| 17656 | 17603 | |
| ... | ... | @@ -17670,7 +17617,7 @@ fn zirUnaryMath( |
| 17670 | 17617 | return block.addUnOp(air_tag, operand); |
| 17671 | 17618 | }, |
| 17672 | 17619 | .ComptimeFloat, .Float => { |
| 17673 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| { |
| 17620 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 17674 | 17621 | if (operand_val.isUndef()) |
| 17675 | 17622 | return sema.addConstUndef(operand_ty); |
| 17676 | 17623 | const result_val = try eval(operand_val, operand_ty, sema.arena, target); |
| ... | ... | @@ -17692,7 +17639,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17692 | 17639 | const operand_ty = sema.typeOf(operand); |
| 17693 | 17640 | const mod = sema.mod; |
| 17694 | 17641 | |
| 17695 | | try sema.resolveTypeLayout(block, operand_src, operand_ty); |
| 17642 | try sema.resolveTypeLayout(operand_ty); |
| 17696 | 17643 | const enum_ty = switch (operand_ty.zigTypeTag()) { |
| 17697 | 17644 | .EnumLiteral => { |
| 17698 | 17645 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); |
| ... | ... | @@ -17749,7 +17696,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17749 | 17696 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); |
| 17750 | 17697 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 17751 | 17698 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 17752 | | const type_info_ty = try sema.resolveBuiltinTypeFields(block, src, "Type"); |
| 17699 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 17753 | 17700 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 17754 | 17701 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 17755 | 17702 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| ... | ... | @@ -17827,18 +17774,18 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17827 | 17774 | const is_allowzero_val = struct_val[6]; |
| 17828 | 17775 | const sentinel_val = struct_val[7]; |
| 17829 | 17776 | |
| 17830 | | if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) { |
| 17777 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 17831 | 17778 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| 17832 | 17779 | } |
| 17833 | | const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?); |
| 17780 | const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?); |
| 17834 | 17781 | |
| 17835 | 17782 | var buffer: Value.ToTypeBuffer = undefined; |
| 17836 | 17783 | const unresolved_elem_ty = child_val.toType(&buffer); |
| 17837 | 17784 | const elem_ty = if (abi_align == 0) |
| 17838 | 17785 | unresolved_elem_ty |
| 17839 | 17786 | else t: { |
| 17840 | | const elem_ty = try sema.resolveTypeFields(block, src, unresolved_elem_ty); |
| 17841 | | try sema.resolveTypeLayout(block, src, elem_ty); |
| 17787 | const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty); |
| 17788 | try sema.resolveTypeLayout(elem_ty); |
| 17842 | 17789 | break :t elem_ty; |
| 17843 | 17790 | }; |
| 17844 | 17791 | |
| ... | ... | @@ -17872,7 +17819,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17872 | 17819 | } else if (ptr_size == .Many and elem_ty.zigTypeTag() == .Opaque) { |
| 17873 | 17820 | return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{}); |
| 17874 | 17821 | } else if (ptr_size == .C) { |
| 17875 | | if (!try sema.validateExternType(block, src, elem_ty, .other)) { |
| 17822 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 17876 | 17823 | const msg = msg: { |
| 17877 | 17824 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); |
| 17878 | 17825 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -18119,7 +18066,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18119 | 18066 | sema.mod, |
| 18120 | 18067 | ); |
| 18121 | 18068 | |
| 18122 | | if (!try sema.intFitsInType(block, src, value_val, enum_obj.tag_ty, null)) { |
| 18069 | if (!try sema.intFitsInType(value_val, enum_obj.tag_ty, null)) { |
| 18123 | 18070 | // TODO: better source location |
| 18124 | 18071 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ |
| 18125 | 18072 | field_name, |
| ... | ... | @@ -18309,7 +18256,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18309 | 18256 | var buffer: Value.ToTypeBuffer = undefined; |
| 18310 | 18257 | gop.value_ptr.* = .{ |
| 18311 | 18258 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), |
| 18312 | | .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?), |
| 18259 | .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?), |
| 18313 | 18260 | }; |
| 18314 | 18261 | } |
| 18315 | 18262 | |
| ... | ... | @@ -18359,7 +18306,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18359 | 18306 | } |
| 18360 | 18307 | |
| 18361 | 18308 | const alignment = alignment: { |
| 18362 | | if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) { |
| 18309 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 18363 | 18310 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| 18364 | 18311 | } |
| 18365 | 18312 | const alignment = @intCast(u29, alignment_val.toUnsignedInt(target)); |
| ... | ... | @@ -18571,10 +18518,10 @@ fn reifyStruct( |
| 18571 | 18518 | // alignment: comptime_int, |
| 18572 | 18519 | const alignment_val = field_struct_val[4]; |
| 18573 | 18520 | |
| 18574 | | if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) { |
| 18521 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 18575 | 18522 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| 18576 | 18523 | } |
| 18577 | | const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?); |
| 18524 | const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?); |
| 18578 | 18525 | |
| 18579 | 18526 | if (layout == .Packed and abi_align != 0) { |
| 18580 | 18527 | return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{}); |
| ... | ... | @@ -18614,7 +18561,7 @@ fn reifyStruct( |
| 18614 | 18561 | struct_obj.status = .layout_wip; |
| 18615 | 18562 | |
| 18616 | 18563 | for (struct_obj.fields.values()) |field, index| { |
| 18617 | | sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) { |
| 18564 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 18618 | 18565 | error.AnalysisFail => { |
| 18619 | 18566 | const msg = sema.err orelse return err; |
| 18620 | 18567 | try sema.addFieldErrNote(struct_ty, index, msg, "while checking this field", .{}); |
| ... | ... | @@ -18697,7 +18644,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18697 | 18644 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 18698 | 18645 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 18699 | 18646 | |
| 18700 | | var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded); |
| 18647 | var anon_decl = try block.startAnonDecl(); |
| 18701 | 18648 | defer anon_decl.deinit(); |
| 18702 | 18649 | |
| 18703 | 18650 | const bytes = try ty.nameAllocArena(anon_decl.arena(), sema.mod); |
| ... | ... | @@ -18735,7 +18682,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18735 | 18682 | _ = try sema.checkIntType(block, ty_src, dest_ty); |
| 18736 | 18683 | try sema.checkFloatType(block, operand_src, operand_ty); |
| 18737 | 18684 | |
| 18738 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 18685 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18739 | 18686 | const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty); |
| 18740 | 18687 | return sema.addConstant(dest_ty, result_val); |
| 18741 | 18688 | } else if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| ... | ... | @@ -18774,9 +18721,9 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18774 | 18721 | try sema.checkFloatType(block, ty_src, dest_ty); |
| 18775 | 18722 | _ = try sema.checkIntType(block, operand_src, operand_ty); |
| 18776 | 18723 | |
| 18777 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 18724 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18778 | 18725 | const target = sema.mod.getTarget(); |
| 18779 | | const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema.kit(block, operand_src)); |
| 18726 | const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema); |
| 18780 | 18727 | return sema.addConstant(dest_ty, result_val); |
| 18781 | 18728 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| 18782 | 18729 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); |
| ... | ... | @@ -18801,7 +18748,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18801 | 18748 | const elem_ty = ptr_ty.elemType2(); |
| 18802 | 18749 | try sema.checkPtrType(block, type_src, ptr_ty); |
| 18803 | 18750 | const target = sema.mod.getTarget(); |
| 18804 | | const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema.kit(block, src)); |
| 18751 | const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema); |
| 18805 | 18752 | |
| 18806 | 18753 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 18807 | 18754 | const addr = val.toUnsignedInt(target); |
| ... | ... | @@ -18819,7 +18766,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18819 | 18766 | } |
| 18820 | 18767 | |
| 18821 | 18768 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 18822 | | if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, elem_ty)) { |
| 18769 | if (block.wantSafety() and try sema.typeHasRuntimeBits(elem_ty)) { |
| 18823 | 18770 | if (!ptr_ty.isAllowzeroPtr()) { |
| 18824 | 18771 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); |
| 18825 | 18772 | try sema.addSafetyCheck(block, is_non_zero, .cast_to_null); |
| ... | ... | @@ -18961,11 +18908,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18961 | 18908 | operand; |
| 18962 | 18909 | |
| 18963 | 18910 | const dest_elem_ty = dest_ty.elemType2(); |
| 18964 | | try sema.resolveTypeLayout(block, dest_ty_src, dest_elem_ty); |
| 18911 | try sema.resolveTypeLayout(dest_elem_ty); |
| 18965 | 18912 | const dest_align = dest_ty.ptrAlignment(target); |
| 18966 | 18913 | |
| 18967 | 18914 | const operand_elem_ty = operand_ty.elemType2(); |
| 18968 | | try sema.resolveTypeLayout(block, operand_src, operand_elem_ty); |
| 18915 | try sema.resolveTypeLayout(operand_elem_ty); |
| 18969 | 18916 | const operand_align = operand_ty.ptrAlignment(target); |
| 18970 | 18917 | |
| 18971 | 18918 | // If the destination is less aligned than the source, preserve the source alignment |
| ... | ... | @@ -19009,7 +18956,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19009 | 18956 | return sema.failWithOwnedErrorMsg(msg); |
| 19010 | 18957 | } |
| 19011 | 18958 | |
| 19012 | | if (try sema.resolveMaybeUndefVal(block, operand_src, ptr)) |operand_val| { |
| 18959 | if (try sema.resolveMaybeUndefVal(ptr)) |operand_val| { |
| 19013 | 18960 | if (!dest_ty.ptrAllowsZero() and operand_val.isUndef()) { |
| 19014 | 18961 | return sema.failWithUseOfUndef(block, operand_src); |
| 19015 | 18962 | } |
| ... | ... | @@ -19024,7 +18971,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19024 | 18971 | |
| 19025 | 18972 | try sema.requireRuntimeBlock(block, src, null); |
| 19026 | 18973 | if (block.wantSafety() and operand_ty.ptrAllowsZero() and !dest_ty.ptrAllowsZero() and |
| 19027 | | try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2())) |
| 18974 | try sema.typeHasRuntimeBits(dest_ty.elemType2())) |
| 19028 | 18975 | { |
| 19029 | 18976 | const ptr_int = try block.addUnOp(.ptrtoint, ptr); |
| 19030 | 18977 | const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); |
| ... | ... | @@ -19063,13 +19010,13 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19063 | 19010 | const target = sema.mod.getTarget(); |
| 19064 | 19011 | const dest_info = dest_scalar_ty.intInfo(target); |
| 19065 | 19012 | |
| 19066 | | if (try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty)) |val| { |
| 19013 | if (try sema.typeHasOnePossibleValue(dest_ty)) |val| { |
| 19067 | 19014 | return sema.addConstant(dest_ty, val); |
| 19068 | 19015 | } |
| 19069 | 19016 | |
| 19070 | 19017 | if (operand_scalar_ty.zigTypeTag() != .ComptimeInt) { |
| 19071 | 19018 | const operand_info = operand_ty.intInfo(target); |
| 19072 | | if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| { |
| 19019 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 19073 | 19020 | return sema.addConstant(operand_ty, val); |
| 19074 | 19021 | } |
| 19075 | 19022 | |
| ... | ... | @@ -19099,7 +19046,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19099 | 19046 | } |
| 19100 | 19047 | } |
| 19101 | 19048 | |
| 19102 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19049 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19103 | 19050 | if (val.isUndef()) return sema.addConstUndef(dest_ty); |
| 19104 | 19051 | if (!is_vector) { |
| 19105 | 19052 | return sema.addConstant( |
| ... | ... | @@ -19152,7 +19099,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 19152 | 19099 | |
| 19153 | 19100 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| 19154 | 19101 | if (block.wantSafety() and dest_align > 1 and |
| 19155 | | try sema.typeHasRuntimeBits(block, sema.src, ptr_info.pointee_type)) |
| 19102 | try sema.typeHasRuntimeBits(ptr_info.pointee_type)) |
| 19156 | 19103 | { |
| 19157 | 19104 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 19158 | 19105 | val_payload.* = .{ |
| ... | ... | @@ -19192,11 +19139,11 @@ fn zirBitCount( |
| 19192 | 19139 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19193 | 19140 | const operand = try sema.resolveInst(inst_data.operand); |
| 19194 | 19141 | const operand_ty = sema.typeOf(operand); |
| 19195 | | _ = try checkIntOrVector(sema, block, operand, operand_src); |
| 19142 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| 19196 | 19143 | const target = sema.mod.getTarget(); |
| 19197 | 19144 | const bits = operand_ty.intInfo(target).bits; |
| 19198 | 19145 | |
| 19199 | | if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| { |
| 19146 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 19200 | 19147 | return sema.addConstant(operand_ty, val); |
| 19201 | 19148 | } |
| 19202 | 19149 | |
| ... | ... | @@ -19205,7 +19152,7 @@ fn zirBitCount( |
| 19205 | 19152 | .Vector => { |
| 19206 | 19153 | const vec_len = operand_ty.vectorLen(); |
| 19207 | 19154 | const result_ty = try Type.vector(sema.arena, vec_len, result_scalar_ty); |
| 19208 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19155 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19209 | 19156 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 19210 | 19157 | |
| 19211 | 19158 | var elem_buf: Value.ElemValueBuffer = undefined; |
| ... | ... | @@ -19226,7 +19173,7 @@ fn zirBitCount( |
| 19226 | 19173 | } |
| 19227 | 19174 | }, |
| 19228 | 19175 | .Int => { |
| 19229 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19176 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19230 | 19177 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); |
| 19231 | 19178 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target)); |
| 19232 | 19179 | } else { |
| ... | ... | @@ -19256,13 +19203,13 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19256 | 19203 | ); |
| 19257 | 19204 | } |
| 19258 | 19205 | |
| 19259 | | if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| { |
| 19206 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 19260 | 19207 | return sema.addConstant(operand_ty, val); |
| 19261 | 19208 | } |
| 19262 | 19209 | |
| 19263 | 19210 | switch (operand_ty.zigTypeTag()) { |
| 19264 | 19211 | .Int => { |
| 19265 | | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19212 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19266 | 19213 | if (val.isUndef()) return sema.addConstUndef(operand_ty); |
| 19267 | 19214 | const result_val = try val.byteSwap(operand_ty, target, sema.arena); |
| 19268 | 19215 | return sema.addConstant(operand_ty, result_val); |
| ... | ... | @@ -19272,7 +19219,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19272 | 19219 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| 19273 | 19220 | }, |
| 19274 | 19221 | .Vector => { |
| 19275 | | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19222 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19276 | 19223 | if (val.isUndef()) |
| 19277 | 19224 | return sema.addConstUndef(operand_ty); |
| 19278 | 19225 | |
| ... | ... | @@ -19304,14 +19251,14 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19304 | 19251 | const operand_ty = sema.typeOf(operand); |
| 19305 | 19252 | _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); |
| 19306 | 19253 | |
| 19307 | | if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| { |
| 19254 | if (try sema.typeHasOnePossibleValue(operand_ty)) |val| { |
| 19308 | 19255 | return sema.addConstant(operand_ty, val); |
| 19309 | 19256 | } |
| 19310 | 19257 | |
| 19311 | 19258 | const target = sema.mod.getTarget(); |
| 19312 | 19259 | switch (operand_ty.zigTypeTag()) { |
| 19313 | 19260 | .Int, .ComptimeInt => { |
| 19314 | | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19261 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19315 | 19262 | if (val.isUndef()) return sema.addConstUndef(operand_ty); |
| 19316 | 19263 | const result_val = try val.bitReverse(operand_ty, target, sema.arena); |
| 19317 | 19264 | return sema.addConstant(operand_ty, result_val); |
| ... | ... | @@ -19321,7 +19268,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19321 | 19268 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| 19322 | 19269 | }, |
| 19323 | 19270 | .Vector => { |
| 19324 | | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 19271 | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19325 | 19272 | if (val.isUndef()) |
| 19326 | 19273 | return sema.addConstUndef(operand_ty); |
| 19327 | 19274 | |
| ... | ... | @@ -19346,12 +19293,12 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19346 | 19293 | } |
| 19347 | 19294 | |
| 19348 | 19295 | fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19349 | | const offset = try bitOffsetOf(sema, block, inst); |
| 19296 | const offset = try sema.bitOffsetOf(block, inst); |
| 19350 | 19297 | return sema.addIntUnsigned(Type.comptime_int, offset); |
| 19351 | 19298 | } |
| 19352 | 19299 | |
| 19353 | 19300 | fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19354 | | const offset = try bitOffsetOf(sema, block, inst); |
| 19301 | const offset = try sema.bitOffsetOf(block, inst); |
| 19355 | 19302 | // TODO reminder to make this a compile error for packed structs |
| 19356 | 19303 | return sema.addIntUnsigned(Type.comptime_int, offset / 8); |
| 19357 | 19304 | } |
| ... | ... | @@ -19368,7 +19315,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 19368 | 19315 | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime-known"); |
| 19369 | 19316 | const target = sema.mod.getTarget(); |
| 19370 | 19317 | |
| 19371 | | try sema.resolveTypeLayout(block, lhs_src, ty); |
| 19318 | try sema.resolveTypeLayout(ty); |
| 19372 | 19319 | switch (ty.zigTypeTag()) { |
| 19373 | 19320 | .Struct => {}, |
| 19374 | 19321 | else => { |
| ... | ... | @@ -19758,8 +19705,8 @@ fn checkSimdBinOp( |
| 19758 | 19705 | .len = vec_len, |
| 19759 | 19706 | .lhs = lhs, |
| 19760 | 19707 | .rhs = rhs, |
| 19761 | | .lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs), |
| 19762 | | .rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs), |
| 19708 | .lhs_val = try sema.resolveMaybeUndefVal(lhs), |
| 19709 | .rhs_val = try sema.resolveMaybeUndefVal(rhs), |
| 19763 | 19710 | .result_ty = result_ty, |
| 19764 | 19711 | .scalar_ty = result_ty.scalarType(), |
| 19765 | 19712 | }; |
| ... | ... | @@ -19830,7 +19777,7 @@ fn resolveExportOptions( |
| 19830 | 19777 | src: LazySrcLoc, |
| 19831 | 19778 | zir_ref: Zir.Inst.Ref, |
| 19832 | 19779 | ) CompileError!std.builtin.ExportOptions { |
| 19833 | | const export_options_ty = try sema.getBuiltinType(block, src, "ExportOptions"); |
| 19780 | const export_options_ty = try sema.getBuiltinType("ExportOptions"); |
| 19834 | 19781 | const air_ref = try sema.resolveInst(zir_ref); |
| 19835 | 19782 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 19836 | 19783 | |
| ... | ... | @@ -19885,7 +19832,7 @@ fn resolveBuiltinEnum( |
| 19885 | 19832 | comptime name: []const u8, |
| 19886 | 19833 | reason: []const u8, |
| 19887 | 19834 | ) CompileError!@field(std.builtin, name) { |
| 19888 | | const ty = try sema.getBuiltinType(block, src, name); |
| 19835 | const ty = try sema.getBuiltinType(name); |
| 19889 | 19836 | const air_ref = try sema.resolveInst(zir_ref); |
| 19890 | 19837 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 19891 | 19838 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| ... | ... | @@ -19899,7 +19846,7 @@ fn resolveAtomicOrder( |
| 19899 | 19846 | zir_ref: Zir.Inst.Ref, |
| 19900 | 19847 | reason: []const u8, |
| 19901 | 19848 | ) CompileError!std.builtin.AtomicOrder { |
| 19902 | | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicOrder", reason); |
| 19849 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); |
| 19903 | 19850 | } |
| 19904 | 19851 | |
| 19905 | 19852 | fn resolveAtomicRmwOp( |
| ... | ... | @@ -19908,7 +19855,7 @@ fn resolveAtomicRmwOp( |
| 19908 | 19855 | src: LazySrcLoc, |
| 19909 | 19856 | zir_ref: Zir.Inst.Ref, |
| 19910 | 19857 | ) CompileError!std.builtin.AtomicRmwOp { |
| 19911 | | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known"); |
| 19858 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known"); |
| 19912 | 19859 | } |
| 19913 | 19860 | |
| 19914 | 19861 | fn zirCmpxchg( |
| ... | ... | @@ -19963,13 +19910,13 @@ fn zirCmpxchg( |
| 19963 | 19910 | const result_ty = try Type.optional(sema.arena, elem_ty); |
| 19964 | 19911 | |
| 19965 | 19912 | // special case zero bit types |
| 19966 | | if ((try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) != null) { |
| 19913 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) { |
| 19967 | 19914 | return sema.addConstant(result_ty, Value.@"null"); |
| 19968 | 19915 | } |
| 19969 | 19916 | |
| 19970 | 19917 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 19971 | | if (try sema.resolveMaybeUndefVal(block, expected_src, expected_value)) |expected_val| { |
| 19972 | | if (try sema.resolveMaybeUndefVal(block, new_value_src, new_value)) |new_val| { |
| 19918 | if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| { |
| 19919 | if (try sema.resolveMaybeUndefVal(new_value)) |new_val| { |
| 19973 | 19920 | if (expected_val.isUndef() or new_val.isUndef()) { |
| 19974 | 19921 | // TODO: this should probably cause the memory stored at the pointer |
| 19975 | 19922 | // to become undef as well |
| ... | ... | @@ -20018,7 +19965,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 20018 | 19965 | .len = len, |
| 20019 | 19966 | .elem_type = scalar_ty, |
| 20020 | 19967 | }); |
| 20021 | | if (try sema.resolveMaybeUndefVal(block, scalar_src, scalar)) |scalar_val| { |
| 19968 | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { |
| 20022 | 19969 | if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty); |
| 20023 | 19970 | |
| 20024 | 19971 | return sema.addConstant( |
| ... | ... | @@ -20070,7 +20017,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20070 | 20017 | return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{}); |
| 20071 | 20018 | } |
| 20072 | 20019 | |
| 20073 | | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| { |
| 20020 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 20074 | 20021 | if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty); |
| 20075 | 20022 | |
| 20076 | 20023 | var accum: Value = try operand_val.elemValue(sema.mod, sema.arena, 0); |
| ... | ... | @@ -20084,7 +20031,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20084 | 20031 | .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target), |
| 20085 | 20032 | .Min => accum = accum.numberMin(elem_val, target), |
| 20086 | 20033 | .Max => accum = accum.numberMax(elem_val, target), |
| 20087 | | .Add => accum = try sema.numberAddWrap(block, operand_src, accum, elem_val, scalar_ty), |
| 20034 | .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty), |
| 20088 | 20035 | .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target), |
| 20089 | 20036 | } |
| 20090 | 20037 | } |
| ... | ... | @@ -20222,8 +20169,8 @@ fn analyzeShuffle( |
| 20222 | 20169 | } |
| 20223 | 20170 | } |
| 20224 | 20171 | |
| 20225 | | if (try sema.resolveMaybeUndefVal(block, a_src, a)) |a_val| { |
| 20226 | | if (try sema.resolveMaybeUndefVal(block, b_src, b)) |b_val| { |
| 20172 | if (try sema.resolveMaybeUndefVal(a)) |a_val| { |
| 20173 | if (try sema.resolveMaybeUndefVal(b)) |b_val| { |
| 20227 | 20174 | const values = try sema.arena.alloc(Value, mask_len); |
| 20228 | 20175 | |
| 20229 | 20176 | i = 0; |
| ... | ... | @@ -20319,9 +20266,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 20319 | 20266 | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); |
| 20320 | 20267 | const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src); |
| 20321 | 20268 | |
| 20322 | | const maybe_pred = try sema.resolveMaybeUndefVal(block, pred_src, pred); |
| 20323 | | const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a); |
| 20324 | | const maybe_b = try sema.resolveMaybeUndefVal(block, b_src, b); |
| 20269 | const maybe_pred = try sema.resolveMaybeUndefVal(pred); |
| 20270 | const maybe_a = try sema.resolveMaybeUndefVal(a); |
| 20271 | const maybe_b = try sema.resolveMaybeUndefVal(b); |
| 20325 | 20272 | |
| 20326 | 20273 | const runtime_src = if (maybe_pred) |pred_val| rs: { |
| 20327 | 20274 | if (pred_val.isUndef()) return sema.addConstUndef(vec_ty); |
| ... | ... | @@ -20405,7 +20352,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20405 | 20352 | else => {}, |
| 20406 | 20353 | } |
| 20407 | 20354 | |
| 20408 | | if (try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) |val| { |
| 20355 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { |
| 20409 | 20356 | return sema.addConstant(elem_ty, val); |
| 20410 | 20357 | } |
| 20411 | 20358 | |
| ... | ... | @@ -20462,12 +20409,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20462 | 20409 | } |
| 20463 | 20410 | |
| 20464 | 20411 | // special case zero bit types |
| 20465 | | if (try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) |val| { |
| 20412 | if (try sema.typeHasOnePossibleValue(elem_ty)) |val| { |
| 20466 | 20413 | return sema.addConstant(elem_ty, val); |
| 20467 | 20414 | } |
| 20468 | 20415 | |
| 20469 | 20416 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 20470 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand); |
| 20417 | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 20471 | 20418 | const operand_val = maybe_operand_val orelse { |
| 20472 | 20419 | try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); |
| 20473 | 20420 | break :rs operand_src; |
| ... | ... | @@ -20479,8 +20426,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20479 | 20426 | const new_val = switch (op) { |
| 20480 | 20427 | // zig fmt: off |
| 20481 | 20428 | .Xchg => operand_val, |
| 20482 | | .Add => try sema.numberAddWrap(block, src, stored_val, operand_val, elem_ty), |
| 20483 | | .Sub => try sema.numberSubWrap(block, src, stored_val, operand_val, elem_ty), |
| 20429 | .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty), |
| 20430 | .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty), |
| 20484 | 20431 | .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target), |
| 20485 | 20432 | .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target), |
| 20486 | 20433 | .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target), |
| ... | ... | @@ -20559,9 +20506,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20559 | 20506 | |
| 20560 | 20507 | const target = sema.mod.getTarget(); |
| 20561 | 20508 | |
| 20562 | | const maybe_mulend1 = try sema.resolveMaybeUndefVal(block, mulend1_src, mulend1); |
| 20563 | | const maybe_mulend2 = try sema.resolveMaybeUndefVal(block, mulend2_src, mulend2); |
| 20564 | | const maybe_addend = try sema.resolveMaybeUndefVal(block, addend_src, addend); |
| 20509 | const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1); |
| 20510 | const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2); |
| 20511 | const maybe_addend = try sema.resolveMaybeUndefVal(addend); |
| 20565 | 20512 | |
| 20566 | 20513 | switch (ty.zigTypeTag()) { |
| 20567 | 20514 | .ComptimeFloat, .Float, .Vector => {}, |
| ... | ... | @@ -20618,7 +20565,7 @@ fn resolveCallOptions( |
| 20618 | 20565 | func: Air.Inst.Ref, |
| 20619 | 20566 | func_src: LazySrcLoc, |
| 20620 | 20567 | ) CompileError!std.builtin.CallOptions.Modifier { |
| 20621 | | const call_options_ty = try sema.getBuiltinType(block, src, "CallOptions"); |
| 20568 | const call_options_ty = try sema.getBuiltinType("CallOptions"); |
| 20622 | 20569 | const air_ref = try sema.resolveInst(zir_ref); |
| 20623 | 20570 | const options = try sema.coerce(block, call_options_ty, air_ref, src); |
| 20624 | 20571 | |
| ... | ... | @@ -20767,7 +20714,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 20767 | 20714 | if (struct_ty.zigTypeTag() != .Struct) { |
| 20768 | 20715 | return sema.fail(block, ty_src, "expected struct type, found '{}'", .{struct_ty.fmt(sema.mod)}); |
| 20769 | 20716 | } |
| 20770 | | try sema.resolveTypeLayout(block, ty_src, struct_ty); |
| 20717 | try sema.resolveTypeLayout(struct_ty); |
| 20771 | 20718 | |
| 20772 | 20719 | const field_index = if (struct_ty.isTuple()) blk: { |
| 20773 | 20720 | if (mem.eql(u8, field_name, "len")) { |
| ... | ... | @@ -20981,7 +20928,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 20981 | 20928 | const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: { |
| 20982 | 20929 | if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src; |
| 20983 | 20930 | if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| { |
| 20984 | | if (try sema.resolveMaybeUndefVal(block, value_src, value)) |val| { |
| 20931 | if (try sema.resolveMaybeUndefVal(value)) |val| { |
| 20985 | 20932 | _ = len_val; |
| 20986 | 20933 | _ = val; |
| 20987 | 20934 | return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{}); |
| ... | ... | @@ -21076,7 +21023,7 @@ fn zirVarExtended( |
| 21076 | 21023 | else |
| 21077 | 21024 | uncasted_init; |
| 21078 | 21025 | |
| 21079 | | break :blk (try sema.resolveMaybeUndefVal(block, init_src, init)) orelse |
| 21026 | break :blk (try sema.resolveMaybeUndefVal(init)) orelse |
| 21080 | 21027 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known"); |
| 21081 | 21028 | } else Value.initTag(.unreachable_value); |
| 21082 | 21029 | |
| ... | ... | @@ -21181,7 +21128,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21181 | 21128 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 21182 | 21129 | extra_index += body.len; |
| 21183 | 21130 | |
| 21184 | | const addrspace_ty = try sema.getBuiltinType(block, addrspace_src, "AddressSpace"); |
| 21131 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 21185 | 21132 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known"); |
| 21186 | 21133 | if (val.tag() == .generic_poison) { |
| 21187 | 21134 | break :blk null; |
| ... | ... | @@ -21229,7 +21176,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21229 | 21176 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 21230 | 21177 | extra_index += body.len; |
| 21231 | 21178 | |
| 21232 | | const cc_ty = try sema.getBuiltinType(block, addrspace_src, "CallingConvention"); |
| 21179 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 21233 | 21180 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known"); |
| 21234 | 21181 | if (val.tag() == .generic_poison) { |
| 21235 | 21182 | break :blk null; |
| ... | ... | @@ -21411,7 +21358,7 @@ fn resolvePrefetchOptions( |
| 21411 | 21358 | src: LazySrcLoc, |
| 21412 | 21359 | zir_ref: Zir.Inst.Ref, |
| 21413 | 21360 | ) CompileError!std.builtin.PrefetchOptions { |
| 21414 | | const options_ty = try sema.getBuiltinType(block, src, "PrefetchOptions"); |
| 21361 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 21415 | 21362 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 21416 | 21363 | const target = sema.mod.getTarget(); |
| 21417 | 21364 | |
| ... | ... | @@ -21476,7 +21423,7 @@ fn resolveExternOptions( |
| 21476 | 21423 | zir_ref: Zir.Inst.Ref, |
| 21477 | 21424 | ) CompileError!std.builtin.ExternOptions { |
| 21478 | 21425 | const options_inst = try sema.resolveInst(zir_ref); |
| 21479 | | const extern_options_ty = try sema.getBuiltinType(block, src, "ExternOptions"); |
| 21426 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 21480 | 21427 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 21481 | 21428 | const mod = sema.mod; |
| 21482 | 21429 | |
| ... | ... | @@ -21619,7 +21566,7 @@ fn validateVarType( |
| 21619 | 21566 | var_ty: Type, |
| 21620 | 21567 | is_extern: bool, |
| 21621 | 21568 | ) CompileError!void { |
| 21622 | | if (try sema.validateRunTimeType(block, src, var_ty, is_extern)) return; |
| 21569 | if (try sema.validateRunTimeType(var_ty, is_extern)) return; |
| 21623 | 21570 | |
| 21624 | 21571 | const mod = sema.mod; |
| 21625 | 21572 | |
| ... | ... | @@ -21640,8 +21587,6 @@ fn validateVarType( |
| 21640 | 21587 | |
| 21641 | 21588 | fn validateRunTimeType( |
| 21642 | 21589 | sema: *Sema, |
| 21643 | | block: *Block, |
| 21644 | | src: LazySrcLoc, |
| 21645 | 21590 | var_ty: Type, |
| 21646 | 21591 | is_extern: bool, |
| 21647 | 21592 | ) CompileError!bool { |
| ... | ... | @@ -21682,14 +21627,14 @@ fn validateRunTimeType( |
| 21682 | 21627 | .Optional => { |
| 21683 | 21628 | var buf: Type.Payload.ElemType = undefined; |
| 21684 | 21629 | const child_ty = ty.optionalChild(&buf); |
| 21685 | | return validateRunTimeType(sema, block, src, child_ty, is_extern); |
| 21630 | return sema.validateRunTimeType(child_ty, is_extern); |
| 21686 | 21631 | }, |
| 21687 | 21632 | .Array, .Vector => ty = ty.elemType(), |
| 21688 | 21633 | |
| 21689 | 21634 | .ErrorUnion => ty = ty.errorUnionPayload(), |
| 21690 | 21635 | |
| 21691 | 21636 | .Struct, .Union => { |
| 21692 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 21637 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 21693 | 21638 | const needs_comptime = try sema.typeRequiresComptime(resolved_ty); |
| 21694 | 21639 | return !needs_comptime; |
| 21695 | 21640 | }, |
| ... | ... | @@ -21709,7 +21654,7 @@ fn explainWhyTypeIsComptime( |
| 21709 | 21654 | var type_set = TypeSet{}; |
| 21710 | 21655 | defer type_set.deinit(sema.gpa); |
| 21711 | 21656 | |
| 21712 | | try sema.resolveTypeFully(block, src, ty); |
| 21657 | try sema.resolveTypeFully(ty); |
| 21713 | 21658 | return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set); |
| 21714 | 21659 | } |
| 21715 | 21660 | |
| ... | ... | @@ -21842,8 +21787,6 @@ const ExternPosition = enum { |
| 21842 | 21787 | /// Calls `resolveTypeLayout` for packed containers. |
| 21843 | 21788 | fn validateExternType( |
| 21844 | 21789 | sema: *Sema, |
| 21845 | | block: *Block, |
| 21846 | | src: LazySrcLoc, |
| 21847 | 21790 | ty: Type, |
| 21848 | 21791 | position: ExternPosition, |
| 21849 | 21792 | ) !bool { |
| ... | ... | @@ -21882,13 +21825,13 @@ fn validateExternType( |
| 21882 | 21825 | }, |
| 21883 | 21826 | .Enum => { |
| 21884 | 21827 | var buf: Type.Payload.Bits = undefined; |
| 21885 | | return sema.validateExternType(block, src, ty.intTagType(&buf), position); |
| 21828 | return sema.validateExternType(ty.intTagType(&buf), position); |
| 21886 | 21829 | }, |
| 21887 | 21830 | .Struct, .Union => switch (ty.containerLayout()) { |
| 21888 | 21831 | .Extern => return true, |
| 21889 | 21832 | .Packed => { |
| 21890 | 21833 | const target = sema.mod.getTarget(); |
| 21891 | | const bit_size = try ty.bitSizeAdvanced(target, sema.kit(block, src)); |
| 21834 | const bit_size = try ty.bitSizeAdvanced(target, sema); |
| 21892 | 21835 | switch (bit_size) { |
| 21893 | 21836 | 8, 16, 32, 64, 128 => return true, |
| 21894 | 21837 | else => return false, |
| ... | ... | @@ -21898,9 +21841,9 @@ fn validateExternType( |
| 21898 | 21841 | }, |
| 21899 | 21842 | .Array => { |
| 21900 | 21843 | if (position == .ret_ty or position == .param_ty) return false; |
| 21901 | | return sema.validateExternType(block, src, ty.elemType2(), .element); |
| 21844 | return sema.validateExternType(ty.elemType2(), .element); |
| 21902 | 21845 | }, |
| 21903 | | .Vector => return sema.validateExternType(block, src, ty.elemType2(), .element), |
| 21846 | .Vector => return sema.validateExternType(ty.elemType2(), .element), |
| 21904 | 21847 | .Optional => return ty.isPtrLikeOptional(), |
| 21905 | 21848 | } |
| 21906 | 21849 | } |
| ... | ... | @@ -22173,9 +22116,9 @@ fn panicWithMsg( |
| 22173 | 22116 | _ = try block.addNoOp(.unreach); |
| 22174 | 22117 | return always_noreturn; |
| 22175 | 22118 | } |
| 22176 | | const panic_fn = try sema.getBuiltin(block, src, "panic"); |
| 22177 | | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 22178 | | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 22119 | const panic_fn = try sema.getBuiltin("panic"); |
| 22120 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 22121 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 22179 | 22122 | const target = mod.getTarget(); |
| 22180 | 22123 | const ptr_stack_trace_ty = try Type.ptr(arena, mod, .{ |
| 22181 | 22124 | .pointee_type = stack_trace_ty, |
| ... | ... | @@ -22224,9 +22167,9 @@ fn panicUnwrapError( |
| 22224 | 22167 | _ = try fail_block.addNoOp(.breakpoint); |
| 22225 | 22168 | _ = try fail_block.addNoOp(.unreach); |
| 22226 | 22169 | } else { |
| 22227 | | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicUnwrapError"); |
| 22170 | const panic_fn = try sema.getBuiltin("panicUnwrapError"); |
| 22228 | 22171 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); |
| 22229 | | const err_return_trace = try sema.getErrorReturnTrace(&fail_block, src); |
| 22172 | const err_return_trace = try sema.getErrorReturnTrace(&fail_block); |
| 22230 | 22173 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| 22231 | 22174 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22232 | 22175 | } |
| ... | ... | @@ -22268,7 +22211,7 @@ fn panicIndexOutOfBounds( |
| 22268 | 22211 | _ = try fail_block.addNoOp(.breakpoint); |
| 22269 | 22212 | _ = try fail_block.addNoOp(.unreach); |
| 22270 | 22213 | } else { |
| 22271 | | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicOutOfBounds"); |
| 22214 | const panic_fn = try sema.getBuiltin("panicOutOfBounds"); |
| 22272 | 22215 | const args: [2]Air.Inst.Ref = .{ index, len }; |
| 22273 | 22216 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22274 | 22217 | } |
| ... | ... | @@ -22311,7 +22254,7 @@ fn panicSentinelMismatch( |
| 22311 | 22254 | } else if (sentinel_ty.isSelfComparable(true)) |
| 22312 | 22255 | try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel) |
| 22313 | 22256 | else { |
| 22314 | | const panic_fn = try sema.getBuiltin(parent_block, src, "checkNonScalarSentinel"); |
| 22257 | const panic_fn = try sema.getBuiltin("checkNonScalarSentinel"); |
| 22315 | 22258 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 22316 | 22259 | _ = try sema.analyzeCall(parent_block, panic_fn, src, src, .auto, false, &args, null); |
| 22317 | 22260 | return; |
| ... | ... | @@ -22340,7 +22283,7 @@ fn panicSentinelMismatch( |
| 22340 | 22283 | _ = try fail_block.addNoOp(.breakpoint); |
| 22341 | 22284 | _ = try fail_block.addNoOp(.unreach); |
| 22342 | 22285 | } else { |
| 22343 | | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicSentinelMismatch"); |
| 22286 | const panic_fn = try sema.getBuiltin("panicSentinelMismatch"); |
| 22344 | 22287 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 22345 | 22288 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22346 | 22289 | } |
| ... | ... | @@ -22377,7 +22320,7 @@ fn safetyPanic( |
| 22377 | 22320 | const msg_inst = msg_inst: { |
| 22378 | 22321 | // TODO instead of making a new decl for every panic in the entire compilation, |
| 22379 | 22322 | // introduce the concept of a reference-counted decl for these |
| 22380 | | var anon_decl = try block.startAnonDecl(src); |
| 22323 | var anon_decl = try block.startAnonDecl(); |
| 22381 | 22324 | defer anon_decl.deinit(); |
| 22382 | 22325 | break :msg_inst try sema.analyzeDeclRef(try anon_decl.finish( |
| 22383 | 22326 | try Type.Tag.array_u8.create(anon_decl.arena(), msg.len), |
| ... | ... | @@ -22526,7 +22469,7 @@ fn fieldVal( |
| 22526 | 22469 | ); |
| 22527 | 22470 | }, |
| 22528 | 22471 | .Union => { |
| 22529 | | const union_ty = try sema.resolveTypeFields(block, src, child_type); |
| 22472 | const union_ty = try sema.resolveTypeFields(child_type); |
| 22530 | 22473 | |
| 22531 | 22474 | if (union_ty.getNamespace()) |namespace| { |
| 22532 | 22475 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| ... | ... | @@ -22627,7 +22570,7 @@ fn fieldPtr( |
| 22627 | 22570 | switch (inner_ty.zigTypeTag()) { |
| 22628 | 22571 | .Array => { |
| 22629 | 22572 | if (mem.eql(u8, field_name, "len")) { |
| 22630 | | var anon_decl = try block.startAnonDecl(src); |
| 22573 | var anon_decl = try block.startAnonDecl(); |
| 22631 | 22574 | defer anon_decl.deinit(); |
| 22632 | 22575 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22633 | 22576 | Type.usize, |
| ... | ... | @@ -22729,7 +22672,7 @@ fn fieldPtr( |
| 22729 | 22672 | }); |
| 22730 | 22673 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 22731 | 22674 | |
| 22732 | | var anon_decl = try block.startAnonDecl(src); |
| 22675 | var anon_decl = try block.startAnonDecl(); |
| 22733 | 22676 | defer anon_decl.deinit(); |
| 22734 | 22677 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22735 | 22678 | if (!child_type.isAnyError()) |
| ... | ... | @@ -22749,7 +22692,7 @@ fn fieldPtr( |
| 22749 | 22692 | if (child_type.unionTagType()) |enum_ty| { |
| 22750 | 22693 | if (enum_ty.enumFieldIndex(field_name)) |field_index| { |
| 22751 | 22694 | const field_index_u32 = @intCast(u32, field_index); |
| 22752 | | var anon_decl = try block.startAnonDecl(src); |
| 22695 | var anon_decl = try block.startAnonDecl(); |
| 22753 | 22696 | defer anon_decl.deinit(); |
| 22754 | 22697 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22755 | 22698 | try enum_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -22770,7 +22713,7 @@ fn fieldPtr( |
| 22770 | 22713 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 22771 | 22714 | }; |
| 22772 | 22715 | const field_index_u32 = @intCast(u32, field_index); |
| 22773 | | var anon_decl = try block.startAnonDecl(src); |
| 22716 | var anon_decl = try block.startAnonDecl(); |
| 22774 | 22717 | defer anon_decl.deinit(); |
| 22775 | 22718 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22776 | 22719 | try child_type.copy(anon_decl.arena()), |
| ... | ... | @@ -22839,40 +22782,40 @@ fn fieldCallBind( |
| 22839 | 22782 | find_field: { |
| 22840 | 22783 | switch (concrete_ty.zigTypeTag()) { |
| 22841 | 22784 | .Struct => { |
| 22842 | | const struct_ty = try sema.resolveTypeFields(block, src, concrete_ty); |
| 22785 | const struct_ty = try sema.resolveTypeFields(concrete_ty); |
| 22843 | 22786 | if (struct_ty.castTag(.@"struct")) |struct_obj| { |
| 22844 | 22787 | const field_index_usize = struct_obj.data.fields.getIndex(field_name) orelse |
| 22845 | 22788 | break :find_field; |
| 22846 | 22789 | const field_index = @intCast(u32, field_index_usize); |
| 22847 | 22790 | const field = struct_obj.data.fields.values()[field_index]; |
| 22848 | 22791 | |
| 22849 | | return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 22792 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 22850 | 22793 | } else if (struct_ty.isTuple()) { |
| 22851 | 22794 | if (mem.eql(u8, field_name, "len")) { |
| 22852 | 22795 | return sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount()); |
| 22853 | 22796 | } |
| 22854 | 22797 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 22855 | 22798 | if (field_index >= struct_ty.structFieldCount()) break :find_field; |
| 22856 | | return finishFieldCallBind(sema, block, src, ptr_ty, struct_ty.structFieldType(field_index), field_index, object_ptr); |
| 22799 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index), field_index, object_ptr); |
| 22857 | 22800 | } else |_| {} |
| 22858 | 22801 | } else { |
| 22859 | 22802 | const max = struct_ty.structFieldCount(); |
| 22860 | 22803 | var i: u32 = 0; |
| 22861 | 22804 | while (i < max) : (i += 1) { |
| 22862 | 22805 | if (mem.eql(u8, struct_ty.structFieldName(i), field_name)) { |
| 22863 | | return finishFieldCallBind(sema, block, src, ptr_ty, struct_ty.structFieldType(i), i, object_ptr); |
| 22806 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i), i, object_ptr); |
| 22864 | 22807 | } |
| 22865 | 22808 | } |
| 22866 | 22809 | } |
| 22867 | 22810 | }, |
| 22868 | 22811 | .Union => { |
| 22869 | | const union_ty = try sema.resolveTypeFields(block, src, concrete_ty); |
| 22812 | const union_ty = try sema.resolveTypeFields(concrete_ty); |
| 22870 | 22813 | const fields = union_ty.unionFields(); |
| 22871 | 22814 | const field_index_usize = fields.getIndex(field_name) orelse break :find_field; |
| 22872 | 22815 | const field_index = @intCast(u32, field_index_usize); |
| 22873 | 22816 | const field = fields.values()[field_index]; |
| 22874 | 22817 | |
| 22875 | | return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 22818 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); |
| 22876 | 22819 | }, |
| 22877 | 22820 | .Type => { |
| 22878 | 22821 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| ... | ... | @@ -23058,8 +23001,8 @@ fn structFieldPtr( |
| 23058 | 23001 | ) CompileError!Air.Inst.Ref { |
| 23059 | 23002 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); |
| 23060 | 23003 | |
| 23061 | | const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty); |
| 23062 | | try sema.resolveStructLayout(block, src, struct_ty); |
| 23004 | const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty); |
| 23005 | try sema.resolveStructLayout(struct_ty); |
| 23063 | 23006 | |
| 23064 | 23007 | if (struct_ty.isTuple()) { |
| 23065 | 23008 | if (mem.eql(u8, field_name, "len")) { |
| ... | ... | @@ -23115,7 +23058,7 @@ fn structFieldPtrByIndex( |
| 23115 | 23058 | |
| 23116 | 23059 | var running_bits: u16 = 0; |
| 23117 | 23060 | for (struct_obj.fields.values()) |f, i| { |
| 23118 | | if (!(try sema.typeHasRuntimeBits(block, field_src, f.ty))) continue; |
| 23061 | if (!(try sema.typeHasRuntimeBits(f.ty))) continue; |
| 23119 | 23062 | |
| 23120 | 23063 | if (i == field_index) { |
| 23121 | 23064 | ptr_ty_data.bit_offset = running_bits; |
| ... | ... | @@ -23198,12 +23141,12 @@ fn structFieldVal( |
| 23198 | 23141 | ) CompileError!Air.Inst.Ref { |
| 23199 | 23142 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); |
| 23200 | 23143 | |
| 23201 | | const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty); |
| 23144 | const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty); |
| 23202 | 23145 | switch (struct_ty.tag()) { |
| 23203 | 23146 | .tuple, .empty_struct_literal => return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty), |
| 23204 | 23147 | .anon_struct => { |
| 23205 | 23148 | const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src); |
| 23206 | | return tupleFieldValByIndex(sema, block, src, struct_byval, field_index, struct_ty); |
| 23149 | return sema.tupleFieldValByIndex(block, src, struct_byval, field_index, struct_ty); |
| 23207 | 23150 | }, |
| 23208 | 23151 | .@"struct" => { |
| 23209 | 23152 | const struct_obj = struct_ty.castTag(.@"struct").?.data; |
| ... | ... | @@ -23217,9 +23160,9 @@ fn structFieldVal( |
| 23217 | 23160 | return sema.addConstant(field.ty, field.default_val); |
| 23218 | 23161 | } |
| 23219 | 23162 | |
| 23220 | | if (try sema.resolveMaybeUndefVal(block, src, struct_byval)) |struct_val| { |
| 23163 | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| 23221 | 23164 | if (struct_val.isUndef()) return sema.addConstUndef(field.ty); |
| 23222 | | if ((try sema.typeHasOnePossibleValue(block, src, field.ty))) |opv| { |
| 23165 | if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| { |
| 23223 | 23166 | return sema.addConstant(field.ty, opv); |
| 23224 | 23167 | } |
| 23225 | 23168 | |
| ... | ... | @@ -23247,7 +23190,7 @@ fn tupleFieldVal( |
| 23247 | 23190 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount()); |
| 23248 | 23191 | } |
| 23249 | 23192 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); |
| 23250 | | return tupleFieldValByIndex(sema, block, src, tuple_byval, field_index, tuple_ty); |
| 23193 | return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty); |
| 23251 | 23194 | } |
| 23252 | 23195 | |
| 23253 | 23196 | /// Asserts that `field_name` is not "len". |
| ... | ... | @@ -23286,9 +23229,9 @@ fn tupleFieldValByIndex( |
| 23286 | 23229 | return sema.addConstant(field_ty, tuple.values[field_index]); |
| 23287 | 23230 | } |
| 23288 | 23231 | |
| 23289 | | if (try sema.resolveMaybeUndefVal(block, src, tuple_byval)) |tuple_val| { |
| 23232 | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { |
| 23290 | 23233 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); |
| 23291 | | if ((try sema.typeHasOnePossibleValue(block, src, field_ty))) |opv| { |
| 23234 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { |
| 23292 | 23235 | return sema.addConstant(field_ty, opv); |
| 23293 | 23236 | } |
| 23294 | 23237 | const field_values = tuple_val.castTag(.aggregate).?.data; |
| ... | ... | @@ -23317,7 +23260,7 @@ fn unionFieldPtr( |
| 23317 | 23260 | assert(unresolved_union_ty.zigTypeTag() == .Union); |
| 23318 | 23261 | |
| 23319 | 23262 | const union_ptr_ty = sema.typeOf(union_ptr); |
| 23320 | | const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty); |
| 23263 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); |
| 23321 | 23264 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 23322 | 23265 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 23323 | 23266 | const field = union_obj.fields.values()[field_index]; |
| ... | ... | @@ -23410,13 +23353,13 @@ fn unionFieldVal( |
| 23410 | 23353 | ) CompileError!Air.Inst.Ref { |
| 23411 | 23354 | assert(unresolved_union_ty.zigTypeTag() == .Union); |
| 23412 | 23355 | |
| 23413 | | const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty); |
| 23356 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); |
| 23414 | 23357 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 23415 | 23358 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 23416 | 23359 | const field = union_obj.fields.values()[field_index]; |
| 23417 | 23360 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?); |
| 23418 | 23361 | |
| 23419 | | if (try sema.resolveMaybeUndefVal(block, src, union_byval)) |union_val| { |
| 23362 | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { |
| 23420 | 23363 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); |
| 23421 | 23364 | |
| 23422 | 23365 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| ... | ... | @@ -23586,7 +23529,7 @@ fn elemVal( |
| 23586 | 23529 | // Tuple field access. |
| 23587 | 23530 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); |
| 23588 | 23531 | const index = @intCast(u32, index_val.toUnsignedInt(target)); |
| 23589 | | return tupleField(sema, block, indexable_src, indexable, elem_index_src, index); |
| 23532 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); |
| 23590 | 23533 | }, |
| 23591 | 23534 | else => unreachable, |
| 23592 | 23535 | } |
| ... | ... | @@ -23600,7 +23543,7 @@ fn validateRuntimeElemAccess( |
| 23600 | 23543 | parent_ty: Type, |
| 23601 | 23544 | parent_src: LazySrcLoc, |
| 23602 | 23545 | ) CompileError!void { |
| 23603 | | const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false); |
| 23546 | const valid_rt = try sema.validateRunTimeType(elem_ty, false); |
| 23604 | 23547 | if (!valid_rt) { |
| 23605 | 23548 | const msg = msg: { |
| 23606 | 23549 | const msg = try sema.errMsg( |
| ... | ... | @@ -23659,7 +23602,7 @@ fn tupleFieldPtr( |
| 23659 | 23602 | return sema.addConstant(ptr_field_ty, val); |
| 23660 | 23603 | } |
| 23661 | 23604 | |
| 23662 | | if (try sema.resolveMaybeUndefVal(block, tuple_ptr_src, tuple_ptr)) |tuple_ptr_val| { |
| 23605 | if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| { |
| 23663 | 23606 | return sema.addConstant( |
| 23664 | 23607 | ptr_field_ty, |
| 23665 | 23608 | try Value.Tag.field_ptr.create(sema.arena, .{ |
| ... | ... | @@ -23706,7 +23649,7 @@ fn tupleField( |
| 23706 | 23649 | return sema.addConstant(field_ty, field_val); // comptime field |
| 23707 | 23650 | } |
| 23708 | 23651 | |
| 23709 | | if (try sema.resolveMaybeUndefVal(block, tuple_src, tuple)) |tuple_val| { |
| 23652 | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { |
| 23710 | 23653 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); |
| 23711 | 23654 | return sema.addConstant(field_ty, tuple_val.fieldValue(tuple_ty, field_index)); |
| 23712 | 23655 | } |
| ... | ... | @@ -23736,7 +23679,7 @@ fn elemValArray( |
| 23736 | 23679 | return sema.fail(block, array_src, "indexing into empty array is not allowed", .{}); |
| 23737 | 23680 | } |
| 23738 | 23681 | |
| 23739 | | const maybe_undef_array_val = try sema.resolveMaybeUndefVal(block, array_src, array); |
| 23682 | const maybe_undef_array_val = try sema.resolveMaybeUndefVal(array); |
| 23740 | 23683 | // index must be defined since it can access out of bounds |
| 23741 | 23684 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 23742 | 23685 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -23800,7 +23743,7 @@ fn elemPtrArray( |
| 23800 | 23743 | return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{}); |
| 23801 | 23744 | } |
| 23802 | 23745 | |
| 23803 | | const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(block, array_ptr_src, array_ptr); |
| 23746 | const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(array_ptr); |
| 23804 | 23747 | // The index must not be undefined since it can be out of bounds. |
| 23805 | 23748 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 23806 | 23749 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); |
| ... | ... | @@ -23909,7 +23852,7 @@ fn elemPtrSlice( |
| 23909 | 23852 | const slice_ty = sema.typeOf(slice); |
| 23910 | 23853 | const slice_sent = slice_ty.sentinel() != null; |
| 23911 | 23854 | |
| 23912 | | const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(block, slice_src, slice); |
| 23855 | const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice); |
| 23913 | 23856 | // The index must not be undefined since it can be out of bounds. |
| 23914 | 23857 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 23915 | 23858 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); |
| ... | ... | @@ -23996,15 +23939,15 @@ fn coerceExtra( |
| 23996 | 23939 | else => {}, |
| 23997 | 23940 | } |
| 23998 | 23941 | const dest_ty_src = inst_src; // TODO better source location |
| 23999 | | const dest_ty = try sema.resolveTypeFields(block, dest_ty_src, dest_ty_unresolved); |
| 24000 | | const inst_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst)); |
| 23942 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); |
| 23943 | const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst)); |
| 24001 | 23944 | const target = sema.mod.getTarget(); |
| 24002 | 23945 | // If the types are the same, we can return the operand. |
| 24003 | 23946 | if (dest_ty.eql(inst_ty, sema.mod)) |
| 24004 | 23947 | return inst; |
| 24005 | 23948 | |
| 24006 | 23949 | const arena = sema.arena; |
| 24007 | | const maybe_inst_val = try sema.resolveMaybeUndefVal(block, inst_src, inst); |
| 23950 | const maybe_inst_val = try sema.resolveMaybeUndefVal(inst); |
| 24008 | 23951 | |
| 24009 | 23952 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| 24010 | 23953 | if (in_memory_result == .ok) { |
| ... | ... | @@ -24354,7 +24297,7 @@ fn coerceExtra( |
| 24354 | 24297 | .Int, .ComptimeInt => { |
| 24355 | 24298 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { |
| 24356 | 24299 | // comptime-known integer to other number |
| 24357 | | if (!(try sema.intFitsInType(block, inst_src, val, dest_ty, null))) { |
| 24300 | if (!(try sema.intFitsInType(val, dest_ty, null))) { |
| 24358 | 24301 | if (!opts.report_err) return error.NotCoercible; |
| 24359 | 24302 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) }); |
| 24360 | 24303 | } |
| ... | ... | @@ -24421,7 +24364,7 @@ fn coerceExtra( |
| 24421 | 24364 | } |
| 24422 | 24365 | break :int; |
| 24423 | 24366 | }; |
| 24424 | | const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema.kit(block, inst_src)); |
| 24367 | const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema); |
| 24425 | 24368 | // TODO implement this compile error |
| 24426 | 24369 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 24427 | 24370 | //if (!int_again_val.eql(val, inst_ty, mod)) { |
| ... | ... | @@ -24559,7 +24502,7 @@ fn coerceExtra( |
| 24559 | 24502 | return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src); |
| 24560 | 24503 | } |
| 24561 | 24504 | if (inst_ty.isTupleOrAnonStruct()) { |
| 24562 | | return sema.coerceTupleToStruct(block, dest_ty, dest_ty_src, inst, inst_src); |
| 24505 | return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src); |
| 24563 | 24506 | } |
| 24564 | 24507 | }, |
| 24565 | 24508 | else => {}, |
| ... | ... | @@ -25031,8 +24974,8 @@ fn coerceInMemoryAllowed( |
| 25031 | 24974 | // Pointers / Pointer-like Optionals |
| 25032 | 24975 | var dest_buf: Type.Payload.ElemType = undefined; |
| 25033 | 24976 | var src_buf: Type.Payload.ElemType = undefined; |
| 25034 | | const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, dest_ty, &dest_buf, dest_src); |
| 25035 | | const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, src_ty, &src_buf, src_src); |
| 24977 | const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(dest_ty, &dest_buf); |
| 24978 | const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(src_ty, &src_buf); |
| 25036 | 24979 | if (maybe_dest_ptr_ty) |dest_ptr_ty| { |
| 25037 | 24980 | if (maybe_src_ptr_ty) |src_ptr_ty| { |
| 25038 | 24981 | return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ptr_ty, src_ptr_ty, dest_is_mut, target, dest_src, src_src); |
| ... | ... | @@ -25528,7 +25471,7 @@ fn coerceVarArgParam( |
| 25528 | 25471 | }; |
| 25529 | 25472 | |
| 25530 | 25473 | const coerced_ty = sema.typeOf(coerced); |
| 25531 | | if (!try sema.validateExternType(block, inst_src, coerced_ty, .param_ty)) { |
| 25474 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { |
| 25532 | 25475 | const msg = msg: { |
| 25533 | 25476 | const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); |
| 25534 | 25477 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -25585,7 +25528,7 @@ fn storePtr2( |
| 25585 | 25528 | for (tuple.types) |_, i_usize| { |
| 25586 | 25529 | const i = @intCast(u32, i_usize); |
| 25587 | 25530 | const elem_src = operand_src; // TODO better source location |
| 25588 | | const elem = try tupleField(sema, block, operand_src, uncasted_operand, elem_src, i); |
| 25531 | const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i); |
| 25589 | 25532 | const elem_index = try sema.addIntUnsigned(Type.usize, i); |
| 25590 | 25533 | const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false); |
| 25591 | 25534 | try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store); |
| ... | ... | @@ -25618,7 +25561,7 @@ fn storePtr2( |
| 25618 | 25561 | error.NotCoercible => unreachable, |
| 25619 | 25562 | else => |e| return e, |
| 25620 | 25563 | }; |
| 25621 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand); |
| 25564 | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 25622 | 25565 | |
| 25623 | 25566 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 25624 | 25567 | const operand_val = maybe_operand_val orelse { |
| ... | ... | @@ -25633,7 +25576,7 @@ fn storePtr2( |
| 25633 | 25576 | |
| 25634 | 25577 | // We do this after the possible comptime store above, for the case of field_ptr stores |
| 25635 | 25578 | // to unions because we want the comptime tag to be set, even if the field type is void. |
| 25636 | | if ((try sema.typeHasOnePossibleValue(block, src, elem_ty)) != null) |
| 25579 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) |
| 25637 | 25580 | return; |
| 25638 | 25581 | |
| 25639 | 25582 | if (air_tag == .bitcast) { |
| ... | ... | @@ -25695,7 +25638,7 @@ fn storePtrVal( |
| 25695 | 25638 | operand_val: Value, |
| 25696 | 25639 | operand_ty: Type, |
| 25697 | 25640 | ) !void { |
| 25698 | | var mut_kit = try beginComptimePtrMutation(sema, block, src, ptr_val, operand_ty); |
| 25641 | var mut_kit = try sema.beginComptimePtrMutation(block, src, ptr_val, operand_ty); |
| 25699 | 25642 | try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut); |
| 25700 | 25643 | |
| 25701 | 25644 | switch (mut_kit.pointee) { |
| ... | ... | @@ -25784,20 +25727,20 @@ fn beginComptimePtrMutation( |
| 25784 | 25727 | .decl_ref_mut => { |
| 25785 | 25728 | const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data; |
| 25786 | 25729 | const decl = sema.mod.declPtr(decl_ref_mut.decl_index); |
| 25787 | | return beginComptimePtrMutationInner(sema, block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut); |
| 25730 | return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut); |
| 25788 | 25731 | }, |
| 25789 | 25732 | .comptime_field_ptr => { |
| 25790 | 25733 | const payload = ptr_val.castTag(.comptime_field_ptr).?.data; |
| 25791 | 25734 | const duped = try sema.arena.create(Value); |
| 25792 | 25735 | duped.* = payload.field_val; |
| 25793 | | return beginComptimePtrMutationInner(sema, block, src, payload.field_ty, duped, ptr_elem_ty, .{ |
| 25736 | return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{ |
| 25794 | 25737 | .decl_index = @intToEnum(Module.Decl.Index, 0), |
| 25795 | 25738 | .runtime_index = .comptime_field_ptr, |
| 25796 | 25739 | }); |
| 25797 | 25740 | }, |
| 25798 | 25741 | .elem_ptr => { |
| 25799 | 25742 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; |
| 25800 | | var parent = try beginComptimePtrMutation(sema, block, src, elem_ptr.array_ptr, elem_ptr.elem_ty); |
| 25743 | var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty); |
| 25801 | 25744 | switch (parent.pointee) { |
| 25802 | 25745 | .direct => |val_ptr| switch (parent.ty.zigTypeTag()) { |
| 25803 | 25746 | .Array, .Vector => { |
| ... | ... | @@ -25987,7 +25930,7 @@ fn beginComptimePtrMutation( |
| 25987 | 25930 | }; |
| 25988 | 25931 | } |
| 25989 | 25932 | |
| 25990 | | const elem_abi_size_u64 = try sema.typeAbiSize(block, src, elem_ptr.elem_ty); |
| 25933 | const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty); |
| 25991 | 25934 | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 25992 | 25935 | return ComptimePtrMutationKit{ |
| 25993 | 25936 | .decl_ref_mut = parent.decl_ref_mut, |
| ... | ... | @@ -26005,7 +25948,7 @@ fn beginComptimePtrMutation( |
| 26005 | 25948 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 26006 | 25949 | const field_index = @intCast(u32, field_ptr.field_index); |
| 26007 | 25950 | |
| 26008 | | var parent = try beginComptimePtrMutation(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 25951 | var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 26009 | 25952 | switch (parent.pointee) { |
| 26010 | 25953 | .direct => |val_ptr| switch (val_ptr.tag()) { |
| 26011 | 25954 | .undef => { |
| ... | ... | @@ -26169,7 +26112,7 @@ fn beginComptimePtrMutation( |
| 26169 | 26112 | }, |
| 26170 | 26113 | .eu_payload_ptr => { |
| 26171 | 26114 | const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data; |
| 26172 | | var parent = try beginComptimePtrMutation(sema, block, src, eu_ptr.container_ptr, eu_ptr.container_ty); |
| 26115 | var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty); |
| 26173 | 26116 | switch (parent.pointee) { |
| 26174 | 26117 | .direct => |val_ptr| { |
| 26175 | 26118 | const payload_ty = parent.ty.errorUnionPayload(); |
| ... | ... | @@ -26216,7 +26159,7 @@ fn beginComptimePtrMutation( |
| 26216 | 26159 | const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else { |
| 26217 | 26160 | return sema.beginComptimePtrMutation(block, src, ptr_val, try ptr_elem_ty.optionalChildAlloc(sema.arena)); |
| 26218 | 26161 | }; |
| 26219 | | var parent = try beginComptimePtrMutation(sema, block, src, opt_ptr.container_ptr, opt_ptr.container_ty); |
| 26162 | var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty); |
| 26220 | 26163 | switch (parent.pointee) { |
| 26221 | 26164 | .direct => |val_ptr| { |
| 26222 | 26165 | const payload_ty = try parent.ty.optionalChildAlloc(sema.arena); |
| ... | ... | @@ -26385,7 +26328,7 @@ fn beginComptimePtrLoad( |
| 26385 | 26328 | .elem_ptr => blk: { |
| 26386 | 26329 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; |
| 26387 | 26330 | const elem_ty = elem_ptr.elem_ty; |
| 26388 | | var deref = try beginComptimePtrLoad(sema, block, src, elem_ptr.array_ptr, null); |
| 26331 | var deref = try sema.beginComptimePtrLoad(block, src, elem_ptr.array_ptr, null); |
| 26389 | 26332 | |
| 26390 | 26333 | // This code assumes that elem_ptrs have been "flattened" in order for direct dereference |
| 26391 | 26334 | // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that |
| ... | ... | @@ -26398,7 +26341,7 @@ fn beginComptimePtrLoad( |
| 26398 | 26341 | if (elem_ty.hasWellDefinedLayout()) { |
| 26399 | 26342 | if (deref.parent) |*parent| { |
| 26400 | 26343 | // Update the byte offset (in-place) |
| 26401 | | const elem_size = try sema.typeAbiSize(block, src, elem_ty); |
| 26344 | const elem_size = try sema.typeAbiSize(elem_ty); |
| 26402 | 26345 | const offset = parent.byte_offset + elem_size * elem_ptr.index; |
| 26403 | 26346 | parent.byte_offset = try sema.usizeCast(block, src, offset); |
| 26404 | 26347 | } |
| ... | ... | @@ -26457,13 +26400,13 @@ fn beginComptimePtrLoad( |
| 26457 | 26400 | |
| 26458 | 26401 | .slice => blk: { |
| 26459 | 26402 | const slice = ptr_val.castTag(.slice).?.data; |
| 26460 | | break :blk try beginComptimePtrLoad(sema, block, src, slice.ptr, null); |
| 26403 | break :blk try sema.beginComptimePtrLoad(block, src, slice.ptr, null); |
| 26461 | 26404 | }, |
| 26462 | 26405 | |
| 26463 | 26406 | .field_ptr => blk: { |
| 26464 | 26407 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 26465 | 26408 | const field_index = @intCast(u32, field_ptr.field_index); |
| 26466 | | var deref = try beginComptimePtrLoad(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 26409 | var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.container_ptr, field_ptr.container_ty); |
| 26467 | 26410 | |
| 26468 | 26411 | if (field_ptr.container_ty.hasWellDefinedLayout()) { |
| 26469 | 26412 | const struct_ty = field_ptr.container_ty.castTag(.@"struct"); |
| ... | ... | @@ -26472,7 +26415,7 @@ fn beginComptimePtrLoad( |
| 26472 | 26415 | deref.parent = null; |
| 26473 | 26416 | } else if (deref.parent) |*parent| { |
| 26474 | 26417 | // Update the byte offset (in-place) |
| 26475 | | try sema.resolveTypeLayout(block, src, field_ptr.container_ty); |
| 26418 | try sema.resolveTypeLayout(field_ptr.container_ty); |
| 26476 | 26419 | const field_offset = field_ptr.container_ty.structFieldOffset(field_index, target); |
| 26477 | 26420 | parent.byte_offset = try sema.usizeCast(block, src, parent.byte_offset + field_offset); |
| 26478 | 26421 | } |
| ... | ... | @@ -26535,7 +26478,7 @@ fn beginComptimePtrLoad( |
| 26535 | 26478 | .opt_payload_ptr => try payload_ptr.container_ty.optionalChildAlloc(sema.arena), |
| 26536 | 26479 | else => unreachable, |
| 26537 | 26480 | }; |
| 26538 | | var deref = try beginComptimePtrLoad(sema, block, src, payload_ptr.container_ptr, payload_ptr.container_ty); |
| 26481 | var deref = try sema.beginComptimePtrLoad(block, src, payload_ptr.container_ptr, payload_ptr.container_ty); |
| 26539 | 26482 | |
| 26540 | 26483 | // eu_payload_ptr and opt_payload_ptr never have a well-defined layout |
| 26541 | 26484 | if (deref.parent != null) { |
| ... | ... | @@ -26598,11 +26541,11 @@ fn bitCast( |
| 26598 | 26541 | inst: Air.Inst.Ref, |
| 26599 | 26542 | inst_src: LazySrcLoc, |
| 26600 | 26543 | ) CompileError!Air.Inst.Ref { |
| 26601 | | const dest_ty = try sema.resolveTypeFields(block, inst_src, dest_ty_unresolved); |
| 26602 | | try sema.resolveTypeLayout(block, inst_src, dest_ty); |
| 26544 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); |
| 26545 | try sema.resolveTypeLayout(dest_ty); |
| 26603 | 26546 | |
| 26604 | | const old_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst)); |
| 26605 | | try sema.resolveTypeLayout(block, inst_src, old_ty); |
| 26547 | const old_ty = try sema.resolveTypeFields(sema.typeOf(inst)); |
| 26548 | try sema.resolveTypeLayout(old_ty); |
| 26606 | 26549 | |
| 26607 | 26550 | const target = sema.mod.getTarget(); |
| 26608 | 26551 | const dest_bits = dest_ty.bitSize(target); |
| ... | ... | @@ -26617,7 +26560,7 @@ fn bitCast( |
| 26617 | 26560 | }); |
| 26618 | 26561 | } |
| 26619 | 26562 | |
| 26620 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 26563 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 26621 | 26564 | const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0); |
| 26622 | 26565 | return sema.addConstant(dest_ty, result_val); |
| 26623 | 26566 | } |
| ... | ... | @@ -26653,7 +26596,7 @@ fn coerceArrayPtrToSlice( |
| 26653 | 26596 | inst: Air.Inst.Ref, |
| 26654 | 26597 | inst_src: LazySrcLoc, |
| 26655 | 26598 | ) CompileError!Air.Inst.Ref { |
| 26656 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 26599 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 26657 | 26600 | const ptr_array_ty = sema.typeOf(inst); |
| 26658 | 26601 | const array_ty = ptr_array_ty.childType(); |
| 26659 | 26602 | const slice_val = try Value.Tag.slice.create(sema.arena, .{ |
| ... | ... | @@ -26725,14 +26668,14 @@ fn coerceCompatiblePtrs( |
| 26725 | 26668 | inst_src: LazySrcLoc, |
| 26726 | 26669 | ) !Air.Inst.Ref { |
| 26727 | 26670 | const inst_ty = sema.typeOf(inst); |
| 26728 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 26671 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 26729 | 26672 | // The comptime Value representation is compatible with both types. |
| 26730 | 26673 | return sema.addConstant(dest_ty, val); |
| 26731 | 26674 | } |
| 26732 | 26675 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 26733 | 26676 | const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true; |
| 26734 | 26677 | if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and |
| 26735 | | try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2())) |
| 26678 | try sema.typeHasRuntimeBits(dest_ty.elemType2())) |
| 26736 | 26679 | { |
| 26737 | 26680 | const actual_ptr = if (inst_ty.isSlice()) |
| 26738 | 26681 | try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) |
| ... | ... | @@ -26789,7 +26732,7 @@ fn coerceEnumToUnion( |
| 26789 | 26732 | |
| 26790 | 26733 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 26791 | 26734 | const field = union_obj.fields.values()[field_index]; |
| 26792 | | const field_ty = try sema.resolveTypeFields(block, inst_src, field.ty); |
| 26735 | const field_ty = try sema.resolveTypeFields(field.ty); |
| 26793 | 26736 | if (field_ty.zigTypeTag() == .NoReturn) { |
| 26794 | 26737 | const msg = msg: { |
| 26795 | 26738 | const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{}); |
| ... | ... | @@ -26802,7 +26745,7 @@ fn coerceEnumToUnion( |
| 26802 | 26745 | }; |
| 26803 | 26746 | return sema.failWithOwnedErrorMsg(msg); |
| 26804 | 26747 | } |
| 26805 | | const opv = (try sema.typeHasOnePossibleValue(block, inst_src, field_ty)) orelse { |
| 26748 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 26806 | 26749 | const msg = msg: { |
| 26807 | 26750 | const field_name = union_obj.fields.keys()[field_index]; |
| 26808 | 26751 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{ |
| ... | ... | @@ -26954,7 +26897,7 @@ fn coerceAnonStructToStructPtrs( |
| 26954 | 26897 | ) !Air.Inst.Ref { |
| 26955 | 26898 | const struct_ty = ptr_struct_ty.childType(); |
| 26956 | 26899 | const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src); |
| 26957 | | const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, struct_ty_src, anon_struct, anon_struct_src); |
| 26900 | const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src); |
| 26958 | 26901 | return sema.analyzeRef(block, struct_ty_src, struct_inst); |
| 26959 | 26902 | } |
| 26960 | 26903 | |
| ... | ... | @@ -26989,7 +26932,7 @@ fn coerceArrayLike( |
| 26989 | 26932 | const inst_elem_ty = inst_ty.childType(); |
| 26990 | 26933 | const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_elem_ty, inst_elem_ty, false, target, dest_ty_src, inst_src); |
| 26991 | 26934 | if (in_memory_result == .ok) { |
| 26992 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |inst_val| { |
| 26935 | if (try sema.resolveMaybeUndefVal(inst)) |inst_val| { |
| 26993 | 26936 | // These types share the same comptime value representation. |
| 26994 | 26937 | return sema.addConstant(dest_ty, inst_val); |
| 26995 | 26938 | } |
| ... | ... | @@ -27012,7 +26955,7 @@ fn coerceArrayLike( |
| 27012 | 26955 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 27013 | 26956 | element_refs[i] = coerced; |
| 27014 | 26957 | if (runtime_src == null) { |
| 27015 | | if (try sema.resolveMaybeUndefVal(block, elem_src, coerced)) |elem_val| { |
| 26958 | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 27016 | 26959 | elem.* = elem_val; |
| 27017 | 26960 | } else { |
| 27018 | 26961 | runtime_src = elem_src; |
| ... | ... | @@ -27071,11 +27014,11 @@ fn coerceTupleToArray( |
| 27071 | 27014 | break; |
| 27072 | 27015 | } |
| 27073 | 27016 | const elem_src = inst_src; // TODO better source location |
| 27074 | | const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i); |
| 27017 | const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i); |
| 27075 | 27018 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 27076 | 27019 | element_refs[i] = coerced; |
| 27077 | 27020 | if (runtime_src == null) { |
| 27078 | | if (try sema.resolveMaybeUndefVal(block, elem_src, coerced)) |elem_val| { |
| 27021 | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 27079 | 27022 | elem.* = elem_val; |
| 27080 | 27023 | } else { |
| 27081 | 27024 | runtime_src = elem_src; |
| ... | ... | @@ -27141,11 +27084,10 @@ fn coerceTupleToStruct( |
| 27141 | 27084 | sema: *Sema, |
| 27142 | 27085 | block: *Block, |
| 27143 | 27086 | dest_ty: Type, |
| 27144 | | dest_ty_src: LazySrcLoc, |
| 27145 | 27087 | inst: Air.Inst.Ref, |
| 27146 | 27088 | inst_src: LazySrcLoc, |
| 27147 | 27089 | ) !Air.Inst.Ref { |
| 27148 | | const struct_ty = try sema.resolveTypeFields(block, dest_ty_src, dest_ty); |
| 27090 | const struct_ty = try sema.resolveTypeFields(dest_ty); |
| 27149 | 27091 | |
| 27150 | 27092 | if (struct_ty.isTupleOrAnonStruct()) { |
| 27151 | 27093 | return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src); |
| ... | ... | @@ -27168,11 +27110,11 @@ fn coerceTupleToStruct( |
| 27168 | 27110 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 27169 | 27111 | const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src); |
| 27170 | 27112 | const field = fields.values()[field_index]; |
| 27171 | | const elem_ref = try tupleField(sema, block, inst_src, inst, field_src, i); |
| 27113 | const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, i); |
| 27172 | 27114 | const coerced = try sema.coerce(block, field.ty, elem_ref, field_src); |
| 27173 | 27115 | field_refs[field_index] = coerced; |
| 27174 | 27116 | if (field.is_comptime) { |
| 27175 | | const init_val = (try sema.resolveMaybeUndefVal(block, field_src, coerced)) orelse { |
| 27117 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 27176 | 27118 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); |
| 27177 | 27119 | }; |
| 27178 | 27120 | |
| ... | ... | @@ -27181,7 +27123,7 @@ fn coerceTupleToStruct( |
| 27181 | 27123 | } |
| 27182 | 27124 | } |
| 27183 | 27125 | if (runtime_src == null) { |
| 27184 | | if (try sema.resolveMaybeUndefVal(block, field_src, coerced)) |field_val| { |
| 27126 | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 27185 | 27127 | field_vals[field_index] = field_val; |
| 27186 | 27128 | } else { |
| 27187 | 27129 | runtime_src = field_src; |
| ... | ... | @@ -27264,11 +27206,11 @@ fn coerceTupleToTuple( |
| 27264 | 27206 | |
| 27265 | 27207 | const field_ty = tuple_ty.structFieldType(i); |
| 27266 | 27208 | const default_val = tuple_ty.structFieldDefaultValue(i); |
| 27267 | | const elem_ref = try tupleField(sema, block, inst_src, inst, field_src, i); |
| 27209 | const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, i); |
| 27268 | 27210 | const coerced = try sema.coerce(block, field_ty, elem_ref, field_src); |
| 27269 | 27211 | field_refs[field_index] = coerced; |
| 27270 | 27212 | if (default_val.tag() != .unreachable_value) { |
| 27271 | | const init_val = (try sema.resolveMaybeUndefVal(block, field_src, coerced)) orelse { |
| 27213 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 27272 | 27214 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); |
| 27273 | 27215 | }; |
| 27274 | 27216 | |
| ... | ... | @@ -27277,7 +27219,7 @@ fn coerceTupleToTuple( |
| 27277 | 27219 | } |
| 27278 | 27220 | } |
| 27279 | 27221 | if (runtime_src == null) { |
| 27280 | | if (try sema.resolveMaybeUndefVal(block, field_src, coerced)) |field_val| { |
| 27222 | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 27281 | 27223 | field_vals[field_index] = field_val; |
| 27282 | 27224 | } else { |
| 27283 | 27225 | runtime_src = field_src; |
| ... | ... | @@ -27400,8 +27342,8 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: *Module.Fn) CompileError!void { |
| 27400 | 27342 | }; |
| 27401 | 27343 | } |
| 27402 | 27344 | |
| 27403 | | fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) !Value { |
| 27404 | | var anon_decl = try block.startAnonDecl(src); |
| 27345 | fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value { |
| 27346 | var anon_decl = try block.startAnonDecl(); |
| 27405 | 27347 | defer anon_decl.deinit(); |
| 27406 | 27348 | const decl = try anon_decl.finish( |
| 27407 | 27349 | try ty.copy(anon_decl.arena()), |
| ... | ... | @@ -27412,9 +27354,9 @@ fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) ! |
| 27412 | 27354 | return try Value.Tag.decl_ref.create(sema.arena, decl); |
| 27413 | 27355 | } |
| 27414 | 27356 | |
| 27415 | | fn optRefValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, opt_val: ?Value) !Value { |
| 27357 | fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value { |
| 27416 | 27358 | const val = opt_val orelse return Value.@"null"; |
| 27417 | | const ptr_val = try refValue(sema, block, src, ty, val); |
| 27359 | const ptr_val = try sema.refValue(block, ty, val); |
| 27418 | 27360 | const result = try Value.Tag.opt_payload.create(sema.arena, ptr_val); |
| 27419 | 27361 | return result; |
| 27420 | 27362 | } |
| ... | ... | @@ -27454,8 +27396,8 @@ fn analyzeRef( |
| 27454 | 27396 | ) CompileError!Air.Inst.Ref { |
| 27455 | 27397 | const operand_ty = sema.typeOf(operand); |
| 27456 | 27398 | |
| 27457 | | if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| { |
| 27458 | | var anon_decl = try block.startAnonDecl(src); |
| 27399 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 27400 | var anon_decl = try block.startAnonDecl(); |
| 27459 | 27401 | defer anon_decl.deinit(); |
| 27460 | 27402 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 27461 | 27403 | try operand_ty.copy(anon_decl.arena()), |
| ... | ... | @@ -27495,7 +27437,7 @@ fn analyzeLoad( |
| 27495 | 27437 | else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}), |
| 27496 | 27438 | }; |
| 27497 | 27439 | |
| 27498 | | if (try sema.typeHasOnePossibleValue(block, src, elem_ty)) |opv| { |
| 27440 | if (try sema.typeHasOnePossibleValue(elem_ty)) |opv| { |
| 27499 | 27441 | return sema.addConstant(elem_ty, opv); |
| 27500 | 27442 | } |
| 27501 | 27443 | |
| ... | ... | @@ -27517,7 +27459,7 @@ fn analyzeSlicePtr( |
| 27517 | 27459 | ) CompileError!Air.Inst.Ref { |
| 27518 | 27460 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); |
| 27519 | 27461 | const result_ty = slice_ty.slicePtrFieldType(buf); |
| 27520 | | if (try sema.resolveMaybeUndefVal(block, slice_src, slice)) |val| { |
| 27462 | if (try sema.resolveMaybeUndefVal(slice)) |val| { |
| 27521 | 27463 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 27522 | 27464 | return sema.addConstant(result_ty, val.slicePtr()); |
| 27523 | 27465 | } |
| ... | ... | @@ -27531,7 +27473,7 @@ fn analyzeSliceLen( |
| 27531 | 27473 | src: LazySrcLoc, |
| 27532 | 27474 | slice_inst: Air.Inst.Ref, |
| 27533 | 27475 | ) CompileError!Air.Inst.Ref { |
| 27534 | | if (try sema.resolveMaybeUndefVal(block, src, slice_inst)) |slice_val| { |
| 27476 | if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| { |
| 27535 | 27477 | if (slice_val.isUndef()) { |
| 27536 | 27478 | return sema.addConstUndef(Type.usize); |
| 27537 | 27479 | } |
| ... | ... | @@ -27549,7 +27491,7 @@ fn analyzeIsNull( |
| 27549 | 27491 | invert_logic: bool, |
| 27550 | 27492 | ) CompileError!Air.Inst.Ref { |
| 27551 | 27493 | const result_ty = Type.bool; |
| 27552 | | if (try sema.resolveMaybeUndefVal(block, src, operand)) |opt_val| { |
| 27494 | if (try sema.resolveMaybeUndefVal(operand)) |opt_val| { |
| 27553 | 27495 | if (opt_val.isUndef()) { |
| 27554 | 27496 | return sema.addConstUndef(result_ty); |
| 27555 | 27497 | } |
| ... | ... | @@ -27627,7 +27569,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 27627 | 27569 | return Air.Inst.Ref.bool_true; |
| 27628 | 27570 | } |
| 27629 | 27571 | |
| 27630 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(block, src, operand); |
| 27572 | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 27631 | 27573 | |
| 27632 | 27574 | // exception if the error union error set is known to be empty, |
| 27633 | 27575 | // we allow the comparison but always make it comptime-known. |
| ... | ... | @@ -27791,7 +27733,7 @@ fn analyzeSlice( |
| 27791 | 27733 | ptr_or_slice; |
| 27792 | 27734 | |
| 27793 | 27735 | const start = try sema.coerce(block, Type.usize, uncasted_start, start_src); |
| 27794 | | const new_ptr = try analyzePtrArithmetic(sema, block, src, ptr, start, .ptr_add, ptr_src, start_src); |
| 27736 | const new_ptr = try sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src); |
| 27795 | 27737 | |
| 27796 | 27738 | // true if and only if the end index of the slice, implicitly or explicitly, equals |
| 27797 | 27739 | // the length of the underlying object being sliced. we might learn the length of the |
| ... | ... | @@ -27804,12 +27746,12 @@ fn analyzeSlice( |
| 27804 | 27746 | |
| 27805 | 27747 | if (!end_is_len) { |
| 27806 | 27748 | const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 27807 | | if (try sema.resolveMaybeUndefVal(block, end_src, end)) |end_val| { |
| 27749 | if (try sema.resolveMaybeUndefVal(end)) |end_val| { |
| 27808 | 27750 | const len_s_val = try Value.Tag.int_u64.create( |
| 27809 | 27751 | sema.arena, |
| 27810 | 27752 | array_ty.arrayLenIncludingSentinel(), |
| 27811 | 27753 | ); |
| 27812 | | if (!(try sema.compareAll(block, src, end_val, .lte, len_s_val, Type.usize))) { |
| 27754 | if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) { |
| 27813 | 27755 | const sentinel_label: []const u8 = if (array_ty.sentinel() != null) |
| 27814 | 27756 | " +1 (sentinel)" |
| 27815 | 27757 | else |
| ... | ... | @@ -27842,7 +27784,7 @@ fn analyzeSlice( |
| 27842 | 27784 | if (!end_is_len) { |
| 27843 | 27785 | const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 27844 | 27786 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 27845 | | if (try sema.resolveMaybeUndefVal(block, src, ptr_or_slice)) |slice_val| { |
| 27787 | if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| { |
| 27846 | 27788 | if (slice_val.isUndef()) { |
| 27847 | 27789 | return sema.fail(block, src, "slice of undefined", .{}); |
| 27848 | 27790 | } |
| ... | ... | @@ -27852,7 +27794,7 @@ fn analyzeSlice( |
| 27852 | 27794 | .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel), |
| 27853 | 27795 | }; |
| 27854 | 27796 | const slice_len_val = Value.initPayload(&int_payload.base); |
| 27855 | | if (!(try sema.compareAll(block, src, end_val, .lte, slice_len_val, Type.usize))) { |
| 27797 | if (!(try sema.compareAll(end_val, .lte, slice_len_val, Type.usize))) { |
| 27856 | 27798 | const sentinel_label: []const u8 = if (has_sentinel) |
| 27857 | 27799 | " +1 (sentinel)" |
| 27858 | 27800 | else |
| ... | ... | @@ -27911,7 +27853,7 @@ fn analyzeSlice( |
| 27911 | 27853 | // requirement: start <= end |
| 27912 | 27854 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 27913 | 27855 | if (try sema.resolveDefinedValue(block, start_src, start)) |start_val| { |
| 27914 | | if (!(try sema.compareAll(block, src, start_val, .lte, end_val, Type.usize))) { |
| 27856 | if (!(try sema.compareAll(start_val, .lte, end_val, Type.usize))) { |
| 27915 | 27857 | return sema.fail( |
| 27916 | 27858 | block, |
| 27917 | 27859 | start_src, |
| ... | ... | @@ -27922,7 +27864,7 @@ fn analyzeSlice( |
| 27922 | 27864 | }, |
| 27923 | 27865 | ); |
| 27924 | 27866 | } |
| 27925 | | if (try sema.resolveMaybeUndefVal(block, ptr_src, new_ptr)) |ptr_val| sentinel_check: { |
| 27867 | if (try sema.resolveMaybeUndefVal(new_ptr)) |ptr_val| sentinel_check: { |
| 27926 | 27868 | const expected_sentinel = sentinel orelse break :sentinel_check; |
| 27927 | 27869 | const start_int = start_val.getUnsignedInt(sema.mod.getTarget()).?; |
| 27928 | 27870 | const end_int = end_val.getUnsignedInt(sema.mod.getTarget()).?; |
| ... | ... | @@ -27984,7 +27926,7 @@ fn analyzeSlice( |
| 27984 | 27926 | .size = .One, |
| 27985 | 27927 | }); |
| 27986 | 27928 | |
| 27987 | | const opt_new_ptr_val = try sema.resolveMaybeUndefVal(block, ptr_src, new_ptr); |
| 27929 | const opt_new_ptr_val = try sema.resolveMaybeUndefVal(new_ptr); |
| 27988 | 27930 | const new_ptr_val = opt_new_ptr_val orelse { |
| 27989 | 27931 | const result = try block.addBitCast(return_ty, new_ptr); |
| 27990 | 27932 | if (block.wantSafety()) { |
| ... | ... | @@ -28038,9 +27980,9 @@ fn analyzeSlice( |
| 28038 | 27980 | .size = .Slice, |
| 28039 | 27981 | }); |
| 28040 | 27982 | |
| 28041 | | const runtime_src = if ((try sema.resolveMaybeUndefVal(block, ptr_src, ptr_or_slice)) == null) |
| 27983 | const runtime_src = if ((try sema.resolveMaybeUndefVal(ptr_or_slice)) == null) |
| 28042 | 27984 | ptr_src |
| 28043 | | else if ((try sema.resolveMaybeUndefVal(block, src, start)) == null) |
| 27985 | else if ((try sema.resolveMaybeUndefVal(start)) == null) |
| 28044 | 27986 | start_src |
| 28045 | 27987 | else |
| 28046 | 27988 | end_src; |
| ... | ... | @@ -28132,8 +28074,8 @@ fn cmpNumeric( |
| 28132 | 28074 | uncasted_rhs; |
| 28133 | 28075 | |
| 28134 | 28076 | const runtime_src: LazySrcLoc = src: { |
| 28135 | | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { |
| 28136 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| 28077 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 28078 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 28137 | 28079 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 28138 | 28080 | return sema.addConstUndef(Type.bool); |
| 28139 | 28081 | } |
| ... | ... | @@ -28144,7 +28086,7 @@ fn cmpNumeric( |
| 28144 | 28086 | return Air.Inst.Ref.bool_false; |
| 28145 | 28087 | } |
| 28146 | 28088 | } |
| 28147 | | if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, target, sema.kit(block, src))) { |
| 28089 | if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, target, sema)) { |
| 28148 | 28090 | return Air.Inst.Ref.bool_true; |
| 28149 | 28091 | } else { |
| 28150 | 28092 | return Air.Inst.Ref.bool_false; |
| ... | ... | @@ -28200,11 +28142,11 @@ fn cmpNumeric( |
| 28200 | 28142 | // a signed integer with mantissa bits + 1, and if there was any non-integral part of the float, |
| 28201 | 28143 | // add/subtract 1. |
| 28202 | 28144 | const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| |
| 28203 | | !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src))) |
| 28145 | !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema)) |
| 28204 | 28146 | else |
| 28205 | 28147 | (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt()); |
| 28206 | 28148 | const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val| |
| 28207 | | !(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src))) |
| 28149 | !(try rhs_val.compareAllWithZeroAdvanced(.gte, sema)) |
| 28208 | 28150 | else |
| 28209 | 28151 | (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt()); |
| 28210 | 28152 | const dest_int_is_signed = lhs_is_signed or rhs_is_signed; |
| ... | ... | @@ -28212,7 +28154,7 @@ fn cmpNumeric( |
| 28212 | 28154 | var dest_float_type: ?Type = null; |
| 28213 | 28155 | |
| 28214 | 28156 | var lhs_bits: usize = undefined; |
| 28215 | | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { |
| 28157 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 28216 | 28158 | if (lhs_val.isUndef()) |
| 28217 | 28159 | return sema.addConstUndef(Type.bool); |
| 28218 | 28160 | if (lhs_val.isNan()) switch (op) { |
| ... | ... | @@ -28265,7 +28207,7 @@ fn cmpNumeric( |
| 28265 | 28207 | } |
| 28266 | 28208 | |
| 28267 | 28209 | var rhs_bits: usize = undefined; |
| 28268 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| 28210 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 28269 | 28211 | if (rhs_val.isUndef()) |
| 28270 | 28212 | return sema.addConstUndef(Type.bool); |
| 28271 | 28213 | if (rhs_val.isNan()) switch (op) { |
| ... | ... | @@ -28349,12 +28291,12 @@ fn cmpVector( |
| 28349 | 28291 | const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.@"bool"); |
| 28350 | 28292 | |
| 28351 | 28293 | const runtime_src: LazySrcLoc = src: { |
| 28352 | | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { |
| 28353 | | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| 28294 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 28295 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 28354 | 28296 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 28355 | 28297 | return sema.addConstUndef(result_ty); |
| 28356 | 28298 | } |
| 28357 | | const cmp_val = try sema.compareVector(block, src, lhs_val, op, rhs_val, lhs_ty); |
| 28299 | const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, lhs_ty); |
| 28358 | 28300 | return sema.addConstant(result_ty, cmp_val); |
| 28359 | 28301 | } else { |
| 28360 | 28302 | break :src rhs_src; |
| ... | ... | @@ -28376,7 +28318,7 @@ fn wrapOptional( |
| 28376 | 28318 | inst: Air.Inst.Ref, |
| 28377 | 28319 | inst_src: LazySrcLoc, |
| 28378 | 28320 | ) !Air.Inst.Ref { |
| 28379 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 28321 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 28380 | 28322 | return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, val)); |
| 28381 | 28323 | } |
| 28382 | 28324 | |
| ... | ... | @@ -28393,7 +28335,7 @@ fn wrapErrorUnionPayload( |
| 28393 | 28335 | ) !Air.Inst.Ref { |
| 28394 | 28336 | const dest_payload_ty = dest_ty.errorUnionPayload(); |
| 28395 | 28337 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 28396 | | if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| { |
| 28338 | if (try sema.resolveMaybeUndefVal(coerced)) |val| { |
| 28397 | 28339 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); |
| 28398 | 28340 | } |
| 28399 | 28341 | try sema.requireRuntimeBlock(block, inst_src, null); |
| ... | ... | @@ -28410,7 +28352,7 @@ fn wrapErrorUnionSet( |
| 28410 | 28352 | ) !Air.Inst.Ref { |
| 28411 | 28353 | const inst_ty = sema.typeOf(inst); |
| 28412 | 28354 | const dest_err_set_ty = dest_ty.errorUnionSet(); |
| 28413 | | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 28355 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 28414 | 28356 | switch (dest_err_set_ty.tag()) { |
| 28415 | 28357 | .anyerror => {}, |
| 28416 | 28358 | .error_set_single => ok: { |
| ... | ... | @@ -28464,10 +28406,10 @@ fn unionToTag( |
| 28464 | 28406 | un: Air.Inst.Ref, |
| 28465 | 28407 | un_src: LazySrcLoc, |
| 28466 | 28408 | ) !Air.Inst.Ref { |
| 28467 | | if ((try sema.typeHasOnePossibleValue(block, un_src, enum_ty))) |opv| { |
| 28409 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { |
| 28468 | 28410 | return sema.addConstant(enum_ty, opv); |
| 28469 | 28411 | } |
| 28470 | | if (try sema.resolveMaybeUndefVal(block, un_src, un)) |un_val| { |
| 28412 | if (try sema.resolveMaybeUndefVal(un)) |un_val| { |
| 28471 | 28413 | return sema.addConstant(enum_ty, un_val.unionTag()); |
| 28472 | 28414 | } |
| 28473 | 28415 | try sema.requireRuntimeBlock(block, un_src, null); |
| ... | ... | @@ -29029,72 +28971,57 @@ fn resolvePeerTypes( |
| 29029 | 28971 | return chosen_ty; |
| 29030 | 28972 | } |
| 29031 | 28973 | |
| 29032 | | pub fn resolveFnTypes( |
| 29033 | | sema: *Sema, |
| 29034 | | block: *Block, |
| 29035 | | src: LazySrcLoc, |
| 29036 | | fn_info: Type.Payload.Function.Data, |
| 29037 | | ) CompileError!void { |
| 29038 | | try sema.resolveTypeFully(block, src, fn_info.return_type); |
| 28974 | pub fn resolveFnTypes(sema: *Sema, fn_info: Type.Payload.Function.Data) CompileError!void { |
| 28975 | try sema.resolveTypeFully(fn_info.return_type); |
| 29039 | 28976 | |
| 29040 | 28977 | if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) { |
| 29041 | 28978 | // Ensure the type exists so that backends can assume that. |
| 29042 | | _ = try sema.getBuiltinType(block, src, "StackTrace"); |
| 28979 | _ = try sema.getBuiltinType("StackTrace"); |
| 29043 | 28980 | } |
| 29044 | 28981 | |
| 29045 | 28982 | for (fn_info.param_types) |param_ty| { |
| 29046 | | try sema.resolveTypeFully(block, src, param_ty); |
| 28983 | try sema.resolveTypeFully(param_ty); |
| 29047 | 28984 | } |
| 29048 | 28985 | } |
| 29049 | 28986 | |
| 29050 | 28987 | /// Make it so that calling hash() and eql() on `val` will not assert due |
| 29051 | 28988 | /// to a type not having its layout resolved. |
| 29052 | | fn resolveLazyValue( |
| 29053 | | sema: *Sema, |
| 29054 | | block: *Block, |
| 29055 | | src: LazySrcLoc, |
| 29056 | | val: Value, |
| 29057 | | ) CompileError!void { |
| 28989 | fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void { |
| 29058 | 28990 | switch (val.tag()) { |
| 29059 | 28991 | .lazy_align => { |
| 29060 | 28992 | const ty = val.castTag(.lazy_align).?.data; |
| 29061 | | return sema.resolveTypeLayout(block, src, ty); |
| 28993 | return sema.resolveTypeLayout(ty); |
| 29062 | 28994 | }, |
| 29063 | 28995 | .lazy_size => { |
| 29064 | 28996 | const ty = val.castTag(.lazy_size).?.data; |
| 29065 | | return sema.resolveTypeLayout(block, src, ty); |
| 28997 | return sema.resolveTypeLayout(ty); |
| 29066 | 28998 | }, |
| 29067 | 28999 | .comptime_field_ptr => { |
| 29068 | 29000 | const field_ptr = val.castTag(.comptime_field_ptr).?.data; |
| 29069 | | return sema.resolveLazyValue(block, src, field_ptr.field_val); |
| 29001 | return sema.resolveLazyValue(field_ptr.field_val); |
| 29070 | 29002 | }, |
| 29071 | 29003 | .@"union" => { |
| 29072 | 29004 | const union_val = val.castTag(.@"union").?.data; |
| 29073 | | return sema.resolveLazyValue(block, src, union_val.val); |
| 29005 | return sema.resolveLazyValue(union_val.val); |
| 29074 | 29006 | }, |
| 29075 | 29007 | .aggregate => { |
| 29076 | 29008 | const aggregate = val.castTag(.aggregate).?.data; |
| 29077 | 29009 | for (aggregate) |elem_val| { |
| 29078 | | try sema.resolveLazyValue(block, src, elem_val); |
| 29010 | try sema.resolveLazyValue(elem_val); |
| 29079 | 29011 | } |
| 29080 | 29012 | }, |
| 29081 | 29013 | else => return, |
| 29082 | 29014 | } |
| 29083 | 29015 | } |
| 29084 | 29016 | |
| 29085 | | pub fn resolveTypeLayout( |
| 29086 | | sema: *Sema, |
| 29087 | | block: *Block, |
| 29088 | | src: LazySrcLoc, |
| 29089 | | ty: Type, |
| 29090 | | ) CompileError!void { |
| 29017 | pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29091 | 29018 | switch (ty.zigTypeTag()) { |
| 29092 | | .Struct => return sema.resolveStructLayout(block, src, ty), |
| 29093 | | .Union => return sema.resolveUnionLayout(block, src, ty), |
| 29019 | .Struct => return sema.resolveStructLayout(ty), |
| 29020 | .Union => return sema.resolveUnionLayout(ty), |
| 29094 | 29021 | .Array => { |
| 29095 | 29022 | if (ty.arrayLenIncludingSentinel() == 0) return; |
| 29096 | 29023 | const elem_ty = ty.childType(); |
| 29097 | | return sema.resolveTypeLayout(block, src, elem_ty); |
| 29024 | return sema.resolveTypeLayout(elem_ty); |
| 29098 | 29025 | }, |
| 29099 | 29026 | .Optional => { |
| 29100 | 29027 | var buf: Type.Payload.ElemType = undefined; |
| ... | ... | @@ -29103,23 +29030,18 @@ pub fn resolveTypeLayout( |
| 29103 | 29030 | // for hasRuntimeBits() of the payload type, so we need "requires comptime" |
| 29104 | 29031 | // to be known already before this function returns. |
| 29105 | 29032 | _ = try sema.typeRequiresComptime(payload_ty); |
| 29106 | | return sema.resolveTypeLayout(block, src, payload_ty); |
| 29033 | return sema.resolveTypeLayout(payload_ty); |
| 29107 | 29034 | }, |
| 29108 | 29035 | .ErrorUnion => { |
| 29109 | 29036 | const payload_ty = ty.errorUnionPayload(); |
| 29110 | | return sema.resolveTypeLayout(block, src, payload_ty); |
| 29037 | return sema.resolveTypeLayout(payload_ty); |
| 29111 | 29038 | }, |
| 29112 | 29039 | else => {}, |
| 29113 | 29040 | } |
| 29114 | 29041 | } |
| 29115 | 29042 | |
| 29116 | | fn resolveStructLayout( |
| 29117 | | sema: *Sema, |
| 29118 | | block: *Block, |
| 29119 | | src: LazySrcLoc, |
| 29120 | | ty: Type, |
| 29121 | | ) CompileError!void { |
| 29122 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 29043 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29044 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29123 | 29045 | if (resolved_ty.castTag(.@"struct")) |payload| { |
| 29124 | 29046 | const struct_obj = payload.data; |
| 29125 | 29047 | switch (struct_obj.status) { |
| ... | ... | @@ -29137,7 +29059,7 @@ fn resolveStructLayout( |
| 29137 | 29059 | } |
| 29138 | 29060 | struct_obj.status = .layout_wip; |
| 29139 | 29061 | for (struct_obj.fields.values()) |field, i| { |
| 29140 | | sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) { |
| 29062 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 29141 | 29063 | error.AnalysisFail => { |
| 29142 | 29064 | const msg = sema.err orelse return err; |
| 29143 | 29065 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| ... | ... | @@ -29301,13 +29223,8 @@ fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ |
| 29301 | 29223 | } |
| 29302 | 29224 | } |
| 29303 | 29225 | |
| 29304 | | fn resolveUnionLayout( |
| 29305 | | sema: *Sema, |
| 29306 | | block: *Block, |
| 29307 | | src: LazySrcLoc, |
| 29308 | | ty: Type, |
| 29309 | | ) CompileError!void { |
| 29310 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 29226 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29227 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29311 | 29228 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| 29312 | 29229 | switch (union_obj.status) { |
| 29313 | 29230 | .none, .have_field_types => {}, |
| ... | ... | @@ -29324,7 +29241,7 @@ fn resolveUnionLayout( |
| 29324 | 29241 | } |
| 29325 | 29242 | union_obj.status = .layout_wip; |
| 29326 | 29243 | for (union_obj.fields.values()) |field, i| { |
| 29327 | | sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) { |
| 29244 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 29328 | 29245 | error.AnalysisFail => { |
| 29329 | 29246 | const msg = sema.err orelse return err; |
| 29330 | 29247 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| ... | ... | @@ -29338,35 +29255,30 @@ fn resolveUnionLayout( |
| 29338 | 29255 | |
| 29339 | 29256 | /// Returns `error.AnalysisFail` if any of the types (recursively) failed to |
| 29340 | 29257 | /// be resolved. |
| 29341 | | pub fn resolveTypeFully( |
| 29342 | | sema: *Sema, |
| 29343 | | block: *Block, |
| 29344 | | src: LazySrcLoc, |
| 29345 | | ty: Type, |
| 29346 | | ) CompileError!void { |
| 29258 | pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { |
| 29347 | 29259 | switch (ty.zigTypeTag()) { |
| 29348 | 29260 | .Pointer => { |
| 29349 | | const child_ty = try sema.resolveTypeFields(block, src, ty.childType()); |
| 29350 | | return resolveTypeFully(sema, block, src, child_ty); |
| 29261 | const child_ty = try sema.resolveTypeFields(ty.childType()); |
| 29262 | return sema.resolveTypeFully(child_ty); |
| 29351 | 29263 | }, |
| 29352 | 29264 | .Struct => switch (ty.tag()) { |
| 29353 | | .@"struct" => return resolveStructFully(sema, block, src, ty), |
| 29265 | .@"struct" => return sema.resolveStructFully(ty), |
| 29354 | 29266 | .tuple, .anon_struct => { |
| 29355 | 29267 | const tuple = ty.tupleFields(); |
| 29356 | 29268 | |
| 29357 | 29269 | for (tuple.types) |field_ty| { |
| 29358 | | try sema.resolveTypeFully(block, src, field_ty); |
| 29270 | try sema.resolveTypeFully(field_ty); |
| 29359 | 29271 | } |
| 29360 | 29272 | }, |
| 29361 | 29273 | else => {}, |
| 29362 | 29274 | }, |
| 29363 | | .Union => return resolveUnionFully(sema, block, src, ty), |
| 29364 | | .Array => return resolveTypeFully(sema, block, src, ty.childType()), |
| 29275 | .Union => return sema.resolveUnionFully(ty), |
| 29276 | .Array => return sema.resolveTypeFully(ty.childType()), |
| 29365 | 29277 | .Optional => { |
| 29366 | 29278 | var buf: Type.Payload.ElemType = undefined; |
| 29367 | | return resolveTypeFully(sema, block, src, ty.optionalChild(&buf)); |
| 29279 | return sema.resolveTypeFully(ty.optionalChild(&buf)); |
| 29368 | 29280 | }, |
| 29369 | | .ErrorUnion => return resolveTypeFully(sema, block, src, ty.errorUnionPayload()), |
| 29281 | .ErrorUnion => return sema.resolveTypeFully(ty.errorUnionPayload()), |
| 29370 | 29282 | .Fn => { |
| 29371 | 29283 | const info = ty.fnInfo(); |
| 29372 | 29284 | if (info.is_generic) { |
| ... | ... | @@ -29375,25 +29287,18 @@ pub fn resolveTypeFully( |
| 29375 | 29287 | return; |
| 29376 | 29288 | } |
| 29377 | 29289 | for (info.param_types) |param_ty| { |
| 29378 | | const param_ty_src = src; // TODO better source location |
| 29379 | | try sema.resolveTypeFully(block, param_ty_src, param_ty); |
| 29290 | try sema.resolveTypeFully(param_ty); |
| 29380 | 29291 | } |
| 29381 | | const return_ty_src = src; // TODO better source location |
| 29382 | | try sema.resolveTypeFully(block, return_ty_src, info.return_type); |
| 29292 | try sema.resolveTypeFully(info.return_type); |
| 29383 | 29293 | }, |
| 29384 | 29294 | else => {}, |
| 29385 | 29295 | } |
| 29386 | 29296 | } |
| 29387 | 29297 | |
| 29388 | | fn resolveStructFully( |
| 29389 | | sema: *Sema, |
| 29390 | | block: *Block, |
| 29391 | | src: LazySrcLoc, |
| 29392 | | ty: Type, |
| 29393 | | ) CompileError!void { |
| 29394 | | try resolveStructLayout(sema, block, src, ty); |
| 29298 | fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void { |
| 29299 | try sema.resolveStructLayout(ty); |
| 29395 | 29300 | |
| 29396 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 29301 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29397 | 29302 | const payload = resolved_ty.castTag(.@"struct").?; |
| 29398 | 29303 | const struct_obj = payload.data; |
| 29399 | 29304 | |
| ... | ... | @@ -29411,7 +29316,7 @@ fn resolveStructFully( |
| 29411 | 29316 | |
| 29412 | 29317 | struct_obj.status = .fully_resolved_wip; |
| 29413 | 29318 | for (struct_obj.fields.values()) |field| { |
| 29414 | | try sema.resolveTypeFully(block, src, field.ty); |
| 29319 | try sema.resolveTypeFully(field.ty); |
| 29415 | 29320 | } |
| 29416 | 29321 | struct_obj.status = .fully_resolved; |
| 29417 | 29322 | } |
| ... | ... | @@ -29420,15 +29325,10 @@ fn resolveStructFully( |
| 29420 | 29325 | _ = try sema.typeRequiresComptime(ty); |
| 29421 | 29326 | } |
| 29422 | 29327 | |
| 29423 | | fn resolveUnionFully( |
| 29424 | | sema: *Sema, |
| 29425 | | block: *Block, |
| 29426 | | src: LazySrcLoc, |
| 29427 | | ty: Type, |
| 29428 | | ) CompileError!void { |
| 29429 | | try resolveUnionLayout(sema, block, src, ty); |
| 29328 | fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void { |
| 29329 | try sema.resolveUnionLayout(ty); |
| 29430 | 29330 | |
| 29431 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 29331 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29432 | 29332 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| 29433 | 29333 | switch (union_obj.status) { |
| 29434 | 29334 | .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {}, |
| ... | ... | @@ -29444,7 +29344,7 @@ fn resolveUnionFully( |
| 29444 | 29344 | |
| 29445 | 29345 | union_obj.status = .fully_resolved_wip; |
| 29446 | 29346 | for (union_obj.fields.values()) |field| { |
| 29447 | | try sema.resolveTypeFully(block, src, field.ty); |
| 29347 | try sema.resolveTypeFully(field.ty); |
| 29448 | 29348 | } |
| 29449 | 29349 | union_obj.status = .fully_resolved; |
| 29450 | 29350 | } |
| ... | ... | @@ -29453,7 +29353,7 @@ fn resolveUnionFully( |
| 29453 | 29353 | _ = try sema.typeRequiresComptime(ty); |
| 29454 | 29354 | } |
| 29455 | 29355 | |
| 29456 | | pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| 29356 | pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 29457 | 29357 | switch (ty.tag()) { |
| 29458 | 29358 | .@"struct" => { |
| 29459 | 29359 | const struct_obj = ty.castTag(.@"struct").?.data; |
| ... | ... | @@ -29465,17 +29365,17 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 29465 | 29365 | try sema.resolveTypeFieldsUnion(ty, union_obj); |
| 29466 | 29366 | return ty; |
| 29467 | 29367 | }, |
| 29468 | | .type_info => return sema.resolveBuiltinTypeFields(block, src, "Type"), |
| 29469 | | .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"), |
| 29470 | | .export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"), |
| 29471 | | .atomic_order => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrder"), |
| 29472 | | .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"), |
| 29473 | | .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"), |
| 29474 | | .address_space => return sema.resolveBuiltinTypeFields(block, src, "AddressSpace"), |
| 29475 | | .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"), |
| 29476 | | .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"), |
| 29477 | | .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"), |
| 29478 | | .prefetch_options => return sema.resolveBuiltinTypeFields(block, src, "PrefetchOptions"), |
| 29368 | .type_info => return sema.getBuiltinType("Type"), |
| 29369 | .extern_options => return sema.getBuiltinType("ExternOptions"), |
| 29370 | .export_options => return sema.getBuiltinType("ExportOptions"), |
| 29371 | .atomic_order => return sema.getBuiltinType("AtomicOrder"), |
| 29372 | .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"), |
| 29373 | .calling_convention => return sema.getBuiltinType("CallingConvention"), |
| 29374 | .address_space => return sema.getBuiltinType("AddressSpace"), |
| 29375 | .float_mode => return sema.getBuiltinType("FloatMode"), |
| 29376 | .reduce_op => return sema.getBuiltinType("ReduceOp"), |
| 29377 | .call_options => return sema.getBuiltinType("CallOptions"), |
| 29378 | .prefetch_options => return sema.getBuiltinType("PrefetchOptions"), |
| 29479 | 29379 | |
| 29480 | 29380 | else => return ty, |
| 29481 | 29381 | } |
| ... | ... | @@ -29534,16 +29434,6 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi |
| 29534 | 29434 | union_obj.status = .have_field_types; |
| 29535 | 29435 | } |
| 29536 | 29436 | |
| 29537 | | fn resolveBuiltinTypeFields( |
| 29538 | | sema: *Sema, |
| 29539 | | block: *Block, |
| 29540 | | src: LazySrcLoc, |
| 29541 | | name: []const u8, |
| 29542 | | ) CompileError!Type { |
| 29543 | | const resolved_ty = try sema.getBuiltinType(block, src, name); |
| 29544 | | return sema.resolveTypeFields(block, src, resolved_ty); |
| 29545 | | } |
| 29546 | | |
| 29547 | 29437 | fn resolveInferredErrorSet( |
| 29548 | 29438 | sema: *Sema, |
| 29549 | 29439 | block: *Block, |
| ... | ... | @@ -29828,7 +29718,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 29828 | 29718 | }; |
| 29829 | 29719 | return sema.failWithOwnedErrorMsg(msg); |
| 29830 | 29720 | } |
| 29831 | | if (struct_obj.layout == .Extern and !try sema.validateExternType(&block_scope, src, field.ty, .struct_field)) { |
| 29721 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field.ty, .struct_field)) { |
| 29832 | 29722 | const msg = msg: { |
| 29833 | 29723 | const tree = try sema.getAstTree(&block_scope); |
| 29834 | 29724 | const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i); |
| ... | ... | @@ -29879,7 +29769,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 29879 | 29769 | const init = try sema.resolveBody(&block_scope, body, struct_obj.zir_index); |
| 29880 | 29770 | const field = &struct_obj.fields.values()[i]; |
| 29881 | 29771 | const coerced = try sema.coerce(&block_scope, field.ty, init, src); |
| 29882 | | const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, coerced)) orelse |
| 29772 | const default_val = (try sema.resolveMaybeUndefVal(coerced)) orelse |
| 29883 | 29773 | return sema.failWithNeededComptime(&block_scope, src, "struct field default value must be comptime-known"); |
| 29884 | 29774 | field.default_val = try default_val.copy(decl_arena_allocator); |
| 29885 | 29775 | } |
| ... | ... | @@ -30089,7 +29979,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30089 | 29979 | }); |
| 30090 | 29980 | } else { |
| 30091 | 29981 | const val = if (last_tag_val) |val| |
| 30092 | | try sema.intAdd(&block_scope, src, val, Value.one, int_tag_ty) |
| 29982 | try sema.intAdd(val, Value.one, int_tag_ty) |
| 30093 | 29983 | else |
| 30094 | 29984 | Value.zero; |
| 30095 | 29985 | last_tag_val = val; |
| ... | ... | @@ -30166,7 +30056,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30166 | 30056 | }; |
| 30167 | 30057 | return sema.failWithOwnedErrorMsg(msg); |
| 30168 | 30058 | } |
| 30169 | | if (union_obj.layout == .Extern and !try sema.validateExternType(&block_scope, src, field_ty, .union_field)) { |
| 30059 | if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { |
| 30170 | 30060 | const msg = msg: { |
| 30171 | 30061 | const tree = try sema.getAstTree(&block_scope); |
| 30172 | 30062 | const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i); |
| ... | ... | @@ -30338,41 +30228,76 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: usize, may |
| 30338 | 30228 | return enum_ty; |
| 30339 | 30229 | } |
| 30340 | 30230 | |
| 30341 | | fn getBuiltin( |
| 30342 | | sema: *Sema, |
| 30343 | | block: *Block, |
| 30344 | | src: LazySrcLoc, |
| 30345 | | name: []const u8, |
| 30346 | | ) CompileError!Air.Inst.Ref { |
| 30231 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 30232 | var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope); |
| 30233 | defer wip_captures.deinit(); |
| 30234 | |
| 30235 | var block: Block = .{ |
| 30236 | .parent = null, |
| 30237 | .sema = sema, |
| 30238 | .src_decl = sema.owner_decl_index, |
| 30239 | .namespace = sema.owner_decl.src_namespace, |
| 30240 | .wip_capture_scope = wip_captures.scope, |
| 30241 | .instructions = .{}, |
| 30242 | .inlining = null, |
| 30243 | .is_comptime = true, |
| 30244 | }; |
| 30245 | defer { |
| 30246 | block.instructions.deinit(sema.gpa); |
| 30247 | block.params.deinit(sema.gpa); |
| 30248 | } |
| 30249 | const src = LazySrcLoc.nodeOffset(0); |
| 30250 | |
| 30347 | 30251 | const mod = sema.mod; |
| 30348 | 30252 | const std_pkg = mod.main_pkg.table.get("std").?; |
| 30349 | 30253 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| 30350 | | const opt_builtin_inst = try sema.namespaceLookupRef( |
| 30351 | | block, |
| 30254 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 30255 | &block, |
| 30352 | 30256 | src, |
| 30353 | 30257 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 30354 | 30258 | "builtin", |
| 30355 | | ); |
| 30356 | | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src); |
| 30357 | | const builtin_ty = try sema.analyzeAsType(block, src, builtin_inst); |
| 30358 | | const opt_ty_decl = try sema.namespaceLookup( |
| 30359 | | block, |
| 30259 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 30260 | const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src); |
| 30261 | const builtin_ty = sema.analyzeAsType(&block, src, builtin_inst) catch |err| switch (err) { |
| 30262 | error.AnalysisFail => std.debug.panic("std.builtin is corrupt", .{}), |
| 30263 | else => |e| return e, |
| 30264 | }; |
| 30265 | const opt_ty_decl = (try sema.namespaceLookup( |
| 30266 | &block, |
| 30360 | 30267 | src, |
| 30361 | 30268 | builtin_ty.getNamespace().?, |
| 30362 | 30269 | name, |
| 30363 | | ); |
| 30364 | | return sema.analyzeDeclVal(block, src, opt_ty_decl.?); |
| 30270 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 30271 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); |
| 30365 | 30272 | } |
| 30366 | 30273 | |
| 30367 | | fn getBuiltinType( |
| 30368 | | sema: *Sema, |
| 30369 | | block: *Block, |
| 30370 | | src: LazySrcLoc, |
| 30371 | | name: []const u8, |
| 30372 | | ) CompileError!Type { |
| 30373 | | const ty_inst = try sema.getBuiltin(block, src, name); |
| 30374 | | const result_ty = try sema.analyzeAsType(block, src, ty_inst); |
| 30375 | | try sema.resolveTypeFully(block, src, result_ty); // Should not fail |
| 30274 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 30275 | const ty_inst = try sema.getBuiltin(name); |
| 30276 | |
| 30277 | var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope); |
| 30278 | defer wip_captures.deinit(); |
| 30279 | |
| 30280 | var block: Block = .{ |
| 30281 | .parent = null, |
| 30282 | .sema = sema, |
| 30283 | .src_decl = sema.owner_decl_index, |
| 30284 | .namespace = sema.owner_decl.src_namespace, |
| 30285 | .wip_capture_scope = wip_captures.scope, |
| 30286 | .instructions = .{}, |
| 30287 | .inlining = null, |
| 30288 | .is_comptime = true, |
| 30289 | }; |
| 30290 | defer { |
| 30291 | block.instructions.deinit(sema.gpa); |
| 30292 | block.params.deinit(sema.gpa); |
| 30293 | } |
| 30294 | const src = LazySrcLoc.nodeOffset(0); |
| 30295 | |
| 30296 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { |
| 30297 | error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}), |
| 30298 | else => |e| return e, |
| 30299 | }; |
| 30300 | try sema.resolveTypeFully(result_ty); // Should not fail |
| 30376 | 30301 | return result_ty; |
| 30377 | 30302 | } |
| 30378 | 30303 | |
| ... | ... | @@ -30381,12 +30306,7 @@ fn getBuiltinType( |
| 30381 | 30306 | /// to get the answer. The one in `Type` is for calling during codegen and asserts |
| 30382 | 30307 | /// that the types are already resolved. |
| 30383 | 30308 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 30384 | | pub fn typeHasOnePossibleValue( |
| 30385 | | sema: *Sema, |
| 30386 | | block: *Block, |
| 30387 | | src: LazySrcLoc, |
| 30388 | | ty: Type, |
| 30389 | | ) CompileError!?Value { |
| 30309 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 30390 | 30310 | switch (ty.tag()) { |
| 30391 | 30311 | .f16, |
| 30392 | 30312 | .f32, |
| ... | ... | @@ -30482,7 +30402,7 @@ pub fn typeHasOnePossibleValue( |
| 30482 | 30402 | }, |
| 30483 | 30403 | |
| 30484 | 30404 | .@"struct" => { |
| 30485 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 30405 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30486 | 30406 | const s = resolved_ty.castTag(.@"struct").?.data; |
| 30487 | 30407 | for (s.fields.values()) |field, i| { |
| 30488 | 30408 | if (field.is_comptime) continue; |
| ... | ... | @@ -30496,7 +30416,7 @@ pub fn typeHasOnePossibleValue( |
| 30496 | 30416 | try sema.addFieldErrNote(resolved_ty, i, msg, "while checking this field", .{}); |
| 30497 | 30417 | return sema.failWithOwnedErrorMsg(msg); |
| 30498 | 30418 | } |
| 30499 | | if ((try sema.typeHasOnePossibleValue(block, src, field.ty)) == null) { |
| 30419 | if ((try sema.typeHasOnePossibleValue(field.ty)) == null) { |
| 30500 | 30420 | return null; |
| 30501 | 30421 | } |
| 30502 | 30422 | } |
| ... | ... | @@ -30508,14 +30428,14 @@ pub fn typeHasOnePossibleValue( |
| 30508 | 30428 | for (tuple.values) |val, i| { |
| 30509 | 30429 | const is_comptime = val.tag() != .unreachable_value; |
| 30510 | 30430 | if (is_comptime) continue; |
| 30511 | | if ((try sema.typeHasOnePossibleValue(block, src, tuple.types[i])) != null) continue; |
| 30431 | if ((try sema.typeHasOnePossibleValue(tuple.types[i])) != null) continue; |
| 30512 | 30432 | return null; |
| 30513 | 30433 | } |
| 30514 | 30434 | return Value.initTag(.empty_struct_value); |
| 30515 | 30435 | }, |
| 30516 | 30436 | |
| 30517 | 30437 | .enum_numbered => { |
| 30518 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 30438 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30519 | 30439 | const enum_obj = resolved_ty.castTag(.enum_numbered).?.data; |
| 30520 | 30440 | // An explicit tag type is always provided for enum_numbered. |
| 30521 | 30441 | if (enum_obj.tag_ty.hasRuntimeBits()) { |
| ... | ... | @@ -30532,7 +30452,7 @@ pub fn typeHasOnePossibleValue( |
| 30532 | 30452 | } |
| 30533 | 30453 | }, |
| 30534 | 30454 | .enum_full => { |
| 30535 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 30455 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30536 | 30456 | const enum_obj = resolved_ty.castTag(.enum_full).?.data; |
| 30537 | 30457 | if (enum_obj.tag_ty.hasRuntimeBits()) { |
| 30538 | 30458 | return null; |
| ... | ... | @@ -30548,7 +30468,7 @@ pub fn typeHasOnePossibleValue( |
| 30548 | 30468 | } |
| 30549 | 30469 | }, |
| 30550 | 30470 | .enum_simple => { |
| 30551 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 30471 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30552 | 30472 | const enum_simple = resolved_ty.castTag(.enum_simple).?.data; |
| 30553 | 30473 | switch (enum_simple.fields.count()) { |
| 30554 | 30474 | 0 => return Value.initTag(.unreachable_value), |
| ... | ... | @@ -30558,16 +30478,16 @@ pub fn typeHasOnePossibleValue( |
| 30558 | 30478 | }, |
| 30559 | 30479 | .enum_nonexhaustive => { |
| 30560 | 30480 | const tag_ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty; |
| 30561 | | if (tag_ty.zigTypeTag() != .ComptimeInt and !(try sema.typeHasRuntimeBits(block, src, tag_ty))) { |
| 30481 | if (tag_ty.zigTypeTag() != .ComptimeInt and !(try sema.typeHasRuntimeBits(tag_ty))) { |
| 30562 | 30482 | return Value.zero; |
| 30563 | 30483 | } else { |
| 30564 | 30484 | return null; |
| 30565 | 30485 | } |
| 30566 | 30486 | }, |
| 30567 | 30487 | .@"union", .union_safety_tagged, .union_tagged => { |
| 30568 | | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 30488 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30569 | 30489 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| 30570 | | const tag_val = (try sema.typeHasOnePossibleValue(block, src, union_obj.tag_ty)) orelse |
| 30490 | const tag_val = (try sema.typeHasOnePossibleValue(union_obj.tag_ty)) orelse |
| 30571 | 30491 | return null; |
| 30572 | 30492 | const fields = union_obj.fields.values(); |
| 30573 | 30493 | if (fields.len == 0) return Value.initTag(.unreachable_value); |
| ... | ... | @@ -30582,7 +30502,7 @@ pub fn typeHasOnePossibleValue( |
| 30582 | 30502 | try sema.addFieldErrNote(resolved_ty, 0, msg, "while checking this field", .{}); |
| 30583 | 30503 | return sema.failWithOwnedErrorMsg(msg); |
| 30584 | 30504 | } |
| 30585 | | const val_val = (try sema.typeHasOnePossibleValue(block, src, only_field.ty)) orelse |
| 30505 | const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse |
| 30586 | 30506 | return null; |
| 30587 | 30507 | // TODO make this not allocate. The function in `Type.onePossibleValue` |
| 30588 | 30508 | // currently returns `empty_struct_value` and we should do that here too. |
| ... | ... | @@ -30608,7 +30528,7 @@ pub fn typeHasOnePossibleValue( |
| 30608 | 30528 | .vector, .array, .array_u8 => { |
| 30609 | 30529 | if (ty.arrayLen() == 0) |
| 30610 | 30530 | return Value.initTag(.empty_array); |
| 30611 | | if ((try sema.typeHasOnePossibleValue(block, src, ty.elemType())) != null) { |
| 30531 | if ((try sema.typeHasOnePossibleValue(ty.elemType())) != null) { |
| 30612 | 30532 | return Value.initTag(.the_only_possible_value); |
| 30613 | 30533 | } |
| 30614 | 30534 | return null; |
| ... | ... | @@ -30799,7 +30719,7 @@ pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref { |
| 30799 | 30719 | pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { |
| 30800 | 30720 | const fields = std.meta.fields(@TypeOf(extra)); |
| 30801 | 30721 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len); |
| 30802 | | return addExtraAssumeCapacity(sema, extra); |
| 30722 | return sema.addExtraAssumeCapacity(extra); |
| 30803 | 30723 | } |
| 30804 | 30724 | |
| 30805 | 30725 | pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { |
| ... | ... | @@ -30832,11 +30752,9 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| 30832 | 30752 | |
| 30833 | 30753 | fn isComptimeKnown( |
| 30834 | 30754 | sema: *Sema, |
| 30835 | | block: *Block, |
| 30836 | | src: LazySrcLoc, |
| 30837 | 30755 | inst: Air.Inst.Ref, |
| 30838 | 30756 | ) !bool { |
| 30839 | | return (try sema.resolveMaybeUndefVal(block, src, inst)) != null; |
| 30757 | return (try sema.resolveMaybeUndefVal(inst)) != null; |
| 30840 | 30758 | } |
| 30841 | 30759 | |
| 30842 | 30760 | fn analyzeComptimeAlloc( |
| ... | ... | @@ -30844,10 +30762,9 @@ fn analyzeComptimeAlloc( |
| 30844 | 30762 | block: *Block, |
| 30845 | 30763 | var_type: Type, |
| 30846 | 30764 | alignment: u32, |
| 30847 | | src: LazySrcLoc, |
| 30848 | 30765 | ) CompileError!Air.Inst.Ref { |
| 30849 | 30766 | // Needed to make an anon decl with type `var_type` (the `finish()` call below). |
| 30850 | | _ = try sema.typeHasOnePossibleValue(block, src, var_type); |
| 30767 | _ = try sema.typeHasOnePossibleValue(var_type); |
| 30851 | 30768 | |
| 30852 | 30769 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 30853 | 30770 | .pointee_type = var_type, |
| ... | ... | @@ -30855,7 +30772,7 @@ fn analyzeComptimeAlloc( |
| 30855 | 30772 | .@"align" = alignment, |
| 30856 | 30773 | }); |
| 30857 | 30774 | |
| 30858 | | var anon_decl = try block.startAnonDecl(src); |
| 30775 | var anon_decl = try block.startAnonDecl(); |
| 30859 | 30776 | defer anon_decl.deinit(); |
| 30860 | 30777 | |
| 30861 | 30778 | const decl_index = try anon_decl.finish( |
| ... | ... | @@ -30996,14 +30913,14 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value |
| 30996 | 30913 | return DerefResult{ .needed_well_defined = load_ty }; |
| 30997 | 30914 | } |
| 30998 | 30915 | |
| 30999 | | const load_sz = try sema.typeAbiSize(block, src, load_ty); |
| 30916 | const load_sz = try sema.typeAbiSize(load_ty); |
| 31000 | 30917 | |
| 31001 | 30918 | // Try the smaller bit-cast first, since that's more efficient than using the larger `parent` |
| 31002 | | if (deref.pointee) |tv| if (load_sz <= try sema.typeAbiSize(block, src, tv.ty)) |
| 30919 | if (deref.pointee) |tv| if (load_sz <= try sema.typeAbiSize(tv.ty)) |
| 31003 | 30920 | return DerefResult{ .val = try sema.bitCastVal(block, src, tv.val, tv.ty, load_ty, 0) }; |
| 31004 | 30921 | |
| 31005 | 30922 | // If that fails, try to bit-cast from the largest parent value with a well-defined layout |
| 31006 | | if (deref.parent) |parent| if (load_sz + parent.byte_offset <= try sema.typeAbiSize(block, src, parent.tv.ty)) |
| 30923 | if (deref.parent) |parent| if (load_sz + parent.byte_offset <= try sema.typeAbiSize(parent.tv.ty)) |
| 31007 | 30924 | return DerefResult{ .val = try sema.bitCastVal(block, src, parent.tv.val, parent.tv.ty, load_ty, parent.byte_offset) }; |
| 31008 | 30925 | |
| 31009 | 30926 | if (deref.ty_without_well_defined_layout) |bad_ty| { |
| ... | ... | @@ -31031,10 +30948,8 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError |
| 31031 | 30948 | /// This logic must be kept in sync with `Type.isPtrLikeOptional`. |
| 31032 | 30949 | fn typePtrOrOptionalPtrTy( |
| 31033 | 30950 | sema: *Sema, |
| 31034 | | block: *Block, |
| 31035 | 30951 | ty: Type, |
| 31036 | 30952 | buf: *Type.Payload.ElemType, |
| 31037 | | src: LazySrcLoc, |
| 31038 | 30953 | ) !?Type { |
| 31039 | 30954 | switch (ty.tag()) { |
| 31040 | 30955 | .optional_single_const_pointer, |
| ... | ... | @@ -31073,7 +30988,7 @@ fn typePtrOrOptionalPtrTy( |
| 31073 | 30988 | if (info.@"allowzero") return null; |
| 31074 | 30989 | |
| 31075 | 30990 | // optionals of zero sized types behave like bools, not pointers |
| 31076 | | if ((try sema.typeHasOnePossibleValue(block, src, child_type)) != null) { |
| 30991 | if ((try sema.typeHasOnePossibleValue(child_type)) != null) { |
| 31077 | 30992 | return null; |
| 31078 | 30993 | } |
| 31079 | 30994 | |
| ... | ... | @@ -31090,7 +31005,7 @@ fn typePtrOrOptionalPtrTy( |
| 31090 | 31005 | /// This function returns false negatives when structs and unions are having their |
| 31091 | 31006 | /// field types resolved. |
| 31092 | 31007 | /// TODO assert the return value matches `ty.comptimeOnly` |
| 31093 | | /// TODO merge these implementations together with the "advanced"/sema_kit pattern seen |
| 31008 | /// TODO merge these implementations together with the "advanced"/opt_sema pattern seen |
| 31094 | 31009 | /// elsewhere in value.zig |
| 31095 | 31010 | pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31096 | 31011 | return switch (ty.tag()) { |
| ... | ... | @@ -31287,33 +31202,28 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31287 | 31202 | }; |
| 31288 | 31203 | } |
| 31289 | 31204 | |
| 31290 | | pub fn typeHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 31291 | | return ty.hasRuntimeBitsAdvanced(false, sema.kit(block, src)); |
| 31205 | pub fn typeHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool { |
| 31206 | return ty.hasRuntimeBitsAdvanced(false, sema); |
| 31292 | 31207 | } |
| 31293 | 31208 | |
| 31294 | | fn typeAbiSize(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !u64 { |
| 31295 | | try sema.resolveTypeLayout(block, src, ty); |
| 31209 | fn typeAbiSize(sema: *Sema, ty: Type) !u64 { |
| 31210 | try sema.resolveTypeLayout(ty); |
| 31296 | 31211 | const target = sema.mod.getTarget(); |
| 31297 | 31212 | return ty.abiSize(target); |
| 31298 | 31213 | } |
| 31299 | 31214 | |
| 31300 | | fn typeAbiAlignment(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!u32 { |
| 31215 | fn typeAbiAlignment(sema: *Sema, ty: Type) CompileError!u32 { |
| 31301 | 31216 | const target = sema.mod.getTarget(); |
| 31302 | | return (try ty.abiAlignmentAdvanced(target, .{ .sema_kit = sema.kit(block, src) })).scalar; |
| 31217 | return (try ty.abiAlignmentAdvanced(target, .{ .sema = sema })).scalar; |
| 31303 | 31218 | } |
| 31304 | 31219 | |
| 31305 | 31220 | /// Not valid to call for packed unions. |
| 31306 | 31221 | /// Keep implementation in sync with `Module.Union.Field.normalAlignment`. |
| 31307 | | fn unionFieldAlignment( |
| 31308 | | sema: *Sema, |
| 31309 | | block: *Block, |
| 31310 | | src: LazySrcLoc, |
| 31311 | | field: Module.Union.Field, |
| 31312 | | ) !u32 { |
| 31222 | fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 { |
| 31313 | 31223 | if (field.ty.zigTypeTag() == .NoReturn) { |
| 31314 | 31224 | return @as(u32, 0); |
| 31315 | 31225 | } else if (field.abi_align == 0) { |
| 31316 | | return sema.typeAbiAlignment(block, src, field.ty); |
| 31226 | return sema.typeAbiAlignment(field.ty); |
| 31317 | 31227 | } else { |
| 31318 | 31228 | return field.abi_align; |
| 31319 | 31229 | } |
| ... | ... | @@ -31342,7 +31252,7 @@ fn unionFieldIndex( |
| 31342 | 31252 | field_name: []const u8, |
| 31343 | 31253 | field_src: LazySrcLoc, |
| 31344 | 31254 | ) !u32 { |
| 31345 | | const union_ty = try sema.resolveTypeFields(block, field_src, unresolved_union_ty); |
| 31255 | const union_ty = try sema.resolveTypeFields(unresolved_union_ty); |
| 31346 | 31256 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 31347 | 31257 | const field_index_usize = union_obj.fields.getIndex(field_name) orelse |
| 31348 | 31258 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| ... | ... | @@ -31356,7 +31266,7 @@ fn structFieldIndex( |
| 31356 | 31266 | field_name: []const u8, |
| 31357 | 31267 | field_src: LazySrcLoc, |
| 31358 | 31268 | ) !u32 { |
| 31359 | | const struct_ty = try sema.resolveTypeFields(block, field_src, unresolved_struct_ty); |
| 31269 | const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty); |
| 31360 | 31270 | if (struct_ty.isAnonStruct()) { |
| 31361 | 31271 | return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src); |
| 31362 | 31272 | } else { |
| ... | ... | @@ -31385,34 +31295,30 @@ fn anonStructFieldIndex( |
| 31385 | 31295 | }); |
| 31386 | 31296 | } |
| 31387 | 31297 | |
| 31388 | | fn kit(sema: *Sema, block: *Block, src: LazySrcLoc) Module.WipAnalysis { |
| 31389 | | return .{ .sema = sema, .block = block, .src = src }; |
| 31390 | | } |
| 31391 | | |
| 31392 | 31298 | fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { |
| 31393 | 31299 | const inst_ref = try sema.addType(ty); |
| 31394 | 31300 | try sema.types_to_resolve.append(sema.gpa, inst_ref); |
| 31395 | 31301 | } |
| 31396 | 31302 | |
| 31397 | | fn intAdd(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value, ty: Type) !Value { |
| 31303 | fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value { |
| 31398 | 31304 | if (ty.zigTypeTag() == .Vector) { |
| 31399 | 31305 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31400 | 31306 | for (result_data) |*scalar, i| { |
| 31401 | | scalar.* = try sema.intAddScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i)); |
| 31307 | scalar.* = try sema.intAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i)); |
| 31402 | 31308 | } |
| 31403 | 31309 | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 31404 | 31310 | } |
| 31405 | | return sema.intAddScalar(block, src, lhs, rhs); |
| 31311 | return sema.intAddScalar(lhs, rhs); |
| 31406 | 31312 | } |
| 31407 | 31313 | |
| 31408 | | fn intAddScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value) !Value { |
| 31314 | fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value) !Value { |
| 31409 | 31315 | // TODO is this a performance issue? maybe we should try the operation without |
| 31410 | 31316 | // resorting to BigInt first. |
| 31411 | 31317 | var lhs_space: Value.BigIntSpace = undefined; |
| 31412 | 31318 | var rhs_space: Value.BigIntSpace = undefined; |
| 31413 | 31319 | const target = sema.mod.getTarget(); |
| 31414 | | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); |
| 31415 | | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); |
| 31320 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31321 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31416 | 31322 | const limbs = try sema.arena.alloc( |
| 31417 | 31323 | std.math.big.Limb, |
| 31418 | 31324 | std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1, |
| ... | ... | @@ -31425,8 +31331,6 @@ fn intAddScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va |
| 31425 | 31331 | /// Supports both (vectors of) floats and ints; handles undefined scalars. |
| 31426 | 31332 | fn numberAddWrap( |
| 31427 | 31333 | sema: *Sema, |
| 31428 | | block: *Block, |
| 31429 | | src: LazySrcLoc, |
| 31430 | 31334 | lhs: Value, |
| 31431 | 31335 | rhs: Value, |
| 31432 | 31336 | ty: Type, |
| ... | ... | @@ -31434,18 +31338,16 @@ fn numberAddWrap( |
| 31434 | 31338 | if (ty.zigTypeTag() == .Vector) { |
| 31435 | 31339 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31436 | 31340 | for (result_data) |*scalar, i| { |
| 31437 | | scalar.* = try sema.numberAddWrapScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31341 | scalar.* = try sema.numberAddWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31438 | 31342 | } |
| 31439 | 31343 | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 31440 | 31344 | } |
| 31441 | | return sema.numberAddWrapScalar(block, src, lhs, rhs, ty); |
| 31345 | return sema.numberAddWrapScalar(lhs, rhs, ty); |
| 31442 | 31346 | } |
| 31443 | 31347 | |
| 31444 | 31348 | /// Supports both floats and ints; handles undefined. |
| 31445 | 31349 | fn numberAddWrapScalar( |
| 31446 | 31350 | sema: *Sema, |
| 31447 | | block: *Block, |
| 31448 | | src: LazySrcLoc, |
| 31449 | 31351 | lhs: Value, |
| 31450 | 31352 | rhs: Value, |
| 31451 | 31353 | ty: Type, |
| ... | ... | @@ -31453,21 +31355,19 @@ fn numberAddWrapScalar( |
| 31453 | 31355 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 31454 | 31356 | |
| 31455 | 31357 | if (ty.zigTypeTag() == .ComptimeInt) { |
| 31456 | | return sema.intAdd(block, src, lhs, rhs, ty); |
| 31358 | return sema.intAdd(lhs, rhs, ty); |
| 31457 | 31359 | } |
| 31458 | 31360 | |
| 31459 | 31361 | if (ty.isAnyFloat()) { |
| 31460 | 31362 | return sema.floatAdd(lhs, rhs, ty); |
| 31461 | 31363 | } |
| 31462 | 31364 | |
| 31463 | | const overflow_result = try sema.intAddWithOverflow(block, src, lhs, rhs, ty); |
| 31365 | const overflow_result = try sema.intAddWithOverflow(lhs, rhs, ty); |
| 31464 | 31366 | return overflow_result.wrapped_result; |
| 31465 | 31367 | } |
| 31466 | 31368 | |
| 31467 | 31369 | fn intSub( |
| 31468 | 31370 | sema: *Sema, |
| 31469 | | block: *Block, |
| 31470 | | src: LazySrcLoc, |
| 31471 | 31371 | lhs: Value, |
| 31472 | 31372 | rhs: Value, |
| 31473 | 31373 | ty: Type, |
| ... | ... | @@ -31475,21 +31375,21 @@ fn intSub( |
| 31475 | 31375 | if (ty.zigTypeTag() == .Vector) { |
| 31476 | 31376 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31477 | 31377 | for (result_data) |*scalar, i| { |
| 31478 | | scalar.* = try sema.intSubScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i)); |
| 31378 | scalar.* = try sema.intSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i)); |
| 31479 | 31379 | } |
| 31480 | 31380 | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 31481 | 31381 | } |
| 31482 | | return sema.intSubScalar(block, src, lhs, rhs); |
| 31382 | return sema.intSubScalar(lhs, rhs); |
| 31483 | 31383 | } |
| 31484 | 31384 | |
| 31485 | | fn intSubScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value) !Value { |
| 31385 | fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value) !Value { |
| 31486 | 31386 | // TODO is this a performance issue? maybe we should try the operation without |
| 31487 | 31387 | // resorting to BigInt first. |
| 31488 | 31388 | var lhs_space: Value.BigIntSpace = undefined; |
| 31489 | 31389 | var rhs_space: Value.BigIntSpace = undefined; |
| 31490 | 31390 | const target = sema.mod.getTarget(); |
| 31491 | | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); |
| 31492 | | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); |
| 31391 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31392 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31493 | 31393 | const limbs = try sema.arena.alloc( |
| 31494 | 31394 | std.math.big.Limb, |
| 31495 | 31395 | std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1, |
| ... | ... | @@ -31502,8 +31402,6 @@ fn intSubScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va |
| 31502 | 31402 | /// Supports both (vectors of) floats and ints; handles undefined scalars. |
| 31503 | 31403 | fn numberSubWrap( |
| 31504 | 31404 | sema: *Sema, |
| 31505 | | block: *Block, |
| 31506 | | src: LazySrcLoc, |
| 31507 | 31405 | lhs: Value, |
| 31508 | 31406 | rhs: Value, |
| 31509 | 31407 | ty: Type, |
| ... | ... | @@ -31511,18 +31409,16 @@ fn numberSubWrap( |
| 31511 | 31409 | if (ty.zigTypeTag() == .Vector) { |
| 31512 | 31410 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31513 | 31411 | for (result_data) |*scalar, i| { |
| 31514 | | scalar.* = try sema.numberSubWrapScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31412 | scalar.* = try sema.numberSubWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31515 | 31413 | } |
| 31516 | 31414 | return Value.Tag.aggregate.create(sema.arena, result_data); |
| 31517 | 31415 | } |
| 31518 | | return sema.numberSubWrapScalar(block, src, lhs, rhs, ty); |
| 31416 | return sema.numberSubWrapScalar(lhs, rhs, ty); |
| 31519 | 31417 | } |
| 31520 | 31418 | |
| 31521 | 31419 | /// Supports both floats and ints; handles undefined. |
| 31522 | 31420 | fn numberSubWrapScalar( |
| 31523 | 31421 | sema: *Sema, |
| 31524 | | block: *Block, |
| 31525 | | src: LazySrcLoc, |
| 31526 | 31422 | lhs: Value, |
| 31527 | 31423 | rhs: Value, |
| 31528 | 31424 | ty: Type, |
| ... | ... | @@ -31530,14 +31426,14 @@ fn numberSubWrapScalar( |
| 31530 | 31426 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 31531 | 31427 | |
| 31532 | 31428 | if (ty.zigTypeTag() == .ComptimeInt) { |
| 31533 | | return sema.intSub(block, src, lhs, rhs, ty); |
| 31429 | return sema.intSub(lhs, rhs, ty); |
| 31534 | 31430 | } |
| 31535 | 31431 | |
| 31536 | 31432 | if (ty.isAnyFloat()) { |
| 31537 | 31433 | return sema.floatSub(lhs, rhs, ty); |
| 31538 | 31434 | } |
| 31539 | 31435 | |
| 31540 | | const overflow_result = try sema.intSubWithOverflow(block, src, lhs, rhs, ty); |
| 31436 | const overflow_result = try sema.intSubWithOverflow(lhs, rhs, ty); |
| 31541 | 31437 | return overflow_result.wrapped_result; |
| 31542 | 31438 | } |
| 31543 | 31439 | |
| ... | ... | @@ -31649,8 +31545,6 @@ fn floatSubScalar( |
| 31649 | 31545 | |
| 31650 | 31546 | fn intSubWithOverflow( |
| 31651 | 31547 | sema: *Sema, |
| 31652 | | block: *Block, |
| 31653 | | src: LazySrcLoc, |
| 31654 | 31548 | lhs: Value, |
| 31655 | 31549 | rhs: Value, |
| 31656 | 31550 | ty: Type, |
| ... | ... | @@ -31659,7 +31553,7 @@ fn intSubWithOverflow( |
| 31659 | 31553 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31660 | 31554 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31661 | 31555 | for (result_data) |*scalar, i| { |
| 31662 | | const of_math_result = try sema.intSubWithOverflowScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31556 | const of_math_result = try sema.intSubWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31663 | 31557 | overflowed_data[i] = of_math_result.overflowed; |
| 31664 | 31558 | scalar.* = of_math_result.wrapped_result; |
| 31665 | 31559 | } |
| ... | ... | @@ -31668,13 +31562,11 @@ fn intSubWithOverflow( |
| 31668 | 31562 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 31669 | 31563 | }; |
| 31670 | 31564 | } |
| 31671 | | return sema.intSubWithOverflowScalar(block, src, lhs, rhs, ty); |
| 31565 | return sema.intSubWithOverflowScalar(lhs, rhs, ty); |
| 31672 | 31566 | } |
| 31673 | 31567 | |
| 31674 | 31568 | fn intSubWithOverflowScalar( |
| 31675 | 31569 | sema: *Sema, |
| 31676 | | block: *Block, |
| 31677 | | src: LazySrcLoc, |
| 31678 | 31570 | lhs: Value, |
| 31679 | 31571 | rhs: Value, |
| 31680 | 31572 | ty: Type, |
| ... | ... | @@ -31684,8 +31576,8 @@ fn intSubWithOverflowScalar( |
| 31684 | 31576 | |
| 31685 | 31577 | var lhs_space: Value.BigIntSpace = undefined; |
| 31686 | 31578 | var rhs_space: Value.BigIntSpace = undefined; |
| 31687 | | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); |
| 31688 | | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); |
| 31579 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31580 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31689 | 31581 | const limbs = try sema.arena.alloc( |
| 31690 | 31582 | std.math.big.Limb, |
| 31691 | 31583 | std.math.big.int.calcTwosCompLimbCount(info.bits), |
| ... | ... | @@ -31774,7 +31666,7 @@ fn floatToIntScalar( |
| 31774 | 31666 | else |
| 31775 | 31667 | try Value.Tag.int_big_positive.create(sema.arena, result_limbs); |
| 31776 | 31668 | |
| 31777 | | if (!(try sema.intFitsInType(block, src, result, int_ty, null))) { |
| 31669 | if (!(try sema.intFitsInType(result, int_ty, null))) { |
| 31778 | 31670 | return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{ |
| 31779 | 31671 | val.fmtValue(float_ty, sema.mod), int_ty.fmt(sema.mod), |
| 31780 | 31672 | }); |
| ... | ... | @@ -31788,8 +31680,6 @@ fn floatToIntScalar( |
| 31788 | 31680 | /// If provided, `vector_index` reports the first element that failed the range check. |
| 31789 | 31681 | fn intFitsInType( |
| 31790 | 31682 | sema: *Sema, |
| 31791 | | block: *Block, |
| 31792 | | src: LazySrcLoc, |
| 31793 | 31683 | val: Value, |
| 31794 | 31684 | ty: Type, |
| 31795 | 31685 | vector_index: ?*usize, |
| ... | ... | @@ -31821,7 +31711,7 @@ fn intFitsInType( |
| 31821 | 31711 | const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed); |
| 31822 | 31712 | // If it is u16 or bigger we know the alignment fits without resolving it. |
| 31823 | 31713 | if (info.bits >= max_needed_bits) return true; |
| 31824 | | const x = try sema.typeAbiAlignment(block, src, val.castTag(.lazy_align).?.data); |
| 31714 | const x = try sema.typeAbiAlignment(val.castTag(.lazy_align).?.data); |
| 31825 | 31715 | if (x == 0) return true; |
| 31826 | 31716 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); |
| 31827 | 31717 | return info.bits >= actual_needed_bits; |
| ... | ... | @@ -31835,7 +31725,7 @@ fn intFitsInType( |
| 31835 | 31725 | const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed); |
| 31836 | 31726 | // If it is u64 or bigger we know the size fits without resolving it. |
| 31837 | 31727 | if (info.bits >= max_needed_bits) return true; |
| 31838 | | const x = try sema.typeAbiSize(block, src, val.castTag(.lazy_size).?.data); |
| 31728 | const x = try sema.typeAbiSize(val.castTag(.lazy_size).?.data); |
| 31839 | 31729 | if (x == 0) return true; |
| 31840 | 31730 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); |
| 31841 | 31731 | return info.bits >= actual_needed_bits; |
| ... | ... | @@ -31863,7 +31753,7 @@ fn intFitsInType( |
| 31863 | 31753 | if (info.signedness == .unsigned and x < 0) |
| 31864 | 31754 | return false; |
| 31865 | 31755 | var buffer: Value.BigIntSpace = undefined; |
| 31866 | | return (try val.toBigIntAdvanced(&buffer, target, sema.kit(block, src))).fitsInTwosComp(info.signedness, info.bits); |
| 31756 | return (try val.toBigIntAdvanced(&buffer, target, sema)).fitsInTwosComp(info.signedness, info.bits); |
| 31867 | 31757 | }, |
| 31868 | 31758 | .ComptimeInt => return true, |
| 31869 | 31759 | else => unreachable, |
| ... | ... | @@ -31911,7 +31801,7 @@ fn intFitsInType( |
| 31911 | 31801 | .aggregate => { |
| 31912 | 31802 | assert(ty.zigTypeTag() == .Vector); |
| 31913 | 31803 | for (val.castTag(.aggregate).?.data) |elem, i| { |
| 31914 | | if (!(try sema.intFitsInType(block, src, elem, ty.scalarType(), null))) { |
| 31804 | if (!(try sema.intFitsInType(elem, ty.scalarType(), null))) { |
| 31915 | 31805 | if (vector_index) |some| some.* = i; |
| 31916 | 31806 | return false; |
| 31917 | 31807 | } |
| ... | ... | @@ -31925,37 +31815,33 @@ fn intFitsInType( |
| 31925 | 31815 | |
| 31926 | 31816 | fn intInRange( |
| 31927 | 31817 | sema: *Sema, |
| 31928 | | block: *Block, |
| 31929 | | src: LazySrcLoc, |
| 31930 | 31818 | tag_ty: Type, |
| 31931 | 31819 | int_val: Value, |
| 31932 | 31820 | end: usize, |
| 31933 | 31821 | ) !bool { |
| 31934 | | if (!(try int_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) return false; |
| 31822 | if (!(try int_val.compareAllWithZeroAdvanced(.gte, sema))) return false; |
| 31935 | 31823 | var end_payload: Value.Payload.U64 = .{ |
| 31936 | 31824 | .base = .{ .tag = .int_u64 }, |
| 31937 | 31825 | .data = end, |
| 31938 | 31826 | }; |
| 31939 | 31827 | const end_val = Value.initPayload(&end_payload.base); |
| 31940 | | if (!(try sema.compareAll(block, src, int_val, .lt, end_val, tag_ty))) return false; |
| 31828 | if (!(try sema.compareAll(int_val, .lt, end_val, tag_ty))) return false; |
| 31941 | 31829 | return true; |
| 31942 | 31830 | } |
| 31943 | 31831 | |
| 31944 | 31832 | /// Asserts the type is an enum. |
| 31945 | 31833 | fn enumHasInt( |
| 31946 | 31834 | sema: *Sema, |
| 31947 | | block: *Block, |
| 31948 | | src: LazySrcLoc, |
| 31949 | 31835 | ty: Type, |
| 31950 | 31836 | int: Value, |
| 31951 | 31837 | ) CompileError!bool { |
| 31952 | 31838 | switch (ty.tag()) { |
| 31953 | | .enum_nonexhaustive => return sema.intFitsInType(block, src, int, ty, null), |
| 31839 | .enum_nonexhaustive => return sema.intFitsInType(int, ty, null), |
| 31954 | 31840 | .enum_full => { |
| 31955 | 31841 | const enum_full = ty.castTag(.enum_full).?.data; |
| 31956 | 31842 | const tag_ty = enum_full.tag_ty; |
| 31957 | 31843 | if (enum_full.values.count() == 0) { |
| 31958 | | return intInRange(sema, block, src, tag_ty, int, enum_full.fields.count()); |
| 31844 | return sema.intInRange(tag_ty, int, enum_full.fields.count()); |
| 31959 | 31845 | } else { |
| 31960 | 31846 | return enum_full.values.containsContext(int, .{ |
| 31961 | 31847 | .ty = tag_ty, |
| ... | ... | @@ -31967,7 +31853,7 @@ fn enumHasInt( |
| 31967 | 31853 | const enum_obj = ty.castTag(.enum_numbered).?.data; |
| 31968 | 31854 | const tag_ty = enum_obj.tag_ty; |
| 31969 | 31855 | if (enum_obj.values.count() == 0) { |
| 31970 | | return intInRange(sema, block, src, tag_ty, int, enum_obj.fields.count()); |
| 31856 | return sema.intInRange(tag_ty, int, enum_obj.fields.count()); |
| 31971 | 31857 | } else { |
| 31972 | 31858 | return enum_obj.values.containsContext(int, .{ |
| 31973 | 31859 | .ty = tag_ty, |
| ... | ... | @@ -31984,7 +31870,7 @@ fn enumHasInt( |
| 31984 | 31870 | .data = bits, |
| 31985 | 31871 | }; |
| 31986 | 31872 | const tag_ty = Type.initPayload(&buffer.base); |
| 31987 | | return intInRange(sema, block, src, tag_ty, int, fields_len); |
| 31873 | return sema.intInRange(tag_ty, int, fields_len); |
| 31988 | 31874 | }, |
| 31989 | 31875 | .atomic_order, |
| 31990 | 31876 | .atomic_rmw_op, |
| ... | ... | @@ -32004,8 +31890,6 @@ fn enumHasInt( |
| 32004 | 31890 | |
| 32005 | 31891 | fn intAddWithOverflow( |
| 32006 | 31892 | sema: *Sema, |
| 32007 | | block: *Block, |
| 32008 | | src: LazySrcLoc, |
| 32009 | 31893 | lhs: Value, |
| 32010 | 31894 | rhs: Value, |
| 32011 | 31895 | ty: Type, |
| ... | ... | @@ -32014,7 +31898,7 @@ fn intAddWithOverflow( |
| 32014 | 31898 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32015 | 31899 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32016 | 31900 | for (result_data) |*scalar, i| { |
| 32017 | | const of_math_result = try sema.intAddWithOverflowScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 31901 | const of_math_result = try sema.intAddWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType()); |
| 32018 | 31902 | overflowed_data[i] = of_math_result.overflowed; |
| 32019 | 31903 | scalar.* = of_math_result.wrapped_result; |
| 32020 | 31904 | } |
| ... | ... | @@ -32023,13 +31907,11 @@ fn intAddWithOverflow( |
| 32023 | 31907 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 32024 | 31908 | }; |
| 32025 | 31909 | } |
| 32026 | | return sema.intAddWithOverflowScalar(block, src, lhs, rhs, ty); |
| 31910 | return sema.intAddWithOverflowScalar(lhs, rhs, ty); |
| 32027 | 31911 | } |
| 32028 | 31912 | |
| 32029 | 31913 | fn intAddWithOverflowScalar( |
| 32030 | 31914 | sema: *Sema, |
| 32031 | | block: *Block, |
| 32032 | | src: LazySrcLoc, |
| 32033 | 31915 | lhs: Value, |
| 32034 | 31916 | rhs: Value, |
| 32035 | 31917 | ty: Type, |
| ... | ... | @@ -32039,8 +31921,8 @@ fn intAddWithOverflowScalar( |
| 32039 | 31921 | |
| 32040 | 31922 | var lhs_space: Value.BigIntSpace = undefined; |
| 32041 | 31923 | var rhs_space: Value.BigIntSpace = undefined; |
| 32042 | | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); |
| 32043 | | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); |
| 31924 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31925 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 32044 | 31926 | const limbs = try sema.arena.alloc( |
| 32045 | 31927 | std.math.big.Limb, |
| 32046 | 31928 | std.math.big.int.calcTwosCompLimbCount(info.bits), |
| ... | ... | @@ -32060,8 +31942,6 @@ fn intAddWithOverflowScalar( |
| 32060 | 31942 | /// Note that `!compareAll(.eq, ...) != compareAll(.neq, ...)` |
| 32061 | 31943 | fn compareAll( |
| 32062 | 31944 | sema: *Sema, |
| 32063 | | block: *Block, |
| 32064 | | src: LazySrcLoc, |
| 32065 | 31945 | lhs: Value, |
| 32066 | 31946 | op: std.math.CompareOperator, |
| 32067 | 31947 | rhs: Value, |
| ... | ... | @@ -32070,48 +31950,42 @@ fn compareAll( |
| 32070 | 31950 | if (ty.zigTypeTag() == .Vector) { |
| 32071 | 31951 | var i: usize = 0; |
| 32072 | 31952 | while (i < ty.vectorLen()) : (i += 1) { |
| 32073 | | if (!(try sema.compareScalar(block, src, lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) { |
| 31953 | if (!(try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) { |
| 32074 | 31954 | return false; |
| 32075 | 31955 | } |
| 32076 | 31956 | } |
| 32077 | 31957 | return true; |
| 32078 | 31958 | } |
| 32079 | | return sema.compareScalar(block, src, lhs, op, rhs, ty); |
| 31959 | return sema.compareScalar(lhs, op, rhs, ty); |
| 32080 | 31960 | } |
| 32081 | 31961 | |
| 32082 | 31962 | /// Asserts the values are comparable. Both operands have type `ty`. |
| 32083 | 31963 | fn compareScalar( |
| 32084 | 31964 | sema: *Sema, |
| 32085 | | block: *Block, |
| 32086 | | src: LazySrcLoc, |
| 32087 | 31965 | lhs: Value, |
| 32088 | 31966 | op: std.math.CompareOperator, |
| 32089 | 31967 | rhs: Value, |
| 32090 | 31968 | ty: Type, |
| 32091 | 31969 | ) CompileError!bool { |
| 32092 | 31970 | switch (op) { |
| 32093 | | .eq => return sema.valuesEqual(block, src, lhs, rhs, ty), |
| 32094 | | .neq => return !(try sema.valuesEqual(block, src, lhs, rhs, ty)), |
| 32095 | | else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema.kit(block, src)), |
| 31971 | .eq => return sema.valuesEqual(lhs, rhs, ty), |
| 31972 | .neq => return !(try sema.valuesEqual(lhs, rhs, ty)), |
| 31973 | else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema), |
| 32096 | 31974 | } |
| 32097 | 31975 | } |
| 32098 | 31976 | |
| 32099 | 31977 | fn valuesEqual( |
| 32100 | 31978 | sema: *Sema, |
| 32101 | | block: *Block, |
| 32102 | | src: LazySrcLoc, |
| 32103 | 31979 | lhs: Value, |
| 32104 | 31980 | rhs: Value, |
| 32105 | 31981 | ty: Type, |
| 32106 | 31982 | ) CompileError!bool { |
| 32107 | | return Value.eqlAdvanced(lhs, ty, rhs, ty, sema.mod, sema.kit(block, src)); |
| 31983 | return Value.eqlAdvanced(lhs, ty, rhs, ty, sema.mod, sema); |
| 32108 | 31984 | } |
| 32109 | 31985 | |
| 32110 | 31986 | /// Asserts the values are comparable vectors of type `ty`. |
| 32111 | 31987 | fn compareVector( |
| 32112 | 31988 | sema: *Sema, |
| 32113 | | block: *Block, |
| 32114 | | src: LazySrcLoc, |
| 32115 | 31989 | lhs: Value, |
| 32116 | 31990 | op: std.math.CompareOperator, |
| 32117 | 31991 | rhs: Value, |
| ... | ... | @@ -32120,7 +31994,7 @@ fn compareVector( |
| 32120 | 31994 | assert(ty.zigTypeTag() == .Vector); |
| 32121 | 31995 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32122 | 31996 | for (result_data) |*scalar, i| { |
| 32123 | | const res_bool = try sema.compareScalar(block, src, lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()); |
| 31997 | const res_bool = try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()); |
| 32124 | 31998 | scalar.* = Value.makeBool(res_bool); |
| 32125 | 31999 | } |
| 32126 | 32000 | return Value.Tag.aggregate.create(sema.arena, result_data); |