Skip to content
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

Redundant WAM instructions for inlined goals of meta-predicates #2816

Open
triska opened this issue Feb 5, 2025 · 0 comments
Open

Redundant WAM instructions for inlined goals of meta-predicates #2816

triska opened this issue Feb 5, 2025 · 0 comments

Comments

@triska
Copy link
Contributor

triska commented Feb 5, 2025

Given the following source code:

:- use_module(library(format)).
:- use_module(library(lists)).
:- use_module(library(diag)).

f(a).

fs(Ls) :-
        maplist(f, Ls).

I get:

?- wam_instructions(fs/1, Is), maplist(portray_clause, Is).
put_structure(f,0,x(3)).
set_constant('$index_ptr'(28915)).
get_variable(x(2),1).
put_structure(:,2,x(1)).
set_constant(user).
set_value(x(3)).
execute(maplist,2).

With '$index_ptr'(28915) pointing to the following inlined instructions:

?- inlined_instructions(28915, Is), maplist(portray_clause, Is).
get_constant(level(shallow),a,x(1)).
proceed.

My question: Scryer goes through the extra effort to generate these inlined instructions, and in a sense knows that these instructions are meant when we say maplist(f, ...). At the same time, it also allocates the term user:f on the heap, even though that seems not needed, because we can instead use the inlined goal which is already correctly resolved and compiled.

It seems either one or the other is necessary (i.e., inlined goal or compound term), but not both.

For comparison, GNU Prolog:

predicate(f/1,1,static,private,monofile,global,[
    get_atom(a,0),
    proceed]).

predicate(fs/1,3,static,private,monofile,global,[
    put_value(x(0),1),
    put_atom(f,0),
    execute(maplist/2)]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant