authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-20 16:05:04+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-21 01:30:46+01:00
loga99ad52b362d966f772f29ad14ae1714218bc033
treead8a93f55ed7c4cff101789aedea0b5cc930d0f6
parent2fb78430dbff206af24ecd5e7be163e624fdbb6f
signaturelock-open Commit is signed but in an unrecognized format.

Sema: register correct dependencies for inline calls

And add a corresponding test case.

2 files changed, 30 insertions(+), 0 deletions(-)

src/Sema.zig+7
...@@ -7598,6 +7598,9 @@ fn analyzeCall(...@@ -7598,6 +7598,9 @@ fn analyzeCall(
75987598
7599 const module_fn = zcu.funcInfo(module_fn_index);7599 const module_fn = zcu.funcInfo(module_fn_index);
76007600
7601 // The call site definitely depends on the function's signature.
7602 try sema.declareDependency(.{ .src_hash = module_fn.zir_body_inst });
7603
7601 // This is not a function instance, so the function's `Nav` has a7604 // This is not a function instance, so the function's `Nav` has a
7602 // `Cau` -- we don't need to check `generic_owner`.7605 // `Cau` -- we don't need to check `generic_owner`.
7603 const fn_nav = ip.getNav(module_fn.owner_nav);7606 const fn_nav = ip.getNav(module_fn.owner_nav);
...@@ -7755,6 +7758,10 @@ fn analyzeCall(...@@ -7755,6 +7758,10 @@ fn analyzeCall(
7755 break :res Air.internedToRef(memoized_call.result);7758 break :res Air.internedToRef(memoized_call.result);
7756 }7759 }
77577760
7761 // Since we're doing an inline call, we depend on the source code of the whole
7762 // function declaration.
7763 try sema.declareDependency(.{ .src_hash = fn_cau.zir_index });
7764
7758 new_fn_info.return_type = sema.fn_ret_ty.toIntern();7765 new_fn_info.return_type = sema.fn_ret_ty.toIntern();
7759 if (!is_comptime_call and !block.is_typeof) {7766 if (!is_comptime_call and !block.is_typeof) {
7760 const zir_tags = sema.code.instructions.items(.tag);7767 const zir_tags = sema.code.instructions.items(.tag);
test/incremental/modify_inline_fn created+23
...@@ -0,0 +1,23 @@
1#target=x86_64-linux
2#update=initial version
3#file=main.zig
4const std = @import("std");
5pub fn main() !void {
6 const str = getStr();
7 try std.io.getStdOut().writeAll(str);
8}
9inline fn getStr() []const u8 {
10 return "foo\n";
11}
12#expect_stdout="foo\n"
13#update=change the string
14#file=main.zig
15const std = @import("std");
16pub fn main() !void {
17 const str = getStr();
18 try std.io.getStdOut().writeAll(str);
19}
20inline fn getStr() []const u8 {
21 return "bar\n";
22}
23#expect_stdout="bar\n"