| ... | ... | @@ -252,7 +252,6 @@ pub const Block = struct { |
| 252 | 252 | // TODO is_comptime and comptime_reason should probably be merged together. |
| 253 | 253 | is_comptime: bool, |
| 254 | 254 | is_typeof: bool = false, |
| 255 | | is_coerce_result_ptr: bool = false, |
| 256 | 255 | |
| 257 | 256 | /// Keep track of the active error return trace index around blocks so that we can correctly |
| 258 | 257 | /// pop the error trace upon block exit. |
| ... | ... | @@ -2470,7 +2469,6 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2470 | 2469 | // kind of transformations to make on the result pointer. |
| 2471 | 2470 | var trash_block = block.makeSubBlock(); |
| 2472 | 2471 | trash_block.is_comptime = false; |
| 2473 | | trash_block.is_coerce_result_ptr = true; |
| 2474 | 2472 | defer trash_block.instructions.deinit(sema.gpa); |
| 2475 | 2473 | |
| 2476 | 2474 | const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr)); |
| ... | ... | @@ -2580,6 +2578,9 @@ fn coerceResultPtr( |
| 2580 | 2578 | .array_to_slice => { |
| 2581 | 2579 | return sema.fail(block, src, "TODO coerce_result_ptr array_to_slice", .{}); |
| 2582 | 2580 | }, |
| 2581 | .get_union_tag => { |
| 2582 | return sema.fail(block, src, "TODO coerce_result_ptr get_union_tag", .{}); |
| 2583 | }, |
| 2583 | 2584 | else => { |
| 2584 | 2585 | if (std.debug.runtime_safety) { |
| 2585 | 2586 | std.debug.panic("unexpected AIR tag for coerce_result_ptr: {}", .{ |
| ... | ... | @@ -2730,9 +2731,13 @@ fn createAnonymousDeclTypeNamed( |
| 2730 | 2731 | for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) { |
| 2731 | 2732 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { |
| 2732 | 2733 | const arg = sema.inst_map.get(zir_inst).?; |
| 2733 | | // The comptime call code in analyzeCall already did this, so we're |
| 2734 | | // just repeating it here and it's guaranteed to work. |
| 2735 | | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch unreachable; |
| 2734 | // If this is being called in a generic function then analyzeCall will |
| 2735 | // have already resolved the args and this will work. |
| 2736 | // If not then this is a struct type being returned from a non-generic |
| 2737 | // function and the name doesn't matter since it will later |
| 2738 | // result in a compile error. |
| 2739 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch |
| 2740 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); |
| 2736 | 2741 | |
| 2737 | 2742 | if (arg_i != 0) try buf.appendSlice(","); |
| 2738 | 2743 | try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)}); |
| ... | ... | @@ -3564,6 +3569,13 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3564 | 3569 | )); |
| 3565 | 3570 | } |
| 3566 | 3571 | |
| 3572 | return sema.makePtrConst(block, alloc); |
| 3573 | } |
| 3574 | |
| 3575 | fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Air.Inst.Ref { |
| 3576 | const alloc_ty = sema.typeOf(alloc); |
| 3577 | |
| 3578 | var ptr_info = alloc_ty.ptrInfo().data; |
| 3567 | 3579 | ptr_info.mutable = false; |
| 3568 | 3580 | const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 3569 | 3581 | |
| ... | ... | @@ -3832,7 +3844,6 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3832 | 3844 | |
| 3833 | 3845 | var trash_block = block.makeSubBlock(); |
| 3834 | 3846 | trash_block.is_comptime = false; |
| 3835 | | trash_block.is_coerce_result_ptr = true; |
| 3836 | 3847 | defer trash_block.instructions.deinit(gpa); |
| 3837 | 3848 | |
| 3838 | 3849 | const mut_final_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | ... | @@ -5211,7 +5222,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I |
| 5211 | 5222 | if (block.is_comptime) { |
| 5212 | 5223 | return sema.fail(block, src, "encountered @panic at comptime", .{}); |
| 5213 | 5224 | } |
| 5214 | | try sema.panicWithMsg(block, src, msg_inst); |
| 5225 | try sema.panicWithMsg(block, msg_inst); |
| 5215 | 5226 | return always_noreturn; |
| 5216 | 5227 | } |
| 5217 | 5228 | |
| ... | ... | @@ -6289,7 +6300,6 @@ fn zirCall( |
| 6289 | 6300 | } else { |
| 6290 | 6301 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_len); |
| 6291 | 6302 | } |
| 6292 | | const total_args = args_len + @boolToInt(bound_arg_src != null); |
| 6293 | 6303 | |
| 6294 | 6304 | const callee_ty = sema.typeOf(func); |
| 6295 | 6305 | const func_ty = func_ty: { |
| ... | ... | @@ -6305,45 +6315,16 @@ fn zirCall( |
| 6305 | 6315 | } |
| 6306 | 6316 | return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(sema.mod)}); |
| 6307 | 6317 | }; |
| 6308 | | const func_ty_info = func_ty.fnInfo(); |
| 6309 | | |
| 6310 | | const fn_params_len = func_ty_info.param_types.len; |
| 6311 | | check_args: { |
| 6312 | | if (func_ty_info.is_var_args) { |
| 6313 | | assert(func_ty_info.cc == .C); |
| 6314 | | if (total_args >= fn_params_len) break :check_args; |
| 6315 | | } else if (fn_params_len == total_args) { |
| 6316 | | break :check_args; |
| 6317 | | } |
| 6318 | | |
| 6319 | | const maybe_decl = try sema.funcDeclSrc(func); |
| 6320 | | const member_str = if (bound_arg_src != null) "member function " else ""; |
| 6321 | | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 6322 | | const msg = msg: { |
| 6323 | | const msg = try sema.errMsg( |
| 6324 | | block, |
| 6325 | | func_src, |
| 6326 | | "{s}expected {s}{d} argument(s), found {d}", |
| 6327 | | .{ |
| 6328 | | member_str, |
| 6329 | | variadic_str, |
| 6330 | | fn_params_len - @boolToInt(bound_arg_src != null), |
| 6331 | | args_len, |
| 6332 | | }, |
| 6333 | | ); |
| 6334 | | errdefer msg.destroy(sema.gpa); |
| 6335 | | |
| 6336 | | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{}); |
| 6337 | | break :msg msg; |
| 6338 | | }; |
| 6339 | | return sema.failWithOwnedErrorMsg(msg); |
| 6340 | | } |
| 6318 | const total_args = args_len + @boolToInt(bound_arg_src != null); |
| 6319 | try sema.checkCallArgumentCount(block, func, func_src, func_ty, total_args, bound_arg_src != null); |
| 6341 | 6320 | |
| 6342 | 6321 | const args_body = sema.code.extra[extra.end..]; |
| 6343 | 6322 | |
| 6344 | 6323 | var input_is_error = false; |
| 6345 | 6324 | const block_index = @intCast(Air.Inst.Index, block.instructions.items.len); |
| 6346 | 6325 | |
| 6326 | const func_ty_info = func_ty.fnInfo(); |
| 6327 | const fn_params_len = func_ty_info.param_types.len; |
| 6347 | 6328 | const parent_comptime = block.is_comptime; |
| 6348 | 6329 | // `extra_index` and `arg_index` are separate since the bound function is passed as the first argument. |
| 6349 | 6330 | var extra_index: usize = 0; |
| ... | ... | @@ -6381,14 +6362,18 @@ fn zirCall( |
| 6381 | 6362 | } |
| 6382 | 6363 | resolved_args[arg_index] = resolved; |
| 6383 | 6364 | } |
| 6384 | | if (sema.owner_func == null or !sema.owner_func.?.calls_or_awaits_errorable_fn) |
| 6365 | if (sema.owner_func == null or !sema.owner_func.?.calls_or_awaits_errorable_fn) { |
| 6385 | 6366 | input_is_error = false; // input was an error type, but no errorable fn's were actually called |
| 6367 | } |
| 6368 | |
| 6369 | // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction. |
| 6370 | const call_dbg_node = inst - 1; |
| 6386 | 6371 | |
| 6387 | 6372 | if (sema.mod.backendSupportsFeature(.error_return_trace) and sema.mod.comp.bin_file.options.error_return_tracing and |
| 6388 | 6373 | !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace)) |
| 6389 | 6374 | { |
| 6390 | 6375 | const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: { |
| 6391 | | break :b try sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 6376 | break :b try sema.analyzeCall(block, func, func_ty, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src, call_dbg_node); |
| 6392 | 6377 | }; |
| 6393 | 6378 | |
| 6394 | 6379 | const return_ty = sema.typeOf(call_inst); |
| ... | ... | @@ -6417,14 +6402,86 @@ fn zirCall( |
| 6417 | 6402 | } |
| 6418 | 6403 | |
| 6419 | 6404 | if (modifier == .always_tail) // Perform the call *after* the restore, so that a tail call is possible. |
| 6420 | | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 6405 | return sema.analyzeCall(block, func, func_ty, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src, call_dbg_node); |
| 6421 | 6406 | |
| 6422 | 6407 | return call_inst; |
| 6423 | 6408 | } else { |
| 6424 | | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 6409 | return sema.analyzeCall(block, func, func_ty, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src, call_dbg_node); |
| 6425 | 6410 | } |
| 6426 | 6411 | } |
| 6427 | 6412 | |
| 6413 | fn checkCallArgumentCount( |
| 6414 | sema: *Sema, |
| 6415 | block: *Block, |
| 6416 | func: Air.Inst.Ref, |
| 6417 | func_src: LazySrcLoc, |
| 6418 | func_ty: Type, |
| 6419 | total_args: usize, |
| 6420 | member_fn: bool, |
| 6421 | ) !void { |
| 6422 | const func_ty_info = func_ty.fnInfo(); |
| 6423 | const fn_params_len = func_ty_info.param_types.len; |
| 6424 | const args_len = total_args - @boolToInt(member_fn); |
| 6425 | if (func_ty_info.is_var_args) { |
| 6426 | assert(func_ty_info.cc == .C); |
| 6427 | if (total_args >= fn_params_len) return; |
| 6428 | } else if (fn_params_len == total_args) { |
| 6429 | return; |
| 6430 | } |
| 6431 | |
| 6432 | const maybe_decl = try sema.funcDeclSrc(func); |
| 6433 | const member_str = if (member_fn) "member function " else ""; |
| 6434 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 6435 | const msg = msg: { |
| 6436 | const msg = try sema.errMsg( |
| 6437 | block, |
| 6438 | func_src, |
| 6439 | "{s}expected {s}{d} argument(s), found {d}", |
| 6440 | .{ |
| 6441 | member_str, |
| 6442 | variadic_str, |
| 6443 | fn_params_len - @boolToInt(member_fn), |
| 6444 | args_len, |
| 6445 | }, |
| 6446 | ); |
| 6447 | errdefer msg.destroy(sema.gpa); |
| 6448 | |
| 6449 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{}); |
| 6450 | break :msg msg; |
| 6451 | }; |
| 6452 | return sema.failWithOwnedErrorMsg(msg); |
| 6453 | } |
| 6454 | |
| 6455 | fn callBuiltin( |
| 6456 | sema: *Sema, |
| 6457 | block: *Block, |
| 6458 | builtin_fn: Air.Inst.Ref, |
| 6459 | modifier: std.builtin.CallModifier, |
| 6460 | args: []const Air.Inst.Ref, |
| 6461 | ) !void { |
| 6462 | const callee_ty = sema.typeOf(builtin_fn); |
| 6463 | const func_ty = func_ty: { |
| 6464 | switch (callee_ty.zigTypeTag()) { |
| 6465 | .Fn => break :func_ty callee_ty, |
| 6466 | .Pointer => { |
| 6467 | const ptr_info = callee_ty.ptrInfo().data; |
| 6468 | if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag() == .Fn) { |
| 6469 | break :func_ty ptr_info.pointee_type; |
| 6470 | } |
| 6471 | }, |
| 6472 | else => {}, |
| 6473 | } |
| 6474 | std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(sema.mod)}); |
| 6475 | }; |
| 6476 | |
| 6477 | const func_ty_info = func_ty.fnInfo(); |
| 6478 | const fn_params_len = func_ty_info.param_types.len; |
| 6479 | if (args.len != fn_params_len or (func_ty_info.is_var_args and args.len < fn_params_len)) { |
| 6480 | std.debug.panic("parameter count mismatch calling builtin fn, expected {d}, found {d}", .{ fn_params_len, args.len }); |
| 6481 | } |
| 6482 | _ = try sema.analyzeCall(block, builtin_fn, func_ty, sema.src, sema.src, modifier, false, args, null, null); |
| 6483 | } |
| 6484 | |
| 6428 | 6485 | const GenericCallAdapter = struct { |
| 6429 | 6486 | generic_fn: *Module.Fn, |
| 6430 | 6487 | precomputed_hash: u64, |
| ... | ... | @@ -6499,31 +6556,20 @@ fn analyzeCall( |
| 6499 | 6556 | sema: *Sema, |
| 6500 | 6557 | block: *Block, |
| 6501 | 6558 | func: Air.Inst.Ref, |
| 6559 | func_ty: Type, |
| 6502 | 6560 | func_src: LazySrcLoc, |
| 6503 | 6561 | call_src: LazySrcLoc, |
| 6504 | 6562 | modifier: std.builtin.CallModifier, |
| 6505 | 6563 | ensure_result_used: bool, |
| 6506 | 6564 | uncasted_args: []const Air.Inst.Ref, |
| 6507 | 6565 | bound_arg_src: ?LazySrcLoc, |
| 6566 | call_dbg_node: ?Zir.Inst.Index, |
| 6508 | 6567 | ) CompileError!Air.Inst.Ref { |
| 6509 | 6568 | const mod = sema.mod; |
| 6510 | 6569 | |
| 6511 | 6570 | const callee_ty = sema.typeOf(func); |
| 6512 | | const func_ty = func_ty: { |
| 6513 | | switch (callee_ty.zigTypeTag()) { |
| 6514 | | .Fn => break :func_ty callee_ty, |
| 6515 | | .Pointer => { |
| 6516 | | const ptr_info = callee_ty.ptrInfo().data; |
| 6517 | | if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag() == .Fn) { |
| 6518 | | break :func_ty ptr_info.pointee_type; |
| 6519 | | } |
| 6520 | | }, |
| 6521 | | else => {}, |
| 6522 | | } |
| 6523 | | return sema.fail(block, func_src, "type '{}' is not a function", .{callee_ty.fmt(sema.mod)}); |
| 6524 | | }; |
| 6525 | | |
| 6526 | 6571 | const func_ty_info = func_ty.fnInfo(); |
| 6572 | const fn_params_len = func_ty_info.param_types.len; |
| 6527 | 6573 | const cc = func_ty_info.cc; |
| 6528 | 6574 | if (cc == .Naked) { |
| 6529 | 6575 | const maybe_decl = try sema.funcDeclSrc(func); |
| ... | ... | @@ -6541,27 +6587,6 @@ fn analyzeCall( |
| 6541 | 6587 | }; |
| 6542 | 6588 | return sema.failWithOwnedErrorMsg(msg); |
| 6543 | 6589 | } |
| 6544 | | const fn_params_len = func_ty_info.param_types.len; |
| 6545 | | if (func_ty_info.is_var_args) { |
| 6546 | | assert(cc == .C); |
| 6547 | | if (uncasted_args.len < fn_params_len) { |
| 6548 | | // TODO add error note: declared here |
| 6549 | | return sema.fail( |
| 6550 | | block, |
| 6551 | | func_src, |
| 6552 | | "expected at least {d} argument(s), found {d}", |
| 6553 | | .{ fn_params_len, uncasted_args.len }, |
| 6554 | | ); |
| 6555 | | } |
| 6556 | | } else if (fn_params_len != uncasted_args.len) { |
| 6557 | | // TODO add error note: declared here |
| 6558 | | return sema.fail( |
| 6559 | | block, |
| 6560 | | call_src, |
| 6561 | | "expected {d} argument(s), found {d}", |
| 6562 | | .{ fn_params_len, uncasted_args.len }, |
| 6563 | | ); |
| 6564 | | } |
| 6565 | 6590 | |
| 6566 | 6591 | const call_tag: Air.Inst.Tag = switch (modifier) { |
| 6567 | 6592 | .auto, |
| ... | ... | @@ -6622,6 +6647,7 @@ fn analyzeCall( |
| 6622 | 6647 | uncasted_args, |
| 6623 | 6648 | call_tag, |
| 6624 | 6649 | bound_arg_src, |
| 6650 | call_dbg_node, |
| 6625 | 6651 | )) |some| { |
| 6626 | 6652 | return some; |
| 6627 | 6653 | } else |err| switch (err) { |
| ... | ... | @@ -7010,6 +7036,8 @@ fn analyzeCall( |
| 7010 | 7036 | } |
| 7011 | 7037 | } |
| 7012 | 7038 | |
| 7039 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); |
| 7040 | |
| 7013 | 7041 | try sema.queueFullTypeResolution(func_ty_info.return_type); |
| 7014 | 7042 | if (sema.owner_func != null and func_ty_info.return_type.isError()) { |
| 7015 | 7043 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; |
| ... | ... | @@ -7246,6 +7274,7 @@ fn instantiateGenericCall( |
| 7246 | 7274 | uncasted_args: []const Air.Inst.Ref, |
| 7247 | 7275 | call_tag: Air.Inst.Tag, |
| 7248 | 7276 | bound_arg_src: ?LazySrcLoc, |
| 7277 | call_dbg_node: ?Zir.Inst.Index, |
| 7249 | 7278 | ) CompileError!Air.Inst.Ref { |
| 7250 | 7279 | const mod = sema.mod; |
| 7251 | 7280 | const gpa = sema.gpa; |
| ... | ... | @@ -7502,6 +7531,8 @@ fn instantiateGenericCall( |
| 7502 | 7531 | try sema.queueFullTypeResolution(new_fn_info.return_type); |
| 7503 | 7532 | } |
| 7504 | 7533 | |
| 7534 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); |
| 7535 | |
| 7505 | 7536 | if (sema.owner_func != null and new_fn_info.return_type.isError()) { |
| 7506 | 7537 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; |
| 7507 | 7538 | } |
| ... | ... | @@ -11827,9 +11858,6 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11827 | 11858 | .as_node => try sema.zirAsNode(block, inst), |
| 11828 | 11859 | .field_val => try sema.zirFieldVal(block, inst), |
| 11829 | 11860 | .@"unreachable" => { |
| 11830 | | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; |
| 11831 | | const src = inst_data.src(); |
| 11832 | | |
| 11833 | 11861 | if (!sema.mod.comp.formatted_panics) { |
| 11834 | 11862 | try sema.safetyPanic(block, .unwrap_error); |
| 11835 | 11863 | return true; |
| ... | ... | @@ -11838,18 +11866,17 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 11838 | 11866 | const panic_fn = try sema.getBuiltin("panicUnwrapError"); |
| 11839 | 11867 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11840 | 11868 | const args: [2]Air.Inst.Ref = .{ err_return_trace, operand }; |
| 11841 | | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11869 | try sema.callBuiltin(block, panic_fn, .auto, &args); |
| 11842 | 11870 | return true; |
| 11843 | 11871 | }, |
| 11844 | 11872 | .panic => { |
| 11845 | 11873 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 11846 | | const src = inst_data.src(); |
| 11847 | 11874 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 11848 | 11875 | |
| 11849 | 11876 | const panic_fn = try sema.getBuiltin("panic"); |
| 11850 | 11877 | const err_return_trace = try sema.getErrorReturnTrace(block); |
| 11851 | 11878 | const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value }; |
| 11852 | | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 11879 | try sema.callBuiltin(block, panic_fn, .auto, &args); |
| 11853 | 11880 | return true; |
| 11854 | 11881 | }, |
| 11855 | 11882 | else => unreachable, |
| ... | ... | @@ -17263,7 +17290,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 17263 | 17290 | |
| 17264 | 17291 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 17265 | 17292 | const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr); |
| 17266 | | return sema.retWithErrTracing(block, src, is_non_err, .ret_load, ret_ptr); |
| 17293 | return sema.retWithErrTracing(block, is_non_err, .ret_load, ret_ptr); |
| 17267 | 17294 | } |
| 17268 | 17295 | |
| 17269 | 17296 | _ = try block.addUnOp(.ret_load, ret_ptr); |
| ... | ... | @@ -17273,7 +17300,6 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 17273 | 17300 | fn retWithErrTracing( |
| 17274 | 17301 | sema: *Sema, |
| 17275 | 17302 | block: *Block, |
| 17276 | | src: LazySrcLoc, |
| 17277 | 17303 | is_non_err: Air.Inst.Ref, |
| 17278 | 17304 | ret_tag: Air.Inst.Tag, |
| 17279 | 17305 | operand: Air.Inst.Ref, |
| ... | ... | @@ -17295,7 +17321,7 @@ fn retWithErrTracing( |
| 17295 | 17321 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 17296 | 17322 | |
| 17297 | 17323 | if (!need_check) { |
| 17298 | | _ = try sema.analyzeCall(block, return_err_fn, src, src, .never_inline, false, &args, null); |
| 17324 | try sema.callBuiltin(block, return_err_fn, .never_inline, &args); |
| 17299 | 17325 | _ = try block.addUnOp(ret_tag, operand); |
| 17300 | 17326 | return always_noreturn; |
| 17301 | 17327 | } |
| ... | ... | @@ -17306,7 +17332,7 @@ fn retWithErrTracing( |
| 17306 | 17332 | |
| 17307 | 17333 | var else_block = block.makeSubBlock(); |
| 17308 | 17334 | defer else_block.instructions.deinit(gpa); |
| 17309 | | _ = try sema.analyzeCall(&else_block, return_err_fn, src, src, .never_inline, false, &args, null); |
| 17335 | try sema.callBuiltin(&else_block, return_err_fn, .never_inline, &args); |
| 17310 | 17336 | _ = try else_block.addUnOp(ret_tag, operand); |
| 17311 | 17337 | |
| 17312 | 17338 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + |
| ... | ... | @@ -17452,7 +17478,7 @@ fn analyzeRet( |
| 17452 | 17478 | // Avoid adding a frame to the error return trace in case the value is comptime-known |
| 17453 | 17479 | // to be not an error. |
| 17454 | 17480 | const is_non_err = try sema.analyzeIsNonErr(block, src, operand); |
| 17455 | | return sema.retWithErrTracing(block, src, is_non_err, .ret, operand); |
| 17481 | return sema.retWithErrTracing(block, is_non_err, .ret, operand); |
| 17456 | 17482 | } |
| 17457 | 17483 | |
| 17458 | 17484 | _ = try block.addUnOp(.ret, operand); |
| ... | ... | @@ -17796,7 +17822,7 @@ fn zirStructInit( |
| 17796 | 17822 | try sema.storePtr(block, src, field_ptr, init_inst); |
| 17797 | 17823 | const new_tag = try sema.addConstant(resolved_ty.unionTagTypeHypothetical(), tag_val); |
| 17798 | 17824 | _ = try block.addBinOp(.set_union_tag, alloc, new_tag); |
| 17799 | | return alloc; |
| 17825 | return sema.makePtrConst(block, alloc); |
| 17800 | 17826 | } |
| 17801 | 17827 | |
| 17802 | 17828 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -17923,7 +17949,7 @@ fn finishStructInit( |
| 17923 | 17949 | try sema.storePtr(block, dest_src, field_ptr, field_init); |
| 17924 | 17950 | } |
| 17925 | 17951 | |
| 17926 | | return alloc; |
| 17952 | return sema.makePtrConst(block, alloc); |
| 17927 | 17953 | } |
| 17928 | 17954 | |
| 17929 | 17955 | try sema.requireRuntimeBlock(block, dest_src, null); |
| ... | ... | @@ -18040,7 +18066,7 @@ fn zirStructInitAnon( |
| 18040 | 18066 | } |
| 18041 | 18067 | } |
| 18042 | 18068 | |
| 18043 | | return alloc; |
| 18069 | return sema.makePtrConst(block, alloc); |
| 18044 | 18070 | } |
| 18045 | 18071 | |
| 18046 | 18072 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, types.len); |
| ... | ... | @@ -18143,7 +18169,7 @@ fn zirArrayInit( |
| 18143 | 18169 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 18144 | 18170 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| 18145 | 18171 | } |
| 18146 | | return alloc; |
| 18172 | return sema.makePtrConst(block, alloc); |
| 18147 | 18173 | } |
| 18148 | 18174 | |
| 18149 | 18175 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | ... | @@ -18158,7 +18184,7 @@ fn zirArrayInit( |
| 18158 | 18184 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 18159 | 18185 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| 18160 | 18186 | } |
| 18161 | | return alloc; |
| 18187 | return sema.makePtrConst(block, alloc); |
| 18162 | 18188 | } |
| 18163 | 18189 | |
| 18164 | 18190 | return block.addAggregateInit(array_ty, resolved_args); |
| ... | ... | @@ -18236,7 +18262,7 @@ fn zirArrayInitAnon( |
| 18236 | 18262 | } |
| 18237 | 18263 | } |
| 18238 | 18264 | |
| 18239 | | return alloc; |
| 18265 | return sema.makePtrConst(block, alloc); |
| 18240 | 18266 | } |
| 18241 | 18267 | |
| 18242 | 18268 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| ... | ... | @@ -21662,8 +21688,25 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 21662 | 21688 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty); |
| 21663 | 21689 | } |
| 21664 | 21690 | } |
| 21691 | |
| 21692 | const callee_ty = sema.typeOf(func); |
| 21693 | const func_ty = func_ty: { |
| 21694 | switch (callee_ty.zigTypeTag()) { |
| 21695 | .Fn => break :func_ty callee_ty, |
| 21696 | .Pointer => { |
| 21697 | const ptr_info = callee_ty.ptrInfo().data; |
| 21698 | if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag() == .Fn) { |
| 21699 | break :func_ty ptr_info.pointee_type; |
| 21700 | } |
| 21701 | }, |
| 21702 | else => {}, |
| 21703 | } |
| 21704 | return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(sema.mod)}); |
| 21705 | }; |
| 21706 | try sema.checkCallArgumentCount(block, func, func_src, func_ty, resolved_args.len, bound_arg_src != null); |
| 21707 | |
| 21665 | 21708 | const ensure_result_used = extra.flags.ensure_result_used; |
| 21666 | | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 21709 | return sema.analyzeCall(block, func, func_ty, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src, null); |
| 21667 | 21710 | } |
| 21668 | 21711 | |
| 21669 | 21712 | fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -23474,7 +23517,6 @@ fn addSafetyCheckExtra( |
| 23474 | 23517 | fn panicWithMsg( |
| 23475 | 23518 | sema: *Sema, |
| 23476 | 23519 | block: *Block, |
| 23477 | | src: LazySrcLoc, |
| 23478 | 23520 | msg_inst: Air.Inst.Ref, |
| 23479 | 23521 | ) !void { |
| 23480 | 23522 | const mod = sema.mod; |
| ... | ... | @@ -23497,7 +23539,7 @@ fn panicWithMsg( |
| 23497 | 23539 | Value.null, |
| 23498 | 23540 | ); |
| 23499 | 23541 | const args: [3]Air.Inst.Ref = .{ msg_inst, null_stack_trace, .null_value }; |
| 23500 | | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 23542 | try sema.callBuiltin(block, panic_fn, .auto, &args); |
| 23501 | 23543 | } |
| 23502 | 23544 | |
| 23503 | 23545 | fn panicUnwrapError( |
| ... | ... | @@ -23535,7 +23577,7 @@ fn panicUnwrapError( |
| 23535 | 23577 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); |
| 23536 | 23578 | const err_return_trace = try sema.getErrorReturnTrace(&fail_block); |
| 23537 | 23579 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| 23538 | | _ = try sema.analyzeCall(&fail_block, panic_fn, sema.src, sema.src, .auto, false, &args, null); |
| 23580 | try sema.callBuiltin(&fail_block, panic_fn, .auto, &args); |
| 23539 | 23581 | } |
| 23540 | 23582 | } |
| 23541 | 23583 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| ... | ... | @@ -23620,7 +23662,7 @@ fn panicSentinelMismatch( |
| 23620 | 23662 | else { |
| 23621 | 23663 | const panic_fn = try sema.getBuiltin("checkNonScalarSentinel"); |
| 23622 | 23664 | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 23623 | | _ = try sema.analyzeCall(parent_block, panic_fn, sema.src, sema.src, .auto, false, &args, null); |
| 23665 | try sema.callBuiltin(parent_block, panic_fn, .auto, &args); |
| 23624 | 23666 | return; |
| 23625 | 23667 | }; |
| 23626 | 23668 | |
| ... | ... | @@ -23657,7 +23699,7 @@ fn safetyCheckFormatted( |
| 23657 | 23699 | _ = try fail_block.addNoOp(.trap); |
| 23658 | 23700 | } else { |
| 23659 | 23701 | const panic_fn = try sema.getBuiltin(func); |
| 23660 | | _ = try sema.analyzeCall(&fail_block, panic_fn, sema.src, sema.src, .auto, false, args, null); |
| 23702 | try sema.callBuiltin(&fail_block, panic_fn, .auto, args); |
| 23661 | 23703 | } |
| 23662 | 23704 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| 23663 | 23705 | } |
| ... | ... | @@ -23676,7 +23718,7 @@ fn safetyPanic( |
| 23676 | 23718 | )).?; |
| 23677 | 23719 | |
| 23678 | 23720 | const msg_inst = try sema.analyzeDeclVal(block, sema.src, msg_decl_index); |
| 23679 | | try sema.panicWithMsg(block, sema.src, msg_inst); |
| 23721 | try sema.panicWithMsg(block, msg_inst); |
| 23680 | 23722 | } |
| 23681 | 23723 | |
| 23682 | 23724 | fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| ... | ... | @@ -29134,8 +29176,6 @@ fn analyzeIsNonErrComptimeOnly( |
| 29134 | 29176 | if (ies.errors.count() != 0) break :blk; |
| 29135 | 29177 | if (maybe_operand_val == null) { |
| 29136 | 29178 | // Try to avoid resolving inferred error set if possible. |
| 29137 | | if (ies.errors.count() != 0) break :blk; |
| 29138 | | if (ies.is_anyerror) break :blk; |
| 29139 | 29179 | for (ies.inferred_error_sets.keys()) |other_ies| { |
| 29140 | 29180 | if (ies == other_ies) continue; |
| 29141 | 29181 | try sema.resolveInferredErrorSet(block, src, other_ies); |
| ... | ... | @@ -29147,11 +29187,10 @@ fn analyzeIsNonErrComptimeOnly( |
| 29147 | 29187 | |
| 29148 | 29188 | if (other_ies.errors.count() != 0) break :blk; |
| 29149 | 29189 | } |
| 29150 | | if (ies.func == sema.owner_func) { |
| 29151 | | // We're checking the inferred errorset of the current function and none of |
| 29152 | | // its child inferred error sets contained any errors meaning that any value |
| 29153 | | // so far with this type can't contain errors either. |
| 29154 | | return Air.Inst.Ref.bool_true; |
| 29190 | if (!ies.is_resolved and ies.func.state == .in_progress) { |
| 29191 | // Calling resolveInferredErrorSet would immediately fail |
| 29192 | // so we'll have to rely on runtime checks. |
| 29193 | return Air.Inst.Ref.none; |
| 29155 | 29194 | } |
| 29156 | 29195 | try sema.resolveInferredErrorSet(block, src, ies); |
| 29157 | 29196 | if (ies.is_anyerror) break :blk; |
| ... | ... | @@ -31523,6 +31562,16 @@ fn resolveInferredErrorSet( |
| 31523 | 31562 | if (ies_func_info.return_type.tag() == .generic_poison) { |
| 31524 | 31563 | assert(ies_func_info.cc == .Inline); |
| 31525 | 31564 | } else if (ies_func_info.return_type.errorUnionSet().castTag(.error_set_inferred).?.data == ies) { |
| 31565 | if (ies_func_info.is_generic) { |
| 31566 | const msg = msg: { |
| 31567 | const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{}); |
| 31568 | errdefer msg.destroy(sema.gpa); |
| 31569 | |
| 31570 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(), msg, "generic function declared here", .{}); |
| 31571 | break :msg msg; |
| 31572 | }; |
| 31573 | return sema.failWithOwnedErrorMsg(msg); |
| 31574 | } |
| 31526 | 31575 | // In this case we are dealing with the actual InferredErrorSet object that |
| 31527 | 31576 | // corresponds to the function, not one created to track an inline/comptime call. |
| 31528 | 31577 | try sema.ensureFuncBodyAnalyzed(ies.func); |