docs: state unwritten contracts in doc comments#236
Closed
cameroncuster wants to merge 1 commit into
Closed
Conversation
ff18425 to
c59a2be
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.
Documents unwritten contracts — preconditions the code relies on but the
//!doc comments didn't state. Comment-only change (0 code lines touched), plus two line-pin bumps in the cppcheck suppression list.Each contract was verified against the exact line that breaks if it's violated:
graphs/dijkstra.hpprequires weights >= 0strings/binary_trie.hpprequires 0 <= num < 2^61;walk requires a non-empty triemath/mod_division.hpprequires gcd(y, mod) == 1math/matrix_related/row_reduce.hpprequires mod is primemath/matrix_related/matrix_mult.hppwatch for overflow if T is an integer typegraphs/uncommon/enumerate_triangles.hpprequires no self loops or multi edgestiecomparison degenerate; multi-edges double-countloops/submasks.hppexcludes the empty submasksubmask;stops before 0 — easy 4am surprisemath/derangements.hpprequires n >= 1dp[0] = 1on empty vector is UBstrings/kmp.hpprequires t non-emptypi[j - 1]with j==sz(t)==0 reads pi[-1]trees/hld.hppg is mutated (parent edges removed)trees/centroid_decomp.hppg is mutated (edges removed)trees/edge_cd.hppg is mutated (edges reordered/removed)Findings that were considered and deliberately NOT documented (checked against the code):
vector<basic_string<int>> g(n)usage blocks already imply the shapeassert(l < r)— enforced by an assert already in the code, self-documenting0 <= s[i] < max_num— already documented in that header1 <= n <= m— already documented (1<=i<=n<=m)vector dp(0)+ non-executing loop is fine; "xor_convolution power-of-2 undocumented" — it's in the @code block)Validation:
--dry-run --Werrorpasses on all changed filesgrep_clangformat_cppcheck.shpasses