Error on @trace if assignments to untraced mutable struct fields - #3271
Merged
Pangoraw merged 1 commit intoSep 14, 2026
Merged
Conversation
An untraced location in a captured mutable argument has nothing an if result can be written back into, so a branch assigning to it was silently dropped. Detect the discarded assignment during if_condition lowering and error, pointing at promote_to_traced. Applies to plain numbers and enums alike. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI Agent-Model: SWE-2 High Agent-Session: local CLI session (no shareable URL)
jumerckx
approved these changes
Sep 14, 2026
jumerckx
left a comment
Collaborator
There was a problem hiding this comment.
This looks correct to me, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
Split out of #3232 (comment), where this change was flagged as independent of the enum tracing work.
When a
@trace ifbranch assigns a new value to a field of a captured mutable struct whose slot is untraced (e.g. a plainIntorFloat64field), theifresult has no location to be written back into. Previously the assignment was silently discarded;if_conditionnow checks such:resargpaths and raises an error explaining that the field must be traced before theif, e.g. viaReactantCore.promote_to_traced.Caveat: the check only inspects collected result paths, so it is not a general detector of unsupported mutations — a leaf the tracing machinery never tracks produces no path and remains undetectable (this is noted in a comment on
check_untraced_branch_state).The tutorial's conditional-control-flow section now documents the requirement on mutable struct fields.
Test plan
core/control_flowpasses locally (Linux CPU, PJRT): 150/150, including the new "if: assignment to an untraced struct field" testset which asserts the error fires for plainIntandFloat64fields and that an untouched untraced field still works."untraced location"with this change and silently dropped the assignment without it.🤖 Generated with Devin (harness: Devin CLI, model: SWE-2 High) — local CLI session, no shareable URL.