authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-22 15:04:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-23 10:40:40+02:00
log92beb2b490d7d86825d2e0eae3287c06477c9e81
treedb759eb5a68383b3ffd92a5e08acbe54d689416b
parent923b07bac797d66fe6d393cf823402c742250f48

stage2: misc fixes in Sema


5 files changed, 35 insertions(+), 21 deletions(-)

lib/std/math.zig+4-3
...@@ -947,7 +947,7 @@ fn testRem() !void {...@@ -947,7 +947,7 @@ fn testRem() !void {
947/// Result is an unsigned integer.947/// Result is an unsigned integer.
948pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {948pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
949 .ComptimeInt => comptime_int,949 .ComptimeInt => comptime_int,
950 .Int => |intInfo| std.meta.Int(.unsigned, intInfo.bits),950 .Int => |int_info| std.meta.Int(.unsigned, int_info.bits),
951 else => @compileError("absCast only accepts integers"),951 else => @compileError("absCast only accepts integers"),
952} {952} {
953 switch (@typeInfo(@TypeOf(x))) {953 switch (@typeInfo(@TypeOf(x))) {
...@@ -958,8 +958,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {...@@ -958,8 +958,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
958 return x;958 return x;
959 }959 }
960 },960 },
961 .Int => |intInfo| {961 .Int => |int_info| {
962 const Uint = std.meta.Int(.unsigned, intInfo.bits);962 if (int_info.signedness == .unsigned) return x;
963 const Uint = std.meta.Int(.unsigned, int_info.bits);
963 if (x < 0) {964 if (x < 0) {
964 return ~@bitCast(Uint, x +% -1);965 return ~@bitCast(Uint, x +% -1);
965 } else {966 } else {
src/Sema.zig+14-7
...@@ -3351,9 +3351,10 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -3351,9 +3351,10 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
3351 // Check for the possibility of this pattern:3351 // Check for the possibility of this pattern:
3352 // %a = ret_ptr3352 // %a = ret_ptr
3353 // %b = store(%a, %c)3353 // %b = store(%a, %c)
3354 // Where %c is an error union. In such case we need to add to the current function's3354 // Where %c is an error union or error set. In such case we need to add
3355 // inferred error set, if any.3355 // to the current function's inferred error set, if any.
3356 if (sema.typeOf(operand).zigTypeTag() == .ErrorUnion and3356 if ((sema.typeOf(operand).zigTypeTag() == .ErrorUnion or
3357 sema.typeOf(operand).zigTypeTag() == .ErrorSet) and
3357 sema.fn_ret_ty.zigTypeTag() == .ErrorUnion)3358 sema.fn_ret_ty.zigTypeTag() == .ErrorUnion)
3358 {3359 {
3359 if (Zir.refToIndex(extra.lhs)) |ptr_index| {3360 if (Zir.refToIndex(extra.lhs)) |ptr_index| {
...@@ -7665,6 +7666,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -7665,6 +7666,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
7665 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);7666 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
7666 const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs);7667 const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs);
76677668
7669 // tuples are structs but they don't have a namespace
7670 if (container_type.isTuple()) return Air.Inst.Ref.bool_false;
7668 const namespace = container_type.getNamespace() orelse return sema.fail(7671 const namespace = container_type.getNamespace() orelse return sema.fail(
7669 block,7672 block,
7670 lhs_src,7673 lhs_src,
...@@ -12186,7 +12189,7 @@ fn checkPtrOperand(...@@ -12186,7 +12189,7 @@ fn checkPtrOperand(
12186 ty: Type,12189 ty: Type,
12187) CompileError!void {12190) CompileError!void {
12188 switch (ty.zigTypeTag()) {12191 switch (ty.zigTypeTag()) {
12189 .Pointer => {},12192 .Pointer => return,
12190 .Fn => {12193 .Fn => {
12191 const msg = msg: {12194 const msg = msg: {
12192 const msg = try sema.errMsg(12195 const msg = try sema.errMsg(
...@@ -12203,8 +12206,10 @@ fn checkPtrOperand(...@@ -12203,8 +12206,10 @@ fn checkPtrOperand(
12203 };12206 };
12204 return sema.failWithOwnedErrorMsg(msg);12207 return sema.failWithOwnedErrorMsg(msg);
12205 },12208 },
12206 else => return sema.fail(block, ty_src, "expected pointer, found '{}'", .{ty}),12209 .Optional => if (ty.isPtrLikeOptional()) return,
12210 else => {},
12207 }12211 }
12212 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty});
12208}12213}
1220912214
12210fn checkPtrType(12215fn checkPtrType(
...@@ -12214,7 +12219,7 @@ fn checkPtrType(...@@ -12214,7 +12219,7 @@ fn checkPtrType(
12214 ty: Type,12219 ty: Type,
12215) CompileError!void {12220) CompileError!void {
12216 switch (ty.zigTypeTag()) {12221 switch (ty.zigTypeTag()) {
12217 .Pointer => {},12222 .Pointer => return,
12218 .Fn => {12223 .Fn => {
12219 const msg = msg: {12224 const msg = msg: {
12220 const msg = try sema.errMsg(12225 const msg = try sema.errMsg(
...@@ -12231,8 +12236,10 @@ fn checkPtrType(...@@ -12231,8 +12236,10 @@ fn checkPtrType(
12231 };12236 };
12232 return sema.failWithOwnedErrorMsg(msg);12237 return sema.failWithOwnedErrorMsg(msg);
12233 },12238 },
12234 else => return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty}),12239 .Optional => if (ty.isPtrLikeOptional()) return,
12240 else => {},
12235 }12241 }
12242 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty});
12236}12243}
1223712244
12238fn checkVectorElemType(12245fn checkVectorElemType(
src/type.zig+4-2
...@@ -593,10 +593,12 @@ pub const Type = extern union {...@@ -593,10 +593,12 @@ pub const Type = extern union {
593593
594 for (a_info.param_types) |a_param_ty, i| {594 for (a_info.param_types) |a_param_ty, i| {
595 const b_param_ty = b_info.param_types[i];595 const b_param_ty = b_info.param_types[i];
596 if (!eql(a_param_ty, b_param_ty))596 if (a_info.comptime_params[i] != b_info.comptime_params[i])
597 return false;597 return false;
598598
599 if (a_info.comptime_params[i] != b_info.comptime_params[i])599 if (a_param_ty.tag() == .generic_poison) continue;
600 if (b_param_ty.tag() == .generic_poison) continue;
601 if (!eql(a_param_ty, b_param_ty))
600 return false;602 return false;
601 }603 }
602604
test/behavior.zig+9-9
...@@ -120,6 +120,15 @@ test {...@@ -120,6 +120,15 @@ test {
120 _ = @import("behavior/sizeof_and_typeof.zig");120 _ = @import("behavior/sizeof_and_typeof.zig");
121 _ = @import("behavior/switch.zig");121 _ = @import("behavior/switch.zig");
122 _ = @import("behavior/widening.zig");122 _ = @import("behavior/widening.zig");
123 _ = @import("behavior/bugs/421.zig");
124 _ = @import("behavior/bugs/726.zig");
125 _ = @import("behavior/bugs/1421.zig");
126 _ = @import("behavior/bugs/2114.zig");
127 _ = @import("behavior/bugs/3742.zig");
128 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
129 _ = @import("behavior/switch_prong_err_enum.zig");
130 _ = @import("behavior/switch_prong_implicit_cast.zig");
131 _ = @import("behavior/union_with_members.zig");
123132
124 if (builtin.zig_backend == .stage1) {133 if (builtin.zig_backend == .stage1) {
125 // Tests that only pass for the stage1 backend.134 // Tests that only pass for the stage1 backend.
...@@ -128,20 +137,15 @@ test {...@@ -128,20 +137,15 @@ test {
128 _ = @import("behavior/async_fn.zig");137 _ = @import("behavior/async_fn.zig");
129 }138 }
130 _ = @import("behavior/await_struct.zig");139 _ = @import("behavior/await_struct.zig");
131 _ = @import("behavior/bugs/421.zig");
132 _ = @import("behavior/bugs/529.zig");140 _ = @import("behavior/bugs/529.zig");
133 _ = @import("behavior/bugs/718.zig");141 _ = @import("behavior/bugs/718.zig");
134 _ = @import("behavior/bugs/726.zig");
135 _ = @import("behavior/bugs/828.zig");142 _ = @import("behavior/bugs/828.zig");
136 _ = @import("behavior/bugs/920.zig");143 _ = @import("behavior/bugs/920.zig");
137 _ = @import("behavior/bugs/1120.zig");144 _ = @import("behavior/bugs/1120.zig");
138 _ = @import("behavior/bugs/1421.zig");
139 _ = @import("behavior/bugs/1442.zig");145 _ = @import("behavior/bugs/1442.zig");
140 _ = @import("behavior/bugs/1607.zig");146 _ = @import("behavior/bugs/1607.zig");
141 _ = @import("behavior/bugs/1851.zig");147 _ = @import("behavior/bugs/1851.zig");
142 _ = @import("behavior/bugs/2114.zig");
143 _ = @import("behavior/bugs/3384.zig");148 _ = @import("behavior/bugs/3384.zig");
144 _ = @import("behavior/bugs/3742.zig");
145 _ = @import("behavior/bugs/3779.zig");149 _ = @import("behavior/bugs/3779.zig");
146 _ = @import("behavior/bugs/4328.zig");150 _ = @import("behavior/bugs/4328.zig");
147 _ = @import("behavior/bugs/5398.zig");151 _ = @import("behavior/bugs/5398.zig");
...@@ -161,12 +165,8 @@ test {...@@ -161,12 +165,8 @@ test {
161 _ = @import("behavior/muladd.zig");165 _ = @import("behavior/muladd.zig");
162 _ = @import("behavior/select.zig");166 _ = @import("behavior/select.zig");
163 _ = @import("behavior/shuffle.zig");167 _ = @import("behavior/shuffle.zig");
164 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
165 _ = @import("behavior/struct_contains_slice_of_itself.zig");168 _ = @import("behavior/struct_contains_slice_of_itself.zig");
166 _ = @import("behavior/switch_prong_err_enum.zig");
167 _ = @import("behavior/switch_prong_implicit_cast.zig");
168 _ = @import("behavior/typename.zig");169 _ = @import("behavior/typename.zig");
169 _ = @import("behavior/union_with_members.zig");
170 _ = @import("behavior/vector.zig");170 _ = @import("behavior/vector.zig");
171 if (builtin.target.cpu.arch == .wasm32) {171 if (builtin.target.cpu.arch == .wasm32) {
172 _ = @import("behavior/wasm.zig");172 _ = @import("behavior/wasm.zig");
test/behavior/type_info.zig+4
...@@ -323,6 +323,10 @@ fn testOpaque() !void {...@@ -323,6 +323,10 @@ fn testOpaque() !void {
323}323}
324324
325test "type info: function type info" {325test "type info: function type info" {
326 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
327 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
328 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
329
326 // wasm doesn't support align attributes on functions330 // wasm doesn't support align attributes on functions
327 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;331 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;
328 try testFunction();332 try testFunction();