(fix): Scope-aware runtime escape detection#36
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Runtime escape detection (
RUNTIME_CHECK=1) iterated all pool vectors whenchecking for escaping arrays. This caused false-positive
PoolRuntimeEscapeErrorfor arrays acquired in an outer
@with_poolscope and used inside a nestedinner scope — a valid and common pattern.
Additionally, the direct-rewind
@with_poolmacro validated before cleaningup leaked inner scopes, causing
_scope_boundaryto use an incorrect (leaked)depth when an inner scope threw without rewind.
Solution
1.
_scope_boundary— scope-aware overlap checkNew
@inlinefunction that uses the existing checkpoint stack to compute theboundary index: vectors at
1:boundarybelong to outer scopes and are skipped.Applied to all three backends:
_check_pointer_overlap,_check_bitchunks_overlap_check_tp_cuda_overlap_check_tp_metal_overlap2. Macro reorder — leaked scope cleanup before validation
In the direct-rewind
@with_poolexpansion (both block-form and function-form),leaked inner scope cleanup now runs before
_validate_pool_return:This ensures
_scope_boundaryalways sees the correct_current_depth.3. Robust poison for custom isbits types
_poison_fill!now handles custom isbits structs via duck-type zero(
0 * first(v)) whenzero(T)is not defined, and skips poisoning entirelyfor non-isbits reference types (where
resize!(v, 0)handles invalidation).