Skip to content

Commit d06ac43

Browse files
committed
Fixed path optimization + make '-B' flag optional
1 parent e0fc29a commit d06ac43

File tree

4 files changed

+51
-31
lines changed

4 files changed

+51
-31
lines changed

code/prog4enter.hny

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
shared = 0
1+
x = 0
22
entered = [ False, False ]
33

44
def f(self):
55
entered[self] = True
66
await not entered[1 - self]
7-
shared += 1
7+
x += 1
88
entered[self] = False
99

1010
spawn f(0)
1111
spawn f(1)
1212

13-
finally shared == 2
13+
finally x == 2

harmony_model_checker/charm/charm.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,7 @@ static inline void process_step(
835835
f->edge = edge;
836836
add_failure(&w->failures, f);
837837
}
838-
839-
if (w->dfa != NULL) {
838+
else if (w->dfa != NULL) {
840839
assert(so->nlog == 0 || so->nlog == 1);
841840
for (unsigned int i = 0; i < so->nlog; i++) {
842841
int t = dfa_step(w->dfa, sc->dfa_state, step_log(so)[i]);
@@ -1845,7 +1844,7 @@ static void path_recompute(){
18451844
hvalue_t ctx = edge_input(e)->ctx;
18461845

18471846
// printf("MACRO tid=%u ctx=%p choice=%p\n", macro->tid, (void *) ctx,
1848-
// (void *) edge_input(e)->choice);
1847+
// (void *) edge_input(e)->choice);
18491848

18501849
if (e->invariant_chk) {
18511850
global.processes = realloc(global.processes, (global.nprocesses + 1) * sizeof(hvalue_t));
@@ -1879,9 +1878,9 @@ static void path_recompute(){
18791878
}
18801879
global.oldpid = pid;
18811880
}
1882-
// printf("Macrostep %u: T%u -> %p\n", i, pid, (void *) ctx);
1881+
// printf("Macrostep %u: T%u/%u -> %p\n", i, pid, global.nprocesses, (void *) ctx);
18831882
if (pid >= global.nprocesses) {
1884-
printf("PID %p %u %u\n", HV_TO_P(ctx), pid, global.nprocesses);
1883+
// printf("PID %p %u %u\n", HV_TO_P(ctx), pid, global.nprocesses);
18851884
// panic("bad pid");
18861885
global.nmacrosteps = i;
18871886
break;
@@ -2185,6 +2184,11 @@ static bool path_edge_conflict(
21852184
struct edge *edge,
21862185
struct edge *edge2
21872186
) {
2187+
// Consider it a conflict if either edge spawns new threads
2188+
if (edge_output(edge)->nspawned > 0 || edge_output(edge2)->nspawned > 0) {
2189+
return true;
2190+
}
2191+
21882192
for (struct access_info *ai = edge_output(edge)->ai; ai != NULL; ai = ai->next) {
21892193
if (ai->indices != NULL) {
21902194
for (struct access_info *ai2 = edge_output(edge2)->ai; ai2 != NULL; ai2 = ai2->next) {

harmony_model_checker/charm/ops.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,14 @@ void op_Print(const void *env, struct state *state, struct step *step){
674674
if (global.dfa != NULL) {
675675
int t = dfa_step(global.dfa, state->dfa_state, combo);
676676
if (t < 0) {
677-
char *p = value_string(combo);
678-
value_ctx_failure(step->ctx, step->allocator, "Behavior failure on %s", p);
677+
char *p;
678+
if (attrs == VALUE_DICT) {
679+
p = value_string(symbol);
680+
}
681+
else {
682+
p = value_string(combo);
683+
}
684+
value_ctx_failure(step->ctx, step->allocator, "Behavior failure on printing %s", p);
679685
free(p);
680686
return;
681687
}

harmony_model_checker/main.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def handle_hny(ns, output_files, parse_code_only, filenames):
119119

120120
return code, scope
121121

122-
def handle_hvm(ns, output_files, parse_code_only, code, scope):
122+
def handle_hvm(ns, output_files, parse_code_only, code, scope, behavior):
123123
charm_options = ns.cf or []
124-
if ns.B:
125-
charm_options.append("-B" + ns.B)
124+
if behavior != None:
125+
charm_options.append("-B" + behavior)
126126
if ns.b:
127127
charm_options.append("-b")
128128
if ns.T:
@@ -175,16 +175,11 @@ def handle_hvm(ns, output_files, parse_code_only, code, scope):
175175
print("charm model checker failed")
176176
exit(r)
177177

178-
def handle_hco(ns, output_files):
178+
def handle_hco(ns, output_files, behavior):
179179
if ns.quick:
180180
return
181181

182182
suppress_output = ns.suppress
183-
184-
behavior = None
185-
if ns.B:
186-
behavior = ns.B
187-
188183
disable_browser = settings.values.disable_web or ns.noweb
189184

190185
b = Brief()
@@ -270,14 +265,29 @@ def main():
270265
return 1
271266
output_files[suffix] = str(p)
272267

273-
if len(ns.args) != 1:
274-
print(f"harmony: error: invalid number of arguments ({len(ns.args)}). Provide 1 argument.")
275-
args.print_help()
276-
return 1
268+
filename = None
269+
behavior_file = ns.B if ns.B else None
270+
for f in ns.args:
271+
name = pathlib.Path(f)
272+
if not name.exists():
273+
print(f"harmony: error: file named '{name}' does not exist.")
274+
return 1
275+
file_type = name.suffix
276+
if file_type == '.hfa':
277+
if behavior_file != None:
278+
print(f"harmony: error: duplicate behavior file.")
279+
return 1
280+
behavior_file = f
281+
elif filename == None:
282+
filename = name
283+
else:
284+
print(f"harmony: error: multiple input files.")
285+
args.print_help()
286+
return 1
277287

278-
filename = pathlib.Path(ns.args[0])
279-
if not filename.exists():
280-
print(f"harmony: error: file named '{filename}' does not exist.")
288+
if filename == None:
289+
print(f"harmony: no input file")
290+
args.print_help()
281291
return 1
282292

283293
stem = str(filename.parent / filename.stem)
@@ -314,17 +324,17 @@ def main():
314324
if input_file_type == ".hny":
315325
code, scope = handle_hny(ns, output_files, parse_code_only, str(filename))
316326
if charm_flag:
317-
handle_hvm(ns, output_files, parse_code_only, code, scope)
318-
handle_hco(ns, output_files)
327+
handle_hvm(ns, output_files, parse_code_only, code, scope, behavior_file)
328+
handle_hco(ns, output_files, behavior_file)
319329
else:
320330
print("Skipping Phases 2-5...", flush=True)
321331
legacy_harmony.dumpCode(print_code, code, scope)
322332

323333
if input_file_type == ".hvm":
324334
print("Skipping Phase 1...", flush=True)
325-
handle_hvm(ns, output_files, parse_code_only, None, None)
326-
handle_hco(ns, output_files)
335+
handle_hvm(ns, output_files, parse_code_only, None, None, behavior_file)
336+
handle_hco(ns, output_files, behavior_file)
327337

328338
if input_file_type == ".hco":
329339
print("Skipping Phases 1-4...", flush=True)
330-
handle_hco(ns, output_files)
340+
handle_hco(ns, output_files, behavior_file)

0 commit comments

Comments
 (0)