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

Fix string view index in UpdateFileContents() #2079

Merged
merged 3 commits into from
Jan 28, 2024
Merged

Fix string view index in UpdateFileContents() #2079

merged 3 commits into from
Jan 28, 2024

Conversation

hzeller
Copy link
Collaborator

@hzeller hzeller commented Jan 28, 2024

This fixes #2078.
Since some changes are somewhat independent, they are in three different commits.

This also fixes the misfeature that the string view index had to be disabled in cases the VerilogProject is used where it needs to remove files. So instead of a fractured class use, this is now merely a feature that can be enabled.

When updating the parse buffers, make sure the old ones don't disappear
while we still call the callbacks for everyone interested in the changes.

They might've hold on to some data and expect the old one to be still
viable when they get the update call.

Add a unit test.

Issues: #2078
While at it: update and refine documentation.
... needed later in verilog_project to unregeister string-view
ranges.

Issues: #2078
@hzeller hzeller changed the title Fix string view index in UpdateFileConetnts() Fix string view index in UpdateFileContents() Jan 28, 2024
@hzeller hzeller requested a review from ivan444 January 28, 2024 03:07
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (a4d61b1) 92.95% compared to head (3afdb92) 92.99%.

Files Patch % Lines
verilog/analysis/verilog_project.cc 96.77% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2079      +/-   ##
==========================================
+ Coverage   92.95%   92.99%   +0.03%     
==========================================
  Files         358      358              
  Lines       26446    26465      +19     
==========================================
+ Hits        24583    24611      +28     
+ Misses       1863     1854       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -289,7 +291,7 @@ class VerilogProject {
absl::string_view referenced_filename);

// Adds an already opened file by directly passing its content.
// TODO(refactor): is this needed ?
// TODO(refactor): is this needed ? (probaly yes in external kythe backends)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can drop TODO & "probably". This is indeed needed for the external Kythe backends

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// This can come from the .begin() of any entry in string_view_map_.
std::map<absl::string_view::const_iterator, file_set_type::const_iterator>
buffer_to_analyzer_map_;
std::unique_ptr<ContentToFileIndex> content_index_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::optional might be a better fit here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, done.

When files are updated and old ones removed, make sure that the
corresponding index for the substring ranges is also updated.

Move the data and logic needed for the substring index into its
own class ContentToFileIndex. Since we _can_ removed string ranges
now, we don't really have to choose anymore if we want to populate
string view maps; still providing this feature for now, but calling
it provide_lookup_file_origin, as this is what it provides.

Make ParsedVerilogSourceFile take an Analyzer instead of a
TextStructureView to better emphasize that this is essentially the same
as the other VerilogSourceFiles, just with a non-owned Analyzer.
This also allows to return the parse absl::Status instead of a
potentially non-truthful ok().

Updating plumbing needed for the passing-an-analyzer.

Add test for updating the project and verify that no stale
string view index is kept (the original issue in #2078).

Fixes: #2078
@hzeller hzeller merged commit d3e3ea6 into chipsalliance:master Jan 28, 2024
30 of 31 checks passed
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.

Potential crash when local file is replaced with verilog::VerilogProject::UpdateFileContents()
3 participants