library/varset.m:
We have long had two versions of the lookup_name function, and of
the equivalent lookup_name predicate, with the difference being
that one version had an extra argument that specified to prefix
for the names to be constructed for not-explicitly-named variables.
Obsolete the function and the predicate with this extra argument
in favor of a new function/predicate pair, whose shared name is
lookup_name_default_prefix.
Act on an old sortof-XXX by changing the order of arguments of the
set_bindings predicate to make it state-variable-friendly.
Improve some comments.
NEWS.md:
Document the above changes.
library/term.m:
Document the var and var_supply types at their definitions.
Don't intersperse obsolete pragmas together with predicate/function
declarations.
Update some old comments.
compiler/lp_rational.m:
compiler/mlds_to_target_util.m:
Replace calls to the newly-obsoleted function and predicate.
compiler/intermod.m:
We put analysis results into both .opt and .trans_opt files,
but a large chunk of the code that did this was duplicated.
Factor out the commonalities.
Separate the code that gathers the analysis results, and the code
that writes out those results. This allows us to avoid passing
the I/O state through large parts of this module.
Delete the code in this module that wrote out the results of the
termination2 analysis; use the existing code in parse_tree_out_pragma.m
instead.
We put both declarations and definitions of predicates into .opt files.
Call the definitions "definitions" and not "clauses", since the definitions
of predicates consist not of clauses, but of foreign_procs or promises.
Put the declarations before the definitions of predicates in
intermod_infos, since this is the usual order in Mercury programs.
Print foreign_import_module items just after Mercury import or use items,
since they do similar jobs.
Give some predicates better names.
compiler/parse_tree_out.m:
Print foreign_import_module items just after Mercury import or use items,
since they do similar jobs.
Put blank lines between blocks containing different kinds of analysis
results in .opt and .trans_opt files, to match the corresponding output
generated by intermod.m.
Add a new auxiliary predicate for this, and export it to intermod.m.
compiler/parse_tree_out_pragma.m:
Simplify the writing out of many kinds of pragmas using string.format
and io.format.
compiler/rat.m:
Replace write_rat with to_rat_string, which is strictly more flexible.
Rename to_string to to_arith_string, since the job it does is
quite different from to_rat_string's job.
Use a consistent set of variable names.
Delete unneeded module qualifications.
compiler/lp_rational.m:
Simplify code that outputs things.
compiler/term_errors.m:
Improve the style of some comments.
compiler/check_typeclass.m:
compiler/lp_rational.m:
compiler/matching.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/proc_gen.m:
compiler/stack_opt.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/unused_imports.m:
As above.
Use io.format to replace several calls to io.* where possible.
Give some predicates more specific names to avoid ambiguity.
Reorder the arguments of some predicates to allow higher order programming
in future.
Delete some functions that duplicate the functionality of predicates.
Rename VarSet to Varset in several places.
Put all debug predicates in a single group in each module.
compiler/Mercury.options:
Do not specify --no-warn-implicit-stream-calls for the modules above.
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/prog_item.m:
Add types for representing .opt and .trans_opt files that specify
exactly what kinds of items may appear in them.
Provide a mechanism for representing just the kinds of pragmas
that we may want to put into .opt files to represent a predicate marker.
To make the above possible, generalize the item_pragma_info type.
Do not store the "maybe attributes" field in all pragmas; store it
in just the one pragma for which it had pragma-specific code (which code
is dubious anyway). Its only use is to suppress error messages about
incorrect pragmas if that pragma was created by the compiler, on the
theory that the user cannot do anything about any such error messages.
However, if such errors are never reported to anyone, then they won't
be fixed. I think it is better to allow such problems to be discovered,
even if they cause a bit of annoyance to the discoverer. The default
content of the field as set by the parser, item_origin_user, can be
misleading anway; it is correct when the pragma is read in from a .m file
or from a .int* file, but it is wrong when read in from a .*opt file,
since the contents of those are decided by the compiler.
Store a varset and tvarset in structure sharing and reuse pragmas,
since without this, one cannot print them out properly.
compiler/intermod.m:
Change the predicates that write out .opt and .trans_opt files
to return as large a fraction of the parse trees of those files
as possible, as a step towards generating those files not directly,
but by building and then writing out those parse trees. For now,
we cannot do this fully for .opt files, because for a few item kinds,
it is far from obvious how to represent as a item what we write out.
Leave the opening and closing of the file streams for writing out
.opt and .trans_opt files to our caller, because for .opt files,
this allows us to avoid having to open the file *twice*.
Put the output of result-of-analysis pragmas into a standard order.
Factor out as common code the process for deciding what should go into
.opt files.
Give a field of the intermod_info structure a more precise name.
compiler/mercury_compile_front_end.m:
Hold the stream of the .opt file open between the two different pieces
of code that write out the two different parts of .opt files.
If --experiment5 is set, write out the parse tree of the .opt file
to the .optx file, to enable comparison with the .opt file.
compiler/mercury_compile_middle_passes.m:
If --experiment5 is set, write out the parse tree of the .trans_opt file
to the .trans_optx file, to enable comparison with the .trans_opt file.
Reset a memo table for structure_{sharing,reuse}.analysis.
compiler/structure_reuse.analysis.m:
compiler/structure_sharing.analysis.m:
Don't take an I/O state pair as arguments, since we needed them *only*
for that reset, and for progress messages.
Give the main predicates more descriptive names.
compiler/trailing_analysis.m:
Give the main predicate a more descriptive names.
compiler/closure_analysis.m:
Don't take an I/O state pair as arguments, since we needed them *only*
for progress messages.
compiler/add_pragma.m:
Don't ignore an error, since one of the other changes in this diff
could have fixed its cause.
compiler/convert_interface.m:
Export utility functions needed by code added by this diff.
ompiler/lp_rational.m:
Tighten the inst of an output argument for use by intermod.m.
Bring programming style up to date.
compiler/parse_pragma.m:
Don't put a maybe attributes field into item_pragma_infos.
Include the varset in structure sharing and reuse pragmas.
Use simplest_spec where possible.
compiler/parse_tree_out.m:
Add predicates for writing out the new parse trees of .opt and
.trans_opt files.
compiler/parse_tree_out_pragma.m:
Add predicates needed by the new code in parse_tree_out.m.
compiler/add_mutable_aux_preds.m:
compiler/canonicalize_interface.m:
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/item_util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
Conform to the changes above.
compiler/simplify_goal_call.m:
If the --warn-suspicious-recursion option is set, and if the warning
isn't disabled, generate warnings for two different kinds of suspicious
recursion. They are both related to, but separate from, the warning
we have long generated for infinite recursion, which occurs when
the input args of a recursive call are the same as the corresponding
args in the clause head.
Both kinds suspicious recursion look at the input args of a recursive call
that are NOT the same as the corresponding args in the clause head.
Both require these args to have non-unique modes. (If they have unique
modes, then the depth of the recursion may be controlled by state outside
the view of the Mercury compiler, which means that a warning would be
likely to be misleading.)
The first kind is when all these args use state variable notation.
Most of the time, we use state var notation to denote the data structures
updated by the recursive code; having variables using such notation
*controlling* the recursion is much less common, and much more likely
to be unintended. The motivation for the new option was this infinitely
looping code, which resulted from neglecting to s/[X | Xs]/Xs/ after
cutting-and-pasting the clause head to the recursive call.
p([X | Xs], !S) :-
...,
p([X | Xs], !S).
The other kind of suspicious recursive call we warn about involve
input arguments where the base names of the input arguments (the part
before any numeric suffixes) seem be switched between the clause head
and the recursive call, as here:
q(As0, Bs0, ...) :-
...,
q(Bs1, As, ...).
compiler/mercury_compile_main.m:
Disable style warnings when invoked with --make-optimization-interface
or its transitive variant. Without this, warnings about suspicious
recursion would get reported in such invocations.
Move a test from a callee to a caller to allow the callee to be
less indented.
compiler/options.m:
Export functionality to mercury_compile_main.m to make the above possible.
library/string.m:
Add a predicate to convert a string to *reverse* char list directly.
Note a discrepancy between the documentation and the implementation
of the old predicate the new one is based on (which converts a string
to a forward char list).
NEWS:
Note the new predicate in string.m.
compiler/cse_detection.m:
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/distance_granularity.m:
compiler/frameopt.m:
compiler/inst_util.m:
compiler/lp_rational.m:
compiler/matching.m:
compiler/modes.m:
compiler/old_type_constraints.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_arguments.m:
compiler/recompilation.usage.m:
compiler/stratify.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.indirect.m:
compiler/typeclasses.m:
compiler/use_local_vars.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/calendar.m:
library/diet.m:
library/lexer.m:
library/parser.m:
library/parsing_utils.m:
library/ranges.m:
library/set_ctree234.m:
library/set_tree234.m:
library/string.parse_util.m:
library/tree234.m:
library/varset.m:
mdbcomp/program_representation.m:
mdbcomp/rtti_access.m:
profiler/demangle.m:
Avoid warnings for suspicious recursion. In most cases, do this by
wrapping disable_warning scopes around the affected recursive calls;
in a few cases, do this by changing the code.
tests/warnings/suspicious_recursion.{m,exp}:
A test case for the new warnings.
tests/warnings/Mercury.options:
tests/warnings/Mmakefile:
Enable the new test case.
All of these places were pointed out by the new --inform-incomplete-switch
option.
compiler/add_pred.m:
compiler/goal_form.m:
compiler/intermod.m:
compiler/ml_elim_nested.m:
compiler/post_term_analysis.m:
compiler/prog_mode.m:
compiler/prog_type.m:
compiler/unneeded_code.m:
compiler/var_locn.m:
As above. In some cases, this meant adding the missing cons_ids
with a simple `fail' as the goal. In other cases, it meant adding
comments on the `fail'. In yet other cases, it involved replacing
semidet predicates with functions returning bools.
In a few places, the code for the previously-missing cons_id
throws an exception.
In prog_mode.m and var_locn.m, the code for some previously-missing
cons_ids is neither `fail' nor an abort, but code that does the actual
job of the predicate it is in. In these cases, the fact that this code
was previously missing seems to have been a bug.
compiler/lp_rational.m:
Delete unnecessary module qualification on pred and func declarations.
Fix some comments.
compiler/rtti_to_mlds.m:
deep_profiler/html_format.m:
Fix some comments.
compiler/lp.m:
Avoid using =<, = and >= as function symbols.
compiler/lp_rational.m:
Avoid using "constant" as a type name (and "coefficient", for the sake
of symmetry).
compiler/mcsolver.m:
Avoid using == as a function symbol.
Convert (C->T;E) to (if C then T else E).
compiler/term_constr_build.m:
compiler/term_pass1.m:
Conform to the changes above.
compiler/lp.m:
compiler/term_pass1.m:
compiler/term_pass2.m:
compiler/term_traversal.m:
compiler/termination.m:
When these modules were written, you could add diagnostics to code
only if that code had access to the I/O state. Since we now have trace
goals, this is unnecessary.
Simplify some code.
compiler/lp_rational.m:
Fix programming style.
Branches: main, 11.07 (partial)
Fix bug #248: make the argument order of the singleton_set/2 predicates in the
various set modules in the standard library consistent. (This breaks backwards
compatibility but in a fairly minor way.)
Add the predicate is_singleton/2 to those set modules that do not already
provide it.
Fix a bug in the implementation of set_unordlist.singleton_set/2.
library/set.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_unordlist.m:
Swap the argument order of singleton_set/2.
Add is_singleton/2 where it wasn't already present.
library/set_unordlist.m:
Fix a bug: singleton_set/2 failed to take account of
the fact that the representation could contain duplicates
in the singleton_setT::out, set_unordlist(T)::in) mode.
The fix is to sort and remove the duplicates before checking
whether the set is singleton.
NEWS:
Announce the above changes.
library/eqvclass.m:
library/tree234.m:
compiler/accumulator.m:
compiler/code_info.m:
compiler/graph_colour.m:
compiler/higher_order.m:
compiler/lp_rational.m:
compiler/ml_tag_switch.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/proc_gen.m:
compiler/prog_mode.m:
compiler/term_pass1.m:
compiler/type_constraints.m:
compiler/unneeded_code.m:
compiler/var_locn.m:
deep_profiler/autopar_costs.m:
deep_profiler/var_use_analysis.m:
tests/general/set_test.m:
Conform to the above changes.
tests/hard_coded/Mmakefile:
tests/hard_coded/singleton_dups.{m,exp}:
Add a regression test for the problem with set_unordlist.singleton_set/2.
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
Change the argument ordering of predicates in the set module.
library/set.m:
Change predicate argument orders to match the versions
in the svset module.
Group function definitions with the corresponding predicates
rather than at the end of the file.
Delete Ralph's comments regarding the argument order in the
module interface: readers of the library reference guide are
unlikely to be interested in his opinion of the argument ordering
ten or so years ago.
Add extra modes for set.map/3 and set.map_fold/5.
library/svset.m:
library/eqvclass.m:
library/tree234.m:
library/varset.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
mdbcomp/trace_counts.m:
extras/moose/grammar.m:
extras/moose/lalr.m:
extras/moose/moose.m:
tests/hard_coded/bitset_tester.m:
Conform to the above change.
NEWS:
Announce the above changes.
Branches: main
Change the argument order of predicates in the varset module to make
them more conducive to the use of state variable notation.
library/varset.m:
As above.
library/parser.m:
library/term_io.m:
library/svvarset.m:
compiler/*.m:
samples/interpreter.m:
tests/debugger/interpreter.m:
tests/general/interpreter.m:
tests/hard_coded/bigtest.m:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/lp.m:
tests/hard_coded/pprint_test.m:
tests/hard_coded/type_spec_ho_term.m:
Conform to the above change and remove dependencies on the svvarset
module.
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.
Estimated hours taken: 2
Branches: main
Add the predicates sorry, unexpected and expect to library/error.m.
compiler/compiler_util.m:
library/error.m:
Move the predicates sorry, unexpected and expect from compiler_util
to error.
Put the predicates in error.m into the same order as their
declarations.
compiler/*.m:
Change imports as needed.
compiler/lp.m:
compiler/lp_rational.m:
Change imports as needed, and some minor cleanups.
deep_profiler/*.m:
Switch to using the new library predicates, instead of calling error
directly. Some other minor cleanups.
NEWS:
Mention the new predicates in the standard library.
Estimated hours taken: 16
Branches: main
Implement several more changes that together speed up compilation time
on training_cars_full by 12%, and also improve tools/speedtest -h by 7.2%
and tools/speedtest by 1.6%.
The first change is designed to eliminate the time that the compiler spends
constructing error messages that are then ignored. The working predicates of
prog_io_sym_name used to always return a single result, which either gave
a description of the thing being looked, or an error message. However,
in many places, the caller did not consider not finding the thing being looked
for to be an error, and thus threw away the error message, keeping only
the "not found" indication. For each predicate with such callers, this diff
provides a parallel predicate that indicates "not found" simply by failing.
This allows us to eliminate the construction of the error message, the
preparation for the construction of the error message (usually by describing
the context), and the construction of the "ok" wrapper.
The second change is to specialize the handling of from_ground_term_construct
scopes in the termination analyzer. To make this easier, I also cleaned up
of the infrastructure of the termination analyzer.
The third change is to avoid traversing from_ground_term_construct scopes
in quantification.m when finding the variables in a goal, since termination
analysis no longer needs the information it gathers.
The fourth change is to avoid traversing second and later conjuncts in
conjunctions twice. The first step in handling conjunctions is to call
implicitly_quantify_conj, which builds up a data structure that pairs each
conjunct with the variables that occur free in all the conjuncts following it.
However, after this was done and each conjunct was annotated with its
nonlocals, we used to compute the variables that occur free in the conjunction
as a whole from scratch. This diff changes the code so that we now compute that
set based on the information we gathered earlier, avoiding a redundant
traversal.
The fifth change is to create specialized, lower-arity versions of many of
the predicates in quantification.m. These versions are intended for traversals
that take place after the compiler has replaced lambda expressions with
references to separate procedures. These traversals do not need to pass around
arguments representing the variables occurring free in the (now non-existent)
lambda expressions.
compiler/prog_io_sym_name.m:
Make the first change described above.
Change some predicate names to adopt a consistent naming scheme
in which predicates that do the same job and differ only in how they
handle errors have names that differ only in a "try_" prefix.
Add some predicate versions that do common tests on the output
of the base versions. For example, try_parse_sym_name_and_no_args
is a version of try_parse_sym_name_and_args that insists on finding
an empty argument list.
Remove the unused "error term" argument that we used to need a while
ago.
Move some predicate definitions to make their order match the order of
their declarations.
Turn a predicate into a function for its caller's convenience.
compiler/term_constr_build.m:
Make the second change described above by modeling each
from_ground_term_construct scope as a single unification,
assigning the total size of the ground term to the variable being
built.
compiler/term_constr_util.m:
Put the arguments of some predicates into a more standard order.
compiler/lp_rational.m:
Change the names of some function symbols to avoid both the use of
graphic characters that require quoting and clashes with other types.
Change the names of some predicates to make their purpose clear,
and to avoid ambiguity.
compiler/quantification.m:
Make the third, fourth and fifth changes described above.
compiler/*.m:
Conform to the changes above.
Estimated hours taken: 4
Branches: main
Further compiler speedups.
library/varset.m:
Speed up predicates by avoding making the same decisions over and over
again.
library/tree234.m:
library/map.m:
NEWS:
Add tree234.map_values_only and map.map_values_only.
compiler/add_pragma.m:
compiler/analysis.m:
compiler/code_info.m:
compiler/cse_detection.m:
compiler/cse_detection.m:
compiler/equiv_type_hlds.m:
compiler/global_data.m:
compiler/hlds_out.m:
compiler/hlds_rtti.m:
compiler/inst_graph.m:
compiler/lp_rational.m:
compiler/hlds_out.m:
compiler/mlds_to_il.m:
compiler/modules.m:
compiler/par_conj_gen.m:
compiler/polymorphism.m:
compiler/prog_data.m:
compiler/prog_type_subst.m:
compiler/recompilation.version.m:
compiler/simplify.m:
compiler/stack_layout.m:
compiler/type_util.m:
compiler/unneeded_code.m:
Use the new predicates.
compiler/mark_static_terms.m:
Do not bother traversing from_ground_term_construct scopes.
Remove a redundant test.
compiler/ml_unify_gen.m:
Speed up a predicate by avoding making the same decisions over and over
again.
compiler/mlds.m:
Factor out some code.
compiler/typecheck_info.m:
Operate on vartypes directly as maps; don't transform them
unnecessarily into association lists.
Do not bother to apply empty substitutions.
Estimated hours taken: 20
Branches: main
Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.
Act on the output generated by this option.
compiler/simplify.m:
Implement the new option.
Fix an old bug that could cause us to generate warnings about code
that was OK in one duplicated copy but not in another (where a switch
arm's code is duplicated due to the case being selected for more than
one cons_id).
compiler/options.m:
Add the new option.
Add a way to test for the bug fix in simplify.
doc/user_guide.texi:
Document the new option.
NEWS:
Mention the new option.
library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
Convert if-then-elses to switches at most of the sites suggested by the
new option. At the remaining sites, switching to switches would have
nontrivial downsides. This typically happens with the switched-on type
has many functors, and we treat one or two specially (e.g. cons/2 in
the cons_id type).
Perform misc cleanups in the vicinity of the if-then-else to switch
conversions.
In a few cases, improve the error messages generated.
compiler/accumulator.m:
compiler/hlds_goal.m:
(Rename and) move insts for particular kinds of goal from
accumulator.m to hlds_goal.m, to allow them to be used in other
modules. Using these insts allowed us to eliminate some if-then-elses
entirely.
compiler/exprn_aux.m:
Instead of fixing some if-then-elses, delete the predicates containing
them, since they aren't used, and (as pointed out by the new option)
would need considerable other fixing if they were ever needed again.
compiler/lp_rational.m:
Add prefixes to the names of the function symbols on some types,
since without those prefixes, it was hard to figure out what type
the switch corresponding to an old if-then-else was switching on.
tests/invalid/reserve_tag.err_exp:
Expect a new, improved error message.
Estimated hours taken: 0.5
Branches: main
Replace more if-then-elses with switches (particularly on the
type builtin_state/0).
compiler/cse_detection.m:
compiler/deep_profiling.m:
compiler/dependency_graph.m:
compiler/follow_vars.m:
compiler/goal_form.m:
compiler/interval.m:
compiler/live_vars.m:
compiler/lp_rational.m:
compiler/pd_cost.m:
compiler/simplify.m:
compiler/tupling.m:
As above.
Estimated hours taken: 3
Branches: main
Clean up in unused module imports in the Mercury system detected
by --warn-unused-imports.
analysis/*.m:
browser/*.m:
deep_profiler/*.m:
compiler/*.m:
library/*.m:
mdbcomp/*.m:
profiler/*.m:
slice/*.m:
Remove unused module imports.
Fix some minor departures from our coding standards.
analysis/Mercury.options:
browser/Mercury.options:
deep_profiler/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
profiler/Mercury.options:
slice/Mercury.options:
Set --no-warn-unused-imports for those modules that are used as
packages or otherwise break --warn-unused-imports, e.g. because they
contain predicates with both foreign and Mercury clauses and some of
the imports only depend on the latter.
Estimated hours taken: 18
Branches: main
Move the univ, maybe, pair and unit types from std_util into their own
modules. std_util still contains the general purpose higher-order programming
constructs.
library/std_util.m:
Move univ, maybe, pair and unit (plus any other related types
and procedures) into their own modules.
library/maybe.m:
New module. This contains the maybe and maybe_error types and
the associated procedures.
library/pair.m:
New module. This contains the pair type and associated procedures.
library/unit.m:
New module. This contains the types unit/0 and unit/1.
library/univ.m:
New module. This contains the univ type and associated procedures.
library/library.m:
Add the new modules.
library/private_builtin.m:
Update the declaration of the type_ctor_info struct for univ.
runtime/mercury.h:
Update the declaration for the type_ctor_info struct for univ.
runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
Update the definition of MR_Univ.
runtime/mercury_init.h:
Fix a comment: ML_type_name is now exported from type_desc.m.
compiler/mlds_to_il.m:
Update the the name of the module that defines univs (which are
handled specially by the il code generator.)
library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
Conform to the above changes. Import the new modules where they
are needed; don't import std_util where it isn't needed.
Fix formatting in lots of modules. Delete duplicate module
imports.
tests/*:
Update the test suite to confrom to the above changes.
Estimated hours taken: 4
Branches: main
Move the all-solutions predicates from the library module std_util into their
own module, solutions.
Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from
std_util.m into builtin.m.
Add some more utility functions for performing determinism or purity casts.
(The later are primarily intended for use by solver implementors.)
library/std_util.m:
Move the all-solutions predicates into their own module, solutions.m.
For now there are (obsolete) forwarding predicates from this module to
the new one. The forwarding predicates will be included in the
upcoming 0.13 release and then removed in later versions.
Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast
to builtin.m
library/solutions.m:
New file. This is the new home for the all-solutions predicates.
This is pretty much cut and pasted from std_util (with module
qualifiers updated accordingly). I've rearranged the code in a more
top-down fashion as per our current coding standard.
library/builtin.m:
Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and
dynamic_cast/2 to this module.
Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0
and semidet_succeed/0.
Add impure_true/0 and semipure_true/0. These are useful for performing
purity casts, e.g. in solver implementations.
library/library.m:
Add the new module.
NEWS:
Announce the changes.
library/*.m:
Update to conform to the above.
compiler/const_prop.m:
Update evaluate_semidet_call/5 with the new module name for
dynamic_cast.
compiler/*.m:
Module qualify calls to solutions to either disambiguate them from the
versions in std_util (where they weren't module qualified) or change
the module qualifier where they were (to avoid warnings about calls to
the now deprecated versions).
tests/debugger/declarative/solutions.*:
Rename this module as the name conflicts with the new library module.
tests/debugger/declarative/solns.*:
Renamed version of above (with updated expected output).
tests/debugger/declarative/Mmakefile:
Handle the renamed version of the solutions test.
tests/debugger/all_solutions.m:
tests/debugger/declarative/args.m:
tests/debugger/declarative/library_forwarding.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/multisoln_func.m:
tests/invalid/one_member.m:
tests/invalid/promise_equivalent_claueses.m:
tests/valid/simplify_bug2.m:
tests/valid/solv.m:
Update to conform to the above changes.
sample/solutions/*.m:
Update to conform to the above changes.
Estimated hours taken: 4
Branches: main
Various cleanups for the modules in the compiler directory. The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.
compiler/*.m:
Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
appropriate throughout most or the compiler.
Fix inaccurate assertion failure messages, e.g. identifying the
assertion failure as taking place in the wrong module.
Add :- end_module declarations.
Fix formatting problems and bring the positioning of comments
into line with our current coding standards.
Fix some overlong lines.
Convert some more modules to 4-space indentation. Fix some spots
where previous conversions to 4-space indentation have stuffed
the formatting of the code up.
Fix a bunch of typos in comments.
Use state variables in more places; use library predicates
from the sv* modules where appropriate.
Delete unnecessary and duplicate module imports.
Misc. other small cleanups.
Estimated hours taken: 8
Branches: main
compiler/*.m:
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
and 'mer_mode'. This is to avoid the need to parenthesize these type
names in some contexts, and to prepare for the possibility of a parser
that considers those words to be reserved words.
Rename some other uses of those names (e.g. as item types in
recompilation.m).
Delete some redundant synonyms (prog_type, mercury_type) for mer_type.
Change some type names (e.g. mlds__type) and predicate names (e.g.
deforest__goal) to make them unique even without module qualification.
Rename the function symbols (e.g. pure, &) that need to be renamed
to avoid the need to parenthesize them. Make their replacement names
more expressive.
Convert some more modules to four space indentation.
Avoid excessively long lines, such as those resulting from the
automatic substitution of 'mer_type' for 'type'.
Estimated hours taken: lots
Branches: main
Add the first part of the new termination analyser. This includes most
of the argument size analyser and a simple termination checker - I'll
add a more extensive one as part of another diff. The one included here
is only a placeholder and is roughly equivalent to the one used by the
existing termination analyser.
The new analysis abstracts term size relationships over a domain of
(rational) convex constraints. The resulting size relationships are, in
many cases, more precise than we can obtain with the old analysis. This
means that we should be able to prove termination in more cases. The
tradeoff for this increased precision is that the new termination
analysis is slower than the old one. We should also be able to adapt
the new analyser to handle things like higher-order constructs and
intermodule mutual recursion more easily than the old one.
The code for writing termination2_info pragmas to .opt and .trans_opt
files is currently commented out. It will need to stay that way until
after this change bootstraps and after the tests/term directory as been
reworked (the .trans_opt_exp files need to updated and some new test
cases have to added - I'll do this as part of separate diff).
It isn't clear what the relationship between the new analyser and the
existing one should be, so at the moment they are as independent of each
other as possible.
compiler/termination2.m:
New file. Invokes the the other passes of the new analysis
and handles the output of termination2_info pragmas to .opt
and .trans_opt files.
XXX I've disabled the writing out of termination2_info
pragmas to the (transitive-)intermodule optimization files
until I've updated the test suite.
compiler/term_constr_data.m:
New file. Defines the main data structures used by the
new analysis.
compiler/term_constr_initial.m:
New file. Sets up information for builtin and compiler
generated procedures and processes information about
imported procedures. Also handles termination pragmas.
compiler/term_constr_build.m:
New file. Converts the HLDS representation of a procedure
into the abstract representation that we use during the rest
of the analysis.
compiler/term_constr_fixpoint.m:
New file. Perform a fixpoint calculation in order to derive
interargument size relationships for a procedure (in the
form of convex constraints).
compiler/term_constr_pass2.m:
New file. A rudimentary termination checker that is roughly
equivalent to what the existing termination analysis does.
This is just a placeholder.
compiler/term_constr_util.m:
New file. Utility predicates that are used by the above modules.
compiler/term_constr_errors.m:
New file. Equivalent to term_errors.m for the new analyser.
compiler/rat.m:
Provide rational numbers over fixed precision integers.
Originally committed on the termination2 branch.
compiler/lp_rational.m:
Provides the necessary machinery for manipulating systems
of linear constraints. Originally committed on the termination2
branch although most of this version is new. (Some bits of the
version on the termination2 branch are now in polyhedron.m).
The linear solver is essentially the one that is currently
in lp.m converted to use rationals rather than floats.
compiler/polyhedron.m:
New file. An ADT that provides convex polyhedra over the
rationals (or at least over rats). The abstraction barrier was
designed so that we could experiment with different representations
for the polyhedra.
compiler/term_norm:
Clean up the documentation of this module.
Make set_functor_info into a function.
Add a function for finding a lower bound on the weight of a functor.
compiler/trans_opt.m:
Output termination2_info pragmas in .trans_opt files.
compiler/transform_hlds.m:
Include the new termination analyser.
compiler/goal_form.m:
When checking whether a goal can loop or not use
information from the new termination analyser as well as
the old one.
compiler/globals.m:
compiler/handle_options:
compiler/options.m:
Add options to control the new analyser. The documentation
is currently commented out because the new analysis is still
a work-in-progress. It should be uncommented when the new
analysis is more mature.
XXX The user guide still needs to be updated.
compiler/hlds_out.m:
Add hlds_out.write_pred_proc_id/4.
compiler/hlds_pred.m:
Add a slot in the proc_sub_info structure for the
termination2_info structure.
compiler/rat.m:
Provide rational numbers over fixed precision integers.
compiler/lp_rational.m:
Provide the constraint machinery required by the analyser.
compiler/make_hlds.m:
Handle imports of termination2_info pragmas.
compiler/mercury_compile.m:
Run the new pass. Currently, we do this directly after
the old termination analysis pass.
compiler/mercury_to_mercury.m:
Add code to output termination2_info pragmas.
compiler/libs.m:
Include the rat, polyhedron and lp_rational modules.
compiler/prog_data.m:
Define the types necessary for termination2_info pragmas.
Change the cannot_loop constructor of the generic_termination_info
type so it has a polymorphic argument. The new analyser stores
information in it.
Fix some spelling errors in some of the comments
compiler/prog_io_pragma.m:
Parse termination2_info pragmas.
compiler/error_util.m:
Add function versions of sorry/2 and unexpected/2.
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/termination.m
compiler/term_pass2.m
compiler/term_util.m:
Minor changes to confrom to the above.