Skip to content

The fix for the field deref, and the bug no origin can see - #4

Merged
winding-lines merged 1 commit into
mainfrom
owned-and-race
Sep 3, 2026
Merged

winding-lines merged 1 commit into
mainfrom
owned-and-race

Conversation

@winding-lines

Copy link
Copy Markdown
Contributor

Independent of the threads.mojo typed parallel_for PR; this one builds against 0.2.2 as before.

The fix, demonstrated

tests/uncaught/field_deref_after_last_use.mojo now runs the same shape twice. The raw Pointer[Int64, MutUntrackedOrigin] field still reads -1 after the struct is destroyed; the cell behind an OwnedPointer[Int64] reads 499500, because OwnedPointer.__getitem__ returns a ref that borrows the pointer, which borrows the struct. Verified, not argued: the harness checks the five lines in order, with Owned dropped last.

The race

tests/uncaught/plain_store_races.mojo: a task doing seen = t[].sum; …; t[].sum = seen + i. Compiles clean, loses updates every run. It is not a lifetime bug — the origin says only how long totals lives — and it is the case a Sync-style trait would catch; Mojo has none, so it goes in the uncaught set. The load–store window is widened to ~20 µs and run gets a num_workers passthrough pinned at 4, so the outcome does not depend on the runner's core count (10/10 locally).

README: the tables gain the rows, and a closing paragraph sorts the four uncaught cases into three lifetime bugs with fixes that exist today, and one that needs a trait that does not.

pixi run check: 8 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015or6oTZmb7EQTXTbALbBXY

field_deref_after_last_use now runs the same shape twice: once with the
raw untracked pointer field (-1, as before) and once with the cell behind
an OwnedPointer, whose deref borrows the owner, so the struct stays alive
through the read and prints 499500 with the drop last. The fix is a
type, not a compiler change.

plain_store_races is a new uncaught case of a different kind: a task
that writes `sum` with a plain load and store. Every task holds mutable
access to the same value and the origin only says how long it lives; a
Sync-style trait is what would reject this, and Mojo has none. The
load-store window is widened and the worker count fixed at 4 so the
lost updates are certain rather than likely — ten runs, ten times True.

`run` gains a num_workers passthrough for that. 8 passed, 0 failed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015or6oTZmb7EQTXTbALbBXY
@winding-lines
winding-lines merged commit 1d7d304 into main Sep 3, 2026
2 checks passed
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