Skip to content

Implement D12: mut fn on str/fat-pointer owners lowers via share-place (IndirectPlace) #678

Closed

Description

@ehartford

Ruling: D12 (Option A canonized)

mut fn mutates the caller's place on every owner type. This issue implements the str / fat-pointer shape, the delicate sibling of #677 (scalar primitives): a mut fn on a str owner (or a distinct-over-str) lowers via D5 share-place (PassMode::IndirectPlace) over the {ptr, len} fat pointer, so reassigning self rewrites the caller's binding.

extend str:
    mut fn trim_first(): self = self.slice(1, self.len())

var s = "abc"
s.trim_first()   // s == "bc"

Why separate from the scalar case (#677)

str is a fat pointer ({ptr: *const u8, len}), currently PassMode::Fat. IndirectPlace for str = a pointer to the 16-byte fat struct (str*), and the callee writes both fields — a distinct ABI shape from a scalar i32*, with its own drop/lifetime cell (view-origin tracking, §22 ephemeral rules: reassigning self to a sub-slice must not outlive the source). It has its own root-cause line too: src/SemaDecl.w:1089 excludes str owners explicitly (separate from the aggregate gate at ~1093 that #677 addresses).

Approach

  • Remove the blanket str exclusion in fn_param_uses_value_ref_abi for non-move self; classify mut self: str as share-place over the fat pointer.
  • Verify the Fat ↔ IndirectPlace interaction in compute_fn_abi/PassMode (D6) — the receiver is a pointer-to-fat, and the callee prologue must load/store both fields. Confirm via --dump-abi.
  • Enforce view-origin / ephemeral rules on self = <sub-slice-of-self>: the reassigned view must be provably within the caller's original allocation (no escape of a shorter-lived slice).

Acceptance

  • mut fn on str reassigning self to a sub-slice mutates the caller's var; let receiver rejected cleanly.
  • --dump-abi shows SHARE-PLACE for mut self: str.
  • Ephemeral/view-origin: a mut fn that tries to set self to a view outliving the source is rejected (§22).
  • /drop-audit clean for the fat-pointer share-place receiver cells.
  • Behavior + spec fixtures.
  • Full battery.

Refs

Decision D12 · Spec §9.5, §22 (ephemeral) · D5/D6/D7 · umbrella #644 · scalar shape: #677 (land first — lower risk).

Activity

  1. added
    high-priority
    on Jul 17, 2026
  2. ehartford commented on Jul 19, 2026

    @ehartford
    ContributorAuthor

    IMPLEMENTED (e823026, battery-green incl. the allocator lane, reseeded ge823026b0 + asset). Every acceptance item: mut-self str receivers classify SHARE-PLACE over the {ptr,len} fat pointer (--dump-abi verified); 'self = self ++ x' and 'self = self.slice(...)' rewrite the caller's binding — both fields travel (len-change pinned); by-value str params still copy; let receiver gets the clean 'cannot mutate immutable binding' error. Read/plain self on str deliberately stays by-value (a read borrow of a Copy fat pointer is observationally a copy; str reads are the hottest stdlib path). Drop cells are nil (str is Copy, no destructor); the §22 reject-shorter-lived-view cell is VACUOUS under the provisional A5/#608 str backing (heap, never freed — dangling is unconstructible today); real enforcement lands with #691's ownership migration, noted in that campaign. Also closes the silent-no-op window e101e7e opened (str bare-self compiled but mutations vanished — now they land).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    high-priority

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions