authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-01 00:37:28+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-01 01:24:11+03:00
logf2626a3d8ecddf48a08982ca78bff03e9d39d321
tree63f38df1e2d3e9ee24f07b7280841d08e9a10806
parente49fd39463be413a66920087d77eac983a91cb71

Sema: `validate{Array,Struct}Init` shortcut only valid if base ptr is comptime known


1 files changed, 6 insertions(+), 2 deletions(-)

src/Sema.zig+6-2
...@@ -3340,7 +3340,9 @@ fn validateStructInit(...@@ -3340,7 +3340,9 @@ fn validateStructInit(
3340 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);3340 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
3341 const struct_ty = sema.typeOf(struct_ptr).childType();3341 const struct_ty = sema.typeOf(struct_ptr).childType();
33423342
3343 if (is_comptime or block.is_comptime) {3343 if ((is_comptime or block.is_comptime) and
3344 (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null)
3345 {
3344 // In this case the only thing we need to do is evaluate the implicit3346 // In this case the only thing we need to do is evaluate the implicit
3345 // store instructions for default field values, and report any missing fields.3347 // store instructions for default field values, and report any missing fields.
3346 // Avoid the cost of the extra machinery for detecting a comptime struct init value.3348 // Avoid the cost of the extra machinery for detecting a comptime struct init value.
...@@ -3544,7 +3546,9 @@ fn zirValidateArrayInit(...@@ -3544,7 +3546,9 @@ fn zirValidateArrayInit(
3544 });3546 });
3545 }3547 }
35463548
3547 if (is_comptime or block.is_comptime) {3549 if ((is_comptime or block.is_comptime) and
3550 (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null)
3551 {
3548 // In this case the comptime machinery will have evaluated the store instructions3552 // In this case the comptime machinery will have evaluated the store instructions
3549 // at comptime so we have almost nothing to do here. However, in case of a3553 // at comptime so we have almost nothing to do here. However, in case of a
3550 // sentinel-terminated array, the sentinel will not have been populated by3554 // sentinel-terminated array, the sentinel will not have been populated by