forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module AST cache. (FuelLabs#4733)
## Description This adds a module AST cache which speeds up the parsing and type checking stages for modules that have not changed. To make this work, when first parsing, we save the tree of dependencies and hashes for each module. Then when compiling again, we check the cache and re-use if possible. To make this work for LSP, I've had to revert the change that was done earlier to re-create the engines for each compilation step. This may lead to memory bloating, which was the reason that change was done in the first place IIRC, so I'll be investigating a garbage collection step that LSP can run after each compilation. On the LSP `did_change` test, that compiles a single file, makes a change, and re-parses again, this drops the time from 6s (3s + 3s for the second parse) to 3s, as expected, since the core and standard library are re-used instead of being parsed and analyzed again. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
11 changed files
with
241 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
use sway_error::handler::ErrorEmitted; | ||
use sway_utils::PerformanceData; | ||
|
||
use super::{lexed::LexedProgram, parsed::ParseProgram, ty::TyProgram}; | ||
|
||
/// Contains the lexed, parsed, and typed compilation stages of a program. | ||
/// Contains the lexed, parsed, typed compilation stages of a program, as well | ||
/// as compilation metrics. | ||
#[derive(Clone, Debug)] | ||
pub struct Programs { | ||
pub lexed: LexedProgram, | ||
pub parsed: ParseProgram, | ||
pub typed: Result<TyProgram, ErrorEmitted>, | ||
pub metrics: PerformanceData, | ||
} | ||
|
||
impl Programs { | ||
pub fn new( | ||
lexed: LexedProgram, | ||
parsed: ParseProgram, | ||
typed: Result<TyProgram, ErrorEmitted>, | ||
metrics: PerformanceData, | ||
) -> Programs { | ||
Programs { | ||
lexed, | ||
parsed, | ||
typed, | ||
metrics, | ||
} | ||
} | ||
} |
Oops, something went wrong.