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 {...@@ -237,13 +237,12 @@ pub const Symbol = struct {
237 };237 };
238};238};
239239
240/// Deprecated because it returns the optimization mode of the standard240/// Deprecated in favor of `std.lang.Optimize.runtimeSafety`, to be removed after 0.18.0
241/// library, when the caller probably wants to use the optimization mode of241///
242/// their own module.242/// Returns whether the standard library has safety checks enabled. Callsites
243pub const runtime_safety = switch (builtin.mode) {243/// likely would rather know whether their own module's optimization mode
244 .debug, .safe => true,244/// (found via `@import("builtin").optimize`) has safety checks enabled.
245 .fast, .small => false,245pub const runtime_safety = builtin.mode.runtimeSafety();
246};
247246
248/// Whether we can unwind the stack on this target, allowing capturing and/or printing the current247/// Whether we can unwind the stack on this target, allowing capturing and/or printing the current
249/// stack trace. It is still legal to call `captureCurrentStackTrace`, `writeCurrentStackTrace`, and248/// stack trace. It is still legal to call `captureCurrentStackTrace`, `writeCurrentStackTrace`, and
lib/std/lang.zig+9
...@@ -144,6 +144,15 @@ pub const Optimize = enum {...@@ -144,6 +144,15 @@ pub const Optimize = enum {
144 .{ "small", .small },144 .{ "small", .small },
145 }).get(s);145 }).get(s);
146 }146 }
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 }
147};156};
148157
149/// The calling convention of a function defines how arguments and return values are passed, as well158/// The calling convention of a function defines how arguments and return values are passed, as well