Commit Graph

130 Commits

Author SHA1 Message Date
Peter Wang
b45b70199b Add a post-processing pass directly after mode checking that tries to transform
Estimated hours taken: 30
Branches: main

Add a post-processing pass directly after mode checking that tries to transform
procedures to avoid intermediate partially instantiated data structures.  The
Erlang backend in particular cannot handle partially instantiated data
structures.

compiler/delay_partial_inst.m:
	New module.

compiler/check_hlds.m:
	Import delay_partial_inst.m

compiler/modes.m:
	Call the delay partial instantiations pass after mode checking succeeds
	if it is enabled.

compiler/options.m:
	Add a new internal option `--delay-partial-instantiations', disabled by
	default.

compiler/handle_options.m:
	Make Erlang target imply --delay-partial-instantiations.

compiler/notes/compiler_design.html:
	Mention delay_partial_inst.m

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/delay_partial_test.exp:
tests/hard_coded/delay_partial_test.m:
tests/hard_coded/delay_partial_test2.exp:
tests/hard_coded/delay_partial_test2.m:
	Add test cases for --delay-partial-instantiations.

compiler/goal_util.m:
	Fix a comment.
2007-06-25 00:58:14 +00:00
Peter Wang
4f723d6a53 Add initial support for typeclasses in the Erlang backend.
Estimated hours taken: 30
Branches: main

Add initial support for typeclasses in the Erlang backend.

Fix some bugs in the Erlang backend.  Most of these are related to the
optimisation that does away with unused and dummy arguments.  We cannot drop
those arguments for higher order functions, and we must materialise any
references to dummy arguments if they appear for some reason, e.g. in
contexts where they can't be dropped.

compiler/elds.m:
	Extend the ELDS for Erlang functions that, when called, return
	structures containing RTTI data.

	Collapse the representations of plain calls, higher order calls and
	calls to builtins so they share a single function symbol.

	Add references to RTTI data as a new type of ELDS expression.

	Simplify the implementation of join_exprs, whic also works better if
	one of the expressions to be joined could be an empty elds_block.

	Add some more helper predicates.

compiler/elds_to_erlang.m:
	Generate to code of standard modules to mercury__<module>.erl files,
	rather than <module>.erl.

	Output RTTI function definitions and export them to other modules.

	Fix a bug where opt_imported predicates were being qualified with their
	declaring module, even though the code was being generated in the
	current module.

	Quote more atoms which are spelt the same as Erlang keywords.

	Conform to other changes in the ELDS.

compiler/erl_call_gen.m:
	Generate code for class method calls.

	Materialise variables of dummy types if they appear in the argument
	lists of calls.

	Fix bugs in which arguments of dummy types were being dropped from
	the argument lists of higher order procedure calls.

	Refactor some code which was duplicated between plain calls, higher
	order calls and class method calls.

compiler/erl_code_gen.m:
	Fix some cases where references to unbound variables would show up
	after `erroneous' goals.

	Generate code for promise_purity and barrier scopes goals.

compiler/erl_code_util.m:
	Add a parameter to erl_gen_arg_list to control whether dummy and
	unused arguments should be discarded when dividing call arguments
	into inputs and outputs.

	Add erl_gen_arg_list_arg_modes which can be used instead of
	erl_gen_arg_list_arg_modes when only arg_modes are available
	(instead of modes).

	Add erl_base_typeclass_info_method_offset which returns the offset
	into the typeclass_info tuple of the first typeclass method.

	Conform to changes in the ELDS.

compiler/erl_rtti.m:
	New module to generate ELDS functions that return RTTI data structures.
	Currently we only generate functions for base_typeclass_infos.

compiler/erl_backend.m:
	Include erl_rtti.

compiler/erl_unify_gen.m:
	Ignore assignment unifications between variables of dummy types.

	Handle construction of partially instantiated data structures
	by assigning free variables to `false' before the construction.

	Handle construction of type ctor infos (incomplete due to missing
	RTTI function definitions), base typeclass infos and type infos and
	typeclass infos.

	Handle dummy arguments properly when creating higher order terms.

compiler/instmap.m:
	Fix an assumption in `var_is_bound_in_instmap_delta' that the instmap
	and instmap_delta that it is passed are reachable.  It used to succeed
	for unreachable instmaps (deltas) implying that the variable was bound.
	In some cases this resulted in Erlang code not binding some variables
	that it should have when `erroneous' code was reached.

	The only other user of `var_is_bound_in_instmap_delta' is the dependent
	parallel conjunction transformation.  Currently `erroneous' goals are
	not allowed in parallel conjunctions anyway.

compiler/mercury_compile.m:
	Call the code to generate ELDS function definitions for RTTI data.

compiler/notes/compiler_design.html:
	Mention erl_rtti.m.

	s/mlds_to_rtti/rtti_to_mlds/ in a spot.
2007-05-28 03:13:53 +00:00
Peter Wang
08f82a2f01 Initial version of a HLDS->Erlang code generator.
Estimated hours taken: 50
Branches: main

Initial version of a HLDS->Erlang code generator.  Currently det and semidet
code is supported.  The code generator converts HLDS data structures into a
new ELDS data structure, which is an internal representation of Erlang code.
Then the ELDS data structure is printed out into concrete Erlang syntax.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
	New files.

compiler/Mercury.options:
	Add --no-warn-unused-imports for erl_backend package.

compiler/top_level.m:
compiler/mercury_compile.m:
	Import the Erlang backend and call it for --target erlang.

compiler/modules.m:
	Add module_name_to_file_name_sep which is like module_name_to_file_name
	but allows modules to be qualified with a string other than ".".

library/array.m:
library/bitmap.m:
library/io.m:
	Add Erlang foreign_type declarations for array(T), bitmap and
	io.system_error so the compiler doesn't abort when generating
	interface files in the Erlang grade.

compiler/notes/compiler_design.html:
	Describe the Erlang backend.
2007-05-15 02:38:23 +00:00
Zoltan Somogyi
14f8ee8369 Move the part of typecheck.m that deals with improving headvar names
Estimated hours taken: 0.2
Branches: main

compiler/headvar_names.m:
compiler/typecheck.m:
	Move the part of typecheck.m that deals with improving headvar names
	into a module of its own.

	There are no algorithmic changes.

compiler/hlds.m:
	Include the new module.

compiler/notes/compiler_design.html:
	Mention the new module.
2007-05-14 10:58:26 +00:00
Julien Fischer
1a41307633 During the initial stage of the polymorphism transformation maintain
Estimated hours taken: 4
Branches: main

During the initial stage of the polymorphism transformation maintain
a more strict separation between the modes for the different kinds
of introduced arguments.

Add a new data structure to do this.  The new data structure is called a
poly_arg_vector, which is similar to a proc_arg_vector but is intended to
represent only those arguments that have been introduced by polymorphism.
The new data structure is implemented as a proc_arg_vector in order to
ensure that the calling convention is consistent across both structure.

compiler/hlds_args.m:
	Add the poly_arg_vector structure and some predicates that
	operate on it.

	Fix a comment.

compiler/polymorphism.m:
	When processing the clause arguments accumulate the modes for the
	introduced type_infos and typeclass_info arguments in a
	poly_arg_vector rather than just building up a list of them.
	This allows us to maintain the distinction between the different
	kinds of introduced arguments.

	Introduce state variables in a couple of places and rearrange
	some argument orderings to make this possible.

compiler/notes/compiler_design.html:
	Mention the hlds_args module.
2007-01-11 03:36:01 +00:00
Zoltan Somogyi
82eab0e65e Add an optional pass that tries to avoid generating too many parallel goals.
Estimated hours taken: 12
Branches: main

Add an optional pass that tries to avoid generating too many parallel goals.
The first transformation implemented by this pass is to transform parallel
conjunctions into goals of the form

	( queues already contain lot of work ->
		sequential version of parallel conjunction
	;
		parallel conjunction as before
	)

if they contain recursive calls.

The effect of this transformation is to reduce the overhead of the new par_fib
test case from:

	fib(35): sequential 189 vs parallel 5770

to

	fib(35): sequential 189 vs parallel 1090

i.e. a speedup of more than a factor of five.

compiler/granularity.m:
	New module that implements this transformation. I intend to add other,
	more sophisticated transformations in the future.

compiler/transform_hlds.m:
	Add granularity.m as one of the submodules of transform_hlds.m.

compiler/mercury_compile.m:
	Invoke the new pass.

	Invoke dep_par_conj only if needed.

	Fix some stage numbers.

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

	Document some modules that should have been documented earlier.

	Fix a hurried deletion of a reference to the Aditi backend.

compiler/goal_util.m:
	Add some utility functions for use by the new module.

compiler/simplify.m:
	Record the information mercury_compile.m needs in order to check
	whether we have any parallelism for granularity.m and dep_par_conj.m
	to process.

compiler/hlds_module.m:
	Add a slot to the module_info to record the information from
	simplify.m. Clean up some interfaces.

compiler/add_type.m:
	Conform to the change to hlds_module.m.

compiler/dependency_graph.m:
	Delete unnecessary module qualifications, and rename some predicates
	to avoid potential ambiguities.

compiler/options.m:
	Add the options required for controlling the new transformation.

	Rename an option's internal name to avoid conflict with a language
	keyword (the user-visible name remains unchanged).

	Move some options around to put them in logical groups.

doc/user_guide.texi:
	Document the new options.

	Fix some omissions in some earlier options.

compiler/handle_options.m:
compiler/termination.m:
	Conform to the option rename.

compiler/quantification.m:
	Rename some predicates to avoid ambiguities.

library/par_builtin.m:
	Add a predicate for use by the new transformation.

tests/par_conj/par_fib.{m,exp}:
	A new test case: a version of fib for use in testing parallelism.

tests/par_conj/Mmakefile:
	Enable the new test case.
2006-11-03 08:31:22 +00:00
Peter Ross
f08f22a7de Generate an XML representation of the du types in the current module.
Estimated hours taken: 24
Branches: main

Generate an XML representation of the du types in the current module.
The XML representation contains all the information about the type,
as well as associating with each type, data constructor and data field
any comments located near the comment.

The current strategy associates the comment starting on the same line
as the type declaration, and if there is none then the comment directly
above.  At a later date, this strategy needs to be made more flexible.

This required two main changes to the compiler.
Change one was to associate with a term.variable the context
of that variable.
Then the constructor and constructor_arg types had to have their
context recorded.

compiler/xml_documentation.m:
	Add a pass that generates an XML documentation
	for the du types in the current module.

compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
	Call the xml_documentation phase and stop afterwards.

compiler/error_utils.m:
	Add a utitily predicate for reporting errors where
	a file is unable to be opened.

library/term.m:
	Add the term.context to term.variables.
	Remove the backwards mode of var_list_to_term_list as it
	no longer works.
	Make the predicate version of term_list_to_var_list
	semidet as we can no longer use the backwards version
	var_list_to_term_list.

NEWS:
	Mention the changes to the term module.

library/parser.m:
	Fill in the term.context of term.variables while parsing.

compiler/prog_data.m:
	Add the context to the constructor and constructor_arg types.

compiler/prog_io.m:
	Fill in the context fields in the constructor and constructor_arg
	types.

compiler/add_clause.m:
compiler/prog_io.m:
compiler/prog_io_typeclass.m:
compiler/typecheck.m:
	Call the correct version of term_list_to_var_list,
	to deal with the fact that we removed the reverse
	mode of var_list_to_term_list.

compiler/notes/compiler_design.html:
doc/user_guide.texi:
	Document the new module.

compiler/add_clause.m:
compiler/det_util.m:
compiler/fact_table.m:
compiler/hlds_out.m:
compiler/inst_graph.m:
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/prog_ctgc.m:
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/state_var.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/typecheck_errors.m:
library/term_io.m:
library/varset.m:
	Handle the context in the term.variable structure.

compiler/add_type.m:
compiler/check_typeclass.m:
compiler/equiv_type.m:
compiler/hhf.m:
compiler/hlds_out.m:
compiler/inst_check.m:
compiler/make_tags.m:
compiler/mercury_to_mercury.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/prog_io.m:
compiler/prog_mode.m:
compiler/prog_type.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/special_pred.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/untupling.m:
compiler/unused_imports.m:
	Handle the context field in the constructor and constructor_arg
	types.

compiler/check_hlds.m:
	Add the xml_documentation module.
2006-11-01 06:33:38 +00:00
Peter Ross
3c5640b572 Add an analysis which determines the set of modules which
Branch: main
Estimated hours: 24

Add an analysis which determines the set of modules which
are imported but are not used.
It also has a more precise analysis of those modules not needed
in the interface, as it reports more modules than the current
analysis.

compiler/unused_imports.m:
	The module which does the analysis.

compiler/make_hlds_passes.m:
	Record the parent used modules.
	Factor out the code for adding the module specifiers.

compiler/hlds_module.m:
	Add utility predicates for recording those modules
	used in the parent modules of the current module and
	those imports which are in the interface.

compiler/options.m:
	Add the option --warn-unused-imports.
	By default it's turned off because I have yet
	to run this analysis on the compiler and fix
	the modules.

compiler/check_hlds.m:
compiler/mercury_compile.m:
	Add the analysis to the compiler.

doc/user_guide.texi:
	Document the new option.

compiler/notes/compiler_design.html:
	Document the new pass.
2006-09-15 11:14:38 +00:00
Zoltan Somogyi
91501d2453 This diff is the first step in implementing trace events.
Estimated hours taken: 12
Branches: main

This diff is the first step in implementing trace events. It introduces the
representation of trace event goals into both the parse tree and HLDS
representations, and updates most compiler passes to handle them.
Changes to the code generator and to the runtime system, user-level
documentation and test cases will come later.

library/ops.m:
	Add "event" as an operator.

mdbcomp/program_representation.m:
	Extend the representation of goals to include events.

browser/declarative_execution.m:
	Allow the reconstruction from bytecode of event goals.

browser/declarative_tree.m:
	Extend the algorithm for following terms to their sources to allow
	it to traverse events (which never generate any values).

compiler/prog_item.m:
compiler/hlds_goal.m:
	Extend the parse tree and the HLDS representations to include event
	goals.

compiler/prog_io_goal.m:
	Convert the term representation of events to the parse tree
	representation.

compiler/add_clause.m:
	Convert the parse tree representation of events to the HLDS
	representation.

compiler/prog_event.m:
	Add this new module to contain the compiler's database of event types.

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

compiler/parse_tree.m:
	Include the new module.

compiler/prog_rep.m:
	Generate the extended bytecode for event goals.

compiler/mercury_to_mercury.m:
	Output event goals.

compiler/typecheck.m:
	Typecheck event goals. The types of the arguments of each event type
	is given by the database in prog_event.m.

compiler/typecheck_errors.m:
	Add a predicate for reporting unknown events.

compiler/modecheck_call.m:
	Add a predicate to modecheck event goals. The modes of the arguments
	are also given by the database in prog_event.m.

compiler/modes.m:
	Call the new predicate in modecheck_call.m for event goals.

	Some predicates in this module took a boolean flag, tested many times
	at runtime, to control whether an exact match was required or not.
	However, the choice was fixed at all call sites except one. I have
	split each predicate into two, one for each value of the boolean flag,
	both for clarity of code and for slightly improved speed.

compiler/ml_call_gen.m:
	Ignore event goals, since the MLDS backend doesn't support debugging.

compiler/call_gen.m:
	Document the fact that event goals *should* be handled here.

compiler/build_mode_constraints.m:
compiler/deep_profiling.m:
compiler/exception_analysis.m:
compiler/goal_util.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/mercury_to_mercury.m:
compiler/mlds_to_c.m:
compiler/mode_constraints.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/simplify.m:
compiler/superhomogeneous.m:
compiler/tabling_analysis.m:
compiler/term_traversal.m:
compiler/trailing_analysis.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/unique_modes.m:
	Handle the new goal type. In most cases the new code should be
	functional, but in a few cases (e.g. constraint based mode analysis
	and deep profiling) it just aborts the compiler.
2006-09-05 06:21:37 +00:00
Zoltan Somogyi
9d23d8e2e7 Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main

Implement the trace goal construct we discussed, for now for the LLDS backends
only.

Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.

We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.

Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.

library/ops.m:
	Add "trace" as an operator.

compiler/prog_data.m:
	Define data types to represent the various attributes of trace goals.

	Rename some function symbols to avoid ambiguities.

compiler/prog_item.m:
	Extend the parse tree representation of goals with a trace goal.

compiler/mercury_to_mercury.m:
	Output the new kind of goal and its components.

compiler/hlds_goal.m:
	Extend the HLDS representation of scopes with a scope_reason
	representing trace goals.

	Add a mechanism (an extra argument in foreign_procs) to allow
	the representation of goals that evaluate runtime trace conditions.

	Since this requires modifying all code that traverses the HLDS,
	do some renames that were long overdue: rename not as negation,
	rename call as plain_call, and rename foreign_proc as
	call_foreign_proc. These renames all avoid using language keywords
	as function symbols.

	Change the way we record goals' purities. Instead of optional features
	to indicate impure or semipure, which is error-prone, use a plain
	field in the goal_info, accessed in the usual way.

	Add a way to represent that a goal contains a trace goal, and should
	therefore be treated as if it were impure when considering whether to
	optimize it away.

	Reformat some comments describing function symbols.

compiler/hlds_out.m:
	Output the new construct in the HLDS.

compiler/prog_io_util.m:
	Generalize the maybe[123] types to allow the representation of more
	than one error message. Add functions to extract the error messages.
	Add a maybe4 type. Rename the function symbols of these types to
	avoid massive ambiguity.

	Change the order of some predicates to bring related predicates
	next to each other.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
	Rework these modules almost completely to find and accumulate syntax
	errors as terms are being parsed. In some cases, this allowed us to
	replace "XXX this is a hack" markers with meaningful error-reporting
	code.

	In prog_io_goal.m, add code for parsing trace goals.

	In a bunch of places, update obsolete coding practices, such as using
	nested chains of closures instead of simple sequential code, and
	using A0 and A to refer to values of different types (terms and goals
	respectively). Use more meaningful variable names.

	Break up some too-large predicates.

compiler/superhomogeneous.m:
	Find and accumulate syntax errors as terms are being parsed.

compiler/add_clause.m:
	Add code to transform trace goals from the parse tree to the HLDS.
	This is where the IO state and mutable variable attributes of trace
	goals are handled.

	Eliminate the practice of using the naming scheme Body0 and Body
	to refer to values of different types (prog_item.goal and hlds_goal
	respectively).

	Use error_util for some error messages.

library/private_builtin.m:
	Add the predicates referred to by the transformation in add_clause.m.

compiler/goal_util.m:
	Rename a predicate to avoid ambiguity.

compiler/typecheck.m:
	Do not print error messages about missing clauses if some errors have
	been detected previously.

compiler/purity.m:
	Instead of just computing purity, compute (and record) also whether
	a goal contains a trace goal. However, treat trace goals as pure.

compiler/mode_info.m:
	Add trace goals as a reason for locking variables.

	Rename some function symbols to avoid ambiguity.

compiler/modes.m:
	When analyzing trace goal scopes, lock the scope's nonlocal variables
	to prevent them from being further instantiated.

compiler/det_analysis.m:
	Insist on the code in trace goal scopes being det or cc_multi.

compiler/det_report.m:
	Generate the error message if the code in a trace goal scope isn't det
	or cc_multi.

compiler/simplify.m:
	At the end of the front end, eliminate trace goal scopes if their
	compile-time condition is false. Transform trace goals with runtime
	conditions as described at the top.

	Treat goals that contain trace goals as if they were impure when
	considering whether to optimize them away.

compiler/mercury_compile.m:
	Tell simplify when it is being invoked at the end of the front end.

	Rename a predicate to avoid ambiguity.

compiler/trace_params.m:
	Provide the predicates simplify.m need to be able to evaluate the trace
	goal conditions regarding trace levels.

compiler/trace.m:
compiler/trace_gen.m:
	Rename the trace module as trace_gen, since "trace" is now an operator.

	Rename some predicates exported by the module, now that it is no longer
	possible to preface calls with "trace." as a module qualifier.

compiler/notes/compiler_design.html:
	Document this name change.

compiler/options.m:
	Rename the trace option as trace_level internally, since "trace"
	is now an operator. The user-visible name remains the same.

	Add the new --trace-flag option.

	Delete an obsolete option.

compiler/handle_options.m:
	Rename the function symbols of the grade_component type,
	since "trace" is now an operator.

compiler/llds.m:
	Extend the LLDS with a mechanism to refer to C global variables.
	For now, these are used to refer to C globals that will be created
	by mkinit to represent the initial values of the environment variables
	referred to by trace goals.

compiler/commit_gen.m:
	Check that no trace goal with a runtime condition survives to code
	generation; they should have been transformed by simplify.m.

compiler/code_gen.m:
	Tell commit_gen.m what kind of scope it is generating code for.

compiler/pragma_c_gen.m:
	Generate code for runtime conditions when handling the foreign_procs
	created by simplify.m.

compiler/code_info.m:
	Allow pragma_c_gen.m to record what environment variables it has
	generated references to.

compiler/proc_gen.m:
	Record the set of environment variables a procedure refers to
	in the LLDS procedure header, for efficient access by llds_out.m.

compiler/llds_out.m:
	Handle the new LLDS construct, and tell mkinit which environment
	variables need C globals created for them.

compiler/pd_util.m:
	Rename some predicates to avoid ambiguity.

compiler/*.m:
	Conform to the changes above, mainly the renames of function symbols
	and predicates, the changed signatures of some predicates, and the new
	handling of purity.

util/mkinit.c:
	Generate the definitions and the initializations of any C globals
	representing the initial status (set or not set) of environment
	variables needed by trace goals.

library/assoc_list.m:
	Add some predicates that are useful in prog_io*.m.

library/term_io.m:
	Minor cleanup.

tests/hard_coded/trace_goal_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at compile time.

tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at run time.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
	Enable the new test cases.

tests/invalid/*.err_exp:
	Update the expected output for the new versions of the error messages
	now being generated.
2006-07-27 05:03:54 +00:00
Ian MacLarty
c876a25f68 Issue a warning message if a user defined bound inst is not consistent with
Estimated hours taken: 6
Branches: main

Issue a warning message if a user defined bound inst is not consistent with
any of the types in scope.

The warning needs to be disabled by default until all the Mercury machines
have been updated.  This is because we will need to disable the warning for
the array module, since the following inst triggers the warning:

	:- inst array(I) == bound(array(I)).

The problem is that there is no type with a function symbol array/1.  I think
if we allow insts to be annotated with a type (as Zoltan suggested), then this
problem would go away, since we needn't check insts that are for foreign types.

NEWS:
	Mention the new warning.

compiler/check_hlds.m:
	Include the new module check_hlds.inst_check.

compiler/inst_check.m:
	Implement a predicate that checks that all user defined insts
	are consistent with at least one type in scope.  The predicate
	issues a warning if no consistent types are found for an inst.

compiler/mercury_compile.m:
	Check insts at stage 12, before type and mode checking.

compiler/options.m:
	Add an option to turn the new warning on or off.

compiler/notes/compiler_design.html:
	Document the new module and compilation stage.

doc/user_guide.texi:
	Document the option to disable the new warning.

tests/warnings/Mmakefile:
tests/warnings/Mercury.options:
tests/warnings/inst_with_no_type.m:
tests/warnings/inst_with_no_type.exp:
tests/warnings/inst_with_no_type_2.m:
	Test the new warning.
2006-07-20 01:50:47 +00:00
Julien Fischer
1505c035be Add an analysis that determines what goals might call code that uses minimal
Estimated hours taken: 12
Branches: main

Add an analysis that determines what goals might call code that uses minimal
model tabling.  We use this information to avoid emitting redundant pneg
context wrappers.  This reduces the overhead of minimal model tabling.

Add two new foreign_proc attributes: `may_call_mm_tabled' and
`will_not_call_mm_tabled' that allow users to annotate foreign_procs that may
call Mercury with information about whether they call minimal model tabled
procedures.

compiler/tabling_analysis.m:
	New file.  This module contains code for the new analysis.
	It is similar to trail usage analysis.

compiler/transform_hlds.m:
	Include the new module.

compiler/options.m:
	Add a new option `--analyse-mm-tabling' that enables the new analysis
	and optimization.

	Delete a now-redundant comment about the `--optimize-trail-usage'
	option.

	Fix some bad indentation.

compiler/mercury_compile.m:
	Add the analysis.

	Rearrange the stage numbers after stage 190 as we are running out of
	room between 190-200.

compiler/hlds_module.m:
	Add a slot in the HLDS to store information about which procedures
	might call minimal model tabled procedures.

compiler/prog_data.m:
	Add support for the new foreign_proc attributes: `may_call_mm_tabled'
	and `will_not_call_mm_tabled'.

compiler/mmc_analysis.m:
	Allow the new analysis to be use within the intermodule-analysis
	framework.

compiler/prog_item.m:
compiler/add_pragma.m:
compiler/prog_io_pragma.m:
compiler/mercury_to_mercury.m:
compiler/trans_opt.m:
	Add a new pragma, mm_tabling_info, for use in .opt and .trans_opt
	files.

compiler/hlds_goal.m:
	Add a new goal feature that indicates that a goal does not call
	minimal model tabled procedures.

compiler/ite_gen.m:
	Do not emit pneg context wrappers for goals that cannot call minimal
	model tabled procedures.

compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/saved_vars.m:
	Minor changes to conform to the above.

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

	Fix a typo: s/qualication/qualification/

doc/user_guide.texi:
doc/reference_manual.texi:
	Document the foreign code attributes and compiler options.
2006-06-05 02:26:12 +00:00
Zoltan Somogyi
4e6c603d30 Fix two bugs that caused test case failures in deep profiling grades.
Estimated hours taken: 3
Branches: main

compiler/lookup_switch.m:
	Fix two bugs that caused test case failures in deep profiling grades.

	One bug was that an acquired register wasn't being released before
	the creation of a resume point, which rebuilds the code generator state
	(and thus forgets about acquired registers).

	The other bug was that is_lookup_switch wasn't performing the actions
	generate_goal would have when processing goals. In particular, it
	wasn't invoking pre_goal_update and post_goal_update on disjunctions
	inside the switch.

compiler/lookup_util.m:
	Do not standardize goals by removing scopes from around other goals,
	because this could also remove the effects of the code generator
	annotations (e.g. liveness changes such as pre-births) on the scope
	goal.

compiler/simplify.m:
	Eliminate those redundant scopes if asked to do so. Since this is done
	before the code generator annotations are put on goals, this is safe.

compiler/code_gen.m:
compiler/proc_gen.m:
	Divide the old code_gen.m into two modules: the new code_gen.m
	concerned with generating code for goals, and the new module proc_gen.m
	concerned with generating code for procedures. Without this, the code
	for handling goals is lost inside the old code_gen.m module.

compiler/ll_backend.m:
	Include the new module.

compiler/mercury_compile.m:
	Import proc_gen instead of code_gen, and ask simplify to eliminate
	unnecessary scopes before code generation.

compiler/middle_rec.m:
	Update a reference to a predicate now in proc_gen.m.

compiler/notes/compiler_design.html:
	Document the new module.
2006-05-03 06:46:20 +00:00
Zoltan Somogyi
d5d5986472 Implement lookup switches in which a switch arm may contain more than one
Estimated hours taken: 40
Branches: main

Implement lookup switches in which a switch arm may contain more than one
solution, such as this code here:

	p(d, "four", f1, 4.4).
	p(e, "five", f2, 5.5).
	p(e, "five2", f3(5), 55.5).
	p(f, "six", f4("hex"), 6.6).
	p(g, "seven", f5(77.7), 7.7).
	p(g, "seven2", f1, 777.7).
	p(g, "seven3", f2, 7777.7).

Such code occurs frequently in benchmark programs used to evaluate the
performance of tabled logic programming systems.

Change frameopt.m, which previously worked only on det and semidet code,
to also work for nondet code. For predicates such as the one above, frameopt
can now arrange for the predicate's nondet stack frame to be created only
when a switch arm that has more than one solution is selected.

compiler/lookup_switch.m:
	Extend the existing code for recognizing and implementing lookup
	switches to recognize and implement them even if they are model_non.

compiler/lookup_util.m:
	New module containing utility predicates useful for implementing
	both lookup switches, and in the future, lookup disjunctions (i.e.
	disjunctions that correspond to a nondet arm of a lookup switch).

compiler/ll_backend.m:
	Include the new module.

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

compiler/global_data.m:
	Move the job of filling in dummy slots to our caller, in this case
	lookup_switch.m.

compiler/frameopt.m:
	Generalize the existing code for delaying stack frame creation,
	which worked only on predicates that live on the det stack, to work
	also on predicates that live on the nondet stack. Without this,
	predicates whose bodies are model_non lookup switches would create
	a nonstack stack frame before the switch is ever entered, which
	is wasteful if the selected switch arm has at most one solution.

	Since the structure of model_non predicates is more complex (you can
	cause a branch to a label by storing its address in a redoip slot,
	you can succeed from the frame without removing the frame), this
	required considerable extra work. To make the new code debuggable,
	record, for each basic block that needs a stack frame, *why* it
	needs that stack frame.

compiler/opt_util.m:
	Be more conservative about what refers to the stack. Export some
	previously internal functionality for frameopt. Turn some predicates
	into functions, and rename them to better reflect their purpose.

compiler/opt_debug.m:
	Print much more information about pragma_c and call LLDS instructions.

compiler/prog_data.m:
	Add an extra attribute to foreign_procs that says that the code
	of the foreign_proc assumes the existence of a stack frame.
	This is needed to avoid frameopt optimizing the stack frame away.

compiler/add_pragma.m:
	When processing fact tables, we create foreign_procs that assume
	the existence of the stack frame, so set the new attribute.

compiler/pragma_c_gen.m:
	When processing foreign_procs, transmit the information in the
	attribute to the generated LLDS code.

compiler/llds.m:
	Rename the function symbols referring to the fixed slots in nondet
	stack frames to make them clearer and to avoid overloading function
	symbols such as curfr and succip.

	Rename the function symbols of the call_model type to avoid overloading
	the function symbols of the code_model type.

	Add a new field to the c_procedure type giving the code_model of the
	procedure, and give names to all the fields.

	Describe the stack slots used by lookup switches to the debugger
	and native gc.

compiler/options.m:
doc/user_guide.texi:
	Add a new option, --debug-opt-pred-name, that does when the existing
	--debug-opt-pred-id options does, but taking a user-friendly predicate
	name rather than a pred_id as its argument.

compiler/handle_options.m:
	Process --debug-opt-pred-name, and make --frameopt-comments imply
	--auto-comments, since it is not useful without it.

	Reformat some existing comments that were written in the days of
	8-space indentation.

compiler/optimize.m:
	Implement the new option.

	Use the new field of the c_procedure type to try only the version
	of frameopt appropriate for the code model of the current procedure.

	Do a peephole pass after frameopt, since frameopt can generate code
	sequences that peephole can optimize.

	Make the mechanism for recording the process of optimizing procedure
	bodies more easily usable by including the name of the optimization
	that created a given version of the code in the name of the file
	that contains that version of the code, and ensuring that all numbers
	are two characters long, so that "vi procname*.opt*" looks at the
	relevant files in the proper chronological sequence, instead of having
	version 11 appear before version 2.

compiler/peephole.m:
	Add a new optimization pattern: a "mkframe, goto fail" pair (which
	can be generated by frameopt) should be replaced by a simple "goto
	redo".

compiler/code_gen.m:
	Factor out some common code.

compiler/llds_out.m:
	Ensure that C comments nested inside comment(_) LLDS instructions
	aren't emitted as nested C comments, since C compilers cannot handle
	these.

compiler/code_info.m:
compiler/code_util.m:
compiler/continuation_info.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/middle_rec.m:
compiler/ml_code_gen.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/stack_layout.m:
compiler/transform_llds.m:
compiler/var_locn.m:
	Conform to the change to prog_data.m, opt_util.m and/or llds.m.

compiler/handle_options.m:
	Don't execute the code in stdlabel.m if doing so would cause a compiler
	abort.

tests/hard_coded/dense_lookup_switch_non.{m,exp}:
	New test case to exercise the new algorithm.

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

tests/hard_coded/cycles.m:
	Make this test case conform to our coding convention.
2006-04-26 03:06:29 +00:00
Zoltan Somogyi
e8832be3a5 A new module that contains code to standardize labels in the LLDS.
Estimated hours taken: 1
Branches: main

compiler/stdlabel.m:
	A new module that contains code to standardize labels in the LLDS.

compiler/ll_backend.m:
	Include the new module in this package.

compiler/options.m:
	Add an option that governs whether stdlabel.m is invoked or not.

compiler/optimize.m:
	If the option is set, invoke stdlabel.m.

compiler/opt_util.m:
	Add an option to opt_util.replace_labels_instruction_list to allow
	it to replace labels in label instructions themselves.

compiler/dupelim.m:
	Conform to the changes in opt_util.m

compiler/notes/compiler_design.html:
	Document the new module.
2006-04-10 04:28:24 +00:00
Zoltan Somogyi
3ebda6545f Move the stuff currently in hlds_pred.m that deals with clauses into a new
Estimated hours taken: 1.5
Branches: main

Move the stuff currently in hlds_pred.m that deals with clauses into a new
module, hlds_clauses.m.

Move the stuff currently in hlds_pred.m that deals with RTTI into a new
module, hlds_rtti.m.

Move the stuff currently in hlds_module.m that deals with predicate tables
into a new module, pred_table.m.

These changes make hlds_pred.m and hlds_module.m much more cohesive, but there
are no changes in algorithms.

compiler/hlds_clauses.m:
compiler/hlds_rtti.m:
compiler/pred_table.m:
	New modules as described above. In some cases, fix mixleading or
	ambiguous predicate names in the process, and convert a few predicates
	to functions.

compiler/hlds_pred.m:
compiler/hlds_module.m:
	Delete the stuff moved to other modules.

compiler/*.m:
	In modules that need the functionality moved a new module, import
	the new module. It is rare for all the new modules to be needed,
	and many modules don't need any of the new modules at all. (For
	example, of the 200+ modules that import hlds_module.m, only about 40
	need pred_table.m.)

	Conform to the few minor changes to e.g. predicate names.

compiler/notes/compiler_design.html:
	Document the new modules.
2006-03-24 03:04:20 +00:00
Zoltan Somogyi
4d377aba26 Fix a bug reported by Greg Duck. The bug was that the compiler always generated
Estimated hours taken: 5
Branches: main

Fix a bug reported by Greg Duck. The bug was that the compiler always generated
a global variable of type MR_Word for each mutable, but could then assign
variables of other types to and from this global. If this other type is
float, the assignments discard the fractional part. If this other type
is something else, the result can be even worse.

There are two ways to fix this discrepancy. One is to change the type of the
global, and the other is to change the type of the variables it is assigned
to and from. The former looks cleaner, but it would mean that every call
to the get predicate would require a boxing operation, and that can be
relatively slow, since (e.g. for floats) it may require allocating a heap cell.
This diff implements both solutions.

We use the second solution on the LLDS backend because of its better
performance. We have to use the first solution on the MLDS backend,
because on that backend the type of the mutable variable is reflected
in the signature of the getter and setter predicates (whereas on the
LLDS backend all arguments are always MR_Words).

compiler/options.m:
	Add an internal-only option that controls whether we use the first
	solution or the second.

compiler/handle_options.m:
	Make the MLDS backend imply the first solution.

compiler/prog_data.m:
	For each argument of a foreign_proc item, record whether we want to
	keep it boxed in the foreign code.

	Add a foreign_proc attribute that asks for every arg to be kept boxed.
	We can attach this to the mutable implementation foreign_procs we write
	out to .opt files. This attribute is deliberately undocumented since
	users should never use it.

compiler/make_hlds_passes.m:
	For each argument of the get and set foreign_procs we create for
	mutables, record that we do want to keep it boxed.

	Move the action of creating the foreign code for the mutable's
	declaration and definition to the third pass, since during the second
	pass we don't necessarily know yet what its foreign type is (we may not
	have processed a foreign_type declaration affecting it). Move the code
	for creating the foreign code here from prog_mutable, since it depends
	on the HLDS (and prog_mutable.m is in the parse_tree package).

	Hoist some error handling code to put it where it belongs,
	and to avoid some errors being reported twice.

compiler/hlds_goal.m:
	For each argument of a foreign_proc goal, record whether we want to
	keep it boxed in the foreign code.

compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
compiler/ml_call_gen.m:
	If a foreign_proc argument is noted as being kept boxed in the
	foreign_proc code, then keep it that way.

compiler/prog_io_pragma.m:
	Parse the new foreign_proc annotation.

compiler/simplify.m:
	If a foreign_proc has the always_boxed annotation, attach this info
	to each of its args. We do this here because simplify is guaranteed
	to be executed before all the code that may inspect these arguments.
	Since nothing ever deletes an always_boxed annotation of a foreign_proc
	arg, the code that attaches the annotation is idempotent, so the fact
	that the compiler executes simplify twice is not a problem.

compiler/*.m:
	Minor changes to conform to the changes in data structures above.

compiler/prog_type.m:
	Move a function definition from prog_mutable to prog_type, and
	fix the lack of abstraction in its code.

compiler/prog_mutable.m:
	Delete the code moved to make_hlds_passes.m and prog_type.m.

compiler/notes/compiler_design.html:
	Make the documentation of prog_mutable.m easier to read in source.

tests/hard_coded/float_gv.{m,exp}:
	An extended version of Greg's code as a new test case.

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

tests/hard_coded/sub-modules/non_word_mutable.{m,exp}:
tests/hard_coded/sub-modules/non_word_mutable.child.m:
	A version of the float_gv test case in which the compiler-generated
	get and set foreign_procs should end up in .opt files.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/Mercury_options:
	Enable the new test case, and make it execute with intermodule
	optimization.

tests/invalid/bad_mutable.err_exp:
	Expect the new output (in which an error is reported just once,
	not twice).
2006-02-24 01:42:19 +00:00
Zoltan Somogyi
5af71b60ac Remove support for the Aditi backend. It is a pain to have to update it every
Estimated hours taken: 2
Branches: main

Remove support for the Aditi backend. It is a pain to have to update it every
time a data structure changes when we don't see any benefit from it, and its
presence makes compilation of the compiler directory take about 10% longer
(since the Aditi backend modules are roughly 10% of the code in the compiler
directory). Deleting the Aditi-specific data structures from the HLDS should
also speed up compilation a little bit.

I have spoken to Rao and he is fine with this step.

Aditi users, if there are any, can continue to use the Aditi support in
release 0.12.*. I also tagged the last version on the trunk to support aditi
with the name "last_aditi". The need for modifications in this Aditi support
is likely to be very rare to nonexistent, if the recent past is any guide:
the Aditi backend hasn't seen a nontrivial modification in a year or more.

This diff removes a net 31492 lines.

compiler/add_aditi.m:
compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/context.m:
compiler/dnf.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/rl.m:
compiler/rl_analyse.m:
compiler/rl_block.m:
compiler/rl_block_opt.m:
compiler/rl_code.m:
compiler/rl_dump.m:
compiler/rl_exprn.m:
compiler/rl_file.pp:
compiler/rl_gen.m:
compiler/rl_info.m:
compiler/rl_key.m:
compiler/rl_liveness.m:
compiler/rl_loop.m:
compiler/rl_opt.m:
compiler/rl_out.pp:
compiler/rl_relops.m:
compiler/rl_sort.m:
compiler/rl_stream.m:
	Remove these compiler modules, since they existed only to support the
	Aditi backend.

compiler/hlds_goal.m:
	Delete the Aditi-specific components of goals (e.g. the aditi-builtin
	kind of generic calls and Aditi-evaluated lambdas).

compiler/hlds_pred.m:
	Delete the Aditi-specific components of pred_infos.

compiler/prog_data.m:
	Delete the Aditi-specific items.

compiler/passes_aux.m:
	Don't worry about processing all procedures or just all non-Aditi
	procedures.

compiler/add_clause.m:
	Add a predicate from a deleted module that is now used only here.

compiler/*.m:
	Conform to the data structure changes above.

compiler/notes/*.html:
	Remove references to the Aditi backend.

tests/invalid/aditi.m:
tests/invalid/aditi_errors.err_exp:
tests/invalid/aditi_errors.m:
tests/invalid/aditi_private_builtin.m:
tests/invalid/aditi_state_errors.err_exp:
tests/invalid/aditi_state_errors.m:
tests/invalid/aditi_update_derived_relation.err_exp:
tests/invalid/aditi_update_derived_relation.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/valid/aditi.m:
tests/valid/aditi_calls_mercury.m:
tests/valid/aditi_error_bug.m:
tests/valid/aditi_error_bug2.m:
tests/valid/aditi_error_bug3.m:
tests/valid/aditi_private_builtin.m:
tests/valid/aditi_query.m:
tests/valid/aditi_update.m:
tests/valid/base_relation.m:
tests/valid/base_relation2.m:
tests/valid/ite_to_disj.m:
	Remove these Aditi-specific tests.

tests/*/Mmakefile:
	Remove the references to these Aditi-specific tests.
2006-02-23 09:37:30 +00:00
Richard James Fothergill
765109cde2 Extend constraints based mode analysis.
Estimated hours taken: 120.
Branches: main.

Extend constraints based mode analysis.
Constraints on the producing and consuming goals for program
variables are now solved, and the solutions used for
conjunction reordering. The resulting HLDS is then thrown away,
after maybe being dumped (stage 33).

Extend dumping of mode analysis constraints.
Constraints are no longer dumped to file - they are displayed as
error messages when the --debug-mode-constraints is set. After
conjunction ordering, the original goal paths are printed in the
order they now appear.

compiler/options.m:
	Added the option described above, and some comments describing
	various mode constraint options.

compiler/check_hlds.m:
	Grouped ":- include_module"s for propagation solver
	constraints based mode analysis, and included
	new modules in this area - mcsolver and
	ordering_mode_constraints.

compiler/mode_constraints.m:
	Changes to the nature of constraint dumping - introduction
	of the use of --debug-mode-constraints.
	Introduction of conjunction ordering (call to module
	ordering_mode_constraints).

compiler/prop_mode_constraints.m:
	Changes to way constraints are dumped as described above.
	Changes to the way constraint variables are created -
	constraint variables can now be constructed as needed
	when the constraints are built.
	Structural changes to make constraint generation more
	natural (eg introduction of state variables, instead
	of use of functions).

compiler/abstract_mode_constraints.m:
	Changes to the way constraints are stored - the old
	speculative code became redundant with the introduction
	of rafe's solver (see mcsolver.m).
	New, specialised constraint generation predicates.
	Constraints are now created with a context attached,
	and space was left for adding other information.

compiler/build_mode_constraints.m:
	Changes to the way constraint variables are created -
	constraint variables can now be constructed as needed
	when the constraints are built.
	Structural changes to make constraint generation more
	natural (eg introduction of state variables, instead
	of use of functions).
	Constraints are now created with a context attached.

compiler/ordering_mode_constraints.m:
	New file. Uses solutions to the producer/consumer
	constraints to order conjunctions for mode analysis.
	Does not yet do mode inference.

compiler/mcsolver.m:
	New file. Written by rafe, modified by myself to
	accomodate the rest of the mode constraints branch
	(and a new constraint type). Solves mode constraints
	to produce bindings for constraint variables from
	producer/consumer analysis.

compiler/notes/compiler_design.html:
	Updated notes about constraints based mode analysis.
2006-02-02 00:38:30 +00:00
Zoltan Somogyi
b819fbc0a6 Give the compiler the capability of detecting errors that manifest themselves
Estimated hours taken: 16
Branches: main

Give the compiler the capability of detecting errors that manifest themselves
as mismatches between the format string and the list of values to be printed
in calls to string.format and io.format.

This capability is controlled through two new options:

	--warn-known-bad-format-calls
	--warn-unknown-format-calls

The first (which will default to "on" once this change has bootstrapped)
controls whether the compiler emits warnings for statically known mismatches.
The second (which will default to "off") controls whether the compiler emits
warnings in cases where either the format string or the structure of the list
of values to be printed is not available statically to be checked.

NEWS:
	Mention the new capability.

compiler/options.m:
	Add the two new options.

doc/user_guide.texi:
	Document the new options.

compiler/format_call.m:
	New module to implement the new capability.

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

compiler/check_hlds.m:
	Include the new module.

compiler/simplify.m:
	Invoke the new module if the procedure being processed contains calls
	to string.format or io.format.

	Fix an old bug: we could generate warnings or even errors when
	simplifying predicate bodies imported from other modules via
	intermodule optimization.

	Don't export get/set predicates that do not need to be exported.

compiler/det_report.m:
	Add new kinds of error specifications for the errors detected by the
	new module.

	Separate out the context of each error specification, in order
	to allow the error messages to be sorted by context; this makes
	the output much easier to read.

compiler/common.m:
compiler/det_analysis.m:
compiler/simplify.m:
	Conform to the change to det_report.m.

mdbcomp/prim_data.m:
	Add a utility function for forming the possibly qualified names of
	library modules (such as "io" and "string").

library/Mercury.options:
compiler/Mercury.options:
	Add the lines that disable the new checks in the modules that need them
	disabled. The new lines are commented out until installed compilers all
	understand them, at which point in time we will add the requirement to
	understand the option to configure.in.

compiler/fact_table.m:
compiler/mlds_to_il.m:
	Fix three bugs reported by the new check that have apparently escaped
	detection all this time.

library/rtti_implementation.m:
	Change some code to avoid a spurious warning from the new checks.

library/string.m:
	Rename a predicate to avoid an unnecessary and confusing overloading of
	its name.

	Replace __ with . as module qualifier connective.

compiler/handle_options.m:
library/pprint.m:
	Misc cleanups.

tests/invalid/string_format_bad.{m,err_exp}:
tests/invalid/string_format_unknown.{m,err_exp}:
	New test cases to test the new warnings.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
	Enable the new test cases.

tests/general/string_format_test*.exp*:
	Update any expected abort messages to expect . instead of __ as module
	qualifier connective.

tests/invalid/det_errors_cc.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/warnings/simple_code.exp:
	Expect the same error messages in program context order.
2006-01-27 05:52:27 +00:00
Julien Fischer
2a477fb7e7 Split the parse tree (currently defined in prog_data.m) into two
Estimated hours taken: 3.5
Branches: main

Split the parse tree (currently defined in prog_data.m) into two
separate modules.  The reason for doing this is that while over 80%
of the modules in the compiler import prog_data, very few of them actually
require access to the types that define the parse tree (principally
the item type).  At the moment even small changes to these types can
result in recompiles that rebuild almost all of the compiler.  This change
shifts the item type (and related types) into a new module, prog_item,
that is only imported where these types are required (mostly at the
frontend of the compiler).  This should reduce the size of recompiles
required when the parse tree is modified.

This diff does not change any algorithms; it just shifts things around.

compiler/prog_data.m:
	Move the item type and any related types that are not needed
	after the HLDS has been built to the new prog_item module.

	Fix bitrot in comments.

	Fix formatting and layout of comments.

	Use unexpected/2 in place of error/1 in a spot.

compiler/prog_item.m:
	New file.  This module contains any parts of the parse tree
	that are not needed by the rest of the compiler after the
	HLDS has been built.

compiler/check_typeclass.m:
	s/list(instance_method)/instance_methods/

compiler/equiv_type.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/make_hlds.m:
compiler/mercury_compile.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/parse_tree.m:
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/trans_opt.m:
	Conform to the above changes.

compiler/notes/compiler_design.html:
	Mention the new module.
2005-11-23 04:44:10 +00:00
Julien Fischer
bd7e19b4ce Further work on trail usage analysis and optimization.
Estimated hours taken: 5
Branches: main

Further work on trail usage analysis and optimization.

compiler/mercury_compile.m:
	Move trail usage analysis from stage 123 to stage 167.
	The advantage of having it later is that compiler
	introduced predicates are also added to the trailing_info table.

compiler/trailing_analysis.m:
	Do not run this analysis unless we are compiling in a trailing grade.

	Add a table of (non-builtin) procedures from the standard library
	whose trailing status can be assumed to be known.  This works around
	some limitations in our current intermodule analysis framework and
	also improves trail usage optimization when we are compiling without
	any intermodule optimization.

	Fix some typos.

doc/user_guide.texi.m:
compiler/options.m:
	Document `--analyse-trail-usage' and `--optimize-trail-usage'.

doc/reference_manual.texi:
	Document the `will_not_modify_trail' and `may_modify_trail'
	foreign code attributes.

compiler/notes/compiler_design.html:
	Mention the trailing_analysis module.
2005-11-16 07:02:00 +00:00
Zoltan Somogyi
21685c9e22 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 6
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-11-04 03:41:09 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Julien Fischer
9ec3ae8d08 Fix the problems with mutable declarations and sub-modules by making
Estimated hours taken: 11
Branches: main

Fix the problems with mutable declarations and sub-modules by making
sure that the relevant information is written out in the private interface
files.

Fix a bug where mutable variables were not being initialised with their
declared intial value.  The problem was that the compiler was optimizing away
the body of the automatically generated predicate that was setting the initial
value.  We now make such predicates impure to prevent this.

In order to support the above, accept `:- intialise' declarations that specify
impure predicates, provided that the declaration in question was generated by the
compiler.  It is still an error for the user to specify such declarations.

Fix some other problems with mutable declarations.

compiler/modules.m:
	Do not write `:- mutable' declarations out to private interface
	files, instead write out the predicate and mode declarations for
	the access predicates.

	Remove some old XXX comments about mutables that are no longer
	relevant.

compiler/make_hlds_passes.m:
	Don't add the export pragmas for initialise declarations during pass
	2.  For some reason we were doing this during pass 2 and again during
	pass 3.

	Make the intialise predicates for mutable variables impure in order to
	prevent the compiler from optimizing them away

	Fix origin fields that were being set incorrectly during the mutable
	transformation.

compiler/prog_mutable.m:
	New module.  Shift some code from make_hlds_passes to here, since
	modules.m also needs access to it.

compiler/parse_tree.m:
	Include the new module.

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

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/mutable_parent.m:
tests/hard_coded/sub-modules/mutable_child.m:
tests/hard_coded/sub-modules/mutable_grandchild.m:
tests/hard_coded/sub-modules/mutable_parent.exp:
	Test case for mutables and sub-modules.

tests/hard_coded/not_in_interface.m:
tests/hard_coded/not_in_interface.err_exp:
	Test for ordering problems between mutable and initialise
	declarations when emitting errors about items that should
	not occur in module interfaces. This can happen if the
	item's origin field is incorrectly set.
2005-09-15 07:38:47 +00:00
Zoltan Somogyi
df0d9036cf Optimize calls that would be tail calls in Prolog but are followed by
Estimated hours taken: 40
Branches: main

Optimize calls that would be tail calls in Prolog but are followed by
construction unifications in Mercury: last call modulo construction.
For now, the optimization is available only for the LLDS backend.

compiler/lco.m:
	Turn this module from a placeholder to a real implementation
	of the optimization.

compiler/hlds_goal.m:
	Allow lco.m to attach to construction unifications a note that says
	that certain arguments, instead of being filled in by the unification,
	should have their addresses taken and stored in the corresponding
	variables.

	Group this note together with the note that asks for term size
	profiling to avoid an increase in the sizes of goals in the compiler
	in most cases.

compiler/hlds_pred.m:
	Provide a predicate for setting the name of a predicate after its
	creation. This functionality is used by lco.m.

	Extend the pred_transformation part of the pred_origin type to allow
	it to express that a procedure was created by lco.m.

	List the new primitive store_at_ref as a no-typeinfo builtin.

	Fix some problems with indentation.

compiler/layout_out.m:
	Handle the new pred_transformation.

compiler/unify_gen.m:
	When processing construction unifications that have the new feaure
	turned on, perform the requested action.

	Fix some departures from coding style. Shorten lines by deleting
	unnecessary module qualifications. Add some auxiliary predicates
	to make the code easier to read.

compiler/var_locn.m:
	Fix an earlier oversight: when materializing variables inside rvals
	and lvals, look inside memory references too. Previously, the omission
	didn't matter, since we didn't generate such references, but now we do.

	Fix some departures from coding style.

compiler/llds_out.m:
	Fix some old XXXs in code handling memory references. We didn't use to
	generate such references, but now we do.

	Move some functionality here from code_aux.m.

compiler/code_info.m:
	Provide some primitive operations needed by the new code in var_locn.m.

	Delete an unneeded predicate.

compiler/options.m:
	Rename the existing option optimize_constructor_last_call as
	optimize_constructor_last_call_accumulator, since that optimization
	is done by accumulator.m.

	Make optimize_constructor_last_call be the option that calls for the
	new optimization.

compiler/handle_options.m:
	Handle the implications of the new option.

compiler/mercury_compile.m:
	Invoke the lco module by its new interface.

librrary/private_builtin.m:
	Add a new primitive operation, store_at_ref, for use by the new
	optimization.

	Switch the module to four-space indentation.

compiler/add_clause.m:
	Comment out the warning for clauses for builtin, since this is needed
	to bootstrap the addition of the new builtin.

compiler/term_constr_initial.m:
	Handle the new builtin.

compiler/accumulator.m:
	Conform to the change in options.

compiler/builtin_ops.m:
	Provide a third template for builtins, for use by store_at_ref.

	Convert the file to four-space indentation.

compiler/call_gen.m:
	Generate code following the new builtin template.

compiler/rl_exprn.m:
	Minor changes to conform to the changes in builtin templates.

compiler/quantification.m:
	Minor changes to conform to the changes in construct unifications.

	Don't make the "get" predicates operating on quantification_infos
	to return the "new" quantification_info: it is always the same
	as the old one.

compiler/aditi_builtin_ops.m:
compiler/common.m:
compiler/deep_profiling.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/lambda.m:
compiler/magic_util.m:
compiler/ml_unify_gen.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/size_prof.m:
	Minor changes to conform to the changes in construct unifications.

compiler/dependency_graph.m:
	Add a new predicate to recompute the dependency information,
	even if a previous (and possibly now inaccurate) version is present.

	Change the interface to make it clearer, by changing bools into types
	specific to the situation.

	Convert the file to four-space indentation.

compiler/mode_constraints.m:
	Minor changes to conform to the changes in dependency_graph.m.

compiler/code_aux.m:
	Delete this module. Half its functionality has been moved into
	llds_out.m, half to middle_rec.m (its only user).

compiler/goal_form.m:
	Move the predicates in this module that are used only by middle_rec.m
	to middle_rec.m.

	Convert the file to four-space indentation.

compiler/goal_util.m:
compiler/det_util.m:
	Move update_instmap from det_util to goal_util, since it is usefulness
	extends beyond determinism analysis.

	Convert det_util.m to four-space indentation.

compiler/middle_rec.m:
	Move here the code required only here from code_aux and goal_form.
	Update the moved code for the changes in construct unifications.
	The updates are specific to middle_rec.m: they wouldn't be of use
	to other modules. They basically say that any code that takes the
	addresses of fields cannot be handled by middle_rec.m.

compiler/code_gen.m:
compiler/det_analysis.m:
compiler/live_vars.m:
compiler/ll_backend.m:
compiler/loop_inv.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/notes/compiler_design.html:
	Minor changes to conform to the deletion of code_aux.m and/or the
	movement of code from det_util to goal_util.m.

compiler/opt_debug.m:
	Print info for vars in rvals.

compiler/hlds_module.m:
	Convert a lambda to an explicit predicate to make some code easier to
	read.

	Switch the module to four-space indentation.
2005-09-13 04:56:20 +00:00
Zoltan Somogyi
10536c5ee0 Divide make_hlds.m into submodules of manageable size.
Estimated hours taken: 12
Branches: main

Divide make_hlds.m into submodules of manageable size.

