Rust: Replace recursion through forall with ranked recursion#21679
Open
hvitved wants to merge 3 commits intogithub:mainfrom
Open
Rust: Replace recursion through forall with ranked recursion#21679hvitved wants to merge 3 commits intogithub:mainfrom
forall with ranked recursion#21679hvitved wants to merge 3 commits intogithub:mainfrom
Conversation
27f8658 to
5c6c3c0
Compare
1888e7a to
ad0a58f
Compare
ad0a58f to
e7930fe
Compare
e7930fe to
27f7f74
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Rust type inference library to avoid timeouts caused by recursion-through-forall in call-target compatibility checks, and includes a small refinement to blanket-constraint handling. It also updates/adjusts affected library tests and expectations to reflect the new resolution behavior.
Changes:
- Replaces recursion-through-
forallwith ranked recursion for “no compatible target” checks (via a newNoCompatibleTargethelper module) and fixes an incorrect compatibility check used for shared-borrow cases. - Refines blanket-constraint checking to work from the bound
Path(and updates related constraint-satisfaction plumbing accordingly). - Updates type-inference and dataflow library-test sources/expected outputs for the new behavior.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll | Introduces ranked-recursion based “no compatible target” logic and refactors borrow-candidate selection. |
| rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll | Adjusts blanket-constraint selection to use bound paths and updates constraint satisfaction interface usage. |
| rust/ql/lib/codeql/rust/internal/PathResolution.qll | Adds getBoundPath(int) and refactors bound resolution to use it. |
| rust/ql/test/library-tests/type-inference/closure.rs | Updates/extends a closure test case to capture the new/known-missing resolution behavior. |
| rust/ql/test/library-tests/type-inference/type-inference.expected | Updates expected type-inference results for the modified call/borrow resolution behavior. |
| rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected | Updates expected local dataflow steps reflecting changed implicit borrow/deref modeling. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 1
rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A recent QA run showed a timeout on
mimuw-distributed-systems-group/cmemu. The problematic predicate washasNoCompatibleTargetNoBorrowToIndex, where we do recursion throughforallvia the inlined predicatehasNoCompatibleNonBlanketTargetCheck. This PR applies the standard trick of replacing such recursion with ranked recursion, and since the original check already happened inside such (another) ranked recursion, it means we are now doing two levels of ranked recursion (see QL doc on the newly introducedNoCompatibleTargetmodule).I also noted that in the original
hasNoCompatibleTargetSharedBorrowcheck we were callinghasNoCompatibleNonBlanketLikeTargetCheck, which should have beenhasNoCompatibleTargetCheck(just like inhasNoCompatibleTargetNoBorrow), so this has been fixed as well.The second commit is an unrelated improvement to how we check blanket constraints.
DCA shows improved performance as well as reduction in inconsistencies (because of the
hasNoCompatibleTargetCheckchange), except forrust-lang/rust: while type inference is in fact faster, the queryrust/access-after-lifetime-endedis much slower, as a side-effect of improved call resolution.