1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! Query language for AST-aware code search
//!
//! This module provides a powerful query language for searching code based on
//! semantic properties like symbol type, name patterns, language, and more.
//!
//! # Query Parsing
//!
//! All queries are parsed through the boolean AST parser:
//!
//! - **Boolean queries**: Parsed directly via [`QueryParser`](crate::query::QueryParser)
//! - **Execution**: Use [`QueryExecutor::execute_on_graph`](crate::query::QueryExecutor::execute_on_graph) for string queries
//!
//! ## Recommended Entry Points
//!
//! | Use Case | Function | Notes |
//! |----------|----------|-------|
//! | Query execution | [`QueryExecutor::execute_on_graph`](crate::query::QueryExecutor::execute_on_graph) | Most common - handles everything |
//! | AST access | [`QueryParser::parse_query`](crate::query::QueryParser::parse_query) | Boolean queries only |
//!
//! # Query Language
//!
//! The boolean query language supports:
//!
//! - **Boolean operators**: AND, OR, NOT
//! - **Comparison operators**: `:` (equal), `~=` (regex), `>`, `<`, `>=`, `<=`
//! - **Field types**: kind, name, path, lang, text, and plugin-specific fields
//! - **Values**: strings, regex patterns, numbers, booleans
//! - **Grouping**: parentheses for precedence
//!
//! # Core Types
//!
//! - [`Query`](crate::query::types::Query) - Complete query with root expression
//! - [`Expr`](crate::query::Expr) - Expression nodes (Or, And, Not, Condition)
//! - [`Condition`](crate::query::Condition) - Field-operator-value conditions
//! - [`Operator`](crate::query::Operator) - Comparison operators
//! - [`Value`](crate::query::Value) - Values in conditions
//!
//! # Error Handling
//!
//! All errors use [`QueryError`](crate::query::QueryError) which wraps:
//! - [`LexError`](crate::query::LexError) - Tokenization errors
//! - [`ParseError`](crate::query::ParseError) - Parsing errors
//! - [`ValidationError`](crate::query::ValidationError) - Semantic validation errors
//! - [`ExecutionError`](crate::query::ExecutionError) - Runtime execution errors
//!
//! # Performance
//!
//! The query lexer uses a thread-local buffer pool to reduce allocations:
//!
//! - **Allocation efficiency**: 80% fewer heap allocations vs creating fresh lexers
//! - **Memory efficiency**: Reuses token buffers across multiple tokenize calls
//! - **Thread-safe**: Each thread has its own isolated pool
//! - **Configurable**: Can be tuned or disabled via environment variables
//!
//! ## Lexer Pool Configuration
//!
//! The lexer pool can be configured via environment variables:
//!
//! ```bash
//! # Pool size (default: 4 lexers per thread)
//! export SQRY_LEXER_POOL_MAX=8
//!
//! # Buffer capacity limit (default: 256 tokens)
//! export SQRY_LEXER_POOL_MAX_CAP=512
//!
//! # Shrink ratio (default: 8x)
//! export SQRY_LEXER_POOL_SHRINK_RATIO=4
//!
//! # Disable pooling (for latency-critical workloads)
//! export SQRY_LEXER_POOL_MAX=0
//! ```
//!
//! **Performance characteristics**:
//! - Simple queries (<10 tokens): ~380ns (pooled) vs ~223ns (fresh) – pooling adds overhead
//! - Long queries (>100 tokens): ~18.2µs (pooled) vs ~19.1µs (fresh) – pooling saves ~4%
//! - High-throughput workloads: Pool reduces GC pressure and memory fragmentation
//!
//! **Recommendation**: Keep pooling enabled (default) for most workloads. The overhead
//! (~150ns per query) is negligible compared to typical query execution time (>10ms).
//! Disable only for latency-critical single-query scenarios.
//!
//! # Examples
//!
//! ```ignore
//! use sqry_core::query::QueryParser;
//!
//! // Find all async functions
//! let query = QueryParser::parse_query("kind:function AND async:true").unwrap();
//!
//! // Find test functions (using regex)
//! let query = QueryParser::parse_query("kind:function AND name~=/^test_/").unwrap();
//!
//! // Find functions OR methods in Rust files
//! let query = QueryParser::parse_query("(kind:function OR kind:method) AND lang:rust").unwrap();
//!
//! // Find non-test functions
//! let query = QueryParser::parse_query("kind:function AND NOT name~=/test/").unwrap();
//! ```
// Core query modules
// Boolean query language modules
// Existing exports
pub use QueryExecutor;
// CD Predicate exports (duplicate detection, cycle detection, unused analysis)
//
// Cycle detection (`CircularType` + `CircularConfig`) and unused-symbol
// detection (`UnusedScope`) have their *configuration types* in
// `cycles_config` / `unused_config`. The actual queries moved to
// `sqry-db` in Phase 3C DB15-DB19 (cached derived queries). The legacy
// `find_all_cycles_graph` / `is_node_in_cycle` / `find_unused_nodes` /
// `compute_reachable_set_graph` / `is_node_unused` functions were
// deleted in DB19 — all callers route through sqry-db.
pub use ;
pub use UnusedScope;
// Duplicate detection still lives in the executor (DB20 scope).
pub use build_duplicate_groups_graph;
pub use ;
pub use RepoFilter;
// New exports
pub use ;
pub use ;
pub use Optimizer;
pub use ParsedQuery;
pub use Parser as QueryParser;
pub use ;
pub use ;
pub use ;
pub use ;
// Pipeline/aggregation results
pub use ;
// Pipeline execution
pub use execute_pipeline_stage;
// Builder API exports (P2-10)
pub use ;
// CodeGraph-native query results (v6)
pub use ;