Commit Graph

17 Commits

Author SHA1 Message Date
Zoltan Somogyi
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

library/library.m:
	Include the new module in the library.

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Zoltan Somogyi
168500343c This change adds new facilities for debugging minimal model tabling, and
Estimated hours taken: 160
Branches: main

This change adds new facilities for debugging minimal model tabling, and
has several bug fixes found with the aid of those facilities. Most of the
diff affects the behavior of the system only in minimal model grades and/or
when debugging flags are defined.

compiler/ite_gen.m:
	In minimal model grades, surround the conditions of if-then-elses
	with calls to three functions. These functions detect when a
	condition fails due to one or more suspensions, and abort the
	program. (After resumptions, the condition may actually have
	solutions, but by then the computation has committed to the wrong
	path.)

compiler/table_gen.m:
	Change the program transformation for model_non predicates
	to use a switch instead of nested if-then-elses, to avoid the
	overhead of wrapping the condition. The version with switches
	is also a bit easier to debug.

	The transformation for model_det and model_semi predicates
	stays as before, because for such predicates finding the status
	(which we want to switch on) requires computation, not just a lookup.

	Switch to state variable syntax in the affected predicates.

	Make the error message for an internal error in loopcheck predicates
	more precise.

	Mark the code fragments that modify tabling data structures as impure
	and code fragments that examine tabling data structures as semipure.

runtime/mercury_stacks.[ch]:
	Implement the new stack of possibly negated contexts that we use
	to detect false failures due to suspensions in negated contexts.

	Fix a bug: don't refer to MR_cut_stack[-1].

	Shorten the name of the generator stack.

runtime/mercury_context.[ch]:
runtime/mercury_memory.c:
runtime/mercury_wrapper.[ch]:
	Allocate memory for the new stack of possibly negated contexts.

	Use the shortened name of the generator stack.

runtime/mercury_regorder.h:
	Allocate a pointer for the new stack of possibly negated contexts.

runtime/mercury_minimal_model.[ch]:
	A new module holding the part of mercury_tabling.[ch]
	that is specific to minimal model tabling. This version contains
	tools to help debugging of minimal model tabling, as well as some
	bug fixes found with the aid of those tools.

runtime/mercury_tabling.[ch]:
	Remove the code moved to mercury_minimal_model.[ch], and add the
	code moved here from trace/mercury_trace_internal.c.

	Add prefixes to a bunch of structure fields to make it easier
	to read code accessing those fields.

	Add mechanisms to allocate and copy tabling structures with type
	safety.

runtime/mercury_imp.h:
	#include the new header file, if it is needed.

runtime/Mmakefile:
	Mention the new module, and fix sortedness errors.

runtime/mercury_stack_trace.c:
	Fix a bug that sometimes caused stack traces to abort in minimal model
	grades: they were trying to get layout information from labels
	that do not have them, such as do_fail.

	If MR_TABLE_DEBUG is defined, print the locations of stack frames
	when doing stack dumps.

runtime/mercury_trace_base.h:
	Export to mercury_stack_trace.c the labels that we use to let the
	debugger get control at redos and fails, since they don't have
	layout information.

runtime/mercury_types.h:
	Move typedefs here from mercury_tabling.h, and add typedefs for some
	newly added types.

runtime/mercury_engine.[ch]:
	Add a table mapping debugging flags to their offsets in the
	MR_debugflag array, for use in the debugger.

runtime/mercury_misc.c:
	Make the formatting of det stack pointers the same as nondet stack
	pointers in debugging output.

runtime/mercury_debug.[ch]:
	Add conditionally compiled debugging output when creating temp frames
	on the nondet stack.

library/table_builtin.m:
	Conform to the new names of some fields.

	Add a predicate to return the status of a subgoal.

	Add conditionally compiled debugging code.

library/Mmakefile:
	Make table_builtin.m depend on runtime/mercury_minimal_model.h.

trace/mercury_trace.c:
	Conform to the new names of some fields.

trace/mercury_trace_internal.c:
	Add two new mdb commands, to print the cut stack and the new possibly
	negated context stack.

	Add two new mdb commands to print a subgoal and a consumer.

	Move some of the code to print tabling-related
	data structures to runtime/mercury_tabling.[ch].

	Add a new mdb command to report the values of debugging flags and
	to set and clear them. Previously, one had to turn on these debugging
	flags with environment variables, which were problematic because they
	turned on diagnostic printouts even in Mercury programs that *weren't*
	being debugged, such as the Mercury compiler when being used to
	generate the program to be debugged. Now the flags can be turned on
	from a .mdbrc file, which eliminates much setting and unsetting of
	environment variables.

doc/user_guide.tex:
	Document the new mdb commands.

tests/debugger/mdb_command_test.inp:
	Test the documentation of the new mdb commands.

tests/debugger/completion.exp:
	Expect the new commands in the command completion test.

tests/debugger//nondet_stack.exp*:
	Expect the new format of det stack pointers.

tests/debugger/all_solutions.exp3:
tests/debugger/exception_value.exp3:
tests/debugger/declarative/catch.exp3:
tests/debugger/declarative/ho5.exp3:
tests/debugger/declarative/throw.exp3:
	New expected test cases for use in minimal model grades. They
	differ from existing expected output files only in the precise
	phrasing of error messages.

tests/debugger/declarative/Mmakefile:
	Disable the untraced_subgoal test case in .mm grades, since we don't
	pass it yet.

tests/tabling/Mmakefile:
	Enable the mday test case, now that we pass it.
2003-03-18 16:39:01 +00:00
Zoltan Somogyi
010a9ecf74 Fix several bugs in deep profiling. These allow the compiler to bootstrap
Estimated hours taken: 30
Branches: main

Fix several bugs in deep profiling. These allow the compiler to bootstrap
again, *including* writing out the profiling data, with sanity checks enabled.
Some test cases still fail, but significantly fewer than before.

These fixes required several improvements in the infrastructure for low
level debugging in the LLDS grades.

compiler/deep_profiling.m:
	Mark calls that have a prepare_for_{normal,ho,...}_call inserted before
	them as impure, to prevent simplify from optimizing them away, e.g. as
	duplicate calls. This is needed because a prepare_for_{...}_call that
	is not followed immediately by the call port code of the callee leaves
	the profiling tree in a state that violates its invariants.

	Mark the redo port code of model_non predicates as needing to be
	preserved, even if determinism analysis would normally cause it to be
	cut by marking the disjunction it is part of (whose two disjuncts are
	the det exit port code and the failure redo port code) as det.

	Fix the generation of goal paths to match what the rest of the compiler
	does. Start number conjuncts, disjuncts and switch arms from 1, not 0,
	and do not reverse goal paths before attaching them to goals; they will
	be reversed when they are converted to strings.

compiler/det_analysis.m:
	If a disjunct has determinism failure but is impure, treat it as being
	able to succeed when computing the max number of solutions of the
	disjunction as a whole, *provided* that some earlier disjuct could
	succeed. The idea is that ( impure failure ; det ) should be treated
	as det, since all backtracking is local within it, while disjunctions
	of the form ( det ; impure failure ) should be treated as multi, since
	we want to be able to backtrack to the second disjunct from *outside*
	the disjunction.

	At the moment, we do this not for all impure goals, but only for the
	impure goals that deep_profiling marks with the preserve_backtrack_into
	feature.

compiler/hlds_goal.m:
	Add the preserve_backtrack_into feature.

	Add utility predicates for handling the features of a goal directly,
	without explicitly dealing with its goal_info.

runtime/mercury_debug.[ch]:
	Add mechanisms for turning the printing of low level debugging messages
	on and off. Without this, enabling low level debugging can generate
	literally gigabytes of debugging output.

	The mechanisms all depend on numbering calls.

	One mechanism allows messages to be printed starting from calls in
	given ranges, by including e.g. -di100-200,300-400 in MERCURY_OPTIONS.

	Another mechanism allows N messages to be printed starting from calls
	to a given procedure or from calls at which next_call_site_dynamic
	has a given value. The value of N (the size of the block of calls)
	can be specified by include -dB<num> in MERCURY_OPTIONS. The name of
	the given procedure (actually the name of its entry label) can be
	specified by including -dj<entrylabel> in MERCURY_OPTIONS. The address
	of the call_site_dynamic structure to watch for is specified with the
	-dW<addr> option in MERCURY_OPTIONS, as before.

runtime/mercury_wrapper.[ch]:
	Add the global variables required to implement the new low level
	debugging functionality, as well as the option processing code required
	to set those global variables.

	Separate the flags controlling the printing of the values of stack
	control registers (sp, curfr etc) and ordinary registers (r1, r2 etc).
	Print ordinary registers only if explicitly requested.

runtime/mercury_engine.h:
	Add the required global flags.

runtime/mercury_deep_profiling.[ch]:
	Add two extra arguments to MR_deep_assert, and print them if an
	assertion fails. This makes it easier to decide what parameters to give
	to the new low level debugging mechanisms.

runtime/mercury_deep_*_port_body.h:
runtime/mercury_deep_rec_depth_*.h:
library/profiling_builtin.m:
	Pass the extra arguments to MR_deep_assert, and print low level
	debugging messages only if the relevant flag is set.

tools/lmc:
	Add mechanisms to add to the list of C compiler flags the program is
	compiled with by lmc.
2002-08-14 06:41:36 +00:00
Zoltan Somogyi
bac4b47f2a Harmonize the treatment of the builtin types by the runtime system across
Estimated hours taken: 36
Branches: main

Harmonize the treatment of the builtin types by the runtime system across
the MLDS and LLDS C backends. (Their treatment by the .NET and Java backends
is unchanged, at least for now.)

Previously, the RTTI data structures and unify and compare predicates for the
builtin types were defined in runtime/mercury.c for the MLDS backend but in
library/{builtin,private_builtin,type_desc}.m for the LLDS backend. This
make several kinds of maintenance difficult, and more likely to be forgotten.
The two backends also had their generic unify/compare code in different modules
(mercury.c and mercuy_ho_call.c) and used distinct macros for defining RTTI
data structures. This change fixes those problems by defining a consistent
set of macros (with backend-specific implementations but backend-independent
semantics), concentrating the definitions of all the RTTI structures and of all
the unify and compare predicates for builtin types in a new module in the
runtime, mercury_builtin_types.[ch], and concentrating all the generic
unify/compare predicates in mercury_ho_call.[ch].

This change also makes the runtime use consistently module qualified names
for the RTTI data structures for the builtin types. Since they are not module
qualified by the Mercury compiler, we module qualify them by macros that map
the mmc-generated names to the ones expected by the runtime system. This makes
it easier to use the same macros in LLDS and MLDS grades.

runtime/mercury_builtin_types.[ch]:
	New module to contain all the C code for the implementation of
	unify and compare predicates for the builtin types. Its contents
	comes from mercury.c in the runtime (for the MLDS C backend) and
	builtin.m, private_builtin.m and type_desc.m in the library (for the
	LLDS C backend).

	The unify/compare predicates for tuples now report errors. This is
	necessary because the tuple is a variable arity constructor. Their
	previous implementations for the MLDS backend relied on only being
	called from the generic unify/compare routines with a nonstandard
	interface, being passed a typeinfo for the tuple type, rather than
	the typeinfos for the arguments of the type constructor. This worked
	because we don't currently specialize unifies/compares of tuple types,
	but was a potential problem if we ever started to do such
	specialization. The fix is to handle tuples in the generic
	unify/compare routines, just as in the LLDS backend.

