Skip to content

Commit c034829

Browse files
committed
fix(codex P1 #457): restore deprecated NarsRule + nars_rule() for back-compat
PR #457 removed PearlJunction::nars_rule() + the NarsRule enum outright. Codex P1 review flagged this as a breaking change for downstream consumers that imported PR #456's public surface, even one commit after introduction. This PR restores both as #[deprecated] shims: - pub enum NarsRule { Deduction, Induction, Abduction } marked #[deprecated(since = "0.2.0", note = "...")] - preserved as the original three-variant alias enum - PearlJunction::nars_rule() -> Option<NarsRule> marked deprecated with the same since/note - delegates to the same Chain/ChainRev/ Fork/Collider mapping it had in PR #456 - impl From<NarsRule> for InferenceType - 1:1 migration helper so consumers can lift the deprecated type to the canonical one The canonical inference_type() -> Option<InferenceType> method introduced in PR #457 is the recommended API; the deprecated shims emit a compile-time warning pointing to it. Removed in a future major version bump. Tests: - deprecated_nars_rule_matches_inference_type (round-trip via From) - deprecated_nars_rule_none_when_unrelated - from_nars_rule_lifts_to_inference_type (the From mapping) All marked #[allow(deprecated)] so they exercise the shim without triggering the warning. Net: the public surface of PR #456 remains intact (with deprecation warnings); new consumers reach for inference_type() + InferenceType; the duplication-map drift CodeRabbit warned about is constrained to the deprecated subset and slated for removal in 0.x.0. Provenance: codex P1 on PR #457 commit 5e3740c.
1 parent 063f7df commit c034829

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

crates/lance-graph-contract/src/pearl_junction.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,72 @@ impl PearlJunction {
9999
Self::Unrelated => None,
100100
}
101101
}
102+
103+
/// **Deprecated** — use [`Self::inference_type`] instead.
104+
///
105+
/// Back-compat shim preserved for downstream consumers that imported
106+
/// PR #456's `nars_rule() -> Option<NarsRule>` surface (per codex P1
107+
/// review on PR #457 — removing the method outright is a breaking
108+
/// change even one commit after introduction). New code should call
109+
/// `inference_type()`, which returns the canonical
110+
/// [`crate::nars::InferenceType`].
111+
///
112+
/// The mapping is identical (Chain / ChainRev → Deduction; Fork →
113+
/// Induction; Collider → Abduction); the returned [`NarsRule`] is a
114+
/// deprecated subset enum that `From`-converts into `InferenceType`.
115+
#[deprecated(
116+
since = "0.2.0",
117+
note = "Use `inference_type()` which returns the canonical `crate::nars::InferenceType`. `NarsRule` is preserved as a deprecated alias for back-compat with PR #456."
118+
)]
119+
#[allow(deprecated)]
120+
pub const fn nars_rule(self) -> Option<NarsRule> {
121+
match self {
122+
Self::Chain | Self::ChainRev => Some(NarsRule::Deduction),
123+
Self::Fork => Some(NarsRule::Induction),
124+
Self::Collider => Some(NarsRule::Abduction),
125+
Self::Unrelated => None,
126+
}
127+
}
128+
}
129+
130+
/// **Deprecated** — use [`crate::nars::InferenceType`] instead.
131+
///
132+
/// Back-compat alias for PR #456's original three-variant NARS-rule
133+
/// enum. `NarsRule` always corresponds 1:1 to a subset of
134+
/// [`InferenceType`] (Deduction / Induction / Abduction); the full
135+
/// `InferenceType` taxonomy also includes Revision + Synthesis which
136+
/// are not junction-derivable. `From<NarsRule>` lifts to the canonical
137+
/// type for migration.
138+
///
139+
/// Removed in a future major bump; new code should not introduce
140+
/// references to this enum.
141+
#[deprecated(
142+
since = "0.2.0",
143+
note = "Use `crate::nars::InferenceType` instead. `NarsRule` is preserved as a back-compat alias for PR #456's original surface; `From<NarsRule>` lifts to the canonical type."
144+
)]
145+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
146+
pub enum NarsRule {
147+
/// Chain figure: `M -> P`, `S -> M` ⊢ `S -> P` (or the reverse).
148+
Deduction,
149+
/// Fork figure (common cause): `M -> P`, `M -> S` ⊢ `S -> P` (with
150+
/// confidence calibrated by Pearl's induction discounting).
151+
Induction,
152+
/// Collider figure (explaining-away): `P -> M`, `S -> M` ⊢ `S -> P`
153+
/// (with confidence calibrated by Pearl's abduction discounting).
154+
Abduction,
155+
}
156+
157+
#[allow(deprecated)]
158+
impl From<NarsRule> for InferenceType {
159+
/// Lift a deprecated [`NarsRule`] to the canonical
160+
/// [`InferenceType`]. The mapping is 1:1.
161+
fn from(r: NarsRule) -> Self {
162+
match r {
163+
NarsRule::Deduction => InferenceType::Deduction,
164+
NarsRule::Induction => InferenceType::Induction,
165+
NarsRule::Abduction => InferenceType::Abduction,
166+
}
167+
}
102168
}
103169

104170
/// A pair of SPO edges expressed as their four `NiblePath` endpoints.
@@ -345,4 +411,49 @@ mod tests {
345411
// Both edges' subjects are out-of-range → EMPTY.
346412
assert_eq!(EdgePair::new(bad1, real, bad2, real).classify(), PearlJunction::Unrelated);
347413
}
414+
415+
416+
// ===== Back-compat shim (codex P1 on PR #457) =====
417+
418+
/// The deprecated nars_rule() method must continue to work for
419+
/// downstream consumers that imported PR #456's surface. Verifies the
420+
/// 1:1 correspondence with inference_type().
421+
#[test]
422+
#[allow(deprecated)]
423+
fn deprecated_nars_rule_matches_inference_type() {
424+
let dog = NiblePath::root(0x1).child(0x1);
425+
let cat = NiblePath::root(0x1).child(0x2);
426+
let mammal = NiblePath::root(0x1);
427+
428+
let collider = EdgePair::new(dog, mammal, cat, mammal).classify();
429+
assert_eq!(collider.nars_rule(), Some(NarsRule::Abduction));
430+
assert_eq!(collider.inference_type(), Some(InferenceType::Abduction));
431+
432+
// Round-trip via From<NarsRule>
433+
let canonical: InferenceType = collider.nars_rule().unwrap().into();
434+
assert_eq!(canonical, collider.inference_type().unwrap());
435+
}
436+
437+
/// Unrelated returns None on both methods.
438+
#[test]
439+
#[allow(deprecated)]
440+
fn deprecated_nars_rule_none_when_unrelated() {
441+
let a = NiblePath::root(0x1);
442+
let b = NiblePath::root(0x2);
443+
let c = NiblePath::root(0x3);
444+
let d = NiblePath::root(0x4);
445+
let j = EdgePair::new(a, b, c, d).classify();
446+
assert_eq!(j.nars_rule(), None);
447+
assert_eq!(j.inference_type(), None);
448+
}
449+
450+
/// From<NarsRule> for InferenceType covers the three deprecated variants.
451+
#[test]
452+
#[allow(deprecated)]
453+
fn from_nars_rule_lifts_to_inference_type() {
454+
assert_eq!(InferenceType::from(NarsRule::Deduction), InferenceType::Deduction);
455+
assert_eq!(InferenceType::from(NarsRule::Induction), InferenceType::Induction);
456+
assert_eq!(InferenceType::from(NarsRule::Abduction), InferenceType::Abduction);
457+
}
458+
348459
}

0 commit comments

Comments
 (0)