( arr: LeanArray<LeanBorrowed<'_>>, n_threads: usize, )
| 322 | /// Each thread decodes all exprs and counts nodes. |
| 323 | #[unsafe(no_mangle)] |
| 324 | pub extern "C" fn rs_mt_parallel_decode_exprs( |
| 325 | arr: LeanArray<LeanBorrowed<'_>>, |
| 326 | n_threads: usize, |
| 327 | ) -> LeanOwned { |
| 328 | fn count_expr_nodes(expr: &LeanIxExpr<impl LeanRef>) -> u64 { |
| 329 | let ctor = expr.as_ctor(); |
| 330 | match ctor.tag() { |
| 331 | 5 => { |
| 332 | // app |
| 333 | 1 + count_expr_nodes(&LeanIxExpr(ctor.get(0))) |
| 334 | + count_expr_nodes(&LeanIxExpr(ctor.get(1))) |
| 335 | }, |
| 336 | _ => 1, |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | let shared = LeanShared::new(arr.inner().to_owned_ref()); |
| 341 | |
| 342 | let handles: Vec<_> = (0..n_threads) |
| 343 | .map(|_| { |
| 344 | let shared_clone = shared.clone(); |
| 345 | thread::spawn(move || { |
| 346 | let borrowed_arr = shared_clone.borrow().as_array(); |
| 347 | let mut total: u64 = 0; |
| 348 | for elem in borrowed_arr.iter() { |
| 349 | total += count_expr_nodes(&LeanIxExpr(elem)); |
| 350 | } |
| 351 | total |
| 352 | }) |
| 353 | }) |
| 354 | .collect(); |
| 355 | |
| 356 | let total: u64 = handles.into_iter().map(|h| h.join().unwrap()).sum(); |
| 357 | LeanNat::from_nat(&Nat::from(total)).into() |
| 358 | } |
| 359 | |
| 360 | /// Parallel roundtrip: mark array of Names as MT, each thread decodes |
| 361 | /// all names and rebuilds them. Returns an array of rebuilt names from |
nothing calls this directly
no test coverage detected