runtime/mercury_ho_call.c:
	Move the generic unify/compare routines for the MLDS backend here
	from mercury.c.

	Conform to the coding standard wrt indentation.

runtime/mercury_ho_call.h:
	Declare the generic unify/compare routines for both backends.

	Delete a typedef that now needs to be in mercury_types.h to avoid
	circular dependencies.

runtime/mercury_type_info.h:
	Use the same macros for defining type_ctor_info structures for the MLDS
	and LLDS backends.

	This required moving the definitions of MR_UnifyFunc_N and
	MR_CompareFunc_N here from mercury.c.

runtime/mercury_hlc_types.h:
	A new file containing definitions of types needed by the MLDS C
	backend. These definitions used to be in mercury.h, but now they are
	needed in mercury_type_info.h, a header file that doesn't and shouldn't
	include mercury.h. They can't easily be put in mercury_types.h because
	they depend on mercury_std.h, and we are not allowed to include
	mercury_std.h in mercury_types.h.

runtime/mercury.h:
	Delete the definitions of the C types representing type_info and
	pseudo_type_infos, since these are now in mercury_type_info.h.
	#include mercury_type_info.h.

	Delete the definitions now in mercury_hlc_types.h.

runtime/mercury.c:
	Delete the definitions of the C types representing unify and compare
	predicates, since these are now in mercury_type_info.h.

runtime/mercury_bootstrap.h:
	Module qualify the RTTI data structures of the builtin types, since
	it makes it easier to use the same macros to define RTTI structures
	in the LLDS and MLDS backend. (Previously, mercury_bootstrap.h had
	macros to delete such module qualification for the variable arity
	types.)

runtime/mercury_types.h:
	Move some type definitions from mercury_ho_call.h and
	mercury_deep_profiling.h to mercury_types.h to prevent problems
	with circular dependencies between header files.

runtime/mercury_debug.h:
	Delete a #include to prevent a circular dependency.

runtime/mercury_profiling_builtin.[ch]:
	A new module containing the {call,exit,redo,fail} port predicates
	for deep profiling, moved here from library/profiling_builtin.m.
	They are referred to by the implementations of the unify and compare
	predicates of builtin types, and thus they need to be in the runtime
	directory to avoid references from the runtime to the library.

runtime/Mmakefile:
	Add the new files.

tools/make_port_code:
	A script to generate runtime/mercury_profiling_builtin.[ch] fully
	automatically.

library/array.m:
	Use the new backend-independent macros to reduce the amount of code
	that was duplicated for the two backends.

library/builtin.m:
library/private_builtin.m:
library/type_desc.m:
	Delete RTTI structures and unify and compare predicates
	that are now in runtime/mercury_builtin_types.c.

library/profiling_builtin.m:
	Replace the definitions of the predicates implementing the
	{call,exit,redo,fail} port predicates with external declarations.

trace/mercury_trace_vars.c:
	Use a now backend-independent macro to refer to a type_ctor_info.

trace/Mmakefile:
	Do not define MERCURY_BOOTSTRAP_H, since mercury_bootstrap.h now
	contains some definitions needed by code in the trace directory.
	Replace it with MR_NO_BACKWARDS_COMPAT.

util/mkinit.c:
	Module qualify the references to the RTTI structures of builtin types,
	since the generated _init.c files don't include mercury_bootstrap.h.
	Note that after this change has bootstrapped, we should be able to
	delete those references, since they were only needed to give the
	runtime access to the addresses of RTTI structures that used to be
	defined in the library, but are now defined in the runtime.
2002-08-09 05:26:56 +00:00
Zoltan Somogyi
f212df382e Make the compiler bootstrap again in deep profiling grades, even with sanity
Estimated hours taken: 10
Branches: main

Make the compiler bootstrap again in deep profiling grades, even with sanity
checks enabled. A few test cases still fail, and actually writing out profiling
data still trips a sanity check.

library/exception.m:
runtime/mercury_exception_catch_body.h:
	Fix a bug: builtin_catch was not calling prepare_for_ho_call before
	making a higher order call. This let the call port code in the called
	predicate access memory through an uninitialized pointer.

library/private_builtin.m:
	Fix the initialization code used in deep profiling grades, which
	previously were misrepresenting internal labels as entry labels.

compiler/options.m:
	Turn off the special handling of tail recursion by the deep profiling
	transformation, since at the moment it doesn't work.

compiler/layout_out.m:
	When outputing each call_site_static structure, include a comment
	giving its offset in the array containing it. This makes it easier
	to find the index you want in a large array of call_site_static
	structures.

runtime/mercury_debug.[ch]:
	Add an extra argument to MR_print_deep_prof_vars, to identify where it
	is called from. This makes it easier to understand debugging output.

runtime/mercury_deep_call_port_body.h:
library/profiling_builtin.m:
trace/mercury_trace_internal.m:
	Add the new argument to calls to MR_print_deep_prof_vars.

	Make calls to MR_print_deep_prof_vars conditional on a runtime test,
	to prevent huge amounts of unwanted output.
2002-08-07 03:18:57 +00:00
Zoltan Somogyi
04e614485d Implement deep profiling; merge the changes on the deep2 branch back
Estimated hours taken: 500
Branches: main

Implement deep profiling; merge the changes on the deep2 branch back
onto the trunk.

The main documentation on the general architecture of the deep profiler
is the deep profiling paper.

doc/user_guide.texi:
	Document how to use the deep profiler.

deep_profiler:
deep_profiler/Mmakefile:
	A new directory holding the deep profiler and its mmakefile.

Mmakefile:
	Add targets for the new directory.

	Add support for removing inappropriate files from directories.

deep_profiler/interface.m:
	The deep profiler consists of two programs: mdprof_cgi.m, which acts
	as a CGI "script", and mdprof_server.m, which implements the server
	process that the CGI script talks to. Interface.m defines the
	interface between them.

script/mdprof.in:
	A shell script template. ../configure uses it to generate mdprof,
	which is a wrapper around mdprof_cgi that tells it how to find
	mdprof_server.

deep_profiler/mdprof_cgi.m:
	The CGI "script" program.

deep_profiler/mdprof_server.m:
	The top level predicates of the server.

deep_profiler/profile.m:
	The main data structures of the server and their operations.

deep_profiler/read_profile.m:
	Code for reading in profiling data files.

deep_profiler/startup.m:
	Code for post-processing the information in profiling data files,
	propagating costs from procedures to their ancestors and performing
	various kinds of summaries.

deep_profiler/server.m:
	Code for responding to requests from the CGI script.

deep_profiler/cliques.m:
	Code to find cliques in graphs.

deep_profiler/array_util.m:
deep_profiler/util.m:
	Utility predicates.

deep_profiler/dense_bitset.m:
	An implementation of (part of) the set ADT with dense bit vectors.

deep_profiler/measurements.m:
	Operations on profiling measurements.

deep_profiler/timeout.m:
	An implementation of a timeout facility.

deep_profiler/conf.m:
	Functions that depend on autoconfigured settings.

configure.in:
	Find out what command to use to find the name of the local host.

	Install deep profiling versions of the standard library along with the
	other profiling versions.

runtime/mercury_conf.h.in:
	Add some macros for deep_profiler/conf.m to use.

library/profiling_builtin.m:
runtime/mercury_deep_call_port_body.h:
runtime/mercury_deep_leave_port_body.h:
runtime/mercury_deep_redo_port_body.h:
	A new library module that implements deep profiling primitives.
	Some of these primitives have many versions, whose common code is
	factor is factored out in three new include files in the runtime.

compiler/deep_profiling.m:
	New module to perform the program transformations described in the
	paper.

compiler/notes/compiler_design.html:
	Document the new compiler module.

compiler/mercury_compiler.m:
	Invoke the new module in deep profiling grades. Allow global static
	data to be generated by deep_profiling.m.

compiler/options.m:
	Add options to turn on deep profiling and (for benchmarking purposes)
	control its implementation.

	Add an optiooption disable tailcall optimization in the LLDS backend,
	to help benchmarking deep profiling.

compiler/jumpopt.m:
compiler/optimize.m:
	Obey the option to disable tailcalls.

compiler/handle_options.m:
	Handle the implications of deep profiling.

compiler/modules.m:
	In deep profiling grades, automatically import profiling_builtin.m.

compiler/prog_util.m:
doc/Makefile:
library/library.m:
	Handle the new builtin module.

compiler/export.m:
	In deep profiling grades, wrap deep profiling code around exported
	procedures to handle the "unscheduled call" aspects of callbacks to
	Mercury from the foreign language.

compiler/higher_order.m:
profiler/demangle.m:
util/demangle.c:
	When creating a name for a higher-order-specialized predicate, include
	the mode number in the name.

compiler/add_trail_ops.m:
compiler/type_util.m:
	Move c_pointer_type from add_trail_ops to type_util, so it can also be
	used by deep_profiling.m.

compiler/hlds_goal.m:
	Add a new goal feature that marks a tail call, for use by
	deep_profiling.m.

compiler/hlds_pred.m:
	Add a new field to proc_info structures for use by deep_profiling.m.

	Add a mechanism for getting proc_ids for procedure clones.

	Remove next_proc_id, an obsolete and unused predicate.

compiler/hlds_data.m:
	Add a new cons_id to refer to the proc_static structure of a procedure.

compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/dependency_graph.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Trivial changes to handle the new cons_id, goal feature and/or
	proc_info argument.

compiler/rtti.m:
	Add a utility predicate for extracting pred_id and proc_id from an
	rtti_proc_label, for use by hlds_out.m

compiler/layout.m:
compiler/layout_out.m:
compiler/llds.m:
compiler/llds_common.m:
	Add support for proc_static and call_site_static structures.

compiler/layout_out.m:
compiler/llds_out.m:
	Add code for the output of proc_static structures.

compiler/code_util.m:
	Make code_util__make_proc_label_from_rtti a function, and export it.

util/mkinit.c:
compiler/llds_out.m:
compiler/layout.m:
compiler/modules.m:
	Add support for a fourth per-module C function, for writing out
	proc_static structures (and the call_site_static structures they
	contains).

	Since proc_static structures can be referred to from LLDS code (and not
	just from other static structures and compiler-generated C code),
	reorganize the declarations of static structures slightly.

	Change the schema for the name of the first per-module C function
	slightly, to make it the addition of the fourth function easier.
	The scheme now is:

		mercury__<modulename>__init
		mercury__<modulename>__init_type_tables
		mercury__<modulename>__init_debugger
		mercury__<modulename>__write_out_proc_statics

	Improve formatting of the generated C code.

library/*.m:
runtime/mercury.c:
runtime/mercury_context.c:
runtime/mercury_engine.c:
runtime/mercury_ho_call.c:
runtime/mercury_tabling.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
trace/mercrury_trace.[ch]:
trace/mercrury_trace_declarative.c:
trace/mercrury_trace_external.c:
trace/mercrury_trace_internal.c:
	Conform to the new scheme for initialization functions for hand-written
	modules.

compiler/mercury_compile.m:
library/benchmarking.m:
runtime/mercury_conf_param.h:
runtime/mercury.h:
runtime/mercury_engine.c:
runtime/mercury_goto.c:
runtime/mercury_grade.h:
runtime/mercury_ho_call.c:
runtime/mercury_label.[ch]:
runtime/mercury_prof.[ch]:
	Add an MR_MPROF_ prefix in front of the C macros used to control the
	old profiler.

compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make deep profiling completely separate from the old profiling system,
	by making the deep profiling grade independent of MR_MPROF_PROFILE_TIME
	and the compiler option --profile-time.

library/array.m:
library/builtin.m:
library/std_util.m:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_compare_body.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of hand-written unification
	and comparison procedures.

	Make the reporting of array bounds violations switchable between
	making them fatal errors, as we currently, and reporting them by
	throwing an exception. Throwing an exception makes debugging code
	using arrays easier, but since exceptions aren't (yet) propagated
	across engine boundaries, we keep the old behaviour as the default;
	the new behaviour is for implementors.

runtime/mercury_deep_profiling_hand.h:
	New file that defines macros for use in Mercury predicates whose
	definition is in hand-written C code.

library/exception.m:
runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of the various modes of builtin_catch.

	Provide a function that C code can use to throw exceptions.

library/benchmarking.m:
library/exception.m:
library/gc.m:
library/std_util.m:
runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_overflow.h:
runtime/mercury_regs.h:
runtime/mercury_stacks.h:
runtime/mercury_thread.c:
runtime/mercury_wrapper.c:
	Add prefixes to the names of the fields in the engine and context
	structures, to make code using them easier to understand and modify.

runtime/mercury_deep_profiling.[ch]:
	New module containing support functions for deep profiling and
	functions for writing out a deep profiling data file at the end of
	execution.

runtime/mercury_debug.[ch]:
	Add support for debugging deep profiling.

	Add support for watching the value at a given address.

	Make the buffered/unbuffered nature of debugging output controllable
	via the -du option.

	Print register contents only if -dr is specified.

runtime/mercury_goto.h:
runtime/mercury_std.h:
	Use the macros in mercury_std.h instead of defining local variants.

runtime/mercury_goto.h:
runtime/mercury_stack_layout.h:
runtime/mercury_stack_trace.c:
runtime/mercury_tabling.c:
trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.c:
	Standardize some of the macro names with those used in the debugger
	paper.

runtime/mercury_heap.h:
	Add support for memory profiling with the deep profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_prof_time.[ch]:
	Move the functionality that both the old profiler and the deep profiler
	need into the new module mercury_prof_time. Leave mercury_prof
	containing stuff that is only relevant to the old profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_strerror.[ch]:
	Move the definition of strerror from mercury_prof to its own file.

runtime/mercury_wrapper.[ch]:
	Add support for deep profiling.

	Add suppory for controlling whether debugging output is buffered or
	not.

	Add support for watching the value at a given address.

runtime/Mmakefile:
	Mention all the added files.

scripts/mgnuc.in:
	Add an option for turning on deep profiling.

	Add options for controlling the details of deep profiling. These
	are not documented because they are intended only for benchmarking
	the deep profiler itself, for the paper; they are not for general use.

tools/bootcheck:
	Compile the deep_profiler directory as well as the other directories
	containing Mercury code.

	Turn off the creation of deep profiling data files during bootcheck,
	since all but one of these in each directory will be overwritten
	anyway.

	Add support for turning on --keep-objs by default in a workspace.

tools/speedtest:
	Preserve any deep profiling data files created by the tests.

trace/mercury_trace.c:
	Trap attempts to perform retries in deep profiling grades, since they
	would lead to core dumps otherwise.

util/Mmakefile:
	Avoid compile-time warnings when compiling getopt.

tests/*/Mmakefile:
tests/*/*/Mmakefile:
	In deep profiling grades, switch off the tests that test features
	that don't work with deep profiling, either by design or because
	the combination hasn't been implemented yet.
2001-05-31 06:00:27 +00:00
Fergus Henderson
2f737704b9 Add some Mmake rules to the runtime and some code to tools/bootcheck
Estimated hours taken: 16

Add some Mmake rules to the runtime and some code to tools/bootcheck
so that we automatically check that the namespace remains clean.
Also add some `MR_' prefixes that Zoltan missed in his earlier change.

tools/bootcheck:
	Add an option, which is enabled by default, to
	build the check_namespace target in the runtime.

runtime/RESERVED_MACRO_NAMES:
	New file.  Contains a list of the macros names that
	don't start with `MR_' or the like.

runtime/Mmakefile:
	Change the rule for `check_headers' so that it checks for macros
	that don't occur in the RESERVED_MACRO_NAMES files, as well as not
	starting with `MR_' prefixes, and reports errors for such macros.
	Also add a rule for check_objs that checks whether the object
	files define any global symbols that don't have the right prefixes,
	and a rule `check_namespace' that does both of the above.

runtime/mercury_bootstrap.h:
	#include "mercury_types.h" and "mercury_float.h",
	to ensure that this header file is self-contained.
	Also make sure that all the old names are disabled if you
	compile with `-DMR_NO_BACKWARDS_COMPAT'.

runtime/mercury_context.c:
runtime/mercury_thread.h:
runtime/mercury_thread.c:
	Use `bool' rather than `MR_Bool' for the argument to
	MR_check_pending_contexts() and the return type of
	MR_init_thread(), since these are C bools, not Mercury
	bools, and there's no requirement that they have the
	same size as MR_Integer.

runtime/mercury_type_info.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
library/std_util.m:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
tests/hard_coded/existential_types_test.m:
	Add MR_ prefixes to UNIV_OFFSET_FOR_TYPEINFO and UNIV_OFFSET_FOR_VALUE.

trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_tables.c:
	Add MR_ prefixes to do_init_modules().

runtime/mercury_tabling.h:
runtime/mercury_tabling.c:
runtime/mercury_overflow.h:
runtime/mercury_debug.h:
	Add MR_ prefixes to table_*.

runtime/mercury_overflow.h:
runtime/mercury_debug.h:
	Add MR_ prefixes to IF().

runtime/mercury_context.h:
	Add MR_ prefixes to IF_MR_THREAD_SAFE().

runtime/mercury_engine.h:
	Add MR_ prefixes to IF_NOT_CONSERVATIVE_GC().

runtime/mercury_engine.h:
runtime/mercury_engine.c:
extras/aditi/aditi.m:
	Add MR_ prefixs to do_fail, do_redo, do_not_reached, etc.

compiler/trace.m:
compiler/fact_table.m:
compiler/llds_out.m:
	Add MR_ prefixes to the generated code.
2000-12-04 18:28:57 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +00:00
Tyson Dowd
db64a3588d Add MR_ prefixes to the types used when generating C code.
Estimated hours taken: 4

Add MR_ prefixes to the types used when generating C code.
This means types such as Word, String, Bool, Float become MR_Word,
MR_String, MR_Bool, MR_Float.  Also define MR_Box for both the LLDS and
MLDS backends so we can use it uniformly.

This is very important in environments where String or Bool have already
been used as system types (for example, managed C++).  And besides, we
should do it anyway as part of the grand namespace cleanup.

I have fixed all of the uses of the non-prefixed types in the runtime
and trace directories.  I haven't done it for the library and compiler
directories yet (no promises that I will do it in future either).  But
if you see a non-prefixed type in code from now on, please consider it a
bug and fix it.

mercury_bootstrap.h contains #defines to map the non-prefixed types into
the prefixed ones.  Like many of the other namespace cleaning backwards
compatibility macros, this can be turned off with
MR_NO_BACKWARDS_COMPAT.

This shouldn't break any code, but this kind of change affects so many
things that of course there could be problems lurking in there somewhere.

If you start getting errors from the C compiler after this change is
installed, you will want to make sure you at least have the runtime
system updated so that you are getting the backwards compatibility
definitions in mercury_bootstrap.h.  Then if you continue to have
problems you can bug me about it.

compiler/export.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
	Use MR_Word, MR_Float, MR_Bool, etc when generating C.

doc/reference_manual.texi:
	Update the reference manual to talk about MR_Word, MR_String,
	MR_Char, etc.

runtime/mercury_bootstrap.h:
	Add bootstrapping typedefs.

