mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-30 04:45:22 +03:00
revert introduction of @errorCast in this branch
This commit is contained in:
+1
-1
@@ -495,6 +495,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/std/unicode.zig
|
||||
lib/std/zig.zig
|
||||
lib/std/zig/Ast.zig
|
||||
lib/std/zig/Ast/Render.zig
|
||||
lib/std/zig/AstGen.zig
|
||||
lib/std/zig/AstRlAnnotate.zig
|
||||
lib/std/zig/LibCInstallation.zig
|
||||
@@ -503,7 +504,6 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/std/zig/WindowsSdk.zig
|
||||
lib/std/zig/Zir.zig
|
||||
lib/std/zig/c_builtins.zig
|
||||
lib/std/zig/render.zig
|
||||
lib/std/zig/string_literal.zig
|
||||
lib/std/zig/system.zig
|
||||
lib/std/zig/system/NativePaths.zig
|
||||
|
||||
@@ -138,10 +138,10 @@ pub fn main() !void {
|
||||
}
|
||||
}
|
||||
|
||||
var fixups: Ast.Fixups = .{};
|
||||
var fixups: Ast.Render.Fixups = .{};
|
||||
defer fixups.deinit(gpa);
|
||||
|
||||
var more_fixups: Ast.Fixups = .{};
|
||||
var more_fixups: Ast.Render.Fixups = .{};
|
||||
defer more_fixups.deinit(gpa);
|
||||
|
||||
var rng = std.Random.DefaultPrng.init(seed);
|
||||
|
||||
+2
-2
@@ -428,11 +428,11 @@ fn merge_paths(base: Component, new: []u8, aux_buf: *[]u8) error{NoSpaceLeft}!Co
|
||||
var aux: std.io.BufferedWriter = undefined;
|
||||
aux.initFixed(aux_buf.*);
|
||||
if (!base.isEmpty()) {
|
||||
aux.print("{fpath}", .{base}) catch |err| return @errorCast(err);
|
||||
aux.print("{fpath}", .{base}) catch return error.NoSpaceLeft;
|
||||
aux.end = std.mem.lastIndexOfScalar(u8, aux.getWritten(), '/') orelse
|
||||
return remove_dot_segments(new);
|
||||
}
|
||||
aux.print("/{s}", .{new}) catch |err| return @errorCast(err);
|
||||
aux.print("/{s}", .{new}) catch return error.NoSpaceLeft;
|
||||
const merged_path = remove_dot_segments(aux.getWritten());
|
||||
aux_buf.* = aux_buf.*[merged_path.percent_encoded.len..];
|
||||
return merged_path;
|
||||
|
||||
@@ -57,7 +57,10 @@ pub fn readLeb128(fbr: *FixedBufferReader, comptime T: type) Error!T {
|
||||
br.seek = fbr.pos;
|
||||
const result = br.takeLeb128(T);
|
||||
fbr.pos = br.seek;
|
||||
return @errorCast(result);
|
||||
return result catch |err| switch (err) {
|
||||
error.ReadFailed => return error.EndOfStream,
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn readUleb128(fbr: *FixedBufferReader, comptime T: type) Error!T {
|
||||
|
||||
@@ -902,8 +902,8 @@ pub const Response = struct {
|
||||
/// when the end of stream occurs by calling `end`.
|
||||
pub fn write(r: *Response, bytes: []const u8) std.io.Writer.Error!usize {
|
||||
switch (r.transfer_encoding) {
|
||||
.content_length, .none => return @errorCast(cl_writeSplat(r, &.{bytes}, 1)),
|
||||
.chunked => return @errorCast(chunked_writeSplat(r, &.{bytes}, 1)),
|
||||
.content_length, .none => return cl_writeSplat(r, &.{bytes}, 1),
|
||||
.chunked => return chunked_writeSplat(r, &.{bytes}, 1),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ pub fn valueAlloc(gpa: Allocator, v: anytype, options: Options) error{OutOfMemor
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const writer = aw.init(gpa);
|
||||
defer aw.deinit();
|
||||
value(v, options, writer) catch return error.OutOfMemory; // TODO: try @errorCast(...)
|
||||
value(v, options, writer) catch return error.OutOfMemory;
|
||||
return aw.toOwnedSlice();
|
||||
}
|
||||
|
||||
|
||||
+9
-14
@@ -128,12 +128,6 @@ pub fn deinit(tree: *Ast, gpa: Allocator) void {
|
||||
tree.* = undefined;
|
||||
}
|
||||
|
||||
pub const RenderError = error{
|
||||
/// Ran out of memory allocating call stack frames to complete rendering, or
|
||||
/// ran out of memory allocating space in the output buffer.
|
||||
OutOfMemory,
|
||||
};
|
||||
|
||||
pub const Mode = enum { zig, zon };
|
||||
|
||||
/// Result should be freed with tree.deinit() when there are
|
||||
@@ -199,19 +193,21 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A
|
||||
|
||||
/// `gpa` is used for allocating the resulting formatted source code.
|
||||
/// Caller owns the returned slice of bytes, allocated with `gpa`.
|
||||
pub fn renderAlloc(tree: Ast, gpa: Allocator) RenderError![]u8 {
|
||||
pub fn renderAlloc(tree: Ast, gpa: Allocator) error{OutOfMemory}![]u8 {
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const bw = aw.init(gpa);
|
||||
errdefer aw.deinit();
|
||||
render(tree, gpa, bw, .{}) catch |err| return @errorCast(err); // TODO try @errorCast(...)
|
||||
render(tree, gpa, bw, .{}) catch |err| switch (err) {
|
||||
error.WriteFailed => return error.OutOfMemory,
|
||||
};
|
||||
return aw.toOwnedSlice();
|
||||
}
|
||||
|
||||
pub fn render(tree: Ast, gpa: Allocator, bw: *std.io.BufferedWriter, fixups: Fixups) RenderError!void {
|
||||
return @import("./render.zig").renderTree(gpa, bw, tree, fixups);
|
||||
}
|
||||
pub const Render = @import("Ast/Render.zig");
|
||||
|
||||
pub const Fixups = private_render.Fixups;
|
||||
pub fn render(tree: Ast, gpa: Allocator, bw: *std.io.BufferedWriter, fixups: Render.Fixups) Render.Error!void {
|
||||
return Render.tree(gpa, bw, tree, fixups);
|
||||
}
|
||||
|
||||
/// Returns an extra offset for column and byte offset of errors that
|
||||
/// should point after the token in the error message.
|
||||
@@ -4130,9 +4126,8 @@ const Token = std.zig.Token;
|
||||
const Ast = @This();
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Parse = @import("Parse.zig");
|
||||
const private_render = @import("./render.zig");
|
||||
|
||||
test {
|
||||
_ = Parse;
|
||||
_ = private_render;
|
||||
_ = Render;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const std = @import("../std.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
const Allocator = std.mem.Allocator;
|
||||
@@ -7,10 +7,22 @@ const Ast = std.zig.Ast;
|
||||
const Token = std.zig.Token;
|
||||
const primitives = std.zig.primitives;
|
||||
|
||||
const Render = @This();
|
||||
|
||||
const indent_delta = 4;
|
||||
const asm_indent_delta = 2;
|
||||
|
||||
pub const Error = Ast.RenderError;
|
||||
gpa: Allocator,
|
||||
ais: *AutoIndentingStream,
|
||||
tree: Ast,
|
||||
fixups: Fixups,
|
||||
|
||||
pub const Error = error{
|
||||
/// Ran out of memory allocating call stack frames to complete rendering.
|
||||
OutOfMemory,
|
||||
/// Transitive failure from
|
||||
WriteFailed,
|
||||
};
|
||||
|
||||
pub const Fixups = struct {
|
||||
/// The key is the mut token (`var`/`const`) of the variable declaration
|
||||
@@ -70,13 +82,6 @@ pub const Fixups = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const Render = struct {
|
||||
gpa: Allocator,
|
||||
ais: *AutoIndentingStream,
|
||||
tree: Ast,
|
||||
fixups: Fixups,
|
||||
};
|
||||
|
||||
pub fn renderTree(gpa: Allocator, bw: *std.io.BufferedWriter, tree: Ast, fixups: Fixups) Error!void {
|
||||
assert(tree.errors.len == 0); // Cannot render an invalid tree.
|
||||
var auto_indenting_stream: AutoIndentingStream = .init(gpa, bw, indent_delta);
|
||||
@@ -11445,7 +11445,9 @@ fn parseStrLit(
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const bw = aw.fromArrayList(astgen.gpa, buf);
|
||||
defer buf.* = aw.toArrayList();
|
||||
break :r std.zig.string_literal.parseWrite(bw, raw_string) catch |err| return @errorCast(err);
|
||||
break :r std.zig.string_literal.parseWrite(bw, raw_string) catch |err| switch (err) {
|
||||
error.WriteFailed => return error.OutOfMemory,
|
||||
};
|
||||
};
|
||||
switch (result) {
|
||||
.success => return,
|
||||
@@ -13928,25 +13930,25 @@ fn lowerAstErrors(astgen: *AstGen) error{OutOfMemory}!void {
|
||||
break :blk idx - tok_start;
|
||||
};
|
||||
|
||||
const err: Ast.Error = .{
|
||||
const ast_err: Ast.Error = .{
|
||||
.tag = Ast.Error.Tag.invalid_byte,
|
||||
.token = tok,
|
||||
.extra = .{ .offset = bad_off },
|
||||
};
|
||||
msg.clearRetainingCapacity();
|
||||
tree.renderError(err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(ast_err, msg_bw) catch return error.OutOfMemory;
|
||||
return try astgen.appendErrorTokNotesOff(tok, bad_off, "{s}", .{msg.getWritten()}, notes.items);
|
||||
}
|
||||
|
||||
var cur_err = tree.errors[0];
|
||||
for (tree.errors[1..]) |err| {
|
||||
if (err.is_note) {
|
||||
tree.renderError(err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(err, msg_bw) catch return error.OutOfMemory;
|
||||
try notes.append(gpa, try astgen.errNoteTok(err.token, "{s}", .{msg.getWritten()}));
|
||||
} else {
|
||||
// Flush error
|
||||
const extra_offset = tree.errorOffset(cur_err);
|
||||
tree.renderError(cur_err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(cur_err, msg_bw) catch return error.OutOfMemory;
|
||||
try astgen.appendErrorTokNotesOff(cur_err.token, extra_offset, "{s}", .{msg.getWritten()}, notes.items);
|
||||
notes.clearRetainingCapacity();
|
||||
cur_err = err;
|
||||
@@ -13960,7 +13962,7 @@ fn lowerAstErrors(astgen: *AstGen) error{OutOfMemory}!void {
|
||||
|
||||
// Flush error
|
||||
const extra_offset = tree.errorOffset(cur_err);
|
||||
tree.renderError(cur_err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(cur_err, msg_bw) catch return error.OutOfMemory;
|
||||
try astgen.appendErrorTokNotesOff(cur_err.token, extra_offset, "{s}", .{msg.getWritten()}, notes.items);
|
||||
}
|
||||
|
||||
|
||||
@@ -470,7 +470,9 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory,
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const bw = aw.fromArrayList(gpa, &zg.string_bytes);
|
||||
defer zg.string_bytes = aw.toArrayList();
|
||||
break :r std.zig.string_literal.parseWrite(bw, raw_string) catch |err| return @errorCast(err);
|
||||
break :r std.zig.string_literal.parseWrite(bw, raw_string) catch |err| switch (err) {
|
||||
error.WriteFailed => return error.OutOfMemory,
|
||||
};
|
||||
};
|
||||
switch (result) {
|
||||
.success => {},
|
||||
@@ -567,7 +569,9 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const bw = aw.fromArrayList(gpa, &zg.string_bytes);
|
||||
defer zg.string_bytes = aw.toArrayList();
|
||||
break :r parseStrLit(zg.tree, str_node, bw) catch |err| return @errorCast(err);
|
||||
break :r parseStrLit(zg.tree, str_node, bw) catch |err| switch (err) {
|
||||
error.WriteFailed => return error.OutOfMemory,
|
||||
};
|
||||
};
|
||||
switch (result) {
|
||||
.success => {},
|
||||
@@ -895,11 +899,11 @@ fn lowerAstErrors(zg: *ZonGen) Allocator.Error!void {
|
||||
var cur_err = tree.errors[0];
|
||||
for (tree.errors[1..]) |err| {
|
||||
if (err.is_note) {
|
||||
tree.renderError(err, msg_bw) catch |e| return @errorCast(e); // TODO: try @errorCast(...)
|
||||
tree.renderError(err, msg_bw) catch return error.OutOfMemory;
|
||||
try notes.append(gpa, try zg.errNoteTok(err.token, "{s}", .{msg.getWritten()}));
|
||||
} else {
|
||||
// Flush error
|
||||
tree.renderError(cur_err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(cur_err, msg_bw) catch return error.OutOfMemory;
|
||||
const extra_offset = tree.errorOffset(cur_err);
|
||||
try zg.addErrorTokNotesOff(cur_err.token, extra_offset, "{s}", .{msg.getWritten()}, notes.items);
|
||||
notes.clearRetainingCapacity();
|
||||
@@ -916,7 +920,7 @@ fn lowerAstErrors(zg: *ZonGen) Allocator.Error!void {
|
||||
|
||||
// Flush error
|
||||
const extra_offset = tree.errorOffset(cur_err);
|
||||
tree.renderError(cur_err, msg_bw) catch |e| return @errorCast(e); // TODO try @errorCast(...)
|
||||
tree.renderError(cur_err, msg_bw) catch return error.OutOfMemory;
|
||||
try zg.addErrorTokNotesOff(cur_err.token, extra_offset, "{s}", .{msg.getWritten()}, notes.items);
|
||||
}
|
||||
|
||||
|
||||
@@ -8945,8 +8945,8 @@ pub fn getIntrinsic(
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
const bw = aw.fromArrayList(self.gpa, &self.strtab_string_bytes);
|
||||
defer self.strtab_string_bytes = aw.toArrayList();
|
||||
bw.print("llvm.{s}", .{@tagName(id)}) catch |err| return @errorCast(err);
|
||||
for (overload) |ty| bw.print(".{fm}", .{ty.fmt(self)}) catch |err| return @errorCast(err);
|
||||
bw.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;
|
||||
for (overload) |ty| bw.print(".{fm}", .{ty.fmt(self)}) catch return error.OutOfMemory;
|
||||
}
|
||||
break :name try self.trailingStrtabString();
|
||||
};
|
||||
|
||||
@@ -360,8 +360,9 @@ pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
aw.init(allocator);
|
||||
defer aw.deinit();
|
||||
// TODO try @errorCast(...)
|
||||
const result = parseWrite(&aw.buffered_writer, bytes) catch |err| return @errorCast(err);
|
||||
const result = parseWrite(&aw.buffered_writer, bytes) catch |err| switch (err) {
|
||||
error.WriteFailed => return error.OutOfMemory,
|
||||
};
|
||||
switch (result) {
|
||||
.success => return aw.toOwnedSlice(),
|
||||
.failure => return error.InvalidLiteral,
|
||||
|
||||
+8
-8
@@ -3032,7 +3032,7 @@ pub fn createTypeName(
|
||||
aw.init(gpa);
|
||||
defer aw.deinit();
|
||||
const bw = &aw.buffered_writer;
|
||||
bw.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch |err| return @errorCast(err);
|
||||
bw.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory;
|
||||
|
||||
var arg_i: usize = 0;
|
||||
for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
|
||||
@@ -3045,7 +3045,7 @@ pub fn createTypeName(
|
||||
// result in a compile error.
|
||||
const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat
|
||||
|
||||
if (arg_i != 0) bw.writeByte(',') catch |err| return @errorCast(err);
|
||||
if (arg_i != 0) bw.writeByte(',') catch return error.OutOfMemory;
|
||||
|
||||
// Limiting the depth here helps avoid type names getting too long, which
|
||||
// in turn helps to avoid unreasonably long symbol names for namespaced
|
||||
@@ -3056,7 +3056,7 @@ pub fn createTypeName(
|
||||
.pt = pt,
|
||||
.opt_sema = sema,
|
||||
.depth = 1,
|
||||
})}) catch |err| return @errorCast(err);
|
||||
})}) catch return error.OutOfMemory;
|
||||
|
||||
arg_i += 1;
|
||||
continue;
|
||||
@@ -5920,19 +5920,19 @@ fn zirCompileLog(
|
||||
const args = sema.code.refSlice(extra.end, extended.small);
|
||||
|
||||
for (args, 0..) |arg_ref, i| {
|
||||
if (i != 0) bw.writeAll(", ") catch |err| return @errorCast(err);
|
||||
if (i != 0) bw.writeAll(", ") catch return error.OutOfMemory;
|
||||
|
||||
const arg = try sema.resolveInst(arg_ref);
|
||||
const arg_ty = sema.typeOf(arg);
|
||||
if (try sema.resolveValueResolveLazy(arg)) |val| {
|
||||
bw.print("@as({f}, {f})", .{
|
||||
arg_ty.fmt(pt), val.fmtValueSema(pt, sema),
|
||||
}) catch |err| return @errorCast(err);
|
||||
}) catch return error.OutOfMemory;
|
||||
} else {
|
||||
bw.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch |err| return @errorCast(err);
|
||||
bw.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch return error.OutOfMemory;
|
||||
}
|
||||
}
|
||||
try bw.print("\n", .{});
|
||||
bw.writeByte('\n') catch return error.OutOfMemory;
|
||||
|
||||
const line_data = try zcu.intern_pool.getOrPutString(gpa, pt.tid, aw.getWritten(), .no_embedded_nulls);
|
||||
|
||||
@@ -37379,7 +37379,7 @@ fn notePathToComptimeAllocPtr(sema: *Sema, msg: *Zcu.ErrorMsg, src: LazySrcLoc,
|
||||
.lvalue,
|
||||
.{ .str = inter_name },
|
||||
20,
|
||||
) catch |err| return @errorCast(err);
|
||||
) catch return error.OutOfMemory;
|
||||
|
||||
switch (deriv_start) {
|
||||
.int, .nav_ptr => unreachable,
|
||||
|
||||
@@ -751,7 +751,7 @@ pub const Object = struct {
|
||||
const bw = object.builder.setModuleAsm(&aw);
|
||||
errdefer aw.deinit();
|
||||
for (object.pt.zcu.global_assembly.values()) |assembly| {
|
||||
bw.print("{s}\n", .{assembly}) catch |err| return @errorCast(err);
|
||||
bw.print("{s}\n", .{assembly}) catch return error.OutOfMemory;
|
||||
}
|
||||
try object.builder.finishModuleAsm(&aw);
|
||||
}
|
||||
@@ -2681,7 +2681,7 @@ pub const Object = struct {
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
aw.init(o.gpa);
|
||||
defer aw.deinit();
|
||||
ty.print(&aw.buffered_writer, o.pt) catch |err| return @errorCast(err);
|
||||
ty.print(&aw.buffered_writer, o.pt) catch return error.OutOfMemory;
|
||||
return aw.toOwnedSliceSentinel(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1262,7 +1262,7 @@ const NavGen = struct {
|
||||
fn resolveTypeName(self: *NavGen, ty: Type) Allocator.Error![]const u8 {
|
||||
var aw: std.io.AllocatingWriter = undefined;
|
||||
aw.init(self.gpa);
|
||||
ty.print(&aw.buffered_writer, self.pt) catch |err| return @errorCast(err);
|
||||
ty.print(&aw.buffered_writer, self.pt) catch return error.OutOfMemory;
|
||||
return aw.toOwnedSlice();
|
||||
}
|
||||
|
||||
|
||||
+21
-21
@@ -1482,8 +1482,8 @@ pub const WipNav = struct {
|
||||
assert(wip_nav.func != .none);
|
||||
if (wip_nav.dwarf.debug_frame.header.format == .none) return;
|
||||
const loc_cfa: Cfa = .{ .advance_loc = loc };
|
||||
loc_cfa.write(wip_nav) catch |err| return @errorCast(err);
|
||||
cfa.write(wip_nav) catch |err| return @errorCast(err);
|
||||
try loc_cfa.write(wip_nav);
|
||||
try cfa.write(wip_nav);
|
||||
}
|
||||
|
||||
pub const LocalVarTag = enum { arg, local_var };
|
||||
@@ -1541,7 +1541,7 @@ pub const WipNav = struct {
|
||||
|
||||
pub fn genVarArgsDebugInfo(wip_nav: *WipNav) UpdateError!void {
|
||||
assert(wip_nav.func != .none);
|
||||
wip_nav.abbrevCode(.is_var_args) catch |err| return @errorCast(err);
|
||||
try wip_nav.abbrevCode(.is_var_args);
|
||||
wip_nav.any_children = true;
|
||||
}
|
||||
|
||||
@@ -1560,8 +1560,8 @@ pub const WipNav = struct {
|
||||
delta_line - header.line_base >= header.line_range)
|
||||
remaining: {
|
||||
assert(delta_line != 0);
|
||||
dlbw.writeByte(DW.LNS.advance_line) catch |err| return @errorCast(err);
|
||||
dlbw.writeLeb128(delta_line) catch |err| return @errorCast(err);
|
||||
try dlbw.writeByte(DW.LNS.advance_line);
|
||||
try dlbw.writeLeb128(delta_line);
|
||||
break :remaining 0;
|
||||
} else delta_line);
|
||||
|
||||
@@ -1569,39 +1569,39 @@ pub const WipNav = struct {
|
||||
header.maximum_operations_per_instruction + delta_op;
|
||||
const max_op_advance: u9 = (std.math.maxInt(u8) - header.opcode_base) / header.line_range;
|
||||
const remaining_op_advance: u8 = @intCast(if (op_advance >= 2 * max_op_advance) remaining: {
|
||||
dlbw.writeByte(DW.LNS.advance_pc) catch |err| return @errorCast(err);
|
||||
dlbw.writeLeb128(op_advance) catch |err| return @errorCast(err);
|
||||
try dlbw.writeByte(DW.LNS.advance_pc);
|
||||
try dlbw.writeLeb128(op_advance);
|
||||
break :remaining 0;
|
||||
} else if (op_advance >= max_op_advance) remaining: {
|
||||
dlbw.writeByte(DW.LNS.const_add_pc) catch |err| return @errorCast(err);
|
||||
try dlbw.writeByte(DW.LNS.const_add_pc);
|
||||
break :remaining op_advance - max_op_advance;
|
||||
} else op_advance);
|
||||
|
||||
dlbw.writeByte(
|
||||
try dlbw.writeByte(
|
||||
if (remaining_delta_line == 0 and remaining_op_advance == 0)
|
||||
DW.LNS.copy
|
||||
else
|
||||
@intCast((remaining_delta_line - header.line_base) +
|
||||
(header.line_range * remaining_op_advance) + header.opcode_base),
|
||||
) catch |err| return @errorCast(err);
|
||||
);
|
||||
}
|
||||
|
||||
pub fn setColumn(wip_nav: *WipNav, column: u32) Allocator.Error!void {
|
||||
const dlbw = &wip_nav.debug_line.buffered_writer;
|
||||
dlbw.writeByte(DW.LNS.set_column) catch |err| return @errorCast(err);
|
||||
dlbw.writeLeb128(column + 1) catch |err| return @errorCast(err);
|
||||
try dlbw.writeByte(DW.LNS.set_column);
|
||||
try dlbw.writeLeb128(column + 1);
|
||||
}
|
||||
|
||||
pub fn negateStmt(wip_nav: *WipNav) Allocator.Error!void {
|
||||
return @errorCast(wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.negate_stmt));
|
||||
return wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.negate_stmt);
|
||||
}
|
||||
|
||||
pub fn setPrologueEnd(wip_nav: *WipNav) Allocator.Error!void {
|
||||
return @errorCast(wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.set_prologue_end));
|
||||
return wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.set_prologue_end);
|
||||
}
|
||||
|
||||
pub fn setEpilogueBegin(wip_nav: *WipNav) Allocator.Error!void {
|
||||
return @errorCast(wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.set_epilogue_begin));
|
||||
return wip_nav.debug_line.buffered_writer.writeByte(DW.LNS.set_epilogue_begin);
|
||||
}
|
||||
|
||||
pub fn enterBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void {
|
||||
@@ -2432,7 +2432,7 @@ pub fn initWipNav(
|
||||
nav_index: InternPool.Nav.Index,
|
||||
sym_index: u32,
|
||||
) error{ OutOfMemory, CodegenFail }!?WipNav {
|
||||
return dwarf.initWipNavInner(pt, nav_index, sym_index) catch |err| switch (@as(UpdateError, @errorCast(err))) {
|
||||
return dwarf.initWipNavInner(pt, nav_index, sym_index) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => |e| return pt.zcu.codegenFail(nav_index, "failed to init dwarf nav: {s}", .{@errorName(e)}),
|
||||
};
|
||||
@@ -2445,7 +2445,7 @@ pub fn finishWipNavFunc(
|
||||
code_size: u64,
|
||||
wip_nav: *WipNav,
|
||||
) error{ OutOfMemory, CodegenFail }!void {
|
||||
return dwarf.finishWipNavFuncInner(pt, nav_index, code_size, wip_nav) catch |err| switch (@as(UpdateError, @errorCast(err))) {
|
||||
return dwarf.finishWipNavFuncInner(pt, nav_index, code_size, wip_nav) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => |e| return pt.zcu.codegenFail(nav_index, "failed to finish dwarf func nav: {s}", .{@errorName(e)}),
|
||||
};
|
||||
@@ -2457,7 +2457,7 @@ pub fn finishWipNav(
|
||||
nav_index: InternPool.Nav.Index,
|
||||
wip_nav: *WipNav,
|
||||
) error{ OutOfMemory, CodegenFail }!void {
|
||||
return dwarf.finishWipNavInner(pt, nav_index, wip_nav) catch |err| switch (@as(UpdateError, @errorCast(err))) {
|
||||
return dwarf.finishWipNavInner(pt, nav_index, wip_nav) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => |e| return pt.zcu.codegenFail(nav_index, "failed to finish dwarf nav: {s}", .{@errorName(e)}),
|
||||
};
|
||||
@@ -2468,7 +2468,7 @@ pub fn updateComptimeNav(
|
||||
pt: Zcu.PerThread,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
) error{ OutOfMemory, CodegenFail }!void {
|
||||
return dwarf.updateComptimeNavInner(pt, nav_index) catch |err| switch (@as(UpdateError, @errorCast(err))) {
|
||||
return dwarf.updateComptimeNavInner(pt, nav_index) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => |e| return pt.zcu.codegenFail(nav_index, "failed to update dwarf comptime nav: {s}", .{@errorName(e)}),
|
||||
};
|
||||
@@ -2479,14 +2479,14 @@ pub fn updateContainerType(
|
||||
pt: Zcu.PerThread,
|
||||
type_index: InternPool.Index,
|
||||
) error{ OutOfMemory, CodegenFail }!void {
|
||||
return dwarf.updateContainerType(pt, type_index) catch |err| switch (@as(UpdateError, @errorCast(err))) {
|
||||
return dwarf.updateContainerType(pt, type_index) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => |e| return pt.zcu.codegenFailType(type_index, "failed to update dwarf comptime nav: {s}", .{@errorName(e)}),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
|
||||
return @errorCast(dwarf.flushModuleInner(pt));
|
||||
return dwarf.flushModuleInner(pt);
|
||||
}
|
||||
|
||||
fn initWipNavInner(
|
||||
|
||||
@@ -674,7 +674,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi
|
||||
error.InvalidInstruction,
|
||||
error.CannotEncode,
|
||||
=> has_reloc_errors = true,
|
||||
else => |e| return @errorCast(e),
|
||||
else => |e| return e,
|
||||
},
|
||||
.aarch64 => aarch64.resolveRelocAlloc(self, elf_file, rel, target, args, &it, &bw) catch |err| switch (err) {
|
||||
error.RelocFailure,
|
||||
@@ -682,13 +682,13 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi
|
||||
error.UnexpectedRemainder,
|
||||
error.DivisionByZero,
|
||||
=> has_reloc_errors = true,
|
||||
else => |e| return @errorCast(e),
|
||||
else => |e| return e,
|
||||
},
|
||||
.riscv64 => riscv.resolveRelocAlloc(self, elf_file, rel, target, args, &it, &bw) catch |err| switch (err) {
|
||||
error.RelocFailure,
|
||||
error.RelaxFailure,
|
||||
=> has_reloc_errors = true,
|
||||
else => |e| return @errorCast(e),
|
||||
else => |e| return e,
|
||||
},
|
||||
else => return error.UnsupportedCpuArch,
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ pub fn resolveRelocs(self: Atom, macho_file: *MachO, buffer: []u8) !void {
|
||||
}
|
||||
|
||||
bw.end = std.math.cast(usize, rel_offset) orelse return error.Overflow;
|
||||
self.resolveRelocInner(rel, subtractor, buffer, macho_file, &bw) catch |err| switch (@as(ResolveError, @errorCast(err))) {
|
||||
self.resolveRelocInner(rel, subtractor, buffer, macho_file, &bw) catch |err| switch (err) {
|
||||
error.RelaxFail => {
|
||||
const target = switch (rel.tag) {
|
||||
.@"extern" => rel.getTargetSymbol(self, macho_file).getName(macho_file),
|
||||
|
||||
@@ -67,7 +67,7 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Pat
|
||||
|
||||
try writeSections(macho_file);
|
||||
sortRelocs(macho_file);
|
||||
writeSectionsToFile(macho_file) catch |err| return @errorCast(err);
|
||||
try writeSectionsToFile(macho_file);
|
||||
|
||||
// In order to please Apple ld (and possibly other MachO linkers in the wild),
|
||||
// we will now sanitize segment names of Zig-specific segments.
|
||||
@@ -131,7 +131,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
|
||||
|
||||
try writeSections(macho_file);
|
||||
sortRelocs(macho_file);
|
||||
writeSectionsToFile(macho_file) catch |err| return @errorCast(err);
|
||||
try writeSectionsToFile(macho_file);
|
||||
|
||||
// In order to please Apple ld (and possibly other MachO linkers in the wild),
|
||||
// we will now sanitize segment names of Zig-specific segments.
|
||||
|
||||
+4
-4
@@ -665,11 +665,11 @@ pub fn flush(
|
||||
// connect the previous decl to the next
|
||||
const delta_line = @as(i32, @intCast(out.start_line)) - @as(i32, @intCast(linecount));
|
||||
|
||||
changeLine(linecountinfo_bw, delta_line) catch |err| return @errorCast(err);
|
||||
try changeLine(linecountinfo_bw, delta_line);
|
||||
// TODO change the pc too (maybe?)
|
||||
|
||||
// write out the actual info that was generated in codegen now
|
||||
linecountinfo_bw.writeAll(out.lineinfo) catch |err| return @errorCast(err);
|
||||
try linecountinfo_bw.writeAll(out.lineinfo);
|
||||
linecount = out.end_line;
|
||||
}
|
||||
foff += out.code.len;
|
||||
@@ -692,7 +692,7 @@ pub fn flush(
|
||||
}
|
||||
if (linecountinfo_aw.getWritten().len & 1 == 1) {
|
||||
// just a nop to make it even, the plan9 linker does this
|
||||
linecountinfo_bw.writeByte(129) catch |err| return @errorCast(err);
|
||||
try linecountinfo_bw.writeByte(129);
|
||||
}
|
||||
}
|
||||
const linecountinfo = linecountinfo_aw.getWritten();
|
||||
@@ -822,7 +822,7 @@ pub fn flush(
|
||||
var syms_aw: std.io.AllocatingWriter = undefined;
|
||||
syms_aw.init(gpa);
|
||||
defer syms_aw.deinit();
|
||||
self.writeSyms(&syms_aw.buffered_writer) catch |err| return @errorCast(err);
|
||||
try self.writeSyms(&syms_aw.buffered_writer);
|
||||
const syms = syms_aw.getWritten();
|
||||
assert(2 + self.atomCount() - self.externCount() == iovecs_i); // we didn't write all the decls
|
||||
iovecs[iovecs_i] = .{ .base = syms.ptr, .len = syms.len };
|
||||
|
||||
+4
-4
@@ -207,7 +207,7 @@ pub fn flush(
|
||||
error_info.init(self.object.gpa);
|
||||
defer error_info.deinit();
|
||||
|
||||
error_info.buffered_writer.writeAll("zig_errors:") catch |err| return @errorCast(err);
|
||||
try error_info.buffered_writer.writeAll("zig_errors:");
|
||||
const ip = &self.base.comp.zcu.?.intern_pool;
|
||||
for (ip.global_error_set.getNamesFromMainThread()) |name| {
|
||||
// Errors can contain pretty much any character - to encode them in a string we must escape
|
||||
@@ -215,8 +215,8 @@ pub fn flush(
|
||||
// name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
|
||||
// We're using : as separator, which is a reserved character.
|
||||
|
||||
error_info.buffered_writer.writeByte(':') catch |err| return @errorCast(err);
|
||||
std.Uri.Component.percentEncode(
|
||||
try error_info.buffered_writer.writeByte(':');
|
||||
try std.Uri.Component.percentEncode(
|
||||
&error_info.buffered_writer,
|
||||
name.toSlice(ip),
|
||||
struct {
|
||||
@@ -227,7 +227,7 @@ pub fn flush(
|
||||
};
|
||||
}
|
||||
}.isValidChar,
|
||||
) catch |err| return @errorCast(err);
|
||||
);
|
||||
}
|
||||
try spv.sections.debug_strings.emit(gpa, .OpSourceExtension, .{
|
||||
.extension = error_info.getWritten(),
|
||||
|
||||
Reference in New Issue
Block a user