authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-24 13:44:41+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-24 20:30:52+01:00
log7d54c62c8a55240bbe144ab03c78573a344598ce
treef93383d99f058b4cf1aec8a3088c1c9847f138e0
parent2d7c26cc66facc401b37c26cb17bbae1da00d170

incremental: fix adding/removing aggregate fields

I don't recall why I put these checks here -- they aren't correct. We can freely recreate a type even if its fields have changed, because we are going to re-do all type resolution. The only conditions for recreations are (a) the ZIR index must not be lost and (b) the number of captures must be the same. These conditions are permissible because if either is violated, we can guarantee that analysis of a valid `zirStructDecl` (etc) will never reference this type (since the ZIR index has just been tracked, and the captures have just been created based on the ZIR). Adds a corresponding test case. Resolves: #21185

2 files changed, 23 insertions(+), 3 deletions(-)

src/Zcu/PerThread.zig-3
......@@ -3378,7 +3378,6 @@ fn recreateStructType(
33783378 } else 0;
33793379
33803380 if (captures_len != key.captures.owned.len) return error.AnalysisFail;
3381 if (fields_len != struct_obj.field_types.len) return error.AnalysisFail;
33823381
33833382 // The old type will be unused, so drop its dependency information.
33843383 ip.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .cau = struct_obj.cau.unwrap().? }));
......@@ -3466,7 +3465,6 @@ fn recreateUnionType(
34663465 } else 0;
34673466
34683467 if (captures_len != key.captures.owned.len) return error.AnalysisFail;
3469 if (fields_len != union_obj.field_types.len) return error.AnalysisFail;
34703468
34713469 // The old type will be unused, so drop its dependency information.
34723470 ip.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .cau = union_obj.cau }));
......@@ -3577,7 +3575,6 @@ fn recreateEnumType(
35773575 } else 0;
35783576
35793577 if (captures_len != key.captures.owned.len) return error.AnalysisFail;
3580 if (fields_len != enum_obj.names.len) return error.AnalysisFail;
35813578
35823579 extra_index += captures_len;
35833580 extra_index += decls_len;
test/incremental/remove_enum_field created+23
......@@ -0,0 +1,23 @@
1#target=x86_64-linux
2#update=initial version
3#file=main.zig
4const MyEnum = enum(u8) {
5 foo = 1,
6 bar = 2,
7};
8pub fn main() !void {
9 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});
10}
11const std = @import("std");
12#expect_stdout="1\n"
13#update=remove enum field
14#file=main.zig
15const MyEnum = enum(u8) {
16 //foo = 1,
17 bar = 2,
18};
19pub fn main() !void {
20 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});
21}
22const std = @import("std");
23#expect_error=ignored