Commit Graph

4 Commits

Author SHA1 Message Date
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
Zoltan Somogyi
33eb3028f5 Clean up the tests in half the test directories.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the debugger tests,
    specify the new line numbers in .inp files and expect them in .exp files.
2015-02-14 20:14:03 +11:00
Zoltan Somogyi
9bdc5db590 Try to work around the Snow Leopard linker's performance problem with
Estimated hours taken: 20
Branches: main

Try to work around the Snow Leopard linker's performance problem with
debug grade object files by greatly reducing the number of symbols needed
to represent the debugger's data structures.

Specifically, this diff groups all label layouts in a module, each of which
previously had its own named global variable, into only a few (one to four)
global variables, each of which is an array. References to the old global
variables are replaced by references to slots in these arrays.

This same treatment could also be applied to other layout structures. However,
most layouts are label layouts, so doing just label layouts gets most of the
available benefit.

When the library and compiler are compiled in grade asm_fast.gc.debug,
this diff leads to about a 1.5% increase in the size of their generated C
source files (from 338 to 343 Mb), but a more significant reduction (about 17%)
in the size of the corresponding object files (from 155 to 128 Mb). This leads
to an overall reduction in disk requirements from 493 to 471 Mb (about 4.5%).
Since we generate the same code and data as before, with the data just being
arranged differently, the decrease in object file sizes is coming from the
reduction in relocation information, the information processed by the linker.
This should speed up the linker.

compiler/layout.m:
	Make the change described above. We now define up to four arrays:
	one each for label layouts with and without information about
	variables, one for the layout structures of user events,
	and one for the variable number lists of user events.

compiler/layout_out.m:
	Generate the new arrays that the module being compiled needs.

	Use purpose-specific types instead of booleans.

compiler/trace_gen.m:
	Use a new field in foreign_proc_code instructions to record the
	identity of any labels whose layout structures we want to refer to,
	even though layout structures have not been generated yet. The labels
	will be looked up in a map (generated together with the layout
	structures) by llds_out.m.

compiler/llds.m:
	Add this extra field to foreign_proc_code instructions.

	Add the map (which is actually in two parts) to the c_file type,
	which is the data structure representing the entire LLDS.

	Also add to the c_file type some other data structures that previously
	we used to hand around alongside it. Some of these data structures
	used to conmingle layout structures that we now separate.

compiler/stack_layout.m:
	Generate array slots instead of separate structures for label layouts.
	Return the different arrays separately.

compiler/llds_out.m:
	Order the output of layout structures to require fewer forward
	declarations. The forward declarations of the few arrays holding the
	label layout structures replace a lot of the declarations previously
	needed.

	Include the information needed by layout_out.m in the llds_out_info,
	and conform to the changes above.

	As a side-effect of all these changes, we now generate proc layout
	structures in the same order as the procedures' appearence in the HLDS,
	which is the same as their order in the source code, modulo any
	procedures added by the compiler itself (for lambdas, unification
	predicates, etc).

compiler/code_info.m:
compiler/dupelim.m:
compiler/dup_proc.m:
compiler/exprn_aux.m:
compiler/frameopt.m:
compiler/global_data.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Conform to the changes above.

runtime/mercury_goto.h:
	Add the macros used by the new code in layout_out.m and llds_out.m.
	We need new macros because the old ones assumed that the
	C preprocessor can construct the address of a label's layout structure
	from the name of the label, which is obviously no longer possible.

	Make even existing families of macros handle in bulk up to 10 labels,
	up from the previous 8.

runtime/mercury_stack_layout.h:
	Add macros for use by the new code in layout.m.

tests/debugger/*.{inp,exp}:
tests/debugger/declarative/*.{inp,exp}:
	Update these test cases to account for the new (and better) order
	of proc layout structures. Where inputs changed, this was to ensure
	that we still select the same procedures from lists of procedures,
	e.g. to put a breakpoint on.
2009-10-21 06:36:37 +00:00
Zoltan Somogyi
f71532a398 Add an mdb command, all_procedures, for listing all the procedures in the
Estimated hours taken: 2
Branches: main

Add an mdb command, all_procedures, for listing all the procedures in the
program. It has two options: -u or --uci for listing unify, compare, index and
init predicates, and -s or --separate for printing the various parts of
procedure names in separate fields, for automatic processing (e.g. by awk
scripts).

trace/mercury_trace_internal.c:
	Implement all_procedures.

	Fix a couple of small bugs: a wrong help category argument in an option
	processing call, and a NULL completer function.

trace/mercury_trace_tables.[ch]:
	Provide a function that is the guts of all_procedures.

	Fix the code for handling the specification of unify, compare and
	index procedures to also handle init procedures.

doc/user_guide.texi:
	Document all_procedures.

runtime/mercury_stack_trace.[ch]:
	Add a new function for printing procedure ids for all_procedures -s.

	Fix the code for printing unify, compare and index predicates to also
	handle init predicates.

tests/debugger/solver_test.{m,inp,exp}:
	A new test case to test the fix of the printing of init predicates.

tests/debugger/Mmakefile:
tests/debugger/Mercury.options:
	Add the new test case.

tests/debugger/mdb_command_test.inp:
tests/debugger/completion.exp:
	Update these files to account for the new mdb command.
2004-12-09 01:03:22 +00:00