Commit Graph

27 Commits

Author SHA1 Message Date
Zoltan Somogyi
7b52bb2713 Carve indent.m out of parse_tree_out_misc.m.
compiler/indent.m:
compiler/parse_tree_out_misc.m:
    Move indent operations from parse_tree_out_misc.m to a new module,
    indent.m.

    Include a "2" in the names of these operations, because

    - these operations print two spaces per level of indentation, but
    - some other, similar operations in the compiler use four spaces per level,
      and they should be moved here later as well.

compiler/libs.m:
    Add the new module to the libs package.

compiler/notes/compiler_design.html:
    Document the new module, as well as some other modules in the libs
    package that weren't documented before.

compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_type_table.m:
    Try to use the indent2_string function instead of the write_indent2
    predicate, since this allows the indent to printed as part of a call
    to io.format.

    Fix the printing of loop control scope reasons. Make slight improvements
    in the format of some other parts of the output.

compiler/hlds_out_typeclass_table.m:
    Try to use the indent2_string function instead of the write_indent2
    predicate, since this allows the indent to printed as part of a call
    to io.format.

    Several fields of class and instance infos that contain lists of stuff
    (e.g. method_infos) were being written out on a single line, even though
    the lists could be quite long. Fix this by writing out each list item
    on its own line. Indent these lines, to separate them visually from
    the heading lines preceding them.

    Print more information about method_infos to help make sense of them.

compiler/hlds_out_util.m:
    Try to use the indent2_string function instead of the write_indent2
    predicate, since this allows the indent to printed as part of a call
    to io.format.

    Write each proof in a constraint proof map on its line.

compiler/parse_tree_out_sym_name.m:
    Add a function version of a predicate, which returns a string
    without writing it out.

compiler/hlds_out_mode.m:
    Improve variable names.

compiler/write_error_spec.m:
    Conform to the function renames in indent.m.
2023-05-09 20:14:55 +10:00
Zoltan Somogyi
6bdd8b84ee Move maybe_changed to maybe_succeeded.m and rename it.
compiler/maybe_util.m:
    Move the maybe_changed type from several modules of the compiler
    to maybe_succeeded.m, and rename it to maybe_util.m.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Implement and document the rename.

compiler/common.m:
compiler/compile_target_code.m:
compiler/decide_type_repn.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/parse_tree_out.m:
compiler/process_util.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-04-21 17:24:30 +10:00
Zoltan Somogyi
67bb8fce33 Move uint_emu.m's contents into int_emu.m ...
... as a preliminary for extending the emulation to sized ints and uints.

compiler/int_emu.m:
    Move all the emulation operations from uint_emu.m to int_emu.m,
    moving each uint operation next to its int equivalent. To make this
    possible without naming conflicts, add a distinguishing prefix
    to the name of each emulation predicate. (The emulations of each op
    for signed and unsigned ints are related though somewhat different,
    and both the similarities and differences are easily visible and checkable
    when their code is next to each other.)

    On the other hand, the emulation code for an operation for e.g.
    int/int8/int16/int32/int64 can be *identical* when the number of bits
    is a parameter of that code, and the next diff will exploit this fact.

    Unify the target_bits_per_int predicate from int_emu.m and the
    target_bits_per_uint predicate from uint_emu.m, which had exactly
    the same logic, and call it target_word_bits.

compiler/uint_emu.m:
    Delete this module.

compiler/libs.m:
    Delete both int_emu.m and uint_emu as a submodule of this package.

compiler/parse_tree.m:
    Move int_emu.m to become a submodule of this package, to allow the next
    change to it to use the some_int_const type in prog_data.m.

compiler/notes/compiler_design.html:
    Generalize the description of int_emu.m. Note that the description
    of uint_emu.m cannot be deleted, because it didn't exist :-(

compiler/const_prop.m:
compiler/simplify_goal_call.m:
    Conform to the changes above.
2023-04-18 12:59:55 +10:00
Peter Wang
5e638af0f1 Speed up retrieval of foreign imports.
For a do-nothing build of Prince with intermodule optimisation enabled,
mmc --make spends a large fraction of its time computing foreign imports,
or rather looking up the cached results of such. (There are 650 modules,
and the results for each module are looked up tens to hundreds of
thousands of times each.)

This change replaces the representation of cached_foreign_imports from
tree234 to one based on version_array. It reduces the average run time
for a do-nothing build of Prince on my machine from 7.80 s to 5.87 s,
for a speedup of ~25%.

compiler/va_map.m:
    Add a simplified version of a module that I originally wrote for
    Prince. I have permission to include it in the Mercury compiler and
    assign copyright to the Mercury team.

compiler/libs.m:
    Include the new module in the libs package.

compiler/make.deps_set.m:
    Implement a typeclass needed to use module_index as a va_map key.

compiler/make.dependencies.m:
    Implement a typeclass needed to use maybe(T) as a va_map_value.

    Use va_map to represent cached_foreign_imports instead of map.
2022-11-23 16:50:45 +11:00
Julien Fischer
cedbee7190 Move quote_arg/1 out of options.m.
Move the function quote_arg/1, which is used to quote arguments to shell
commands, out of options.m and into its own module. It is called from
several other places other than options.m and its implementation details
have nothing to do with the other contents of options.m.

Rename the function to quote_shell_cmd_arg/1.

compiler/shell_util.m:
    New module for quote_arg/1 and its supporting predicates.

compiler/libs.m:
    Include the new module.

compiler/options.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Import the new module where necessary.

compiler/notes/compiler_design.m:
    Update this document.
2022-07-25 23:43:25 +10:00
Zoltan Somogyi
775dad0599 Move the maybe_succeeded type to maybe_succeeded.m.
compiler/maybe_succeeded.m:
    The new module.

compiler/libs.m:
    Include the new module in the libs package.

compiler/notes/compiler_design.html:
    Document the new module.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/process_util.m:
    Conform to the move.
2021-08-13 03:08:19 +10:00
Peter Wang
bd7e672dec Replace MD4 implementation with MD5.
We used MD4 digests in the implementation of the `--track-flags'
feature. While there is no particular need to change, IIRC the only
reason I didn't use the more common MD5 algorithm is because I did not
know of a small portable implementation at the time.

compiler/md5.m:
compiler/Mercury.options:
    Add implementation of MD5 digest algorithm.
    The C code is public domain code, and apparently widely used.

compiler/md4.m:
    Delete this module.

compiler/libs.m:
    Include new module and delete old module.

compiler/make.m:
    Calculate MD5 digest for `.track_flags' files instead of MD4.
2021-06-05 13:15:19 +10:00
Zoltan Somogyi
181ada0dbf Avoid -O<n> resetting previously set options.
This implements Mantis feature request #495.

NEWS:
    Announce the change.

compiler/optimization_options.m:
    A new module for managing optimization options.

    It defines a separate bespoke type for every boolean optimization option
    to make it harder to confuse them. It defines a tuple type (opt_tuple)
    for accessing optimization options quickly. It implements the turning on
    (but NOT turning off) of optimizations when a given optimization level
    is selected.

tools/make_optimization_options_middle:
tools/make_optimization_options_db:
    The script that generates the meat of optimization_options.m,
    and the database of option names, kinds and initial values
    that it uses as its input. The script also generates some code
    for the special_handler predicate in compiler/options.m.

tools/make_optimization_options_start:
tools/make_optimization_options_end:
    The handwritten initial and final parts of optimization_options.m.

tools/make_optimization_options:
    The script that pulls these parts together to form optimization_options.m.

compiler/options.m:
    Make every optimization option a special option, to be handled by
    the special_handler predicate. That handling consists of simply
    adding a representation of the option to the end of a cord of
    optimization options, to be processed later by optimization_options.m.
    That processing will record the values of these options in the opt_tuple,
    which is where every other part of the compiler should get them from.

    Change the interface of special_handler to make the above possible.

    Add an "optopt_" (optimization option) prefix to the name of
    every optimization option, to make them inaccessible to the rest
    of the compiler under their old name, and thus help enforce the switch
    to using the opt_tuple. Any access to these options to look up
    their values would fail anyway, since the option data would no longer be
    e.g. bool(yes), but bool_special, but the name change makes this failure
    happen at compile time, not runtime.

    Reclassify a few options to make the above make sense. Some options
    (unneeded_code_debug, unneeded_code_debug_pred_name, and
    common_struct_preds) were classified as oc_opt even though they
    control only the *debugging* of optimizations, while some options
    (c_optimize and inline_alloc) were not classified as oc_opt
    even though we do set them automatically at some optimization levels.

    Delete the opt_level_number option, since it was not used anywhere.

    Delete the code for handling -ON and --opt-space, since that is now
    done in optimization_options.m.

    Add some XXXs.

compiler/handle_options.m:
    Switch to using getopt_io.process_options_userdata_se, as required
    by the new interface of the special_handler in options.m.
    In the absence of errors, invoke optimization_options.m to initialize
    the opt_tuple. Then update the opt_tuple incrementally when processing
    option implications that affect optimization options.

compiler/globals.m:
    Put the opt_tuple into a new field of the globals structure.

compiler/accumulator.m:
compiler/add_pragma_type_spec.m:
compiler/add_trail_ops.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/compile_target_code.m:
compiler/const_struct.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/disj_gen.m:
compiler/erl_code_gen.m:
compiler/format_call.m:
compiler/global_data.m:
compiler/grab_modules.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/libs.m:
compiler/llds_out_code_addr.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_instr.m:
compiler/llds_out_util.m:
compiler/matching.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_disj_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/optimize.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/proc_gen.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/simplify_tasks.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/tag_switch.m:
compiler/tupling.m:
compiler/unify_gen_construct.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
    Conform to the changes above, mostly by looking up optimization options
    in the opt_tuple. In some places, replace bools containing optimization
    options with the bespoke type of that specific optimization option.

library/getopt_template:
    Fix a bug that screwed up an error message.

    The bug happened when processing a --file option. If one of the
    options in the file was a special option whose special handler failed,
    the code handling that failing option returned both an error indication,
    and the rest of the argument list read in from the file. The code
    handling the --file option then *ignored* the error indication from
    the failed special option, and returned an error message of its own
    complaining about the unconsumed remaining arguments in the file,
    believing them to be non-option arguments, even though these arguments
    were never looked it to see if they were options.

    The fix is for the code handling --flag options to check whether
    the code processing the file contents found any errors, and if so,
    return that error *without* looking at the list of remaining arguments.

    In an unrelated change, factor out a duplicate call.
2020-09-28 18:16:13 +10:00
Julien Fischer
88a681a063 Move the library grade install check out of the make package.
Move the library grade install check out of the make package and into its own
module in the libs package.  This is in preparation for performing the check
when building single source file programs.

compiler/check_libgrades.m:
    New module containing the code that implements the library grade install
    check.

compiler/libs.m:
    Include the new module.

compiler/make.program_target.m:
    Conform to the above change.

compiler/notes/compiler_design.html:
    Mention the new module.
2019-09-12 16:52:59 +10:00
Zoltan Somogyi
1db9b84390 Generate Mmakefile fragments via an internal representation.
The compiler generates several kinds of files (including .d, .dv, and
.dep files) that contain mmakefile fragments. Imposing structure on
those fragments makes it easier to compare different versions
of those fragments. This should make it easier to find the reason
why modifications to a module in a directory that is compiled with
intermodule optimization (such as the library directory) usually requires
rebuilding those mmakefile fragments via an "mmake depend".

One advantage of the new way of creating mmakefile fragments
is that the internal representation makes it clear where the code
that constructs one mmakefile entry ends and code that constructs
the next one begins. With the old approach, this was often significantly
less clear than one would expect and want.

compiler/mmakefiles.m:
    A new module that defines a representation for mmakefiles and mmakefile
    fragments, and for printing them out.

    It provides the means for a gradual transition from the current code
    writing out mmakefile fragments directly to printing them out
    via this module. The main technique it uses for this is to let both
    the manually-written and the generated-from-internal-representation
    versions of a mmakefile fragment be printed, with one version
    or the other being disabled via the make equivalent of C's "#ifdef 0".

compiler/libs.m:
    Add mmakefiles.m to the libs package.

compiler/notes/compiler_design.html:
    Document mmakefiles.m.

compiler/write_deps_file.m:
    After each piece of code that prints out a part of an mmakefile,
    add code to construct the internal representation of that part,
    and let mmakefiles.m print it if that the current state of the transition
    calls for it.

    This change duplicates a significant amount of functionality.
    However, this should be only a short time. After a transition period,
    we can delete the old version of each such piece of code.

    The new versions of the code use "some [!StateVar]" scopes
    reasonably extensively. I refrained from indenting the bodies
    of those scopes to avoid having to wrap the code inside them,
    since that would make this diff harder to review.

    Put a vim modeline at the top of generated mmakefile fragments,
    to make it easier to look at them with vim.

    Move all the code that opens and closes I/O streams to one predicate.

    Delete the tests of the assume_gmake option. While this was useful
    at one time in the past, we have, for a long time now, generated
    mmakefile fragments that assumed gmake even when assume_gmake
    was NOT set.

    In several places, give variables more meaningful names.

compiler/file_names.m:
    Provide versions of some predicates that are easier to use
    with higher-order code.

compiler/Mercury.options:
    Specify --warn-implicit-stream-calls for both mmakefiles.m and
    write_deps_file.m
2017-06-11 23:31:00 +02:00
Julien Fischer
dd4b389f56 Implement compile time evaluation for uint operations.
compiler/const_prop.m:
    Extend this module to support compile time evaluation of uint operations.

compiler/uint_emu.m:
    A new module that emulates `uint' operations for the bits-per-uint in
    a manner similar to the int_emu module.

compiler/libs.m:
    Include the new module.

tests/hard_coded/constant_prop_1.{m,exp}:
tests/hard_coded/constant_prop_2.{m,exp}:
    Test compile time evaluation of uint operations.

    Update coding style in these tests.

tests/hard_coded/Mmakefile:
    Conform to the above changes.  (XXX the existing check
    for the Java grade doesn't actually work.)

    Delete left over IL and GCC backend stuff.
2017-05-14 02:40:26 +10:00
Paul Bone
e2ffb8d01a Reorganise dependency graph code
This change moves code that could be generic/common out of
hlds_dependency_graph.m into dependency_graph.m.  It also moves some code
from hlds_module.m into hlds_dependency_graph.m where it makes more sense.

compiler/dependency_graph.m:
    New module.

    Make the accessors predicates functions and give them more sensible
    names.

    Create a new accessors to get a version or the dependency ordering,
    condensed into a single list.

compiler/hlds_dependency_graph.m:
    Build the dependency_info structure in a more straightforward way.  It
    can easily be created with a single call rather than three.  The
    dependency ordering information is now calculated by dependency_graph.m.

    Make build_dependency_graph, build_proc_dependency_graph and
    build_pred_dependency_graph functions rather than predicates.

compiler/hlds_module.m:
    As above.

compiler/closure_analysis.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/exception_analysis.m:
compiler/granularity.m:
compiler/hlds_dependency_graph.m:
compiler/inlining.m:
compiler/lco.m:
compiler/libs.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_constraints.m:
compiler/par_loop_control.m:
compiler/rbmm.interproc_region_lifetime.m:
compiler/rbmm.points_to_analysis.m:
compiler/stratify.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/tupling.m:
    Conform to changes.
2017-02-16 12:41:51 +11:00
Zoltan Somogyi
d08f1fbe6c Move the code that computes the grade to a new module.
compiler/compute_grade.m:
    New module containing all the code previously in handle_options.m
    that concern grades.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Include and document the new module.

compiler/compiler_util.m:
    Since both handle_options.m and compute_grade.m now need to be able
    to record errors, move the predicates that handle_options.m used to use
    for this purpose to this module, which already contains related predicates.
    Generalize the moved predicates, so they can be used from phases other than
    option processing.

compiler/handle_options.m
    Remove the moved code.

compiler/exception_analysis.m:
compiler/file_names.m:
compiler/file_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_user.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
compiler/mercury_compile_front_end.m:
compiler/module_cmds.m:
compiler/options.m:
compiler/tabling_analysis.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
    Conform to the above, and/or delete unneeded imports.
2015-10-17 23:09:22 +11:00
Zoltan Somogyi
08d84a144d Put the op_mode in the globals.
compiler/globals.m:
    Put the op_mode into the globals structure.

compiler/handle_options.m:
    Invoke the code that computes the op_mode *before* creating the globals.
    Delete the code duplication concerning the computation of the Link flag.

compiler/op_mode.m:
    New module containing the definition of the op_mode type,
    and the predicate that figures out the op_mode from the values of options.
    These are taken from mercury_compile.m, and the latter is adapted
    to work on the option_table, not the globals, since it is now invoked
    as *part* of the code to build up the globals.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Include the new module.

    Do not include the atsort.m module in the libs package, since it
    hasn't been used in a long time, and its inclusion adds to the bulk
    of the compiler executable without any compensating gain.

compiler/mercury_compile.m:
    Delete the code now in op_mode.m.

    Conform to the changes above.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/mercury_compile_erl_back_end.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
    Standardise dividing lines.
2015-10-14 03:06:46 +11:00
Peter Wang
6e3e60fae0 More robust compile-time evaluation of `int' operations.
Compile-time evaluation of `int' operations previously required that
the target have the same number of bits per int as the host compiler.
In other cases, the user would have to pass `--cross-compiling' to avoid
the compiler silently producing a different result at compile time to
what would be produced at run time.

This change makes the compiler aware of the target's `int' width when
evaluating operations at compile-time.

Passing `--cross-compiling' is no longer required to avoid the problems
that this change addresses, but it MAY still be required for other reasons.
As of now, the one problem it would avoid is generating incorrect trie
string switches containing non-ASCII strings when targeting a high-level
C grade from a compiler built in Java or C# grades (not really
supported, but something we can fix anyway).  I have not removed any
references to the `--cross-compiling' option in the documentation.

compiler/libs.m:
compiler/int_emu.m:
	Add new module to emulate `int' operations for the target
	bits-per-int.  The predicates will only succeed if the result
	would be well-defined (including no overflow), and the result
	fits in the host's `int' type (no truncation).

compiler/const_prop.m:
	Evaluate `int' operations at compile time using `int_emu'
	predicates.

	Delete now unnecessary checks for cross_compiling=no.

	Delete comment about checking for overflow, now done.

compiler/simplify_goal_call.m:
	Use the target's value of bits-per-int in relevant
	simplifications.

	Delete check for cross_compiling=no.

compiler/handle_options.m:
	Don't imply `--cross-compiling' when targeting java, csharp and
	erlang grades.  This was a temporary workaround in case the
	Mercury compiler itself uses 64-bit ints.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/constant_prop_int.exp:
tests/hard_coded/constant_prop_int.exp2:
tests/hard_coded/constant_prop_int.m:
	Add test case.

compiler/notes/compiler_design.html:
	Document new module.
2015-03-19 14:20:54 +11:00
Peter Wang
3085aa8f6d Add mmc --make --track-flags:
Branches: main

Add mmc --make --track-flags:

    --track-flags
	With `--make', keep track of the options used when compiling
	each module.  If an option for a module is added or removed,
	`mmc --make' will then know to recompile the module even if the
	timestamp on the file itself has not changed.  Warning and
	verbosity options are not tracked.

The motivation was to be able to set the execution trace level on selected
modules by editing Mercury.options, without needing to manually touch the
affected files afterwards to force recompilation.  It's probably useful for
anyone that's worried about consistent builds.

The implementation works by recording a hash of the option table which is the
product of the options set for each particular module in .track_flags files,
not a hash of the actual options passed by the user, which might be reordered
or redundant, etc.  Hashes are used as they are much quicker to compare and
take less space (the full options tables are quite big).

compiler/options.m:
	Add the new option.

	Add a predicate to return options that shouldn't be tracked
	(e.g. adding -v shouldn't cause everything to recompile).

compiler/make.m:
	When --track-flags is enabled, write `.track_flags' files which need
	to be changed.

compiler/make.dependencies.m:
	When --track-flags is enabled, make compiled code files depend on the
	`.track_flags' files.

compiler/make.program_target.m:
	Delete .track_flags files on realclean.

compiler/make.module_target.m:
compiler/make.util.m:
	Conform to changes above.

compiler/libs.m:
compiler/md4.m:
	Add an implementation of the MD4 digest function to libs.

doc/user_guide.texi:
NEWS:
	Document the new option.

	Recommend `mmc --make' instead of `mmake' in the user guide.

library/term_io.m:
	Avoid unnecessary memory allocation in should_atom_be_quoted.
2009-04-16 01:45:09 +00:00
Zoltan Somogyi
1373003785 Delete the old tree.m module (which did a small subset of what cords now do),
Estimated hours taken: 6
Branches: main

Delete the old tree.m module (which did a small subset of what cords now do),
and switch to using cords instead. This is more standard, as well as very
slightly more efficient, because with cords, e.g. concatenating ten code
fragments of which eight are empty doesn't allocate ten cons cells.
My measurements show a 0.1% reduction in executable size and a 0.3% reduction
in compilation time. Both of those are in the noise; the main reason for the
change is more convenient coding.

compiler/tree.m:
	Remove this module.

compiler/libs.m:
	Remove the inclusion of tree.m.

compiler/notes/compiler_design.html:
	Remove the description of tree.m.

compiler/bytecode.m:
	Switch to using cords to represent code in the bytecode backend.

compiler/llds.m:
	Switch to using cords to represent code in the LLDS backend.

compiler/mlds_to_il.m:
	Switch to using cords to represent IL code being built.

compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/commit_gen.m:
compiler/dense_switch.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/lookup_switch.m:
compiler/lookup_util.m:
compiler/middle_rec.m:
compiler/par_conj_gen.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/switch_case.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/trace_gen.m:
compiler/unify_gen.m:
compiler/var_locn.m:
	Conform to the changes above.

library/cord.m:
	Add a predicate form of map.
2009-01-06 03:56:53 +00:00
Peter Wang
c3fcb07f78 Add a caching feature for `mmc --make' so as to avoid reparsing the same
Branches: main

Add a caching feature for `mmc --make' so as to avoid reparsing the same
`.analysis' files repeatedly when many modules in the program or library
import similar sets of modules.

An `.analysis_cache' file contains a binary representation of the parsed
information in its corresponding `.analysis' file.  These can be faster to
load, under certain conditions.  Cache files are stored in
`Mercury/analysis_cache' or `Mercury/<grade>/<arch>/Mercury/analysis_cache'
for the duration of a single make target.  Afterwards the directory is
deleted.  This avoids stale cache files lying around which are incompatible
between different versions of the compiler, host platform, etc.

compiler/libs.m:
compiler/pickle.m:
	Add a module in libs to un/serialise arbitrary data structures.

compiler/options.m:
	Add `--analysis-file-cache' and `--analysis-file-cache-dir <dir>'
	(internal option).

compiler/analysis.file.m:
	Read and write analysis cache files if the cache directory is set.
	Cache files are written after `.analysis' files are written (if
	changed) or after an `.analysis' file is read (if it didn't exist).

compiler/make.program_target.m:
	For certain targets, set up the analysis cache directory before
	running the build procedure, and remove it afterwards.

compiler/module_cmds.m:
	Add a version of update_interface that returns whether the
	interface file changed.

doc/user_guide.texi:
	Add commented out documentation for `--analysis-file-cache'.
2008-07-25 00:47:57 +00:00
Zoltan Somogyi
a00596c283 The file modules.m contains lots of different kinds of functionality.
Estimated hours taken: 16
Branches: main

The file modules.m contains lots of different kinds of functionality.
While much of it belongs together, much of it does not. This diff moves
most of the functionality that does not belong with the rest to several
new modules:

	libs.file_util
	parse_tree.deps_map
	parse_tree.file_names
	parse_tree.module_cmds
	parse_tree.module_imports
	parse_tree.read_module
	parse_tree.write_deps_file

To make them coherent, move some predicates from hlds.passes_aux,
parse_tree.prog_io and parse_tree.prog_out to the new modules, making them
more accessible, reducing the required access from the hlds package to
parse_tree, or from the parse_tree package to libs.

In the same spirit, this diff also moves some simple predicates and functions
dealing with sym_names from prog_util.m to mdbcomp/prim_data.m. This allows
several modules to avoid depending on parse_tree.prog_util.

Rename some of the moved predicates and function symbols where this avoids
ambiguity. (There were several that differed from other predicates or function
symbols only in arity.)

Replace several uses of bools with purpose-specific types. This makes some
of the code significantly easier to read.

This diff moves modules.m from being by far the largest module, to being
only the seventh largest, from 8900+ lines to just 4200+. It also reduces
the number of modules that import parse_tree.modules considerably; most
modules that imported it now import only one or two of the new modules instead.

Despite the size of the diff, there should be no algorithmic changes.

compiler/modules.m:
compiler/passes_aux.m:
compiler/prog_io.m:
compiler/prog_out.m:
	Delete the moved functionality.

compiler/file_util.m:
	New module in the libs package. Its predicates search for files
	and do simple error or progress reporting.

compiler/file_names.m:
	New module in the parse_tree package. It contains predicates for
	converting module names to file names.

compiler/module_cmds.m:
	New module in the parse_tree package. Its predicates handle the
	commands for manipulating interface files of various kinds.

compiler/module_import.m:
	New module in the parse_tree package. It contains the module_imports
	type and its access predicates, and the predicates that compute
	various sorts of direct dependencies (those caused by imports)
	between modules.

compiler/deps_map.m:
	New module in the parse_tree package. It contains the data structure
	for recording indirect dependencies between modules, and the predicates
	for creating it.

compiler/read_module.m:
	New module in the parse_tree package. Its job is reading in modules,
	both human-written and machine-written (such as interface and
	optimization files).

compiler/write_deps_file.m:
	New module in the parse_tree package. Its job is writing out
	makefile fragments.

compiler/libs.m:
compiler/parse_tree.m:
	Include the new modules.

compiler/notes/compiler_design.m:
	Document the new modules.

mdbcomp/prim_data.m:
compiler/prog_util.m:
	Move the predicates that operate on nothing but sym_names from
	prog_util to prim_data.

	Move get_ancestors from modules to prim_data.

compiler/prog_item.m:
	Move stuff that looks for foreign code in a list of items here from
	modules.m.

compiler/source_file_map.m:
	Note why this module needs to be in the parse_tree package.

compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/analysis.file.m:
compiler/analysis.m:
compiler/assertion.m:
compiler/check_typeclass.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/elds_to_erlang.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_passes.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mercury_compile.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/optimize.m:
compiler/passes_aux.m:
compiler/proc_gen.m:
compiler/prog_foreign.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/pseudo_type_info.m:
compiler/purity.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/simplify.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.direct.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/trans_opt.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_info.m:
compiler/unify_proc.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
	Minor changes to conform to the changes above.
2008-07-21 03:10:29 +00:00
Julien Fischer
5f589e98fb Various cleanups for the modules in the compiler directory.
Estimated hours taken: 4
Branches: main

Various cleanups for the modules in the compiler directory.  The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.

compiler/*.m:
	Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
	appropriate throughout most or the compiler.

	Fix inaccurate assertion failure messages, e.g. identifying the
	assertion failure as taking place in the wrong module.

	Add :- end_module declarations.

	Fix formatting problems and bring the positioning of comments
	into line with our current coding standards.

	Fix some overlong lines.

	Convert some more modules to 4-space indentation.  Fix some spots
	where previous conversions to 4-space indentation have stuffed
	the formatting of the code up.

	Fix a bunch of typos in comments.

	Use state variables in more places; use library predicates
	from the sv* modules where appropriate.

	Delete unnecessary and duplicate module imports.

	Misc. other small cleanups.
2005-11-17 15:57:34 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Zoltan Somogyi
905e4a114f Convert a bunch of modules to four-space indentation.
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Convert a bunch of modules to four-space indentation.
	In the process, fix departures from our coding standards.

	In some cases, do minor other cleanups such as changing argument orders
	to be friendly to state variables.

	There are no algorithmic changes.
2005-10-12 23:51:38 +00:00
Julien Fischer
4c39d891fc Clean up lp.m and bring it more into sync with the corresponding
Estimated hours taken: 1.5
Branches: main

Clean up lp.m and bring it more into sync with the corresponding
parts of lp_rational.m.  The one algorithmic change is to replace
two closures that where called by an all solutions predicate with a
single iterative predicate that does the same thing.

Shift lp.m from the transform_hlds package into the libs package.

compiler/lp.m:
	Shift to 4-space indentation throughout.

	Use state variables throughout and rearrange argument
	orders where necessary.

	Use predmode syntax throughout.

	Add field names to several of the major data structures
	in this module.

	Standardize variable names.

	s/__/./ throughout.

	Other minor formatting changes.

compiler/transform_hlds.m:
compiler/libs.m:
	Move the lp module from the transform_hlds package to the
	libs package.  It doesn't really have anything to do with
	the HLDS.

compiler/term_pass1.m:
compiler/notes/compiler_design.html:
	Minor changes to conform to the above.
2005-04-19 02:47:16 +00:00
Julien Fischer
c5e315b0fc Add the first part of the new termination analyser.
Estimated hours taken: lots
Branches: main

Add the first part of the new termination analyser.  This includes most
of the argument size analyser and a simple termination checker - I'll
add a more extensive one as part of another diff.  The one included here
is only a placeholder and is roughly equivalent to the one used by the
existing termination analyser.

The new analysis abstracts term size relationships over a domain of
(rational) convex constraints.  The resulting size relationships are, in
many cases, more precise than we can obtain with the old analysis.  This
means that we should be able to prove termination in more cases.  The
tradeoff for this increased precision is that the new termination
analysis is slower than the old one.  We should also be able to adapt
the new analyser to handle things like higher-order constructs and
intermodule mutual recursion more easily than the old one.

The code for writing termination2_info pragmas to .opt and .trans_opt
files is currently commented out.  It will need to stay that way until
after this change bootstraps and after the tests/term directory as been
reworked (the .trans_opt_exp files need to updated and some new test
cases have to added - I'll do this as part of separate diff).

It isn't clear what the relationship between the new analyser and the
existing one should be, so at the moment they are as independent of each
other as possible.

compiler/termination2.m:
	New file.  Invokes the the other passes of the new analysis
	and handles the output of termination2_info pragmas to .opt
	and .trans_opt files.

	XXX I've disabled the writing out of termination2_info
	pragmas to the (transitive-)intermodule optimization files
	until I've updated the test suite.

compiler/term_constr_data.m:
	New file.  Defines the main data structures used by the
	new analysis.

compiler/term_constr_initial.m:
	New file.  Sets up information for builtin and compiler
	generated procedures and processes information about
	imported procedures.  Also handles termination pragmas.

compiler/term_constr_build.m:
	New file.  Converts the HLDS representation of a procedure
	into the abstract representation that we use during the rest
	of the analysis.

compiler/term_constr_fixpoint.m:
	New file.  Perform a fixpoint calculation in order to derive
	interargument size relationships for a procedure (in the
	form of convex constraints).

compiler/term_constr_pass2.m:
	New file.  A rudimentary termination checker that is roughly
	equivalent to what the existing termination analysis does.
	This is just a placeholder.

compiler/term_constr_util.m:
	New file.  Utility predicates that are used by the above modules.

compiler/term_constr_errors.m:
	New file.  Equivalent to term_errors.m for the new analyser.

compiler/rat.m:
	Provide rational numbers over fixed precision integers.
	Originally committed on the termination2 branch.

compiler/lp_rational.m:
	Provides the necessary machinery for manipulating systems
	of linear constraints.  Originally committed on the termination2
	branch although most of this version is new.  (Some bits of the
	version on the termination2 branch are now in polyhedron.m).
	The linear solver is essentially the one that is currently
	in lp.m converted to use rationals rather than floats.

compiler/polyhedron.m:
	New file.  An ADT that provides convex polyhedra over the
	rationals (or at least over rats).  The abstraction barrier was
	designed so that we could experiment with different representations
	for the polyhedra.

compiler/term_norm:
	Clean up the documentation of this module.
	Make set_functor_info into a function.
	Add a function for finding a lower bound on the weight of a functor.

compiler/trans_opt.m:
	Output termination2_info pragmas in .trans_opt files.

compiler/transform_hlds.m:
	Include the new termination analyser.

compiler/goal_form.m:
	When checking whether a goal can loop or not use
	information from the new termination analyser as well as
	the old one.

compiler/globals.m:
compiler/handle_options:
compiler/options.m:
	Add options to control the new analyser.   The documentation
	is currently commented out because the new analysis is still
	a work-in-progress.  It should be uncommented when the new
	analysis is more mature.

	XXX The user guide still needs to be updated.

compiler/hlds_out.m:
	Add hlds_out.write_pred_proc_id/4.

compiler/hlds_pred.m:
	Add a slot in the proc_sub_info structure for the
	termination2_info structure.

compiler/rat.m:
	Provide rational numbers over fixed precision integers.

compiler/lp_rational.m:
	Provide the constraint machinery required by the analyser.

compiler/make_hlds.m:
	Handle imports of termination2_info pragmas.

compiler/mercury_compile.m:
	Run the new pass.  Currently, we do this directly after
	the old termination analysis pass.

compiler/mercury_to_mercury.m:
	Add code to output termination2_info pragmas.

compiler/libs.m:
	Include the rat, polyhedron and lp_rational modules.

compiler/prog_data.m:
	Define the types necessary for termination2_info pragmas.

	Change the cannot_loop constructor of the generic_termination_info
	type so it has a polymorphic argument.  The new analyser stores
	information in it.

	Fix some spelling errors in some of the comments

compiler/prog_io_pragma.m:
	Parse termination2_info pragmas.

compiler/error_util.m:
	Add function versions of sorry/2 and unexpected/2.

compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/termination.m
compiler/term_pass2.m
compiler/term_util.m:
	Minor changes to confrom to the above.
2005-04-07 06:32:17 +00:00
Zoltan Somogyi
1cb657b998 Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3
Branches: main

Reduce inappropriate dependencies on ll_backend modules. Except for
simplification of unnecessarily complicated logic in dependency_graph.m,
this change only moves functionality around.

compiler/llds_out.m:
compiler/c_util.m:
compiler/name_mangle.m:
	Move predicates that are used by multiple backends from
	ll_backend__llds_out to backend_libs__c_util and to a new module
	backend_libs__name_mangle. Make the relevant ones functions,
	and give some of them more meaningful names.

compiler/trace.m:
compiler/hlds_goal.m:
	Move a backend-independent predicate from ll_backend__trace
	to hlds__hlds_goal.

compiler/llds.m:
compiler/trace_params.m:
	Move the definition of the trace_port type from ll_backend__llds
	to libs__trace_params to avoid having libs__trace_params depend on
	ll_backend.

compiler/exprn_aux.m:
compiler/globals.m:
	Move the definition of the imported_is_constant from
	ll_backend__exprn_aux to libs__globals to avoid having libs__globals
	depend on ll_backend.

compiler/*.m:
	Conform to the above changes. This removes many inappropriate
	dependencies on the LLDS backend.
2003-03-16 08:01:31 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00