Skip to main content

relate_core/
integer_args.rs

1//! The integer-argument sites' authored texts.
2//!
3//! Written once so every layer that raises a site's rejection reads the
4//! same text: the planner's checks at plan time and, for the sites with a
5//! runtime coercion, the executor's argument coercion at run time. The
6//! slice bounds are plan-time only — their runtime coercion has no type
7//! rejection — and `SKIP` / `LIMIT` carry their own planner tokens.
8//! [`crate::FUNCTION_REQUIRES_ONE_ARGUMENT`] sets the precedent for a
9//! rejection spelling shared across layers. The `CALL { … } IN
10//! TRANSACTIONS` modifier sites (the batch size, the concurrency hint,
11//! REL8-2179) are rows in the same table: the planner's literal check
12//! and the executor's runtime coercion read one row, so the plan-time
13//! and run-time spellings cannot diverge.
14
15/// One ADR-0175 function-argument site's authored texts.
16pub struct IntegerArgSite {
17    /// The `InvalidArgumentType` detail of a non-numeric argument.
18    pub type_error: &'static str,
19    /// The site label a `NumberOutOfRange` rejection names. `None` where the
20    /// site has no runtime coercion to label: `range()`'s out-of-range
21    /// rejection (zero step, overflowing length) is authored in its executor,
22    /// not per argument.
23    pub range: Option<&'static str>,
24}
25
26/// A site that only gates the argument's type at plan time.
27const fn type_site(type_error: &'static str) -> IntegerArgSite {
28    IntegerArgSite {
29        type_error,
30        range: None,
31    }
32}
33
34/// A site whose runtime coercion raises `NumberOutOfRange`.
35const fn coercion_site(type_error: &'static str, range: &'static str) -> IntegerArgSite {
36    IntegerArgSite {
37        type_error,
38        range: Some(range),
39    }
40}
41
42/// The `CALL { … } IN TRANSACTIONS` modifier sites (REL8-2179): the
43/// `OF n ROWS` batch size and the `IN n CONCURRENT TRANSACTIONS` hint.
44/// Both fields carry the class mapping, stated once: `type_error` is
45/// the plan-time `InvalidArgumentType` sentence a non-INTEGER literal
46/// rejects with and the runtime wrong-typed (`TypeError`) detail;
47/// `range` is the plan-time `InvalidArgument` sentence a non-positive
48/// INTEGER literal rejects with and the runtime `NumberOutOfRange`
49/// (`ArgumentError`) detail for the batch size — a whole sentence,
50/// where a function site's `range` names its site.
51pub const TX_BATCH_SIZE: IntegerArgSite = coercion_site(
52    "batch size must be an integer",
53    "batch size must be a positive integer",
54);
55pub const TX_CONCURRENCY: IntegerArgSite = coercion_site(
56    "concurrency must be an integer",
57    "concurrency must be a positive integer",
58);
59
60/// The `ON ERROR RETRY … WAIT n` retry duration: the plan-time
61/// shape gate's two sentences — the non-numeric rejection's type text
62/// and the negative-duration rejection's range text.
63pub const TX_RETRY_DURATION: IntegerArgSite = coercion_site(
64    "retry duration must be numeric",
65    "retry duration must be non-negative",
66);
67
68/// A site's range sentence — the one accessor every layer reads (the
69/// planner's non-positive literal arms through
70/// [`crate::invalid_argument_text`], the executor's runtime
71/// `NumberOutOfRange` detail directly), owning the coercion-site
72/// invariant the `string_index_arg` sites already rely on.
73pub fn range_text(site: &IntegerArgSite) -> &'static str {
74    site.range
75        .expect("a coercion site states its range sentence")
76}
77
78pub const RANGE_START: IntegerArgSite = type_site("range() start");
79pub const RANGE_END: IntegerArgSite = type_site("range() end");
80pub const RANGE_STEP: IntegerArgSite = type_site("range() step");
81pub const SUBSTRING_START: IntegerArgSite =
82    coercion_site("substring() start must be an integer", "substring() start");
83pub const SUBSTRING_LENGTH: IntegerArgSite = coercion_site(
84    "substring() length must be an integer",
85    "substring() length",
86);
87pub const LEFT_LENGTH: IntegerArgSite =
88    coercion_site("left() length must be an integer", "left() length");
89pub const RIGHT_LENGTH: IntegerArgSite =
90    coercion_site("right() length must be an integer", "right() length");
91pub const LIST_INDEX: IntegerArgSite = type_site("list index must be an integer");
92pub const SLICE_START: IntegerArgSite = type_site("slice start must be an integer");
93pub const SLICE_END: IntegerArgSite = type_site("slice end must be an integer");