Skip to main content

Module structural

Module structural 

Source
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:

  1. crate::features turns each file’s IR into candidate-extraction features (statement windows, subtrees, characteristic vector, approximate CFG, API calls);
  2. crate::candidate seeds exact-hash fragment pairs and crate::near_match proposes near-clone unit pairs by MinHash/LSH — both over-approximate cheaply, and both are lifted here to unit pairs;
  3. crate::maximal folds 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;
  4. crate::verify judges each distinct unit pair precisely, keeping only the ones that clear the clone threshold;
  5. crate::grouping turns 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§

BodyMateriality
Material operations shared by every member of a structural clone group.
CrossVariantComparison
The result of an explicit cross-build-variant comparison.
CrossVariantGroup
One exact group found across independent build variants.
CrossVariantMember
A member of a cross-build-variant exact clone group.
CrossVariantUnit
One unit offered to an explicit build-variant comparison.
GroupDetail
Reporting detail for one clone group, parallel to the group at the same index in StructuralReport::groups.
GroupSiblings
Siblings of one primary group, addressed by its index in StructuralReport::groups.
RegionOccurrence
One occurrence of a duplicated statement run, resolved against the source it was found in.
ResolvedTypes
What a compiler resolved about the files being analysed.
SiblingConfig
Tuning for the post-grouping sibling sweep.
SiblingSweepStats
Counters for the bounded post-grouping sibling sweep.
SourceTokenSpan
A half-open token span in one SyntaxIrFile.
StructuralConfig
Tuning for a whole structural run: one config per stage.
StructuralNearMiss
One LSH-proposed unit pair that passed the size gate but landed inside the bounded estimate band immediately below the primary near-match threshold.
StructuralRegion
A duplicated run of statements and every place it occurs.
StructuralReport
The structural run’s output: cohesive groups over Self::units, plus the funnel statistics.
StructuralSibling
One incomplete local mirror attached to an established primary group.
StructuralStats
Funnel counters across the whole run: how many fragments, candidate pairs and verified pairs each stage saw.
StructuralUnit
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::units is the index grouping refers to.
VerifiedPair
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
analyze with 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.