rototo 0.1.0-alpha.7

Control plane for runtime configuration of your application.
Documentation
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
use std::collections::BTreeMap;
use std::sync::Arc;

use serde_json::Value as JsonValue;

use crate::diagnostics::{
    CustomRuleDefinition, CustomRuleId, DiagnosticLocation, DocId, LintStage, SemanticEntity,
    SemanticField, SemanticTarget,
};
use crate::expression::Expression;

use super::ids::{
    CatalogId, EvaluationContextId, EvaluationContextSampleId, LayerId, ListId, PackagePath,
    ValueKey, VariableId,
};
use super::targets::RegisteredLintSelector;

pub(in crate::lint) struct ManifestNode {
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) extends: PackageExtendsCollection,
    pub(in crate::lint) trace: Vec<TracePolicyNode>,
}

impl ManifestNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::Manifest.into()
    }
}

/// One `[[trace]]` policy declared in the manifest. The `when` is a CEL boolean
/// that may, uniquely, read `env.resolving.*` (the entity being resolved).
pub(in crate::lint) struct TracePolicyNode {
    /// Position in the `[[trace]]` array, used to label the policy.
    pub(in crate::lint) index: usize,
    pub(in crate::lint) when: ProjectField<Expression>,
}

pub(in crate::lint) struct PackageExtendNode {
    pub(in crate::lint) source: String,
    pub(in crate::lint) location: DiagnosticLocation,
}

pub(in crate::lint) enum PackageExtendsCollection {
    Missing,
    Invalid {
        location: DiagnosticLocation,
    },
    Sources {
        location: DiagnosticLocation,
        values: Vec<PackageExtendNode>,
    },
}

pub(in crate::lint) struct VariableNode {
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) id: VariableId,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) schema_version: ProjectField<i64>,
    pub(in crate::lint) description: Option<ProjectField<String>>,
    pub(in crate::lint) type_source: TypeSourceNode,
    pub(in crate::lint) values: ValuesNode,
    pub(in crate::lint) resolve: ResolveNode,
}

impl VariableNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::Variable {
            id: self.id.clone(),
        }
        .into()
    }

    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::Variable {
                id: self.id.clone(),
            },
            field,
        )
    }
}

pub(in crate::lint) enum TypeSourceNode {
    Primitive(Spanned<String>),
    Catalog(Spanned<String>),
    Schema(Spanned<String>),
    Missing { location: DiagnosticLocation },
    Conflict { location: DiagnosticLocation },
    Invalid { location: DiagnosticLocation },
}

impl TypeSourceNode {
    pub(in crate::lint) fn location(&self) -> DiagnosticLocation {
        match self {
            Self::Primitive(type_name) => type_name.location.clone(),
            Self::Catalog(catalog) => catalog.location.clone(),
            Self::Schema(schema) => schema.location.clone(),
            Self::Missing { location }
            | Self::Conflict { location }
            | Self::Invalid { location } => location.clone(),
        }
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub(in crate::lint) enum VariableTypeKind {
    Primitive(String),
    Catalog(String),
    List(String),
    Array(Box<VariableTypeKind>),
}

impl VariableTypeKind {
    pub(in crate::lint) fn catalog_ids(&self) -> Vec<&str> {
        match self {
            Self::Primitive(_) | Self::List(_) => Vec::new(),
            Self::Catalog(catalog) => vec![catalog.as_str()],
            Self::Array(item) => item.catalog_ids(),
        }
    }

    pub(in crate::lint) fn list_ids(&self) -> Vec<&str> {
        match self {
            Self::Primitive(_) | Self::Catalog(_) => Vec::new(),
            Self::List(id) => vec![id.as_str()],
            Self::Array(item) => item.list_ids(),
        }
    }

    pub(in crate::lint) fn array_catalog(&self) -> Option<&str> {
        match self {
            Self::Array(item) => match item.as_ref() {
                Self::Catalog(catalog) => Some(catalog.as_str()),
                _ => None,
            },
            _ => None,
        }
    }
}

pub(in crate::lint) fn variable_type_kind(
    source: &TypeSourceNode,
) -> Option<Spanned<VariableTypeKind>> {
    match source {
        TypeSourceNode::Primitive(type_name) => {
            parse_variable_type(&type_name.value).map(|value| Spanned {
                value,
                location: type_name.location.clone(),
            })
        }
        TypeSourceNode::Catalog(catalog) => Some(Spanned {
            value: VariableTypeKind::Catalog(catalog.value.clone()),
            location: catalog.location.clone(),
        }),
        TypeSourceNode::Schema(_)
        | TypeSourceNode::Missing { .. }
        | TypeSourceNode::Conflict { .. }
        | TypeSourceNode::Invalid { .. } => None,
    }
}

fn parse_variable_type(value: &str) -> Option<VariableTypeKind> {
    let value = value.trim();
    if let Some(inner) = value
        .strip_prefix("array<")
        .and_then(|value| value.strip_suffix('>'))
    {
        return parse_variable_type(inner).map(|item| VariableTypeKind::Array(Box::new(item)));
    }
    if let Some((class, id)) = value.split_once('=') {
        return match crate::address::EntityClass::parse_name(class) {
            Some(crate::address::EntityClass::Catalog) => {
                (!id.is_empty()).then(|| VariableTypeKind::Catalog(id.to_owned()))
            }
            Some(crate::address::EntityClass::List) => {
                (!id.is_empty()).then(|| VariableTypeKind::List(id.to_owned()))
            }
            // Any other binding is not a type; let the unknown-type rule name it.
            _ => Some(VariableTypeKind::Primitive(value.to_owned())),
        };
    }
    Some(VariableTypeKind::Primitive(value.to_owned()))
}

/// A named list under `lists/<id>.toml`: one file holding the contract
/// (the member scalar type) and the member set, like a variable holds its
/// type and its resolution.
pub(in crate::lint) struct ListNode {
    #[allow(dead_code)]
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) id: ListId,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) schema_version: ProjectField<i64>,
    #[allow(dead_code)]
    pub(in crate::lint) description: Option<ProjectField<String>>,
    pub(in crate::lint) member_type: ProjectField<String>,
    pub(in crate::lint) members: ProjectField<Vec<Spanned<JsonValue>>>,
    /// Location of a `deleted` key. Deletes belong in update markers and
    /// are consumed when layers flatten; one surviving into lint has no
    /// base member set to remove from.
    pub(in crate::lint) deleted: Option<DiagnosticLocation>,
}

