feat: introduce forc-pkg level cache #7303
Draft
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.
Description
This pull request introduces a persistent
CompilationCache
to manage engines and compilation state across multiple sessions, enhancing the efficiency and modularity of theforc-pkg
package. The changes primarily focus on integrating this cache into thebuild
andcheck
functions, refactoring their logic to utilize the cache, and ensuring thread-safe operations usingMutex
. Below are the most important changes grouped by theme:Introduction of
CompilationCache
:CompilationCache
struct: A new struct was introduced to hold engines and compilation state usingArc<Mutex<Engines>>
. It includes methods for managing engines, clearing programs/modules, setting observers, and executing functions with locked engines. (forc-pkg/src/pkg.rs
)Refactoring
build
Function:build_with_cache
: A new function was added to perform package builds using theCompilationCache
, replacing direct usage ofEngines
with cache-based operations. (forc-pkg/src/pkg.rs
)Engines
withCompilationCache
: Updated the logic in thebuild
function to use the cache for operations like setting observers, accessing engines, and managing compilation state. (forc-pkg/src/pkg.rs
) [1] [2] [3]Refactoring
check
Function:check_with_cache
: Similar tobuild_with_cache
, this function uses theCompilationCache
for checking packages, enabling persistent state management during checks. (forc-pkg/src/pkg.rs
)check
logic: Updatedcheck
to use the cache for operations such as dependency namespace creation and AST compilation. (forc-pkg/src/pkg.rs
) [1] [2]Thread-Safety Enhancements:
Engines
usage withMutex
locks to ensure safe concurrent access to engines in bothbuild
andcheck
functions. (forc-pkg/src/pkg.rs
) [1] [2] [3]These changes improve the modularity, maintainability, and efficiency of the
forc-pkg
package by introducing a persistent cache and ensuring thread-safe operations.