| author | |
| committer | |
| log | d69e97ae1677ca487833caf6937fa428563ed0ae |
| tree | 9299ebd6762715fd756972458f152ed123bf718f |
| parent | 913b4a3f19955296a892ffe4f148f8c097a7732a |
| parent | 6039554b26b1aee6502063d9130907369c4ffd38 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
misc fixes and improvements30 files changed, 120 insertions(+), 194 deletions(-)
lib/compiler_rt/divdc3.zig+3-1| ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); | ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); |
| 3 | const Complex = @import("./mulc3.zig").Complex; | 3 | const Complex = @import("./mulc3.zig").Complex; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | @export(__divdc3, .{ .name = "__divdc3", .linkage = common.linkage }); | 6 | if (@import("builtin").zig_backend != .stage2_c) { |
| 7 | @export(__divdc3, .{ .name = "__divdc3", .linkage = common.linkage }); | ||
| 8 | } | ||
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | pub fn __divdc3(a: f64, b: f64, c: f64, d: f64) callconv(.C) Complex(f64) { | 11 | pub fn __divdc3(a: f64, b: f64, c: f64, d: f64) callconv(.C) Complex(f64) { |
lib/compiler_rt/divhc3.zig+3-1| ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); | ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); |
| 3 | const Complex = @import("./mulc3.zig").Complex; | 3 | const Complex = @import("./mulc3.zig").Complex; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | @export(__divhc3, .{ .name = "__divhc3", .linkage = common.linkage }); | 6 | if (@import("builtin").zig_backend != .stage2_c) { |
| 7 | @export(__divhc3, .{ .name = "__divhc3", .linkage = common.linkage }); | ||
| 8 | } | ||
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | pub fn __divhc3(a: f16, b: f16, c: f16, d: f16) callconv(.C) Complex(f16) { | 11 | pub fn __divhc3(a: f16, b: f16, c: f16, d: f16) callconv(.C) Complex(f16) { |
lib/compiler_rt/divsc3.zig+3-1| ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); | ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); |
| 3 | const Complex = @import("./mulc3.zig").Complex; | 3 | const Complex = @import("./mulc3.zig").Complex; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | @export(__divsc3, .{ .name = "__divsc3", .linkage = common.linkage }); | 6 | if (@import("builtin").zig_backend != .stage2_c) { |
| 7 | @export(__divsc3, .{ .name = "__divsc3", .linkage = common.linkage }); | ||
| 8 | } | ||
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | pub fn __divsc3(a: f32, b: f32, c: f32, d: f32) callconv(.C) Complex(f32) { | 11 | pub fn __divsc3(a: f32, b: f32, c: f32, d: f32) callconv(.C) Complex(f32) { |
lib/compiler_rt/divtc3.zig+3-1| ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); | ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); |
| 3 | const Complex = @import("./mulc3.zig").Complex; | 3 | const Complex = @import("./mulc3.zig").Complex; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | @export(__divtc3, .{ .name = "__divtc3", .linkage = common.linkage }); | 6 | if (@import("builtin").zig_backend != .stage2_c) { |
| 7 | @export(__divtc3, .{ .name = "__divtc3", .linkage = common.linkage }); | ||
| 8 | } | ||
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | pub fn __divtc3(a: f128, b: f128, c: f128, d: f128) callconv(.C) Complex(f128) { | 11 | pub fn __divtc3(a: f128, b: f128, c: f128, d: f128) callconv(.C) Complex(f128) { |
lib/compiler_rt/divxc3.zig+3-1| ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); | ... | @@ -3,7 +3,9 @@ const divc3 = @import("./divc3.zig"); |
| 3 | const Complex = @import("./mulc3.zig").Complex; | 3 | const Complex = @import("./mulc3.zig").Complex; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | @export(__divxc3, .{ .name = "__divxc3", .linkage = common.linkage }); | 6 | if (@import("builtin").zig_backend != .stage2_c) { |
| 7 | @export(__divxc3, .{ .name = "__divxc3", .linkage = common.linkage }); | ||
| 8 | } | ||
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | pub fn __divxc3(a: f80, b: f80, c: f80, d: f80) callconv(.C) Complex(f80) { | 11 | pub fn __divxc3(a: f80, b: f80, c: f80, d: f80) callconv(.C) Complex(f80) { |
lib/compiler_rt/muldc3.zig+3-1| ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); | ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); |
| 4 | pub const panic = common.panic; | 4 | pub const panic = common.panic; |
| 5 | 5 | ||
| 6 | comptime { | 6 | comptime { |
| 7 | @export(__muldc3, .{ .name = "__muldc3", .linkage = common.linkage }); | 7 | if (@import("builtin").zig_backend != .stage2_c) { |
| 8 | @export(__muldc3, .{ .name = "__muldc3", .linkage = common.linkage }); | ||
| 9 | } | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | pub fn __muldc3(a: f64, b: f64, c: f64, d: f64) callconv(.C) mulc3.Complex(f64) { | 12 | pub fn __muldc3(a: f64, b: f64, c: f64, d: f64) callconv(.C) mulc3.Complex(f64) { |
lib/compiler_rt/mulhc3.zig+3-1| ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); | ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); |
| 4 | pub const panic = common.panic; | 4 | pub const panic = common.panic; |
| 5 | 5 | ||
| 6 | comptime { | 6 | comptime { |
| 7 | @export(__mulhc3, .{ .name = "__mulhc3", .linkage = common.linkage }); | 7 | if (@import("builtin").zig_backend != .stage2_c) { |
| 8 | @export(__mulhc3, .{ .name = "__mulhc3", .linkage = common.linkage }); | ||
| 9 | } | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | pub fn __mulhc3(a: f16, b: f16, c: f16, d: f16) callconv(.C) mulc3.Complex(f16) { | 12 | pub fn __mulhc3(a: f16, b: f16, c: f16, d: f16) callconv(.C) mulc3.Complex(f16) { |
lib/compiler_rt/mulsc3.zig+3-1| ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); | ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); |
| 4 | pub const panic = common.panic; | 4 | pub const panic = common.panic; |
| 5 | 5 | ||
| 6 | comptime { | 6 | comptime { |
| 7 | @export(__mulsc3, .{ .name = "__mulsc3", .linkage = common.linkage }); | 7 | if (@import("builtin").zig_backend != .stage2_c) { |
| 8 | @export(__mulsc3, .{ .name = "__mulsc3", .linkage = common.linkage }); | ||
| 9 | } | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | pub fn __mulsc3(a: f32, b: f32, c: f32, d: f32) callconv(.C) mulc3.Complex(f32) { | 12 | pub fn __mulsc3(a: f32, b: f32, c: f32, d: f32) callconv(.C) mulc3.Complex(f32) { |
lib/compiler_rt/multc3.zig+3-1| ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); | ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); |
| 4 | pub const panic = common.panic; | 4 | pub const panic = common.panic; |
| 5 | 5 | ||
| 6 | comptime { | 6 | comptime { |
| 7 | @export(__multc3, .{ .name = "__multc3", .linkage = common.linkage }); | 7 | if (@import("builtin").zig_backend != .stage2_c) { |
| 8 | @export(__multc3, .{ .name = "__multc3", .linkage = common.linkage }); | ||
| 9 | } | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | pub fn __multc3(a: f128, b: f128, c: f128, d: f128) callconv(.C) mulc3.Complex(f128) { | 12 | pub fn __multc3(a: f128, b: f128, c: f128, d: f128) callconv(.C) mulc3.Complex(f128) { |
lib/compiler_rt/mulxc3.zig+3-1| ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); | ... | @@ -4,7 +4,9 @@ const mulc3 = @import("./mulc3.zig"); |
| 4 | pub const panic = common.panic; | 4 | pub const panic = common.panic; |
| 5 | 5 | ||
| 6 | comptime { | 6 | comptime { |
| 7 | @export(__mulxc3, .{ .name = "__mulxc3", .linkage = common.linkage }); | 7 | if (@import("builtin").zig_backend != .stage2_c) { |
| 8 | @export(__mulxc3, .{ .name = "__mulxc3", .linkage = common.linkage }); | ||
| 9 | } | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | pub fn __mulxc3(a: f80, b: f80, c: f80, d: f80) callconv(.C) mulc3.Complex(f80) { | 12 | pub fn __mulxc3(a: f80, b: f80, c: f80, d: f80) callconv(.C) mulc3.Complex(f80) { |
lib/std/build/OptionsStep.zig+1-1| ... | @@ -177,7 +177,7 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { | ... | @@ -177,7 +177,7 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 177 | .Float, | 177 | .Float, |
| 178 | .Null, | 178 | .Null, |
| 179 | => try out.print("{any}", .{val}), | 179 | => try out.print("{any}", .{val}), |
| 180 | else => @compileError(comptime std.fmt.comptimePrint("`{s}` are not yet supported as build options", .{@tagName(@typeInfo(T))})), | 180 | else => @compileError(std.fmt.comptimePrint("`{s}` are not yet supported as build options", .{@tagName(@typeInfo(T))})), |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | 183 |
lib/std/fmt.zig+1-1| ... | @@ -199,7 +199,7 @@ pub fn format( | ... | @@ -199,7 +199,7 @@ pub fn format( |
| 199 | switch (missing_count) { | 199 | switch (missing_count) { |
| 200 | 0 => unreachable, | 200 | 0 => unreachable, |
| 201 | 1 => @compileError("unused argument in '" ++ fmt ++ "'"), | 201 | 1 => @compileError("unused argument in '" ++ fmt ++ "'"), |
| 202 | else => @compileError((comptime comptimePrint("{d}", .{missing_count})) ++ " unused arguments in '" ++ fmt ++ "'"), | 202 | else => @compileError(comptimePrint("{d}", .{missing_count}) ++ " unused arguments in '" ++ fmt ++ "'"), |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | } | 205 | } |
lib/std/testing.zig+1-1| ... | @@ -765,7 +765,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime | ... | @@ -765,7 +765,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime |
| 765 | } | 765 | } |
| 766 | const expected_args_tuple_len = fn_args_fields.len - 1; | 766 | const expected_args_tuple_len = fn_args_fields.len - 1; |
| 767 | if (extra_args.len != expected_args_tuple_len) { | 767 | if (extra_args.len != expected_args_tuple_len) { |
| 768 | @compileError("The provided function expects " ++ (comptime std.fmt.comptimePrint("{d}", .{expected_args_tuple_len})) ++ " extra arguments, but the provided tuple contains " ++ (comptime std.fmt.comptimePrint("{d}", .{extra_args.len}))); | 768 | @compileError("The provided function expects " ++ std.fmt.comptimePrint("{d}", .{expected_args_tuple_len}) ++ " extra arguments, but the provided tuple contains " ++ std.fmt.comptimePrint("{d}", .{extra_args.len})); |
| 769 | } | 769 | } |
| 770 | 770 | ||
| 771 | // Setup the tuple that will actually be used with @call (we'll need to insert | 771 | // Setup the tuple that will actually be used with @call (we'll need to insert |
lib/std/zig/tokenizer.zig+17-1| ... | @@ -425,7 +425,16 @@ pub const Tokenizer = struct { | ... | @@ -425,7 +425,16 @@ pub const Tokenizer = struct { |
| 425 | const c = self.buffer[self.index]; | 425 | const c = self.buffer[self.index]; |
| 426 | switch (state) { | 426 | switch (state) { |
| 427 | .start => switch (c) { | 427 | .start => switch (c) { |
| 428 | 0 => break, | 428 | 0 => { |
| 429 | if (self.index != self.buffer.len) { | ||
| 430 | result.tag = .invalid; | ||
| 431 | result.loc.start = self.index; | ||
| 432 | self.index += 1; | ||
| 433 | result.loc.end = self.index; | ||
| 434 | return result; | ||
| 435 | } | ||
| 436 | break; | ||
| 437 | }, | ||
| 429 | ' ', '\n', '\t', '\r' => { | 438 | ' ', '\n', '\t', '\r' => { |
| 430 | result.loc.start = self.index + 1; | 439 | result.loc.start = self.index + 1; |
| 431 | }, | 440 | }, |
| ... | @@ -1851,6 +1860,13 @@ test "saturating operators" { | ... | @@ -1851,6 +1860,13 @@ test "saturating operators" { |
| 1851 | try testTokenize("-|=", &.{.minus_pipe_equal}); | 1860 | try testTokenize("-|=", &.{.minus_pipe_equal}); |
| 1852 | } | 1861 | } |
| 1853 | 1862 | ||
| 1863 | test "null byte before eof" { | ||
| 1864 | try testTokenize("123 \x00 456", &.{ .number_literal, .invalid, .number_literal }); | ||
| 1865 | try testTokenize("//\x00", &.{.invalid}); | ||
| 1866 | try testTokenize("\\\\\x00", &.{ .multiline_string_literal_line, .invalid }); | ||
| 1867 | try testTokenize("\x00", &.{.invalid}); | ||
| 1868 | } | ||
| 1869 | |||
| 1854 | fn testTokenize(source: [:0]const u8, expected_token_tags: []const Token.Tag) !void { | 1870 | fn testTokenize(source: [:0]const u8, expected_token_tags: []const Token.Tag) !void { |
| 1855 | var tokenizer = Tokenizer.init(source); | 1871 | var tokenizer = Tokenizer.init(source); |
| 1856 | for (expected_token_tags) |expected_token_tag| { | 1872 | for (expected_token_tags) |expected_token_tag| { |
src/AstGen.zig+4| ... | @@ -8455,8 +8455,12 @@ fn simpleUnOp( | ... | @@ -8455,8 +8455,12 @@ fn simpleUnOp( |
| 8455 | operand_node: Ast.Node.Index, | 8455 | operand_node: Ast.Node.Index, |
| 8456 | tag: Zir.Inst.Tag, | 8456 | tag: Zir.Inst.Tag, |
| 8457 | ) InnerError!Zir.Inst.Ref { | 8457 | ) InnerError!Zir.Inst.Ref { |
| 8458 | const prev_force_comptime = gz.force_comptime; | ||
| 8459 | defer gz.force_comptime = prev_force_comptime; | ||
| 8460 | |||
| 8458 | switch (tag) { | 8461 | switch (tag) { |
| 8459 | .tag_name, .error_name, .ptr_to_int => try emitDbgNode(gz, node), | 8462 | .tag_name, .error_name, .ptr_to_int => try emitDbgNode(gz, node), |
| 8463 | .compile_error => gz.force_comptime = true, | ||
| 8460 | else => {}, | 8464 | else => {}, |
| 8461 | } | 8465 | } |
| 8462 | const operand = try expr(gz, scope, operand_ri, operand_node); | 8466 | const operand = try expr(gz, scope, operand_ri, operand_node); |
src/Sema.zig+17| ... | @@ -5405,6 +5405,13 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5405,6 +5405,13 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5405 | }, | 5405 | }, |
| 5406 | else => |e| return e, | 5406 | else => |e| return e, |
| 5407 | }; | 5407 | }; |
| 5408 | { | ||
| 5409 | try sema.mod.ensureDeclAnalyzed(decl_index); | ||
| 5410 | const exported_decl = sema.mod.declPtr(decl_index); | ||
| 5411 | if (exported_decl.val.castTag(.function)) |some| { | ||
| 5412 | return sema.analyzeExport(block, src, options, some.data.owner_decl); | ||
| 5413 | } | ||
| 5414 | } | ||
| 5408 | try sema.analyzeExport(block, src, options, decl_index); | 5415 | try sema.analyzeExport(block, src, options, decl_index); |
| 5409 | } | 5416 | } |
| 5410 | 5417 | ||
| ... | @@ -17870,6 +17877,13 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -17870,6 +17877,13 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17870 | operand_ty.fmt(mod), | 17877 | operand_ty.fmt(mod), |
| 17871 | }), | 17878 | }), |
| 17872 | }; | 17879 | }; |
| 17880 | if (enum_ty.enumFieldCount() == 0) { | ||
| 17881 | // TODO I don't think this is the correct way to handle this but | ||
| 17882 | // it prevents a crash. | ||
| 17883 | return sema.fail(block, operand_src, "cannot get @tagName of empty enum '{}'", .{ | ||
| 17884 | enum_ty.fmt(mod), | ||
| 17885 | }); | ||
| 17886 | } | ||
| 17873 | const enum_decl_index = enum_ty.getOwnerDecl(); | 17887 | const enum_decl_index = enum_ty.getOwnerDecl(); |
| 17874 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); | 17888 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); |
| 17875 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { | 17889 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { |
| ... | @@ -20997,6 +21011,9 @@ fn analyzeMinMax( | ... | @@ -20997,6 +21011,9 @@ fn analyzeMinMax( |
| 20997 | 21011 | ||
| 20998 | if (rhs_val.isUndef()) return sema.addConstUndef(simd_op.result_ty); | 21012 | if (rhs_val.isUndef()) return sema.addConstUndef(simd_op.result_ty); |
| 20999 | 21013 | ||
| 21014 | try sema.resolveLazyValue(lhs_val); | ||
| 21015 | try sema.resolveLazyValue(rhs_val); | ||
| 21016 | |||
| 21000 | const opFunc = switch (air_tag) { | 21017 | const opFunc = switch (air_tag) { |
| 21001 | .min => Value.numberMin, | 21018 | .min => Value.numberMin, |
| 21002 | .max => Value.numberMax, | 21019 | .max => Value.numberMax, |
src/TypedValue.zig+42-8| ... | @@ -46,6 +46,7 @@ pub fn enumToInt(tv: TypedValue, buffer: *Value.Payload.U64) Value { | ... | @@ -46,6 +46,7 @@ pub fn enumToInt(tv: TypedValue, buffer: *Value.Payload.U64) Value { |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | const max_aggregate_items = 100; | 48 | const max_aggregate_items = 100; |
| 49 | const max_string_len = 256; | ||
| 49 | 50 | ||
| 50 | const FormatContext = struct { | 51 | const FormatContext = struct { |
| 51 | tv: TypedValue, | 52 | tv: TypedValue, |
| ... | @@ -141,10 +142,12 @@ pub fn print( | ... | @@ -141,10 +142,12 @@ pub fn print( |
| 141 | .extern_options_type => return writer.writeAll("std.builtin.ExternOptions"), | 142 | .extern_options_type => return writer.writeAll("std.builtin.ExternOptions"), |
| 142 | .type_info_type => return writer.writeAll("std.builtin.Type"), | 143 | .type_info_type => return writer.writeAll("std.builtin.Type"), |
| 143 | 144 | ||
| 144 | .empty_struct_value, .aggregate => { | 145 | .empty_struct_value => return writer.writeAll(".{}"), |
| 146 | .aggregate => { | ||
| 145 | if (level == 0) { | 147 | if (level == 0) { |
| 146 | return writer.writeAll(".{ ... }"); | 148 | return writer.writeAll(".{ ... }"); |
| 147 | } | 149 | } |
| 150 | const values = val.castTag(.aggregate).?; | ||
| 148 | if (ty.zigTypeTag() == .Struct) { | 151 | if (ty.zigTypeTag() == .Struct) { |
| 149 | try writer.writeAll(".{"); | 152 | try writer.writeAll(".{"); |
| 150 | const max_len = std.math.min(ty.structFieldCount(), max_aggregate_items); | 153 | const max_len = std.math.min(ty.structFieldCount(), max_aggregate_items); |
| ... | @@ -159,9 +162,9 @@ pub fn print( | ... | @@ -159,9 +162,9 @@ pub fn print( |
| 159 | try print(.{ | 162 | try print(.{ |
| 160 | .ty = ty.structFieldType(i), | 163 | .ty = ty.structFieldType(i), |
| 161 | .val = switch (ty.containerLayout()) { | 164 | .val = switch (ty.containerLayout()) { |
| 162 | .Packed => val.castTag(.aggregate).?.data[i], | 165 | .Packed => values.data[i], |
| 163 | else => ty.structFieldValueComptime(i) orelse b: { | 166 | else => ty.structFieldValueComptime(i) orelse b: { |
| 164 | const vals = val.castTag(.aggregate).?.data; | 167 | const vals = values.data; |
| 165 | break :b vals[i]; | 168 | break :b vals[i]; |
| 166 | }, | 169 | }, |
| 167 | }, | 170 | }, |
| ... | @@ -172,17 +175,31 @@ pub fn print( | ... | @@ -172,17 +175,31 @@ pub fn print( |
| 172 | } | 175 | } |
| 173 | return writer.writeAll("}"); | 176 | return writer.writeAll("}"); |
| 174 | } else { | 177 | } else { |
| 175 | try writer.writeAll(".{ "); | ||
| 176 | const elem_ty = ty.elemType2(); | 178 | const elem_ty = ty.elemType2(); |
| 177 | const len = ty.arrayLen(); | 179 | const len = ty.arrayLen(); |
| 178 | const max_len = std.math.min(len, max_aggregate_items); | ||
| 179 | 180 | ||
| 181 | if (elem_ty.eql(Type.u8, mod)) str: { | ||
| 182 | const max_len = @intCast(usize, std.math.min(len, max_string_len)); | ||
| 183 | var buf: [max_string_len]u8 = undefined; | ||
| 184 | |||
| 185 | var i: u32 = 0; | ||
| 186 | while (i < max_len) : (i += 1) { | ||
| 187 | buf[i] = std.math.cast(u8, values.data[i].toUnsignedInt(target)) orelse break :str; | ||
| 188 | } | ||
| 189 | |||
| 190 | const truncated = if (len > max_string_len) " (truncated)" else ""; | ||
| 191 | return writer.print("\"{}{s}\"", .{ std.zig.fmtEscapes(buf[0..max_len]), truncated }); | ||
| 192 | } | ||
| 193 | |||
| 194 | try writer.writeAll(".{ "); | ||
| 195 | |||
| 196 | const max_len = std.math.min(len, max_aggregate_items); | ||
| 180 | var i: u32 = 0; | 197 | var i: u32 = 0; |
| 181 | while (i < max_len) : (i += 1) { | 198 | while (i < max_len) : (i += 1) { |
| 182 | if (i != 0) try writer.writeAll(", "); | 199 | if (i != 0) try writer.writeAll(", "); |
| 183 | try print(.{ | 200 | try print(.{ |
| 184 | .ty = elem_ty, | 201 | .ty = elem_ty, |
| 185 | .val = val.castTag(.aggregate).?.data[i], | 202 | .val = values.data[i], |
| 186 | }, writer, level - 1, mod); | 203 | }, writer, level - 1, mod); |
| 187 | } | 204 | } |
| 188 | if (len > max_aggregate_items) { | 205 | if (len > max_aggregate_items) { |
| ... | @@ -372,11 +389,28 @@ pub fn print( | ... | @@ -372,11 +389,28 @@ pub fn print( |
| 372 | return writer.writeAll(".{ ... }"); | 389 | return writer.writeAll(".{ ... }"); |
| 373 | } | 390 | } |
| 374 | const payload = val.castTag(.slice).?.data; | 391 | const payload = val.castTag(.slice).?.data; |
| 375 | try writer.writeAll(".{ "); | ||
| 376 | const elem_ty = ty.elemType2(); | 392 | const elem_ty = ty.elemType2(); |
| 377 | const len = payload.len.toUnsignedInt(target); | 393 | const len = payload.len.toUnsignedInt(target); |
| 378 | const max_len = std.math.min(len, max_aggregate_items); | ||
| 379 | 394 | ||
| 395 | if (elem_ty.eql(Type.u8, mod)) str: { | ||
| 396 | const max_len = @intCast(usize, std.math.min(len, max_string_len)); | ||
| 397 | var buf: [max_string_len]u8 = undefined; | ||
| 398 | |||
| 399 | var i: u32 = 0; | ||
| 400 | while (i < max_len) : (i += 1) { | ||
| 401 | var elem_buf: Value.ElemValueBuffer = undefined; | ||
| 402 | const elem_val = payload.ptr.elemValueBuffer(mod, i, &elem_buf); | ||
| 403 | buf[i] = std.math.cast(u8, elem_val.toUnsignedInt(target)) orelse break :str; | ||
| 404 | } | ||
| 405 | |||
| 406 | // TODO would be nice if this had a bit of unicode awareness. | ||
| 407 | const truncated = if (len > max_string_len) " (truncated)" else ""; | ||
| 408 | return writer.print("\"{}{s}\"", .{ std.zig.fmtEscapes(buf[0..max_len]), truncated }); | ||
| 409 | } | ||
| 410 | |||
| 411 | try writer.writeAll(".{ "); | ||
| 412 | |||
| 413 | const max_len = std.math.min(len, max_aggregate_items); | ||
| 380 | var i: u32 = 0; | 414 | var i: u32 = 0; |
| 381 | while (i < max_len) : (i += 1) { | 415 | while (i < max_len) : (i += 1) { |
| 382 | if (i != 0) try writer.writeAll(", "); | 416 | if (i != 0) try writer.writeAll(", "); |
test/behavior/maximum_minimum.zig+7| ... | @@ -95,3 +95,10 @@ test "@min for vectors" { | ... | @@ -95,3 +95,10 @@ test "@min for vectors" { |
| 95 | try S.doTheTest(); | 95 | try S.doTheTest(); |
| 96 | comptime try S.doTheTest(); | 96 | comptime try S.doTheTest(); |
| 97 | } | 97 | } |
| 98 | |||
| 99 | test "@min/@max on lazy values" { | ||
| 100 | const A = extern struct { u8_4: [4]u8 }; | ||
| 101 | const B = extern struct { u8_16: [16]u8 }; | ||
| 102 | const size = @max(@sizeOf(A), @sizeOf(B)); | ||
| 103 | try expect(size == @sizeOf(B)); | ||
| 104 | } |
test/cases/compile_errors/stage1/attempt_to_use_0_bit_type_in_extern_fn.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | extern fn foo(ptr: fn(*void) callconv(.C) void) void; | ||
| 2 | |||
| 3 | export fn entry() void { | ||
| 4 | foo(bar); | ||
| 5 | } | ||
| 6 | |||
| 7 | fn bar(x: *void) callconv(.C) void { _ = x; } | ||
| 8 | export fn entry2() void { | ||
| 9 | bar(&{}); | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // backend=stage1 | ||
| 14 | // target=native | ||
| 15 | // | ||
| 16 | // tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C' | ||
| 17 | // tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C' | ||
test/cases/compile_errors/stage1/comptime_ptrcast_of_zero-sized_type.zig deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | fn foo() void { | ||
| 2 | const node: struct {} = undefined; | ||
| 3 | const vla_ptr = @ptrCast([*]const u8, &node); | ||
| 4 | _ = vla_ptr; | ||
| 5 | } | ||
| 6 | comptime { foo(); } | ||
| 7 | |||
| 8 | // error | ||
| 9 | // backend=stage1 | ||
| 10 | // target=native | ||
| 11 | // | ||
| 12 | // tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation | ||
test/cases/compile_errors/stage1/error_equality_but_sets_have_no_common_members.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Set1 = error{A, C}; | ||
| 2 | const Set2 = error{B, D}; | ||
| 3 | export fn entry() void { | ||
| 4 | foo(Set1.A); | ||
| 5 | } | ||
| 6 | fn foo(x: Set1) void { | ||
| 7 | if (x == Set2.B) { | ||
| 8 | |||
| 9 | } | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // backend=stage1 | ||
| 14 | // target=native | ||
| 15 | // | ||
| 16 | // tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors | ||
test/cases/compile_errors/stage1/implicit_casting_undefined_c_pointer_to_zig_pointer.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | var c_ptr: [*c]u8 = undefined; | ||
| 3 | var zig_ptr: *u8 = c_ptr; | ||
| 4 | _ = zig_ptr; | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage1 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // tmp.zig:3:24: error: use of undefined value here causes undefined behavior | ||
test/cases/compile_errors/stage1/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | export fn foo1() void { | ||
| 2 | const a: *[1]u8 = undefined; | ||
| 3 | var b: []u8 = a; | ||
| 4 | _ = b; | ||
| 5 | } | ||
| 6 | export fn foo2() void { | ||
| 7 | comptime { | ||
| 8 | var a: *[1]u8 = undefined; | ||
| 9 | var b: []u8 = a; | ||
| 10 | _ = b; | ||
| 11 | } | ||
| 12 | } | ||
| 13 | export fn foo3() void { | ||
| 14 | comptime { | ||
| 15 | const a: *[1]u8 = undefined; | ||
| 16 | var b: []u8 = a; | ||
| 17 | _ = b; | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | // error | ||
| 22 | // backend=stage1 | ||
| 23 | // target=native | ||
| 24 | // | ||
| 25 | // tmp.zig:3:19: error: use of undefined value here causes undefined behavior | ||
| 26 | // tmp.zig:9:23: error: use of undefined value here causes undefined behavior | ||
| 27 | // tmp.zig:16:23: error: use of undefined value here causes undefined behavior | ||
test/cases/compile_errors/stage1/ptrToInt_on_void.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | export fn entry() bool { | ||
| 2 | return @ptrToInt(&{}) == @ptrToInt(&{}); | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // backend=stage1 | ||
| 7 | // target=native | ||
| 8 | // | ||
| 9 | // tmp.zig:2:23: error: pointer to size 0 type has no address | ||
test/cases/compile_errors/stage1/ptrToInt_with_pointer_to_zero-sized_type.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | var pointer: ?*u0 = null; | ||
| 3 | var x = @ptrToInt(pointer); | ||
| 4 | _ = x; | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage1 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // tmp.zig:3:23: error: pointer to size 0 type has no address | ||
test/cases/compile_errors/stage1/reify_type.Pointer_with_invalid_address_space.zig deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | _ = @Type(.{ .Pointer = .{ | ||
| 3 | .size = .One, | ||
| 4 | .is_const = false, | ||
| 5 | .is_volatile = false, | ||
| 6 | .alignment = 1, | ||
| 7 | .address_space = .gs, | ||
| 8 | .child = u8, | ||
| 9 | .is_allowzero = false, | ||
| 10 | .sentinel = null, | ||
| 11 | }}); | ||
| 12 | } | ||
| 13 | |||
| 14 | // error | ||
| 15 | // backend=stage1 | ||
| 16 | // target=native | ||
| 17 | // | ||
| 18 | // tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic | ||
test/cases/compile_errors/stage1/reify_type_with_non-constant_expression.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const builtin = @import("std").builtin; | ||
| 2 | var globalTypeInfo : builtin.Type = undefined; | ||
| 3 | export fn entry() void { | ||
| 4 | _ = @Type(globalTypeInfo); | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage1 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // tmp.zig:4:15: error: unable to evaluate constant expression | ||
test/cases/compile_errors/stage1/slicing_of_global_undefined_pointer.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | var buf: *[1]u8 = undefined; | ||
| 2 | export fn entry() void { | ||
| 3 | _ = buf[0..1]; | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // backend=stage1 | ||
| 8 | // target=native | ||
| 9 | // | ||
| 10 | // tmp.zig:3:12: error: non-zero length slice of undefined pointer | ||
test/cases/compile_errors/stage1/switch_with_invalid_expression_parameter.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | Test(i32); | ||
| 3 | } | ||
| 4 | fn Test(comptime T: type) void { | ||
| 5 | const x = switch (T) { | ||
| 6 | []u8 => |x| x, | ||
| 7 | i32 => |x| x, | ||
| 8 | else => unreachable, | ||
| 9 | }; | ||
| 10 | _ = x; | ||
| 11 | } | ||
| 12 | |||
| 13 | // error | ||
| 14 | // backend=stage1 | ||
| 15 | // target=native | ||
| 16 | // | ||
| 17 | // tmp.zig:7:17: error: switch on type 'type' provides no expression parameter | ||
test/cases/compile_errors/stage1/use_of_comptime-known_undefined_function_value.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const Cmd = struct { | ||
| 2 | exec: fn () void, | ||
| 3 | }; | ||
| 4 | export fn entry() void { | ||
| 5 | const command = Cmd{ .exec = undefined }; | ||
| 6 | command.exec(); | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // backend=stage1 | ||
| 11 | // target=native | ||
| 12 | // | ||
| 13 | // tmp.zig:6:12: error: use of undefined value here causes undefined behavior | ||