Skip to content

Add two-phase borrow support #56

Description

@itsfuad

Goal

Support reserved-then-activated mutable call borrows without weakening reference-origin or exclusive &mut guarantees.

Semantics

  • Every mutable reference call argument reserves during left-to-right evaluation: explicit &mut, implicit reborrow, mutable receiver, optional mutable reference, and indirect callable.
  • Reads and shared borrows may overlap a reservation only when they end before activation.
  • Mutation, move, free, overwrite, destruction, and nested mutable activation conflict with reserved storage.
  • Activation occurs immediately before entering the callee and requires exclusive access.
  • Both(&mut value, Read(&value)) is valid when Read returns an owned/copied value.
  • Both(&mut value, &value) remains invalid because the shared reference enters the same call.
  • Unequal concrete fields/fixed indexes may reserve independently; dynamic indexes and views remain conservative.

Architecture

  • Keep reservation facts expression-local in existing ownership loanContext.
  • Keep persistent NLL on existing ownership CFG.
  • Keep origin overlap canonical in internal/semantics/place.
  • Preserve ReturnOriginSources and reference-return composition.
  • No syntax, ABI, HIR, MIR, backend, runtime loan state, or second CFG changes.

Validation

Passed on 2026-07-19 under 2 GiB process cap:

  • Focused two-phase ownership tests, 20 repeated runs.
  • Full go test -p 1 ./....
  • Full go test -race -p 1 ./....
  • Full go vet ./....
  • Compiler bundle.
  • Positive x_test/runtime_borrow_conflicts runtime fixture.
  • Negative x_test/negative_borrow_conflict fixture with exactly seven intended T0037 errors and no unrelated diagnostics.
  • gofmt -l, git diff --check, and executable-artifact scan clean.

Follow-up to #43.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlanguage-modelPeeper language model, ownership, pointer, optional, array/slice workownershipOwnership, move, copy, pointer-safety work

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions