Skip to content

DFCC: skip loop assigns inference when no loop needs it - #9582

Open
Kieran-Hulsman wants to merge 1 commit into
diffblue:developfrom
Kieran-Hulsman:kieran/dfcc-skip-loop-assigns-inference
Open

Kieran-Hulsman wants to merge 1 commit into
diffblue:developfrom
Kieran-Hulsman:kieran/dfcc-skip-loop-assigns-inference

Conversation

@Kieran-Hulsman

Copy link
Copy Markdown

DFCC runs the loop assigns inference for every function with a loop contract, but only uses the result for loops without an assigns clause. The inference inlines every callee, so it gets expensive quickly. This skips it when every loop with a contract already has an assigns clause. The instrumented program doesn't change (same --show-goto-functions output on the inputs below).

I discovered this while writing model-checking/verify-rust-std#758. Kani always emits loop assigns clauses, so it pays for the inference without using it. On the BinaryHeap harnesses there, goto-instrument 6.11.0 ran out of memory or needed up to 14 GB. With this patch, none needs more than 142 MB. This may also be the cause of model-checking/kani#4967.

loop_assigns_inference-all-explicit checks that the inference is skipped, and -mixed and -mixed-fail check that it still runs when only some loops have an assigns clause.

goto-instrument on develop (cf12e35b):

Input develop this PR
Generated C: one loop with an assigns clause, calling a chain of 120 functions (about 12000 instructions once inlined) 19.9 s / 3686 MB 9.9 s / 254 MB
Same generator with 40 functions, loop without an assigns clause (the inference is still needed) 3.1 s / 431 MB 2.5 s / 431 MB
Goto binary from Kani for a BinaryHeap::sift_up-style loop with -Z valid-value-checks 16.3 s / 1596 MB 1.6 s / 37 MB
  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

The inferred loop assigns are only used for loops that have a contract
but no assigns clause, yet dfcc_cfg_infot ran the inference for every
function with a loop contract. The inference inlines all callees and
computes dominators, so its cost is quadratic in the inlined size.

Only run it when some loop needs it. The instrumented program does not
change. On a synthetic loop that reaches 12000 instructions,
goto-instrument goes from 19.9 s and 3.7 GB to 9.9 s and 254 MB.
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.32%. Comparing base (cf12e35) to head (5d1de7d).
⚠️ Report is 41 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9582      +/-   ##
===========================================
+ Coverage    81.28%   81.32%   +0.03%     
===========================================
  Files         1725     1726       +1     
  Lines       191618   191741     +123     
  Branches        73       73              
===========================================
+ Hits        155763   155936     +173     
+ Misses       35855    35805      -50     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

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

Labels

Code Contracts Function and loop contracts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants