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

Function decode_level

crates/ffi/src/lean_env.rs:640–666  ·  view source on GitHub ↗
(obj: LeanBorrowed<'_>, cache: &mut Cache<'_>)

Source from the content-addressed store, hash-verified

638 list: LeanList<LeanBorrowed<'a>>,
639) -> Vec<LeanBorrowed<'a>> {
640 list.to_vec()
641}
642
643/// Collect list elements as LeanShared handles for cross-thread use.
644/// The caller should have already MT-marked the parent list via `LeanShared::new`,
645/// so `lean_mark_mt` on each element is a single `lean_is_st` check (fast no-op).
646fn collect_list_shared(list: LeanList<LeanBorrowed<'_>>) -> Vec<LeanShared> {
647 list.iter().map(|b| LeanShared::new(b.to_owned_ref())).collect()
648}
649
650// Name decoding with global cache
651pub fn decode_name(obj: LeanBorrowed<'_>, global: &GlobalCache) -> Name {
652 let ptr = obj.as_raw();
653 // Fast path: check if already cached
654 if let Some(name) = global.names.get(&ptr) {
655 return name.clone();
656 }
657
658 // Compute the name
659 let name = if obj.is_scalar() {
660 Name::anon()
661 } else {
662 let n = LeanIxName::from_ctor(obj.as_ctor());
663 let pre = decode_name(n.get_obj(0), global);
664 let pos = n.get_obj(1);
665 match n.as_ctor().tag() {
666 1 => Name::str(pre, pos.as_string().to_string()),
667 2 => Name::num(pre, LeanNat::to_nat(&pos)),
668 tag => unreachable!("Invalid Lean.Name tag: {tag}"),
669 }

Callers 1

decode_exprFunction · 0.85

Calls 6

decode_nameFunction · 0.85
tagMethod · 0.80
paramFunction · 0.50
getMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected