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§
- ApiCall
Feature - The API-call profile of one unit.
- CfgFeature
- The approximate control-flow profile of one unit.
- Characteristic
Vector - Shape-tag counts plus tree size and depth: a candidate filter.
- Feature
Hash - A 128-bit feature hash.
- File
Features - The features of every unit in one file, in pre-order source order.
- Subtree
Feature - One subtree fingerprint: a Merkle hash over an IR subtree.
- Unit
Features - The candidate-extraction features of one unit.
- UnitRef
- A reference to one unit inside a slice of
FileFeatures. - Window
Feature - One statement window: a fixed-length run of adjacent statements inside one block, hashed from per-statement summaries.
Enums§
- Feature
Kind - 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
SubtreeFeatureto be emitted. Smaller subtrees are ubiquitous and would only inflate the candidate index. - SHAPE_
TAG_ SLOTS - Number of slots in
CharacteristicVector::counts: one perShapetag, 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.