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

Enhance match struct with the matched_string field #321

Merged
merged 1 commit into from
Jan 10, 2023

Conversation

ketkarameya
Copy link
Collaborator

@ketkarameya ketkarameya commented Jan 9, 2023

Add the field matched_string to Match struct. This field will store the code snippet matched by the rule.

@ketkarameya ketkarameya changed the base branch from master to cleanup-edit-usage January 9, 2023 17:51
Copy link
Contributor

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

That said, question: Are these substrings eager copies in memory or are they stored some other way? Any concern about memory usage ballooning due to multiple copies of substrings of the code under analysis? Specially under, say, a long chain of simplifications on the same huge boolean expression? (Seems unlikely, but still, one alternative is to keep just the start and end position and a pointer to the full source - or even the file, to be read on demand and cached - and then just constructing the substring when requested through a method of the match struct, no?)

@ketkarameya ketkarameya marked this pull request as draft January 9, 2023 18:27
@ketkarameya
Copy link
Collaborator Author

I totally agree to what u say. I think we should not do this.
I was leaning towards usability over performance. But i feel this will get really bad when we capture these large constructs like class or file.
With storing references comes lifetimes :|

@ketkarameya
Copy link
Collaborator Author

Another problem is that, we are using this Match struct for our python bindings too.
And pyo3 library doesnt support struct with lifetimes.

@ketkarameya
Copy link
Collaborator Author

ketkarameya commented Jan 9, 2023

We actually require this matched_string for debugging :|
But I guess, let's not do that!

@dvmarcilio
Copy link
Collaborator

In the case of edits/rewrites, I wonder what would happen if there is no matched string.
I may be misunderstanding, but we might not be able to get the original match content if rewrites (e.g., delete a function) happen.

@ketkarameya
Copy link
Collaborator Author

yes. And Diego makes a good point too. If we dont do this eagerly we will not be able to report it at all.

@ketkarameya ketkarameya marked this pull request as ready for review January 9, 2023 19:48
@ketkarameya
Copy link
Collaborator Author

I think I am gonna merge this. It might have performance implications (in memory) but I guess its alright. Neither do we have any benchmarks to empirically prove how bad it is. @lazaroclapp what do u think ? (I know u have already accepted the PR)

@lazaroclapp
Copy link
Contributor

I think I am gonna merge this. It might have performance implications (in memory) but I guess its alright. Neither do we have any benchmarks to empirically prove how bad it is. @lazaroclapp what do u think ? (I know u have already accepted the PR)

I think this makes sense to me, given the complications involved in designing something that would work well with deletions (I am sure there is some involved copy-on-write way to handle it, but it feels like premature optimization). Separate from this PR, a good question is whether we have any way to measure internally Piranha's memory usage. But, also, I wouldn't worry too much about it unless we start seeing issues, since it's not like Piranha is running during a standard build or anything like that. It is very much an "off main pipeline" tool 🙂

@ketkarameya
Copy link
Collaborator Author

Thanks a lot. I will merge this PR.
Filed the issue #322 to track this.

@ketkarameya ketkarameya merged commit 5314bff into cleanup-edit-usage Jan 10, 2023
ketkarameya added a commit that referenced this pull request Jan 10, 2023
@ketkarameya ketkarameya deleted the enhance-match-struct branch July 13, 2023 18:13
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.

3 participants