Files
mercury/library/std_util.m
Zoltan Somogyi 4563d57d1b The transformation that implements dependent parallel conjunctions can create
Estimated hours taken: 12
Branches: main

The transformation that implements dependent parallel conjunctions can create
specialized versions of existing procedures, versions in which one or more
wait and/or signal operations are pushed into the procedure. However, if
the procedure waits for the consumer variable immediately at the start,
or if it generated the signalled produced variable just before the end,
then the specialization gains no time but does increase program size
(and through cache effects also increases runtime). This diff ensures
that we push waits and signals into procedure bodies only when we estimate
that doing so is worthwhile.

compiler/dep_par_conj.m:
	Implement the change above.

	Add some XXXs documention weaknesses of the existing code.

compiler/options.m:
doc/user_guide.texi:
	Add an option, --always-specialize-in-dep-par-conjs, that restores
	the old behavior, to allow implementors to measure the effect of this
	change.

	Document an old option whose documentation was missing.

library/std_util.m:
	Add a utility predicate for use in assertions.
2008-10-24 02:47:44 +00:00

114 lines
3.3 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%-----------------------------------------------------------------------------%
% Copyright (C) 1994-2006, 2008 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% File: std_util.m.
% Main author: fjh.
% Stability: high.
%
% This file contains higher-order programming constructs and other
% useful standard utilities.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module std_util.
:- interface.
:- import_module maybe.
%-----------------------------------------------------------------------------%
%
% General purpose higher-order programming constructs
%
% compose(F, G, X) = F(G(X))
%
% Function composition.
% XXX It would be nice to have infix `o' or somesuch for this.
%
:- func compose(func(T2) = T3, func(T1) = T2, T1) = T3.
% converse(F, X, Y) = F(Y, X).
%
:- func converse(func(T1, T2) = T3, T2, T1) = T3.
% pow(F, N, X) = F^N(X)
%
% Function exponentiation.
%
:- func pow(func(T) = T, int, T) = T.
% The identity function.
%
:- func id(T) = T.
%-----------------------------------------------------------------------------%
% maybe_pred(Pred, X, Y) takes a closure Pred which transforms an
% input semideterministically. If calling the closure with the input
% X succeeds, Y is bound to `yes(Z)' where Z is the output of the
% call, or to `no' if the call fails.
%
:- pred maybe_pred(pred(T1, T2), T1, maybe(T2)).
:- mode maybe_pred(pred(in, out) is semidet, in, out) is det.
:- func maybe_func(func(T1) = T2, T1) = maybe(T2).
:- mode maybe_func(func(in) = out is semidet, in) = out is det.
%-----------------------------------------------------------------------------%
% isnt(Pred, X) <=> not Pred(X)
%
% This is useful in higher order programming, e.g.
% Odds = list.filter(odd, Xs)
% Evens = list.filter(isnt(odd), Xs)
%
:- pred isnt(pred(T)::in(pred(in) is semidet), T::in) is semidet.
% negate(Pred) <=> not Pred
%
% This is useful in higher order programming, e.g.
% expect(negate(Pred), ...)
%
:- pred negate((pred)::in((pred) is semidet)) is semidet.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int.
%-----------------------------------------------------------------------------%
maybe_pred(Pred, X, Y) :-
Y = ( Pred(X, Z) -> yes(Z) ; no ).
maybe_func(PF, X) =
( if Y = PF(X) then yes(Y) else no ).
compose(F, G, X) =
F(G(X)).
converse(F, X, Y) =
F(Y, X).
pow(F, N, X) =
( if N = 0 then X else pow(F, N - 1, F(X)) ).
isnt(P, X) :-
not P(X).
negate(P) :-
not P.
id(X) = X.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%