From 4fccc95b0152aefeb40912768ec045b57a2fdc2b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 20 Jan 2022 15:36:40 -0700 Subject: Sema: fix requiresComptime infinite recursion When asking a struct or union whether the type requires comptime, it may need to ask itself recursively, for example because of a field which is a pointer to itself. This commit adds a field to each to keep track of when computing the "requires comptime" value and returns `false` if the check is already ongoing. --- src/Module.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index c66509f33a..1cb890b886 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -821,6 +821,8 @@ pub const ErrorSet = struct { } }; +pub const RequiresComptime = enum { no, yes, unknown, wip }; + /// Represents the data that a struct declaration provides. pub const Struct = struct { /// The Decl that corresponds to the struct itself. @@ -849,6 +851,7 @@ pub const Struct = struct { /// If true, definitely nonzero size at runtime. If false, resolving the fields /// is necessary to determine whether it has bits at runtime. known_has_bits: bool, + requires_comptime: RequiresComptime = .unknown, pub const Fields = std.StringArrayHashMapUnmanaged(Field); @@ -1038,6 +1041,7 @@ pub const Union = struct { // which `have_layout` does not ensure. fully_resolved, }, + requires_comptime: RequiresComptime = .unknown, pub const Field = struct { /// undefined until `status` is `have_field_types` or `have_layout`. -- cgit v1.2.3