From 34a6fcd88e20a2491bf6a5396d583a7449cac20b Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Fri, 11 Mar 2022 14:18:23 -0700 Subject: stage2: Add hasWellDefinedLayout() to type.zig and Sema.zig This follows the same strategy as sema.typeRequiresComptime() and type.comptimeOnly(): Two versions of the function, one which performs resolution just-in-time and another which asserts that resolution is complete. Thankfully, this doesn't cause very viral type resolution, since auto-layout structs and unions are very common and are known to not have a well-defined layout without resolving their fields. --- src/Module.zig | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index b6104df232..7c6c654660 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -852,7 +852,7 @@ pub const ErrorSet = struct { } }; -pub const RequiresComptime = enum { no, yes, unknown, wip }; +pub const PropertyBoolean = enum { no, yes, unknown, wip }; /// Represents the data that a struct declaration provides. pub const Struct = struct { @@ -884,7 +884,8 @@ pub const Struct = struct { /// If false, resolving the fields is necessary to determine whether the type has only /// one possible value. known_non_opv: bool, - requires_comptime: RequiresComptime = .unknown, + requires_comptime: PropertyBoolean = .unknown, + has_well_defined_layout: PropertyBoolean = .unknown, pub const Fields = std.StringArrayHashMapUnmanaged(Field); @@ -1079,6 +1080,8 @@ pub const EnumFull = struct { /// An integer type which is used for the numerical value of the enum. /// Whether zig chooses this type or the user specifies it, it is stored here. tag_ty: Type, + /// true if zig inferred this tag type, false if user specified it + tag_ty_inferred: bool, /// Set of field names in declaration order. fields: NameMap, /// Maps integer tag value to field index. @@ -1132,7 +1135,8 @@ pub const Union = struct { // which `have_layout` does not ensure. fully_resolved, }, - requires_comptime: RequiresComptime = .unknown, + requires_comptime: PropertyBoolean = .unknown, + has_well_defined_layout: PropertyBoolean = .unknown, pub const Field = struct { /// undefined until `status` is `have_field_types` or `have_layout`. -- cgit v1.2.3