-
Notifications
You must be signed in to change notification settings - Fork 143
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
Adding --proof-hint
flag to PyK KRun
#4532
base: develop
Are you sure you want to change the base?
Changes from 2 commits
55ee1b3
efcc3ed
93ca0c0
ffb2d54
86c8214
977bcb6
b5a445e
832c329
43d618d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import logging | ||
from enum import Enum | ||
from os import write | ||
from pathlib import Path | ||
from subprocess import CalledProcessError | ||
from typing import TYPE_CHECKING | ||
|
@@ -74,6 +75,7 @@ def run_process( | |
pipe_stderr: bool = True, | ||
bug_report: BugReport | None = None, | ||
debugger: bool = False, | ||
proof_hint: bool = False, | ||
) -> CompletedProcess: | ||
with self._temp_file() as ntf: | ||
pgm.write(ntf) | ||
|
@@ -97,6 +99,7 @@ def run_process( | |
check=False, | ||
pipe_stderr=pipe_stderr, | ||
debugger=debugger, | ||
proof_hint=proof_hint, | ||
) | ||
|
||
def run( | ||
|
@@ -115,6 +118,7 @@ def run( | |
pipe_stderr: bool = True, | ||
bug_report: BugReport | None = None, | ||
debugger: bool = False, | ||
proof_hint: bool = False, | ||
) -> None: | ||
result = self.run_process( | ||
pgm, | ||
|
@@ -129,8 +133,14 @@ def run( | |
pipe_stderr=pipe_stderr, | ||
bug_report=bug_report, | ||
debugger=debugger, | ||
proof_hint=proof_hint, | ||
) | ||
|
||
if proof_hint: | ||
# Print the binary proof hint to stdout regardless of the output option | ||
write(1, result.stdout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the intent of the code here is; it seems confusing that the proof hint mode will unconditionally escape the Python framework and dump directly to stdout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it would be better to expose this operation mode as a separate function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual behavior of the flag in the krun. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For instance, krun only So I believe this mimics the same behavior we already have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The point is that we manage |
||
return | ||
|
||
if output != KRunOutput.NONE: | ||
output_kore = KoreParser(result.stdout).pattern() | ||
match output: | ||
|
@@ -208,6 +218,7 @@ def _krun( | |
logger: Logger | None = None, | ||
bug_report: BugReport | None = None, | ||
debugger: bool = False, | ||
proof_hint: bool = False, | ||
) -> CompletedProcess: | ||
if input_file: | ||
check_file_path(input_file) | ||
|
@@ -236,6 +247,7 @@ def _krun( | |
search_final=search_final, | ||
no_pattern=no_pattern, | ||
debugger=debugger, | ||
proof_hint=proof_hint, | ||
) | ||
|
||
if bug_report is not None: | ||
|
@@ -265,6 +277,7 @@ def _build_arg_list( | |
search_final: bool, | ||
no_pattern: bool, | ||
debugger: bool, | ||
proof_hint: bool = False, | ||
Robertorosmaninho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> list[str]: | ||
args = [command] | ||
if input_file: | ||
|
@@ -293,6 +306,8 @@ def _build_arg_list( | |
args += ['--no-pattern'] | ||
if debugger: | ||
args += ['--debugger'] | ||
if proof_hint: | ||
args += ['--proof-hint'] | ||
return args | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this approach won't work: under the hood it leads to a call like
which will raise an exception:
This is because
stdout=subprocess.PIPE
, soCompletedProcess.stdout
will be populated.text=True
, so the function will try to decode the bytes output to produceCompletedProcess.stdout
.You drop any of these arguments and it'll work.
Please add a test to reproduce this issue.
Workarounds:
_build_arg_list
and callsubprocess.run
directly.encoding
through tosubprocess.run
(standard encodings).pipe_stdout=False
torun_process
, so that you havestdout=None
insubprocess.run
.run_process
(and it's newer version,run_process_2
) to accepttext=False
, but that's not straightforward.I'd prefer a solution that won't prevent us from dropping
run_process
in favor ofrun_process_2
in the future, i.e. (1) or (2).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! I dropped
text=True
locally and forgot to commit this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About your workarounds:
run_process
?pipe_stdout = not prof_hint
.If you don't mind, I would prefer to stick to option 3 to unblock Pi2 folks, and when we need to drop
run_process
in favor ofrun_process_2
, we can sit together again to brainstorm a way to make it compatible with proof hints.