runtime/*:
trace/*:
	Change Word, Float, Bool, Code, String, etc to
	MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.
2000-08-03 06:19:31 +00:00
Fergus Henderson
24ef39876c Reorganize some code in the runtime.
Estimated hours taken: 2

Reorganize some code in the runtime.

These changes were motivated in part by the desire to keep the runtime
for the MLDS back-end as well separated from the complications of the
current LLDS back-end as possible.

runtime/mercury_std.h:
runtime/mercury_misc.h:
	Move the definition of NO_RETURN from miscury_misc.h
	to mercury_std.h, since it's better to define all the
	compiler-dependent macros like this in one spot.

runtime/Mmakefile:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_debug.h:
runtime/mercury_debug.c:
	Move the debugging stuff from mercury_misc.{h,c}
	to mercury_debug.{h,c}.  Note that mercury_debug.c
	is a new file.

runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_reg_workarounds.h:
runtime/mercury_reg_workarounds.c:
	Move MR_memcpy() from mercury_misc.{h,c} to
	mercury_reg_workarounds.{h,c}.

runtime/mercury_stack_trace.c:
runtime/mercury_array_macros.h:
runtime/mercury_tabling.h:
	Add/remove/modify the #include directives
	to reflect the above-mentioned changes.
2000-05-08 14:01:02 +00:00
Zoltan Somogyi
566cec5b30 Prefix everything defined in runtime/mercury_{stacks,tags}.h MR_.
Estimated hours taken: 3

Prefix everything defined in runtime/mercury_{stacks,tags}.h MR_.
In the process, get rid of the grade component MR_DEBUG_NONDET_STACK,
since this makes the update to mercury_stacks.h simpler and its use is
long obsolete.

runtime/mercury_tags.h:
	Put MR_ prefixes in front of everything defined here.

runtime/mercury_stacks.h:
	Put MR_ prefixes in front of everything defined here.

	Remove support for MR_DEBUG_NONDET_STACK. Replace most of the
	lost functionality by calling an updated mkframe_msg.

	Remove the definitions of push() and pop(). Their use conflicts with
	the idea that everything on the det stack is part of a frame, which
	the RTTI stuff depends on.

runtime/mercury_bootstrap.h:
	Add backward compatibility macros for the old names in the above two
	files.

	Remove some old entries in this file which are no longer needed.

runtime/mercury_wrapper.c:
	Remove the only uses of push() and pop().

	Put MR_ in front of some things that need them.

runtime/mercury_engine.c:
	Put MR_ in front of some things that need them.

runtime/mercury_misc.[ch]:
	Make mkframe_msg get the name of the procedure that owns the stack
	frame from an explicitly passed argument, rather than the prednm slot
	(which no longer exists). This actually improves low-level debugging
	support without MR_DEBUG_NONDET_STACK.

	Remove unnecessary return statements.

runtime/mercury_debug.h:
	Pass on the new arg of mkframe_msg.

	Fix long lines.

runtime/mercury_conf_param.h:
	Remove the documentation of MR_DEBUG_NONDET_STACK.

runtime/mercury_grade.h:
	Remove the grade component of MR_DEBUG_NONDET_STACK.

doc/reference_manual.texi:
	Document the MR_ prefixed versions of list_empty, list_cons etc.

library/io.m:
library/std_util.m:
library/string.m:
	Add prefixes to some references to the runtime.
1999-04-30 04:25:43 +00:00
Zoltan Somogyi
5d33372f98 Fix some bugs in tabling, to enable the boyer test case to work.
Estimated hours taken: 6

Fix some bugs in tabling, to enable the boyer test case to work.

runtime/mercury_tabling.h:
	Add a new set of macros that optionally print debugging info at
	tabling actions. Debugging recquires compilation with -DMR_TABLE_DEBUG
	and -dT in MERCURY_OPTIONS.

runtime/mercury_table_any.c:
	Use the debugging macros. Fix two bugs, one found with their help.
	One is that a tagged pointer to the table giving information about
	remote secondary tags did not have its tag stripped before use.
	The other is that the extraction of local secondary tags from words
	was done by subtracting the tag, and not by shifting out the tag,
	leaving the secondary tag value too high by a factor of 4 or 8.

runtime/mercury_table_any.[ch]:
runtime/mercury_table_enum.[ch]:
	Change the order of some function arguments to be consistent with
	the orders in the macros that call these functions.

runtime/mercury_table_enum.c:
	Add an optional sanity check that detects the second bug above.

runtime/mercury_engine.[ch]:
	Add a new debug flag, MR_tabledebug. Rename the flags so they always
	start with MR_.

runtime/mercury_wrapper.c:
	Allow -dT in MERCURY_OPTIONS to set MR_tabledebug.

runtime/*.[ch]:
	Trivial changes for the new names of the debug flags.

runtime/Mmakefile:
	Reimpose alphabetical order on the list of C files.

library/private_builtin.m:
	Use the new debugging macros in the C code that does tabling.

	Expose the equivalence between ml_table, ml_subgoal_table_node etc
	and c_pointer. The reason is

	% These equivalences should be local to private_builtin. However,
	% at the moment table_gen.m assumes that it can use a single variable
	% sometimes as an ml_table and other times as an ml_subgoal_table_node
	% (e.g. by giving the output of table_lookup_insert_int as input to
	% table_have_all_ans). The proper fix would be for table_gen.m to
	% use additional variables and insert unsafe casts. However, this
	% would require significant work for no real gain, so for now
	% we fix the problem by exposing the equivalences to code generated
	% by table_gen.m.

library/mercury_builtin.m:
	Delete the contents of this obsolete file, leaving only a pointer
	to builtin.m and private_builtin.m.

tests/tabling/Mmakefile:
	Enable the boyer benchmark, since we now pass it.
1998-08-24 08:25:03 +00:00
Zoltan Somogyi
ed063bcc00 Extend the new failure handling method to optionally preserve an invariant
Estimated hours taken: 30

Extend the new failure handling method to optionally preserve an invariant
required by accurate gc: always being able to tell with respect to what MR_sp
or MR_curfr to interpret the stackvars and framevars referred to by the label
whose address is the redoip slot of a nondet stack frame. This basically
requires limitations on the hijacking of redoip/redofr slot pairs.

compiler/notes/failure.html:
	Describe the new extension.

	Change the terminology to conform to what is used in the code.

compiler/llds.m:
	For each temporary frame on the nondet stack, specify the native
	stack of the procedure that created it. This is so that we know
	whether the temporary frame ought to have the fourth slot that
	specifies the right value of MR_sp. (The fourth slot is included
	only in temporary nondet stack frames created procedures that live
	on the det stack; procedures that live on the nondet stack never
	have any of their variables on the det stack.)

	Remove the modframe llds instruction, since it does not specify
	what frame's redoip slot it is assigning to. This is error-prone
	(see peephole.m below). We were not using modframe much anyway.

compiler/llds_out.m:
compiler/opt_debug.m:
	Emit either mktempframe or mkdettempframe depending on the new
	field in temp_frame.

compiler/code_info.m:
	Add a fourth item to the failure state, which states whether
	the top frame of the nondet stack may be hijacked. Initialize
	it from the option --allow-hijacks. If about to do a hijack
	but the failure state says no, create a temporary frame instead.

	Separate out the code for creating temporary frames, since it
	is now called from more than one place. Generalize the code
	to handle the new type of temp frame.

compiler/code_info.m:
compiler/ite_gen.m:
	Simplify the way we transmit information about the location
	of the address of the nondet stack frame in which the soft cut
	is performed from the start of the condition to its end.

	Remove the predicate code_info__maybe_push_temp_frame;
	its functionality is now achieved in code_info.m by disabling
	and restoring --allow-hijacks around the generation of code
	for the condition. This also allows us to get rid of the code
	that finds out whether the condition can do any hijacking.

compiler/opt_util.m:
	Rename next_modframe as next_assign_to_redoip, and add an additional
	argument that says which frame's redoip we are after.

compiler/peephole.m:
	Use the new argument of opt_util__next_assign_to_redoip to fix a bug
	where a mkframe of a temporary frame (which leaves curfr unchanged)
	that was followed a modframe (which assigns to the redoip of curfr)
	was incorrectly optimized (the assignment to the redoip slot was
	applied to the temporary frame, not the ordinary one).

compiler/*.m:
	Minor changes to accommodate the disappearance of modframe.

runtime/mercury_stacks.h:
	Add macros to support four-word temp frames on the nondet stack.

	Make the macros that access nondet stack frame slots start with MR_,
	while keeping (redefined) macros needed for backward compatibility.

	Remove the modframe macro.

	Fix a dangling reference to PREDNM instead of MR_PREDNM.

runtime/mercury_stack_trace.c:
	Modify the stack tracing code to allow for the new four-word temp
	frames.

	Use the new MR_ prefixed variants of the macros.

runtime/mercury_debug.h:
runtime/mercury_misc.[ch]:
	Remove references to modframe.

tests/general/complex_failure.{m,exp}:
	A new test case to tickle the various ways of handling nested
	disjunctions and if-then-elses in the new code generator.

tests/general/Mmakefile:
	Enable the new test case.

tests/{general,hard_coded}/space.{m,exp}:
	Move this test case from general to hard_coded. Although NU-Prolog
	can execute it, it does not give the same answers as Mercury due to
	a different default ordering and a difference in integer size (26-bit
	integers in NU-Prolog) that changes the behavior of the pseudo
	random-number generator.

tests/hard_coded/cycles2.exp:
	Add the missing .exp file for this existing test case.

tests/hard_coded/Mmakefile:
	Enable the old test cases cycles, cycles2 and space, since
	we now pass them.
1998-07-29 08:57:09 +00:00
Fergus Henderson
c315607690 Clean up the handling of configuration macros in the runtime.
Estimated hours taken: 4

Clean up the handling of configuration macros in the runtime.

runtime/mercury_conf.h.in:
runtime/mercury_conf_param.h:
	Move the code to set configuration parameters based on
	the values of other configuration parameters from
	mercury_conf.h.in to a new file mercury_conf_param.h,
	because otherwise autoconf munges the code in undesirable ways
	(it replaces all `#undef <foo>' statements with `/* #undef <foo> */').

