Files
mercury/tests/debugger/solver_test.exp
Zoltan Somogyi ef6d68a88d Add items to the HLDS by kinds, not in passes.
There are several reasons for this change.

First, it is more flexible than the previous arrangement of adding items
to the HLDS in three passes. Since adding a fourth pass would have had
significant performance implications, we refrained from making changes
that would have required a fourth pass in a pass-based algorithm.
With the new structure, such changes do not lead to any detectable slowdown,
so there is no reason why we should avoid making them.

In fact, the immediate motivation for this diff is to make such a change.
This is a fix for Mantis bug 318, which requires adding abstract and/or
non-foreign definitions for types before foreign definitions for those types
*regardless* of their relative order in the source code.

This diff also has the side effect that e.g. the mode declarations for
a predicate don't have to follow the declaration of the (type of) the predicate
itself. Pred and mode declarations used to be processed in the same pass,
but now, all pred declaration are processed before all mode declarations.

Second, as identified earlier, the new structure is conceptually cleaner than
the old one, and the constraints on when different kinds of items have to be
added to the HLDS can documented next to the code that does the adding,
since that code is no longer mixed with code that adds other kinds of items
at the same time.

Third, the code we used to use to detect invalid type definitions
was only a crude approximation. With the new setup, it is trivial to use
an exact computation. We now proceed to later compiler passes in many cases
that previously led us to stop before type checking because we (erroneously)
believed that the program had an invalid type definition.

Fourth, my benchmarking shows a speedup on tools/speedtest -l -m of about
1.2% to 1.5%. The new approach does allocate a bit more memory (a pair
and a cons cell per item), but it traverses most items just once, not
three times. A few kinds of items (e.g. pred declarations) do have to be
processed more than once, e.g. both before and after some other kinds
of items are added to the HLDS, but four of the five most frequent items
in bootchecks (the pragmas recording the results of the termination and
exception analyses, mode declarations, and clauses) are processed just once.
Evidently, the speedup from traversing fewer items, and avoiding the
switches on item kinds that those traversals involve, is greater than
the extra cost of the additional memory allocations, including their effect
on garbage collection times.

compiler/make_hlds_passes.m:
    Make the change described above.

    Remove "shim" code, i.e. code that serves only to unpack the pairing
    of an item with other info such as a status, and code that tests
    that status, e.g. to see whether the item is defined in the module
    being compiled. Move that shim code to the other submodules of
    make_hlds.m. (We used to have add_xyz predicate in make_hlds_passes.m
    and module_add_xyz predicates in those submodules, in which add_xyz
    contained only shim code and a call to the corresponding module_add_xyz
    predicate.)

compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
    Move shim code here from make_hlds_passes.m.

    Give some predicates better names.

    In a few cases, remove unneeded arguments from predicates. For example,
    most predicates that do only checks don't need write access to the
    module_info.

compiler/add_pragma.m:
    Use subtypes to make the code a bit more efficient.

    Add specialized fold predicates that can handle those subtypes.

compiler/add_type.m:
    Add documentation for an old design decision.

compiler/make_hlds.m:
    Add some utility types for use by make_hlds_passes.m and the various
    add_xyz.m.

compiler/check_typeclass.m:
    Improve an error message. We now get this error message even for modules
    on which the compiler previously stopped before getting to typechecking.

compiler/modes.m:
    Don't generate redundant error messages for mode errors in mutables' aux
    preds. (Previously, the mode checker wouldn't have been invoked if
    make_hlds_passes.m found the original problem.)

compiler/prog_item_stats.m:
    Delete an unneeded import.

library/list.m:
    Add an inst-preserving version of reverse, since make_hlds_passes.m
    now needs one.

tests/debugger/solver_test.exp:
    We add predicates to the HLDS in a different order now (auxiliary
    predicates for solver types are added *after* used-defined predicates).
    This test prints the raw order of those predicates, so expect the new
    order.

tests/invalid/typeclass_test_9.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
    Expect error messages we didn't used to get, because the compiler
    stopped before typechecking due to (incorrectly) believing that it found
    an invalid type definition.

    For typeclass_test_9, expect the updated error message from
    check_typeclass.m. (This newly printed error message was the reason
    *why* I improved the message from check_typeclass.m.)

tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_missing_mode_2.err_exp:
tests/invalid/typeclass_test_10.err_exp:
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
    Expect the updated error message from check_typeclass.m.

tests/valid/bug318.m:
    A test case for Mantis bug 318.

tests/valid/Mmakefile:
    Enable the new test case.
2015-10-29 14:13:46 +11:00

19 lines
685 B
Plaintext

E1: C1 CALL pred solver_test.main/2-0 (det) solver_test.m:29
mdb> echo on
Command echo enabled.
mdb> register --quiet
mdb> procedures solver_test
List of procedures in module `solver_test'
pred solver_test.main/2-0 (det)
pred solver_test.init_foo/1-0 (det)
pred solver_test.test_any_free_unify/2-0 (det)
func solver_test.representation of ground foo/0/1-0 (det)
func solver_test.representation of any foo/0/1-0 (det)
func solver_test.representation to ground foo/0/1-0 (det)
func solver_test.representation to any foo/0/1-0 (det)
__Unify__ for solver_test.foo/0-0 (semidet)
__Compare__ for solver_test.foo/0-0 (det)
__Initialise__ for solver_test.foo/0-0 (det)
mdb> quit -y