Skip to content

Higher order code trees#833

Open
mezpusz wants to merge 8 commits intomasterfrom
higher-order-code-tree
Open

Higher order code trees#833
mezpusz wants to merge 8 commits intomasterfrom
higher-order-code-tree

Conversation

@mezpusz
Copy link
Copy Markdown
Contributor

@mezpusz mezpusz commented Mar 26, 2026

Adapting code trees and structures that use them to HOL matching. The is mostly just shoving a compile-time flag into all of these structures and then disallowing:

  1. iterating into subterms of lambdas
  2. binding a variable during the matching to a term that contains a loose (unbound) DB index

Some minor improvements:

  1. fixed the Twee transformation
  2. added a sampler for HOL, which is just a copy of the FOL one, except I commented function definition introduction, as that still causes a lot of trouble
  3. added a debug check in the clause constructor that ensures that variables have consistent sorts across the clause

FOL regression showed no difference, and a couple of rounds of debug sampling only showed problems with other, not yet touched inferences. HOL regression showed that a few dozens crashes are now avoided and we get the following figures:

Discount:

run 0 unsat: 2104 (6) sat: 1 (0) cputime: 8654.87 s instructions: 42508618 Mi memory: 111919.98 MB
run 1 unsat: 2102 (4) sat: 1 (0) cputime: 8766.45 s instructions: 43656482 Mi memory: 111123.53 MB

Otter:

run 0 unsat: 2067 (13) sat: 1 (0) cputime: 8814.59 s instructions: 40455089 Mi memory: 124760.39 MB
run 1 unsat: 2081 (27) sat: 1 (0) cputime: 9170.97 s instructions: 44360027 Mi memory: 133042.59 MB

// MY_GEN_RULE, MY_GEN_TESTER, LIST_ALPHA_SUGAR,
// Generation::SymmetricTest()
// .options(options("all"))
// .inputs({ clause({ cons(a, nil()) != cons(x, nil()),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joe-hauns do you have some idea how to fix this test? The reason I commented this is due to x having two different sorts in the input clause, violating the new variable sort consistency check I added.

fte++;
ASS_EQ(fte->_tag(), FlatTerm::FUN_TERM_PTR);
ASS(fte->_term());
if constexpr (higherOrder) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the important bit, where we do something differently for HOL.

} else {
doAssignVar();
}
shouldBacktrack=!doAssignVar();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might backtrack here now, but this never happens with higherOrder==false and hopefully gets optimized away.

(*this)[i] = lits[i];
}

#if VDEBUG
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the variable sort consistency check I mentioned in the summary. I think it's worth having it, as we get an error much earlier, avoiding well-sortedness errors later seemingly coming out of nowhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug builds have always been glacial (and only got worse recently when I turned on all the sanitisers), so I think this is sensible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have it as a "turn on when you get weird typing errors" but then nobody would find it, so I guess this is as good as it gets. (Sidenote: I wonder how much performance impact the well-sortedness check has. Probably not much as it is only performed for to-be-shared terms.)

Copy link
Copy Markdown
Contributor

@MichaelRawson MichaelRawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Nice sensible change, much better than I thought it would be.

General thought: we could at some point run experiments to see if the template for HOL is worth the template parameter or whether treating everything as maybe-HOLy is OK.

except I commented function definition introduction, as that still causes a lot of trouble

Ugh. Do you have a nice short crash for me? I could look into why/how this happens.

op=entry;
Base::ft=ft_;
Base::tp=0;
Base::op=Base::entry;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection, but why do we need to have this Base thing now? Is the compiler not smart enough to figure it out inside a templated class or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the usual C++ crap. I could also use this-> everywhere, but I decided to add some often used names as using and use Base:: for the rest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, I learned something. 😷

(*this)[i] = lits[i];
}

#if VDEBUG
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug builds have always been glacial (and only got worse recently when I turned on all the sanitisers), so I think this is sensible.

@mezpusz
Copy link
Copy Markdown
Contributor Author

mezpusz commented Mar 27, 2026

we could at some point run experiments to see if the template for HOL is worth the template parameter or whether treating everything as maybe-HOLy is OK.

I agree about this, my plan is to add some more sensible HO matching, where the templating matters, so that hopefully this gets justified in the future.

@mezpusz
Copy link
Copy Markdown
Contributor Author

mezpusz commented Mar 27, 2026

Ugh. Do you have a nice short crash for me? I could look into why/how this happens.

I will look at this again soon, I just didn't want to spagettify this PR too much. I think it might be as simple as changing NonVariableNonTypeIterator to RewritableSubtermIterator<higherOrder> on this line. Otherwise I will summon you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants