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

Function decompile_const

crates/compile/src/decompile.rs:1795–1891  ·  view source on GitHub ↗

Decompile a single constant (non-mutual).

(
  name: &Name,
  named: &Named,
  stt: &CompileState,
  dstt: &DecompileState,
)

Source from the content-addressed store, hash-verified

1793 cnst,
1794 induct: induct_name,
1795 cidx: Nat::from(ctor.cidx),
1796 num_params: Nat::from(ctor.params),
1797 num_fields: Nat::from(ctor.fields),
1798 is_unsafe: ctor.is_unsafe,
1799 })
1800}
1801
1802/// Decompile an Inductive.
1803/// Constructor metadata is resolved from Named entries, not from CtorMeta.
1804fn decompile_inductive(
1805 ind: &Inductive,
1806 meta: &ConstantMeta,
1807 cache: &mut BlockCache,
1808 stt: &CompileState,
1809 dstt: &DecompileState,
1810) -> Result<(InductiveVal, Vec<ConstructorVal>), DecompileError> {
1811 let name = decompile_name_from_meta(meta, stt)?;
1812 let level_params = decompile_level_names_from_meta(meta, stt)?;
1813
1814 let (arena, type_root) = get_arena_and_type_root(meta);
1815 let typ = decompile_expr(
1816 &ind.typ,
1817 arena,
1818 type_root,
1819 &level_params,
1820 cache,
1821 stt,
1822 dstt,
1823 )?;
1824
1825 // Extract constructor name addresses and all from metadata. The
1826 // non-Indc arm should be unreachable — `decompile_inductive` is only
1827 // called when the meta is an Indc variant. If we ever get here with
1828 // a different variant shape, that's structural corruption, not a
1829 // silently recoverable condition.
1830 let (ctor_name_addrs, all) = match &meta.info {
1831 ConstantMetaInfo::Indc { ctors, all: all_addrs, .. } => {
1832 let all = all_addrs
1833 .iter()
1834 .map(|a| decompile_name(a, stt))
1835 .collect::<Result<Vec<_>, _>>()?;
1836 (ctors.as_slice(), all)
1837 },
1838 other => {
1839 return Err(DecompileError::BadConstantFormat {
1840 msg: format!(
1841 "decompile_inductive for '{}': expected ConstantMetaInfo::Indc, \
1842 got variant with discriminant {:?}",
1843 name.pretty(),
1844 std::mem::discriminant(other),
1845 ),
1846 });
1847 },
1848 };
1849
1850 let mut ctors = Vec::with_capacity(ind.ctors.len());
1851 let mut ctor_names = Vec::new();
1852

Callers 1

decompile_named_constFunction · 0.85

Calls 13

read_constFunction · 0.85
get_all_from_metaFunction · 0.85
decompile_nameFunction · 0.85
all_to_ctxFunction · 0.85
decompile_definitionFunction · 0.85
decompile_recursorFunction · 0.85
decompile_axiomFunction · 0.85
decompile_quotientFunction · 0.85
prettyMethod · 0.80
load_meta_extensionsMethod · 0.80
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected