Commit Graph

230 Commits

Author SHA1 Message Date
Fergus Henderson
ef7ed9c2f5 Support impurity declarations for higher-order code.
Estimated hours taken: 24
Branches: main

Support impurity declarations for higher-order code.

In particular, allow `impure' and `semipure' annotations on
higher-order types, higher-order calls, and lambda expresions.

NEWS:
doc/reference_manual.texi:
	Document the new language feature.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add `purity' field to
	- the `higher_order' alternative of the hlds_goal.generic_call type
	- the `higher_order' alternative of the hlds_pred.generic_call_id type
	- the `lambda_goal' alternative of the hlds_goal.unify_rhs type

compiler/type_util.m:
	Add a new `purity' argument to the procedures dealing with
	higher-order types.  Add code for parsing impure/semipure
	higher-order types.

compiler/lambda.m:
compiler/make_hlds.m:
compiler/typecheck.m:
compiler/post_typecheck.m:
compiler/purity.m:
compiler/polymorphism.m:
	Various minor changes to support impure/semipure higher-order lambda
	expressions.

compiler/polymorphism.m:
compiler/pseudo_type_info.m:
	XXX ought to change these to include purity in the RTTI for
	higher-order function types.

compiler/simplify.m:
	Don't try to optimize semipure/impure higher-order calls.

compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/equiv_type.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/pd_util.m:
compiler/prog_rep.m:
compiler/pseudo_type_info.m:
compiler/quantification.m:
compiler/recompilation.usage.m:
compiler/rl_gen.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/unify_gen.m:
compiler/unique_modes.m:
	Trivial changes to handle the new purity fields and/or arguments.

tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/impure_func_t5_fixed2.m:
tests/hard_coded/purity/impure_func_t5_fixed2.exp:
tests/hard_coded/purity/impure_func_t5_fixed2.exp2:
tests/hard_coded/purity/impure_pred_t1_fixed3.m:
tests/hard_coded/purity/impure_pred_t1_fixed3.exp:
tests/invalid/purity/Mmakefile:
tests/invalid/purity/impure_func_t5_fixed.m:
tests/invalid/purity/impure_func_t5_fixed.err_exp:
tests/invalid/purity/impure_pred_t1_fixed.m:
tests/invalid/purity/impure_pred_t1_fixed.err_exp:
	Add new test cases to test the new feature.

tests/invalid/purity/impure_func_t5.err_exp:
tests/invalid/purity/impure_pred_t1.err_exp:
tests/invalid/purity/impure_pred_t2.err_exp:
tests/invalid/purity/purity.err_exp:
tests/invalid/purity/purity_nonsense.err_exp:
	Update the expected error messages for existing test cases.

tests/invalid/purity/.cvsignore:
	New file, copied from tests/invalid/.cvsignore.
2003-01-27 09:21:03 +00:00
Mark Brown
06f2029688 Allow typeclass constraints on ground types.
Estimated hours taken: 3
Branches: main

Allow typeclass constraints on ground types.

compiler/prog_io_typeclass.m:
	Remove the check that typeclass constraints are non-ground.

compiler/polymorphism.m:
compiler/typecheck.m:
	Change tests for monomorphic calls to also test for no constraints.
	The optimizations that are applied if these tests succeed assume
	that there are no constraints.

	Remove "sanity" checks which are no longer applicable.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/ground_constraint.exp:
tests/hard_coded/typeclasses/ground_constraint.m:
	Test the new feature.

tests/invalid/Mmakefile:
tests/invalid/typeclass_constraint_no_var.err_exp:
tests/invalid/typeclass_constraint_no_var.m:
tests/valid/Mmakefile:
tests/valid/typeclass_constraint_no_var.m:
	Move this test from invalid to valid, since it should compile
	successfully now.
2002-09-25 06:49:43 +00:00
David Overton
9739517435 Allow constraints on pred/func, instance and typeclass declarations to
Estimated hours taken: 25
Branches: main


Allow constraints on pred/func, instance and typeclass declarations to
constraint arbitrary types rather than just type variables.  The only
restriction is that each constraint must contain at least one type
variable and that all type variables in the constraint must also occur
somewhere else in the declaration.

compiler/prog_io_typeclass.m:
	When parsing class constraints (on pred/func, instance and
	typeclass declarations) remove the restriction that the
	arguments must all be variables.  Instead, ensure that at least
	one argument contains at least one variable.

compiler/hlds_data.m:
compiler/hlds_out.m:
compiler/make_hlds.m:
	Allow superclass constraints to have arguments of arbitrary type
	(rather than just variables) in the superclass table.

compiler/polymorphism.m:
compiler/typecheck.m:
	Put in some checks to ensure that we don't get into an infinite
	loop when processing mutually constrained intances, e.g.

		:- instance c(f(T)) <= d(g(T)).
		:- instance d(g(T)) <= c(f(T)).

doc/reference_manual.texi:
	Document the change.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/arbitrary_constraint_class.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_class.m:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_1.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_1.m:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_2.exp:
tests/hard_coded/typeclasses/arbitrary_constraint_pred_2.m:
tests/hard_coded/typeclasses/recursive_instance_1.exp:
tests/hard_coded/typeclasses/recursive_instance_1.m:
tests/hard_coded/typeclasses/recursive_instance_2.exp:
tests/hard_coded/typeclasses/recursive_instance_2.m:
tests/invalid/Mmakefile:
tests/invalid/typeclass_constraint_extra_var.err_exp:
tests/invalid/typeclass_constraint_extra_var.m:
tests/invalid/typeclass_constraint_no_var.err_exp:
tests/invalid/typeclass_constraint_no_var.m:
	Add some test cases.
2002-07-26 06:33:20 +00:00
Simon Taylor
9dbcf4714a Fix a bug which caused type-incorrect HLDS to be generated by mode
Estimated hours taken: 5
Branches: main

Fix a bug which caused type-incorrect HLDS to be generated by mode
analysis, which then caused a compiler abort in simplification.
In the code below, mode analysis must treat the headvar unification
as a construction followed by a var-var unification. If it is treated
as a deconstruction, the argument unifications will be ill-typed.

	:- type t ---> some [T] f(T) => enum(T).
	:- pred p(t::in) is semidet.
	p('new f'(1)).

compiler/modecheck_unify.m:
	Make sure unifications with a RHS of the form 'new f(X)'
	are always classified as constructions.

compiler/hlds_goal.m:
compiler/*.m:
	Add a field to var-functor unifications which identifies
	those which must be treated as constructions.

compiler/polymorphism.m:
	Fill in the field.

tests/hard_coded/Mmakefile:
tests/hard_coded/unify_existq_cons.{m,exp}:
	Test case.
2002-07-22 06:30:04 +00:00
Simon Taylor
e66536cbe8 Update a comment about a bug which has been fixed.
Estimated hours taken: 0.25
Branches: main

compiler/polymorphism.m:
	Update a comment about a bug which has been fixed.
2002-07-21 03:09:59 +00:00
Simon Taylor
f65c3fd341 Previously, we assumed that when a type variable had not
Estimated hours taken: 1.5
Branches: main, release

compiler/polymorphism.m:
	Previously, we assumed that when a type variable had not
	been seen before, a type_info would be produced for
	it by a later goal. This didn't work when the type_info
	was contained in a typeclass_info produced by the later
	goal. Now whenever an existential typeclass_info is produced
	by a call or deconstruction unification, the type_info_varmap
	entries for such type variables are updated to point to the
	type_class_info, and code is generated to extract the type_info
	from the typeclass_info.

tests/hard_coded/Mmakefile:
tests/hard_coded/existential_reordering_class.{m,exp}:
	Before this change, the compiler reported a spurious mode
	error for this test case.
2002-06-11 16:29:57 +00:00
Simon Taylor
ba848ac99d Make sure the type-infos needed for complicated argument
Estimated hours taken: 3

compiler/polymorphism.m:
	Make sure the type-infos needed for complicated argument
	unifications of var-functor unifications are included in
	the non-locals set of the unification.
	This bug caused an MLDS code generator abort when compiling
	library/set_bbbtree.m with `--target asm'.

tests/hard_coded/Mmakefile:
tests/hard_coded/unify_typeinfo_bug.{m,exp}:
	Test case.
2002-06-11 09:30:54 +00:00
Zoltan Somogyi
6e8a16b6d8 Give the Mercury variables containing type_ctor_infos a meaningful,
Estimated hours taken: 0.5
Branches: main

compiler/polymorphism.m:
	Give the Mercury variables containing type_ctor_infos a meaningful,
	non-misleading name, i.e. name them TypeCtorInfo, not TypeInfo.

tests/debugger/nondet_stack.exp*:
	Update expected output containing variable names affected by the
	change to polymorphism.m.
2002-04-17 00:52:57 +00:00
Zoltan Somogyi
bf2ae5868d Fix some documentation rot.
Estimated hours taken: 0.1
Branches: main

compiler/polymorphism.m:
	Fix some documentation rot.
2002-04-12 02:25:22 +00:00
Zoltan Somogyi
189b9215ae This diff implements stack slot optimization for the LLDS back end based on
Estimated hours taken: 400
Branches: main

This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.

Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.

The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.

The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.

To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.

compiler/stack_opt.m:
	New module containing the code that performs the transformation
	to optimize stack slot usage.

compiler/matching.m:
	New module containing an algorithm for maximal matching in bipartite
	graphs, specialized for the graphs needed by stack_opt.m.

compiler/mercury_compile.m:
	Invoke the new optimization if the options ask for it.

compiler/stack_alloc.m:
	New module containing code that is shared between the old,
	non-optimizing stack slot allocation system and the new, optimizing
	stack slot allocation system, and the code for actually allocating
	stack slots in the absence of optimization.

	Live_vars.m used to have two tasks: find out what variables need to be
	saved on the stack, and allocating those variables to stack slots.
	Live_vars.m now does only the first task; stack_alloc.m now does
	the second, using code that used to be in live_vars.m.

compiler/trace_params:
	Add a new function to test the trace level, which returns yes if we
	want to preserve the values of the input headvars.

compiler/notes/compiler_design.html:
	Document the new modules (as well as trace_params.m, which wasn't
	documented earlier).

compiler/live_vars.m:
	Delete the code that is now in stack_alloc.m and graph_colour.m.

	Separate out the kinds of stack uses due to nondeterminism: the stack
	slots used by nondet calls, and the stack slots used by resumption
	points, in order to allow the reuse of stack slots used by resumption
	points after execution has left their scope. This should allow the
	same stack slots to be used by different variables in the resumption
	point at the start of an else branch and nondet calls in the then
	branch, since the resumption point of the else branch is not in effect
	when the then branch is executed.

	If the new option --opt-no-return-calls is set, then say that we do not
	need to save any values across erroneous calls.

	Use type classes to allow the information generated by this module
	to be recorded in the way required by its invoker.

	Package up the data structures being passed around readonly into a
	single tuple.

compiler/store_alloc.m:
	Allow this module to be invoked by stack_opt.m without invoking the
	follow_vars transformation, since applying follow_vars before the form
	of the HLDS code is otherwise final can be a pessimization.

	Make the module_info a part of the record containing the readonly data
	passed around during the traversal.

compiler/common.m:
	Do not delete or move around unifications created by stack_opt.m.

compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
	Allow the code generator to delete its last record of the location
	of a value when generating code to make an erroneous call, if the new
	--opt-no-return-calls option is set.

compiler/code_gen.m:
	Use a more useful algorithm to create the messages/comments that
	we put into incr_sp instructions, e.g. by distinguishing between
	predicates and functions. This is to allow the new scripts in the
	tool directory to gather statistics about the effect of the
	optimization on stack frame sizes.

library/exception.m:
	Make a hand-written incr_sp follow the new pattern.

compiler/arg_info.m:
	Add predicates to figure out the set of input, output and unused
	arguments of a procedure in several different circumstances.
	Previously, variants of these predicates were repeated in several
	places.

compiler/goal_util.m:
	Export some previously private utility predicates.

compiler/handle_options.m:
	Turn off stack slot optimizations when debugging, unless
	--trace-optimized is set.

	Add a new dump format useful for debugging --optimize-saved-vars.

compiler/hlds_llds.m:
	New module for handling all the stuff specific to the LLDS back end
	in HLDS goal_infos.

compiler/hlds_goal.m:
	Move all the relevant stuff into the new back end specific field
	in goal_infos.

compiler/notes/allocation.html:
	Update the documentation of store maps to reflect their movement
	into a subfield of goal_infos.

