Skip to content

Commit

Permalink
docs: Clarify that donotdelete does not affect unreachable code (#5…
Browse files Browse the repository at this point in the history
…2869)

In generally accepted compiler terminology, dead code is all code that
if removed does not affect the observable behavior of the program.
However, people sometimes use the phrase dead code to mean *unreachable*
code, which is a subset of dead code (being dead because it is never
semantically executed). If one assumes that definition, the docstring
for `donotdelete` may be confusing, as it may in fact be deleted from
the code if it is unreachable (existence or non-existence in the IR is
not ever semantically observable in Julia, so there could not be such an
intrinsic, but of course knowing that requires a deep understanding of
Julia semantics). Add an extra note to the docs to clarify this point.
  • Loading branch information
Keno authored Jan 12, 2024
1 parent 270ea64 commit 5b6a94d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3312,7 +3312,7 @@ kw"atomic"
This function prevents dead-code elimination (DCE) of itself and any arguments
passed to it, but is otherwise the lightest barrier possible. In particular,
it is not a GC safepoint, does model an observable heap effect, does not expand
it is not a GC safepoint, does not model an observable heap effect, does not expand
to any code itself and may be re-ordered with respect to other side effects
(though the total number of executions may not change).
Expand All @@ -3330,6 +3330,14 @@ unused and delete the entire benchmark code).
`donotdelete(1+1)`, no add instruction needs to be executed at runtime and
the code is semantically equivalent to `donotdelete(2).`
!!! note
This intrinsic 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,
in memory, etc.).
# Examples
```julia
Expand Down

0 comments on commit 5b6a94d

Please sign in to comment.