fix: exclude shared host desktop bookkeeping from visual dependencies

This commit is contained in:
2026-10-24 01:55:27 +08:00
parent 9bb61befd8
commit ae3a2d6163
3 changed files with 38 additions and 3 deletions
+2
View File
@@ -244,3 +244,5 @@ Foreground REPL/events now retain a BeforeInput request while an existing idle l
Source layout/paint now validate name-level read observations from Aster: each globals/builtins lookup records its text key and observed presence/value, while dictionary kind checks remain separate. Updating the REPL result `_` or another unread global no longer invalidates these frames solely because the whole globals dictionary version changed. Reading `_` still observes its value; adding a previously missing global correctly invalidates a builtin fallback. Ordinary native dictionary iteration/content reads retain whole-object version dependencies. Measurement cache hits replay their recorded observations into the outer solve; they do not drop dependencies merely because source execution was skipped. Cache observations contain borrowed handles (including object-valued names), add no GC roots, and never write comparison snapshots back into language objects. Invalid-name diagnostics report only identity/key, not captured values. General Block binding and other legacy readers keep their existing conservative object dependencies. See examples/global-dependencies.endor.
Source layout/paint and measurement caches exclude every presentation's private desktop identity, including the primary desktop captured by shared native visual methods. Per-window bookkeeping must not invalidate another window's source output. This exclusion does not cover managed Window objects, viewport input records, type definitions or business objects; their observed changes remain dependencies.
+7
View File
@@ -48,6 +48,13 @@ pub struct Cache {
pub misses: usize,
}
impl Cache {
pub(crate) fn exclude_host_desktops(&mut self, desktops: &HashSet<ObjectRef>) {
for entry in self.entries.values_mut() {
entry
.reads
.retain(|read| !desktops.contains(&read.object()));
}
}
pub fn invalidate(&mut self, owners: &HashSet<ObjectRef>) {
self.entries
.retain(|_, entry| !owners.contains(&entry.owner));
+29 -3
View File
@@ -236,6 +236,15 @@ struct Session {
exiting: bool,
}
impl Session {
fn host_desktops(&self) -> std::collections::HashSet<ObjectRef> {
self.presentations
.values()
.map(|view| view.desktop)
.collect()
}
}
impl std::ops::Deref for Session {
type Target = crate::presentation::Presentation;
fn deref(&self) -> &Self::Target {
@@ -2612,11 +2621,18 @@ impl UiBridge {
progress: crate::source_paint::Progress,
) -> Result<crate::source_paint::Progress> {
if let crate::source_paint::Progress::Complete(draft) = &progress {
let (reads, names) = crate::presentation::split_reads(draft.reads.clone());
let mut state = self
.session
.lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
let desktops = state.host_desktops();
let reads = draft
.reads
.iter()
.filter(|read| !desktops.contains(&read.object()))
.cloned()
.collect();
let (reads, names) = crate::presentation::split_reads(reads);
state.paint_reads = reads;
state.paint_names = names;
state.paint_slices = draft.slices;
@@ -2893,8 +2909,8 @@ impl UiBridge {
let crate::source_layout::Draft {
mut frame,
runtime: mut layout,
cache,
reads,
mut cache,
mut reads,
} = draft;
let result: Result<crate::document::Frame> = (|| {
self.select_window(window)?;
@@ -2910,6 +2926,16 @@ impl UiBridge {
frame.tabs = tabs;
frame.window = window;
// Capture versions before lifecycle hooks can change a dependency.
let desktops = self
.session
.lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
.host_desktops();
// Shared intrinsic functions capture the primary desktop even when
// invoked from another window. Desktop bookkeeping is private host
// state; Window, viewport input and business dependencies remain.
reads.retain(|read| !desktops.contains(&read.object()));
cache.exclude_host_desktops(&desktops);
let (reads, names) = crate::presentation::split_reads(reads);
frame.focus = match vm.get_attr(desktop, "focus") {
Ok(Value::Number(id)) => id.as_i64().and_then(|n| u64::try_from(n).ok()),