compiler/make.module_dep_file.m:
Write foreign included file names to the .module_dep stream
instead of the implicit output stream. The bug was introduced in
commit 5f50259d16.
tests/mmc_make/Mmakefile:
mmc --make does not set a non-zero exit status even if there were
problems reading a .module_dep file. Explicitly grep for "error" in
the mmc --make output in the include_file test that should have
caught the preceding bug (assuming the workspace is built with
--use-subdirs).
grep for "error" in another test case.
compiler/prog_data.m:
As above.
compiler/mercury_to_mercury.m:
When generating debugging output, generate different output
for tuple_cons cons_ids than for the initial representation
of the tuple constructor, cons(unqualified("{}"), ...).
To make this possible, take an argument that specifies whether
we are generating debugging output.
compiler/error_msg_inst.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/mode_errors.m:
compiler/parse_tree_out_inst.m:
compiler/prog_ctgc.m:
Pass the language (debug or not) to mercury_to_mercury.m
when printing cons_ids.
compiler/type_util.m:
compiler/inst_util.m:
Move two predicates that operate on types but are used only by code
that manipulates insts from type_util.m to inst_util.m. The reason
is that both predicates lose higher order inst information, and fixing
that will require them to operate on insts as well. Moving them now
should make the diff with the fix easier to review.
compiler/inst_match.m:
compiler/inst_test.m:
Conform to the moves above.
compiler/mode_info.m:
Add a new field to the debug flags we set up when --debug-modes is enabled.
This field specifies whether the debug output is from mode checking,
or from *unique* mode checking. Without this, the two are far too easy
to confuse, as I found out the hard way.
compiler/mode_debug.m:
Use the new field to add visually distinguish mode checkpoints from
the two passes. For example. where mode checking would output
"Enter unify", unique mode checking will output "Enter unique unify".
compiler/unique_modes.m:
Delete a marker on mode checkpoints for conjunctions that also baffled me.
compiler/inst_match.m:
Change the predicates that compare two insts to make the nested switch
(first on one inst, then the other), make the nesting explicit.
Give a predicate a more meaningful name.
Add XXXs on dodgy code.
compiler/inst_match.m:
Replace a bool and a maybe with bespoke types, so that during a debugging
session, there is no need to waste time on trying to remember what e.g.
a "no" stands for.
compiler/modes.m:
Put the code that checks each arg's final inst into its own predicate,
to make the result easier to observe in mdb.
Don't thread a goal through the code that checks final insts,
since the code never updated or even looked at the goals.
Delete this pair of goals from the argument lists of the ancestors
of this predicate whenever possible, including an exported predicate.
compiler/modecheck_unify.m:
Put a piece of code making a tricky decision into its own predicate,
to allow breakpoints on that predicate to show the result of the decision.
Conform to the change in modes.m.
compiler/modecheck_call.m:
This fixes a bug in my fix for Mantis bug #529.
compiler/options.m:
Allow configure to test whether the bug is fixed, so we can delete
any now-redundant explicit higher order insts in mode declarations.
compiler/modecheck_call.m:
As above. This fixes Mantis bug #529.
compiler/options.m:
Allow configure to test whether the bug is fixed, so we can delete
any now-redundant explicit higher order insts in mode declarations.
tests/hard_coded/exist_cons_ho_arg.{m,exp}:
A test case for the bug. This is a strengthened version of the
Mantis test case.
tests/hard_coded/Mmakefile:
Enable the new test case.
compiler/mode_errors.m:
As above.
Delete predicates that (a) do not belong here, but (b) do belong
in some other module.
compiler/mode_info.m:
Move mode_context_init here from mode_errors.m, since the mode_context
type is defined here.
compiler/modes.m:
Move two predicates, maybe_report_error_no_modes and
+report_mode_inference_messages_for_preds here from mode_errors.m,
since their only callers are here.
compiler/post_typecheck.m:
Move +report_indistinguishable_modes_error here from mode_errors.m,
since its only caller is here.
compiler/mode_errors.m:
Give the function symbols representing the various kinds of mode errors
more meaningful names. (Some fix misleading implications, such as when
a function symbol name includes "pred", but the error applies to functions
as well.) Do the same for other function symbols in this module.
Where arguments are lists that should never be empty, change their type
to one_or_more to encode this invariant.
In one case (var_multimode_pred_error), the same data items were packaged
in two different ways in two different places. Remove this unnecessary
difference.
In some cases, put arguments in a more logical order.
Improve the comments on most of these function symbols, fixing errors,
fixing omissions, documenting arguments. Add XXXs where warranted.
Put the types used in the various kinds of mode errors below the
mode_error type itself. Put them into meaningful groups.
The current order of the mode_error function symbols is totally
haphazard. Propose a new order for them, but do not implement it yet,
in order to make this diff easier to review.
Make the representation of the error that says "calling an implied mode
for this predicate or function is not implemented" say *why* it is
not implemented. Include this info in the error message we generate.
This error message is not exercised by any existing test case, which is
why there are no changes to test cases in this diff.
Improve the explanation for why you cannot unify two functions or
two predicates. Since this explanation occurs only in verbose output,
no test case is affected by this change either.
Improve variable names.
compiler/mode_info.m:
Conform to the changes in mode_errors.m.
If --debug-modes is specified, print each error message as it is added
to the mode_info. This helped me track down a bug in this change.
compiler/instmap.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
Conform to the changes in mode_errors.m and/or mode_info.m.
Add XXXs in some places. One marks one possible cause of Mantis bug #529.
This fixes Mantis bug #528.
compiler/error_msg_inst.m:
Since an inst_name IN may be used nested inside itself, as in
IN(..., IN(...), ...), do not insist that both occurrences of IN
in such cases lead to the insertion of a new entry in the inst name
expansion map.
tests/invalid/html.{m,err_exp}:
The Mantis test case.
tests/invalid/Mmakefile:
Enable the Mantis test case.
compiler/c_util.m:
Add missing stream argument.
compiler/Mercury.options:
Fix misspelt filename that prevented the problem in c_util.m
from being automatically diagnosed.
Normally, foreign_procs are assumed to be type correct, because they
have to be: a Mercury compiler cannot check foreign code. However,
in one case, we can get type errors for foreign_procs That case is when
a predicate has
- an existentially typed argument, and
- two or more modes implemented by foreign procs.
The compiler has never been able to correctly handle more than one clause
defining the type_info of an existentially typed argument. When those clauses
were Mercury clauses, it generated an error; when those "clauses" were
foreign_procs, it *tried* to generate an error, but the code that did that
crashed the compiler.
compiler/typecheck_errors.m:
Fix the compiler abort, letting the error message be generated.
tests/invalid/foreign_procs_exist_type.{m,err_exp}:
Add a test case for this fix.
tests/invalid/Mmakefile:
Enable the new test case.
Delete the `' quotes around predicate names, since these confuse vim's
syntax highlighting.
Put each argument of a foreign_proc on its own line, since putting
all the args on one line often causes vim to regard the line
as excessively long, highlighting all characters after column #80.
This fixes the failure of the warnings/bug412 test case with -O5
--intermodule-optimization.
compiler/const_struct.m:
For each const_struct in the const_struct_db, record whether it was
created from code that is defined in the current module.
When a const_struct is defined in more than one place, record it as
being defined in the current module if *any* of the definitions are
in the current module.
compiler/unused_imports.m:
If a const_struct is not defined in the current module, then do not
scan it: the modules it refers to should not be counted as being used
by the current module.
Update debugging infrastructure as needed to find this bug.
compiler/polymorphism.m:
compiler/simplify_goal_scope.m:
When creating const_structs, fill in the new field.
compiler/simplify_info.m:
Add a field to the simplify_info for use by the new code in
simplify_goal_scope.m.
compiler/hlds_out_module.m:
Output the new field in HLDS dumps.
compiler/dead_proc_elim.m:
compiler/higher_order.m:
compiler/ml_unify_gen_construct.m:
compiler/modecheck_unify.m:
compiler/term_norm.m:
compiler/unify_gen_construct.m:
Ignore the new field.
compiler/direct_arg_in_out.m:
We don't require callees of plain_calls to have daio arguments,
so don't require call_foreign_procs to have daio arguments either
(since most won't). Update the related documentation.
This fix uses the approach discussed on m-dev 2020 nov 16/17 for fixing
github issue #72, whose core problem is a need for information flow
back to a the caller from a callee when the callee fills in the
argument of a function symbol whose representation is a direct_arg tag.
In most cases when the callee fills in the value of an argument,
the caller can see it because the argument is in a word on the heap,
but when the function symbol uses a direct_arg tag, that is not the case.
compiler/direct_arg_in_out.m:
A new module that implements the transformation proposed on m-dev.
It creates a fresh clone variable every time an argument of a direct_arg
tag function symbol is (or may be) updated. This can happen several
times if a type has more than one function symbol with a direct_arg tag.
Since the affected variable can be bound to only one function symbol
at the start, its argument can be filled in only once, but the
compiler cannot know in advance what function symbol the variable
contains, and therefore which of the possibly several fill-in sites
(which fill in the arguments of different function symbols) executed
in sequence will actually update the variable.
The transformation ensures that once a variable is cloned, it is
never referred to again. It also ensures that in a branched control
structure (if-then-else, disjunction or switch), all branches will use
the *same* variable to represent the latest version of each cloned
variable at the end, so that following code has a consistent view
regardless of through which branch execution has reached it.
There are three situations that the transformation cannot and does not
handle.
1. Situations in which the mode of an argument is either an inst variable,
or an abstract inst. In either case, the pass cannot know whether
it should apply its transformation to the argument.
2. Situations where a procedure that has such an argument is
exported to C code as a function. In that case, the C signature
of the function we would generate would be different from what
the user would normally expect. We could modify the documentation
of the export pragma, but I don't think there much point due to
lack of demand. (The problem cannot arise when targeting any language
other than C, because we use direct_arg tags only with the low level
data representation, which we only use for C.)
3. Situations where a procedure that has such an argument is defined
by foreign_proc. Again, dealing with the problem would require
nontrivial changes to the documented interface between code in
foreign_procs and the surrounding Mercury code, and I see no demand
for code that could benefit from that.
In these cases, this module generates error messages.
compiler/transform_hlds.m:
Include the new module in the transform_hlds package.
Delete unnecessary module qualification on some existing inclusions.
Put some existing inclusions into a more meaningful order.
compiler/notes/compiler_design.html:
Document the new pass. Fix some nearby prose.
compiler/lambda.m:
compiler/simplify_proc.m:
Use a predicate exported by direct_arg_in_out.m to test, for each
procedure, whether the procedure has any argument positions that are
subject to the problem that direct_arg_in_out.m addresses.
simplify_proc.m does this for all procedures it processes;
lambda.m does this for all the procedures it creates from
lambda expressions.
Give a predicate in simplify_proc.m a better name.
Sort a list of predicate names.
compiler/hlds_module.m:
Add a field to the module_info that simplify_proc.m and lambda.m
can use to tell direct_arg_in_out.m what work (if any) it needs to do.
compiler/mercury_compile_middle_passes.m:
Invoke direct_arg_in_out.m if the new field in the HLDS indicates
that it has some work to do. (In the vast majority of compiler invocations,
it won't have any.)
compiler/hlds_pred.m:
The new code in direct_arg_in_out.m creates a clone of each procedure
affected by the problem, before deleting the originals (to make sure that
no references to the unfixed versions of now-fixed procedures remain.)
Make it possible to create exact clones of both predicates and procedures
by adding two pairs of predicates, {pred,proc}_prepare_to_clone and
{pred,proc}_create.
Add the direct_arg_in_out transformation as a possible source
of transformed predicates.
library/private_builtin.m:
Add a new builtin operation, partial_inst_copy, that the new module
generates calls to.
configure.ac:
Require the installed compiler to recognize partial_inst_copy
as a no_type_info builtin.
compiler/builtin_ops.m:
Recognize the new builtin. (This was committed before the rest; the diff
to private_builtin.m can be done only once the change to builtin_ops.m
is part of the installed compiler.)
compiler/options.m:
Add a way to test whether the builtin_ops.m in the installed compiler
recognizes the new builtin.
compiler/dead_proc_elim.m:
Do not delete the new primitive before direct_arg_in_out.m has had
a chance to generate calls to it.
Add an XXX.
compiler/error_util.m:
Recognize the new module as a source of error messages.
compiler/pred_table.m:
Add a pair of utility predicates to be used when looking up
builtin predicates, for which the compiler writer knows that
there should be exactly one match. These are used in direct_arg_in_out.m.
compiler/simplify_goal_call.m:
Replace some existing code with calls to the new predicates
in pred_table.m.
compiler/hlds_goal.m:
Add modes to rename_vars_in_goal_expr that express the fact
that when an atomic goal_expr has some variables renamed inside it,
it does not suddenly become some *other* kind of goal_expr.
New code in direct_arg_in_out.m relies on this.
compiler/hlds_out_goal.m:
When the HLDS we are dumping out is malformed because it contains
calls to predicates that have been deleted, the compiler used to abort
at such calls. (I ran into this while debugging direct_arg_in_out.m.)
Fix this. When such calls are encountered, we now print out as much
information we can about the call, and prefix the call with an
unmistakable prefix to draw attention to the problem.
compiler/inst_util.m:
Fix a bug that prevented direct_arg_in_out.m from even being invoked
on some test code for it.
The bug was in code that we use to unify a headvar's initial inst
with its final inst. When the initial inst was a non-ground bound_inst
such as the ones used in tests/hard_coded/gh72.m, and the final inst
was simply "ground", this code quite properly returned a bound_inst
(which, unlike ground, can show the exact set of function symbols
that the headvar could be bound to). The problem was that it
reused the original bound_inst's test results, including the one
that said the final inst is NOT ground, which of course is wrong
for any inst unified with ground. Fix two instances of this bug.
compiler/modes.m:
Make some of the code I had to traverse to find the bug in inst_util.m
easier to read and understand.
Replace some uses of booleans with bespoke enum types.
Change the argument lists of some predicates to put related arguments
next to each other.
Give some variables more descriptive names.
compiler/layout_out.m:
Conform to the change in hlds_pred.m.
compiler/var_locn.m:
Fix a code generation bug. When filling-in the value of the argument
of a function symbol represented by a direct_arg tag, the code we
generated for it worked only if the direct_arg tag used 0
as its ptag value. In the test cases we initially used for
github issue 72, that was the case, but the new tests/hard_coded/gh72.m
has direct_tag args that use other ptag values as well.
Document the reason why the updated code works.
compiler/term_constr_initial.m:
Add the new primitive predicate added to private_builtin.m,
partial_inst_copy, to a table of builtins that do not take type_infos,
even though their signatures contain type variables.
Fix a bunch of old bugs: most other such primitives were not listed
either.
mdbcomp/program_representation.m:
Add partial_inst_copy to the master list of builtins that do not take
type_infos even though their signatures contain type variables. (Done
by an earlier commit.)
Document the fact that any updates here require updates to
term_constr_initial.m.
library/multi_map.m:
We have long had multi_map.add and multi_map.set as synonyms,
but we only had multi_map.reverse_set. Add multi_map.reverse_add
as a synonym for it.
Define the "set" versions in terms of the "add" versions,
instead of vice versa.
NEWS:
Document the new predicates in multi_map.m.
tests/hard_coded/gh72a.m:
Fix typo.
tests/hard_coded/gh72.{m,exp}:
A new, much more comprehensive test case than gh72a.m.
This one tries to tickle github issue 72 in as many forms of code
as I can think of.
tests/invalid/gh72_errors.{m,err_exp}:
A test case for testing the generation of error messages for
two out of the three kinds of situations that direct_arg_in_out.m
cannot handle. (Proposals for how to test the third category welcome.)
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Enable the two new test cases, as well as two old ones, gh72[ab].m,
that previously we didn't pass.
tests/invalid/Mercury.option:
Do not compile gh72_error.m with --errorcheck-only, since its errors
are reported by a pass that --errorcheck-only does not invoke.
Zoltan's recent addition of support for formatting fixed size integer types
using string.format and friends works by casting the fixed size integer value
to an int or uint value and then re-using the existing code we already have for
formatting those. This works in all cases except when formatting 64-bit integer
types on systems where int / uint is a 32-bit quantity (notably, both the C#
and Java backends). This diff lifts that restrictions.
library/string.format.m:
Add support for formatting 64-bit integers without having to cast them
to an int or uint.
Export new format predicates for use by the code generated by
compiler/format_call.m.
compiler/format_call.m:
Generate calls to the 64-bit versions of the format_*_component predicates
where necessary.
compiler/simplify_proc.m:
Update the list of predicates that may be introduced by the compiler.
NEWS:
Delete the mention of the restriction.
tests/hard_coded/opt_format.{m,exp}:
Extend this test to cover 64-bit integers.
compiler/hlds_out_module.m:
Instead of writing out first the definition of a data constructor
(including all its arguments), and then the type representation
information pertaining to that data constructor, put the cons_tag
of the data constructor immediately after its name, and put
the representation of each argument immediately after its type.
Write out the type representation information in a more readable form,
cutting out irrelevant details, in forms that fit on 80 lines. Take
advantage of the fact that HLDS dumps do not have to be round-trippable,
i.e. we don't have to output Mercury code that can be read back in.
The code that outputs entries in the type table has two versions:
one for dumps before type representations have been decided, and one
for dumps after that time. Put the corresponding pieces of code
next to each other, to make the required double maintence easier.
compiler/parse_tree_out.m:
The change to hlds_out_module.m adds two slighly-modified copies
of the existing mercury_output_ctor predicate. Reduce the amount
of code duplication by factoring out major parts of mercury_output_ctor,
and making them available to hlds_out_module.m as well, in one case
in a parameterized form.
compiler/mercury_to_mercury.m:
compiler/parse_tree_out_term.m:
Provide utility predicates for the modules above.
compiler/typecheck_info.m:
Take a pred_info argument, whose meaning is obvious, instead of a boolean
argument, whose meaning is not.
compiler/typecheck.m:
Pass the pred_info to typecheck_info.m instead of the boolean, thus
replacing two tests with one.
Delete excess assignment unifications.
Add a comment.
When library/store.m was compiled with LIBRARY_INTERMODULE = no,
it used to get these warnings:
store.m:264: Warning: predicate `store_equal'/2 mode 0 is never called.
store.m:270: Warning: predicate `store_compare'/3 mode 0 is never called.
The reason was that
- the only places that refer to these predicates are the "where equality is"
and "where comparison is" clauses of the foreign type definitions
for the store/1 type constructor,
- when the compiler constructs the unify and compare predicates for store/1,
it is supposed to make them call store_equal and store_compare respectively,
- BUT store/1 is listed as a builtin dummy type, along with io.state.
They are indeed dummy types in the sense that they don't need any
representation, but they are NOT dummy types in the sense that
they have one function symbol which is a constant.
- Nevertheless, because of this, the unify and compare predicates for store/1
used to get a clause body that always succeeds, since that is what is
appropriate for a type that has one function symbol which is a constant.
For I/O states, this does not matter, since the in,in mode of the arguments
of the unify and compare predicates means that any I/O state being compared
cannot be used either as a di input or as a uo output, so such erroneous
comparisons would always have been detected, though the error message
would have been misleading. For stores, any attempts to unify or compare them
would have silently succeeded. Even though store_equal and store_compare
were designed to abort the program in such an event, the old, wrong code in
unify_proc.m meant that they were never called.
This meant that store_equal and store_compare were never called, but with
intermodule optimization turned on (the default), the fact that the
foreign_type pragmas were opt_exported had suppressed such warnings.
library/io.m:
Specify clones of store_equal and store_compare as the type-specific
unify and compare predicates for I/O states.
compiler/unify_proc.m:
Now that both builtin dummy type ctors have type-specific unify
and compare predicates that always abort, construct their overall
unify and compare predicates from them; do not special case them.
Note a potential problem with applying an equality pre-test in
user-specified unify and compare predicates that always abort.
This includes io.state/0 and store.store/1, but may also include
other type constructors.
compiler/hlds_out_module.m:
As above.
Print the status of each type on a separate line from the context,
since putting them on one line often makes the line exceed 80 chars.
compiler/hlds_out_util.m:
When printing out contexts, quote the file name as "filename", not as
`filename', since the latter screws up vim's syntax highlighting.