Skip to content

Commit

Permalink
Another TCO improvement - fact matching
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Sep 30, 2024
1 parent c3a51ab commit 4ff5b35
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
2 changes: 0 additions & 2 deletions samples/tco.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
test3(0) :- !, statistics, nl, fail.
test3(N) :- f(_), N1 is N-1, test3(N1).

% No local vars & no structures, yet not recovered...

f(_, _).

test4(0) :- !, statistics, fail.
Expand Down
2 changes: 1 addition & 1 deletion src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ struct query_ {
bool no_tco:1;
bool has_vars:1;
bool has_indirects:1;
bool has_compounds:1;
bool has_structs:1;
bool error:1;
bool did_throw:1;
bool trace:1;
Expand Down
3 changes: 1 addition & 2 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,8 @@ static void commit_frame(query *q)
// Matching a fact (see disjunction in bif_control.c)...

if (q->pl->opt && last_match && !body
&& !cl->nbr_vars // must be ground
&& !q->has_indirects
&& !q->has_compounds
&& !q->has_structs
) {
leave_predicate(q, q->st.pr);
drop_choice(q);
Expand Down
2 changes: 1 addition & 1 deletion src/unify.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ static bool unify_internal(query *q, cell *p1, pl_idx p1_ctx, cell *p2, pl_idx p

if (p1->arity || p2->arity) {
return unify_structs(q, p1, p1_ctx, p2, p2_ctx, depth+1);
if (depth) q->has_compounds = true;
if (depth) q->has_structs = true;
}

return g_disp[p1->tag].fn(q, p1, p2);
Expand Down

0 comments on commit 4ff5b35

Please sign in to comment.