authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-31 02:32:09-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:58-07:00
logb2391a7d4425418a29598523dcbdf2bfc9325ecd
tree4c0fb2197e1d5f02fe3cab697aa08d703cc1a4c0
parent71c4077c359096d0706a251a10eeae6c41f299ca

Sema: remove opv status from arrays with sentinels

Being able to create a pointer to the non-opv sentinel means that these types have to actually be stored.

2 files changed, 7 insertions(+), 4 deletions(-)

src/Sema.zig+4-2
...@@ -33468,11 +33468,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33468,11 +33468,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33468 .inferred_error_set_type,33468 .inferred_error_set_type,
33469 => null,33469 => null,
3347033470
33471 inline .array_type, .vector_type => |seq_type| {33471 inline .array_type, .vector_type => |seq_type, seq_tag| {
33472 if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{33472 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
33473 if (seq_type.len + @boolToInt(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{
33473 .ty = ty.toIntern(),33474 .ty = ty.toIntern(),
33474 .storage = .{ .elems = &.{} },33475 .storage = .{ .elems = &.{} },
33475 } })).toValue();33476 } })).toValue();
33477
33476 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {33478 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {
33477 return (try mod.intern(.{ .aggregate = .{33479 return (try mod.intern(.{ .aggregate = .{
33478 .ty = ty.toIntern(),33480 .ty = ty.toIntern(),
src/type.zig+3-2
...@@ -2479,8 +2479,9 @@ pub const Type = struct {...@@ -2479,8 +2479,9 @@ pub const Type = struct {
2479 .inferred_error_set_type,2479 .inferred_error_set_type,
2480 => return null,2480 => return null,
24812481
2482 inline .array_type, .vector_type => |seq_type| {2482 inline .array_type, .vector_type => |seq_type, seq_tag| {
2483 if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{2483 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
2484 if (seq_type.len + @boolToInt(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{
2484 .ty = ty.toIntern(),2485 .ty = ty.toIntern(),
2485 .storage = .{ .elems = &.{} },2486 .storage = .{ .elems = &.{} },
2486 } })).toValue();2487 } })).toValue();