| ... | @@ -195,7 +195,7 @@ pub const Block = struct { | ... | @@ -195,7 +195,7 @@ pub const Block = struct { |
| 195 | try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{}); | 195 | try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{}); |
| 196 | }, | 196 | }, |
| 197 | .comptime_ret_ty => |rt| { | 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 | var src_loc = capture; | 199 | var src_loc = capture; |
| 200 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; | 200 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 201 | break :blk src_loc; | 201 | break :blk src_loc; |
| ... | @@ -579,10 +579,9 @@ pub const Block = struct { | ... | @@ -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 | return WipAnonDecl{ | 583 | return WipAnonDecl{ |
| 584 | .block = block, | 584 | .block = block, |
| 585 | .src = src, | | |
| 586 | .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa), | 585 | .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa), |
| 587 | .finished = false, | 586 | .finished = false, |
| 588 | }; | 587 | }; |
| ... | @@ -590,7 +589,6 @@ pub const Block = struct { | ... | @@ -590,7 +589,6 @@ pub const Block = struct { |
| 590 | | 589 | |
| 591 | pub const WipAnonDecl = struct { | 590 | pub const WipAnonDecl = struct { |
| 592 | block: *Block, | 591 | block: *Block, |
| 593 | src: LazySrcLoc, | | |
| 594 | new_decl_arena: std.heap.ArenaAllocator, | 592 | new_decl_arena: std.heap.ArenaAllocator, |
| 595 | finished: bool, | 593 | finished: bool, |
| 596 | | 594 | |
| ... | @@ -610,7 +608,7 @@ pub const Block = struct { | ... | @@ -610,7 +608,7 @@ pub const Block = struct { |
| 610 | const sema = wad.block.sema; | 608 | const sema = wad.block.sema; |
| 611 | // Do this ahead of time because `createAnonymousDecl` depends on calling | 609 | // Do this ahead of time because `createAnonymousDecl` depends on calling |
| 612 | // `type.hasRuntimeBits()`. | 610 | // `type.hasRuntimeBits()`. |
| 613 | _ = try sema.typeHasRuntimeBits(wad.block, wad.src, ty); | 611 | _ = try sema.typeHasRuntimeBits(ty); |
| 614 | const new_decl_index = try sema.mod.createAnonymousDecl(wad.block, .{ | 612 | const new_decl_index = try sema.mod.createAnonymousDecl(wad.block, .{ |
| 615 | .ty = ty, | 613 | .ty = ty, |
| 616 | .val = val, | 614 | .val = val, |
| ... | @@ -995,7 +993,7 @@ fn analyzeBodyInner( | ... | @@ -995,7 +993,7 @@ fn analyzeBodyInner( |
| 995 | .shl_exact => try sema.zirShl(block, inst, .shl_exact), | 993 | .shl_exact => try sema.zirShl(block, inst, .shl_exact), |
| 996 | .shl_sat => try sema.zirShl(block, inst, .shl_sat), | 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 | .ret_type => try sema.addType(sema.fn_ret_ty), | 997 | .ret_type => try sema.addType(sema.fn_ret_ty), |
| 1000 | | 998 | |
| 1001 | // Instructions that we know to *always* be noreturn based solely on their tag. | 999 | // Instructions that we know to *always* be noreturn based solely on their tag. |
| ... | @@ -1023,7 +1021,7 @@ fn analyzeBodyInner( | ... | @@ -1023,7 +1021,7 @@ fn analyzeBodyInner( |
| 1023 | .this => try sema.zirThis( block, extended), | 1021 | .this => try sema.zirThis( block, extended), |
| 1024 | .ret_addr => try sema.zirRetAddr( block, extended), | 1022 | .ret_addr => try sema.zirRetAddr( block, extended), |
| 1025 | .builtin_src => try sema.zirBuiltinSrc( block, extended), | 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 | .frame => try sema.zirFrame( block, extended), | 1025 | .frame => try sema.zirFrame( block, extended), |
| 1028 | .frame_address => try sema.zirFrameAddress( block, extended), | 1026 | .frame_address => try sema.zirFrameAddress( block, extended), |
| 1029 | .alloc => try sema.zirAllocExtended( block, extended), | 1027 | .alloc => try sema.zirAllocExtended( block, extended), |
| ... | @@ -1031,7 +1029,7 @@ fn analyzeBodyInner( | ... | @@ -1031,7 +1029,7 @@ fn analyzeBodyInner( |
| 1031 | .@"asm" => try sema.zirAsm( block, extended, false), | 1029 | .@"asm" => try sema.zirAsm( block, extended, false), |
| 1032 | .asm_expr => try sema.zirAsm( block, extended, true), | 1030 | .asm_expr => try sema.zirAsm( block, extended, true), |
| 1033 | .typeof_peer => try sema.zirTypeofPeer( block, extended), | 1031 | .typeof_peer => try sema.zirTypeofPeer( block, extended), |
| 1034 | .compile_log => try sema.zirCompileLog( block, extended), | 1032 | .compile_log => try sema.zirCompileLog( extended), |
| 1035 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), | 1033 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| 1036 | .sub_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), | 1034 | .sub_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| 1037 | .mul_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), | 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,8 +1744,8 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 1746 | const addrs_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, addr_arr_ty)); | 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 | // var st: StackTrace = undefined; | 1746 | // var st: StackTrace = undefined; |
| 1749 | const unresolved_stack_trace_ty = try sema.getBuiltinType(&err_trace_block, src, "StackTrace"); | 1747 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 1750 | const stack_trace_ty = try sema.resolveTypeFields(&err_trace_block, src, unresolved_stack_trace_ty); | 1748 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 1751 | const st_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty)); | 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 | // st.instruction_addresses = &addrs; | 1751 | // st.instruction_addresses = &addrs; |
| ... | @@ -1774,7 +1772,7 @@ fn resolveValue( | ... | @@ -1774,7 +1772,7 @@ fn resolveValue( |
| 1774 | air_ref: Air.Inst.Ref, | 1772 | air_ref: Air.Inst.Ref, |
| 1775 | reason: []const u8, | 1773 | reason: []const u8, |
| 1776 | ) CompileError!Value { | 1774 | ) CompileError!Value { |
| 1777 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { | 1775 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1778 | if (val.tag() == .generic_poison) return error.GenericPoison; | 1776 | if (val.tag() == .generic_poison) return error.GenericPoison; |
| 1779 | return val; | 1777 | return val; |
| 1780 | } | 1778 | } |
| ... | @@ -1790,7 +1788,7 @@ fn resolveConstMaybeUndefVal( | ... | @@ -1790,7 +1788,7 @@ fn resolveConstMaybeUndefVal( |
| 1790 | inst: Air.Inst.Ref, | 1788 | inst: Air.Inst.Ref, |
| 1791 | reason: []const u8, | 1789 | reason: []const u8, |
| 1792 | ) CompileError!Value { | 1790 | ) CompileError!Value { |
| 1793 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| { | 1791 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { |
| 1794 | switch (val.tag()) { | 1792 | switch (val.tag()) { |
| 1795 | .variable => return sema.failWithNeededComptime(block, src, reason), | 1793 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1796 | .generic_poison => return error.GenericPoison, | 1794 | .generic_poison => return error.GenericPoison, |
| ... | @@ -1809,7 +1807,7 @@ fn resolveConstValue( | ... | @@ -1809,7 +1807,7 @@ fn resolveConstValue( |
| 1809 | air_ref: Air.Inst.Ref, | 1807 | air_ref: Air.Inst.Ref, |
| 1810 | reason: []const u8, | 1808 | reason: []const u8, |
| 1811 | ) CompileError!Value { | 1809 | ) CompileError!Value { |
| 1812 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { | 1810 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1813 | switch (val.tag()) { | 1811 | switch (val.tag()) { |
| 1814 | .undef => return sema.failWithUseOfUndef(block, src), | 1812 | .undef => return sema.failWithUseOfUndef(block, src), |
| 1815 | .variable => return sema.failWithNeededComptime(block, src, reason), | 1813 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| ... | @@ -1828,7 +1826,7 @@ fn resolveDefinedValue( | ... | @@ -1828,7 +1826,7 @@ fn resolveDefinedValue( |
| 1828 | src: LazySrcLoc, | 1826 | src: LazySrcLoc, |
| 1829 | air_ref: Air.Inst.Ref, | 1827 | air_ref: Air.Inst.Ref, |
| 1830 | ) CompileError!?Value { | 1828 | ) CompileError!?Value { |
| 1831 | if (try sema.resolveMaybeUndefVal(block, src, air_ref)) |val| { | 1829 | if (try sema.resolveMaybeUndefVal(air_ref)) |val| { |
| 1832 | if (val.isUndef()) { | 1830 | if (val.isUndef()) { |
| 1833 | if (block.is_typeof) return null; | 1831 | if (block.is_typeof) return null; |
| 1834 | return sema.failWithUseOfUndef(block, src); | 1832 | return sema.failWithUseOfUndef(block, src); |
| ... | @@ -1843,11 +1841,9 @@ fn resolveDefinedValue( | ... | @@ -1843,11 +1841,9 @@ fn resolveDefinedValue( |
| 1843 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. | 1841 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 1844 | fn resolveMaybeUndefVal( | 1842 | fn resolveMaybeUndefVal( |
| 1845 | sema: *Sema, | 1843 | sema: *Sema, |
| 1846 | block: *Block, | | |
| 1847 | src: LazySrcLoc, | | |
| 1848 | inst: Air.Inst.Ref, | 1844 | inst: Air.Inst.Ref, |
| 1849 | ) CompileError!?Value { | 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 | switch (val.tag()) { | 1847 | switch (val.tag()) { |
| 1852 | .variable => return null, | 1848 | .variable => return null, |
| 1853 | .generic_poison => return error.GenericPoison, | 1849 | .generic_poison => return error.GenericPoison, |
| ... | @@ -1861,11 +1857,9 @@ fn resolveMaybeUndefVal( | ... | @@ -1861,11 +1857,9 @@ fn resolveMaybeUndefVal( |
| 1861 | /// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`. | 1857 | /// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`. |
| 1862 | fn resolveMaybeUndefValIntable( | 1858 | fn resolveMaybeUndefValIntable( |
| 1863 | sema: *Sema, | 1859 | sema: *Sema, |
| 1864 | block: *Block, | | |
| 1865 | src: LazySrcLoc, | | |
| 1866 | inst: Air.Inst.Ref, | 1860 | inst: Air.Inst.Ref, |
| 1867 | ) CompileError!?Value { | 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 | var check = val; | 1863 | var check = val; |
| 1870 | while (true) switch (check.tag()) { | 1864 | while (true) switch (check.tag()) { |
| 1871 | .variable, .decl_ref, .decl_ref_mut, .comptime_field_ptr => return null, | 1865 | .variable, .decl_ref, .decl_ref_mut, .comptime_field_ptr => return null, |
| ... | @@ -1874,21 +1868,16 @@ fn resolveMaybeUndefValIntable( | ... | @@ -1874,21 +1868,16 @@ fn resolveMaybeUndefValIntable( |
| 1874 | .eu_payload_ptr, .opt_payload_ptr => check = check.cast(Value.Payload.PayloadPtr).?.data.container_ptr, | 1868 | .eu_payload_ptr, .opt_payload_ptr => check = check.cast(Value.Payload.PayloadPtr).?.data.container_ptr, |
| 1875 | .generic_poison => return error.GenericPoison, | 1869 | .generic_poison => return error.GenericPoison, |
| 1876 | else => { | 1870 | else => { |
| 1877 | try sema.resolveLazyValue(block, src, val); | 1871 | try sema.resolveLazyValue(val); |
| 1878 | return val; | 1872 | return val; |
| 1879 | }, | 1873 | }, |
| 1880 | }; | 1874 | }; |
| 1881 | } | 1875 | } |
| 1882 | | 1876 | |
| 1883 | /// Returns all Value tags including `variable` and `undef`. | 1877 | /// Returns all Value tags including `variable` and `undef`. |
| 1884 | fn resolveMaybeUndefValAllowVariables( | 1878 | fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 1885 | sema: *Sema, | | |
| 1886 | block: *Block, | | |
| 1887 | src: LazySrcLoc, | | |
| 1888 | inst: Air.Inst.Ref, | | |
| 1889 | ) CompileError!?Value { | | |
| 1890 | var make_runtime = false; | 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 | if (make_runtime) return null; | 1881 | if (make_runtime) return null; |
| 1893 | return val; | 1882 | return val; |
| 1894 | } | 1883 | } |
| ... | @@ -1898,8 +1887,6 @@ fn resolveMaybeUndefValAllowVariables( | ... | @@ -1898,8 +1887,6 @@ fn resolveMaybeUndefValAllowVariables( |
| 1898 | /// Returns all Value tags including `variable`, `undef` and `runtime_value`. | 1887 | /// Returns all Value tags including `variable`, `undef` and `runtime_value`. |
| 1899 | fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | 1888 | fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 1900 | sema: *Sema, | 1889 | sema: *Sema, |
| 1901 | block: *Block, | | |
| 1902 | src: LazySrcLoc, | | |
| 1903 | inst: Air.Inst.Ref, | 1890 | inst: Air.Inst.Ref, |
| 1904 | make_runtime: *bool, | 1891 | make_runtime: *bool, |
| 1905 | ) CompileError!?Value { | 1892 | ) CompileError!?Value { |
| ... | @@ -1910,7 +1897,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | ... | @@ -1910,7 +1897,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 1910 | } | 1897 | } |
| 1911 | i -= Air.Inst.Ref.typed_value_map.len; | 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 | return opv; | 1901 | return opv; |
| 1915 | } | 1902 | } |
| 1916 | const air_tags = sema.air_instructions.items(.tag); | 1903 | const air_tags = sema.air_instructions.items(.tag); |
| ... | @@ -2209,7 +2196,7 @@ pub fn resolveAlign( | ... | @@ -2209,7 +2196,7 @@ pub fn resolveAlign( |
| 2209 | zir_ref: Zir.Inst.Ref, | 2196 | zir_ref: Zir.Inst.Ref, |
| 2210 | ) !u32 { | 2197 | ) !u32 { |
| 2211 | const air_ref = try sema.resolveInst(zir_ref); | 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 | fn resolveInt( | 2202 | fn resolveInt( |
| ... | @@ -2221,7 +2208,7 @@ fn resolveInt( | ... | @@ -2221,7 +2208,7 @@ fn resolveInt( |
| 2221 | reason: []const u8, | 2208 | reason: []const u8, |
| 2222 | ) !u64 { | 2209 | ) !u64 { |
| 2223 | const air_ref = try sema.resolveInst(zir_ref); | 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 | fn analyzeAsInt( | 2214 | fn analyzeAsInt( |
| ... | @@ -2235,7 +2222,7 @@ fn analyzeAsInt( | ... | @@ -2235,7 +2222,7 @@ fn analyzeAsInt( |
| 2235 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); | 2222 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| 2236 | const val = try sema.resolveConstValue(block, src, coerced, reason); | 2223 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 2237 | const target = sema.mod.getTarget(); | 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 | // Returns a compile error if the value has tag `variable`. See `resolveInstValue` for | 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,7 +2304,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2317 | const iac = ptr_val.castTag(.inferred_alloc_comptime).?; | 2304 | const iac = ptr_val.castTag(.inferred_alloc_comptime).?; |
| 2318 | // There will be only one coerce_result_ptr because we are running at comptime. | 2305 | // There will be only one coerce_result_ptr because we are running at comptime. |
| 2319 | // The alloc will turn into a Decl. | 2306 | // The alloc will turn into a Decl. |
| 2320 | var anon_decl = try block.startAnonDecl(src); | 2307 | var anon_decl = try block.startAnonDecl(); |
| 2321 | defer anon_decl.deinit(); | 2308 | defer anon_decl.deinit(); |
| 2322 | iac.data.decl_index = try anon_decl.finish( | 2309 | iac.data.decl_index = try anon_decl.finish( |
| 2323 | try pointee_ty.copy(anon_decl.arena()), | 2310 | try pointee_ty.copy(anon_decl.arena()), |
| ... | @@ -2325,7 +2312,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2325,7 +2312,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2325 | iac.data.alignment, | 2312 | iac.data.alignment, |
| 2326 | ); | 2313 | ); |
| 2327 | if (iac.data.alignment != 0) { | 2314 | if (iac.data.alignment != 0) { |
| 2328 | try sema.resolveTypeLayout(block, src, pointee_ty); | 2315 | try sema.resolveTypeLayout(pointee_ty); |
| 2329 | } | 2316 | } |
| 2330 | const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 2317 | const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 2331 | .pointee_type = pointee_ty, | 2318 | .pointee_type = pointee_ty, |
| ... | @@ -2355,7 +2342,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2355,7 +2342,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2355 | | 2342 | |
| 2356 | const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr)); | 2343 | const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr)); |
| 2357 | const dummy_operand = try trash_block.addBitCast(pointee_ty, .void_value); | 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 | fn coerceResultPtr( | 2348 | fn coerceResultPtr( |
| ... | @@ -2386,7 +2373,7 @@ fn coerceResultPtr( | ... | @@ -2386,7 +2373,7 @@ fn coerceResultPtr( |
| 2386 | const trash_inst = trash_block.instructions.items[trash_block.instructions.items.len - 1]; | 2373 | const trash_inst = trash_block.instructions.items[trash_block.instructions.items.len - 1]; |
| 2387 | if (air_tags[trash_inst] != .store) { | 2374 | if (air_tags[trash_inst] != .store) { |
| 2388 | // no store instruction is generated for zero sized types | 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 | } else { | 2377 | } else { |
| 2391 | trash_block.instructions.items.len -= 1; | 2378 | trash_block.instructions.items.len -= 1; |
| 2392 | assert(trash_inst == sema.air_instructions.len - 1); | 2379 | assert(trash_inst == sema.air_instructions.len - 1); |
| ... | @@ -2876,7 +2863,7 @@ fn zirEnumDecl( | ... | @@ -2876,7 +2863,7 @@ fn zirEnumDecl( |
| 2876 | } | 2863 | } |
| 2877 | } else if (any_values) { | 2864 | } else if (any_values) { |
| 2878 | const tag_val = if (last_tag_val) |val| | 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 | else | 2867 | else |
| 2881 | Value.zero; | 2868 | Value.zero; |
| 2882 | last_tag_val = tag_val; | 2869 | last_tag_val = tag_val; |
| ... | @@ -2905,7 +2892,7 @@ fn zirEnumDecl( | ... | @@ -2905,7 +2892,7 @@ fn zirEnumDecl( |
| 2905 | last_tag_val = Value.initPayload(&tag_val_buf.base); | 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 | const tree = try sema.getAstTree(block); | 2896 | const tree = try sema.getAstTree(block); |
| 2910 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); | 2897 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2911 | const msg = try sema.errMsg(block, field_src, "enumeration value '{}' too large for type '{}'", .{ | 2898 | const msg = try sema.errMsg(block, field_src, "enumeration value '{}' too large for type '{}'", .{ |
| ... | @@ -3113,16 +3100,13 @@ fn zirErrorSetDecl( | ... | @@ -3113,16 +3100,13 @@ fn zirErrorSetDecl( |
| 3113 | return sema.analyzeDeclVal(block, src, new_decl_index); | 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 | const tracy = trace(@src()); | 3104 | const tracy = trace(@src()); |
| 3118 | defer tracy.end(); | 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 | if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) { | 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); | 3108 | const fn_ret_ty = try sema.resolveTypeFields(sema.fn_ret_ty); |
| 3125 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); | 3109 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0); |
| 3126 | } | 3110 | } |
| 3127 | | 3111 | |
| 3128 | const target = sema.mod.getTarget(); | 3112 | const target = sema.mod.getTarget(); |
| ... | @@ -3287,7 +3271,6 @@ fn zirAllocExtended( | ... | @@ -3287,7 +3271,6 @@ fn zirAllocExtended( |
| 3287 | extended: Zir.Inst.Extended.InstData, | 3271 | extended: Zir.Inst.Extended.InstData, |
| 3288 | ) CompileError!Air.Inst.Ref { | 3272 | ) CompileError!Air.Inst.Ref { |
| 3289 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); | 3273 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 3290 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | | |
| 3291 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | 3274 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; |
| 3292 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; | 3275 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; |
| 3293 | const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small); | 3276 | const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small); |
| ... | @@ -3314,7 +3297,7 @@ fn zirAllocExtended( | ... | @@ -3314,7 +3297,7 @@ fn zirAllocExtended( |
| 3314 | | 3297 | |
| 3315 | if (block.is_comptime or small.is_comptime) { | 3298 | if (block.is_comptime or small.is_comptime) { |
| 3316 | if (small.has_type) { | 3299 | if (small.has_type) { |
| 3317 | return sema.analyzeComptimeAlloc(block, var_ty, alignment, ty_src); | 3300 | return sema.analyzeComptimeAlloc(block, var_ty, alignment); |
| 3318 | } else { | 3301 | } else { |
| 3319 | return sema.addConstant( | 3302 | return sema.addConstant( |
| 3320 | inferred_alloc_ty, | 3303 | inferred_alloc_ty, |
| ... | @@ -3331,7 +3314,7 @@ fn zirAllocExtended( | ... | @@ -3331,7 +3314,7 @@ fn zirAllocExtended( |
| 3331 | try sema.validateVarType(block, ty_src, var_ty, false); | 3314 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 3332 | } | 3315 | } |
| 3333 | const target = sema.mod.getTarget(); | 3316 | const target = sema.mod.getTarget(); |
| 3334 | try sema.resolveTypeLayout(block, src, var_ty); | 3317 | try sema.resolveTypeLayout(var_ty); |
| 3335 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ | 3318 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 3336 | .pointee_type = var_ty, | 3319 | .pointee_type = var_ty, |
| 3337 | .@"align" = alignment, | 3320 | .@"align" = alignment, |
| ... | @@ -3360,12 +3343,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -3360,12 +3343,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3360 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3343 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3361 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3344 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3362 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 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 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 3349 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3367 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3350 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3368 | const src = inst_data.src(); | | |
| 3369 | const alloc = try sema.resolveInst(inst_data.operand); | 3351 | const alloc = try sema.resolveInst(inst_data.operand); |
| 3370 | const alloc_ty = sema.typeOf(alloc); | 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,13 +3388,13 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3406 | } | 3388 | } |
| 3407 | | 3389 | |
| 3408 | const store_op = air_datas[store_inst].bin_op; | 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 | if (store_op.lhs != alloc) break :ct; | 3392 | if (store_op.lhs != alloc) break :ct; |
| 3411 | | 3393 | |
| 3412 | // Remove all the unnecessary runtime instructions. | 3394 | // Remove all the unnecessary runtime instructions. |
| 3413 | block.instructions.shrinkRetainingCapacity(search_index); | 3395 | block.instructions.shrinkRetainingCapacity(search_index); |
| 3414 | | 3396 | |
| 3415 | var anon_decl = try block.startAnonDecl(src); | 3397 | var anon_decl = try block.startAnonDecl(); |
| 3416 | defer anon_decl.deinit(); | 3398 | defer anon_decl.deinit(); |
| 3417 | return sema.analyzeDeclRef(try anon_decl.finish( | 3399 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 3418 | try elem_ty.copy(anon_decl.arena()), | 3400 | try elem_ty.copy(anon_decl.arena()), |
| ... | @@ -3425,7 +3407,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3425,7 +3407,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3425 | const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); | 3407 | const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 3426 | | 3408 | |
| 3427 | // Detect if a comptime value simply needs to have its type changed. | 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 | return sema.addConstant(const_ptr_ty, val); | 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,7 +3439,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3457 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3439 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3458 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3440 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3459 | if (block.is_comptime) { | 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 | const target = sema.mod.getTarget(); | 3444 | const target = sema.mod.getTarget(); |
| 3463 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ | 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,7 +3458,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 3476 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3458 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3477 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3459 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3478 | if (block.is_comptime) { | 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 | try sema.validateVarType(block, ty_src, var_ty, false); | 3463 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 3482 | const target = sema.mod.getTarget(); | 3464 | const target = sema.mod.getTarget(); |
| ... | @@ -3641,12 +3623,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3641,12 +3623,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3641 | } else unreachable; // TODO shouldn't need this | 3623 | } else unreachable; // TODO shouldn't need this |
| 3642 | | 3624 | |
| 3643 | const store_op = air_datas[store_inst].bin_op; | 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 | if (store_op.lhs != Air.indexToRef(bitcast_inst)) break :ct; | 3627 | if (store_op.lhs != Air.indexToRef(bitcast_inst)) break :ct; |
| 3646 | if (air_datas[bitcast_inst].ty_op.operand != Air.indexToRef(const_inst)) break :ct; | 3628 | if (air_datas[bitcast_inst].ty_op.operand != Air.indexToRef(const_inst)) break :ct; |
| 3647 | | 3629 | |
| 3648 | const new_decl_index = d: { | 3630 | const new_decl_index = d: { |
| 3649 | var anon_decl = try block.startAnonDecl(src); | 3631 | var anon_decl = try block.startAnonDecl(); |
| 3650 | defer anon_decl.deinit(); | 3632 | defer anon_decl.deinit(); |
| 3651 | const new_decl_index = try anon_decl.finish( | 3633 | const new_decl_index = try anon_decl.finish( |
| 3652 | try final_elem_ty.copy(anon_decl.arena()), | 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,7 +3650,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3668 | // Unless the block is comptime, `alloc_inferred` always produces | 3650 | // Unless the block is comptime, `alloc_inferred` always produces |
| 3669 | // a runtime constant. The final inferred type needs to be | 3651 | // a runtime constant. The final inferred type needs to be |
| 3670 | // fully resolved so it can be lowered in codegen. | 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 | return; | 3655 | return; |
| 3674 | } | 3656 | } |
| ... | @@ -3714,7 +3696,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3714,7 +3696,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3714 | defer bitcast_block.instructions.deinit(gpa); | 3696 | defer bitcast_block.instructions.deinit(gpa); |
| 3715 | | 3697 | |
| 3716 | trash_block.instructions.shrinkRetainingCapacity(empty_trash_count); | 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 | assert(bitcast_block.instructions.items.len > 0); | 3701 | assert(bitcast_block.instructions.items.len > 0); |
| 3720 | // If only one instruction is produced then we can replace the bitcast | 3702 | // If only one instruction is produced then we can replace the bitcast |
| ... | @@ -3997,7 +3979,7 @@ fn validateUnionInit( | ... | @@ -3997,7 +3979,7 @@ fn validateUnionInit( |
| 3997 | } else { | 3979 | } else { |
| 3998 | first_block_index = @min(first_block_index, block_index); | 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 | break; | 3983 | break; |
| 4002 | } | 3984 | } |
| 4003 | | 3985 | |
| ... | @@ -4073,7 +4055,7 @@ fn validateStructInit( | ... | @@ -4073,7 +4055,7 @@ fn validateStructInit( |
| 4073 | if ((is_comptime or block.is_comptime) and | 4055 | if ((is_comptime or block.is_comptime) and |
| 4074 | (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null) | 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 | // In this case the only thing we need to do is evaluate the implicit | 4059 | // In this case the only thing we need to do is evaluate the implicit |
| 4078 | // store instructions for default field values, and report any missing fields. | 4060 | // store instructions for default field values, and report any missing fields. |
| 4079 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. | 4061 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. |
| ... | @@ -4143,12 +4125,9 @@ fn validateStructInit( | ... | @@ -4143,12 +4125,9 @@ fn validateStructInit( |
| 4143 | | 4125 | |
| 4144 | field: for (found_fields) |field_ptr, i| { | 4126 | field: for (found_fields) |field_ptr, i| { |
| 4145 | if (field_ptr != 0) { | 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 | // Determine whether the value stored to this pointer is comptime-known. | 4128 | // Determine whether the value stored to this pointer is comptime-known. |
| 4150 | const field_ty = struct_ty.structFieldType(i); | 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 | field_values[i] = opv; | 4131 | field_values[i] = opv; |
| 4153 | continue; | 4132 | continue; |
| 4154 | } | 4133 | } |
| ... | @@ -4210,7 +4189,7 @@ fn validateStructInit( | ... | @@ -4210,7 +4189,7 @@ fn validateStructInit( |
| 4210 | } else { | 4189 | } else { |
| 4211 | first_block_index = @min(first_block_index, block_index); | 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 | field_values[i] = val; | 4193 | field_values[i] = val; |
| 4215 | } else { | 4194 | } else { |
| 4216 | struct_is_comptime = false; | 4195 | struct_is_comptime = false; |
| ... | @@ -4271,7 +4250,7 @@ fn validateStructInit( | ... | @@ -4271,7 +4250,7 @@ fn validateStructInit( |
| 4271 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); | 4250 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); |
| 4272 | return; | 4251 | return; |
| 4273 | } | 4252 | } |
| 4274 | try sema.resolveStructLayout(block, init_src, struct_ty); | 4253 | try sema.resolveStructLayout(struct_ty); |
| 4275 | | 4254 | |
| 4276 | // Our task is to insert `store` instructions for all the default field values. | 4255 | // Our task is to insert `store` instructions for all the default field values. |
| 4277 | for (found_fields) |field_ptr, i| { | 4256 | for (found_fields) |field_ptr, i| { |
| ... | @@ -4352,14 +4331,11 @@ fn zirValidateArrayInit( | ... | @@ -4352,14 +4331,11 @@ fn zirValidateArrayInit( |
| 4352 | // being comptime-known. | 4331 | // being comptime-known. |
| 4353 | const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel()); | 4332 | const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel()); |
| 4354 | const element_vals = try sema.arena.alloc(Value, array_len_s); | 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 | const air_tags = sema.air_instructions.items(.tag); | 4335 | const air_tags = sema.air_instructions.items(.tag); |
| 4357 | const air_datas = sema.air_instructions.items(.data); | 4336 | const air_datas = sema.air_instructions.items(.data); |
| 4358 | | 4337 | |
| 4359 | outer: for (instrs) |elem_ptr, i| { | 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 | // Determine whether the value stored to this pointer is comptime-known. | 4339 | // Determine whether the value stored to this pointer is comptime-known. |
| 4364 | | 4340 | |
| 4365 | if (array_ty.isTuple()) { | 4341 | if (array_ty.isTuple()) { |
| ... | @@ -4427,7 +4403,7 @@ fn zirValidateArrayInit( | ... | @@ -4427,7 +4403,7 @@ fn zirValidateArrayInit( |
| 4427 | } else { | 4403 | } else { |
| 4428 | first_block_index = @min(first_block_index, block_index); | 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 | element_vals[i] = val; | 4407 | element_vals[i] = val; |
| 4432 | } else { | 4408 | } else { |
| 4433 | array_is_comptime = false; | 4409 | array_is_comptime = false; |
| ... | @@ -4465,7 +4441,6 @@ fn zirValidateArrayInit( | ... | @@ -4465,7 +4441,6 @@ fn zirValidateArrayInit( |
| 4465 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4441 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4466 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 4442 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4467 | const src = inst_data.src(); | 4443 | const src = inst_data.src(); |
| 4468 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | | |
| 4469 | const operand = try sema.resolveInst(inst_data.operand); | 4444 | const operand = try sema.resolveInst(inst_data.operand); |
| 4470 | const operand_ty = sema.typeOf(operand); | 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,11 +4453,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4478 | } | 4453 | } |
| 4479 | | 4454 | |
| 4480 | const elem_ty = operand_ty.elemType2(); | 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 | if (val.isUndef()) { | 4457 | if (val.isUndef()) { |
| 4483 | return sema.fail(block, src, "cannot dereference undefined value", .{}); | 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 | const msg = msg: { | 4461 | const msg = msg: { |
| 4487 | const msg = try sema.errMsg( | 4462 | const msg = try sema.errMsg( |
| 4488 | block, | 4463 | block, |
| ... | @@ -4689,9 +4664,9 @@ fn storeToInferredAllocComptime( | ... | @@ -4689,9 +4664,9 @@ fn storeToInferredAllocComptime( |
| 4689 | const operand_ty = sema.typeOf(operand); | 4664 | const operand_ty = sema.typeOf(operand); |
| 4690 | // There will be only one store_to_inferred_ptr because we are running at comptime. | 4665 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 4691 | // The alloc will turn into a Decl. | 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 | if (operand_val.tag() == .variable) break :store; | 4668 | if (operand_val.tag() == .variable) break :store; |
| 4694 | var anon_decl = try block.startAnonDecl(src); | 4669 | var anon_decl = try block.startAnonDecl(); |
| 4695 | defer anon_decl.deinit(); | 4670 | defer anon_decl.deinit(); |
| 4696 | iac.data.decl_index = try anon_decl.finish( | 4671 | iac.data.decl_index = try anon_decl.finish( |
| 4697 | try operand_ty.copy(anon_decl.arena()), | 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,7 +4763,7 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air |
| 4788 | gop.value_ptr.* = .none; | 4763 | gop.value_ptr.* = .none; |
| 4789 | } | 4764 | } |
| 4790 | const decl_index = gop.value_ptr.unwrap() orelse di: { | 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 | defer anon_decl.deinit(); | 4767 | defer anon_decl.deinit(); |
| 4793 | | 4768 | |
| 4794 | const decl_index = try anon_decl.finish( | 4769 | const decl_index = try anon_decl.finish( |
| ... | @@ -4869,7 +4844,6 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -4869,7 +4844,6 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 4869 | | 4844 | |
| 4870 | fn zirCompileLog( | 4845 | fn zirCompileLog( |
| 4871 | sema: *Sema, | 4846 | sema: *Sema, |
| 4872 | block: *Block, | | |
| 4873 | extended: Zir.Inst.Extended.InstData, | 4847 | extended: Zir.Inst.Extended.InstData, |
| 4874 | ) CompileError!Air.Inst.Ref { | 4848 | ) CompileError!Air.Inst.Ref { |
| 4875 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); | 4849 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); |
| ... | @@ -4878,7 +4852,6 @@ fn zirCompileLog( | ... | @@ -4878,7 +4852,6 @@ fn zirCompileLog( |
| 4878 | | 4852 | |
| 4879 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); | 4853 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 4880 | const src_node = extra.data.src_node; | 4854 | const src_node = extra.data.src_node; |
| 4881 | const src = LazySrcLoc.nodeOffset(src_node); | | |
| 4882 | const args = sema.code.refSlice(extra.end, extended.small); | 4855 | const args = sema.code.refSlice(extra.end, extended.small); |
| 4883 | | 4856 | |
| 4884 | for (args) |arg_ref, i| { | 4857 | for (args) |arg_ref, i| { |
| ... | @@ -4886,8 +4859,8 @@ fn zirCompileLog( | ... | @@ -4886,8 +4859,8 @@ fn zirCompileLog( |
| 4886 | | 4859 | |
| 4887 | const arg = try sema.resolveInst(arg_ref); | 4860 | const arg = try sema.resolveInst(arg_ref); |
| 4888 | const arg_ty = sema.typeOf(arg); | 4861 | const arg_ty = sema.typeOf(arg); |
| 4889 | if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| { | 4862 | if (try sema.resolveMaybeUndefVal(arg)) |val| { |
| 4890 | try sema.resolveLazyValue(block, src, val); | 4863 | try sema.resolveLazyValue(val); |
| 4891 | try writer.print("@as({}, {})", .{ | 4864 | try writer.print("@as({}, {})", .{ |
| 4892 | arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod), | 4865 | arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod), |
| 4893 | }); | 4866 | }); |
| ... | @@ -5207,7 +5180,7 @@ fn analyzeBlockBody( | ... | @@ -5207,7 +5180,7 @@ fn analyzeBlockBody( |
| 5207 | // TODO add note "missing else causes void value" | 5180 | // TODO add note "missing else causes void value" |
| 5208 | | 5181 | |
| 5209 | const type_src = src; // TODO: better source location | 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 | if (!valid_rt) { | 5184 | if (!valid_rt) { |
| 5212 | const msg = msg: { | 5185 | const msg = msg: { |
| 5213 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); | 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,7 +5325,7 @@ pub fn analyzeExport( |
| 5352 | try mod.ensureDeclAnalyzed(exported_decl_index); | 5325 | try mod.ensureDeclAnalyzed(exported_decl_index); |
| 5353 | const exported_decl = mod.declPtr(exported_decl_index); | 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 | const msg = msg: { | 5329 | const msg = msg: { |
| 5357 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)}); | 5330 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)}); |
| 5358 | errdefer msg.destroy(sema.gpa); | 5331 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -5581,10 +5554,10 @@ fn addDbgVar( | ... | @@ -5581,10 +5554,10 @@ fn addDbgVar( |
| 5581 | const operand_ty = sema.typeOf(operand); | 5554 | const operand_ty = sema.typeOf(operand); |
| 5582 | switch (air_tag) { | 5555 | switch (air_tag) { |
| 5583 | .dbg_var_ptr => { | 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 | .dbg_var_val => { | 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 | else => unreachable, | 5562 | else => unreachable, |
| 5590 | } | 5563 | } |
| ... | @@ -5746,8 +5719,8 @@ fn lookupInNamespace( | ... | @@ -5746,8 +5719,8 @@ fn lookupInNamespace( |
| 5746 | return null; | 5719 | return null; |
| 5747 | } | 5720 | } |
| 5748 | | 5721 | |
| 5749 | fn funcDeclSrc(sema: *Sema, block: *Block, src: LazySrcLoc, func_inst: Air.Inst.Ref) !?Module.SrcLoc { | 5722 | fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?Module.SrcLoc { |
| 5750 | const func_val = (try sema.resolveMaybeUndefVal(block, src, func_inst)) orelse return null; | 5723 | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; |
| 5751 | if (func_val.isUndef()) return null; | 5724 | if (func_val.isUndef()) return null; |
| 5752 | const owner_decl_index = switch (func_val.tag()) { | 5725 | const owner_decl_index = switch (func_val.tag()) { |
| 5753 | .extern_fn => func_val.castTag(.extern_fn).?.data.owner_decl, | 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,11 +5742,11 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 5769 | if (block.is_comptime) | 5742 | if (block.is_comptime) |
| 5770 | return .none; | 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 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 5746 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 5774 | else => |e| return e, | 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 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 5750 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 5778 | else => |e| return e, | 5751 | else => |e| return e, |
| 5779 | }; | 5752 | }; |
| ... | @@ -5812,8 +5785,8 @@ fn popErrorReturnTrace( | ... | @@ -5812,8 +5785,8 @@ fn popErrorReturnTrace( |
| 5812 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or | 5785 | // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or |
| 5813 | // the result is comptime-known to be a non-error. Either way, pop unconditionally. | 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"); | 5788 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 5816 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 5789 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 5817 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); | 5790 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 5818 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 5791 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 5819 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, "index", src, stack_trace_ty, true); | 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,8 +5810,8 @@ fn popErrorReturnTrace( |
| 5837 | defer then_block.instructions.deinit(sema.gpa); | 5810 | defer then_block.instructions.deinit(sema.gpa); |
| 5838 | | 5811 | |
| 5839 | // If non-error, then pop the error return trace by restoring the index. | 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"); | 5813 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 5841 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 5814 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 5842 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); | 5815 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 5843 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); | 5816 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 5844 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, "index", src, stack_trace_ty, true); | 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,7 +5907,7 @@ fn zirCall( |
| 5934 | break :check_args; | 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 | const member_str = if (bound_arg_src != null) "member function " else ""; | 5911 | const member_str = if (bound_arg_src != null) "member function " else ""; |
| 5939 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; | 5912 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 5940 | const msg = msg: { | 5913 | const msg = msg: { |
| ... | @@ -6017,8 +5990,8 @@ fn zirCall( | ... | @@ -6017,8 +5990,8 @@ fn zirCall( |
| 6017 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only | 5990 | // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only |
| 6018 | // need to clean-up our own trace if we were passed to a non-error-handling expression. | 5991 | // need to clean-up our own trace if we were passed to a non-error-handling expression. |
| 6019 | if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError())) { | 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"); | 5993 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 6021 | const stack_trace_ty = try sema.resolveTypeFields(block, call_src, unresolved_stack_trace_ty); | 5994 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 6022 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, "index", call_src); | 5995 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, "index", call_src); |
| 6023 | | 5996 | |
| 6024 | // Insert a save instruction before the arg resolution + call instructions we just generated | 5997 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| ... | @@ -6145,7 +6118,7 @@ fn analyzeCall( | ... | @@ -6145,7 +6118,7 @@ fn analyzeCall( |
| 6145 | const func_ty_info = func_ty.fnInfo(); | 6118 | const func_ty_info = func_ty.fnInfo(); |
| 6146 | const cc = func_ty_info.cc; | 6119 | const cc = func_ty_info.cc; |
| 6147 | if (cc == .Naked) { | 6120 | if (cc == .Naked) { |
| 6148 | const decl_src = try sema.funcDeclSrc(block, func_src, func); | 6121 | const decl_src = try sema.funcDeclSrc(func); |
| 6149 | const msg = msg: { | 6122 | const msg = msg: { |
| 6150 | const msg = try sema.errMsg( | 6123 | const msg = try sema.errMsg( |
| 6151 | block, | 6124 | block, |
| ... | @@ -6677,7 +6650,7 @@ fn analyzeInlineCallArg( | ... | @@ -6677,7 +6650,7 @@ fn analyzeInlineCallArg( |
| 6677 | // Needed so that lazy values do not trigger | 6650 | // Needed so that lazy values do not trigger |
| 6678 | // assertion due to type not being resolved | 6651 | // assertion due to type not being resolved |
| 6679 | // when the hash function is called. | 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 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); | 6656 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | @@ -6687,7 +6660,7 @@ fn analyzeInlineCallArg( | ... | @@ -6687,7 +6660,7 @@ fn analyzeInlineCallArg( |
| 6687 | }; | 6660 | }; |
| 6688 | } else if (zir_tags[inst] == .param_comptime or try sema.typeRequiresComptime(param_ty)) { | 6661 | } else if (zir_tags[inst] == .param_comptime or try sema.typeRequiresComptime(param_ty)) { |
| 6689 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); | 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 | // We have a comptime value but we need a runtime value to preserve inlining semantics, | 6664 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6692 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); | 6665 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); |
| 6693 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); | 6666 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); |
| ... | @@ -6719,7 +6692,7 @@ fn analyzeInlineCallArg( | ... | @@ -6719,7 +6692,7 @@ fn analyzeInlineCallArg( |
| 6719 | // Needed so that lazy values do not trigger | 6692 | // Needed so that lazy values do not trigger |
| 6720 | // assertion due to type not being resolved | 6693 | // assertion due to type not being resolved |
| 6721 | // when the hash function is called. | 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 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); | 6698 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | @@ -6729,7 +6702,7 @@ fn analyzeInlineCallArg( | ... | @@ -6729,7 +6702,7 @@ fn analyzeInlineCallArg( |
| 6729 | }; | 6702 | }; |
| 6730 | } else if (zir_tags[inst] == .param_anytype_comptime or try sema.typeRequiresComptime(param_ty)) { | 6703 | } else if (zir_tags[inst] == .param_anytype_comptime or try sema.typeRequiresComptime(param_ty)) { |
| 6731 | try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg); | 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 | // We have a comptime value but we need a runtime value to preserve inlining semantics, | 6706 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6734 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); | 6707 | const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val)); |
| 6735 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); | 6708 | try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped); |
| ... | @@ -6750,7 +6723,7 @@ fn analyzeCallArg( | ... | @@ -6750,7 +6723,7 @@ fn analyzeCallArg( |
| 6750 | param_ty: Type, | 6723 | param_ty: Type, |
| 6751 | uncasted_arg: Air.Inst.Ref, | 6724 | uncasted_arg: Air.Inst.Ref, |
| 6752 | ) !Air.Inst.Ref { | 6725 | ) !Air.Inst.Ref { |
| 6753 | try sema.resolveTypeFully(block, arg_src, param_ty); | 6726 | try sema.resolveTypeFully(param_ty); |
| 6754 | return sema.coerce(block, param_ty, uncasted_arg, arg_src); | 6727 | return sema.coerce(block, param_ty, uncasted_arg, arg_src); |
| 6755 | } | 6728 | } |
| 6756 | | 6729 | |
| ... | @@ -6773,14 +6746,14 @@ fn analyzeGenericCallArg( | ... | @@ -6773,14 +6746,14 @@ fn analyzeGenericCallArg( |
| 6773 | try sema.queueFullTypeResolution(param_ty); | 6746 | try sema.queueFullTypeResolution(param_ty); |
| 6774 | runtime_args[runtime_i.*] = casted_arg; | 6747 | runtime_args[runtime_i.*] = casted_arg; |
| 6775 | runtime_i.* += 1; | 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 | _ = try sema.coerce(block, comptime_arg.ty, uncasted_arg, arg_src); | 6750 | _ = try sema.coerce(block, comptime_arg.ty, uncasted_arg, arg_src); |
| 6778 | } | 6751 | } |
| 6779 | } | 6752 | } |
| 6780 | | 6753 | |
| 6781 | fn analyzeGenericCallArgVal(sema: *Sema, block: *Block, arg_src: LazySrcLoc, uncasted_arg: Air.Inst.Ref) !Value { | 6754 | fn analyzeGenericCallArgVal(sema: *Sema, block: *Block, arg_src: LazySrcLoc, uncasted_arg: Air.Inst.Ref) !Value { |
| 6782 | const arg_val = try sema.resolveValue(block, arg_src, uncasted_arg, "parameter is comptime"); | 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 | return arg_val; | 6757 | return arg_val; |
| 6785 | } | 6758 | } |
| 6786 | | 6759 | |
| ... | @@ -7032,7 +7005,7 @@ fn instantiateGenericCall( | ... | @@ -7032,7 +7005,7 @@ fn instantiateGenericCall( |
| 7032 | } | 7005 | } |
| 7033 | const arg = uncasted_args[arg_i]; | 7006 | const arg = uncasted_args[arg_i]; |
| 7034 | if (is_comptime) { | 7007 | if (is_comptime) { |
| 7035 | if (try sema.resolveMaybeUndefVal(block, .unneeded, arg)) |arg_val| { | 7008 | if (try sema.resolveMaybeUndefVal(arg)) |arg_val| { |
| 7036 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); | 7009 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); |
| 7037 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); | 7010 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 7038 | } else { | 7011 | } else { |
| ... | @@ -7105,11 +7078,7 @@ fn instantiateGenericCall( | ... | @@ -7105,11 +7078,7 @@ fn instantiateGenericCall( |
| 7105 | } | 7078 | } |
| 7106 | | 7079 | |
| 7107 | if (is_comptime) { | 7080 | if (is_comptime) { |
| 7108 | const arg_val = (child_sema.resolveMaybeUndefValAllowVariables( | 7081 | const arg_val = (child_sema.resolveMaybeUndefValAllowVariables(arg) catch unreachable).?; |
| 7109 | &child_block, | | |
| 7110 | .unneeded, | | |
| 7111 | arg, | | |
| 7112 | ) catch unreachable).?; | | |
| 7113 | child_sema.comptime_args[arg_i] = .{ | 7082 | child_sema.comptime_args[arg_i] = .{ |
| 7114 | .ty = copied_arg_ty, | 7083 | .ty = copied_arg_ty, |
| 7115 | .val = try arg_val.copy(new_decl_arena_allocator), | 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,7 +7209,7 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 7240 | for (tuple.values) |field_val, i| { | 7209 | for (tuple.values) |field_val, i| { |
| 7241 | try sema.resolveTupleLazyValues(block, src, tuple.types[i]); | 7210 | try sema.resolveTupleLazyValues(block, src, tuple.types[i]); |
| 7242 | if (field_val.tag() == .unreachable_value) continue; | 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,7 +7398,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 7429 | const uncasted_operand = try sema.resolveInst(extra.operand); | 7398 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 7430 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | 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 | if (val.isUndef()) { | 7402 | if (val.isUndef()) { |
| 7434 | return sema.addConstUndef(Type.err_int); | 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,11 +7570,11 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7601 | var int_tag_type_buffer: Type.Payload.Bits = undefined; | 7570 | var int_tag_type_buffer: Type.Payload.Bits = undefined; |
| 7602 | const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena); | 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 | return sema.addConstant(int_tag_ty, opv); | 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 | var buffer: Value.Payload.U64 = undefined; | 7578 | var buffer: Value.Payload.U64 = undefined; |
| 7610 | const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer); | 7579 | const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer); |
| 7611 | return sema.addConstant(int_tag_ty, try val.copy(sema.arena)); | 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,14 +7598,14 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7629 | } | 7598 | } |
| 7630 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); | 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 | if (dest_ty.isNonexhaustiveEnum()) { | 7602 | if (dest_ty.isNonexhaustiveEnum()) { |
| 7634 | return sema.addConstant(dest_ty, int_val); | 7603 | return sema.addConstant(dest_ty, int_val); |
| 7635 | } | 7604 | } |
| 7636 | if (int_val.isUndef()) { | 7605 | if (int_val.isUndef()) { |
| 7637 | return sema.failWithUseOfUndef(block, operand_src); | 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 | const msg = msg: { | 7609 | const msg = msg: { |
| 7641 | const msg = try sema.errMsg( | 7610 | const msg = try sema.errMsg( |
| 7642 | block, | 7611 | block, |
| ... | @@ -7653,7 +7622,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -7653,7 +7622,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7653 | return sema.addConstant(dest_ty, int_val); | 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 | const result = try sema.addConstant(dest_ty, opv); | 7626 | const result = try sema.addConstant(dest_ty, opv); |
| 7658 | // The operand is runtime-known but the result is comptime-known. In | 7627 | // The operand is runtime-known but the result is comptime-known. In |
| 7659 | // this case we still need a safety check. | 7628 | // this case we still need a safety check. |
| ... | @@ -8355,7 +8324,7 @@ fn funcCommon( | ... | @@ -8355,7 +8324,7 @@ fn funcCommon( |
| 8355 | }; | 8324 | }; |
| 8356 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 8328 | const msg = msg: { |
| 8360 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ | 8329 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ |
| 8361 | return_type.fmt(sema.mod), @tagName(cc_workaround), | 8330 | return_type.fmt(sema.mod), @tagName(cc_workaround), |
| ... | @@ -8459,8 +8428,8 @@ fn funcCommon( | ... | @@ -8459,8 +8428,8 @@ fn funcCommon( |
| 8459 | if (!is_generic and sema.wantErrorReturnTracing(return_type)) { | 8428 | if (!is_generic and sema.wantErrorReturnTracing(return_type)) { |
| 8460 | // Make sure that StackTrace's fields are resolved so that the backend can | 8429 | // Make sure that StackTrace's fields are resolved so that the backend can |
| 8461 | // lower this fn type. | 8430 | // lower this fn type. |
| 8462 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, ret_ty_src, "StackTrace"); | 8431 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 8463 | _ = try sema.resolveTypeFields(block, ret_ty_src, unresolved_stack_trace_ty); | 8432 | _ = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 8464 | } | 8433 | } |
| 8465 | | 8434 | |
| 8466 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ | 8435 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ |
| ... | @@ -8583,7 +8552,7 @@ fn analyzeParameter( | ... | @@ -8583,7 +8552,7 @@ fn analyzeParameter( |
| 8583 | }; | 8552 | }; |
| 8584 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 8556 | const msg = msg: { |
| 8588 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ | 8557 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ |
| 8589 | param.ty.fmt(sema.mod), @tagName(cc), | 8558 | param.ty.fmt(sema.mod), @tagName(cc), |
| ... | @@ -8693,7 +8662,7 @@ fn zirParam( | ... | @@ -8693,7 +8662,7 @@ fn zirParam( |
| 8693 | } | 8662 | } |
| 8694 | | 8663 | |
| 8695 | if (sema.preallocated_new_func != null) { | 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 | // In this case we are instantiating a generic function call with a non-comptime | 8666 | // In this case we are instantiating a generic function call with a non-comptime |
| 8698 | // non-anytype parameter that ended up being a one-possible-type. | 8667 | // non-anytype parameter that ended up being a one-possible-type. |
| 8699 | // We don't want the parameter to be part of the instantiated function type. | 8668 | // We don't want the parameter to be part of the instantiated function type. |
| ... | @@ -8733,7 +8702,6 @@ fn zirParamAnytype( | ... | @@ -8733,7 +8702,6 @@ fn zirParamAnytype( |
| 8733 | comptime_syntax: bool, | 8702 | comptime_syntax: bool, |
| 8734 | ) CompileError!void { | 8703 | ) CompileError!void { |
| 8735 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 8704 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 8736 | const src = inst_data.src(); | | |
| 8737 | const param_name = inst_data.get(sema.code); | 8705 | const param_name = inst_data.get(sema.code); |
| 8738 | | 8706 | |
| 8739 | if (sema.inst_map.get(inst)) |air_ref| { | 8707 | if (sema.inst_map.get(inst)) |air_ref| { |
| ... | @@ -8743,7 +8711,7 @@ fn zirParamAnytype( | ... | @@ -8743,7 +8711,7 @@ fn zirParamAnytype( |
| 8743 | // function type of the function instruction in this block. | 8711 | // function type of the function instruction in this block. |
| 8744 | return; | 8712 | return; |
| 8745 | } | 8713 | } |
| 8746 | if (null != try sema.typeHasOnePossibleValue(block, src, param_ty)) { | 8714 | if (null != try sema.typeHasOnePossibleValue(param_ty)) { |
| 8747 | return; | 8715 | return; |
| 8748 | } | 8716 | } |
| 8749 | // The map is already populated but we do need to add a runtime parameter. | 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,7 +8797,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8829 | if (!ptr_ty.isPtrAtRuntime()) { | 8797 | if (!ptr_ty.isPtrAtRuntime()) { |
| 8830 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}); | 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 | return sema.addConstant(Type.usize, ptr_val); | 8801 | return sema.addConstant(Type.usize, ptr_val); |
| 8834 | } | 8802 | } |
| 8835 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); | 8803 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| ... | @@ -8942,7 +8910,7 @@ fn intCast( | ... | @@ -8942,7 +8910,7 @@ fn intCast( |
| 8942 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src); | 8910 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src); |
| 8943 | const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); | 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 | return sema.coerce(block, dest_ty, operand, operand_src); | 8914 | return sema.coerce(block, dest_ty, operand, operand_src); |
| 8947 | } else if (dest_scalar_ty.zigTypeTag() == .ComptimeInt) { | 8915 | } else if (dest_scalar_ty.zigTypeTag() == .ComptimeInt) { |
| 8948 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{}); | 8916 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{}); |
| ... | @@ -8951,7 +8919,7 @@ fn intCast( | ... | @@ -8951,7 +8919,7 @@ fn intCast( |
| 8951 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src); | 8919 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src); |
| 8952 | const is_vector = dest_ty.zigTypeTag() == .Vector; | 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 | // requirement: intCast(u0, input) iff input == 0 | 8923 | // requirement: intCast(u0, input) iff input == 0 |
| 8956 | if (runtime_safety and block.wantSafety()) { | 8924 | if (runtime_safety and block.wantSafety()) { |
| 8957 | try sema.requireRuntimeBlock(block, src, operand_src); | 8925 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -9012,7 +8980,7 @@ fn intCast( | ... | @@ -9012,7 +8980,7 @@ fn intCast( |
| 9012 | // range to account for negative values. | 8980 | // range to account for negative values. |
| 9013 | const dest_range_val = if (wanted_info.signedness == .signed) range_val: { | 8981 | const dest_range_val = if (wanted_info.signedness == .signed) range_val: { |
| 9014 | const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, target); | 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 | } else dest_max_val; | 8984 | } else dest_max_val; |
| 9017 | const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val); | 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,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 | return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target)); | 9226 | return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target)); |
| 9259 | } | 9227 | } |
| 9260 | if (dest_is_comptime_float) { | 9228 | if (dest_is_comptime_float) { |
| ... | @@ -9415,7 +9383,7 @@ fn zirSwitchCapture( | ... | @@ -9415,7 +9383,7 @@ fn zirSwitchCapture( |
| 9415 | return block.addStructFieldVal(operand_ptr, field_index, field_ty); | 9383 | return block.addStructFieldVal(operand_ptr, field_index, field_ty); |
| 9416 | } | 9384 | } |
| 9417 | } else if (is_ref) { | 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 | } else { | 9387 | } else { |
| 9420 | return block.inline_case_capture; | 9388 | return block.inline_case_capture; |
| 9421 | } | 9389 | } |
| ... | @@ -9616,14 +9584,14 @@ fn zirSwitchCond( | ... | @@ -9616,14 +9584,14 @@ fn zirSwitchCond( |
| 9616 | if (operand_ty.isSlice()) { | 9584 | if (operand_ty.isSlice()) { |
| 9617 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}); | 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 | return sema.addConstant(operand_ty, opv); | 9588 | return sema.addConstant(operand_ty, opv); |
| 9621 | } | 9589 | } |
| 9622 | return operand; | 9590 | return operand; |
| 9623 | }, | 9591 | }, |
| 9624 | | 9592 | |
| 9625 | .Union => { | 9593 | .Union => { |
| 9626 | const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty); | 9594 | const union_ty = try sema.resolveTypeFields(operand_ty); |
| 9627 | const enum_ty = union_ty.unionTagType() orelse { | 9595 | const enum_ty = union_ty.unionTagType() orelse { |
| 9628 | const msg = msg: { | 9596 | const msg = msg: { |
| 9629 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); | 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,8 +10304,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10336 | // Validation above ensured these will succeed. | 10304 | // Validation above ensured these will succeed. |
| 10337 | const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, "") catch unreachable; | 10305 | const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, "") catch unreachable; |
| 10338 | const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last, "") catch unreachable; | 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 | 10307 | if ((try sema.compareAll(operand_val, .gte, first_tv.val, operand_ty)) and |
| 10340 | (try sema.compareAll(block, src, operand_val, .lte, last_tv.val, operand_ty))) | 10308 | (try sema.compareAll(operand_val, .lte, last_tv.val, operand_ty))) |
| 10341 | { | 10309 | { |
| 10342 | if (is_inline) child_block.inline_case_capture = operand; | 10310 | if (is_inline) child_block.inline_case_capture = operand; |
| 10343 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); | 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,7 +10455,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10487 | | 10455 | |
| 10488 | while (item.compareAll(.lte, item_last, operand_ty, sema.mod)) : ({ | 10456 | while (item.compareAll(.lte, item_last, operand_ty, sema.mod)) : ({ |
| 10489 | // Previous validation has resolved any possible lazy values. | 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 | cases_len += 1; | 10460 | cases_len += 1; |
| 10493 | | 10461 | |
| ... | @@ -10766,7 +10734,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10766,7 +10734,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10766 | } | 10734 | } |
| 10767 | }, | 10735 | }, |
| 10768 | .Int => { | 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 | while (try it.next()) |cur| { | 10738 | while (try it.next()) |cur| { |
| 10771 | cases_len += 1; | 10739 | cases_len += 1; |
| 10772 | | 10740 | |
| ... | @@ -10909,8 +10877,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10909,8 +10877,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10909 | | 10877 | |
| 10910 | const RangeSetUnhandledIterator = struct { | 10878 | const RangeSetUnhandledIterator = struct { |
| 10911 | sema: *Sema, | 10879 | sema: *Sema, |
| 10912 | block: *Block, | | |
| 10913 | src: LazySrcLoc, | | |
| 10914 | ty: Type, | 10880 | ty: Type, |
| 10915 | cur: Value, | 10881 | cur: Value, |
| 10916 | max: Value, | 10882 | max: Value, |
| ... | @@ -10918,15 +10884,13 @@ const RangeSetUnhandledIterator = struct { | ... | @@ -10918,15 +10884,13 @@ const RangeSetUnhandledIterator = struct { |
| 10918 | range_i: usize = 0, | 10884 | range_i: usize = 0, |
| 10919 | first: bool = true, | 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 | const target = sema.mod.getTarget(); | 10888 | const target = sema.mod.getTarget(); |
| 10923 | const min = try ty.minInt(sema.arena, target); | 10889 | const min = try ty.minInt(sema.arena, target); |
| 10924 | const max = try ty.maxInt(sema.arena, target); | 10890 | const max = try ty.maxInt(sema.arena, target); |
| 10925 | | 10891 | |
| 10926 | return RangeSetUnhandledIterator{ | 10892 | return RangeSetUnhandledIterator{ |
| 10927 | .sema = sema, | 10893 | .sema = sema, |
| 10928 | .block = block, | | |
| 10929 | .src = src, | | |
| 10930 | .ty = ty, | 10894 | .ty = ty, |
| 10931 | .cur = min, | 10895 | .cur = min, |
| 10932 | .max = max, | 10896 | .max = max, |
| ... | @@ -10937,7 +10901,7 @@ const RangeSetUnhandledIterator = struct { | ... | @@ -10937,7 +10901,7 @@ const RangeSetUnhandledIterator = struct { |
| 10937 | fn next(it: *RangeSetUnhandledIterator) !?Value { | 10901 | fn next(it: *RangeSetUnhandledIterator) !?Value { |
| 10938 | while (it.range_i < it.ranges.len) : (it.range_i += 1) { | 10902 | while (it.range_i < it.ranges.len) : (it.range_i += 1) { |
| 10939 | if (!it.first) { | 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 | it.first = false; | 10906 | it.first = false; |
| 10943 | if (it.cur.compareAll(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) { | 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,7 +10910,7 @@ const RangeSetUnhandledIterator = struct { |
| 10946 | it.cur = it.ranges[it.range_i].last; | 10910 | it.cur = it.ranges[it.range_i].last; |
| 10947 | } | 10911 | } |
| 10948 | if (!it.first) { | 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 | it.first = false; | 10915 | it.first = false; |
| 10952 | if (it.cur.compareAll(.lte, it.max, it.ty, it.sema.mod)) { | 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,8 +11163,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11199 | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; | 11163 | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; |
| 11200 | const src = inst_data.src(); | 11164 | const src = inst_data.src(); |
| 11201 | | 11165 | |
| 11202 | const panic_fn = try sema.getBuiltin(block, src, "panicUnwrapError"); | 11166 | const panic_fn = try sema.getBuiltin("panicUnwrapError"); |
| 11203 | const err_return_trace = try sema.getErrorReturnTrace(block, src); | 11167 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11204 | const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; | 11168 | const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; |
| 11205 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); | 11169 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11206 | return true; | 11170 | return true; |
| ... | @@ -11210,8 +11174,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op | ... | @@ -11210,8 +11174,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11210 | const src = inst_data.src(); | 11174 | const src = inst_data.src(); |
| 11211 | const msg_inst = try sema.resolveInst(inst_data.operand); | 11175 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 11212 | | 11176 | |
| 11213 | const panic_fn = try sema.getBuiltin(block, src, "panic"); | 11177 | const panic_fn = try sema.getBuiltin("panic"); |
| 11214 | const err_return_trace = try sema.getErrorReturnTrace(block, src); | 11178 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11215 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; | 11179 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; |
| 11216 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); | 11180 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11217 | return true; | 11181 | return true; |
| ... | @@ -11272,7 +11236,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -11272,7 +11236,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 11272 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 11236 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 11273 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); | 11237 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 11274 | const field_name = try sema.resolveConstString(block, name_src, extra.rhs, "field name must be comptime-known"); | 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 | const has_field = hf: { | 11241 | const has_field = hf: { |
| 11278 | if (ty.isSlice()) { | 11242 | if (ty.isSlice()) { |
| ... | @@ -11315,7 +11279,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -11315,7 +11279,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11315 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 11279 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 11316 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "decl name must be comptime-known"); | 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 | const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false; | 11284 | const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false; |
| 11321 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { | 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,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 | defer anon_decl.deinit(); | 11358 | defer anon_decl.deinit(); |
| 11395 | | 11359 | |
| 11396 | const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1]; | 11360 | const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1]; |
| ... | @@ -11451,15 +11415,15 @@ fn zirShl( | ... | @@ -11451,15 +11415,15 @@ fn zirShl( |
| 11451 | // TODO coerce rhs if air_tag is not shl_sat | 11415 | // TODO coerce rhs if air_tag is not shl_sat |
| 11452 | const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty); | 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); | 11418 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 11455 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); | 11419 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 11456 | | 11420 | |
| 11457 | if (maybe_rhs_val) |rhs_val| { | 11421 | if (maybe_rhs_val) |rhs_val| { |
| 11458 | if (rhs_val.isUndef()) { | 11422 | if (rhs_val.isUndef()) { |
| 11459 | return sema.addConstUndef(sema.typeOf(lhs)); | 11423 | return sema.addConstUndef(sema.typeOf(lhs)); |
| 11460 | } | 11424 | } |
| 11461 | // If rhs is 0, return lhs without doing any calculations. | 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 | return lhs; | 11427 | return lhs; |
| 11464 | } | 11428 | } |
| 11465 | if (scalar_ty.zigTypeTag() != .ComptimeInt and air_tag != .shl_sat) { | 11429 | if (scalar_ty.zigTypeTag() != .ComptimeInt and air_tag != .shl_sat) { |
| ... | @@ -11620,15 +11584,15 @@ fn zirShr( | ... | @@ -11620,15 +11584,15 @@ fn zirShr( |
| 11620 | const target = sema.mod.getTarget(); | 11584 | const target = sema.mod.getTarget(); |
| 11621 | const scalar_ty = lhs_ty.scalarType(); | 11585 | const scalar_ty = lhs_ty.scalarType(); |
| 11622 | | 11586 | |
| 11623 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); | 11587 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 11624 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); | 11588 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 11625 | | 11589 | |
| 11626 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { | 11590 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { |
| 11627 | if (rhs_val.isUndef()) { | 11591 | if (rhs_val.isUndef()) { |
| 11628 | return sema.addConstUndef(lhs_ty); | 11592 | return sema.addConstUndef(lhs_ty); |
| 11629 | } | 11593 | } |
| 11630 | // If rhs is 0, return lhs without doing any calculations. | 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 | return lhs; | 11596 | return lhs; |
| 11633 | } | 11597 | } |
| 11634 | if (scalar_ty.zigTypeTag() != .ComptimeInt) { | 11598 | if (scalar_ty.zigTypeTag() != .ComptimeInt) { |
| ... | @@ -11662,7 +11626,7 @@ fn zirShr( | ... | @@ -11662,7 +11626,7 @@ fn zirShr( |
| 11662 | if (air_tag == .shr_exact) { | 11626 | if (air_tag == .shr_exact) { |
| 11663 | // Detect if any ones would be shifted out. | 11627 | // Detect if any ones would be shifted out. |
| 11664 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target); | 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 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); | 11630 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); |
| 11667 | } | 11631 | } |
| 11668 | } | 11632 | } |
| ... | @@ -11759,8 +11723,8 @@ fn zirBitwise( | ... | @@ -11759,8 +11723,8 @@ fn zirBitwise( |
| 11759 | const runtime_src = runtime: { | 11723 | const runtime_src = runtime: { |
| 11760 | // TODO: ask the linker what kind of relocations are available, and | 11724 | // TODO: ask the linker what kind of relocations are available, and |
| 11761 | // in some cases emit a Value that means "this decl's address AND'd with this operand". | 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| { | 11726 | if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| { |
| 11763 | if (try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs)) |rhs_val| { | 11727 | if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| { |
| 11764 | const result_val = switch (air_tag) { | 11728 | const result_val = switch (air_tag) { |
| 11765 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target), | 11729 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target), |
| 11766 | .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target), | 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,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 | if (val.isUndef()) { | 11767 | if (val.isUndef()) { |
| 11804 | return sema.addConstUndef(operand_type); | 11768 | return sema.addConstUndef(operand_type); |
| 11805 | } else if (operand_type.zigTypeTag() == .Vector) { | 11769 | } else if (operand_type.zigTypeTag() == .Vector) { |
| ... | @@ -11946,7 +11910,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -11946,7 +11910,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 11946 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 11910 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 11947 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); | 11911 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); |
| 11948 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); | 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 | break :s lhs_sent_casted_val; | 11914 | break :s lhs_sent_casted_val; |
| 11951 | } else { | 11915 | } else { |
| 11952 | break :s null; | 11916 | break :s null; |
| ... | @@ -12019,7 +11983,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12019,7 +11983,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12019 | element_vals[result_len] = sent_val; | 11983 | element_vals[result_len] = sent_val; |
| 12020 | } | 11984 | } |
| 12021 | const val = try Value.Tag.aggregate.create(sema.arena, element_vals); | 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 | } else break :rs rhs_src; | 11987 | } else break :rs rhs_src; |
| 12024 | } else lhs_src; | 11988 | } else lhs_src; |
| 12025 | | 11989 | |
| ... | @@ -12238,7 +12202,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12238,7 +12202,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12238 | } | 12202 | } |
| 12239 | break :v try Value.Tag.aggregate.create(sema.arena, element_vals); | 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 | try sema.requireRuntimeBlock(block, src, lhs_src); | 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,7 +12274,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12310 | | 12274 | |
| 12311 | if (rhs_scalar_ty.isAnyFloat()) { | 12275 | if (rhs_scalar_ty.isAnyFloat()) { |
| 12312 | // We handle float negation here to ensure negative zero is represented in the bits. | 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 | if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty); | 12278 | if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty); |
| 12315 | const target = sema.mod.getTarget(); | 12279 | const target = sema.mod.getTarget(); |
| 12316 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target)); | 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,8 +12370,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12406 | | 12370 | |
| 12407 | const mod = sema.mod; | 12371 | const mod = sema.mod; |
| 12408 | const target = mod.getTarget(); | 12372 | const target = mod.getTarget(); |
| 12409 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 12373 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12410 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 12374 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12411 | | 12375 | |
| 12412 | if ((lhs_ty.zigTypeTag() == .ComptimeFloat and rhs_ty.zigTypeTag() == .ComptimeInt) or | 12376 | if ((lhs_ty.zigTypeTag() == .ComptimeFloat and rhs_ty.zigTypeTag() == .ComptimeInt) or |
| 12413 | (lhs_ty.zigTypeTag() == .ComptimeInt and rhs_ty.zigTypeTag() == .ComptimeFloat)) | 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,7 +12419,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12455 | .Int, .ComptimeInt, .ComptimeFloat => { | 12419 | .Int, .ComptimeInt, .ComptimeFloat => { |
| 12456 | if (maybe_lhs_val) |lhs_val| { | 12420 | if (maybe_lhs_val) |lhs_val| { |
| 12457 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 12423 | const zero_val = if (is_vector) b: { |
| 12460 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 12424 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12461 | } else Value.zero; | 12425 | } else Value.zero; |
| ... | @@ -12467,7 +12431,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -12467,7 +12431,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12467 | if (rhs_val.isUndef()) { | 12431 | if (rhs_val.isUndef()) { |
| 12468 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 12435 | return sema.failWithDivideByZero(block, rhs_src); |
| 12472 | } | 12436 | } |
| 12473 | // TODO: if the RHS is one, return the LHS directly | 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,7 +12445,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12481 | if (lhs_val.isUndef()) { | 12445 | if (lhs_val.isUndef()) { |
| 12482 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { | 12446 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12483 | if (maybe_rhs_val) |rhs_val| { | 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 | return sema.addConstUndef(resolved_type); | 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,7 +12458,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 12494 | if (is_int) { | 12458 | if (is_int) { |
| 12495 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); | 12459 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12496 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); | 12462 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12499 | } | 12463 | } |
| 12500 | return sema.addConstant(resolved_type, res); | 12464 | return sema.addConstant(resolved_type, res); |
| ... | @@ -12566,8 +12530,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12566,8 +12530,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12566 | | 12530 | |
| 12567 | const mod = sema.mod; | 12531 | const mod = sema.mod; |
| 12568 | const target = mod.getTarget(); | 12532 | const target = mod.getTarget(); |
| 12569 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 12533 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12570 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 12534 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12571 | | 12535 | |
| 12572 | const runtime_src = rs: { | 12536 | const runtime_src = rs: { |
| 12573 | // For integers: | 12537 | // For integers: |
| ... | @@ -12590,7 +12554,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12590,7 +12554,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12590 | if (lhs_val.isUndef()) { | 12554 | if (lhs_val.isUndef()) { |
| 12591 | return sema.failWithUseOfUndef(block, rhs_src); | 12555 | return sema.failWithUseOfUndef(block, rhs_src); |
| 12592 | } else { | 12556 | } else { |
| 12593 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) { | 12557 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 12594 | const zero_val = if (is_vector) b: { | 12558 | const zero_val = if (is_vector) b: { |
| 12595 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 12559 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12596 | } else Value.zero; | 12560 | } else Value.zero; |
| ... | @@ -12602,7 +12566,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12602,7 +12566,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12602 | if (rhs_val.isUndef()) { | 12566 | if (rhs_val.isUndef()) { |
| 12603 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 12570 | return sema.failWithDivideByZero(block, rhs_src); |
| 12607 | } | 12571 | } |
| 12608 | // TODO: if the RHS is one, return the LHS directly | 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,7 +12580,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12616 | } | 12580 | } |
| 12617 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); | 12581 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12618 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); | 12584 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12621 | } | 12585 | } |
| 12622 | return sema.addConstant(resolved_type, res); | 12586 | return sema.addConstant(resolved_type, res); |
| ... | @@ -12731,8 +12695,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12731,8 +12695,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12731 | | 12695 | |
| 12732 | const mod = sema.mod; | 12696 | const mod = sema.mod; |
| 12733 | const target = mod.getTarget(); | 12697 | const target = mod.getTarget(); |
| 12734 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 12698 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12735 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 12699 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12736 | | 12700 | |
| 12737 | const runtime_src = rs: { | 12701 | const runtime_src = rs: { |
| 12738 | // For integers: | 12702 | // For integers: |
| ... | @@ -12756,7 +12720,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12756,7 +12720,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12756 | // If the lhs is undefined, result is undefined. | 12720 | // If the lhs is undefined, result is undefined. |
| 12757 | if (maybe_lhs_val) |lhs_val| { | 12721 | if (maybe_lhs_val) |lhs_val| { |
| 12758 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 12724 | const zero_val = if (is_vector) b: { |
| 12761 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 12725 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12762 | } else Value.zero; | 12726 | } else Value.zero; |
| ... | @@ -12768,7 +12732,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12768,7 +12732,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12768 | if (rhs_val.isUndef()) { | 12732 | if (rhs_val.isUndef()) { |
| 12769 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 12736 | return sema.failWithDivideByZero(block, rhs_src); |
| 12773 | } | 12737 | } |
| 12774 | // TODO: if the RHS is one, return the LHS directly | 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,7 +12741,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12777 | if (lhs_val.isUndef()) { | 12741 | if (lhs_val.isUndef()) { |
| 12778 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { | 12742 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12779 | if (maybe_rhs_val) |rhs_val| { | 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 | return sema.addConstUndef(resolved_type); | 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,8 +12812,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12848 | | 12812 | |
| 12849 | const mod = sema.mod; | 12813 | const mod = sema.mod; |
| 12850 | const target = mod.getTarget(); | 12814 | const target = mod.getTarget(); |
| 12851 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 12815 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 12852 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 12816 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 12853 | | 12817 | |
| 12854 | const runtime_src = rs: { | 12818 | const runtime_src = rs: { |
| 12855 | // For integers: | 12819 | // For integers: |
| ... | @@ -12873,7 +12837,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12873,7 +12837,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12873 | // If the lhs is undefined, result is undefined. | 12837 | // If the lhs is undefined, result is undefined. |
| 12874 | if (maybe_lhs_val) |lhs_val| { | 12838 | if (maybe_lhs_val) |lhs_val| { |
| 12875 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 12841 | const zero_val = if (is_vector) b: { |
| 12878 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 12842 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 12879 | } else Value.zero; | 12843 | } else Value.zero; |
| ... | @@ -12885,7 +12849,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12885,7 +12849,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12885 | if (rhs_val.isUndef()) { | 12849 | if (rhs_val.isUndef()) { |
| 12886 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 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,7 +12857,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12893 | if (lhs_val.isUndef()) { | 12857 | if (lhs_val.isUndef()) { |
| 12894 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { | 12858 | if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) { |
| 12895 | if (maybe_rhs_val) |rhs_val| { | 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 | return sema.addConstUndef(resolved_type); | 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,7 +12870,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12906 | if (is_int) { | 12870 | if (is_int) { |
| 12907 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); | 12871 | const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target); |
| 12908 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); | 12874 | return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index); |
| 12911 | } | 12875 | } |
| 12912 | return sema.addConstant(resolved_type, res); | 12876 | return sema.addConstant(resolved_type, res); |
| ... | @@ -13092,8 +13056,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13092,8 +13056,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13092 | | 13056 | |
| 13093 | const mod = sema.mod; | 13057 | const mod = sema.mod; |
| 13094 | const target = mod.getTarget(); | 13058 | const target = mod.getTarget(); |
| 13095 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 13059 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13096 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 13060 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13097 | | 13061 | |
| 13098 | const runtime_src = rs: { | 13062 | const runtime_src = rs: { |
| 13099 | // For integers: | 13063 | // For integers: |
| ... | @@ -13114,7 +13078,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13114,7 +13078,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13114 | if (lhs_val.isUndef()) { | 13078 | if (lhs_val.isUndef()) { |
| 13115 | return sema.failWithUseOfUndef(block, lhs_src); | 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 | const zero_val = if (is_vector) b: { | 13082 | const zero_val = if (is_vector) b: { |
| 13119 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13083 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13120 | } else Value.zero; | 13084 | } else Value.zero; |
| ... | @@ -13127,18 +13091,18 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13127,18 +13091,18 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13127 | if (rhs_val.isUndef()) { | 13091 | if (rhs_val.isUndef()) { |
| 13128 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 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 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); | 13098 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); |
| 13135 | } | 13099 | } |
| 13136 | if (maybe_lhs_val) |lhs_val| { | 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 | // If this answer could possibly be different by doing `intMod`, | 13102 | // If this answer could possibly be different by doing `intMod`, |
| 13139 | // we must emit a compile error. Otherwise, it's OK. | 13103 | // we must emit a compile error. Otherwise, it's OK. |
| 13140 | if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src))) and | 13104 | if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema)) and |
| 13141 | !(try rem_result.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) | 13105 | !(try rem_result.compareAllWithZeroAdvanced(.eq, sema))) |
| 13142 | { | 13106 | { |
| 13143 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 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,14 +13120,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13156 | if (rhs_val.isUndef()) { | 13120 | if (rhs_val.isUndef()) { |
| 13157 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 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 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); | 13127 | return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty); |
| 13164 | } | 13128 | } |
| 13165 | if (maybe_lhs_val) |lhs_val| { | 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 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); | 13131 | return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty); |
| 13168 | } | 13132 | } |
| 13169 | return sema.addConstant( | 13133 | return sema.addConstant( |
| ... | @@ -13190,38 +13154,32 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13190,38 +13154,32 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13190 | | 13154 | |
| 13191 | fn intRem( | 13155 | fn intRem( |
| 13192 | sema: *Sema, | 13156 | sema: *Sema, |
| 13193 | block: *Block, | | |
| 13194 | ty: Type, | 13157 | ty: Type, |
| 13195 | lhs: Value, | 13158 | lhs: Value, |
| 13196 | lhs_src: LazySrcLoc, | | |
| 13197 | rhs: Value, | 13159 | rhs: Value, |
| 13198 | rhs_src: LazySrcLoc, | | |
| 13199 | ) CompileError!Value { | 13160 | ) CompileError!Value { |
| 13200 | if (ty.zigTypeTag() == .Vector) { | 13161 | if (ty.zigTypeTag() == .Vector) { |
| 13201 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 13162 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 13202 | for (result_data) |*scalar, i| { | 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 | return Value.Tag.aggregate.create(sema.arena, result_data); | 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 | fn intRemScalar( | 13171 | fn intRemScalar( |
| 13211 | sema: *Sema, | 13172 | sema: *Sema, |
| 13212 | block: *Block, | | |
| 13213 | lhs: Value, | 13173 | lhs: Value, |
| 13214 | lhs_src: LazySrcLoc, | | |
| 13215 | rhs: Value, | 13174 | rhs: Value, |
| 13216 | rhs_src: LazySrcLoc, | | |
| 13217 | ) CompileError!Value { | 13175 | ) CompileError!Value { |
| 13218 | const target = sema.mod.getTarget(); | 13176 | const target = sema.mod.getTarget(); |
| 13219 | // TODO is this a performance issue? maybe we should try the operation without | 13177 | // TODO is this a performance issue? maybe we should try the operation without |
| 13220 | // resorting to BigInt first. | 13178 | // resorting to BigInt first. |
| 13221 | var lhs_space: Value.BigIntSpace = undefined; | 13179 | var lhs_space: Value.BigIntSpace = undefined; |
| 13222 | var rhs_space: Value.BigIntSpace = undefined; | 13180 | var rhs_space: Value.BigIntSpace = undefined; |
| 13223 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, lhs_src)); | 13181 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 13224 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, rhs_src)); | 13182 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 13225 | const limbs_q = try sema.arena.alloc( | 13183 | const limbs_q = try sema.arena.alloc( |
| 13226 | math.big.Limb, | 13184 | math.big.Limb, |
| 13227 | lhs_bigint.limbs.len, | 13185 | lhs_bigint.limbs.len, |
| ... | @@ -13274,8 +13232,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13274,8 +13232,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13274 | | 13232 | |
| 13275 | const mod = sema.mod; | 13233 | const mod = sema.mod; |
| 13276 | const target = mod.getTarget(); | 13234 | const target = mod.getTarget(); |
| 13277 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 13235 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13278 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 13236 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13279 | | 13237 | |
| 13280 | const runtime_src = rs: { | 13238 | const runtime_src = rs: { |
| 13281 | // For integers: | 13239 | // For integers: |
| ... | @@ -13299,7 +13257,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13299,7 +13257,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13299 | if (rhs_val.isUndef()) { | 13257 | if (rhs_val.isUndef()) { |
| 13300 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 13261 | return sema.failWithDivideByZero(block, rhs_src); |
| 13304 | } | 13262 | } |
| 13305 | if (maybe_lhs_val) |lhs_val| { | 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,7 +13276,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13318 | if (rhs_val.isUndef()) { | 13276 | if (rhs_val.isUndef()) { |
| 13319 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 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,8 +13335,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13377 | | 13335 | |
| 13378 | const mod = sema.mod; | 13336 | const mod = sema.mod; |
| 13379 | const target = mod.getTarget(); | 13337 | const target = mod.getTarget(); |
| 13380 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 13338 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13381 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 13339 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13382 | | 13340 | |
| 13383 | const runtime_src = rs: { | 13341 | const runtime_src = rs: { |
| 13384 | // For integers: | 13342 | // For integers: |
| ... | @@ -13402,13 +13360,13 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13402,13 +13360,13 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13402 | if (rhs_val.isUndef()) { | 13360 | if (rhs_val.isUndef()) { |
| 13403 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 13364 | return sema.failWithDivideByZero(block, rhs_src); |
| 13407 | } | 13365 | } |
| 13408 | if (maybe_lhs_val) |lhs_val| { | 13366 | if (maybe_lhs_val) |lhs_val| { |
| 13409 | return sema.addConstant( | 13367 | return sema.addConstant( |
| 13410 | resolved_type, | 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 | break :rs lhs_src; | 13372 | break :rs lhs_src; |
| ... | @@ -13421,7 +13379,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -13421,7 +13379,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 13421 | if (rhs_val.isUndef()) { | 13379 | if (rhs_val.isUndef()) { |
| 13422 | return sema.failWithUseOfUndef(block, rhs_src); | 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 | return sema.failWithDivideByZero(block, rhs_src); | 13383 | return sema.failWithDivideByZero(block, rhs_src); |
| 13426 | } | 13384 | } |
| 13427 | } | 13385 | } |
| ... | @@ -13480,8 +13438,8 @@ fn zirOverflowArithmetic( | ... | @@ -13480,8 +13438,8 @@ fn zirOverflowArithmetic( |
| 13480 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)}); | 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); | 13441 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 13484 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); | 13442 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 13485 | | 13443 | |
| 13486 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); | 13444 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); |
| 13487 | const ov_ty = tuple_ty.tupleFields().types[1]; | 13445 | const ov_ty = tuple_ty.tupleFields().types[1]; |
| ... | @@ -13500,12 +13458,12 @@ fn zirOverflowArithmetic( | ... | @@ -13500,12 +13458,12 @@ fn zirOverflowArithmetic( |
| 13500 | // to the result, even if it is undefined.. | 13458 | // to the result, even if it is undefined.. |
| 13501 | // Otherwise, if either of the argument is undefined, undefined is returned. | 13459 | // Otherwise, if either of the argument is undefined, undefined is returned. |
| 13502 | if (maybe_lhs_val) |lhs_val| { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 13462 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; |
| 13505 | } | 13463 | } |
| 13506 | } | 13464 | } |
| 13507 | if (maybe_rhs_val) |rhs_val| { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13467 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13510 | } | 13468 | } |
| 13511 | } | 13469 | } |
| ... | @@ -13515,7 +13473,7 @@ fn zirOverflowArithmetic( | ... | @@ -13515,7 +13473,7 @@ fn zirOverflowArithmetic( |
| 13515 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 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 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13477 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); |
| 13520 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | 13478 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); |
| 13521 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | 13479 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; |
| ... | @@ -13528,14 +13486,14 @@ fn zirOverflowArithmetic( | ... | @@ -13528,14 +13486,14 @@ fn zirOverflowArithmetic( |
| 13528 | if (maybe_rhs_val) |rhs_val| { | 13486 | if (maybe_rhs_val) |rhs_val| { |
| 13529 | if (rhs_val.isUndef()) { | 13487 | if (rhs_val.isUndef()) { |
| 13530 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13490 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13533 | } else if (maybe_lhs_val) |lhs_val| { | 13491 | } else if (maybe_lhs_val) |lhs_val| { |
| 13534 | if (lhs_val.isUndef()) { | 13492 | if (lhs_val.isUndef()) { |
| 13535 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 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 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13497 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); |
| 13540 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | 13498 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); |
| 13541 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | 13499 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; |
| ... | @@ -13548,9 +13506,9 @@ fn zirOverflowArithmetic( | ... | @@ -13548,9 +13506,9 @@ fn zirOverflowArithmetic( |
| 13548 | // Otherwise, if either of the arguments is undefined, both results are undefined. | 13506 | // Otherwise, if either of the arguments is undefined, both results are undefined. |
| 13549 | if (maybe_lhs_val) |lhs_val| { | 13507 | if (maybe_lhs_val) |lhs_val| { |
| 13550 | if (!lhs_val.isUndef()) { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 13512 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; |
| 13555 | } | 13513 | } |
| 13556 | } | 13514 | } |
| ... | @@ -13558,9 +13516,9 @@ fn zirOverflowArithmetic( | ... | @@ -13558,9 +13516,9 @@ fn zirOverflowArithmetic( |
| 13558 | | 13516 | |
| 13559 | if (maybe_rhs_val) |rhs_val| { | 13517 | if (maybe_rhs_val) |rhs_val| { |
| 13560 | if (!rhs_val.isUndef()) { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13522 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13565 | } | 13523 | } |
| 13566 | } | 13524 | } |
| ... | @@ -13584,12 +13542,12 @@ fn zirOverflowArithmetic( | ... | @@ -13584,12 +13542,12 @@ fn zirOverflowArithmetic( |
| 13584 | // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred. | 13542 | // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred. |
| 13585 | // Oterhwise if either of the arguments is undefined, both results are undefined. | 13543 | // Oterhwise if either of the arguments is undefined, both results are undefined. |
| 13586 | if (maybe_lhs_val) |lhs_val| { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13546 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13589 | } | 13547 | } |
| 13590 | } | 13548 | } |
| 13591 | if (maybe_rhs_val) |rhs_val| { | 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 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13551 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; |
| 13594 | } | 13552 | } |
| 13595 | } | 13553 | } |
| ... | @@ -13697,7 +13655,7 @@ fn analyzeArithmetic( | ... | @@ -13697,7 +13655,7 @@ fn analyzeArithmetic( |
| 13697 | .{@tagName(zir_tag)}, | 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,8 +13677,8 @@ fn analyzeArithmetic( |
| 13719 | | 13677 | |
| 13720 | const mod = sema.mod; | 13678 | const mod = sema.mod; |
| 13721 | const target = mod.getTarget(); | 13679 | const target = mod.getTarget(); |
| 13722 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); | 13680 | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 13723 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); | 13681 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 13724 | const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: { | 13682 | const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: { |
| 13725 | switch (zir_tag) { | 13683 | switch (zir_tag) { |
| 13726 | .add => { | 13684 | .add => { |
| ... | @@ -13732,7 +13690,7 @@ fn analyzeArithmetic( | ... | @@ -13732,7 +13690,7 @@ fn analyzeArithmetic( |
| 13732 | // overflow (max_int), causing illegal behavior. | 13690 | // overflow (max_int), causing illegal behavior. |
| 13733 | // For floats: either operand being undef makes the result undef. | 13691 | // For floats: either operand being undef makes the result undef. |
| 13734 | if (maybe_lhs_val) |lhs_val| { | 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 | return casted_rhs; | 13694 | return casted_rhs; |
| 13737 | } | 13695 | } |
| 13738 | } | 13696 | } |
| ... | @@ -13744,7 +13702,7 @@ fn analyzeArithmetic( | ... | @@ -13744,7 +13702,7 @@ fn analyzeArithmetic( |
| 13744 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13706 | return casted_lhs; |
| 13749 | } | 13707 | } |
| 13750 | } | 13708 | } |
| ... | @@ -13759,9 +13717,9 @@ fn analyzeArithmetic( | ... | @@ -13759,9 +13717,9 @@ fn analyzeArithmetic( |
| 13759 | } | 13717 | } |
| 13760 | if (maybe_rhs_val) |rhs_val| { | 13718 | if (maybe_rhs_val) |rhs_val| { |
| 13761 | if (is_int) { | 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 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vector_index); | 13723 | return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vector_index); |
| 13766 | } | 13724 | } |
| 13767 | return sema.addConstant(resolved_type, sum); | 13725 | return sema.addConstant(resolved_type, sum); |
| ... | @@ -13779,7 +13737,7 @@ fn analyzeArithmetic( | ... | @@ -13779,7 +13737,7 @@ fn analyzeArithmetic( |
| 13779 | // If either of the operands are zero, the other operand is returned. | 13737 | // If either of the operands are zero, the other operand is returned. |
| 13780 | // If either of the operands are undefined, the result is undefined. | 13738 | // If either of the operands are undefined, the result is undefined. |
| 13781 | if (maybe_lhs_val) |lhs_val| { | 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 | return casted_rhs; | 13741 | return casted_rhs; |
| 13784 | } | 13742 | } |
| 13785 | } | 13743 | } |
| ... | @@ -13788,13 +13746,13 @@ fn analyzeArithmetic( | ... | @@ -13788,13 +13746,13 @@ fn analyzeArithmetic( |
| 13788 | if (rhs_val.isUndef()) { | 13746 | if (rhs_val.isUndef()) { |
| 13789 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13750 | return casted_lhs; |
| 13793 | } | 13751 | } |
| 13794 | if (maybe_lhs_val) |lhs_val| { | 13752 | if (maybe_lhs_val) |lhs_val| { |
| 13795 | return sema.addConstant( | 13753 | return sema.addConstant( |
| 13796 | resolved_type, | 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 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 13757 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| 13800 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; | 13758 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| ... | @@ -13804,7 +13762,7 @@ fn analyzeArithmetic( | ... | @@ -13804,7 +13762,7 @@ fn analyzeArithmetic( |
| 13804 | // If either of the operands are zero, then the other operand is returned. | 13762 | // If either of the operands are zero, then the other operand is returned. |
| 13805 | // If either of the operands are undefined, the result is undefined. | 13763 | // If either of the operands are undefined, the result is undefined. |
| 13806 | if (maybe_lhs_val) |lhs_val| { | 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 | return casted_rhs; | 13766 | return casted_rhs; |
| 13809 | } | 13767 | } |
| 13810 | } | 13768 | } |
| ... | @@ -13812,12 +13770,12 @@ fn analyzeArithmetic( | ... | @@ -13812,12 +13770,12 @@ fn analyzeArithmetic( |
| 13812 | if (rhs_val.isUndef()) { | 13770 | if (rhs_val.isUndef()) { |
| 13813 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13774 | return casted_lhs; |
| 13817 | } | 13775 | } |
| 13818 | if (maybe_lhs_val) |lhs_val| { | 13776 | if (maybe_lhs_val) |lhs_val| { |
| 13819 | const val = if (scalar_tag == .ComptimeInt) | 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 | else | 13779 | else |
| 13822 | try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target); | 13780 | try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target); |
| 13823 | | 13781 | |
| ... | @@ -13841,7 +13799,7 @@ fn analyzeArithmetic( | ... | @@ -13841,7 +13799,7 @@ fn analyzeArithmetic( |
| 13841 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13803 | return casted_lhs; |
| 13846 | } | 13804 | } |
| 13847 | } | 13805 | } |
| ... | @@ -13856,9 +13814,9 @@ fn analyzeArithmetic( | ... | @@ -13856,9 +13814,9 @@ fn analyzeArithmetic( |
| 13856 | } | 13814 | } |
| 13857 | if (maybe_rhs_val) |rhs_val| { | 13815 | if (maybe_rhs_val) |rhs_val| { |
| 13858 | if (is_int) { | 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 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vector_index); | 13820 | return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vector_index); |
| 13863 | } | 13821 | } |
| 13864 | return sema.addConstant(resolved_type, diff); | 13822 | return sema.addConstant(resolved_type, diff); |
| ... | @@ -13879,7 +13837,7 @@ fn analyzeArithmetic( | ... | @@ -13879,7 +13837,7 @@ fn analyzeArithmetic( |
| 13879 | if (rhs_val.isUndef()) { | 13837 | if (rhs_val.isUndef()) { |
| 13880 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13841 | return casted_lhs; |
| 13884 | } | 13842 | } |
| 13885 | } | 13843 | } |
| ... | @@ -13891,7 +13849,7 @@ fn analyzeArithmetic( | ... | @@ -13891,7 +13849,7 @@ fn analyzeArithmetic( |
| 13891 | if (maybe_rhs_val) |rhs_val| { | 13849 | if (maybe_rhs_val) |rhs_val| { |
| 13892 | return sema.addConstant( | 13850 | return sema.addConstant( |
| 13893 | resolved_type, | 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 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; | 13854 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| 13897 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 13855 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| ... | @@ -13904,7 +13862,7 @@ fn analyzeArithmetic( | ... | @@ -13904,7 +13862,7 @@ fn analyzeArithmetic( |
| 13904 | if (rhs_val.isUndef()) { | 13862 | if (rhs_val.isUndef()) { |
| 13905 | return sema.addConstUndef(resolved_type); | 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 | return casted_lhs; | 13866 | return casted_lhs; |
| 13909 | } | 13867 | } |
| 13910 | } | 13868 | } |
| ... | @@ -13914,7 +13872,7 @@ fn analyzeArithmetic( | ... | @@ -13914,7 +13872,7 @@ fn analyzeArithmetic( |
| 13914 | } | 13872 | } |
| 13915 | if (maybe_rhs_val) |rhs_val| { | 13873 | if (maybe_rhs_val) |rhs_val| { |
| 13916 | const val = if (scalar_tag == .ComptimeInt) | 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 | else | 13876 | else |
| 13919 | try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target); | 13877 | try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target); |
| 13920 | | 13878 | |
| ... | @@ -13933,13 +13891,13 @@ fn analyzeArithmetic( | ... | @@ -13933,13 +13891,13 @@ fn analyzeArithmetic( |
| 13933 | // For floats: either operand being undef makes the result undef. | 13891 | // For floats: either operand being undef makes the result undef. |
| 13934 | if (maybe_lhs_val) |lhs_val| { | 13892 | if (maybe_lhs_val) |lhs_val| { |
| 13935 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 13895 | const zero_val = if (is_vector) b: { |
| 13938 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13896 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13939 | } else Value.zero; | 13897 | } else Value.zero; |
| 13940 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_rhs; | 13901 | return casted_rhs; |
| 13944 | } | 13902 | } |
| 13945 | } | 13903 | } |
| ... | @@ -13953,13 +13911,13 @@ fn analyzeArithmetic( | ... | @@ -13953,13 +13911,13 @@ fn analyzeArithmetic( |
| 13953 | return sema.addConstUndef(resolved_type); | 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 | const zero_val = if (is_vector) b: { | 13915 | const zero_val = if (is_vector) b: { |
| 13958 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13916 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13959 | } else Value.zero; | 13917 | } else Value.zero; |
| 13960 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_lhs; | 13921 | return casted_lhs; |
| 13964 | } | 13922 | } |
| 13965 | if (maybe_lhs_val) |lhs_val| { | 13923 | if (maybe_lhs_val) |lhs_val| { |
| ... | @@ -13973,7 +13931,7 @@ fn analyzeArithmetic( | ... | @@ -13973,7 +13931,7 @@ fn analyzeArithmetic( |
| 13973 | if (is_int) { | 13931 | if (is_int) { |
| 13974 | const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target); | 13932 | const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target); |
| 13975 | var vector_index: usize = undefined; | 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 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index); | 13935 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index); |
| 13978 | } | 13936 | } |
| 13979 | return sema.addConstant(resolved_type, product); | 13937 | return sema.addConstant(resolved_type, product); |
| ... | @@ -13993,13 +13951,13 @@ fn analyzeArithmetic( | ... | @@ -13993,13 +13951,13 @@ fn analyzeArithmetic( |
| 13993 | // If either of the operands are undefined, result is undefined. | 13951 | // If either of the operands are undefined, result is undefined. |
| 13994 | if (maybe_lhs_val) |lhs_val| { | 13952 | if (maybe_lhs_val) |lhs_val| { |
| 13995 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 13955 | const zero_val = if (is_vector) b: { |
| 13998 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13956 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 13999 | } else Value.zero; | 13957 | } else Value.zero; |
| 14000 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_rhs; | 13961 | return casted_rhs; |
| 14004 | } | 13962 | } |
| 14005 | } | 13963 | } |
| ... | @@ -14009,13 +13967,13 @@ fn analyzeArithmetic( | ... | @@ -14009,13 +13967,13 @@ fn analyzeArithmetic( |
| 14009 | if (rhs_val.isUndef()) { | 13967 | if (rhs_val.isUndef()) { |
| 14010 | return sema.addConstUndef(resolved_type); | 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 | const zero_val = if (is_vector) b: { | 13971 | const zero_val = if (is_vector) b: { |
| 14014 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13972 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14015 | } else Value.zero; | 13973 | } else Value.zero; |
| 14016 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_lhs; | 13977 | return casted_lhs; |
| 14020 | } | 13978 | } |
| 14021 | if (maybe_lhs_val) |lhs_val| { | 13979 | if (maybe_lhs_val) |lhs_val| { |
| ... | @@ -14036,13 +13994,13 @@ fn analyzeArithmetic( | ... | @@ -14036,13 +13994,13 @@ fn analyzeArithmetic( |
| 14036 | // If either of the operands are undefined, result is undefined. | 13994 | // If either of the operands are undefined, result is undefined. |
| 14037 | if (maybe_lhs_val) |lhs_val| { | 13995 | if (maybe_lhs_val) |lhs_val| { |
| 14038 | if (!lhs_val.isUndef()) { | 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 | const zero_val = if (is_vector) b: { | 13998 | const zero_val = if (is_vector) b: { |
| 14041 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 13999 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14042 | } else Value.zero; | 14000 | } else Value.zero; |
| 14043 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_rhs; | 14004 | return casted_rhs; |
| 14047 | } | 14005 | } |
| 14048 | } | 14006 | } |
| ... | @@ -14051,13 +14009,13 @@ fn analyzeArithmetic( | ... | @@ -14051,13 +14009,13 @@ fn analyzeArithmetic( |
| 14051 | if (rhs_val.isUndef()) { | 14009 | if (rhs_val.isUndef()) { |
| 14052 | return sema.addConstUndef(resolved_type); | 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 | const zero_val = if (is_vector) b: { | 14013 | const zero_val = if (is_vector) b: { |
| 14056 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); | 14014 | break :b try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 14057 | } else Value.zero; | 14015 | } else Value.zero; |
| 14058 | return sema.addConstant(resolved_type, zero_val); | 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 | return casted_lhs; | 14019 | return casted_lhs; |
| 14062 | } | 14020 | } |
| 14063 | if (maybe_lhs_val) |lhs_val| { | 14021 | if (maybe_lhs_val) |lhs_val| { |
| ... | @@ -14135,7 +14093,7 @@ fn analyzePtrArithmetic( | ... | @@ -14135,7 +14093,7 @@ fn analyzePtrArithmetic( |
| 14135 | // coerce to isize instead of usize. | 14093 | // coerce to isize instead of usize. |
| 14136 | const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src); | 14094 | const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src); |
| 14137 | const target = sema.mod.getTarget(); | 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 | const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); | 14097 | const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); |
| 14140 | const ptr_ty = sema.typeOf(ptr); | 14098 | const ptr_ty = sema.typeOf(ptr); |
| 14141 | const ptr_info = ptr_ty.ptrInfo().data; | 14099 | const ptr_info = ptr_ty.ptrInfo().data; |
| ... | @@ -14183,7 +14141,7 @@ fn analyzePtrArithmetic( | ... | @@ -14183,7 +14141,7 @@ fn analyzePtrArithmetic( |
| 14183 | | 14141 | |
| 14184 | const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(target)); | 14142 | const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(target)); |
| 14185 | if (offset_int == 0) return ptr; | 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 | const elem_size = elem_ty.abiSize(target); | 14145 | const elem_size = elem_ty.abiSize(target); |
| 14188 | const new_addr = switch (air_tag) { | 14146 | const new_addr = switch (air_tag) { |
| 14189 | .ptr_add => addr + elem_size * offset_int, | 14147 | .ptr_add => addr + elem_size * offset_int, |
| ... | @@ -14438,8 +14396,8 @@ fn zirCmpEq( | ... | @@ -14438,8 +14396,8 @@ fn zirCmpEq( |
| 14438 | | 14396 | |
| 14439 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { | 14397 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { |
| 14440 | const runtime_src: LazySrcLoc = src: { | 14398 | const runtime_src: LazySrcLoc = src: { |
| 14441 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lval| { | 14399 | if (try sema.resolveMaybeUndefVal(lhs)) |lval| { |
| 14442 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rval| { | 14400 | if (try sema.resolveMaybeUndefVal(rhs)) |rval| { |
| 14443 | if (lval.isUndef() or rval.isUndef()) { | 14401 | if (lval.isUndef() or rval.isUndef()) { |
| 14444 | return sema.addConstUndef(Type.bool); | 14402 | return sema.addConstUndef(Type.bool); |
| 14445 | } | 14403 | } |
| ... | @@ -14485,7 +14443,7 @@ fn analyzeCmpUnionTag( | ... | @@ -14485,7 +14443,7 @@ fn analyzeCmpUnionTag( |
| 14485 | tag_src: LazySrcLoc, | 14443 | tag_src: LazySrcLoc, |
| 14486 | op: std.math.CompareOperator, | 14444 | op: std.math.CompareOperator, |
| 14487 | ) CompileError!Air.Inst.Ref { | 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 | const union_tag_ty = union_ty.unionTagType() orelse { | 14447 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 14490 | const msg = msg: { | 14448 | const msg = msg: { |
| 14491 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); | 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,7 +14458,7 @@ fn analyzeCmpUnionTag( |
| 14500 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); | 14458 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); |
| 14501 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); | 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 | if (enum_val.isUndef()) return sema.addConstUndef(Type.bool); | 14462 | if (enum_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14505 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); | 14463 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); |
| 14506 | if (field_ty.zigTypeTag() == .NoReturn) { | 14464 | if (field_ty.zigTypeTag() == .NoReturn) { |
| ... | @@ -14598,18 +14556,18 @@ fn cmpSelf( | ... | @@ -14598,18 +14556,18 @@ fn cmpSelf( |
| 14598 | ) CompileError!Air.Inst.Ref { | 14556 | ) CompileError!Air.Inst.Ref { |
| 14599 | const resolved_type = sema.typeOf(casted_lhs); | 14557 | const resolved_type = sema.typeOf(casted_lhs); |
| 14600 | const runtime_src: LazySrcLoc = src: { | 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 | if (lhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 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 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 14562 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14605 | | 14563 | |
| 14606 | if (resolved_type.zigTypeTag() == .Vector) { | 14564 | if (resolved_type.zigTypeTag() == .Vector) { |
| 14607 | const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.@"bool"); | 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 | return sema.addConstant(result_ty, cmp_val); | 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 | return Air.Inst.Ref.bool_true; | 14571 | return Air.Inst.Ref.bool_true; |
| 14614 | } else { | 14572 | } else { |
| 14615 | return Air.Inst.Ref.bool_false; | 14573 | return Air.Inst.Ref.bool_false; |
| ... | @@ -14625,7 +14583,7 @@ fn cmpSelf( | ... | @@ -14625,7 +14583,7 @@ fn cmpSelf( |
| 14625 | // For bools, we still check the other operand, because we can lower | 14583 | // For bools, we still check the other operand, because we can lower |
| 14626 | // bool eq/neq more efficiently. | 14584 | // bool eq/neq more efficiently. |
| 14627 | if (resolved_type.zigTypeTag() == .Bool) { | 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 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 14587 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 14630 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src); | 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,7 +14668,6 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14710 | | 14668 | |
| 14711 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14669 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14712 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 14670 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 14713 | const src = inst_data.src(); | | |
| 14714 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 14671 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 14715 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); | 14672 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 14716 | switch (operand_ty.zigTypeTag()) { | 14673 | switch (operand_ty.zigTypeTag()) { |
| ... | @@ -14746,7 +14703,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -14746,7 +14703,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 14746 | => {}, | 14703 | => {}, |
| 14747 | } | 14704 | } |
| 14748 | const target = sema.mod.getTarget(); | 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 | return sema.addIntUnsigned(Type.comptime_int, bit_size); | 14707 | return sema.addIntUnsigned(Type.comptime_int, bit_size); |
| 14751 | } | 14708 | } |
| 14752 | | 14709 | |
| ... | @@ -14767,14 +14724,13 @@ fn zirClosureCapture( | ... | @@ -14767,14 +14724,13 @@ fn zirClosureCapture( |
| 14767 | ) CompileError!void { | 14724 | ) CompileError!void { |
| 14768 | // TODO: Compile error when closed over values are modified | 14725 | // TODO: Compile error when closed over values are modified |
| 14769 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 14726 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 14770 | const src = inst_data.src(); | | |
| 14771 | // Closures are not necessarily constant values. For example, the | 14727 | // Closures are not necessarily constant values. For example, the |
| 14772 | // code might do something like this: | 14728 | // code might do something like this: |
| 14773 | // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; } | 14729 | // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; } |
| 14774 | // ...in which case the closure_capture instruction has access to a runtime | 14730 | // ...in which case the closure_capture instruction has access to a runtime |
| 14775 | // value only. In such case we preserve the type and use a dummy runtime value. | 14731 | // value only. In such case we preserve the type and use a dummy runtime value. |
| 14776 | const operand = try sema.resolveInst(inst_data.operand); | 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 | Value.initTag(.unreachable_value); | 14734 | Value.initTag(.unreachable_value); |
| 14779 | | 14735 | |
| 14780 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, .{ | 14736 | try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, .{ |
| ... | @@ -14913,7 +14869,7 @@ fn zirBuiltinSrc( | ... | @@ -14913,7 +14869,7 @@ fn zirBuiltinSrc( |
| 14913 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); | 14869 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); |
| 14914 | | 14870 | |
| 14915 | const func_name_val = blk: { | 14871 | const func_name_val = blk: { |
| 14916 | var anon_decl = try block.startAnonDecl(src); | 14872 | var anon_decl = try block.startAnonDecl(); |
| 14917 | defer anon_decl.deinit(); | 14873 | defer anon_decl.deinit(); |
| 14918 | const name = std.mem.span(fn_owner_decl.name); | 14874 | const name = std.mem.span(fn_owner_decl.name); |
| 14919 | const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]); | 14875 | const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]); |
| ... | @@ -14926,7 +14882,7 @@ fn zirBuiltinSrc( | ... | @@ -14926,7 +14882,7 @@ fn zirBuiltinSrc( |
| 14926 | }; | 14882 | }; |
| 14927 | | 14883 | |
| 14928 | const file_name_val = blk: { | 14884 | const file_name_val = blk: { |
| 14929 | var anon_decl = try block.startAnonDecl(src); | 14885 | var anon_decl = try block.startAnonDecl(); |
| 14930 | defer anon_decl.deinit(); | 14886 | defer anon_decl.deinit(); |
| 14931 | const relative_path = try fn_owner_decl.getFileScope().fullPath(sema.arena); | 14887 | const relative_path = try fn_owner_decl.getFileScope().fullPath(sema.arena); |
| 14932 | const absolute_path = std.fs.realpathAlloc(sema.arena, relative_path) catch |err| { | 14888 | const absolute_path = std.fs.realpathAlloc(sema.arena, relative_path) catch |err| { |
| ... | @@ -14952,7 +14908,7 @@ fn zirBuiltinSrc( | ... | @@ -14952,7 +14908,7 @@ fn zirBuiltinSrc( |
| 14952 | field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1); | 14908 | field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1); |
| 14953 | | 14909 | |
| 14954 | return sema.addConstant( | 14910 | return sema.addConstant( |
| 14955 | try sema.getBuiltinType(block, src, "SourceLocation"), | 14911 | try sema.getBuiltinType("SourceLocation"), |
| 14956 | try Value.Tag.aggregate.create(sema.arena, field_values), | 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,7 +14917,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14961 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 14917 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 14962 | const src = inst_data.src(); | 14918 | const src = inst_data.src(); |
| 14963 | const ty = try sema.resolveType(block, src, inst_data.operand); | 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 | const target = sema.mod.getTarget(); | 14921 | const target = sema.mod.getTarget(); |
| 14966 | | 14922 | |
| 14967 | switch (ty.zigTypeTag()) { | 14923 | switch (ty.zigTypeTag()) { |
| ... | @@ -15032,7 +14988,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15032,7 +14988,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15032 | // TODO: look into memoizing this result. | 14988 | // TODO: look into memoizing this result. |
| 15033 | const info = ty.fnInfo(); | 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 | defer params_anon_decl.deinit(); | 14992 | defer params_anon_decl.deinit(); |
| 15037 | | 14993 | |
| 15038 | const param_vals = try params_anon_decl.arena().alloc(Value, info.param_types.len); | 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,7 +15143,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15187 | // is_allowzero: bool, | 15143 | // is_allowzero: bool, |
| 15188 | Value.makeBool(info.@"allowzero"), | 15144 | Value.makeBool(info.@"allowzero"), |
| 15189 | // sentinel: ?*const anyopaque, | 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 | return sema.addConstant( | 15149 | return sema.addConstant( |
| ... | @@ -15206,7 +15162,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15206,7 +15162,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15206 | // child: type, | 15162 | // child: type, |
| 15207 | field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type); | 15163 | field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type); |
| 15208 | // sentinel: ?*const anyopaque, | 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 | return sema.addConstant( | 15167 | return sema.addConstant( |
| 15212 | type_info_ty, | 15168 | type_info_ty, |
| ... | @@ -15246,7 +15202,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15246,7 +15202,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15246 | ); | 15202 | ); |
| 15247 | }, | 15203 | }, |
| 15248 | .ErrorSet => { | 15204 | .ErrorSet => { |
| 15249 | var fields_anon_decl = try block.startAnonDecl(src); | 15205 | var fields_anon_decl = try block.startAnonDecl(); |
| 15250 | defer fields_anon_decl.deinit(); | 15206 | defer fields_anon_decl.deinit(); |
| 15251 | | 15207 | |
| 15252 | // Get the Error type | 15208 | // Get the Error type |
| ... | @@ -15278,7 +15234,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15278,7 +15234,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15278 | for (vals) |*field_val, i| { | 15234 | for (vals) |*field_val, i| { |
| 15279 | const name = names[i]; | 15235 | const name = names[i]; |
| 15280 | const name_val = v: { | 15236 | const name_val = v: { |
| 15281 | var anon_decl = try block.startAnonDecl(src); | 15237 | var anon_decl = try block.startAnonDecl(); |
| 15282 | defer anon_decl.deinit(); | 15238 | defer anon_decl.deinit(); |
| 15283 | const bytes = try anon_decl.arena().dupeZ(u8, name); | 15239 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15284 | const new_decl = try anon_decl.finish( | 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,7 +15313,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15357 | | 15313 | |
| 15358 | const is_exhaustive = Value.makeBool(!ty.isNonexhaustiveEnum()); | 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 | defer fields_anon_decl.deinit(); | 15317 | defer fields_anon_decl.deinit(); |
| 15362 | | 15318 | |
| 15363 | const enum_field_ty = t: { | 15319 | const enum_field_ty = t: { |
| ... | @@ -15389,7 +15345,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15389,7 +15345,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15389 | | 15345 | |
| 15390 | const name = enum_fields.keys()[i]; | 15346 | const name = enum_fields.keys()[i]; |
| 15391 | const name_val = v: { | 15347 | const name_val = v: { |
| 15392 | var anon_decl = try block.startAnonDecl(src); | 15348 | var anon_decl = try block.startAnonDecl(); |
| 15393 | defer anon_decl.deinit(); | 15349 | defer anon_decl.deinit(); |
| 15394 | const bytes = try anon_decl.arena().dupeZ(u8, name); | 15350 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15395 | const new_decl = try anon_decl.finish( | 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,7 +15412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15456 | .Union => { | 15412 | .Union => { |
| 15457 | // TODO: look into memoizing this result. | 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 | defer fields_anon_decl.deinit(); | 15416 | defer fields_anon_decl.deinit(); |
| 15461 | | 15417 | |
| 15462 | const union_field_ty = t: { | 15418 | const union_field_ty = t: { |
| ... | @@ -15473,8 +15429,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15473,8 +15429,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15473 | break :t try union_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena()); | 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); | 15432 | const union_ty = try sema.resolveTypeFields(ty); |
| 15477 | try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout | 15433 | try sema.resolveTypeLayout(ty); // Getting alignment requires type layout |
| 15478 | const layout = union_ty.containerLayout(); | 15434 | const layout = union_ty.containerLayout(); |
| 15479 | | 15435 | |
| 15480 | const union_fields = union_ty.unionFields(); | 15436 | const union_fields = union_ty.unionFields(); |
| ... | @@ -15484,7 +15440,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15484,7 +15440,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15484 | const field = union_fields.values()[i]; | 15440 | const field = union_fields.values()[i]; |
| 15485 | const name = union_fields.keys()[i]; | 15441 | const name = union_fields.keys()[i]; |
| 15486 | const name_val = v: { | 15442 | const name_val = v: { |
| 15487 | var anon_decl = try block.startAnonDecl(src); | 15443 | var anon_decl = try block.startAnonDecl(); |
| 15488 | defer anon_decl.deinit(); | 15444 | defer anon_decl.deinit(); |
| 15489 | const bytes = try anon_decl.arena().dupeZ(u8, name); | 15445 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15490 | const new_decl = try anon_decl.finish( | 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,7 +15453,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15497 | | 15453 | |
| 15498 | const union_field_fields = try fields_anon_decl.arena().create([3]Value); | 15454 | const union_field_fields = try fields_anon_decl.arena().create([3]Value); |
| 15499 | const alignment = switch (layout) { | 15455 | const alignment = switch (layout) { |
| 15500 | .Auto, .Extern => try sema.unionFieldAlignment(block, src, field), | 15456 | .Auto, .Extern => try sema.unionFieldAlignment(field), |
| 15501 | .Packed => 0, | 15457 | .Packed => 0, |
| 15502 | }; | 15458 | }; |
| 15503 | | 15459 | |
| ... | @@ -15564,7 +15520,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15564,7 +15520,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15564 | .Struct => { | 15520 | .Struct => { |
| 15565 | // TODO: look into memoizing this result. | 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 | defer fields_anon_decl.deinit(); | 15524 | defer fields_anon_decl.deinit(); |
| 15569 | | 15525 | |
| 15570 | const struct_field_ty = t: { | 15526 | const struct_field_ty = t: { |
| ... | @@ -15580,8 +15536,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15580,8 +15536,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15580 | var buffer: Value.ToTypeBuffer = undefined; | 15536 | var buffer: Value.ToTypeBuffer = undefined; |
| 15581 | break :t try struct_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena()); | 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); | 15539 | const struct_ty = try sema.resolveTypeFields(ty); |
| 15584 | try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout | 15540 | try sema.resolveTypeLayout(ty); // Getting alignment requires type layout |
| 15585 | const layout = struct_ty.containerLayout(); | 15541 | const layout = struct_ty.containerLayout(); |
| 15586 | | 15542 | |
| 15587 | const struct_field_vals = fv: { | 15543 | const struct_field_vals = fv: { |
| ... | @@ -15592,7 +15548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15592,7 +15548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15592 | for (struct_field_vals) |*struct_field_val, i| { | 15548 | for (struct_field_vals) |*struct_field_val, i| { |
| 15593 | const field_ty = field_types[i]; | 15549 | const field_ty = field_types[i]; |
| 15594 | const name_val = v: { | 15550 | const name_val = v: { |
| 15595 | var anon_decl = try block.startAnonDecl(src); | 15551 | var anon_decl = try block.startAnonDecl(); |
| 15596 | defer anon_decl.deinit(); | 15552 | defer anon_decl.deinit(); |
| 15597 | const bytes = if (struct_ty.castTag(.anon_struct)) |payload| | 15553 | const bytes = if (struct_ty.castTag(.anon_struct)) |payload| |
| 15598 | try anon_decl.arena().dupeZ(u8, payload.data.names[i]) | 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,7 +15569,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15613 | const field_val = tuple.values[i]; | 15569 | const field_val = tuple.values[i]; |
| 15614 | const is_comptime = field_val.tag() != .unreachable_value; | 15570 | const is_comptime = field_val.tag() != .unreachable_value; |
| 15615 | const opt_default_val = if (is_comptime) field_val else null; | 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 | struct_field_fields.* = .{ | 15573 | struct_field_fields.* = .{ |
| 15618 | // name: []const u8, | 15574 | // name: []const u8, |
| 15619 | name_val, | 15575 | name_val, |
| ... | @@ -15637,7 +15593,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15637,7 +15593,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15637 | const field = struct_fields.values()[i]; | 15593 | const field = struct_fields.values()[i]; |
| 15638 | const name = struct_fields.keys()[i]; | 15594 | const name = struct_fields.keys()[i]; |
| 15639 | const name_val = v: { | 15595 | const name_val = v: { |
| 15640 | var anon_decl = try block.startAnonDecl(src); | 15596 | var anon_decl = try block.startAnonDecl(); |
| 15641 | defer anon_decl.deinit(); | 15597 | defer anon_decl.deinit(); |
| 15642 | const bytes = try anon_decl.arena().dupeZ(u8, name); | 15598 | const bytes = try anon_decl.arena().dupeZ(u8, name); |
| 15643 | const new_decl = try anon_decl.finish( | 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,7 +15612,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15656 | null | 15612 | null |
| 15657 | else | 15613 | else |
| 15658 | field.default_val; | 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 | const alignment = field.alignment(target, layout); | 15616 | const alignment = field.alignment(target, layout); |
| 15661 | | 15617 | |
| 15662 | struct_field_fields.* = .{ | 15618 | struct_field_fields.* = .{ |
| ... | @@ -15736,7 +15692,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15736,7 +15692,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15736 | .Opaque => { | 15692 | .Opaque => { |
| 15737 | // TODO: look into memoizing this result. | 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 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace()); | 15696 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace()); |
| 15741 | | 15697 | |
| 15742 | const field_values = try sema.arena.create([1]Value); | 15698 | const field_values = try sema.arena.create([1]Value); |
| ... | @@ -15766,7 +15722,7 @@ fn typeInfoDecls( | ... | @@ -15766,7 +15722,7 @@ fn typeInfoDecls( |
| 15766 | type_info_ty: Type, | 15722 | type_info_ty: Type, |
| 15767 | opt_namespace: ?*Module.Namespace, | 15723 | opt_namespace: ?*Module.Namespace, |
| 15768 | ) CompileError!Value { | 15724 | ) CompileError!Value { |
| 15769 | var decls_anon_decl = try block.startAnonDecl(src); | 15725 | var decls_anon_decl = try block.startAnonDecl(); |
| 15770 | defer decls_anon_decl.deinit(); | 15726 | defer decls_anon_decl.deinit(); |
| 15771 | | 15727 | |
| 15772 | const declaration_ty = t: { | 15728 | const declaration_ty = t: { |
| ... | @@ -15790,7 +15746,7 @@ fn typeInfoDecls( | ... | @@ -15790,7 +15746,7 @@ fn typeInfoDecls( |
| 15790 | const decl_index = opt_namespace.?.decls.keys()[i]; | 15746 | const decl_index = opt_namespace.?.decls.keys()[i]; |
| 15791 | const decl = sema.mod.declPtr(decl_index); | 15747 | const decl = sema.mod.declPtr(decl_index); |
| 15792 | const name_val = v: { | 15748 | const name_val = v: { |
| 15793 | var anon_decl = try block.startAnonDecl(src); | 15749 | var anon_decl = try block.startAnonDecl(); |
| 15794 | defer anon_decl.deinit(); | 15750 | defer anon_decl.deinit(); |
| 15795 | const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0)); | 15751 | const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0)); |
| 15796 | const new_decl = try anon_decl.finish( | 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,7 +15927,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 15971 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 15927 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 15972 | | 15928 | |
| 15973 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); | 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 | return if (val.isUndef()) | 15931 | return if (val.isUndef()) |
| 15976 | sema.addConstUndef(Type.bool) | 15932 | sema.addConstUndef(Type.bool) |
| 15977 | else if (val.toBool()) | 15933 | else if (val.toBool()) |
| ... | @@ -16044,7 +16000,7 @@ fn zirBoolBr( | ... | @@ -16044,7 +16000,7 @@ fn zirBoolBr( |
| 16044 | _ = try rhs_block.addBr(block_inst, rhs_result); | 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 | if (!sema.typeOf(rhs_result).isNoReturn()) { | 16004 | if (!sema.typeOf(rhs_result).isNoReturn()) { |
| 16049 | if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { | 16005 | if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { |
| 16050 | if (is_bool_or and rhs_val.toBool()) { | 16006 | if (is_bool_or and rhs_val.toBool()) { |
| ... | @@ -16119,7 +16075,7 @@ fn zirIsNonNullPtr( | ... | @@ -16119,7 +16075,7 @@ fn zirIsNonNullPtr( |
| 16119 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 16075 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16120 | const src = inst_data.src(); | 16076 | const src = inst_data.src(); |
| 16121 | const ptr = try sema.resolveInst(inst_data.operand); | 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 | return block.addUnOp(.is_non_null_ptr, ptr); | 16079 | return block.addUnOp(.is_non_null_ptr, ptr); |
| 16124 | } | 16080 | } |
| 16125 | const loaded = try sema.analyzeLoad(block, src, ptr, src); | 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,7 +16405,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 16449 | | 16405 | |
| 16450 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { | 16406 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 16451 | const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr); | 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 | _ = try block.addUnOp(.ret_load, ret_ptr); | 16411 | _ = try block.addUnOp(.ret_load, ret_ptr); |
| ... | @@ -16473,11 +16429,11 @@ fn retWithErrTracing( | ... | @@ -16473,11 +16429,11 @@ fn retWithErrTracing( |
| 16473 | else => true, | 16429 | else => true, |
| 16474 | }; | 16430 | }; |
| 16475 | const gpa = sema.gpa; | 16431 | const gpa = sema.gpa; |
| 16476 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); | 16432 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 16477 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 16433 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 16478 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); | 16434 | const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 16479 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 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 | const args: [1]Air.Inst.Ref = .{err_return_trace}; | 16437 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 16482 | | 16438 | |
| 16483 | if (!need_check) { | 16439 | if (!need_check) { |
| ... | @@ -16635,13 +16591,13 @@ fn analyzeRet( | ... | @@ -16635,13 +16591,13 @@ fn analyzeRet( |
| 16635 | return always_noreturn; | 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 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { | 16596 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 16641 | // Avoid adding a frame to the error return trace in case the value is comptime-known | 16597 | // Avoid adding a frame to the error return trace in case the value is comptime-known |
| 16642 | // to be not an error. | 16598 | // to be not an error. |
| 16643 | const is_non_err = try sema.analyzeIsNonErr(block, src, operand); | 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 | _ = try block.addUnOp(.ret, operand); | 16603 | _ = try block.addUnOp(.ret, operand); |
| ... | @@ -16720,7 +16676,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -16720,7 +16676,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16720 | break :blk 0; | 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 | try sema.validateAlign(block, align_src, abi_align); | 16680 | try sema.validateAlign(block, align_src, abi_align); |
| 16725 | break :blk abi_align; | 16681 | break :blk abi_align; |
| 16726 | } else 0; | 16682 | } else 0; |
| ... | @@ -16752,8 +16708,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -16752,8 +16708,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16752 | const elem_ty = if (abi_align == 0) | 16708 | const elem_ty = if (abi_align == 0) |
| 16753 | unresolved_elem_ty | 16709 | unresolved_elem_ty |
| 16754 | else t: { | 16710 | else t: { |
| 16755 | const elem_ty = try sema.resolveTypeFields(block, elem_ty_src, unresolved_elem_ty); | 16711 | const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty); |
| 16756 | try sema.resolveTypeLayout(block, elem_ty_src, elem_ty); | 16712 | try sema.resolveTypeLayout(elem_ty); |
| 16757 | break :t elem_ty; | 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,7 +16728,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16772 | } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) { | 16728 | } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) { |
| 16773 | return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{}); | 16729 | return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{}); |
| 16774 | } else if (inst_data.size == .C) { | 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 | const msg = msg: { | 16732 | const msg = msg: { |
| 16777 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); | 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 | errdefer msg.destroy(sema.gpa); | 16734 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -16831,7 +16787,7 @@ fn structInitEmpty( | ... | @@ -16831,7 +16787,7 @@ fn structInitEmpty( |
| 16831 | ) CompileError!Air.Inst.Ref { | 16787 | ) CompileError!Air.Inst.Ref { |
| 16832 | const gpa = sema.gpa; | 16788 | const gpa = sema.gpa; |
| 16833 | // This logic must be synchronized with that in `zirStructInit`. | 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 | // The init values to use for the struct instance. | 16792 | // The init values to use for the struct instance. |
| 16837 | const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount()); | 16793 | const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount()); |
| ... | @@ -16884,7 +16840,7 @@ fn unionInit( | ... | @@ -16884,7 +16840,7 @@ fn unionInit( |
| 16884 | const field = union_ty.unionFields().values()[field_index]; | 16840 | const field = union_ty.unionFields().values()[field_index]; |
| 16885 | const init = try sema.coerce(block, field.ty, uncasted_init, init_src); | 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 | const tag_ty = union_ty.unionTagTypeHypothetical(); | 16844 | const tag_ty = union_ty.unionTagTypeHypothetical(); |
| 16889 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name).?); | 16845 | const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name).?); |
| 16890 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 16846 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| ... | @@ -16916,7 +16872,7 @@ fn zirStructInit( | ... | @@ -16916,7 +16872,7 @@ fn zirStructInit( |
| 16916 | const first_field_type_data = zir_datas[first_item.field_type].pl_node; | 16872 | const first_field_type_data = zir_datas[first_item.field_type].pl_node; |
| 16917 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; | 16873 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; |
| 16918 | const resolved_ty = try sema.resolveType(block, src, first_field_type_extra.container_type); | 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 | if (resolved_ty.zigTypeTag() == .Struct) { | 16877 | if (resolved_ty.zigTypeTag() == .Struct) { |
| 16922 | // This logic must be synchronized with that in `zirStructInitEmpty`. | 16878 | // This logic must be synchronized with that in `zirStructInitEmpty`. |
| ... | @@ -16962,7 +16918,7 @@ fn zirStructInit( | ... | @@ -16962,7 +16918,7 @@ fn zirStructInit( |
| 16962 | found_fields[field_index] = item.data.field_type; | 16918 | found_fields[field_index] = item.data.field_type; |
| 16963 | field_inits[field_index] = try sema.resolveInst(item.data.init); | 16919 | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| 16964 | if (!is_packed) if (resolved_ty.structFieldValueComptime(field_index)) |default_value| { | 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 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 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,10 +16946,9 @@ fn zirStructInit( |
| 16990 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); | 16946 | const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index); |
| 16991 | | 16947 | |
| 16992 | const init_inst = try sema.resolveInst(item.data.init); | 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 | return sema.addConstantMaybeRef( | 16950 | return sema.addConstantMaybeRef( |
| 16995 | block, | 16951 | block, |
| 16996 | src, | | |
| 16997 | resolved_ty, | 16952 | resolved_ty, |
| 16998 | try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }), | 16953 | try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }), |
| 16999 | is_ref, | 16954 | is_ref, |
| ... | @@ -17107,7 +17062,7 @@ fn finishStructInit( | ... | @@ -17107,7 +17062,7 @@ fn finishStructInit( |
| 17107 | } | 17062 | } |
| 17108 | | 17063 | |
| 17109 | const is_comptime = for (field_inits) |field_init| { | 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 | break false; | 17066 | break false; |
| 17112 | } | 17067 | } |
| 17113 | } else true; | 17068 | } else true; |
| ... | @@ -17115,14 +17070,14 @@ fn finishStructInit( | ... | @@ -17115,14 +17070,14 @@ fn finishStructInit( |
| 17115 | if (is_comptime) { | 17070 | if (is_comptime) { |
| 17116 | const values = try sema.arena.alloc(Value, field_inits.len); | 17071 | const values = try sema.arena.alloc(Value, field_inits.len); |
| 17117 | for (field_inits) |field_init, i| { | 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 | const struct_val = try Value.Tag.aggregate.create(sema.arena, values); | 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 | if (is_ref) { | 17079 | if (is_ref) { |
| 17125 | try sema.resolveStructLayout(block, dest_src, struct_ty); | 17080 | try sema.resolveStructLayout(struct_ty); |
| 17126 | const target = sema.mod.getTarget(); | 17081 | const target = sema.mod.getTarget(); |
| 17127 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 17082 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 17128 | .pointee_type = struct_ty, | 17083 | .pointee_type = struct_ty, |
| ... | @@ -17197,8 +17152,7 @@ fn zirStructInitAnon( | ... | @@ -17197,8 +17152,7 @@ fn zirStructInitAnon( |
| 17197 | }; | 17152 | }; |
| 17198 | return sema.failWithOwnedErrorMsg(msg); | 17153 | return sema.failWithOwnedErrorMsg(msg); |
| 17199 | } | 17154 | } |
| 17200 | const init_src = src; // TODO better source location | 17155 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 17201 | if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| { | | |
| 17202 | values[i] = init_val; | 17156 | values[i] = init_val; |
| 17203 | } else { | 17157 | } else { |
| 17204 | values[i] = Value.initTag(.unreachable_value); | 17158 | values[i] = Value.initTag(.unreachable_value); |
| ... | @@ -17216,7 +17170,7 @@ fn zirStructInitAnon( | ... | @@ -17216,7 +17170,7 @@ fn zirStructInitAnon( |
| 17216 | | 17170 | |
| 17217 | const runtime_index = opt_runtime_index orelse { | 17171 | const runtime_index = opt_runtime_index orelse { |
| 17218 | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); | 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 | sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) { | 17176 | sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) { |
| ... | @@ -17303,7 +17257,7 @@ fn zirArrayInit( | ... | @@ -17303,7 +17257,7 @@ fn zirArrayInit( |
| 17303 | | 17257 | |
| 17304 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { | 17258 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { |
| 17305 | const arg_src = src; // TODO better source location | 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 | if (!comptime_known) break arg_src; | 17261 | if (!comptime_known) break arg_src; |
| 17308 | } else null; | 17262 | } else null; |
| 17309 | | 17263 | |
| ... | @@ -17312,11 +17266,11 @@ fn zirArrayInit( | ... | @@ -17312,11 +17266,11 @@ fn zirArrayInit( |
| 17312 | | 17266 | |
| 17313 | for (resolved_args) |arg, i| { | 17267 | for (resolved_args) |arg, i| { |
| 17314 | // We checked that all args are comptime above. | 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 | const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals); | 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 | try sema.requireRuntimeBlock(block, src, runtime_src); | 17276 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -17395,7 +17349,7 @@ fn zirArrayInitAnon( | ... | @@ -17395,7 +17349,7 @@ fn zirArrayInitAnon( |
| 17395 | }; | 17349 | }; |
| 17396 | return sema.failWithOwnedErrorMsg(msg); | 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 | values[i] = val; | 17353 | values[i] = val; |
| 17400 | } else { | 17354 | } else { |
| 17401 | values[i] = Value.initTag(.unreachable_value); | 17355 | values[i] = Value.initTag(.unreachable_value); |
| ... | @@ -17412,7 +17366,7 @@ fn zirArrayInitAnon( | ... | @@ -17412,7 +17366,7 @@ fn zirArrayInitAnon( |
| 17412 | | 17366 | |
| 17413 | const runtime_src = opt_runtime_src orelse { | 17367 | const runtime_src = opt_runtime_src orelse { |
| 17414 | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); | 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 | try sema.requireRuntimeBlock(block, src, runtime_src); | 17372 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | @@ -17451,14 +17405,13 @@ fn zirArrayInitAnon( | ... | @@ -17451,14 +17405,13 @@ fn zirArrayInitAnon( |
| 17451 | fn addConstantMaybeRef( | 17405 | fn addConstantMaybeRef( |
| 17452 | sema: *Sema, | 17406 | sema: *Sema, |
| 17453 | block: *Block, | 17407 | block: *Block, |
| 17454 | src: LazySrcLoc, | | |
| 17455 | ty: Type, | 17408 | ty: Type, |
| 17456 | val: Value, | 17409 | val: Value, |
| 17457 | is_ref: bool, | 17410 | is_ref: bool, |
| 17458 | ) !Air.Inst.Ref { | 17411 | ) !Air.Inst.Ref { |
| 17459 | if (!is_ref) return sema.addConstant(ty, val); | 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 | defer anon_decl.deinit(); | 17415 | defer anon_decl.deinit(); |
| 17463 | const decl = try anon_decl.finish( | 17416 | const decl = try anon_decl.finish( |
| 17464 | try ty.copy(anon_decl.arena()), | 17417 | try ty.copy(anon_decl.arena()), |
| ... | @@ -17499,7 +17452,7 @@ fn fieldType( | ... | @@ -17499,7 +17452,7 @@ fn fieldType( |
| 17499 | ) CompileError!Air.Inst.Ref { | 17452 | ) CompileError!Air.Inst.Ref { |
| 17500 | var cur_ty = aggregate_ty; | 17453 | var cur_ty = aggregate_ty; |
| 17501 | while (true) { | 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 | cur_ty = resolved_ty; | 17456 | cur_ty = resolved_ty; |
| 17504 | switch (cur_ty.zigTypeTag()) { | 17457 | switch (cur_ty.zigTypeTag()) { |
| 17505 | .Struct => { | 17458 | .Struct => { |
| ... | @@ -17538,18 +17491,13 @@ fn fieldType( | ... | @@ -17538,18 +17491,13 @@ fn fieldType( |
| 17538 | } | 17491 | } |
| 17539 | } | 17492 | } |
| 17540 | | 17493 | |
| 17541 | fn zirErrorReturnTrace( | 17494 | fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 17542 | sema: *Sema, | 17495 | return sema.getErrorReturnTrace(block); |
| 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); | | |
| 17548 | } | 17496 | } |
| 17549 | | 17497 | |
| 17550 | fn getErrorReturnTrace(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!Air.Inst.Ref { | 17498 | fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 17551 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); | 17499 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 17552 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 17500 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 17553 | const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); | 17501 | const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 17554 | | 17502 | |
| 17555 | // TODO implement this feature in all the backends and then delete this check. | 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,9 +17540,8 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17592 | | 17540 | |
| 17593 | fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17541 | fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17594 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 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 | const operand = try sema.resolveInst(inst_data.operand); | 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 | if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1)); | 17545 | if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1)); |
| 17599 | const bool_ints = [2]Air.Inst.Ref{ .zero, .one }; | 17546 | const bool_ints = [2]Air.Inst.Ref{ .zero, .one }; |
| 17600 | return bool_ints[@boolToInt(val.toBool())]; | 17547 | return bool_ints[@boolToInt(val.toBool())]; |
| ... | @@ -17650,7 +17597,7 @@ fn zirUnaryMath( | ... | @@ -17650,7 +17597,7 @@ fn zirUnaryMath( |
| 17650 | const scalar_ty = operand_ty.scalarType(); | 17597 | const scalar_ty = operand_ty.scalarType(); |
| 17651 | const vec_len = operand_ty.vectorLen(); | 17598 | const vec_len = operand_ty.vectorLen(); |
| 17652 | const result_ty = try Type.vector(sema.arena, vec_len, scalar_ty); | 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 | if (val.isUndef()) | 17601 | if (val.isUndef()) |
| 17655 | return sema.addConstUndef(result_ty); | 17602 | return sema.addConstUndef(result_ty); |
| 17656 | | 17603 | |
| ... | @@ -17670,7 +17617,7 @@ fn zirUnaryMath( | ... | @@ -17670,7 +17617,7 @@ fn zirUnaryMath( |
| 17670 | return block.addUnOp(air_tag, operand); | 17617 | return block.addUnOp(air_tag, operand); |
| 17671 | }, | 17618 | }, |
| 17672 | .ComptimeFloat, .Float => { | 17619 | .ComptimeFloat, .Float => { |
| 17673 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| { | 17620 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 17674 | if (operand_val.isUndef()) | 17621 | if (operand_val.isUndef()) |
| 17675 | return sema.addConstUndef(operand_ty); | 17622 | return sema.addConstUndef(operand_ty); |
| 17676 | const result_val = try eval(operand_val, operand_ty, sema.arena, target); | 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,7 +17639,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17692 | const operand_ty = sema.typeOf(operand); | 17639 | const operand_ty = sema.typeOf(operand); |
| 17693 | const mod = sema.mod; | 17640 | const mod = sema.mod; |
| 17694 | | 17641 | |
| 17695 | try sema.resolveTypeLayout(block, operand_src, operand_ty); | 17642 | try sema.resolveTypeLayout(operand_ty); |
| 17696 | const enum_ty = switch (operand_ty.zigTypeTag()) { | 17643 | const enum_ty = switch (operand_ty.zigTypeTag()) { |
| 17697 | .EnumLiteral => { | 17644 | .EnumLiteral => { |
| 17698 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); | 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,7 +17696,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17749 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); | 17696 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); |
| 17750 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 17697 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 17751 | const src = LazySrcLoc.nodeOffset(extra.node); | 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 | const uncasted_operand = try sema.resolveInst(extra.operand); | 17700 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 17754 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 17701 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 17755 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 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,18 +17774,18 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17827 | const is_allowzero_val = struct_val[6]; | 17774 | const is_allowzero_val = struct_val[6]; |
| 17828 | const sentinel_val = struct_val[7]; | 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 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 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 | var buffer: Value.ToTypeBuffer = undefined; | 17782 | var buffer: Value.ToTypeBuffer = undefined; |
| 17836 | const unresolved_elem_ty = child_val.toType(&buffer); | 17783 | const unresolved_elem_ty = child_val.toType(&buffer); |
| 17837 | const elem_ty = if (abi_align == 0) | 17784 | const elem_ty = if (abi_align == 0) |
| 17838 | unresolved_elem_ty | 17785 | unresolved_elem_ty |
| 17839 | else t: { | 17786 | else t: { |
| 17840 | const elem_ty = try sema.resolveTypeFields(block, src, unresolved_elem_ty); | 17787 | const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty); |
| 17841 | try sema.resolveTypeLayout(block, src, elem_ty); | 17788 | try sema.resolveTypeLayout(elem_ty); |
| 17842 | break :t elem_ty; | 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,7 +17819,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 17872 | } else if (ptr_size == .Many and elem_ty.zigTypeTag() == .Opaque) { | 17819 | } else if (ptr_size == .Many and elem_ty.zigTypeTag() == .Opaque) { |
| 17873 | return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{}); | 17820 | return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{}); |
| 17874 | } else if (ptr_size == .C) { | 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 | const msg = msg: { | 17823 | const msg = msg: { |
| 17877 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); | 17824 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); |
| 17878 | errdefer msg.destroy(sema.gpa); | 17825 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -18119,7 +18066,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in | ... | @@ -18119,7 +18066,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18119 | sema.mod, | 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 | // TODO: better source location | 18070 | // TODO: better source location |
| 18124 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ | 18071 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ |
| 18125 | field_name, | 18072 | field_name, |
| ... | @@ -18309,7 +18256,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in | ... | @@ -18309,7 +18256,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18309 | var buffer: Value.ToTypeBuffer = undefined; | 18256 | var buffer: Value.ToTypeBuffer = undefined; |
| 18310 | gop.value_ptr.* = .{ | 18257 | gop.value_ptr.* = .{ |
| 18311 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), | 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,7 +18306,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18359 | } | 18306 | } |
| 18360 | | 18307 | |
| 18361 | const alignment = alignment: { | 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 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 18310 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| 18364 | } | 18311 | } |
| 18365 | const alignment = @intCast(u29, alignment_val.toUnsignedInt(target)); | 18312 | const alignment = @intCast(u29, alignment_val.toUnsignedInt(target)); |
| ... | @@ -18571,10 +18518,10 @@ fn reifyStruct( | ... | @@ -18571,10 +18518,10 @@ fn reifyStruct( |
| 18571 | // alignment: comptime_int, | 18518 | // alignment: comptime_int, |
| 18572 | const alignment_val = field_struct_val[4]; | 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 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 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 | if (layout == .Packed and abi_align != 0) { | 18526 | if (layout == .Packed and abi_align != 0) { |
| 18580 | return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{}); | 18527 | return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{}); |
| ... | @@ -18614,7 +18561,7 @@ fn reifyStruct( | ... | @@ -18614,7 +18561,7 @@ fn reifyStruct( |
| 18614 | struct_obj.status = .layout_wip; | 18561 | struct_obj.status = .layout_wip; |
| 18615 | | 18562 | |
| 18616 | for (struct_obj.fields.values()) |field, index| { | 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 | error.AnalysisFail => { | 18565 | error.AnalysisFail => { |
| 18619 | const msg = sema.err orelse return err; | 18566 | const msg = sema.err orelse return err; |
| 18620 | try sema.addFieldErrNote(struct_ty, index, msg, "while checking this field", .{}); | 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,7 +18644,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18697 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 18644 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 18698 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); | 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 | defer anon_decl.deinit(); | 18648 | defer anon_decl.deinit(); |
| 18702 | | 18649 | |
| 18703 | const bytes = try ty.nameAllocArena(anon_decl.arena(), sema.mod); | 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,7 +18682,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18735 | _ = try sema.checkIntType(block, ty_src, dest_ty); | 18682 | _ = try sema.checkIntType(block, ty_src, dest_ty); |
| 18736 | try sema.checkFloatType(block, operand_src, operand_ty); | 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 | const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty); | 18686 | const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty); |
| 18740 | return sema.addConstant(dest_ty, result_val); | 18687 | return sema.addConstant(dest_ty, result_val); |
| 18741 | } else if (dest_ty.zigTypeTag() == .ComptimeInt) { | 18688 | } else if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| ... | @@ -18774,9 +18721,9 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -18774,9 +18721,9 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18774 | try sema.checkFloatType(block, ty_src, dest_ty); | 18721 | try sema.checkFloatType(block, ty_src, dest_ty); |
| 18775 | _ = try sema.checkIntType(block, operand_src, operand_ty); | 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 | const target = sema.mod.getTarget(); | 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 | return sema.addConstant(dest_ty, result_val); | 18727 | return sema.addConstant(dest_ty, result_val); |
| 18781 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { | 18728 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| 18782 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); | 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,7 +18748,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18801 | const elem_ty = ptr_ty.elemType2(); | 18748 | const elem_ty = ptr_ty.elemType2(); |
| 18802 | try sema.checkPtrType(block, type_src, ptr_ty); | 18749 | try sema.checkPtrType(block, type_src, ptr_ty); |
| 18803 | const target = sema.mod.getTarget(); | 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 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { | 18753 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 18807 | const addr = val.toUnsignedInt(target); | 18754 | const addr = val.toUnsignedInt(target); |
| ... | @@ -18819,7 +18766,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18819,7 +18766,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18819 | } | 18766 | } |
| 18820 | | 18767 | |
| 18821 | try sema.requireRuntimeBlock(block, src, operand_src); | 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 | if (!ptr_ty.isAllowzeroPtr()) { | 18770 | if (!ptr_ty.isAllowzeroPtr()) { |
| 18824 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); | 18771 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); |
| 18825 | try sema.addSafetyCheck(block, is_non_zero, .cast_to_null); | 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,11 +18908,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18961 | operand; | 18908 | operand; |
| 18962 | | 18909 | |
| 18963 | const dest_elem_ty = dest_ty.elemType2(); | 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 | const dest_align = dest_ty.ptrAlignment(target); | 18912 | const dest_align = dest_ty.ptrAlignment(target); |
| 18966 | | 18913 | |
| 18967 | const operand_elem_ty = operand_ty.elemType2(); | 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 | const operand_align = operand_ty.ptrAlignment(target); | 18916 | const operand_align = operand_ty.ptrAlignment(target); |
| 18970 | | 18917 | |
| 18971 | // If the destination is less aligned than the source, preserve the source alignment | 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,7 +18956,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19009 | return sema.failWithOwnedErrorMsg(msg); | 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 | if (!dest_ty.ptrAllowsZero() and operand_val.isUndef()) { | 18960 | if (!dest_ty.ptrAllowsZero() and operand_val.isUndef()) { |
| 19014 | return sema.failWithUseOfUndef(block, operand_src); | 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,7 +18971,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19024 | | 18971 | |
| 19025 | try sema.requireRuntimeBlock(block, src, null); | 18972 | try sema.requireRuntimeBlock(block, src, null); |
| 19026 | if (block.wantSafety() and operand_ty.ptrAllowsZero() and !dest_ty.ptrAllowsZero() and | 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 | const ptr_int = try block.addUnOp(.ptrtoint, ptr); | 18976 | const ptr_int = try block.addUnOp(.ptrtoint, ptr); |
| 19030 | const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); | 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,13 +19010,13 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19063 | const target = sema.mod.getTarget(); | 19010 | const target = sema.mod.getTarget(); |
| 19064 | const dest_info = dest_scalar_ty.intInfo(target); | 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 | return sema.addConstant(dest_ty, val); | 19014 | return sema.addConstant(dest_ty, val); |
| 19068 | } | 19015 | } |
| 19069 | | 19016 | |
| 19070 | if (operand_scalar_ty.zigTypeTag() != .ComptimeInt) { | 19017 | if (operand_scalar_ty.zigTypeTag() != .ComptimeInt) { |
| 19071 | const operand_info = operand_ty.intInfo(target); | 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 | return sema.addConstant(operand_ty, val); | 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,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 | if (val.isUndef()) return sema.addConstUndef(dest_ty); | 19050 | if (val.isUndef()) return sema.addConstUndef(dest_ty); |
| 19104 | if (!is_vector) { | 19051 | if (!is_vector) { |
| 19105 | return sema.addConstant( | 19052 | return sema.addConstant( |
| ... | @@ -19152,7 +19099,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -19152,7 +19099,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 19152 | | 19099 | |
| 19153 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); | 19100 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| 19154 | if (block.wantSafety() and dest_align > 1 and | 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 | const val_payload = try sema.arena.create(Value.Payload.U64); | 19104 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 19158 | val_payload.* = .{ | 19105 | val_payload.* = .{ |
| ... | @@ -19192,11 +19139,11 @@ fn zirBitCount( | ... | @@ -19192,11 +19139,11 @@ fn zirBitCount( |
| 19192 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 19139 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19193 | const operand = try sema.resolveInst(inst_data.operand); | 19140 | const operand = try sema.resolveInst(inst_data.operand); |
| 19194 | const operand_ty = sema.typeOf(operand); | 19141 | const operand_ty = sema.typeOf(operand); |
| 19195 | _ = try checkIntOrVector(sema, block, operand, operand_src); | 19142 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| 19196 | const target = sema.mod.getTarget(); | 19143 | const target = sema.mod.getTarget(); |
| 19197 | const bits = operand_ty.intInfo(target).bits; | 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 | return sema.addConstant(operand_ty, val); | 19147 | return sema.addConstant(operand_ty, val); |
| 19201 | } | 19148 | } |
| 19202 | | 19149 | |
| ... | @@ -19205,7 +19152,7 @@ fn zirBitCount( | ... | @@ -19205,7 +19152,7 @@ fn zirBitCount( |
| 19205 | .Vector => { | 19152 | .Vector => { |
| 19206 | const vec_len = operand_ty.vectorLen(); | 19153 | const vec_len = operand_ty.vectorLen(); |
| 19207 | const result_ty = try Type.vector(sema.arena, vec_len, result_scalar_ty); | 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 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 19156 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 19210 | | 19157 | |
| 19211 | var elem_buf: Value.ElemValueBuffer = undefined; | 19158 | var elem_buf: Value.ElemValueBuffer = undefined; |
| ... | @@ -19226,7 +19173,7 @@ fn zirBitCount( | ... | @@ -19226,7 +19173,7 @@ fn zirBitCount( |
| 19226 | } | 19173 | } |
| 19227 | }, | 19174 | }, |
| 19228 | .Int => { | 19175 | .Int => { |
| 19229 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 19176 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 19230 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); | 19177 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); |
| 19231 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target)); | 19178 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target)); |
| 19232 | } else { | 19179 | } else { |
| ... | @@ -19256,13 +19203,13 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -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 | return sema.addConstant(operand_ty, val); | 19207 | return sema.addConstant(operand_ty, val); |
| 19261 | } | 19208 | } |
| 19262 | | 19209 | |
| 19263 | switch (operand_ty.zigTypeTag()) { | 19210 | switch (operand_ty.zigTypeTag()) { |
| 19264 | .Int => { | 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 | if (val.isUndef()) return sema.addConstUndef(operand_ty); | 19213 | if (val.isUndef()) return sema.addConstUndef(operand_ty); |
| 19267 | const result_val = try val.byteSwap(operand_ty, target, sema.arena); | 19214 | const result_val = try val.byteSwap(operand_ty, target, sema.arena); |
| 19268 | return sema.addConstant(operand_ty, result_val); | 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,7 +19219,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19272 | return block.addTyOp(.byte_swap, operand_ty, operand); | 19219 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| 19273 | }, | 19220 | }, |
| 19274 | .Vector => { | 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 | if (val.isUndef()) | 19223 | if (val.isUndef()) |
| 19277 | return sema.addConstUndef(operand_ty); | 19224 | return sema.addConstUndef(operand_ty); |
| 19278 | | 19225 | |
| ... | @@ -19304,14 +19251,14 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19304,14 +19251,14 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19304 | const operand_ty = sema.typeOf(operand); | 19251 | const operand_ty = sema.typeOf(operand); |
| 19305 | _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); | 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 | return sema.addConstant(operand_ty, val); | 19255 | return sema.addConstant(operand_ty, val); |
| 19309 | } | 19256 | } |
| 19310 | | 19257 | |
| 19311 | const target = sema.mod.getTarget(); | 19258 | const target = sema.mod.getTarget(); |
| 19312 | switch (operand_ty.zigTypeTag()) { | 19259 | switch (operand_ty.zigTypeTag()) { |
| 19313 | .Int, .ComptimeInt => { | 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 | if (val.isUndef()) return sema.addConstUndef(operand_ty); | 19262 | if (val.isUndef()) return sema.addConstUndef(operand_ty); |
| 19316 | const result_val = try val.bitReverse(operand_ty, target, sema.arena); | 19263 | const result_val = try val.bitReverse(operand_ty, target, sema.arena); |
| 19317 | return sema.addConstant(operand_ty, result_val); | 19264 | return sema.addConstant(operand_ty, result_val); |
| ... | @@ -19321,7 +19268,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19321,7 +19268,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19321 | return block.addTyOp(.bit_reverse, operand_ty, operand); | 19268 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| 19322 | }, | 19269 | }, |
| 19323 | .Vector => { | 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 | if (val.isUndef()) | 19272 | if (val.isUndef()) |
| 19326 | return sema.addConstUndef(operand_ty); | 19273 | return sema.addConstUndef(operand_ty); |
| 19327 | | 19274 | |
| ... | @@ -19346,12 +19293,12 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19346,12 +19293,12 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19346 | } | 19293 | } |
| 19347 | | 19294 | |
| 19348 | fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | return sema.addIntUnsigned(Type.comptime_int, offset); | 19297 | return sema.addIntUnsigned(Type.comptime_int, offset); |
| 19351 | } | 19298 | } |
| 19352 | | 19299 | |
| 19353 | fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | // TODO reminder to make this a compile error for packed structs | 19302 | // TODO reminder to make this a compile error for packed structs |
| 19356 | return sema.addIntUnsigned(Type.comptime_int, offset / 8); | 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,7 +19315,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 19368 | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime-known"); | 19315 | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime-known"); |
| 19369 | const target = sema.mod.getTarget(); | 19316 | const target = sema.mod.getTarget(); |
| 19370 | | 19317 | |
| 19371 | try sema.resolveTypeLayout(block, lhs_src, ty); | 19318 | try sema.resolveTypeLayout(ty); |
| 19372 | switch (ty.zigTypeTag()) { | 19319 | switch (ty.zigTypeTag()) { |
| 19373 | .Struct => {}, | 19320 | .Struct => {}, |
| 19374 | else => { | 19321 | else => { |
| ... | @@ -19758,8 +19705,8 @@ fn checkSimdBinOp( | ... | @@ -19758,8 +19705,8 @@ fn checkSimdBinOp( |
| 19758 | .len = vec_len, | 19705 | .len = vec_len, |
| 19759 | .lhs = lhs, | 19706 | .lhs = lhs, |
| 19760 | .rhs = rhs, | 19707 | .rhs = rhs, |
| 19761 | .lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs), | 19708 | .lhs_val = try sema.resolveMaybeUndefVal(lhs), |
| 19762 | .rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs), | 19709 | .rhs_val = try sema.resolveMaybeUndefVal(rhs), |
| 19763 | .result_ty = result_ty, | 19710 | .result_ty = result_ty, |
| 19764 | .scalar_ty = result_ty.scalarType(), | 19711 | .scalar_ty = result_ty.scalarType(), |
| 19765 | }; | 19712 | }; |
| ... | @@ -19830,7 +19777,7 @@ fn resolveExportOptions( | ... | @@ -19830,7 +19777,7 @@ fn resolveExportOptions( |
| 19830 | src: LazySrcLoc, | 19777 | src: LazySrcLoc, |
| 19831 | zir_ref: Zir.Inst.Ref, | 19778 | zir_ref: Zir.Inst.Ref, |
| 19832 | ) CompileError!std.builtin.ExportOptions { | 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 | const air_ref = try sema.resolveInst(zir_ref); | 19781 | const air_ref = try sema.resolveInst(zir_ref); |
| 19835 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 19782 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 19836 | | 19783 | |
| ... | @@ -19885,7 +19832,7 @@ fn resolveBuiltinEnum( | ... | @@ -19885,7 +19832,7 @@ fn resolveBuiltinEnum( |
| 19885 | comptime name: []const u8, | 19832 | comptime name: []const u8, |
| 19886 | reason: []const u8, | 19833 | reason: []const u8, |
| 19887 | ) CompileError!@field(std.builtin, name) { | 19834 | ) CompileError!@field(std.builtin, name) { |
| 19888 | const ty = try sema.getBuiltinType(block, src, name); | 19835 | const ty = try sema.getBuiltinType(name); |
| 19889 | const air_ref = try sema.resolveInst(zir_ref); | 19836 | const air_ref = try sema.resolveInst(zir_ref); |
| 19890 | const coerced = try sema.coerce(block, ty, air_ref, src); | 19837 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 19891 | const val = try sema.resolveConstValue(block, src, coerced, reason); | 19838 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| ... | @@ -19899,7 +19846,7 @@ fn resolveAtomicOrder( | ... | @@ -19899,7 +19846,7 @@ fn resolveAtomicOrder( |
| 19899 | zir_ref: Zir.Inst.Ref, | 19846 | zir_ref: Zir.Inst.Ref, |
| 19900 | reason: []const u8, | 19847 | reason: []const u8, |
| 19901 | ) CompileError!std.builtin.AtomicOrder { | 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 | fn resolveAtomicRmwOp( | 19852 | fn resolveAtomicRmwOp( |
| ... | @@ -19908,7 +19855,7 @@ fn resolveAtomicRmwOp( | ... | @@ -19908,7 +19855,7 @@ fn resolveAtomicRmwOp( |
| 19908 | src: LazySrcLoc, | 19855 | src: LazySrcLoc, |
| 19909 | zir_ref: Zir.Inst.Ref, | 19856 | zir_ref: Zir.Inst.Ref, |
| 19910 | ) CompileError!std.builtin.AtomicRmwOp { | 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 | fn zirCmpxchg( | 19861 | fn zirCmpxchg( |
| ... | @@ -19963,13 +19910,13 @@ fn zirCmpxchg( | ... | @@ -19963,13 +19910,13 @@ fn zirCmpxchg( |
| 19963 | const result_ty = try Type.optional(sema.arena, elem_ty); | 19910 | const result_ty = try Type.optional(sema.arena, elem_ty); |
| 19964 | | 19911 | |
| 19965 | // special case zero bit types | 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 | return sema.addConstant(result_ty, Value.@"null"); | 19914 | return sema.addConstant(result_ty, Value.@"null"); |
| 19968 | } | 19915 | } |
| 19969 | | 19916 | |
| 19970 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 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| { | 19918 | if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| { |
| 19972 | if (try sema.resolveMaybeUndefVal(block, new_value_src, new_value)) |new_val| { | 19919 | if (try sema.resolveMaybeUndefVal(new_value)) |new_val| { |
| 19973 | if (expected_val.isUndef() or new_val.isUndef()) { | 19920 | if (expected_val.isUndef() or new_val.isUndef()) { |
| 19974 | // TODO: this should probably cause the memory stored at the pointer | 19921 | // TODO: this should probably cause the memory stored at the pointer |
| 19975 | // to become undef as well | 19922 | // to become undef as well |
| ... | @@ -20018,7 +19965,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -20018,7 +19965,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 20018 | .len = len, | 19965 | .len = len, |
| 20019 | .elem_type = scalar_ty, | 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 | if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty); | 19969 | if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty); |
| 20023 | | 19970 | |
| 20024 | return sema.addConstant( | 19971 | return sema.addConstant( |
| ... | @@ -20070,7 +20017,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -20070,7 +20017,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20070 | return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{}); | 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 | if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty); | 20021 | if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty); |
| 20075 | | 20022 | |
| 20076 | var accum: Value = try operand_val.elemValue(sema.mod, sema.arena, 0); | 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,7 +20031,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20084 | .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target), | 20031 | .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target), |
| 20085 | .Min => accum = accum.numberMin(elem_val, target), | 20032 | .Min => accum = accum.numberMin(elem_val, target), |
| 20086 | .Max => accum = accum.numberMax(elem_val, target), | 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 | .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target), | 20035 | .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target), |
| 20089 | } | 20036 | } |
| 20090 | } | 20037 | } |
| ... | @@ -20222,8 +20169,8 @@ fn analyzeShuffle( | ... | @@ -20222,8 +20169,8 @@ fn analyzeShuffle( |
| 20222 | } | 20169 | } |
| 20223 | } | 20170 | } |
| 20224 | | 20171 | |
| 20225 | if (try sema.resolveMaybeUndefVal(block, a_src, a)) |a_val| { | 20172 | if (try sema.resolveMaybeUndefVal(a)) |a_val| { |
| 20226 | if (try sema.resolveMaybeUndefVal(block, b_src, b)) |b_val| { | 20173 | if (try sema.resolveMaybeUndefVal(b)) |b_val| { |
| 20227 | const values = try sema.arena.alloc(Value, mask_len); | 20174 | const values = try sema.arena.alloc(Value, mask_len); |
| 20228 | | 20175 | |
| 20229 | i = 0; | 20176 | i = 0; |
| ... | @@ -20319,9 +20266,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -20319,9 +20266,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 20319 | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); | 20266 | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); |
| 20320 | const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src); | 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); | 20269 | const maybe_pred = try sema.resolveMaybeUndefVal(pred); |
| 20323 | const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a); | 20270 | const maybe_a = try sema.resolveMaybeUndefVal(a); |
| 20324 | const maybe_b = try sema.resolveMaybeUndefVal(block, b_src, b); | 20271 | const maybe_b = try sema.resolveMaybeUndefVal(b); |
| 20325 | | 20272 | |
| 20326 | const runtime_src = if (maybe_pred) |pred_val| rs: { | 20273 | const runtime_src = if (maybe_pred) |pred_val| rs: { |
| 20327 | if (pred_val.isUndef()) return sema.addConstUndef(vec_ty); | 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,7 +20352,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20405 | else => {}, | 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 | return sema.addConstant(elem_ty, val); | 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,12 +20409,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20462 | } | 20409 | } |
| 20463 | | 20410 | |
| 20464 | // special case zero bit types | 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 | return sema.addConstant(elem_ty, val); | 20413 | return sema.addConstant(elem_ty, val); |
| 20467 | } | 20414 | } |
| 20468 | | 20415 | |
| 20469 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 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 | const operand_val = maybe_operand_val orelse { | 20418 | const operand_val = maybe_operand_val orelse { |
| 20472 | try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); | 20419 | try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); |
| 20473 | break :rs operand_src; | 20420 | break :rs operand_src; |
| ... | @@ -20479,8 +20426,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -20479,8 +20426,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20479 | const new_val = switch (op) { | 20426 | const new_val = switch (op) { |
| 20480 | // zig fmt: off | 20427 | // zig fmt: off |
| 20481 | .Xchg => operand_val, | 20428 | .Xchg => operand_val, |
| 20482 | .Add => try sema.numberAddWrap(block, src, stored_val, operand_val, elem_ty), | 20429 | .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty), |
| 20483 | .Sub => try sema.numberSubWrap(block, src, stored_val, operand_val, elem_ty), | 20430 | .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty), |
| 20484 | .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target), | 20431 | .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target), |
| 20485 | .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target), | 20432 | .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target), |
| 20486 | .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target), | 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,9 +20506,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 20559 | | 20506 | |
| 20560 | const target = sema.mod.getTarget(); | 20507 | const target = sema.mod.getTarget(); |
| 20561 | | 20508 | |
| 20562 | const maybe_mulend1 = try sema.resolveMaybeUndefVal(block, mulend1_src, mulend1); | 20509 | const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1); |
| 20563 | const maybe_mulend2 = try sema.resolveMaybeUndefVal(block, mulend2_src, mulend2); | 20510 | const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2); |
| 20564 | const maybe_addend = try sema.resolveMaybeUndefVal(block, addend_src, addend); | 20511 | const maybe_addend = try sema.resolveMaybeUndefVal(addend); |
| 20565 | | 20512 | |
| 20566 | switch (ty.zigTypeTag()) { | 20513 | switch (ty.zigTypeTag()) { |
| 20567 | .ComptimeFloat, .Float, .Vector => {}, | 20514 | .ComptimeFloat, .Float, .Vector => {}, |
| ... | @@ -20618,7 +20565,7 @@ fn resolveCallOptions( | ... | @@ -20618,7 +20565,7 @@ fn resolveCallOptions( |
| 20618 | func: Air.Inst.Ref, | 20565 | func: Air.Inst.Ref, |
| 20619 | func_src: LazySrcLoc, | 20566 | func_src: LazySrcLoc, |
| 20620 | ) CompileError!std.builtin.CallOptions.Modifier { | 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 | const air_ref = try sema.resolveInst(zir_ref); | 20569 | const air_ref = try sema.resolveInst(zir_ref); |
| 20623 | const options = try sema.coerce(block, call_options_ty, air_ref, src); | 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,7 +20714,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 20767 | if (struct_ty.zigTypeTag() != .Struct) { | 20714 | if (struct_ty.zigTypeTag() != .Struct) { |
| 20768 | return sema.fail(block, ty_src, "expected struct type, found '{}'", .{struct_ty.fmt(sema.mod)}); | 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 | const field_index = if (struct_ty.isTuple()) blk: { | 20719 | const field_index = if (struct_ty.isTuple()) blk: { |
| 20773 | if (mem.eql(u8, field_name, "len")) { | 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,7 +20928,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 20981 | const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: { | 20928 | const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: { |
| 20982 | if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src; | 20929 | if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src; |
| 20983 | if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| { | 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 | _ = len_val; | 20932 | _ = len_val; |
| 20986 | _ = val; | 20933 | _ = val; |
| 20987 | return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{}); | 20934 | return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{}); |
| ... | @@ -21076,7 +21023,7 @@ fn zirVarExtended( | ... | @@ -21076,7 +21023,7 @@ fn zirVarExtended( |
| 21076 | else | 21023 | else |
| 21077 | uncasted_init; | 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 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known"); | 21027 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known"); |
| 21081 | } else Value.initTag(.unreachable_value); | 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,7 +21128,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21181 | const body = sema.code.extra[extra_index..][0..body_len]; | 21128 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 21182 | extra_index += body.len; | 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 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known"); | 21132 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known"); |
| 21186 | if (val.tag() == .generic_poison) { | 21133 | if (val.tag() == .generic_poison) { |
| 21187 | break :blk null; | 21134 | break :blk null; |
| ... | @@ -21229,7 +21176,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -21229,7 +21176,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21229 | const body = sema.code.extra[extra_index..][0..body_len]; | 21176 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 21230 | extra_index += body.len; | 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 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known"); | 21180 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known"); |
| 21234 | if (val.tag() == .generic_poison) { | 21181 | if (val.tag() == .generic_poison) { |
| 21235 | break :blk null; | 21182 | break :blk null; |
| ... | @@ -21411,7 +21358,7 @@ fn resolvePrefetchOptions( | ... | @@ -21411,7 +21358,7 @@ fn resolvePrefetchOptions( |
| 21411 | src: LazySrcLoc, | 21358 | src: LazySrcLoc, |
| 21412 | zir_ref: Zir.Inst.Ref, | 21359 | zir_ref: Zir.Inst.Ref, |
| 21413 | ) CompileError!std.builtin.PrefetchOptions { | 21360 | ) CompileError!std.builtin.PrefetchOptions { |
| 21414 | const options_ty = try sema.getBuiltinType(block, src, "PrefetchOptions"); | 21361 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 21415 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); | 21362 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 21416 | const target = sema.mod.getTarget(); | 21363 | const target = sema.mod.getTarget(); |
| 21417 | | 21364 | |
| ... | @@ -21476,7 +21423,7 @@ fn resolveExternOptions( | ... | @@ -21476,7 +21423,7 @@ fn resolveExternOptions( |
| 21476 | zir_ref: Zir.Inst.Ref, | 21423 | zir_ref: Zir.Inst.Ref, |
| 21477 | ) CompileError!std.builtin.ExternOptions { | 21424 | ) CompileError!std.builtin.ExternOptions { |
| 21478 | const options_inst = try sema.resolveInst(zir_ref); | 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 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); | 21427 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 21481 | const mod = sema.mod; | 21428 | const mod = sema.mod; |
| 21482 | | 21429 | |
| ... | @@ -21619,7 +21566,7 @@ fn validateVarType( | ... | @@ -21619,7 +21566,7 @@ fn validateVarType( |
| 21619 | var_ty: Type, | 21566 | var_ty: Type, |
| 21620 | is_extern: bool, | 21567 | is_extern: bool, |
| 21621 | ) CompileError!void { | 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 | const mod = sema.mod; | 21571 | const mod = sema.mod; |
| 21625 | | 21572 | |
| ... | @@ -21640,8 +21587,6 @@ fn validateVarType( | ... | @@ -21640,8 +21587,6 @@ fn validateVarType( |
| 21640 | | 21587 | |
| 21641 | fn validateRunTimeType( | 21588 | fn validateRunTimeType( |
| 21642 | sema: *Sema, | 21589 | sema: *Sema, |
| 21643 | block: *Block, | | |
| 21644 | src: LazySrcLoc, | | |
| 21645 | var_ty: Type, | 21590 | var_ty: Type, |
| 21646 | is_extern: bool, | 21591 | is_extern: bool, |
| 21647 | ) CompileError!bool { | 21592 | ) CompileError!bool { |
| ... | @@ -21682,14 +21627,14 @@ fn validateRunTimeType( | ... | @@ -21682,14 +21627,14 @@ fn validateRunTimeType( |
| 21682 | .Optional => { | 21627 | .Optional => { |
| 21683 | var buf: Type.Payload.ElemType = undefined; | 21628 | var buf: Type.Payload.ElemType = undefined; |
| 21684 | const child_ty = ty.optionalChild(&buf); | 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 | .Array, .Vector => ty = ty.elemType(), | 21632 | .Array, .Vector => ty = ty.elemType(), |
| 21688 | | 21633 | |
| 21689 | .ErrorUnion => ty = ty.errorUnionPayload(), | 21634 | .ErrorUnion => ty = ty.errorUnionPayload(), |
| 21690 | | 21635 | |
| 21691 | .Struct, .Union => { | 21636 | .Struct, .Union => { |
| 21692 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 21637 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 21693 | const needs_comptime = try sema.typeRequiresComptime(resolved_ty); | 21638 | const needs_comptime = try sema.typeRequiresComptime(resolved_ty); |
| 21694 | return !needs_comptime; | 21639 | return !needs_comptime; |
| 21695 | }, | 21640 | }, |
| ... | @@ -21709,7 +21654,7 @@ fn explainWhyTypeIsComptime( | ... | @@ -21709,7 +21654,7 @@ fn explainWhyTypeIsComptime( |
| 21709 | var type_set = TypeSet{}; | 21654 | var type_set = TypeSet{}; |
| 21710 | defer type_set.deinit(sema.gpa); | 21655 | defer type_set.deinit(sema.gpa); |
| 21711 | | 21656 | |
| 21712 | try sema.resolveTypeFully(block, src, ty); | 21657 | try sema.resolveTypeFully(ty); |
| 21713 | return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set); | 21658 | return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set); |
| 21714 | } | 21659 | } |
| 21715 | | 21660 | |
| ... | @@ -21842,8 +21787,6 @@ const ExternPosition = enum { | ... | @@ -21842,8 +21787,6 @@ const ExternPosition = enum { |
| 21842 | /// Calls `resolveTypeLayout` for packed containers. | 21787 | /// Calls `resolveTypeLayout` for packed containers. |
| 21843 | fn validateExternType( | 21788 | fn validateExternType( |
| 21844 | sema: *Sema, | 21789 | sema: *Sema, |
| 21845 | block: *Block, | | |
| 21846 | src: LazySrcLoc, | | |
| 21847 | ty: Type, | 21790 | ty: Type, |
| 21848 | position: ExternPosition, | 21791 | position: ExternPosition, |
| 21849 | ) !bool { | 21792 | ) !bool { |
| ... | @@ -21882,13 +21825,13 @@ fn validateExternType( | ... | @@ -21882,13 +21825,13 @@ fn validateExternType( |
| 21882 | }, | 21825 | }, |
| 21883 | .Enum => { | 21826 | .Enum => { |
| 21884 | var buf: Type.Payload.Bits = undefined; | 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 | .Struct, .Union => switch (ty.containerLayout()) { | 21830 | .Struct, .Union => switch (ty.containerLayout()) { |
| 21888 | .Extern => return true, | 21831 | .Extern => return true, |
| 21889 | .Packed => { | 21832 | .Packed => { |
| 21890 | const target = sema.mod.getTarget(); | 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 | switch (bit_size) { | 21835 | switch (bit_size) { |
| 21893 | 8, 16, 32, 64, 128 => return true, | 21836 | 8, 16, 32, 64, 128 => return true, |
| 21894 | else => return false, | 21837 | else => return false, |
| ... | @@ -21898,9 +21841,9 @@ fn validateExternType( | ... | @@ -21898,9 +21841,9 @@ fn validateExternType( |
| 21898 | }, | 21841 | }, |
| 21899 | .Array => { | 21842 | .Array => { |
| 21900 | if (position == .ret_ty or position == .param_ty) return false; | 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 | .Optional => return ty.isPtrLikeOptional(), | 21847 | .Optional => return ty.isPtrLikeOptional(), |
| 21905 | } | 21848 | } |
| 21906 | } | 21849 | } |
| ... | @@ -22173,9 +22116,9 @@ fn panicWithMsg( | ... | @@ -22173,9 +22116,9 @@ fn panicWithMsg( |
| 22173 | _ = try block.addNoOp(.unreach); | 22116 | _ = try block.addNoOp(.unreach); |
| 22174 | return always_noreturn; | 22117 | return always_noreturn; |
| 22175 | } | 22118 | } |
| 22176 | const panic_fn = try sema.getBuiltin(block, src, "panic"); | 22119 | const panic_fn = try sema.getBuiltin("panic"); |
| 22177 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); | 22120 | const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace"); |
| 22178 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 22121 | const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty); |
| 22179 | const target = mod.getTarget(); | 22122 | const target = mod.getTarget(); |
| 22180 | const ptr_stack_trace_ty = try Type.ptr(arena, mod, .{ | 22123 | const ptr_stack_trace_ty = try Type.ptr(arena, mod, .{ |
| 22181 | .pointee_type = stack_trace_ty, | 22124 | .pointee_type = stack_trace_ty, |
| ... | @@ -22224,9 +22167,9 @@ fn panicUnwrapError( | ... | @@ -22224,9 +22167,9 @@ fn panicUnwrapError( |
| 22224 | _ = try fail_block.addNoOp(.breakpoint); | 22167 | _ = try fail_block.addNoOp(.breakpoint); |
| 22225 | _ = try fail_block.addNoOp(.unreach); | 22168 | _ = try fail_block.addNoOp(.unreach); |
| 22226 | } else { | 22169 | } else { |
| 22227 | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicUnwrapError"); | 22170 | const panic_fn = try sema.getBuiltin("panicUnwrapError"); |
| 22228 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); | 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 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; | 22173 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| 22231 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); | 22174 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22232 | } | 22175 | } |
| ... | @@ -22268,7 +22211,7 @@ fn panicIndexOutOfBounds( | ... | @@ -22268,7 +22211,7 @@ fn panicIndexOutOfBounds( |
| 22268 | _ = try fail_block.addNoOp(.breakpoint); | 22211 | _ = try fail_block.addNoOp(.breakpoint); |
| 22269 | _ = try fail_block.addNoOp(.unreach); | 22212 | _ = try fail_block.addNoOp(.unreach); |
| 22270 | } else { | 22213 | } else { |
| 22271 | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicOutOfBounds"); | 22214 | const panic_fn = try sema.getBuiltin("panicOutOfBounds"); |
| 22272 | const args: [2]Air.Inst.Ref = .{ index, len }; | 22215 | const args: [2]Air.Inst.Ref = .{ index, len }; |
| 22273 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); | 22216 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22274 | } | 22217 | } |
| ... | @@ -22311,7 +22254,7 @@ fn panicSentinelMismatch( | ... | @@ -22311,7 +22254,7 @@ fn panicSentinelMismatch( |
| 22311 | } else if (sentinel_ty.isSelfComparable(true)) | 22254 | } else if (sentinel_ty.isSelfComparable(true)) |
| 22312 | try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel) | 22255 | try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel) |
| 22313 | else { | 22256 | else { |
| 22314 | const panic_fn = try sema.getBuiltin(parent_block, src, "checkNonScalarSentinel"); | 22257 | const panic_fn = try sema.getBuiltin("checkNonScalarSentinel"); |
| 22315 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; | 22258 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 22316 | _ = try sema.analyzeCall(parent_block, panic_fn, src, src, .auto, false, &args, null); | 22259 | _ = try sema.analyzeCall(parent_block, panic_fn, src, src, .auto, false, &args, null); |
| 22317 | return; | 22260 | return; |
| ... | @@ -22340,7 +22283,7 @@ fn panicSentinelMismatch( | ... | @@ -22340,7 +22283,7 @@ fn panicSentinelMismatch( |
| 22340 | _ = try fail_block.addNoOp(.breakpoint); | 22283 | _ = try fail_block.addNoOp(.breakpoint); |
| 22341 | _ = try fail_block.addNoOp(.unreach); | 22284 | _ = try fail_block.addNoOp(.unreach); |
| 22342 | } else { | 22285 | } else { |
| 22343 | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicSentinelMismatch"); | 22286 | const panic_fn = try sema.getBuiltin("panicSentinelMismatch"); |
| 22344 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; | 22287 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 22345 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); | 22288 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 22346 | } | 22289 | } |
| ... | @@ -22377,7 +22320,7 @@ fn safetyPanic( | ... | @@ -22377,7 +22320,7 @@ fn safetyPanic( |
| 22377 | const msg_inst = msg_inst: { | 22320 | const msg_inst = msg_inst: { |
| 22378 | // TODO instead of making a new decl for every panic in the entire compilation, | 22321 | // TODO instead of making a new decl for every panic in the entire compilation, |
| 22379 | // introduce the concept of a reference-counted decl for these | 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 | defer anon_decl.deinit(); | 22324 | defer anon_decl.deinit(); |
| 22382 | break :msg_inst try sema.analyzeDeclRef(try anon_decl.finish( | 22325 | break :msg_inst try sema.analyzeDeclRef(try anon_decl.finish( |
| 22383 | try Type.Tag.array_u8.create(anon_decl.arena(), msg.len), | 22326 | try Type.Tag.array_u8.create(anon_decl.arena(), msg.len), |
| ... | @@ -22526,7 +22469,7 @@ fn fieldVal( | ... | @@ -22526,7 +22469,7 @@ fn fieldVal( |
| 22526 | ); | 22469 | ); |
| 22527 | }, | 22470 | }, |
| 22528 | .Union => { | 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 | if (union_ty.getNamespace()) |namespace| { | 22474 | if (union_ty.getNamespace()) |namespace| { |
| 22532 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { | 22475 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| ... | @@ -22627,7 +22570,7 @@ fn fieldPtr( | ... | @@ -22627,7 +22570,7 @@ fn fieldPtr( |
| 22627 | switch (inner_ty.zigTypeTag()) { | 22570 | switch (inner_ty.zigTypeTag()) { |
| 22628 | .Array => { | 22571 | .Array => { |
| 22629 | if (mem.eql(u8, field_name, "len")) { | 22572 | if (mem.eql(u8, field_name, "len")) { |
| 22630 | var anon_decl = try block.startAnonDecl(src); | 22573 | var anon_decl = try block.startAnonDecl(); |
| 22631 | defer anon_decl.deinit(); | 22574 | defer anon_decl.deinit(); |
| 22632 | return sema.analyzeDeclRef(try anon_decl.finish( | 22575 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22633 | Type.usize, | 22576 | Type.usize, |
| ... | @@ -22729,7 +22672,7 @@ fn fieldPtr( | ... | @@ -22729,7 +22672,7 @@ fn fieldPtr( |
| 22729 | }); | 22672 | }); |
| 22730 | } else (try sema.mod.getErrorValue(field_name)).key; | 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 | defer anon_decl.deinit(); | 22676 | defer anon_decl.deinit(); |
| 22734 | return sema.analyzeDeclRef(try anon_decl.finish( | 22677 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22735 | if (!child_type.isAnyError()) | 22678 | if (!child_type.isAnyError()) |
| ... | @@ -22749,7 +22692,7 @@ fn fieldPtr( | ... | @@ -22749,7 +22692,7 @@ fn fieldPtr( |
| 22749 | if (child_type.unionTagType()) |enum_ty| { | 22692 | if (child_type.unionTagType()) |enum_ty| { |
| 22750 | if (enum_ty.enumFieldIndex(field_name)) |field_index| { | 22693 | if (enum_ty.enumFieldIndex(field_name)) |field_index| { |
| 22751 | const field_index_u32 = @intCast(u32, field_index); | 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 | defer anon_decl.deinit(); | 22696 | defer anon_decl.deinit(); |
| 22754 | return sema.analyzeDeclRef(try anon_decl.finish( | 22697 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22755 | try enum_ty.copy(anon_decl.arena()), | 22698 | try enum_ty.copy(anon_decl.arena()), |
| ... | @@ -22770,7 +22713,7 @@ fn fieldPtr( | ... | @@ -22770,7 +22713,7 @@ fn fieldPtr( |
| 22770 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 22713 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 22771 | }; | 22714 | }; |
| 22772 | const field_index_u32 = @intCast(u32, field_index); | 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 | defer anon_decl.deinit(); | 22717 | defer anon_decl.deinit(); |
| 22775 | return sema.analyzeDeclRef(try anon_decl.finish( | 22718 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 22776 | try child_type.copy(anon_decl.arena()), | 22719 | try child_type.copy(anon_decl.arena()), |
| ... | @@ -22839,40 +22782,40 @@ fn fieldCallBind( | ... | @@ -22839,40 +22782,40 @@ fn fieldCallBind( |
| 22839 | find_field: { | 22782 | find_field: { |
| 22840 | switch (concrete_ty.zigTypeTag()) { | 22783 | switch (concrete_ty.zigTypeTag()) { |
| 22841 | .Struct => { | 22784 | .Struct => { |
| 22842 | const struct_ty = try sema.resolveTypeFields(block, src, concrete_ty); | 22785 | const struct_ty = try sema.resolveTypeFields(concrete_ty); |
| 22843 | if (struct_ty.castTag(.@"struct")) |struct_obj| { | 22786 | if (struct_ty.castTag(.@"struct")) |struct_obj| { |
| 22844 | const field_index_usize = struct_obj.data.fields.getIndex(field_name) orelse | 22787 | const field_index_usize = struct_obj.data.fields.getIndex(field_name) orelse |
| 22845 | break :find_field; | 22788 | break :find_field; |
| 22846 | const field_index = @intCast(u32, field_index_usize); | 22789 | const field_index = @intCast(u32, field_index_usize); |
| 22847 | const field = struct_obj.data.fields.values()[field_index]; | 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 | } else if (struct_ty.isTuple()) { | 22793 | } else if (struct_ty.isTuple()) { |
| 22851 | if (mem.eql(u8, field_name, "len")) { | 22794 | if (mem.eql(u8, field_name, "len")) { |
| 22852 | return sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount()); | 22795 | return sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount()); |
| 22853 | } | 22796 | } |
| 22854 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { | 22797 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 22855 | if (field_index >= struct_ty.structFieldCount()) break :find_field; | 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 | } else |_| {} | 22800 | } else |_| {} |
| 22858 | } else { | 22801 | } else { |
| 22859 | const max = struct_ty.structFieldCount(); | 22802 | const max = struct_ty.structFieldCount(); |
| 22860 | var i: u32 = 0; | 22803 | var i: u32 = 0; |
| 22861 | while (i < max) : (i += 1) { | 22804 | while (i < max) : (i += 1) { |
| 22862 | if (mem.eql(u8, struct_ty.structFieldName(i), field_name)) { | 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 | .Union => { | 22811 | .Union => { |
| 22869 | const union_ty = try sema.resolveTypeFields(block, src, concrete_ty); | 22812 | const union_ty = try sema.resolveTypeFields(concrete_ty); |
| 22870 | const fields = union_ty.unionFields(); | 22813 | const fields = union_ty.unionFields(); |
| 22871 | const field_index_usize = fields.getIndex(field_name) orelse break :find_field; | 22814 | const field_index_usize = fields.getIndex(field_name) orelse break :find_field; |
| 22872 | const field_index = @intCast(u32, field_index_usize); | 22815 | const field_index = @intCast(u32, field_index_usize); |
| 22873 | const field = fields.values()[field_index]; | 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 | .Type => { | 22820 | .Type => { |
| 22878 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); | 22821 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| ... | @@ -23058,8 +23001,8 @@ fn structFieldPtr( | ... | @@ -23058,8 +23001,8 @@ fn structFieldPtr( |
| 23058 | ) CompileError!Air.Inst.Ref { | 23001 | ) CompileError!Air.Inst.Ref { |
| 23059 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); | 23002 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); |
| 23060 | | 23003 | |
| 23061 | const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty); | 23004 | const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty); |
| 23062 | try sema.resolveStructLayout(block, src, struct_ty); | 23005 | try sema.resolveStructLayout(struct_ty); |
| 23063 | | 23006 | |
| 23064 | if (struct_ty.isTuple()) { | 23007 | if (struct_ty.isTuple()) { |
| 23065 | if (mem.eql(u8, field_name, "len")) { | 23008 | if (mem.eql(u8, field_name, "len")) { |
| ... | @@ -23115,7 +23058,7 @@ fn structFieldPtrByIndex( | ... | @@ -23115,7 +23058,7 @@ fn structFieldPtrByIndex( |
| 23115 | | 23058 | |
| 23116 | var running_bits: u16 = 0; | 23059 | var running_bits: u16 = 0; |
| 23117 | for (struct_obj.fields.values()) |f, i| { | 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 | if (i == field_index) { | 23063 | if (i == field_index) { |
| 23121 | ptr_ty_data.bit_offset = running_bits; | 23064 | ptr_ty_data.bit_offset = running_bits; |
| ... | @@ -23198,12 +23141,12 @@ fn structFieldVal( | ... | @@ -23198,12 +23141,12 @@ fn structFieldVal( |
| 23198 | ) CompileError!Air.Inst.Ref { | 23141 | ) CompileError!Air.Inst.Ref { |
| 23199 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); | 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 | switch (struct_ty.tag()) { | 23145 | switch (struct_ty.tag()) { |
| 23203 | .tuple, .empty_struct_literal => return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty), | 23146 | .tuple, .empty_struct_literal => return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty), |
| 23204 | .anon_struct => { | 23147 | .anon_struct => { |
| 23205 | const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src); | 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 | .@"struct" => { | 23151 | .@"struct" => { |
| 23209 | const struct_obj = struct_ty.castTag(.@"struct").?.data; | 23152 | const struct_obj = struct_ty.castTag(.@"struct").?.data; |
| ... | @@ -23217,9 +23160,9 @@ fn structFieldVal( | ... | @@ -23217,9 +23160,9 @@ fn structFieldVal( |
| 23217 | return sema.addConstant(field.ty, field.default_val); | 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 | if (struct_val.isUndef()) return sema.addConstUndef(field.ty); | 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 | return sema.addConstant(field.ty, opv); | 23166 | return sema.addConstant(field.ty, opv); |
| 23224 | } | 23167 | } |
| 23225 | | 23168 | |
| ... | @@ -23247,7 +23190,7 @@ fn tupleFieldVal( | ... | @@ -23247,7 +23190,7 @@ fn tupleFieldVal( |
| 23247 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount()); | 23190 | return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount()); |
| 23248 | } | 23191 | } |
| 23249 | const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src); | 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 | /// Asserts that `field_name` is not "len". | 23196 | /// Asserts that `field_name` is not "len". |
| ... | @@ -23286,9 +23229,9 @@ fn tupleFieldValByIndex( | ... | @@ -23286,9 +23229,9 @@ fn tupleFieldValByIndex( |
| 23286 | return sema.addConstant(field_ty, tuple.values[field_index]); | 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 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); | 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 | return sema.addConstant(field_ty, opv); | 23235 | return sema.addConstant(field_ty, opv); |
| 23293 | } | 23236 | } |
| 23294 | const field_values = tuple_val.castTag(.aggregate).?.data; | 23237 | const field_values = tuple_val.castTag(.aggregate).?.data; |
| ... | @@ -23317,7 +23260,7 @@ fn unionFieldPtr( | ... | @@ -23317,7 +23260,7 @@ fn unionFieldPtr( |
| 23317 | assert(unresolved_union_ty.zigTypeTag() == .Union); | 23260 | assert(unresolved_union_ty.zigTypeTag() == .Union); |
| 23318 | | 23261 | |
| 23319 | const union_ptr_ty = sema.typeOf(union_ptr); | 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 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 23264 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 23322 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); | 23265 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 23323 | const field = union_obj.fields.values()[field_index]; | 23266 | const field = union_obj.fields.values()[field_index]; |
| ... | @@ -23410,13 +23353,13 @@ fn unionFieldVal( | ... | @@ -23410,13 +23353,13 @@ fn unionFieldVal( |
| 23410 | ) CompileError!Air.Inst.Ref { | 23353 | ) CompileError!Air.Inst.Ref { |
| 23411 | assert(unresolved_union_ty.zigTypeTag() == .Union); | 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 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 23357 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 23415 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); | 23358 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 23416 | const field = union_obj.fields.values()[field_index]; | 23359 | const field = union_obj.fields.values()[field_index]; |
| 23417 | const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?); | 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 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); | 23363 | if (union_val.isUndef()) return sema.addConstUndef(field.ty); |
| 23421 | | 23364 | |
| 23422 | const tag_and_val = union_val.castTag(.@"union").?.data; | 23365 | const tag_and_val = union_val.castTag(.@"union").?.data; |
| ... | @@ -23586,7 +23529,7 @@ fn elemVal( | ... | @@ -23586,7 +23529,7 @@ fn elemVal( |
| 23586 | // Tuple field access. | 23529 | // Tuple field access. |
| 23587 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 23530 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); |
| 23588 | const index = @intCast(u32, index_val.toUnsignedInt(target)); | 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 | else => unreachable, | 23534 | else => unreachable, |
| 23592 | } | 23535 | } |
| ... | @@ -23600,7 +23543,7 @@ fn validateRuntimeElemAccess( | ... | @@ -23600,7 +23543,7 @@ fn validateRuntimeElemAccess( |
| 23600 | parent_ty: Type, | 23543 | parent_ty: Type, |
| 23601 | parent_src: LazySrcLoc, | 23544 | parent_src: LazySrcLoc, |
| 23602 | ) CompileError!void { | 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 | if (!valid_rt) { | 23547 | if (!valid_rt) { |
| 23605 | const msg = msg: { | 23548 | const msg = msg: { |
| 23606 | const msg = try sema.errMsg( | 23549 | const msg = try sema.errMsg( |
| ... | @@ -23659,7 +23602,7 @@ fn tupleFieldPtr( | ... | @@ -23659,7 +23602,7 @@ fn tupleFieldPtr( |
| 23659 | return sema.addConstant(ptr_field_ty, val); | 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 | return sema.addConstant( | 23606 | return sema.addConstant( |
| 23664 | ptr_field_ty, | 23607 | ptr_field_ty, |
| 23665 | try Value.Tag.field_ptr.create(sema.arena, .{ | 23608 | try Value.Tag.field_ptr.create(sema.arena, .{ |
| ... | @@ -23706,7 +23649,7 @@ fn tupleField( | ... | @@ -23706,7 +23649,7 @@ fn tupleField( |
| 23706 | return sema.addConstant(field_ty, field_val); // comptime field | 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 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); | 23653 | if (tuple_val.isUndef()) return sema.addConstUndef(field_ty); |
| 23711 | return sema.addConstant(field_ty, tuple_val.fieldValue(tuple_ty, field_index)); | 23654 | return sema.addConstant(field_ty, tuple_val.fieldValue(tuple_ty, field_index)); |
| 23712 | } | 23655 | } |
| ... | @@ -23736,7 +23679,7 @@ fn elemValArray( | ... | @@ -23736,7 +23679,7 @@ fn elemValArray( |
| 23736 | return sema.fail(block, array_src, "indexing into empty array is not allowed", .{}); | 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 | // index must be defined since it can access out of bounds | 23683 | // index must be defined since it can access out of bounds |
| 23741 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 23684 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 23742 | const target = sema.mod.getTarget(); | 23685 | const target = sema.mod.getTarget(); |
| ... | @@ -23800,7 +23743,7 @@ fn elemPtrArray( | ... | @@ -23800,7 +23743,7 @@ fn elemPtrArray( |
| 23800 | return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{}); | 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 | // The index must not be undefined since it can be out of bounds. | 23747 | // The index must not be undefined since it can be out of bounds. |
| 23805 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { | 23748 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 23806 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); | 23749 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); |
| ... | @@ -23909,7 +23852,7 @@ fn elemPtrSlice( | ... | @@ -23909,7 +23852,7 @@ fn elemPtrSlice( |
| 23909 | const slice_ty = sema.typeOf(slice); | 23852 | const slice_ty = sema.typeOf(slice); |
| 23910 | const slice_sent = slice_ty.sentinel() != null; | 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 | // The index must not be undefined since it can be out of bounds. | 23856 | // The index must not be undefined since it can be out of bounds. |
| 23914 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { | 23857 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 23915 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); | 23858 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target)); |
| ... | @@ -23996,15 +23939,15 @@ fn coerceExtra( | ... | @@ -23996,15 +23939,15 @@ fn coerceExtra( |
| 23996 | else => {}, | 23939 | else => {}, |
| 23997 | } | 23940 | } |
| 23998 | const dest_ty_src = inst_src; // TODO better source location | 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); | 23942 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); |
| 24000 | const inst_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst)); | 23943 | const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst)); |
| 24001 | const target = sema.mod.getTarget(); | 23944 | const target = sema.mod.getTarget(); |
| 24002 | // If the types are the same, we can return the operand. | 23945 | // If the types are the same, we can return the operand. |
| 24003 | if (dest_ty.eql(inst_ty, sema.mod)) | 23946 | if (dest_ty.eql(inst_ty, sema.mod)) |
| 24004 | return inst; | 23947 | return inst; |
| 24005 | | 23948 | |
| 24006 | const arena = sema.arena; | 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 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); | 23952 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| 24010 | if (in_memory_result == .ok) { | 23953 | if (in_memory_result == .ok) { |
| ... | @@ -24354,7 +24297,7 @@ fn coerceExtra( | ... | @@ -24354,7 +24297,7 @@ fn coerceExtra( |
| 24354 | .Int, .ComptimeInt => { | 24297 | .Int, .ComptimeInt => { |
| 24355 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { | 24298 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { |
| 24356 | // comptime-known integer to other number | 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 | if (!opts.report_err) return error.NotCoercible; | 24301 | if (!opts.report_err) return error.NotCoercible; |
| 24359 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) }); | 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,7 +24364,7 @@ fn coerceExtra( |
| 24421 | } | 24364 | } |
| 24422 | break :int; | 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 | // TODO implement this compile error | 24368 | // TODO implement this compile error |
| 24426 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); | 24369 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 24427 | //if (!int_again_val.eql(val, inst_ty, mod)) { | 24370 | //if (!int_again_val.eql(val, inst_ty, mod)) { |
| ... | @@ -24559,7 +24502,7 @@ fn coerceExtra( | ... | @@ -24559,7 +24502,7 @@ fn coerceExtra( |
| 24559 | return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src); | 24502 | return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src); |
| 24560 | } | 24503 | } |
| 24561 | if (inst_ty.isTupleOrAnonStruct()) { | 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 | else => {}, | 24508 | else => {}, |
| ... | @@ -25031,8 +24974,8 @@ fn coerceInMemoryAllowed( | ... | @@ -25031,8 +24974,8 @@ fn coerceInMemoryAllowed( |
| 25031 | // Pointers / Pointer-like Optionals | 24974 | // Pointers / Pointer-like Optionals |
| 25032 | var dest_buf: Type.Payload.ElemType = undefined; | 24975 | var dest_buf: Type.Payload.ElemType = undefined; |
| 25033 | var src_buf: Type.Payload.ElemType = undefined; | 24976 | var src_buf: Type.Payload.ElemType = undefined; |
| 25034 | const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, dest_ty, &dest_buf, dest_src); | 24977 | const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(dest_ty, &dest_buf); |
| 25035 | const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, src_ty, &src_buf, src_src); | 24978 | const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(src_ty, &src_buf); |
| 25036 | if (maybe_dest_ptr_ty) |dest_ptr_ty| { | 24979 | if (maybe_dest_ptr_ty) |dest_ptr_ty| { |
| 25037 | if (maybe_src_ptr_ty) |src_ptr_ty| { | 24980 | if (maybe_src_ptr_ty) |src_ptr_ty| { |
| 25038 | return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ptr_ty, src_ptr_ty, dest_is_mut, target, dest_src, src_src); | 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,7 +25471,7 @@ fn coerceVarArgParam( |
| 25528 | }; | 25471 | }; |
| 25529 | | 25472 | |
| 25530 | const coerced_ty = sema.typeOf(coerced); | 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 | const msg = msg: { | 25475 | const msg = msg: { |
| 25533 | const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); | 25476 | const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); |
| 25534 | errdefer msg.destroy(sema.gpa); | 25477 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -25585,7 +25528,7 @@ fn storePtr2( | ... | @@ -25585,7 +25528,7 @@ fn storePtr2( |
| 25585 | for (tuple.types) |_, i_usize| { | 25528 | for (tuple.types) |_, i_usize| { |
| 25586 | const i = @intCast(u32, i_usize); | 25529 | const i = @intCast(u32, i_usize); |
| 25587 | const elem_src = operand_src; // TODO better source location | 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 | const elem_index = try sema.addIntUnsigned(Type.usize, i); | 25532 | const elem_index = try sema.addIntUnsigned(Type.usize, i); |
| 25590 | const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false); | 25533 | const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false); |
| 25591 | try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store); | 25534 | try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store); |
| ... | @@ -25618,7 +25561,7 @@ fn storePtr2( | ... | @@ -25618,7 +25561,7 @@ fn storePtr2( |
| 25618 | error.NotCoercible => unreachable, | 25561 | error.NotCoercible => unreachable, |
| 25619 | else => |e| return e, | 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 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 25566 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 25624 | const operand_val = maybe_operand_val orelse { | 25567 | const operand_val = maybe_operand_val orelse { |
| ... | @@ -25633,7 +25576,7 @@ fn storePtr2( | ... | @@ -25633,7 +25576,7 @@ fn storePtr2( |
| 25633 | | 25576 | |
| 25634 | // We do this after the possible comptime store above, for the case of field_ptr stores | 25577 | // We do this after the possible comptime store above, for the case of field_ptr stores |
| 25635 | // to unions because we want the comptime tag to be set, even if the field type is void. | 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 | return; | 25580 | return; |
| 25638 | | 25581 | |
| 25639 | if (air_tag == .bitcast) { | 25582 | if (air_tag == .bitcast) { |
| ... | @@ -25695,7 +25638,7 @@ fn storePtrVal( | ... | @@ -25695,7 +25638,7 @@ fn storePtrVal( |
| 25695 | operand_val: Value, | 25638 | operand_val: Value, |
| 25696 | operand_ty: Type, | 25639 | operand_ty: Type, |
| 25697 | ) !void { | 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 | try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut); | 25642 | try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut); |
| 25700 | | 25643 | |
| 25701 | switch (mut_kit.pointee) { | 25644 | switch (mut_kit.pointee) { |
| ... | @@ -25784,20 +25727,20 @@ fn beginComptimePtrMutation( | ... | @@ -25784,20 +25727,20 @@ fn beginComptimePtrMutation( |
| 25784 | .decl_ref_mut => { | 25727 | .decl_ref_mut => { |
| 25785 | const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data; | 25728 | const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data; |
| 25786 | const decl = sema.mod.declPtr(decl_ref_mut.decl_index); | 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 | .comptime_field_ptr => { | 25732 | .comptime_field_ptr => { |
| 25790 | const payload = ptr_val.castTag(.comptime_field_ptr).?.data; | 25733 | const payload = ptr_val.castTag(.comptime_field_ptr).?.data; |
| 25791 | const duped = try sema.arena.create(Value); | 25734 | const duped = try sema.arena.create(Value); |
| 25792 | duped.* = payload.field_val; | 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 | .decl_index = @intToEnum(Module.Decl.Index, 0), | 25737 | .decl_index = @intToEnum(Module.Decl.Index, 0), |
| 25795 | .runtime_index = .comptime_field_ptr, | 25738 | .runtime_index = .comptime_field_ptr, |
| 25796 | }); | 25739 | }); |
| 25797 | }, | 25740 | }, |
| 25798 | .elem_ptr => { | 25741 | .elem_ptr => { |
| 25799 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; | 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 | switch (parent.pointee) { | 25744 | switch (parent.pointee) { |
| 25802 | .direct => |val_ptr| switch (parent.ty.zigTypeTag()) { | 25745 | .direct => |val_ptr| switch (parent.ty.zigTypeTag()) { |
| 25803 | .Array, .Vector => { | 25746 | .Array, .Vector => { |
| ... | @@ -25987,7 +25930,7 @@ fn beginComptimePtrMutation( | ... | @@ -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 | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); | 25934 | const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64); |
| 25992 | return ComptimePtrMutationKit{ | 25935 | return ComptimePtrMutationKit{ |
| 25993 | .decl_ref_mut = parent.decl_ref_mut, | 25936 | .decl_ref_mut = parent.decl_ref_mut, |
| ... | @@ -26005,7 +25948,7 @@ fn beginComptimePtrMutation( | ... | @@ -26005,7 +25948,7 @@ fn beginComptimePtrMutation( |
| 26005 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; | 25948 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 26006 | const field_index = @intCast(u32, field_ptr.field_index); | 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 | switch (parent.pointee) { | 25952 | switch (parent.pointee) { |
| 26010 | .direct => |val_ptr| switch (val_ptr.tag()) { | 25953 | .direct => |val_ptr| switch (val_ptr.tag()) { |
| 26011 | .undef => { | 25954 | .undef => { |
| ... | @@ -26169,7 +26112,7 @@ fn beginComptimePtrMutation( | ... | @@ -26169,7 +26112,7 @@ fn beginComptimePtrMutation( |
| 26169 | }, | 26112 | }, |
| 26170 | .eu_payload_ptr => { | 26113 | .eu_payload_ptr => { |
| 26171 | const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data; | 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 | switch (parent.pointee) { | 26116 | switch (parent.pointee) { |
| 26174 | .direct => |val_ptr| { | 26117 | .direct => |val_ptr| { |
| 26175 | const payload_ty = parent.ty.errorUnionPayload(); | 26118 | const payload_ty = parent.ty.errorUnionPayload(); |
| ... | @@ -26216,7 +26159,7 @@ fn beginComptimePtrMutation( | ... | @@ -26216,7 +26159,7 @@ fn beginComptimePtrMutation( |
| 26216 | const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else { | 26159 | const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else { |
| 26217 | return sema.beginComptimePtrMutation(block, src, ptr_val, try ptr_elem_ty.optionalChildAlloc(sema.arena)); | 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 | switch (parent.pointee) { | 26163 | switch (parent.pointee) { |
| 26221 | .direct => |val_ptr| { | 26164 | .direct => |val_ptr| { |
| 26222 | const payload_ty = try parent.ty.optionalChildAlloc(sema.arena); | 26165 | const payload_ty = try parent.ty.optionalChildAlloc(sema.arena); |
| ... | @@ -26385,7 +26328,7 @@ fn beginComptimePtrLoad( | ... | @@ -26385,7 +26328,7 @@ fn beginComptimePtrLoad( |
| 26385 | .elem_ptr => blk: { | 26328 | .elem_ptr => blk: { |
| 26386 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; | 26329 | const elem_ptr = ptr_val.castTag(.elem_ptr).?.data; |
| 26387 | const elem_ty = elem_ptr.elem_ty; | 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 | // This code assumes that elem_ptrs have been "flattened" in order for direct dereference | 26333 | // This code assumes that elem_ptrs have been "flattened" in order for direct dereference |
| 26391 | // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that | 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,7 +26341,7 @@ fn beginComptimePtrLoad( |
| 26398 | if (elem_ty.hasWellDefinedLayout()) { | 26341 | if (elem_ty.hasWellDefinedLayout()) { |
| 26399 | if (deref.parent) |*parent| { | 26342 | if (deref.parent) |*parent| { |
| 26400 | // Update the byte offset (in-place) | 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 | const offset = parent.byte_offset + elem_size * elem_ptr.index; | 26345 | const offset = parent.byte_offset + elem_size * elem_ptr.index; |
| 26403 | parent.byte_offset = try sema.usizeCast(block, src, offset); | 26346 | parent.byte_offset = try sema.usizeCast(block, src, offset); |
| 26404 | } | 26347 | } |
| ... | @@ -26457,13 +26400,13 @@ fn beginComptimePtrLoad( | ... | @@ -26457,13 +26400,13 @@ fn beginComptimePtrLoad( |
| 26457 | | 26400 | |
| 26458 | .slice => blk: { | 26401 | .slice => blk: { |
| 26459 | const slice = ptr_val.castTag(.slice).?.data; | 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 | .field_ptr => blk: { | 26406 | .field_ptr => blk: { |
| 26464 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; | 26407 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| 26465 | const field_index = @intCast(u32, field_ptr.field_index); | 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 | if (field_ptr.container_ty.hasWellDefinedLayout()) { | 26411 | if (field_ptr.container_ty.hasWellDefinedLayout()) { |
| 26469 | const struct_ty = field_ptr.container_ty.castTag(.@"struct"); | 26412 | const struct_ty = field_ptr.container_ty.castTag(.@"struct"); |
| ... | @@ -26472,7 +26415,7 @@ fn beginComptimePtrLoad( | ... | @@ -26472,7 +26415,7 @@ fn beginComptimePtrLoad( |
| 26472 | deref.parent = null; | 26415 | deref.parent = null; |
| 26473 | } else if (deref.parent) |*parent| { | 26416 | } else if (deref.parent) |*parent| { |
| 26474 | // Update the byte offset (in-place) | 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 | const field_offset = field_ptr.container_ty.structFieldOffset(field_index, target); | 26419 | const field_offset = field_ptr.container_ty.structFieldOffset(field_index, target); |
| 26477 | parent.byte_offset = try sema.usizeCast(block, src, parent.byte_offset + field_offset); | 26420 | parent.byte_offset = try sema.usizeCast(block, src, parent.byte_offset + field_offset); |
| 26478 | } | 26421 | } |
| ... | @@ -26535,7 +26478,7 @@ fn beginComptimePtrLoad( | ... | @@ -26535,7 +26478,7 @@ fn beginComptimePtrLoad( |
| 26535 | .opt_payload_ptr => try payload_ptr.container_ty.optionalChildAlloc(sema.arena), | 26478 | .opt_payload_ptr => try payload_ptr.container_ty.optionalChildAlloc(sema.arena), |
| 26536 | else => unreachable, | 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 | // eu_payload_ptr and opt_payload_ptr never have a well-defined layout | 26483 | // eu_payload_ptr and opt_payload_ptr never have a well-defined layout |
| 26541 | if (deref.parent != null) { | 26484 | if (deref.parent != null) { |
| ... | @@ -26598,11 +26541,11 @@ fn bitCast( | ... | @@ -26598,11 +26541,11 @@ fn bitCast( |
| 26598 | inst: Air.Inst.Ref, | 26541 | inst: Air.Inst.Ref, |
| 26599 | inst_src: LazySrcLoc, | 26542 | inst_src: LazySrcLoc, |
| 26600 | ) CompileError!Air.Inst.Ref { | 26543 | ) CompileError!Air.Inst.Ref { |
| 26601 | const dest_ty = try sema.resolveTypeFields(block, inst_src, dest_ty_unresolved); | 26544 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); |
| 26602 | try sema.resolveTypeLayout(block, inst_src, dest_ty); | 26545 | try sema.resolveTypeLayout(dest_ty); |
| 26603 | | 26546 | |
| 26604 | const old_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst)); | 26547 | const old_ty = try sema.resolveTypeFields(sema.typeOf(inst)); |
| 26605 | try sema.resolveTypeLayout(block, inst_src, old_ty); | 26548 | try sema.resolveTypeLayout(old_ty); |
| 26606 | | 26549 | |
| 26607 | const target = sema.mod.getTarget(); | 26550 | const target = sema.mod.getTarget(); |
| 26608 | const dest_bits = dest_ty.bitSize(target); | 26551 | const dest_bits = dest_ty.bitSize(target); |
| ... | @@ -26617,7 +26560,7 @@ fn bitCast( | ... | @@ -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 | const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0); | 26564 | const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0); |
| 26622 | return sema.addConstant(dest_ty, result_val); | 26565 | return sema.addConstant(dest_ty, result_val); |
| 26623 | } | 26566 | } |
| ... | @@ -26653,7 +26596,7 @@ fn coerceArrayPtrToSlice( | ... | @@ -26653,7 +26596,7 @@ fn coerceArrayPtrToSlice( |
| 26653 | inst: Air.Inst.Ref, | 26596 | inst: Air.Inst.Ref, |
| 26654 | inst_src: LazySrcLoc, | 26597 | inst_src: LazySrcLoc, |
| 26655 | ) CompileError!Air.Inst.Ref { | 26598 | ) CompileError!Air.Inst.Ref { |
| 26656 | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { | 26599 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 26657 | const ptr_array_ty = sema.typeOf(inst); | 26600 | const ptr_array_ty = sema.typeOf(inst); |
| 26658 | const array_ty = ptr_array_ty.childType(); | 26601 | const array_ty = ptr_array_ty.childType(); |
| 26659 | const slice_val = try Value.Tag.slice.create(sema.arena, .{ | 26602 | const slice_val = try Value.Tag.slice.create(sema.arena, .{ |
| ... | @@ -26725,14 +26668,14 @@ fn coerceCompatiblePtrs( | ... | @@ -26725,14 +26668,14 @@ fn coerceCompatiblePtrs( |
| 26725 | inst_src: LazySrcLoc, | 26668 | inst_src: LazySrcLoc, |
| 26726 | ) !Air.Inst.Ref { | 26669 | ) !Air.Inst.Ref { |
| 26727 | const inst_ty = sema.typeOf(inst); | 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 | // The comptime Value representation is compatible with both types. | 26672 | // The comptime Value representation is compatible with both types. |
| 26730 | return sema.addConstant(dest_ty, val); | 26673 | return sema.addConstant(dest_ty, val); |
| 26731 | } | 26674 | } |
| 26732 | try sema.requireRuntimeBlock(block, inst_src, null); | 26675 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 26733 | const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true; | 26676 | const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true; |
| 26734 | if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and | 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 | const actual_ptr = if (inst_ty.isSlice()) | 26680 | const actual_ptr = if (inst_ty.isSlice()) |
| 26738 | try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) | 26681 | try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) |
| ... | @@ -26789,7 +26732,7 @@ fn coerceEnumToUnion( | ... | @@ -26789,7 +26732,7 @@ fn coerceEnumToUnion( |
| 26789 | | 26732 | |
| 26790 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 26733 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 26791 | const field = union_obj.fields.values()[field_index]; | 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 | if (field_ty.zigTypeTag() == .NoReturn) { | 26736 | if (field_ty.zigTypeTag() == .NoReturn) { |
| 26794 | const msg = msg: { | 26737 | const msg = msg: { |
| 26795 | const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{}); | 26738 | const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{}); |
| ... | @@ -26802,7 +26745,7 @@ fn coerceEnumToUnion( | ... | @@ -26802,7 +26745,7 @@ fn coerceEnumToUnion( |
| 26802 | }; | 26745 | }; |
| 26803 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 26749 | const msg = msg: { |
| 26807 | const field_name = union_obj.fields.keys()[field_index]; | 26750 | const field_name = union_obj.fields.keys()[field_index]; |
| 26808 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{ | 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,7 +26897,7 @@ fn coerceAnonStructToStructPtrs( |
| 26954 | ) !Air.Inst.Ref { | 26897 | ) !Air.Inst.Ref { |
| 26955 | const struct_ty = ptr_struct_ty.childType(); | 26898 | const struct_ty = ptr_struct_ty.childType(); |
| 26956 | const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src); | 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 | return sema.analyzeRef(block, struct_ty_src, struct_inst); | 26901 | return sema.analyzeRef(block, struct_ty_src, struct_inst); |
| 26959 | } | 26902 | } |
| 26960 | | 26903 | |
| ... | @@ -26989,7 +26932,7 @@ fn coerceArrayLike( | ... | @@ -26989,7 +26932,7 @@ fn coerceArrayLike( |
| 26989 | const inst_elem_ty = inst_ty.childType(); | 26932 | const inst_elem_ty = inst_ty.childType(); |
| 26990 | const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_elem_ty, inst_elem_ty, false, target, dest_ty_src, inst_src); | 26933 | const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_elem_ty, inst_elem_ty, false, target, dest_ty_src, inst_src); |
| 26991 | if (in_memory_result == .ok) { | 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 | // These types share the same comptime value representation. | 26936 | // These types share the same comptime value representation. |
| 26994 | return sema.addConstant(dest_ty, inst_val); | 26937 | return sema.addConstant(dest_ty, inst_val); |
| 26995 | } | 26938 | } |
| ... | @@ -27012,7 +26955,7 @@ fn coerceArrayLike( | ... | @@ -27012,7 +26955,7 @@ fn coerceArrayLike( |
| 27012 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); | 26955 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 27013 | element_refs[i] = coerced; | 26956 | element_refs[i] = coerced; |
| 27014 | if (runtime_src == null) { | 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 | elem.* = elem_val; | 26959 | elem.* = elem_val; |
| 27017 | } else { | 26960 | } else { |
| 27018 | runtime_src = elem_src; | 26961 | runtime_src = elem_src; |
| ... | @@ -27071,11 +27014,11 @@ fn coerceTupleToArray( | ... | @@ -27071,11 +27014,11 @@ fn coerceTupleToArray( |
| 27071 | break; | 27014 | break; |
| 27072 | } | 27015 | } |
| 27073 | const elem_src = inst_src; // TODO better source location | 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 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); | 27018 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 27076 | element_refs[i] = coerced; | 27019 | element_refs[i] = coerced; |
| 27077 | if (runtime_src == null) { | 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 | elem.* = elem_val; | 27022 | elem.* = elem_val; |
| 27080 | } else { | 27023 | } else { |
| 27081 | runtime_src = elem_src; | 27024 | runtime_src = elem_src; |
| ... | @@ -27141,11 +27084,10 @@ fn coerceTupleToStruct( | ... | @@ -27141,11 +27084,10 @@ fn coerceTupleToStruct( |
| 27141 | sema: *Sema, | 27084 | sema: *Sema, |
| 27142 | block: *Block, | 27085 | block: *Block, |
| 27143 | dest_ty: Type, | 27086 | dest_ty: Type, |
| 27144 | dest_ty_src: LazySrcLoc, | | |
| 27145 | inst: Air.Inst.Ref, | 27087 | inst: Air.Inst.Ref, |
| 27146 | inst_src: LazySrcLoc, | 27088 | inst_src: LazySrcLoc, |
| 27147 | ) !Air.Inst.Ref { | 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 | if (struct_ty.isTupleOrAnonStruct()) { | 27092 | if (struct_ty.isTupleOrAnonStruct()) { |
| 27151 | return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src); | 27093 | return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src); |
| ... | @@ -27168,11 +27110,11 @@ fn coerceTupleToStruct( | ... | @@ -27168,11 +27110,11 @@ fn coerceTupleToStruct( |
| 27168 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); | 27110 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 27169 | const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src); | 27111 | const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src); |
| 27170 | const field = fields.values()[field_index]; | 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 | const coerced = try sema.coerce(block, field.ty, elem_ref, field_src); | 27114 | const coerced = try sema.coerce(block, field.ty, elem_ref, field_src); |
| 27173 | field_refs[field_index] = coerced; | 27115 | field_refs[field_index] = coerced; |
| 27174 | if (field.is_comptime) { | 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 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 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,7 +27123,7 @@ fn coerceTupleToStruct( |
| 27181 | } | 27123 | } |
| 27182 | } | 27124 | } |
| 27183 | if (runtime_src == null) { | 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 | field_vals[field_index] = field_val; | 27127 | field_vals[field_index] = field_val; |
| 27186 | } else { | 27128 | } else { |
| 27187 | runtime_src = field_src; | 27129 | runtime_src = field_src; |
| ... | @@ -27264,11 +27206,11 @@ fn coerceTupleToTuple( | ... | @@ -27264,11 +27206,11 @@ fn coerceTupleToTuple( |
| 27264 | | 27206 | |
| 27265 | const field_ty = tuple_ty.structFieldType(i); | 27207 | const field_ty = tuple_ty.structFieldType(i); |
| 27266 | const default_val = tuple_ty.structFieldDefaultValue(i); | 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 | const coerced = try sema.coerce(block, field_ty, elem_ref, field_src); | 27210 | const coerced = try sema.coerce(block, field_ty, elem_ref, field_src); |
| 27269 | field_refs[field_index] = coerced; | 27211 | field_refs[field_index] = coerced; |
| 27270 | if (default_val.tag() != .unreachable_value) { | 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 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 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,7 +27219,7 @@ fn coerceTupleToTuple( |
| 27277 | } | 27219 | } |
| 27278 | } | 27220 | } |
| 27279 | if (runtime_src == null) { | 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 | field_vals[field_index] = field_val; | 27223 | field_vals[field_index] = field_val; |
| 27282 | } else { | 27224 | } else { |
| 27283 | runtime_src = field_src; | 27225 | runtime_src = field_src; |
| ... | @@ -27400,8 +27342,8 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: *Module.Fn) CompileError!void { | ... | @@ -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 { | 27345 | fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value { |
| 27404 | var anon_decl = try block.startAnonDecl(src); | 27346 | var anon_decl = try block.startAnonDecl(); |
| 27405 | defer anon_decl.deinit(); | 27347 | defer anon_decl.deinit(); |
| 27406 | const decl = try anon_decl.finish( | 27348 | const decl = try anon_decl.finish( |
| 27407 | try ty.copy(anon_decl.arena()), | 27349 | try ty.copy(anon_decl.arena()), |
| ... | @@ -27412,9 +27354,9 @@ fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) ! | ... | @@ -27412,9 +27354,9 @@ fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) ! |
| 27412 | return try Value.Tag.decl_ref.create(sema.arena, decl); | 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 | const val = opt_val orelse return Value.@"null"; | 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 | const result = try Value.Tag.opt_payload.create(sema.arena, ptr_val); | 27360 | const result = try Value.Tag.opt_payload.create(sema.arena, ptr_val); |
| 27419 | return result; | 27361 | return result; |
| 27420 | } | 27362 | } |
| ... | @@ -27454,8 +27396,8 @@ fn analyzeRef( | ... | @@ -27454,8 +27396,8 @@ fn analyzeRef( |
| 27454 | ) CompileError!Air.Inst.Ref { | 27396 | ) CompileError!Air.Inst.Ref { |
| 27455 | const operand_ty = sema.typeOf(operand); | 27397 | const operand_ty = sema.typeOf(operand); |
| 27456 | | 27398 | |
| 27457 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| { | 27399 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 27458 | var anon_decl = try block.startAnonDecl(src); | 27400 | var anon_decl = try block.startAnonDecl(); |
| 27459 | defer anon_decl.deinit(); | 27401 | defer anon_decl.deinit(); |
| 27460 | return sema.analyzeDeclRef(try anon_decl.finish( | 27402 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 27461 | try operand_ty.copy(anon_decl.arena()), | 27403 | try operand_ty.copy(anon_decl.arena()), |
| ... | @@ -27495,7 +27437,7 @@ fn analyzeLoad( | ... | @@ -27495,7 +27437,7 @@ fn analyzeLoad( |
| 27495 | else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}), | 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 | return sema.addConstant(elem_ty, opv); | 27441 | return sema.addConstant(elem_ty, opv); |
| 27500 | } | 27442 | } |
| 27501 | | 27443 | |
| ... | @@ -27517,7 +27459,7 @@ fn analyzeSlicePtr( | ... | @@ -27517,7 +27459,7 @@ fn analyzeSlicePtr( |
| 27517 | ) CompileError!Air.Inst.Ref { | 27459 | ) CompileError!Air.Inst.Ref { |
| 27518 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); | 27460 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); |
| 27519 | const result_ty = slice_ty.slicePtrFieldType(buf); | 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 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 27463 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 27522 | return sema.addConstant(result_ty, val.slicePtr()); | 27464 | return sema.addConstant(result_ty, val.slicePtr()); |
| 27523 | } | 27465 | } |
| ... | @@ -27531,7 +27473,7 @@ fn analyzeSliceLen( | ... | @@ -27531,7 +27473,7 @@ fn analyzeSliceLen( |
| 27531 | src: LazySrcLoc, | 27473 | src: LazySrcLoc, |
| 27532 | slice_inst: Air.Inst.Ref, | 27474 | slice_inst: Air.Inst.Ref, |
| 27533 | ) CompileError!Air.Inst.Ref { | 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 | if (slice_val.isUndef()) { | 27477 | if (slice_val.isUndef()) { |
| 27536 | return sema.addConstUndef(Type.usize); | 27478 | return sema.addConstUndef(Type.usize); |
| 27537 | } | 27479 | } |
| ... | @@ -27549,7 +27491,7 @@ fn analyzeIsNull( | ... | @@ -27549,7 +27491,7 @@ fn analyzeIsNull( |
| 27549 | invert_logic: bool, | 27491 | invert_logic: bool, |
| 27550 | ) CompileError!Air.Inst.Ref { | 27492 | ) CompileError!Air.Inst.Ref { |
| 27551 | const result_ty = Type.bool; | 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 | if (opt_val.isUndef()) { | 27495 | if (opt_val.isUndef()) { |
| 27554 | return sema.addConstUndef(result_ty); | 27496 | return sema.addConstUndef(result_ty); |
| 27555 | } | 27497 | } |
| ... | @@ -27627,7 +27569,7 @@ fn analyzeIsNonErrComptimeOnly( | ... | @@ -27627,7 +27569,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 27627 | return Air.Inst.Ref.bool_true; | 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 | // exception if the error union error set is known to be empty, | 27574 | // exception if the error union error set is known to be empty, |
| 27633 | // we allow the comparison but always make it comptime-known. | 27575 | // we allow the comparison but always make it comptime-known. |
| ... | @@ -27791,7 +27733,7 @@ fn analyzeSlice( | ... | @@ -27791,7 +27733,7 @@ fn analyzeSlice( |
| 27791 | ptr_or_slice; | 27733 | ptr_or_slice; |
| 27792 | | 27734 | |
| 27793 | const start = try sema.coerce(block, Type.usize, uncasted_start, start_src); | 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 | // true if and only if the end index of the slice, implicitly or explicitly, equals | 27738 | // true if and only if the end index of the slice, implicitly or explicitly, equals |
| 27797 | // the length of the underlying object being sliced. we might learn the length of the | 27739 | // the length of the underlying object being sliced. we might learn the length of the |
| ... | @@ -27804,12 +27746,12 @@ fn analyzeSlice( | ... | @@ -27804,12 +27746,12 @@ fn analyzeSlice( |
| 27804 | | 27746 | |
| 27805 | if (!end_is_len) { | 27747 | if (!end_is_len) { |
| 27806 | const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); | 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 | const len_s_val = try Value.Tag.int_u64.create( | 27750 | const len_s_val = try Value.Tag.int_u64.create( |
| 27809 | sema.arena, | 27751 | sema.arena, |
| 27810 | array_ty.arrayLenIncludingSentinel(), | 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 | const sentinel_label: []const u8 = if (array_ty.sentinel() != null) | 27755 | const sentinel_label: []const u8 = if (array_ty.sentinel() != null) |
| 27814 | " +1 (sentinel)" | 27756 | " +1 (sentinel)" |
| 27815 | else | 27757 | else |
| ... | @@ -27842,7 +27784,7 @@ fn analyzeSlice( | ... | @@ -27842,7 +27784,7 @@ fn analyzeSlice( |
| 27842 | if (!end_is_len) { | 27784 | if (!end_is_len) { |
| 27843 | const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); | 27785 | const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 27844 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { | 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 | if (slice_val.isUndef()) { | 27788 | if (slice_val.isUndef()) { |
| 27847 | return sema.fail(block, src, "slice of undefined", .{}); | 27789 | return sema.fail(block, src, "slice of undefined", .{}); |
| 27848 | } | 27790 | } |
| ... | @@ -27852,7 +27794,7 @@ fn analyzeSlice( | ... | @@ -27852,7 +27794,7 @@ fn analyzeSlice( |
| 27852 | .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel), | 27794 | .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel), |
| 27853 | }; | 27795 | }; |
| 27854 | const slice_len_val = Value.initPayload(&int_payload.base); | 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 | const sentinel_label: []const u8 = if (has_sentinel) | 27798 | const sentinel_label: []const u8 = if (has_sentinel) |
| 27857 | " +1 (sentinel)" | 27799 | " +1 (sentinel)" |
| 27858 | else | 27800 | else |
| ... | @@ -27911,7 +27853,7 @@ fn analyzeSlice( | ... | @@ -27911,7 +27853,7 @@ fn analyzeSlice( |
| 27911 | // requirement: start <= end | 27853 | // requirement: start <= end |
| 27912 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { | 27854 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 27913 | if (try sema.resolveDefinedValue(block, start_src, start)) |start_val| { | 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 | return sema.fail( | 27857 | return sema.fail( |
| 27916 | block, | 27858 | block, |
| 27917 | start_src, | 27859 | start_src, |
| ... | @@ -27922,7 +27864,7 @@ fn analyzeSlice( | ... | @@ -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 | const expected_sentinel = sentinel orelse break :sentinel_check; | 27868 | const expected_sentinel = sentinel orelse break :sentinel_check; |
| 27927 | const start_int = start_val.getUnsignedInt(sema.mod.getTarget()).?; | 27869 | const start_int = start_val.getUnsignedInt(sema.mod.getTarget()).?; |
| 27928 | const end_int = end_val.getUnsignedInt(sema.mod.getTarget()).?; | 27870 | const end_int = end_val.getUnsignedInt(sema.mod.getTarget()).?; |
| ... | @@ -27984,7 +27926,7 @@ fn analyzeSlice( | ... | @@ -27984,7 +27926,7 @@ fn analyzeSlice( |
| 27984 | .size = .One, | 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 | const new_ptr_val = opt_new_ptr_val orelse { | 27930 | const new_ptr_val = opt_new_ptr_val orelse { |
| 27989 | const result = try block.addBitCast(return_ty, new_ptr); | 27931 | const result = try block.addBitCast(return_ty, new_ptr); |
| 27990 | if (block.wantSafety()) { | 27932 | if (block.wantSafety()) { |
| ... | @@ -28038,9 +27980,9 @@ fn analyzeSlice( | ... | @@ -28038,9 +27980,9 @@ fn analyzeSlice( |
| 28038 | .size = .Slice, | 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 | ptr_src | 27984 | ptr_src |
| 28043 | else if ((try sema.resolveMaybeUndefVal(block, src, start)) == null) | 27985 | else if ((try sema.resolveMaybeUndefVal(start)) == null) |
| 28044 | start_src | 27986 | start_src |
| 28045 | else | 27987 | else |
| 28046 | end_src; | 27988 | end_src; |
| ... | @@ -28132,8 +28074,8 @@ fn cmpNumeric( | ... | @@ -28132,8 +28074,8 @@ fn cmpNumeric( |
| 28132 | uncasted_rhs; | 28074 | uncasted_rhs; |
| 28133 | | 28075 | |
| 28134 | const runtime_src: LazySrcLoc = src: { | 28076 | const runtime_src: LazySrcLoc = src: { |
| 28135 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { | 28077 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 28136 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { | 28078 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 28137 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 28079 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 28138 | return sema.addConstUndef(Type.bool); | 28080 | return sema.addConstUndef(Type.bool); |
| 28139 | } | 28081 | } |
| ... | @@ -28144,7 +28086,7 @@ fn cmpNumeric( | ... | @@ -28144,7 +28086,7 @@ fn cmpNumeric( |
| 28144 | return Air.Inst.Ref.bool_false; | 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 | return Air.Inst.Ref.bool_true; | 28090 | return Air.Inst.Ref.bool_true; |
| 28149 | } else { | 28091 | } else { |
| 28150 | return Air.Inst.Ref.bool_false; | 28092 | return Air.Inst.Ref.bool_false; |
| ... | @@ -28200,11 +28142,11 @@ fn cmpNumeric( | ... | @@ -28200,11 +28142,11 @@ fn cmpNumeric( |
| 28200 | // a signed integer with mantissa bits + 1, and if there was any non-integral part of the float, | 28142 | // a signed integer with mantissa bits + 1, and if there was any non-integral part of the float, |
| 28201 | // add/subtract 1. | 28143 | // add/subtract 1. |
| 28202 | const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| | 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 | else | 28146 | else |
| 28205 | (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt()); | 28147 | (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt()); |
| 28206 | const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val| | 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 | else | 28150 | else |
| 28209 | (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt()); | 28151 | (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt()); |
| 28210 | const dest_int_is_signed = lhs_is_signed or rhs_is_signed; | 28152 | const dest_int_is_signed = lhs_is_signed or rhs_is_signed; |
| ... | @@ -28212,7 +28154,7 @@ fn cmpNumeric( | ... | @@ -28212,7 +28154,7 @@ fn cmpNumeric( |
| 28212 | var dest_float_type: ?Type = null; | 28154 | var dest_float_type: ?Type = null; |
| 28213 | | 28155 | |
| 28214 | var lhs_bits: usize = undefined; | 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 | if (lhs_val.isUndef()) | 28158 | if (lhs_val.isUndef()) |
| 28217 | return sema.addConstUndef(Type.bool); | 28159 | return sema.addConstUndef(Type.bool); |
| 28218 | if (lhs_val.isNan()) switch (op) { | 28160 | if (lhs_val.isNan()) switch (op) { |
| ... | @@ -28265,7 +28207,7 @@ fn cmpNumeric( | ... | @@ -28265,7 +28207,7 @@ fn cmpNumeric( |
| 28265 | } | 28207 | } |
| 28266 | | 28208 | |
| 28267 | var rhs_bits: usize = undefined; | 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 | if (rhs_val.isUndef()) | 28211 | if (rhs_val.isUndef()) |
| 28270 | return sema.addConstUndef(Type.bool); | 28212 | return sema.addConstUndef(Type.bool); |
| 28271 | if (rhs_val.isNan()) switch (op) { | 28213 | if (rhs_val.isNan()) switch (op) { |
| ... | @@ -28349,12 +28291,12 @@ fn cmpVector( | ... | @@ -28349,12 +28291,12 @@ fn cmpVector( |
| 28349 | const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.@"bool"); | 28291 | const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.@"bool"); |
| 28350 | | 28292 | |
| 28351 | const runtime_src: LazySrcLoc = src: { | 28293 | const runtime_src: LazySrcLoc = src: { |
| 28352 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { | 28294 | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 28353 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { | 28295 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 28354 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 28296 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 28355 | return sema.addConstUndef(result_ty); | 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 | return sema.addConstant(result_ty, cmp_val); | 28300 | return sema.addConstant(result_ty, cmp_val); |
| 28359 | } else { | 28301 | } else { |
| 28360 | break :src rhs_src; | 28302 | break :src rhs_src; |
| ... | @@ -28376,7 +28318,7 @@ fn wrapOptional( | ... | @@ -28376,7 +28318,7 @@ fn wrapOptional( |
| 28376 | inst: Air.Inst.Ref, | 28318 | inst: Air.Inst.Ref, |
| 28377 | inst_src: LazySrcLoc, | 28319 | inst_src: LazySrcLoc, |
| 28378 | ) !Air.Inst.Ref { | 28320 | ) !Air.Inst.Ref { |
| 28379 | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { | 28321 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 28380 | return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, val)); | 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,7 +28335,7 @@ fn wrapErrorUnionPayload( |
| 28393 | ) !Air.Inst.Ref { | 28335 | ) !Air.Inst.Ref { |
| 28394 | const dest_payload_ty = dest_ty.errorUnionPayload(); | 28336 | const dest_payload_ty = dest_ty.errorUnionPayload(); |
| 28395 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); | 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 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); | 28339 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); |
| 28398 | } | 28340 | } |
| 28399 | try sema.requireRuntimeBlock(block, inst_src, null); | 28341 | try sema.requireRuntimeBlock(block, inst_src, null); |
| ... | @@ -28410,7 +28352,7 @@ fn wrapErrorUnionSet( | ... | @@ -28410,7 +28352,7 @@ fn wrapErrorUnionSet( |
| 28410 | ) !Air.Inst.Ref { | 28352 | ) !Air.Inst.Ref { |
| 28411 | const inst_ty = sema.typeOf(inst); | 28353 | const inst_ty = sema.typeOf(inst); |
| 28412 | const dest_err_set_ty = dest_ty.errorUnionSet(); | 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 | switch (dest_err_set_ty.tag()) { | 28356 | switch (dest_err_set_ty.tag()) { |
| 28415 | .anyerror => {}, | 28357 | .anyerror => {}, |
| 28416 | .error_set_single => ok: { | 28358 | .error_set_single => ok: { |
| ... | @@ -28464,10 +28406,10 @@ fn unionToTag( | ... | @@ -28464,10 +28406,10 @@ fn unionToTag( |
| 28464 | un: Air.Inst.Ref, | 28406 | un: Air.Inst.Ref, |
| 28465 | un_src: LazySrcLoc, | 28407 | un_src: LazySrcLoc, |
| 28466 | ) !Air.Inst.Ref { | 28408 | ) !Air.Inst.Ref { |
| 28467 | if ((try sema.typeHasOnePossibleValue(block, un_src, enum_ty))) |opv| { | 28409 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { |
| 28468 | return sema.addConstant(enum_ty, opv); | 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 | return sema.addConstant(enum_ty, un_val.unionTag()); | 28413 | return sema.addConstant(enum_ty, un_val.unionTag()); |
| 28472 | } | 28414 | } |
| 28473 | try sema.requireRuntimeBlock(block, un_src, null); | 28415 | try sema.requireRuntimeBlock(block, un_src, null); |
| ... | @@ -29029,72 +28971,57 @@ fn resolvePeerTypes( | ... | @@ -29029,72 +28971,57 @@ fn resolvePeerTypes( |
| 29029 | return chosen_ty; | 28971 | return chosen_ty; |
| 29030 | } | 28972 | } |
| 29031 | | 28973 | |
| 29032 | pub fn resolveFnTypes( | 28974 | pub fn resolveFnTypes(sema: *Sema, fn_info: Type.Payload.Function.Data) CompileError!void { |
| 29033 | sema: *Sema, | 28975 | try sema.resolveTypeFully(fn_info.return_type); |
| 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); | | |
| 29039 | | 28976 | |
| 29040 | if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) { | 28977 | if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) { |
| 29041 | // Ensure the type exists so that backends can assume that. | 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 | for (fn_info.param_types) |param_ty| { | 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 | /// Make it so that calling hash() and eql() on `val` will not assert due | 28987 | /// Make it so that calling hash() and eql() on `val` will not assert due |
| 29051 | /// to a type not having its layout resolved. | 28988 | /// to a type not having its layout resolved. |
| 29052 | fn resolveLazyValue( | 28989 | fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void { |
| 29053 | sema: *Sema, | | |
| 29054 | block: *Block, | | |
| 29055 | src: LazySrcLoc, | | |
| 29056 | val: Value, | | |
| 29057 | ) CompileError!void { | | |
| 29058 | switch (val.tag()) { | 28990 | switch (val.tag()) { |
| 29059 | .lazy_align => { | 28991 | .lazy_align => { |
| 29060 | const ty = val.castTag(.lazy_align).?.data; | 28992 | const ty = val.castTag(.lazy_align).?.data; |
| 29061 | return sema.resolveTypeLayout(block, src, ty); | 28993 | return sema.resolveTypeLayout(ty); |
| 29062 | }, | 28994 | }, |
| 29063 | .lazy_size => { | 28995 | .lazy_size => { |
| 29064 | const ty = val.castTag(.lazy_size).?.data; | 28996 | const ty = val.castTag(.lazy_size).?.data; |
| 29065 | return sema.resolveTypeLayout(block, src, ty); | 28997 | return sema.resolveTypeLayout(ty); |
| 29066 | }, | 28998 | }, |
| 29067 | .comptime_field_ptr => { | 28999 | .comptime_field_ptr => { |
| 29068 | const field_ptr = val.castTag(.comptime_field_ptr).?.data; | 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 | .@"union" => { | 29003 | .@"union" => { |
| 29072 | const union_val = val.castTag(.@"union").?.data; | 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 | .aggregate => { | 29007 | .aggregate => { |
| 29076 | const aggregate = val.castTag(.aggregate).?.data; | 29008 | const aggregate = val.castTag(.aggregate).?.data; |
| 29077 | for (aggregate) |elem_val| { | 29009 | for (aggregate) |elem_val| { |
| 29078 | try sema.resolveLazyValue(block, src, elem_val); | 29010 | try sema.resolveLazyValue(elem_val); |
| 29079 | } | 29011 | } |
| 29080 | }, | 29012 | }, |
| 29081 | else => return, | 29013 | else => return, |
| 29082 | } | 29014 | } |
| 29083 | } | 29015 | } |
| 29084 | | 29016 | |
| 29085 | pub fn resolveTypeLayout( | 29017 | pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29086 | sema: *Sema, | | |
| 29087 | block: *Block, | | |
| 29088 | src: LazySrcLoc, | | |
| 29089 | ty: Type, | | |
| 29090 | ) CompileError!void { | | |
| 29091 | switch (ty.zigTypeTag()) { | 29018 | switch (ty.zigTypeTag()) { |
| 29092 | .Struct => return sema.resolveStructLayout(block, src, ty), | 29019 | .Struct => return sema.resolveStructLayout(ty), |
| 29093 | .Union => return sema.resolveUnionLayout(block, src, ty), | 29020 | .Union => return sema.resolveUnionLayout(ty), |
| 29094 | .Array => { | 29021 | .Array => { |
| 29095 | if (ty.arrayLenIncludingSentinel() == 0) return; | 29022 | if (ty.arrayLenIncludingSentinel() == 0) return; |
| 29096 | const elem_ty = ty.childType(); | 29023 | const elem_ty = ty.childType(); |
| 29097 | return sema.resolveTypeLayout(block, src, elem_ty); | 29024 | return sema.resolveTypeLayout(elem_ty); |
| 29098 | }, | 29025 | }, |
| 29099 | .Optional => { | 29026 | .Optional => { |
| 29100 | var buf: Type.Payload.ElemType = undefined; | 29027 | var buf: Type.Payload.ElemType = undefined; |
| ... | @@ -29103,23 +29030,18 @@ pub fn resolveTypeLayout( | ... | @@ -29103,23 +29030,18 @@ pub fn resolveTypeLayout( |
| 29103 | // for hasRuntimeBits() of the payload type, so we need "requires comptime" | 29030 | // for hasRuntimeBits() of the payload type, so we need "requires comptime" |
| 29104 | // to be known already before this function returns. | 29031 | // to be known already before this function returns. |
| 29105 | _ = try sema.typeRequiresComptime(payload_ty); | 29032 | _ = try sema.typeRequiresComptime(payload_ty); |
| 29106 | return sema.resolveTypeLayout(block, src, payload_ty); | 29033 | return sema.resolveTypeLayout(payload_ty); |
| 29107 | }, | 29034 | }, |
| 29108 | .ErrorUnion => { | 29035 | .ErrorUnion => { |
| 29109 | const payload_ty = ty.errorUnionPayload(); | 29036 | const payload_ty = ty.errorUnionPayload(); |
| 29110 | return sema.resolveTypeLayout(block, src, payload_ty); | 29037 | return sema.resolveTypeLayout(payload_ty); |
| 29111 | }, | 29038 | }, |
| 29112 | else => {}, | 29039 | else => {}, |
| 29113 | } | 29040 | } |
| 29114 | } | 29041 | } |
| 29115 | | 29042 | |
| 29116 | fn resolveStructLayout( | 29043 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29117 | sema: *Sema, | 29044 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29118 | block: *Block, | | |
| 29119 | src: LazySrcLoc, | | |
| 29120 | ty: Type, | | |
| 29121 | ) CompileError!void { | | |
| 29122 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | | |
| 29123 | if (resolved_ty.castTag(.@"struct")) |payload| { | 29045 | if (resolved_ty.castTag(.@"struct")) |payload| { |
| 29124 | const struct_obj = payload.data; | 29046 | const struct_obj = payload.data; |
| 29125 | switch (struct_obj.status) { | 29047 | switch (struct_obj.status) { |
| ... | @@ -29137,7 +29059,7 @@ fn resolveStructLayout( | ... | @@ -29137,7 +29059,7 @@ fn resolveStructLayout( |
| 29137 | } | 29059 | } |
| 29138 | struct_obj.status = .layout_wip; | 29060 | struct_obj.status = .layout_wip; |
| 29139 | for (struct_obj.fields.values()) |field, i| { | 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 | error.AnalysisFail => { | 29063 | error.AnalysisFail => { |
| 29142 | const msg = sema.err orelse return err; | 29064 | const msg = sema.err orelse return err; |
| 29143 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); | 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,13 +29223,8 @@ fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ |
| 29301 | } | 29223 | } |
| 29302 | } | 29224 | } |
| 29303 | | 29225 | |
| 29304 | fn resolveUnionLayout( | 29226 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29305 | sema: *Sema, | 29227 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29306 | block: *Block, | | |
| 29307 | src: LazySrcLoc, | | |
| 29308 | ty: Type, | | |
| 29309 | ) CompileError!void { | | |
| 29310 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | | |
| 29311 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; | 29228 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| 29312 | switch (union_obj.status) { | 29229 | switch (union_obj.status) { |
| 29313 | .none, .have_field_types => {}, | 29230 | .none, .have_field_types => {}, |
| ... | @@ -29324,7 +29241,7 @@ fn resolveUnionLayout( | ... | @@ -29324,7 +29241,7 @@ fn resolveUnionLayout( |
| 29324 | } | 29241 | } |
| 29325 | union_obj.status = .layout_wip; | 29242 | union_obj.status = .layout_wip; |
| 29326 | for (union_obj.fields.values()) |field, i| { | 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 | error.AnalysisFail => { | 29245 | error.AnalysisFail => { |
| 29329 | const msg = sema.err orelse return err; | 29246 | const msg = sema.err orelse return err; |
| 29330 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); | 29247 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| ... | @@ -29338,35 +29255,30 @@ fn resolveUnionLayout( | ... | @@ -29338,35 +29255,30 @@ fn resolveUnionLayout( |
| 29338 | | 29255 | |
| 29339 | /// Returns `error.AnalysisFail` if any of the types (recursively) failed to | 29256 | /// Returns `error.AnalysisFail` if any of the types (recursively) failed to |
| 29340 | /// be resolved. | 29257 | /// be resolved. |
| 29341 | pub fn resolveTypeFully( | 29258 | pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { |
| 29342 | sema: *Sema, | | |
| 29343 | block: *Block, | | |
| 29344 | src: LazySrcLoc, | | |
| 29345 | ty: Type, | | |
| 29346 | ) CompileError!void { | | |
| 29347 | switch (ty.zigTypeTag()) { | 29259 | switch (ty.zigTypeTag()) { |
| 29348 | .Pointer => { | 29260 | .Pointer => { |
| 29349 | const child_ty = try sema.resolveTypeFields(block, src, ty.childType()); | 29261 | const child_ty = try sema.resolveTypeFields(ty.childType()); |
| 29350 | return resolveTypeFully(sema, block, src, child_ty); | 29262 | return sema.resolveTypeFully(child_ty); |
| 29351 | }, | 29263 | }, |
| 29352 | .Struct => switch (ty.tag()) { | 29264 | .Struct => switch (ty.tag()) { |
| 29353 | .@"struct" => return resolveStructFully(sema, block, src, ty), | 29265 | .@"struct" => return sema.resolveStructFully(ty), |
| 29354 | .tuple, .anon_struct => { | 29266 | .tuple, .anon_struct => { |
| 29355 | const tuple = ty.tupleFields(); | 29267 | const tuple = ty.tupleFields(); |
| 29356 | | 29268 | |
| 29357 | for (tuple.types) |field_ty| { | 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 | else => {}, | 29273 | else => {}, |
| 29362 | }, | 29274 | }, |
| 29363 | .Union => return resolveUnionFully(sema, block, src, ty), | 29275 | .Union => return sema.resolveUnionFully(ty), |
| 29364 | .Array => return resolveTypeFully(sema, block, src, ty.childType()), | 29276 | .Array => return sema.resolveTypeFully(ty.childType()), |
| 29365 | .Optional => { | 29277 | .Optional => { |
| 29366 | var buf: Type.Payload.ElemType = undefined; | 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 | .Fn => { | 29282 | .Fn => { |
| 29371 | const info = ty.fnInfo(); | 29283 | const info = ty.fnInfo(); |
| 29372 | if (info.is_generic) { | 29284 | if (info.is_generic) { |
| ... | @@ -29375,25 +29287,18 @@ pub fn resolveTypeFully( | ... | @@ -29375,25 +29287,18 @@ pub fn resolveTypeFully( |
| 29375 | return; | 29287 | return; |
| 29376 | } | 29288 | } |
| 29377 | for (info.param_types) |param_ty| { | 29289 | for (info.param_types) |param_ty| { |
| 29378 | const param_ty_src = src; // TODO better source location | 29290 | try sema.resolveTypeFully(param_ty); |
| 29379 | try sema.resolveTypeFully(block, param_ty_src, param_ty); | | |
| 29380 | } | 29291 | } |
| 29381 | const return_ty_src = src; // TODO better source location | 29292 | try sema.resolveTypeFully(info.return_type); |
| 29382 | try sema.resolveTypeFully(block, return_ty_src, info.return_type); | | |
| 29383 | }, | 29293 | }, |
| 29384 | else => {}, | 29294 | else => {}, |
| 29385 | } | 29295 | } |
| 29386 | } | 29296 | } |
| 29387 | | 29297 | |
| 29388 | fn resolveStructFully( | 29298 | fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void { |
| 29389 | sema: *Sema, | 29299 | try sema.resolveStructLayout(ty); |
| 29390 | block: *Block, | | |
| 29391 | src: LazySrcLoc, | | |
| 29392 | ty: Type, | | |
| 29393 | ) CompileError!void { | | |
| 29394 | try resolveStructLayout(sema, block, src, ty); | | |
| 29395 | | 29300 | |
| 29396 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 29301 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29397 | const payload = resolved_ty.castTag(.@"struct").?; | 29302 | const payload = resolved_ty.castTag(.@"struct").?; |
| 29398 | const struct_obj = payload.data; | 29303 | const struct_obj = payload.data; |
| 29399 | | 29304 | |
| ... | @@ -29411,7 +29316,7 @@ fn resolveStructFully( | ... | @@ -29411,7 +29316,7 @@ fn resolveStructFully( |
| 29411 | | 29316 | |
| 29412 | struct_obj.status = .fully_resolved_wip; | 29317 | struct_obj.status = .fully_resolved_wip; |
| 29413 | for (struct_obj.fields.values()) |field| { | 29318 | for (struct_obj.fields.values()) |field| { |
| 29414 | try sema.resolveTypeFully(block, src, field.ty); | 29319 | try sema.resolveTypeFully(field.ty); |
| 29415 | } | 29320 | } |
| 29416 | struct_obj.status = .fully_resolved; | 29321 | struct_obj.status = .fully_resolved; |
| 29417 | } | 29322 | } |
| ... | @@ -29420,15 +29325,10 @@ fn resolveStructFully( | ... | @@ -29420,15 +29325,10 @@ fn resolveStructFully( |
| 29420 | _ = try sema.typeRequiresComptime(ty); | 29325 | _ = try sema.typeRequiresComptime(ty); |
| 29421 | } | 29326 | } |
| 29422 | | 29327 | |
| 29423 | fn resolveUnionFully( | 29328 | fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void { |
| 29424 | sema: *Sema, | 29329 | try sema.resolveUnionLayout(ty); |
| 29425 | block: *Block, | | |
| 29426 | src: LazySrcLoc, | | |
| 29427 | ty: Type, | | |
| 29428 | ) CompileError!void { | | |
| 29429 | try resolveUnionLayout(sema, block, src, ty); | | |
| 29430 | | 29330 | |
| 29431 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 29331 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 29432 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; | 29332 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| 29433 | switch (union_obj.status) { | 29333 | switch (union_obj.status) { |
| 29434 | .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {}, | 29334 | .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {}, |
| ... | @@ -29444,7 +29344,7 @@ fn resolveUnionFully( | ... | @@ -29444,7 +29344,7 @@ fn resolveUnionFully( |
| 29444 | | 29344 | |
| 29445 | union_obj.status = .fully_resolved_wip; | 29345 | union_obj.status = .fully_resolved_wip; |
| 29446 | for (union_obj.fields.values()) |field| { | 29346 | for (union_obj.fields.values()) |field| { |
| 29447 | try sema.resolveTypeFully(block, src, field.ty); | 29347 | try sema.resolveTypeFully(field.ty); |
| 29448 | } | 29348 | } |
| 29449 | union_obj.status = .fully_resolved; | 29349 | union_obj.status = .fully_resolved; |
| 29450 | } | 29350 | } |
| ... | @@ -29453,7 +29353,7 @@ fn resolveUnionFully( | ... | @@ -29453,7 +29353,7 @@ fn resolveUnionFully( |
| 29453 | _ = try sema.typeRequiresComptime(ty); | 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 | switch (ty.tag()) { | 29357 | switch (ty.tag()) { |
| 29458 | .@"struct" => { | 29358 | .@"struct" => { |
| 29459 | const struct_obj = ty.castTag(.@"struct").?.data; | 29359 | const struct_obj = ty.castTag(.@"struct").?.data; |
| ... | @@ -29465,17 +29365,17 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) | ... | @@ -29465,17 +29365,17 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 29465 | try sema.resolveTypeFieldsUnion(ty, union_obj); | 29365 | try sema.resolveTypeFieldsUnion(ty, union_obj); |
| 29466 | return ty; | 29366 | return ty; |
| 29467 | }, | 29367 | }, |
| 29468 | .type_info => return sema.resolveBuiltinTypeFields(block, src, "Type"), | 29368 | .type_info => return sema.getBuiltinType("Type"), |
| 29469 | .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"), | 29369 | .extern_options => return sema.getBuiltinType("ExternOptions"), |
| 29470 | .export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"), | 29370 | .export_options => return sema.getBuiltinType("ExportOptions"), |
| 29471 | .atomic_order => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrder"), | 29371 | .atomic_order => return sema.getBuiltinType("AtomicOrder"), |
| 29472 | .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"), | 29372 | .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"), |
| 29473 | .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"), | 29373 | .calling_convention => return sema.getBuiltinType("CallingConvention"), |
| 29474 | .address_space => return sema.resolveBuiltinTypeFields(block, src, "AddressSpace"), | 29374 | .address_space => return sema.getBuiltinType("AddressSpace"), |
| 29475 | .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"), | 29375 | .float_mode => return sema.getBuiltinType("FloatMode"), |
| 29476 | .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"), | 29376 | .reduce_op => return sema.getBuiltinType("ReduceOp"), |
| 29477 | .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"), | 29377 | .call_options => return sema.getBuiltinType("CallOptions"), |
| 29478 | .prefetch_options => return sema.resolveBuiltinTypeFields(block, src, "PrefetchOptions"), | 29378 | .prefetch_options => return sema.getBuiltinType("PrefetchOptions"), |
| 29479 | | 29379 | |
| 29480 | else => return ty, | 29380 | else => return ty, |
| 29481 | } | 29381 | } |
| ... | @@ -29534,16 +29434,6 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi | ... | @@ -29534,16 +29434,6 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi |
| 29534 | union_obj.status = .have_field_types; | 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 | fn resolveInferredErrorSet( | 29437 | fn resolveInferredErrorSet( |
| 29548 | sema: *Sema, | 29438 | sema: *Sema, |
| 29549 | block: *Block, | 29439 | block: *Block, |
| ... | @@ -29828,7 +29718,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -29828,7 +29718,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 29828 | }; | 29718 | }; |
| 29829 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 29722 | const msg = msg: { |
| 29833 | const tree = try sema.getAstTree(&block_scope); | 29723 | const tree = try sema.getAstTree(&block_scope); |
| 29834 | const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i); | 29724 | const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i); |
| ... | @@ -29879,7 +29769,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -29879,7 +29769,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 29879 | const init = try sema.resolveBody(&block_scope, body, struct_obj.zir_index); | 29769 | const init = try sema.resolveBody(&block_scope, body, struct_obj.zir_index); |
| 29880 | const field = &struct_obj.fields.values()[i]; | 29770 | const field = &struct_obj.fields.values()[i]; |
| 29881 | const coerced = try sema.coerce(&block_scope, field.ty, init, src); | 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 | return sema.failWithNeededComptime(&block_scope, src, "struct field default value must be comptime-known"); | 29773 | return sema.failWithNeededComptime(&block_scope, src, "struct field default value must be comptime-known"); |
| 29884 | field.default_val = try default_val.copy(decl_arena_allocator); | 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,7 +29979,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30089 | }); | 29979 | }); |
| 30090 | } else { | 29980 | } else { |
| 30091 | const val = if (last_tag_val) |val| | 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 | else | 29983 | else |
| 30094 | Value.zero; | 29984 | Value.zero; |
| 30095 | last_tag_val = val; | 29985 | last_tag_val = val; |
| ... | @@ -30166,7 +30056,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -30166,7 +30056,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30166 | }; | 30056 | }; |
| 30167 | return sema.failWithOwnedErrorMsg(msg); | 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 | const msg = msg: { | 30060 | const msg = msg: { |
| 30171 | const tree = try sema.getAstTree(&block_scope); | 30061 | const tree = try sema.getAstTree(&block_scope); |
| 30172 | const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i); | 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,41 +30228,76 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: usize, may |
| 30338 | return enum_ty; | 30228 | return enum_ty; |
| 30339 | } | 30229 | } |
| 30340 | | 30230 | |
| 30341 | fn getBuiltin( | 30231 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 30342 | sema: *Sema, | 30232 | var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope); |
| 30343 | block: *Block, | 30233 | defer wip_captures.deinit(); |
| 30344 | src: LazySrcLoc, | 30234 | |
| 30345 | name: []const u8, | 30235 | var block: Block = .{ |
| 30346 | ) CompileError!Air.Inst.Ref { | 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 | const mod = sema.mod; | 30251 | const mod = sema.mod; |
| 30348 | const std_pkg = mod.main_pkg.table.get("std").?; | 30252 | const std_pkg = mod.main_pkg.table.get("std").?; |
| 30349 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; | 30253 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| 30350 | const opt_builtin_inst = try sema.namespaceLookupRef( | 30254 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 30351 | block, | 30255 | &block, |
| 30352 | src, | 30256 | src, |
| 30353 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, | 30257 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 30354 | "builtin", | 30258 | "builtin", |
| 30355 | ); | 30259 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 30356 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src); | 30260 | const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src); |
| 30357 | const builtin_ty = try sema.analyzeAsType(block, src, builtin_inst); | 30261 | const builtin_ty = sema.analyzeAsType(&block, src, builtin_inst) catch |err| switch (err) { |
| 30358 | const opt_ty_decl = try sema.namespaceLookup( | 30262 | error.AnalysisFail => std.debug.panic("std.builtin is corrupt", .{}), |
| 30359 | block, | 30263 | else => |e| return e, |
| | 30264 | }; |
| | 30265 | const opt_ty_decl = (try sema.namespaceLookup( |
| | 30266 | &block, |
| 30360 | src, | 30267 | src, |
| 30361 | builtin_ty.getNamespace().?, | 30268 | builtin_ty.getNamespace().?, |
| 30362 | name, | 30269 | name, |
| 30363 | ); | 30270 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 30364 | return sema.analyzeDeclVal(block, src, opt_ty_decl.?); | 30271 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); |
| 30365 | } | 30272 | } |
| 30366 | | 30273 | |
| 30367 | fn getBuiltinType( | 30274 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 30368 | sema: *Sema, | 30275 | const ty_inst = try sema.getBuiltin(name); |
| 30369 | block: *Block, | 30276 | |
| 30370 | src: LazySrcLoc, | 30277 | var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope); |
| 30371 | name: []const u8, | 30278 | defer wip_captures.deinit(); |
| 30372 | ) CompileError!Type { | 30279 | |
| 30373 | const ty_inst = try sema.getBuiltin(block, src, name); | 30280 | var block: Block = .{ |
| 30374 | const result_ty = try sema.analyzeAsType(block, src, ty_inst); | 30281 | .parent = null, |
| 30375 | try sema.resolveTypeFully(block, src, result_ty); // Should not fail | 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 | return result_ty; | 30301 | return result_ty; |
| 30377 | } | 30302 | } |
| 30378 | | 30303 | |
| ... | @@ -30381,12 +30306,7 @@ fn getBuiltinType( | ... | @@ -30381,12 +30306,7 @@ fn getBuiltinType( |
| 30381 | /// to get the answer. The one in `Type` is for calling during codegen and asserts | 30306 | /// to get the answer. The one in `Type` is for calling during codegen and asserts |
| 30382 | /// that the types are already resolved. | 30307 | /// that the types are already resolved. |
| 30383 | /// TODO assert the return value matches `ty.onePossibleValue` | 30308 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 30384 | pub fn typeHasOnePossibleValue( | 30309 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 30385 | sema: *Sema, | | |
| 30386 | block: *Block, | | |
| 30387 | src: LazySrcLoc, | | |
| 30388 | ty: Type, | | |
| 30389 | ) CompileError!?Value { | | |
| 30390 | switch (ty.tag()) { | 30310 | switch (ty.tag()) { |
| 30391 | .f16, | 30311 | .f16, |
| 30392 | .f32, | 30312 | .f32, |
| ... | @@ -30482,7 +30402,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30482,7 +30402,7 @@ pub fn typeHasOnePossibleValue( |
| 30482 | }, | 30402 | }, |
| 30483 | | 30403 | |
| 30484 | .@"struct" => { | 30404 | .@"struct" => { |
| 30485 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 30405 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30486 | const s = resolved_ty.castTag(.@"struct").?.data; | 30406 | const s = resolved_ty.castTag(.@"struct").?.data; |
| 30487 | for (s.fields.values()) |field, i| { | 30407 | for (s.fields.values()) |field, i| { |
| 30488 | if (field.is_comptime) continue; | 30408 | if (field.is_comptime) continue; |
| ... | @@ -30496,7 +30416,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30496,7 +30416,7 @@ pub fn typeHasOnePossibleValue( |
| 30496 | try sema.addFieldErrNote(resolved_ty, i, msg, "while checking this field", .{}); | 30416 | try sema.addFieldErrNote(resolved_ty, i, msg, "while checking this field", .{}); |
| 30497 | return sema.failWithOwnedErrorMsg(msg); | 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 | return null; | 30420 | return null; |
| 30501 | } | 30421 | } |
| 30502 | } | 30422 | } |
| ... | @@ -30508,14 +30428,14 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30508,14 +30428,14 @@ pub fn typeHasOnePossibleValue( |
| 30508 | for (tuple.values) |val, i| { | 30428 | for (tuple.values) |val, i| { |
| 30509 | const is_comptime = val.tag() != .unreachable_value; | 30429 | const is_comptime = val.tag() != .unreachable_value; |
| 30510 | if (is_comptime) continue; | 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 | return null; | 30432 | return null; |
| 30513 | } | 30433 | } |
| 30514 | return Value.initTag(.empty_struct_value); | 30434 | return Value.initTag(.empty_struct_value); |
| 30515 | }, | 30435 | }, |
| 30516 | | 30436 | |
| 30517 | .enum_numbered => { | 30437 | .enum_numbered => { |
| 30518 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 30438 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30519 | const enum_obj = resolved_ty.castTag(.enum_numbered).?.data; | 30439 | const enum_obj = resolved_ty.castTag(.enum_numbered).?.data; |
| 30520 | // An explicit tag type is always provided for enum_numbered. | 30440 | // An explicit tag type is always provided for enum_numbered. |
| 30521 | if (enum_obj.tag_ty.hasRuntimeBits()) { | 30441 | if (enum_obj.tag_ty.hasRuntimeBits()) { |
| ... | @@ -30532,7 +30452,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30532,7 +30452,7 @@ pub fn typeHasOnePossibleValue( |
| 30532 | } | 30452 | } |
| 30533 | }, | 30453 | }, |
| 30534 | .enum_full => { | 30454 | .enum_full => { |
| 30535 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 30455 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30536 | const enum_obj = resolved_ty.castTag(.enum_full).?.data; | 30456 | const enum_obj = resolved_ty.castTag(.enum_full).?.data; |
| 30537 | if (enum_obj.tag_ty.hasRuntimeBits()) { | 30457 | if (enum_obj.tag_ty.hasRuntimeBits()) { |
| 30538 | return null; | 30458 | return null; |
| ... | @@ -30548,7 +30468,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30548,7 +30468,7 @@ pub fn typeHasOnePossibleValue( |
| 30548 | } | 30468 | } |
| 30549 | }, | 30469 | }, |
| 30550 | .enum_simple => { | 30470 | .enum_simple => { |
| 30551 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); | 30471 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30552 | const enum_simple = resolved_ty.castTag(.enum_simple).?.data; | 30472 | const enum_simple = resolved_ty.castTag(.enum_simple).?.data; |
| 30553 | switch (enum_simple.fields.count()) { | 30473 | switch (enum_simple.fields.count()) { |
| 30554 | 0 => return Value.initTag(.unreachable_value), | 30474 | 0 => return Value.initTag(.unreachable_value), |
| ... | @@ -30558,16 +30478,16 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30558,16 +30478,16 @@ pub fn typeHasOnePossibleValue( |
| 30558 | }, | 30478 | }, |
| 30559 | .enum_nonexhaustive => { | 30479 | .enum_nonexhaustive => { |
| 30560 | const tag_ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty; | 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 | return Value.zero; | 30482 | return Value.zero; |
| 30563 | } else { | 30483 | } else { |
| 30564 | return null; | 30484 | return null; |
| 30565 | } | 30485 | } |
| 30566 | }, | 30486 | }, |
| 30567 | .@"union", .union_safety_tagged, .union_tagged => { | 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 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; | 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 | return null; | 30491 | return null; |
| 30572 | const fields = union_obj.fields.values(); | 30492 | const fields = union_obj.fields.values(); |
| 30573 | if (fields.len == 0) return Value.initTag(.unreachable_value); | 30493 | if (fields.len == 0) return Value.initTag(.unreachable_value); |
| ... | @@ -30582,7 +30502,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30582,7 +30502,7 @@ pub fn typeHasOnePossibleValue( |
| 30582 | try sema.addFieldErrNote(resolved_ty, 0, msg, "while checking this field", .{}); | 30502 | try sema.addFieldErrNote(resolved_ty, 0, msg, "while checking this field", .{}); |
| 30583 | return sema.failWithOwnedErrorMsg(msg); | 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 | return null; | 30506 | return null; |
| 30587 | // TODO make this not allocate. The function in `Type.onePossibleValue` | 30507 | // TODO make this not allocate. The function in `Type.onePossibleValue` |
| 30588 | // currently returns `empty_struct_value` and we should do that here too. | 30508 | // currently returns `empty_struct_value` and we should do that here too. |
| ... | @@ -30608,7 +30528,7 @@ pub fn typeHasOnePossibleValue( | ... | @@ -30608,7 +30528,7 @@ pub fn typeHasOnePossibleValue( |
| 30608 | .vector, .array, .array_u8 => { | 30528 | .vector, .array, .array_u8 => { |
| 30609 | if (ty.arrayLen() == 0) | 30529 | if (ty.arrayLen() == 0) |
| 30610 | return Value.initTag(.empty_array); | 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 | return Value.initTag(.the_only_possible_value); | 30532 | return Value.initTag(.the_only_possible_value); |
| 30613 | } | 30533 | } |
| 30614 | return null; | 30534 | return null; |
| ... | @@ -30799,7 +30719,7 @@ pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref { | ... | @@ -30799,7 +30719,7 @@ pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref { |
| 30799 | pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { | 30719 | pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { |
| 30800 | const fields = std.meta.fields(@TypeOf(extra)); | 30720 | const fields = std.meta.fields(@TypeOf(extra)); |
| 30801 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len); | 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 | pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { | 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,11 +30752,9 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| 30832 | | 30752 | |
| 30833 | fn isComptimeKnown( | 30753 | fn isComptimeKnown( |
| 30834 | sema: *Sema, | 30754 | sema: *Sema, |
| 30835 | block: *Block, | | |
| 30836 | src: LazySrcLoc, | | |
| 30837 | inst: Air.Inst.Ref, | 30755 | inst: Air.Inst.Ref, |
| 30838 | ) !bool { | 30756 | ) !bool { |
| 30839 | return (try sema.resolveMaybeUndefVal(block, src, inst)) != null; | 30757 | return (try sema.resolveMaybeUndefVal(inst)) != null; |
| 30840 | } | 30758 | } |
| 30841 | | 30759 | |
| 30842 | fn analyzeComptimeAlloc( | 30760 | fn analyzeComptimeAlloc( |
| ... | @@ -30844,10 +30762,9 @@ fn analyzeComptimeAlloc( | ... | @@ -30844,10 +30762,9 @@ fn analyzeComptimeAlloc( |
| 30844 | block: *Block, | 30762 | block: *Block, |
| 30845 | var_type: Type, | 30763 | var_type: Type, |
| 30846 | alignment: u32, | 30764 | alignment: u32, |
| 30847 | src: LazySrcLoc, | | |
| 30848 | ) CompileError!Air.Inst.Ref { | 30765 | ) CompileError!Air.Inst.Ref { |
| 30849 | // Needed to make an anon decl with type `var_type` (the `finish()` call below). | 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 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ | 30769 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 30853 | .pointee_type = var_type, | 30770 | .pointee_type = var_type, |
| ... | @@ -30855,7 +30772,7 @@ fn analyzeComptimeAlloc( | ... | @@ -30855,7 +30772,7 @@ fn analyzeComptimeAlloc( |
| 30855 | .@"align" = alignment, | 30772 | .@"align" = alignment, |
| 30856 | }); | 30773 | }); |
| 30857 | | 30774 | |
| 30858 | var anon_decl = try block.startAnonDecl(src); | 30775 | var anon_decl = try block.startAnonDecl(); |
| 30859 | defer anon_decl.deinit(); | 30776 | defer anon_decl.deinit(); |
| 30860 | | 30777 | |
| 30861 | const decl_index = try anon_decl.finish( | 30778 | const decl_index = try anon_decl.finish( |
| ... | @@ -30996,14 +30913,14 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value | ... | @@ -30996,14 +30913,14 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value |
| 30996 | return DerefResult{ .needed_well_defined = load_ty }; | 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 | // Try the smaller bit-cast first, since that's more efficient than using the larger `parent` | 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 | return DerefResult{ .val = try sema.bitCastVal(block, src, tv.val, tv.ty, load_ty, 0) }; | 30920 | return DerefResult{ .val = try sema.bitCastVal(block, src, tv.val, tv.ty, load_ty, 0) }; |
| 31004 | | 30921 | |
| 31005 | // If that fails, try to bit-cast from the largest parent value with a well-defined layout | 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 | return DerefResult{ .val = try sema.bitCastVal(block, src, parent.tv.val, parent.tv.ty, load_ty, parent.byte_offset) }; | 30924 | return DerefResult{ .val = try sema.bitCastVal(block, src, parent.tv.val, parent.tv.ty, load_ty, parent.byte_offset) }; |
| 31008 | | 30925 | |
| 31009 | if (deref.ty_without_well_defined_layout) |bad_ty| { | 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,10 +30948,8 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError |
| 31031 | /// This logic must be kept in sync with `Type.isPtrLikeOptional`. | 30948 | /// This logic must be kept in sync with `Type.isPtrLikeOptional`. |
| 31032 | fn typePtrOrOptionalPtrTy( | 30949 | fn typePtrOrOptionalPtrTy( |
| 31033 | sema: *Sema, | 30950 | sema: *Sema, |
| 31034 | block: *Block, | | |
| 31035 | ty: Type, | 30951 | ty: Type, |
| 31036 | buf: *Type.Payload.ElemType, | 30952 | buf: *Type.Payload.ElemType, |
| 31037 | src: LazySrcLoc, | | |
| 31038 | ) !?Type { | 30953 | ) !?Type { |
| 31039 | switch (ty.tag()) { | 30954 | switch (ty.tag()) { |
| 31040 | .optional_single_const_pointer, | 30955 | .optional_single_const_pointer, |
| ... | @@ -31073,7 +30988,7 @@ fn typePtrOrOptionalPtrTy( | ... | @@ -31073,7 +30988,7 @@ fn typePtrOrOptionalPtrTy( |
| 31073 | if (info.@"allowzero") return null; | 30988 | if (info.@"allowzero") return null; |
| 31074 | | 30989 | |
| 31075 | // optionals of zero sized types behave like bools, not pointers | 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 | return null; | 30992 | return null; |
| 31078 | } | 30993 | } |
| 31079 | | 30994 | |
| ... | @@ -31090,7 +31005,7 @@ fn typePtrOrOptionalPtrTy( | ... | @@ -31090,7 +31005,7 @@ fn typePtrOrOptionalPtrTy( |
| 31090 | /// This function returns false negatives when structs and unions are having their | 31005 | /// This function returns false negatives when structs and unions are having their |
| 31091 | /// field types resolved. | 31006 | /// field types resolved. |
| 31092 | /// TODO assert the return value matches `ty.comptimeOnly` | 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 | /// elsewhere in value.zig | 31009 | /// elsewhere in value.zig |
| 31095 | pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | 31010 | pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31096 | return switch (ty.tag()) { | 31011 | return switch (ty.tag()) { |
| ... | @@ -31287,33 +31202,28 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -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 { | 31205 | pub fn typeHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool { |
| 31291 | return ty.hasRuntimeBitsAdvanced(false, sema.kit(block, src)); | 31206 | return ty.hasRuntimeBitsAdvanced(false, sema); |
| 31292 | } | 31207 | } |
| 31293 | | 31208 | |
| 31294 | fn typeAbiSize(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !u64 { | 31209 | fn typeAbiSize(sema: *Sema, ty: Type) !u64 { |
| 31295 | try sema.resolveTypeLayout(block, src, ty); | 31210 | try sema.resolveTypeLayout(ty); |
| 31296 | const target = sema.mod.getTarget(); | 31211 | const target = sema.mod.getTarget(); |
| 31297 | return ty.abiSize(target); | 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 | const target = sema.mod.getTarget(); | 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 | /// Not valid to call for packed unions. | 31220 | /// Not valid to call for packed unions. |
| 31306 | /// Keep implementation in sync with `Module.Union.Field.normalAlignment`. | 31221 | /// Keep implementation in sync with `Module.Union.Field.normalAlignment`. |
| 31307 | fn unionFieldAlignment( | 31222 | fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 { |
| 31308 | sema: *Sema, | | |
| 31309 | block: *Block, | | |
| 31310 | src: LazySrcLoc, | | |
| 31311 | field: Module.Union.Field, | | |
| 31312 | ) !u32 { | | |
| 31313 | if (field.ty.zigTypeTag() == .NoReturn) { | 31223 | if (field.ty.zigTypeTag() == .NoReturn) { |
| 31314 | return @as(u32, 0); | 31224 | return @as(u32, 0); |
| 31315 | } else if (field.abi_align == 0) { | 31225 | } else if (field.abi_align == 0) { |
| 31316 | return sema.typeAbiAlignment(block, src, field.ty); | 31226 | return sema.typeAbiAlignment(field.ty); |
| 31317 | } else { | 31227 | } else { |
| 31318 | return field.abi_align; | 31228 | return field.abi_align; |
| 31319 | } | 31229 | } |
| ... | @@ -31342,7 +31252,7 @@ fn unionFieldIndex( | ... | @@ -31342,7 +31252,7 @@ fn unionFieldIndex( |
| 31342 | field_name: []const u8, | 31252 | field_name: []const u8, |
| 31343 | field_src: LazySrcLoc, | 31253 | field_src: LazySrcLoc, |
| 31344 | ) !u32 { | 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 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 31256 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 31347 | const field_index_usize = union_obj.fields.getIndex(field_name) orelse | 31257 | const field_index_usize = union_obj.fields.getIndex(field_name) orelse |
| 31348 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 31258 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| ... | @@ -31356,7 +31266,7 @@ fn structFieldIndex( | ... | @@ -31356,7 +31266,7 @@ fn structFieldIndex( |
| 31356 | field_name: []const u8, | 31266 | field_name: []const u8, |
| 31357 | field_src: LazySrcLoc, | 31267 | field_src: LazySrcLoc, |
| 31358 | ) !u32 { | 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 | if (struct_ty.isAnonStruct()) { | 31270 | if (struct_ty.isAnonStruct()) { |
| 31361 | return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src); | 31271 | return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src); |
| 31362 | } else { | 31272 | } else { |
| ... | @@ -31385,34 +31295,30 @@ fn anonStructFieldIndex( | ... | @@ -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 | fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { | 31298 | fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { |
| 31393 | const inst_ref = try sema.addType(ty); | 31299 | const inst_ref = try sema.addType(ty); |
| 31394 | try sema.types_to_resolve.append(sema.gpa, inst_ref); | 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 | if (ty.zigTypeTag() == .Vector) { | 31304 | if (ty.zigTypeTag() == .Vector) { |
| 31399 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31305 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31400 | for (result_data) |*scalar, i| { | 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 | return Value.Tag.aggregate.create(sema.arena, result_data); | 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 | // TODO is this a performance issue? maybe we should try the operation without | 31315 | // TODO is this a performance issue? maybe we should try the operation without |
| 31410 | // resorting to BigInt first. | 31316 | // resorting to BigInt first. |
| 31411 | var lhs_space: Value.BigIntSpace = undefined; | 31317 | var lhs_space: Value.BigIntSpace = undefined; |
| 31412 | var rhs_space: Value.BigIntSpace = undefined; | 31318 | var rhs_space: Value.BigIntSpace = undefined; |
| 31413 | const target = sema.mod.getTarget(); | 31319 | const target = sema.mod.getTarget(); |
| 31414 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); | 31320 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31415 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); | 31321 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31416 | const limbs = try sema.arena.alloc( | 31322 | const limbs = try sema.arena.alloc( |
| 31417 | std.math.big.Limb, | 31323 | std.math.big.Limb, |
| 31418 | std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1, | 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,8 +31331,6 @@ fn intAddScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va |
| 31425 | /// Supports both (vectors of) floats and ints; handles undefined scalars. | 31331 | /// Supports both (vectors of) floats and ints; handles undefined scalars. |
| 31426 | fn numberAddWrap( | 31332 | fn numberAddWrap( |
| 31427 | sema: *Sema, | 31333 | sema: *Sema, |
| 31428 | block: *Block, | | |
| 31429 | src: LazySrcLoc, | | |
| 31430 | lhs: Value, | 31334 | lhs: Value, |
| 31431 | rhs: Value, | 31335 | rhs: Value, |
| 31432 | ty: Type, | 31336 | ty: Type, |
| ... | @@ -31434,18 +31338,16 @@ fn numberAddWrap( | ... | @@ -31434,18 +31338,16 @@ fn numberAddWrap( |
| 31434 | if (ty.zigTypeTag() == .Vector) { | 31338 | if (ty.zigTypeTag() == .Vector) { |
| 31435 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31339 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31436 | for (result_data) |*scalar, i| { | 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 | return Value.Tag.aggregate.create(sema.arena, result_data); | 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 | /// Supports both floats and ints; handles undefined. | 31348 | /// Supports both floats and ints; handles undefined. |
| 31445 | fn numberAddWrapScalar( | 31349 | fn numberAddWrapScalar( |
| 31446 | sema: *Sema, | 31350 | sema: *Sema, |
| 31447 | block: *Block, | | |
| 31448 | src: LazySrcLoc, | | |
| 31449 | lhs: Value, | 31351 | lhs: Value, |
| 31450 | rhs: Value, | 31352 | rhs: Value, |
| 31451 | ty: Type, | 31353 | ty: Type, |
| ... | @@ -31453,21 +31355,19 @@ fn numberAddWrapScalar( | ... | @@ -31453,21 +31355,19 @@ fn numberAddWrapScalar( |
| 31453 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 31355 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 31454 | | 31356 | |
| 31455 | if (ty.zigTypeTag() == .ComptimeInt) { | 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 | if (ty.isAnyFloat()) { | 31361 | if (ty.isAnyFloat()) { |
| 31460 | return sema.floatAdd(lhs, rhs, ty); | 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 | return overflow_result.wrapped_result; | 31366 | return overflow_result.wrapped_result; |
| 31465 | } | 31367 | } |
| 31466 | | 31368 | |
| 31467 | fn intSub( | 31369 | fn intSub( |
| 31468 | sema: *Sema, | 31370 | sema: *Sema, |
| 31469 | block: *Block, | | |
| 31470 | src: LazySrcLoc, | | |
| 31471 | lhs: Value, | 31371 | lhs: Value, |
| 31472 | rhs: Value, | 31372 | rhs: Value, |
| 31473 | ty: Type, | 31373 | ty: Type, |
| ... | @@ -31475,21 +31375,21 @@ fn intSub( | ... | @@ -31475,21 +31375,21 @@ fn intSub( |
| 31475 | if (ty.zigTypeTag() == .Vector) { | 31375 | if (ty.zigTypeTag() == .Vector) { |
| 31476 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31376 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31477 | for (result_data) |*scalar, i| { | 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 | return Value.Tag.aggregate.create(sema.arena, result_data); | 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 | // TODO is this a performance issue? maybe we should try the operation without | 31386 | // TODO is this a performance issue? maybe we should try the operation without |
| 31487 | // resorting to BigInt first. | 31387 | // resorting to BigInt first. |
| 31488 | var lhs_space: Value.BigIntSpace = undefined; | 31388 | var lhs_space: Value.BigIntSpace = undefined; |
| 31489 | var rhs_space: Value.BigIntSpace = undefined; | 31389 | var rhs_space: Value.BigIntSpace = undefined; |
| 31490 | const target = sema.mod.getTarget(); | 31390 | const target = sema.mod.getTarget(); |
| 31491 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); | 31391 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31492 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); | 31392 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31493 | const limbs = try sema.arena.alloc( | 31393 | const limbs = try sema.arena.alloc( |
| 31494 | std.math.big.Limb, | 31394 | std.math.big.Limb, |
| 31495 | std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1, | 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,8 +31402,6 @@ fn intSubScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va |
| 31502 | /// Supports both (vectors of) floats and ints; handles undefined scalars. | 31402 | /// Supports both (vectors of) floats and ints; handles undefined scalars. |
| 31503 | fn numberSubWrap( | 31403 | fn numberSubWrap( |
| 31504 | sema: *Sema, | 31404 | sema: *Sema, |
| 31505 | block: *Block, | | |
| 31506 | src: LazySrcLoc, | | |
| 31507 | lhs: Value, | 31405 | lhs: Value, |
| 31508 | rhs: Value, | 31406 | rhs: Value, |
| 31509 | ty: Type, | 31407 | ty: Type, |
| ... | @@ -31511,18 +31409,16 @@ fn numberSubWrap( | ... | @@ -31511,18 +31409,16 @@ fn numberSubWrap( |
| 31511 | if (ty.zigTypeTag() == .Vector) { | 31409 | if (ty.zigTypeTag() == .Vector) { |
| 31512 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31410 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31513 | for (result_data) |*scalar, i| { | 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 | return Value.Tag.aggregate.create(sema.arena, result_data); | 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 | /// Supports both floats and ints; handles undefined. | 31419 | /// Supports both floats and ints; handles undefined. |
| 31522 | fn numberSubWrapScalar( | 31420 | fn numberSubWrapScalar( |
| 31523 | sema: *Sema, | 31421 | sema: *Sema, |
| 31524 | block: *Block, | | |
| 31525 | src: LazySrcLoc, | | |
| 31526 | lhs: Value, | 31422 | lhs: Value, |
| 31527 | rhs: Value, | 31423 | rhs: Value, |
| 31528 | ty: Type, | 31424 | ty: Type, |
| ... | @@ -31530,14 +31426,14 @@ fn numberSubWrapScalar( | ... | @@ -31530,14 +31426,14 @@ fn numberSubWrapScalar( |
| 31530 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 31426 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 31531 | | 31427 | |
| 31532 | if (ty.zigTypeTag() == .ComptimeInt) { | 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 | if (ty.isAnyFloat()) { | 31432 | if (ty.isAnyFloat()) { |
| 31537 | return sema.floatSub(lhs, rhs, ty); | 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 | return overflow_result.wrapped_result; | 31437 | return overflow_result.wrapped_result; |
| 31542 | } | 31438 | } |
| 31543 | | 31439 | |
| ... | @@ -31649,8 +31545,6 @@ fn floatSubScalar( | ... | @@ -31649,8 +31545,6 @@ fn floatSubScalar( |
| 31649 | | 31545 | |
| 31650 | fn intSubWithOverflow( | 31546 | fn intSubWithOverflow( |
| 31651 | sema: *Sema, | 31547 | sema: *Sema, |
| 31652 | block: *Block, | | |
| 31653 | src: LazySrcLoc, | | |
| 31654 | lhs: Value, | 31548 | lhs: Value, |
| 31655 | rhs: Value, | 31549 | rhs: Value, |
| 31656 | ty: Type, | 31550 | ty: Type, |
| ... | @@ -31659,7 +31553,7 @@ fn intSubWithOverflow( | ... | @@ -31659,7 +31553,7 @@ fn intSubWithOverflow( |
| 31659 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31553 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31660 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31554 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 31661 | for (result_data) |*scalar, i| { | 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 | overflowed_data[i] = of_math_result.overflowed; | 31557 | overflowed_data[i] = of_math_result.overflowed; |
| 31664 | scalar.* = of_math_result.wrapped_result; | 31558 | scalar.* = of_math_result.wrapped_result; |
| 31665 | } | 31559 | } |
| ... | @@ -31668,13 +31562,11 @@ fn intSubWithOverflow( | ... | @@ -31668,13 +31562,11 @@ fn intSubWithOverflow( |
| 31668 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), | 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 | fn intSubWithOverflowScalar( | 31568 | fn intSubWithOverflowScalar( |
| 31675 | sema: *Sema, | 31569 | sema: *Sema, |
| 31676 | block: *Block, | | |
| 31677 | src: LazySrcLoc, | | |
| 31678 | lhs: Value, | 31570 | lhs: Value, |
| 31679 | rhs: Value, | 31571 | rhs: Value, |
| 31680 | ty: Type, | 31572 | ty: Type, |
| ... | @@ -31684,8 +31576,8 @@ fn intSubWithOverflowScalar( | ... | @@ -31684,8 +31576,8 @@ fn intSubWithOverflowScalar( |
| 31684 | | 31576 | |
| 31685 | var lhs_space: Value.BigIntSpace = undefined; | 31577 | var lhs_space: Value.BigIntSpace = undefined; |
| 31686 | var rhs_space: Value.BigIntSpace = undefined; | 31578 | var rhs_space: Value.BigIntSpace = undefined; |
| 31687 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); | 31579 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 31688 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); | 31580 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 31689 | const limbs = try sema.arena.alloc( | 31581 | const limbs = try sema.arena.alloc( |
| 31690 | std.math.big.Limb, | 31582 | std.math.big.Limb, |
| 31691 | std.math.big.int.calcTwosCompLimbCount(info.bits), | 31583 | std.math.big.int.calcTwosCompLimbCount(info.bits), |
| ... | @@ -31774,7 +31666,7 @@ fn floatToIntScalar( | ... | @@ -31774,7 +31666,7 @@ fn floatToIntScalar( |
| 31774 | else | 31666 | else |
| 31775 | try Value.Tag.int_big_positive.create(sema.arena, result_limbs); | 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 | return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{ | 31670 | return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{ |
| 31779 | val.fmtValue(float_ty, sema.mod), int_ty.fmt(sema.mod), | 31671 | val.fmtValue(float_ty, sema.mod), int_ty.fmt(sema.mod), |
| 31780 | }); | 31672 | }); |
| ... | @@ -31788,8 +31680,6 @@ fn floatToIntScalar( | ... | @@ -31788,8 +31680,6 @@ fn floatToIntScalar( |
| 31788 | /// If provided, `vector_index` reports the first element that failed the range check. | 31680 | /// If provided, `vector_index` reports the first element that failed the range check. |
| 31789 | fn intFitsInType( | 31681 | fn intFitsInType( |
| 31790 | sema: *Sema, | 31682 | sema: *Sema, |
| 31791 | block: *Block, | | |
| 31792 | src: LazySrcLoc, | | |
| 31793 | val: Value, | 31683 | val: Value, |
| 31794 | ty: Type, | 31684 | ty: Type, |
| 31795 | vector_index: ?*usize, | 31685 | vector_index: ?*usize, |
| ... | @@ -31821,7 +31711,7 @@ fn intFitsInType( | ... | @@ -31821,7 +31711,7 @@ fn intFitsInType( |
| 31821 | const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed); | 31711 | const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed); |
| 31822 | // If it is u16 or bigger we know the alignment fits without resolving it. | 31712 | // If it is u16 or bigger we know the alignment fits without resolving it. |
| 31823 | if (info.bits >= max_needed_bits) return true; | 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 | if (x == 0) return true; | 31715 | if (x == 0) return true; |
| 31826 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); | 31716 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); |
| 31827 | return info.bits >= actual_needed_bits; | 31717 | return info.bits >= actual_needed_bits; |
| ... | @@ -31835,7 +31725,7 @@ fn intFitsInType( | ... | @@ -31835,7 +31725,7 @@ fn intFitsInType( |
| 31835 | const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed); | 31725 | const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed); |
| 31836 | // If it is u64 or bigger we know the size fits without resolving it. | 31726 | // If it is u64 or bigger we know the size fits without resolving it. |
| 31837 | if (info.bits >= max_needed_bits) return true; | 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 | if (x == 0) return true; | 31729 | if (x == 0) return true; |
| 31840 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); | 31730 | const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); |
| 31841 | return info.bits >= actual_needed_bits; | 31731 | return info.bits >= actual_needed_bits; |
| ... | @@ -31863,7 +31753,7 @@ fn intFitsInType( | ... | @@ -31863,7 +31753,7 @@ fn intFitsInType( |
| 31863 | if (info.signedness == .unsigned and x < 0) | 31753 | if (info.signedness == .unsigned and x < 0) |
| 31864 | return false; | 31754 | return false; |
| 31865 | var buffer: Value.BigIntSpace = undefined; | 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 | .ComptimeInt => return true, | 31758 | .ComptimeInt => return true, |
| 31869 | else => unreachable, | 31759 | else => unreachable, |
| ... | @@ -31911,7 +31801,7 @@ fn intFitsInType( | ... | @@ -31911,7 +31801,7 @@ fn intFitsInType( |
| 31911 | .aggregate => { | 31801 | .aggregate => { |
| 31912 | assert(ty.zigTypeTag() == .Vector); | 31802 | assert(ty.zigTypeTag() == .Vector); |
| 31913 | for (val.castTag(.aggregate).?.data) |elem, i| { | 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 | if (vector_index) |some| some.* = i; | 31805 | if (vector_index) |some| some.* = i; |
| 31916 | return false; | 31806 | return false; |
| 31917 | } | 31807 | } |
| ... | @@ -31925,37 +31815,33 @@ fn intFitsInType( | ... | @@ -31925,37 +31815,33 @@ fn intFitsInType( |
| 31925 | | 31815 | |
| 31926 | fn intInRange( | 31816 | fn intInRange( |
| 31927 | sema: *Sema, | 31817 | sema: *Sema, |
| 31928 | block: *Block, | | |
| 31929 | src: LazySrcLoc, | | |
| 31930 | tag_ty: Type, | 31818 | tag_ty: Type, |
| 31931 | int_val: Value, | 31819 | int_val: Value, |
| 31932 | end: usize, | 31820 | end: usize, |
| 31933 | ) !bool { | 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 | var end_payload: Value.Payload.U64 = .{ | 31823 | var end_payload: Value.Payload.U64 = .{ |
| 31936 | .base = .{ .tag = .int_u64 }, | 31824 | .base = .{ .tag = .int_u64 }, |
| 31937 | .data = end, | 31825 | .data = end, |
| 31938 | }; | 31826 | }; |
| 31939 | const end_val = Value.initPayload(&end_payload.base); | 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 | return true; | 31829 | return true; |
| 31942 | } | 31830 | } |
| 31943 | | 31831 | |
| 31944 | /// Asserts the type is an enum. | 31832 | /// Asserts the type is an enum. |
| 31945 | fn enumHasInt( | 31833 | fn enumHasInt( |
| 31946 | sema: *Sema, | 31834 | sema: *Sema, |
| 31947 | block: *Block, | | |
| 31948 | src: LazySrcLoc, | | |
| 31949 | ty: Type, | 31835 | ty: Type, |
| 31950 | int: Value, | 31836 | int: Value, |
| 31951 | ) CompileError!bool { | 31837 | ) CompileError!bool { |
| 31952 | switch (ty.tag()) { | 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 | .enum_full => { | 31840 | .enum_full => { |
| 31955 | const enum_full = ty.castTag(.enum_full).?.data; | 31841 | const enum_full = ty.castTag(.enum_full).?.data; |
| 31956 | const tag_ty = enum_full.tag_ty; | 31842 | const tag_ty = enum_full.tag_ty; |
| 31957 | if (enum_full.values.count() == 0) { | 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 | } else { | 31845 | } else { |
| 31960 | return enum_full.values.containsContext(int, .{ | 31846 | return enum_full.values.containsContext(int, .{ |
| 31961 | .ty = tag_ty, | 31847 | .ty = tag_ty, |
| ... | @@ -31967,7 +31853,7 @@ fn enumHasInt( | ... | @@ -31967,7 +31853,7 @@ fn enumHasInt( |
| 31967 | const enum_obj = ty.castTag(.enum_numbered).?.data; | 31853 | const enum_obj = ty.castTag(.enum_numbered).?.data; |
| 31968 | const tag_ty = enum_obj.tag_ty; | 31854 | const tag_ty = enum_obj.tag_ty; |
| 31969 | if (enum_obj.values.count() == 0) { | 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 | } else { | 31857 | } else { |
| 31972 | return enum_obj.values.containsContext(int, .{ | 31858 | return enum_obj.values.containsContext(int, .{ |
| 31973 | .ty = tag_ty, | 31859 | .ty = tag_ty, |
| ... | @@ -31984,7 +31870,7 @@ fn enumHasInt( | ... | @@ -31984,7 +31870,7 @@ fn enumHasInt( |
| 31984 | .data = bits, | 31870 | .data = bits, |
| 31985 | }; | 31871 | }; |
| 31986 | const tag_ty = Type.initPayload(&buffer.base); | 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 | .atomic_order, | 31875 | .atomic_order, |
| 31990 | .atomic_rmw_op, | 31876 | .atomic_rmw_op, |
| ... | @@ -32004,8 +31890,6 @@ fn enumHasInt( | ... | @@ -32004,8 +31890,6 @@ fn enumHasInt( |
| 32004 | | 31890 | |
| 32005 | fn intAddWithOverflow( | 31891 | fn intAddWithOverflow( |
| 32006 | sema: *Sema, | 31892 | sema: *Sema, |
| 32007 | block: *Block, | | |
| 32008 | src: LazySrcLoc, | | |
| 32009 | lhs: Value, | 31893 | lhs: Value, |
| 32010 | rhs: Value, | 31894 | rhs: Value, |
| 32011 | ty: Type, | 31895 | ty: Type, |
| ... | @@ -32014,7 +31898,7 @@ fn intAddWithOverflow( | ... | @@ -32014,7 +31898,7 @@ fn intAddWithOverflow( |
| 32014 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31898 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32015 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31899 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32016 | for (result_data) |*scalar, i| { | 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 | overflowed_data[i] = of_math_result.overflowed; | 31902 | overflowed_data[i] = of_math_result.overflowed; |
| 32019 | scalar.* = of_math_result.wrapped_result; | 31903 | scalar.* = of_math_result.wrapped_result; |
| 32020 | } | 31904 | } |
| ... | @@ -32023,13 +31907,11 @@ fn intAddWithOverflow( | ... | @@ -32023,13 +31907,11 @@ fn intAddWithOverflow( |
| 32023 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), | 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 | fn intAddWithOverflowScalar( | 31913 | fn intAddWithOverflowScalar( |
| 32030 | sema: *Sema, | 31914 | sema: *Sema, |
| 32031 | block: *Block, | | |
| 32032 | src: LazySrcLoc, | | |
| 32033 | lhs: Value, | 31915 | lhs: Value, |
| 32034 | rhs: Value, | 31916 | rhs: Value, |
| 32035 | ty: Type, | 31917 | ty: Type, |
| ... | @@ -32039,8 +31921,8 @@ fn intAddWithOverflowScalar( | ... | @@ -32039,8 +31921,8 @@ fn intAddWithOverflowScalar( |
| 32039 | | 31921 | |
| 32040 | var lhs_space: Value.BigIntSpace = undefined; | 31922 | var lhs_space: Value.BigIntSpace = undefined; |
| 32041 | var rhs_space: Value.BigIntSpace = undefined; | 31923 | var rhs_space: Value.BigIntSpace = undefined; |
| 32042 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src)); | 31924 | const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema); |
| 32043 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src)); | 31925 | const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema); |
| 32044 | const limbs = try sema.arena.alloc( | 31926 | const limbs = try sema.arena.alloc( |
| 32045 | std.math.big.Limb, | 31927 | std.math.big.Limb, |
| 32046 | std.math.big.int.calcTwosCompLimbCount(info.bits), | 31928 | std.math.big.int.calcTwosCompLimbCount(info.bits), |
| ... | @@ -32060,8 +31942,6 @@ fn intAddWithOverflowScalar( | ... | @@ -32060,8 +31942,6 @@ fn intAddWithOverflowScalar( |
| 32060 | /// Note that `!compareAll(.eq, ...) != compareAll(.neq, ...)` | 31942 | /// Note that `!compareAll(.eq, ...) != compareAll(.neq, ...)` |
| 32061 | fn compareAll( | 31943 | fn compareAll( |
| 32062 | sema: *Sema, | 31944 | sema: *Sema, |
| 32063 | block: *Block, | | |
| 32064 | src: LazySrcLoc, | | |
| 32065 | lhs: Value, | 31945 | lhs: Value, |
| 32066 | op: std.math.CompareOperator, | 31946 | op: std.math.CompareOperator, |
| 32067 | rhs: Value, | 31947 | rhs: Value, |
| ... | @@ -32070,48 +31950,42 @@ fn compareAll( | ... | @@ -32070,48 +31950,42 @@ fn compareAll( |
| 32070 | if (ty.zigTypeTag() == .Vector) { | 31950 | if (ty.zigTypeTag() == .Vector) { |
| 32071 | var i: usize = 0; | 31951 | var i: usize = 0; |
| 32072 | while (i < ty.vectorLen()) : (i += 1) { | 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 | return false; | 31954 | return false; |
| 32075 | } | 31955 | } |
| 32076 | } | 31956 | } |
| 32077 | return true; | 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 | /// Asserts the values are comparable. Both operands have type `ty`. | 31962 | /// Asserts the values are comparable. Both operands have type `ty`. |
| 32083 | fn compareScalar( | 31963 | fn compareScalar( |
| 32084 | sema: *Sema, | 31964 | sema: *Sema, |
| 32085 | block: *Block, | | |
| 32086 | src: LazySrcLoc, | | |
| 32087 | lhs: Value, | 31965 | lhs: Value, |
| 32088 | op: std.math.CompareOperator, | 31966 | op: std.math.CompareOperator, |
| 32089 | rhs: Value, | 31967 | rhs: Value, |
| 32090 | ty: Type, | 31968 | ty: Type, |
| 32091 | ) CompileError!bool { | 31969 | ) CompileError!bool { |
| 32092 | switch (op) { | 31970 | switch (op) { |
| 32093 | .eq => return sema.valuesEqual(block, src, lhs, rhs, ty), | 31971 | .eq => return sema.valuesEqual(lhs, rhs, ty), |
| 32094 | .neq => return !(try sema.valuesEqual(block, src, lhs, rhs, ty)), | 31972 | .neq => return !(try sema.valuesEqual(lhs, rhs, ty)), |
| 32095 | else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema.kit(block, src)), | 31973 | else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema), |
| 32096 | } | 31974 | } |
| 32097 | } | 31975 | } |
| 32098 | | 31976 | |
| 32099 | fn valuesEqual( | 31977 | fn valuesEqual( |
| 32100 | sema: *Sema, | 31978 | sema: *Sema, |
| 32101 | block: *Block, | | |
| 32102 | src: LazySrcLoc, | | |
| 32103 | lhs: Value, | 31979 | lhs: Value, |
| 32104 | rhs: Value, | 31980 | rhs: Value, |
| 32105 | ty: Type, | 31981 | ty: Type, |
| 32106 | ) CompileError!bool { | 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 | /// Asserts the values are comparable vectors of type `ty`. | 31986 | /// Asserts the values are comparable vectors of type `ty`. |
| 32111 | fn compareVector( | 31987 | fn compareVector( |
| 32112 | sema: *Sema, | 31988 | sema: *Sema, |
| 32113 | block: *Block, | | |
| 32114 | src: LazySrcLoc, | | |
| 32115 | lhs: Value, | 31989 | lhs: Value, |
| 32116 | op: std.math.CompareOperator, | 31990 | op: std.math.CompareOperator, |
| 32117 | rhs: Value, | 31991 | rhs: Value, |
| ... | @@ -32120,7 +31994,7 @@ fn compareVector( | ... | @@ -32120,7 +31994,7 @@ fn compareVector( |
| 32120 | assert(ty.zigTypeTag() == .Vector); | 31994 | assert(ty.zigTypeTag() == .Vector); |
| 32121 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 31995 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32122 | for (result_data) |*scalar, i| { | 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 | scalar.* = Value.makeBool(res_bool); | 31998 | scalar.* = Value.makeBool(res_bool); |
| 32125 | } | 31999 | } |
| 32126 | return Value.Tag.aggregate.create(sema.arena, result_data); | 32000 | return Value.Tag.aggregate.create(sema.arena, result_data); |