Skip to content

Treat writes to the data of a fresh Julia Memory or array as local - #3418

Merged
wsmoses merged 4 commits into
mainfrom
enzyme-fresh-memory
Oct 5, 2026
Merged

wsmoses merged 4 commits into
mainfrom
enzyme-fresh-memory

Conversation

@wsmoses

@wsmoses wsmoses commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Builds on #3415 (merged).

A Julia function that builds a temporary array, such as Distributions' sqmahal(d, x) = invquad(d.Σ, x .- d.μ), writes it through a data pointer it loads from the array's storage:

  %m    = call @jl_alloc_genericmemory(@"ejl_inserted$_Core_GenericMemory_…$false$…", n)
  %mem  = phi [ %m, … ], [ @"ejl_inserted$_Core_GenericMemory_…$true$…", … ]   ; empty singleton for n == 0
  %data = load ptr, ptr (%mem + 8)
  store double %z, ptr (%data + 8*i)

DetectReadonlyOrThrowFn only accepted writes whose base object is an allocation, so such functions were not marked LocalReadOnlyOrThrow, and with #3415 a call to one still counted as an unknown write for the calls before it.

Change

Accept a write as local when its base is a pointer loaded from the data field of

  • a fresh Memory (the field after the length), i.e. one
    • allocated by jl_alloc_genericmemory (or its i/_unchecked variants): the field is set on allocation and never changed, so the data is fresh too, or
    • the empty Memory singleton, whose data no in-bounds access writes — identified by enzymejl_empty_memory metadata on its global, which Mark the global for the empty Memory singleton enzymejl_empty_memory Enzyme.jl#3761 adds (the global's name alone does not distinguish it from other Memory objects, nor from the Memory{T} type itself);
  • a fresh array (the field at offset 0), i.e. one allocated in the function — by jl_alloc_array_*/jl_new_array on Julia 1.10, or like any other object (julia.gc_alloc_obj) from 1.11 on — whose data field only ever holds fresh data while the function runs. Unlike a Memory's, this field can change (e.g. when the array grows), so every store to it must store fresh data (or null), and the array's address must not be stored or passed to a call that may capture or write through it. Returning it is fine.

or a phi/select of these, found with getBaseObjects (the field's offset comes from stripAndAccumulateConstantOffsets). Only done with -enzyme-julia-addr-load.

getBaseObjects now also looks through selects, returning the base objects of both operands as it does for a phi's incoming values. Its existing users in activity analysis treat its result as the set of objects a pointer may refer to, so they become more precise the same way.

On Julia 1.11 LLVM usually forwards the data pointer of a fresh array from its Memory, so the Memory case covers it; the array case matters most on Julia 1.10, where the runtime initializes the field and every access reloads it.

Tests

  • readonlyorthrow_fresh_memory.ll: a function writing a fresh Memory (alone, or in a phi or select with the marked empty singleton) is marked LocalReadOnlyOrThrow; with an unmarked global in the phi, or writing through a pointer loaded from another field, it is not.
  • readonlyorthrow_fresh_array.ll: writing the data of a 1.11-style array pointed at a fresh Memory, or of a 1.10 jl_alloc_array_1d array (also through a select of two), is marked; not if the field holds other data, the array escapes, it is passed to jl_array_grow_end, or the pointer is loaded from another field.
  • Both fail without this change. Full lit suite passes locally on LLVM 15 and 16 (1097 passed, 10 expected failures).
  • Enzyme.jl main + Mark the global for the empty Memory singleton enzymejl_empty_memory Enzyme.jl#3761, with this branch's libEnzyme: full test suite passes on Julia 1.10 (179083 passed, 60 broken) and 1.11 (226479 passed, 59 broken).

Effect

  • Julia functions allocating an array with similar(x) or zeros(n) and filling it are now marked LocalReadOnlyOrThrow on both 1.10 and 1.11 (neither was before). Arrays grown with push!, or filled by a non-inlined callee, still are not.
  • DynamicPPL multivariate(1000) benchmark (benchmarks: show main and PR primal times in one table TuringLang/DynamicPPL.jl#1513) with stock Distributions on 1.11: Enzyme gradient ~3.5 µs → 2.32 µs (Mooncake 1.2 µs); gradients match Mooncake to ~1e-11. The remaining gap is mostly allocating the temporaries and their shadows, which Mooncake's hand-written sqmahal rule avoids.

🤖 Generated with Claude Code

https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

@wsmoses
wsmoses force-pushed the enzyme-fresh-memory branch from d025521 to 8932eb7 Compare October 5, 2026 14:25
Base automatically changed from enzyme-cache-followers to main October 5, 2026 15:27
A Julia function that builds a temporary array, such as `x .- μ`, writes it
through the Memory's data pointer, which is loaded from the Memory object.
The read-only-or-throw inference only accepted writes whose base object is
an allocation, so it did not mark such functions LocalReadOnlyOrThrow, and
callers had to treat calls to them as possibly overwriting anything.

The data field, which follows the length, of a Memory allocated by
jl_alloc_genericmemory is set on allocation and never changed, so its data
did not exist before the call either. For n == 0 Julia uses the empty Memory
singleton instead of allocating; no in-bounds access writes its data, and
Enzyme.jl marks its global enzymejl_empty_memory. Accept writes through a
pointer loaded from that field of such objects, or of phis and selects of
them, as local writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
@wsmoses
wsmoses force-pushed the enzyme-fresh-memory branch from 8932eb7 to 309759c Compare October 5, 2026 15:30
Writes through the data field, at offset 0, of a Julia array allocated in
the function also write memory that did not exist before the call, provided
the field only ever holds fresh data. On Julia 1.10, jl_alloc_array_* sets it
to data it allocates, and every array access reloads it from the array. From
Julia 1.11 on the array is allocated like any object and the function stores
the data of a fresh Memory into it.

Unlike a Memory's, the field can change, e.g. when the array grows. Accept it
only if every store to it in the function stores fresh data (or null), and
the array's address is not stored or passed to a call that may capture or
write through it, so no other code can change the field while the function
runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
@wsmoses wsmoses changed the title Treat writes to the data of a fresh Julia Memory as local Treat writes to the data of a fresh Julia Memory or array as local Oct 5, 2026
wsmoses and others added 2 commits October 5, 2026 11:13
Take the offset of the loaded data pointer from LLVM's
stripAndAccumulateConstantOffsets, and the objects it may point into from
getBaseObjects, rather than a custom stripping helper and recursion over
phis. Selects of fresh objects are no longer recognized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
A select picks one of its operands like a phi does, so return the base
objects of both. This lets a pointer loaded from a select of fresh Julia
Memory or array objects be recognized again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
@wsmoses
wsmoses merged commit b62f728 into main Oct 5, 2026
52 checks passed
@wsmoses
wsmoses deleted the enzyme-fresh-memory branch October 5, 2026 17:45
nsiccha pushed a commit to nsiccha/ReactiveKernels.jl that referenced this pull request Oct 6, 2026
Enzyme_jll 0.0.302, which Enzyme 0.13.211 requires, segfaults native
reverse gradients on Julia 1.10 when a differentiated function returns a
freshly allocated array, such as an index gather (EnzymeAD/Enzyme.jl#3776,
caused by EnzymeAD/Enzyme#3418 and fixed by the unreleased EnzymeAD/Enzyme#3445).
The RKPPL eight-schools gradient in the example-packages CI job and BRM
grouped-effect gradients crash this way; Enzyme 0.13.210 / Enzyme_jll 0.0.301
is correct.

Declare Enzyme_jll as a compat-only weak dependency of the root package with
`Enzyme_jll = "0.0.0 - 0.0.301, 0.0.303 - 0.0"`. Pkg applies a weak
dependency's compat whenever that package is in the environment, so every
environment and test sandbox that contains ReactiveKernels resolves the
previous binary today and admits the next one without another edit. No
extension loads Enzyme_jll and it stays out of [deps]. The package-boundary
test keeps the exclusion in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JkDGspUCofC5eCFRQnzce9
wsmoses added a commit that referenced this pull request Oct 10, 2026
…n flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
wsmoses added a commit that referenced this pull request Oct 11, 2026
…n flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
wsmoses added a commit that referenced this pull request Oct 11, 2026
…n flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
wsmoses added a commit that referenced this pull request Oct 11, 2026
…n flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
wsmoses added a commit that referenced this pull request Oct 11, 2026
…n flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR
wsmoses added a commit that referenced this pull request Oct 11, 2026
…n flow back (#3445)

* Make callers of local read-only-or-throw callees local when memory can flow back

A local read-only-or-throw callee may write memory it allocates and hand it
to its caller through its return value or an sret-like argument. The
inference only checked where the callee's sret-like arguments point, so a
caller that returned such memory was marked fully read-only-or-throw.
Activity analysis then treated a call to it returning a pointer as unable to
propagate derivatives, and the reverse pass passed `nothing` for the shadow
of its arguments.

Since #3418 a Julia 1.10 function filling a new array is local
read-only-or-throw, so a function returning `collect(::SVector)` was marked
fully read-only-or-throw, and the gradient of a closure calling it segfaulted
(EnzymeAD/Enzyme.jl#3776).

Make the caller local if the call's return value, or an sret-like argument,
can hold a pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Treat calls marked local read-only-or-throw by metadata like calls to such functions

A call carrying `enzyme_LocalReadOnlyOrThrow` metadata was skipped by the
read-only-or-throw inference, so its caller could be marked fully
read-only-or-throw although the call may hand it memory it wrote. Handle it
like a call to a local read-only-or-throw function, accounting for its sret-
like arguments and its result.

Also clarify the documentation of the two attributes: a fully
read-only-or-throw function never returns memory holding data it wrote,
while a local one may.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Decide whether a caller of a local callee is local by whether memory escapes

Rather than whether the call's result or sret type may hold a pointer,
treat memory a local read-only-or-throw callee hands back like an allocation
of ours that was written to: the caller is only local read-only-or-throw if
the call's result, or memory its sret-like arguments point to, may escape it,
directly or through a pointer loaded from it. A caller that only reads that
memory stays fully read-only-or-throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Make a function local only if memory it wrote may reach its return value

A function writing an object it allocated, or memory a local
read-only-or-throw callee handed it, was made local read-only-or-throw as
soon as that memory was captured at all. Only if the memory may reach the
function's return value does it outlive the call holding data the function
wrote. Escaping otherwise does not matter: storing it into memory existing
before the call is a write that disqualifies the function anyway, and storing
it into another allocation is checked when that allocation is written to.

Share one walk, mayReachReturn, for all of these. It follows pointer
arithmetic, phis, selects and aggregates, stores into allocas through what is
loaded or copied from them, and treats returning a pointer, or passing it to
a call that may capture and hand it back, as reaching the return value.

Also accept writes through any field of an object allocated uninitialized,
not only the data field of a Julia array, if the field only holds fresh data.
Julia's runtime allocators initialize their objects' other fields themselves,
so only their data field is accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Decide whether a value may hold a pointer from its uses and enzyme_type info

Integers can hold pointers (e.g. Julia's Ptr, or the result of ptrtoint), so
the LLVM type of a value written memory reaches says nothing about whether it
may return that memory. Follow the uses whatever their type, and only rule
out a pointer for void or token values, or when enzyme_type info (on a
call's result, the callee's return, an instruction's metadata, or the
function's own return) says every byte is an integer or a float.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Include SmallSet.h in FunctionUtils.cpp

Newer LLVM versions no longer pull it in through other headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Recheck callers of pending callees; keep calls that move active data active

When a function was first checked while some callees were not yet known to
be read only or throw, it was later marked using the result of that first
check, which could not tell whether a callee that turned out to be only
local made it local too (by returning memory the callee wrote), or ruled it
out (by having the callee write through an argument that is not ours). Check
such functions again once all their callees are known.

Activity analysis treated any read-only-or-throw call returning no float as
an inactive instruction. A read-only-or-throw function may still move active
data into memory of its own (e.g. copying an active argument into a
temporary), which makes the call active even though no derivative outlives
it: its reverse pass accumulates into the shadows of its arguments, so it
must be passed them rather than undef. Infer enzyme_NoDataWrite for
read-only-or-throw functions that write no data at all (allocating does not
count), and only skip the analysis for read-only-or-throw calls returning a
pointer if the callee writes no data or is an allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01En5yBUJEvaEnaaCAoSm5UR

* Keep read-only-or-throw calls inactive; pass differentiated calls their shadows

A fully read-only-or-throw function writes nothing that outlives the call
(allocating is not a write), so a call to it that returns no float is
inactive, as before. Drop the exception for initializing returned objects
from the documentation, and revert the activity-analysis change and the
enzyme_NoDataWrite inference that only fed it.

The crash it worked around was elsewhere: a constant-instruction call whose
result is active is still differentiated, but its reverse call was passed
undef for its arguments' shadows, while its augmented call got the real ones.
A callee whose reverse touches those shadows, for instance to propagate a
copy into a temporary of its own, then crashes, although what it adds is
zero. Pass the reverse call the same shadows as the augmented call.

For the gradient pass, differential-use analysis now also counts the shadow
of an argument to such a call as needed in the reverse pass whenever the
call's shadow result is used at all (asked of the primal pass, which decided
to differentiate the call), so the shadow is kept rather than erased.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Move the reverse-call shadow fix to its own PR

The fix for reverse calls of differentiated constant calls being passed
undef shadows is now #3468. Restore AdjointGenerator.h,
DifferentialUseAnalysis.h and the affected tests here, and drop
retptr_writes_local.ll, which #3468 replaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Do not treat floating-point values or arithmetic on them as possible pointers

Whether a value may hold a pointer to written memory was decided only by
void/token types and enzyme_type info, so a double loaded from memory a local
callee returned made its caller local when returned, and any arithmetic on it
(which fell through to the conservative end of the escape walk) did too.
Floating-point values and integers narrower than a pointer cannot hold one;
integers as wide as a pointer still can (ptrtoint, Julia's Ptr). The walk
now follows integer arithmetic on a possible pointer and ignores
instructions that neither write memory nor produce a value able to hold one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Follow a written pointer stored into memory of the function

When a pointer to written memory was stored into memory that is not an
alloca, the escape walk relied on that memory being checked "when it is
written to", but that check only asks whether the memory itself reaches the
return value, not whether a pointer loaded back out of it does. A function
boxing a written object in another allocation and returning what it loads
back from the box, directly or through a call returning a field, was marked
fully read-only-or-throw.

Follow such memory like an alloca: what is loaded from it, deeply, and any
object whose fresh data it is. Storing the pointer into an argument or a
global hands it to the caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Check every load of a written fresh field, including nested owners

A write to fresh data only checked whether the written pointer itself, or
the objects whose field it was loaded from, reach the return value. Two
gaps:

* Another load of the same field yields the same written data. Returning
  it (a Julia `pointer(arr)`) was missed.
* Fresh data found through a store of other fresh data into an object's
  field (e.g. a Memory's data pointer kept in another fresh object) did not
  record the objects at the inner level, so returning the Memory itself was
  missed.

Record each owning object with the offset of the field holding the fresh
data, at every level, and check the object, every load of that field, and
anything copying the field or handing back what a call loads from the
object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Only treat fields of allocators that leave them uninitialized as fresh

Any field of any allocation call was accepted as holding only fresh data if
every write to it in the function did. But isAllocationCall also covers
allocators that initialize fields themselves, e.g. swift_allocObject's
metadata pointer, custom enzyme_allocator ones, and allocators registered
with a shadow handler, whose fields may point to memory that existed before
the call. Writing through such a field was taken as writing fresh data.

Accept fields only of the C and C++ allocators and Julia's object
allocators, which leave them uninitialized (or zeroed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Read sret-like markings of the called function when walking through a call

mayHandBackPointer used hasSRetRRootsOrUnionSRet, which reads only call-site
attributes and only an sret on the first argument, while
enzymejl_returnRoots and enzymejl_sret_union_bytes usually sit on the
called function. Also check sret on any argument and those markings on the
callee.

No test fails before this: a callee writing a pointer into such an argument
is either local read-only-or-throw, and the local-callee branch already
reads the callee's markings and follows the argument, or it disqualifies
the caller. This keeps the escape walk consistent with that branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Cache escape queries per object and skip them while a callee is pending

Each write to the same object reran the full escape walk (and the fresh
data check), and a function with a callee not yet known to be read only or
throw ran all of them although the result is discarded and the function is
checked again once its callees are known.

Cache isFreshData, mayReachReturn and the per-field checks per object
within one check of a function, and skip the escape queries, which only
decide whether the function is local, once a callee is pending. Whether a
write is allowed at all is still decided.

No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Do not count julia.gc_loaded rooting a fresh object as handing back its field

The check that a written fresh field cannot reach the return value treated
any call receiving the owning object and returning a pointer as possibly
handing back what it loads from it. julia.gc_loaded(obj, ptr), which Julia
1.11+ emits around every access to Memory data, takes obj only to keep it
alive and returns ptr; a load of the field passed as ptr is checked as a
load. Counting it made every function writing fresh Memory data local, e.g.
bc1_affine_normalize in Enzyme.jl's test/advanced.jl, which writes a
temporary it does not return and so is fully read-only-or-throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Spell out the field overlap check so clang-format 16 and 18 agree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Skip the escape queries for a function that cannot hand back a pointer

A function whose return value cannot hold a pointer, by its type or
enzyme_type, and that has no sret-like argument cannot hand memory it wrote
to its caller other than by a write that rules it out anyway. Decide that
once, rather than walking every written object to its return.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Make the helpers of the read-only-or-throw check members

The static helpers only the check uses become members of
ReadOnlyOrThrowDetector: those that took a TargetLibraryInfo use the
class's, the pure type and value predicates are static members, and the
type aliases they share move into the class. The lambdas caching escape
queries become member functions with their caches as members.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

* Format cannotHandBackPointer with clang-format 16

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant