MCPcopy Create free account
hub / github.com/argumentcomputer/ix / try_def_eq_unit

Method try_def_eq_unit

crates/kernel/src/def_eq.rs:856–897  ·  view source on GitHub ↗

Unit-like type: non-recursive, 0 indices, 1 ctor with 0 fields. If both values inhabit the same unit-like type, they're def-eq.

(
    &mut self,
    a: &KExpr<M>,
    b: &KExpr<M>,
  )

Source from the content-addressed store, hash-verified

854 /// Returns true iff `ty` is a propositional type — i.e. its sort is
855 /// `Sort 0`. Memoized on `(ty.hash_key(), ctx_hash)` because the answer
856 /// is a pure function of the type and the relevant context suffix.
857 ///
858 /// On a hit this is one `FxHashMap` probe; on a miss it pays the
859 /// existing `infer ∘ whnf` chain and stores the result. Errors from
860 /// the inner chain are propagated as `Ok(false)` (treating ill-typed
861 /// metadata as non-prop), matching the previous behaviour of
862 /// `try_proof_irrel`.
863 pub(crate) fn is_prop_type(&mut self, ty: &KExpr<M>) -> bool {
864 let cache_key = (ty.hash_key(), self.ctx_addr_for_lbr(ty.lbr()));
865 if let Some(&cached) = self.env.is_prop_cache.get(&cache_key) {
866 self.env.perf.record_is_prop_hit();
867 return cached;
868 }
869 self.env.perf.record_is_prop_miss();
870 self.record_hot_miss("is-prop", ty);
871
872 // infer(ty) returns the Sort that classifies `ty`. WHNF is needed because
873 // the inferred sort may be wrapped in `mdata` or a let-bound sort
874 // synonym before being structurally `Sort u`.
875 let result = match self.with_infer_only(|tc| tc.infer(ty)) {
876 Ok(sort) => match self.whnf(&sort) {
877 Ok(reduced) => match reduced.data() {
878 ExprData::Sort(u, _) => u.is_zero(),
879 _ => false,
880 },
881 Err(_) => false,
882 },
883 Err(_) => false,
884 };
885 self.env.is_prop_cache.insert(cache_key, result);
886 result
887 }
888
889 /// Unit-like type: non-recursive, 0 indices, 1 ctor with 0 fields.
890 /// If both values inhabit the same unit-like type, they're def-eq.
891 fn try_def_eq_unit(
892 &mut self,
893 a: &KExpr<M>,
894 b: &KExpr<M>,
895 ) -> Result<bool, TcError<M>> {
896 let a_ty = match self.with_infer_only(|tc| tc.infer(a)) {
897 Ok(ty) => ty,
898 Err(_) => return Ok(false),
899 };
900 let a_ty_w = match self.whnf(&a_ty) {

Callers 1

is_def_eq_whnfMethod · 0.80

Calls 9

collect_app_spineFunction · 0.85
with_infer_onlyMethod · 0.80
inferMethod · 0.80
whnfMethod · 0.80
dataMethod · 0.45
cloneMethod · 0.45
try_get_constMethod · 0.45
lenMethod · 0.45
is_def_eqMethod · 0.45

Tested by

no test coverage detected