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

Function rs_compile_env_rust_first

crates/ffi/src/compile.rs:672–712  ·  view source on GitHub ↗
(
  env_consts_ptr: LeanList<LeanBorrowed<'_>>,
)

Source from the content-addressed store, hash-verified

670 };
671
672 // Build block map: lowlink name -> (serialized bytes, sharing len)
673 let mut blocks: HashMap<Name, (Vec<u8>, usize)> = HashMap::new();
674
675 // Iterate over all names and their addresses
676 for entry in rust_stt.name_to_addr.iter() {
677 let name = entry.key().clone();
678 let addr = entry.value().clone();
679
680 // Skip if we already have this block (multiple names map to same block)
681 if blocks.contains_key(&name) {
682 continue;
683 }
684
685 // Get the compiled constant
686 if let Some(constant) = rust_stt.env.get_const(&addr) {
687 let mut bytes = Vec::new();
688 constant.put(&mut bytes);
689 let sharing_len = constant.sharing.len();
690 blocks.insert(name, (bytes, sharing_len));
691 }
692 }
693
694 // Return boxed RustCompiledEnv with full compile state for pre-sharing access
695 Box::into_raw(Box::new(RustCompiledEnv { blocks, compile_state: rust_stt }))
696}
697
698/// FFI: Compare a single block and return packed result.
699/// Returns a packed u64: high 32 bits = matches (1) or error code (0 = mismatch, 2 = not found)
700/// low 32 bits = first diff offset (if mismatch)
701#[cfg(feature = "test-ffi")]
702#[unsafe(no_mangle)]
703extern "C" fn rs_compare_block(
704 rust_env: *const RustCompiledEnv,
705 lowlink_name: LeanOwned,
706 lean_bytes: LeanByteArray<LeanOwned>,
707) -> u64 {
708 if rust_env.is_null() {
709 return 2u64 << 32; // not found
710 }
711 let global_cache = GlobalCache::default();
712 let name = decode_name(lowlink_name.borrow(), &global_cache);
713
714 let rust_env = unsafe { &*rust_env };
715 let lean_data = lean_bytes.as_bytes();

Callers

nothing calls this directly

Calls 11

decode_envFunction · 0.85
compile_env_with_optionsFunction · 0.85
keyMethod · 0.80
valueMethod · 0.80
iterMethod · 0.45
cloneMethod · 0.45
contains_keyMethod · 0.45
get_constMethod · 0.45
putMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected