From 9f3e29cb43198dd002a2d3766a19e73d5d2293d6 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Sat, 14 Sep 2024 12:08:44 -0500 Subject: [PATCH 1/3] make Base.donotdelete public --- base/public.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/public.jl b/base/public.jl index 803766a0cec1b..c1b371c27e089 100644 --- a/base/public.jl +++ b/base/public.jl @@ -117,4 +117,5 @@ public notnothing, runtests, text_colors, - depwarn + depwarn, + donotdelete From bfa91323122f9907f1071d1ac8391b7f3ec38b73 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Mon, 4 Nov 2024 13:28:02 -0600 Subject: [PATCH 2/3] add news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c12cc3c64300c..b04afe0bfcf3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -74,6 +74,7 @@ New library functions * `uuid7()` creates an RFC 9652 compliant UUID with version 7 ([#54834]). * `insertdims(array; dims)` allows to insert singleton dimensions into an array which is the inverse operation to `dropdims` * The new `Fix` type is a generalization of `Fix1/Fix2` for fixing a single argument ([#54653]). +* `Base.donotdelete` is now public. It prevents deadcode elemination of its arguments ([#55774]). New library features -------------------- From 680ce5a21c4b329d938642c6baa1033e21b49eec Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Mon, 4 Nov 2024 13:36:03 -0600 Subject: [PATCH 3/3] make Base.donotdelete a generic function --- base/docs/basedocs.jl | 8 ++++---- base/essentials.jl | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index e03d0db78f29f..7cefa7d2b0ce4 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -3705,11 +3705,11 @@ unused and delete the entire benchmark code). the code is semantically equivalent to `donotdelete(2).` !!! note - This intrinsic does not affect the semantics of code that is dead because it is + This function does not affect the semantics of code that is dead because it is *unreachable*. For example, the body of the function `f(x) = false && donotdelete(x)` - may be deleted in its entirety. The semantics of this intrinsic only guarantee that - *if* the intrinsic is semantically executed, then there is some program state at - which the value of the arguments of this intrinsic were available (in a register, + may be deleted in its entirety. The semantics of this function only guarantee that + *if* the function is semantically executed, then there is some program state at + which the value of the arguments of this function were available (in a register, in memory, etc.). # Examples diff --git a/base/essentials.jl b/base/essentials.jl index 32c44a9571f23..8539d423e9327 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Core: CodeInfo, SimpleVector, donotdelete, compilerbarrier, memoryrefnew, memoryrefget, memoryrefset! +using Core: CodeInfo, SimpleVector, compilerbarrier, memoryrefnew, memoryrefget, memoryrefset! const Callable = Union{Function,Type} @@ -1261,3 +1261,5 @@ typename(typeof(function < end)).constprop_heuristic = Core.SAMETYPE_HEURISTIC typename(typeof(function > end)).constprop_heuristic = Core.SAMETYPE_HEURISTIC typename(typeof(function << end)).constprop_heuristic = Core.SAMETYPE_HEURISTIC typename(typeof(function >> end)).constprop_heuristic = Core.SAMETYPE_HEURISTIC + +donotdelete(args...) = Core.donotdelete(args...)