Skip to content

Commit

Permalink
Move back to the old experiment setting, identify only those suppress…
Browse files Browse the repository at this point in the history
… more warnings.
  • Loading branch information
Hhyemin committed Sep 12, 2024
1 parent 893e77e commit 2b47e7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
33 changes: 4 additions & 29 deletions src/suppression_study/evolution/AccidentalSuppressionFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import ast
import os
from os.path import join, exists
import subprocess
from typing import List
from suppression_study.evolution.ExtractHistory import read_histories_from_json
from suppression_study.evolution.MapWarningLines import MapWarningLines
from suppression_study.utils.FunctionsCommon import get_commit_list
from suppression_study.warnings.WarningSuppressionMapper import main as compute_warning_suppression_mapping
from suppression_study.warnings.WarningSuppressionUtil import read_mapping_from_csv
Expand Down Expand Up @@ -113,7 +111,6 @@ def get_suppression_warning_pairs(repo_dir, commit, relevant_files, results_dir,
def check_for_accidental_suppressions(repo_dir, history, relevant_commits, relevant_files, results_dir, is_file_specific):
accidentally_suppressed_warnings = []
previous_commit = None
previous_suppression = None
warnings_suppressed_at_previous_commit = None

add_event = history[0]
Expand Down Expand Up @@ -162,44 +159,22 @@ def check_for_accidental_suppressions(repo_dir, history, relevant_commits, relev
# at the previous commit, create an AccidentallySuppressedWarning
if warnings_suppressed_at_previous_commit is not None:
if suppression is not None:
new_warning_hinder = None
num_new_warning = 0
current_len = len(warnings_suppressed_at_commit)
previous_len = len(warnings_suppressed_at_previous_commit)
if previous_len > current_len:
pass
elif previous_len == current_len and warnings_suppressed_at_previous_commit != warnings_suppressed_at_commit: #
backup_warnings_suppressed_at_previous_commit = [w for w in warnings_suppressed_at_previous_commit]
backup_warnings_suppressed_at_commit = [w for w in warnings_suppressed_at_commit]
# the warnings may different, run diff to check the line number maps
new_warning_hinder, num_new_warning = MapWarningLines(repo_dir, previous_commit, commit, \
backup_warnings_suppressed_at_previous_commit, backup_warnings_suppressed_at_commit ).check_warning_mapping()
elif previous_len < current_len:
num_new_warning = current_len - previous_len

if num_new_warning > 0:
if len(warnings_suppressed_at_commit) > len(warnings_suppressed_at_previous_commit):
# there's a new warning suppressed by this suppression
summary = f"from {previous_len} to {current_len}, new warnings: {num_new_warning}"
accidentally_suppressed_warnings.append(
AccidentallySuppressedWarning(summary,
previous_commit,
AccidentallySuppressedWarning(previous_commit,
commit,
previous_suppression,
suppression,
warnings_suppressed_at_previous_commit,
warnings_suppressed_at_commit,
new_warning_hinder))
warnings_suppressed_at_commit))
previous_commit = commit
previous_suppression = suppression
warnings_suppressed_at_previous_commit = warnings_suppressed_at_commit
else:
warnings_suppressed_at_previous_commit = None
previous_commit = None
previous_suppression = None
else:
warnings_suppressed_at_previous_commit = None
previous_commit = None
previous_suppression = None

return accidentally_suppressed_warnings

Expand Down Expand Up @@ -234,4 +209,4 @@ def main(repo_dir, commits_file, history_file, results_dir, is_file_specific):

if __name__ == "__main__":
args = parser.parse_args()
main(args.repo_dir, args.commits_file, args.history_file, args.results_dir, args.file_name_specific)
main(args.repo_dir, args.commits_file, args.history_file, args.results_dir, args.file_name_specific)
19 changes: 3 additions & 16 deletions src/suppression_study/evolution/AccidentallySuppressedWarning.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@


class AccidentallySuppressedWarning:
def __init__(self, summary, previous_commit, commit, previous_suppression, suppression, \
previous_warnings, warnings, new_warning_hinder):
self.summary = summary
def __init__(self, previous_commit, commit, suppression, previous_warnings, warnings):
self.previous_commit = previous_commit
self.commit = commit
self.previous_suppression = previous_suppression
self.suppression = suppression
self.previous_warnings = previous_warnings
self.warnings = warnings
self.new_warning_hinder = new_warning_hinder

def __lt__(self, other):
"""Sort based on attributes. Useful for getting a deterministic order when writing to a file."""
if self.previous_commit != other.previous_commit:
return self.previous_commit < other.previous_commit
elif self.commit != other.commit:
return self.commit < other.commit
elif self.previous_suppression != other.previous_suppression:
return self.previous_suppression < other.previous_suppression
elif self.suppression != other.suppression:
return self.suppression < other.suppression
elif self.previous_warnings != other.previous_warnings:
Expand All @@ -30,27 +24,20 @@ def __lt__(self, other):

def to_dict(self):
d = {
"summary": self.summary,
"previous_commit": self.previous_commit,
"commit": self.commit,
"previous_suppression": {
"path": self.previous_suppression.path,
"text": self.previous_suppression.text,
"line": self.previous_suppression.line
},
"suppression": {
"path": self.suppression.path,
"text": self.suppression.text,
"line": self.suppression.line
},
"previous_warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.previous_warnings)],
"warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.warnings)],
"new_warning_hinder": self.new_warning_hinder
"warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.warnings)]
}
return d


def write_accidentally_suppressed_warnings(accidentally_suppressed_warnings, output_file):
with open(output_file, "w") as f:
list_of_dicts = [w.to_dict() for w in accidentally_suppressed_warnings]
json.dump(list_of_dicts, f, indent=4)
json.dump(list_of_dicts, f, indent=4)
3 changes: 1 addition & 2 deletions src/suppression_study/evolution/MapWarningLines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import subprocess
from suppression_study.warnings.Warning import Warning

# Sept. 12, just keep the file here, but this is not necessary for old experiment setting.

class MapWarningLines():
def __init__(self, repo_dir, pre_c, c, pre_warnings, warnings):
Expand Down

0 comments on commit 2b47e7a

Please sign in to comment.