uor-foundation 0.3.5

UOR Foundation — typed Rust traits for the complete ontology. Import and implement.
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
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
// @generated by uor-crate from uor-ontology — do not edit manually

//! `region/` namespace — Spatial locality of content-addressed ring elements. Defines computable working sets for resolver stages, independent of physical memory layout..
//!
//! Space: Kernel

use crate::enums::MeasurementUnit;
use crate::HostTypes;

/// A contiguous range of u:Element values accessible during a single reduction step. Defines the resolver’s working set.
pub trait AddressRegion<H: HostTypes> {
    /// Associated type for `RegionBound`.
    type RegionBound: RegionBound<H>;
    /// The boundary of this region.
    fn region_bound(&self) -> &Self::RegionBound;
    /// Associated type for `LocalityMetric`.
    type LocalityMetric: LocalityMetric<H>;
    /// The metric defining contiguity for this region.
    fn locality_metric(&self) -> &Self::LocalityMetric;
    /// Number of addresses in this region.
    fn region_cardinality(&self) -> u64;
}

/// The boundary of an AddressRegion: a pair (lowerAddress, upperAddress) in the content-address ordering.
pub trait RegionBound<H: HostTypes> {
    /// Associated type for `Element`.
    type Element: crate::kernel::address::Element<H>;
    /// The lower bound of the address range.
    fn region_lower(&self) -> &Self::Element;
    /// The upper bound of the address range.
    fn region_upper(&self) -> &Self::Element;
}

/// A metric on u:Element values determining which addresses are near each other for resolution purposes.
pub trait LocalityMetric<H: HostTypes>: crate::bridge::observable::MetricObservable<H> {}

/// The set of AddressRegions needed by a resolver at a specific reduction step for a specific type. Computable from the type’s constraint nerve.
pub trait WorkingSet<H: HostTypes> {
    /// Associated type for `AddressRegion`.
    type AddressRegion: AddressRegion<H>;
    /// The address regions composing this working set.
    fn working_set_regions(&self) -> &[Self::AddressRegion];
    /// Associated type for `ReductionStep`.
    type ReductionStep: crate::kernel::reduction::ReductionStep<H>;
    /// The reduction step this working set applies to.
    fn working_set_stage(&self) -> &Self::ReductionStep;
    /// Associated type for `TypeDefinition`.
    type TypeDefinition: crate::user::type_::TypeDefinition<H>;
    /// The type being resolved.
    fn working_set_type(&self) -> &Self::TypeDefinition;
    /// Total addresses across all regions in the working set.
    fn working_set_size(&self) -> u64;
}

/// An assignment of AddressRegions to reduction steps for a given computation. Enables Prism to pre-compute memory layout.
pub trait RegionAllocation<H: HostTypes> {
    /// Associated type for `ReductionStep`.
    type ReductionStep: crate::kernel::reduction::ReductionStep<H>;
    /// Reduction steps in this allocation.
    fn allocation_stage(&self) -> &[Self::ReductionStep];
    /// Associated type for `WorkingSet`.
    type WorkingSet: WorkingSet<H>;
    /// The working sets assigned to each stage.
    fn allocation_working_set(&self) -> &[Self::WorkingSet];
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `AddressRegion<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullAddressRegion<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullAddressRegion<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullAddressRegion<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullAddressRegion<H> = NullAddressRegion {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> AddressRegion<H> for NullAddressRegion<H> {
    type RegionBound = NullRegionBound<H>;
    fn region_bound(&self) -> &Self::RegionBound {
        &<NullRegionBound<H>>::ABSENT
    }
    type LocalityMetric = NullLocalityMetric<H>;
    fn locality_metric(&self) -> &Self::LocalityMetric {
        &<NullLocalityMetric<H>>::ABSENT
    }
    fn region_cardinality(&self) -> u64 {
        0
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `RegionBound<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullRegionBound<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullRegionBound<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullRegionBound<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullRegionBound<H> = NullRegionBound {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> RegionBound<H> for NullRegionBound<H> {
    type Element = crate::kernel::address::NullElement<H>;
    fn region_lower(&self) -> &Self::Element {
        &<crate::kernel::address::NullElement<H>>::ABSENT
    }
    fn region_upper(&self) -> &Self::Element {
        &<crate::kernel::address::NullElement<H>>::ABSENT
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `LocalityMetric<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullLocalityMetric<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullLocalityMetric<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullLocalityMetric<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullLocalityMetric<H> = NullLocalityMetric {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> crate::bridge::observable::Observable<H> for NullLocalityMetric<H> {
    fn value(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn source(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn target(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn has_unit(&self) -> MeasurementUnit {
        <MeasurementUnit>::default()
    }
}
impl<H: HostTypes> crate::bridge::observable::MetricObservable<H> for NullLocalityMetric<H> {}
impl<H: HostTypes> LocalityMetric<H> for NullLocalityMetric<H> {}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `WorkingSet<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullWorkingSet<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullWorkingSet<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullWorkingSet<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullWorkingSet<H> = NullWorkingSet {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> WorkingSet<H> for NullWorkingSet<H> {
    type AddressRegion = NullAddressRegion<H>;
    fn working_set_regions(&self) -> &[Self::AddressRegion] {
        &[]
    }
    type ReductionStep = crate::kernel::reduction::NullReductionStep<H>;
    fn working_set_stage(&self) -> &Self::ReductionStep {
        &<crate::kernel::reduction::NullReductionStep<H>>::ABSENT
    }
    type TypeDefinition = crate::user::type_::NullTypeDefinition<H>;
    fn working_set_type(&self) -> &Self::TypeDefinition {
        &<crate::user::type_::NullTypeDefinition<H>>::ABSENT
    }
    fn working_set_size(&self) -> u64 {
        0
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `RegionAllocation<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullRegionAllocation<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullRegionAllocation<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullRegionAllocation<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullRegionAllocation<H> = NullRegionAllocation {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> RegionAllocation<H> for NullRegionAllocation<H> {
    type ReductionStep = crate::kernel::reduction::NullReductionStep<H>;
    fn allocation_stage(&self) -> &[Self::ReductionStep] {
        &[]
    }
    type WorkingSet = NullWorkingSet<H>;
    fn allocation_working_set(&self) -> &[Self::WorkingSet] {
        &[]
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `AddressRegion<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct AddressRegionHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for AddressRegionHandle<H> {}
impl<H: HostTypes> Clone for AddressRegionHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for AddressRegionHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for AddressRegionHandle<H> {}
impl<H: HostTypes> core::hash::Hash for AddressRegionHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> AddressRegionHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `AddressRegion<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait AddressRegionResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: AddressRegionHandle<H>) -> Option<AddressRegionRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `AddressRegion<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AddressRegionRecord<H: HostTypes> {
    pub region_bound_handle: RegionBoundHandle<H>,
    pub locality_metric_handle: LocalityMetricHandle<H>,
    pub region_cardinality: u64,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `AddressRegion<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedAddressRegion<'r, R: AddressRegionResolver<H>, H: HostTypes> {
    handle: AddressRegionHandle<H>,
    resolver: &'r R,
    record: Option<AddressRegionRecord<H>>,
}
impl<'r, R: AddressRegionResolver<H>, H: HostTypes> ResolvedAddressRegion<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: AddressRegionHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> AddressRegionHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&AddressRegionRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: AddressRegionResolver<H>, H: HostTypes> AddressRegion<H>
    for ResolvedAddressRegion<'r, R, H>
{
    type RegionBound = NullRegionBound<H>;
    fn region_bound(&self) -> &Self::RegionBound {
        &<NullRegionBound<H>>::ABSENT
    }
    type LocalityMetric = NullLocalityMetric<H>;
    fn locality_metric(&self) -> &Self::LocalityMetric {
        &<NullLocalityMetric<H>>::ABSENT
    }
    fn region_cardinality(&self) -> u64 {
        match &self.record {
            Some(r) => r.region_cardinality,
            None => 0,
        }
    }
}
impl<'r, R: AddressRegionResolver<H>, H: HostTypes> ResolvedAddressRegion<'r, R, H> {
    /// Promote the `region_bound` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_region_bound<'r2, R2: RegionBoundResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<ResolvedRegionBound<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(ResolvedRegionBound::new(record.region_bound_handle, r))
    }
    /// Promote the `locality_metric` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_locality_metric<'r2, R2: LocalityMetricResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<ResolvedLocalityMetric<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(ResolvedLocalityMetric::new(
            record.locality_metric_handle,
            r,
        ))
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `RegionBound<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct RegionBoundHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for RegionBoundHandle<H> {}
impl<H: HostTypes> Clone for RegionBoundHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for RegionBoundHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for RegionBoundHandle<H> {}
impl<H: HostTypes> core::hash::Hash for RegionBoundHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> RegionBoundHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `RegionBound<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait RegionBoundResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: RegionBoundHandle<H>) -> Option<RegionBoundRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `RegionBound<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RegionBoundRecord<H: HostTypes> {
    pub region_lower_handle: crate::kernel::address::ElementHandle<H>,
    pub region_upper_handle: crate::kernel::address::ElementHandle<H>,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `RegionBound<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedRegionBound<'r, R: RegionBoundResolver<H>, H: HostTypes> {
    handle: RegionBoundHandle<H>,
    resolver: &'r R,
    record: Option<RegionBoundRecord<H>>,
}
impl<'r, R: RegionBoundResolver<H>, H: HostTypes> ResolvedRegionBound<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: RegionBoundHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> RegionBoundHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&RegionBoundRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: RegionBoundResolver<H>, H: HostTypes> RegionBound<H> for ResolvedRegionBound<'r, R, H> {
    type Element = crate::kernel::address::NullElement<H>;
    fn region_lower(&self) -> &Self::Element {
        &<crate::kernel::address::NullElement<H>>::ABSENT
    }
    fn region_upper(&self) -> &Self::Element {
        &<crate::kernel::address::NullElement<H>>::ABSENT
    }
}
impl<'r, R: RegionBoundResolver<H>, H: HostTypes> ResolvedRegionBound<'r, R, H> {
    /// Promote the `region_lower` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_region_lower<'r2, R2: crate::kernel::address::ElementResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<crate::kernel::address::ResolvedElement<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(crate::kernel::address::ResolvedElement::new(
            record.region_lower_handle,
            r,
        ))
    }
    /// Promote the `region_upper` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_region_upper<'r2, R2: crate::kernel::address::ElementResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<crate::kernel::address::ResolvedElement<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(crate::kernel::address::ResolvedElement::new(
            record.region_upper_handle,
            r,
        ))
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `LocalityMetric<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct LocalityMetricHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for LocalityMetricHandle<H> {}
impl<H: HostTypes> Clone for LocalityMetricHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for LocalityMetricHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for LocalityMetricHandle<H> {}
impl<H: HostTypes> core::hash::Hash for LocalityMetricHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> LocalityMetricHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `LocalityMetric<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait LocalityMetricResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: LocalityMetricHandle<H>) -> Option<LocalityMetricRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `LocalityMetric<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct LocalityMetricRecord<H: HostTypes> {
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `LocalityMetric<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedLocalityMetric<'r, R: LocalityMetricResolver<H>, H: HostTypes> {
    handle: LocalityMetricHandle<H>,
    resolver: &'r R,
    record: Option<LocalityMetricRecord<H>>,
}
impl<'r, R: LocalityMetricResolver<H>, H: HostTypes> ResolvedLocalityMetric<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: LocalityMetricHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> LocalityMetricHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&LocalityMetricRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: LocalityMetricResolver<H>, H: HostTypes> crate::bridge::observable::Observable<H>
    for ResolvedLocalityMetric<'r, R, H>
{
    fn value(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn source(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn target(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn has_unit(&self) -> MeasurementUnit {
        <MeasurementUnit>::default()
    }
}
impl<'r, R: LocalityMetricResolver<H>, H: HostTypes> crate::bridge::observable::MetricObservable<H>
    for ResolvedLocalityMetric<'r, R, H>
{
}
impl<'r, R: LocalityMetricResolver<H>, H: HostTypes> LocalityMetric<H>
    for ResolvedLocalityMetric<'r, R, H>
{
}

/// Phase 8 (orphan-closure) — content-addressed handle for `WorkingSet<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct WorkingSetHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for WorkingSetHandle<H> {}
impl<H: HostTypes> Clone for WorkingSetHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for WorkingSetHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for WorkingSetHandle<H> {}
impl<H: HostTypes> core::hash::Hash for WorkingSetHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> WorkingSetHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `WorkingSet<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait WorkingSetResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: WorkingSetHandle<H>) -> Option<WorkingSetRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `WorkingSet<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct WorkingSetRecord<H: HostTypes> {
    pub working_set_stage_handle: crate::kernel::reduction::ReductionStepHandle<H>,
    pub working_set_type_handle: crate::user::type_::TypeDefinitionHandle<H>,
    pub working_set_size: u64,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `WorkingSet<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedWorkingSet<'r, R: WorkingSetResolver<H>, H: HostTypes> {
    handle: WorkingSetHandle<H>,
    resolver: &'r R,
    record: Option<WorkingSetRecord<H>>,
}
impl<'r, R: WorkingSetResolver<H>, H: HostTypes> ResolvedWorkingSet<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: WorkingSetHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> WorkingSetHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&WorkingSetRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: WorkingSetResolver<H>, H: HostTypes> WorkingSet<H> for ResolvedWorkingSet<'r, R, H> {
    type AddressRegion = NullAddressRegion<H>;
    fn working_set_regions(&self) -> &[Self::AddressRegion] {
        &[]
    }
    type ReductionStep = crate::kernel::reduction::NullReductionStep<H>;
    fn working_set_stage(&self) -> &Self::ReductionStep {
        &<crate::kernel::reduction::NullReductionStep<H>>::ABSENT
    }
    type TypeDefinition = crate::user::type_::NullTypeDefinition<H>;
    fn working_set_type(&self) -> &Self::TypeDefinition {
        &<crate::user::type_::NullTypeDefinition<H>>::ABSENT
    }
    fn working_set_size(&self) -> u64 {
        match &self.record {
            Some(r) => r.working_set_size,
            None => 0,
        }
    }
}
impl<'r, R: WorkingSetResolver<H>, H: HostTypes> ResolvedWorkingSet<'r, R, H> {
    /// Promote the `working_set_stage` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_working_set_stage<
        'r2,
        R2: crate::kernel::reduction::ReductionStepResolver<H>,
    >(
        &self,
        r: &'r2 R2,
    ) -> Option<crate::kernel::reduction::ResolvedReductionStep<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(crate::kernel::reduction::ResolvedReductionStep::new(
            record.working_set_stage_handle,
            r,
        ))
    }
    /// Promote the `working_set_type` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_working_set_type<'r2, R2: crate::user::type_::TypeDefinitionResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<crate::user::type_::ResolvedTypeDefinition<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(crate::user::type_::ResolvedTypeDefinition::new(
            record.working_set_type_handle,
            r,
        ))
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `RegionAllocation<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct RegionAllocationHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for RegionAllocationHandle<H> {}
impl<H: HostTypes> Clone for RegionAllocationHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for RegionAllocationHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for RegionAllocationHandle<H> {}
impl<H: HostTypes> core::hash::Hash for RegionAllocationHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> RegionAllocationHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `RegionAllocation<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait RegionAllocationResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: RegionAllocationHandle<H>) -> Option<RegionAllocationRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `RegionAllocation<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RegionAllocationRecord<H: HostTypes> {
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `RegionAllocation<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedRegionAllocation<'r, R: RegionAllocationResolver<H>, H: HostTypes> {
    handle: RegionAllocationHandle<H>,
    resolver: &'r R,
    record: Option<RegionAllocationRecord<H>>,
}
impl<'r, R: RegionAllocationResolver<H>, H: HostTypes> ResolvedRegionAllocation<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: RegionAllocationHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> RegionAllocationHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&RegionAllocationRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: RegionAllocationResolver<H>, H: HostTypes> RegionAllocation<H>
    for ResolvedRegionAllocation<'r, R, H>
{
    type ReductionStep = crate::kernel::reduction::NullReductionStep<H>;
    fn allocation_stage(&self) -> &[Self::ReductionStep] {
        &[]
    }
    type WorkingSet = NullWorkingSet<H>;
    fn allocation_working_set(&self) -> &[Self::WorkingSet] {
        &[]
    }
}