diff --git a/stage0/sema.c b/stage0/sema.c index 7cb21bfaf2..78f6fdbb1f 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -457,79 +457,100 @@ static void zirDbgVar( } // --- Declaration.Flags.Id helpers --- -// Ported from lib/std/zig/Zir.zig Declaration.Flags.Id methods. +// Ported from lib/std/zig/Zir.zig Declaration.Flags.Id. // The Id is a 5-bit enum packed in the upper bits of Declaration.flags_1. -// -// Enum values (matching Zir.zig order): -// 0=unnamed_test, 1=test, 2=decltest, 3=comptime, -// 4=const_simple, 5=const_typed, 6=const, -// 7=pub_const_simple, 8=pub_const_typed, 9=pub_const, -// 10=extern_const_simple, 11=extern_const, -// 12=pub_extern_const_simple, 13=pub_extern_const, -// 14=export_const, 15=pub_export_const, -// 16=var_simple, 17=var, 18=var_threadlocal, -// 19=pub_var_simple, 20=pub_var, 21=pub_var_threadlocal, -// 22=extern_var, 23=extern_var_threadlocal, -// 24=pub_extern_var, 25=pub_extern_var_threadlocal, -// 26=export_var, 27=export_var_threadlocal, -// 28=pub_export_var, 29=pub_export_var_threadlocal +typedef enum { + DECL_ID_UNNAMED_TEST, // 0 + DECL_ID_TEST, // 1 + DECL_ID_DECLTEST, // 2 + DECL_ID_COMPTIME, // 3 + DECL_ID_CONST_SIMPLE, // 4 + DECL_ID_CONST_TYPED, // 5 + DECL_ID_CONST, // 6 + DECL_ID_PUB_CONST_SIMPLE, // 7 + DECL_ID_PUB_CONST_TYPED, // 8 + DECL_ID_PUB_CONST, // 9 + DECL_ID_EXTERN_CONST_SIMPLE, // 10 + DECL_ID_EXTERN_CONST, // 11 + DECL_ID_PUB_EXTERN_CONST_SIMPLE, // 12 + DECL_ID_PUB_EXTERN_CONST, // 13 + DECL_ID_EXPORT_CONST, // 14 + DECL_ID_PUB_EXPORT_CONST, // 15 + DECL_ID_VAR_SIMPLE, // 16 + DECL_ID_VAR, // 17 + DECL_ID_VAR_THREADLOCAL, // 18 + DECL_ID_PUB_VAR_SIMPLE, // 19 + DECL_ID_PUB_VAR, // 20 + DECL_ID_PUB_VAR_THREADLOCAL, // 21 + DECL_ID_EXTERN_VAR, // 22 + DECL_ID_EXTERN_VAR_THREADLOCAL, // 23 + DECL_ID_PUB_EXTERN_VAR, // 24 + DECL_ID_PUB_EXTERN_VAR_THREADLOCAL, // 25 + DECL_ID_EXPORT_VAR, // 26 + DECL_ID_EXPORT_VAR_THREADLOCAL, // 27 + DECL_ID_PUB_EXPORT_VAR, // 28 + DECL_ID_PUB_EXPORT_VAR_THREADLOCAL, // 29 +} DeclFlagsId; -static bool declIdHasName(uint32_t id) { - // false for unnamed_test(0) and comptime(3) - return id != 0 && id != 3; +static bool declIdHasName(DeclFlagsId id) { + return id != DECL_ID_UNNAMED_TEST && id != DECL_ID_COMPTIME; } -static bool declIdHasLibName(uint32_t id) { - return id == 11 || id == 13 || id == 22 || id == 23 || id == 24 - || id == 25; +static bool declIdHasLibName(DeclFlagsId id) { + return id == DECL_ID_EXTERN_CONST || id == DECL_ID_PUB_EXTERN_CONST + || id == DECL_ID_EXTERN_VAR || id == DECL_ID_EXTERN_VAR_THREADLOCAL + || id == DECL_ID_PUB_EXTERN_VAR + || id == DECL_ID_PUB_EXTERN_VAR_THREADLOCAL; } -static bool declIdHasTypeBody(uint32_t id) { - // false for untyped constructs (0-3) and simple reprs (4,7,16,19) - return !(id == 0 || id == 1 || id == 2 || id == 3 || id == 4 || id == 7 - || id == 16 || id == 19); +static bool declIdHasTypeBody(DeclFlagsId id) { + return id != DECL_ID_UNNAMED_TEST && id != DECL_ID_TEST + && id != DECL_ID_DECLTEST && id != DECL_ID_COMPTIME + && id != DECL_ID_CONST_SIMPLE && id != DECL_ID_PUB_CONST_SIMPLE + && id != DECL_ID_VAR_SIMPLE && id != DECL_ID_PUB_VAR_SIMPLE; } -static bool declIdHasValueBody(uint32_t id) { - // false for extern IDs (10-13, 22-25) - return !(id == 10 || id == 11 || id == 12 || id == 13 || id == 22 - || id == 23 || id == 24 || id == 25); +static bool declIdHasValueBody(DeclFlagsId id) { + return id != DECL_ID_EXTERN_CONST_SIMPLE && id != DECL_ID_EXTERN_CONST + && id != DECL_ID_PUB_EXTERN_CONST_SIMPLE + && id != DECL_ID_PUB_EXTERN_CONST && id != DECL_ID_EXTERN_VAR + && id != DECL_ID_EXTERN_VAR_THREADLOCAL && id != DECL_ID_PUB_EXTERN_VAR + && id != DECL_ID_PUB_EXTERN_VAR_THREADLOCAL; } -static bool declIdHasSpecialBodies(uint32_t id) { - // false for untyped (0-3), simple const (4,5,7,8), - // extern_const_simple (10,12), simple var (16,19) - return !(id == 0 || id == 1 || id == 2 || id == 3 || id == 4 || id == 5 - || id == 7 || id == 8 || id == 10 || id == 12 || id == 16 || id == 19); +static bool declIdHasSpecialBodies(DeclFlagsId id) { + return id != DECL_ID_UNNAMED_TEST && id != DECL_ID_TEST + && id != DECL_ID_DECLTEST && id != DECL_ID_COMPTIME + && id != DECL_ID_CONST_SIMPLE && id != DECL_ID_CONST_TYPED + && id != DECL_ID_PUB_CONST_SIMPLE && id != DECL_ID_PUB_CONST_TYPED + && id != DECL_ID_EXTERN_CONST_SIMPLE + && id != DECL_ID_PUB_EXTERN_CONST_SIMPLE && id != DECL_ID_VAR_SIMPLE + && id != DECL_ID_PUB_VAR_SIMPLE; } // Ported from Zir.zig Declaration.Flags.Id.linkage -static bool declIdIsExport(uint32_t id) { - // 14=export_const, 15=pub_export_const, - // 26=export_var, 27=export_var_threadlocal, - // 28=pub_export_var, 29=pub_export_var_threadlocal - return id == 14 || id == 15 || id == 26 || id == 27 || id == 28 - || id == 29; +static bool declIdIsExport(DeclFlagsId id) { + return id == DECL_ID_EXPORT_CONST || id == DECL_ID_PUB_EXPORT_CONST + || id == DECL_ID_EXPORT_VAR || id == DECL_ID_EXPORT_VAR_THREADLOCAL + || id == DECL_ID_PUB_EXPORT_VAR + || id == DECL_ID_PUB_EXPORT_VAR_THREADLOCAL; } -// Ported from Zir.zig Declaration.Id.isPub -static bool declIdIsPub(uint32_t id) { - // 7=pub_const_simple, 8=pub_const_typed, 9=pub_const, - // 12=pub_extern_const_simple, 13=pub_extern_const, - // 15=pub_export_const, - // 19=pub_var_simple, 20=pub_var, 21=pub_var_threadlocal, - // 24=pub_extern_var, 25=pub_extern_var_threadlocal, - // 28=pub_export_var, 29=pub_export_var_threadlocal - return id == 7 || id == 8 || id == 9 || id == 12 || id == 13 || id == 15 - || id == 19 || id == 20 || id == 21 || id == 24 || id == 25 || id == 28 - || id == 29; +// Ported from Zir.zig Declaration.Flags.Id.isPub +static bool declIdIsPub(DeclFlagsId id) { + return id == DECL_ID_PUB_CONST_SIMPLE || id == DECL_ID_PUB_CONST_TYPED + || id == DECL_ID_PUB_CONST || id == DECL_ID_PUB_EXTERN_CONST_SIMPLE + || id == DECL_ID_PUB_EXTERN_CONST || id == DECL_ID_PUB_EXPORT_CONST + || id == DECL_ID_PUB_VAR_SIMPLE || id == DECL_ID_PUB_VAR + || id == DECL_ID_PUB_VAR_THREADLOCAL || id == DECL_ID_PUB_EXTERN_VAR + || id == DECL_ID_PUB_EXTERN_VAR_THREADLOCAL + || id == DECL_ID_PUB_EXPORT_VAR + || id == DECL_ID_PUB_EXPORT_VAR_THREADLOCAL; } -// Ported from Zir.zig Declaration.Id.kind: check if const (not var) -static bool declIdIsConst(uint32_t id) { - // 0-15 are const-related (test, comptime, const, extern_const, - // export_const), 16-29 are var-related - return id <= 15; +// Ported from Zir.zig Declaration.Flags.Id.kind +static bool declIdIsConst(DeclFlagsId id) { + return id <= DECL_ID_PUB_EXPORT_CONST; } // Forward declarations. @@ -5720,9 +5741,9 @@ static uint32_t findFuncInstInZir(const Zir* zir, const char* func_name) { uint32_t flags_1 = zir->extra[payload + 5]; uint32_t id = (flags_1 >> 27) & 0x1F; - // Skip test declarations (unnamed_test=0, test=1, decltest=2) - // and comptime blocks (3) — only look at const/var/export decls. - if (id <= 3) + // Skip test declarations and comptime blocks — + // only look at const/var/export decls. + if (id <= DECL_ID_COMPTIME) continue; uint32_t di = payload + 6;