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

Function compile_single_def

crates/compile/src/compile.rs:3228–3301  ·  view source on GitHub ↗

Helper: compile a single definition/theorem/opaque (non-mutual case). When `aux` is false (ephemeral compilation for metadata capture), skip storing the Ixon blob, Named entry, and block stats.

(
    name: &Name,
    def: &Def,
    cache: &mut BlockCache,
    stt: &CompileState,
    aux: bool,
  )

Source from the content-addressed store, hash-verified

3226 (MutConst::Defn(x), MutConst::Defn(y)) => compare_defn(x, y, mut_ctx, stt)?,
3227 (MutConst::Indc(x), MutConst::Indc(y)) => {
3228 compare_indc(x, y, mut_ctx, cache, stt)?
3229 },
3230 (MutConst::Recr(x), MutConst::Recr(y)) => compare_recr(x, y, mut_ctx, stt)?,
3231 _ => SOrd::cmp(&mut_const_kind(x), &mut_const_kind(y)),
3232 };
3233 if so.strong {
3234 cache.cmps.insert(key, so.ordering);
3235 }
3236 Ok(if reversed { so.ordering.reverse() } else { so.ordering })
3237}
3238
3239/// Check if two mutual constants are structurally equal.
3240pub fn eq_const(
3241 x: &MutConst,
3242 y: &MutConst,
3243 mut_ctx: &MutCtx,
3244 cache: &mut BlockCache,
3245 stt: &CompileState,
3246) -> Result<bool, CompileError> {
3247 let ordering = compare_const(x, y, mut_ctx, cache, stt)?;
3248 Ok(ordering == Ordering::Equal)
3249}
3250
3251/// Group consecutive equal elements in a sorted slice. Assumes the input
3252/// is already sorted by the same relation used for equality testing.
3253pub fn group_by<T, F>(
3254 items: Vec<&T>,
3255 mut eq: F,
3256) -> Result<Vec<Vec<&T>>, CompileError>
3257where
3258 F: FnMut(&T, &T) -> Result<bool, CompileError>,
3259{
3260 let mut groups = Vec::new();
3261 let mut current: Vec<&T> = Vec::new();
3262 for item in items {
3263 if let Some(last) = current.last() {
3264 if eq(last, item)? {
3265 current.push(item);
3266 } else {
3267 groups.push(std::mem::replace(&mut current, vec![item]));
3268 }
3269 } else {
3270 current.push(item);
3271 }
3272 }
3273 if !current.is_empty() {
3274 groups.push(current);
3275 }
3276 Ok(groups)
3277}
3278
3279/// Merge two sorted sequences of mutual constants into one sorted sequence.
3280pub fn merge<'a>(
3281 left: Vec<&'a MutConst>,
3282 right: Vec<&'a MutConst>,
3283 ctx: &MutCtx,
3284 cache: &mut BlockCache,
3285 stt: &CompileState,

Callers 1

compile_const_innerFunction · 0.85

Calls 13

preseed_expr_tablesFunction · 0.85
compile_definitionFunction · 0.85
prettyMethod · 0.80
as_sliceMethod · 0.80
store_constMethod · 0.80
register_nameMethod · 0.80
promote_auxMethod · 0.80
cloneMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected