| ... | ... | @@ -7560,14 +7560,14 @@ fn analyzeCall( |
| 7560 | 7560 | operation: CallOperation, |
| 7561 | 7561 | ) CompileError!Air.Inst.Ref { |
| 7562 | 7562 | const pt = sema.pt; |
| 7563 | | const mod = pt.zcu; |
| 7564 | | const ip = &mod.intern_pool; |
| 7563 | const zcu = pt.zcu; |
| 7564 | const ip = &zcu.intern_pool; |
| 7565 | 7565 | |
| 7566 | 7566 | const callee_ty = sema.typeOf(func); |
| 7567 | | const func_ty_info = mod.typeToFunc(func_ty).?; |
| 7567 | const func_ty_info = zcu.typeToFunc(func_ty).?; |
| 7568 | 7568 | const cc = func_ty_info.cc; |
| 7569 | 7569 | if (try sema.resolveValue(func)) |func_val| |
| 7570 | | if (func_val.isUndef(mod)) |
| 7570 | if (func_val.isUndef(zcu)) |
| 7571 | 7571 | return sema.failWithUseOfUndef(block, call_src); |
| 7572 | 7572 | if (cc == .Naked) { |
| 7573 | 7573 | const maybe_func_inst = try sema.funcDeclSrcInst(func); |
| ... | ... | @@ -7679,7 +7679,7 @@ fn analyzeCall( |
| 7679 | 7679 | .needed_comptime_reason = "function being called at comptime must be comptime-known", |
| 7680 | 7680 | .block_comptime_reason = comptime_reason, |
| 7681 | 7681 | }); |
| 7682 | | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7682 | const module_fn_index = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { |
| 7683 | 7683 | .@"extern" => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 7684 | 7684 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 7685 | 7685 | }), |
| ... | ... | @@ -7696,7 +7696,7 @@ fn analyzeCall( |
| 7696 | 7696 | }, |
| 7697 | 7697 | else => {}, |
| 7698 | 7698 | } |
| 7699 | | assert(callee_ty.isPtrAtRuntime(mod)); |
| 7699 | assert(callee_ty.isPtrAtRuntime(zcu)); |
| 7700 | 7700 | return sema.fail(block, call_src, "{s} call of function pointer", .{ |
| 7701 | 7701 | if (is_comptime_call) "comptime" else "inline", |
| 7702 | 7702 | }); |
| ... | ... | @@ -7736,7 +7736,7 @@ fn analyzeCall( |
| 7736 | 7736 | }, |
| 7737 | 7737 | }; |
| 7738 | 7738 | |
| 7739 | | const module_fn = mod.funcInfo(module_fn_index); |
| 7739 | const module_fn = zcu.funcInfo(module_fn_index); |
| 7740 | 7740 | |
| 7741 | 7741 | // This is not a function instance, so the function's `Nav` has a |
| 7742 | 7742 | // `Cau` -- we don't need to check `generic_owner`. |
| ... | ... | @@ -7750,7 +7750,7 @@ fn analyzeCall( |
| 7750 | 7750 | // whenever performing an operation where the difference matters. |
| 7751 | 7751 | var ics = InlineCallSema.init( |
| 7752 | 7752 | sema, |
| 7753 | | mod.cauFileScope(fn_cau_index).zir, |
| 7753 | zcu.cauFileScope(fn_cau_index).zir, |
| 7754 | 7754 | module_fn_index, |
| 7755 | 7755 | block.error_return_trace_index, |
| 7756 | 7756 | ); |
| ... | ... | @@ -7784,13 +7784,16 @@ fn analyzeCall( |
| 7784 | 7784 | |
| 7785 | 7785 | // Whether this call should be memoized, set to false if the call can |
| 7786 | 7786 | // mutate comptime state. |
| 7787 | | var should_memoize = true; |
| 7787 | // TODO: comptime call memoization is currently not supported under incremental compilation |
| 7788 | // since dependencies are not marked on callers. If we want to keep this around (we should |
| 7789 | // check that it's worthwhile first!), each memoized call needs a `Cau`. |
| 7790 | var should_memoize = !zcu.comp.incremental; |
| 7788 | 7791 | |
| 7789 | 7792 | // If it's a comptime function call, we need to memoize it as long as no external |
| 7790 | 7793 | // comptime memory is mutated. |
| 7791 | 7794 | const memoized_arg_values = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); |
| 7792 | 7795 | |
| 7793 | | const owner_info = mod.typeToFunc(Type.fromInterned(module_fn.ty)).?; |
| 7796 | const owner_info = zcu.typeToFunc(Type.fromInterned(module_fn.ty)).?; |
| 7794 | 7797 | const new_param_types = try sema.arena.alloc(InternPool.Index, owner_info.param_types.len); |
| 7795 | 7798 | var new_fn_info: InternPool.GetFuncTypeKey = .{ |
| 7796 | 7799 | .param_types = new_param_types, |
| ... | ... | @@ -7875,12 +7878,12 @@ fn analyzeCall( |
| 7875 | 7878 | // bug generating invalid LLVM IR. |
| 7876 | 7879 | const res2: Air.Inst.Ref = res2: { |
| 7877 | 7880 | if (should_memoize and is_comptime_call) { |
| 7878 | | if (mod.intern_pool.getIfExists(.{ .memoized_call = .{ |
| 7881 | if (zcu.intern_pool.getIfExists(.{ .memoized_call = .{ |
| 7879 | 7882 | .func = module_fn_index, |
| 7880 | 7883 | .arg_values = memoized_arg_values, |
| 7881 | 7884 | .result = .none, |
| 7882 | 7885 | } })) |memoized_call_index| { |
| 7883 | | const memoized_call = mod.intern_pool.indexToKey(memoized_call_index).memoized_call; |
| 7886 | const memoized_call = zcu.intern_pool.indexToKey(memoized_call_index).memoized_call; |
| 7884 | 7887 | break :res2 Air.internedToRef(memoized_call.result); |
| 7885 | 7888 | } |
| 7886 | 7889 | } |
| ... | ... | @@ -7939,7 +7942,7 @@ fn analyzeCall( |
| 7939 | 7942 | // a reference to `comptime_allocs` so is not stable across instances of `Sema`. |
| 7940 | 7943 | // TODO: check whether any external comptime memory was mutated by the |
| 7941 | 7944 | // comptime function call. If so, then do not memoize the call here. |
| 7942 | | if (should_memoize and !Value.fromInterned(result_interned).canMutateComptimeVarState(mod)) { |
| 7945 | if (should_memoize and !Value.fromInterned(result_interned).canMutateComptimeVarState(zcu)) { |
| 7943 | 7946 | _ = try pt.intern(.{ .memoized_call = .{ |
| 7944 | 7947 | .func = module_fn_index, |
| 7945 | 7948 | .arg_values = memoized_arg_values, |
| ... | ... | @@ -7978,7 +7981,7 @@ fn analyzeCall( |
| 7978 | 7981 | if (param_ty) |t| assert(!t.isGenericPoison()); |
| 7979 | 7982 | arg_out.* = try args_info.analyzeArg(sema, block, arg_idx, param_ty, func_ty_info, func); |
| 7980 | 7983 | try sema.validateRuntimeValue(block, args_info.argSrc(block, arg_idx), arg_out.*); |
| 7981 | | if (sema.typeOf(arg_out.*).zigTypeTag(mod) == .NoReturn) { |
| 7984 | if (sema.typeOf(arg_out.*).zigTypeTag(zcu) == .NoReturn) { |
| 7982 | 7985 | return arg_out.*; |
| 7983 | 7986 | } |
| 7984 | 7987 | } |
| ... | ... | @@ -7987,15 +7990,15 @@ fn analyzeCall( |
| 7987 | 7990 | |
| 7988 | 7991 | switch (sema.owner.unwrap()) { |
| 7989 | 7992 | .cau => {}, |
| 7990 | | .func => |owner_func| if (Type.fromInterned(func_ty_info.return_type).isError(mod)) { |
| 7993 | .func => |owner_func| if (Type.fromInterned(func_ty_info.return_type).isError(zcu)) { |
| 7991 | 7994 | ip.funcSetCallsOrAwaitsErrorableFn(owner_func); |
| 7992 | 7995 | }, |
| 7993 | 7996 | } |
| 7994 | 7997 | |
| 7995 | 7998 | if (try sema.resolveValue(func)) |func_val| { |
| 7996 | | if (mod.intern_pool.isFuncBody(func_val.toIntern())) { |
| 7999 | if (zcu.intern_pool.isFuncBody(func_val.toIntern())) { |
| 7997 | 8000 | try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = func_val.toIntern() })); |
| 7998 | | try mod.ensureFuncBodyAnalysisQueued(func_val.toIntern()); |
| 8001 | try zcu.ensureFuncBodyAnalysisQueued(func_val.toIntern()); |
| 7999 | 8002 | } |
| 8000 | 8003 | } |
| 8001 | 8004 | |
| ... | ... | @@ -8022,7 +8025,7 @@ fn analyzeCall( |
| 8022 | 8025 | // Function pointers and extern functions aren't guaranteed to |
| 8023 | 8026 | // actually be noreturn so we add a safety check for them. |
| 8024 | 8027 | if (try sema.resolveValue(func)) |func_val| { |
| 8025 | | switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 8028 | switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { |
| 8026 | 8029 | .func => break :skip_safety, |
| 8027 | 8030 | .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) { |
| 8028 | 8031 | .nav => |nav| if (!ip.getNav(nav).isExtern(ip)) break :skip_safety, |