From 4349d4a66f218308a05858bc7fcdd61fbf416ff4 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 20 Aug 2026 08:18:15 +0900 Subject: [PATCH] compiler-core: implement DerefMut and IndexMut for Constants `Constants` exposed `Deref` and `Index` but neither mutable counterpart, so an owner of a `CodeObject` could read a constant but not replace one in place and had to rebuild the whole boxed slice. `[T]` already carries both halves of the `VarNum` pair in this file. Assisted-by: Claude --- crates/compiler-core/src/bytecode.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index ba1639170a7..0272270526b 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -11,7 +11,7 @@ use bitflags::bitflags; use core::{ cell::UnsafeCell, hash, mem, - ops::{Deref, Index, IndexMut}, + ops::{Deref, DerefMut, Index, IndexMut}, sync::atomic::{AtomicU8, AtomicU16, AtomicUsize, Ordering}, }; use itertools::Itertools; @@ -383,6 +383,12 @@ impl Deref for Constants { } } +impl DerefMut for Constants { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + impl Index for Constants { type Output = C; @@ -391,6 +397,12 @@ impl Index for Constants { } } +impl IndexMut for Constants { + fn index_mut(&mut self, consti: oparg::ConstIdx) -> &mut Self::Output { + &mut self.0[consti.as_usize()] + } +} + impl FromIterator for Constants { fn from_iter>(iter: T) -> Self { Self(iter.into_iter().collect())