Phase 3 added the tractable built-in attributes: #cold, #section("…"), #weak, #link_name("…"), #keep (backend), and #must_use (sema) — plus #maybe_unused is accepted. These remaining ones each need infrastructure beyond a simple attribute flag:
#when(cond) — conditional declaration inclusion
Drop a top-level declaration when a comptime cond folds to false (e.g. #when(core::os == "windows")). Top-level #if is not currently supported, so this fills a real gap. Needs a pre-sema pass (like runCompilerHookPass): tolerant sema → ComptimeVm → evaluate each #when cond to a bool → filter the decls before the strict pass. The dropped decls must be removed before sema so platform-specific code in the inactive branch isn't type-checked. (src/pipeline.zig — mirror the compiler-hook pass; reuse ComptimeVm.evalToImm.)
#test / #bench
Mark functions for collection by a test/benchmark runner. Needs: a collection pass that gathers #test/#bench functions, a generated entry point that runs them, and wiring into the build system's test_dir step (which currently compiles+runs whole files). Related to the existing b.test_dir(...) mechanism.
#on_start / #on_exit
Run a fn() (void, no args) at program startup / shutdown. Maps to LLVM @llvm.global_ctors / @llvm.global_dtors with a priority. Needs backend support to append the function to those global arrays. (src/backend/llvm — add a global_ctors/dtors emitter; the IrFunction would carry an on_start/on_exit priority.)
All are parsed today (unknown attributes are silently accepted), so adding them is additive — no migration. Priority is roughly #when > #on_start/#on_exit > #test/#bench.
Phase 3 added the tractable built-in attributes:
#cold,#section("…"),#weak,#link_name("…"),#keep(backend), and#must_use(sema) — plus#maybe_unusedis accepted. These remaining ones each need infrastructure beyond a simple attribute flag:#when(cond)— conditional declaration inclusionDrop a top-level declaration when a comptime
condfolds to false (e.g.#when(core::os == "windows")). Top-level#ifis not currently supported, so this fills a real gap. Needs a pre-sema pass (likerunCompilerHookPass): tolerant sema →ComptimeVm→ evaluate each#whencond to a bool → filter the decls before the strict pass. The dropped decls must be removed before sema so platform-specific code in the inactive branch isn't type-checked. (src/pipeline.zig — mirror the compiler-hook pass; reuseComptimeVm.evalToImm.)#test/#benchMark functions for collection by a test/benchmark runner. Needs: a collection pass that gathers
#test/#benchfunctions, a generated entry point that runs them, and wiring into the build system'stest_dirstep (which currently compiles+runs whole files). Related to the existingb.test_dir(...)mechanism.#on_start/#on_exitRun a
fn()(void, no args) at program startup / shutdown. Maps to LLVM@llvm.global_ctors/@llvm.global_dtorswith a priority. Needs backend support to append the function to those global arrays. (src/backend/llvm — add aglobal_ctors/dtorsemitter; the IrFunction would carry anon_start/on_exitpriority.)All are parsed today (unknown attributes are silently accepted), so adding them is additive — no migration. Priority is roughly
#when>#on_start/#on_exit>#test/#bench.