Skip to content

#3026 (D111): an unannotated let of a str place takes the str; a str global reads as a value - #3028

Merged
ehartford merged 3 commits into
mainfrom
d111-str-place-let
Nov 3, 2026
Merged

ehartford merged 3 commits into
mainfrom
d111-str-place-let

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #3026.

A str is a value (D111), so the binding of a str place is a count increment, never a view of the place. Three refusals said otherwise:

  • let old = self.name then self.name = to: "cannot mutate self while old is a live view into it", with the help text being the : str annotation the census counts as ceremony (str-view-copy-annotation, D179). field_let_binds_as_view answered true for a str field (only plain bits took the value), and MIR alias-bound the binding.
  • let name = record.name then a consume of record: "view name may outlive its origin".
  • fn label() -> str: g_label: "cannot move out of global g_label … clone it".

Now the str field let takes the str (the annotated form's copy path: copy _1.name in MIR, as before for let old: str = self.name), and reject_move_out_of_global and the tail-read rule exempt str. Sema only; MIR and codegen unchanged.

Found by the #2942 sweep (#3027), whose seven kept .clone() are exactly these shapes; they are re-swept once this lands.

Fixture behav_3026_str_place_let_takes_the_str (a rename through self, a global read as a value, a record consumed after its field was read): fails on the installed compiler with both old errors, passes on the stage1, --debug-alloc leak count 0. Str/view-origin regression set and gate reported below. Draft until the battery is green.

@ehartford

Copy link
Copy Markdown
Contributor Author

Second commit (8639268): the Sema-only change left MIR aliasing any field let on syntax (lower_let_binding → lower_binding_alias_place), so let p = x.inner.s; x.inner = …; print(p) printed the replacement; MIR now aliases a field access only when Sema recorded the let as view-bound (D65). Seven old refusal fixtures pinned the live-view rule on a str field: three are now behavior fixtures printing the saved value, four keep their rule on a List[i32] field, plus err_3026_list_field_let_stays_a_view. The five #3026 fixtures pass on the stage1 (debug-alloc clean); the str/view-origin regression set (440 files) is re-running on it, then the gate and :drop-audit.

Eric Hartford added 2 commits November 3, 2026 14:21
…a str global reads as a value

A str is a value (D111): the binding of a str field, of a local
record's str field, or of a global is a count increment, never a view
of the place. `field_let_binds_as_view` answered true for a str field
(only plain bits took the value), so MIR alias-bound the binding, a
later write of the owner was refused ("cannot mutate `self` while
`old` is a live view into it"), a consume of the record was refused
("view may outlive its origin"), and the diagnostic's own help was the
`: str` annotation the census counts as ceremony. A str global read in
value position was refused as a move ("cannot move out of global …
clone it"). Now the str field let takes the str (the annotated form's
copy path, `copy _1.name` in MIR) and `reject_move_out_of_global` and
the tail-read rule exempt str.

Found by the #2942 sweep, whose seven kept `.clone()` are these shapes.
Fixture: behav_3026_str_place_let_takes_the_str (a rename through
self, a global read as a value, a record consumed after its field was
read); debug-alloc clean.
…w pins keep a non-str field

Sema decides whether a field let is a view of its place or takes the
value (view_bound_let_nodes); MirLower.lower_let_binding aliased any
field access on syntax alone (D65), so `let p = x.inner.s; x.inner =
…; print(p)` printed the replacement after Sema had made the binding a
value. A field access is now aliased only when Sema recorded the let
as view-bound.

Seven refusal fixtures pinned the live-view rule on a str field, whose
binding now takes the str: three become behavior fixtures printing the
saved value (behav_3026_assign_str_field_under_saved_value,
behav_3026_concat_str_field_after_saved_value,
behav_3026_assign_parent_after_saved_str_field); four keep their rule
on a List[i32] field (err_loop_write_under_view_used_after_loop,
err_loop_write_under_view_used_next_iteration,
err_move_field_under_live_view, err_move_whole_under_live_field_view),
and err_3026_list_field_let_stays_a_view pins the List case beside
the str case.
@ehartford
ehartford marked this pull request as ready for review November 3, 2026 19:49
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on ffa08ba (seed-driven gate, uat, battery-checks; out/battery/battery.log rc=0 green); drop-audit green; the first battery was red on ten #1819/#1827 global-view fixtures that pinned their rule on a str field — rewritten with a List[i32] field (same conversion as the seven), and all 305 live-view/outlive refusal fixtures pass.

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.

D111: an unannotated let of a str field, and a str global read, still need .clone() (seven sites the #2942 sweep could not remove)

1 participant