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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
... and bundle sets of error kinds and their associated lists of error_specs
into a single structure.
compiler/parse_error.m:
Use separate types to represent fatal errors and nonfatal errors,
because those two kinds of errors are often treated differently.
Change the read_module_errors type, which used to be just a set of errors,
to being a set of fatal errors, a set of nonfatal errors, the error
message for each, and error messages for warnings. This preserves
distinctions that we should be able to use in the future to improve
error handling.
Provide utility routines for operating on this now-structured type.
compiler/parse_types.m:
Change the definition of the item_or_marker type slighly to preserve
distinctions that the read_module_errors type now cares about.
compiler/parse_module.m:
Thread the new read_module_errors structure through the predicates
that parse source, interface and optimization files.
Treat the failure of reading the contents of a file as a fatal error.
Previously, we treated it as a nonfatal error.
Delete some fields from types when those field were always set to the
same value, and therefore contained no useful information.
compiler/module_baggage.m:
Switch to using the new read_module_errors structure in module baggage.
compiler/grab_modules.m:
Conform to the changes above.
Use a bespoke type to represent the absence/presence of errors
when reading in optimization files.
compiler/mercury_compile_make_hlds.m:
Conform to the changes above.
Delete a call to pre_hlds_write_out_errors that duplicates
another call a few lines above.
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_type_defn.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/module_baggage.m:
This reflects the changes to this module over the last year.
compiler/parse_tree.m:
Change the module name in the include_module declaration.
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_dep_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Change the module name in import_module declarations.
compiler/notes/compiler_design.html:
Change the module name in the module description.
compiler/make.module_dep_file.m:
When generating an error message about being unable to compute
dependencies due to being unable to open the file supposedly containing
a module, say whether that module was included or imported, instead of
just saying "module abc is imported or included by module def".
To make this possible, ...
compiler/make.make_info.m:
... change the slot in the make_info that holds the name of the
importing or including module ("def" in the above example) to say
whether it is importing or including the module in question ("abc"
in the example), and ...
compiler/make.dependencies.m:
... have this module fill in that slot.
library/io.file.m:
library/io.m:
Move two sections of io.m, the "file handling predicates" section
and the "handling temporary files" section to the new submodule io.file.m.
Leave behind in io.m "forwarding predicates", predicates that do nothing
except call the moved predicates in io.file.m, to provide backward
compatibility. But do mark the forwarding predicates as obsolete,
to tell people to update their (at their leisure, since the obsoleteness
warning can be turned off).
Also leave behind in io.m the definitions of the two types used
by some parameters of some of the moved predicates. Document the reason
why this is done.
library/MODULES_DOC:
List the new module among the documented modules.
NEWS:
Announce the changes.
browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
Call the file operation predicates directly in io.file.m, not indirectly
through io.m.
In two modules, add a #include of fcntl.h in C code. These modules contain
C code that needs this #include, but until now, they got it via a copy
in an automatically generated C header file of a foreign_decl pragma
in io.m that contained that #include. This diff moves that foreign_decl
to io.file.m, removing that crutch.
tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
Call the file operation predicates directly in io.file.m, not indirectly
through io.m.
compiler/module_imports.m:
Introduce the type burdened_module, as a version of burdened_aug_comp_unit
that contains only the parse_tree_module_src part of an augmented
compilation unit (i.e. the part *before* any augmentation).
Make some predicates operate on parse_tree_module_srcs instead of
aug_comp_units.
compiler/deps_map.m:
compiler/module_dep_info.m:
Replace burdened_aug_comp_units with burdened_modules in dependency maps
and module_dep_infos respectively. This works because in both cases,
we only ever use the parse_tree_module_src part of the aug_comp_units,
and the presence of the rest of the aug_comp_unit is just a maintenance
burden. (The use of burdened_aug_comp_units was a holdover from
ancient code that used module_and_imports structures, while they existed.)
The burdened_aug_comp_units we used to put into those data structures
always consisted of a parse_tree_module_src *without* any augmentation.
In deps_map.m, simplify some code.
compiler/write_deps_file.m:
This module gets dependency information from two sources: full,
actually-filled-out aug_comp_units from mercury_compile_main.m,
and from deps_maps. In the latter case, turn the burdened_modules
into burdened_aug_comp_units just before entering code that also handles
actually-filled-out aug_comp_units.
Update some old documentation.
compiler/make.module_dep_file.m:
Delete code that used to actively strip away any preexisting augmentation
from burdened_aug_comp_units, since burdened_modules have nothing to strip.
Conform to the changes above.
compiler/mercury_compile_main.m:
Pass a burdened_module, instead of a burdened_aug_comp_unit,
to the predicate in make.module_dep_file.m that used to strip away
all the augmentation from the burdened_aug_comp_unit.
compiler/generate_dep_d_files.m:
Conform to the changes above.
compiler/module_dep_info.m:
As above. The only change is added documentation.
compiler/parse_tree.m:
Include the new module in the parse_tree package.
compiler/notes/compiler_design.html:
Document the new module, and update the documentation of module_imports.m.
compiler/module_imports.m:
Delete the moved code, put the main data structure at the top,
and add some documentation for it.
compiler/compile_target_code.m:
compiler/generate_dep_d_files.m:
compiler/make.dependencies.m:
compiler/make.make_info.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/module_deps_graph.m:
Import module_dep_info.m, usually instead of module_imports.m,
sometimes beside module_imports.m.
compiler/options_file.m:
Change the interface of three lookup predicates to return
either the information they are intended to look up, or a list of
error_specs, but not both. The old code would have made sense
if some error_specs generated during the lookup could be warnings,
but they are always errors.
compiler/make.build.m:
Do not make room for warnings in make build's setup, because
(a) the code that filled in that slot with info from options_file.m
could never put any warnings in there, and (b) most users of that
data structure ignored that slot anyway.
Don't take parameters that are unneeded after this change.
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:
Conform to the changes above.
compiler/maybe_error.m:
Add a utility predicate.
compiler/read_modules.m:
When reading in Mercury source files, interface files or optimization
files, we optionally generate progress messages of the form
% Reading module xyz... done.
But the form of these messages has not been consistent, so that
when reading .opt files, we got messages of the form
% Reading xyz.opt...
% Done.
And we sometimes got messages such as
% Reading .int file for module xyz.int... done.
This is mostly because responsibility for constructing these messages
has been dispersed; different parts of it were generated in different
places, and sometimes when one place switches to a new scheme, not all
the corresponding places where updated accordingly.
This diff changes that by constructing these messages in two predicates
(output_read_msg and output_read_done_msg) in this module, leaving to
callers only a choice between a set of four message forms.
To make this possible, move the read_module_{plain,trans}_opt predicates
here from grab_modules.m. Their equivalents for reading Mercury source
files and interface files were here already, so here is where they belong.
Add several "XXX CLEANUP" markers for future changes.
compiler/parse_module.m:
Do not expect callers to compute the filenames containing .opt
and .trans_opt files, since the code here already does that.
compiler/grab_modules.m:
Delete the predicates moved to read_modules.m (under new names, to fit in
with the predicates already there).
Delete some obsolete comments.
Fix some old variable names.
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
Over time, we have almost completely switched over to using error_specs,
using their severity (if not yet printed out) and their effect on the
exit status (if already printed out) to represent the presence of errors,
leaving only a few places that either updated or paid attention to the
num_error field in the module_info. This diff completes that process.
compiler/hlds_module.m:
Delete the num_errors field in the module_info, and the predicates
that operate on it.
compiler/hlds_error_util.m:
Delete module_info arguments whose only purpose was to update the
now-delete field.
compiler/error_util.m:
Delete the old write_error_spec predicates that updated a count of warnings
and a count of errors.
Rename the write_error_spec_ignore predicates, which ignored those counts,
by deleting the "_ignore" from their names. This makes them take the
place of the deleted predicates.
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/handle_options.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_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/mode_info.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/pred_table.m:
compiler/recompilation.check.m:
compiler/typecheck.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/make.make_info.m:
Carve these three modules out of make.m.
make.top_level.m contains the top level of the mmc --make algorithm.
make.track_flags.m contains code for keeping track of which options
were used to compile which modules.
make.make_info.m defines the make_info structure used by all the
submodules of make.m, as well as a few other utility types.
compiler/notes/compiler_design.html:
Document the new modules.
compiler/make.m:
Delete the code that has been moved to the new modules, leaving
make.m as purely a package.
Include make.build.m in the interface, so we can delete the forwarding
predicate we used to have here for use by mercury_compile_main.m.
compiler/Mercury.options:
Make make.top_level.m and make.track_flags inherit make.m's old
-no-warn-implicit-stream-calls option.
compiler/file_names.m:
Move a utility function about extensions here from make.m.
This also allows the removal of an undesirable module import of make.m
in write_deps_file.m.
compiler/make.build.m:
Move a type here from make.m, since it is needed to allow
mercury_compile_main.m call this module directly (i.e. not through
a forwarding predicate in make.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.util.m:
compiler/mercury_compile_main.m:
compiler/options_file.m:
compiler/write_deps_file.m:
Conform to the changes above. This mostly means having each module make.X
actually import the modules it uses, instead of relying on make.m
importing them, and getting those imports via make.int0.
In a few cases, it means having each module make.X NOT import the modules
it does NOT use, since after the "package-ification" of make.m,
we now get warnings about these imports being unused.
compiler/make.module_dep_file.m:
Judge whether calls to write_short_interface_file_int3 succeeded
by an explicit maybe_succeeded value they now return, instead of
checking the exit status in the I/O state.
compiler/module_cmds.m:
compiler/parse_tree_out.m:
compiler/write_module_interface_files.m:
Make operations on files return a maybe_succeeded argument to indicate
success vs failure.
compiler/make.module_target.m:
compiler/mlds_to_c_file.m:
Take the new maybe_succeeded arguments in calls into account
when computing whether an action succeeded.
compiler/analysis.m:
compiler/export.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/recompilation.check.m:
Ignore the maybe_succeeded results returned by calls, for now.
In export.m, switch from /* */ to // syntax for the C comments we write.
compiler/module_imports.m:
As above. One was unused. Inline the other in its two call sites.
One is here, while the other is ...
compiler/make.module_dep_file.m:
... here.
compiler/make.build.m:
Delete build_module_with_options after inlining it at all its call sites.
The resulting code is easier to understand, and should be easier
to modify.
Transfer its documentation, suitably modified, to its replacement.
compiler/make.module_dep_file.m:
Inline build_module_with_options at its call site.
compiler/process_util.m:
Replace build_with_check_for_interrupt with setup_checking_for_interrupt
and teardown_checking_for_interrupt, two new predicates whose code is
respectively the part of build_with_check_for_interrupt before and after
the main higher order call. This makes the code at the former call sites
significantly easier to read, especially the ones which had higher order
calls inside higher order calls inside higher order calls.
Move a type that process_util.m does not need anymore to
make.program_target.m.
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
Conform to the changes above.
compiler/module_imports.m:
Delete the module_and_imports type, and replace its uses with
aug_compilation_units.
The structure of module_and_imports used to be private, but the
structure of aug_compilation_units is public. Delete the getter/setter
predicates on module_and_imports structures that can now be done
using field names on aug_compilation_units. Delete, along with this,
the infrastructure for keeping track of which module_and_imports fields
are ever accessed. It has served its purpose, but it won't be needed
anymore.
Change types that used to include module_and_imports to include
aug_compilation_units instead.
Rename any types, predicates and functions that used to contain
the "module_and_imports" string in their name.
compiler/prog_item.m:
Move the version number map to be the last field of aug_compilation_units,
as it used to be in module_and_imports structures, since this fits better.
compiler/get_dependencies.m:
Make the name of a predicate more reflective of the type it returns.
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/equiv_type.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_separate_items.m:
compiler/mercury_compile_main.m:
compiler/module_qual.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/module_imports.m:
Keep in the module_and_imports structure only the fields that used to
construct aug_compilation_units, to prepare for the replacement
of module_and_imports by aug_compilation_unit. Move the remaining fields
into a new structure, the module_baggage, and introduce a new type,
module_imports_and_baggage, that contains module_and_imports (for now)
and module_baggage.
The point of this is to allow the splitting of aug_compilation_unit
into types:
- one (aug_compilation_unit itself) for use when generating
target language code, and
- one (maybe named aug_make_int_unit) for use when generating
.int/.int2 files.
These two use cases fill some of the fields, such as direct and indirect
imports, with different kinds of parse trees. Until now, we handled this
using types such as direct_int_spec, which could contain either kind
of parse tree, but having separate aug_compilation_unit/aug_make_int_unit
types would allow the compiler to enforce the different invariants
of the two use cases.
This split requires factoring out the common parts of module_and_imports
structure. The module_baggage type contains these common parts.
Simplify some operations as permitted by the above change.
Rename others to reflect the new names of the types they operate on.
Don't return an output argument that is contained in another output
argument.
Delete operations on deleted fields.
Delete a predicate that has become identical to another.
compiler/grab_modules.m:
Add operations on module_baggage (that previously were operations on
module_and_imports) that are needed only in this module.
Conform to the changes above.
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
... and other bespoke types.
compiler/process_util.m:
Define the maybe_succeeded type, and two operations on it.
compiler/make.m:
Define the maybe_keep_going and maybe_invoked_by_mmc_make types.
Use the new types instead of bools where applicable.
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.module_dep_file.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:
Use the new types instead of bools where applicable.
Do not look up the value of the keep_going option in the globals
when its value (converted to the maybe_keep_going type) is available
in the make_info.
Use standard terminology in variable names.
compiler/module_imports.m:
Delete module_and_imports' {int,imp}_deps fields, as their contents
are computable from the field containing the parse_tree_module_src.
Add a utility predicate that returns the int and imp dependencies
separately. Clients for whom the int/imp distinction is not relevant
can get the union of those sets more simply by just taking the
key set of the parse_tree_module_src's import_and_or_use_map.
Delete now unneeded arguments.
Make some minor rearrangements to minimize the remaining differences
between the two methods of initializing module_and_imports structures,
init_module_and_imports and make_module_and_imports.
compiler/grab_modules.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/write_deps_file.m:
Conform to the change above.
compiler/module_imports.m:
As above. The new approach has a much simpler correctness argument,
especially since some of the methods for initializing module_and_imports
structures didn't actually fill in one of the fields with meaningful
information.
Don't ask callers for arguments that are not used.
compiler/get_dependencies.m:
Add utility predicates for computing the information that those fields
used to contain on demand.
Simplify the interface to some similar recently-added utility predicates.
compiler/make.module_dep_file.m:
Call those utility predicates when needed.
compiler/item_util.m:
Delete the utility predicates that module_imports.m *used* to use
to fill in those fields, which is no longer needed.
compiler/grab_modules.m:
compiler/write_deps_file.m:
Conform to the changes above.
compiler/module_imports.m:
Delete the field containing foreign_import_module (fim) info from
the module_and_imports structure, for two reasons. First, because
it is redundant; the same info is implicit in the other fields
of the module_and_imports structure. Second, because its semantics
were unclear: on different code paths and at different points in time,
it could contain fims from only the parse_tree_module_src, on other
code paths it could contain fims from the imported interface and/or
optimization files as well, and yet on other paths and times
it could be just set to empty regardless of the presence of fims
in the module being compiled.
Replace this with a predicate that calls get_dependencies.m to get fims
on demand from the parse_tree_module_src.
Don't give write_deps_file.m info it does not need.
compiler/get_dependencies.m:
Provide the utility predicate that does that.
compiler/item_util.m:
Provide helper predicates for the new predicate in get_dependencies.m.
(Eventually, these could be moved to get_dependencies.m, but while
the predicate whose logic they follow is in item_util.m, that is
where they should be.)
compiler/write_deps_file.m:
Eliminate the special cases in the code that generates the mmake rules
for dependencies on foreign imported modules. The codes handling the
two special cases never had any documented or easily discoverable
correctness arguments, and the fact that we can now never forcibly
initialize the fims field of the module_and_imports structure to
the empty list has tickled a bug in at least one of the special cases:
the fact that it did not restrict the set of fims to be recorded
to the fims for the relevant target language. Deleting the special
cases seems a better bet that a bandaid fix on questionable code.
Also, replace the two rules we used to generate, which were
modulename.o: <list of .mh files>
modulename.pic_o: <list of .mh files>
where the .mh file lists were always the same with a single mmake rule
of the form
modulename.o modulename.pic_o: <list of .mh files>
In one predicate, do not both updating several fields of a local copy
of a module_and_imports structure, because the fields that used
to be update are never read before the variable goes out of scope.
compiler/deps_map.m:
compiler/make.module_dep_file.m:
Conform to the changes above.
compiler/module_imports.m:
Delete the field containing foreign_include_file_infos from
the module_and_imports structure, because it is redundant;
the same info is implicit in the parse_tree_module_src field.
compiler/grab_modules.m:
Don't pass the set of foreign_file_include_infos to module_imports.m,
since it does not need it anymore.
compiler/get_dependencies.m:
Provide a predicate to get the set of foreign_file_include_infos
on demand. Provide this info in the form of a set, not a cord,
since duplicates don't count.
compiler/make.module_dep_file.m:
compiler/write_deps_file.m:
Get the set of foreign_file_include_infos when needed.
compiler/prog_data_foreign.m:
Delete a type synonym that is not needed anymore.
compiler/module_imports.m:
Delete the redundant fact table field from module_and_imports.
Get that info when needed from the parse_tree_module_src stored
in the module_and_imports structure.
compiler/get_dependencies.m:
Add a predicate to get this info on demand.
compiler/grab_modules.m:
Don't precompute the set of fact tables. (Actually, for now we do
precompute it but ignore it, but the precomputation should be gone soon.)
compiler/make.module_dep_file.m:
Conform to the changes above, and give a predicate a better name.
compiler/write_deps_file.m:
Conform to the changes above.
compiler/module_imports.m:
Until now, we stored the information we read in from .dep files
in module_and_imports structures in which most of the fields
were left filled-in with default values, which could be correct
only by accident.
This diff switches to storing information from .dep files in
a values of a type, module_dep_summary, that is made for this purpose.
With this type, it is obvious that the only fields that are ever
accessed are fields that have been properly filled in.
Delete the old predicate that constructed the half-filled-in
module_and_imports structure, since it is not needed anymore.
Also, delete the mcm_read construction method, since the deleted
predicate was its only user.
Since mmc --make operates both on values of this type *and* on
values of the old module_and_imports type, introduce a new type,
module_dep_info, which stores either one or the other,
and add the needed access predicates on this type.
Give a field of module_and_imports a more descriptive name.
compiler/make.m:
Switch to recording module_dep_infos for modules, instead of
just module_and_imports.
Replace some uses of maybes and pairs with bespoke types.
compiler/make.module_dep_file.m:
Store the result of reading a .dep file in a module_dep_summary,
not in a partially-filled-in module_and_imports.
compiler/module_deps_graph.m:
Store module_dep_infos in the deps_graph instead of module_and_imports
structures.
Delete a named mode, since mode "in" now works for functions
with the default mode.
compiler/make.dependencies.m:
Delete the maybe(option) field from dep_file, since it was *always*
set to "no".
Conform to the changes above.
compiler/make.util.m:
Add a new utility predicate, for use in make.dependencies.m.
Conform to the changes above.
compiler/generate_dep_d_files.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
Conform to the changes above.
compiler/compile_target_code.m:
Expect a module_dep_info instead of a module_and_imports,
since that is what our callers have.
Add an XXX for a surprising piece of code.
compiler/module_imports.m:
As above; delete the ancestors field, since users can compute its value
by calling get_ancestors_set on the module name.
On some initialization paths, the ancestors field used to be filled
with a dummy empty set, so this change should improve robustness.
compiler/deps_map.m:
compiler/grab_modules.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/module_deps_graph.m:
compiler/write_deps_file.m:
Conform to the changes in module_imports.m.
compiler/module_imports.m:
The module_and_imports structure used to have a field, mf_nested_children,
which stored a set of module names, but which had confusing semantics:
it had two different meanings in two different circumstances.
Replace that field with a value of a new type, maybe_top_module, which
has two separate function symbols for those two circumstances:
when a module is the top module in its source file, and when it is not.
compiler/mercury_compile_main.m:
Conform to the change above.
Put related arguments next to each other.
compiler/grab_modules.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
Conform to the change above.
tests/recompilation/test_functions:
Impose a limit of 10 minutes of CPU time on each process. This should
help catch infinite loops, such as happened during the development
of this diff.
Fix indentation, and clarify some comments.
tests/recompilation/README:
Fix stray blank line.
... instead of into raw_compilation_units. Besides being more convenient to
work on, a parse_tree_module_src encodes in its type a significant number
of invariants that a raw_compilation unit does not.
compiler/split_parse_tree_src.m:
Immediately after creating a raw_compilation_unit for one of the modules
in a potentially multi-module source file, convert it to a
parse_tree_module_src.
Fix an old problem that can come up in contrived erroneous code.
Specifically, when a submodule is both nested inside its parent module,
*and* it also has an explicit include_module declaration, we used to
record the contexts of both "inclusions", after generating an error
message. The more rigorous checking that later code now does on the
resulting inclusion map would look at this "duplicate inclusion"
and generate *another* error message. To avoid this redundant message,
do not record the contexts of erroneous inclusions for which a message
has already been generated.
compiler/grab_modules.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
This allows us to avoid having code for doing what converting the
raw_compilation_unit to a parse_tree_module_src has already done.
In fact, that conversion code does a better job. The old code assumed
that all implicitly available modules are used in the interface,
whereas in fact only some should be used in the interface, with
the rest being used in the implementation section.
compiler/module_imports.m:
Make the predicates that create module_and_imports structures
take a parse_tree_module_src instead of a raw_compilation_unit
as input. For now, we convert the parse_tree_module_src back to
a raw_compilation_unit for further processing, but I intend
a later diff to change this. Nevertheless, one immediate change
is that init_module_and_imports now stores the *actual*
parse_tree_module_src in the module_and_imports structure,
not a dummy.
compiler/prog_item.m:
Do not include a list of foreign_enum items in the interface section
of a parse_tree_module_src, since such items are not allowed to occur
in interface sections.
For the same reason, delete the field for foreign_enums in the interface
sections of .int0 and .int files.
compiler/check_raw_comp_unit.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
compiler/comp_unit_interface.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
Do not expect any foreign_enum items in interface sections, since
they are not allowed there.
compiler/read_modules.m:
Provide a mechanism to remember having read a parse_tree_module_src.
compiler/write_module_interface_files.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
compiler/get_dependencies.m:
Add a new version of an existing utility predicate. The old one operated
on raw item lists, the new one operates on parse_tree_module_srcs.
To make this possible, factor out the code pieces that operate on
each non-ignored kind of item.
compiler/item_util.m:
Add some new utility predicates/functions.
compiler/convert_parse_tree.m:
Conform to the change in prog_item.m. (We already generated an error
message for a foreign_enum item in the interface, but still passed around
a list of foreign_enum items that was guaranteed to be stay empty.)
compiler/make.module_dep_file.m:
Conform to the changes above.
Use explicit streams in one place.
Do not pass an unneeded argument.
compiler/check_parse_tree_type_defns.m:
compiler/equiv_type.m:
compiler/make_hlds_separate_items.m:
Conform to the change in prog_item.m.
compiler/mercury_compile_main.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
Conform to the changes above.
library/map.m:
library/tree234.m:
Add foldl6, foldl6_values and foldr6 predicates. An earlier version
of this diff needed foldl6, and I added the others for symmetry.
NEWS:
Announce the new library predicates.
tests/invalid/bad_mutable.m:
Export something, to avoid a warning about not exporting anything.
tests/invalid_submodules/duplicate_module.m:
tests/invalid_submodules/duplicate_module_test.m:
Update programming style.
compiler/prog_out.m:
For every predicate that writes output to the current output stream,
ensure that there is another predicate with the same name that takes
an explicit stream as an additional arguments.
Some of these predicates already existed under different names,
but that name difference prevents --warn-implicit-stream-calls
from warning about the implicit stream use. Fix that.
Delete write_quoted_module_name, since it is a synonym for
write_quoted_sym_name (since the compiler' current code depends on
module_name being a synonym for sym_name in lots of places already).
compiler/add_clause.m:
compiler/analysis.file.m:
compiler/closure_analysis.m:
compiler/higher_order.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/pd_debug.m:
compiler/recompilation.check.m:
compiler/smm_common.m:
compiler/source_file_map.m:
compiler/structure_reuse.indirect.m:
Conform to the changes in prog_out.m. There is no switchover
to explicit streams in this diff; that will come later.
compiler/make.module_dep_file.m:
Write foreign included file names to the .module_dep stream
instead of the implicit output stream. The bug was introduced in
commit 5f50259d16.
tests/mmc_make/Mmakefile:
mmc --make does not set a non-zero exit status even if there were
problems reading a .module_dep file. Explicitly grep for "error" in
the mmc --make output in the include_file test that should have
caught the preceding bug (assuming the workspace is built with
--use-subdirs).
grep for "error" in another test case.
Right now, most parts of the compiler write to the "current output stream".
This was a pragmatic choice at the time, but has not aged well. The problem
is that the answer to the question "where is the current output stream going?"
is not obvious in *all* places in the compiler (although it is obvious in
most). When using such implicit streams, finding where the output is going
to in a given predicate requires inspecting not just the ancestors of that
predicate, but also all their older siblings (since any of them could have
changed the current stream), *including* their entire call trees. This is
usually an infeasible task. By constrast, if we explicitly pass streams
to all output operations, we need only follow the places where the variable
representing that stream is bound, which the mode system makes easy.
This diff switches large parts of the compiler over to doing output only
to explicitly passed streams, never to the implicit "current output stream".
The parts it switches over are the parts that rely to a significant degree
on the innermost change, which is to the "output" typeclass in
parse_tree_out_info.m. This is the part that has to be switched over to
explicit streams first, because (a) many modules such as mercury_to_mercury.m
rely on the output typeclass, and (b) most other modules that do output
call predicates in these modules. Starting anywhere else would be like
building a skyscraper starting at the top.
This typeclass, output(U), has two instances: output(io), and output(string),
so you could output either to the current output stream, or to a string.
To allow the specification of the destination stream in the first case,
this diff changes the typeclass to output(S, U) with a functional dependency
from U to S, with the two instances being output(io.text_output_stream, io)
and output(unit, string). (The unit arg is ignored in the second case.)
There is a complication with the output typeclass method, add_list, that
outputs a list of items. The complication is that each item is output
by a predicate supplied by the caller, but the separator between the items
(usually a comma) is output by add_list itself. We don't want to give
callers of this method the opportunity to screw up by specifying (possibly
implicitly) two different output streams for these two purposes, so we want
(a) the caller to tell add_list where to put the separators, and then
(b) for add_list, not its caller, tell the user-supplied predicate what
stream to write to. This works only if the stream argument is just before
the di,uo pair of I/O state arguments, which differs from our usual practice
of passing the stream at or near the left edge of the argument list,
not near the right. The result of this complication is that two categories
of predicates that are and are not used to print items in a list differ
in where they put the stream in their argument lists. This makes it easy
to pass the stream in the wrong argument position if you call a predicate
without looking up its signature, and may require *changing* the argument
order when a predicate is used to print an item in a list for the first time.
A complete switch over to always passing the stream just before !IO
would fix this inconsistency, but is far to big a change to make all at once.
compiler/parse_tree_out_info.m:
Make the changes described above.
Add write_out_list, which is a variant of io.write_list specifically
designed to address the "complication" described above. It also has
the arguments in an order that is better suited for higher-order use.
Make the same change to argument order in the class method add_list
as well.
Almost all of the following changes consist of passing an extra stream
argument to output predicates. In some places, where I thought this would
aid readability, I replaced sequences of calls to output predicates
with a single io.format.
compiler/prog_out.m:
This module had many predicates that wrote things to the current output
stream. This diff adds versions of these predicates that take an
explicit stream argument.
If the originals are still needed after the changes to the other modules,
keep them, but add "_to_cur_stream" to the end of their names.
Otherwise, delete them. (Many of the changes below replace
write_xyz(..., !IO) with io.write_string(Stream, xyz_to_string(...), !IO),
especially when write_xyz did nothing except call xyz_to_string
and wrote out the result.)
compiler/c_util.m:
Add either an explicit stream argument to the argument list, or a
"_current_stream" suffix to the name, of every predicate defined
in this module that does output.
Add a new predicate to print out the block comment containing
input for mkinit. This factors out common code in the LLDS and MLDS
backends.
compiler/name_mangle.m:
Delete all predicates that used to write to the current output stream,
after replacing them if necessary with functions that return a string,
which the caller can print to wherever it wants. (The "if necessary"
part is there because some of the "replacement" functions already
existed.)
When converting a proc_label to a string, *always* require the caller
to say whether the label prefix should be added to the string,
instead of silently assuming "yes, add it", as calls to one of the old,
now deleted predicates had it.
compiler/file_util.m:
Add output_to_file_stream, a version of output_to_file which
simply passes the output file stream it opens to the predicate
that is intended to define the contents of the newly created or
updated file. The existing output_to_file, which instead sets
and resets the current output stream around the equivalent
predicate call, is still needed e.g. by the MLDS backend,
but hopefully for not too long.
compiler/mercury_to_mercury.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_clause.m:
compiler/parse_tree_out_inst.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_repn.m:
Change the code writing out parse trees to explicitly pass a stream
to every predicate that does output.
In some places, this allows us to avoid changing the identity
of the current output stream.
compiler/hlds_out.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
Change the code writing out HLDS code to explicitly pass a stream
to every predicate that does output. (The changes to these modules
belong in this diff because these modules call many of the output
predicates in the parse tree package.)
In hlds_out_util.m, delete some write_to_xyz(...) predicates that wrote
the result of xyz_to_string(...) to the current output stream.
Replace calls to the deleted predicates with calls to io.write_string
with the string being written being computed by xyz_to_string.
Add a predicate to hlds_out_util.m that outputs a comment containing
the current context, if it is valid. This factors out code that used
to be common to several of the other modules.
In a few places in hlds_out_module.m, the new code generates a
slighly different set of blank lines, but this should not be a problem.
compiler/layout_out.m:
compiler/llds_out_code_addr.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_global.m:
compiler/llds_out_instr.m:
compiler/llds_out_util.m:
compiler/opt_debug.m:
compiler/rtti_out.m:
Change the code writing out the LLDS to explicitly pass a stream
to every predicate that does output. (The changes to these modules
belong in this diff because layout_out.m and rtti_out.m call
many of the output predicates in the parse tree package,
and through them, the rest of the LLDS backend is affected as well.)
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
Replace code that sets and resets the current output stream
with code that simply passes an explicit output stream to a
predicate that now *takes* an explicit stream as an argument.
compiler/accumulator.m:
compiler/add_clause.m:
compiler/code_gen.m:
compiler/code_loc_dep.m:
compiler/cse_detection.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/error_msg_inst.m:
compiler/export.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/ite_gen.m:
compiler/lco.m:
compiler/liveness.m:
compiler/lp_rational.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_global.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/optimize.m:
compiler/passes_aux.m:
compiler/pd_debug.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/prog_ctgc.m:
compiler/push_goals_together.m:
compiler/rat.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/rtti.m:
compiler/saved_vars.m:
compiler/simplify_goal_conj.m:
compiler/stack_opt.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/superhomogeneous.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_pass2.m:
compiler/term_constr_util.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/unneeded_code.m:
compiler/write_deps_file.m:
Conform to the changes above, mostly by passing streams explicitly.
compiler/hlds_dependency_graph.m:
Conform to the changes above, mostly by passing streams explicitly.
Move a predicate's definition next it only use.
compiler/Mercury.options:
Specify --warn-implicit-stream-calls for all the modules in which
this diff has replaced all implicit streams with explicit streams.
(Unfortunately, debugging this diff has shown that --warn-implicit-
stream-calls detects only *some*, and not *all*, uses of implicit
streams.)
library/term_io.m:
Fix documentation.