aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-12 13:31:50 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-13 22:13:44 -0700
commit336d0c97feabad4c93525ba6ef73a6b6163f49c7 (patch)
tree0cf55d52805897bc9ce255c903bd9dc18043973f /test/behavior/array.zig
parentb019a19b5546d51865175359ec1ae8e5aa3f4128 (diff)
downloadzig-336d0c97feabad4c93525ba6ef73a6b6163f49c7.tar.gz
zig-336d0c97feabad4c93525ba6ef73a6b6163f49c7.zip
stage2: detection of comptime array literals
Introduce `validate_array_init_comptime`, similar to `validate_struct_init_comptime` introduced in 713d2a9b3883942491b40738245232680877cc66. `zirValidateArrayInit` is improved to detect comptime array literals and emit AIR accordingly. This code is very similar to the changes introduced in that same commit for `zirValidateStructInit`. The C backend needed some improvements to continue passing the same set of tests: * `resolveInst` for arrays now will add a local `static const` with the array value and so then `elem_val` instructions reference that local. It memoizes accesses using `value_map`, which is changed to use `Air.Inst.Ref` as the key rather than `Air.Inst.Index`. * This required a mechanism for writing to a "header" which is lines that appear at the beginning of a function body, before everything else. * dbg_stmt output comments rather than `#line` directives. TODO comment reproduced here: We need to re-evaluate whether to emit these or not. If we naively emit these directives, the output file will report bogus line numbers because every newline after the #line directive adds one to the line. We also don't print the filename yet, so the output is strictly unhelpful. If we wanted to go this route, we would need to go all the way and not output newlines until the next dbg_stmt occurs. Perhaps an additional compilation option is in order? `Value.elemValue` is improved to support `elem_ptr` values.
Diffstat (limited to 'test/behavior/array.zig')
-rw-r--r--test/behavior/array.zig7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index cd74640bea..cd2d029e22 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -114,6 +114,13 @@ test "void arrays" {
}
test "nested arrays" {
+ if (builtin.zig_backend == .stage2_wasm) {
+ // TODO this is a recent stage2 test case regression due to an enhancement;
+ // now arrays are properly detected as comptime. This exercised a new code
+ // path in the wasm backend that is not yet implemented.
+ return error.SkipZigTest;
+ }
+
const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" };
for (array_of_strings) |s, i| {
if (i == 0) try expect(mem.eql(u8, s, "hello"));