runtime/mercury_conf.h.in:
runtime/mercury_conf_param.h:
runtime/*.h:
runtime/*.c:
	Use more meaningful names, starting with the usual `MR_' prefix,
	for various configuration parameters:
		- replace the existing configuration macros SPEED with
		  three new macros MR_CHECK_OVERFLOW, MR_LOWLEVEL_DEBUG,
		  and MR_DEBUG_NONDET_STACK;
		- rename DEBUG_GOTOS as MR_DEBUG_GOTOS, and make it
		  implied by MR_LOWLEVEL_DEBUG;
		- rename DEBUG_LABELS as MR_CHOOSE_ENTRY_POINT.

	(But there are still many configuration parameters that don't
	start with `MR_', I'm afraid.)

runtime/CFLAGSFILE:
runtime/mercury_conf_param.h:
	Removed CFLAGSFILE.  The documentation there was had rotted badly.
	I moved most of it to mercury_conf_param.h where hopefully
	it will stand a better chance of being kept up-to-date.
	I added documentation for the configuration parameters added in
	the last year or so.  The documentation here now covers
	every configuration parameter that we use; please keep it that way!

runtime/mercury_debug.h:
	Fix a bug: there was a misplaced "#endif".

runtime/mercury_stack_trace.c:
	Fix yet another misspelling of "deterministic".
1998-03-16 12:23:40 +00:00
Fergus Henderson
d1795181eb Fix a name clash: the code here and in mercury_heap.h
Estimated hours taken: 0.5

runtime/mercury_debug.h:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
	Fix a name clash: the code here and in mercury_heap.h
	were using the name `incr_hp_msg' to mean two different things.
	The reason this wasn't picked up earlier is that the
	code here is only included conditionally, if DEBUG is defined.
	To fix it, I renamed the one here as `incr_hp_debug_msg'.
1998-01-23 15:26:35 +00:00
Tyson Dowd
bd19208eb9 Remove old .h files.
Estimated hours taken: 1

runtime/*.h:
runtime/*.c:
runtime/mercury_conf.h.in:
	Remove old .h files.
	Update #includes to refer to mercury_*.h
	Update #ifdef MODULE_H to be #ifdef MERCURY_MODULE_H
1997-11-23 07:21:53 +00:00
Tyson Dowd
7ce7d489a2 Cleaned up runtime directory.
Estimated hours taken: 2

Cleaned up runtime directory.

runtime/*.c:
	- Renamed all .c files as mercury_*.c
	  Some have been renamed to make their purpose clearer.
	  	call.mod -> mercury_ho_call.c

runtime/*.h:
	- Moved contents of .h files to mercury_*.h
	- *.h now contain #include mercury_*.h. They be removed later.
	- Updated references to conf.h -> mercury_conf.h

runtime/conf.h.in:
	- Renamed conf.h.in as mercury_conf.h.in.
	  Didn't leave a forwarding header for this one, as conf.h was
	  never part of the repository anyway.

runtime/Mmakefile:
	- Convert lists to one-per-line lists.
	- Add mercury_accurate_gc.h to HDRS.
	- Remove all .mod files
	- Make sure runtime.init uses the ORIG_CS not MOD_CS.
	- Fix the rules for "clean_o" and "clean_mod_c", which used
	  wildcards like "*.o" to remove files.  The one that removed
	  all .c files corresponding with *.mod, instead of using MOD_CS
	  was particularly vicious.
	- Cope with the file renamings.

configure.in:
	- Cope with the file renamings.
1997-11-20 02:04:40 +00:00