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

Method validate_expr_well_scoped

crates/kernel/src/check.rs:500–576  ·  view source on GitHub ↗
(
    &mut self,
    root: &KExpr<M>,
    root_depth: u64,
    lvl_bound: usize,
    mut timing: Option<&mut ValidationTiming>,
  )

Source from the content-addressed store, hash-verified

498 ) -> Result<Option<KId<M>>, TcError<M>> {
499 match c {
500 KConst::Defn { block, .. } => {
501 self.coordinated_block_if_kind(block, CheckBlockKind::Defn)
502 },
503 KConst::Indc { block, .. } => {
504 self.coordinated_block_if_kind(block, CheckBlockKind::Inductive)
505 },
506 KConst::Ctor { induct, .. } => {
507 let Some(parent) = self.try_get_const(induct)? else {
508 return Ok(None);
509 };
510 match parent {
511 KConst::Indc { block, .. } => {
512 self.coordinated_block_if_kind(&block, CheckBlockKind::Inductive)
513 },
514 _ => Ok(None),
515 }
516 },
517 KConst::Recr { block, .. } => {
518 self.coordinated_block_if_kind(block, CheckBlockKind::Recursor)
519 },
520 KConst::Axio { .. } | KConst::Quot { .. } => Ok(None),
521 }
522 }
523
524 fn coordinated_block_if_kind(
525 &mut self,
526 block: &KId<M>,
527 expected: CheckBlockKind,
528 ) -> Result<Option<KId<M>>, TcError<M>> {
529 let Some(members) = self.try_get_block(block)? else {
530 return Ok(None);
531 };
532 match self.classify_block(&members) {
533 Ok(kind) if kind == expected => Ok(Some(block.clone())),
534 Ok(_) | Err(_) => Ok(None),
535 }
536 }
537
538 fn classify_block(
539 &mut self,
540 members: &[KId<M>],
541 ) -> Result<CheckBlockKind, TcError<M>> {
542 if members.is_empty() {
543 return Err(TcError::Other("empty check block".into()));
544 }
545
546 let mut saw_defn = false;
547 let mut saw_recr = false;
548 let mut saw_inductive_like = false;
549 for member in members {
550 match self.get_const(member)? {
551 KConst::Defn { .. } => saw_defn = true,
552 KConst::Recr { .. } => saw_recr = true,
553 KConst::Indc { .. } | KConst::Ctor { .. } => {
554 saw_inductive_like = true;
555 },
556 KConst::Axio { .. } | KConst::Quot { .. } => {
557 return Err(TcError::Other(format!(

Callers 1

Calls 10

hash_keyMethod · 0.80
lvlsMethod · 0.80
pushMethod · 0.80
has_constMethod · 0.80
insertMethod · 0.45
dataMethod · 0.45
get_constMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected