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

Method infer_proj

crates/kernel/src/infer.rs:329–448  ·  view source on GitHub ↗
(
    &mut self,
    struct_id: &KId<M>,
    field: u64,
    val: &KExpr<M>,
    val_ty: &KExpr<M>,
  )

Source from the content-addressed store, hash-verified

327
328 fn infer_proj(
329 &mut self,
330 struct_id: &KId<M>,
331 field: u64,
332 val: &KExpr<M>,
333 val_ty: &KExpr<M>,
334 ) -> Result<KExpr<M>, TcError<M>> {
335 use super::level::univ_eq;
336 use super::tc::collect_app_spine;
337
338 let wty = self.whnf(val_ty)?;
339 let (head, args) = collect_app_spine(&wty);
340
341 let head_id = match head.data() {
342 ExprData::Const(id, _, _) => id,
343 _ => {
344 return Err(TcError::Other(
345 "projection: struct type is not a constant".into(),
346 ));
347 },
348 };
349 if head_id.addr != struct_id.addr {
350 return Err(TcError::Other(
351 "projection: type mismatch with declared struct".into(),
352 ));
353 }
354
355 let (i_levels, num_params, num_indices, ctors) = match self
356 .try_get_const(head_id)?
357 {
358 Some(KConst::Indc { params, indices, ctors, .. }) => {
359 let levels = match head.data() {
360 ExprData::Const(_, us, _) => us.clone(),
361 _ => unreachable!(),
362 };
363 (
364 levels,
365 u64_to_usize::<M>(params)?,
366 u64_to_usize::<M>(indices)?,
367 ctors.clone(),
368 )
369 },
370 _ => {
371 return Err(TcError::Other("projection: not an inductive type".into()));
372 },
373 };
374
375 if ctors.len() != 1 {
376 return Err(TcError::Other(
377 "projection: inductive must have exactly one constructor".into(),
378 ));
379 }
380
381 // Check if the structure lives in Prop. Do this from the inductive
382 // declaration's result sort instead of inferring the full applied value
383 // type: projection-heavy proof terms otherwise re-infer every parameter
384 // and index argument just to recover a universe that is declaration-local.
385 let is_prop_struct = self.inductive_app_is_prop(
386 head_id,

Callers 1

inferMethod · 0.80

Calls 15

collect_app_spineFunction · 0.85
substFunction · 0.85
univ_eqFunction · 0.85
whnfMethod · 0.80
inductive_app_is_propMethod · 0.80
peel_proj_forallMethod · 0.80
inferMethod · 0.80
ensure_sortMethod · 0.80
lbrMethod · 0.80
internMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected