authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-19 21:28:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-20 17:26:50-07:00
logf2c2ee28cbb2aad3943a5726ea5d1dfa427c96af
tree618cb7d385a7735e20eb8a647ae914b5b0e1fdf4
parentae4e835a662a3b8c512511b87f4a44065e26dbb7

std.lang.Optimize: provide alternative to std.debug.runtime_safety


2 files changed, 15 insertions(+), 7 deletions(-)

lib/std/debug.zig+6-7
......@@ -237,13 +237,12 @@ pub const Symbol = struct {
237237 };
238238};
239239
240/// Deprecated because it returns the optimization mode of the standard
241/// library, when the caller probably wants to use the optimization mode of
242/// their own module.
243pub const runtime_safety = switch (builtin.mode) {
244 .debug, .safe => true,
245 .fast, .small => false,
246};
240/// Deprecated in favor of `std.lang.Optimize.runtimeSafety`, to be removed after 0.18.0
241///
242/// Returns whether the standard library has safety checks enabled. Callsites
243/// likely would rather know whether their own module's optimization mode
244/// (found via `@import("builtin").optimize`) has safety checks enabled.
245pub const runtime_safety = builtin.mode.runtimeSafety();
247246
248247/// Whether we can unwind the stack on this target, allowing capturing and/or printing the current
249248/// stack trace. It is still legal to call `captureCurrentStackTrace`, `writeCurrentStackTrace`, and
lib/std/lang.zig+9
......@@ -144,6 +144,15 @@ pub const Optimize = enum {
144144 .{ "small", .small },
145145 }).get(s);
146146 }
147
148 /// Returns whether illegal behavior safety checks are enabled based on the
149 /// provided optimization mode.
150 pub fn runtimeSafety(o: @This()) bool {
151 return switch (o) {
152 .debug, .safe => true,
153 .fast, .small => false,
154 };
155 }
147156};
148157
149158/// The calling convention of a function defines how arguments and return values are passed, as well