Say the environment once, and stop a hint read going uncounted

The eleventh sweep, over the built-in bounds work in 2ac0843.

`Painter::size_hint` refused to answer for a bounded widget by returning
above the diagnostics, so that read was neither a hint hit nor a miss and
`hint_read` recorded nothing. It is a miss now, with the reason on it.

The two `for axis in Axis::BOTH` loops that `draw_widget` grew, both
writing `own_holds`, are one loop, and the comment about combining the
ask's holds no longer sits between a comment and the code it describes.

`Declared::from_axes` lost its only caller with `Widgets::declared_lens`;
`Bounds::from_axes` and `SizeRule::declared` never had one.

The scenario shrinker printed a rule with derived `Debug`, which is 130
characters an axis in a line that carries every ancestor, in the one
function whose job is output a tree can be rebuilt from. It prints its
parts again.

`bounds_cost` invented three environment-reading spellings where four
copies of one `env` helper already existed; there is now one, in
`tests/rig`, and the four copies are gone. It also verified 128 regions
inside its measured loop, which the other rigs deliberately do before
theirs; that measured 0.65% of the total, and none of it is layout.

The 250-window row with a 300 cap was built by two tests, and the one
that still explained itself tested less; they are one. The half of
`a_cap_attribute_narrows_the_widgets_box` that the wrapper's removal left
without its deciding assertion is the allocator's path instead, which
nothing at the root covered.

Format, workspace clippy under -D warnings with and without
layout-diagnostics, 206 ordinary and 210 diagnostic tests, 400 depth-5
trees warm against cold in 64.19s, and the cold dump byte-identical to
2ac0843 across all 34,986 boxes.
This commit is contained in:
iris-ai committed 2026-09-20 20:13:57 -04:00
1 parent 2ac0843cb2
commit ea1f836bf9
16 files changed
+178 -146

No files matched your search

