Files
zig/test/incremental/add_remove_struct_fields
T
Pavel Verigo ad7a028228 stage2-wasm: pass incremental tests
This PR enables all incremental tests under the `test/incremental` directory, except one: `change_exports`, which is currently ignored as it requires a non-trivial amount of work on the linker, since we do not currently support exporting data symbols.

To enable the other tests, the following fixes were needed:

1. `src/link/Wasm.zig`: instead of chasing function type through Nav, get it directly.
2. `src/target.zig`: `.panic_fn` appears to work fine with the wasm backend.
3. `src/codegen/wasm/CodeGen.zig`: there was a liveness related bug that caused some `ArenaAllocator` code to crash the backend.

More info on (3), the liveness and local reuse code in the backend for years in unfinished state. For example there is currently no branch merging and reuse happens only when inst die in same block level. I initially considered doing a large refactor to implement everything correctly, but aborted due to its sheer size and currently! no clear idea about how to do this efficiently.

Instead, I fixed the bug with minimal changes and removed useless code, keeping the old solution otherwise intact.
2026-04-04 15:21:35 +02:00

100 lines
3.4 KiB
Plaintext

#target=x86_64-linux-selfhosted
#target=x86_64-windows-selfhosted
#target=x86_64-linux-cbe
#target=x86_64-windows-cbe
#target=x86_64-linux-llvm
#target=wasm32-wasi-selfhosted
#update=initial version
#file=main.zig
const S = struct { x: u8 };
pub fn main(init: std.process.Init) !void {
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
printFieldCount(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
printOneField(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
}
fn printFieldCount(w: *Writer) Writer.Error!void {
try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
}
fn printOneField(w: *Writer) Writer.Error!void {
const val: S = .{ .x = 100 };
try w.print("{d}\n", .{val.x});
}
const std = @import("std");
const Writer = std.Io.Writer;
#expect_stdout="1 100\n"
#update=add a field
#file=main.zig
const S = struct { x: u8, y: u16 = 200 };
pub fn main(init: std.process.Init) !void {
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
printFieldCount(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
printOneField(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
}
fn printFieldCount(w: *Writer) Writer.Error!void {
try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
}
fn printOneField(w: *Writer) Writer.Error!void {
const val: S = .{ .x = 100 };
try w.print("{d}\n", .{val.x});
}
const std = @import("std");
const Writer = std.Io.Writer;
#expect_stdout="2 100\n"
#update=remove all fields
#file=main.zig
const S = struct {};
pub fn main(init: std.process.Init) !void {
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
printFieldCount(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
printOneField(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
}
fn printFieldCount(w: *Writer) Writer.Error!void {
try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
}
fn printOneField(w: *Writer) Writer.Error!void {
const val: S = .{ .x = 100 };
try w.print("{d}\n", .{val.x});
}
const std = @import("std");
const Writer = std.Io.Writer;
#expect_error=main.zig:15:24: error: no field named 'x' in struct 'main.S'
#expect_error=main.zig:1:11: note: struct declared here
#update=remove reference to non-existent field
#file=main.zig
const S = struct {};
pub fn main(init: std.process.Init) !void {
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
printFieldCount(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
printOneField(&stdout_writer.interface) catch |err| switch (err) {
error.WriteFailed => return stdout_writer.err.?,
};
}
fn printFieldCount(w: *Writer) Writer.Error!void {
try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
}
fn printOneField(w: *Writer) Writer.Error!void {
//const val: S = .{ .x = 100 };
//try w.print("{d}\n", .{val.x});
try w.writeAll("<no fields>\n");
}
const std = @import("std");
const Writer = std.Io.Writer;
#expect_stdout="0 <no fields>\n"