Skip to content

Commit 4afd1b9

Browse files
committed
Refactor argument formatting and add quote removal to enable quoted
commands to be parallelizable Signed-off-by: kwakubiney <[email protected]>
1 parent f7b5293 commit 4afd1b9

File tree

6 files changed

+37
-34
lines changed

6 files changed

+37
-34
lines changed

compiler/annotations_utils/util_parsing.py

-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def parse_arg_list_to_command_invocation(
6666
command, flags_options_operands
6767
) -> CommandInvocationInitial:
6868
cmd_name = format_arg_chars(command)
69-
#strip quotes from command where necessary
70-
#quoted commands are interpreted as non-parallelizable
71-
cmd_name = cmd_name.strip().strip('"').strip("'")
7269
json_data = get_json_data(cmd_name)
7370
set_of_all_flags: Set[str] = get_set_of_all_flags(json_data)
7471
dict_flag_to_primary_repr: dict[str, str] = get_dict_flag_to_primary_repr(json_data)

compiler/ast_to_ir.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ def compile_asts(ast_objects: "list[AstNode]", fileIdGen, config):
100100
if isinstance(compiled_ast, IR):
101101
acc_ir.background_union(compiled_ast)
102102
else:
103-
## shouldn't happen since compile_node should have already
104-
## raised this error
105-
raise UnparallelizableError(f"Node: {compiled_ast} is not pure")
103+
## TODO: Make this union the compiled_ast with the
104+
## accumulated IR, since the user wanted to run these
105+
## commands in parallel (Is that correct?)
106+
# acc_ir.background_union(IR([compiled_ast]))
107+
compiled_asts.append(acc_ir)
108+
acc_it = None
109+
compiled_asts.append(compiled_ast)
106110

107111
## If the current compiled ast not in background (and so
108112
## the union isn't in background too), stop accumulating
109-
if not acc_ir.is_in_background():
113+
if not acc_ir is None and not acc_ir.is_in_background():
110114
compiled_asts.append(acc_ir)
111115
acc_ir = None
112116
else:
113117
## If the compiled ast is in background, start
114118
## accumulating it
115-
if compiled_ast.is_in_background():
119+
if isinstance(compiled_ast, IR) and compiled_ast.is_in_background():
116120
acc_ir = compiled_ast
117121
else:
118122
compiled_asts.append(compiled_ast)
@@ -124,7 +128,7 @@ def compile_asts(ast_objects: "list[AstNode]", fileIdGen, config):
124128
return compiled_asts
125129

126130

127-
def compile_node(ast_object, fileIdGen, config) -> IR:
131+
def compile_node(ast_object, fileIdGen, config):
128132
global compile_cases
129133
return ast_match(ast_object, compile_cases, fileIdGen, config)
130134

compiler/orchestrator_runtime/pash_prepare_call_compiler.sh

+10-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
## OUTPUT: When it completes it sets "$pash_script_to_execute"
44

5-
## Let daemon know that this region is done
6-
function inform_daemon_exit () {
7-
## Send to daemon
8-
msg="Exit:${process_id}"
9-
daemon_response=$(pash_communicate_daemon_just_send "$msg")
10-
}
11-
125
## Only needed for expansion
136
export pash_input_args=( "$@" )
147

@@ -40,8 +33,7 @@ pash_redir_output echo "$$: (2) Before asking the daemon for compilation..."
4033
msg="Compile:${pash_compiled_script_file}| Variable File:${pash_runtime_shell_variables_file}| Input IR File:${pash_input_ir_file}"
4134
daemon_response=$(pash_communicate_daemon "$msg") # Blocking step, daemon will not send response until it's safe to continue
4235

43-
# WARNING: finicky!
44-
if [[ "$daemon_response" == *"not"*"parallelizable"* ]]; then
36+
if [[ "$daemon_response" == *"not all regions are parallelizable"* ]]; then
4537
pash_all_region_parallelizable=1
4638
else
4739
pash_all_region_parallelizable=0
@@ -74,20 +66,17 @@ pash_redir_output echo "$$: (2) Compiler exited with code: $pash_runtime_return_
7466
## only when --assert_all_regions_parallellizable is used do we care about all regions being parallelizable
7567
if [ "$pash_all_region_parallelizable" -ne 0 ] && [ "$pash_assert_all_regions_parallelizable_flag" -eq 1 ]; then
7668
pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code because some regions were not parallelizable: $pash_all_region_parallelizable while assert_all_regions_parallelizable_flag was enabled! Exiting PaSh..."
77-
inform_daemon_exit
7869
exit 1
7970
fi
8071

8172
if [ "$pash_runtime_return_code" -ne 0 ] && [ "$pash_assert_all_regions_parallelizable_flag" -eq 1 ]; then
8273
pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code: $pash_runtime_return_code while assert_all_regions_parallelizable_flag was enabled! Exiting PaSh..."
83-
inform_daemon_exit
8474
exit 1
8575
fi
8676

87-
## for pash_assert_compiler_success_flag, exit when return code is not 0 (general exception caught) and when all regions are parallelizable
77+
## for pash_assert_compiler_success_flag, exit when return code is 0 (general exception caught) and not when all regions are parallelizable
8878
if [ "$pash_runtime_return_code" -ne 0 ] && [ "$pash_all_region_parallelizable" -eq 0 ] && [ "$pash_assert_compiler_success_flag" -eq 1 ]; then
8979
pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code: $pash_runtime_return_code while assert_compiler_success was enabled! Exiting PaSh..."
90-
inform_daemon_exit
9180
exit 1
9281
fi
9382

@@ -104,3 +93,11 @@ if [ "$pash_runtime_return_code" -ne 0 ] || [ "$pash_dry_run_compiler_flag" -eq
10493
else
10594
export pash_script_to_execute="${pash_compiled_script_file}"
10695
fi
96+
97+
## Let daemon know that this region is done
98+
function inform_daemon_exit () {
99+
## Send to daemon
100+
msg="Exit:${process_id}"
101+
daemon_response=$(pash_communicate_daemon_just_send "$msg")
102+
}
103+

compiler/pash_compilation_server.py

-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ def remove_process(self, process_id):
379379
]
380380
)
381381

382-
assert self.running_procs > 0
383382
self.running_procs -= 1
384383
if self.running_procs == 0:
385384
self.unsafe_running = False

compiler/pash_runtime.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ else
141141
pash_redir_output echo "$$: (5) BaSh script exited with ec: $pash_runtime_final_status"
142142
else
143143
function run_parallel() {
144-
# ideally we'd call inform_daemon_exit with the EXIT handler,
145-
# but it isn't called on Ubuntu 20.04 (for no clear reason)
146-
trap inform_daemon_exit SIGTERM SIGINT
144+
trap inform_daemon_exit SIGTERM SIGINT EXIT
147145
export SCRIPT_TO_EXECUTE="$pash_script_to_execute"
148146
source "$RUNTIME_DIR/pash_restore_state_and_execute.sh"
149147
inform_daemon_exit

compiler/shell_ast/ast_util.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@ def __init__(self, text):
4444
def check_if_ast_is_supported(construct, arguments, **kwargs):
4545
return
4646

47-
48-
def format_args(args):
49-
formatted_args = [format_arg_chars(arg_chars) for arg_chars in args]
50-
return formatted_args
51-
52-
5347
def format_arg_chars(arg_chars):
54-
chars = [format_arg_char(arg_char) for arg_char in arg_chars]
55-
return "".join(chars)
48+
return traverse_and_format(arg_chars)
49+
50+
def traverse_and_format(arg_char):
51+
if isinstance(arg_char, list):
52+
return "".join(traverse_and_format(c) for c in arg_char)
53+
elif isinstance(arg_char, QArgChar):
54+
return remove_quotes_from_quoted_content(arg_char.format())
55+
elif isinstance(arg_char, (CArgChar, EArgChar)):
56+
return format_arg_char(arg_char)
57+
else:
58+
# Fallback: not sure what the fallback for non recognized characters should be?
59+
return format_arg_char(arg_char)
60+
61+
def remove_quotes_from_quoted_content(arg_char):
62+
formatted_content = traverse_and_format(arg_char)
63+
return formatted_content.strip('"').strip("'")
5664

5765

5866
def format_arg_char(arg_char: ArgChar) -> str:

0 commit comments

Comments
 (0)