Skip to content

Commit

Permalink
feat: remove parsing check since javalang sometimes hangs forever
Browse files Browse the repository at this point in the history
  • Loading branch information
UniverseFly committed Aug 15, 2023
1 parent c5177ea commit 4220f4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
8 changes: 5 additions & 3 deletions src/realm/ploting.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def generation_datapoint_getter(datapoint: GenerationDatapoint) -> list[int]:
# Print averaged summary
# TODO: now the points' total and unique is the same. To change this, modify
# `map_validaton_datapoint`

print("Validation Summary")
for tag, runner, (_, raw_results) in zip(tags, runners, raw_validation_results):
if runner.report.validation_result is None:
Expand Down Expand Up @@ -161,12 +162,13 @@ def generation_datapoint_getter(datapoint: GenerationDatapoint) -> list[int]:
# for proj, bug_id_results in raw_results
# }
# n_plausible = {proj: v.n_test_success for proj, v in proj_summary.items()}
assert runner.report.repair_result is not None
print("N bugs: ", len(runner.report.repair_result.result_dict))
print(tag, "Metadata", summary)
print(
tag,
f"Compilation rate: {summary.unique_compilation_rate()}",
f"Plausible rate: {summary.unique_plausible_rate()}",
f"Compilation rate: {summary.unique_compilation_rate() * 100:.1f}%",
f"Plausible rate: {summary.unique_plausible_rate() * 100:.2f}%",
f"Plausible fixes: {sum(1 for fixes in plausible_fixes.values() for fix in fixes)}",
)
print()
Expand All @@ -176,7 +178,7 @@ def generation_datapoint_getter(datapoint: GenerationDatapoint) -> list[int]:
assert point.gen_datapoint.n_total == point.gen_datapoint.n_unique
print(
f"Top-{top_k}: ",
point.compilation_rate(),
f"{point.compilation_rate() * 100:.1f}",
point.n_comp_success,
point.gen_datapoint.n_total,
)
Expand Down
55 changes: 2 additions & 53 deletions src/realm/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import time
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, TypeVar, Any
import javalang
from typing import Any, Iterable, TypeVar

import regex as re
from joblib import Parallel, delayed

Expand Down Expand Up @@ -39,42 +39,6 @@
Datapoint = TypeVar("Datapoint")
EvaluationResult = TypeVar("EvaluationResult")

import multiprocessing

class TimeoutError(Exception):
pass

def worker(input_data: str, queue: multiprocessing.Queue) -> None:
try:
result = javalang.parse.parse(input_data)
queue.put(('success', result))
except Exception as e:
queue.put(('error', e))

def parse_with_timeout(input_data: str, timeout=10) -> None:
"""Parse the input with timeout since the javalang parser sometimes hangs"""
# Create a Queue to share results
queue = multiprocessing.Queue()

# Start the worker process
p = multiprocessing.Process(target=worker, args=(input_data, queue))
p.start()

# Wait for the process to complete or timeout
p.join(timeout)

# Check if the process is still alive (meaning it exceeded the timeout)
if p.is_alive():
queue.close()
p.terminate() # Terminate the process if it's still running
raise TimeoutError(f"The parse function exceeded the {timeout} second timeout")

# Check the result from the queue
status, result_or_exception = queue.get()
queue.close()

if status == 'error':
raise result_or_exception

@dataclass
class Runner:
Expand Down Expand Up @@ -599,24 +563,9 @@ def cost():
# Checkout the fixed version and then apply patches b/c we do not consider test file changes
d4j.checkout(bug_id, buggy=False, dirty=False)
for patch_text_file in patch_files:
try:
parse_with_timeout(patch_text_file.content)
except (
javalang.parser.JavaSyntaxError,
javalang.tokenizer.LexerError,
) as e:
return PatchValidationResult(Outcome.ParseError, cost(), "", str(e))
except Exception as e:
# TODO: add an InternalError record in `Report`
with open("unexpected_exception", "a") as f:
f.write(str(type(e)))
f.write("\n")
f.write(str(e))
patch_text_file.root = d4j.d4j_checkout_root
assert patch_text_file.path.exists()
patch_text_file.write()
print("Done parse", patch_text_file.path)
# patch_text_file.path.touch()
print("Compile...")
comp_success, comp_stdout, comp_stderr = d4j.compile(bug_id)
print("Done compile.")
Expand Down

0 comments on commit 4220f4e

Please sign in to comment.