Files
mercury/compiler/simplify.m
Zoltan Somogyi 4a292707cf Replace simplify.m (which had 4500 lines) with several submodules.
The objective of this change is to improve module cohesion, with each
of the new modules doing only one task, or two or three closely related tasks.
Moving common.m into the new simplify package also improves information hiding,
since the details of the simplify_info data structure that common.m needs
aren't exposed to the rest of the compiler anymore.

This change mostly moves code around. There are no algorithmic changes.
In several places I did

- make predicate names more meaningful,
- reordered predicate definitions to put related predicates together
  (previously, the predicates involved in simplifying a particular kind of goal
  were often interspersed with predicates that worked only on other kinds of
  goals), and
- improved documentation (in some places expanding it, in some places
  correcting comments that suffered bit-rot and were out-of-date).

compiler/simplify.m:
    This file is now a package, including its submodules,
    but no code anymore.

compiler/simplify_goal.m:
    New submodule containing generic processing of goals.

compiler/simplify_goal_call.m:
compiler/simplify_goal_unify.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_scope.m:
    New submodules containing goal-type-specific processing of goals.
    Each of these modules is much more cohesive than the original simplify.m
    ever was; most export only one predicate per handled goal type.

compiler/simplify_info.m:
    New submodule containing the definition of simplify_info
    and its access predicates.

compiler/simplify_tasks.m:
    New submodule listing the tasks that the simplification pass
    may be asked to perform.

compiler/simplify_proc.m:
    New submodule containing the top-level processing of procedures.

compiler/common.m:
    Make this module a part of the simplify package. It is only ever invoked
    by simplification, and leaving it outside the package would require
    exporting more than a few internal details of simplify_info.

compiler/format_call.m:
    Make this module a part of the simplify package. It does its job during
    simplification, even though the need for it is noted during determinism
    analysis.

compiler/check_hlds.m:
    Remove common.m and format_call.m from the list of direct submodules
    of check_hlds.m. (They are now indirect submodules, through
    check_hlds.simplify.)

compiler/notes/compiler_design.html:
    Document the new modules, and the new status of common and format_call..

compiler/pd_util.m:
    Move some code from here to the new simplify_proc.m, since it allows us
    to avoid exposing internal details of how simplification works.

compiler/mercury_compile_front_end.m:
    Move a predicate here from the old simplify.m, since the job it does
    belongs here.

    Remove the ability to disable the invocation of cse_detection.
    This capability was only ever needed when measuring the effectiveness
    of determinism analysis for a paper; it hasn't been needed in a decade.

compiler/cse_detection.m:
    Improve the top level comment.

compiler/options.m:
doc/user_guide.texi:
    Remove the option that used to control the invocation of cse_detection.

compiler/*.m:
    Conform to the split of simplify.m, importing its submodules where needed.
2014-07-24 10:47:12 +02:00

58 lines
2.7 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 1996-2012 The University of Melbourne.
% Copyright (C) 2014 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.
%-----------------------------------------------------------------------------%
%
% The two jobs of the simplification package are
%
% - to find and exploit opportunities for simplifying the internal form
% of the program, both to optimize the code and to massage the code
% into a form the code generator will accept, and
%
% - to warn the programmer about any constructs that look suspicious.
%
% Originally, we warned only about code that was so simple that
% it should not have been included in the program in the first place
% (such as if-then-elses whose conditions cannot fail), but we now
% also warn about other things as well, such as mismatches between
% format strings and the values supplied to be printed.
%
%-----------------------------------------------------------------------------%
:- module check_hlds.simplify.
:- interface.
% We export simplify_tasks because it defines the type that
% clients of simplify use to tell simplify what tasks to perform.
:- include_module check_hlds.simplify.simplify_tasks.
% We export simplify_proc because it exports the predicates that
% clients of simplify call to invoke simplify.
:- include_module check_hlds.simplify.simplify_proc.
% We export format_call because the presence of calls in a procedure
% that format_call needs to check (and may be able to optimize) is noticed
% by code outside the simplify package, in determinism analysis.
% (We could have simplify look for such calls itself, but that would require
% an extra traversal of every procedure.)
:- include_module check_hlds.simplify.format_call.
:- implementation.
:- include_module check_hlds.simplify.common.
:- include_module check_hlds.simplify.simplify_goal.
:- include_module check_hlds.simplify.simplify_goal_call.
:- include_module check_hlds.simplify.simplify_goal_conj.
:- include_module check_hlds.simplify.simplify_goal_disj.
:- include_module check_hlds.simplify.simplify_goal_ite.
:- include_module check_hlds.simplify.simplify_goal_scope.
:- include_module check_hlds.simplify.simplify_goal_switch.
:- include_module check_hlds.simplify.simplify_goal_unify.
:- include_module check_hlds.simplify.simplify_info.
%-----------------------------------------------------------------------------%
:- end_module check_hlds.simplify.
%-----------------------------------------------------------------------------%