190 Commits

Author SHA1 Message Date
Zoltan Somogyi
47e7b8eedd Reduce the number of modules that set the exit status ...
... by removing four more modules from that set.

compiler/make.module_dep_file.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_middle_passes.m:
    Replace bespoke error reporting code with invocations of standardized
    error reporting predicates.

compiler/source_file_map.m:
    Delete an unused predicate.
2026-04-03 04:16:56 +11:00
Julien Fischer
318b21ae48 Fix a problem with reading .module_dep files.
The source file name that is used as the second argument of a .module_dep file
may be directory qualified (e.g. if we are using source file mapping to
include source files from multiple directories). On Windows, such directory
qualified source file names may use '\' as a path separator. We use the term
parser to read the contents of .module dep files and that requires '\' to be
escaped. However, the code that writes module_dep files does not currently
do the required escaping. Fix that.

compiler/make.module_dep_file.m:
    Escape the source file name before writing it to a .module_dep file.
2026-01-05 19:41:41 +11:00
Zoltan Somogyi
d208501c43 Give construct_d_file_deps_hlds more detailed info.
Instead of passing it a single set of modules that represents all the
other modules that the current mode depends on, pass it a structure that
specifies *how* it depends on those modules. Without this info, we cannot
eliminate any unnecessary dependencies we now put into .d files.
However, do not change the .d files that we output *yet*.

compiler/generate_dep_d_files.m:
    Define the type that holds this more detailed info, and use it.

compiler/hlds_module.m:
    Use this new type to collect the info that it is intended to collect.
    Change the set of getter, setter and update predicates to make distinctions
    that we now need that we ignored in the past.

compiler/module_baggage.m:
compiler/module_dep_info.m:
    Make a field name more descriptive.

compiler/generate_mmakefile_fragments.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_augment.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/ml_top_gen.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2025-08-01 15:35:29 +02:00
Zoltan Somogyi
79bfb1247f Carve prog_parse_tree.m out of prog_item.m.
compiler/prog_item.m:
compiler/prog_parse_tree.m:
    Split prog_item.m into two modules, with the new module prog_parse_tree.m
    containing the definitions of the file-kind-specific parse trees,
    and prog_item.m continuing to contain the definitions of the items
    that occur in those parse trees. Specialize the top-of-module comment
    to the current contents of each module.

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

compiler/*.m:
    Conform to the changes above.
2024-12-19 01:27:00 +11:00
Zoltan Somogyi
3b3b543a84 Return both legacy and proposed file names.
compiler/file_names.m:
    Change the predicates that return file names to return as their result
    both the current, legacy filename, and the proposed filename.

    For ext_cur extensions, the legacy and the proposed filenames
    will always be identical. Add a predicate for these that returns
    just this one filename.

compiler/comp_unit_interface.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.check_up_to_date.m:
compiler/make.clean.m:
compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/make_module_file_names.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.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/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above. In most places, this means ignoring
    the proposed filename for now, but marking such places with "XXX LEGACY",
    to make them easier to find when we *do* start to make use of the proposed
    file names (first alongside the legacy names, and then without them).

    In some places, make variable names more descriptive.

library/set.m:
    Add utility predicate for use by a diff to one of the modules above.

NEWS.md:
    Announce the new library predicate.
2024-09-19 12:42:33 +02:00
Zoltan Somogyi
aa7b899e74 Undo making .module_dep files grade-specific, for now. 2024-09-04 16:54:06 +02:00
Zoltan Somogyi
b296fac67d Put .module_dep files grade-specific dirs.
compiler/file_names.m:
    Reclassify .module_dep files as being put into grade-specific
    subdirs in the presence of --use-grade-subdirs.

    Document why .err_date files also belong in grade-specific subdirs.

    Document why .prof files do NOT belong in grade-specific subdirs.

    Fix some typos.

compiler/generate_mmakefile_fragments.m:
compiler/make.get_module_dep_info.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2024-08-04 12:41:25 +02:00
Zoltan Somogyi
25f8a6cc99 Add new option --generate-dependencies-ints.
This new option extends --generate-dependencies to take advantage of the
opportunity afforded by the fact that "mmc --generate-dependencies prog.m"
reads in every Mercury source file in the current directory that is
part of "prog". It does this by

- generating the .int3 file of all local-directory modules of the program;
- generating the .int0 file for each these modules that has submodules;
- generating the .int and .int2 files of all local-directory modules
  of the program.

Normally, the process of creating .int0, .int and .int3 files would
need to read in .int0 and .int3 files, but in every one of these cases,
we have just written out those files, so simply holding onto their
parse trees, we can skip this step. On my laptop, on a directory
containing library/*.m, mdbcomp/*.m and compiler/*.m, generating
the dependencies and generating all the .int3/.int0/.int/.int2 files
takes just over 25 seconds. Using the new option, the same process
takes less than 10 seconds.

compiler/options.m:
    Add the new option.

compiler/op_mode.m:
    Add a new variant of the existing op_mode for --generate-dependencies,
    which we select in the presence of the new option.

compiler/mercury_compile_main.m:
    Implement the new op_mode.

    Fix an old issue, which is that "mmc --make-private-interface x.m"
    generated a .int0 file for *every* module in x.m, even the modules
    that don't have any submodules.

compiler/deps_map.m:
    The code implementing the new option needs to know which modules
    of the program are in the current directory. The deps_map structure
    built by the code shared with the implementation of --generate-dependencies
    has not needed that info until now, so add a new field to the deps
    structure of each module to provide this info.

compiler/generate_dep_d_files.m:
    Return the deps_map created by the code that implements both
    --generate-dependencies and the new option to mercury_compile_main.m.

compiler/write_module_interface_files.m:
    Add a flag to the predicates that first construct the parse trees of,
    and then write out, .int3/.int0/.int/.int2 files, that
    mercury_compile_main.m can use to tell them to record the parse trees
    in the have read module maps.

    Add new variants of two of those predicates that take some of their
    arguments from burdened_module structures, since that is the form
    in which mercury_compile_main.m has that info.

compiler/module_baggage.m:
    The predicates in write_module_interface_files.m that generate
    .int0/.int/.int2 files take an argument that should be the timestamp
    of the source file they are being derived from, if that timestamp
    is needed for smart recompilation. Until now, we only ever invoked
    those predicates when we have just read in the source file,
    and this timestamp was readily available. The code implementing
    the new option needs to store this info for a short time, and
    the module baggage is the obvious place to store it, so add this field
    to the baggage.

compiler/error_spec.m:
    An invocation of the compiler with new option may report errors that
    prevent the construction of interface files for several modules.
    The new code in mercury_compile.m prints the error_specs that have
    contexts in the order of those contexts, but we want to print
    the messages without contexts (which in this case report that
    certain files could not be written or copied) to have a useful
    order too. Make this possible by allowing the invisible pieces
    we use for ordering to specify that order via a string (in this case,
    the name of the file that e.g. could not be written), rather than
    the only previous option, an integer.

compiler/grab_modules.m:
compiler/make.get_module_dep_info.m:
compiler/make.module_dep_file.m:
    Fill in the new field in the module baggage.

compiler/check_module_interface.m:
compiler/handle_options.m:
compiler/make_hlds_error.m:
compiler/parse_module.m:
compiler/prog_foreign_enum.m:
compiler/typecheck_error_util.m:
compiler/typecheck_msgs.m:
compiler/write_deps_file.m:
compiler/write_error_spec.m:
    Conform to the changes above.
2023-10-12 06:50:07 +11:00
Zoltan Somogyi
95ab5899f6 Fix comment rot.
Improve the names of the predicates and function symbols.
2023-09-29 03:54:12 +10:00
Zoltan Somogyi
cdb7fd50c0 Move some code to make.module_dep_file.m.
compiler/make.module_dep_file.m:
compiler/make.get_module_dep_info.m:
    Carve the code for reading the contents of a .module_dep files
    out of its predicate in make.get_module_dep_info.m, to a separate
    predicate, and move that predicate to make.module_dep_file.m,
    which contains the code to parse what is read.

compiler/maybe_error.m:
    Generalize some existing types to make the above possible.
2023-09-22 19:40:16 +10:00
Zoltan Somogyi
20895364e1 Carve make.get_module_dep_info.m out of make.module_dep_file.m.
compiler/make.get_module_dep_info.m:
compiler/make.module_dep_file.m:
    As above. make.module_dep_file now deals only with reading and writing
    .module_dep files, as its name suggests, while make.get_module_dep_info.m,
    which is significantly larger, manages the process of getting
    module_dep_infos, which it can do either by finding .module_dep files,
    or by building them if necessary.

compiler/make.m:
    Include the new module.

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

compiler/make.check_up_to_date.m:
compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.find_local_modules.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
    Conform to the changes above.
2023-09-22 17:09:01 +10:00
Zoltan Somogyi
d3ca1ded9e Make make.module_dep_file.m more readable.
compiler/make.module_dep_file.m:
    Give several predicates more descriptive names.

    Do this partly by avoiding the ambiguous term "dependencies".
    In make.dependencies.m, and in several of the other make.*.m files,
    it means "the things that in a Makefile would be found on the
    right hand side of a rule", but here, it was used to mean
    "the information that goes into a value of type module_dep_info".

    Do this partly by giving predicates names based on what they actually do,
    rather than on the circumstances in which they are invoked.

    Delete a predicate after inlining it at its two call sites, because this
    (with the new purpose-reflecting names of the predicates it invokes)
    makes significantly clearer the task of the predicate containing
    both of those call sites.

    Delete two predicates that were each called exactly once after inlining
    them at their call sites.

    When we find .module_dep files, we parse them the usual Mercury way:
    first by parsing them into terms, and then parsing the terms themselves.
    The two stages of parsing used to be done in two different predicates.
    Fix this.

    Make the code doing the first stage of parsing operate on a string
    containing the whole file, using the new predicate in find_module.m.

    Improve some variable names.

compiler/find_module.m:
    Add search_for_file_returning_dir_and_contents, a new variant of
    the existing search_for_file_returning_dir_and_stream that,
    instead of returning a stream of the found and opened file,
    returns the file's contents as a string. This allows I/O to be done
    in bulk.
2023-09-22 00:44:51 +10:00
Zoltan Somogyi
e1e5480f16 Eliminate calls to io.output_stream in read_modules.m.
compiler/read_modules.m:
    When invoked to read a file specified by file name (as opposed to
    by module name), the code of this module wrote out progress messages
    to the current output stream, as returned by io.output_stream.
    Fix this by consistently requiring the ancestors of the predicates involved
    to pass an explicit stream to write progress messages to.

    The interfaces of some of the exported predicates allowed their callers
    to either pass a progress stream or not; if they didn't, this prevented
    the generation of any progress messages with -v and the generation of
    any statistics with -S. Most callers did specify the progress stream;
    the main parts of the compiler that did not were

    - the code that read the old versions of interface files in order to see
      whether the new version was identical to it, or not, and
    - the intermodule analysis framework.

    This diff requires callers to always pass a progress stream, because
    we *always* want to write out any error messages about nonexistent
    or unreadable files, and we don't want to write these to an implicitly
    specified file. We *could* add a parameter to the affected predicates
    to shut up progress messages and statistics for use at the call sites
    that previously passed us "no" as the maybe progress stream argument,
    but I see no reason why one wouldn't want -v and -S to work as usual
    in these above circumstances. If anyone ever finds such a reason,
    there is a simpler fix anyway: turning off -v and -S in the globals
    passed along next to the progress stream.

compiler/module_cmds.m:
    Stop requiring an error stream and as well as a progress stream
    when touching files. If the two streams were ever different, the
    output would have looked strange, as the error message would NOT follow
    the progress message announcing the operation that failed.

compiler/analysis.m:
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
    Conform to the changes above, mostly by passing along
    an explicit progress stream.
2023-09-15 17:55:14 +10:00
Zoltan Somogyi
fe31a6c82e Write direct to .err files if possible.
compiler/make.build.m:
    If the compiler has not yet written to a module's .err file, then direct
    the output from processing that module directly there. Use the old
    algorithm, which is to direct that output to a temp file, and then
    appending that the contents of the temp file to the .err file later,
    only if this compiler invocation *has* written to the .err file before.
    This should save the cost of a file copy in such cases.

    Change the interface of the predicates that open and close the module error
    stream to make the above possible.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the change in the interface.
2023-09-15 17:13:49 +10:00
Zoltan Somogyi
78e8776b3e Rename the redirect/unredirect predicates.
compiler/make.build.m:
    The redirect/unredirect predicates originally did do what their
    names said, but that hasn't been true for a while. This diff gives
    them names that describe their current functionality, and changes
    them to use a bespoke type for their return value.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes in make.build.m.

    In one place, add an XXX; in another, move an XXX.
2023-09-14 13:11:30 +10:00
Zoltan Somogyi
627847b642 Replace more uses of io.output_stream.
compiler/make.build.m:
    Replace one of the two remaining calls to io.output_stream
    with an explicit stream passed from higher up in the call tree.

compiler/make.dependencies.m:
    Replace many remaining calls to io.output_stream with an explicit stream
    passed from higher up in the call tree, though some of these still get it
    by calling io.output_stream themselves. Fixing these will require changes
    to the same higher order predicate.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_main.m:
    Pass the explicit stream that predicates exported from make.build.m
    and make.dependencies.m now require.
2023-09-14 12:49:30 +10:00
Zoltan Somogyi
18c8053141 Stop using io.output_stream in make.module_dep_file.m. 2023-09-14 07:54:20 +10:00
Zoltan Somogyi
3fa0093aa6 Stop using io.output_stream streams in several modules.
compiler/make.file_names.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Instead of getting streams by calling io.output_stream, get it from
    higher up in the call tree. (There is still one place left in
    make.program_target.m that does this, which may require further changes
    elsewhere before it can be eliminated.)

compiler/make.build.m:
    Add a version of an existing predicate that has its arguments reordered
    to suit the requirements of another higher-order predicate.

compiler/make.module_dep_file.m:
compiler/make.timestamp.m:
    Conform to the changes above.
2023-09-13 21:41:05 +10:00
Zoltan Somogyi
34471810dd Stop current output stream redirects in make.module_dep_file.m.
compiler/make.module_dep_file.m:
    As above. Pass an explicit stream to which to write progress messages,
    instead of writing to the current output stream.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for the module.
2023-09-12 23:40:02 +10:00
Zoltan Somogyi
f70f458f6a Stop using implicit streams in make.build.m.
compiler/make.build.m:
    Require callers to specify an output stream to replace
    a previously-implicit stream.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-streams for make.build.m.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Pass the stream now required by make.build.
2023-09-11 09:51:34 +10:00
Zoltan Somogyi
6ab4bc6be0 Improve readability of make.module_dep_file.m.
compiler/make.module_dep_file.m:
    Rename the main exported predicate, get_dependencies, to
    get_maybe_module_dep_info, since while the latter expresses its purpose
    much more precisely. Rename some of its subcontractor predicates
    in a similar fashion.

    Clarify the structure of a predicate by replacing a seeming three-way
    switch with code that reflects its actual structure: one two-way switch
    nested inside one arm of another two-way switch. Move code needed
    only on some paths to be executed on just that path.

    Update an example.

compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
    Conform to the changes above.
2023-09-07 10:55:25 +10:00
Zoltan Somogyi
56e31f7eaa Stop using implicit streams in make.module_dep_file.m.
compiler/make.module_dep_file.m:
    Replace all I/O done to implicit streams with I/O to explicit streams.

    We cannot yet disable --no-warn-implicit-stream-calls for the module,
    because it still contains code to change the current output stream.

compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/mercury_compile_make_hlds.m:
    Conform to the change in make.module_dep_file.m.
2023-09-07 09:37:59 +10:00
Zoltan Somogyi
9bbd9c7a58 Stop using implicit streams in make.util.m.
compiler/make.util.m:
    Delete the versions of maybe_write_msg and maybe_write_msg_locked
    that wrote to the (implicit) current output stream. The versions
    that write to an explicitly specified stream remain.

    Change the old callers to the deleted predicates to pass an explicit
    stream to the remaining versions. To make this possible, require *their*
    callers to specify an explicit stream.

    Give two predicates less-confusing names.

compiler/Mercury.options:
    Stop specifying -no-warn-implicit-stream-calls for make.util.m.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes in make.util.m. In most places, we do still use
    implicit streams, but moving such uses higher and higher in the call tree
    gets us closer and closer to using only explicit streams.
2023-09-06 13:11:03 +10:00
Zoltan Somogyi
691e5ca0c5 Group extensions by their translation algorithms.
compiler/file_names.m:
    Replace the current groups of extensions, which are based on the
    shared purpose of the files with those extensions, with a smaller
    number of groups, which are based on the algorithm we use to decide
    in what (sub)directories we want to place files with those extensions.
    The old distinctions based on purpose still remain in the naming
    convention for the enum values within each of the new groups.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.file_names.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above.
2023-08-10 02:47:01 +02:00
Zoltan Somogyi
c85e348faa Group all "always in current dir" extensions together.
compiler/file_names.m:
    Replace several groups of extensions that stood for semantically
    different groups of extensions by one group, the "always in the
    current directory" group. The enum type of the new type representing
    the now larger group consists of the enum values from the types
    representing the old, smaller groups. The old boundaries are thus
    no longer expressed in types, but still remain in the naming schemes
    of the enum values.

    Once we have done the same for the six other groups of extensions,
    with each group having its own pattern of where its extensions are put
    under which circumstances, we can replace code that does multiple
    modulename+extension to filename translations with code that does
    one modulename+extension to DIRECTORY PATH translation, and then
    constructs multiple filenames from that, repeating just the
    "extension enum to extension string" part of the old translation
    for each operand. We can do this because unlike the old extension
    categories, the new ones will make clear which groups of extensions
    are guarantee to map to the same directory path, and which have
    no such guarantee.

compiler/compile_target_code.m:
compiler/export.m:
compiler/generate_dep_d_files.m:
compiler/make.build.m:
compiler/make.file_names.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2023-08-09 12:37:31 +02:00
Zoltan Somogyi
5a65105be3 Carve three new modules out of make.util.m.
Each of the new modules, and the new make.util.m, has better cohesion
than the old make.util.m. (For example, the lists of modules they import
don't overlap all that much.)

compiler/make.file_names.m:
compiler/make.hash.m:
compiler/make.timestamp.m:
    Carve these three modules out of make.util.m

    - make.file_names.m does filename translations.
    - make.hash.m does hashing.
    - make.hash.m looks up and compares timestamps.

compiler/make.m:
    Include the new modules.

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

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.util.m:
    Update module imports.
2023-08-07 13:13:17 +02:00
Zoltan Somogyi
19bf43f85f Print errors returned by read_module.m. 2023-08-06 18:14:48 +02:00
Zoltan Somogyi
544a519a52 Make --output-compiler-error-lines a maybe_int option.
compiler/options.m:
doc/user_guide.texi:
    As above. --no-output-compiler-error-lines specifies that all the lines
    of the .err file should be written out.

compiler/make.build.m:
    Update the code copying the first N lines of a .err file to the current
    output stream to handle the newly-possible absence of a limit, as well
    as the existing situation where there is a limit.

compiler/make.module_dep_file.m:
    Print all of a file, not just 10000 lines, in the presence of a fatal
    error.
2023-08-05 18:58:54 +02:00
Zoltan Somogyi
b1c0b42a34 Generate the default option_table just once.
compiler/handle_options.m:
    The main predicate of this module, handle_given_options, used
    to generate the default option table every time it was called,
    and its callers couldn't prevent this by supplying it with that
    default option table. Fix this by adding an argument for that info.

compiler/mercury_compile_main.m:
    Create the default option table at the start of real_main_after_expansion.
    Pass it to later invocations of handle_given_options.

compiler/globals.m:
    Include the default option table, as well as the processed option table
    (created by handle_given_options from the default table) in the globals
    structure. This is so that the parts of the make package that want to
    build a new globals structure "from scratch" don't have to redo
    the part of the work that is independent of the set of actually specified
    options.

compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Conform to the changes above.

    In some cases, fix misleading variable names.

    In make.track_flags.m, add an XXX outlining a possibly better approach
    to hashing options for tracking.

library/Mmakefile:
    Stop copying a part of getopt_io.m to geteopt.m, because it is
    confusing as hell after an automatic edit.

library/getopt.m:
    Expect the effect of the change to library/Mmakefile.
2023-07-10 19:40:56 +02:00
Zoltan Somogyi
3a928fe1ea Start using the string builder in parse_tree_out*.m
compiler/parse_tree_out_sym_name.m:
    As a test, implement the output of sym_names, one of the smallest
    nonatomic parse tree components, using string builders.

    Change the name of the write_X version of the operation
    from just write_sym_name to write_escaped_sym_name,
    since every component of the sym_name is in fact escaped.

    Change the name of the X_to_string version of the operation
    from sym_name_to_escaped_string to escaped_sym_name_to_string,
    to make the X identical to the write_X version. Change its implementation
    to use string builders.

    Implement both write_escaped_sym_name and escaped_sym_name_to_string
    in terms of the new predicate format_escaped_sym_name.

    Add an XXX about a potential problem.

compiler/parse_tree_out_info.m:
    Since format_escaped_sym_name calls term_io.format_escaped_string,
    it needs to comply with its typeclass constraint. This requires
    making the typeclass in the constraint on format_escaped_sym_name,
    the "output" typeclass in parse_tree_out_info.m, a superclass of
    stream.writer.

    However, giving parse_tree_out_info.m access to the stream.writer class
    also gives it access to the stream.output class, since they are both
    defined in library/stream.m. Avoiding a flood of ambiguity warnings
    about output being either stream.output or parse_tree_out_info.output
    requires either fully module qualifying all occurrences of the output
    typeclass name, or renaming one of the typeclasses. The obvious one
    to rename is parse_tree_out_info.output, so this diff renames it to
    pt_output (pt being short for "parse tree").

compiler/higher_order.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/hlds_out_type_table.m:
compiler/hlds_out_util.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_cons_id.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_misc.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_pred_decl.m:
compiler/parse_tree_out_term.m:
compiler/parse_tree_out_type.m:
compiler/recompilation.check.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2023-07-08 14:42:26 +02:00
Zoltan Somogyi
d5c54ce697 Take ext_src out of the ext type.
compiler/file_names.m:
    Take ext_src out of the ext type, because this allows us to delete
    the I/O state pair of arguments out of every file translation predicate
    other than module_name_to_source_file_name and the ones that create
    directories.

compiler/file_kind.m:
    Delete the ext output argument of file_kind_to_extension, because
    we can't return ext_src for fk_src anymore.

compiler/write_deps_file.m:
    Delete a test for ext_src which could never succeed, because the
    predicate in question is never called with ext_src.

    Undo an accidental change from the diff that introduced
    module_name_to_lib_file_name_create_dirs.

    Conform to the changes above.

compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mlds_to_c_file.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-07-06 16:14:35 +02:00
Zoltan Somogyi
89979d681a Replace Mkdir parameters with predicate versions.
compiler/file_names.m:
    Split module_name_to_file_name into three versions.

    - One corresponds to the old predicate's operation with do_not_create_dirs,
    - one corresponds to the old predicate's operation with do_create_dirs, and
    - one just returns the directory path, and lets the caller make those
      directories if it wants to, using procedures that we now export.

    Do the same for module_name_to_lib_file_name.

    Do not do the same for fact_table_file_name, which has too few callers
    to make it worthwhile.

    The point is that the versions that do not create any dirs should NOT
    need to take I/O state pairs as arguments, once we take ext_src
    out of the ext type.

compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.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/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Update calls to the affected predicates.

    In some places, add XXXs about seemingly-strange choices about
    what calls create directories and which don't.
2023-07-06 12:36:14 +02:00
Zoltan Somogyi
6517982c87 s/newext/ext/g and s/NewExt/Ext/g. 2023-07-04 22:32:38 +02:00
Zoltan Somogyi
0b60f07c46 Cut over to the new code in file_names.m.
compiler/file_names.m:
    Delete the old code for doing filename translations, and use
    just the new code.

    Delete all the code that was needed only for comparing the old and
    new code.

    Delete the newext_other extension category, since it was also needed
    only for that purpose. Delete all the code that supported it.

    Switch the infrastructure for recording the demand for translations
    to work with the new code.

compiler/analysis.file.m:
    Delete functions that returned old-style extensions, which are
    not useful anymore. The new-style extensions, by identifying
    extensions via enums rather than strings, serve the purpose
    for which these functions were created.

compiler/mercury_compile_main.m:
    Move the code to call to write out the translation record
    from just after a call to real_main_after_expansion to the
    end of real_main_after_expansion. The reason is that the
    predicate being called now needs access to a globals structure,
    real_main_after_expansion has access to a globals structure,
    but its caller does not.

    Don't try to test the equivalence of the old and new algorithms
    for file name translation, since that test code has been deleted.

compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.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/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes in file_names.m.
2023-07-04 18:22:42 +02:00
Zoltan Somogyi
9eb003458b Add verbose_make_N_part_msg predicates.
compiler/make.util.m:
    Add verbose_make_N_part_msg predicates, and the more general
    option_set_make_N_part_msg predicates, to allow simpler code
    to construct progress and informational messages.

    Pass to debug_make_msg a message *generator*, instead of a predicate
    that *writes out* a message. Make debug_make_msg return the message
    (if debug_make is enabled) to be written out (hopefully) to an explicitly
    specified stream.

compiler/make.dependencies.m:
    Rename the dependency_status predicate to get_dependency_status.
    Make it return the original dependency_file, and the filename it
    corresponds to, alongside the status, because this is the simplest
    way to avoid requiring its callers to reconstruct that information
    after their calls to get_dependency_status.

    Change the signature of check_dependency_timestamps to expect
    the new output of get_dependency_status.

    Replace code to write out debugging messages with code to just return
    them as a string. Move one of these predicates to just after its caller.

    Give some predicates more descriptive names.

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

    In make.program_target.m, add XXXs about progress messages
    that end with a period, unlike all the other progress messages.
2023-06-28 15:13:43 +02:00
Zoltan Somogyi
dbcb4672d3 Create progress/error msgs separately from writing them.
compiler/make.util.m:
    The predicates that handled progress messages in this module

    - tested whether the progress message was needed, and if yes,
    - first constructed the message,
    - and then printed it.

    The predicates that handled error messages were similar,
    but error messages are always needed.

    In most cases, the printing was done to the current *implicit* output
    stream.

    Code calling these predicates won't get warnings about implicit stream
    calls unless every predicate has both implicit and explicit stream
    variants.

    Make all these predicates do just the first two of the above jobs,
    and return a string that may be empty or not. Then require callers
    to call one of four new predicates to print out the resulting string
    if it is not empty. The four are distinguished along two axes:
    implicit vs explicit stream, and locked/unlocked stdout.

    Add XXXs about the problems of even this updated approach,
    including the one with locking stdout when the output stream,
    whether implicitly or explicitly specified, is *not* stdout.

    Make the names of all the predicates affected by the above change
    end in "_msg". Change some of the names to be more descriptive.
    Delete one predicate whose code was identical to that of another.

compiler/make.build.m:
    Export the lock/unlock stdout predicates for use by the new predicates
    in make.util.m.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
    Conform to the changes above.

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

    Give a predicate a less misleading name.

    Add an XXX in a place.
2023-06-28 01:27:27 +02:00
Zoltan Somogyi
056fe37a5b Make make_info an abstract type.
This should allow profiling runs to collect information about the
number of accesses to each field.

compiler/make.make_info.m:
    Move the definition of the make_info type from the interface section
    to the implementation section. Add getter functions for all its fields,
    setter predicates for its writeable fields, and an initialization
    function.

    Move all the readonly fields to the start of the structure.
    Put related fields next to each other.

compiler/make.top_level.m:
    Replace the explicit construction of the initial make_info value
    with a call to its initialization function.

compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.deps_set.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
    Replace all accesses to the fields of make_info with calls to the
    getter functions or the setter predicates.
2023-06-24 09:34:15 +02:00
Zoltan Somogyi
4f63a92085 Minor improvements in make.*.m.
compiler/make.dependencies.m:
    Delete a comment about deleting a field from the make_info, and passing
    its info via separate arguments. An experiment showed that it would
    complicate much more code than it would simplify.

compiler/make.make_info.m:
    Document why that field of the make_info should stay there.

    Fix some comment rot.

    Add some XXXs about unclear comments.

    Give a type a more meaningful name.

compiler/make.module_dep_file.m:
    Use that new type name.

compiler/make.deps_set.m:
    Improve a variable name.
2023-06-23 22:08:44 +02:00
Zoltan Somogyi
edeb58bc16 Start using the new code in file_names.m.
compiler/file_names.m:
    Change the argument vectors of the predicates that compute filenames
    by taking *two* arguments to specify the extension: adding an argument
    value of the "newext" type right after the old "ext" type. To make this
    possible, export the newext type.

    By default, use the new argument to do every filename computation twice,
    with the old and new algorithms, throwing an exception if their results
    differ. (There is no easy way to test whether the "make-any-needed-dirs"
    part was done the same way, but this is reasonably easy to check
    visually in the code.)

    In case an exception does get thrown, this can be suppressed (hopefully
    after the exception being reported) by setting the environment variable
    "NO_EXT_CHECKS" to any value.

    Add representations of "get the value of this extension from this option"
    style extensions to the newext type, for each of the options that the
    compiler uses this way. The one exception is java_object_file_extension,
    which was used in this way, but which had no code handling it in
    file_names.m.

    Add a representation of ".$(EXT_FOR_PIC_OBJECTS)" as a value
    to the newext type.

    Shorten some function symbol names in the newext type and its components,
    to make them easier to fit without excessive line lengths in the modules
    listed below.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.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/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Pass extensions as ext/newext pairs, not just as exts.

    To make this possible, change functions and predicates that returned
    just old-style extensions to return new-style extensions as well.

compiler/make.program_target.m:
    Pass extensions as ext/newext pairs, not just as exts.

    Add an XXX about java_object_file_extension for Julien, since he added
    this option (in 2001 :-().
2023-06-07 18:46:48 +02:00
Zoltan Somogyi
083d376e65 Eliminate some redundant target->filename conversions.
compiler/make.util.m:
    Many operations in this module that operate on filenames did not take
    those filenames as arguments; instead, they took an argument such as
    a target_file from which they *computed* the filename. This meant that
    any predicate that called more than one of these operations implicitly
    computed the filename more than once. This could be a problem, because

    - there are several predicates one can use to compute the filename, but
    - there is no guarantee that different operations use the same predicate.

    As a first step in fixing this, change the predicates that print
    filenames in progress or error messages to take those filenames
    as parameters. Delete one of them, target_file_error, because
    after this change, it would have become identical to the existing
    file_error predicate.

compiler/make.module_target.m:
    Require the callers of record_made_target to supply the filename
    as well as the target_file from which it is derived.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
    Compute the filename before calling the updated operations in make.util.m
    and/or make.module_target.m.

    Add "XXX MAKE_STREAM" to places in the code that operate on either
    implicit or badly-chosed explicit streams.
2023-06-01 18:17:40 +02:00
Zoltan Somogyi
9adcbd9840 Improve infrastructure for file name translations.
compiler/file_names.m:
    Document the meaning of the maybe_create_dirs and maybe_search types.

    Delete long-obsolete references to .il files.

compiler/make.util.m:
    Rename make_remove_target_file to remove_make_target_file, since this
    predicate removes target files in Makefiles, and does not "make" anything.
    Rename several other predicates in a similar manner, for the same reason.

    Add an extra argument to get_file_name and some related predicates
    that will allow future conditionally-enabled trace goals in the compiler
    to track where the requests for file name translations come from.

compiler/write_deps_file.m:
    Factor out some code.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.

tools/file_name_translation_stats:
    Allow for large numbers of file name translations.
2023-05-31 10:14:31 +02: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
b6178ef723 Delete prog_out.m, moving its code to other modules.
compiler/parse_tree_out_cons_id.m:
    Move the predicates and functions in prog_out.m that deal with cons_ids
    to this module.

compiler/parse_tree_out_sym_name.m:
    Move the predicates and functions in prog_out.m that deal with sym_names
    and similar entities to this module.

compiler/parse_tree_out_type.m:
    Move the predicates and functions in prog_out.m that deal with types
    to this module.

compiler/parse_tree_out_misc.m:
    Move the predicates and functions in prog_out.m that deal with simple
    types to this module.

    Delete mercury_output_det and mercury_format_det, replacing all their
    uses with calls to mercury_det_to_string.

compiler/prog_out.m:
    Delete this module.

compiler/parse_tree.m:
    Delete prog_out from the parse_tree package.

compiler/Mercury.options:
compiler/notes/compiler_design.html:
    Delete references to prog_out.m.

compiler/*.m:
    Update imports and any explicit module qualifications to account
    for the moved code.

tools/filter_sort_imports:
    Automatically filter out any repeated imports. This can help with
    changes like this that redistribute the contents of one module to other
    modules. In this case, after a global replacement of prog_out's import
    with the import of parse_tree_out_misc, this updated script could
    remove this changed import from modules that already imported
    parse_tree_out_misc.
2023-04-09 16:23:13 +10:00
Zoltan Somogyi
e2a8a8cbfa Break up mercury_to_mercury.m.
compiler/mercury_to_mercury.m:
    Delete this module, and replace it with ...

compiler/parse_tree_out_cons_id.m:
compiler/parse_tree_out_sym_name.m:
compiler/parse_tree_out_type.m:
compiler/parse_tree_out_misc.m:
    ... these four modules. The first three write out the entities
    in their names: cons_ids, sym_names, and types. The fourth contains
    the rest of the old mercury_to_mercury.m, plus a few predicates
    moved there from prog_out.m that deal with indentation.

compiler/parse_tree.m:
    Include the four new modules, and stop including the deleted module.

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

compiler/prog_out.m:
    Delete the code moved to parse_tree_out_misc.m.

compiler/*.m:
    Adjust the imports as needed. Most modules need only one, maybe two
    of mercury_to_mercury's four successor modules.
2023-04-06 15:32:48 +10:00
Peter Wang
1bc5cadf25 Fix writing fact table file names in .module_dep files.
Commit 5f50259d16 inadvertently wrote out
the list of fact table file names in a .module_dep file without quoting,
so the .module_dep parser would fail to read it back.

compiler/make.module_dep_file.m:
    Write fact table file names in .module_dep files as quoted strings.

tests/mmc_make/Mmakefile:
tests/mmc_make/factt.m:
tests/mmc_make/factt_examples:
    Add a test case.
2022-12-05 17:29:03 +11:00
Zoltan Somogyi
6f82724091 Pass streams explicitly at the top levels.
compiler/mercury_compile_main.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
    Pass progress and error streams explicitly in these top modules
    of the compiler. Use "XXX STREAM" to mark places where we could switch
    from using stderr for both the progress and error streams to using
    module-specific files as the progress and/or error streams.

compiler/passes_aux.m:
    Add a "maybe_" prefix to the names of the predicates that print progress
    messages at the appropriate verbosity levels, as their printing of those
    messages is conditional.

    Provide versions of those predicates that take explicitly specified
    streams to write to, and mark the versions that write to the current
    output stream as obsolete.

    The predicate that wrote progress messages for procedures
    used to have two versions, one taking a pred_proc_id, and one taking
    a pred_id/proc_id pair. Delete the latter, because the arity difference
    that differentiated the two versions is now needed for the difference
    between supplying and not supplying an explicit stream.

compiler/file_util.m:
compiler/hlds_error_util.m:
compiler/write_error_spec.m:
    Delete several predicates that wrote to the current output stream,
    since all their callers now use the versions that specify an explicit
    output stream.

compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/deps_map.m:
compiler/direct_arg_in_out.m:
compiler/grab_modules.m:
compiler/handle_options.m:
compiler/hhf.m:
compiler/inlining.m:
compiler/make.module_dep_file.m:
compiler/ml_proc_gen.m:
compiler/ml_top_gen.m:
compiler/mode_constraints.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/purity.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/saved_vars.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/stack_opt.m:
compiler/switch_detection.m:
compiler/typecheck.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/write_module_interface_files.m:
    Get these modules to take an explicitly specified stream to which
    to write progress messages when they are invoked from mercury_compile_*.m.

    For predicates in these modules that can be invoked both directly
    by mercury_compile_*.m *and* by other modules, the latter effectively
    as a subcontractor, make them take a maybe(stream), with the intention
    being that all the other modules that use the predicate as a subcontractor
    would pass a "no". This avoids the need to pass progress streams
    down to the internals of other passes, and also avoids overwhelming
    the user invoking the compiler with unnecessary details.

    As above, and also delete a progress message that shouldn't be needed
    anymore.

    Move a test of option value compatibility from
    mercury_compile_middle_passes.m to handle_options.m, where it belongs.

compiler/float_regs.m:
    Write a debug message to the debug stream.

compiler/pd_info.m:
    Include the progress stream in the pd_info structure, because this is
    the simplest way to ensure that all parts of the partial deduction pass
    have access to it.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when the make package is converted to consistently
    use explicit streams.

compiler/bytecode_gen.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when these modules start being maintained again.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for mercury_compile_*.m,
    since this diff makes that unnecessary.

    Start specifying --no-warn-implicit-stream-calls for some modules that
    are not currently being actively maintained, because the addition of
    progress-reporting predicates that take explicitly specified streams
    would otherwise cause the generation of such warnings for them.
2022-11-01 11:33:41 +11:00
Zoltan Somogyi
307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00
Zoltan Somogyi
752bb66f5b Carve four modules out of term.m.
Most modules that imported the old term.m need only a small subset
of its functionality. After this diff, most modules that used to import
term.m will need to import just one more module, and will import many
fewer predicates and functions in total.

library/term_int.m:
    A new module carved out of term.m containing the predicates
    that recognize terms containing integers, and the functions
    that construct such terms.

    While this job has *some* similarity to the job of the existing
    term_conversion.m module, most modules in the compiler use only one
    of those two modules, so merging them would not be a good idea.

library/term_subst.m:
    A new module carved out of term.m containing code to do
    substitutions and renames of various kinds.

    Rename the occurs predicate as var_occurs_in_subst_term,
    and occurs_list as var_occurs_in_subst_terms, since the latter
    are much more descriptive. Change the argument order to match
    the new names (var, subst, term/terms), as the old one did not
    even have the term/terms and the substitution next to each other,
    even though neither makes sense without the other.

library/term_unify.m:
    A new module carved out of term.m containing code to do unifications.

    Give all the predicates more meaningful names:

    unify_term ->                   unify_terms
    unify_term_list ->              unify_term_lists
    unify_term_dont_bind ->         unify_terms_dont_bind
    unify_term_list_dont_bind ->    unify_term_lists_dont_bind
    list_subsumes ->                first_term_list_subsumes_second

library/term_vars.m:
    A new module carved out of term.m containing code that find variables
    in terms.

    Give all the predicates more meaningful names:

    vars ->                         vars_in_term
    vars_2 ->                       vars_in_term_acc
    vars_list ->                    vars_in_terms
    contains_var ->                 term_contains_var
    contains_var_list ->            terms_contain_var

    Don't move the function version of vars_2 to term_vars.m, effectively
    deleting it, since operations that update an accumulator are awkward
    for functions.

library/term.m:
    Keep the moved predicates and functions in term.m, but

    - change their implementation to simply call the moved copy, and
    - obsolete the original in favor of the moved copy.

    Eventually, after either the next release or the release after the next,
    we should delete the obsoleted predicates and functions.

library/MODULES_DOC:
library/library.m:
    Add the new modules as documented parts of the standard library.

browser/interactive_query.m:
compiler/analysis.file.m:
compiler/det_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/parse_class.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_sym_name.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_defn.m:
compiler/parse_util.m:
compiler/prog_ctgc.m:
compiler/prog_util.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/typecheck.m:
library/io.m:
library/term_conversion.m:
library/varset.m:
    Conform to the changes above.
2022-08-21 01:01:21 +10:00
Zoltan Somogyi
4ea9695030 Move predicates that find modules' files to find_module.m.
compiler/file_util.m:
compiler/find_module.m:
    As above. Users may specify a module by its module name or
    by its file name, but having the predicates that search
    for a module's source, interface or optimization files by file name
    be in file_util.m while similar predicates that search by module name
    be in find_module.m is suboptimal, since it prevents factoring out
    any commonalities, and makes it harder to spot things that *should*
    be common but arent't.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/make.module_dep_file.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mmc_analysis.m:
compiler/options_file.m:
compiler/parse_module.m:
    Update module imports.
2022-05-08 21:33:20 +10:00
Zoltan Somogyi
7b6bace9ec Don't return dummy parse_trees for missing files.
The predicates that read a Mercury source, interface or optimization file
used to return four things:

- the name of the file (for callers who specified only a module name),
- the timestamp, if requested and available,
- a parse tree, and
- a representation of any errors (sets of error categories, and error_specs).

However, these four things were not independent. Some combinations of their
values were not allowed, but (a) there was no documentation of what these
combinations were, and (b) code that processed these four things had to be
prepared to handle illegal as well as legal combinations.

This diff makes these predicates return only one result, which contains

- all four of the above things, when the file could be opened, but
- only the file name and a representation of the error if the file
  could not be opened,
- only the file name and a representation of *no* errors, if the caller
  asked the predicate to read the file only if its timestamp did not match
  a specified value, and it does match that value.

We use a somewhat modified version of an existing type, have_read_module,
for this. It is modified both by including information that its users
now need that they did not need before, and shortening the names of its
function symbols, which now occur in many more places than before.

compiler/read_modules.m:
    Make the change to the output arguments described above.

    Making this change requires having the affected predicates deal with
    the case where we either cannot find or cannot open the relevant file.
    (The two are effectively the same thing in this module, since we search
    by attempting to open.) Passing that task off to parse_modules.m
    was always inelegant.

    Simplify the have_read_module_map type by making the key always
    be a module_name. We deleted the only use of have_read_module_maps
    with another kind of key a while ago.

    Delete some no-longer-needed predicates.

compiler/parse_module.m:
    Delete the code dealing with the absence of a file stream to parse.

    Replace code that used to construct dummy parse trees with code
    that simply returns *no* parse tree if the file could be opened
    but could not be read, or if its timestamp indicated that reading it
    would have been redundant.

    Delete some utility predicates moved to parse_error.m, so that
    read_modules.m could also use them.

    Fix comment rot.

compiler/parse_error.m:
    Add some utility predicates for use by read_modules.m and parse_module.m.

compiler/deps_map.m:
    Conform to the changes above.

    Document the dubious effects of an old design decision.

    Fix a misleading predicate name.

    Fix comment rot.

compiler/grab_modules.m:
    Conform to the changes above.

    Some predicates used to return parse trees that could be dummies.
    Change them to return just the parts of the parse tree that the
    caller was interested in, which was usually a tiny part, and which
    can be constructed trivially even when we don't have a parse tree.

    Delete an unneeded type.

compiler/recompilation.check.m:
    Conform to the changes above.

    Represent the operations we need to test version numbers in interface files
    as a typeclass, and rewrite the checking operation in terms of that
    typeclass, with one instance for each kind of interface file.

    Move some repeated code into a predicate.

    Shorten some long names.

compiler/mercury_compile_main.m:
    Conform to the changes above.

    Break up a large predicate.

compiler/generate_dep_d_files.m:
compiler/make.module_dep_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

compiler/prog_item.m:
    Delete the parse_tree_some_int type. The change in recompilation.check.m,
    deleted its last few uses there, and allowed the deletion of the last
    uses in read_modules.m.

tests/recompilation/two_module_debug:
    Extend this script to help deal with problems in all stages of the
    execution of a test case, since that was required while debugging
    this diff.

    Document which parts of this script correspond to which parts of
    two_module_test.

tests/recompilation/test_functions:
tests/recompilation/two_module_test:
    Simplify the logic of the main test function, by testing a condition
    once instead of three times.

    Specify whether a recompilation test is expected to succeed or fail
    directly, using alternatives that model a bespoke type, instead
    of alternatives that mimic a boolean answer to a question, which
    does not help readers who don't remember the question.

    Always put shell variable names in braces.

    Note a problem that makes one of the shell functions ineffective.

tests/recompilation/Mmakefile:
    Tell two_module_test what to do using its updated interface.
2022-04-30 14:37:22 +10:00