authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-26 08:01:51+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-01-26 08:01:51+01:00
log48f9e491cb97de54c7e8d395170d8b4c8ea9a62b
tree1814df5a930afc03f1cadd114ccee2b2204107f1
parent96a55f6ce86dc2e25c275ee3211b2cde0e3d92ab
parenta95d58caf289ecc2ab36cdb30437f634c07b64e4
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #14453 from ziglang/self-hosted-codegen-cleanup

self-hosted: cleanup codegen.Result

12 files changed, 121 insertions(+), 211 deletions(-)

src/arch/aarch64/CodeGen.zig+9-9
......@@ -24,7 +24,7 @@ const log = std.log.scoped(.codegen);
2424const build_options = @import("build_options");
2525
2626const GenerateSymbolError = codegen.GenerateSymbolError;
27const FnResult = codegen.FnResult;
27const Result = codegen.Result;
2828const DebugInfoOutput = codegen.DebugInfoOutput;
2929
3030const bits = @import("bits.zig");
......@@ -349,7 +349,7 @@ pub fn generate(
349349 liveness: Liveness,
350350 code: *std.ArrayList(u8),
351351 debug_output: DebugInfoOutput,
352) GenerateSymbolError!FnResult {
352) GenerateSymbolError!Result {
353353 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
354354 @panic("Attempted to compile for architecture that was disabled by build configuration");
355355 }
......@@ -392,8 +392,8 @@ pub fn generate(
392392 defer function.dbg_info_relocs.deinit(bin_file.allocator);
393393
394394 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
395 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
396 error.OutOfRegisters => return FnResult{
395 error.CodegenFail => return Result{ .fail = function.err_msg.? },
396 error.OutOfRegisters => return Result{
397397 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
398398 },
399399 else => |e| return e,
......@@ -406,8 +406,8 @@ pub fn generate(
406406 function.max_end_stack = call_info.stack_byte_count;
407407
408408 function.gen() catch |err| switch (err) {
409 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
410 error.OutOfRegisters => return FnResult{
409 error.CodegenFail => return Result{ .fail = function.err_msg.? },
410 error.OutOfRegisters => return Result{
411411 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
412412 },
413413 else => |e| return e,
......@@ -439,14 +439,14 @@ pub fn generate(
439439 defer emit.deinit();
440440
441441 emit.emitMir() catch |err| switch (err) {
442 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },
442 error.EmitFail => return Result{ .fail = emit.err_msg.? },
443443 else => |e| return e,
444444 };
445445
446446 if (function.err_msg) |em| {
447 return FnResult{ .fail = em };
447 return Result{ .fail = em };
448448 } else {
449 return FnResult{ .appended = {} };
449 return Result.ok;
450450 }
451451}
452452
src/arch/arm/CodeGen.zig+9-9
......@@ -23,7 +23,7 @@ const leb128 = std.leb;
2323const log = std.log.scoped(.codegen);
2424const build_options = @import("build_options");
2525
26const FnResult = codegen.FnResult;
26const Result = codegen.Result;
2727const GenerateSymbolError = codegen.GenerateSymbolError;
2828const DebugInfoOutput = codegen.DebugInfoOutput;
2929
......@@ -356,7 +356,7 @@ pub fn generate(
356356 liveness: Liveness,
357357 code: *std.ArrayList(u8),
358358 debug_output: DebugInfoOutput,
359) GenerateSymbolError!FnResult {
359) GenerateSymbolError!Result {
360360 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
361361 @panic("Attempted to compile for architecture that was disabled by build configuration");
362362 }
......@@ -399,8 +399,8 @@ pub fn generate(
399399 defer function.dbg_info_relocs.deinit(bin_file.allocator);
400400
401401 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
402 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
403 error.OutOfRegisters => return FnResult{
402 error.CodegenFail => return Result{ .fail = function.err_msg.? },
403 error.OutOfRegisters => return Result{
404404 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
405405 },
406406 else => |e| return e,
......@@ -413,8 +413,8 @@ pub fn generate(
413413 function.max_end_stack = call_info.stack_byte_count;
414414
415415 function.gen() catch |err| switch (err) {
416 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
417 error.OutOfRegisters => return FnResult{
416 error.CodegenFail => return Result{ .fail = function.err_msg.? },
417 error.OutOfRegisters => return Result{
418418 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
419419 },
420420 else => |e| return e,
......@@ -446,14 +446,14 @@ pub fn generate(
446446 defer emit.deinit();
447447
448448 emit.emitMir() catch |err| switch (err) {
449 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },
449 error.EmitFail => return Result{ .fail = emit.err_msg.? },
450450 else => |e| return e,
451451 };
452452
453453 if (function.err_msg) |em| {
454 return FnResult{ .fail = em };
454 return Result{ .fail = em };
455455 } else {
456 return FnResult{ .appended = {} };
456 return Result.ok;
457457 }
458458}
459459
src/arch/riscv64/CodeGen.zig+9-9
......@@ -22,7 +22,7 @@ const leb128 = std.leb;
2222const log = std.log.scoped(.codegen);
2323const build_options = @import("build_options");
2424
25const FnResult = @import("../../codegen.zig").FnResult;
25const Result = @import("../../codegen.zig").Result;
2626const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;
2727const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2828
......@@ -225,7 +225,7 @@ pub fn generate(
225225 liveness: Liveness,
226226 code: *std.ArrayList(u8),
227227 debug_output: DebugInfoOutput,
228) GenerateSymbolError!FnResult {
228) GenerateSymbolError!Result {
229229 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
230230 @panic("Attempted to compile for architecture that was disabled by build configuration");
231231 }
......@@ -268,8 +268,8 @@ pub fn generate(
268268 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
269269
270270 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
271 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
272 error.OutOfRegisters => return FnResult{
271 error.CodegenFail => return Result{ .fail = function.err_msg.? },
272 error.OutOfRegisters => return Result{
273273 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
274274 },
275275 else => |e| return e,
......@@ -282,8 +282,8 @@ pub fn generate(
282282 function.max_end_stack = call_info.stack_byte_count;
283283
284284 function.gen() catch |err| switch (err) {
285 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
286 error.OutOfRegisters => return FnResult{
285 error.CodegenFail => return Result{ .fail = function.err_msg.? },
286 error.OutOfRegisters => return Result{
287287 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
288288 },
289289 else => |e| return e,
......@@ -309,14 +309,14 @@ pub fn generate(
309309 defer emit.deinit();
310310
311311 emit.emitMir() catch |err| switch (err) {
312 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },
312 error.EmitFail => return Result{ .fail = emit.err_msg.? },
313313 else => |e| return e,
314314 };
315315
316316 if (function.err_msg) |em| {
317 return FnResult{ .fail = em };
317 return Result{ .fail = em };
318318 } else {
319 return FnResult{ .appended = {} };
319 return Result.ok;
320320 }
321321}
322322
src/arch/sparc64/CodeGen.zig+9-9
......@@ -20,7 +20,7 @@ const Emit = @import("Emit.zig");
2020const Liveness = @import("../../Liveness.zig");
2121const Type = @import("../../type.zig").Type;
2222const GenerateSymbolError = @import("../../codegen.zig").GenerateSymbolError;
23const FnResult = @import("../../codegen.zig").FnResult;
23const Result = @import("../../codegen.zig").Result;
2424const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
2525
2626const build_options = @import("build_options");
......@@ -265,7 +265,7 @@ pub fn generate(
265265 liveness: Liveness,
266266 code: *std.ArrayList(u8),
267267 debug_output: DebugInfoOutput,
268) GenerateSymbolError!FnResult {
268) GenerateSymbolError!Result {
269269 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
270270 @panic("Attempted to compile for architecture that was disabled by build configuration");
271271 }
......@@ -310,8 +310,8 @@ pub fn generate(
310310 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
311311
312312 var call_info = function.resolveCallingConventionValues(fn_type, .callee) catch |err| switch (err) {
313 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
314 error.OutOfRegisters => return FnResult{
313 error.CodegenFail => return Result{ .fail = function.err_msg.? },
314 error.OutOfRegisters => return Result{
315315 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
316316 },
317317 else => |e| return e,
......@@ -324,8 +324,8 @@ pub fn generate(
324324 function.max_end_stack = call_info.stack_byte_count;
325325
326326 function.gen() catch |err| switch (err) {
327 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
328 error.OutOfRegisters => return FnResult{
327 error.CodegenFail => return Result{ .fail = function.err_msg.? },
328 error.OutOfRegisters => return Result{
329329 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
330330 },
331331 else => |e| return e,
......@@ -351,14 +351,14 @@ pub fn generate(
351351 defer emit.deinit();
352352
353353 emit.emitMir() catch |err| switch (err) {
354 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },
354 error.EmitFail => return Result{ .fail = emit.err_msg.? },
355355 else => |e| return e,
356356 };
357357
358358 if (function.err_msg) |em| {
359 return FnResult{ .fail = em };
359 return Result{ .fail = em };
360360 } else {
361 return FnResult{ .appended = {} };
361 return Result.ok;
362362 }
363363}
364364
src/arch/wasm/CodeGen.zig+3-10
......@@ -627,13 +627,6 @@ test "Wasm - buildOpcode" {
627627 try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
628628}
629629
630pub const Result = union(enum) {
631 /// The codegen bytes have been appended to `Context.code`
632 appended: void,
633 /// The data is managed externally and are part of the `Result`
634 externally_managed: []const u8,
635};
636
637630/// Hashmap to store generated `WValue` for each `Air.Inst.Ref`
638631pub const ValueTable = std.AutoArrayHashMapUnmanaged(Air.Inst.Ref, WValue);
639632
......@@ -1171,7 +1164,7 @@ pub fn generate(
11711164 liveness: Liveness,
11721165 code: *std.ArrayList(u8),
11731166 debug_output: codegen.DebugInfoOutput,
1174) codegen.GenerateSymbolError!codegen.FnResult {
1167) codegen.GenerateSymbolError!codegen.Result {
11751168 _ = src_loc;
11761169 var code_gen: CodeGen = .{
11771170 .gpa = bin_file.allocator,
......@@ -1190,11 +1183,11 @@ pub fn generate(
11901183 defer code_gen.deinit();
11911184
11921185 genFunc(&code_gen) catch |err| switch (err) {
1193 error.CodegenFail => return codegen.FnResult{ .fail = code_gen.err_msg },
1186 error.CodegenFail => return codegen.Result{ .fail = code_gen.err_msg },
11941187 else => |e| return e,
11951188 };
11961189
1197 return codegen.FnResult{ .appended = {} };
1190 return codegen.Result.ok;
11981191}
11991192
12001193fn genFunc(func: *CodeGen) InnerError!void {
src/arch/x86_64/CodeGen.zig+9-9
......@@ -16,7 +16,7 @@ const Compilation = @import("../../Compilation.zig");
1616const DebugInfoOutput = codegen.DebugInfoOutput;
1717const DW = std.dwarf;
1818const ErrorMsg = Module.ErrorMsg;
19const FnResult = codegen.FnResult;
19const Result = codegen.Result;
2020const GenerateSymbolError = codegen.GenerateSymbolError;
2121const Emit = @import("Emit.zig");
2222const Liveness = @import("../../Liveness.zig");
......@@ -257,7 +257,7 @@ pub fn generate(
257257 liveness: Liveness,
258258 code: *std.ArrayList(u8),
259259 debug_output: DebugInfoOutput,
260) GenerateSymbolError!FnResult {
260) GenerateSymbolError!Result {
261261 if (build_options.skip_non_native and builtin.cpu.arch != bin_file.options.target.cpu.arch) {
262262 @panic("Attempted to compile for architecture that was disabled by build configuration");
263263 }
......@@ -305,8 +305,8 @@ pub fn generate(
305305 defer if (builtin.mode == .Debug) function.mir_to_air_map.deinit();
306306
307307 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
308 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
309 error.OutOfRegisters => return FnResult{
308 error.CodegenFail => return Result{ .fail = function.err_msg.? },
309 error.OutOfRegisters => return Result{
310310 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
311311 },
312312 else => |e| return e,
......@@ -319,8 +319,8 @@ pub fn generate(
319319 function.max_end_stack = call_info.stack_byte_count;
320320
321321 function.gen() catch |err| switch (err) {
322 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
323 error.OutOfRegisters => return FnResult{
322 error.CodegenFail => return Result{ .fail = function.err_msg.? },
323 error.OutOfRegisters => return Result{
324324 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
325325 },
326326 else => |e| return e,
......@@ -345,14 +345,14 @@ pub fn generate(
345345 };
346346 defer emit.deinit();
347347 emit.lowerMir() catch |err| switch (err) {
348 error.EmitFail => return FnResult{ .fail = emit.err_msg.? },
348 error.EmitFail => return Result{ .fail = emit.err_msg.? },
349349 else => |e| return e,
350350 };
351351
352352 if (function.err_msg) |em| {
353 return FnResult{ .fail = em };
353 return Result{ .fail = em };
354354 } else {
355 return FnResult{ .appended = {} };
355 return Result.ok;
356356 }
357357}
358358
src/codegen.zig+58-131
......@@ -21,16 +21,11 @@ const TypedValue = @import("TypedValue.zig");
2121const Value = @import("value.zig").Value;
2222const Zir = @import("Zir.zig");
2323
24pub const FnResult = union(enum) {
25 /// The `code` parameter passed to `generateSymbol` has the value appended.
26 appended: void,
27 fail: *ErrorMsg,
28};
2924pub const Result = union(enum) {
30 /// The `code` parameter passed to `generateSymbol` has the value appended.
31 appended: void,
32 /// The value is available externally, `code` is unused.
33 externally_managed: []const u8,
25 /// The `code` parameter passed to `generateSymbol` has the value ok.
26 ok: void,
27
28 /// There was a codegen error.
3429 fail: *ErrorMsg,
3530};
3631
......@@ -89,7 +84,7 @@ pub fn generateFunction(
8984 liveness: Liveness,
9085 code: *std.ArrayList(u8),
9186 debug_output: DebugInfoOutput,
92) GenerateSymbolError!FnResult {
87) GenerateSymbolError!Result {
9388 switch (bin_file.options.target.cpu.arch) {
9489 .arm,
9590 .armeb,
......@@ -145,7 +140,7 @@ pub fn generateSymbol(
145140 if (typed_value.val.isUndefDeep()) {
146141 const abi_size = math.cast(usize, typed_value.ty.abiSize(target)) orelse return error.Overflow;
147142 try code.appendNTimes(0xaa, abi_size);
148 return Result{ .appended = {} };
143 return Result.ok;
149144 }
150145
151146 switch (typed_value.ty.zigTypeTag()) {
......@@ -176,7 +171,7 @@ pub fn generateSymbol(
176171 128 => writeFloat(f128, typed_value.val.toFloat(f128), target, endian, try code.addManyAsArray(16)),
177172 else => unreachable,
178173 }
179 return Result{ .appended = {} };
174 return Result.ok;
180175 },
181176 .Array => switch (typed_value.val.tag()) {
182177 .bytes => {
......@@ -185,7 +180,7 @@ pub fn generateSymbol(
185180 // The bytes payload already includes the sentinel, if any
186181 try code.ensureUnusedCapacity(len);
187182 code.appendSliceAssumeCapacity(bytes[0..len]);
188 return Result{ .appended = {} };
183 return Result.ok;
189184 },
190185 .str_lit => {
191186 const str_lit = typed_value.val.castTag(.str_lit).?.data;
......@@ -197,7 +192,7 @@ pub fn generateSymbol(
197192 const byte = @intCast(u8, sent_val.toUnsignedInt(target));
198193 code.appendAssumeCapacity(byte);
199194 }
200 return Result{ .appended = {} };
195 return Result.ok;
201196 },
202197 .aggregate => {
203198 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
......@@ -208,14 +203,11 @@ pub fn generateSymbol(
208203 .ty = elem_ty,
209204 .val = elem_val,
210205 }, code, debug_output, reloc_info)) {
211 .appended => {},
212 .externally_managed => |slice| {
213 code.appendSliceAssumeCapacity(slice);
214 },
206 .ok => {},
215207 .fail => |em| return Result{ .fail = em },
216208 }
217209 }
218 return Result{ .appended = {} };
210 return Result.ok;
219211 },
220212 .repeated => {
221213 const array = typed_value.val.castTag(.repeated).?.data;
......@@ -229,10 +221,7 @@ pub fn generateSymbol(
229221 .ty = elem_ty,
230222 .val = array,
231223 }, code, debug_output, reloc_info)) {
232 .appended => {},
233 .externally_managed => |slice| {
234 code.appendSliceAssumeCapacity(slice);
235 },
224 .ok => {},
236225 .fail => |em| return Result{ .fail = em },
237226 }
238227 }
......@@ -242,15 +231,12 @@ pub fn generateSymbol(
242231 .ty = elem_ty,
243232 .val = sentinel_val,
244233 }, code, debug_output, reloc_info)) {
245 .appended => {},
246 .externally_managed => |slice| {
247 code.appendSliceAssumeCapacity(slice);
248 },
234 .ok => {},
249235 .fail => |em| return Result{ .fail = em },
250236 }
251237 }
252238
253 return Result{ .appended = {} };
239 return Result.ok;
254240 },
255241 .empty_array_sentinel => {
256242 const elem_ty = typed_value.ty.childType();
......@@ -259,13 +245,10 @@ pub fn generateSymbol(
259245 .ty = elem_ty,
260246 .val = sentinel_val,
261247 }, code, debug_output, reloc_info)) {
262 .appended => {},
263 .externally_managed => |slice| {
264 code.appendSliceAssumeCapacity(slice);
265 },
248 .ok => {},
266249 .fail => |em| return Result{ .fail = em },
267250 }
268 return Result{ .appended = {} };
251 return Result.ok;
269252 },
270253 else => return Result{
271254 .fail = try ErrorMsg.create(
......@@ -289,7 +272,7 @@ pub fn generateSymbol(
289272 },
290273 else => unreachable,
291274 }
292 return Result{ .appended = {} };
275 return Result.ok;
293276 },
294277 .variable => {
295278 const decl = typed_value.val.castTag(.variable).?.data.owner_decl;
......@@ -309,10 +292,7 @@ pub fn generateSymbol(
309292 .ty = slice_ptr_field_type,
310293 .val = slice.ptr,
311294 }, code, debug_output, reloc_info)) {
312 .appended => {},
313 .externally_managed => |external_slice| {
314 code.appendSliceAssumeCapacity(external_slice);
315 },
295 .ok => {},
316296 .fail => |em| return Result{ .fail = em },
317297 }
318298
......@@ -321,14 +301,11 @@ pub fn generateSymbol(
321301 .ty = Type.initTag(.usize),
322302 .val = slice.len,
323303 }, code, debug_output, reloc_info)) {
324 .appended => {},
325 .externally_managed => |external_slice| {
326 code.appendSliceAssumeCapacity(external_slice);
327 },
304 .ok => {},
328305 .fail => |em| return Result{ .fail = em },
329306 }
330307
331 return Result{ .appended = {} };
308 return Result.ok;
332309 },
333310 .field_ptr => {
334311 const field_ptr = typed_value.val.castTag(.field_ptr).?.data;
......@@ -375,13 +352,10 @@ pub fn generateSymbol(
375352 .ty = typed_value.ty,
376353 .val = container_ptr,
377354 }, code, debug_output, reloc_info)) {
378 .appended => {},
379 .externally_managed => |external_slice| {
380 code.appendSliceAssumeCapacity(external_slice);
381 },
355 .ok => {},
382356 .fail => |em| return Result{ .fail = em },
383357 }
384 return Result{ .appended = {} };
358 return Result.ok;
385359 },
386360 else => return Result{
387361 .fail = try ErrorMsg.create(
......@@ -434,7 +408,7 @@ pub fn generateSymbol(
434408 .signed => @bitCast(u8, @intCast(i8, typed_value.val.toSignedInt(target))),
435409 };
436410 try code.append(x);
437 return Result{ .appended = {} };
411 return Result.ok;
438412 }
439413 if (info.bits > 64) {
440414 var bigint_buffer: Value.BigIntSpace = undefined;
......@@ -443,7 +417,7 @@ pub fn generateSymbol(
443417 const start = code.items.len;
444418 try code.resize(start + abi_size);
445419 bigint.writeTwosComplement(code.items[start..][0..abi_size], endian);
446 return Result{ .appended = {} };
420 return Result.ok;
447421 }
448422 switch (info.signedness) {
449423 .unsigned => {
......@@ -471,7 +445,7 @@ pub fn generateSymbol(
471445 }
472446 },
473447 }
474 return Result{ .appended = {} };
448 return Result.ok;
475449 },
476450 .Enum => {
477451 var int_buffer: Value.Payload.U64 = undefined;
......@@ -481,7 +455,7 @@ pub fn generateSymbol(
481455 if (info.bits <= 8) {
482456 const x = @intCast(u8, int_val.toUnsignedInt(target));
483457 try code.append(x);
484 return Result{ .appended = {} };
458 return Result.ok;
485459 }
486460 if (info.bits > 64) {
487461 return Result{
......@@ -519,12 +493,12 @@ pub fn generateSymbol(
519493 }
520494 },
521495 }
522 return Result{ .appended = {} };
496 return Result.ok;
523497 },
524498 .Bool => {
525499 const x: u8 = @boolToInt(typed_value.val.toBool());
526500 try code.append(x);
527 return Result{ .appended = {} };
501 return Result.ok;
528502 },
529503 .Struct => {
530504 if (typed_value.ty.containerLayout() == .Packed) {
......@@ -549,12 +523,7 @@ pub fn generateSymbol(
549523 .ty = field_ty,
550524 .val = field_val,
551525 }, &tmp_list, debug_output, reloc_info)) {
552 .appended => {
553 mem.copy(u8, code.items[current_pos..], tmp_list.items);
554 },
555 .externally_managed => |external_slice| {
556 mem.copy(u8, code.items[current_pos..], external_slice);
557 },
526 .ok => mem.copy(u8, code.items[current_pos..], tmp_list.items),
558527 .fail => |em| return Result{ .fail = em },
559528 }
560529 } else {
......@@ -563,7 +532,7 @@ pub fn generateSymbol(
563532 bits += @intCast(u16, field_ty.bitSize(target));
564533 }
565534
566 return Result{ .appended = {} };
535 return Result.ok;
567536 }
568537
569538 const struct_begin = code.items.len;
......@@ -576,10 +545,7 @@ pub fn generateSymbol(
576545 .ty = field_ty,
577546 .val = field_val,
578547 }, code, debug_output, reloc_info)) {
579 .appended => {},
580 .externally_managed => |external_slice| {
581 code.appendSliceAssumeCapacity(external_slice);
582 },
548 .ok => {},
583549 .fail => |em| return Result{ .fail = em },
584550 }
585551 const unpadded_field_end = code.items.len - struct_begin;
......@@ -593,7 +559,7 @@ pub fn generateSymbol(
593559 }
594560 }
595561
596 return Result{ .appended = {} };
562 return Result.ok;
597563 },
598564 .Union => {
599565 const union_obj = typed_value.val.castTag(.@"union").?.data;
......@@ -612,10 +578,7 @@ pub fn generateSymbol(
612578 .ty = typed_value.ty.unionTagType().?,
613579 .val = union_obj.tag,
614580 }, code, debug_output, reloc_info)) {
615 .appended => {},
616 .externally_managed => |external_slice| {
617 code.appendSliceAssumeCapacity(external_slice);
618 },
581 .ok => {},
619582 .fail => |em| return Result{ .fail = em },
620583 }
621584 }
......@@ -632,10 +595,7 @@ pub fn generateSymbol(
632595 .ty = field_ty,
633596 .val = union_obj.val,
634597 }, code, debug_output, reloc_info)) {
635 .appended => {},
636 .externally_managed => |external_slice| {
637 code.appendSliceAssumeCapacity(external_slice);
638 },
598 .ok => {},
639599 .fail => |em| return Result{ .fail = em },
640600 }
641601
......@@ -650,15 +610,12 @@ pub fn generateSymbol(
650610 .ty = union_ty.tag_ty,
651611 .val = union_obj.tag,
652612 }, code, debug_output, reloc_info)) {
653 .appended => {},
654 .externally_managed => |external_slice| {
655 code.appendSliceAssumeCapacity(external_slice);
656 },
613 .ok => {},
657614 .fail => |em| return Result{ .fail = em },
658615 }
659616 }
660617
661 return Result{ .appended = {} };
618 return Result.ok;
662619 },
663620 .Optional => {
664621 var opt_buf: Type.Payload.ElemType = undefined;
......@@ -669,7 +626,7 @@ pub fn generateSymbol(
669626
670627 if (!payload_type.hasRuntimeBits()) {
671628 try code.writer().writeByteNTimes(@boolToInt(is_pl), abi_size);
672 return Result{ .appended = {} };
629 return Result.ok;
673630 }
674631
675632 if (typed_value.ty.optionalReprIsPayload()) {
......@@ -678,10 +635,7 @@ pub fn generateSymbol(
678635 .ty = payload_type,
679636 .val = payload.data,
680637 }, code, debug_output, reloc_info)) {
681 .appended => {},
682 .externally_managed => |external_slice| {
683 code.appendSliceAssumeCapacity(external_slice);
684 },
638 .ok => {},
685639 .fail => |em| return Result{ .fail = em },
686640 }
687641 } else if (!typed_value.val.isNull()) {
......@@ -689,17 +643,14 @@ pub fn generateSymbol(
689643 .ty = payload_type,
690644 .val = typed_value.val,
691645 }, code, debug_output, reloc_info)) {
692 .appended => {},
693 .externally_managed => |external_slice| {
694 code.appendSliceAssumeCapacity(external_slice);
695 },
646 .ok => {},
696647 .fail => |em| return Result{ .fail = em },
697648 }
698649 } else {
699650 try code.writer().writeByteNTimes(0, abi_size);
700651 }
701652
702 return Result{ .appended = {} };
653 return Result.ok;
703654 }
704655
705656 const value = if (typed_value.val.castTag(.opt_payload)) |payload| payload.data else Value.initTag(.undef);
......@@ -708,14 +659,11 @@ pub fn generateSymbol(
708659 .ty = payload_type,
709660 .val = value,
710661 }, code, debug_output, reloc_info)) {
711 .appended => {},
712 .externally_managed => |external_slice| {
713 code.appendSliceAssumeCapacity(external_slice);
714 },
662 .ok => {},
715663 .fail => |em| return Result{ .fail = em },
716664 }
717665
718 return Result{ .appended = {} };
666 return Result.ok;
719667 },
720668 .ErrorUnion => {
721669 const error_ty = typed_value.ty.errorUnionSet();
......@@ -740,10 +688,7 @@ pub fn generateSymbol(
740688 .ty = error_ty,
741689 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
742690 }, code, debug_output, reloc_info)) {
743 .appended => {},
744 .externally_managed => |external_slice| {
745 code.appendSliceAssumeCapacity(external_slice);
746 },
691 .ok => {},
747692 .fail => |em| return Result{ .fail = em },
748693 }
749694 }
......@@ -756,10 +701,7 @@ pub fn generateSymbol(
756701 .ty = payload_ty,
757702 .val = payload_val,
758703 }, code, debug_output, reloc_info)) {
759 .appended => {},
760 .externally_managed => |external_slice| {
761 code.appendSliceAssumeCapacity(external_slice);
762 },
704 .ok => {},
763705 .fail => |em| return Result{ .fail = em },
764706 }
765707 const unpadded_end = code.items.len - begin;
......@@ -778,10 +720,7 @@ pub fn generateSymbol(
778720 .ty = error_ty,
779721 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
780722 }, code, debug_output, reloc_info)) {
781 .appended => {},
782 .externally_managed => |external_slice| {
783 code.appendSliceAssumeCapacity(external_slice);
784 },
723 .ok => {},
785724 .fail => |em| return Result{ .fail = em },
786725 }
787726 const unpadded_end = code.items.len - begin;
......@@ -793,7 +732,7 @@ pub fn generateSymbol(
793732 }
794733 }
795734
796 return Result{ .appended = {} };
735 return Result.ok;
797736 },
798737 .ErrorSet => {
799738 switch (typed_value.val.tag()) {
......@@ -806,7 +745,7 @@ pub fn generateSymbol(
806745 try code.writer().writeByteNTimes(0, @intCast(usize, Type.anyerror.abiSize(target)));
807746 },
808747 }
809 return Result{ .appended = {} };
748 return Result.ok;
810749 },
811750 .Vector => switch (typed_value.val.tag()) {
812751 .bytes => {
......@@ -814,7 +753,7 @@ pub fn generateSymbol(
814753 const len = @intCast(usize, typed_value.ty.arrayLen());
815754 try code.ensureUnusedCapacity(len);
816755 code.appendSliceAssumeCapacity(bytes[0..len]);
817 return Result{ .appended = {} };
756 return Result.ok;
818757 },
819758 .aggregate => {
820759 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
......@@ -825,14 +764,11 @@ pub fn generateSymbol(
825764 .ty = elem_ty,
826765 .val = elem_val,
827766 }, code, debug_output, reloc_info)) {
828 .appended => {},
829 .externally_managed => |slice| {
830 code.appendSliceAssumeCapacity(slice);
831 },
767 .ok => {},
832768 .fail => |em| return Result{ .fail = em },
833769 }
834770 }
835 return Result{ .appended = {} };
771 return Result.ok;
836772 },
837773 .repeated => {
838774 const array = typed_value.val.castTag(.repeated).?.data;
......@@ -845,14 +781,11 @@ pub fn generateSymbol(
845781 .ty = elem_ty,
846782 .val = array,
847783 }, code, debug_output, reloc_info)) {
848 .appended => {},
849 .externally_managed => |slice| {
850 code.appendSliceAssumeCapacity(slice);
851 },
784 .ok => {},
852785 .fail => |em| return Result{ .fail = em },
853786 }
854787 }
855 return Result{ .appended = {} };
788 return Result.ok;
856789 },
857790 .str_lit => {
858791 const str_lit = typed_value.val.castTag(.str_lit).?.data;
......@@ -860,7 +793,7 @@ pub fn generateSymbol(
860793 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
861794 try code.ensureUnusedCapacity(str_lit.len);
862795 code.appendSliceAssumeCapacity(bytes);
863 return Result{ .appended = {} };
796 return Result.ok;
864797 },
865798 else => unreachable,
866799 },
......@@ -901,10 +834,7 @@ fn lowerDeclRef(
901834 .ty = slice_ptr_field_type,
902835 .val = typed_value.val,
903836 }, code, debug_output, reloc_info)) {
904 .appended => {},
905 .externally_managed => |external_slice| {
906 code.appendSliceAssumeCapacity(external_slice);
907 },
837 .ok => {},
908838 .fail => |em| return Result{ .fail = em },
909839 }
910840
......@@ -917,14 +847,11 @@ fn lowerDeclRef(
917847 .ty = Type.usize,
918848 .val = Value.initPayload(&slice_len.base),
919849 }, code, debug_output, reloc_info)) {
920 .appended => {},
921 .externally_managed => |external_slice| {
922 code.appendSliceAssumeCapacity(external_slice);
923 },
850 .ok => {},
924851 .fail => |em| return Result{ .fail = em },
925852 }
926853
927 return Result{ .appended = {} };
854 return Result.ok;
928855 }
929856
930857 const ptr_width = target.cpu.arch.ptrBitWidth();
......@@ -932,7 +859,7 @@ fn lowerDeclRef(
932859 const is_fn_body = decl.ty.zigTypeTag() == .Fn;
933860 if (!is_fn_body and !decl.ty.hasRuntimeBits()) {
934861 try code.writer().writeByteNTimes(0xaa, @divExact(ptr_width, 8));
935 return Result{ .appended = {} };
862 return Result.ok;
936863 }
937864
938865 module.markDeclAlive(decl);
......@@ -950,7 +877,7 @@ fn lowerDeclRef(
950877 else => unreachable,
951878 }
952879
953 return Result{ .appended = {} };
880 return Result.ok;
954881}
955882
956883pub fn errUnionPayloadOffset(payload_ty: Type, target: std.Target) u64 {
src/link/Coff.zig+3-5
......@@ -928,7 +928,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
928928 .none,
929929 );
930930 const code = switch (res) {
931 .appended => code_buffer.items,
931 .ok => code_buffer.items,
932932 .fail => |em| {
933933 decl.analysis = .codegen_failure;
934934 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -981,8 +981,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
981981 .parent_atom_index = atom.sym_index,
982982 });
983983 const code = switch (res) {
984 .externally_managed => |x| x,
985 .appended => code_buffer.items,
984 .ok => code_buffer.items,
986985 .fail => |em| {
987986 decl.analysis = .codegen_failure;
988987 try mod.failed_decls.put(mod.gpa, decl_index, em);
......@@ -1042,8 +1041,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !
10421041 .parent_atom_index = decl.link.coff.sym_index,
10431042 });
10441043 const code = switch (res) {
1045 .externally_managed => |x| x,
1046 .appended => code_buffer.items,
1044 .ok => code_buffer.items,
10471045 .fail => |em| {
10481046 decl.analysis = .codegen_failure;
10491047 try module.failed_decls.put(module.gpa, decl_index, em);
src/link/Elf.zig+3-5
......@@ -2479,7 +2479,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
24792479 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
24802480
24812481 const code = switch (res) {
2482 .appended => code_buffer.items,
2482 .ok => code_buffer.items,
24832483 .fail => |em| {
24842484 decl.analysis = .codegen_failure;
24852485 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -2553,8 +2553,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v
25532553 });
25542554
25552555 const code = switch (res) {
2556 .externally_managed => |x| x,
2557 .appended => code_buffer.items,
2556 .ok => code_buffer.items,
25582557 .fail => |em| {
25592558 decl.analysis = .codegen_failure;
25602559 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -2618,8 +2617,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module
26182617 .parent_atom_index = atom.local_sym_index,
26192618 });
26202619 const code = switch (res) {
2621 .externally_managed => |x| x,
2622 .appended => code_buffer.items,
2620 .ok => code_buffer.items,
26232621 .fail => |em| {
26242622 decl.analysis = .codegen_failure;
26252623 try mod.failed_decls.put(mod.gpa, decl_index, em);
src/link/MachO.zig+3-5
......@@ -2017,7 +2017,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
20172017 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
20182018
20192019 const code = switch (res) {
2020 .appended => code_buffer.items,
2020 .ok => code_buffer.items,
20212021 .fail => |em| {
20222022 decl.analysis = .codegen_failure;
20232023 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -2082,8 +2082,7 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
20822082 .parent_atom_index = atom.sym_index,
20832083 });
20842084 const code = switch (res) {
2085 .externally_managed => |x| x,
2086 .appended => code_buffer.items,
2085 .ok => code_buffer.items,
20872086 .fail => |em| {
20882087 decl.analysis = .codegen_failure;
20892088 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -2167,8 +2166,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
21672166 });
21682167
21692168 const code = switch (res) {
2170 .externally_managed => |x| x,
2171 .appended => code_buffer.items,
2169 .ok => code_buffer.items,
21722170 .fail => |em| {
21732171 decl.analysis = .codegen_failure;
21742172 try module.failed_decls.put(module.gpa, decl_index, em);
src/link/Plan9.zig+3-5
......@@ -299,7 +299,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv
299299 },
300300 );
301301 const code = switch (res) {
302 .appended => try code_buffer.toOwnedSlice(),
302 .ok => try code_buffer.toOwnedSlice(),
303303 .fail => |em| {
304304 decl.analysis = .codegen_failure;
305305 try module.failed_decls.put(module.gpa, decl_index, em);
......@@ -358,8 +358,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
358358 .parent_atom_index = @enumToInt(decl_index),
359359 });
360360 const code = switch (res) {
361 .externally_managed => |x| x,
362 .appended => code_buffer.items,
361 .ok => code_buffer.items,
363362 .fail => |em| {
364363 decl.analysis = .codegen_failure;
365364 try mod.failed_decls.put(mod.gpa, decl_index, em);
......@@ -403,8 +402,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index)
403402 .parent_atom_index = @enumToInt(decl_index),
404403 });
405404 const code = switch (res) {
406 .externally_managed => |x| x,
407 .appended => code_buffer.items,
405 .ok => code_buffer.items,
408406 .fail => |em| {
409407 decl.analysis = .codegen_failure;
410408 try module.failed_decls.put(module.gpa, decl_index, em);
src/link/Wasm.zig+3-5
......@@ -1046,7 +1046,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes
10461046 );
10471047
10481048 const code = switch (result) {
1049 .appended => code_writer.items,
1049 .ok => code_writer.items,
10501050 .fail => |em| {
10511051 decl.analysis = .codegen_failure;
10521052 try mod.failed_decls.put(mod.gpa, decl_index, em);
......@@ -1113,8 +1113,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
11131113 );
11141114
11151115 const code = switch (res) {
1116 .externally_managed => |x| x,
1117 .appended => code_writer.items,
1116 .ok => code_writer.items,
11181117 .fail => |em| {
11191118 decl.analysis = .codegen_failure;
11201119 try mod.failed_decls.put(mod.gpa, decl_index, em);
......@@ -1250,8 +1249,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In
12501249 },
12511250 );
12521251 const code = switch (result) {
1253 .externally_managed => |x| x,
1254 .appended => value_bytes.items,
1252 .ok => value_bytes.items,
12551253 .fail => |em| {
12561254 decl.analysis = .codegen_failure;
12571255 try mod.failed_decls.put(mod.gpa, decl_index, em);