Helper: build a minimal Lean environment with mutual inductives.
(
names: &[&str],
ctor_counts: &[usize],
)
| 1206 | occurrence supplies {}", |
| 1207 | hr.target_rec.pretty(), |
| 1208 | needed, |
| 1209 | occ_levels.len() |
| 1210 | )); |
| 1211 | }; |
| 1212 | Ok((target_levels, sig.specs.clone())) |
| 1213 | } |
| 1214 | |
| 1215 | fn source_minor_type( |
| 1216 | rec: &RecursorVal, |
| 1217 | rec_levels: &[Level], |
| 1218 | params: &[LeanExpr], |
| 1219 | motives: &[LeanExpr], |
| 1220 | minors: &[LeanExpr], |
| 1221 | src_minor_idx: usize, |
| 1222 | ) -> Option<LeanExpr> { |
| 1223 | let mut cur = subst_levels(&rec.cnst.typ, &rec.cnst.level_params, rec_levels); |
| 1224 | for arg in |
| 1225 | params.iter().chain(motives.iter()).chain(minors.iter().take(src_minor_idx)) |
| 1226 | { |
| 1227 | match cur.as_data() { |
| 1228 | ExprData::ForallE(_, _, body, _, _) => { |
| 1229 | // `instantiate_rev`, not `instantiate1`: call-site args may carry |
| 1230 | // loose BVars into the caller's telescope (rec applications under |
| 1231 | // binders, e.g. `.brecOn_N.go` bodies) and must be lifted when |
| 1232 | // substituted under the type's remaining binders. |
| 1233 | cur = instantiate_rev(body, std::slice::from_ref(arg)); |
| 1234 | }, |
| 1235 | _ => return None, |
| 1236 | } |
| 1237 | } |
| 1238 | match cur.as_data() { |
| 1239 | ExprData::ForallE(_, dom, _, _, _) => Some(consume_type_annotations(dom)), |
| 1240 | _ => None, |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | fn peel_binders( |
| 1245 | mut cur: LeanExpr, |
| 1246 | n: usize, |
| 1247 | prefix: &str, |
| 1248 | offset: usize, |
| 1249 | ) -> Option<(Vec<LocalDecl>, Vec<LeanExpr>, LeanExpr)> { |
| 1250 | let mut decls = Vec::with_capacity(n); |
| 1251 | let mut fvars = Vec::with_capacity(n); |
| 1252 | for i in 0..n { |
| 1253 | match cur.as_data() { |
| 1254 | ExprData::ForallE(name, dom, body, bi, _) => { |
| 1255 | let (fv_name, fv) = fresh_fvar(prefix, offset + i); |
| 1256 | let decl = LocalDecl { |
| 1257 | fvar_name: fv_name, |
| 1258 | binder_name: name.clone(), |
| 1259 | domain: consume_type_annotations(dom), |
| 1260 | info: bi.clone(), |
| 1261 | }; |
| 1262 | cur = instantiate1(body, &fv); |
| 1263 | fvars.push(fv); |
| 1264 | decls.push(decl); |
| 1265 | }, |