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.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
Delete these modules, which together constitute the Erlang backend.
compiler/notes/compiler_design.html:
Delete references to the deleted modules.
compiler/parse_tree_out_type_repn.m:
Update the format we use to represent the sets of foreign_type and
foreign_enum declarations for a type as part of its item_type_repn_info,
now that Erlang is no longer a target language.
compiler/parse_type_repn.m:
Accept both the updated version of the item_type_repn_info and the
immediately previous version, since the installed compiler will
initially generate that previous version. However, stop accepting
an even older version that we stopped generating several months ago.
compiler/parse_pragma_foreign.m:
When the compiler finds a reference to Erlang as a foreign language,
add a message about support for Erlang being discontinued to the error
message.
Make the code parsing foreign_decls handle the term containing
the foreign language the same way as the codes parsing foreign
codes, procs, types and enums.
Add a mechanism to help parse_mutable.m to do the same.
compiler/parse_mutable.m:
When the compiler finds a reference to Erlang as a foreign language,
print an error message about support for Erlang being discontinued.
compiler/compute_grade.m:
When the compiler finds a reference to Erlang as a grade component,
print an informational message about support for Erlang being discontinued.
compiler/pickle.m:
compiler/make.build.m:
Delete Erlang foreign procs and types.
compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
Remove references to Erlang as a backend or as a target language.
tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
Add a test for Erlang as an invalid foreign language. Expect both the
new error message for this new error, and the updated list of now-valid
foreign languages on all errors.
... using an approach proposed by Peter, with an extra twist from Julien.
Instead of having two modules, getopt.m and getopt_io.m, with the former
defining predicates that do not take an I/O state pair, and the latter
defining predicates that do take an I/O state pair, put both kinds of
predicates into a single module. The versions with an I/O state pair
have an "_io" suffix added to their names for disambiguation.
Both versions are a veneer on top of a common infrastructure,
which relies on a simple type class to implement the operation
"give the contents of the file with this name". The predicate versions
with I/O state pairs have a normal implementation of this typeclass,
while the predicate versions that do not have I/O state pairs
have an implementation that always returns an error indication.
The above change just about doubles the number of exported predicates.
We already had two versions of most exported predicates that differed
in whether we returned errors in the form of a string, or in the form
of a structured representation, with names of the latter having
an "_se" suffix. Since we agreed that the structured representation
is the form we want to encourage, this diff deletes the string versions,
and deletes the "_se" suffix from the predicate names that used to have them.
(It still remains at the end of the name of a type.) This "undoubling"
should offset the effect of the doubling in the previous paragraph.
Eventually, we want to have just one module, getopt.m, containing
the updated code described above, but for now, we put the same code
into both getopt_io.m and getopt.m to prevent too big a shock to
people with existing code that uses getopt_io.m.
library/getopt.m:
library/getopt_io.m:
Make the changes described above.
library/Mmakefile:
Instead of building both getopt_io.m and getopt.m from getopt_template,
build getopt.m from getopt_io.m.
tools/bootcheck:
Delete references to getopt_template.
compiler/typecheck_errors.m:
When a type error involves one of the getopt/getopt_io predicates
whose interfaces are changed by this diff, tell the user about
how these changes could have caused the error, and thus what the
probable fix is.
compiler/handle_options.m:
browser/parse.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
slice/mcov.m:
slice/mdice.m:
slice/mslice.m:
slice/mtc_diff.m:
slice/mtc_union.m:
tests/hard_coded/space.m:
Use the updated getopt interface.
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/deforest.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/ml_top_gen.m:
compiler/module_cmds.m:
compiler/op_mode.m:
compiler/optimization_options.m:
compiler/options.m:
compiler/write_module_interface_files.m:
tools/make_optimization_options_middle:
tools/make_optimization_options_start:
Replace references to getopt_io.m with references to getopt.m.
tests/invalid/getopt_io_old.{m,err_exp}:
tests/invalid/getopt_old.{m,err_exp}:
tests/invalid/getopt_old_se.{m, err_exp}:
New test cases for the extra help
tests/invalid/Mmakefile:
Enable the new test cases.
This is a first step towards a much finer grained partition.
compiler/file_names.m:
Split the ext type into ext_src and ext_other, as mentioned above.
Add the first predicate for checking whether a string falls into
a given category of extensions.
Add an XXX proposing a better solution for an old problem that does not
actually arise in practice.
compiler/compile_target_code.m:
Split the two-moded predicate maybe_pic_object_file_extension into
two separate one-mode predicates, one for each old mode. The
implementations of the two modes were already separate, because
the two modes already did different jobs: while one went from PIC
to an "extension", the other went from an "extension string" to PIC.
Until now, "extension" and "extension string" were equivalent;
after this diff, they aren't anymore.
Delete an unused argument.
compiler/make.util.m:
Split the two-moded predicate target_extension into
two separate one-mode predicates, one for each old mode,
for the same reason as maybe_pic_object_file_extension above:
the fact that "extension" and "extension string" are now distinct.
compiler/options_file.m:
Move debug infrastructure here from mercury_compile_main.m, to help
debug possible problems with options files. (I had such a problem
while writing this diff.)
Improve how progress messages are printed.
compiler/options.m:
Make an error message more useful.
compiler/mercury_compile_main.m:
Add infrastructure for debugging possible problems with command lines.
(I had such a problem while writing this diff.)
compiler/analysis.m:
Conform to the changes above. Put the arguments of some methods
into the same order as similar predicates in file_names.m.
compiler/find_module.m:
Conform to the changes above. Delete an unused argument,
compiler/analysis.file.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.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.deps_set.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
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.check.m:
compiler/recompilation.usage.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
... to allow later changes to its definition.
compiler/file_names.m:
We used to represent filename extensions simply as strings. This meant
all calls to the predicates in file_names.m that convert module names
to file names with various suffixes had to go through a complicated
sequence of tests that effectively partition the extensions into
several classes, with all extensions in a class being treated the same
but different classes being treated differently. And since this general
translation process is quite convoluted (which is not helped by it
being spread across several predicates), it is very hard to construct
a correctness argument for it.
It would be better to represent the different classes of extensions
explicitly, in a du type, with each function symbol of that type
representing all the extensions in the corresponding class (in the sense
of the paragraph above). However, getting there in one diff would make
that diff far too hard to test and to review. So this first diff
starts by simply making extension a notag type.
The above is the first step in implementing one old XXX. This diff
fully implements another old XXX, which is to make the argument order
of several predicates friendly to higher order code.
Add infrastructure for profiling how often this code makes directories.
Delete an unused type.
Add comments outlining proposed future improvements.
compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/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/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/module_imports.m:
compiler/parse_tree_out.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the change to file_names.m.
Consistently use "Ext" for the abstract representation of extensions
and "ExtStr" for their string representation.
In a few places, add "XXX EXT" where the code manipulates extensions
as strings in a way that potentially inferferes with the partition
of extensions into classes.
In a few places, rename predicates to avoid ambiguities. factor out
common code, delete unneeded arguments, replace bools with bespoke types,
and make similar minor improvements.
In a few places, remove rafe-isms, such as the use ^elem.
And add tests for how the compiler handles both valid and invalid
options files.
compiler/options_file.m:
This diff rewrites options_file.m in a straightforward, direct style that
returns indications of errors as error_specs rather than as exceptions.
A recent diff started on this task; this diff finishes it.
The new approach has several advantages.
- The control flow is much simpler, and therefore more understandable.
Correctness arguments for propositions such as "this code closes
all the file streams that it opens" are now much simpler to make.
- We now report errors using error_specs, which contain context
information, while previously, each error was described only
by a string, without context info.
- Once we detect and report one error, we can continue to read the
rest of the input. This allows a single compiler invocation to find
and report several errors, not just the first.
- Since we now return the gathered set of error_specs instead of printing
them, the predicates of this file don't have to take globals structures
as arguments, which allows our callers to avoid constructing those
structures.
- Deep profiling, which cannot handle exceptions, now works on
the code of this module.
Change over to using trace goals for debugging prints, since continuing
to use debug_make_msg would require a globals structure.
Add an XXX on a likely bug.
Add a mechanism for writing out a database of variable names and values.
compiler/mercury_compile_main.m:
Conform to the changes in options_file.m. Document where exactly
we could avoid constructing a globals just for options_file.m.
If the right option is given, get options_file to write out the database
of variable names and values it has just read in, to enable the
functionality of this module to be tested.
compiler/options.m:
doc/user_guide.texi:
Add a new developer option, --dump-options-file, to control the above.
compiler/make.build.m:
compiler/make.m:
compiler/make.program_target.m:
Conform to the changes in options_file.m.
compiler/file_util.m:
Fix an error message.
tests/Mmakefile:
tools/bootcheck:
List options_file and invalid_options_file as two new test directories.
Fix a command in bootcheck.
tests/options_file/Mmakefile:
Add a mechanism for testing whether options_file.m builds mapping
from make variable names to values that we expect.
tests/Mmake.common:
Provide a mechanism for comparing dumped options_files against
their expected contents, for use by tests/invalid_options_file/Mmakefile.
Fix a comment.
tests/options_file/basic_test.m:
tests/options_file/basic_test.optfile_exp:
tests/options_file/basic_test.options_file:
tests/options_file/basic_test.options_file.sub0:
tests/options_file/basic_test.options_file.sub1:
A simple test case for exercising all the usual options_file constructs.
tests/invalid_options_file/Mmakefile:
Add a mechanism for testing whether options_file.m generates
the error messages we expect for various kinds of errors in options files.
tests/invalid_options_file/no_assign.{m,options_file,err_exp}:
tests/invalid_options_file/no_var.{m,options_file,err_exp}:
tests/invalid_options_file/nonexistent_file.{m,options_file,err_exp}:
tests/invalid_options_file/undefined_var.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_string.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_var.{m,options_file,err_exp}:
Six test cases to test six different kinds of errors that can be
detected by options_file.m.
compiler/prog_data.m:
Delete the simple_call_id data type, since it is isomorphic
to the pf_sym_name_arity type, which more clearly specifies
what is stored inside it.
compiler/prog_out.m:
Rename (all three versions of) simple_call_id_to_string to
pf_sym_name_orig_arity_to_string, both to conform to the change
in the input data type, and to emphasize that the resulting string
will contain the *original* arity of functions (which does not include
the return value), which is one less than the arity in the
pf_sym_name_arity structure (which, in accordance with the
convention inside the compiler that the arity is the length
of the argument list, *does* include the return value).
Delete the provision inside simple_call_id_to_string, now
pf_sym_name_orig_arity_to_string, for special handling of the names
of the predicates we use to implement promises, because it seems that
*none* of the call sites to any of the three versions of this function
can actually pass to it the identity of such a predicate. These calls
refer to a predicate or mode declaration item (which promise predicates
do not have), to clause or foreign_proc items (which again, promise
predicates cannot have) or calls to the predicate (promise predicates
cannot be called).
Delete the exported predicate simple_call_id_to_sym_name_arity.
It was called from exactly one place, inside prog_out.m itself,
and this diff inlines that call.
Avoid unnecessary forwarding of work from prog_out.m to error_util.m.
Delete (all three versions of) write_simple_call_id. The changes
below replace all their (few) uses with calls to
pf_sym_name_orig_arity_to_string.
compiler/error_util.m:
Replace the simple_call() error piece with qual_pf_sym_name_orig_arity,
and add a new version unqual_pf_sym_name_orig_arity. Their names
explicitly say that they print the original arities of functions,
also say whether they strip away any module qualification on the
sym_name inside the pf_sym_name_arity. We prefer the unqual version
in situations where the module qualifier is implicit, which usually means
that it must be the same as the name of the module being compiled, because
it reduces visual clutter for readers of error messages.
Put {qual,unqual}_pf_sym_name_orig_arity next to their most closely
related function symbols, {qual,unqual}_sym_name_arity, in the
format_component type. (This yields a few inconsequential changes
in the order of error_specs when sorted.)
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_data.m:
compiler/hlds_desc.m:
compiler/hlds_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/inst_util.m:
compiler/llds_out_instr.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/ml_unify_gen_construct.m:
compiler/mlds_to_c_stmt.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modecheck_util.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_type_repn.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/pre_quantification.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/recompilation.version.m:
compiler/term_constr_build.m:
compiler/termination.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unused_imports.m:
Conform to the changes above. Where I am pretty sure that in an error
message, the module qualifier of a name must be the current module,
use unqual_pf_sym_name_orig_arity instead of qual_pf_sym_name_orig_arity.
Add some sanity checks where they seem appropriate.
Replace sequences of io.write_strings with uses of io.format where this
yields clearer code. (This is why there were no remaining calls to
write_simple_call_id.)
Shorten some too-long lines.
In add_pred.m, make the order of some predicate definitions match
the order of the calls to them.
tests/invalid/ambiguous_method.err_exp:
tests/invalid/ambiguous_method_2.err_exp:
tests/invalid/bad_pred_arity.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug410.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/complex_constraint_err.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/exported_mode.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/foreign_singleton.err_exp:
tests/invalid/funcs_as_preds.err_exp:
tests/invalid/imported_mode.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/make_opt_error.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_1.err_exp2:
tests/invalid/require_tailrec_2.err_exp:
tests/invalid/require_tailrec_2.err_exp2:
tests/invalid/require_tailrec_3.err_exp:
tests/invalid/require_tailrec_3.err_exp2:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_constraint_extra_var.err_exp:
tests/invalid/typeclass_mode_2.err_exp:
tests/invalid/typeclass_test_12.err_exp:
tests/invalid/typeclass_test_2.err_exp:
tests/invalid/typeclass_test_9.err_exp:
tests/invalid/types.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/unbound_type_vars.err_exp:
tests/invalid/with_type.err_exp:
tests/invalid_purity/purity_nonsense.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
tests/warnings/double_underscore.exp:
tests/warnings/pragma_source_file.exp:
tests/warnings/singleton_test.exp:
tests/warnings/singleton_test.exp2:
tests/warnings/singleton_test.exp3:
tests/warnings/singleton_test.exp4:
tests/warnings/singleton_test_state_var.exp:
tests/warnings/warn_return.exp:
tests/warnings/warn_return.exp2:
tests/warnings/warn_return.exp3:
tests/warnings/warn_succ_ind.exp:
tests/warnings/warn_succ_ind.exp2:
tests/warnings/warn_succ_ind.exp3:
tests/warnings/warn_succ_ind.exp4:
Update all these expected output files. Most changes are due to
predicate and function names no longer being module qualified when
the module qualification is obvious. A few changes are due to the
change in the relative ordering of the function symbols of the
format_component type.
For singleton_test, warn_return and warn_succ_ind in warnings,
the changes to the non-C .exp files were done by hand, so they
may have the wrong white space.
Perform library grade install checks when the compiler is invoked on a single
source file linked target; previously we only performed this checks when using
mmc --make.
compiler/mercury_compile_main.m:
As above.
compiler/check_libgrades.m:
Check whether --libgrade-install-check is enabled here, rather than
in our callers.
compiler/handle_options.m:
Do not disable the library grade install checks when the compiler
is invoked to build a single source file linked target.
compiler/make.program_target.m:
Conform to the above changes.
Move the library grade install check out of the make package and into its own
module in the libs package. This is in preparation for performing the check
when building single source file programs.
compiler/check_libgrades.m:
New module containing the code that implements the library grade install
check.
compiler/libs.m:
Include the new module.
compiler/make.program_target.m:
Conform to the above change.
compiler/notes/compiler_design.html:
Mention the new module.
Enable library grade checks for the Erlang grade. (This should
have always worked, but was just never enabled.)
compiler/make.program_target.m:
Extend library grade checks to work for the C# and Java grades.
In those grades we do not generate .init files, so instead check
for the presence of the library JAR or DLL to tell whether a library
is present.
compiler/handle_options.m:
Enable library grade checks for the non-C grades.
compiler/module_imports.m:
As above.
compiler/modules.m:
Use the new access predicates if relevant. Add a sanity check.
compiler/compile_target_code.m:
compiler/deps_map.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/module_deps_graph.m:
compiler/write_deps_file.m:
Use the new access predicates if relevant.
compiler/module_imports.m:
Make the definition of module_and_imports private, to make future changes
to its structure easier.
Add the construction, deconstruction, getter and setter predicates
on the type that are now needed by the other compiler modules.
Put the related fields of module_and_imports next to each other.
Give some of the fields more descriptive names.
compiler/compile_target_code.m:
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.dependencies.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_deps_graph.m:
compiler/modules.m:
compiler/write_deps_file.m:
Conform to the changes above.
compiler/make.m:
Replace references to private, long and short interfaces with references
to int0, int1, int2 and int3 in two types. These two types, even though
they were adjacent, used the same word, "short", to refer to two DIFFERENT
interface file kinds: int2 in one, int3 in the other.
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
Conform to the change above.
Replace the definitions of some predicates, which used to be lists of
clauses, with a single clause each containing a disjunction, especially
where the old definitions implemented the DRY principle through recursion
(because switch arms shared between two or more cons_ids were not yet
supported when they were written).
Do some other minor cleanups.
When you get this message, the error may be in the module name that it
reports to be wrong, but it may be in the places that set the compiler's
expectations of what the name of the module should be. This latter is
very likely the case when one moves a module of the Mercury compiler
from one package to another. In such cases, the problems are the old modules
that continue to refer to the renamed module by its old name.
This diff improves the error message by indicating *precisely* the locations
that refer to the old name, since these are the locations that establish the
expectation that is not met.
compiler/module_imports.m:
Change the module_and_imports structure to record, for each imported
or used module, and for each child module, the location of the relevant
":- import_module" or ":- include_module" declaration(s).
compiler/deps_map.m:
When tracing references from module A to module B.C (either because
A imports B.C, or because A = B and A includes C), record the location
of the ":- import_module" or ":- include_module" declaration as a source
of the expectation that any file that contains module C will have
B.C as module C's fully qualified name. Since a module is usually imported
by more than one other module, there may be several sources of such
expectations.
compiler/parse_module.m:
Change the wording of the error message to reflect the change in what
the context denotes.
compiler/get_dependencies.m:
compiler/prog_item.m:
When returning the sets of modules imported, used or included by some
entities such as item blocks, return the contexts of those
imports/uses/includes as well.
compiler/compile_target_code.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/module_deps_graph.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/write_deps_file.m:
Conform to the changes above.
tests/invalid/bad_module_name.err_exp:
Expect the updated error message.
compiler/file_names.m:
Change the order of arguments of module_name_to_file_name and related
predicates to make it easier to construct closures from them. Delete
the previous higher-order-friendly versions, which the previous step
has made unnecessary.
compiler/compile_target_code.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/intermod.m:
compiler/llds_out_file.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/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/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/modules.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the change above. In several places, this means replacing
explicit lambda expressions with simple partial application of the
relevant predicates.
compiler/Mercury.options:
Don't disable --warn-unused-imports for any packages.
compiler/make.m:
compiler/recompilation.m:
Delete the imports in these packages that aren't used in the module itself.
(These are the imports that --warn-unused-imports warns about.)
The other packages in the compiler no unused imports.
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
Conform to the above. In most cases, this means adding the imports
that previously these modules got from their parent package.
In some cases, it means *deleting* unused imports that previously
weren't warned about because the import also came from the parent
module. Some imports deleted from the packages weren't needed
in *any* of their modules.
This fixes mantis bug #404.
compiler/compile_target_code.m:
compiler/make.dependencies.m:
Use the value of the rebuild option, not the op_mode, to make decisions
about executing operations that even when timestamps don't call for them.
This fixes the bug, because unlike the op_mode, the value of the option
isn't overridden by setting the invoked_by_mmc_make option when recomputing
the op_mode.
compiler/make.program_target.m:
compiler/make.util.m:
Reset the rebuild option, not the op_mode, since this is what matters now.
compiler/op_mode.m:
Take the value of the --rebuild option out of the op_mode, since it is not
needed *there* anymore.
Note that --rebuild still implies --make, so the rebuild option still does
play a role in selecting the op_mode. (This was the original motivation
for its inclusion in the op_mode in the first place.) This is why its value
matters when converting an op_mode back into its original option string.
Fix the copyright years.
compiler/options.m:
Since the rebuild option isn't stored in the op_mode anymore, give it back
its original, non-op_mode internal name.
compiler/handle_options.m:
compiler/mercury_compile_main.m:
Conform to the changes above.
compiler/file_util.m:
The predicates in this module that find the file containing a Mercury
module used to allow the caller to specify that if the file can be
successfully opened, then the current input stream should be set to
the resulting stream. This meant that callers had to save the original
current input stream *before* calling this predicate, and later restore it,
*without* anything in between that would signal to readers of the code
that the current input stream had ever been changed.
Replace each of these predicates with two predicates. One returns
the stream as an explicit part of an output argument, letting the caller
do with the stream what it wished (in some cases, that would mean
using it in I/O operations as *explicitly* passed parameters, which
would not require touching the identity of the current input stream),
giving it the responsibility to close the stream when it is done using it.
The other would close the stream immediately, not letting the caller know
that the file was ever opened. The two versions are distinguised both
by name and by return type.
compiler/find_module.m:
Make the same change to search_for_module_source. (This predicate was
the motivation for this change, because unlike the predicates in
file_util.m, its signature did NOT provide readers with any sort of clue
that the searched-for file would actually be opened, and that the
resulting stream would become the new current input stream.)
Clarify the code that tries to find the source file for a module
by dropping qualifiers from the module name by (a) giving the predicate
a more explicit name, and (b) separating the search from the code
that handles the failure of the search.
compiler/parse_module.m:
compiler/read_modules.m:
Change part of the interface between these two modules. This used to be
that code in read_modules.m passed closures to parse_module.m for it
to invoke, closures whose predicates were always one of the predicates
affected by the changes above. Simplify the interface by making
read_modules.m invoke those predicates directly, and simply pass
the results.
compiler/compile_target_code.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/options_file.m:
compiler/write_deps_file.m:
Conform to the changes above.
For picreg, this is only the first half of the change; it deletes code
that generates references to this grade component. When this diff has been
installed on all our machines, will come the second half, which will delete
the code that understands references to picreg. The delay is needed because
your current installed compiler is still generating such references.
runtime/mercury_grade.h:
Remove both regparm and picreg as grade components.
doc/user_guide.texi:
Remove the (commented out) documentation of picreg; regparm had
no documentation to delete.
runtime/mercury_std.h:
Remove the small bit of code that implemented regparm.
runtime/mercury_conf_param.h:
Don't define MR_PIC_REG.
runtime/machdeps/i386_regs.h:
runtime/mercury_conf_bootstrap.h:
Remove references to picreg.
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
Keep in place the code that accepts picreg grade components,
but make them do nothing. Mark such do-nothing code so that
it can be deleted when this first-half diff has been bootstrapped.
configure.ac:
Delete the autoconfigured variable EXT_FOR_LINK_WITH_PIC_OBJECTS,
which could be set to either 'lpic_o' or just 'o', because it is now
*always* the latter.
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
Remove code that transmitted the value of EXT_FOR_LINK_WITH_PIC_OBJECTS
to the compiler via the --link-with-pic-object-file-extension option.
compiler/options.m:
Keep the --link-with-pic-object-file-extension and --pic-reg options,
but mark them for deletion in the second half of this change.
compiler/compile_target_code.m:
Change the code that dealt with the value of the
--link-with-pic-object-file-extension and --pic-reg options to assume
that the former is always the same as the non-pic file extension,
and that --pic-reg is never needed. The former means that we don't need
to handle link_with_pic as a separate category of object files from
just plain non_pic.
compiler/compute_grade.m:
Keep accepting picreg grades, but mark the code that does this
for deletion.
compiler/make.program_target.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
Conform to the changes above.
The options that help determine the op_mode are only sort-of mutually
exclusive; in some cases, more than one can be set. Using the op_mode
instead of the options themselves means that we are using the result
of the process (in op_mode.m) that resolves conflicts between them.
Another benefit is that in some places in the code, many op_modes
have already been processed, which means that the set of remaining op_modes
is a reasonably small set.
compiler/options.m:
Give all the options that op_mode.m uses to compute the op_mode
new internal names. (The user-visible names are not affected.)
Each new internal name is the old internal name with an added
"only_opmode_" prefix, indicating that the option should not be used
for any purpose other than computing the op_mode.
Change the documentation of the --generate-module-order and --imports-graph
options. (See handle_options.m below for the reason.)
doc/user_guide.texi:
Change the documentation of the --generate-module-order and --imports-graph
options, as in compiler/options.m.
compiler/handle_options.m:
Delete implications that set the values of options that help decide the
op_mode, since those implications used to be executed *after* we decided
the op_mode. Replace each of their functionalities with something else.
For the implication from --rebuild to --make, the replacement is
new code in op_mode.m (see below).
For the implication from --invoked-by-mmc-make to --no-make,
the needed replacement code was already in op_mode.m.
For the implications from --generate-module-order and --imports-graph
to --generate-dependencies, do not replace them. Instead, document that
they are effective only if the op mode is generating dependencies.
This goes against the current documentation of --generate-module-order,
though not of --imports-graph (the help message for --imports-graph
is silent on its relationship with --generate-dependencies). However,
the new documented (and implemented) behavior is actually more useful,
since it allows both options to be specified in Mmakefiles or
Mercury.options files, have them be acted on when making dependencies,
but not get error messages about incompatible op mode options.
However, it does mean that "mmc --generate-module-order x.m" would
now try to compile x.m while ignoring the option, whereas previously
it would implicitly act as if the command line were "mmc
--generate-dependencies --generate-module-order x.m". And similarly
for --imports-graph.
Simplify the code that disables smart recompilation when it is not
relevant.
NEWS:
Mention the changes to --generate-module-order and --imports-graph.
compiler/op_mode.m:
Make the opm_top_make functor take an argument that says whether we
are forcing rebuilds or not. The --rebuild option implies we are;
the --make option without --rebuild implies we are not. This replaces
the deleted implication in handle_options.m.
Conform to the name changes in options.m.
compiler/add_type.m:
compiler/compile_target_code.m:
compiler/exception_analysis.m:
compiler/headvar_names.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_errors.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_initial.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/unused_args.m:
Replace tests of op_mode options with tests of the op_mode itself.
In mercury_compile*.m, get the op_mode to the places that now need it.
In a few places in make.*.m, replace code that sets op_mode options
(temporarily, for the duration of an operation) with code that sets
the op_mode itself.
compiler/globals.m:
Add the now-needed capability to set the op_mode.
compiler/compute_grade.m:
New module containing all the code previously in handle_options.m
that concern grades.
compiler/libs.m:
compiler/notes/compiler_design.html:
Include and document the new module.
compiler/compiler_util.m:
Since both handle_options.m and compute_grade.m now need to be able
to record errors, move the predicates that handle_options.m used to use
for this purpose to this module, which already contains related predicates.
Generalize the moved predicates, so they can be used from phases other than
option processing.
compiler/handle_options.m
Remove the moved code.
compiler/exception_analysis.m:
compiler/file_names.m:
compiler/file_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_user.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
compiler/mercury_compile_front_end.m:
compiler/module_cmds.m:
compiler/options.m:
compiler/tabling_analysis.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
Conform to the above, and/or delete unneeded imports.
compiler/globals.m:
Put the op_mode into the globals structure.
compiler/handle_options.m:
Invoke the code that computes the op_mode *before* creating the globals.
Delete the code duplication concerning the computation of the Link flag.
compiler/op_mode.m:
New module containing the definition of the op_mode type,
and the predicate that figures out the op_mode from the values of options.
These are taken from mercury_compile.m, and the latter is adapted
to work on the option_table, not the globals, since it is now invoked
as *part* of the code to build up the globals.
compiler/libs.m:
compiler/notes/compiler_design.html:
Include the new module.
Do not include the atsort.m module in the libs package, since it
hasn't been used in a long time, and its inclusion adds to the bulk
of the compiler executable without any compensating gain.
compiler/mercury_compile.m:
Delete the code now in op_mode.m.
Conform to the changes above.
compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
Conform to the changes above.
compiler/mercury_compile_erl_back_end.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
Standardise dividing lines.
compiler/handle_options.m:
As above.
Generate warnings the same way as we generate errors, since unlike strings,
error_specs can support the distinction.
Use more consistent phraseology in error messages.
Use auxiliary predicates to lookup up bool, int, string and accumulating
options, thus factoring out some old common code.
compiler/error_util.m:
Add a way to assign a phase to errors discovered during option processing.
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile.m:
Conform to the changes in handle_options.m.
compiler/make.m:
Fix white space.
Convert (C->T;E) to (if C then T else E).
Avoid the use of DCGs.
Rename some predicates to avoid ambiguities.
Delete some unused predicate arguments.
Replace several lambdas with named predicates.
Avoid the use of solutions.m.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_managed.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/ilds.m:
Delete the modules making up the MLDS->IL code generator.
compiler/globals.m:
compiler/prog_data.m:
Delete IL as a target and foreign language.
compiler/prog_io_pragma.m:
Delete the max_stack_size/1 foreign proc attribute. This was only
ever required by the IL backend.
compiler/options.m
Delete options used for the IL backend.
compiler/write_deps_file.m:
Don't generate mmake targets for .il files etc.
compiler/*.m:
Conform to the above changes.
compiler/notes/compiler_design.html
compiler/notes/work_in_progress.html
Conform to the above changes.
library/*.m:
Delete IL foreign_proc and foreign_export pragmas.
README.DotNet:
Delete this file.
browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
Conform the above changes.
configure.ac:
Don't check that IL is a supported foreign language when performing the
up-to-date check.
Delete the '--enable-dotnet-grades' option.
scripts/Mmake.vars.in:
Delete variables used for the IL backend (and in on case by the Aditi
backend).
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.rules:
scripts/canonical_grade.sh-subr:
tools/bootcheck:
Delete stuff related to the 'il' and 'ilc' grades.
doc/reference_manual.texi:
Delete the documentation of the 'max_stack_size' option.
doc/user_guide.texi:
Delete stuff related to the IL backend.
tests/hard_coded/csharp_test.{m,exp}:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/valid/csharp_hello.m:
Delete these tests: they are no longer relevant.
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/intermod_foreign_type2.m:
tests/hard_coded/lp.m:
tests/hard_coded/user_compare.m:
tests/invalid/foreign_type_2.m:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/invalid/foreign_type_visibility.m:
tests/invalid/illtyped_compare.{m,err_exp}:
tests/submodules/external_unification_pred.m
tests/valid/big_foreign_type.m
tests/valid/solver_type_bug.m
tests/valid_seq/foreign_type_spec.m
tests/valid_seq/intermod_impure2.m
Delete IL foreign_procs where necessary.
tests/hard_coded/Mmakefile
tests/invalid/Mercury.options
tests/invalid/Mmakefile
tests/submodules/Mmakefile
tests/valid/Mercury.options
tests/valid/Mmake.valid.common
tests/valid/Mmakefile
tests/valid_seq/Mmakefile
tests/valid_seq/Mercury.options
Conform to the above changes.
After my earlier changes to the item list, we used module_defns for only
two things: recording when one module includes another, and recording
when one module imports or uses another. After this diff, both those
pieces of information are stored separately in each item block.
This has two benefits.
The first benefit is that it allows us to use the type system to enforce
structural invariants about where include_module, import_module and use_module
declarations may appear. The one invariant that we now enforce is that
optimization files may not contain either include_module or import_module
declarations, though they may contain use_module declarations. I suspect that
there are also similar invariants about interface files, but finding them
requires something like this change.
The second benefit is that it allows traversals of item blocks to scan
only the part of the item block that may contain the object of interest.
While reading in interface and optimization files, we used to scan the
full item list several times to find included and imported modules; those
scans can now look at just the relevant information. Since the item lists
that need to be processed usually include all the declarations in a
substantial number of other modules, including some (such as list.m) that
have LOTS of declarations, the speedup can be substantial. On tools/speedtest,
the speedup is 1.5%.
compiler/prog_item.m:
Make the change described above.
Provide utility predicates on the new types representing include_module,
import_module and use_module declarations.
Move an old utility predicate from here to prog_io.m, since only prog_io.m
uses it.
compiler/module_imports.m:
Several fields of the module_imports type contained sets of module names,
but stored them as lists. Change these to actual sets, to distinguish them
from the lists whose order is actually important. (Basically, the order
of processing .trans_opt files is important, but the order in which
we read in .int0, .int3, .int2, .int and .opt files isn't.) In several
places, this also avoids the need for conversions of lists to sets
for set operations, and then back to lists.
compiler/modules.m:
This module had several predicates that processed list of module names.
Make these operate on sets of module names instead, and break each of them
into two predicates: one that decides whether there is a next module name,
and if yes whether it has been processed already, and one to do the actual
processing if needed. This avoid the need for excessive indentation.
The code that discovers what other modules' interface files may need
to be read is now simpler due to the updated item_block structure.
Remove the submodule whose job it was to discover what modules are included
in items or item blocks, since that task has now become trivial, and is
now done by a utility predicate in prog_item.m. Since this was the second
last submodule (of the original eight), the last submodule is now the
whole module. Therefore this module now has significantly greater cohesion
than it had before.
compiler/write_module_interface_files.m:
compiler/prog_io_item.m:
Parse include_module, import_module and use_module declarations as
markers, not as items.
compiler/prog_io.m:
Expect include_module, import_module and use_module declarations as
markers, not as items.
compiler/split_parse_tree_src.m:
Discover included submodules more simply with the updated item_block
structure.
compiler/compile_target_code.m:
Put the arguments of the predicates in this module in a more standard
order.
compiler/recompilation.version.m:
Conform to the above changes. Note a possible bug.
Use a bespoke type to replace some bools.
compiler/check_raw_comp_unit.m:
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/equiv_type.m:
compiler/generate_dep_d_files.m:
compiler/get_dependencies.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_to_mercury.m:
compiler/module_deps_graph.m:
compiler/module_qual.m:
compiler/prog_io_find.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/trans_opt.m:
compiler/write_deps_file.m:
Conform to the above changes.
mdbcomp/sym_name.m:
Provide a utility predicate to get the set of ancestors of a module
as a set as well as a list.
tests/invalid/exported_unify3.err_exp:
tests/invalid/ii_parent.ii_child.err_exp:
Update the expected error messages, which refer to line numbers in
.int0 files, which have now changed, as we now put all import_module
declarations before ordinary items.
(Error messages shouldn't refer to automatically generated files,
but that is a separate concern.)
The predicates in modules.m that generate .dep and .d files are independent
of the rest of that module, so moving them out into a new module improves
both modules' cohesion.
compiler/generate_dep_d_file.m:
New module containing the code moved out of modules.m, as well as
some code moved here from module_deps_graph.m, since it was called
only from here.
Give some predicates more descrriptive names.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Mention the new module.
compiler/modules.m:
Remove the stuff moved to generate_dep_d_file.m.
compiler/make.program_target.m:
Move here a predicate from module_deps_graph.m, since it was only called
from here.
compiler/write_deps_file.m:
Move here a predicate from module_deps_graph.m, since it was only called
from here.
compiler/module_deps_graph.m:
Remove the stuff moved to generate_dep_d_file.m, make.program_target.m
or write_deps_file.m. What is left does only one job, and it is needed
by both generate_dep_d_file.m and make.program_target.m.
compiler/mercury_compile.m:
Conform to the changes above.
When building an executable in the Java grade, the Mercury compiler generates
all the class files in the Mercury subdirectory and then generates a wrapper
script or batch file that points towards these class files. This makes
deploying executables built in the Java grade rather awkward. This change
makes the Mercury compiler package up all the class files for an executable
into a JAR file and modifies the wrapper scripts to point to this JAR file.
NOTE: the JAR file we generate cannot be executed with 'java -jar ...'. This
is because in that mode of operation the Java interpreter ignores all user
classpath settings, such as those that tell the interpreter where the Mercury
standard library is. (We could support this mode of operation by setting any
required library classpath directories in the archive's manifest, but that
would mean either hardcoding installation specific directories in the manifest
or copying any required .jars to a known location relative to the executable's
class files. Generating such self-contained archives may be useful in some
cases, but it is not something this change addresses.)
compiler/compile_target_code.m:
Rename the link target type for Java executables.
Add a predicate for creating Java "executables": this involves generating
an archive (as we do for libraries) and then generating the wrapper script
or batch file.
Simplify some code that generates an error message.
compiler/module_cmds.m:
Change the wrapper scripts for Java executables to point towards
the .jar file generated instead of the class files in the Mercury
subdirectory.
Ditto for the wrapper batch files.
compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
Conform to the above changes.
README.Java:
Mention that class files for the executable are packaged up in
an archive.
NEWS:
Announce this change.
Add two new options for querying the compiler. The first new option,
--output-target-arch, prints the target architecture. This is useful in
situations where you are working directly with the contents of the Mercury
subdirectory and --use-grade-subdirs is enabled. (The directory names
generated by --use-grade-subdirs include the target architecture.) The second
new option, --output-class-dir, deals with a more specific instance of the
above. It prints out the name of the directory in which the Mercury compiler
places generated Java class files.
Replace the use of 'fullarch' by 'target_arch' throughout the compiler.
(We still currently support '--fullarch' as a synonym for '--target-arch'
but that too will eventually be dropped.)
compiler/options.m:
Add the new options.
compiler/mercury_compile.m:
Implement the new options.
s/fullarch/target_arch/
Add an XXX comment about an inaccurate error message.
compiler/handle_options.m:
compiler/compile_target_code.m:
compiler/file_names.m:
compiler/make.program_target.m:
Conform to the above changes.
doc/user_guide.texi:
Document the new options.
Once upon a time, modules.m contained all the code in the compiler that dealt
with interface files, and it was by far the biggest module in the compiler
(almost 9000 lines). Once before, I moved cohesive bunches of functionality
out of modules.m into new modules, such as file_util.m and module_cmds.m.
This diff does likewise, creating three new modules.
Besides that main task, it has two minor algorithmic changes that should
have no overall effect on correctness. First, it merges some traversals of
the item list, which should yield a very minor speedup, and second,
in order to avoid the need for an undesirable module import, it eliminates
an unnecessary sorting of the item list that we used to do when reading
in interface files. (The sorting makes sense only when *creating* interface
files).
This diff also gives more meaningful names to some predicates.
compiler/module_deps_graph.m:
This new module defines the module dependency graph, and provides
predicates for building it and using it.
compiler/write_module_iterface_files.m:
This new module does what its name says it does.
compiler/item_util.m:
This new module contains utility predicates that deal with items that are
now needed in more than one module.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Include the new modules.
compiler/write_deps_file.m:
Move some predicates here from modules.m, since they belong here.
E.g. one prints .d files, and related code to print .dv and .dep files
was already here.
compiler/mercury_compile.m:
Move a predicate here from modules.m, since it was only called from here,
and related code is also here.
compiler/prog_item.m:
Move a predicate here from modules.m, since it is a utility predicate
for a type that is defined here.
compiler/prog_type.m:
Move a predicate here from modules.m, since it is a utility predicate
for types, like all the other predicates in this module.
compiler/modules.m:
Remove the code that is now in other modules. Impose some structure
on the remaining code. (It used to be too jumbled up to make much sense of,
which was one reason why working with this code was unnecessarily hard).
compiler/deps_map.m:
Note the relationship to the new module module_deps_graph.m.
compiler/*.m:
Import the new modules as well as (or instead of) modules.m, and/or conform
to new names for predicates.
No progress has been made on the LLDS->x86_64 backend since the initial work on
it and it is now more have a maintenance headache then anything else.
compiler/llds_to_x86_64.m:
compiler/llds_to_x86_64_out.m:
compiler/x86_64_instrs.m:
compiler/x86_64_out.m:
compiler/x86_64_regs.m:
Delete these modules.
compiler/globals.m:
Delete the x86_64 target type.
compiler/*.m:
Conform to the above changes.
Uses of --no-libgrade and --libgrade in Mercury.options files should override
any detected library grades. For example, in a directory with a Mercury.options
file that contains
MCFLAGS = --no-libgrade
we should expect "mmc --output-libgrades" to print nothing. This was not the case.
compiler/mercury_compile.m:
Do not combine the detected library grade flags with the ones from
the command line options. We need to keep them separate because
they must be injected into the overall set of command line options
before any flags from Mercury.options files.
Add a note about a theoretical problem with DEFAULT_MCFLAGS and
detected library grades. It is not a problem in practice because
the entire point of detected library grades was to avoid passing
any information about library grades via DEFAULT_MCFLAGS.
Thread the set of flags from detected grades down to places where
they are needed.
If the library grade set is empty, don't print out a single newline
with --output-libgrades.
compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
Pass the set of detected grade flags to where they are needed.
Allow the possibility of the compiler automatically deciding what command(s) to
use to install files and directories instead of using the value of
--install-command (which defaults to "cp"). The eventual intention (NYI) is
that in the absence of a value for --install-command, the compiler will choose
an appropriate command based on the setting of --host-env-type (and possibly
some other stuff, for the example the OS version).
The rationale for all this to try to improve the current situation on Windows
(in the absence of Cygwin or MSYS) where file copying is a bit of a mess. It
should also mean that the same Mercury installation can be more easily used
from both MSYS and cmd.exe.
NOTE: for the moment --install-command is still specified in Mercury.config.
This will be removed in a later change and the compiler will default to
choosing automatically.
compiler/globals.m:
Add a type whose values describe how we should install files and
directories.
Add a field of that type, file_install_cmd, to the globals structure.
Add access predicates.
compiler/handle_options.m:
Set the new field in the globals.
compiler/file_util.m:
Provide functions for constructing a command line for installing files
and directories based on the value of the file_install_cmd field in
the globals.
compiler/make.program_target.m:
compiler/module_cmds.m:
Use the new functions in file_util.m.
As discussed in the recent Mercury meeting, remove support for the GCC backend.
It was very much out of date and supporting it proprerly would means having to
track changes to GCC's internals. Furthermore, its presence complicates
building the compiler.
The main thing this change does not address is the fact that we invoke
the compiler through C code, e.g. main.c in the top-level of the source
tree. This was required by the GCC backend and can now be removed, but
I will do that as a separate change.
configure.ac:
Mmake.common.in:
scripts/Mmake.rules:
compiler/Mercury.options:
compiler/Mmakefile:
compiler/gcc.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mlds_to_gcc.m:
Delete the files containing the GCC backend.
compiler/options.m:
compiler/handle_options.m:
Delete support for `--target asm' and `--pic'.
(The latter was only used by the GCC backend.)
compiler/*.m:
doc/user_guide.texi:
compiler/notes/comiler_design.html:
compiler/notes/work_in_progress.m:
Conform to the above change.
README.gcc-backend.m:
Delete this file.
Branches: main
Prevent interleaved error message output when using parallel `mmc --make'.
compiler/make.m:
Add a field to `make_info' to hold an inter-process lock.
compiler/make.util.m:
Reuse the `job_ctl' type as the stdout lock. Add predicates to acquire
and release the lock.
Make `foldl2_maybe_stop_at_error_parallel_processes' set the stdout
lock in `make_info' for child processes to see.
Acquire and release the stdout lock in various predicates that write
errors messages.
compiler/make.module_target.m:
compiler/make.program_target.m:
Conform to changes.
Branches: main, 11.07
Fix bug #252: support parallel builds for the various build_all targets with
mmc --make.
compiler/make.program_target.m:
As above.
Branches: main, 11.07
Fix problems with nested sub-modules and parallel mmc --make.
The interface and intermediate target files for nested sub-modules
are built as part of their parent modules. In sequential mode, there is
no harm in trying to build those files separately, but with parallel
make, two processes may try to create the files from the same parent
module simultaneously.
compiler/make.dependencies.m:
Add a predicate to remove nested modules from a list.
compiler/make.program_target.m:
Remove nested modules from the list of intermediate targets to
create.
Remove nested modules from the list of interface files to create.
Estimated hours taken: 6
Branches: main
compiler/*.m:
Convert almost all remaining modules in the compiler to use
"$module, $pred" instead of "this_file" in error messages.
In a few cases, the old error message was misleading, since it
contained an incorrect, out-of-date or cut-and-pasted predicate name.
tests/invalid/unresolved_overloading.err_exp:
Update an expected output containing an updated error message.
Branches: main
Improve consistency amongst the standard library modules.
library/array2d.m:
library/bitmap.m:
library/hash_table.m:
library/store.m:
library/thread.semaphore.m:
library/version_array.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
Use the name "init" for predicates and functions that create new empty
data structures instead of the name "new". (The majority of standard
library modules already use the former.)
Mark the "new" versions as obsolete.
library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/io.m:
library/thread.mvar.m:
browser/declarative_execution.m:
compiler/make.m:
compiler/make.program_target.m:
ssdb/ssdb.m:
Conform to the above changes.
NEWS:
Announce the above changes.
Branches: main
Change the argument order of many of the predicates in the map, bimap, and
multi_map modules so they are more conducive to the use of state variable
notation, i.e. make the order the same as in the sv* modules.
Prepare for the deprecation of the sv{bimap,map,multi_map} modules by
removing their use throughout the system.
library/bimap.m:
library/map.m:
library/multi_map.m:
As above.
NEWS:
Announce the change.
Separate out the "highlights" from the "detailed listing" for
the post-11.01 NEWS.
Reorganise the announcement of the Unicode support.
benchmarks/*/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
extras/*/*.m:
mdbcomp/*.m:
profiler/*.m:
tests/*/*.m:
ssdb/*.m:
samples/*/*.m
slice/*.m:
Conform to the above change.
Remove any dependencies on the sv{bimap,map,multi_map} modules.