( name: &Name, named: &Named, cnst: &Constant, mutuals: &[MutConst], block_sharing: &[Arc<Expr>], block_refs: &[Address], block_univs: &[Arc<Univ>], stt: &CompileState, dstt: &Decomp
| 1663 | /// Extract the all field from ConstantMeta (original Lean all field for roundtrip). |
| 1664 | fn get_all_from_meta(meta: &ConstantMeta) -> &[Address] { |
| 1665 | match &meta.info { |
| 1666 | ConstantMetaInfo::Def { all, .. } => all, |
| 1667 | ConstantMetaInfo::Indc { all, .. } => all, |
| 1668 | ConstantMetaInfo::Rec { all, .. } => all, |
| 1669 | _ => &[], |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | /// Extract the ctx field from ConstantMeta (MutCtx used during compilation for Rec expr decompilation). |
| 1674 | fn get_ctx_from_meta(meta: &ConstantMeta) -> &[Address] { |
| 1675 | match &meta.info { |
| 1676 | ConstantMetaInfo::Def { ctx, .. } => ctx, |
| 1677 | ConstantMetaInfo::Indc { ctx, .. } => ctx, |
| 1678 | ConstantMetaInfo::Rec { ctx, .. } => ctx, |
| 1679 | _ => &[], |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /// Decompile a name from ConstantMeta. |
| 1684 | fn decompile_name_from_meta( |
| 1685 | meta: &ConstantMeta, |
| 1686 | stt: &CompileState, |
| 1687 | ) -> Result<Name, DecompileError> { |
| 1688 | match get_name_addr_from_meta(meta) { |
| 1689 | Some(addr) => decompile_name(addr, stt), |
| 1690 | None => { |
| 1691 | Err(DecompileError::BadConstantFormat { msg: "empty metadata".into() }) |
| 1692 | }, |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | /// Extract level param names from ConstantMeta. |
| 1697 | fn decompile_level_names_from_meta( |
| 1698 | meta: &ConstantMeta, |
| 1699 | stt: &CompileState, |
| 1700 | ) -> Result<Vec<Name>, DecompileError> { |
| 1701 | get_lvls_from_meta(meta).iter().map(|a| decompile_name(a, stt)).collect() |
| 1702 | } |
| 1703 | |
| 1704 | // =========================================================================== |
| 1705 | // Constant decompilation |
| 1706 | // =========================================================================== |
| 1707 | |
| 1708 | /// Decompile a ConstantVal (name, level_params, type). |
| 1709 | fn decompile_const_val( |
| 1710 | typ: &Arc<Expr>, |
| 1711 | meta: &ConstantMeta, |
| 1712 | cache: &mut BlockCache, |
| 1713 | stt: &CompileState, |
| 1714 | dstt: &DecompileState, |
| 1715 | ) -> Result<ConstantVal, DecompileError> { |
| 1716 | let name = decompile_name_from_meta(meta, stt)?; |
| 1717 | let level_params = decompile_level_names_from_meta(meta, stt)?; |
| 1718 | let (arena, type_root) = get_arena_and_type_root(meta); |
| 1719 | let typ = |
| 1720 | decompile_expr(typ, arena, type_root, &level_params, cache, stt, dstt)?; |
| 1721 | Ok(ConstantVal { name, level_params, typ }) |
| 1722 | } |
no test coverage detected