Skip to content

Let engine G run on terms with free variables - #357

Merged
tamnd merged 3 commits into
mainfrom
perf/g-open
Dec 2, 2026
Merged

tamnd merged 3 commits into
mainfrom
perf/g-open

Conversation

@tamnd

@tamnd tamnd commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Part of #354.

Engine G (ground.rs) now runs on terms with free variables. Before this change, ground_ok rejected each term with a free variable, so the Nat extension gave these terms to engine R.

The machine of engine G is lazy. An argument goes into a thunk, and a step that reads a free variable stops the machine. So when engine G gives a result, the result does not depend on a free variable, and it is the result of the same steps of engine R.

In short-circuit-and-bad, t[i]! needs the size of an array that 600 Array.push calls build. The elements read the free variables p and q, but the size does not read them. Engine R forced the full list with about 938k rule steps, and each step made and interned new terms. Engine G now gives the size with no new terms.

Measures (instructions, build without PGO, server4):

Test Before After
short-circuit-and-bad 23.94 G 4.28 G
init 46.11 G 46.10 G
std 83.37 G 83.37 G
Sum of the 44 perf tests 96.63 G 76.96 G

No other perf test changes by more than 0.05 G. The 238 Arena verdicts are correct, and --confirm all gives 0 disagreements on init, std and the Arena tests. The sum of the perf tests is now less than the sum of each rival (kefir 85.59 G, gruszka 97.69 G, nano-lean 100.78 G).

Changes:

  • ground_ok no longer needs a term with no free variable.
  • A new unit test nat_argument_with_a_free_variable in crates/rulean-core/tests/tc.rs.
  • Spec section perf/19.32, with a correction to 19.31.7.
  • A changelog entry.

tamnd added 3 commits December 2, 2026 21:11
Engine G is lazy, so a free variable that the computation does not read stays in its thunk, and a read of a free variable bails. So engine G can give the value of an open term such as the length of a list whose elements read a free variable.
The test gives a Nat argument that has a free variable that the computation does not read, and an argument where the computation reads the free variable.
The section gives the root cause of the cost of short-circuit-and-bad, the change to engine G, the measures and the tests where rulean is behind. It also corrects 19.31.7, and the changelog and the module doc of engine G follow the change.
@tamnd tamnd added this to the M14 Perf: closed computation milestone Dec 2, 2026
@tamnd tamnd added area/core The type checker: engines F and R, declarations, profiles type/perf Fewer instructions, less memory or less wall time labels Dec 2, 2026
@tamnd
tamnd enabled auto-merge (squash) December 2, 2026 14:34
@tamnd tamnd mentioned this pull request Dec 2, 2026
2 of 9 tasks
@tamnd
tamnd merged commit c394a69 into main Dec 2, 2026
27 of 29 checks passed
@tamnd
tamnd deleted the perf/g-open branch December 2, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core The type checker: engines F and R, declarations, profiles type/perf Fewer instructions, less memory or less wall time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant