mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 01:28:53 +00:00
Previously, it was possible for rounding to result in small percentage constructs to be dropped entirely, breaking invariants. For example, when generating >100 entities, a 2% share should reliably be >=2. Some parts of source gen already propagated remainders to avoid exactly this issue, but we weren't propagating them everywhere, notably across depths and different definitions in plans. We fix this by introducing a helper for this more robust form of percent scaling that carries remainders across the slices. It also seeds this rounding from Phi across [0,100) to keep the edge cases uniformly distributed without causing instability from the source generator's seed. The seeded remainder doesn't impact providing the invariant, so the fix should be durable. Once this is done, we can shard the tests without the separate processes allowing the above failure mode to occur. Assisted-by: Antigravity with Gemini --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>