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
+174 -142

No files matched your search

+8 -4
View File
@@ -439,10 +439,14 @@ impl<'a> Painter<'a> {
/// against this widget's rel base, which is the rel base a child asked with /// against this widget's rel base, which is the rel base a child asked with
/// nothing narrowed gets. Asking counts as reading its size. /// nothing narrowed gets. Asking counts as reading its size.
pub fn size_hint<W: ?Sized>(&mut self, id: &StrongWidget<W>, axis: Axis) -> Option<LayoutLen> { pub fn size_hint<W: ?Sized>(&mut self, id: &StrongWidget<W>, axis: Axis) -> Option<LayoutLen> {
if self.rsc.widgets().size_rules(id.id())[axis].bound != Bound::ANY { // A bound is composed into a request rather than applied to a hint,
return None; // so a bounded widget cannot say its length without being asked: what
} // it comes to is a comparison only the ask or the allocator makes.
let hint = self.rsc.widgets().exact_len(id.id(), axis); // A miss rather than no read at all, so the counters see it.
let bounded = self.rsc.widgets().size_rules(id.id())[axis].bound != Bound::ANY;
let hint = (!bounded)
.then(|| self.rsc.widgets().exact_len(id.id(), axis))
.flatten();
let rel_base = self.rel_base[axis]; let rel_base = self.rel_base[axis];
let resolved = hint.map(|hint| hint.within_len(rel_base)); let resolved = hint.map(|hint| hint.within_len(rel_base));
#[cfg(feature = "layout-diagnostics")] #[cfg(feature = "layout-diagnostics")]
+22 -22
View File
@@ -452,23 +452,34 @@ impl UiRenderState {
x: ruled(Axis::X, size.x), x: ruled(Axis::X, size.x),
y: ruled(Axis::Y, size.y), y: ruled(Axis::Y, size.y),
}; };
// A bound is a promise about the length as well as about the box: a // What the drawing read is combined with what the ask decided rather
// widget that drew past the box it was given -- a text too tall for // than replacing it: a widget may widen its own ranges, and cannot
// it, an image at its own size under a cap -- is still held to what // widen the ask's.
// its rule allows. let mut own_holds = own.and(info.ask_holds);
for axis in Axis::BOTH {
// A rule that is a fraction of the rel base is answered with the
// rel base's own length, so the answer is that rel base's and not
// just that many pixels of this window -- the same pin a widget
// that read its rel base took for its drawing. A bound counts:
// which side of it the box fell was decided against this rel
// base, and the same box of a different one can fall on the other.
if rules[axis].has_fraction() {
own_holds[axis].rel_base = Some(info.rel_base[axis]);
}
// A bound is a promise about the length as well as about the box:
// a widget that drew past the box it was given -- a text too tall
// for it, an image at its own size under a cap -- is still held to
// what its rule allows.
// //
// Held here rather than taken from the box, even where the bound // Held here rather than taken from the box, even where the bound
// decided that box. What a widget answers is its own, and a bound // decided that box. What a widget answers is its own, and a bound
// that replaced the answer would make a share into a fixed length // that replaced the answer would make a share into a fixed length
// the moment a box was long enough -- which is a length the span // the moment a box was long enough -- which is a length the span
// dividing that box decided from this answer, so the two would // dividing that box decided from this answer, so the two would
// choose each other. A share is left alone here for the same reason: // choose each other. A share is left alone here for the same
// it is a length only to whoever divides one, and the box that // reason: it is a length only to whoever divides one, and the box
// divider gives is a box this widget is asked in, where the bound is // that divider gives is a box this widget is asked in, where the
// applied to it. // bound is applied to it.
// Widgets may widen their own read ranges, but not the ask's constraints.
let mut own_holds = own.and(info.ask_holds);
for axis in Axis::BOTH {
let answer = size[axis]; let answer = size[axis];
if answer.leftover != Weight::ZERO { if answer.leftover != Weight::ZERO {
continue; continue;
@@ -479,17 +490,6 @@ impl UiRenderState {
size[axis] = held.into(); size[axis] = held.into();
} }
} }
// A rule that is a fraction of the rel base is answered with the
// rel base's own length, so the answer is that rel base's and not just
// that many pixels of this window -- the same pin a widget that read
// its rel base took for its drawing. A bound counts: which side of it
// the box fell was decided against this rel base, and the same box of
// a different one can fall on the other.
for axis in Axis::BOTH {
if rules[axis].has_fraction() {
own_holds[axis].rel_base = Some(info.rel_base[axis]);
}
}
// A widget that clipped its contents to its box drew nothing outside // A widget that clipped its contents to its box drew nothing outside
// it, so reporting more than the box asks to be placed at a length it // it, so reporting more than the box asks to be placed at a length it
// does not occupy -- and its parent would place the part it cut off. // does not occupy -- and its parent would place the part it cut off.
+1
View File
@@ -169,6 +169,7 @@ impl RequestArena {
let b = self.import(&pair.1, base); let b = self.import(&pair.1, base);
self.combine(op, a, b) self.combine(op, a, b)
} }
pub(crate) fn bounded(&mut self, request: RequestedLen, bound: Bound) -> RequestedLen { pub(crate) fn bounded(&mut self, request: RequestedLen, bound: Bound) -> RequestedLen {
let request = match bound.min { let request = match bound.min {
Some(min) => self.combine(Op::Max, request, min.into()), Some(min) => self.combine(Op::Max, request, min.into()),
+2 -20
View File
@@ -1,5 +1,5 @@
use crate::util::impl_axis_index; use crate::util::impl_axis_index;
use crate::{Axis, LayoutLen, Len, Rel, SizeRequest}; use crate::{LayoutLen, Len, Rel, SizeRequest, Weight};
/// A preferred length and independent bounds on one axis. Without a /// A preferred length and independent bounds on one axis. Without a
/// request, the widget's drawing supplies the preferred length. /// request, the widget's drawing supplies the preferred length.
@@ -45,10 +45,6 @@ impl SizeRule {
rule rule
} }
pub fn declared(&self) -> Option<Len> {
self.exact().and_then(|len| len.declared())
}
/// A linear preferred length, before applying the independent bounds. /// A linear preferred length, before applying the independent bounds.
pub fn exact(&self) -> Option<LayoutLen> { pub fn exact(&self) -> Option<LayoutLen> {
match self.request { match self.request {
@@ -63,7 +59,7 @@ impl SizeRule {
let request = self.request.as_ref()?; let request = self.request.as_ref()?;
match request { match request {
SizeRequest::Linear(len) SizeRequest::Linear(len)
if len.leftover == crate::Weight::ZERO || self.bound == Bound::ANY => if len.leftover == Weight::ZERO || self.bound == Bound::ANY =>
{ {
None None
} }
@@ -121,13 +117,6 @@ impl Bounds {
x: Bound::ANY, x: Bound::ANY,
y: Bound::ANY, y: Bound::ANY,
}; };
pub fn from_axes(f: impl Fn(Axis) -> Bound) -> Self {
Self {
x: f(Axis::X),
y: f(Axis::Y),
}
}
} }
impl_axis_index!(Bounds => Bound); impl_axis_index!(Bounds => Bound);
@@ -175,13 +164,6 @@ pub struct Declared {
impl Declared { impl Declared {
pub const NONE: Self = Self { x: None, y: None }; pub const NONE: Self = Self { x: None, y: None };
pub fn from_axes(f: impl Fn(Axis) -> Option<Len>) -> Self {
Self {
x: f(Axis::X),
y: f(Axis::Y),
}
}
} }
impl_axis_index!(Declared => Option<Len>); impl_axis_index!(Declared => Option<Len>);
+3 -3
View File
@@ -1,8 +1,8 @@
use std::sync::mpsc::{Receiver, Sender, channel}; use std::sync::mpsc::{Receiver, Sender, channel};
use crate::{ use crate::{
Axis, AxisAlign, IdLike, Len, RegionAlign, SizeRule, SizeRules, StrongWidget, WeakWidget, Axis, AxisAlign, IdLike, Len, RegionAlign, SizeRequest, SizeRule, SizeRules, StrongWidget,
Widget, WidgetData, WidgetId, WeakWidget, Widget, WidgetData, WidgetId,
util::{DynBorrower, HashSet, SlotVec, forget_mut, to_mut}, util::{DynBorrower, HashSet, SlotVec, forget_mut, to_mut},
}; };
@@ -146,7 +146,7 @@ impl Widgets {
} }
/// Changes the preferred length without changing its bounds. /// Changes the preferred length without changing its bounds.
pub fn set_len(&mut self, id: impl IdLike, axis: Axis, len: impl Into<crate::SizeRequest>) { pub fn set_len(&mut self, id: impl IdLike, axis: Axis, len: impl Into<SizeRequest>) {
let id = id.id(); let id = id.id();
let rule = SizeRule { let rule = SizeRule {
request: Some(len.into()), request: Some(len.into()),
+2 -8
View File
@@ -63,10 +63,7 @@ widget_trait! {
let len = len.into(); let len = len.into();
move |state| { move |state| {
let id = self.add(state); let id = self.add(state);
state state.ui_mut().widgets.set_len(id, Axis::X, len);
.ui_mut()
.widgets
.set_len(id, Axis::X, len);
id id
} }
} }
@@ -113,10 +110,7 @@ widget_trait! {
let len = len.into(); let len = len.into();
move |state| { move |state| {
let id = self.add(state); let id = self.add(state);
state state.ui_mut().widgets.set_len(id, Axis::Y, len);
.ui_mut()
.widgets
.set_len(id, Axis::Y, len);
id id
} }
} }
+45 -17
View File
@@ -1,17 +1,33 @@
//! CPU comparison of bounds attributes and the former wrapper, using the //! CPU comparison of a bounds attribute against the `MaxSize` wrapper it
//! same builder calls and geometry. Run the release executable under perf; //! replaced, using the same builder calls and the same geometry. The wrapper
//! process totals include the cold frame. MODE=plain|exact|cap, REDRAW=0|1. //! 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 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] #[test]
#[ignore = "instruction-count measurement"] #[ignore = "instruction-count measurement"]
fn bounds_cost() { fn bounds_cost() {
let mode = std::env::var("MODE").unwrap_or_else(|_| "cap".into()); let mode = env("MODE", "cap".to_string());
let redraw = std::env::var("REDRAW").is_ok_and(|value| value == "1"); let redraw = env("REDRAW", 0_u8) != 0;
let frames = std::env::var("FRAMES") let frames = env("FRAMES", 2000_usize);
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(2000);
let mut h = Harness::new((300, 512)); let mut h = Harness::new((300, 512));
let mut column = Span::empty(Dir::DOWN); let mut column = Span::empty(Dir::DOWN);
let mut leaves = Vec::new(); let mut leaves = Vec::new();
@@ -38,23 +54,35 @@ fn bounds_cost() {
ids.len(), ids.len(),
std::mem::size_of::<SizeRule>() std::mem::size_of::<SizeRule>()
); );
for frame in 0..frames { // That the fixture measures what it says is checked on both sides of the
if redraw { // crossing here rather than inside the measured loop, which is what the
for &id in &ids { // other rigs do. Per frame it measured only 0.65% of the total (5.780B
h.rsc.widgets_mut().mark_for_redraw(id); // against 5.743B instructions at MODE=cap, FRAMES=2000), but none of it
} // is the layout the number is about.
} for width in WIDTHS {
let width = if frame % 2 == 0 { 100 } else { 300 };
h.resize((width, 512)); h.resize((width, 512));
h.frame(); h.frame();
let expected = match mode.as_str() { let expected = match mode.as_str() {
"plain" => width / 2, "plain" => width / 2,
"exact" => 40, "exact" => 40,
"cap" => (width / 2).min(80), "cap" => (width / 2).min(80),
_ => unreachable!(), _ => unreachable!("the mode was checked while building"),
}; };
for id in &leaves { for id in &leaves {
assert_eq!(h.region(id).unwrap().size().x, Px::from_int(expected)); 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)); 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] #[test]
fn a_bound_holds_what_a_widget_answers() { 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 mut h = Harness::new((250, 200));
let left = rect(Color::RED).width(200).add(&mut h.rsc); let left = rect(Color::RED).width(200).add(&mut h.rsc);
let right = rect(Color::BLUE).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); let row = (left, right).span(Dir::RIGHT).add(&mut h.rsc);
h.rsc.widgets_mut().set_size_rule(row, Axis::X, rule); h.rsc.widgets_mut().set_size_rule(row, Axis::X, rule);
h.set_root(row); h.set_root(row);
( (h, row, left)
h.region(&row).unwrap().size().x,
h.region(&left).unwrap().size().x,
)
}; };
let (capped, left) = row(SizeRule::max(Len::px(300.0))); let (h, row, left) = bounded_row(SizeRule::max(Len::px(300.0)));
assert_eq!(capped, Px::from_int(300), "the cap, not the 400 drawn"); assert_eq!(
assert_eq!(left, Px::from_int(200), "the box the children were given"); 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))); let (h, row, _) = bounded_row(SizeRule::min(Len::px(600.0)));
assert_eq!(floored, Px::from_int(600), "the floor, not the 400 drawn"); assert_eq!(
h.region(&row).unwrap().size().x,
Px::from_int(600),
"the floor, not the 400 drawn"
);
let (free, _) = row(SizeRule::FREE); let (h, row, _) = bounded_row(SizeRule::FREE);
assert_eq!(free, Px::from_int(400), "what it drew"); 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] #[test]
fn a_cap_attribute_narrows_the_widgets_box() { fn a_cap_attribute_narrows_the_widgets_box() {
let mut h = Harness::new((400, 200)); 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 fills = rect(Color::RED).width(rel(1.0)).add(&mut h.rsc);
let capped = fills.max_width(300).add(&mut h.rsc); let capped = fills.max_width(300).add(&mut h.rsc);
assert_eq!(fills.id(), capped.id()); assert_eq!(fills.id(), capped.id());
h.set_root(capped); h.set_root(capped);
assert_eq!(h.region(&fills).unwrap().size().x, Px::from_int(300)); 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 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); let capped = share.max_width(300).add(&mut h.rsc);
assert_eq!(share.id(), capped.id());
h.set_root(capped); h.set_root(capped);
assert_eq!(h.region(&share).unwrap().size().x, Px::from_int(300)); 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)); 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 { struct Offered {
seen: Rc<Cell<PxVec2>>, seen: Rc<Cell<PxVec2>>,
answer: Size, answer: Size,
+3 -2
View File
@@ -1,3 +1,4 @@
mod rig;
#[path = "scenario/mod.rs"] #[path = "scenario/mod.rs"]
mod scenario; mod scenario;
@@ -5,8 +6,8 @@ use iris::prelude::*;
use iris::random::{Edits, Plan, plan}; use iris::random::{Edits, Plan, plan};
fn check_requests(edit: impl Fn(&mut Plan) + Sync) { fn check_requests(edit: impl Fn(&mut Plan) + Sync) {
let count = scenario::env("IRIS_DEFERRED_SEEDS", 20_u64); let count = rig::env("IRIS_DEFERRED_SEEDS", 20_u64);
let depth = scenario::env("IRIS_DEFERRED_DEPTH", 4_usize); let depth = rig::env("IRIS_DEFERRED_DEPTH", 4_usize);
let seeds = std::env::var("IRIS_DEFERRED_SEED") let seeds = std::env::var("IRIS_DEFERRED_SEED")
.ok() .ok()
.and_then(|seed| seed.parse().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` //! `IRIS_GENERATED_SEED`, `IRIS_GENERATED_SEEDS` and `IRIS_GENERATED_DEPTH`
//! select what the long run covers. //! select what the long run covers.
mod rig;
#[path = "scenario/mod.rs"] #[path = "scenario/mod.rs"]
mod scenario; mod scenario;
use iris::random::{Edits, Plan, plan}; 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 /// 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 /// 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` //! `IRIS_DIRTY` how many widgets `many` marks at once. `IRIS_UNBOUNDED=1`
//! removes intrinsic bounds while preserving the rest of the generated tree. //! removes intrinsic bounds while preserving the rest of the generated tree.
mod rig;
use iris::harness::Harness; use iris::harness::Harness;
use iris::prelude::*; use iris::prelude::*;
use iris::random::{Edits, Tree, build, plan}; use iris::random::{Edits, Tree, build, plan};
use rig::env;
use std::time::Instant; use std::time::Instant;
const OUTPUT: (f32, f32) = (1920.0, 1200.0); const OUTPUT: (f32, f32) = (1920.0, 1200.0);
@@ -94,13 +97,6 @@ fn a_selected_widget_retains_its_layout_events() {
diagnostics::clear_traced_widgets(); 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")] #[cfg(feature = "layout-diagnostics")]
fn trace_selected(tree: &Tree) { fn trace_selected(tree: &Tree) {
let Ok(value) = std::env::var("IRIS_TRACE_INDEX") else { 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 //! 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. //! in the diagnostics rig, which compares the two paths over the same shapes.
mod rig;
use iris::harness::Harness; use iris::harness::Harness;
use iris::random::{Edits, build, plan}; use iris::random::{Edits, build, plan};
use rig::env;
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)
}
#[test] #[test]
#[ignore = "a dump to diff across commits, not a check"] #[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 //! 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. //! row and frame counts. Wall time on this machine is not a stable comparison.
mod rig;
use iris::harness::Harness; use iris::harness::Harness;
use iris::prelude::*; use iris::prelude::*;
use rig::env;
use std::time::Instant; use std::time::Instant;
/// xorshift64, so one seed is one set of paragraphs on any machine. /// 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); 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 /// 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 /// overflowing text: the shape that makes a container measure a child in a
/// box it will not keep. /// 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. /// The window a tree is grown in, and the one a resize takes it to.
const OUTER: (f32, f32) = (1920.0, 1200.0); const OUTER: (f32, f32) = (1920.0, 1200.0);
const INNER: (f32, f32) = (640.0, 900.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 /// out by hand. A failure is a lead; the fast test that replaces it has to be
/// buildable from what the failure printed. /// buildable from what the failure printed.
fn describe(id: WidgetId, h: &Harness) -> String { fn describe(id: WidgetId, h: &Harness) -> String {
let rules = h.rsc.widgets().size_rules(id).clone(); let rules = h.rsc.widgets().size_rules(id);
let rule = |r: SizeRule| format!("{r:?}"); // 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 align = h.rsc.widgets().alignment(id);
let side = |a: AxisAlign| { let side = |a: AxisAlign| {
if a == AxisAlign::NEG { 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 // A rule and an alignment are properties of whatever carries them, so
// they print with that widget rather than as widgets of their own. // they print with that widget rather than as widgets of their own.
let mut out = describe_widget(id, h); let mut out = describe_widget(id, h);
if rules != SizeRules::default() { if *rules != SizeRules::default() {
out += &format!("[x:{},y:{}]", rule(rules.x), rule(rules.y)); out += &format!("[x:{},y:{}]", rule(&rules.x), rule(&rules.y));
} }
if align != RegionAlign::default() { if align != RegionAlign::default() {
out += &format!("@{},{}", side(align.x), side(align.y)); 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 //! 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. //! finds into a test of its own rather than leaving a seed as the record.
mod rig;
#[path = "scenario/mod.rs"] #[path = "scenario/mod.rs"]
mod scenario; mod scenario;
use iris::random::{Edits, Plan, plan}; 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 /// Takes the first simplification that still fails, until none does. The
/// simplifications come biggest first, so this walks down rather than /// simplifications come biggest first, so this walks down rather than