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

Function compile_const_inner

crates/compile/src/compile.rs:3189–3460  ·  view source on GitHub ↗
(
  name: &Name,
  all: &NameSet,
  lean_env: &Arc<LeanEnv>,
  cache: &mut BlockCache,
  stt: &CompileState,
  kctx: &mut KernelCtx,
  aux: bool,
)

Source from the content-addressed store, hash-verified

3187 },
3188 )
3189 })
3190 })
3191 })
3192 })
3193 })
3194 },
3195 )
3196}
3197
3198/// Returns a kind ordinal for cross-kind comparison of mutual constants.
3199fn mut_const_kind(c: &MutConst) -> u8 {
3200 match c {
3201 MutConst::Defn(_) => 0,
3202 MutConst::Indc(_) => 1,
3203 MutConst::Recr(_) => 2,
3204 }
3205}
3206
3207/// Compare two mutual constants with caching. Dispatches to the appropriate
3208/// type-specific comparator (defn, indc, recr). Different-kind constants
3209/// are ordered by kind tag.
3210pub fn compare_const(
3211 x: &MutConst,
3212 y: &MutConst,
3213 mut_ctx: &MutCtx,
3214 cache: &mut BlockCache,
3215 stt: &CompileState,
3216) -> Result<Ordering, CompileError> {
3217 let (key, reversed) = if x.name() <= y.name() {
3218 ((x.name(), y.name()), false)
3219 } else {
3220 ((y.name(), x.name()), true)
3221 };
3222 if let Some(so) = cache.cmps.get(&key) {
3223 return Ok(if reversed { so.reverse() } else { *so });
3224 }
3225 let so: SOrd = match (x, y) {
3226 (MutConst::Defn(x), MutConst::Defn(y)) => compare_defn(x, y, mut_ctx, stt)?,
3227 (MutConst::Indc(x), MutConst::Indc(y)) => {
3228 compare_indc(x, y, mut_ctx, cache, stt)?
3229 },
3230 (MutConst::Recr(x), MutConst::Recr(y)) => compare_recr(x, y, mut_ctx, stt)?,
3231 _ => SOrd::cmp(&mut_const_kind(x), &mut_const_kind(y)),
3232 };
3233 if so.strong {
3234 cache.cmps.insert(key, so.ordering);
3235 }
3236 Ok(if reversed { so.ordering.reverse() } else { so.ordering })
3237}
3238
3239/// Check if two mutual constants are structurally equal.
3240pub fn eq_const(
3241 x: &MutConst,
3242 y: &MutConst,
3243 mut_ctx: &MutCtx,
3244 cache: &mut BlockCache,
3245 stt: &CompileState,
3246) -> Result<bool, CompileError> {

Callers 2

compile_constFunction · 0.85
compile_const_no_auxFunction · 0.85

Calls 15

compile_single_defFunction · 0.85
mk_defnFunction · 0.85
compile_mutualFunction · 0.85
preseed_expr_tablesFunction · 0.85
compile_axiomFunction · 0.85
compile_quotientFunction · 0.85
compile_recursorFunction · 0.85
resolve_addr_auxMethod · 0.80
prettyMethod · 0.80

Tested by

no test coverage detected