impl ListNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::List {
            id: self.id.clone(),
        }
        .into()
    }

    #[allow(dead_code)]
    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::List {
                id: self.id.clone(),
            },
            field,
        )
    }
}

/// The layering contract at `governance.toml`: one block per governed
/// entity, each a gate over operations plus scoped policies.
pub(in crate::lint) struct GovernanceNode {
    #[allow(dead_code)]
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) blocks: Vec<GovernanceBlockNode>,
    /// Top-level keys that are not one of the governed kinds.
    pub(in crate::lint) unknown_kinds: Vec<Spanned<String>>,
}

/// One `[<kind>.<id>]` block: which operations a layer below may perform on
/// this entity, and (for update/delete) where.
pub(in crate::lint) struct GovernanceBlockNode {
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) kind: String,
    pub(in crate::lint) id: String,
    pub(in crate::lint) allowed_operations: Option<ProjectField<Vec<Spanned<String>>>>,
    pub(in crate::lint) denied_operations: Option<ProjectField<Vec<Spanned<String>>>>,
    pub(in crate::lint) update_policy: Option<GovernancePolicyNode>,
    pub(in crate::lint) delete_policy: Option<GovernancePolicyNode>,
    /// Keys under the block rototo does not recognize.
    pub(in crate::lint) unknown_keys: Vec<Spanned<String>>,
}

pub(in crate::lint) struct GovernancePolicyNode {
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) allowed_entries: Option<ProjectField<Vec<Spanned<String>>>>,
    pub(in crate::lint) denied_entries: Option<ProjectField<Vec<Spanned<String>>>>,
    pub(in crate::lint) allowed_fields: Option<ProjectField<Vec<Spanned<String>>>>,
    pub(in crate::lint) denied_fields: Option<ProjectField<Vec<Spanned<String>>>>,
}

/// A layer under `layers/<id>.toml`: a diversion (`unit`, `buckets`) plus the
/// allocations that claim slices of it. The file stem is the layer id.
pub(in crate::lint) struct LayerNode {
    #[allow(dead_code)]
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) id: LayerId,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) schema_version: ProjectField<i64>,
    #[allow(dead_code)]
    pub(in crate::lint) description: Option<ProjectField<String>>,
    pub(in crate::lint) unit: ProjectField<Expression>,
    pub(in crate::lint) buckets: ProjectField<i64>,
    pub(in crate::lint) allocations: Vec<AllocationNode>,
    /// True when `allocation` exists but is not an array of tables.
    pub(in crate::lint) allocations_invalid: bool,
}

impl LayerNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::Layer {
            id: self.id.clone(),
        }
        .into()
    }
}

/// One `[[allocation]]` table inside a layer: a named claim on buckets,
/// divided into arms.
pub(in crate::lint) struct AllocationNode {
    pub(in crate::lint) index: usize,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) id: ProjectField<String>,
    pub(in crate::lint) status: Option<ProjectField<String>>,
    pub(in crate::lint) eligibility: Option<ProjectField<Expression>>,
    pub(in crate::lint) arms: Vec<ArmNode>,
    /// True when `arm` exists but is not an array of tables.
    pub(in crate::lint) arms_invalid: bool,
    pub(in crate::lint) invalid_shape: bool,
}

/// One `[[allocation.arm]]` table: a named slice of the allocation's buckets.
pub(in crate::lint) struct ArmNode {
    pub(in crate::lint) index: usize,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) name: ProjectField<String>,
    pub(in crate::lint) buckets: ProjectField<String>,
    pub(in crate::lint) invalid_shape: bool,
}

/// The `method = "allocation"` parameters on `[resolve]`: the allocation the
/// variable consumes and the per-arm value assignments.
pub(in crate::lint) struct AssignmentsNode {
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) allocation: ProjectField<String>,
    pub(in crate::lint) assigns: Vec<AssignNode>,
    /// True when `assign` exists but is not an array of tables.
    pub(in crate::lint) assigns_invalid: bool,
}

/// One `[[resolve.assign]]` table: the value one arm assigns to the variable.
pub(in crate::lint) struct AssignNode {
    #[allow(dead_code)]
    pub(in crate::lint) index: usize,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) arm: ProjectField<String>,
    pub(in crate::lint) value: ProjectField<JsonValue>,
    pub(in crate::lint) invalid_shape: bool,
}

/// Parse an arm's `buckets` range: `"7"` (one bucket) or `"0-49"` (inclusive).
/// Returns `(start, end)` with `start <= end`, or `None` for anything else.
pub(crate) fn parse_arm_buckets(value: &str) -> Option<(u32, u32)> {
    let value = value.trim();
    match value.split_once('-') {
        Some((start, end)) => {
            let start = start.trim().parse().ok()?;
            let end = end.trim().parse().ok()?;
            (start <= end).then_some((start, end))
        }
        None => {
            let bucket = value.parse().ok()?;
            Some((bucket, bucket))
        }
    }
}

pub(in crate::lint) struct CatalogNode {
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) id: CatalogId,
    pub(in crate::lint) path: PackagePath,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) json: Option<JsonValue>,
    pub(in crate::lint) validator: Option<Arc<jsonschema::Validator>>,
    pub(in crate::lint) invalid_message: Option<String>,
}

impl CatalogNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::Catalog {
            id: self.id.clone(),
        }
        .into()
    }

    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::Catalog {
                id: self.id.clone(),
            },
            field,
        )
    }
}

pub(in crate::lint) struct CatalogEntryNode {
    pub(in crate::lint) catalog_id: CatalogId,
    pub(in crate::lint) key: ValueKey,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) value: JsonValue,
}

impl CatalogEntryNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::CatalogEntry {
            catalog: self.catalog_id.clone(),
            key: self.key.clone(),
        }
        .into()
    }

    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::CatalogEntry {
                catalog: self.catalog_id.clone(),
                key: self.key.clone(),
            },
            field,
        )
    }
}

pub(in crate::lint) struct EvaluationContextNode {
    pub(in crate::lint) id: EvaluationContextId,
    pub(in crate::lint) path: PackagePath,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) json: Option<JsonValue>,
    pub(in crate::lint) validator: Option<Arc<jsonschema::Validator>>,
    pub(in crate::lint) invalid_message: Option<String>,
}

impl EvaluationContextNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::EvaluationContext {
            id: self.id.clone(),
        }
        .into()
    }

    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::EvaluationContext {
                id: self.id.clone(),
            },
            field,
        )
    }
}

pub(in crate::lint) struct EvaluationContextSampleNode {
    pub(in crate::lint) evaluation_context_id: EvaluationContextId,
    pub(in crate::lint) key: EvaluationContextSampleId,
    pub(in crate::lint) path: PackagePath,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) value: Option<JsonValue>,
}

impl EvaluationContextSampleNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::EvaluationContextSample {
            evaluation_context: self.evaluation_context_id.clone(),
            key: self.key.clone(),
        }
        .into()
    }

    pub(in crate::lint) fn field_target(&self, field: SemanticField) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::EvaluationContextSample {
                evaluation_context: self.evaluation_context_id.clone(),
                key: self.key.clone(),
            },
            field,
        )
    }
}

pub(in crate::lint) struct ValuesNode {
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) inline_values: BTreeMap<ValueKey, ValueNode>,
    pub(in crate::lint) invalid_shape: bool,
}

pub(in crate::lint) struct ValueNode {
    pub(in crate::lint) variable_id: VariableId,
    pub(in crate::lint) key: ValueKey,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) value: JsonValue,
    pub(in crate::lint) origin: ValueOrigin,
}

impl ValueNode {
    pub(in crate::lint) fn target(&self) -> SemanticTarget {
        SemanticEntity::Value {
            variable: self.variable_id.clone(),
            key: self.key.clone(),
        }
        .into()
    }
}

