Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions docs/src/safety/compile-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ in expression starting at myfile.jl:1

### Incidental Tail Patterns

Beyond the direct-return patterns above, three additional tail shapes are
Beyond the direct-return patterns above, four additional tail shapes are
checked — they don't *look* like a `return`, but the scope's last expression
still evaluates to a pool-backed array, which then escapes as the scope's
value:
value (also when wrapped in `identity(...)`):

```julia
@with_pool pool begin
Expand All @@ -87,6 +87,10 @@ end
v = acquire!(pool, Float64, 100)
y = v # ← assignment tail
end

@with_pool pool begin
(acquire!(pool, Float64, 100), 1) # ← literal holding a direct acquire call
end
```

Fix: end the block with `nothing` if the value is meant to be discarded —
Expand Down Expand Up @@ -145,3 +149,26 @@ end
```

That's what the [runtime layer](runtime.md) is for.

Loops and comprehensions bind *elements*, not the iterable. Reading an element of
a pool-backed array is a plain value, so this is silent and correct:

```julia
@with_pool pool begin
order = acquire!(pool, Int, n)
contact = 0
for k in order # `k` is an element (e.g. an Int), not pool memory
k == target && (contact = k)
end
(; contact) # fine — no warning, no guard
end
```

Iterating a container *literal* of pool arrays (`for c in (v, w)`) is tracked:
`c` is a pool-backed array inside the loop. Iterating a container held in a
*variable* (`t = (v, w); for c in t`) and destructuring iteration
(`for (a, b) in ...`) are not tracked at compile time. With the default
`runtime_check = 0`, nothing guards those shapes. With `runtime_check = 1`, the
[runtime layer](runtime.md) inspects the scope's return value at exit and throws
`PoolRuntimeEscapeError` if it still references pool memory — including through
a `Tuple` or `NamedTuple` — on every supported Julia version.
8 changes: 4 additions & 4 deletions ext/AdaptiveArrayPoolsCUDAExt/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ end
)
calls = [
:(
_check_tp_cuda_overlap(
getfield(pool, $(QuoteNode(f))), arr_ptr, arr_end,
current_depth, pool, return_site, original_val
)
_check_tp_cuda_overlap(
getfield(pool, $(QuoteNode(f))), arr_ptr, arr_end,
current_depth, pool, return_site, original_val
)
)
for f in GPU_FIXED_SLOT_FIELDS
]
return quote
Expand Down
8 changes: 4 additions & 4 deletions ext/AdaptiveArrayPoolsMetalExt/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ end
)
calls = [
:(
_check_tp_metal_overlap(
getfield(pool, $(QuoteNode(f))), arr_buf, arr_off, arr_end,
current_depth, pool, return_site, original_val
)
_check_tp_metal_overlap(
getfield(pool, $(QuoteNode(f))), arr_buf, arr_off, arr_end,
current_depth, pool, return_site, original_val
)
)
for f in METAL_FIXED_SLOT_FIELDS
]
return quote
Expand Down
8 changes: 4 additions & 4 deletions src/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ end
)
calls = [
:(
_check_tp_pointer_overlap(
getfield(pool, $(QuoteNode(f))), arr_ptr, arr_end,
current_depth, pool, return_site, original_val
)
_check_tp_pointer_overlap(
getfield(pool, $(QuoteNode(f))), arr_ptr, arr_end,
current_depth, pool, return_site, original_val
)
)
for f in FIXED_SLOT_FIELDS
]
return quote
Expand Down
Loading
Loading