From d19fab55b9d3f2f55d824467a174cf06129c249f Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Wed, 21 Oct 2026 14:32:21 +0800 Subject: [PATCH] fix: allow plain local reference rebinding in source paint --- README.md | 2 +- src/block.rs | 6 ++++++ src/endor_host.rs | 22 ++++++++++++++++++++++ src/event_dispatch.rs | 9 +++++++++ src/mount.rs | 3 +++ src/object_list.rs | 3 +++ vendor/aster | 2 +- 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f51d0c..ca78e7f 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ Native measurement finds intrinsic subtree size and clamps the returned size to A source subclass can override `paint(self, mount, geometry): DisplayList`. The renderer invokes that method for each occurrence, after Mount synchronization and hooks, using current logical Bounds. Its commands replace that occurrence's native paint in preorder. Calling `RectBlock.paint(self, mount, geometry)` or another native base method obtains a fresh result that can be modified before returning. `DisplayList(ObjectList(command, ...))` builds multiple commands; ObjectList accepts objects and has a 10000-member bound. PaintCommand fields use kind (`roundedRect`, `strokeRoundedRect` or `text`), x/y/color and the corresponding width/height/radius, strokeWidth, or text/size fields. Commands must pass the same native validation and a total 10000-command frame limit. See [source-paint.endor](examples/source-paint.endor), including a Button source method that updates the same tint field used by two occurrences. -Paint runs in a read-only Aster call: existing heap objects cannot be modified; fresh result graphs may be allocated and filled. Existing globals, model fields, containers, Mounts and types remain protected. invalidate is rejected in this phase. All overrides share one VM budget. Read dependencies are currently recorded per object, with versions used to detect changes without depending on bounded change-notification delivery. Native frames keep their existing dependency/cache behavior. Derived allocations do not produce application change notifications, preventing temporary results from causing redraw feedback. This protects managed heap writes; trusted Rust host implementations must also respect read-only calls for external state and I/O. Paint errors stop the affected runtime before publication; failed PUT candidates preserve the previously running heap and frame. +Renderer-dispatched paint runs in a read-only Aster call: existing heap objects cannot be modified; fresh result graphs may be allocated and filled. Existing globals, model fields, containers, Mounts and types remain protected. invalidate is rejected in this phase. All overrides share one VM budget. Read dependencies are currently recorded per object, with versions used to detect changes without depending on bounded change-notification delivery. Native frames keep their existing dependency/cache behavior. Derived allocations do not produce application change notifications, preventing temporary results from causing redraw feedback. This protects managed heap writes; trusted Rust host implementations must also respect read-only calls for external state and I/O. Paint errors stop the affected runtime before publication; failed PUT candidates preserve the previously running heap and frame. Toggle developer tools with Command-Option-I or F12 on macOS, Control-Shift-I or F12 on Windows/Linux. The compact Console, Sources, Network and Settings tabs diff --git a/src/block.rs b/src/block.rs index c8897be..ce9f119 100644 --- a/src/block.rs +++ b/src/block.rs @@ -41,6 +41,9 @@ pub struct Block { } impl ObjectPayload for Block { + fn reference_assignment_only(&self) -> bool { + true + } fn attribute_target(&self, store: &ObjectStore) -> Result, VmError> { let Value::Object(value) = store.cell_get(self.state)? else { return Err(VmError::InvalidArgument("Block state is not an object")); @@ -148,6 +151,9 @@ impl Data { } impl ObjectPayload for Data { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } diff --git a/src/endor_host.rs b/src/endor_host.rs index 96a8589..9fa7fd0 100644 --- a/src/endor_host.rs +++ b/src/endor_host.rs @@ -801,6 +801,28 @@ mod tests { const EXAMPLE: &str = include_str!("../examples/hello.endor"); const PAGE: &str = include_str!("../examples/page.endor"); + #[test] + fn source_paint_can_rebind_old_plain_reference_to_new_result_without_mutating_it() { + let source = r##"class ReboundRect: RectBlock { + previous: ObjectList + function paint(self: ReboundRect, mount: Mount, geometry: Bounds): DisplayList { + drawing = self.previous + drawing = RectBlock.paint(self, mount, geometry) + return drawing + } + } + previous = ObjectList() + rect = ReboundRect(80, 40, 0, "#DDEEFF", previous) + page = Page() + page.render(rect)"##; + let (mut session, document) = ReplSession::load(source, "app.main", 75, 1).unwrap(); + assert_eq!(document.frame.commands.len(), 1); + assert_eq!( + session.execute("previous.count", "app.main").unwrap().value, + "0" + ); + } + #[test] fn source_paint_overrides_native_commands_and_reacts_to_heap_field_writes() { let (mut session, initial) = ReplSession::load( diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs index 841430b..08b5fcd 100644 --- a/src/event_dispatch.rs +++ b/src/event_dispatch.rs @@ -20,6 +20,9 @@ pub struct Event { prevented: bool, } impl ObjectPayload for Event { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } @@ -38,6 +41,9 @@ pub struct Connection { pub capture: bool, } impl ObjectPayload for Connection { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } @@ -57,6 +63,9 @@ pub struct Subscription { pub connection: WeakObjectRef, } impl ObjectPayload for Subscription { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } diff --git a/src/mount.rs b/src/mount.rs index 9f9c959..295c6fa 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -23,6 +23,9 @@ pub struct Mount { } impl ObjectPayload for Mount { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } diff --git a/src/object_list.rs b/src/object_list.rs index 12bb234..8b37d86 100644 --- a/src/object_list.rs +++ b/src/object_list.rs @@ -6,6 +6,9 @@ use endor_core::{ #[derive(Debug)] struct ObjectList(Vec); impl ObjectPayload for ObjectList { + fn reference_assignment_only(&self) -> bool { + true + } fn as_any(&self) -> &dyn std::any::Any { self } diff --git a/vendor/aster b/vendor/aster index ff49f26..4a2f81c 160000 --- a/vendor/aster +++ b/vendor/aster @@ -1 +1 @@ -Subproject commit ff49f266a23801898321d780dbf0879e9f479b11 +Subproject commit 4a2f81cb484c3114d7d9e15777569c1c1b9a78f3