Better fix for dataflow analysis caching#1353
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1353 +/- ##
=========================================
Coverage 88.39% 88.39%
- Complexity 2592 2594 +2
=========================================
Files 97 98 +1
Lines 8702 8705 +3
Branches 1732 1732
=========================================
+ Hits 7692 7695 +3
Misses 505 505
Partials 505 505 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Main Branch: With This PR: |
WalkthroughThe PR changes DataFlow to store RunOnceForwardAnalysisImpl instances in the analysis cache instead of generic Analysis objects, removes the separate alreadyRunAnalyses cache and its associated invalidation/lookup logic, and updates cache loader and dataflow invocation sites to use RunOnceForwardAnalysisImpl. A new RunOnceForwardAnalysisImpl class wraps ForwardAnalysisImpl and overrides performAnalysis to execute and cache results only on the first call. Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (1)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java(2 hunks)nullaway/src/main/java/com/uber/nullaway/dataflow/RunOnceForwardAnalysisImpl.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: benchmarking
- GitHub Check: Build and test on windows-latest
- GitHub Check: Build and test on macos-latest
- GitHub Check: Build spring-framework with snapshot
- GitHub Check: Build and test on ubuntu-latest
- GitHub Check: Build caffeine with snapshot
🔇 Additional comments (3)
nullaway/src/main/java/com/uber/nullaway/dataflow/RunOnceForwardAnalysisImpl.java (1)
9-15: Run-once wrapper cleanly encapsulates the caching fixThe class-level design and Javadoc clearly move the “already run” state into the analysis instance itself, which should prevent the cache/set desynchronization that caused #1351. Generics and inheritance from
ForwardAnalysisImpllook correct and consistent with the existing dataflow APIs.nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java (2)
80-90: Good refactor: cache now stores run-once analyses keyed by (transfer, cfg)Switching
analysisCachetoLoadingCache<AnalysisParams, RunOnceForwardAnalysisImpl<?, ?, ?>>with the loader constructing a freshRunOnceForwardAnalysisImplfor each(transferFunction, cfg)key cleanly centralizes the “already run” state inside the analysis instance. This eliminates the possibility of the cache entry being evicted while a separatealreadyRunAnalysesstructure still claims the key is initialized, which is exactly the inconsistency that led to the NPE in issue #1351. The key still includescfg, so a single analysis instance is never shared across different CFGs.
159-163:performAnalysisIfNeeded(cfg)correctly replaces external bookkeepingUsing
RunOnceForwardAnalysisImpl<A, S, T>here and callinganalysis.performAnalysisIfNeeded(cfg)wheneverperformAnalysisistrueensures that:
- Analyses are initialized exactly once per cached instance, even if
dataflowis called multiple times.- After eviction, a newly created analysis will always run before
getResult()/getRegularExitStore()is used, socfg-dependent fields can’t remain null.This aligns with the PR’s goal of fixing the out-of-sync cache state and removes the need for a separate “already run” cache.
nullaway/src/main/java/com/uber/nullaway/dataflow/RunOnceForwardAnalysisImpl.java
Outdated
Show resolved
Hide resolved
nullaway/src/main/java/com/uber/nullaway/dataflow/RunOnceForwardAnalysisImpl.java
Show resolved
Hide resolved
|
Main Branch: With This PR: |
Fixes #1351
We get rid of having two related caches that can get out of sync. Instead, we create a new
RunOnceForwardAnalysisImplclass that allows for running a dataflow analysis at most once.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.