Repository navigation
MIR: an owned temporary in an f-string hole is a statement temp, dropped once the string is built (#1390) - #1549
Merged
Merged
Conversation
…ped once the string is built (#1390) Formatting observes its interpolant. lower_fstring turned every OK_MOVE interpolant into a copy (#1394's guard for `move u.name`), which is right for a place an owner holds and wrong for a call or operator result: the temporary then had no owner and nothing dropped it. Route: leak. Evidence on origin/main ba2d5d1's stage1: - `run --debug-alloc` of the issue repro: `LEAK size=16`, leak count=1. - WITH_DEBUG_ALLOC_TRAP_FREE on the block under lldb: one trap-alloc hit, no free; the dbg_trap_alloc_check backtrace is alloc_str <- check at i1390.w:2:25, the `t.slice(0, 2)` call. - MIR of `check`: `call slice(...) -> _3`, `fmt_buf_write_str(copy _2, copy _3)`, and no drop of _3 anywhere in the body. Exact line: MirLower.lower_fstring, the `OK_MOVE -> OK_COPY` rewrite after `lower_expr(expr_node)`. The spec'd/debug view path had the same hole: the str_clone_ref it makes for a `&str` hole was an unregistered OK_MOVE the observing writer never consumed. Fix: observe_interpolant reads a place in place (the #1394 case) and materializes an owned compiler temporary (operand_moves_owned_temp: a plain non-user, non-global local) into a registered statement temp; both hole paths go through it. Matrix (18 hole shapes, `check(&s, c)` called twice; leak count base -> fixed, stdout identical): slice 2->0, spec 2->0, :? 2->0, `++` 2->0, two holes 4->0, to_upper 2->0, `f"{..}" ++` 2->0, spec'd &str view 2->0, :? &str view 2->0; unchanged 0: print(temp), .len() receiver, int hole, if-join hole, field of temp, bound local, element, named local with spec, `move x`, clone in a join arm. Fixture: test/debug_alloc/da_fstring_owned_temp_interpolant.w (base: leak count=20; fixed: 0). The drop audit had no f-string cell: tools/drop_audit.w gains fstring_hole_temp_{field,method,concat,slice,spec} (concat/slice/spec LEAK on the base, PASS fixed). --validate-all said ok over the leaking body; that validator has no leak check (filed separately).
ehartford
force-pushed
the
fix-1390-fstring-temp-leak
branch
from
September 23, 2026 21:39
dbf4eb8 to
7d9d90c
Compare
ehartford
marked this pull request as ready for review
September 23, 2026 22:32
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.
Draft: layer 1 of 7 in the ownership/leaks stack (batch battery pending; iterate tier +
:drop-audit/:move-auditon the layer's stage1 done locally). Closes #1390.Audits (tools/drop_audit.w + tools/move_audit.w, candidate = this layer's stage1, baseline = the pinned seed): drop-audit 190 cells, 0 regressions (the 3 new f-string cells FIXED vs seed); move-audit 0 failures on this layer's cells.
MIR: an owned temporary in an f-string hole is a statement temp, dropped once the string is built (#1390)
Formatting observes its interpolant. lower_fstring turned every OK_MOVE
interpolant into a copy (#1394's guard for
move u.name), which is rightfor a place an owner holds and wrong for a call or operator result: the
temporary then had no owner and nothing dropped it.
Route: leak. Evidence on origin/main ba2d5d1's stage1:
run --debug-allocof the issue repro:LEAK size=16, leak count=1.no free; the dbg_trap_alloc_check backtrace is alloc_str <- check at
i1390.w:2:25, the
t.slice(0, 2)call.check:call slice(...) -> _3,fmt_buf_write_str(copy _2, copy _3), and no drop of _3 anywhere in the body.Exact line: MirLower.lower_fstring, the
OK_MOVE -> OK_COPYrewrite afterlower_expr(expr_node). The spec'd/debug view path had the same hole: thestr_clone_ref it makes for a
&strhole was an unregistered OK_MOVE theobserving writer never consumed.
Fix: observe_interpolant reads a place in place (the #1394 case) and
materializes an owned compiler temporary (operand_moves_owned_temp: a
plain non-user, non-global local) into a registered statement temp; both
hole paths go through it.
Matrix (18 hole shapes,
check(&s, c)called twice; leak countbase -> fixed, stdout identical): slice 2->0, spec 2->0, :? 2->0,
++2->0, two holes 4->0, to_upper 2->0,
f"{..}" ++2->0, spec'd &str view2->0, :? &str view 2->0; unchanged 0: print(temp), .len() receiver, int
hole, if-join hole, field of temp, bound local, element, named local with
spec,
move x, clone in a join arm.Fixture: test/debug_alloc/da_fstring_owned_temp_interpolant.w (base: leak
count=20; fixed: 0).
The drop audit had no f-string cell: tools/drop_audit.w gains
fstring_hole_temp_{field,method,concat,slice,spec} (concat/slice/spec
LEAK on the base, PASS fixed). --validate-all said ok over the leaking
body; that validator has no leak check (filed separately).