diff --git a/stdx/meta.zig b/stdx/meta.zig index 9e37c04..2eb69fe 100644 --- a/stdx/meta.zig +++ b/stdx/meta.zig @@ -110,11 +110,11 @@ pub fn asSlice(comptime T: type) type { .One => switch (@typeInfo(info.child)) { // As Zig, convert pointer to Array as a slice. .Array => |arr_info| arr_info.child, - else => compileError(err_msg), + else => @compileError(err_msg), }, - else => compileError(err_msg), + else => @compileError(err_msg), }, - else => compileError(err_msg), + else => @compileError(err_msg), }; } @@ -146,7 +146,7 @@ pub fn TupleRangeX(comptime T: type, comptime start: usize, comptime end: usize) } pub fn FnParam(comptime func: anytype, comptime n: comptime_int) type { - return @typeInfo(@TypeOf(func)).Fn.params[n].type orelse compileError("anytype is not supported"); + return @typeInfo(@TypeOf(func)).Fn.params[n].type orelse @compileError("anytype is not supported"); } pub fn FnArgs(comptime func: anytype) type { diff --git a/zml/aio.zig b/zml/aio.zig index f263b82..f8fad85 100644 --- a/zml/aio.zig +++ b/zml/aio.zig @@ -526,7 +526,7 @@ pub fn loadBuffers( if (@hasDecl(Model, "init")) { @call(.auto, Model.init, .{&model} ++ init_args); } else { - zml.meta.assertComptime(@TypeOf(init_args) == void or @TypeOf(init_args) == @TypeOf(.{}), "Model of type {} has no init function, so `loadBuffers` should be call with init_args set to {{}} (void)", .{Model}); + stdx.debug.assertComptime(@TypeOf(init_args) == void or @TypeOf(init_args) == @TypeOf(.{}), "Model of type {} has no init function, so `loadBuffers` should be call with init_args set to {{}} (void)", .{Model}); } return loadModelBuffersWithPrefix(Model, model, buffer_store, allocator, platform, ""); @@ -623,7 +623,7 @@ fn visitStructAndLoadBuffer(allocator: std.mem.Allocator, prefix_builder: *Prefi try visitStructAndLoadBuffer(allocator, prefix_builder, buffer_store, value, platform); } - } else zml.meta.compileError("type not supported by visitStructAndLoadBuffer: {}", .{T}); + } else stdx.debug.compileError("type not supported by visitStructAndLoadBuffer: {}", .{T}); }, .Array => { for (obj, 0..) |*value, i| { diff --git a/zml/meta.zig b/zml/meta.zig index 0363802..d527765 100644 --- a/zml/meta.zig +++ b/zml/meta.zig @@ -94,7 +94,7 @@ pub fn mapAlloc(comptime cb: anytype, allocator: std.mem.Allocator, ctx: FnParam const type_info_to_ptr = @typeInfo(@TypeOf(to)); if (type_info_to_ptr != .Pointer) { - stdx.debug.compileError("convertType is expecting a mutable `to` argument but received: " ++ @typeName(@TypeOf(to))); + stdx.debug.compileError("convertType is expecting a mutable `to` argument but received: {}", .{@TypeOf(to)}); } const ToStruct = type_info_to_ptr.Pointer.child; const type_info_to = @typeInfo(ToStruct); @@ -143,7 +143,7 @@ pub fn mapAlloc(comptime cb: anytype, allocator: std.mem.Allocator, ctx: FnParam } else if (field.default_value) |_| { @field(to, field.name) = null; } else { - stdx.meta.compileError("Mapping {} to {} failed. Missing field {s}", .{ FromStruct, ToStruct, field.name }); + stdx.debug.compileError("Mapping {} to {} failed. Missing field {s}", .{ FromStruct, ToStruct, field.name }); }, else => @field(to, field.name) = @field(from, field.name), } @@ -169,7 +169,7 @@ pub fn mapAlloc(comptime cb: anytype, allocator: std.mem.Allocator, ctx: FnParam } to.* = items; }, - else => stdx.meta.compileError("zml.meta.mapAlloc doesn't support: " ++ @typeName(FromStruct)), + else => stdx.debug.compileError("zml.meta.mapAlloc doesn't support: {}", .{FromStruct}), }, .Optional => if (from) |f| { to.* = @as(@typeInfo(type_info_to_ptr.Pointer.child).Optional.child, undefined); @@ -178,7 +178,7 @@ pub fn mapAlloc(comptime cb: anytype, allocator: std.mem.Allocator, ctx: FnParam to.* = null; }, .Int, .Float => to.* = from, - else => stdx.meta.compileError("zml.meta.mapAlloc doesn't support: " ++ @typeName(FromStruct)), + else => stdx.debug.compileError("zml.meta.mapAlloc doesn't support: {}", .{FromStruct}), } } @@ -239,12 +239,12 @@ pub fn visit(comptime cb: anytype, ctx: FnParam(cb, 0), v: anytype) void { const type_info_v = @typeInfo(T); const K = switch (@typeInfo(FnParam(cb, 1))) { .Pointer => |info| info.child, - else => stdx.meta.compileError("zml.meta.visit is expecting a pointer value as second parameter in callback to use but found " ++ @typeName(FnParam(cb, 1))), + else => stdx.debug.compileError("zml.meta.visit is expecting a pointer value as second parameter in callback to use but found {}", .{FnParam(cb, 1)}), }; if (type_info_v != .Pointer) { const Callback = @TypeOf(cb); - stdx.meta.compileError("zml.meta.visit is expecting a pointer input to go with following callback signature: " ++ @typeName(Callback) ++ " but received: " ++ @typeName(T)); + stdx.debug.compileError("zml.meta.visit is expecting a pointer input to go with following callback signature: {} but received: {}", .{ Callback, T }); } const ptr_info = type_info_v.Pointer; if (@typeInfo(ptr_info.child) == .Fn) return; @@ -307,7 +307,7 @@ pub fn visit(comptime cb: anytype, ctx: FnParam(cb, 0), v: anytype) void { } } }, - else => stdx.meta.compileError("Only single pointer and slice are supported. Received " ++ @typeName(T)), + else => stdx.debug.compileError("Only single pointer and slice are supported. Received {}", .{T}), } } @@ -320,9 +320,7 @@ test visit { const MultipleTypesStruct = struct { prop1: Attr, prop2: OtherAttr, prop3: ?Attr }; const NestedTypesStruct = struct { prop1: Attr, prop2: OtherAttr, prop3: NestedAttr, prop4: NestedAttrOptional }; - const LocalContext = struct { - result: usize, - }; + const LocalContext = struct { result: usize }; { var context: LocalContext = .{ .result = 0 }; @@ -406,13 +404,13 @@ pub fn zip(comptime func: anytype, allocator: std.mem.Allocator, values: anytype // const fn_args return switch (@typeInfo(V)) { - .Pointer => stdx.meta.compileError("zip only accept by value arguments. Received: " ++ @typeName(V)), + .Pointer => stdx.debug.compileError("zip only accept by value arguments. Received: {}", .{V}), .Struct => |struct_info| { var out: V = values[0]; inline for (struct_info.fields) |f| { if (f.is_comptime) continue; if (@typeInfo(f.type) == .Pointer) { - stdx.meta.compileError("zip doesn't follow pointers and don't accept struct containing them. Received: " ++ @typeName(V)); + stdx.debug.compileError("zip doesn't follow pointers and don't accept struct containing them. Received: {}", .{V}); } var fields = try allocator.alloc(f.type, values.len); defer allocator.free(fields); @@ -425,7 +423,7 @@ pub fn zip(comptime func: anytype, allocator: std.mem.Allocator, values: anytype }, .Array => |arr_info| { if (@typeInfo(arr_info.child) == .Pointer) { - stdx.meta.compileError("zip doesn't follow pointers and don't accept struct containing them. Received: " ++ @typeName(V)); + stdx.debug.compileError("zip doesn't follow pointers and don't accept struct containing them. Received: {}", .{V}); } var out: V = undefined; var slice = try allocator.alloc(arr_info.child, values.len); @@ -438,7 +436,7 @@ pub fn zip(comptime func: anytype, allocator: std.mem.Allocator, values: anytype } return out; }, - .Union, .Optional => stdx.meta.compileError("zip doesn't yet support " ++ @typeName(V)), + .Union, .Optional => stdx.debug.compileError("zip doesn't yet support {}", .{V}), else => values[0], }; } @@ -484,10 +482,10 @@ pub fn collect(func: anytype, func_ctx: _CollectCtx(func), out: *std.ArrayList(s fn _CollectCtx(func: anytype) type { const params = @typeInfo(@TypeOf(func)).Fn.params; if (params.len == 1) return void; - return params[0].type orelse stdx.meta.compileError("anytype not supported in collect"); + return params[0].type orelse @compileError("anytype not supported in collect"); } fn _CollectArg(func: anytype) type { const params = @typeInfo(@TypeOf(func)).Fn.params; - return params[params.len - 1].type orelse stdx.meta.compileError("anytype not supported in collect"); + return params[params.len - 1].type orelse @compileError("anytype not supported in collect"); } diff --git a/zml/shape.zig b/zml/shape.zig index bafc886..2528364 100644 --- a/zml/shape.zig +++ b/zml/shape.zig @@ -60,7 +60,7 @@ pub const Shape = struct { } else if (comptime isAutoDim(fv)) { dims_.appendAssumeCapacity(-1); } else { - stdx.meta.compileError("Field {s} should be an integer or an auto dimension", .{field.name}); + stdx.debug.compileError("Field {s} should be an integer or an auto dimension", .{field.name}); } if (comptime stdx.meta.isTuple(T)) { tags_.appendAssumeCapacity(TagUnknown); @@ -72,7 +72,7 @@ pub const Shape = struct { return .{ dims_, tags_ }; } - stdx.meta.compileError("expected a dimension tuple eg '.{{ .a = 10, .b = 20}}' or '.{{ 10, 20 }}', got {}", .{T}); + stdx.debug.compileError("expected a dimension tuple eg '.{{ .a = 10, .b = 20}}' or '.{{ 10, 20 }}', got {}", .{T}); } test parseDimensions { @@ -109,7 +109,7 @@ pub const Shape = struct { return .{ axes_, tags_ }; } - stdx.meta.compileError("Wrong type, got {}. Expected .{{.a, .b}}", .{T}); + stdx.debug.compileError("Wrong type, got {}. Expected .{{.a, .b}}", .{T}); } pub fn parseTags(v: anytype) TagsArray { @@ -181,7 +181,7 @@ pub const Shape = struct { EnumLiteral => @tagName(v).ptr, std.builtin.Type.StructField => v.name.ptr, Tag => v, - else => stdx.meta.compileError("Value should be an EnumLiteral, a Shape.Tag or a StructField, got {}", .{T}), + else => stdx.debug.compileError("Value should be an EnumLiteral, a Shape.Tag or a StructField, got {}", .{T}), }; } @@ -239,7 +239,7 @@ pub const Shape = struct { return true; } - stdx.meta.compileError("Expected tuple of tags, got {any}", .{T}); + stdx.debug.compileError("Expected tuple of tags, got {any}", .{T}); } pub fn isFullyTagged(self: Shape) bool { @@ -261,7 +261,7 @@ pub const Shape = struct { return self.axisFromTag(toTag(axis_)); } - stdx.meta.compileError("Wrong axis type, expected .literal, or an integer, got: {any}", .{T}); + stdx.debug.compileError("Wrong axis type, expected .literal, or an integer, got: {any}", .{T}); } pub fn axes(self: Shape, axes_: anytype) AxesArray { @@ -289,7 +289,7 @@ pub const Shape = struct { return res; } - stdx.meta.compileError("axes expects an int-tuple or a tuple of enum literal, got {}", .{T}); + stdx.debug.compileError("axes expects an int-tuple or a tuple of enum literal, got {}", .{T}); } fn axisFromInt(self: Shape, d: isize) u3 { @@ -590,7 +590,7 @@ pub const Shape = struct { return res; } - stdx.meta.compileError("Expected a tuple of enum literals eg: .{ .a, .b, .c } got: {any}", .{@TypeOf(tagz)}); + stdx.debug.compileError("Expected a tuple of enum literals eg: .{ .a, .b, .c } got: {any}", .{@TypeOf(tagz)}); } test withTags { @@ -637,7 +637,7 @@ pub const Shape = struct { return res; } - stdx.meta.compileError("Expected a tuple of enum literals eg: .{ .a, .b, .c } got: {any}", .{@TypeOf(tagz)}); + stdx.debug.compileError("Expected a tuple of enum literals eg: .{ .a, .b, .c } got: {any}", .{@TypeOf(tagz)}); } test withPartialTags { @@ -934,7 +934,7 @@ pub const Shape = struct { return .{ vals_, tags_ }; } - stdx.meta.compileError("parseStruct expects struct or tuple, got {}", .{V}); + stdx.debug.compileError("parseStruct expects struct or tuple, got {}", .{V}); } test parseStruct { @@ -967,7 +967,7 @@ pub const Shape = struct { return res; } - stdx.meta.compileError("parseStruct expects struct or tuple, got {}", .{V}); + stdx.debug.compileError("parseStruct expects struct or tuple, got {}", .{V}); } test parseAxesOptions {