Skip to content

fix(ownership): make consume perform a runtime move-out - #384

Draft
dporkka wants to merge 1 commit into
mainfrom
fix/consume-runtime-move
Draft

dporkka wants to merge 1 commit into
mainfrom
fix/consume-runtime-move

Conversation

@dporkka

@dporkka dporkka commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Makes consume x match its language-level ownership semantics at runtime.

Previously consume x was enforced only by the capability analyzer. HIR lowering treated it exactly like a normal read, leaving the source register live.

Now variable consumption lowers to:

  1. copy the source value into a fresh result temporary
  2. overwrite the source binding with nil without dropping it
  3. yield the moved temporary

Because register copies do not retain, this transfers the source's ownership slot rather than creating a second counted reference.

Non-binding expressions continue to evaluate normally because there is no reusable source slot to invalidate.

Why this precedes sink inference

Nim-style inferred sink/last-use transfer needs a sound explicit move primitive to target. Inferring transfer while consume itself is runtime-copy-only would make the ownership model internally inconsistent.

Tests

Adds a HIR regression test asserting that the move-result copy is emitted before the source is cleared to nil.

Follow-up

The current Drop planner remains deliberately conservative around raw copies, so a moved heap value can live longer than necessary. A follow-up ownership-flow pass can recognize transfer edges and recover eager reclamation without weakening the existing safety proof.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026

Copy link
Copy Markdown

Deploying nulang-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: af6239e
Status: ✅  Deploy successful!
Preview URL: https://1537f262.nulang-docs.pages.dev
Branch Preview URL: https://fix-consume-runtime-move.nulang-docs.pages.dev

View logs

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