compiler/make.util.m:
Many operations in this module that operate on filenames did not take
those filenames as arguments; instead, they took an argument such as
a target_file from which they *computed* the filename. This meant that
any predicate that called more than one of these operations implicitly
computed the filename more than once. This could be a problem, because
- there are several predicates one can use to compute the filename, but
- there is no guarantee that different operations use the same predicate.
As a first step in fixing this, change the predicates that print
filenames in progress or error messages to take those filenames
as parameters. Delete one of them, target_file_error, because
after this change, it would have become identical to the existing
file_error predicate.
compiler/make.module_target.m:
Require the callers of record_made_target to supply the filename
as well as the target_file from which it is derived.
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
Compute the filename before calling the updated operations in make.util.m
and/or make.module_target.m.
Add "XXX MAKE_STREAM" to places in the code that operate on either
implicit or badly-chosed explicit streams.
compiler/make.module_target.m:
Inline the (badly named) make_module_target_file_extra_options predicate
at its only call site in make_module_target. Factor out the commonalities
between the dep_file and dep_target parts of make_module_target, which
(after the above inlining) jump out at you.
make_module_target_main_path used to handle the main path *and* one
special case. Move the code to test for, and handle, that special case
to make_module_target. Since the code handling the special case
involves calling make_module_target with modified arguments, this move
also replaces mutual recursion (which originally involved three predicates)
with self-recursion.
compiler/make.util.m:
The target_type_to_extension used to fail for two target types,
and one of its callers depended on it failling *only* for those two
target types.
Eliminate this unwanted coupling by making target_type_to_extension
det, returning one of three values: an extension as before, or a
representation of one or other of the two previously-failing target types.
Rename the predicate to reflect this change.
Stop exporting this predicate, since all its callers are in make.util.m.
compiler/file_names.m:
Document the meaning of the maybe_create_dirs and maybe_search types.
Delete long-obsolete references to .il files.
compiler/make.util.m:
Rename make_remove_target_file to remove_make_target_file, since this
predicate removes target files in Makefiles, and does not "make" anything.
Rename several other predicates in a similar manner, for the same reason.
Add an extra argument to get_file_name and some related predicates
that will allow future conditionally-enabled trace goals in the compiler
to track where the requests for file name translations come from.
compiler/write_deps_file.m:
Factor out some code.
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
Conform to the changes above.
tools/file_name_translation_stats:
Allow for large numbers of file name translations.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)
Also deprecate the internal compiler option --cflags-for-ansi.
compiler/options.m:
Document that --no-ansi-c is now deprecated.
Document that the internal option --cflags-for-ansi is now
deprecated.
compiler/compile_target_code.m:
Do not pass the ANSI options to the C compiler.
scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
Deprecate the --no-ansi option; delete code that no longer does
anything useful.
configure.ac:
Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
set to be empty. (The comment talks about --no-ansi doing other things
in the mgnuc script. It used to also cause some preprocessor macros
to be defined for compatibility with the system headers on some
platforms -- that has not been the case since 2013.)
doc/user_guide.texi:
Document that --no-ansi-c is deprecated.
bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
Conform to the above change.
NEWS.md:
Announce the above.
compiler/inst_mode_type_prop.m:
Define a data structure, the tprop_cache, that records whether
we have already propagated a type into a user defined inst name.
Thread this data structure through all the code that propagates
types into insts, and use it to propagate a type into a user inst name
(which consists of doing a bunch of checks, and generating errors
if those checks fail) only if have not done it before. For the
valid/inst_perf_bug_2.m test case, this reduces the number of checks
from more than 16 million to just 12. On my laptop, this reduces
the compilation time from more than 13 seconds to just above one second.
Call check_user_inst_args, the new version of maybe_check_user_inst_args,
as part of do_check_for_bad_use_of_user_inst. maybe_check_user_inst_args
only ever did anything if do_check_for_bad_use_of_user_inst gave it
the data it needed, but the communication between the two predicates
was bad. The two calls to maybe_check_user_inst_args invoked it under
seemingly different conditions, but the conditions were actually identical,
because they would have differed only if the inst name being worked was
was both a user inst (tested in do_check_for_bad_use_of_user_inst) and
a typed inst (test in its caller).
compiler/post_typecheck.m:
Thread the tprop_cache through this module as well, since it is
this module that invokes inst_mode_type_prop.m to do its job.
compiler/add_special_pred.m:
Conform to the changes above.
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.
The reason for this is that without such limits,
- the generation of a HLDS dump for the valid/inst_perf_bug_2 test case
takes almost forever, and
- generates a multi-gigabyte HLDS dump, which causes e.g. vim to take
forever to open.
Making the generation and use of HLDS dumps practical is worth the cost
of losing some information. (Information you can't afford to generate
or to use is lost anyway.)
compiler/options.m:
doc/user_guide.texi.m:
Add a new option to limit the size of the insts we output
in the inst tables part of HLDS dumps. This option should allow users
to select the tradeoff between the amount of information being preserved
and the cost of generating/using that information.
compiler/hlds_out_module.m:
Pass the value of the new option to hlds_out_inst_table.m.
compiler/hlds_out_inst_table.m:
Specify the size limit when writing out insts as either the keys or
the values in the various kinds of inst tables.
compiler/parse_tree_to_term.m:
To implement those limits, add inst_to_limited_size_term and
inst_name_to_limited_size_term, versions of the old inst_to_term
and inst_name_to_term functions that truncate the given inst or inst name
at the given "size" if necessary. The measure of "size" is just
function symbols in the resulting term in most cases, though
we treat things that in practice never get too big, such as types,
as "one", regardless of the number of function symbols they contain.
To make the parallel between the old non-size-limiting and the new
size-limiting versions of the relevant codes easier to see, transform
the functions in the old code to predicates. (The new versions have
to be predicates to allow the size to be passed along in a state var.)
compiler/hlds_out_goal.m:
When we print out the argument modes of a unification, limit the depth
to which we write out the various insts to three. This should be
more than enough, because any inst that we now replace with "..."
should be available in the mode information of the atomic goal that
generates it, whether that goal is a unification or a call.
compiler/inst_check.m:
Replace two blocks of code with calls to builtin_type_name.
The old code returned "char" as the name name for the builtin character
type, which was wrong, and also went against the top-of-module comment
in inst_check.m. The calls to builtin_type_name return "character"
instead.
Simplify calls to cord.snoc.
compiler/write_error_spec.m:
Move maybe_print_delayed_error_messages here from mercury_compile_main.m,
and move the mutables that the code already in write_error_spec.m was
using to record infor for maybe_print_delayed_error_messages
here as well from globals.m.
The intention is that the make package should also be able to call
maybe_print_delayed_error_messages.
compiler/globals.m:
compiler/mercury_compile_main.m:
Delete the moved code.
compiler/prog_foreign.m:
foreign_language_module_name and foreign_language_file_extension
were both functions with two modes, one of which was semidet.
Since semidet functions violate the law of least astonishment,
turn both into predicates.
Change the semidet mode into det (this has been possible ever since
we deleted the Erlang backend). Then comment out the other mode,
since it has no use left.
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
Update the calls to the affected functions (now predicates).
compiler/make.util.m:
... after inlining some of their at their only call sites.
The rest were unused.
The inlining should (eventually) help the call sites to avoid
redundant conversions from make's representation of target files
to their actual filesystem names. Eventually, because at the moment,
the other conversions are hidden somewhere in their call trees.
Keep one make_write_X predicate after renaming it to write_make_X.
Add XXXs about possible bugs.
compiler/make.dependencies.m:
Replace a higher order arg that wrote out a filename with one
that just returns that filename.
Improve some debugging output slightly.
compiler/make.module_target.m:
Inline the former make_write_X predicates.
Add XXXs about possible bugs.
compiler/make.program_target.m:
Conform to the change in make.dependencies.m.
The language manual guarantees this order, and we do *invoke* initializer
functions in this order, but we used to *define* them in reverse order
if they came from mutable declarations. This diff fixes that.
compiler/make_hlds_passes.m:
The code for gathering the foreign_proc_exports (FPEs) used to implement
mutables returned them as a list in source order. However, the code
in make_hlds_passes.m itself treated that list as it were in reverse order
(probably as a relic of a time when it *was* in reverse order), adding
new entries to at the front to implement any non-mutable initialize (and
finalise) declarations, and finally "unreversing" it. This "unreversing"
of course *reversed* the originally in-order part. (The order of their
*invocation* is controlled by a different mechanism.)
Fix this by *consistently* using cords, instead of reversed lists,
for everything in this module that needs appending at the logical "end".
Do this even for kinds of items that were not involved in this bug.
compiler/add_mutable_aux_preds.m:
Return the list foreign_proc_exports created as a cord, to allow later
operations to append to its end.
compiler/add_pragma.m:
Return the list of tabled pragmas whose addition to the HLDS is deferred
until a slightly later pass as a cord.
compiler/prog_data.m:
Give two predicates dealing with the names of builtin types
more meaningful names. Document the semantics of both predicates,
and document the reason why the definition of one is effectively
inlined into the definition of the other.
compiler/builtin_ops.m:
Make a copy of one of the predicates easier to read, even though
the copy cannot be replaced by a call.
compiler/module_qual.qualify_items.m:
Do replace such copy by a call.
compiler/error_type_util.m:
compiler/parse_tree_out_type.m:
compiler/parse_tree_to_term.m:
compiler/pred_name.m:
compiler/prog_event.m:
compiler/prog_type.m:
compiler/table_gen.m:
compiler/typecheck_errors.m:
compiler/xml_documentation.m:
Refer to the predicates by their new names.
compiler/mlds.m:
Switch mlds_label from an equivalent type to a notag type.
compiler/ml_code_util.m:
compiler/ml_gen_info.m:
compiler/ml_proc_gen.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_stmt.m:
Conform to the change above.
compiler/mlds_to_c_type.m:
Now that all calls to all predicates in the module that do I/O but one
have been replaced by calls to the function versions returning strings,
delete those I/O predicates. The one being kept is used to print lvals,
not types, and lvals are not (yet) printed by converting them to strings
first.
Replace function pairs that each return a type prefix or a type suffix
with predicates that return both at the same time. This allows readers
to check much more easily that the two match.
Delete a type/inst pair that was never used in this module, after
moving it to the one module that does use it.
Move related functions next to each other.
Move related switch arms next to each other.
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_stmt.m:
Conform to the changes above.
compiler/rtti.m:
Delete a function whose only caller was deleted by the change in
mlds_to_c_type.m.
compiler/mlds_to_c_name.m:
Now that all calls to predicates in the module that do I/O
have been replaced by calls to the function versions returning strings,
delete the I/O predicates.
Update the names of some the functions (most of which were derived
from the names of the original predicates), fitting them into the
naming scheme used in the rest of the module.
compiler/add_pragma_tabling.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_c_stmt.m:
Use the updated function names.
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_export.m:
Move flag functions to the end of the module.
Move predicates/functions near related code.
compiler/mlds_to_c_global.m:
Move flag functions to the end of the module.
Replace a bool with a bespoke type.
Fix a predicate name.
compiler/mlds_to_c_file.m:
Conform to the change in mlds_to_c_global.m.
compiler/mlds_to_c_func.m:
Add a comment.
compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_func.m:
Write out more things in calls to io.format.
Require an enum class to contain at one enum.
compiler/mlds_to_target_util.m:
Delete the output_n_indent and write_indented_line predicates,
since this series of changes has replaced all calls to them.
compiler/indent.m:
compiler/mlds_to_target_util.m:
Move the indent type (a synonym for int) from mlds_to_target_util.m
to indent.m, to prepare for the expansion of its use to other parts
of the compiler.
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_util.m:
Import indent.m instead of mlds_to_target_util.m to get access
to the indent type.
compiler/mlds_to_c_global.m:
Write out more things in calls to io.format.
Switch to using indent.m's facilities for indentation.
compiler/c_util.m:
Fix an error in a comment.
Make related code line up vertically.
compiler/mlds_to_c_export.m:
Replace three switches on the same variable, separated by other code,
with one switch on that variable. This way, each arm of the switch,
each of which processes one kind of export (distinguished by the
number of kind of return values) is handled by one block of code,
making it easier to read and understand.
Turn some predicates that did output into functions returning strings,
to make the above possible.
Add blank lines between export definitions.
compiler/mlds_to_c_file.m:
Write out more things in calls to io.format.
Switch to using indent.m's facilities for indentation.
compiler/mlds_to_c_export.m:
Switch a predicate called from mlds_to_c_file.m to a fold-friendly
argument order.
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_func.m:
Construct and return more entities as strings, to allow their callers
to output more things at once with a single call to io.format.
compiler/mlds_to_c_type.m:
Change a type/inst pair to describe a predicate that *gets*
a prefix/suffix pair, instead of a predicate that *writes out*
a prefix/suffix pair.
Add a utility function to help with the above.
compiler/mlds_to_c_data.m:
Use the same code to write out initializer sequences for both
arrays and structs; the differences between them matter only
for empty lists of initializers. Make this code write out
one line at a time.
Put the stream argument into its usual place.
compiler/mlds_to_c_global.m:
Conform to the changes above.
compiler/mlds_to_c_class.m:
Construct and return more entities as strings, to allow their callers
to output more things at once with a single call to io.format.
compiler/mlds_to_c_type.m:
Provide a way to get both the prefix and the suffix parts of a type
at once, to help with the above.
compiler/mlds_to_c_type.m:
For every predicate that writes out the string form of an entity,
- add a function that just returns the string form, and
- reimplement the predicate in terms of that function.
compiler/mlds_to_c_data.m:
Switch to using the new functions in mlds_to_c_type.m, and to using
indent.m's facilities for indentation.
compiler/mlds_to_c_name.m:
For every predicate that writes out the string form of an entity,
- add a function that just returns the string form, and
- reimplement the predicate in terms of that function.
Give the functions names that form to the naming scheme also used
in mlds_to_{cs,java}_name.m.
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_stmt.m:
Switch to using indent.m for indentation.
Do not generate #line directives, even if their generation is enabled,
in places where its scope contains nothing derived from the original
Mercury source file.
Include as many things as possible in calls to io.format, because
doing so allows people reading the code can see how those items
fit together.
compiler/mlds_to_cs_data.m:
Delete an unneeded ZZZ.
compiler/mlds_to_cs_util.m:
Delete the indent_line_after_context predicate, after the changes above
have replaced all calls to it.
compiler/mlds_to_target_util.m:
Add an indent string argument to maybe_output_pred_proc_id_comment,
because without it, you can't make the comment line up with the code
it is commenting on.
compiler/mlds_to_java_func.m:
Conform to the change in mlds_to_target_util.m, and move the generated
comment to a more logical place.
compiler/mlds_to_cs_name.m:
Delete the last predicates that do I/O.
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
Conform to the changes in mlds_to_cs_name.m.
Include as many things as possible in calls to io.format, because
doing so allows people reading the code can see how those items
fit together.
Switch to using indent.m for indentation.
Inline some predicates at their only call sites.
compiler/mlds_to_cs_stmt.m:
Conform to the changes in mlds_to_cs_name.m.
compiler/mlds_to_cs_type.m:
Improve the documentation of type_to_string_and_dims_for_csharp.
Delete the boxed_type_to_string_for_csharp predicate, which is now
a duplicate of the type_to_string_for_csharp function.
compiler/mlds_to_target_util.m:
Add the utility function add_array_dimensions.
Delete the now-unneeded output_array_dimensions predicate.
Switch to a better naming scheme for init_arg_wrappers_cs_java's
arguments.
compiler/mlds_to_cs_export.m:
The code writing out exports to C# used to be a maze of twisty print
operations, all different. Replace this maze with three simple blocks
of code that each completely handle one of the three possible scenarios:
- no return type, no output args
- no return type, some output args
- one return type
compiler/mlds_to_cs_name.m:
Delete more now-unneeded output operations.
compiler/mlds_to_cs_name.m:
Delete some of the predicates that do I/O, requiring their all callers
to call their function versions instead.
Add a comment at the top explaining the reason for length limiting
identifiers.
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
Conform to the changes in mlds_to_cs_name.m.
Include as many things as possible in calls to io.format, because
doing so allows people reading the code can see how those items
fit together.
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_stmt.m:
Conform to the changes in mlds_to_cs_name.m.
compiler/mlds_to_cs_name.m:
For most of the predicates that write out (processed versions of) names,
add
- a function version that returns the processed name as a string; and
- a function version that returns the processed name *after* it has
had its length reduced below 511 characters, if needed.
The first version has "nll_string" (non-length-limited string)
in its name; the second has "ll_string" (length-limited string) instead.
Apply the same naming scheme to some existing functions.
Turn predicates that return strings into functions.
Add and export a function to do the length limitation.
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_type.m:
Conform to the changes in mlds_to_cs_name.m.
Do so mostly by including the return value of indent2_string
as an item to be printed by io.format. By including as many things
to be printed as possible in a single call to io.format, people
reading the code can see how those items fit together.
compiler/mlds_to_java_name.m:
To allow more use of io.format still, replace the predicates here,
which each printed an entity of some kind, with functions that return
the string form of that entity.
In one case, tweak the job of the function a bit. The old predicate
output_qual_name_prefix_java used to print a period after the qualifier,
but its replacement function qualifier_to_string_for_java does not.
This is because having the format string in a call to io.format
contain no period between the qualifier and the name being qualified
would violate the law of least astonishment.
compiler/mlds_to_target_util.m:
Add a function version of the existing predicate output_generic_tvars,
named generic_tvars_to_string.
Make generic_tvar_to_string, which converts just one tvar, into a function,
because this fits in better with the rest of the ecosystem.
Add the utility function write_indentstr_line, which is a version of
the existing write_indented_line that takes the indent string, not the
indent level, as an argument. When called from callers which have
already converted the indent level to the its string form, calling
the old predicate would require redundant conversions.
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mlds_to_java_util.m:
compiler/mlds_to_java_wrap.m:
Make the changes described at the top, using the updates above.
In one place in mlds_to_java_func.m, generate missing indentation.
compiler/indent.m:
compiler/parse_tree_out_misc.m:
Move indent operations from parse_tree_out_misc.m to a new module,
indent.m.
Include a "2" in the names of these operations, because
- these operations print two spaces per level of indentation, but
- some other, similar operations in the compiler use four spaces per level,
and they should be moved here later as well.
compiler/libs.m:
Add the new module to the libs package.
compiler/notes/compiler_design.html:
Document the new module, as well as some other modules in the libs
package that weren't documented before.
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_type_table.m:
Try to use the indent2_string function instead of the write_indent2
predicate, since this allows the indent to printed as part of a call
to io.format.
Fix the printing of loop control scope reasons. Make slight improvements
in the format of some other parts of the output.
compiler/hlds_out_typeclass_table.m:
Try to use the indent2_string function instead of the write_indent2
predicate, since this allows the indent to printed as part of a call
to io.format.
Several fields of class and instance infos that contain lists of stuff
(e.g. method_infos) were being written out on a single line, even though
the lists could be quite long. Fix this by writing out each list item
on its own line. Indent these lines, to separate them visually from
the heading lines preceding them.
Print more information about method_infos to help make sense of them.
compiler/hlds_out_util.m:
Try to use the indent2_string function instead of the write_indent2
predicate, since this allows the indent to printed as part of a call
to io.format.
Write each proof in a constraint proof map on its line.
compiler/parse_tree_out_sym_name.m:
Add a function version of a predicate, which returns a string
without writing it out.
compiler/hlds_out_mode.m:
Improve variable names.
compiler/write_error_spec.m:
Conform to the function renames in indent.m.
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
Delete the Indent argument from the top level predicates
which always get passed Indent=0. We are not likely to ever pass
any other indent value.
Inline a function that has only one call site.
In mlds_to_java_file.m, write out the comment with the module name
regardless of whether auto-comments are enabled.
In mlds_to_java_file.m, put a blank line after the comment block
listing all the imported modules.
compiler/ml_type_gen.m:
Use // comments in sample C code.
compiler/mlds.m:
Avoid some repeated deconstructs.
compiler/mlds_to_cs_util.m:
compiler/mlds_to_java_util.m:
Always put a space after an inline comment.
Make the name of the predicate writing out inline comments
more descriptive.
compiler/mlds_to_cs_data.m:
compiler/mlds_to_java_data.m:
Conform to the change above.