Skip to main content

Module features

Module features 

Source
Expand description

Structural-mode candidate-extraction features over the Syntax IR.

Structural mode never compares whole units pairwise — that is quadratic in corpus size. Instead every unit (function, method, closure) is reduced to a set of cheap per-unit features, and candidate pairs are proposed only where features collide or lie close. One pass over a SyntaxIrFile extracts four feature families per unit:

  • statement windows (WindowFeature): hashes of fixed-length runs of adjacent statements, the fragment-level candidate signal;
  • subtree fingerprints (SubtreeFeature): Merkle hashes over the IR tree, the exact structural-match signal;
  • a characteristic vector (CharacteristicVector): shape-tag counts used as a cheap candidate filter;
  • an approximate control-flow profile (CfgFeature) and an API-call profile (ApiCallFeature).

§Rename invariance

Candidate extraction must survive Type-2 edits, so no identifier text and no literal text enters any hash, with one deliberate exception: API-call names. Lexical signal comes exclusively from token kind tags (TokenKind::tag) and shape tags (Shape::tag). API-call names are exempt because external API names are normalization-exempt, matching the Fast engine’s treatment of external names.

§The control-flow profile is syntactic

CfgFeature is a syntactic approximation built from AST control shapes, not a real control-flow graph: it linearises loop, branch and match nesting plus control statements in source order. A compiler-provided CFG can replace it behind the same feature interface in a later phase; doing so changes feature derivation and therefore bumps FEATURE_SCHEMA_VERSION.

§Determinism

Every output is derived from source order alone; no hash-map iteration order reaches any feature. Extracting twice from the same IR yields identical results.

Structs§

ApiCallFeature
The API-call profile of one unit.
CfgFeature
The approximate control-flow profile of one unit.
CharacteristicVector
Shape-tag counts plus tree size and depth: a candidate filter.
FeatureHash
A 128-bit feature hash.
FileFeatures
The features of every unit in one file, in pre-order source order.
SubtreeFeature
One subtree fingerprint: a Merkle hash over an IR subtree.
UnitFeatures
The candidate-extraction features of one unit.
UnitRef
A reference to one unit inside a slice of FileFeatures.
WindowFeature
One statement window: a fixed-length run of adjacent statements inside one block, hashed from per-statement summaries.

Enums§

FeatureKind
The kind of a persisted feature hash.

Constants§

FEATURE_SCHEMA_VERSION
Version of the feature-derivation recipe.
MIN_SUBTREE_NODES
Minimum subtree size, in nodes (the subtree root included), for a SubtreeFeature to be emitted. Smaller subtrees are ubiquitous and would only inflate the candidate index.
SHAPE_TAG_SLOTS
Number of slots in CharacteristicVector::counts: one per Shape tag, with slot 0 unused because tags start at 1.
WINDOW_LENGTHS
Statement-window lengths, in statements. Windows slide with stride 1 over each block’s statement sequence; a block shorter than a length yields no window of that length.

Functions§

extract
Extract the candidate features of every unit in file.