( rust_env: *const RustCompiledEnv, lowlink_name: LeanOwned, lean_bytes: LeanByteArray<LeanOwned>, )
| 717 | ) -> *mut RustCompiledEnv { |
| 718 | // Decode Lean environment |
| 719 | let lean_env = crate::lean_env::decode_env(env_consts_ptr); |
| 720 | let lean_env = Arc::new(lean_env); |
| 721 | |
| 722 | // Compile with Rust |
| 723 | let rust_stt = |
| 724 | match compile_env_with_options(&lean_env, CompileOptions::default()) { |
| 725 | Ok(stt) => stt, |
| 726 | Err(_e) => { |
| 727 | return std::ptr::null_mut(); |
| 728 | }, |
| 729 | }; |
| 730 | |
| 731 | // Build block map: lowlink name -> (serialized bytes, sharing len) |
| 732 | let mut blocks: HashMap<Name, (Vec<u8>, usize)> = HashMap::new(); |
| 733 | |
| 734 | // Iterate over all names and their addresses |
| 735 | for entry in rust_stt.name_to_addr.iter() { |
| 736 | let name = entry.key().clone(); |
| 737 | let addr = entry.value().clone(); |
| 738 | |
| 739 | // Skip if we already have this block (multiple names map to same block) |
| 740 | if blocks.contains_key(&name) { |
| 741 | continue; |
| 742 | } |
| 743 | |
| 744 | // Get the compiled constant |
| 745 | if let Some(constant) = rust_stt.env.get_const(&addr) { |
| 746 | let mut bytes = Vec::new(); |
| 747 | constant.put(&mut bytes); |
| 748 | let sharing_len = constant.sharing.len(); |
| 749 | blocks.insert(name, (bytes, sharing_len)); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // Return boxed RustCompiledEnv with full compile state for pre-sharing access |
| 754 | Box::into_raw(Box::new(RustCompiledEnv { blocks, compile_state: rust_stt })) |
| 755 | } |
| 756 | |
| 757 | /// FFI: Compare a single block and return packed result. |
| 758 | /// Returns a packed u64: high 32 bits = matches (1) or error code (0 = mismatch, 2 = not found) |
| 759 | /// low 32 bits = first diff offset (if mismatch) |
nothing calls this directly
no test coverage detected