Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ci/proofs/platform-generated-enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"machine/src/machine.rs": [
"571415d64a9885248f852b402153feedd4660acbe03606e4796c59659726049f",
"03a6e18f576dcbaff66c3d7405923b155302bfb2996bb373dac115ece055a5bf",
"d08b44dbff241962286eb7e1f85897073ba9f2f712a2ba935837f901635369a8"
"d08b44dbff241962286eb7e1f85897073ba9f2f712a2ba935837f901635369a8",
"9b1ffb66c7ba2eb9fdffcb4bcbf0a29cda87a003cce69b16c73567c8bc0a65b0"
]
},
"text_hashing": "sha256-utf8-bytes-crlf-to-lf-local-root-version-v1",
Expand Down Expand Up @@ -74,7 +75,8 @@
"languages_rs emits only unit variants; Pseudo cfg_attr only allows dead_code",
"string slots use Rust Debug escaping; numeric slots are integers",
"install_identities writes only install_identities.rs, never languages.rs",
"PR1366: PressRead identity/live/active and owned-present sibling/test modules; canonical machine child and doc-only u32 newtype producer unchanged"
"PR1366: PressRead identity/live/active and owned-present sibling/test modules; canonical machine child and doc-only u32 newtype producer unchanged",
"PR1385: Canon byte-feed loops inlined (impl Canon and canon_tests only, FNV-1a byte stream unchanged); newtype macro and its ten u32 invocations unchanged"
],
"assumptions": [
"Offline source-backed unit-enum proof; certificate changes require source review.",
Expand Down
13 changes: 8 additions & 5 deletions ci/readonly_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from readonly_dependencies import _local_sha, _sha, _json, _manifest_paths, _configs, _workspace_hashes, WORKSPACE_HASHING

CERTIFICATE_PATH = Path(__file__).with_name('proofs') / 'platform-generated-enums.json'
CERTIFICATE_SHA256 = 'd7cf4ee3937fa0fb7ec2460d49c41219a40b0263a81612240123f11fd1c52663'
CERTIFICATE_SHA256 = 'b61be9b470960a80bbb097dfa466fa5fd4229f89ef8f1234bb302edabf9f8396'
SOURCES = ['platform/Cargo.toml', 'platform/src/lib.rs', 'platform/src/i18n/mod.rs',
'platform/build.rs', 'platform/build_support/catalog.rs', 'build_support/install_identities.rs',
'machine/src/lib.rs', 'machine/src/machine.rs']
Expand All @@ -23,7 +23,8 @@

MACHINE_SOURCES = ['571415d64a9885248f852b402153feedd4660acbe03606e4796c59659726049f',
'03a6e18f576dcbaff66c3d7405923b155302bfb2996bb373dac115ece055a5bf',
'd08b44dbff241962286eb7e1f85897073ba9f2f712a2ba935837f901635369a8']
'd08b44dbff241962286eb7e1f85897073ba9f2f712a2ba935837f901635369a8',
'9b1ffb66c7ba2eb9fdffcb4bcbf0a29cda87a003cce69b16c73567c8bc0a65b0']
MACHINE_LIB_SOURCES = ['105afdbb05fb762e6752cef260b6d928b1d828993350aaa71651f96cee0c3188',
'c35d39ae620b5607e7035222ab1023799adaf091d6a4f737a847dd70b26c1b36']

Expand All @@ -33,8 +34,9 @@

def source_hashes(root):
sources = {p: _local_sha((root / p).read_bytes()) for p in SOURCES}
# Reviewed variants add NavOp::SelectTabWithChild or PressRead identity/live/active;
# the complete doc-only newtype producer and its u32 invocations are unchanged.
# Reviewed variants add NavOp::SelectTabWithChild or PressRead identity/live/active, or rewrite
# the Canon byte-feed loops; the complete doc-only newtype producer and its u32 invocations
# are unchanged.
if sources['machine/src/machine.rs'] not in MACHINE_SOURCES: raise ValueError('unreviewed machine source')
sources['machine/src/machine.rs'] = MACHINE_SOURCES
# Owned-present migration changes sibling/test modules, never the canonical machine child.
Expand Down Expand Up @@ -62,7 +64,8 @@ def produce_certificate(root):
'languages_rs emits only unit variants; Pseudo cfg_attr only allows dead_code',
'string slots use Rust Debug escaping; numeric slots are integers',
'install_identities writes only install_identities.rs, never languages.rs',
'PR1366: PressRead identity/live/active and owned-present sibling/test modules; canonical machine child and doc-only u32 newtype producer unchanged'],
'PR1366: PressRead identity/live/active and owned-present sibling/test modules; canonical machine child and doc-only u32 newtype producer unchanged',
'PR1385: Canon byte-feed loops inlined (impl Canon and canon_tests only, FNV-1a byte stream unchanged); newtype macro and its ten u32 invocations unchanged'],
'assumptions': __doc__.splitlines()}


Expand Down
29 changes: 16 additions & 13 deletions rust-modules/appkit/src/player_hud/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ fn long_hud_titles_fit_before_every_control_slot() {
for slot in slots {
let right = compiled_title_right(&compiled, slot);
let items = geometry(&compiled, 0, slot, true, false).items;
// What a title draws depends on the cell's right edge and the title, never on which
// control holds the focus or how far its pop has run (an unpaused title reads no clock):
// drawn once per slot and kicker, not again for every focused control and pop frame.
for kicker in [Kicker::Episode(long.as_ptr()), Kicker::Context(long.as_ptr())] {
let runs = plx_ui::draw_census::capture_runs(|| {
draw_player_title(Painter::recording(), kicker, long.as_ptr(),
right, measure, false, &clock);
});
assert_eq!(runs.len(), 2);
for run in runs {
assert!(run.text.ends_with('…'), "{}: expected ellipsis: {run:?}", language.tag());
assert_eq!(run.at.x, SB_X);
assert!(measure.width_str(&run.text, run.size, run.bold) <= right - SB_X + 1.0,
"{}: fitted title exceeds the control boundary: {run:?}", language.tag());
}
}
let mut row = HudMotion::new();
for focused in 0..slot.items() {
for _ in 0..30 {
Expand All @@ -100,19 +116,6 @@ fn long_hud_titles_fit_before_every_control_slot() {
let Some(rect) = items[i as usize] else { continue };
assert!(right + theme::space::MD <= rect.scaled(row.scale(i, Default::default())).x + 0.001);
}
for kicker in [Kicker::Episode(long.as_ptr()), Kicker::Context(long.as_ptr())] {
let runs = plx_ui::draw_census::capture_runs(|| {
draw_player_title(Painter::recording(), kicker, long.as_ptr(),
right, measure, false, &clock);
});
assert_eq!(runs.len(), 2);
for run in runs {
assert!(run.text.ends_with('…'), "{}: expected ellipsis: {run:?}", language.tag());
assert_eq!(run.at.x, SB_X);
assert!(measure.width_str(&run.text, run.size, run.bold) <= right - SB_X + 1.0,
"{}: fitted title exceeds the control boundary: {run:?}", language.tag());
}
}
}
}
}
Expand Down
75 changes: 63 additions & 12 deletions rust-modules/machine/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,30 @@ impl Canon {
}
}

// `inline(always)` and plain index loops, not `for b in bytes` / `to_le_bytes()` iterators: this
// runs over the whole logical state several times a frame in a debug build (the dispatcher's
// `state_hash` assertions), where every iterator `next` is a call that is never inlined, and
// they were most of a dispatcher test frame. The bytes fed, and so the hash, are unchanged
// (`canon_is_fnv_1a_over_tagged_little_endian_bytes`).
#[inline(always)]
fn byte(&mut self, b: u8) {
self.h ^= b as u64;
self.h = self.h.wrapping_mul(Self::PRIME);
self.len += 1;
}

#[inline(always)]
fn bytes(&mut self, bytes: &[u8]) {
let mut h = self.h;
let mut i = 0;
while i < bytes.len() {
h = (h ^ bytes[i] as u64).wrapping_mul(Self::PRIME);
i += 1;
}
self.h = h;
self.len += bytes.len() as u64;
}

