Skip to main content

Module verify

Module verify 

Source
Expand description

Structural-mode weighted verification: the precise judgment of a candidate pair.

The candidate stages (crate::candidate, crate::near_match) propose pairs cheaply and over-approximate; this stage decides. It compares two units across several independent dimensions, keeps every dimension’s score rather than collapsing to one opaque number (AGENTS.md §22), and only then forms a composite and a clone classification.

The dimensions:

  • lexical — how much of the aligned statements’ text matches verbatim; separates a verbatim copy from a renamed one;
  • structural — the statement-summary alignment (a rename-invariant LCS) folded with the characteristic-vector cosine and the subtree overlap;
  • control flow — the approximate control-flow profiles (a syntactic approximation, refined by a real CFG in Semantic mode);
  • type — how much the two units’ resolved types agree, as crate::types::TypeEvidence. Unavailable in Structural mode, which resolves no types: the dimension is then None and the classification’s confidence is penalised accordingly rather than guessing. Supplying evidence for both sides is what lifts that penalty, and only a compiler can supply it;
  • api — how much the two call surfaces overlap. Semantic mode uses compiler-resolved targets when both units have them; otherwise it retains Structural mode’s call-name comparison. It is unavailable when neither unit calls anything, since two empty call surfaces are an absence of evidence rather than agreement.

Alignment is a by-product: the LCS backtrace records which statements matched and which are unique to each side, which is the diff explain shows. The composite weights are configurable and versioned (WEIGHT_VERSION), and that version travels with the detector identity (AGENTS.md §2-4) so two results can be compared knowing which weights produced them. Changing the weights changes findings, and before the first release that invalidates the results recorded under the old ones rather than raising the version, which stays at v1. Everything here is a pure function of its inputs.

§What the composite can and cannot separate

The acceptance threshold is what separates clones from lookalikes, and the labelled corpora bound how well it can: functions written to share a skeleton while computing different things score up to 0.69, and the weakest pair that is a real copy scores 0.71. VerifyConfig::type3_min_composite sits between them.

Two properties of that gap are worth stating, because they decide where future accuracy work belongs.

First, lexical is the dimension that discriminates. Lookalikes agree on shape by construction — that is what makes them lookalikes — so structural and control-flow agreement is high for both populations and only lexical agreement pulls them apart. Weighting shape more heavily than text therefore costs precision rather than buying it, and no reweighting of these five dimensions separates the two populations by more than a hair unless lexical is the one carrying the weight.

Second, a unit can be a genuine clone and still not be worth reporting. Two one-line accessors are copies of each other by every measure in this module, and they score accordingly. Suppressing them is crate::boilerplate’s job, not this one’s: lowering a similarity score to hide a triviality would corrupt the evidence the score exists to carry.

Structs§

Alignment
The statement alignment behind a verdict: the diff explain renders.
SimilarityBreakdown
The per-dimension similarity scores and their composite.
UnitView
One unit’s inputs to verification: its flattened statement sequence, the token stream those statements span, and its extracted features.
Verdict
The outcome of verifying a candidate pair.
VerifyConfig
Tuning for verification. Thresholds are provisional and calibrated against the mutation corpus.
Weights
Relative weights of the similarity dimensions in the composite score.

Enums§

Confidence
How far past the acceptance threshold a finding’s composite similarity sits.

Constants§

WEIGHT_VERSION
Version of the composite-weight recipe and judgment rules. Bump it when any weight default or classification rule changes, since findings change with it. Recorded as a detector version.

Functions§

statement_sequence
Flatten a unit subtree into its statement summaries, in pre-order: each block contributes its direct statements before its nested blocks do.
verify
Verify a candidate pair, producing its similarity breakdown, alignment and clone classification.