compiler/*.m:
	Minor changes to accomodate the placement of all back end specific
	information about goals from goal_exprs and individual fields of
	goal_infos into a new field in goal_infos that gathers together
	all back end specific information.

compiler/use_local_vars.m:
	Look for sequences in which several instructions use a fake register
	or stack slot as a base register pointing to a cell, and make those
	instructions use a local variable instead.

	Without this, a key assumption of the stack slot optimization,
	that accessing a field in a cell costs only one load or store
	instruction, would be much less likely to be true. (With this
	optimization, the assumption will be false only if the C compiler's
	code generator runs out of registers in a basic block, which for
	the code we generate should be unlikely even on x86s.)

compiler/options.m:
	Make the old option --optimize-saved-vars ask for both the old stack
	slot optimization (implemented by saved_vars.m) that only eliminates
	the storing of constants in stack slots, and the new optimization.

	Add two new options --optimize-saved-vars-{const,cell} to turn on
	the two optimizations separately.

	Add a bunch of options to specify the parameters of the new
	optimizations, both in stack_opt.m and use_local_vars.m. These are
	for implementors only; they are deliberately not documented.

	Add a new option, --opt-no-return-cells, that governs whether we avoid
	saving variables on the stack at calls that cannot return, either by
	succeeding or by failing. This is for implementors only, and thus
	deliberately documented only in comments. It is enabled by default.

compiler/optimize.m:
	Transmit the value of a new option to use_local_vars.m.

doc/user_guide.texi:
	Update the documentation of --optimize-saved-vars.

library/tree234.m:
	Undo a previous change of mine that effectively applied this
	optimization by hand. That change complicated the code, and now
	the compiler can do the optimization automatically.

tools/extract_incr_sp:
	A new script for extracting stack frame sizes and messages from
	stack increment operations in the C code for LLDS grades.

tools/frame_sizes:
	A new script that uses extract_incr_sp to extract information about
	stack frame sizes from the C files saved from a stage 2 directory
	by makebatch and summarizes the resulting information.

tools/avg_frame_size:
	A new script that computes average stack frame sizes from the files
	created by frame_sizes.

tools/compare_frame_sizes:
	A new script that compares the stack frame size information
	extracted from two different stage 2 directories by frame_sizes,
	reporting on both average stack frame sizes and on specific procedures
	that have different stack frame sizes in the two versions.
2002-03-28 03:44:41 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Zoltan Somogyi
41a27af862 Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Change type_id to the more descriptive type_ctor everywhere.
2002-03-07 08:30:28 +00:00
Fergus Henderson
9aca3d48f4 Another substantial step towards supporting accurate garbage
Branches: main
Estimated hours taken: 50

Another substantial step towards supporting accurate garbage
collection for the MLDS->C back-end: generate code for the
GC tracing functions.

compiler/mlds.m:
	Add new fields to store, with each local variable or argument
	declaration, the code for the GC to trace that local variable
	or argument.

compiler/ml_code_util.m:
	Add a new procedure ml_gen_maybe_gc_trace_code to generate the
	code for GC tracing a variable.  The generated MLDS code calls
	private_builtin:gc_trace/1, passing the variable's address and
	the type_info for that variable.  This code is generated by
	invoking polymorphism__make_type_info_var to generate HLDS code
	to build the type_infos needed, and then calling ml_code_gen.m
	to convert that to MLDS.

library/private_builtin.m:
	Add a new procedure gc_trace, which calls MR_agc_deep_copy().
	This gets invoked by the code generated by ml_code_util.m.

compiler/polymorphism.m:
	Export polymorphism__make_type_info_var, for use by ml_code_util.m.

compiler/mercury_compile.m:
	Invoke the chain_gc_stack_frames pass before invoking the
	hoist_nested_functions pass, since otherwise it doesn't work.

compiler/handle_options.m
	Add a couple of checks for options that are not supported
	in combination with `--gc accurate'.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
	Various changes to handle the GC trace code field for variable and
	argument declarations.
2002-01-11 07:44:29 +00:00
Fergus Henderson
36050375bf Fix a bug in the handling of pragma c_code / foreign_proc: in
Estimated hours taken: 2
Branches: main

compiler/polymorphism.m:
	Fix a bug in the handling of pragma c_code / foreign_proc: in
	the case where the procedure had both type class constraints
	and unconstrained type variables, it was getting the arguments
	in the wrong order.
2001-08-06 06:20:29 +00:00
Tyson Dowd
b0d7da6a01 Add a field to clauses_info to record whether we have any
Estimated hours taken: 20
Branches: main

compiler/hlds_pred.m:
	Add a field to clauses_info to record whether we have any
	foreign_proc clauses.

	Add a new goal type clauses_and_pragmas to describe predicates
	that have procedures implemented using both pragmas and clauses.

	Add pred_info_pragma_goal_type and pred_info_clause_goal_type
	to simplify cases where we are just interested whether the goal
	types might contain pragmas or goals.

compiler/make_hlds.m:
	Record errors if we try to add a foreign_proc that will replace
	a Mercury clause that is not mode-specific, or if we try to add
	a non-mode specific Mercury clause that will replace a foreign
	proc.
	Otherwise, we allow a foreign_proc to replace mode-specific
	Mercury clauses.
	Set the goal type for potentially mixed mercury/foreign_proc
	clauses as "clauses".
	Add Mercury clauses only for modes not yet covered by
	foreign_proc clauses.  Checking this could be a performance
	problem so we check the have_foreign_clauses boolean so
	that we don't need to search all the clauses every time we add a
	Mercury clause (only when there are foreign_clauses to search for).

	Traverse clauses and decide upon our course of action (add
	new foreign_proc clause, ignore new foreign_proc clause, replace
	existing clause, split existing clause and add new clause)
	all in one go.

compiler/clause_to_proc.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/purity.m:
compiler/polymorphism.m:
compiler/unify_proc.m:
	Handle have_foreign_clauses field in clauses_info.
	Handle clauses_and_pragmas goal type.

compiler/intermod.m:
	Handle clauses_and_pragmas goal type.
	Handle all clauses in a single pass, since we now know on a
	clause by clause basis whether they are foreign_proc clauses
	or Mercury clauses we can simplify the traversal of all clauses
	down to a single pass.

doc/reference_manual.texi:
doc/user_guide.texi:
	Document the ability to mix mode-specific Mercury and
	foreign_proc clauses.

	Document the behaviour of the implementation when it comes to
	specific backends (that is, the preferred foreign languages list).
	Also a few fixes from fjh's review that didn't quite make it
	into the review.
2001-07-31 14:30:15 +00:00
Tyson Dowd
cdbbaa5ac2 Support multiple language foreign_procs in the one file.
Estimated hours taken: 16
Branches: main

Support multiple language foreign_procs in the one file.

If there is more then one applicable foreign_proc for a
given clause, select the most "preferred" programming
language to use as the implementation.

Currently only the IL backend has multiple languages
supported by the backend, and C# is preferred over MC++.

compiler/options.m:
compiler/handle_options.m:
	Rename backend_foreign_language as backend_foreign_languages,
	and use it to record the list of foreign languages the selected
	backend can handle.
	Remove --use-foreign-language as it doesn't do anything right now.

compiler/foreign.m:
	Update code to use the list of backend foreign languages.
	Add prefer_foreign_language function, to compute the preferred
	foreign language ordering for each backend.
	Move simple_foreign_language_string here from globals.m,
	and add foreign_language_file_extension and
	foreign_language_module_name functions.

	(much of the rest of the code in this module is intended to deal with
	the case where the backend *doesn't* handle the foreign
	language, but we don't have any working support for that at the
	moment).

compiler/globals.m:
	Add globals__io_get_backend_foreign_languages and
	globals__get_backend_foreign_languages.

compiler/make_hlds.m:
	Handle selection of foreign_proc code depending upon the preferred
	language.
	Rename a few *_foreign_code predicates as *_foreign_proc
	predicates.
	Handle the extra field in clause.

compiler/ml_code_gen.m:
compiler/mlds.m:
	Generate different mlds__foreign_code for each language (only
	one language is selected for each predicate, but there can be
	multiple languages in the onle module).
	and put them in a map which is indexed on foreign language.

compiler/modules.m:
	Generate appropriate dependencies for foreign language modules.
	We now record which languages a list of items uses (taking into
	account the preferred foreign language for foreign_proc).
	We also allow for the fact that some foreign_proc declarations
	won't generate any external modules.


compiler/hlds_pred.m:
	Add an extra field to clause which records which language this
	clause has been implemented in.

compiler/assertion.m:
compiler/clause_to_proc.m:
compiler/dead_proc_elim.m:
compiler/goal_util.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/purity.m:
compiler/typecheck.m:
compiler/unify_proc.m:
	Handle the extra field in clause.


compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
	Select the appropriate mlds__foreign code from the map and
	generate code for it.
2001-07-20 14:14:30 +00:00
Simon Taylor
14cdb854dd Disable the test which causes us to not pass type-infos to C
Estimated hours taken: 0.1
Branches: main

(This change was sent to mecury-reviews by dgj. I'm committing it
now so that the installation on earth will succeed tonight).

compiler/polymorphism.m:
        Disable the test which causes us to not pass type-infos to C
        code which do not use the variable corresponding to that type-info.
        For some reason, this is causing the compiler to abort when
        compiling stage2/browser/declarative_execution.m.
2001-07-12 16:30:44 +00:00
Simon Taylor
d701d8ba06 Use pred_const cons_ids in the unify_rhs field for constructions
Estimated hours taken: 4

Use pred_const cons_ids in the unify_rhs field for constructions
of higher-order terms. Previously there would be a `cons(sym_name, arity)'
cons_id in the `unify_rhs', and a pred_const in the `unification'.

This avoids multiple calls to get_pred_id_and_proc_id, and is more
consistent with how other cons_ids are handled.

compiler/post_typecheck.m:
	Find the pred_const cons_id for constructions of higher-order terms.

	Make sure the sym_name field of a call goal is fully module qualified.

compiler/higher_order.m:
compiler/lambda.m:
	Use `pred_const' rather than `cons(sym_name, arity)' in the
	`unify_rhs' of constructions of higher-order terms.

compiler/polymorphism.m:
compiler/modecheck_unify.m:
	Change the interface of polymorphism__convert_pred_to_lambda_goal
	to reflect the fact that the pred_proc_id of the higher-order term
	has already been computed by post_typecheck.m.

compiler/purity.m:
	Don't attempt to resolve overloading if there were type errors.
	If the type inference iteration limit was exceeded the code
	to resolve overloading of higher-order terms in post_typecheck.m
	can abort. This occurred with tests/invalid/type_inf_loop.m.

compiler/hlds_goal.m:
	Remove documentation about the restrictions on cons_ids
	in a unify_rhs, since they no longer apply.

compiler/intermod.m:
	Remove code duplicated from post_typecheck.m.

compiler/hlds_data.m:
	Add a comment that code_addr_const cons_ids are no longer
	used (they are left over from an old method of constructing
	type_ctor_infos).

compiler/hlds_out.m:
	Don't abort on code_addr_consts in hlds_out__write_functor_cons_id.
	This will avoid problems if anyone decides to start using
	code_addr_consts again.

tests/invalid/Mmakefile:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_derived_relation.{m,err_exp}:
	Separate out parts of aditi_update_errors.m which
	were no longer being tested because post_typecheck
	is no longer run when there are type errors.

tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_mode_errors.err_exp:
	Update the expected output.
2001-07-10 10:45:36 +00:00
David Jeffery
204e151516 Do not pass a type-info or typeclass-info to C code that does not use
Estimated hours taken: 9

mercury/compiler/polymorphism.m:
        Do not pass a type-info or typeclass-info to C code that does not use
        the variable.
        To check if the C code uses the variable, we simply check for the
        occurence of the variable name in the string that represents the C
        code. This is potentially unsafe if the user decides to do something
        horrible with the preprocessor, but I don't think this needs to be
        specially documented --- AFAIK there is no user-visible documentation
        about passing type-infos to and from C anyway.
2001-07-10 08:06:13 +00:00
David Jeffery
3ea6e2e88d Fix a bug reported by Nick Nethercote. The symptom of this bug was that
Estimated hours taken: 4

Fix a bug reported by Nick Nethercote. The symptom of this bug was that
the compiler aborted during the polymorphism transformation for predicates
whose type contained a repeated type class constraint.

library/map.m:
	Add a new predicate map__set_from_corresponding_lists which is like
	map__det_insert_from_corresponding_lists but uses map__set rather
	than map__det_insert. ie. it does not abort if a duplicate key
	is provided. Also add a pred map__set_from_assoc_list and function
	versions of these two new preds to be consistent with
	map__det_insert_from_corresponding_lists.

compiler/polymorphism.m:
	When building the initial type class info variable map, use
	map__set_from_corresponding_lists rather than
	map__det_insert_from_corresponding_lists to take the case of repeated
	type class constraints into account.

tests/valid/Mmakefile:
tests/valid/repeated_class_constraint.m:
	A test case for this.
2001-05-24 02:32:31 +00:00
Fergus Henderson
59250e8f20 Fix bugs with the handling of existentially typed data types
Estimated hours taken: 8
Branches: main, release

Fix bugs with the handling of existentially typed data types
in various parts of the RTTI code.

Most of these bugs were due to passing in the pointer to the secondary
tag, rather than the pointer to the first real argument (one word
past the secondary tag).

library/std_util.m:
	Fix bugs in ML_expand() and du_get_functor_info.

runtime/mercury_tabling.c:
	Fix bug in MR_table_type().

runtime/mercury_deep_copy_body.h:
	Fix bug in MR_agc_deep_copy(), the accurate GC version of deep_copy().
	Also fix another bug in the same function: when copying existentially
	typed data types, it was trying to use the type_infos in the original
	data after they had already been replaced by forwarding pointers.

compiler/polymorphism.m:
	For existentially typed data types, make sure that the
	type_infos come BEFORE the typeclass_infos, not vice versa.
	This is needed to match the code in the runtime system.
	It's also consistent with the way we order them for procedure calls.

runtime/mercury_type_info.h:
	Improve the comments a little.

tests/hard_coded/Mmakefile:
tests/hard_coded/deep_copy_exist.m:
tests/hard_coded/deep_copy_exist.exp:
	Regression tests.
2001-04-29 18:22:02 +00:00
Fergus Henderson
36bb97d223 Fix a bug where the compiler was silently accepting invalid code.
Estimated hours taken: 6
Branches: main, release

Fix a bug where the compiler was silently accepting invalid code.

doc/reference_manual.texi:
	Document that type class methods must have their modes and
	determinism explicitly declared.

compiler/make_hlds.m:
	Report errors for predicate type class methods with no modes
	or with modes but no determinism.

compiler/check_typeclass.m:
compiler/polymorphism.m:
	Handle the case where a method has no declared determinism:
	since make_hlds.m will have already reported the error,
	we just need to avoid aborting or issuing spurious flow-on errors.

tests/invalid/Mmakefile:
tests/invalid/typeclass_missing_mode.m:
tests/invalid/typeclass_missing_mode.err_exp:
tests/invalid/typeclass_missing_mode_2.m:
tests/invalid/typeclass_missing_mode_2.err_exp:
tests/invalid/typeclass_missing_det.m:
tests/invalid/typeclass_missing_det.err_exp:
tests/invalid/typeclass_missing_det_2.m:
tests/invalid/typeclass_missing_det_2.err_exp:
tests/invalid/typeclass_missing_det_3.m:
tests/invalid/typeclass_missing_det_3.err_exp:
	Add some regression tests.

tests/invalid/tc_err1.err_exp:
	Update the expected output for this existing test.
2001-04-29 07:54:37 +00:00
Adrian Pellas-Rice
1c65d003f7 Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main

Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.

compiler/hlds_goal.m
        Create a new type, the `shorthand_goal_expr', for goals kinds that
        are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
        transformation.  At present, bi_implication is the only kind of
        of goal that is implemented in this way.

        Moved bi_implication functor from the type goal_expr to the new
        shorthand_goal_expr type.

        Added the functor shorthand to the goal_expr type.

compiler/*.m
        Change switches on hlds_goal_expr that call error when they recognise
        `bi_implication' from calling error when they recognise
        `bi_implication' to calling error when they recognise `shorthand'.

        For all predicates K that
                a) switch on hlds_goal_expr and
                b) perform non-trivial processing when they recognise
                   `bi_implication'
        change K such that it now calls K_shorthand upon recognising the
        functor `shorthand'. Define K_shorthand to switch on
        shorthand_goal_expr, where the code for the `bi_implication' case
        formerly contained in K is now contained in K_shorthand.
2001-04-07 14:05:03 +00:00
Tyson Dowd
711da78188 Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0
Branches: main

Rename foreign_code as foreign_proc where appropriate in the compiler.
The rationale for this change is that it makes maintaining the code much
simpler because it is clear whether `foreign' refers to a slab of code
(foreign_code) or a procedure (foreign_proc).

:- type pragma_foreign_code_attributes
:- type pragma_foreign_proc_attributes

The functors for pragma_type
	foreign(Lang, BodyCode)
	foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl)
become
	foreign_code(Lang, BodyCode)
	foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl)

And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'.

compiler/*.m:
	Update the compiler to use the new names.
2001-04-03 03:20:33 +00:00
David Jeffery
29baab7783 Fix a bug reported by petdr on October 30th last year.
Estimated hours taken: 12

Fix a bug reported by petdr on October 30th last year.

compiler/polymorphism.m:
        When looking up the variable which contains a typeclass info for
        a particular constraint to be passed to a call, handle the case where
        there is *no* variable for such a constraint. This occurs in the case
        where the producer of the variable occurs later on in the goal (but
        will get re-ordered by the mode checker). The solution is to just
        create a variable for the typeclass info, and whenever creating
        a `head' variable to hold a constraint being produced by a call,
        check first whether there is already a variable allocated for that
        constraint.

doc/reference_manual.texi:
        Delete mention of this bug from the "Known Bugs"  in the existential
        types section.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/reordered_existential_constraint.exp:
tests/hard_coded/typeclasses/reordered_existential_constraint.m:
        A test case for this. (Not the same as petdr's original test case,
        but much simpler and exhibits the same bug).
2001-02-12 05:14:58 +00:00
Simon Taylor
7fc6ce8792 Fix a bug which caused some programs using typeclasses to
Estimated hours taken: 6

Fix a bug which caused some programs using typeclasses to
crash with a segmentation fault.

compiler/polymorphism.m:
	For typeclass method implementations, make sure the
	order of the type-info and typeclass-info arguments
	matches the order used by do_call_class_method.
	The type-infos for the unconstrained type variables in
	the instance declaration and the typeclass-infos for the
	constraints on the instance declaration must come
	before any other type-infos and typeclass-infos.

compiler/hlds_pred.m:
	Add a field to the pred_info type to record for each
	typeclass method implementation which class constraints
	come from the `:- instance' declaration and which come
	from the predicate or function declaration in the
	`:- typeclass' declaration.

compiler/check_typeclass.m:
	Fill in the new field in the pred_info.

compiler/typecheck.m:
	Apply the necessary renamings to the types and
	class constraints in the new field in the pred_info.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/typeclass_order_bug.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug2.{m,exp}
tests/hard_coded/typeclasses/typeclass_order_bug3.{m,exp}
	Test cases.
2001-01-15 07:15:34 +00:00
Tyson Dowd
477ecb18f6 Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60

Implement pragma foreign_code for Managed C++.

Currently you can only write MC++ code if your backend is capable of
generating use MC++ as its "native" foreign language.  The IL backend is
the only backend that does this at the moment (the other backends have C
as their "native" foreign language).

Most of the machinery is in place to call from C to (normal) C++
but there is little work done on actually spitting out the C++ code into
a separate file.  The IL backend does this step already with managed C++.
The intention is to turn foreign_code for C++ into a pragma import
(which imports the C++ function from a separate file) and
foreign_code for C (which calls the imported function).  The C++ code
will be inserted into a separate file that is compiled using C linkage.

The important improvement this change gives is that you can write a
module with a C and a MC++ implementations side-by-side.  The target
backend will select the most appropriate foreign language to use.
You can override its choice using --use-foreign-language.  Later on
we will probably want more flexibility than just a single language
selection option).

This change also implements :- pragma foreign_decl, which allows header
file style declarations to be written in languages other than C.

compiler/code_gen.m:
	Reject code that is not C when generating LLDS.

compiler/export.m:
	Start renaming C as foreign.
	Reject code that is not C when generating exports.

compiler/foreign.m:
	A new module to handle foreign language interfacing.
	The bulk of the code for pragma import has been moved here from
	make_hlds.

compiler/globals.m:
	Convert foreign language names to foreign_language.
	This code has been moved closer to the similar conversion we do
	for target language names.
	Add globals__io_lookup_foreign_language_option to make it easier
	to deterministically lookup the options relating to foreign
	languages.


compiler/hlds_module.m:
	Move module_add_foreign_decl and module_add_foreign_body_code
	from make_hlds.m (where they were called module_add_c_header and
	module_add_c_code).

compiler/hlds_out.m:
	Write the foreign language out in HLDS dumps.

compiler/llds.m:
	Change foreign_header_info to foreign_decl_info.
	Change definitions of foreign_decl_code and foreign_body_code to
	include the language.

compiler/llds_out.m:
	Reject code that is not C when writing out LLDS.

compiler/make_hlds.m:
	Add foreign language information to the bodys and decls when
	creating them.
	Update error messages to refer to foreign code instead of C
	code.
	Use foreign.m to generate interfaces from the backend language
	to the foreign language.
	Hardcode C as the language for fact tables.

compiler/mercury_compile.m:
	Collect the appropriate foreign language code together for
	output to the backend.

compiler/intermod.m:
compiler/mercury_to_mercury.m:
	Output the foreign language string.
	Change a few names to foreign_code instead of c_code.

compiler/ml_code_gen.m:
	Filter the foreign language bodys and decls so that we only get
	the ones we are in (given by the use-foreign-language option).

compiler/mlds_to_c.m:
	Abort if we are given non C foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/mlds_to_ilasm.m:
	Abort if we are given non MC++ foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/options.m:
compiler/handle_options.m:
	Add --use-foreign-language as a user option to control the
	preferred foreign language to use as the implementation of this
	module.
	Add backend_foreign_language as an internal option which stores
	the foreign language that the compiler will use as a default
	(e.g. the natural foreign language for the backend to use).
	Set the preferred backend foreign language depending on the
	target.

compiler/prog_data.m:
	Add managedcplusplus as a new alternative for the
	foreign_language type.
	Make c_header_code into foreign_decl.
	Give the foreign language for foreign_code as an attribute of
	the code.
	Write code to turn attributes into a list of strings (suitable
	for writing out by mercury_to_mercury).  This fixes what appears
	to be a bug in tabled_for_io -- the tabled_for_io attribute was not
	being written out.  Structure the code so this bug is
	difficult to repeat in future.

compiler/prog_io_pragma.m:
	Parse foreign_decl.
	Turn c_header_code into a special case of foreign_decl.

compiler/*.m:
	Remove the language field from pragma_foreign_code, it is now an
	attribute of the code.
	Various type and variable renamings.

tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
	Update the tests to reflect the new error messages talking
	about :- pragma foreign_code rather than :- pragma c_code.
2000-11-17 17:48:52 +00:00
David Jeffery
e29f9a3d2f Fix a bug whereby polymorphism was not using the complete set of class
Estimated hours taken: 5

Fix a bug whereby polymorphism was not using the complete set of class
constraint proofs when generating a type class info, resulting in a map
lookup failure under certain conditions.

compiler/polymorphism.m:
        When generating a type class info, don't just pass the proofs for
        the instance declaration that we calculated in check_typeclass.m.
        These proofs just specify how to build the type class infos for any
        superclass constraints *given the constraints on the instance
        declaration*. Instead, we pass the union of those constraints and
        those local to the predicate. This provides proofs for the constraints
        on the instance declaration too.

compiler/typecheck.m:
        Rather than using the headvars as the set of variables that must not
        be bound when searching the superclass relation, use all the variables
        in the varset. This remove a parameter from the exported constraint
        reduction predicate.
compiler/check_typeclass.m:
        Remove the redundant parameter.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/superclass_bug2.exp:
tests/hard_coded/typeclasses/superclass_bug2.m:
        A test case for this.
2000-11-06 04:10:06 +00:00
Fergus Henderson
e6769ef622 Record the module that each instance declaration came from.
Estimated hours taken: 8

Record the module that each instance declaration came from.
This is needed for the IL back-end, which includes that
module name in the symbol name that it generates for each
instance declaration.

compiler/prog_data.m:
	Add a module_name field to the `instance' item.

compiler/prog_io_typeclass.m:
	When parsing `instance' declarations, store the
	module name that they came from in the module_name field
	of the `instance' item.

compiler/hlds_data.m:
	Add a module_name field to the `hlds_instance_defn' structure.

compiler/make_hlds.m:
	Copy the module_name field from the `instance' item to the
	`hlds_instance_defn' structure.

compiler/polymorphism.m:
	Fix an old XXX: when constructing `base_typeclass_info_const's,
	use the module name from the `hlds_instance_defn', rather than
	hard-coding the invalid value "some bogus module name".

compiler/rtti.m:
	Add a module_name field to the `base_typeclass_info' rtti_name
	and rtti_data.

compiler/base_typeclass_info.m:
	Copy the module_name field in the `hlds_instance_defn' to the
	module_name field in the `base_typeclass_info' rtti_data
	and rtti_name.

compiler/rtti_to_mlds.m:
	When constructing mlds `data_addr's, use the module_name from
	the `base_typeclass_info' rtti_name, rather than assuming that
	such references always refer to instance declarations in the
	current module.  (That assumption would be a safe one currently,
	but doing it this way is probably a bit more robust against
	future changes.)

compiler/*.m:
	Trivial changes to reflect the above data structure changes.
2000-11-01 05:12:14 +00:00
David Overton
82378c381b Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80

Allow polymorphic ground insts.  This change assumes that all inst
parameters in the mode declaration for a predicate or function are
constrained to be ground-shared.  This is a temporary measure until we
work out a nice syntax to allow the programmer to tell the compiler that
certain inst parameters may be treated as ground insts.  Since we don't
currently support unconstrained inst parameters anyway, this shouldn't
cause a problem.

	TODO:
		- Add syntax, something like `:- mode p(in(I)) <= ground(I).',
		  to specify that an inst parameter represents a ground inst.
		- Allow abstract ground insts that are treated in a similar
		  way to what we've done here with ground inst parameters.
		- Make mode checking more efficient (i.e. rewrite the mode
		  system).

compiler/inst.m:
	Add a new alternative for ground insts:
		`constrained_inst_var(inst_var)'.
	Define the type `inst_var_sub'.

compiler/inst_match.m:
	Change inst_matches_initial so that it:
		- handles constrained_inst_vars correctly;
		- returns the inst_var substitutions necessary for the call;
		- handles inst_matches_initial(ground(...), bound(...), ...)
		  properly (this requires knowing the type of the variable).

	  The last change has also been made for inst_matches_final
	  and inst_matches_binding.  However, the check is disabled for
	  now because, without alias tracking, the mode checker
	  becomes too conservative.

compiler/hlds_pred.m:
compiler/mode_info.m:
compiler/simplify.m:
compiler/det_util.m:
	Include the inst_varset in the proc_info, mode_info and simplify_info.
	Add a vartypes field to the det_info.
	Remove the vartypes field from the simplify_info since it is
	now in the det_info.
	Use record syntax for these data structures and their access predicates
	to make future changes easier.

compiler/prog_io.m:
	When processing pred and func mode declarations, convert all inst_var(V)
	insts to ground(shared, constrained_inst_var(V)).

compiler/prog_data.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/mode_util.m:
	Use inst_vars instead of inst_params.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
compiler/mode_util.m:
	When checking or recomputing initial insts of a call, build up
	an inst_var substitution (using the modified
	inst_matches_initial) and apply this to the final insts of the
	called procedure before checking/recomputing them.

compiler/mode_util.m:
	Make sure that recompute_instmap_delta recomputes the
	instmap_deltas for lambda_goals even when RecomputeAtomic = no.

compiler/type_util.m:
	Add a new predicate, type_util__cons_id_arg_types which
	nondeterministically returns the cons_ids and argument types for a
	given type.
	Add a new predicate type_util__get_consid_non_existential_arg_types
	which is the same as type_util__get_existential_arg_types except
	that it fails rather than aborting for existenially typed arguments.

compiler/accumulator.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/dnf.m:
compiler/follow_code.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_io_util.m:
compiler/prog_rep.m:
compiler/saved_vars.m:
compiler/stack_layout.m:
compiler/table_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Pass inst_varsets and types where needed.
	Changes to reflect change in definition of the inst data type.

compiler/inlining.m:
	Recompute the instmap deltas for a procedure after inlining.
	This bug showed up compiling tests/hard_coded/lp.m with
	inlining and deforestation turned on: deforestation was
	getting incorrect instmap deltas from inlining, causing
	the transformation to break mode-correctness.  It has only
	just shown up because of the added call to
	`inst_matches_initial' from within `recompute_instmap_delta'.

tests/invalid/Mmakefile:
tests/invalid/unbound_inst_var.m:
tests/invalid/unbound_inst_var.err_exp:
tests/valid/Mmakefile:
tests/valid/unbound_inst_var.m:
	Move the `unbound_inst_var' test case from `invalid' to `valid'
	and extend its coverage a bit.
2000-10-13 13:56:17 +00:00
Simon Taylor
3cf329a739 Fix bugs in explicit type qualification.
Estimated hours taken: 4

Fix bugs in explicit type qualification.

compiler/make_hlds.m:
	Make the code to handle type qualification expressions match
	the documentation. Variables occurring in type qualifications
	but not in the predicate's argument types are local to the
	clause in which they occur.

	Don't export clauses_info_init -- it's not used anywhere else.

	Add field labels to the qual_info type.

compiler/hlds_pred.m:
compiler/*.m:
	Add a field to the clauses_info to contain the mapping from
	type variable names to type variables for the head types.
	This needs to be maintained because type variables added
	while processing type qualifications in a clause should
	not be added to the map used for other clauses.

compiler/typecheck.m:
	Apply substitutions to the explicit vartypes at the end
	of each pass of typechecking to keep them in sync with
	the type variables in the argument types.

compiler/type_util.m:
	Add a predicate type_util__apply_variable_renaming_to_type_map
	for use by typecheck.m.

doc/reference_manual.texi:
	Add some more comments about the handling of explicit type
	qualifications to the documentation about valid type assignments.

	Change references to existential type _qualifiers_ to consistently
	refer to existential type _quantifiers_.

tests/hard_coded/type_qual.{m,exp}:
	Add some more tests.

tests/hard_coded/Mmakefile:
	Pass `--infer-all' to mmc when compiling type_qual.m.
2000-09-25 04:23:19 +00:00
Simon Taylor
46a8da81cb Implement builtin tuple types, similar to those in Haskell.
Estimated hours taken: 30

Implement builtin tuple types, similar to those in Haskell.

Tuples are constructed and deconstructed using
the syntax X = {Arg1, Arg2, ...}.
Tuples have type `{Arg1, Arg2, ...}'.

Unary tuples (X = {Arg}) do work, unlike in Haskell. The rationale
for this is that it is useful to be able to construct unary tuples
to be passed to a polymorphic predicate which uses std_util__deconstruct
to deal with a tuple of any arity. Since this is probably the only
use for unary tuples, it's not really worth the effort of treating
them as no_tag types, so we don't.

The type-infos for tuples have the same structure as for higher-order
types. There is a single type_ctor_info for tuples, and the arity
is placed before the argument type_infos.

library/parser.m:
	Change the way '{}/N' terms are parsed, so that the parsed
	representation is consistent with the way other functors
	are represented (previously the arguments were left as
	unparsed ','/2 terms). This avoids special case code
	in prog_io__parse_qualified_term, term__term_to_type
	and term__type_to_term.

compiler/prog_io_dcg.m:
compiler/prog_io_util.m:
	Handle the new structure of '{}/N' terms when parsing DCG escapes
	by converting the argument list back into a single ','/2 term.

compiler/module_qual.m:
	Treat tuples as a builtin type.

compiler/typecheck.m:
	Typecheck tuple constructors.

compiler/mode_util.m:
	Propagate types into tuple bound insts.

compiler/type_util.m:
	Add type_is_tuple/2 and type_id_is_tuple/1 to identify tuple types.
	Add tuples to the list of types which are not atomic types.

	Handle tuple types in `type_constructors' and
	`get_cons_id_arg_types' and `switch_type_num_functors'.

compiler/tabling.m:
	Handle tabling of tuples.

compiler/term_util.m:
	Handle tuples in the code to compute functor norms.

compiler/magic_util.m:
compiler/rl.m:
compiler/rl_key.m:
	Handle tuple types in the Aditi back end.

compiler/mercury_to_mercury.m:
library/io.m:
library/term_io.m:
	Handle output of '{}/N' terms.

compiler/higher_order.m:
compiler/simplify.m:
	Don't specialize complicated unifications of tuple
	types into calls to a specific unification procedure --
	even if the procedure were implemented, it probably
	wouldn't be that much more efficient.

compiler/unify_proc.m:
	Generate unification procedures for complicated unifications
	of tuples (other than in-in unifications). These are generated
	lazily as required.

compiler/make_hlds.m:
	Export add_special_pred for use by unify_proc.m.

compiler/polymorphism.m:
	Export polymorphism__process_pred for use by unify_proc.m.

compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/ml_code_util.m:
	Handle unify procedure names and tags for tuple types.

compiler/mlds_to_c.m:
	Output tuple types as MR_Tuple.

compiler/ml_unify_gen.m:
	Compute the field types for tuples.

compiler/polymorphism.m:
compiler/pseudo_type_info.m:
	Treat tuple type_infos in a similar way to higher-order type_infos.

compiler/hlds_data.m:
	Document how cons_ids for tuple types are represented.

compiler/switch_gen.m:
compiler/table_gen.m:
	Add tuple types to switches on type_util__builtin_type.

compiler/llds_out.m:
util/mdemangle.c:
profiler/demangle.m:
	Transform items named "{}" to "f_tuple" when mangling symbols.

library/builtin.m:
	Define the type_ctor_info used for tuples.

library/private_builtin.m:
	Add `builtin_unify_tuple/2' and `builtin_compare_tuple/3',
	both of which abort. All comparisons and in-in unifications
	of tuples are performed by the generic unification functions
	in runtime/mercury_ho_call.c and runtime/mercury.c.

library/std_util.m:
	Implement the various RTTI functions for tuples.

	Encode tuple `TypeCtorDesc's in a similar way to that
	used for higher-order types. This has the consequence that the limit
	on the arity of higher-order types is now MAX_VIRTUAL_REG,
	rather than 2*MAX_VIRTUAL_REG.

	Avoid calling MR_GC_free for the type-info vector returned
	from ML_expand() for tuples because unlike the vectors
	for du types, it is not copied.

runtime/mercury_type_info.h:
	Add macros for extracting fields from tuple type-infos.
	These just call the macros for extracting fields from higher-order
	type-infos.

	Add a macro MR_type_ctor_rep_is_variable_arity(), which
	returns TRUE for tuples and higher-order types.

	The distinction between higher-order and first-order types
	is now misnamed -- the distinction is really between fixed arity
	types and builtin variable arity types. I'm not sure whether
	it's worth renaming everything.

runtime/mercury.h:
runtime/mercury.c:
	Define unification and comparison of tuples in
	high-level code grades.

runtime/mercury_deep_copy_body.h:
runtime/mercury_make_type_info_body.h:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
	Handle tuple types in code which traverses data using RTTI.

tests/hard_coded/construct.{m,exp}:
tests/hard_coded/expand.{m,exp}:
	Test RTTI functions from std_util.m applied to tuples.

tests/hard_coded/tuple_test.{m,exp}:
	Test unification, comparison, term_to_type etc. applied to tuples.

tests/hard_coded/deep_copy.{m,exp}:
	Test deep copy of tuples.

tests/hard_coded/typeclasses/tuple_instance.{m,exp}:
	Test instance declarations for tuples.

tests/tabling/expand_tuple.{m,exp}:
	Test tabling of tuples.

tests/hard_coded/write.m:
	Add some module qualifications for code which uses
	`{}/1' constructors which are not tuples.

tests/invalid/errors2.{m,err_exp,err_exp2}:
	Test handling of tuples in type errors messages.

NEWS:
doc/reference_manual.texi:
w3/news/newsdb.inc:
	Document tuples.

doc/transition_guide.texi:
	Document the change to the parsing of '{}/N' terms.
2000-09-18 11:53:19 +00:00
Simon Taylor
2490aac4dd Generate declarations and clauses for the compiler-generated
Estimated hours taken: 10

Generate declarations and clauses for the compiler-generated
unification and comparison procedures only when they are needed.
The vast majority of these procedures are never used.
This change speeds up `mmc -C make_hlds' by about 5%.

compiler/make_hlds.m:
	Export add_special_pred_for_real and add_special_pred_decl_for_real
	for use by unify_proc.m.

	Don't generate declarations or clauses for unification or
	comparison predicates for imported types immediately
	unless the predicate needs to be typechecked.

	Don't generate clauses for comparison predicates for
	imported types -- they will never be used because the
	predicate has import_status `imported'.

compiler/special_pred.m:
compiler/typecheck.m:
	Add predicate special_pred_for_type_needs_typecheck,
	which succeeds for types with user-defined equality
	and types with existentially typed constructors.

compiler/unify_proc.m:
	Make sure the declarations and clauses for the unification
	predicate for a type have been generated before processing a
	unify_request for that type.

	Add predicates for use by higher_order.m to force generation
	of a special predicate when required for specialization
	of a call to unify/2 or compare/3.

	Simplify the code for unification predicates for enumeration
	types. The code that was being generated cast the arguments
	to int, then called unify/2 on the ints. The simpler version
	just creates a unify goal. Enumerations are atomic types, so
	modecheck_unify.m will treat the unification as a simple_test.

compiler/polymorphism.m:
	Add a predicate polymorphism__process_generated_pred to
	be used by unify_proc.m to process the bodies of the
	generated unification predicates.

compiler/post_typecheck.m:
	Add versions of post_typecheck__finish_pred and
	post_typecheck__finish_imported_pred which don't require
	an io__state, for use by unify_proc.m. Errors should never
	be reported in post_typecheck.m for unification or
	comparison predicates.

compiler/simplify.m:
	Don't generate calls to the type-specific predicate
	for an in-in complicated unification if the predicate is
	generated lazily. higher_order.m will handle the
	specialization in that case.

compiler/higher_order.m:
	Call unify_proc.m to generate the declarations for a
	special pred when there is a call to that special pred
	which could be specialized.

	Add field labels to the higher_order_info type.

compiler/type_util.m:
	Add predicates type_id_is_atomic and classify_type_id,
	which are similar to type_is_atomic and classify_type,
	for use by special_pred.m.
2000-09-16 00:08:36 +00:00
Zoltan Somogyi
10a433374b Restore the clipping of instmap deltas to the nonlocals set, undoing most of
Estimated hours taken: 16

Restore the clipping of instmap deltas to the nonlocals set, undoing most of
a recent change of mine. (The general cleanup parts of that change, e.g.
added field names, stay.) The reason is that the previous diff changed the
clipping algorithm only where the instmap deltas were being originally
computed, whereas for completeness you also need to do this in places where
they are recomputed after optimizations such as deforestation, and doing so
would have required changes in several more parts of the compiler, which
would have been tedious to maintain.

Instead, I now use a different technique to solve the original problem.
This technique is to change liveness.m so that it considers the first
occurrence of any type(class)info variable to be a value giving occurrence
even if the variable is not referred to by the instmap delta of the goal.
This assumption is true in the current polymorphism design and in any
extension of it that I can foresee. Type(class)info variables will therefore
be born in the first goal that refers to them, even if they are not in the
nonlocal set of that goal. If there are any later references to variables
whose type is described in whole or in part by that typeinfo, the typeinfo
will die at the last such reference, otherwise it will die in the goal
in which it is born.

From now on, the only module of the compile which needs to worry about the
extension of the life of type(class)info variables beyond the goals referring
to them is liveness.m.

compiler/quantification.m:
compiler/mode_info.m:
compiler/mode_util.m:
	Reset the interfaces of quantification and mode checking to the old
	ones, which do not require knowing typeinfo_liveness and typeinfo
	varmaps.

compiler/modes.m:
compiler/unique_modes.m:
	Clip instmap deltas to the nonlocals, not the completed nonlocals.

compiler/hlds_goal.m:
	Add a utility pred which gets the nonlocals from a goal, not a
	goal_info.

compiler/liveness.m:
	Add special handling for type(class)info vars as described above.

compiler/accumulator.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/lambda.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/unify_proc.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Use the reset interfaces of quantification and mode checking,
	and eliminate redundant local copies of goal_get_nonlocals.
2000-09-16 00:08:31 +00:00
David Jeffery
ec4a898e2b This change fixes a bug reported by Tom Conway yesterday.
Estimated hours taken: 2

This change fixes a bug reported by Tom Conway yesterday. The problem was
that when a construction using a constructor with existentially quantified
args appeared in more than one disjunct, the necessary typeclass infos were
only created on one branch.

compiler/polymorphism.m:
        Only update the locations of typeclass info variables when doing
        a deconstruction of a functor with existentially typed arguments.
        (ie. don't do it for constructions). This is analagous to our handling
        of universally/existentially quantified arguments to predicate calls.

tests/hard_coded/typeclasses/exist_disjunction.{m,exp}:
        A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
        Turn this test case on.
2000-09-05 02:38:20 +00:00
Simon Taylor
695425d66b Fix type specialization of calls to class methods for which
Estimated hours taken: 4

Fix type specialization of calls to class methods for which
the instance declaration has unconstrained type variables.
Fix bugs in the specialization of existentially quantified
procedures.

compiler/higher_order.m:
	Extract the type_infos for the unconstrained type variables
	from the typeclass_info and pass them to the call.

	Only pass the universally quantified type parameters, not
	the head_type_params, when working out type substitutions
	for specialized versions of predicates, since the existentially
	quantified type variables can be bound by the substitution.

compiler/polymorphism.m:
	Make sure that the types of the type_infos for existentially
	quantified types match the types of the variables they describe.
	We were getting this right for the types returned by
	pred_info_arg_types, but the types in the vartypes fields
	of the clauses_infos and proc_infos weren't bound enough.
	As a result, polymorphism was producing unifications such as
	`TypeInfo_for_T : type_info(T) =
		TypeInfo_for_string : type_info(string)'.
	This is likely to cause problems for optimization passes.

tests/hard_coded/typeclasses/Mmakefile:
	Remove `--no-user-guided-type-specialization' flags which
	were used to work around these bugs.

tests/hard_coded/typeclasses/instance_unconstrained_tvar_type_spec.m:
tests/hard_coded/typeclasses/instance_unconstrained_tvar_type_spec.exp:
	Test case.
2000-09-01 11:48:22 +00:00
Simon Taylor
e6f09bff49 Fix a bug in the handling of typeclass methods with unconstrained
Estimated hours taken: 0.5

Fix a bug in the handling of typeclass methods with unconstrained
existentially typed arguments. The modes of the extra arguments
introduced by polymorphism.m were added in the wrong order,
resulting in a mode error.

compiler/polymorphism.m:
	Add the modes for type_infos before the modes of typeclass_infos,
	not the other way around.

tests/hard_coded/Mmakefile:
tests/hard_coded/typeclass_exist_method_2.m:
	Test case.
2000-08-24 05:59:35 +00:00
Tyson Dowd
c192d50143 Add preliminary support for a new pragma:
Estimated hours taken: 15

Add preliminary support for a new pragma:

:- pragma foreign_code(LanguageString, .... <same args as c_code>).

This is intended to be the eventual replacement of pragma c_code.
Presently the only valid language is "C".
The existing pragma c_code is simply turned into pragma foreign_code.

pragma foreign_code is not a supported pragma at the moment.  There are
several other changes that are intended (for example, foreign_code will
be impure by default).

This change also changes the HLDS goal pragma_c_code/7 to
pragma_foreign_code/8 where the extra argument is the foreign language.

Any code currently generating output for pragma C code simply checks
that the foreign language is set to "c".  Since this is the only
alternative of the type foreign_language, it will always succeed.
However when new alternatives are added it should be fairly easy to find
where the changes need to be made.

Some type names and predicate names have also been updated, however
there are many more that haven't yet been touched.

compiler/prog_io_pragma.m:
	Accept the new syntax.	Turn the old syntax into the new item.

compiler/hlds_goal.m:
	Change pragma_c_code/7 to pragma_foreign_code/8.
	Define the foreign_language type.

compiler/llds.m:
	Change user_c_code/2 to user_foreign_code/3.

compiler/*.m:
	Update the rest of the compiler to handle these types.
	Make a few small changes to update variable names, predicate
	names and type names.
2000-08-09 07:48:04 +00:00
Zoltan Somogyi
891b89e650 Make sure that all parts of the compiler use a consistent idea of which
Estimated hours taken: 4

Make sure that all parts of the compiler use a consistent idea of which
predicates should have typeinfo liveness applied to their bodies when the
relevant option is set. This set is all predicates except the few in
the builtin modules which do not have the required arguments.

compiler/hlds_pred.m:
	Expand the interface of the should_use_typeinfo_liveness family of
	predicates to include an id of the predicate in question, to enable
	them to test whether the pred is a no_type_info_builtin.

compiler/hlds_pred.m:
compiler/polymorphism.m:
	Move the list of no_type_info_builtins from polymorphism to hlds_pred,
	since body_should_use_typeinfo_liveness also needs it now.

compiler/*.m:
	Minor changes to pass the right arguments to predicates of the
	should_use_typeinfo_liveness family, directly or indirectly.
2000-08-08 04:44:54 +00:00
Zoltan Somogyi
a0a6daa06f If we are using typeinfo liveness, then clip the instmap delta fields in
Estimated hours taken: 16

If we are using typeinfo liveness, then clip the instmap delta fields in
goal_infos not to the nonlocals, but to the nonlocals plus the
type info or typeclass info variables needed to describe the types of the
nonlocals (this set is now called the "typeinfo completed nonlocals").

This is necessary for the proper handling of code such as resume_typeinfos.m
in tests/debugger. This involves a call to a procedure with an existentially
typed argument, where the returned argument is processed only in ways that do
not need the typeinfo describing it. The compiler therefore considered the
typeinfo to be local to the call binding it. Its binding was therefore not
recorded in the instmap delta, which in turn meant that in the absence of a
value-giving occurrence, liveness.m considered it not to be born anywhere.
On the other hand, with typeinfo liveness, occurrences of the argument are
also considered value-using occurrences of the typeinfo, so the typeinfo
was considered to die at the last such occurrence. Therefore the typeinfo
died without being born. The current code generator is sloppy enough not
to mind this, but the upcoming eager code generator isn't.

compiler/hlds_goal.m:
	Document the new semantics of instmap_deltas.

compiler/quantification.m:
compiler/mode_util.m:
compiler/modes.m:
compiler/unique_modes.m:
	If typeinfo liveness is set, include the relevant typeinfo variables
	in the set of variables the instmap is limited to.

compiler/modes.m:
	Delete some unused predicates.

compiler/hlds_pred.m:
	Centralize the code for (maybe) completing a set of vars with the set
	of typeinfo vars describing their types here.

compiler/call_gen.m:
compiler/live_vars.m:
	Use the central code in hlds_pred.m.

compiler/accumulator.m:
compiler/cse_detection.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/lambda.m:
compiler/liveness.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mode_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Call quantification and/or mode_util with the right arguments.
	In some cases, introduce field names, predmode declarations and/or
	shorter type names to make this change easier.
2000-08-03 08:46:44 +00:00
Peter Ross
a48beedc9d Fix a bug where pragma imports of polymorphic predicates where not
Estimated hours taken: 16

Fix a bug where pragma imports of polymorphic predicates where not
having typeinfos prepended to the call.

compiler/prog_data.m:
    Add a the new functor import/4 to pragma_c_code impl.
    The functor stores all the information needed to constuct a C code
    fragment a pragma import.

compiler/make_hlds.m:
    Rather then constructing the C code fragment immediately, construct
    the sub-parts and store them in import/4.

compiler/polymorphism.m:
    Prepend the typeinfos to the list of variables passed to the
    imported C function.

compiler/ml_code_gen.m:
compiler/pragma_c_gen.m:
    Construct the C code fragment then call the routine which handles
    `ordinary' pragma c_code.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
    Add code to recognise the import/4 functor.
2000-07-20 11:24:12 +00:00
Zoltan Somogyi
a5b691091c Simplify the code of maybe_init_second_cell by not testing conditions
Estimated hours taken: 1

compiler/polymorphism.m:
	Simplify the code of maybe_init_second_cell by not testing conditions
	twice.
2000-07-19 07:21:47 +00:00
David Jeffery
018c2aeb94 Replace a series of list__appends with a list__condense.
Estimated hours taken: 0.1

compiler/polymorphism.m:
        Replace a series of list__appends with a list__condense.
2000-05-25 02:35:03 +00:00
Fergus Henderson
082b084ac7 Implement static allocation of grounds terms for the
Estimated hours taken: 20

Implement static allocation of grounds terms for the
MLDS back-end.

compiler/hlds_goal.m:
	Change the `maybe(cell_to_reuse)' field of `construct'
	unifications from a `maybe(cell_to_reuse)' into a
	`how_to_construct' type with three alternatives,
	`reuse_cell(cell_to_reuse)', `construct_dynamically',
	and the new alternative `construct_statically(static_cons)'.
	`static_cons' is a new type that provides information on
	how to construct a static ground term.

compiler/goal_util.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/quantification.m:
	Trivial changes to handle the change to the `maybe(cell_to_reuse)'
	field of `construct' unifications.

compiler/mark_static_terms.m:
	New module.  This traverses the HLDS and marks terms which can
	be construction unifications which can be allocated statically
	with the `construct_statically' flag.

compiler/mercury_compile.m:
	For the MLDS back-end, if the static_ground_terms option is set,
	invoke the mark_static_terms pass.

compiler/ml_unify_gen.m:
	When generating code for construction unifications, pass down
	the `how_to_reuse' field.  If this is `construct_statically',
	then generate a local initialized static constant, rather than
	using `new_object' to allocate the memory dynamically.
	(This required some fairly substantial reorganization.
	I changed ml_gen_construct so that no_tag types and compound
	terms, including closures, are handled separately from
	constants.  I moved some of the code from ml_gen_construct_rep
	into ml_gen_construct, and the remainder, which deals with
	constants, was simplified and renamed ml_get_constant.  The
	code for constructing closures was moved into a separate
	predicate ml_gen_closure, and was simplified by elimination of
	some code duplication.  I also added a bunch of new procedures
	for generating static constants.)

compiler/mlds.m:
	Add a new alternative `mlds__array_type' to the mlds__type type.
	This is needed by ml_unify_gen.m for static constants.

compiler/mlds_to_c.m:
	Handle `mlds__array_type'.  This required splitting
	mlds_output_type into mlds_output_type_prefix and
	mlds_output_type_suffix.

compiler/ml_code_util.m:
	Reorder the code slightly, to improve readability.
2000-05-22 18:00:52 +00:00
Fergus Henderson
54678e871a Fix a bug that broke tests/hard_coded/existential_type_classes in MLDS
Estimated hours taken: 1

Fix a bug that broke tests/hard_coded/existential_type_classes in MLDS
grades.  The bug was that the typeclass_info type generated for pragma
c_code instructions was wrong: it was missing the `constraint' parameter.
This caused the MLDS code generator (specifically ml_gen_box_or_unbox_rval)
to insert an unnecessary cast, which in turn mean that the generated
rval was one that ml_gen_c_code_for_rval didn't know how to handle.

compiler/polymorphism.m:
	Change the code that generates types for typeclass_info
	variables in `pragma c_code' instructions so that it does so
	using `polymorphism__generate_typeclass_info_type', rather
	than hand-coding it, since the hand-coded version was wrong.
	Similarly, change a few places to use
	`polymorphism__build_type_info_type' to construct types for
	type_infos, rather than hand-coding it (in this case the
	hand-coding was OK, but the new code is more maintainable).
2000-05-21 11:39:45 +00:00
Simon Taylor
7622eb1d36 Finish the implementation of Aditi updates.
Estimated hours taken: 120

Finish the implementation of Aditi updates.

compiler/hlds_goal.m:
	Refactor the aditi_builtin type so that operations with
	similar syntax and implementations are grouped together.

	Add operations to delete a single tuple (`aditi_delete') and
	to modify tuples (`aditi_bulk_modify').

compiler/*.m:
	Minor changes required by refactoring the aditi_builtin type.

compiler/make_hlds.m:
	Parse `aditi_delete' and `aditi_bulk_modify' goals.

	Parse a nicer syntax for `aditi_bulk_delete' and
	`aditi_bulk_insert' goals
	(e.g. aditi_bulk_delete(p(_, X, _) :- X > 2)).

compiler/rl_out.pp:
	For each base relation, generate RL procedures to apply
	deletions and modifications to the relation. `aditi_bulk_modify'
	takes a closure which produces tuples which contain both the
	attributes of the tuple to delete and the tuple to insert. The
	modification RL procedure performs two projections on the
	closure result to produce the tuples to delete and the tuples
	to delete.

	The input stream to the rl_PROC_delete RL instruction must contain
	only tuples taken from the relation to delete from -- the deletion
	is done using the tuple-id rather than the tuple contents.
	The generated deletion procedure performs a semi-join of the
	relation to delete from with the relation containing the
	tuples to delete.

compiler/rl.m:
	Add predicates to generate the names of the modification
	and deletion RL procedures generated for each base relation.

compiler/rl_exprn.m:
	Generate the projection expressions required by the modification
	RL procedures generated for each base relation.

	Generate the equi-join expressions required by the modification
	and deletion RL procedures generated for each base relation.

compiler/unify_gen.m:
	Implement code generation for `aditi_bottom_up' closures.

compiler/rl.m:
compiler/magic.m:
	Factor out the code used to create the name of the RL procedure
	used to interface top-down Mercury to Aditi, for use by unify_gen.m
	to generate `aditi_bottom_up' closures.

compiler/code_util.m:
	Add predicate code_util__make_user_proc_label, which constructs
	a label name from the given all the individual pieces of information
	used to construct it, rather than just a pred_id and proc_id.
	This is used to produce the RL procedure name for an `aditi_bottom_up'
	closure, so that the code doesn't have to work out what the pred_id
	of the magic sets transformed procedure is.

compiler/magic.m:
	Always create new procedures to interface Mercury to Aditi,
	to make it easier for unify_gen.m to work out what the name
	of the interface procedure is -- don't optimize the case of
	a predicate with no input arguments.

	Alter the goal generated for the interface procedures so
	that it doesn't matter whether the interface procedure
	and the procedure it interfaces to are compiled together
	by rl_gen.m -- the old code generated for these procedures
	assumed they were compiled separately, which wasn't always the
	case.

	Don't pass a `magic_info' through the code to generate the
	C interface procedures -- only the module_info field was
	required.

compiler/magic_util.m:
compiler/magic.m:
compiler/context.m:
	Don't pass a `magic_info' through
	magic_util__create_input_test_unifications --
	only the module_info and proc_info fields were used.

compiler/post_typecheck.m:
compiler/magic_util.m:
	Don't report errors for the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify'.

compiler/purity.m:
	Change the mode of the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify' to `unused'.

compiler/call_gen.m:
	Generate `aditi_delete' and `aditi_bulk_modify'.

	Remove the `aditi__state' from the tuple to insert passed
	to an `aditi_insert' or `aditi_delete' operation -- the relation
	on disk does not contain the `aditi__state' attribute.

extras/aditi/aditi.m:
	Implement the updates.

	Allocate all memory on the Mercury heap to avoid memory
	leaks when a transaction aborts.

	Uncaught exceptions within a transaction now cause
	the transaction to abort, and the exception is rethrown
	to the caller.

	If using trailing, add trail entries for the output relation
	and cursor created for a call to an Aditi procedure, so that
	they will be cleaned up if only one solution of the call
	is needed or if an exception is thrown.

	Include line numbers in the debugging messages if an Aditi API
	function fails.

compiler/llds.m:
compiler/*.m:
	Rename the `do_aditi_modify' label to `do_aditi_bulk_modify' -- we
	may eventually want to implement a modification goal type which
	doesn't produce all modified tuples before applying the update.

doc/reference_manual.texi:
	Document `aditi_delete' and `aditi_bulk_modify'.

	Add some extra spacing in the Aditi update section to
	improve readability.

tests/valid/aditi_update.m:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
	Changed to fit in with the new syntax.

tests/valid/Mmakefile:
	Code generation for Aditi updates now works, so enable full
	compilation of the aditi_update.m test case, rather than
	just checking for errors.
2000-04-14 08:39:24 +00:00
David Jeffery
281796aa9a Make an addition to the type class info structure; add type infos for
Estimated hours taken: 10

Make an addition to the type class info structure; add type infos for
any type variables from the head of the instance declaration which are
unconstrained, and make the class method call mechanism insert these as
arguments to method calls. The implementations of methods expect to be passed
a type info for each unconstrained type variable and a type class info for
each constraint. Previously we were not passing the appropriate type infos.

Also move the documentation about the type class transformation from
polymorphism.m to a new file, compiler/notes/type_class_transformation.html.

compiler/base_typeclass_info.m:
        Generate the appropriate part of the new structure in the
        base_typeclass_info.
compiler/polymorphism.m:
        Add the appropriate type infos to the typeclass_info.
compiler/type_util.m:
        Add a new predicate `get_unconstrained_tvars'.
runtime/mercury_deep_copy_body.h:
        Update copy_typeclass_info to reflect the new structure.
runtime/mercury_ho_call.c:
        Copy the extra type infos to the beginning of the arguments when
        doing a class method call.
runtime/mercury_type_info.h:
        Update the macros used to access the type class info.

compiler/notes/type_class_transformation.html:
        The documentation about the type class transformation has been
        moved from polymorphism.m to here. This change corrects that
        documentation in several places and updates that documentation to
        reflect the changes to the typeclass_info structure from this diff.

tests/hard_coded/typeclasses/instance_unconstrained_tvar.exp:
tests/hard_coded/typeclasses/instance_unconstrained_tvar.m:
        A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
        Turn this test case on. For the moment, type specialisation is
        turned off for this test case as the specialiser does not insert the
        extra type infos that are needed.
2000-04-10 07:20:51 +00:00
Zoltan Somogyi
184e4710b1 Get the system to work with --no-special-preds, relying on RTTI interpretation
Estimated hours taken: 30

Get the system to work with --no-special-preds, relying on RTTI interpretation
to perform unifications and comparisons, in almost all cases. The only thing
that doesn't work is comparisons involving types with user-defined equality;
the generated exception does not get propagated across MR_call_engine
boundaries properly.

compiler/make_hlds.m:
	With --no-special-spreds, do not generate even declarations for
	type-specific index and compare predicates. Generate declarations
	and clauses for type-specific unify predicates, since we may need
	them for unifications that are not (in,in). However, we prevent
	the generation of code for the (in,in) case (i.e. mode 0) by pretending
	that the unify predicate is pseudo_imported, even in the module
	defining the type. There is one exception to this: for types with
	user-defined equality, we do generate a proper __Unify__ predicate,
	since this is the only convenient way to convert the specified
	sym_name of the equality predicate into a pred_id and proc_id,
	and a proper __Compare__ predicate, since this is the only convenient
	way to generate the full type name for the error message at runtime
	(due to polymorphism, the full type may not be known at compile time).
	(Finding the pred_id may require resolving type overloading,
	and finding the proc_id may require mode checking.)

compiler/simplify.m:
	When converting complicated unifications to calls, call the generic
	unify/2 and compare/3 predicates instead of the type-specific
	__Unify__ and __Compare__ predicates, if the latter do not exist.

compiler/higher_order.m:
	Do not specialize calls to the generic unify/2 and compare/3 predicates
	to type-specific __Unify__ and __Compare__ predicates, if the latter
	do not exist.

	Previously, we were not specializing comparisons of builtins and
	enumerations here, leaving it to inlining. In the absence of
	--special-preds, that doesn't work for enumerations, since there
	is no compiler-generated comparison predicate to do the inlining in.
	We therefore now perform both specializations.

compiler/polymorphism.m:
	Fix a bug: the code for looking up the special preds for user defined
	types was handling enums as builtins, which they are not: they can have
	user-defined equality.

compiler/type_ctor_info.m:
	Even with --no-special-preds, the type has type-specific __Unify_
	and __Compare__ predicates if it has user-defined equality. These
	predicates must be, and now are, put into the type_ctor_info.

runtime/mercury_wrapper.[ch]:
	Expand the facilities for collecting statistics about unify, index
	and compare operations. We used to collect only counts of operations
	for each type_ctor_rep; we now also collect counts of operations
	for each specific type. Rename MR_CTOR_REP_STATS as MR_TYPE_CTOR_STATS
	to reflect this expansion.

runtime/mercury_conf_param.h:
	Document MR_TYPE_CTOR_STATS instead of MR_CTOR_REP_STATS.

runtime/mercury_ho_call.c:
runtime/mercury_unify_compare_body.h:
	Fix a bug that showed with --no-special-preds: the Mercury predicate
	unify_2_0 cannot call the MR_generic_compare function to handle the
	arguments of a function symbol, because comparison is not defined
	on types with user-defined equality. Instead, we need to call the new
	MR_generic_unify C function, which does work on such types.

	Fix a bug that showed with --no-special-preds: the MR_succip register
	has to be saved and restored across calls to MR_generic_unify, since
	for types with user-defined equality, such calls involve a recursive
	invocation of the Mercury engine.

	Optimize the unification of du types by performing only one
	functor_desc lookup instead of two, and failing as early as possible.

	Use the new statistics facilities provided by mercury_wrapper.c.

tools/bootcheck
	If the new --type-stats option is given, preserve the type constructor
	statistics derived from (a) the stage 3 compilation process, and (b)
	compiling the test suite, for later analysis.

tools/type_ctor_stats:
	A new shell script to analyze type constructor statistics in their
	new, expanded format.

tests/hard_coded/user_defined_equality.{m,exp}:
	Test comparisons as well as unifications on enums with user-defined
	equality.
2000-04-05 06:29:12 +00:00
Zoltan Somogyi
c2a696d8b6 Clean up the runtime system's handling of type_infos and pseudo_type_infos.
Estimated hours taken: 40

Clean up the runtime system's handling of type_infos and pseudo_type_infos.
This cleanup has two major aspects. First, it represents type_infos and
pseudo_type_infos with distinct C types, and reducing the use of casts
to the minimum. These casts are in two kinds of places: in a few macros
defined in runtime/mercury_type_info.h, and at the interfaces between C code
and Mercury code (since Mercury code represents (pseudo-)type_infos, like
everything else, as Words). Part of this aspect is the separation of the
type "MR_TypeInfo" from the type "MR_TypeInfoParams"; a MR_TypeInfo can be
used as a source of type parameters directly only when it is first order.
Second, it removes the confusion between the types named "type_info" and
"type_ctor_info" defined by the modules private_builtin.m and std_util.m,
by renaming the types defined in std_util.m to "type_desc" and
"type_ctor_desc".

To avoid doing this cleanup twice, this diff also removes support for the
old type_ctor_info representation. This in turn makes it feasible to provide
conditionally enabled code to support unification and comparison by RTTI.

runtime/mercury_grade.h:
	Increment the binary compatibility version number. This is required
	by the dropping of support for old type_ctor_info representations.

runtime/mercury_type_info.h:
	Define the types MR_TypeInfo, MR_PseudoTypeInfo and MR_TypeInfoParams,
	and macros that operate on them.

	Remove the types and macros that were useful only with the old RTTI
	representation.

	Move the section that deals with initializing code addresses in
	type_ctor_info structure for grades without static code addresses
	to the logical place.

	Add a const qualifier to the MR_sectag_alternatives field in
	MR_DuPtagLayout, since this simplifies code manipulating du types.

	Convert the whole file to 4 space indentation, since it is a nuisance
	if only part of it is so indented.

runtime/mercury_deep_copy.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling.c:
	Clean up the implementation as described above.

runtime/mercury_type_info.c:
runtime/mercury_make_type_info_body.h:
	Clean up the implementation as described above.

	Eliminate the code duplication between the function MR_make_type_info
	and MR_create_type_info, and their helpers, which do the same thing
	except for how they allocate memory, by putting the common code into
	the new file mercury_make_type_info_body.h, and including it twice
	in two different #define contexts.

	Move the (updated) documentation of those functions to
	mercury_type_info.h, where it belongs.

runtime/mercury_ho_call.c:
runtime/mercury_unify_compare_body.h:
	Clean up the implementation as described above.

	Eliminate the code duplication between the implementation of unify
	and compare, which do very similar jobs, by putting the common code
	into the new file mercury_unify_compare_body.h, and including it three
	times in two different #define contexts. The third time is for defining
	the body of a C function which does the same thing as compare. This
	is necessary for unification and comparison by RTTI, since the
	unification or comparison of two structured terms requires comparing
	their subterms. (There is no need for a separate C function for
	unification; the C comparison function is sufficient.)

	mercury_unify_compare_body.h has conditional support for unification
	and comparison by RTTI. Although this has been tested and is known
	to work, it is turned off for the moment. This may change after
	benchmarking.

runtime/Mmakefile:
	Add the new include files to the list.

library/std_util.m:
	Rename type_info to type_desc and type_ctor_info to type_info_desc.
	Keep the old names as equivalence types, for the time being.
	Document the representations.

	Move the macros that refer to type_descs and type_ctor_descs here from
	runtime/mercury_type_info.h, since this is the only place where they
	are used. Rename them to conform to the new names of the types.

	Clean up the implementation of the RTTI predicates and functions
	as described above. In the process, fix some bugs where type variables
	were expanded twice, with the second expansion's code being incorrect.
	Also factor out some common code, and unfactor some uncommon code
	(where a function had two uses, but its implementation was inefficient
	overkill for one of them).

library/builtin.m:
library/private_builtin.m:
library/io.m:
library/store.m:
runtime/mercury_layout_util.[ch]:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.[ch]:
	When calling C functions involving type_infos, cast them to the new
	types.

runtime/mercury_stack_layout.h:
	Fix a bug that was masked by casts in its client code.

compiler/rtti_out.m:
	Delete from the output a cast made unnecessary by the new const
	qualifier on MR_sectag_alternatives.

browser/browse.m:
browser/help.m:
library/io.m:
library/term.m:
tests/hard_coded/construct.m;
tests/hard_coded/existential_types_test.m:
tests/hard_coded/higher_order_type_manip.{m,exp}:
	Refer to the types defined in std_util.m by their new names.

tests/hard_coded/existential_rtti.{m,exp}:
	Make the test tougher by printing out not just one deconstructed term,
	but deconstructed versions of all the terms created by this test.
2000-03-24 10:28:07 +00:00
David Jeffery
6434c9a02e Include the number of typeclass methods in the base_typeclass_info
Estimated hours taken: 0.25

Include the number of typeclass methods in the base_typeclass_info
structure, making the structure self-describing. This information
is not used at the moment, but may be useful.

compiler/base_typeclass_info.m:
        Add the new information.
compiler/polymorphism.m:
        Update the documentation.
runtime/mercury_type_info.h:
        Update and add macros for the new structure.
2000-01-17 03:39:29 +00:00