| author | |
| committer | |
| log | 935d208ffb955e74864e12f0f7e265f64642a02f |
| tree | b38fe66f493abb214853c9385a14dbd4d50bcf31 |
| parent | 95fc41b2b433ccfa751c8877ec7edac3b9bffbd6 |
| parent | ba62853d26f6a3388a7ad099a1d9091d7eca45c9 |
| signature |
stage2: correct comptime-known inferred alloc type, plus comptime array init sentinels2 files changed, 23 insertions(+), 17 deletions(-)
src/Sema.zig+8-14| ... | ... | @@ -2623,10 +2623,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2623 | 2623 | // block so that codegen does not see it. |
| 2624 | 2624 | block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3); |
| 2625 | 2625 | sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl); |
| 2626 | // Would be nice if we could just assign `bitcast_ty_ref` to | |
| 2627 | // `air_datas[ptr_inst].ty_pl.ty`, wouldn't it? Alas, that is almost correct, | |
| 2628 | // except that the pointer is mutable and we need to make it constant here. | |
| 2629 | air_datas[ptr_inst].ty_pl.ty = try sema.addType(final_ptr_ty); | |
| 2626 | // if bitcast ty ref needs to be made const, make_ptr_const | |
| 2627 | // ZIR handles it later, so we can just use the ty ref here. | |
| 2628 | air_datas[ptr_inst].ty_pl.ty = air_datas[bitcast_inst].ty_op.ty; | |
| 2630 | 2629 | |
| 2631 | 2630 | return; |
| 2632 | 2631 | } |
| ... | ... | @@ -11828,21 +11827,16 @@ fn zirArrayInit( |
| 11828 | 11827 | }); |
| 11829 | 11828 | }; |
| 11830 | 11829 | |
| 11831 | const elems = if (!is_sent) | |
| 11832 | resolved_args | |
| 11833 | else | |
| 11834 | resolved_args[0 .. resolved_args.len - 1]; | |
| 11835 | ||
| 11836 | const opt_runtime_src: ?LazySrcLoc = for (elems) |arg| { | |
| 11830 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { | |
| 11837 | 11831 | const arg_src = src; // TODO better source location |
| 11838 | 11832 | const comptime_known = try sema.isComptimeKnown(block, arg_src, arg); |
| 11839 | 11833 | if (!comptime_known) break arg_src; |
| 11840 | 11834 | } else null; |
| 11841 | 11835 | |
| 11842 | 11836 | const runtime_src = opt_runtime_src orelse { |
| 11843 | const elem_vals = try sema.arena.alloc(Value, elems.len); | |
| 11837 | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); | |
| 11844 | 11838 | |
| 11845 | for (elems) |arg, i| { | |
| 11839 | for (resolved_args) |arg, i| { | |
| 11846 | 11840 | // We checked that all args are comptime above. |
| 11847 | 11841 | elem_vals[i] = (sema.resolveMaybeUndefVal(block, src, arg) catch unreachable).?; |
| 11848 | 11842 | } |
| ... | ... | @@ -11869,7 +11863,7 @@ fn zirArrayInit( |
| 11869 | 11863 | }); |
| 11870 | 11864 | const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); |
| 11871 | 11865 | |
| 11872 | for (elems) |arg, i| { | |
| 11866 | for (resolved_args) |arg, i| { | |
| 11873 | 11867 | const index = try sema.addIntUnsigned(Type.usize, i); |
| 11874 | 11868 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 11875 | 11869 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| ... | ... | @@ -11877,7 +11871,7 @@ fn zirArrayInit( |
| 11877 | 11871 | return alloc; |
| 11878 | 11872 | } |
| 11879 | 11873 | |
| 11880 | return block.addAggregateInit(array_ty, elems); | |
| 11874 | return block.addAggregateInit(array_ty, resolved_args); | |
| 11881 | 11875 | } |
| 11882 | 11876 | |
| 11883 | 11877 | fn zirArrayInitAnon( |
test/behavior/pointers.zig+15-3| ... | ... | @@ -317,7 +317,11 @@ test "allow any sentinel" { |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | test "pointer sentinel with enums" { |
| 320 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | |
| 320 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 321 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 322 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 323 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 324 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 321 | 325 | |
| 322 | 326 | const S = struct { |
| 323 | 327 | const Number = enum { |
| ... | ... | @@ -336,7 +340,11 @@ test "pointer sentinel with enums" { |
| 336 | 340 | } |
| 337 | 341 | |
| 338 | 342 | test "pointer sentinel with optional element" { |
| 339 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | |
| 343 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 344 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 345 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 346 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 347 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 340 | 348 | |
| 341 | 349 | const S = struct { |
| 342 | 350 | fn doTheTest() !void { |
| ... | ... | @@ -349,7 +357,11 @@ test "pointer sentinel with optional element" { |
| 349 | 357 | } |
| 350 | 358 | |
| 351 | 359 | test "pointer sentinel with +inf" { |
| 352 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | |
| 360 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 361 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 362 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 363 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 364 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 353 | 365 | |
| 354 | 366 | const S = struct { |
| 355 | 367 | fn doTheTest() !void { |