+45 -17
View File
@@ -1,17 +1,33 @@
//! CPU comparison of bounds attributes and the former wrapper, using the
//! same builder calls and geometry. Run the release executable under perf;
//! process totals include the cold frame. MODE=plain|exact|cap, REDRAW=0|1.
//! CPU comparison of a bounds attribute against the `MaxSize` wrapper it
//! replaced, using the same builder calls and the same geometry. The wrapper
//! is gone from this tree, so its side of the comparison is run by checking
//! out a commit that still has it: the fixture is written to build the same
//! way at both.
//!
//! MODE=cap FRAMES=2000 cargo test --release --test bounds_cost \
//! -- --ignored --nocapture
//!
//! `MODE` is `plain`, `exact` or `cap`; `REDRAW=1` marks every widget for
//! redraw each frame; `FRAMES` is how many resize frames to measure. Use
//! repeated `perf stat -e instructions:u` runs on the executable directly.
//! Process totals include the cold frame, so compare identical modes and
//! frame counts. Wall time on this machine is not a stable comparison.
mod rig;
use iris::{harness::Harness, prelude::*};
use rig::env;
/// The two widths the loop alternates. The cap of 80 binds at 300 and does
/// not at 100, so the measured frames cross it in both directions.
const WIDTHS: [i32; 2] = [100, 300];
#[test]
#[ignore = "instruction-count measurement"]
fn bounds_cost() {
let mode = std::env::var("MODE").unwrap_or_else(|_| "cap".into());
let redraw = std::env::var("REDRAW").is_ok_and(|value| value == "1");
let frames = std::env::var("FRAMES")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(2000);
let mode = env("MODE", "cap".to_string());
let redraw = env("REDRAW", 0_u8) != 0;
let frames = env("FRAMES", 2000_usize);
let mut h = Harness::new((300, 512));
let mut column = Span::empty(Dir::DOWN);
let mut leaves = Vec::new();
@@ -38,23 +54,35 @@ fn bounds_cost() {
ids.len(),
std::mem::size_of::<SizeRule>()
);
for frame in 0..frames {
if redraw {
for &id in &ids {
h.rsc.widgets_mut().mark_for_redraw(id);
}
}
let width = if frame % 2 == 0 { 100 } else { 300 };
// That the fixture measures what it says is checked on both sides of the
// crossing here rather than inside the measured loop, which is what the
// other rigs do. Per frame it measured only 0.65% of the total (5.780B
// against 5.743B instructions at MODE=cap, FRAMES=2000), but none of it
// is the layout the number is about.
for width in WIDTHS {
h.resize((width, 512));
h.frame();
let expected = match mode.as_str() {
"plain" => width / 2,
"exact" => 40,
"cap" => (width / 2).min(80),
_ => unreachable!(),
_ => unreachable!("the mode was checked while building"),
};
for id in &leaves {
assert_eq!(h.region(id).unwrap().size().x, Px::from_int(expected));
}
println!(
"width {width}: first leaf {}",
h.region(&leaves[0]).unwrap()
);
}
for frame in 0..frames {
if redraw {
for &id in &ids {
h.rsc.widgets_mut().mark_for_redraw(id);
}
}
h.resize((WIDTHS[frame % WIDTHS.len()], 512));
h.frame();
}
}
+41 -32
View File
@@ -1005,46 +1005,72 @@ fn a_region_node_root_is_a_region_node() {
assert_eq!(h.region(&probe).unwrap().size().x, Px::from_int(900));
}
/// A bound holds the length a widget reports as well as narrowing the box it
/// is offered, and the two are not the same question. Here two 200-wide rects
/// fill a row in a 250 window, so a cap of 300 leaves the box alone and only
/// cuts what the row reports -- which the window then centres, past both its
/// edges -- while a floor raises the report and the rects stay where the 250
/// box put them.
#[test]
fn a_bound_holds_what_a_widget_answers() {
let row = |rule: SizeRule| {
let bounded_row = |rule: SizeRule| {
let mut h = Harness::new((250, 200));
let left = rect(Color::RED).width(200).add(&mut h.rsc);
let right = rect(Color::BLUE).width(200).add(&mut h.rsc);
let row = (left, right).span(Dir::RIGHT).add(&mut h.rsc);
h.rsc.widgets_mut().set_size_rule(row, Axis::X, rule);
h.set_root(row);
(
h.region(&row).unwrap().size().x,
h.region(&left).unwrap().size().x,
)
(h, row, left)
};
let (capped, left) = row(SizeRule::max(Len::px(300.0)));
assert_eq!(capped, Px::from_int(300), "the cap, not the 400 drawn");
assert_eq!(left, Px::from_int(200), "the box the children were given");
let (h, row, left) = bounded_row(SizeRule::max(Len::px(300.0)));
assert_eq!(
h.region(&row).unwrap().size().x,
Px::from_int(300),
"the cap, not the 400 drawn"
);
assert_eq!(
h.region(&left).unwrap().size().x,
Px::from_int(200),
"the box the children were given"
);
assert_corners!(h, row, (-25, 0), (275, 200));
let (floored, _) = row(SizeRule::min(Len::px(600.0)));
assert_eq!(floored, Px::from_int(600), "the floor, not the 400 drawn");
let (h, row, _) = bounded_row(SizeRule::min(Len::px(600.0)));
assert_eq!(
h.region(&row).unwrap().size().x,
Px::from_int(600),
"the floor, not the 400 drawn"
);
let (free, _) = row(SizeRule::FREE);
assert_eq!(free, Px::from_int(400), "what it drew");
let (h, row, _) = bounded_row(SizeRule::FREE);
assert_eq!(
h.region(&row).unwrap().size().x,
Px::from_int(400),
"what it drew"
);
}
/// A cap narrows the box the widget is asked in, whether a declaration of its
/// own decides that box or the allocator divides a share into it. The cap is
/// an attribute of the widget rather than something wrapped around it, which
/// is what the id assertions say.
#[test]
fn a_cap_attribute_narrows_the_widgets_box() {
let mut h = Harness::new((400, 200));
// A fraction of its box, so it says what box it was asked in.
let fills = rect(Color::RED).width(rel(1.0)).add(&mut h.rsc);
let capped = fills.max_width(300).add(&mut h.rsc);
assert_eq!(fills.id(), capped.id());
h.set_root(capped);
assert_eq!(h.region(&fills).unwrap().size().x, Px::from_int(300));
// A share with nothing beside it: the cap is composed into the request
// and the allocator answers with it rather than the whole 400.
let mut h = Harness::new((400, 200));
let share = rect(Color::RED).add(&mut h.rsc);
let share = rect(Color::RED).width(leftover(1)).add(&mut h.rsc);
let capped = share.max_width(300).add(&mut h.rsc);
assert_eq!(share.id(), capped.id());
h.set_root(capped);
assert_eq!(h.region(&share).unwrap().size().x, Px::from_int(300));
}
@@ -1082,23 +1108,6 @@ fn a_cap_is_a_fraction_of_the_box_it_was_given() {
assert_eq!(h.region(&probe).unwrap().size().x, Px::from_int(150));
}
/// A cap is a promise about the length as well as the box: a widget whose
/// content is longer than the box it was given reports what it drew, and the
/// cap holds that down even though it never decided the box.
#[test]
fn a_cap_holds_an_answer_that_overflowed_its_box() {
let mut h = Harness::new((250, 200));
let left = rect(Color::RED).width(200).add(&mut h.rsc);
let right = rect(Color::BLUE).width(200).add(&mut h.rsc);
let row = (left, right).span(Dir::RIGHT).add(&mut h.rsc);
h.rsc.widgets_mut().set_max_len(row, Axis::X, 300.into());
h.set_root(row);
// The box is the 250 window, which the cap of 300 leaves alone, and the
// row draws 400 of it. Its answer is the cap, and the window centres it.
assert_corners!(h, row, (-25, 0), (275, 200));
}
struct Offered {
seen: Rc<Cell<PxVec2>>,
answer: Size,
+3 -2
View File
@@ -1,3 +1,4 @@
mod rig;
#[path = "scenario/mod.rs"]
mod scenario;
@@ -5,8 +6,8 @@ use iris::prelude::*;
use iris::random::{Edits, Plan, plan};
fn check_requests(edit: impl Fn(&mut Plan) + Sync) {
let count = scenario::env("IRIS_DEFERRED_SEEDS", 20_u64);
let depth = scenario::env("IRIS_DEFERRED_DEPTH", 4_usize);
let count = rig::env("IRIS_DEFERRED_SEEDS", 20_u64);
let depth = rig::env("IRIS_DEFERRED_DEPTH", 4_usize);
let seeds = std::env::var("IRIS_DEFERRED_SEED")
.ok()
.and_then(|seed| seed.parse().ok())
+3 -1
View File
@@ -11,11 +11,13 @@
//! `IRIS_GENERATED_SEED`, `IRIS_GENERATED_SEEDS` and `IRIS_GENERATED_DEPTH`
//! select what the long run covers.
mod rig;
#[path = "scenario/mod.rs"]
mod scenario;
use iris::random::{Edits, Plan, plan};
use scenario::{ALL, Case, diverges, env, over_seeds};
use rig::env;
use scenario::{ALL, Case, diverges, over_seeds};
/// How deep the generator branches. The generator widens two to four ways per
/// level, so depth is exponential in width and a deep narrow tree is not
+3 -7
View File
@@ -16,9 +16,12 @@
//! `IRIS_DIRTY` how many widgets `many` marks at once. `IRIS_UNBOUNDED=1`
//! removes intrinsic bounds while preserving the rest of the generated tree.
mod rig;
use iris::harness::Harness;
use iris::prelude::*;
use iris::random::{Edits, Tree, build, plan};
use rig::env;
use std::time::Instant;
const OUTPUT: (f32, f32) = (1920.0, 1200.0);
@@ -94,13 +97,6 @@ fn a_selected_widget_retains_its_layout_events() {
diagnostics::clear_traced_widgets();
}
fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
std::env::var(name)
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(fallback)
}
#[cfg(feature = "layout-diagnostics")]
fn trace_selected(tree: &Tree) {
let Ok(value) = std::env::var("IRIS_TRACE_INDEX") else {
+3 -7
View File
@@ -11,15 +11,11 @@
//! it is not drawn. `IRIS_UNBOUNDED=1` drops the trees' intrinsic bounds, as
//! in the diagnostics rig, which compares the two paths over the same shapes.
mod rig;
use iris::harness::Harness;
use iris::random::{Edits, build, plan};
fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
std::env::var(name)
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(fallback)
}
use rig::env;
#[test]
#[ignore = "a dump to diff across commits, not a check"]
+3 -7
View File
@@ -18,8 +18,11 @@
//! process totals include font loading and the cold frame, so compare identical
//! row and frame counts. Wall time on this machine is not a stable comparison.
mod rig;
use iris::harness::Harness;
use iris::prelude::*;
use rig::env;
use std::time::Instant;
/// xorshift64, so one seed is one set of paragraphs on any machine.
@@ -81,13 +84,6 @@ fn words(rng: &mut Rng, least: usize, most: usize) -> String {
const OUTPUT: (f32, f32) = (900.0, 1200.0);
fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
std::env::var(name)
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(fallback)
}
/// A row of a fixed-width rect beside a column of one wrapping and one
/// overflowing text: the shape that makes a container measure a child in a
/// box it will not keep.
+12
View File
@@ -0,0 +1,12 @@
//! What the rigs need and none of them should spell its own way. Every
//! fuzzer and measurement here is run by hand with its parameters in the
//! environment, so one reader is shared rather than copied into each target.
/// A rig's parameter from the environment, or its default. A switch is
/// `env("NAME", 0_u8) != 0`, so `NAME=1` turns it on.
pub fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
std::env::var(name)
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(fallback)
}
+20 -11
View File
@@ -30,13 +30,6 @@ pub fn over_seeds(seeds: Vec<u64>, run: impl Fn(u64) + Sync) {
});
}
pub fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
std::env::var(name)
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(fallback)
}
/// The window a tree is grown in, and the one a resize takes it to.
const OUTER: (f32, f32) = (1920.0, 1200.0);
const INNER: (f32, f32) = (640.0, 900.0);
@@ -356,8 +349,24 @@ fn change(case: Case, warm: &mut Harness, tree: &mut Tree, plan: &Plan, rng: &mu
/// out by hand. A failure is a lead; the fast test that replaces it has to be
/// buildable from what the failure printed.
fn describe(id: WidgetId, h: &Harness) -> String {
let rules = h.rsc.widgets().size_rules(id).clone();
let rule = |r: SizeRule| format!("{r:?}");
let rules = h.rsc.widgets().size_rules(id);
// The tree a failure names is written out again from what it printed, so
// every part of a rule prints: the preferred length and the bounds are
// independent, and a bound lumped into "no rule" could not be rebuilt.
let rule = |r: &SizeRule| {
let mut out = match &r.request {
None => String::new(),
Some(SizeRequest::Linear(len)) => format!("{len}"),
Some(request) => format!("{request:?}"),
};
if let Some(min) = r.bound.min {
out += &format!(">{}", LayoutLen::from(min));
}
if let Some(max) = r.bound.max {
out += &format!("<{}", LayoutLen::from(max));
}
if out.is_empty() { "-".into() } else { out }
};
let align = h.rsc.widgets().alignment(id);
let side = |a: AxisAlign| {
if a == AxisAlign::NEG {
@@ -373,8 +382,8 @@ fn describe(id: WidgetId, h: &Harness) -> String {
// A rule and an alignment are properties of whatever carries them, so
// they print with that widget rather than as widgets of their own.
let mut out = describe_widget(id, h);
if rules != SizeRules::default() {
out += &format!("[x:{},y:{}]", rule(rules.x), rule(rules.y));
if *rules != SizeRules::default() {
out += &format!("[x:{},y:{}]", rule(&rules.x), rule(&rules.y));
}
if align != RegionAlign::default() {
out += &format!("@{},{}", side(align.x), side(align.y));
+3 -1
View File
@@ -17,11 +17,13 @@
//! It is a fuzzer: run it once the ordinary tests pass, and turn what it
//! finds into a test of its own rather than leaving a seed as the record.
mod rig;
#[path = "scenario/mod.rs"]
mod scenario;
use iris::random::{Edits, Plan, plan};
use scenario::{ALL, Case, diverges, env, over_seeds};
use rig::env;
use scenario::{ALL, Case, diverges, over_seeds};
/// Takes the first simplification that still fails, until none does. The
/// simplifications come biggest first, so this walks down rather than