Repository navigation
Fix UnionWeight constructed or populated with non-member elements. - #343
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
copybara/994352243
branch
from
October 7, 2026 15:23
9c2de3a to
7f8c7f3
Compare
`UnionWeight<W, O>` represents the empty set (`Zero()`) with `!first_.Member()` and `rest_.empty()`, and represents `NoWeight()` (`UnionWeight(W::Zero(), W::NoWeight())`) with `first_ = W::Zero()` and `rest_ = {W::NoWeight()}`. However, constructing `UnionWeight(W weight)` from a non-member `weight` or calling `PushBack(weight, srt)` with a non-member `weight` on an empty `UnionWeight` left `!first_.Member()` while pushing `NoWeight()` to `rest_`. Because `Size()` returns `0` and `UnionWeightIterator::Done()` is immediately `true` when `!first_.Member()`, such weights reported `Member() == true`, compared equal to `Zero()`, printed as `"EmptySet"` instead of `"BadSet"`, and failed to propagate `NoWeight()` in `Plus`, `Times`, `Divide`, `Quantize`, `Reverse`, and `Write`.
- In `UnionWeight(W weight)` and `UnionWeight::PushBack`, set `first_ = W::Zero()` when `!weight.Member()` and `!first_.Member()`, matching `UnionWeight::NoWeight()`.
- In `UnionWeight::Member()`, check `if (!first_.Member()) return rest_.empty();` and verify `w.Member()` across `rest_`.
PiperOrigin-RevId: 995132105
copybara-service
Bot
force-pushed
the
copybara/994352243
branch
from
October 7, 2026 15:42
7f8c7f3 to
cbd6624
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
UnionWeightconstructed or populated with non-member elements.UnionWeight<W, O>represents the empty set (Zero()) with!first_.Member()andrest_.empty(), and representsNoWeight()(UnionWeight(W::Zero(), W::NoWeight())) withfirst_ = W::Zero()andrest_ = {W::NoWeight()}. However, constructingUnionWeight(W weight)from a non-memberweightor callingPushBack(weight, srt)with a non-memberweighton an emptyUnionWeightleft!first_.Member()while pushingNoWeight()torest_. BecauseSize()returns0andUnionWeightIterator::Done()is immediatelytruewhen!first_.Member(), such weights reportedMember() == true, compared equal toZero(), printed as"EmptySet"instead of"BadSet", and failed to propagateNoWeight()inPlus,Times,Divide,Quantize,Reverse, andWrite.UnionWeight(W weight)andUnionWeight::PushBack, setfirst_ = W::Zero()when!weight.Member()and!first_.Member(), matchingUnionWeight::NoWeight().UnionWeight::Member(), checkif (!first_.Member()) return rest_.empty();and verifyw.Member()acrossrest_.