Skip to content

Commit

Permalink
More on TCO
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Oct 10, 2024
1 parent ccb1f55 commit 3d5d330
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions samples/tco.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
write(test1), write(': '), test1(1000000);
write(test2), write(': '), test2(1000000);
write(test3), write(': '), test3(1000000);
%write(test4), write(': '), test4(1000000);
%write(test5), write(': '), test5(1000000);
write(test4), write(': '), test4(1000000);
write(test5), write(': '), test5(1000000);
true.

1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ struct query_ {
bool portray_vars:1;
bool status:1;
bool no_tco:1;
bool no_fact:1;
bool has_vars:1;
bool error:1;
bool did_throw:1;
Expand Down
3 changes: 1 addition & 2 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,7 @@ static void commit_frame(query *q)
// Matching a ground fact (see disjunction in bif_control.c)...

if (q->pl->opt && last_match && !body
&& !cl->nbr_vars
&& !q->no_tco
&& !q->no_fact
) {
leave_predicate(q, q->st.pr);
drop_choice(q);
Expand Down
4 changes: 2 additions & 2 deletions src/unify.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ static void set_var(query *q, const cell *c, pl_idx c_ctx, cell *v, pl_idx v_ctx
q->run_hook = true;

if (is_compound(v) && (v_ctx == q->st.fp))
q->no_tco = true;
q->no_fact = true;

if (is_managed(v))
q->no_tco = true;
q->no_fact = true;

// If anything outside the current frame points inside the
// current frame then we can't TCO.
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/test101.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test1: [4,0,3,7]
test2: [4,0,3,7]
test3: [4,0,3,7]
test4: [4,0,3,7]
test5: [4,0,3,7]
4 changes: 2 additions & 2 deletions tests/tests/test101.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
write(test1), write(': '), test1(1000000);
write(test2), write(': '), test2(1000000);
write(test3), write(': '), test3(1000000);
%write(test4), write(': '), test4(1000000);
%write(test5), write(': '), test5(1000000);
write(test4), write(': '), test4(1000000);
write(test5), write(': '), test5(1000000);
true.

0 comments on commit 3d5d330

Please sign in to comment.