fix(analysis): count elements the way the client-checked OverPy counter does - #308
Merged
Merged
Conversation
…er does The element count was 37% below the client on a production project. Number literals, constants that wrap a literal, variable reads, comparison operators, omitted defaulted arguments, and the Else If, Else and End actions were undercounted, and disabled rules, actions and conditions made the whole program uncountable. Derive the missing costs from OverPy's per-action #!debugElementCount on 2867 actions of that project, count disabled actions and conditions like enabled ones, count hero pairs per direct argument, and keep the closing End of loops and subroutine rules while an If left open at the end of any other rule is not counted. Every action and rule count now equals OverPy's, and the total is 30067, OverPy's own figure. Document the model and its evidence in element-count.md and reproduce one rule per case in the tests. Fixes #305
Teakowa
requested changes
Sep 26, 2026
Teakowa
left a comment
Contributor
There was a problem hiding this comment.
One blocking count-model issue.
…ter writes it The count omitted the closing End of any final If in a non-subroutine rule and kept it in subroutine rules and, through nested last Ifs, elsewhere. The countable program does not record whether a trailing End was written, so a written and an omitted End are one program. Follow the canonical emitter: only the last action of a rule, when it is an If, is closed without End, in every rule. Nested blocks, While and For keep theirs. Add tests that a written and an omitted trailing End cost the same, that only the last action is closed without End, and that the count of a program equals the count of its emitted text. State the eight rules where the count differs from OverPy on the calibration project.
Teakowa
approved these changes
Sep 26, 2026
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.
Fixes #305.
Program::element_countwas about 37% below the client on a production project (OWBastion/Bastion, zh-CNmain): 18891 against the client's 30070 for the OverPy build, whose own counter says 30067. The model now reproduces OverPy's figure to within 2 elements.What changed
Derived by comparing every action and condition of that project against pinned OverPy 9.7.10's
#!debugElementCount(2867 leaf actions, 309 rules), then fitting the missing costs:Team,Hero,Color,ButtonandMapconstants likewise;Custom Stringhas three replacement slots);Else If,ElseandEndare actions; the count follows the canonical emitter, which closes the last action of a rule withoutEndwhen it is anIfand keeps every otherEnd(a written and an omitted trailingEndare one program);Evidence
On the project's
mainentry every action count equals OverPy's and the total is 30065 against OverPy's 30067. Eight rules differ by one where the emitter'sEndspelling differs from OverPy's (documented indocs/element-count.md). The client counted OverPy's build at 30070; the three elements of difference are not explained. The model is calibrated on this one project; constructs it does not exercise follow the Workshop.codes reference.docs/element-count.mdstates this, andtests/element_count.rsreproduces ten small OverPy-counted programs, one rule each.Verification
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace --all-targets,workshop-catalog-gen check,git diff --check. The full-project comparison was run locally against OverPy's annotated output; the project source is not part of this repository.Counts for existing programs change, so consumers that pinned a total will see different numbers.