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

Method check_ctor_against_inductive_member

crates/kernel/src/inductive.rs:360–424  ·  view source on GitHub ↗

Validate a standalone constructor against its parent inductive. Runs the same A1–A4 checks that `check_inductive_member` runs per-ctor.

(
    &mut self,
    ctor_id: &KId<M>,
    induct_id: &KId<M>,
  )

Source from the content-addressed store, hash-verified

358 KConst::Indc {
359 params, indices, lvls, block, is_unsafe, ty, ..
360 } => (params, indices, lvls, block.clone(), is_unsafe, ty.clone()),
361 _ => {
362 return Err(TcError::Other(
363 "check_ctor: parent inductive not found".into(),
364 ));
365 },
366 };
367
368 let block_inds = self.discover_block_inductives(&ind_block)?;
369 let block_addrs: Vec<Address> =
370 block_inds.iter().map(|id| id.addr.clone()).collect();
371
372 let ind_level = self.get_result_sort_level(
373 &ind_ty,
374 u64_to_usize(ind_params + ind_indices)?,
375 )?;
376
377 // A1: Parameter domain agreement
378 self.check_param_agreement(&ind_ty, &ctor_ty, u64_to_usize(ind_params)?)?;
379
380 // A3: Strict positivity. Match Lean: unsafe inductives bypass this check.
381 if !ind_is_unsafe {
382 self.check_positivity(
383 &ctor_ty,
384 u64_to_usize(ind_params)?,
385 &block_addrs,
386 )?;
387 }
388
389 // A4: Universe constraints
390 self.check_field_universes(
391 &ctor_ty,
392 u64_to_usize(ind_params)?,
393 &ind_level,
394 )?;
395
396 // A2: Constructor return type
397 self.check_ctor_return_type(
398 &ctor_ty,
399 u64_to_usize(ind_params)?,
400 u64_to_usize(ind_indices)?,
401 ctor_fields,
402 &induct_id.addr,
403 ind_lvls,
404 &block_addrs,
405 )?;
406
407 Ok(())
408 }
409
410 /// Discover all inductives in a mutual block.
411 fn discover_block_inductives(
412 &mut self,
413 block_id: &KId<M>,
414 ) -> Result<Vec<KId<M>>, TcError<M>> {
415 let Some(members) = self.try_get_block(block_id)? else {
416 return Ok(vec![]);
417 };

Callers 3

check_const_memberMethod · 0.80
check_inductive_blockMethod · 0.80

Calls 10

u64_to_usizeFunction · 0.85
get_result_sort_levelMethod · 0.80
check_param_agreementMethod · 0.80
check_positivityMethod · 0.80
check_field_universesMethod · 0.80
get_constMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected