authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-19 15:03:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-19 15:03:41-07:00
log2083208f19a4eb7caa1953980f9a2f2496115695
treebfd2d7549780d25b012638422e38386313e0e321
parent22015c1b3bfcf816faf10ea0fc152c4686efb363

AstGen: implement functions with inferred error sets

This commit also reclaims +2 ZIR instruction tags by moving the following to `extended`: * func_var_args * func_extra * func_extra_var_args The following ZIR instruction tag is added: * func_inferred

5 files changed, 215 insertions(+), 183 deletions(-)

BRANCH_TODO+24
......@@ -737,3 +737,27 @@ fn errorSetDecl(
737737 try mod.analyzeExport(&decl_scope.base, export_src, name, decl);
738738 }
739739 }
740
741 fn writeFuncExtra(
742 self: *Writer,
743 stream: anytype,
744 inst: Inst.Index,
745 var_args: bool,
746 ) !void {
747 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
748 const src = inst_data.src();
749 const extra = self.code.extraData(Inst.FuncExtra, inst_data.payload_index);
750 const param_types = self.code.refSlice(extra.end, extra.data.param_types_len);
751 const cc = extra.data.cc;
752 const body = self.code.extra[extra.end + param_types.len ..][0..extra.data.body_len];
753 return self.writeFuncCommon(
754 stream,
755 param_types,
756 extra.data.return_type,
757 var_args,
758 cc,
759 body,
760 src,
761 );
762 }
763
src/AstGen.zig+17-37
......@@ -1375,9 +1375,7 @@ fn blockExprStmts(
13751375 .field_ptr_named,
13761376 .field_val_named,
13771377 .func,
1378 .func_var_args,
1379 .func_extra,
1380 .func_extra_var_args,
1378 .func_inferred,
13811379 .int,
13821380 .float,
13831381 .float128,
......@@ -2129,9 +2127,8 @@ fn fnDecl(
21292127 }
21302128
21312129 const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1;
2132 if (token_tags[maybe_bang] == .bang) {
2133 return astgen.failTok(maybe_bang, "TODO implement inferred error sets", .{});
2134 }
2130 const is_inferred_error = token_tags[maybe_bang] == .bang;
2131
21352132 const return_type_inst = try AstGen.expr(
21362133 &decl_gz,
21372134 &decl_gz.base,
......@@ -2153,31 +2150,24 @@ fn fnDecl(
21532150
21542151 const func_inst: Zir.Inst.Ref = if (body_node == 0) func: {
21552152 if (is_extern) {
2156 return astgen.failNode(fn_proto.ast.fn_token, "non-extern function has no body", .{});
2153 return astgen.failTok(fn_proto.ast.fn_token, "non-extern function has no body", .{});
21572154 }
2158
2159 if (cc != .none or lib_name != 0) {
2160 const tag: Zir.Inst.Tag = if (is_var_args) .func_extra_var_args else .func_extra;
2161 break :func try decl_gz.addFuncExtra(tag, .{
2162 .src_node = fn_proto.ast.proto_node,
2163 .ret_ty = return_type_inst,
2164 .param_types = param_types,
2165 .cc = cc,
2166 .lib_name = lib_name,
2167 .body = &[0]Zir.Inst.Index{},
2168 });
2155 if (is_inferred_error) {
2156 return astgen.failTok(maybe_bang, "function prototype requires explicit error set", .{});
21692157 }
2170
2171 const tag: Zir.Inst.Tag = if (is_var_args) .func_var_args else .func;
2172 break :func try decl_gz.addFunc(tag, .{
2158 break :func try decl_gz.addFunc(.{
21732159 .src_node = fn_proto.ast.proto_node,
21742160 .ret_ty = return_type_inst,
21752161 .param_types = param_types,
21762162 .body = &[0]Zir.Inst.Index{},
2163 .cc = cc,
2164 .lib_name = lib_name,
2165 .is_var_args = is_var_args,
2166 .is_inferred_error = false,
21772167 });
21782168 } else func: {
21792169 if (is_var_args) {
2180 return astgen.failNode(fn_proto.ast.fn_token, "non-extern function is variadic", .{});
2170 return astgen.failTok(fn_proto.ast.fn_token, "non-extern function is variadic", .{});
21812171 }
21822172
21832173 var fn_gz: Scope.GenZir = .{
......@@ -2224,30 +2214,20 @@ fn fnDecl(
22242214 if (fn_gz.instructions.items.len == 0 or
22252215 !astgen.instructions.items(.tag)[fn_gz.instructions.items.len - 1].isNoReturn())
22262216 {
2227 // astgen uses result location semantics to coerce return operands.
22282217 // Since we are adding the return instruction here, we must handle the coercion.
22292218 // We do this by using the `ret_coerce` instruction.
22302219 _ = try fn_gz.addUnTok(.ret_coerce, .void_value, tree.lastToken(body_node));
22312220 }
22322221
2233 if (cc != .none or lib_name != 0) {
2234 const tag: Zir.Inst.Tag = if (is_var_args) .func_extra_var_args else .func_extra;
2235 break :func try decl_gz.addFuncExtra(tag, .{
2236 .src_node = fn_proto.ast.proto_node,
2237 .ret_ty = return_type_inst,
2238 .param_types = param_types,
2239 .cc = cc,
2240 .lib_name = lib_name,
2241 .body = fn_gz.instructions.items,
2242 });
2243 }
2244
2245 const tag: Zir.Inst.Tag = if (is_var_args) .func_var_args else .func;
2246 break :func try decl_gz.addFunc(tag, .{
2222 break :func try decl_gz.addFunc(.{
22472223 .src_node = fn_proto.ast.proto_node,
22482224 .ret_ty = return_type_inst,
22492225 .param_types = param_types,
22502226 .body = fn_gz.instructions.items,
2227 .cc = cc,
2228 .lib_name = lib_name,
2229 .is_var_args = is_var_args,
2230 .is_inferred_error = is_inferred_error,
22512231 });
22522232 };
22532233
src/Module.zig+74-63
......@@ -1278,79 +1278,90 @@ pub const Scope = struct {
12781278 }
12791279 }
12801280
1281 pub fn addFuncExtra(gz: *GenZir, tag: Zir.Inst.Tag, args: struct {
1281 pub fn addFunc(gz: *GenZir, args: struct {
12821282 src_node: ast.Node.Index,
12831283 param_types: []const Zir.Inst.Ref,
1284 body: []const Zir.Inst.Index,
12841285 ret_ty: Zir.Inst.Ref,
12851286 cc: Zir.Inst.Ref,
1286 body: []const Zir.Inst.Index,
12871287 lib_name: u32,
1288 is_var_args: bool,
1289 is_inferred_error: bool,
12881290 }) !Zir.Inst.Ref {
12891291 assert(args.src_node != 0);
12901292 assert(args.ret_ty != .none);
1291 assert(args.cc != .none);
1292 const gpa = gz.astgen.gpa;
1293 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1294 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
1295 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1296 @typeInfo(Zir.Inst.FuncExtra).Struct.fields.len + args.param_types.len +
1297 args.body.len);
1298
1299 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.FuncExtra{
1300 .return_type = args.ret_ty,
1301 .cc = args.cc,
1302 .param_types_len = @intCast(u32, args.param_types.len),
1303 .body_len = @intCast(u32, args.body.len),
1304 .lib_name = args.lib_name,
1305 });
1306 gz.astgen.appendRefsAssumeCapacity(args.param_types);
1307 gz.astgen.extra.appendSliceAssumeCapacity(args.body);
1308
1309 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1310 gz.astgen.instructions.appendAssumeCapacity(.{
1311 .tag = tag,
1312 .data = .{ .pl_node = .{
1313 .src_node = gz.nodeIndexToRelative(args.src_node),
1314 .payload_index = payload_index,
1315 } },
1316 });
1317 gz.instructions.appendAssumeCapacity(new_index);
1318 return gz.indexToRef(new_index);
1319 }
1320
1321 pub fn addFunc(gz: *GenZir, tag: Zir.Inst.Tag, args: struct {
1322 src_node: ast.Node.Index,
1323 ret_ty: Zir.Inst.Ref,
1324 param_types: []const Zir.Inst.Ref,
1325 body: []const Zir.Inst.Index,
1326 }) !Zir.Inst.Ref {
1327 assert(args.src_node != 0);
1328 assert(args.ret_ty != .none);
1329 const gpa = gz.astgen.gpa;
1330 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1331 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
1332 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1333 @typeInfo(Zir.Inst.Func).Struct.fields.len + args.param_types.len +
1334 args.body.len);
1335
1336 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Func{
1337 .return_type = args.ret_ty,
1338 .param_types_len = @intCast(u32, args.param_types.len),
1339 .body_len = @intCast(u32, args.body.len),
1340 });
1341 gz.astgen.appendRefsAssumeCapacity(args.param_types);
1342 gz.astgen.extra.appendSliceAssumeCapacity(args.body);
1293 const astgen = gz.astgen;
1294 const gpa = astgen.gpa;
13431295
1344 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1345 gz.astgen.instructions.appendAssumeCapacity(.{
1346 .tag = tag,
1347 .data = .{ .pl_node = .{
1296 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1297 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1298
1299 if (args.cc != .none or args.lib_name != 0 or args.is_var_args) {
1300 try astgen.extra.ensureUnusedCapacity(
1301 gpa,
1302 @typeInfo(Zir.Inst.ExtendedFunc).Struct.fields.len +
1303 args.param_types.len + args.body.len +
1304 @boolToInt(args.lib_name != 0) +
1305 @boolToInt(args.cc != .none),
1306 );
1307 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.ExtendedFunc{
13481308 .src_node = gz.nodeIndexToRelative(args.src_node),
1349 .payload_index = payload_index,
1350 } },
1351 });
1352 gz.instructions.appendAssumeCapacity(new_index);
1353 return gz.indexToRef(new_index);
1309 .return_type = args.ret_ty,
1310 .param_types_len = @intCast(u32, args.param_types.len),
1311 .body_len = @intCast(u32, args.body.len),
1312 });
1313 if (args.cc != .none) {
1314 astgen.extra.appendAssumeCapacity(@enumToInt(args.cc));
1315 }
1316 if (args.lib_name != 0) {
1317 astgen.extra.appendAssumeCapacity(args.lib_name);
1318 }
1319 astgen.appendRefsAssumeCapacity(args.param_types);
1320 astgen.extra.appendSliceAssumeCapacity(args.body);
1321
1322 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
1323 astgen.instructions.appendAssumeCapacity(.{
1324 .tag = .extended,
1325 .data = .{ .extended = .{
1326 .opcode = .func,
1327 .small = @bitCast(u16, Zir.Inst.ExtendedFunc.Small{
1328 .is_var_args = args.is_var_args,
1329 .is_inferred_error = args.is_inferred_error,
1330 .has_lib_name = args.lib_name != 0,
1331 .has_cc = args.cc != .none,
1332 }),
1333 .operand = payload_index,
1334 } },
1335 });
1336 gz.instructions.appendAssumeCapacity(new_index);
1337 return gz.indexToRef(new_index);
1338 } else {
1339 try gz.astgen.extra.ensureUnusedCapacity(
1340 gpa,
1341 @typeInfo(Zir.Inst.Func).Struct.fields.len +
1342 args.param_types.len + args.body.len,
1343 );
1344
1345 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Func{
1346 .return_type = args.ret_ty,
1347 .param_types_len = @intCast(u32, args.param_types.len),
1348 .body_len = @intCast(u32, args.body.len),
1349 });
1350 gz.astgen.appendRefsAssumeCapacity(args.param_types);
1351 gz.astgen.extra.appendSliceAssumeCapacity(args.body);
1352
1353 const tag: Zir.Inst.Tag = if (args.is_inferred_error) .func_inferred else .func;
1354 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1355 gz.astgen.instructions.appendAssumeCapacity(.{
1356 .tag = tag,
1357 .data = .{ .pl_node = .{
1358 .src_node = gz.nodeIndexToRelative(args.src_node),
1359 .payload_index = payload_index,
1360 } },
1361 });
1362 gz.instructions.appendAssumeCapacity(new_index);
1363 return gz.indexToRef(new_index);
1364 }
13541365 }
13551366
13561367 pub fn addCall(
src/Sema.zig+71-36
......@@ -194,9 +194,7 @@ pub fn analyzeBody(
194194 .field_val => try sema.zirFieldVal(block, inst),
195195 .field_val_named => try sema.zirFieldValNamed(block, inst),
196196 .func => try sema.zirFunc(block, inst, false),
197 .func_extra => try sema.zirFuncExtra(block, inst, false),
198 .func_extra_var_args => try sema.zirFuncExtra(block, inst, true),
199 .func_var_args => try sema.zirFunc(block, inst, true),
197 .func_inferred => try sema.zirFunc(block, inst, true),
200198 .import => try sema.zirImport(block, inst),
201199 .indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst),
202200 .int => try sema.zirInt(block, inst),
......@@ -2646,7 +2644,12 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
26462644 }
26472645}
26482646
2649fn zirFunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, var_args: bool) InnerError!*Inst {
2647fn zirFunc(
2648 sema: *Sema,
2649 block: *Scope.Block,
2650 inst: Zir.Inst.Index,
2651 inferred_error_set: bool,
2652) InnerError!*Inst {
26502653 const tracy = trace(@src());
26512654 defer tracy.end();
26522655
......@@ -2654,40 +2657,17 @@ fn zirFunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, var_args: boo
26542657 const src = inst_data.src();
26552658 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
26562659 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
2660 const body = sema.code.extra[extra.end + param_types.len ..][0..extra.data.body_len];
26572661
26582662 return sema.funcCommon(
26592663 block,
26602664 inst_data.src_node,
26612665 param_types,
2666 body,
26622667 extra.data.return_type,
26632668 .Unspecified,
2664 var_args,
2665 );
2666}
2667
2668fn zirFuncExtra(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, var_args: bool) InnerError!*Inst {
2669 const tracy = trace(@src());
2670 defer tracy.end();
2671
2672 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2673 const src = inst_data.src();
2674 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };
2675 const extra = sema.code.extraData(Zir.Inst.FuncExtra, inst_data.payload_index);
2676 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
2677
2678 const cc_tv = try sema.resolveInstConst(block, cc_src, extra.data.cc);
2679 // TODO once we're capable of importing and analyzing decls from
2680 // std.builtin, this needs to change
2681 const cc_str = cc_tv.val.castTag(.enum_literal).?.data;
2682 const cc = std.meta.stringToEnum(std.builtin.CallingConvention, cc_str) orelse
2683 return sema.mod.fail(&block.base, cc_src, "Unknown calling convention {s}", .{cc_str});
2684 return sema.funcCommon(
2685 block,
2686 inst_data.src_node,
2687 param_types,
2688 extra.data.return_type,
2689 cc,
2690 var_args,
2669 false,
2670 inferred_error_set,
26912671 );
26922672}
26932673
......@@ -2696,9 +2676,11 @@ fn funcCommon(
26962676 block: *Scope.Block,
26972677 src_node_offset: i32,
26982678 zir_param_types: []const Zir.Inst.Ref,
2679 body: []const Zir.Inst.Index,
26992680 zir_return_type: Zir.Inst.Ref,
27002681 cc: std.builtin.CallingConvention,
27012682 var_args: bool,
2683 inferred_error_set: bool,
27022684) InnerError!*Inst {
27032685 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
27042686 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
......@@ -5307,15 +5289,68 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
53075289 const extended = sema.code.instructions.items(.data)[inst].extended;
53085290 switch (extended.opcode) {
53095291 // zig fmt: off
5310 .c_undef => return sema.zirCUndef( block, inst, extended),
5311 .c_include => return sema.zirCInclude( block, inst, extended),
5312 .c_define => return sema.zirCDefine( block, inst, extended),
5313 .wasm_memory_size => return sema.zirWasmMemorySize( block, inst, extended),
5314 .wasm_memory_grow => return sema.zirWasmMemoryGrow( block, inst, extended),
5292 .func => return sema.zirFuncExtended( block, inst, extended),
5293 .c_undef => return sema.zirCUndef( block, inst, extended),
5294 .c_include => return sema.zirCInclude( block, inst, extended),
5295 .c_define => return sema.zirCDefine( block, inst, extended),
5296 .wasm_memory_size => return sema.zirWasmMemorySize(block, inst, extended),
5297 .wasm_memory_grow => return sema.zirWasmMemoryGrow(block, inst, extended),
53155298 // zig fmt: on
53165299 }
53175300}
53185301
5302fn zirFuncExtended(
5303 sema: *Sema,
5304 block: *Scope.Block,
5305 inst: Zir.Inst.Index,
5306 extended: Zir.Inst.Extended.InstData,
5307) InnerError!*Inst {
5308 const tracy = trace(@src());
5309 defer tracy.end();
5310
5311 const extra = sema.code.extraData(Zir.Inst.ExtendedFunc, extended.operand);
5312 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
5313 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = extra.data.src_node };
5314 const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small);
5315
5316 var extra_index: usize = extra.end;
5317 if (small.has_lib_name) {
5318 const lib_name = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
5319 extra_index += 1;
5320 return sema.mod.fail(&block.base, src, "TODO: implement Sema func lib name", .{});
5321 }
5322 const cc: std.builtin.CallingConvention = if (small.has_cc) blk: {
5323 const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
5324 extra_index += 1;
5325 const cc_tv = try sema.resolveInstConst(block, cc_src, cc_ref);
5326 // TODO this needs to resolve other kinds of Value tags rather than
5327 // assuming the tag will be .enum_field_index.
5328 const cc_field_index = cc_tv.val.castTag(.enum_field_index).?.data;
5329 // TODO should `@intToEnum` do this `@intCast` for you?
5330 const cc = @intToEnum(
5331 std.builtin.CallingConvention,
5332 @intCast(@typeInfo(std.builtin.CallingConvention).Enum.tag_type, cc_field_index),
5333 );
5334 break :blk cc;
5335 } else .Unspecified;
5336
5337 const param_types = sema.code.refSlice(extra_index, extra.data.param_types_len);
5338 extra_index += 1;
5339
5340 const body = sema.code.extra[extra_index..][0..extra.data.body_len];
5341
5342 return sema.funcCommon(
5343 block,
5344 extra.data.src_node,
5345 param_types,
5346 body,
5347 extra.data.return_type,
5348 cc,
5349 small.is_var_args,
5350 small.is_inferred_error,
5351 );
5352}
5353
53195354fn zirCUndef(
53205355 sema: *Sema,
53215356 block: *Scope.Block,
src/Zir.zig+29-47
......@@ -371,15 +371,8 @@ pub const Inst = struct {
371371 /// the body_len is 0. Calling convention is auto.
372372 /// Uses the `pl_node` union field. `payload_index` points to a `Func`.
373373 func,
374 /// Same as `func` but the function is variadic.
375 func_var_args,
376 /// Same as `func` but with extra fields:
377 /// * calling convention
378 /// * extern lib name
379 /// Uses the `pl_node` union field. `payload_index` points to a `FuncExtra`.
380 func_extra,
381 /// Same as `func_extra` but the function is variadic.
382 func_extra_var_args,
374 /// Same as `func` but has an inferred error set.
375 func_inferred,
383376 /// Implements the `@import` builtin.
384377 /// Uses the `str_tok` field.
385378 import,
......@@ -1010,9 +1003,7 @@ pub const Inst = struct {
10101003 .field_ptr_named,
10111004 .field_val_named,
10121005 .func,
1013 .func_var_args,
1014 .func_extra,
1015 .func_extra_var_args,
1006 .func_inferred,
10161007 .has_decl,
10171008 .int,
10181009 .float,
......@@ -1211,6 +1202,11 @@ pub const Inst = struct {
12111202 /// Rarer instructions are here; ones that do not fit in the 8-bit `Tag` enum.
12121203 /// `noreturn` instructions may not go here; they must be part of the main `Tag` enum.
12131204 pub const Extended = enum(u16) {
1205 /// Represents a function declaration or function prototype, depending on
1206 /// whether body_len is 0.
1207 /// `operand` is payload index to `ExtendedFunc`.
1208 /// `small` is `ExtendedFunc.Small`.
1209 func,
12141210 /// `operand` is payload index to `UnNode`.
12151211 c_undef,
12161212 /// `operand` is payload index to `UnNode`.
......@@ -1774,15 +1770,23 @@ pub const Inst = struct {
17741770 };
17751771
17761772 /// Trailing:
1777 /// 0. param_type: Ref // for each param_types_len
1778 /// 1. body: Index // for each body_len
1779 pub const FuncExtra = struct {
1780 cc: Ref,
1781 /// null terminated string index, or 0 to mean none.
1782 lib_name: u32,
1773 /// 0. lib_name: u32, // null terminated string index, if has_lib_name is set
1774 /// 1. cc: Ref, // if has_cc is set
1775 /// 2. param_type: Ref // for each param_types_len
1776 /// 3. body: Index // for each body_len
1777 pub const ExtendedFunc = struct {
1778 src_node: i32,
17831779 return_type: Ref,
17841780 param_types_len: u32,
17851781 body_len: u32,
1782
1783 pub const Small = packed struct {
1784 is_var_args: bool,
1785 is_inferred_error: bool,
1786 has_lib_name: bool,
1787 has_cc: bool,
1788 _: u12 = undefined,
1789 };
17861790 };
17871791
17881792 /// Trailing:
......@@ -2459,9 +2463,7 @@ const Writer = struct {
24592463 => try self.writeStrTok(stream, inst),
24602464
24612465 .func => try self.writeFunc(stream, inst, false),
2462 .func_extra => try self.writeFuncExtra(stream, inst, false),
2463 .func_var_args => try self.writeFunc(stream, inst, true),
2464 .func_extra_var_args => try self.writeFuncExtra(stream, inst, true),
2466 .func_inferred => try self.writeFunc(stream, inst, true),
24652467
24662468 .@"unreachable" => try self.writeUnreachable(stream, inst),
24672469
......@@ -3099,7 +3101,7 @@ const Writer = struct {
30993101 self: *Writer,
31003102 stream: anytype,
31013103 inst: Inst.Index,
3102 var_args: bool,
3104 inferred_error_set: bool,
31033105 ) !void {
31043106 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
31053107 const src = inst_data.src();
......@@ -3110,36 +3112,14 @@ const Writer = struct {
31103112 stream,
31113113 param_types,
31123114 extra.data.return_type,
3113 var_args,
3115 inferred_error_set,
3116 false,
31143117 .none,
31153118 body,
31163119 src,
31173120 );
31183121 }
31193122
3120 fn writeFuncExtra(
3121 self: *Writer,
3122 stream: anytype,
3123 inst: Inst.Index,
3124 var_args: bool,
3125 ) !void {
3126 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
3127 const src = inst_data.src();
3128 const extra = self.code.extraData(Inst.FuncExtra, inst_data.payload_index);
3129 const param_types = self.code.refSlice(extra.end, extra.data.param_types_len);
3130 const cc = extra.data.cc;
3131 const body = self.code.extra[extra.end + param_types.len ..][0..extra.data.body_len];
3132 return self.writeFuncCommon(
3133 stream,
3134 param_types,
3135 extra.data.return_type,
3136 var_args,
3137 cc,
3138 body,
3139 src,
3140 );
3141 }
3142
31433123 fn writeBoolBr(self: *Writer, stream: anytype, inst: Inst.Index) !void {
31443124 const inst_data = self.code.instructions.items(.data)[inst].bool_br;
31453125 const extra = self.code.extraData(Inst.Block, inst_data.payload_index);
......@@ -3184,6 +3164,7 @@ const Writer = struct {
31843164 stream: anytype,
31853165 param_types: []const Inst.Ref,
31863166 ret_ty: Inst.Ref,
3167 inferred_error_set: bool,
31873168 var_args: bool,
31883169 cc: Inst.Ref,
31893170 body: []const Inst.Index,
......@@ -3197,7 +3178,8 @@ const Writer = struct {
31973178 try stream.writeAll("], ");
31983179 try self.writeInstRef(stream, ret_ty);
31993180 try self.writeOptionalInstRef(stream, ", cc=", cc);
3200 try self.writeFlag(stream, ", var_args", var_args);
3181 try self.writeFlag(stream, ", vargs", var_args);
3182 try self.writeFlag(stream, ", inferror", inferred_error_set);
32013183
32023184 try stream.writeAll(", {\n");
32033185 self.indent += 2;