| ... | @@ -15263,17 +15263,29 @@ fn analyzeArithmetic( | ... | @@ -15263,17 +15263,29 @@ fn analyzeArithmetic( |
| 15263 | if (zir_tag != .sub) { | 15263 | if (zir_tag != .sub) { |
| 15264 | return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction"); | 15264 | return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction"); |
| 15265 | } | 15265 | } |
| 15266 | if (!lhs_ty.childType(zcu).eql(rhs_ty.childType(zcu), zcu)) { | 15266 | |
| | 15267 | // MLUGG TODO: these semantics are insane and matching them is causing my soul to fragment into a thousand pieces |
| | 15268 | const lhs_elem_ty = ty: { |
| | 15269 | const ptr_elem_ty = lhs_ty.childType(zcu); |
| | 15270 | if (lhs_ty.ptrSize(zcu) == .one and ptr_elem_ty.isArrayOrVector(zcu)) break :ty ptr_elem_ty.childType(zcu); |
| | 15271 | break :ty ptr_elem_ty; |
| | 15272 | }; |
| | 15273 | const rhs_elem_ty = ty: { |
| | 15274 | const ptr_elem_ty = rhs_ty.childType(zcu); |
| | 15275 | if (rhs_ty.ptrSize(zcu) == .one and ptr_elem_ty.isArrayOrVector(zcu)) break :ty ptr_elem_ty.childType(zcu); |
| | 15276 | break :ty ptr_elem_ty; |
| | 15277 | }; |
| | 15278 | if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) { |
| 15267 | return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{ | 15279 | return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{ |
| 15268 | lhs_ty.fmt(pt), rhs_ty.fmt(pt), | 15280 | lhs_ty.fmt(pt), rhs_ty.fmt(pt), |
| 15269 | }); | 15281 | }); |
| 15270 | } | 15282 | } |
| 15271 | | 15283 | |
| 15272 | try sema.ensureLayoutResolved(lhs_ty.childType(zcu), src, .ptr_offset); | 15284 | try sema.ensureLayoutResolved(lhs_elem_ty, src, .ptr_offset); |
| 15273 | const elem_size = lhs_ty.childType(zcu).abiSize(zcu); | 15285 | const elem_size = lhs_elem_ty.abiSize(zcu); |
| 15274 | if (elem_size == 0) { | 15286 | if (elem_size == 0) { |
| 15275 | return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{ | 15287 | return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{ |
| 15276 | lhs_ty.childType(zcu).fmt(pt), | 15288 | lhs_elem_ty.fmt(pt), |
| 15277 | }); | 15289 | }); |
| 15278 | } | 15290 | } |
| 15279 | | 15291 | |
| ... | @@ -16293,20 +16305,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16293,20 +16305,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16293 | const func_ty_info = zcu.typeToFunc(ty).?; | 16305 | const func_ty_info = zcu.typeToFunc(ty).?; |
| 16294 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | 16306 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); |
| 16295 | var func_is_generic = false; | 16307 | var func_is_generic = false; |
| 16296 | for (param_vals, 0..) |*param_val, i| { | 16308 | |
| 16297 | const param_ty = func_ty_info.param_types.get(ip)[i]; | 16309 | for (param_vals, 0..) |*param_val, param_index| { |
| | 16310 | const param_ty = func_ty_info.param_types.get(ip)[param_index]; |
| 16298 | const is_generic = param_ty == .generic_poison_type; | 16311 | const is_generic = param_ty == .generic_poison_type; |
| 16299 | if (is_generic or Type.fromInterned(param_ty).comptimeOnly(zcu)) func_is_generic = true; | 16312 | const is_noalias, const is_comptime = flags: { |
| | 16313 | const i = std.math.cast(u5, param_index) orelse break :flags .{ false, false }; |
| | 16314 | break :flags .{ func_ty_info.paramIsNoalias(i), func_ty_info.paramIsComptime(i) }; |
| | 16315 | }; |
| | 16316 | |
| | 16317 | if (is_generic or is_comptime or Type.fromInterned(param_ty).comptimeOnly(zcu)) { |
| | 16318 | func_is_generic = true; |
| | 16319 | } |
| | 16320 | |
| 16300 | const param_ty_val = try pt.intern(.{ .opt = .{ | 16321 | const param_ty_val = try pt.intern(.{ .opt = .{ |
| 16301 | .ty = try pt.intern(.{ .opt_type = .type_type }), | 16322 | .ty = try pt.intern(.{ .opt_type = .type_type }), |
| 16302 | .val = if (is_generic) .none else param_ty, | 16323 | .val = if (is_generic) .none else param_ty, |
| 16303 | } }); | 16324 | } }); |
| 16304 | | 16325 | |
| 16305 | const is_noalias = blk: { | | |
| 16306 | const index = std.math.cast(u5, i) orelse break :blk false; | | |
| 16307 | break :blk @as(u1, @truncate(func_ty_info.noalias_bits >> index)) != 0; | | |
| 16308 | }; | | |
| 16309 | | | |
| 16310 | const param_fields = .{ | 16326 | const param_fields = .{ |
| 16311 | // is_generic: bool, | 16327 | // is_generic: bool, |
| 16312 | Value.makeBool(is_generic).toIntern(), | 16328 | Value.makeBool(is_generic).toIntern(), |
| ... | @@ -16348,15 +16364,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16348,15 +16364,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16348 | | 16364 | |
| 16349 | const ret_ty_is_generic = generic: { | 16365 | const ret_ty_is_generic = generic: { |
| 16350 | const ret_ty: Type = .fromInterned(func_ty_info.return_type); | 16366 | const ret_ty: Type = .fromInterned(func_ty_info.return_type); |
| 16351 | if (ret_ty.toIntern() == .generic_poison_type) break :generic true; | 16367 | if (ret_ty.toIntern() == .generic_poison_type or |
| 16352 | if (ret_ty.zigTypeTag(zcu) == .error_union) { | 16368 | (ret_ty.zigTypeTag(zcu) == .error_union and |
| 16353 | if (ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) { | 16369 | ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type)) |
| 16354 | break :generic true; | 16370 | { |
| 16355 | } | 16371 | break :generic true; |
| 16356 | } | 16372 | } |
| 16357 | break :generic false; | 16373 | break :generic false; |
| 16358 | }; | 16374 | }; |
| 16359 | if (ret_ty_is_generic) func_is_generic = true; | 16375 | if (ret_ty_is_generic or Type.fromInterned(func_ty_info.return_type).comptimeOnly(zcu)) { |
| | 16376 | func_is_generic = true; |
| | 16377 | } |
| 16360 | | 16378 | |
| 16361 | const ret_ty_opt = try pt.intern(.{ .opt = .{ | 16379 | const ret_ty_opt = try pt.intern(.{ .opt = .{ |
| 16362 | .ty = try pt.intern(.{ .opt_type = .type_type }), | 16380 | .ty = try pt.intern(.{ .opt_type = .type_type }), |