Skip to content

Vec.set_i32/set_i64 intrinsics bypass the receiver-mutability check that push and v[i] = x enforce #1007

Closed

Description

@ehartford

Found 2026-09-03 while rewriting MirLower.w's legacy self.field.set_i32(i as i64, v) calls to self.field[i] = v (the least-ceremony rule). The rewrite produced 14 cannot assign through a read-only place (§15.10) errors, and fixing them honestly cascaded into 20 methods that had to become mut fn: clear_local_value_moved, cancel_scheduled_value_drop_for_local, remove_moved_field_entry, cancel_stmt_temp_for_local, remember_regex_pattern_captures, set_string_local_flags, set_string_field_path_flags, set_string_field_flags, mark_string_base_fields_may_alias, forget_string_flow_facts, clear_moved_fields_for_local, clear_moved_fields_for_place, set_string_local_may_alias, set_string_place_flags, transfer_string_field_facts_between_bases, update_string_aggregate_alias_after_assignment, mark_string_local_copied, set_string_place_may_alias, update_string_alias_after_assignment, mark_string_place_copied.

Every one of them was declared with a read-only fn receiver and mutated self through set_i32. The same body with push is rejected (method 'Vec.push' requires a mutable receiver), and with v[i] = x it is rejected (§15.10). So the intrinsic is a hole in the receiver contract: "the signature states parameter ownership mode — load-bearing" (CLAUDE.md, spec §3.8) is false for any fn that calls set_i32/set_i64.

Repro

type T { xs: Vec[i32] }
impl T:
    fn poke(): self.xs.set_i32(0, 7)      // accepted today
    fn poke2(): self.xs[0] = 7             // rejected (§15.10)
    fn poke3(): self.xs.push(7)            // rejected (mutable receiver)

Expected

set_i32/set_i64 obey the same receiver rule as element assignment (Sema.w syms.set_i32, SemaCheck.w:14284 groups it with push/clear but the read-only-receiver rejection does not fire). Better: retire the set_* intrinsics in favor of v[i] = x now that element assignment exists — 177 call sites in src/ and 2 in tools/, all rewritable mechanically (the uncast.w script from this batch already does .set_i32(E as i64, V) → [E] = V). The 20 MirLower methods are already mut fn on main after this batch.

Activity

  1. ehartford commented on Sep 4, 2026

    @ehartford
    ContributorAuthor

    Fixed on main: b9e0e65 — the compiler-modeled Vec.set_i32 intrinsic is retired from Sema/MirLower/CodegenDispatch/CCodegen (every use across src/, lib/std incl. subdirectories, rt, tools is element assignment), so the receiver contract is enforced by v[i] = x's own rule; the 73 read-only methods that mutated through the seam are mut fn since 2bb9a3f. Pin: test/compile_errors/err_read_receiver_element_assign.w. Battery green, reseeded at afab485.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions