| ... | ... | @@ -5353,7 +5353,9 @@ fn zirCall( |
| 5353 | 5353 | const func_type = sema.typeOf(func); |
| 5354 | 5354 | |
| 5355 | 5355 | // Desugar bound functions here |
| 5356 | var bound_arg_src: ?LazySrcLoc = null; |
| 5356 | 5357 | if (func_type.tag() == .bound_fn) { |
| 5358 | bound_arg_src = func_src; |
| 5357 | 5359 | const bound_func = try sema.resolveValue(block, .unneeded, func, undefined); |
| 5358 | 5360 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; |
| 5359 | 5361 | func = bound_data.func_inst; |
| ... | ... | @@ -5369,7 +5371,7 @@ fn zirCall( |
| 5369 | 5371 | } |
| 5370 | 5372 | } |
| 5371 | 5373 | |
| 5372 | | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args); |
| 5374 | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 5373 | 5375 | } |
| 5374 | 5376 | |
| 5375 | 5377 | const GenericCallAdapter = struct { |
| ... | ... | @@ -5438,6 +5440,7 @@ fn analyzeCall( |
| 5438 | 5440 | modifier: std.builtin.CallOptions.Modifier, |
| 5439 | 5441 | ensure_result_used: bool, |
| 5440 | 5442 | uncasted_args: []const Air.Inst.Ref, |
| 5443 | bound_arg_src: ?LazySrcLoc, |
| 5441 | 5444 | ) CompileError!Air.Inst.Ref { |
| 5442 | 5445 | const mod = sema.mod; |
| 5443 | 5446 | |
| ... | ... | @@ -5532,6 +5535,7 @@ fn analyzeCall( |
| 5532 | 5535 | ensure_result_used, |
| 5533 | 5536 | uncasted_args, |
| 5534 | 5537 | call_tag, |
| 5538 | bound_arg_src, |
| 5535 | 5539 | )) |some| { |
| 5536 | 5540 | return some; |
| 5537 | 5541 | } else |err| switch (err) { |
| ... | ... | @@ -5654,6 +5658,7 @@ fn analyzeCall( |
| 5654 | 5658 | var arg_i: usize = 0; |
| 5655 | 5659 | for (fn_info.param_body) |inst| { |
| 5656 | 5660 | sema.analyzeInlineCallArg( |
| 5661 | block, |
| 5657 | 5662 | &child_block, |
| 5658 | 5663 | .unneeded, |
| 5659 | 5664 | inst, |
| ... | ... | @@ -5665,12 +5670,13 @@ fn analyzeCall( |
| 5665 | 5670 | memoized_call_key, |
| 5666 | 5671 | ) catch |err| switch (err) { |
| 5667 | 5672 | error.NeededSourceLocation => { |
| 5673 | sema.inst_map.clearRetainingCapacity(); |
| 5668 | 5674 | const decl = sema.mod.declPtr(block.src_decl); |
| 5675 | child_block.src_decl = block.src_decl; |
| 5669 | 5676 | try sema.analyzeInlineCallArg( |
| 5670 | | // Intentionally use the wrong block here since we know it's |
| 5671 | | // going to fail and `argSrc` is relative to `block.src_decl`. |
| 5672 | 5677 | block, |
| 5673 | | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i), |
| 5678 | &child_block, |
| 5679 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src), |
| 5674 | 5680 | inst, |
| 5675 | 5681 | new_fn_info, |
| 5676 | 5682 | &arg_i, |
| ... | ... | @@ -5832,7 +5838,7 @@ fn analyzeCall( |
| 5832 | 5838 | const decl = sema.mod.declPtr(block.src_decl); |
| 5833 | 5839 | _ = try sema.analyzeCallArg( |
| 5834 | 5840 | block, |
| 5835 | | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i), |
| 5841 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src), |
| 5836 | 5842 | param_ty, |
| 5837 | 5843 | uncasted_arg, |
| 5838 | 5844 | ); |
| ... | ... | @@ -5873,7 +5879,8 @@ fn analyzeCall( |
| 5873 | 5879 | |
| 5874 | 5880 | fn analyzeInlineCallArg( |
| 5875 | 5881 | sema: *Sema, |
| 5876 | | block: *Block, |
| 5882 | arg_block: *Block, |
| 5883 | param_block: *Block, |
| 5877 | 5884 | arg_src: LazySrcLoc, |
| 5878 | 5885 | inst: Zir.Inst.Index, |
| 5879 | 5886 | new_fn_info: Type.Payload.Function.Data, |
| ... | ... | @@ -5892,19 +5899,19 @@ fn analyzeInlineCallArg( |
| 5892 | 5899 | const param_src = pl_tok.src(); |
| 5893 | 5900 | const extra = sema.code.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 5894 | 5901 | const param_body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| 5895 | | const param_ty_inst = try sema.resolveBody(block, param_body, inst); |
| 5896 | | const param_ty = try sema.analyzeAsType(block, param_src, param_ty_inst); |
| 5902 | const param_ty_inst = try sema.resolveBody(param_block, param_body, inst); |
| 5903 | const param_ty = try sema.analyzeAsType(param_block, param_src, param_ty_inst); |
| 5897 | 5904 | new_fn_info.param_types[arg_i.*] = param_ty; |
| 5898 | 5905 | const uncasted_arg = uncasted_args[arg_i.*]; |
| 5899 | | if (try sema.typeRequiresComptime(block, arg_src, param_ty)) { |
| 5900 | | _ = try sema.resolveConstMaybeUndefVal(block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known"); |
| 5906 | if (try sema.typeRequiresComptime(arg_block, arg_src, param_ty)) { |
| 5907 | _ = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known"); |
| 5901 | 5908 | } |
| 5902 | | const casted_arg = try sema.coerce(block, param_ty, uncasted_arg, arg_src); |
| 5909 | const casted_arg = try sema.coerce(arg_block, param_ty, uncasted_arg, arg_src); |
| 5903 | 5910 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| 5904 | 5911 | |
| 5905 | 5912 | if (is_comptime_call) { |
| 5906 | 5913 | // TODO explain why function is being called at comptime |
| 5907 | | const arg_val = try sema.resolveConstMaybeUndefVal(block, arg_src, casted_arg, "argument to function being called at comptime must be comptime known"); |
| 5914 | const arg_val = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to function being called at comptime must be comptime known"); |
| 5908 | 5915 | switch (arg_val.tag()) { |
| 5909 | 5916 | .generic_poison, .generic_poison_type => { |
| 5910 | 5917 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | ... | @@ -5915,7 +5922,7 @@ fn analyzeInlineCallArg( |
| 5915 | 5922 | // Needed so that lazy values do not trigger |
| 5916 | 5923 | // assertion due to type not being resolved |
| 5917 | 5924 | // when the hash function is called. |
| 5918 | | try sema.resolveLazyValue(block, arg_src, arg_val); |
| 5925 | try sema.resolveLazyValue(arg_block, arg_src, arg_val); |
| 5919 | 5926 | }, |
| 5920 | 5927 | } |
| 5921 | 5928 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | ... | @@ -5935,7 +5942,7 @@ fn analyzeInlineCallArg( |
| 5935 | 5942 | |
| 5936 | 5943 | if (is_comptime_call) { |
| 5937 | 5944 | // TODO explain why function is being called at comptime |
| 5938 | | const arg_val = try sema.resolveConstMaybeUndefVal(block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime known"); |
| 5945 | const arg_val = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime known"); |
| 5939 | 5946 | switch (arg_val.tag()) { |
| 5940 | 5947 | .generic_poison, .generic_poison_type => { |
| 5941 | 5948 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | ... | @@ -5946,7 +5953,7 @@ fn analyzeInlineCallArg( |
| 5946 | 5953 | // Needed so that lazy values do not trigger |
| 5947 | 5954 | // assertion due to type not being resolved |
| 5948 | 5955 | // when the hash function is called. |
| 5949 | | try sema.resolveLazyValue(block, arg_src, arg_val); |
| 5956 | try sema.resolveLazyValue(arg_block, arg_src, arg_val); |
| 5950 | 5957 | }, |
| 5951 | 5958 | } |
| 5952 | 5959 | should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(); |
| ... | ... | @@ -6011,6 +6018,7 @@ fn instantiateGenericCall( |
| 6011 | 6018 | ensure_result_used: bool, |
| 6012 | 6019 | uncasted_args: []const Air.Inst.Ref, |
| 6013 | 6020 | call_tag: Air.Inst.Tag, |
| 6021 | bound_arg_src: ?LazySrcLoc, |
| 6014 | 6022 | ) CompileError!Air.Inst.Ref { |
| 6015 | 6023 | const mod = sema.mod; |
| 6016 | 6024 | const gpa = sema.gpa; |
| ... | ... | @@ -6070,7 +6078,7 @@ fn instantiateGenericCall( |
| 6070 | 6078 | const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[i]) catch |err| switch (err) { |
| 6071 | 6079 | error.NeededSourceLocation => { |
| 6072 | 6080 | const decl = sema.mod.declPtr(block.src_decl); |
| 6073 | | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i); |
| 6081 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src); |
| 6074 | 6082 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]); |
| 6075 | 6083 | return error.AnalysisFail; |
| 6076 | 6084 | }, |
| ... | ... | @@ -6392,7 +6400,7 @@ fn instantiateGenericCall( |
| 6392 | 6400 | const decl = sema.mod.declPtr(block.src_decl); |
| 6393 | 6401 | _ = try sema.analyzeGenericCallArg( |
| 6394 | 6402 | block, |
| 6395 | | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, total_i), |
| 6403 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, total_i, bound_arg_src), |
| 6396 | 6404 | uncasted_args[total_i], |
| 6397 | 6405 | comptime_args[total_i], |
| 6398 | 6406 | runtime_args, |
| ... | ... | @@ -14263,7 +14271,7 @@ fn analyzeRet( |
| 14263 | 14271 | const ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 14264 | 14272 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 14265 | 14273 | const args: [1]Air.Inst.Ref = .{err_return_trace}; |
| 14266 | | _ = try sema.analyzeCall(block, return_err_fn, src, src, .never_inline, false, &args); |
| 14274 | _ = try sema.analyzeCall(block, return_err_fn, src, src, .never_inline, false, &args, null); |
| 14267 | 14275 | } |
| 14268 | 14276 | |
| 14269 | 14277 | try sema.resolveTypeLayout(block, src, sema.fn_ret_ty); |
| ... | ... | @@ -17880,7 +17888,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17880 | 17888 | var resolved_args: []Air.Inst.Ref = undefined; |
| 17881 | 17889 | |
| 17882 | 17890 | // Desugar bound functions here |
| 17891 | var bound_arg_src: ?LazySrcLoc = null; |
| 17883 | 17892 | if (sema.typeOf(func).tag() == .bound_fn) { |
| 17893 | bound_arg_src = func_src; |
| 17884 | 17894 | const bound_func = try sema.resolveValue(block, .unneeded, func, undefined); |
| 17885 | 17895 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; |
| 17886 | 17896 | func = bound_data.func_inst; |
| ... | ... | @@ -17896,7 +17906,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17896 | 17906 | } |
| 17897 | 17907 | } |
| 17898 | 17908 | const ensure_result_used = extra.flags.ensure_result_used; |
| 17899 | | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args); |
| 17909 | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src); |
| 17900 | 17910 | } |
| 17901 | 17911 | |
| 17902 | 17912 | fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -19182,7 +19192,7 @@ fn panicWithMsg( |
| 19182 | 19192 | Value.@"null", |
| 19183 | 19193 | ); |
| 19184 | 19194 | const args: [2]Air.Inst.Ref = .{ msg_inst, null_stack_trace }; |
| 19185 | | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args); |
| 19195 | _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null); |
| 19186 | 19196 | return always_noreturn; |
| 19187 | 19197 | } |
| 19188 | 19198 | |
| ... | ... | @@ -19223,7 +19233,7 @@ fn panicUnwrapError( |
| 19223 | 19233 | const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand); |
| 19224 | 19234 | const err_return_trace = try sema.getErrorReturnTrace(&fail_block, src); |
| 19225 | 19235 | const args: [2]Air.Inst.Ref = .{ err_return_trace, err }; |
| 19226 | | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args); |
| 19236 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 19227 | 19237 | } |
| 19228 | 19238 | } |
| 19229 | 19239 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |
| ... | ... | @@ -19264,7 +19274,7 @@ fn panicIndexOutOfBounds( |
| 19264 | 19274 | } else { |
| 19265 | 19275 | const panic_fn = try sema.getBuiltin(&fail_block, src, "panicOutOfBounds"); |
| 19266 | 19276 | const args: [2]Air.Inst.Ref = .{ index, len }; |
| 19267 | | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args); |
| 19277 | _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null); |
| 19268 | 19278 | } |
| 19269 | 19279 | } |
| 19270 | 19280 | try sema.addSafetyCheckExtra(parent_block, ok, &fail_block); |