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

Function rs_kernel_check_consts

crates/ffi/src/kernel.rs:222–343  ·  view source on GitHub ↗
(
  env_consts: LeanList<LeanBorrowed<'_>>,
  names: LeanArray<LeanBorrowed<'_>>,
  expect_pass: LeanArray<LeanBorrowed<'_>>,
  quiet: LeanBool<LeanBorrowed<'_>>,
)

Source from the content-addressed store, hash-verified

220/// `IX_KERNEL_CHECK_NAME_CHARS`.
221#[unsafe(no_mangle)]
222pub extern "C" fn rs_kernel_check_consts(
223 env_consts: LeanList<LeanBorrowed<'_>>,
224 names: LeanArray<LeanBorrowed<'_>>,
225 expect_pass: LeanArray<LeanBorrowed<'_>>,
226 quiet: LeanBool<LeanBorrowed<'_>>,
227) -> LeanIOResult<LeanOwned> {
228 let total_start = Instant::now();
229 let quiet = quiet.to_bool();
230
231 // ---------------------------------------------------------------------
232 // Decode inputs
233 // ---------------------------------------------------------------------
234 let t0 = Instant::now();
235 let rust_env = decode_env(env_consts);
236 // Decode names structurally — no `Name.toString` / `parse_name` dance.
237 // The resulting `Name`s are byte-for-byte the same as the kernel's
238 // stored names (same component strings, same content hash).
239 let names_vec: Vec<Name> = decode_name_array(&names);
240 // `Array Bool` elements are boxed tagged scalars:
241 // `lean_box(n) = (n << 1) | 1`, so `Bool.false` has raw value 1 and
242 // `Bool.true` has raw value 3. `unbox_usize()` (= `as_raw() >> 1`)
243 // recovers the ctor tag (0 = false, 1 = true).
244 let expect_pass_vec: Vec<bool> =
245 expect_pass.map(|b| b.unbox_usize() == 1).into_iter().collect();
246 eprintln!("[rs_kernel_check] read env: {:>8.1?}", t0.elapsed());
247
248 // ---------------------------------------------------------------------
249 // Compile Lean → Ixon
250 // ---------------------------------------------------------------------
251 let t1 = Instant::now();
252 let rust_env_arc = Arc::new(rust_env);
253 let compile_state =
254 match compile_env_with_options(&rust_env_arc, CompileOptions::default()) {
255 Ok(s) => s,
256 Err(e) => {
257 return build_uniform_error(
258 names_vec.len(),
259 &format!("[compile] {e:?}"),
260 );
261 },
262 };
263 eprintln!("[rs_kernel_check] compile: {:>8.1?}", t1.elapsed());
264
265 let CompileState { env: ixon_env, ungrounded: compile_ungrounded, .. } =
266 compile_state;
267
268 // Snapshot per-constant compile failures (ill-formed inductives,
269 // cascading MissingConstant, etc.) keyed by `Name` so the check loop
270 // can skip the kernel and report them as compile-side rejections.
271 // `compile_env` no longer aborts on per-block failure; it populates
272 // `CompileState.ungrounded` and continues, letting good constants still
273 // compile cleanly.
274 let ungrounded: FxHashMap<Name, String> = compile_ungrounded
275 .iter()
276 .map(|e| (e.key().clone(), e.value().clone()))
277 .collect();
278 drop(compile_ungrounded);
279 drop(rust_env_arc);

Callers

nothing calls this directly

Calls 15

decode_envFunction · 0.85
decode_name_arrayFunction · 0.85
compile_env_with_optionsFunction · 0.85
build_uniform_errorFunction · 0.85
build_result_arrayFunction · 0.85
keyMethod · 0.80
valueMethod · 0.80
prettyMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected