Skip to main content

sim_lib_class/
inventory.rs

1//! Machine-readable ownership, reuse, exclusion, and non-goal ledgers.
2
3/// Candidate semantics examined before assigning concrete class ownership.
4#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
5pub enum CandidateModel {
6    KernelClassProtocol,
7    PythonClassSpace,
8    JavascriptPrototype,
9    LuaMetatable,
10    TypeclassDictionary,
11    PrologRelation,
12    GenericDispatch,
13    JvmLoaderIdentity,
14}
15
16/// How this crate treats a candidate implementation.
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub enum CandidateDisposition {
19    /// Use the contract without moving its ownership.
20    Reuse,
21    /// Reuse an algorithm, but not the candidate's language-specific object policy.
22    Compose,
23    /// The candidate is not class inheritance.
24    Exclude,
25}
26
27/// The semantic domain actually governed by a candidate model.
28#[derive(Clone, Copy, Debug, Eq, PartialEq)]
29pub enum SemanticDomain {
30    ClassProtocol,
31    ClassInheritance,
32    PropertyLookup,
33    MetamethodLookup,
34    ConstraintEvidence,
35    LogicalRelation,
36    MethodSelection,
37    RuntimeTypeIdentity,
38}
39
40/// Exact meaning that an edge or declaration has in a candidate model.
41#[derive(Clone, Copy, Debug, Eq, PartialEq)]
42pub enum ParentMeaning {
43    /// A direct superclass contributes ancestry and participates in C3 order.
44    DeclaredSuperclass,
45    /// A protocol reports direct parents but owns no concrete hierarchy.
46    ProtocolReportedSuperclass,
47    /// An object delegates missing property reads to another object.
48    PrototypeDelegate,
49    /// A table delegates selected operations through `__index` and metamethods.
50    MetatableDelegate,
51    /// A dictionary witnesses that a type satisfies a named constraint.
52    ConstraintWitness,
53    /// A predicate relates terms; the word "parent" has no privileged meaning.
54    PredicateArgument,
55    /// Applicability and Shape specificity order methods for one invocation.
56    ApplicableMethod,
57    /// Defining-loader plus binary-name identifies a runtime type.
58    DefiningLoaderIdentity,
59}
60
61/// One complete candidate row.
62#[derive(Clone, Copy, Debug, Eq, PartialEq)]
63pub struct SemanticCandidate {
64    pub model: CandidateModel,
65    pub disposition: CandidateDisposition,
66    pub domain: SemanticDomain,
67    pub declared_parent: ParentMeaning,
68    pub source_anchor: &'static str,
69}
70
71/// Structured reason an adjacent model cannot implement declared class parents.
72#[derive(Clone, Copy, Debug, Eq, PartialEq)]
73pub struct ExclusionReason {
74    pub model: CandidateModel,
75    /// Meaning required by this crate's declared `parents` field.
76    pub required: ParentMeaning,
77    /// Meaning supplied by the excluded model.
78    pub actual: ParentMeaning,
79    /// Stable code consumed by ownership guards; never infer this from prose.
80    pub mismatch_code: &'static str,
81}
82
83/// Precise behavior intentionally outside this crate.
84#[derive(Clone, Copy, Debug, Eq, PartialEq)]
85pub struct NonGoal {
86    pub model: CandidateModel,
87    pub excluded_semantics: &'static str,
88}
89
90pub const fn candidate_inventory() -> &'static [SemanticCandidate] {
91    &[
92        SemanticCandidate {
93            model: CandidateModel::KernelClassProtocol,
94            disposition: CandidateDisposition::Reuse,
95            domain: SemanticDomain::ClassProtocol,
96            declared_parent: ParentMeaning::ProtocolReportedSuperclass,
97            source_anchor: "sim-kernel/src/class.rs",
98        },
99        SemanticCandidate {
100            model: CandidateModel::PythonClassSpace,
101            disposition: CandidateDisposition::Compose,
102            domain: SemanticDomain::ClassInheritance,
103            declared_parent: ParentMeaning::DeclaredSuperclass,
104            source_anchor: "sim-runtime/crates/sim-lib-lang-python/src/objects.rs",
105        },
106        SemanticCandidate {
107            model: CandidateModel::JavascriptPrototype,
108            disposition: CandidateDisposition::Exclude,
109            domain: SemanticDomain::PropertyLookup,
110            declared_parent: ParentMeaning::PrototypeDelegate,
111            source_anchor: "sim-runtime/crates/sim-lib-lang-javascript/src/objects/space.rs",
112        },
113        SemanticCandidate {
114            model: CandidateModel::LuaMetatable,
115            disposition: CandidateDisposition::Exclude,
116            domain: SemanticDomain::MetamethodLookup,
117            declared_parent: ParentMeaning::MetatableDelegate,
118            source_anchor: "sim-runtime/crates/sim-lib-lang-lua/src/metatable.rs",
119        },
120        SemanticCandidate {
121            model: CandidateModel::TypeclassDictionary,
122            disposition: CandidateDisposition::Exclude,
123            domain: SemanticDomain::ConstraintEvidence,
124            declared_parent: ParentMeaning::ConstraintWitness,
125            source_anchor: "sim-runtime/crates/sim-lib-lang-typed-lazy/src/runtime.rs",
126        },
127        SemanticCandidate {
128            model: CandidateModel::PrologRelation,
129            disposition: CandidateDisposition::Exclude,
130            domain: SemanticDomain::LogicalRelation,
131            declared_parent: ParentMeaning::PredicateArgument,
132            source_anchor: "sim-runtime/crates/sim-lib-lang-prolog/src/surface.rs",
133        },
134        SemanticCandidate {
135            model: CandidateModel::GenericDispatch,
136            disposition: CandidateDisposition::Exclude,
137            domain: SemanticDomain::MethodSelection,
138            declared_parent: ParentMeaning::ApplicableMethod,
139            source_anchor: "sim-runtime/crates/sim-lib-dispatch/src/method.rs",
140        },
141        SemanticCandidate {
142            model: CandidateModel::JvmLoaderIdentity,
143            disposition: CandidateDisposition::Exclude,
144            domain: SemanticDomain::RuntimeTypeIdentity,
145            declared_parent: ParentMeaning::DefiningLoaderIdentity,
146            source_anchor: "no-owner:index-and-source-inventory",
147        },
148    ]
149}
150
151pub const fn exclusion_ledger() -> &'static [ExclusionReason] {
152    &[
153        ExclusionReason {
154            model: CandidateModel::JavascriptPrototype,
155            required: ParentMeaning::DeclaredSuperclass,
156            actual: ParentMeaning::PrototypeDelegate,
157            mismatch_code: "prototype-delegates-properties-not-declared-ancestry",
158        },
159        ExclusionReason {
160            model: CandidateModel::LuaMetatable,
161            required: ParentMeaning::DeclaredSuperclass,
162            actual: ParentMeaning::MetatableDelegate,
163            mismatch_code: "metatable-delegates-operations-not-declared-ancestry",
164        },
165        ExclusionReason {
166            model: CandidateModel::TypeclassDictionary,
167            required: ParentMeaning::DeclaredSuperclass,
168            actual: ParentMeaning::ConstraintWitness,
169            mismatch_code: "dictionary-witnesses-constraint-not-subclass-edge",
170        },
171        ExclusionReason {
172            model: CandidateModel::PrologRelation,
173            required: ParentMeaning::DeclaredSuperclass,
174            actual: ParentMeaning::PredicateArgument,
175            mismatch_code: "predicate-name-has-no-inheritance-semantics",
176        },
177        ExclusionReason {
178            model: CandidateModel::GenericDispatch,
179            required: ParentMeaning::DeclaredSuperclass,
180            actual: ParentMeaning::ApplicableMethod,
181            mismatch_code: "specificity-orders-methods-not-classes",
182        },
183        ExclusionReason {
184            model: CandidateModel::JvmLoaderIdentity,
185            required: ParentMeaning::DeclaredSuperclass,
186            actual: ParentMeaning::DefiningLoaderIdentity,
187            mismatch_code: "loader-qualifies-type-identity-not-parent-resolution",
188        },
189    ]
190}
191
192pub const fn non_goals() -> &'static [NonGoal] {
193    &[
194        NonGoal {
195            model: CandidateModel::JavascriptPrototype,
196            excluded_semantics: "prototype mutation, property descriptors, private brands, and constructor/new policy",
197        },
198        NonGoal {
199            model: CandidateModel::LuaMetatable,
200            excluded_semantics: "__index traversal, metamethod invocation, and raw table access",
201        },
202        NonGoal {
203            model: CandidateModel::TypeclassDictionary,
204            excluded_semantics: "constraint inference, instance coherence, and dictionary method lookup",
205        },
206        NonGoal {
207            model: CandidateModel::PrologRelation,
208            excluded_semantics: "unification, backtracking, clauses, and relation evaluation",
209        },
210        NonGoal {
211            model: CandidateModel::GenericDispatch,
212            excluded_semantics: "method applicability, Shape specificity, method combination, and invocation",
213        },
214        NonGoal {
215            model: CandidateModel::JvmLoaderIdentity,
216            excluded_semantics: "classfile loading, verification, initialization, linking, and defining-loader namespaces",
217        },
218    ]
219}