pub(in crate::lint) enum ValueOrigin {
    Inline { variable_doc: DocId },
}

#[derive(Default)]
pub(in crate::lint) struct CustomLintRegistry {
    pub(in crate::lint) rules: BTreeMap<CustomRuleId, CustomRuleDefinitionNode>,
    pub(in crate::lint) files: BTreeMap<PackagePath, CustomLintFileNode>,
    pub(in crate::lint) registrations: Vec<CustomLintRegistration>,
}

#[derive(Clone)]
pub(in crate::lint) struct CustomRuleDefinitionNode {
    pub(in crate::lint) definition: CustomRuleDefinition,
}

#[derive(Clone)]
pub(in crate::lint) struct CustomLintFileNode {
    pub(in crate::lint) path: PackagePath,
    pub(in crate::lint) doc: DocId,
    pub(in crate::lint) location: DiagnosticLocation,
}

#[derive(Clone)]
pub(in crate::lint) struct CustomLintRegistration {
    pub(in crate::lint) file_path: PackagePath,
    pub(in crate::lint) rule: CustomRuleId,
    pub(in crate::lint) stage: LintStage,
    pub(in crate::lint) selector: RegisteredLintSelector,
    pub(in crate::lint) handler: String,
    pub(in crate::lint) location: DiagnosticLocation,
}

pub(in crate::lint) enum ResolveNode {
    Missing {
        location: DiagnosticLocation,
    },
    Invalid {
        location: DiagnosticLocation,
    },
    Resolve {
        location: DiagnosticLocation,
        /// The resolution method: `rules` (the default when absent), `query`,
        /// or `allocation`.
        method: Option<Box<Spanned<String>>>,
        default: Box<ProjectField<JsonValue>>,
        rules: RuleCollection,
        query: Option<Box<QueryNode>>,
        /// The `method = "allocation"` parameters, present when the
        /// `allocation` key or any `[[resolve.assign]]` appears.
        assignments: Option<Box<AssignmentsNode>>,
    },
}

/// The `method = "query"` parameters, flat on `[resolve]`: a CEL pipeline over
/// one catalog's entries.
pub(in crate::lint) struct QueryNode {
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) from: ProjectField<String>,
    pub(in crate::lint) filter: Option<ProjectField<Expression>>,
    pub(in crate::lint) sort: Option<ProjectField<Expression>>,
    pub(in crate::lint) order: Option<ProjectField<String>>,
    pub(in crate::lint) limit: Option<ProjectField<i64>>,
}

impl ResolveNode {
    pub(in crate::lint) fn as_query(&self) -> Option<&QueryNode> {
        match self {
            Self::Resolve { query, .. } => query.as_deref(),
            _ => None,
        }
    }

    pub(in crate::lint) fn as_assignments(&self) -> Option<&AssignmentsNode> {
        match self {
            Self::Resolve { assignments, .. } => assignments.as_deref(),
            _ => None,
        }
    }

    pub(in crate::lint) fn location(&self) -> DiagnosticLocation {
        match self {
            Self::Missing { location }
            | Self::Invalid { location }
            | Self::Resolve { location, .. } => location.clone(),
        }
    }
}

pub(in crate::lint) enum RuleCollection {
    Rules(Vec<VariableRuleNode>),
    Invalid { location: DiagnosticLocation },
}

pub(in crate::lint) struct VariableRuleNode {
    pub(in crate::lint) index: usize,
    pub(in crate::lint) location: DiagnosticLocation,
    pub(in crate::lint) when: Option<ProjectField<Expression>>,
    pub(in crate::lint) value: ProjectField<JsonValue>,
    pub(in crate::lint) invalid_shape: bool,
}

impl VariableRuleNode {
    pub(in crate::lint) fn target(&self, variable_id: &str) -> SemanticTarget {
        SemanticEntity::Rule {
            variable: variable_id.to_owned(),
            index: self.index,
        }
        .into()
    }

    pub(in crate::lint) fn field_target(
        &self,
        variable_id: &str,
        field: SemanticField,
    ) -> SemanticTarget {
        SemanticTarget::field(
            SemanticEntity::Rule {
                variable: variable_id.to_owned(),
                index: self.index,
            },
            field,
        )
    }
}

#[derive(Clone)]
pub(in crate::lint) struct Spanned<T> {
    pub(in crate::lint) value: T,
    pub(in crate::lint) location: DiagnosticLocation,
}

pub(in crate::lint) enum ProjectField<T> {
    Present(Spanned<T>),
    Invalid { location: DiagnosticLocation },
    Missing { location: DiagnosticLocation },
}

impl<T> ProjectField<T> {
    pub(in crate::lint) fn location(&self) -> DiagnosticLocation {
        match self {
            Self::Present(value) => value.location.clone(),
            Self::Invalid { location } | Self::Missing { location } => location.clone(),
        }
    }
}