This fixes Mantis bug 476. The root cause of the compiler abort was the
following sequence of events.
- We first inserted the declaration of the predicate named "mark"
near the bottom of bug476.m file into the predicate table.
- Later we tried to insert the declaration of the class method predicate
named "mark" near the top of the file into the predicate table.
This insertion failed, but it nevertheless returned a valid pred_proc_id
to the code handling the addition of the class methods to the HLDS.
This was the pred_proc_id resulting from the first, successful insertion.
- The compiler expects every predicate that represents a class method
to have at least one universal typeclass constraint on it, this being
the constraint implicit in its nature as a typeclass method. The code
that checks typeclass constraints aborts if it does not find it.
In this case, it did not find it, since we added into the pred_info
we constructed it for the second, unsuccessful insertion, but this
never made it into the HLDS.
The fix is entirely in the change to add_pred.m. The rest of the changes
represent a cleanup of the affected code, which enabled me to find the
root cause of the problem.
compiler/add_pred.m:
When adding a predmode declaration to the HLDS, if adding the pred
part fails (because there is already another predicate with the
same name in the HLDS), do not try to add the mode part, because
it does not make sense to add the mode part of a predmode declaration
to the predicate resulting from a *different* pred declaration.
Mantis bug 476 was caused by (a) the compiler doing this nonsensical
addition, (b) by chance this addition being successful, and (c) this
success misleading the code in add_class.m that handles the predmode
declarations of class methods.
compiler/prog_item.m:
Change the representation of the two kinds of declarations that may occur
inside class declarations, predicate declarations (including predmode
declarations) and mode declarations, to allow each kind to be handled
separately.
Document their fields a bit better.
compiler/add_class.m:
Use the new representation in prog_item.m to simplify the old,
convoluted code for adding the pred and mode declarations inside
typeclass definitions to the HLDS.
compiler/hlds_pred.m:
Document the invariant whose violation led to the compiler abort.
compiler/make_hlds_passes.m:
Fix a comment.
compiler/equiv_type.m:
compiler/module_qual.qualify_items.m:
compiler/parse_class.m:
compiler/parse_item.m:
compiler/parse_tree_out.m:
compiler/prog_data.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
Conform to the change in prog_item.m.
tests/invalid/bug476.{m,err_exp}:
A regression test for the bug.
tests/invalid/Mmakefile:
Enable the new test case.