compiler/error_msg_inst.m:
Fix a bug that caused the suffix that all paths in two predicates
were supposed to add at the logical end of the constructed pieces
(though it could be followed by some punctuation) to *not* be added
to the constructed pieces on some paths. Since with our current approach,
the suffix for one inst in a list of insts can be the description
of *all the insts following it in the list*, this bug could delete
not just punctuation, but entire insts from the output. This did actually
happen for the invalid/html text case below.
Fix a problem that could cause each inst in a list of insts
to be indented one more level than the previous inst, which can be
very confusing.
Delete the comma from "instname, which expands to ...". When this output
occurs in an argument list, the presence of the comma can make it
harder to recognize where one argument ends and the next argument begins.
Factor out some common code.
Add an XXX noting a problem.
Fix documentation.
compiler/parse_tree_out_inst.m:
Provide two functions for use by error_msg_inst.m.
compiler/prog_mode.m:
Fix a comment.
tests/invalid/html.m:
Fix the description of the problem we are testing for.
tests/invalid/html.err_exp:
Expect the fix for the "omitted insts" bug above.
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Do not expect the deleted comma.
We used to have several predicates whose job was to simplify modes for
presentation to users. Their jobs were slightly different, but contained
a shared core: recognizing the exploded (from_inst >> to_inst)
forms of the standard builtin modes. Replace these
compiler/prog_mode.m:
Moves an existing predicate in parse_tree_out_inst.m for recognizing
the standard builtin modes to prog_mode.m, to make it generally available.
Refactor the existing insts_to_mode predicate to use this predicate.
Make insts_to_mode recognize mdi(I) modes as well.
Add utility predicates for stripping all type_inst wrappers from
insts and modes. Base these on the similar utility predicates
for stripping builtin qualifiers from insts and modes. Export
all meaningful variants of both sets of utilities.
Use variables named InstNameX for inst names; the old InstX names
were misleading, since the inst_name type is different from mer_inst.
compiler/parse_tree_out_inst.m:
Delete the code moved to prog_mode.m.
Use the updated functionality in prog_mode to simplify modes.
This means that we can now simplify all in(...) modes, not just
when the ... is a higher order inst.
Strip module qualifiers from modes when printing output for humans
(and *only* for humans), since in 99.9+% of cases they are clutter.
compiler/error_msg_inst.m:
Replace the old code for recognizing standard modes with calls
to the predicates in prog_mode.m. They can do a better job than
the old code did. The recognize arity 1 standard modes, not just
arity 0, and they remove typed_inst wrappers everywhere in insts,
not just at the top level.
compiler/hlds_out_util.m:
Fix an old bug: don't *assume* that any modes being converted to string
are intended only for humans; get our callers to *tell us* whether
that is the case. When intermod.m uses hlds_out_goal.m to write out
the modes on the arguments of lambda goals, this is *not* the case,
since some transformations intended for humans, such as stripping
module qualifications, can actually break things.
Give a field in the hlds_out_info a more meaningful name.
compiler/hlds_out_goal.m:
compiler/hlds_out_module.m:
compiler/intermod.m:
compiler/mode_errors.m:
Conform to the changes in hlds_out_util.m.
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/mode_inf.err_exp:
Expect the updated forms of modes in error messages.
compiler/mode_errors.m:
When printing an error message that says "these args have these modes,
which do not match any declared mode of the callee", avoid confusing
users by not mentioning the extra type_info/typeclass_info args added by
polymorphism, except in the very rare case that they could be the *cause*
of the mode error.
When the callee is a function, list its return value separately from
the other arguments, again in an effort to reduce possible confusion.
compiler/mode_info.m:
To make the above possible, record the actual pred_id of the callee
for plain calls. This should actually be faster than the old code
it replaces, because it avoids the computation of the call_id from
the pred_id for all calls that do not result in error messages.
Fix a misleading predicate name.
compiler/modecheck_goal.m:
compiler/modecheck_util.m:
compiler/unique_modes.m:
Conform to the changes in mode_info.m.
compiler/hlds_pred.m:
Fix a misleading predicate name.
compiler/polymorphism.m:
compiler/pred_table.m:
Conform to the changes in hlds_pred.m.
compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/higher_order.m:
Use variable names that specify which kind of arity they talk about:
the one that counts functions' return values, or the one that doesn't.
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/try_detism.err_exp:
Update these expected output files to account for the change to
mode_errors.m above.
tests/invalid/any_passed_as_ground.err_exp2:
The old any_passed_as_ground.err_exp could not be matched for a long time
now. The new any_passed_as_ground.err_exp actually updates the old
any_passed_as_ground.err_exp2, since we can't have a .err_exp2 file
without a .err_exp file. Since we now need only one expected output file,
delete the .err_exp2 file.
tests/invalid/ho_default_func_1.err_exp2:
tests/invalid/ho_default_func_3.err_exp2:
Delete these files, since they could not be matched for a long time now.
tests/invalid/try_detism.err_exp2:
The same deal as with the any_passed_as_ground test case.
compiler/error_msg_inst.m:
When prettyprinting insts for use in error messages, we have to be careful
to generate finite output even for recursive insts. Previously, we did
the required check when processing user-defined inst names, but not when
processing compiler-generated inst names, which can also be recursive.
Fix this bug, which is Mantis bug 415.
Previously, we passed information about what potentially-recursive inst
names we have seen so far only downward. With the fix above, this avoids
infinite loops, but in some cases, it leads us to print the definition
of a given named inst more than once. Change our approach so that we
now pass information about the set of potentially-recursive inst names
we have seen sideways as well. This can make us generate more compact
and therefore more understandable output when prettyprinting insts that
contain such non-nested duplication.
When printing something that says "inst name x, which expands to ...",
indent the "..." one level deeper than the "inst name x". This visually
separates the thing being defined and its definition.
When prettyprinting complex insts, we show their structure using
indentation levels in the output. Each increase of indentation
should be balanced by a later matching decrease. Move the code that
does the increase and the decrease next to each other, to make it easier
to see the implicit correctness argument.
tests/invalid/bug415.{m,err_exp}:
A new test case for this bug.
tests/invalid/Mmakefile:
Enable the new test case.
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Expect the extra level of indentation after "which expands to".
tests/invalid/ho_default_func_4.err_exp:
Expect the extra level of indentation after "which expands to",
and expect a repeated inst name NOT to have its definition repeated.
compiler/mode_errors.m:
When printing insts in error messages, use predicates specifically
designed for that purpose.
The insts output by these predicates improve on the existing output
in the following ways.
- We now show the structure of complex insts through indentation.
- We now show both the name of named insts, and their expansion.
Sometimes, you need the expanded inst to understand the error message,
in the case of recursive insts, you cannot expand them forever.
Since the expansion *has* to refer to the inst name, showing that name
at the *start* of the expansion is necessary to allow readers to
understand the inst.
- We now eliminate the module qualification from the names of function
symbols. The module qualifiers on function symbols are specified
by the type, not the inst, of the relevant term, and if we get to
the point of mode analysis having been run, then the predicate
we are generating errors for must be *type* correct, though obviously
it is not *mode* correct.
- We now eliminate the module qualification from names of named insts
if the module qualifier is the name of the module being compiled.
This is a common case, and in these cases, the module qualifier
in the error message acts as clutter, making it *harder* to read.
- We now avoid printing parentheses that humans never need, but which
the parser sometimes does, and which the existing inst output predicates
therefore had to print.
- Higher order insts contain the modes of the function or predicate.
We now print the builtin modes as e.g. "in" instead of the old
"free >> ground".
compiler/error_util.m:
Add some utility predicates now needed by mode_errors.m.
tests/invalid/any_passed_as_ground.err_exp2:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.sub.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/state_vars_test4.err_exp:
tests/invalid/try_detism.err_exp2:
tests/warnings/unify_f_g.exp:
Update expected outputs.
These test cases were not enabled before due to problems with the mode
checker, since fixed in commit 491bb0ab5f
and thereabouts.
tests/invalid/Mmakefile:
Enable ho_default_func_4 and inst_matches_final_bug.
tests/invalid/ho_default_func_4.m:
Update module import.
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
Add expected outputs.
Estimated hours taken: 12
Branches: main
Implement a change to the mode system suggested by Ralph Becket to make use of
higher order functions a bit easier.
During mode checking of higher order calls, if the variable being called has a
higher-order function type, but only a ground inst with no higher-order
information, assume that it has the default function modes.
Also, when doing anything that might cause a variable's inst to lose higher
order mode information, report a mode error if the variable has a non-standard
higher order function mode. Situations where this may occur are at call sites,
exit sites and when merging insts at the end of a branched goal.
Note that because of this restriction, this change is not backwards compatible.
compiler/inst_util.m:
Define some predicates to check for and produce pred_inst_infos for
default function modes.
In 'inst_merge', ensure that higher order inst information is not lost
from non-standard function insts.
compiler/inst_match.m:
In 'inst_matches_initial' and 'inst_matches_final', ensure that higher
order inst information is not lost from non-standard function insts.
Also allow 'inst_matches_{initial,final,binding}' to succeed
where the first inst is a standard function inst and the
second is ground.
compiler/modecheck_call.m:
In 'modecheck_higher_order_call', if the variable to be called has no
pred_inst_info, but the correct higher-order function type, assume it
has the default function modes.
mode_util.m:
pd_util.m:
Before replacing a ground inst with 'ground(Uniq, none)', ensure that it
does not contain any nonstandard function insts.
tests/hard_coded/Mmakefile:
tests/hard_coded/ho_func_default_inst.m:
tests/hard_coded/ho_func_default_inst.exp:
tests/invalid/Mmakefile:
tests/invalid/ho_default_func_1.m:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.m:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_default_func_3.m:
tests/invalid/ho_default_func_3.err_exp:
Add some test cases.
tests/invalid/Mmakefile:
tests/invalid/ho_default_func_4.m:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/inst_matches_final_bug.m:
tests/invalid/inst_matches_final_bug.err_exp:
Add some test cases which we do not yet pass due to a bug in
inst_matches_final.
NEWS:
doc/reference_manual.tex:
Document the change.