craft-ui: a memoized view's run in a pass egui will discard keeps no record

egui paints nothing of a pass it will discard (Painter::is_visible is false in it), so a run there registers invisible
widgets and no nodes; a shown pass's replay of that record lacked them. The kept record stays the last shown pass's, a
settled view still replays in such a pass, and the replay audit skips it. Trial: a settled view replays through a
discarded pass, and new props there run the view again in the shown pass.
This commit is contained in:
aiongg committed 2026-11-20 07:31:57 +00:00
1 parent c3c1ef70ad
commit d5ea6a0e53
4 files changed
+42 -3

No files matched your search

+3 -2
View File
@@ -234,10 +234,11 @@ struct Audited<'a> {
shift: egui::RecordShift,
}
/// Whether the replay audit runs a child that would replay in a pass whose runs are `real` (test builds only).
/// Whether the replay audit runs a child that would replay in a pass whose runs are `real` (test builds only). A pass
/// egui will discard paints nothing, so a run there is no shown run to compare with: the child replays.
fn audits(ctx: &egui::Context, real: bool) -> bool {
#[cfg(feature = "testing")]
return real && crate::runtime::audit::runs(ctx);
return real && !ctx.will_discard() && crate::runtime::audit::runs(ctx);
#[cfg(not(feature = "testing"))]
{
let _ = (ctx, real);
+3
View File
@@ -3,6 +3,9 @@
//! naming the view and the first difference of each kind: a replay that differs from a real run is a view whose props
//! miss an input, or a registration the journal misses.
//!
//! A pass egui will discard paints nothing and keeps no record (`lazy::ran`): the audit skips it, and a view there
//! replays.
//!
//! The audit run keeps the kept run as it was, so every later pass compares with what a replay adds, and every decision
//! is the one the pass makes with the audit off. Only the outermost view that would replay runs: a view that would
//! replay inside an audit run replays, and the outer comparison covers that replay. The count trials' counters count
+10 -1
View File
@@ -554,6 +554,10 @@ pub(crate) fn audit(
same: Option<crate::runtime::audit::SameOutput>,
shift: &RecordShift,
) {
// A pass that turned to discard during the audit run paints nothing: its run is no shown run to compare with.
if ctx.will_discard() {
return;
}
let Some(kept) = with(ctx, |store, _, _| store.entries.get(&id).and_then(|entry| entry.settled.clone())) else { return };
let kept_run = crate::runtime::audit::Shown { record: &kept.record, rect: kept.rect, output: kept.output.as_ref() };
crate::runtime::audit::compare(name, id, (kept_run, shift), run, same);
@@ -587,8 +591,13 @@ pub(crate) struct Ran {
pub(crate) output: Option<Output>,
}
/// Keeps the real run `record` of the memoized view `id`, which ran at `place` and took `rect`.
/// Keeps the real run `record` of the memoized view `id`, which ran at `place` and took `rect`. A run in a pass egui
/// will discard keeps none: egui paints nothing of that pass (`Painter::is_visible` is false in it), so the run registers
/// invisible widgets and no nodes, which a shown pass's replay must not add. The kept record stays the last shown pass's.
pub(crate) fn ran(ctx: &Context, id: Id, record: Record, place: Place, rect: Rect, Ran { key, edits, seen, view, output }: Ran) {
if ctx.will_discard() {
return;
}
let targets = focus::targets(ctx);
let engaged_now = record.focus.stop_ids().any(|stop| targets.contains(&Some(stop)));
let lives = crate::runtime::memory::ended_generation(ctx);
@@ -206,6 +206,32 @@ fn a_changed_prop_runs_its_view_once() {
assert_eq!(scene.out, run, "a replay returns what the run returned");
}
/// A pass egui will discard paints nothing, so a run there keeps no record: a settled view replays through it, and the
/// replay audit runs nothing in it; a view whose props change in it runs there and again in the shown pass, whose run
/// is the one kept. The audit is on, so each later replay is compared with a real run.
#[trial]
fn a_pass_egui_will_discard_keeps_no_record_and_replays_settled_views() {
let mut frames = Frames::new();
craft_ui::testing::audit_replays(&frames.ctx, true);
let frame = |frames: &mut Frames, shown: &str, discard: bool| {
let passes = frames.frame(vec![], |ui| {
if discard && ui.ctx().current_pass_index() == 0 {
frame::discard_pass(ui.ctx(), "trial");
}
in_region(ui, region(0), |ui| MemoView::new("title", Title { title: shown.to_owned() }, title).show(ui));
});
(passes, title_runs())
};
for _ in 0..WARM {
frame(&mut frames, "A", false);
}
assert_eq!(frame(&mut frames, "A", false), (1, 0), "a settled view replays");
assert_eq!(frame(&mut frames, "A", true), (2, 0), "it replays through the discarded pass and the shown one");
assert_eq!(frame(&mut frames, "A", false), (1, 0), "its kept record is unchanged: a run gives what it replays");
assert_eq!(frame(&mut frames, "B", true), (2, 2), "new props run it in the discarded pass and again in the shown one");
assert_eq!(frame(&mut frames, "B", false), (1, 0), "then it replays the shown pass's run");
}
/// A view that writes its own `&mut Tracked` runs twice for the change that asked for the write, the writing run and
/// one that reads the written value, then replays.
#[trial]