fix: preserve plain reference rebinding during read-only calls

This commit is contained in:
2026-10-21 14:30:06 +08:00
parent ff49f266a2
commit 4a2f81cb48
9 changed files with 51 additions and 2 deletions
+15
View File
@@ -28,6 +28,9 @@ impl EndorStringObject {
}
impl ObjectPayload for EndorStringObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -87,6 +90,9 @@ impl EndorDictObject {
}
impl ObjectPayload for EndorDictObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -126,6 +132,9 @@ impl EndorCellObject {
}
impl ObjectPayload for EndorCellObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -199,6 +208,9 @@ impl EndorFunctionObject {
}
impl ObjectPayload for EndorFunctionObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -302,6 +314,9 @@ impl EndorBaseExceptionObject {
}
impl ObjectPayload for EndorBaseExceptionObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
+3
View File
@@ -174,6 +174,9 @@ impl EndorCodeObject {
}
impl ObjectPayload for EndorCodeObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
+3
View File
@@ -203,6 +203,9 @@ impl ContextNativeFunction {
}
impl ObjectPayload for ContextNativeFunction {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
+3
View File
@@ -276,6 +276,9 @@ impl EndorNumberObject {
}
impl ObjectPayload for EndorNumberObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
+13
View File
@@ -120,6 +120,13 @@ pub trait ObjectPayload: Any + fmt::Debug + Send + Sync {
/// object identity after replacing its host-owned target. Ordinary payloads
/// return false and retain normal value assignment. Implementations must
/// validate before mutation and must not add untraced managed-object edges.
/// True only when legacy assign_from always returns false. Read-only
/// callers can then rebind a local reference without attempting mutation.
/// assignment_cell is checked first and remains a protected write protocol.
fn reference_assignment_only(&self) -> bool {
false
}
fn assign_from(&self, _source: &dyn ObjectPayload) -> Result<bool, VmError> {
Ok(false)
}
@@ -141,6 +148,9 @@ pub trait ObjectPayload: Any + fmt::Debug + Send + Sync {
pub struct Record;
impl ObjectPayload for Record {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -180,6 +190,9 @@ impl EndorNativeFunctionObject {
pub type NativeFunction = EndorNativeFunctionObject;
impl ObjectPayload for EndorNativeFunctionObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
+6 -1
View File
@@ -72,13 +72,14 @@ impl ObjectStore {
}
pub fn assign_from(&mut self, target: ObjectRef, source: ObjectRef) -> Result<bool, VmError> {
self.heap.prepare_change(target)?;
self.object(target)?;
self.object(source)?;
if let Some(cell) = self
.object(target)?
.payload()
.assignment_cell(source, self)?
{
self.heap.prepare_change(target)?;
// Replacing the Cell edge may otherwise reclaim a target which is
// reachable only through the edge being removed.
self.retain(target)?;
@@ -89,6 +90,10 @@ impl ObjectStore {
self.release(target)?;
return result.map(|()| true);
}
if self.is_read_only() && self.object(target)?.payload().reference_assignment_only() {
return Ok(false);
}
self.heap.prepare_change(target)?;
let changed = self
.object(target)?
.payload()
+6
View File
@@ -50,6 +50,9 @@ impl EndorTypeObject {
}
impl ObjectPayload for EndorTypeObject {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
@@ -462,6 +465,9 @@ struct BoundMethod {
function: ObjectRef,
}
impl ObjectPayload for BoundMethod {
fn reference_assignment_only(&self) -> bool {
true
}
fn as_any(&self) -> &dyn std::any::Any {
self
}