Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate the environment in project when the compiler crashes #36492

Merged

Conversation

azinneera
Copy link
Contributor

@azinneera azinneera commented Jun 9, 2022

Purpose

Invalidate the environment in project when the compiler crashes
Fixes #36231

Approach

The project environment will be reloaded when there is a compiler crash.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #36492 (9217211) into 2201.1.x (7d57315) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@              Coverage Diff               @@
##             2201.1.x   #36492      +/-   ##
==============================================
+ Coverage       73.96%   74.00%   +0.03%     
- Complexity      48085    48236     +151     
==============================================
  Files            3215     3224       +9     
  Lines          187161   187678     +517     
  Branches        24459    24524      +65     
==============================================
+ Hits           138442   138890     +448     
- Misses          40686    40731      +45     
- Partials         8033     8057      +24     
Impacted Files Coverage Δ
...g/src/main/java/io/ballerina/projects/Project.java 100.00% <ø> (ø)
...n/java/io/ballerina/projects/bala/BalaProject.java 91.66% <100.00%> (+0.96%) ⬆️
.../io/ballerina/projects/directory/BuildProject.java 89.90% <100.00%> (+0.14%) ⬆️
...allerina/projects/directory/SingleFileProject.java 77.77% <100.00%> (+3.58%) ⬆️
.../org/wso2/ballerinalang/compiler/PackageCache.java 70.58% <0.00%> (-15.69%) ⬇️
...ballerina/compiler/api/impl/BallerinaModuleID.java 88.88% <0.00%> (-7.41%) ⬇️
...oviders/context/util/ServiceTemplateGenerator.java 80.34% <0.00%> (-7.26%) ⬇️
...erinalang/debugadapter/variable/types/BRecord.java 60.78% <0.00%> (-2.55%) ⬇️
...llerina/runtime/internal/scheduling/Scheduler.java 71.22% <0.00%> (-1.44%) ⬇️
...n/providers/AbstractImplementMethodCodeAction.java 80.00% <0.00%> (-1.06%) ⬇️
... and 43 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d57315...9217211. Read the comment docs.


// Check if the compiler crashed
Collection<Diagnostic> errors = packageCompilation.diagnosticResult().errors();
if (errors != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this null check required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove it.

@@ -87,6 +92,11 @@ protected void setCurrentPackage(Package currentPackage) {
}

public ProjectEnvironment projectEnvironmentContext() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we ensure that this method is invoked right after a compiler crash?

There can be places where we have cached compilerContext instances. If that's the case, then we will end up having multiple stale instances of compilerContext objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored the implementation as follows:

  • Removed the crash recovery part from the Project API (which was added in the initial commit)
  • Improved Project.clearCaches to reset the entire environment

The API user can call the Project.clearCaches method when there is a crash.

@azinneera azinneera force-pushed the prj_api_compilerCrash2 branch 4 times, most recently from 5824835 to 6dd999f Compare June 17, 2022 04:51
@azinneera azinneera force-pushed the prj_api_compilerCrash2 branch from 6dd999f to 9217211 Compare June 17, 2022 05:53
@azinneera azinneera merged commit 616b168 into ballerina-platform:2201.1.x Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants