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

JVM: Add static information of target method in prompts #416

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data_prep/introspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ def _get_exceptions(function: dict) -> List[str]:
return function.get('exceptions', [])


def _is_static(function: dict) -> bool:
"""Returns the static property of this function."""
return function.get('is_static', False)


def _get_arg_names(function: dict, project: str, language: str) -> list[str]:
"""Returns the function argument names."""
if language == 'jvm':
Expand Down Expand Up @@ -607,6 +612,7 @@ def populate_benchmarks_using_introspector(project: str, language: str,
_get_clean_arg_types(function, project),
_get_arg_names(function, project, language)),
_get_exceptions(function),
_is_static(function),
harness,
target_name,
function_dict=function))
Expand Down
4 changes: 4 additions & 0 deletions experiment/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def to_yaml(cls, benchmarks: list[Benchmark], outdir: str = './'):
'return_type': b.return_type,
'params': b.params,
'exceptions': b.exceptions,
'is_static': b.is_static,
} for b in benchmarks],
}
with open(os.path.join(outdir, f'{benchmarks[0].project}.yaml'),
Expand Down Expand Up @@ -100,6 +101,7 @@ def from_yaml(cls, benchmark_path: str) -> List:
function.get('return_type'),
function.get('params'),
function.get('exceptions', []),
function.get('is_static', False),
data['target_path'],
data.get('target_name'),
use_project_examples=use_project_examples,
Expand All @@ -119,6 +121,7 @@ def __init__(self,
return_type: str,
params: list[dict[str, str]],
exceptions: list[str],
is_static: bool,
target_path: str,
preferred_target_name: Optional[str] = None,
use_project_examples=True,
Expand All @@ -134,6 +137,7 @@ def __init__(self,
self.return_type = return_type
self.params = params
self.exceptions = exceptions
self.is_static = is_static
self.function_dict = function_dict
self.target_path = target_path
self._preferred_target_name = preferred_target_name
Expand Down
12 changes: 12 additions & 0 deletions llm_toolkit/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ def _format_requirement(self, signature: str) -> str:
else:
requirement = requirement.replace('{HARNESS_NAME}', 'Fuzz')

class_name = self.benchmark.function_name[1:].split(']')[0]
if '<init>' in self.benchmark.function_name:
creation = (f'The target method is a constructor of {class_name} '
'invoke it directly with new keyword.')
elif self.benchmark.is_static:
creation = ('The target method is a static method, invoke it directly '
'without creating an object.')
else:
creation = (f'You must create the {class_name} object before calling '
'the target method.')
requirement = requirement.replace('{STATIC_OR_INSTANCE}', creation)

return requirement

def _format_data_filler(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions prompts/template_xml/jvm_requirement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<item>Please add import statements for necessary classes, except for classes in the java.lang package.</item>
<item>You must create the object before calling the target method.</item>
<item>Please use {HARNESS_NAME} as the Java class name.</item>
<item>{STATIC_OR_INSTANCE}</item>
<item>Do not create new variables with the same names as existing variables.
WRONG:
<code>
Expand Down
Loading