authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-08 11:53:43-08:00
committergravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-08 12:04:51-08:00
logcd32b11eb8d33225a1a2bc3bc9e0755936a39ade
tree9a1d9ccc5011f4cbc8efa9b5d76df597c7b803ca
parent55ccf4c7a8451edca47d8d6d82bddd9fe192744a
signaturelock-open Commit is signed but in an unrecognized format.

stage2: inferred alloc can use bitcast ty

The comment notes that we can't because of constness, but the recent work by @Vexu lets us use the bitcast ty cause constness comes later. The following tests pass from this: ``` test "A" { const ary = [_:0]u8{42}; const ptr: [*:0]const u8 = &ary; try expect(ptr[1] == 0); } test "B" { comptime { const ary = [_:0]u8{42}; const ptr: [*:0]const u8 = &ary; try expect(ptr[1] == 0); } } ```

1 files changed, 3 insertions(+), 4 deletions(-)

src/Sema.zig+3-4
......@@ -2623,10 +2623,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
26232623 // block so that codegen does not see it.
26242624 block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3);
26252625 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;
26302629
26312630 return;
26322631 }