craft-ui: a record journals each read once

The reads are a set to what reads them. A run that measures a component again (a kept
transcript's check) reads nothing new, so its journal no longer depends on how many
times the pass measured.
This commit is contained in:
aiongg
2026-11-20 05:38:29 +00:00
parent 6b634df42e
commit 2b3f149afe
2 changed files with 22 additions and 1 deletions
+3 -1
View File
@@ -96,7 +96,9 @@ pub(crate) fn note(ctx: &Context, key: BindKey, reader: Id, measuring: bool, sam
} else {
let read = Read { key, reader, measuring, runs, samples };
crate::runtime::replay::note_read(ctx, key);
crate::runtime::replay::journal(ctx, || read.clone(), |ctx, read| with(ctx, |reads| reads.reads.push(read.clone())));
// The reads are a set to what reads them: a run that measures a component again (a kept transcript's check)
// reads nothing new.
crate::runtime::replay::journal_distinct(ctx, || read.clone(), |ctx, read| with(ctx, |reads| reads.reads.push(read.clone())));
with(ctx, |reads| reads.reads.push(read));
}
}
+19
View File
@@ -356,6 +356,25 @@ where
}
}
/// `journal` for a registration that a second equal one adds nothing to: the innermost open record keeps it once, so
/// its journal does not depend on how many times its run made it.
pub(crate) fn journal_distinct<A, F>(ctx: &Context, args: impl FnOnce() -> A, again: F)
where
A: PartialEq + fmt::Debug + Shift + Send + Sync + 'static,
F: Fn(&Context, &A) + Copy + Send + Sync + 'static,
{
const { assert!(std::mem::size_of::<F>() == 0, "`journal_distinct`'s `again` captures nothing: pass its state in `args`") };
if recording(ctx) && !pass_state::with::<Recorder, _>(ctx, |recorder| recorder.replaying) {
let entry = Entry(Arc::new(Note { args: args(), again }));
pass_state::with::<Recorder, _>(ctx, |recorder| {
let from = recorder.open.last().map_or(0, |open| open.from);
if !recorder.journal[from..].contains(&entry) {
recorder.journal.push(entry);
}
});
}
}
/// Notes that the running code read the value `key`.
pub(crate) fn note_read(ctx: &Context, key: BindKey) {
with_open(ctx, |facts| {