Files
mercury/compiler/maybe_util.m
Zoltan Somogyi b7a4aa83dc Reorder the contents of unused_args.m.
compiler/unused_args.m:
    Put both the primitive operations on the module's main analysis
    data structure, and the code required for the analysis typeclass
    instances, into separate blocks near the end of the module,
    just before the debugging routines.

    Replace more uses of bools with the maybe_changed type.

    Do not allocate new hlds_goal structures that are identical to
    already existing hlds_goal structure.

    Carve two new small predicates out of an existing too-big one.

    Make some other simplifications, and improve some other type,
    predicate and variable names.

compiler/maybe_util.m:
    Add two utility functions for use by unused_args.m.
2026-02-12 19:47:27 +11:00

77 lines
2.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2021, 2023, 2025-2026 The Mercury team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------%
:- module libs.maybe_util.
:- interface.
:- import_module list.
:- type maybe_succeeded
---> did_not_succeed
; succeeded.
:- func maybe_succeeded `and` maybe_succeeded = maybe_succeeded.
:- func and_list(list(maybe_succeeded)) = maybe_succeeded.
%---------------------%
:- type is_first
---> is_first
; is_not_first.
:- type is_last
---> is_last
; is_not_last.
%---------------------%
:- type maybe_changed
---> unchanged
; changed.
:- func maybe_changed `or` maybe_changed = maybe_changed.
:- func or_list(list(maybe_changed)) = maybe_changed.
%---------------------%
:- type need_to_requantify
---> need_to_requantify
; do_not_need_to_requantify.
%---------------------------------------------------------------------------%
:- implementation.
%---------------------------------------------------------------------------%
SucceededA `and` SucceededB =
( if SucceededA = succeeded, SucceededB = succeeded then
succeeded
else
did_not_succeed
).
and_list(Succeededs) = AllSucceeded :-
AllSucceeded = list.foldl(and, Succeededs, succeeded).
%---------------------------------------------------------------------------%
ChangedA `or` ChangedB =
( if (ChangedA = changed ; ChangedB = changed) then
changed
else
unchanged
).
or_list(Changeds) = AnyChanged :-
AnyChanged = list.foldl(or, Changeds, unchanged).
%---------------------------------------------------------------------------%
:- end_module libs.maybe_util.
%---------------------------------------------------------------------------%