@@ -3948,6 +3948,7 @@ fn validateArrayInitTy(
3948
3948
return;
3949
3949
},
3950
3950
.Struct => if (ty.isTuple()) {
3951
+ _ = try sema.resolveTypeFields(ty);
3951
3952
const array_len = ty.arrayLen();
3952
3953
if (extra.init_count > array_len) {
3953
3954
return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{
@@ -4642,11 +4643,11 @@ fn failWithBadMemberAccess(
4642
4643
.Enum => "enum",
4643
4644
else => unreachable,
4644
4645
};
4645
- if (sema.mod.declIsRoot(agg_ty.getOwnerDecl() )) {
4646
+ if (agg_ty.getOwnerDeclOrNull()) |some| if ( sema.mod.declIsRoot(some )) {
4646
4647
return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{
4647
4648
agg_ty.fmt(sema.mod), field_name,
4648
4649
});
4649
- }
4650
+ };
4650
4651
const msg = msg: {
4651
4652
const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{
4652
4653
kw_name, agg_ty.fmt(sema.mod), field_name,
@@ -7514,7 +7515,7 @@ fn resolveGenericInstantiationType(
7514
7515
}
7515
7516
7516
7517
fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
7517
- if (!ty.isSimpleTuple ()) return;
7518
+ if (!ty.isSimpleTupleOrAnonStruct ()) return;
7518
7519
const tuple = ty.tupleFields();
7519
7520
for (tuple.values) |field_val, i| {
7520
7521
try sema.resolveTupleLazyValues(block, src, tuple.types[i]);
@@ -11771,8 +11772,8 @@ fn zirShl(
11771
11772
// TODO coerce rhs if air_tag is not shl_sat
11772
11773
const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
11773
11774
11774
- const maybe_lhs_val = try sema.resolveMaybeUndefVal (lhs);
11775
- const maybe_rhs_val = try sema.resolveMaybeUndefVal (rhs);
11775
+ const maybe_lhs_val = try sema.resolveMaybeUndefValIntable (lhs);
11776
+ const maybe_rhs_val = try sema.resolveMaybeUndefValIntable (rhs);
11776
11777
11777
11778
if (maybe_rhs_val) |rhs_val| {
11778
11779
if (rhs_val.isUndef()) {
@@ -11842,7 +11843,7 @@ fn zirShl(
11842
11843
if (scalar_ty.zigTypeTag() == .ComptimeInt) {
11843
11844
break :val shifted.wrapped_result;
11844
11845
}
11845
- if (shifted.overflow_bit.compareAllWithZero(.eq)) {
11846
+ if (shifted.overflow_bit.compareAllWithZero(.eq, sema.mod )) {
11846
11847
break :val shifted.wrapped_result;
11847
11848
}
11848
11849
return sema.fail(block, src, "operation caused overflow", .{});
@@ -11959,8 +11960,8 @@ fn zirShr(
11959
11960
const target = sema.mod.getTarget();
11960
11961
const scalar_ty = lhs_ty.scalarType();
11961
11962
11962
- const maybe_lhs_val = try sema.resolveMaybeUndefVal (lhs);
11963
- const maybe_rhs_val = try sema.resolveMaybeUndefVal (rhs);
11963
+ const maybe_lhs_val = try sema.resolveMaybeUndefValIntable (lhs);
11964
+ const maybe_rhs_val = try sema.resolveMaybeUndefValIntable (rhs);
11964
11965
11965
11966
const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
11966
11967
if (rhs_val.isUndef()) {
@@ -12799,7 +12800,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
12799
12800
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
12800
12801
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
12801
12802
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
12802
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .div );
12803
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
12803
12804
12804
12805
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
12805
12806
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -12831,7 +12832,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
12831
12832
const lhs_val = maybe_lhs_val orelse unreachable;
12832
12833
const rhs_val = maybe_rhs_val orelse unreachable;
12833
12834
const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod) catch unreachable;
12834
- if (!rem.compareAllWithZero(.eq)) {
12835
+ if (!rem.compareAllWithZero(.eq, mod )) {
12835
12836
return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; non-zero remainder '{}'", .{
12836
12837
@tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), rem.fmtValue(resolved_type, sema.mod),
12837
12838
});
@@ -12959,7 +12960,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12959
12960
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
12960
12961
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
12961
12962
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
12962
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .div_exact );
12963
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
12963
12964
12964
12965
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
12965
12966
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -13024,7 +13025,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13024
13025
if (maybe_rhs_val) |rhs_val| {
13025
13026
if (is_int) {
13026
13027
const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod);
13027
- if (!(modulus_val.compareAllWithZero(.eq))) {
13028
+ if (!(modulus_val.compareAllWithZero(.eq, mod ))) {
13028
13029
return sema.fail(block, src, "exact division produced remainder", .{});
13029
13030
}
13030
13031
const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
@@ -13035,7 +13036,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13035
13036
return sema.addConstant(resolved_type, res);
13036
13037
} else {
13037
13038
const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod);
13038
- if (!(modulus_val.compareAllWithZero(.eq))) {
13039
+ if (!(modulus_val.compareAllWithZero(.eq, mod ))) {
13039
13040
return sema.fail(block, src, "exact division produced remainder", .{});
13040
13041
}
13041
13042
return sema.addConstant(
@@ -13122,7 +13123,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13122
13123
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
13123
13124
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
13124
13125
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
13125
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .div_floor );
13126
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
13126
13127
13127
13128
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
13128
13129
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -13238,7 +13239,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13238
13239
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
13239
13240
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
13240
13241
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
13241
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .div_trunc );
13242
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
13242
13243
13243
13244
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
13244
13245
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -13481,7 +13482,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13481
13482
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
13482
13483
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
13483
13484
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
13484
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .mod_rem );
13485
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
13485
13486
13486
13487
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
13487
13488
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -13664,7 +13665,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13664
13665
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
13665
13666
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
13666
13667
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
13667
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .mod );
13668
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
13668
13669
13669
13670
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
13670
13671
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -13766,7 +13767,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13766
13767
const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison();
13767
13768
const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
13768
13769
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
13769
- try sema.checkInvalidPtrArithmetic(block, src, lhs_ty, .rem );
13770
+ try sema.checkInvalidPtrArithmetic(block, src, lhs_ty);
13770
13771
13771
13772
const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
13772
13773
const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{
@@ -14106,12 +14107,7 @@ fn analyzeArithmetic(
14106
14107
const air_tag: Air.Inst.Tag = switch (zir_tag) {
14107
14108
.add => .ptr_add,
14108
14109
.sub => .ptr_sub,
14109
- else => return sema.fail(
14110
- block,
14111
- src,
14112
- "invalid pointer arithmetic operand: '{s}''",
14113
- .{@tagName(zir_tag)},
14114
- ),
14110
+ else => return sema.fail(block, src, "invalid pointer arithmetic operator", .{}),
14115
14111
};
14116
14112
return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
14117
14113
},
@@ -19697,7 +19693,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
19697
19693
}
19698
19694
}
19699
19695
19700
- if (try sema.resolveMaybeUndefVal (operand)) |val| {
19696
+ if (try sema.resolveMaybeUndefValIntable (operand)) |val| {
19701
19697
if (val.isUndef()) return sema.addConstUndef(dest_ty);
19702
19698
if (!is_vector) {
19703
19699
return sema.addConstant(
@@ -19901,15 +19897,15 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
19901
19897
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
19902
19898
const operand = try sema.resolveInst(inst_data.operand);
19903
19899
const operand_ty = sema.typeOf(operand);
19904
- _ = try sema.checkIntOrVectorAllowComptime (block, operand_ty , operand_src);
19900
+ const scalar_ty = try sema.checkIntOrVector (block, operand , operand_src);
19905
19901
19906
19902
if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
19907
19903
return sema.addConstant(operand_ty, val);
19908
19904
}
19909
19905
19910
19906
const target = sema.mod.getTarget();
19911
19907
switch (operand_ty.zigTypeTag()) {
19912
- .Int, .ComptimeInt => {
19908
+ .Int => {
19913
19909
const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
19914
19910
if (val.isUndef()) return sema.addConstUndef(operand_ty);
19915
19911
const result_val = try val.bitReverse(operand_ty, target, sema.arena);
@@ -19929,7 +19925,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
19929
19925
const elems = try sema.arena.alloc(Value, vec_len);
19930
19926
for (elems) |*elem, i| {
19931
19927
const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
19932
- elem.* = try elem_val.bitReverse(operand_ty , target, sema.arena);
19928
+ elem.* = try elem_val.bitReverse(scalar_ty , target, sema.arena);
19933
19929
}
19934
19930
return sema.addConstant(
19935
19931
operand_ty,
@@ -20028,16 +20024,15 @@ fn checkInvalidPtrArithmetic(
20028
20024
block: *Block,
20029
20025
src: LazySrcLoc,
20030
20026
ty: Type,
20031
- zir_tag: Zir.Inst.Tag,
20032
20027
) CompileError!void {
20033
20028
switch (try ty.zigTypeTagOrPoison()) {
20034
20029
.Pointer => switch (ty.ptrSize()) {
20035
20030
.One, .Slice => return,
20036
20031
.Many, .C => return sema.fail(
20037
20032
block,
20038
20033
src,
20039
- "invalid pointer arithmetic operand: '{s}'' ",
20040
- .{@tagName(zir_tag) },
20034
+ "invalid pointer arithmetic operator ",
20035
+ .{},
20041
20036
),
20042
20037
},
20043
20038
else => return,
0 commit comments