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

Function compare_level

crates/compile/src/compile.rs:2385–2436  ·  view source on GitHub ↗

Compare two universe levels structurally, using level parameter position (not name) for `Param` comparisons.

(
  x: &Level,
  y: &Level,
  x_ctx: &[Name],
  y_ctx: &[Name],
)

Source from the content-addressed store, hash-verified

2383 let value_root = *cache.arena_roots.last().expect("missing value arena root");
2384
2385 // Take arena, surgery sharing, and level-spelling channels (canonicity
2386 // §10.6), clear for next constant
2387 let arena = std::mem::take(&mut cache.arena);
2388 let surgery_sharing = std::mem::take(&mut cache.surgery_sharing);
2389 let meta_univs: Vec<Arc<Univ>> =
2390 std::mem::take(&mut cache.meta_univs).into_iter().collect();
2391 let univ_patches = std::mem::take(&mut cache.univ_patches);
2392 cache.arena_roots.clear();
2393 cache.exprs.clear();
2394
2395 let name_addr = compile_name(&def.name, stt);
2396 let lvl_addrs: Vec<Address> =
2397 univ_params.iter().map(|n| compile_name(n, stt)).collect();
2398 let all_addrs: Vec<Address> =
2399 def.all.iter().map(|n| compile_name(n, stt)).collect();
2400 let ctx_addrs: Vec<Address> = ctx_addrs.to_vec();
2401
2402 let data = Definition {
2403 kind: def.kind,
2404 safety: def.safety,
2405 lvls: def.level_params.len() as u64,
2406 typ,
2407 value,
2408 };
2409
2410 let mut meta = ConstantMeta::new(ConstantMetaInfo::Def {
2411 name: name_addr,
2412 lvls: lvl_addrs,
2413 all: all_addrs,
2414 ctx: ctx_addrs,
2415 arena,
2416 type_root,
2417 value_root,
2418 });
2419 meta.meta_sharing = surgery_sharing;
2420 meta.meta_univs = meta_univs;
2421 meta.univ_patches = univ_patches;
2422 stt.def_hints.insert(def.name.clone(), def.hints);
2423
2424 Ok((data, meta))
2425}
2426
2427/// Compile a RecursorRule.
2428fn compile_recursor_rule(
2429 rule: &LeanRecursorRule,
2430 univ_params: &[Name],
2431 mut_ctx: &MutCtx,
2432 cache: &mut BlockCache,
2433 stt: &CompileState,
2434) -> Result<(RecursorRule, Address), CompileError> {
2435 let rhs = compile_expr(&rule.rhs, univ_params, mut_ctx, cache, stt)?;
2436 let ctor_addr = compile_name(&rule.ctor, stt);
2437 let fields = nat_to_u64(&rule.n_fields, "n_fields too large")?;
2438
2439 Ok((RecursorRule { fields, rhs }, ctor_addr))

Callers 1

compare_exprFunction · 0.85

Calls 3

as_dataMethod · 0.80
prettyMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected