authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-13 13:12:18-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-02-13 13:12:18-05:00
log1675d4f82b94b4db0272aff483760cd526963a4c
tree1c2f56508d70b602d9520eb7a593a3079c54e540
parentfa377dbd1510fc733607afe47dc04dfe55d5ff88
parentf93c219f30b4b4f3bb9280d39be7b585ddcd8447
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4443 from LemonBoy/werkzeug

A train of small patches

7 files changed, 81 insertions(+), 22 deletions(-)

lib/std/meta.zig+15
......@@ -433,6 +433,14 @@ pub fn eql(a: var, b: @TypeOf(a)) bool {
433433 if (!eql(e, b[i])) return false;
434434 return true;
435435 },
436 builtin.TypeId.Vector => {
437 const info = @typeInfo(T).Vector;
438 var i: usize = 0;
439 while (i < info.len) : (i += 1) {
440 if (!eql(a[i], b[i])) return false;
441 }
442 return true;
443 },
436444 builtin.TypeId.Pointer => {
437445 const info = @typeInfo(T).Pointer;
438446 switch (info.size) {
......@@ -510,6 +518,13 @@ test "std.meta.eql" {
510518 testing.expect(eql(EU.tst(true), EU.tst(true)));
511519 testing.expect(eql(EU.tst(false), EU.tst(false)));
512520 testing.expect(!eql(EU.tst(false), EU.tst(true)));
521
522 var v1 = @splat(4, @as(u32, 1));
523 var v2 = @splat(4, @as(u32, 1));
524 var v3 = @splat(4, @as(u32, 2));
525
526 testing.expect(eql(v1, v2));
527 testing.expect(!eql(v1, v3));
513528}
514529
515530test "intToEnum with error return" {
lib/std/os/test.zig+8-11
......@@ -276,8 +276,11 @@ test "mmap" {
276276 testing.expectEqual(@as(usize, 1234), data.len);
277277
278278 // By definition the data returned by mmap is zero-filled
279 std.mem.set(u8, data[0 .. data.len - 1], 0x55);
280 testing.expect(mem.indexOfScalar(u8, data, 0).? == 1234 - 1);
279 testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
280
281 // Make sure the memory is writeable as requested
282 std.mem.set(u8, data, 0x55);
283 testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
281284 }
282285
283286 const test_out_file = "os_tmp_test";
......@@ -300,10 +303,7 @@ test "mmap" {
300303
301304 // Map the whole file
302305 {
303 const file = try fs.cwd().createFile(test_out_file, .{
304 .read = true,
305 .truncate = false,
306 });
306 const file = try fs.cwd().openFile(test_out_file, .{});
307307 defer file.close();
308308
309309 const data = try os.mmap(
......@@ -327,15 +327,12 @@ test "mmap" {
327327
328328 // Map the upper half of the file
329329 {
330 const file = try fs.cwd().createFile(test_out_file, .{
331 .read = true,
332 .truncate = false,
333 });
330 const file = try fs.cwd().openFile(test_out_file, .{});
334331 defer file.close();
335332
336333 const data = try os.mmap(
337334 null,
338 alloc_size,
335 alloc_size / 2,
339336 os.PROT_READ,
340337 os.MAP_PRIVATE,
341338 file.handle,
lib/std/testing.zig+16-1
......@@ -56,7 +56,6 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
5656 .EnumLiteral,
5757 .Enum,
5858 .Fn,
59 .Vector,
6059 .ErrorSet,
6160 => {
6261 if (actual != expected) {
......@@ -88,6 +87,15 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
8887
8988 .Array => |array| expectEqualSlices(array.child, &expected, &actual),
9089
90 .Vector => |vectorType| {
91 var i: usize = 0;
92 while (i < vectorType.len) : (i += 1) {
93 if (!std.meta.eql(expected[i], actual[i])) {
94 std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
95 }
96 }
97 },
98
9199 .Struct => |structType| {
92100 inline for (structType.fields) |field| {
93101 expectEqual(@field(expected, field.name), @field(actual, field.name));
......@@ -202,3 +210,10 @@ test "expectEqual nested array" {
202210
203211 expectEqual(a, b);
204212}
213
214test "expectEqual vector" {
215 var a = @splat(4, @as(u32, 4));
216 var b = @splat(4, @as(u32, 4));
217
218 expectEqual(a, b);
219}
src/analyze.cpp+2-2
......@@ -6937,9 +6937,9 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu
69376937 return;
69386938 }
69396939 case ConstArraySpecialNone: {
6940 ZigValue *base = &array->data.s_none.elements[start];
6941 assert(base != nullptr);
69426940 assert(start + len <= const_val->type->data.array.len);
6941 ZigValue *base = &array->data.s_none.elements[start];
6942 assert(len == 0 || base != nullptr);
69436943
69446944 buf_appendf(buf, "%s{", buf_ptr(type_name));
69456945 for (uint64_t i = 0; i < len; i += 1) {
src/ir.cpp+13-1
......@@ -14840,6 +14840,16 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
1484014840 }
1484114841 }
1484214842
14843 // @Vector(N,T1) to @Vector(N,T2)
14844 if (actual_type->id == ZigTypeIdVector && wanted_type->id == ZigTypeIdVector) {
14845 if (actual_type->data.vector.len == wanted_type->data.vector.len &&
14846 types_match_const_cast_only(ira, wanted_type->data.vector.elem_type,
14847 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
14848 {
14849 return ir_analyze_bit_cast(ira, source_instr, value, wanted_type);
14850 }
14851 }
14852
1484314853 // *@Frame(func) to anyframe->T or anyframe
1484414854 // *@Frame(func) to ?anyframe->T or ?anyframe
1484514855 // *@Frame(func) to E!anyframe->T or E!anyframe
......@@ -16409,9 +16419,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1640916419 case ZigTypeIdComptimeInt:
1641016420 case ZigTypeIdInt:
1641116421 case ZigTypeIdFloat:
16412 case ZigTypeIdVector:
1641316422 zig_unreachable(); // handled with the type_is_numeric checks above
1641416423
16424 case ZigTypeIdVector:
16425 // Not every case is handled by the type_is_numeric checks above,
16426 // vectors of bool trigger this code path
1641516427 case ZigTypeIdBool:
1641616428 case ZigTypeIdMetaType:
1641716429 case ZigTypeIdVoid:
src/link.cpp-7
......@@ -2642,13 +2642,6 @@ void codegen_link(CodeGen *g) {
26422642 lj.rpath_table.init(4);
26432643 lj.codegen = g;
26442644
2645 if (g->verbose_llvm_ir) {
2646 fprintf(stderr, "\nOptimization:\n");
2647 fprintf(stderr, "---------------\n");
2648 fflush(stderr);
2649 LLVMDumpModule(g->module);
2650 }
2651
26522645 if (g->out_type == OutTypeObj) {
26532646 lj.args.append("-r");
26542647 }
test/stage1/behavior/vector.zig+27
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const mem = std.mem;
33const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
45const builtin = @import("builtin");
56
67test "implicit cast vector to array - bool" {
......@@ -250,3 +251,29 @@ test "initialize vector which is a struct field" {
250251 S.doTheTest();
251252 comptime S.doTheTest();
252253}
254
255test "vector comparison operators" {
256 const S = struct {
257 fn doTheTest() void {
258 {
259 const v1: @Vector(4, bool) = [_]bool{ true, false, true, false };
260 const v2: @Vector(4, bool) = [_]bool{ false, true, false, true };
261 expectEqual(@splat(4, true), v1 == v1);
262 expectEqual(@splat(4, false), v1 == v2);
263 expectEqual(@splat(4, true), v1 != v2);
264 expectEqual(@splat(4, false), v2 != v2);
265 }
266 {
267 const v1 = @splat(4, @as(u32, 0xc0ffeeee));
268 const v2: @Vector(4, c_uint) = v1;
269 const v3 = @splat(4, @as(u32, 0xdeadbeef));
270 expectEqual(@splat(4, true), v1 == v2);
271 expectEqual(@splat(4, false), v1 == v3);
272 expectEqual(@splat(4, true), v1 != v3);
273 expectEqual(@splat(4, false), v1 != v2);
274 }
275 }
276 };
277 S.doTheTest();
278 comptime S.doTheTest();
279}