pub fn u8(&mut self, v: u8) -> &mut Self {
self.tag(1);
self.byte(v);
Expand All @@ -893,17 +911,13 @@ impl Canon {

pub fn u32(&mut self, v: u32) -> &mut Self {
self.tag(2);
for b in v.to_le_bytes() {
self.byte(b);
}
self.bytes(&v.to_le_bytes());
self
}

pub fn u64(&mut self, v: u64) -> &mut Self {
self.tag(3);
for b in v.to_le_bytes() {
self.byte(b);
}
self.bytes(&v.to_le_bytes());
self
}

Expand All @@ -916,18 +930,14 @@ impl Canon {
/// Floats are their BITS: NaN, +0/-0 and Inf are all distinct and all stable.
pub fn f32(&mut self, v: f32) -> &mut Self {
self.tag(5);
for b in v.to_bits().to_le_bytes() {
self.byte(b);
}
self.bytes(&v.to_bits().to_le_bytes());
self
}

pub fn str(&mut self, v: &str) -> &mut Self {
self.tag(6);
self.u32(v.len() as u32);
for b in v.bytes() {
self.byte(b);
}
self.bytes(v.as_bytes());
self
}

Expand Down Expand Up @@ -957,6 +967,7 @@ impl Canon {
self
}

#[inline(always)]
fn tag(&mut self, t: u8) {
self.byte(t);
}
Expand Down Expand Up @@ -1029,6 +1040,46 @@ mod canon_tests {
assert_ne!(z.finish(), nz.finish(), "+0 and -0 are different bits");
}

/// The encoder is FNV-1a over a tag byte and little-endian bytes, `finish` folding the byte count
/// in. Recorded replay anchors hash through it, so its byte stream is pinned two ways: against a
/// one-byte-at-a-time reference written from that sentence, and against the value the encoder
/// produced before its loops were rewritten to run cheaply in a debug build.
#[test]
fn canon_is_fnv_1a_over_tagged_little_endian_bytes() {
let mut c = Canon::new();
c.u8(0xAB)
.u32(0xDEAD_BEEF)
.u64(0x0123_4567_89AB_CDEF)
.bool(true)
.f32(-1.5)
.str("héllo — ☃")
.discriminant(7)
.seq(3)
.option(Some(5u32), |c, v| {
c.u32(v);
})
.option::<u32>(None, |c, v| {
c.u32(v);
});
let mut stream = vec![1, 0xAB, 2];
stream.extend(0xDEAD_BEEFu32.to_le_bytes());
stream.push(3);
stream.extend(0x0123_4567_89AB_CDEFu64.to_le_bytes());
stream.extend([4, 1, 5]);
stream.extend((-1.5f32).to_bits().to_le_bytes());
stream.extend([6, 2]);
stream.extend(("héllo — ☃".len() as u32).to_le_bytes());
stream.extend("héllo — ☃".bytes());
stream.extend([7, 2, 7, 0, 0, 0, 8, 2, 3, 0, 0, 0, 10, 2, 5, 0, 0, 0, 9]);
let (mut h, mut len) = (0xcbf2_9ce4_8422_2325u64, 0u64);
for b in stream {
h = (h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3);
len += 1;
}
assert_eq!(c.finish(), h ^ len.rotate_left(32), "the byte stream is not the specified one");
assert_eq!(c.finish(), 7_471_706_773_540_265_486, "the value the encoder produced before its loops were rewritten");
}

struct NoHost;
#[derive(Clone)]
struct NoArg;
Expand Down
18 changes: 12 additions & 6 deletions rust-modules/media/src/player/ass_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,18 +1259,24 @@ mod tests {
fn a_backward_seek_after_a_deep_read_keeps_the_events_at_the_target() {
let mut s = Store::new();
let g = s.begin("fixture", vec![(0, TrackHeader::Authored(b"header".to_vec()))], vec![]);
// A typeset-heavy file read 30 000 events in; the window holds the latest 8 192.
for n in 0..30_000 {
// A typeset-heavy file read past the window: the window holds the latest 8 192, and every
// event the file has to give is behind its first one. (A push copies and ranks the whole
// window, so reading further than this only repeats the same eviction at a quadratic cost;
// the 30 000 events this once read held the identical 8 192 latest at the seek.)
let read = MAX_EVENTS as i64 + 300;
for n in 0..read {
s.push(g, 0, timed(n), 0);
}
// The viewer rewinds to event 10 000 (the floor follows the rebased clock).
assert_eq!(embedded(&s, 0).len(), MAX_EVENTS, "the window is full");
// The viewer rewinds to event 100, more than `STALE_AHEAD_MS` behind everything the window
// holds (the floor follows the rebased clock).
s.seek(g);
let floor_ms = 10_000_000 - 62_000;
for n in 10_000..10_100 {
let floor_ms = 100_000 - 62_000;
for n in 100..200 {
s.push(g, 0, timed(n), floor_ms);
}
let held = embedded(&s, 0);
for n in 10_000..10_100 {
for n in 100..200 {
assert!(held.contains(&timed(n)), "event {n} at the seek target was lost");
}
assert!(held.len() <= 8192);
Expand Down
14 changes: 9 additions & 5 deletions rust-modules/telemetry/src/telemetry/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,15 @@ mod tests {
#[test]
fn at_the_byte_cap_sessions_are_dropped_before_crash_reports() {
let session = rec("sess", Category::Errors, br#"{"attrs":{"release":"r"},"did":"d","sid":"s","started":"t"}"#);
// The largest crash body for which four crash reports fit and no session does.
let mut n = 90_000;
while 4 * encode(&rec("c", Category::Errors, &vec![b'x'; n + 3])).unwrap().len() <= MAX_BYTES {
n += 3;
}
// The largest crash body for which four crash reports fit and no session does. A frame is a
// fixed overhead (header, JSON fields, an empty body) plus four base64 characters per three
// body bytes, so the body is derived from the overhead instead of searched for by framing
// a ~100 KB record thousands of times; the two asserts pin the derivation to `encode`.
let framed = |n: usize| encode(&rec("c", Category::Errors, &vec![b'x'; n])).unwrap().len();
let overhead = framed(0);
let n = 3 * ((MAX_BYTES / 4 - overhead) / 4);
assert!(4 * framed(n) <= MAX_BYTES, "four crash reports of {n} bytes fit");
assert!(4 * framed(n + 3) > MAX_BYTES, "and one base64 group more does not");
let crash = |id: &str| rec(id, Category::Errors, &vec![b'x'; n]);
let all = vec![crash("c1"), crash("c2"), crash("c3"), crash("c4"), session];
let (kept, dropped) = trim(all);
Expand Down
17 changes: 11 additions & 6 deletions rust-modules/ui/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,11 @@ where
tap.present(f, will_present, why);
// `prepare_does_not_change_the_logical_state_hash` (§5.4): a prepare pass touches render
// resources only — graded on every presenting frame of a debug build
// Hashed only when the prepare pass runs: otherwise nothing between the two hashes can
// reach the hashed state (`rig.opaque_route` is handed one bool), and a debug frame paid
// two full-state hashes to compare a state with itself.
#[cfg(debug_assertions)]
let hash_before_prepare = self.state_hash();
let hash_before_prepare = (will_present && draw).then(|| self.state_hash());

// 9. prepare (only if presenting), then opaque_route on EVERY frame. The activity table:
// the top page prepares unless its host fold is Cached or Replaced; every surface does.
Expand All @@ -1356,11 +1359,13 @@ where
}
rig.opaque_route(self.present.video_plane());
#[cfg(debug_assertions)]
debug_assert_eq!(
self.state_hash(),
hash_before_prepare,
"a prepare pass changed the logical state"
);
if let Some(before) = hash_before_prepare {
debug_assert_eq!(
self.state_hash(),
before,
"a prepare pass changed the logical state"
);
}

// 10. draw, then the tail
if will_present && draw {
Expand Down
17 changes: 15 additions & 2 deletions rust-modules/ui/src/widgets_tab_capsule_motion_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,29 @@ fn backing_at_xy(strip: &TabStrip, ground: TabGround, x: f32, y: f32) -> [f32; 4
/// the 2-D grade the column-only ones could not give.
fn worst_contrast_2d(strip: &TabStrip, ground: TabGround, pill: (f32, f32), ink_of: fn(f32, f32) -> [f32; 4]) -> (f32, f32, f32) {
let rect = Rect::new(pill.0, 0.0, pill.1, INK_H);
// The ink regions are a fact about the strip, the ground and the pill, so they are decided once
// and asked per pixel (`ink_at` is `pill_ink(..).at(..)`: it re-derived them for every one of
// the ~5 000 pixels). A pixel's ratio is a function of its backing and its ink alone, and
// neighbouring pixels nearly always share both, so the last one is kept.
let regions = strip.pill_ink(rect, ground);
let mut last: Option<([f32; 4], [f32; 4], f32)> = None;
let mut worst = (f32::MAX, pill.0, 0.0);
for column in (pill.0.floor() as i32)..((pill.0 + pill.1).ceil() as i32) {
let x = column as f32 + 0.5;
if x < pill.0 + 12.0 || x >= pill.0 + pill.1 - 12.0 { continue; }
for k in -17..17 {
let y = INK_H * 0.5 + k as f32 + 0.5;
let (focus, selected) = strip.ink_at(rect, ground, x, y);
let (focus, selected) = regions.at(x, y);
let backing = backing_at_xy(strip, ground, x, y);
let ink = ink_of(focus, selected);
let ratio = contrast(theme::cross(backing, [ink[0], ink[1], ink[2], 1.0], ink[3]), backing);
let ratio = match last {
Some((b, i, r)) if b == backing && i == ink => r,
_ => {
let r = contrast(theme::cross(backing, [ink[0], ink[1], ink[2], 1.0], ink[3]), backing);
last = Some((backing, ink, r));
r
}
};
if ratio < worst.0 { worst = (ratio, x, y - INK_H * 0.5); }
}
}
Expand Down
Loading