Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The children iterators stop at Term::Def variants #719

Open
developedby opened this issue Sep 23, 2024 · 0 comments
Open

The children iterators stop at Term::Def variants #719

developedby opened this issue Sep 23, 2024 · 0 comments
Labels
bug Something isn't working compilation Compilation of terms and functions to HVM

Comments

@developedby
Copy link
Member

Reproducing the behavior

Term::children and this family of function is not returning the next term in the case of a Term::Def.

This is how it's currently defined

  pub fn children(&self) -> impl DoubleEndedIterator<Item = &Term> + Clone {
    multi_iterator!(ChildrenIter { Zero, One, Two, Vec, Mat, Swt, Bend, Fold });
    match self {
      Term::Mat { arg, bnd: _, with_bnd: _, with_arg, arms } => {
        ChildrenIter::Mat([arg.as_ref()].into_iter().chain(with_arg.iter()).chain(arms.iter().map(|r| &r.2)))
      }
      Term::Swt { arg, bnd: _, with_bnd: _, with_arg, pred: _, arms } => {
        ChildrenIter::Swt([arg.as_ref()].into_iter().chain(with_arg.iter()).chain(arms))
      }
      Term::Bend { bnd: _, arg: init, cond, step, base } => {
        ChildrenIter::Bend(init.iter().chain([cond.as_ref(), step.as_ref(), base.as_ref()]))
      }
      Term::Fold { bnd: _, arg, with_bnd: _, with_arg, arms } => {
        ChildrenIter::Fold([arg.as_ref()].into_iter().chain(with_arg.iter()).chain(arms.iter().map(|r| &r.2)))
      }
      Term::Fan { els, .. } | Term::List { els } => ChildrenIter::Vec(els),
      Term::Let { val: fst, nxt: snd, .. }
      | Term::Ask { val: fst, nxt: snd, .. }
      | Term::Use { val: fst, nxt: snd, .. }
      | Term::App { fun: fst, arg: snd, .. }
      | Term::Oper { fst, snd, .. } => ChildrenIter::Two([fst.as_ref(), snd.as_ref()]),
      Term::Lam { bod, .. } | Term::With { bod, .. } | Term::Open { bod, .. } => {
        ChildrenIter::One([bod.as_ref()])
      }
      Term::Var { .. }
      | Term::Link { .. }
      | Term::Num { .. }
      | Term::Nat { .. }
      | Term::Str { .. }
      | Term::Ref { .. }
      | Term::Def { .. }
      | Term::Era
      | Term::Err => ChildrenIter::Zero([]),
    }
  }

The Term::Def case should instead be Term::Def { nxt, .. } => ChildrenIter::One([nxt]).

This will cause the passes to stop at local function definitions and ignore the subtrees in the AST in this csae.

This will create some bugs in the compilation, although I don't currently have any concrete example.

System Settings

Bend commit 45839a7

Additional context

No response

@developedby developedby added bug Something isn't working compilation Compilation of terms and functions to HVM labels Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compilation Compilation of terms and functions to HVM
Projects
None yet
Development

No branches or pull requests

1 participant