diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 8aaee0e29edaba4523a70710de7eca31cf0bc078..898ae314d9084e35fed670b03854959ec06beead 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -237,13 +237,12 @@ pub const Symbol = struct { }; }; -/// Deprecated because it returns the optimization mode of the standard -/// library, when the caller probably wants to use the optimization mode of -/// their own module. -pub const runtime_safety = switch (builtin.mode) { - .debug, .safe => true, - .fast, .small => false, -}; +/// Deprecated in favor of `std.lang.Optimize.runtimeSafety`, to be removed after 0.18.0 +/// +/// Returns whether the standard library has safety checks enabled. Callsites +/// likely would rather know whether their own module's optimization mode +/// (found via `@import("builtin").optimize`) has safety checks enabled. +pub const runtime_safety = builtin.mode.runtimeSafety(); /// Whether we can unwind the stack on this target, allowing capturing and/or printing the current /// stack trace. It is still legal to call `captureCurrentStackTrace`, `writeCurrentStackTrace`, and diff --git a/lib/std/lang.zig b/lib/std/lang.zig index daa2482eec7429bcd90a83ae2e2515681be29187..2f0868c39331456b03f055cafd8546f19ac51b07 100644 --- a/lib/std/lang.zig +++ b/lib/std/lang.zig @@ -144,6 +144,15 @@ pub const Optimize = enum { .{ "small", .small }, }).get(s); } + + /// Returns whether illegal behavior safety checks are enabled based on the + /// provided optimization mode. + pub fn runtimeSafety(o: @This()) bool { + return switch (o) { + .debug, .safe => true, + .fast, .small => false, + }; + } }; /// The calling convention of a function defines how arguments and return values are passed, as well