From b2391a7d4425418a29598523dcbdf2bfc9325ecd Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Wed, 31 May 2023 02:32:09 -0400 Subject: [PATCH] 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. --- src/Sema.zig | 6 ++++-- src/type.zig | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 9af9b6eace42789f609b0360aacd2c5c8f876017..bc34109bc994a34058acc7010fcc793c0e62bb15 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -33468,11 +33468,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { .inferred_error_set_type, => null, - inline .array_type, .vector_type => |seq_type| { - if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{ + inline .array_type, .vector_type => |seq_type, seq_tag| { + const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; + if (seq_type.len + @boolToInt(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{ .ty = ty.toIntern(), .storage = .{ .elems = &.{} }, } })).toValue(); + if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| { return (try mod.intern(.{ .aggregate = .{ .ty = ty.toIntern(), diff --git a/src/type.zig b/src/type.zig index 0c4dfb7e7e9f85b5b7f32a2c16003e5228ba35be..bbc2a2ce604cdbd0a20793a07e81bf683f6083ec 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2479,8 +2479,9 @@ pub const Type = struct { .inferred_error_set_type, => return null, - inline .array_type, .vector_type => |seq_type| { - if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{ + inline .array_type, .vector_type => |seq_type, seq_tag| { + const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; + if (seq_type.len + @boolToInt(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{ .ty = ty.toIntern(), .storage = .{ .elems = &.{} }, } })).toValue(); -- 2.54.0