[ Predicate Database and Compiler | Reference Manual | Alphabetic Index ]

inline(++Pred)

Declares Pred as a candidate for inlining (unfolding).
Pred
Expression of the form Atom/Integer.

Description

If a predicate is declared inline, the compiler will attempt to textually insert the predicate's definition everywhere the predicate is called. This is also known as unfolding. Inlining will usually improve efficiency, in particular when the inlined predicate is short or has many arguments.

If the inlined predicate has multiple clauses, they will be inlined in the form of a disjunction (note that indexing will be preserved).

If inlining is applied to an exported predicate, one must be aware that the definition will be textually substituted for the original goal in an unknown module context. Although the expansion mechanism will add module qualifications to the expanded source, it means that all predicates called by the expanded source must be exported from their definition module in order to be accessible from elsewhere.

The inline/1 directive must be issued from the definition module of Pred, and should occur before Pred's definition. Only calls that textually follow the definition will be inlined.

Note that inline/1 is a special system-defined case of inline/2, using a transformation predicate called unfold/6. Therefore get_flag(Pred, inline, unfold/6) can be used to test whether a predicate has been declared with inline/1.

Inlining can be disabled for debugging purposes by adding

    :- pragma(noexpand).
to the code containing calls, or by setting the global flag
    :- set_flag(goal_expansion, off).
The global flag also controls whether transformations are applied to goals entered at the interactive toplevel prompt.

Modes and Determinism

Exceptions

(4) instantiation fault
Pred is not fully instantiated.
(5) type error
Pred is not of the form Atom/Integer.
(100) accessing a procedure defined in another module
Pred is not defined is this module.

Examples

    :- inline(double/2).
    double(X, Y) :- Y is 2*X.

    % The predicate
    sample :- ..., double(A, B), ...
    % will be compiled as
    sample :- ..., B is 2*A, ...

    :- inline(yesno/1).
    yesno(yes).
    yesno(no).

    % The predicate
    sample :- ..., yesno(X), ...
    % will be compiled as
    sample :- ..., (X=yes;X=no), ...

See Also

inline / 2, expand_goal / 2, get_flag / 2, pragma / 1, compile / 1