compiler/make_hlds.m:
	Distribute all the code that was previously here to new submodules.
	Include those submodules. Keep the existing interface of this module
	by defining predicates that do nothing except call the actual
	implementation in one of those submodules. The only changes visible
	from outside are the renaming of a predicate and the creation of a
	second name, make_hlds_qual_info, for qual_info. Both changes are
	designed to avoid ambiguity in the presence of intermodule
	optimization.

compiler/add_aditi.m:
	Submodule for dealing with aditi-specific issues.

compiler/add_class.m:
	Submodule for handling typeclasses.

compiler/add_clause.m:
	Submodule for handling the general processing of clauses.

compiler/add_pred.m:
	Submodule for handling new predicates.

compiler/add_special_pred.m:
	Submodule for handling special (unify/compare/index/init) predicates.

compiler/add_type.m:
	Submodule for handling new types.

compiler/add_mode.m:
	Submodule for handling new insts and modes.

compiler/add_solver.m:
	Submodule for handling new solver types.

compiler/add_pragma.m:
	Submodule for handling new pragmas.

compiler/state_var.m:
	Submodule for handling the state variable transformation.

compiler/superhomogeneous.m:
	Submodule for converting clauses to superhomogeneous form.

compiler/field_access.m:
	Submodule for field access syntax.

compiler/make_hlds_passes.m:
	Submodule containing the code that performs passes on the item list,
	adding things to the HLDS, calling the other submodules as necessary.

compiler/make_hlds_warn.m:
	Submodule that looks for constructs that merit warnings.

compiler/make_hlds_error.m:
	Submodule containing error messages used by more than one submodule.

compiler/hlds_pred.m:
	Since this module defines the clauses_info and proc_id types, move
	the predicates that initialize values of that type here as well from
	make_hlds.m (deleting an unnecessary parameter from one).

compiler/hlds_pred.m:
compiler/prog_data.m:
	Move the type tvar_name_map from from hlds_pred.m to prog_data.m,
	since that is where similar maps are.

compiler/check_typeclass.m:
compiler/mercury_compile.m:
	Conform to the change to make_hlds_qual_info.

compiler/hlds_out.m:
compiler/prog_out.m:
	Replace two identical predicates for printing out lists of strings
	in hlds_out.m and make_hlds.m with just one in prog_out.m, since that
	is where it belongs in the compiler.

compiler/prog_util.m:
	Move some utility predicates for substitutions and term recognition
	here from make_hlds.m, since they are needed by more than one
	submodule.

	Make this module conform to our coding guidelines, and convert it to
	four-space indentation to eliminate bad line breaks.

compiler/clause_to_proc.m:
compiler/hlds_code_util.m:
compiler/make_tags.m:
compiler/prog_mode.m:
compiler/quantification.m:
compiler/type_util.m:
	Trivial formatting changes.

compiler/notes/compiler_design.html:
	Describe the new modules.
2005-07-26 01:56:30 +00:00
Zoltan Somogyi
68b1a6c0ea Add a new LLDS optimization we discussed on thursday: elimination of procedures
Estimated hours taken: 4
Branches: main

Add a new LLDS optimization we discussed on thursday: elimination of procedures
whose code is an exact copy of the code of another mode of the same predicate.
This happens with in,out vs di,uo and also possibly with in,out vs any,any.
The new optimization reduces the compiler's code size by 0.6%.

compiler/dupproc.m:
	A new module implementing the new optimization.

compiler/ll_backend.m:
	Add dupproc.m as a new submodule.

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

compiler/options.m:
	Add an option, --optimize-proc-dups, enabling the new optimization.
	Make --opt-space imply the new option.

doc/user_guide.texi:
	Document the new option.

compiler/mercury_compile.m:
	Invoke the new optimization when compiling by predicates.

	Move the imports of library modules to their own section.

compiler/handle_options.m:
	Make --optimize-proc-dups imply compiling by predicates.

The rest of these changes are cosmetic only.

compiler/llds.m:
	Delete an obsolete form of constant we haven't used in a long time.

compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/llds_out.m:
compiler/opt_debug.m:
compiler/opt_util.m:
	Conform to the change in llds.m.

compiler/dependency_graph.m:
	Clean up some comments.

compiler/dupelim.m:
	Fix some variable names.

compiler/hlds_module.m:
compiler/hlds_pred.m:
	Minor cleanups.
2005-07-08 04:22:13 +00:00
Mark Brown
a5eb58d00b Update the design document after the recent changes to add functional
Estimated hours taken: 0.2
Branches: main

compiler/notes/compiler_design.html:
	Update the design document after the recent changes to add functional
	dependencies and split up typecheck.m.

compiler/check_typeclass.m:
	Fix a typo.
2005-04-24 01:47:58 +00:00
Julien Fischer
4c39d891fc Clean up lp.m and bring it more into sync with the corresponding
Estimated hours taken: 1.5
Branches: main

Clean up lp.m and bring it more into sync with the corresponding
parts of lp_rational.m.  The one algorithmic change is to replace
two closures that where called by an all solutions predicate with a
single iterative predicate that does the same thing.

Shift lp.m from the transform_hlds package into the libs package.

compiler/lp.m:
	Shift to 4-space indentation throughout.

	Use state variables throughout and rearrange argument
	orders where necessary.

	Use predmode syntax throughout.

	Add field names to several of the major data structures
	in this module.

	Standardize variable names.

	s/__/./ throughout.

	Other minor formatting changes.

compiler/transform_hlds.m:
compiler/libs.m:
	Move the lp module from the transform_hlds package to the
	libs package.  It doesn't really have anything to do with
	the HLDS.

compiler/term_pass1.m:
compiler/notes/compiler_design.html:
	Minor changes to conform to the above.
2005-04-19 02:47:16 +00:00
Zoltan Somogyi
309910d736 Change the mechanism we use to transmit a representation of procedure bodies
Estimated hours taken: 16
Branches: main

Change the mechanism we use to transmit a representation of procedure bodies
from the compiler to the declarative debugger from Mercury terms to a bytecode.
This achieves two objectives.

First, the code for Mercury terms worked only as long as the compiler used
the same data representation as the program being compiled; it generated
incorrect term representations when e.g. the compiler generating code in
reserve tag grades.

Second, the new representation is significantly smaller. The total size of the
.c files in the compiler directory in grade asm_fast.gc.decldebug.tr is now
only 213 Mb compared with 313 Mb previously (a reduction of almost one third).
The executable file size of a compiler compiled in asm_fast.gc.decldebug.tr is
now only 59 Mb, compare with 64 Mb previously (a reduction of almost 8%, and
there is room for further reductions). The overhead of the decldebug grade
when compared with a plain debug grade now only about 25%, compared to
about 36% before.

The downside is that the procedure body representation must now be constructed
by the declarative debugger from the bytecode instead of being available
directly. We minimize this effect by using a cache to ensure that each
procedure's body representation is constructed at most once.

browser/declarative_execution.m:
	Do not include the procedure representation in call nodes. This should
	make the annotated trace somewhat smaller and quicker to construct.
	Since this code will be executed many more times than the number of
	procedures whose bodies are needed by subterm dependency tracking,
	the overall effect of this change on speed should be positive.

	Instead, add code to construct procedure body representations on demand
	from bytecode, which is reachable indirectly through the call's node
	label label structure.

browser/declarative_tree.m:
	Conform to the new structure of call nodes.

compiler/prog_rep.m:
	Replace the code that generated the term representation of procedure
	bodies with code that generates a bytecode representation of procedure
	bodies.

compiler/static_term.m:
	Delete this file, since it is no longer needed.

compiler/notes/compiler_design.html:
	Document the deletion of static_term.m.

mdbcomp/program_representation.m:
	Add the definitions related to the structure of the bytecode that are
	shared by the compiler and the declarative debugger. This includes
	the representations of determinisms.

compiler/code_model.m:
	To prevent requiring double maintenance, use the facilities now in
	mdbcomp/program_representation.m to encode determinisms.

runtime/mercury_stack_layout.h:
compiler/layout.m:
compiler/layout_out.m:
compiler/opt_debug.m:
compiler/stack_layout.m:
	Replace the proc layout field holding the procedure representation term
	with the field holding the procedure representation bytecode.

runtime/mercury_grade.h:
	Record the breaking of backward compatibility in debug grades.

compiler/options.m:
	Add an option for use by compiler implementors while implementing
	changes like this.

runtime/mercury_trace_base.[ch]:
	Add the hash table that caches the results of bytecode translations.

trace/mercury_trace_declarative.c:
	Do not include procedure representations when constructing call nodes,
	since it is no longer necessary.

trace/mercury_trace_internal.c:
	Update the code that deals with procedure bodies to use the bytecode
	representation.
2005-03-31 04:44:33 +00:00
Julien Fischer
601fe20aba Simplify the structure of the compiler by removing the cycle
Estimated hours taken: 3.5
Branches: main

Simplify the structure of the compiler by removing the cycle
parse_tree -> backend_libs -> check_hlds -> parse_tree
from the package dependency graph.

I've done this by factoring out the code in backend_libs.foreign
and backend_libs.name_mangle that is needed by the frontend of
the compiler and putting it in a new module, parse_tree.prog_foreign.
This removes the dependency between the parse_tree and backend_libs
packages.

The obvious downside to this is that the name mangler is now
split in two, although such a division was always in implicit
in the predicates of the name_mangle module anyway, ie. between
those bits that operate on the HLDS/MLDS/LLDS level data structures
and those that don't.

compiler/name_mangle.m:
compiler/foreign.m:
compiler/prog_foreign.m:
	Move code for dealing with foreign language procedures that
	is required by the parse_tree package into a new module,
	prog_foreign.

	Update the formatting in some of these modules so that
	they match our current coding standard.

compiler/*.m:
	Update to reflect the above change.

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

	Fix some spelling errors.
2005-03-21 04:45:51 +00:00
Richard James Fothergill
388bd7025a These changes provide the framework for a new approach to constraints
Estimated hours taken: 100
Branches: main



These changes provide the framework for a new approach to constraints
based mode analysis. They build constraints for simple mercury programs
(sorry, no higher order unifications), and can later be extended to
handle all applicable hlds goals. They have been designed with the
intention that they would be solved, for example, by a propagation based
constraint solver, and the information used for producing a partial
order on conjuncts and for mode analysis of a mercury program.


compiler/notes/compiler_design.html
	Added a description of various parts of the new constraints
	based mode analysis work.
2005-02-22 12:33:50 +00:00
Zoltan Somogyi
86ac840326 Implement a mechanism to generate the information required to determine the
Estimated hours taken: weeks
Branches: main

Implement a mechanism to generate the information required to determine the
algorithmic complexity of selected procedures.

The basis of the mechanism is a program transformation that wraps up the body
of each selected procedure in code that detects top-level (non-recursive)
calls, and for each top-level call, records the sizes of the input arguments
and information about the cost of the call. For now, the cost information
consists only of the number of cells and words allocated during the call,
but there is provision for later adding information from a real-time clock.

compiler/complexity.m:
	A new module containing the new transformation.

compiler/transform_hlds.m:
	Add complexity.m to the list of submodules.

compiler/mercury_compile.m:
	Invoke the new module.

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

compiler/options.m:
	Add an option, --experimental-complexity. Its argument is a filename
	that specifies the list of procedures to transform.

	Add an option, --no-allow-inlining, to disallow all inlining.
	This is simpler to use than specifying several options to turn off
	each potential reason to inline procedures.

doc/user_guide.texi:
	Document the new options. The documentation present now is only a
	shell; it will be expanded later.

compiler/table_gen.m:
compiler/goal_util.m:
	Move the predicate for creating renamings from table_gen.m to
	goal_util.m, since complexity.m also needs it now. In the process,
	make it more general by allowing outputs to have more complex modes
	than simply `out'.

compiler/goal_util.m:
	Fix a bug exposed by the new transformation: when renaming goals
	(e.g. for quantification), rename the variables holding information
	about term sizes.

compiler/handle_options.m:
	Disable inlining if experimental complexity analysis is enabled.

compiler/compile_target_code.m:
	Pass the --experimental-complexity option on to the linker.

library/term_size_prof_builtin.m:
	Add the Mercury predicates that serve as interfaces to the primitives
	needed by the experimental complexity transformation.

runtime/mercury_term_size.[ch]:
	Add the implementations of the primitives needed by the experimental
	complexity transformation.

runtime/mercury_wrapper.[ch]:
	Add global variables holding counters of the numbers of words and cells
	allocated so far.

runtime/mercury_heap.h:
	Update these global variables when allocating memory.

runtime/mercury_complexity.h:
	New file that contains the definition of the data structures holding
	the data collected by the experimental complexity transformation.
	This is separate from mercury_term_size.h, because it needs to be
	#included in mercury_init.h, the header file of the mkinit-generated
	<program>_init.c files.

runtime/mercury_init.h:
runtime/mercury_imp.h:
	#include mercury_complexity.h.

util/mkinit.c:
	Define and initialize the data structures holding complexity
	information when given the -X option (mkinit doesn't have long
	options).

	Fix some deviations from our coding style.

scripts/parse_ml_options.sh-subr.in:
	Accept the --experiment-complexity option.

scripts/c2init.in:
	Pass the --experiment-complexity option on to mkinit.c.

tools/bootcheck:
	Preserve the files containing the results of complexity analysis,
	if they exist.

tools/makebatch:
	Allow the specification of EXTRA_MLFLAGS in the generated
	Mmake.stage.params files.
2005-02-15 05:22:40 +00:00
Julien Fischer
3e19c2fad6 Improve the termination analyser's handling of user-defined
Estimated hours taken: 20
Branches: main

Improve the termination analyser's handling of user-defined
special predicates.

Currently termination analysis assumes that all calls
to special predicates terminate.  For those that are
user-defined this is not necessarily true.

This diff adds a new pass to the compiler that is run after
the main termination analysis pass. It checks any user-defined
special predicates and emits a warning if their termination
can not be proved.

Add a new option, `--no-warn-non-term-special-preds' that
disables this warning.  The warning is only emitted when
termination analysis is enabled.  The new option has
no effect if termination analysis is not enabled.

compiler/post_term_analysis.m:
	New file.  Add an additional pass that runs after the main
	termination analysis and makes use of the information obtained
	then to perform further semantic checks and optimizations.

compiler/termination.m:
	Run the new pass after the main analysis.

	Update the comment about the termination analyser doing the
	wrong thing for user-defined special predicates.

compiler/options.m:
	Parse the new option.

	Update the special handler for the inhibit_warning
	option so that it handles `--warn-table-with-inline'
	and the new option correctly.

	Fix some typos.

compiler/transform_hlds.m:
	Include the new module.

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

doc/user_guide.texi:
	Document the new option.

	Fix some typos: s/occured/occurred/,
	s/interative/interactive/, s/exlained/explained/
	and /currect/current/

library/array.m:
library/version_array.m:
	Add pragma terminates declarations to the user-defined
	equality and comparison predicates for the array/1
	and version_array/1 types.  The termination analyser
	cannot (yet) prove termination in these cases because
	it cannot reason about iteration over arrays.

tests/warnings/Mercury.options:
tests/warnings/Mmakefile:
tests/warnings/warn_non_term_user_special.m:
tests/warnings/warn_non_term_user_special.exp:
	Test the new option.
2005-01-22 06:10:55 +00:00
Julien Fischer
a3352a6e5d Do not include :- import_module' and :- use_module' declarations
Estimated hours taken: 22
Branches: main

Do not include `:- import_module' and `:- use_module' declarations
in the implementation section of .int and .int2 files unless
the types that they export are required by the definition of
an equivalence type.  This should help prevent unnecessary
recompilations when new imports are made in the implementation
of modules.

Break up check_hlds.type_util so that predicates that do
not require access to the HLDS are placed in a new module,
parse_tree.prog_type.  The above change requires some of
these predicates.  This also removes one of the dependencies
between the parse_tree package on modules of the check_hlds
package.

Remove the remaining such dependency by moving
inst_constrains_unconstrained_var/1 from check_hlds.inst_util
to parse_tree.prog_mode.  None of the modules in parse_tree
now depend upon modules in check_hlds.

Modify the parser so that import_module declarations
that specify more than one module are replaced by multiple
import_module declarations, with one module per declaration.
This makes the above change easier to implement and is in
any case required by the upcoming diff for canonicalizing
module interfaces.  We also do the same for use_module and
include_module declarations.

compiler/modules.m:
	Don't import modules in the implementation section
	of interface files unless they are required by the
	definition of equivalence types.

compiler/prog_type.m:
	New module.  Move procedures from type_util that do
	not depend on the HLDS to here so that we can use them
	when generating interface files.

	XXX There are probably others that could be moved as
	well - I only moved those that were immediately useful.

compiler/type_util.m:
	Delete the procedures that have been moved to the
	new prog_type module.

compiler/prog_io.m:
	Remove the dependency on check_hlds.inst_util.

compiler/prog_io_typeclass.m:
compiler/equiv_type.m:
	Remove dependencies on check_hlds.type_util.

compiler/prog_util.m:
	Add a predicate sym_name_get_module_name/2 that is
	similar to sym_name_get_module_name/3 except that it
	fails if the input is an unqualified sym_name.

compiler/inst_util.m:
	Delete inst_contains_unconstrained_var/1 from this
	module and copy it to prog_mode.m.

compiler/parse_tree.m:
	Include the new module.

	Do not import the check_hlds package as all dependencies
	on this package have been removed.

compiler/*.m:
	Minor changes to conform to the above.

compiler/notes/compiler_design.html:
	Mention the new module.
2005-01-21 03:27:58 +00:00
Zoltan Somogyi
02b9dceb8f Move changes in the compiler on the mode-constraints branch onto the trunk.
Estimated hours taken: unknown, but months (almost all by dmo)
Branches: main

Move changes in the compiler on the mode-constraints branch onto the trunk.

compiler/top_level.m:
	Add the new package mode_robdd.

compiler/check_hlds.m:
	Add the new modules within the check_hlds.m package:
	mode_constraints, mode_constraint_robdd and mode_ordering.

compiler/hlds.m:
	Add the new modules within the hlds.m package, hhf and inst_graph.

compiler/hhf.m:
	This new module implements the transformation from our usual
	superhomogeneous form to the hyperhomogeneous form required by
	constraint based mode analysis.

compiler/inst_graph.m:
	This new module computes the instantiation graphs required by
	constraint based mode analysis.

compiler/hlds_goal.m:
	Add an extra slot into goal_infos for use by constraint based mode
	analysis, and the predicates required to manipulate it.

compiler/hlds_pred.m:
	Add two extra slots into pred_infos and one extra slot into proc_infos
	for use by constraint based mode analysis, and the predicates
	required to manipulate them.

compiler/mercury_compile.m:
	Invoke the constraint based mode analysis pass if the options call for
	it.

compiler/mode_constraints.m:
	This new module implements the top level of the constraint based
	mode analysis algorithm: it finds the constraints and adds them
	to the constraint store, and invokes other modules to find solutions
	and process them.

compiler/mode_ordering.m:
	This new module processes solutions of constraint systems by
	trying to find execution orders for conjunctions that are consistent
	with the assignment of producers represented by a such a solution.

compiler/mode_constraint_robdd.m:
	This new module provides a useful interface to operations on robdds
	used for constraint based mode analysis. The actual implementation
	uses one or two of the mode_robdd.X.m modules.

compiler/mode_robdd.m:
	New top-level package to hold the modules listed below, which deal
	with robdd based solvers for the constraint systems generated by mode
	analysis.

compiler/mode_robdd.check.m:
	This new module invokes two of the modules below and compares their
	results. If one of the modules is known to be good, this is useful
	for debugging the other.

compiler/mode_robdd.r.m:
compiler/mode_robdd.tfeir.m:
compiler/mode_robdd.tfeirn.m:
compiler/mode_robdd.tfer.m:
compiler/mode_robdd.tfern.m:
compiler/mode_robdd.tfr.m:
	These new modules each implement robdd based constraint solvers.
	They differ in the amount of information they keep in the robdd
	versus how much information they keep in Mercury data structures.
	The naming scheme assigns a letter to each kind of information
	we are concerned about, and includes that letter in the name the
	Mercury data structure has a separate field for that kind of
	information. The mapping is:

		r:	robdd (present in all variants)
		tf:	variables known to be true or false
		e:	variable equivalences
		i:	variable implications.
		n:	normalization

	Normally only one of these would be linked in, or two if
	mode_robdd.check.m is being used to compare two of these modules.

compiler/mode_robdd.equiv_vars.m:
	This module implements utility operations involving sets of equivalent
	variables.

compiler/mode_robdd.implications.m:
	This module implements utility operations involving implications
	among variables.

compiler/mode_robdd.prop.m:
	Experimental module; currently unused. Committed only to preserve
	its history.

compiler/goal_path.m:
	Add a variant of an existing predicate needed by constraint based mode
	analysis.

compiler/hlds_out.m:
	Print out the components added to the HLDS by this change if the
	appropriate signal character is present in the revelant option.

compiler/handle_options.m:
	Add the signal for printing mode constraints to the names of the usual
	dumping aliases. They have no effect unless constraint based mode
	analysis is enabled.

compiler/options.m:
	Add the options controlling the experimental mode constraints pass.

doc/user_guide.texi:
	Document the options controlling the experimental mode constraints
	pass for implementors.

compiler/notes/compiler_design.html:
	Document the new modules, and fix some old errors.
2004-12-20 01:15:48 +00:00
Julien Fischer
980afa90c5 Add an analysis that tries to identify those procedures
Estimated hours taken: 70
Branches: main

Add an analysis that tries to identify those procedures
in a module that will not throw an exception.
(I guess it may be more accurate to call it a non-exception analysis).

For those procedures that might throw exceptions the
analysis further tries to distinguish between those
that throw an exception as a result of a call to throw
and those that throw an exception as a result of a
call to a unification/comparison predicate that may involve
calls to user-defined equality/comparison predicates that throw
exceptions.

This sort of thing used to be done by the termination analysis,
where being able to prove termination was equated with not
throwing an exception.  This no longer works now that
the termination analyser considers exception.throw/1 to
be terminating - and in fact it never quite worked anyway
because the termination analyser was not handling things
like foreign code and user-defined equality and comparison
predicates correctly.

There are currently a few limitations, the main ones being:

* we currently use transitive-intermodule optimization rather
  than the intermodule-analysis framework.  This may causes
  problems when their are cycles in the module dependency graph.

* we currently assume that all calls to higher-order predicates
  may result in an exception being thrown.

* we currently assume that all foreign procs that make calls
  back to Mercury may throw exceptions.

* we currently assume that all solver types and existentially
  quantified types might result in an exception being thrown.

It should be possible to remove these limitations in later
versions.

This diff also modifies the cannot_loop_or_throw family of
predicates in goal_form.m.  There are now two versions of each
predicate; one that can make use of information from the
termination and exception analyses and one that cannot.

compiler/exception_analysis.m:
	The new analysis.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
	Handle `:- pragma exceptions(...' in .opt and .trans_opt files.

compiler/hlds_module.m:
	Attach information to each module about whether each procedure
	in the module may throw an exception.

compiler/goal_form.m:
	Rewrite the predicates in this module so that they can
	optionally use information from the exception analysis.

compiler/constraint.m:
compiler/goal_util.m:
compiler/rl.m:
compiler/simplify.m:
	Use information from exception and termination analyses
	when performing various optimizations.

compiler/type_util.m:
	Add a new predicate type_util.type_is_existq/2 that tests
	whether a type is existentially quantified or not.

compiler/mercury_compile.m:
compiler/mercury_to_mercury.m:
compiler/modules.m:
compiler/options.m:
compiler/module_qual.m:
compiler/make_hlds.m:
compiler/recompilation.version.m:
compiler/trans_opt.m:
compiler/transform_hlds.m:
	Minor changes needed by the above.

NEWS:
compiler/notes/compiler_design.html:
doc/user_guide.texi:
	Mention the new analysis.

tests/README:
	Include a description of the term directory.

tests/term/Mercury.options:
tests/term/Mmakefile:
tests/term/exception_analysis_test.m:
tests/term/exception_analysis_test.trans_opt_exp:
	Add a test for the new analysis.
2004-10-16 15:08:55 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
5f32f6a836 Update the documentation of the module structure after the movement
Estimated hours taken: 0.2
Branches: main

compiler/notes/compiler_design.html:
	Update the documentation of the module structure after the movement
	of two submodule between toplevel modules.
2004-03-23 11:02:45 +00:00
Zoltan Somogyi
c91313b32f Bring these modules up to date with our current coding style.
Estimated hours taken: 8
Branches: main

compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
	Bring these modules up to date with our current coding style. Use
	predmode declarations and state variable syntax where appropriate.
	Fix inconsistent indentation. Print more error messages using
	error_util.m for printing error messages.

compiler/trace_param.m:
	Add a new predicate for use by the updated code in handle_options.m.

compiler/error_util.m:
compiler/hlds_error_util.m:
	Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
	Most of its predicates are not dependent on HLDS data structures.
	Move the ones that are into a new module, hlds_error_util, that
	is a submodule of hlds.m. Overall, this reduces the dependence
	of submodules of parse_tree.m, including modules.m, on submodules
	of hlds.m.

compiler/notes/compiler_design.html:
	Update the documentation of compiler modes to account for
	hlds_error_util.m.

compiler/hlds.m:
compiler/parse_tree.m:
	Update the list of included submodules.

compiler/*.m:
	Update module imports and module qualifications as needed for the
	change above.

tests/invalid/*.{exp,exp2}:
	Update the expected outputs of a bunch of test cases to reflect the new
	format of some warning messages due to the user error_util; they now
	observe line length limits, and print contexts in some cases where they
	were previously missing.
2004-03-19 10:19:53 +00:00
Simon Taylor
82c6cdb55e Make definitions of abstract types available when generating
Estimated hours taken: 100
Branches: main

Make definitions of abstract types available when generating
code for importing modules.  This is necessary for the .NET
back-end, and for `:- pragma export' on the C back-end.

compiler/prog_data.m:
compiler/modules.m:
compiler/make.dependencies.m:
compiler/recompilation.version.m:
	Handle implementation sections in interface files.

	There is a new pseudo-declaration `abstract_imported'
	which is applied to items from the implementation
	section of an interface file.  `abstract_imported'
	items may not be used in the error checking passes
	for the curent module.

compiler/equiv_type_hlds.m:
compiler/notes/compiler_design.html:
	New file.

	Go over the HLDS expanding all types fully after
	semantic checking has been run.

compiler/mercury_compile.m:
	Add the new pass.

	Don't write the `.opt' file if there are any errors.

compiler/instmap.m:
	Add a predicate instmap_delta_map_foldl to apply
	a procedure to all insts in an instmap.

compiler/equiv_type.m:
	Export predicates for use by equiv_type_hlds.m

	Reorder arguments so state variables and higher-order
	programming can be used.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Handle `:- pragma foreign_type' as a form of type
	declaration rather than a pragma.

compiler/hlds_data.m:
compiler/*.m:
	Add a field to the type_info_cell_constructor cons_id
	to identify the type_ctor, which is needed by
	equiv_type_hlds.m.

compiler/module_qual.m:
	Donn't allow items from the implementation section of
	interface files to match items in the current module.

compiler/*.m:
tests/*/*.m:
	Add missing imports which only became apparent with
	the bug fixes above.

	Remove unnecessary imports which only became apparent with
	the bug fixes above.

tests/hard_coded/Mmakefile:
tests/hard_coded/export_test2.{m,exp}:
	Test case.

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
	Test case.
2003-12-01 15:56:15 +00:00
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
32c03c9b41 Fix repeated words.
Estimated hours taken: 0.1
Branches: main

compiler/notes/compiler_design.html:
	Fix repeated words.
2003-09-23 04:28:21 +00:00
Fergus Henderson
cf55e41289 Update to reflect the fact that we are now using sub-modules.
Estimated hours taken: 3.5
Branches: main

compiler/notes/compiler_design.html:
	Update to reflect the fact that we are now using sub-modules.
	this required a bit of reorganization in some places.
	Also, document some modules that were previously not mentioned.
2003-06-04 10:58:02 +00:00
Zoltan Somogyi
20d0a371e4 Document a module.
Estimated hours taken: 0.2
Branches: main

compiler/notes/compiler_design.html:
	Document a module.
2003-05-07 06:32:34 +00:00
Zoltan Somogyi
cbd6a7c56a Delete the old, lazy LLDS code generator, since we won't be maintaining it
Estimated hours taken: 3
Branches: main

Delete the old, lazy LLDS code generator, since we won't be maintaining it
anymore. Its deletion speeds up the compiler by 0.2% when using the LLDS
back end.

compiler/code_exprn.m:
	Delete the module.

compiler/ll_backend.m:
	Delete code_exprn from the list of submodules of this module.

compiler/notes/compiler_design.html:
	Delete the documentation of code_exprn.m, and update the documentation
	of var_locn.m.

compiler/options.m:
	Delete the --lazy-code option that used to select code_exprn over
	var_locn.

	Delete the follow_vars option, since the LLDS backend now always
	executes the follow_vars pass.

compiler/handle_options.m:
	Delete the code setting the follow_vars option.

	Make the setting of static_ground_terms conditional on the use of the
	LLDS backend (which now implies the eager code generator).

compiler/code_info.m:
	Delete lots of code that switches between code_exprn.m and var_locn.m.

	Simplify the data structures accordingly.

compiler/store_alloc.m:
	Delete the code and data structures required to cater for the case
	where the follow_vars pass isn't run.

compiler/pragma_c_gen.m:
compiler/var_locn.m:
compiler/hlds_goal.m:
compiler/lookup_switch.m:
	Update a comment.

doc/user_guide.texi:
	Delete the documentation of --follow-vars. --lazy-code was already
	undocumented.

tests/valid/Mercury.options:
	Delete a setting of --no-follow-vars.
2003-05-07 00:50:34 +00:00
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

Make Aditi work with `--highlevel-code'.

(Note that this doesn't work with the current CVS version
of Aditi. The Aditi developers have rewritten the Aditi client
API, and haven't maintained the old version of the API, so Mercury
queries don't work at the moment. extras/aditi will be updated to
use the new interface as a separate change.)

extras/aditi/aditi_private_builtin.m:
extras/aditi/aditi.m:
	Move code to implement Aditi calls and updates into
	a aditi_private_builtin.m. These operations are now
	implemented using ordinary Mercury foreign procedures,
	rather than hand-coded C modules.

compiler/magic.m:
	Use calls to ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m to implement the
	procedures which interface between top-down Mercury
	code and Aditi procedures.

compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Add a pass to convert Aditi builtins (calls and updates)
	into ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add a new generic_call type -- `unsafe_cast'.
	aditi_builtin_ops.m needs to be able to cast
	closures from one type and inst to another.

	Delete the `aditi_call' alternative for `aditi_builtin',
	which is not needed after the change to magic.m described
	above.

	Add predicates `construct_tuple' and `deconstruct_tuple'.

compiler/*hlds.*.m:
compiler/call_gen.m:
compiler/ml_call_gen.m:
	Handle unsafe cast goals.

compiler/common.m:
compiler/higher_order.m:
compiler/unify_proc.m:
	Generate unsafe_cast goals instead of calls to
	private_builtin.unsafe_type_cast.

compiler/purity.m:
compiler/notes/compiler_design.html:
	Convert calls to private_builtin.unsafe_type_cast into
	unsafe_cast goals.

compiler/ml_code_gen.m:
	Don't attempt to generate code for Aditi procedures.

	Remove special case handling of calls to
	private_builtin.unsafe_type_cast -- such
	calls are now transformed away.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/maybe_mlds_to_gcc.m:
	Add the RL code to the generated C file.

compiler/llds_out.m:
compiler/c_util.m:
compiler/compile_target_code.m:
	Move code to generate a `.rlo' file and work out the
	name of the RL constant embeeded in the C file for
	a module into c_util.m, for use by the MLDS backend.

compiler/modules.m:
	Automatically import aditi_private_builtin when compiling
	with `--aditi'.

	We generate a C constant for the RL code for each module,
	so modules compiled with `--aditi' need to be treated
	by the build system as if they contain foreign code.

compiler/polymorphism.m:
	Tuple insertion and deletion no longer need special treatment.

compiler/llds.m:
compiler/ll_backend.*.m:
	Delete the Aditi alternatives of the `code_addr' type.

compiler/mode_util.m:
	Add function versions of in_mode, out_mode, etc.

compiler/prog_util.m:
	Add aditi_public_builtin_module (returns `aditi') and
	aditi_private_builtin_module (returns `aditi_private_builtin').

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Fergus Henderson
5823c8a2e3 Perform loop invariant hoisting after inlining, since inlining
Estimated hours taken: 2
Branches: main

compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Perform loop invariant hoisting after inlining, since inlining
	can create opportunities for loop invariant hoisting.

library/string.m:
	Implement string__index in Mercury, in terms of string__length,
	string__unsafe_index, and a new procedure string__index_check,
	rather than implementing in C.  string__index_check contains
	just the index checking code from the old string__index implementation.
	Implementing string__index in Mercury like this should allow the
	Mercury compiler to do loop invariant hoisting on the calls to
	string__length.

	Declare the output argument for string__unsafe_index
	and string__index_det with mode `uo', to match string__index.
	For unsafe__index, this change was needed now that string__index is
	implemented in terms of string__unsafe_index.
2003-02-22 13:54:45 +00:00
Fergus Henderson
b39fcee35d Trivial comment changes.
Estimated hours taken: 0.25
Branches: main

Trivial comment changes.

compiler/inst_match.m:
	Update some obsolete comments to match the current interface.
	Add a comment about contravariance/covariance in
	pred_inst_argmodes_matches.

compiler/java_util.m:
compiler/notes/compiler_design.html:
	Fix typos.
2003-01-10 10:45:02 +00:00