Expand description
Structural-mode analysis: the whole Type-2/Type-3 pipeline, wired end to end over already-parsed IR.
The stages each live in their own module; this one composes them into the funnel the mode runs:
crate::featuresturns each file’s IR into candidate-extraction features (statement windows, subtrees, characteristic vector, approximate CFG, API calls);crate::candidateseeds exact-hash fragment pairs andcrate::near_matchproposes near-clone unit pairs by MinHash/LSH — both over-approximate cheaply, and both are lifted here to unit pairs;crate::maximalfolds the sliding-window seeds back into the maximal shared statement runs they describe, so a duplicated block is one region rather than a fan of overlapping window matches;crate::verifyjudges each distinct unit pair precisely, keeping only the ones that clear the clone threshold;crate::groupingturns the surviving pairs into cohesive medoid groups, so non-transitive Type-3 chains do not fuse.
Regions and groups answer different questions and neither replaces the other: a group says two whole units are copies of each other, a region says one stretch of statements is shared, which happens between units that are not copies at all.
Every unit carries its raw UnitFingerprint as its stable, position-free
grouping key (crate::stable_id). The whole function is deterministic: the
unit order follows the IR walk, candidate pairs are deduplicated through an
ordered set, and grouping orders its own output. Nothing here executes target
code — it only reads IR that was already produced from source.
Structs§
- Body
Materiality - Material operations shared by every member of a structural clone group.
- Cross
Variant Comparison - The result of an explicit cross-build-variant comparison.
- Cross
Variant Group - One exact group found across independent build variants.
- Cross
Variant Member - A member of a cross-build-variant exact clone group.
- Cross
Variant Unit - One unit offered to an explicit build-variant comparison.
- Group
Detail - Reporting detail for one clone group, parallel to the group at the same
index in
StructuralReport::groups. - Group
Siblings - Siblings of one primary group, addressed by its index in
StructuralReport::groups. - Region
Occurrence - One occurrence of a duplicated statement run, resolved against the source it was found in.
- Resolved
Types - What a compiler resolved about the files being analysed.
- Sibling
Config - Tuning for the post-grouping sibling sweep.
- Sibling
Sweep Stats - Counters for the bounded post-grouping sibling sweep.
- Source
Token Span - A half-open token span in one
SyntaxIrFile. - Structural
Config - Tuning for a whole structural run: one config per stage.
- Structural
Near Miss - One LSH-proposed unit pair that passed the size gate but landed inside the bounded estimate band immediately below the primary near-match threshold.
- Structural
Region - A duplicated run of statements and every place it occurs.
- Structural
Report - The structural run’s output: cohesive groups over
Self::units, plus the funnel statistics. - Structural
Sibling - One incomplete local mirror attached to an established primary group.
- Structural
Stats - Funnel counters across the whole run: how many fragments, candidate pairs and verified pairs each stage saw.
- Structural
Unit - One analysed unit, kept so a caller can map a group’s member indices back to
source locations. The index of a unit in
StructuralReport::unitsis the index grouping refers to. - Verified
Pair - A verified clone relation between two contents that no reported group could hold.
Constants§
- DEFAULT_
MAX_ SHAPE_ DIVERGENCE - Default largest shape-mix divergence a candidate pair may span.
- DEFAULT_
VERIFICATION_ BUDGET - Largest number of distinct unit pairs the precise verifier may inspect.
Functions§
- analyze
- Run the structural pipeline over parsed IR files.
- analyze_
resolved analyzewith what a compiler resolved about the same files.- compare_
build_ variants - Compare exact whole units across C/C++ build partitions.
- span_
identifier_ jaccard - The weakest raw identifier-set agreement between a canonical span and its corresponding spans.