1use crate::error_kinds::TckErrorClass;
46
47use crate::Error;
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52pub enum ParseOption {
53 ObfuscatedLiterals,
54 MixedLabelSyntax,
55 CypherAnnotations,
56 PathConstruction,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
62pub enum DetectorKind {
63 HybridSearch,
64 LocalCallables,
65 Float16,
66 PathConstruction,
67 Chronological,
68}
69
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
76pub enum GateSite {
77 ParseOption(ParseOption),
79 AstDetector(DetectorKind),
81 GraphTypeMembership,
85 NameAdmission,
87 ProcedureDispatch,
89 Namespace,
91 GatedElsewhere,
94}
95
96macro_rules! preview_feature_registry {
102 ($(($variant:ident, $doc:literal, $name:literal, [$($site:expr),* $(,)?])),* $(,)?) => {
103 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
106 pub enum PreviewFeature {
107 $(
108 #[doc = $doc]
109 $variant,
110 )*
111 }
112
113 pub const PREVIEW_FEATURE_TABLE: &[(PreviewFeature, &str)] =
117 &[$((PreviewFeature::$variant, $name)),*];
118
119 pub const PREVIEW_FEATURES: &[PreviewFeature] = &[$(PreviewFeature::$variant),*];
122
123 const _: () = assert!([$(stringify!($variant)),*].len() <= 32);
127
128 impl PreviewFeature {
129 pub fn kebab_name(self) -> &'static str {
133 match self {
134 $(PreviewFeature::$variant => $name,)*
135 }
136 }
137
138 pub fn gate_sites(self) -> &'static [GateSite] {
140 match self {
141 $(PreviewFeature::$variant => &[$($site),*],)*
142 }
143 }
144
145 pub fn from_kebab_name(name: &str) -> Option<Self> {
148 match name {
149 $($name => Some(PreviewFeature::$variant),)*
150 _ => None,
151 }
152 }
153 }
154 };
155}
156
157preview_feature_registry! {
158 (HybridSearch, "CIP-278 hybrid search `COMBINE` (reserved; lands later).", "hybrid-search", [GateSite::AstDetector(DetectorKind::HybridSearch)]),
159 (LocalCallables, "CIP-231 local callables: DEFINE PROCEDURE/FUNCTION, ADR-0382.", "local-callables", [GateSite::AstDetector(DetectorKind::LocalCallables)]),
160 (GraphTypeOptProps, "CIP-283 graph-type optional properties (`prop :: ANY` in element types).", "graph-type-opt-props", [GateSite::GraphTypeMembership]),
161 (GraphTypeDefaultValues, "CIP-262 graph-type property default values (`DEFAULT ON COMMIT <value expression>`).", "graph-type-default-values", [GateSite::GraphTypeMembership]),
162 (GraphTypeImpliedLabels, "CIP-266 graph-type implied labels that identify node element types (inheritance).", "graph-type-implied-labels", [GateSite::GraphTypeMembership]),
163 (
164 Ontology,
165 "The ontology feature's whole dialect surface: the `db.ontology.*` procedures \
166 (ADR-0378: the first non-syntax extension of ADR-0371's scope policy — the \
167 family's contract tracks the non-final Ontology Graph Spec and CIP-287) and, \
168 through the namespace registry's mapping, the `system_ontologies` namespace's \
169 visibility (ADR-0593 — the namespace exists to host this feature's stored \
170 document, so its listing advertises the same non-final surface the procedures \
171 do). Row, mapping and gates are removed once the spec and CIP-287 are final.",
172 "ontology",
173 [GateSite::ProcedureDispatch, GateSite::Namespace]
174 ),
175 (
176 ObfuscatedLiterals,
177 "The Neo4j obfuscated literal `******`: parsed to a dummy `false` \
178 for semantic analysis, never executed. Gates at the lexer, the one point the two \
179 behaviors differ: enabled it lexes as a literal, disabled the stream is the ordinary \
180 `*` tokens and the parser's own syntax error -- Neo4j's disabled form is a syntax \
181 error, not ADR-0371's authored preview error, so the gate never reaches the front \
182 detector loop (the registry names no detector site for it).",
183 "obfuscated-literals",
184 [GateSite::ParseOption(ParseOption::ObfuscatedLiterals)]
185 ),
186 (
187 MixedLabelSyntax,
188 "Neo4j's mixed-label-syntax extra semantic feature: legacy \
189 colon-conjunction, GQL label-expression symbols and the `IS` introducer may mix \
190 across the label expressions of one clause (gates at parse, threaded to the parser \
191 as `ParseOptions`; mixing inside ONE label expression stays rejected).",
192 "mixed-label-syntax",
193 [GateSite::ParseOption(ParseOption::MixedLabelSyntax)]
194 ),
195 (
196 Float16CoordinateTypes,
197 "The FLOAT16/BFLOAT16 vector coordinate types (CIP-280, ADR-0464), mirroring \
198 Neo4j's own configuration toggle: the types in a \
199 `VECTOR<…>` type expression and the `vector(<list>, <dim>, <type>)` constructor. \
200 Detected on the parsed AST; the disabled form is ADR-0371's authored error.",
201 "float16-coordinate-types",
202 [GateSite::AstDetector(DetectorKind::Float16)]
203 ),
204 (
205 ChronologicalComparisons,
206 "Cypher 25's four chronological comparison operators \
207 (`a IS [NOT] BEFORE | AFTER | SAME INSTANT | SAME REPRESENTATION b`), mirroring \
208 Neo4j's own toggle. Detected on the \
209 parsed AST; the disabled form is ADR-0371's authored error.",
210 "chronological-comparisons",
211 [GateSite::AstDetector(DetectorKind::Chronological)]
212 ),
213 (
214 CollectionZip,
215 "CIP-274: the `coll.zip` collection function, callable and \
216 `SHOW`-listed only under this opt-in (ADR-0497). A live Neo4j probe \
217 records the name as front-end registered but unreachable \
218 -- no `SHOW FUNCTIONS` row, 42N48 under CYPHER 5 and 25 -- so the default dialect must \
219 not advertise it. Row and gate are deleted when a Neo4j release ships the function.",
220 "coll-zip",
221 [GateSite::NameAdmission]
222 ),
223 (
224 CollectionHas,
225 "CIP-286: the `coll.hasAnyOf`/`coll.hasAllOf`/\
226 `coll.hasNoneOf` collection functions, callable and `SHOW`-listed only under this \
227 opt-in (ADR-0497). One row for the three-name family; deleted when CIP-286 ships.",
228 "coll-has",
229 [GateSite::NameAdmission]
230 ),
231 (
232 CypherAnnotations,
233 "CIP-281 Cypher annotations: clause-level `@name(params)` markers before a \
234 clause, parsed and semantically checked, then discarded (no runtime effect). \
235 Gates at the lexer, the one point the two behaviors differ: enabled, `@` lexes \
236 as the annotation introducer; disabled, it is the ordinary `unexpected \
237 character: @` syntax error. Row and gate are deleted when the CIP ships in a \
238 release.",
239 "cypher-annotations",
240 [GateSite::ParseOption(ParseOption::CypherAnnotations)]
241 ),
242 (
243 GqlStddevAliases,
244 "CIP-245's `stddev_samp`/`stddev_pop` spellings (ADR-0497): the corpus catalogue lists \
245 only the canonical `stdev_samp`/`stdev_pop`, and Neo4j 2026.05 answers 42N48 for the \
246 GQL spellings, so the default dialect advertises and dispatches only the `stdev_*` \
247 rows. The gate keeps the `@doc`-derived 78/78 reachable. Deleted when a release \
248 registers the spellings (or the scenarios are re-pinned).",
249 "gql-stddev-aliases",
250 [GateSite::NameAdmission]
251 ),
252 (
253 GraphTypeShowVariants,
254 "CIP-275 graph-type display variants of SHOW CURRENT GRAPH TYPE: consolidated and flattened.",
255 "graph-type-show-variants",
256 [GateSite::GraphTypeMembership]
257 ),
258 (
259 PathConstruction,
260 "The `PATH [n1, r1, n2, ...]` path constructor: builds a path value from an \
261 alternating node, relationship, ... list. Detected at the parse point (the \
262 `PATH` word before `[`); the disabled form is ADR-0371's authored error.",
263 "path-construction",
264 [GateSite::ParseOption(ParseOption::PathConstruction), GateSite::AstDetector(DetectorKind::PathConstruction)]
265 ),
266 (
267 PathConcatenation,
268 "The `p1 || p2` path concatenation: joins two paths that share a boundary \
269 node. Gates the `||` operator over path operands at evaluation; the disabled \
270 form is the existing `||` operand type error, not the authored error.",
271 "path-concatenation",
272 [GateSite::GatedElsewhere]
273 ),
274 (
275 VortexStore,
276 "The Vortex columnar property store (ADR-0665), experimental: an \
277 alternative storage representation behind the executor's PropStore \
278 seam. The registry's first storage-representation row (ADR-0703): \
279 the gate is at `Database::open`, not at a parse or dispatch site — \
280 the row attaches the store for every open in the process (the typed \
281 `OpenOptions::vortex_store` field opts in one open), and a build \
282 without the `vortex-store` cargo feature fails the open closed \
283 naming the feature. While disabled nothing changes: the default \
284 compact records answer, and no statement can ask for the store, so \
285 there is no authored disabled-error.",
286 "vortex-store",
287 [GateSite::GatedElsewhere]
288 ),
289}
290
291fn known_feature_names() -> String {
294 PREVIEW_FEATURE_TABLE
295 .iter()
296 .map(|(_, name)| *name)
297 .collect::<Vec<_>>()
298 .join(", ")
299}
300
301#[derive(Debug, Clone, Copy, PartialEq, Eq)]
305pub struct PreviewFeatures(u32);
306
307impl Default for PreviewFeatures {
312 fn default() -> Self {
313 Self::none()
314 }
315}
316
317impl PreviewFeatures {
318 pub fn none() -> Self {
320 Self(0)
321 }
322
323 pub fn parse(raw: &str) -> Result<Self, Error> {
329 if raw.trim().is_empty() {
330 return Ok(Self::none());
331 }
332 let mut enabled = Self(0);
333 for name in raw.split(',') {
334 let name = name.trim();
335 let feature = PreviewFeature::from_kebab_name(name).ok_or_else(|| {
336 Error::semantic(format!(
337 "{}: invalid RELATE_PREVIEW value: unknown preview feature \
338 '{name}' (known features: {})",
339 TckErrorClass::SemanticError.as_str(),
340 known_feature_names(),
341 ))
342 })?;
343 enabled.0 |= 1 << (feature as u32);
345 }
346 Ok(enabled)
347 }
348
349 pub fn enabled(self, feature: PreviewFeature) -> bool {
353 self.0 & (1 << (feature as u32)) != 0
354 }
355
356 pub fn with_feature(self, feature: PreviewFeature) -> Self {
360 Self(self.0 | (1 << (feature as u32)))
361 }
362
363 pub fn require(self, feature: PreviewFeature) -> Result<(), Error> {
366 if self.enabled(feature) {
367 Ok(())
368 } else {
369 Err(preview_feature_disabled(feature))
370 }
371 }
372}
373
374pub fn preview_feature_disabled_text(feature: PreviewFeature) -> String {
383 let name = feature.kebab_name();
384 format!(
385 "{}: preview feature '{name}' is not enabled: set RELATE_PREVIEW={name}",
386 TckErrorClass::SemanticError.as_str(),
387 )
388}
389
390pub(crate) fn preview_feature_disabled(feature: PreviewFeature) -> Error {
395 Error::semantic(preview_feature_disabled_text(feature))
396}
397
398#[cfg(test)]
399mod tests {
400 use super::*;
401
402 #[test]
403 fn registry_names_are_unique_and_round_trip() {
404 let mut seen = std::collections::HashSet::new();
409 for (feature, name) in PREVIEW_FEATURE_TABLE {
410 assert_eq!(feature.kebab_name(), *name);
411 assert!(seen.insert(*name), "duplicate name {name}");
412 assert_eq!(PreviewFeature::from_kebab_name(name), Some(*feature));
413 }
414 assert_eq!(PreviewFeature::from_kebab_name("nope"), None);
415 }
416
417 #[test]
418 fn every_row_declares_a_gate_site() {
419 for feature in PREVIEW_FEATURES {
422 assert!(
423 !feature.gate_sites().is_empty(),
424 "{} declares no gate site",
425 feature.kebab_name()
426 );
427 }
428 }
429
430 #[test]
431 fn gate_sites_never_repeat_within_a_row() {
432 for feature in PREVIEW_FEATURES {
433 let mut seen = std::collections::HashSet::new();
434 for site in feature.gate_sites() {
435 assert!(
436 seen.insert(*site),
437 "{} repeats {site:?}",
438 feature.kebab_name()
439 );
440 }
441 }
442 }
443
444 #[test]
445 fn parse_empty_and_unset_value_enable_nothing() {
446 assert_eq!(PreviewFeatures::parse("").unwrap(), PreviewFeatures::none());
447 assert_eq!(
448 PreviewFeatures::parse(" ").unwrap(),
449 PreviewFeatures::none()
450 );
451 for feature in PREVIEW_FEATURES {
452 assert!(!PreviewFeatures::none().enabled(*feature));
453 }
454 }
455
456 #[test]
457 fn parse_comma_lists_and_whitespace() {
458 let features =
459 PreviewFeatures::parse(" hybrid-search,graph-type-implied-labels , local-callables ")
460 .unwrap();
461 assert!(features.enabled(PreviewFeature::HybridSearch));
462 assert!(features.enabled(PreviewFeature::GraphTypeImpliedLabels));
463 assert!(features.enabled(PreviewFeature::LocalCallables));
464 assert!(!features.enabled(PreviewFeature::GraphTypeOptProps));
465 assert!(!features.enabled(PreviewFeature::GraphTypeDefaultValues));
466 assert_eq!(
468 PreviewFeatures::parse("hybrid-search, hybrid-search").unwrap(),
469 PreviewFeatures::parse("hybrid-search").unwrap(),
470 );
471 }
472
473 #[test]
474 fn parse_unknown_name_fails_closed_naming_known_names() {
475 let error = PreviewFeatures::parse("hybrid-search,bogus").unwrap_err();
476 assert!(matches!(error, Error::Semantic(_)), "{error}");
477 let display = error.to_string();
478 assert!(
479 display.contains("unknown preview feature 'bogus'"),
480 "{display}"
481 );
482 for (_, name) in PREVIEW_FEATURE_TABLE {
483 assert!(display.contains(name), "{display} misses {name}");
484 }
485 let error = PreviewFeatures::parse("hybrid-search,,local-callables").unwrap_err();
487 assert!(
488 error.to_string().contains("unknown preview feature ''"),
489 "{}",
490 error
491 );
492 }
493
494 #[test]
495 fn parse_each_registered_name_enables_exactly_that_feature() {
496 for feature in PREVIEW_FEATURES {
502 let enabled = PreviewFeatures::parse(feature.kebab_name()).unwrap();
503 assert!(enabled.enabled(*feature), "{}", feature.kebab_name());
504 for other in PREVIEW_FEATURES {
505 if other != feature {
506 assert!(
507 !enabled.enabled(*other),
508 "{} also enabled {}",
509 feature.kebab_name(),
510 other.kebab_name()
511 );
512 }
513 }
514 }
515 }
516
517 #[test]
518 fn require_gates_with_the_authored_disabled_error() {
519 let features = PreviewFeatures::parse("local-callables").unwrap();
520 assert!(features.require(PreviewFeature::LocalCallables).is_ok());
521 let error = features.require(PreviewFeature::HybridSearch).unwrap_err();
522 assert_eq!(
523 error.to_string(),
524 "semantic error: SemanticError: preview feature 'hybrid-search' is not enabled: \
525 set RELATE_PREVIEW=hybrid-search"
526 );
527 for (feature, name) in PREVIEW_FEATURE_TABLE {
529 let error = preview_feature_disabled(*feature);
530 assert!(
531 error.to_string().ends_with(&format!(
532 "preview feature '{name}' is not enabled: set RELATE_PREVIEW={name}"
533 )),
534 "{}",
535 error
536 );
537 }
538 }
539}