Commit Graph

238 Commits

Author SHA1 Message Date
Zoltan Somogyi
1790c3b505 When generating calls, specify whether the call is to a predicate or
Estimated hours taken: 1
Branches: main

compiler/goal_util.m:
compiler/hlds_module.m:
	When generating calls, specify whether the call is to a predicate or
	function.

compiler/goal_util.m:
compiler/unify_proc.m:
	Move a predicate that generates unsafe casts from unify_proc to
	goal_util, since polymorphism may also want to use it someday.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/aditi_builtin_ops.m:
compiler/deep_profiling.m:
compiler/det_analysis.m:
compiler/higher_order.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/table_gen.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
	Trivial diffs to conform to the changes above.
2003-05-29 18:17:16 +00:00
Zoltan Somogyi
599ef915d9 Instead of being relied on all over the place, centralize the compiler's
Estimated hours taken: 16
Branches: main

Instead of being relied on all over the place, centralize the compiler's
knowledge of the names of unify, compare and index predicates in one place,
special_pred.m. This should make it easy to change the naming scheme once
we switch over to compiler-generated type_ctor_infos for builtin types,
which will eliminate the runtime system's knowledge of the naming scheme.

compiler/hlds_pred.m:
	Add a field to pred_infos that says whether the predicate is a unify,
	compare or index predicate, and if so, for which type constructor.
	Code that used to test the predicate's name for __Unify__ etc now
	tests this field instead. Similarly the code that used to employ
	devious tricks to find out the type the unify/compare/index predicate
	is for.

compiler/rtti.m:
	Include this field in rtti_proc_labels as well as pred_infos.

compiler/make_hlds.m:
	Fill in this field as appropriate.

compiler/proc_label.m:
	Replace the predicate name with special_pred_id in the proc_labels
	of unify, index and compare preds.

compiler/special_pred.m:
	Narrow the interface to prevent reliance on the naming scheme
	for compiler-generated unify, compare and index predicates,
	except when absolutely necessary, i.e. when creating names for
	them.

	Narrow the mechanism required to reverse-engineer the type constructor
	a unify/compare/index predicate is for from the types to the
	functionality required by higher_order.m.

compiler/code_gen.m:
compiler/det_report.m:
compiler/higher_order.m:
compiler/intermod.m:
compiler/layout_out.m:
compiler/magic_util.m:
compiler/ml_code_util.m:
compiler/name_mangle.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/optimize.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/proc_label.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/simplify.m:
compiler/termination.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unused_args.m:
	Update code and comments to conform to the changes above.

compiler/hlds_out.m:
	Don't refer to the 'type' that a unify, compare or index predicate
	is for; refer to the type *constructor*.

compiler/mlds_to_java.m:
	Delete an unused predicate.

tests/invalid/purity/purity.err_exp:
	Update this expected output for the change in hlds_out.m.
2003-05-27 05:57:30 +00:00
Zoltan Somogyi
6554ef7daa Replace "is" with "=".
Estimated hours taken: 2
Branches: main

Replace "is" with "=".
Add field names where relevant.
Replace integers with counters where relevant.
2003-05-26 09:01:46 +00:00
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

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

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

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

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

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

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

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

	Add predicates `construct_tuple' and `deconstruct_tuple'.

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

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

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

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

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

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

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

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

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

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

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

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

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

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Simon Taylor
129f605d25 Fix bugs in the handling of purity in the optimization passes
Estimated hours taken: 8
Branches: main, release

Fix bugs in the handling of purity in the optimization passes
(in particular constraint propagation), which caused purity
annotations on goals to be lost. This caused
tests/tabling/unused_args to fail on earth.

compiler/hlds_goal.m:
	Make the version of goal_info_init called from
	the optimization passes take the purity as an
	argument. Previously, callers were constructing
	a goal_info then adding the purity, which was
	error prone.

compiler/hlds_goal.m:
compiler/purity.m:
	Move the predicates to deal with purity representation
	in hlds_goal_infos into hlds_goal.m. Rationale -
	goal_info_get_determinism is not in det_analysis.m,
	goal_info_get_nonlocals is not in quantification.m, etc.
	This makes it easier to make the purity setting code
	efficient.

	Don't allocate memory in add_goal_info_purity_feature
	if the call doesn't change the purity.

compiler/*.m:
	Pass the extra argument to goal_info_init.

compiler/polymorphism.m:
	Remove a duplicate definition of
	hlds_goal__make_int_const_construction.

compiler/magic.m:
	Remove some unused code.

tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/Mercury.options:
tests/hard_coded/purity/purity_opt.{m,exp}:
	Test case.
2003-02-28 00:21:42 +00:00
Simon Taylor
660a24a7ad Fix a bug reported by Michael Day which caused spurious
Estimated hours taken: 8
Branches: main, release

Fix a bug reported by Michael Day which caused spurious
"predicate multiply defined" errors if there were predicates
`module1.p' and `module2.module1.p'.

compiler/hlds_module.m:
	For each of the predicate table search predicates which
	takes a module, add an extra argument which states whether
	the module name passed in is fully qualified. If it is, then
	a search for `module1.p' will not return `module2.module1.p'.
	The module name is guaranteed to be fully qualified for
	the head of predicate, clause, etc. items, and for calls
	occurring in `.opt' files.

	Add a predicate `lookup_builtin_pred_proc_id', for
	looking up the builtin predicates in the predicate table.

compiler/goal_util.m:
	Move code to look up builtin predicates into hlds_module.m.

	Set the builtin_state field of the call goal returned
	by generate_simple_call correctly.

compiler/hlds_pred.m:
	Add a function `calls_are_fully_qualified' which takes
	an import_status, and returns whether calls from goals
	with that status are always fully qualified, which is
	true iff the call is in a `.opt' file.

compiler/prog_io.m:
	Module qualify the sym_names in `:- external' items.

compiler/*.m:
	Fill in the extra argument of predicate table searches.

	Use `lookup_builtin_pred_proc_id' rather than
	`predicate_table_search_*'.

compiler/prog_util.m:
	Add function versions of mercury_*_builtin_module.

compiler/polymorphism.m:
compiler/simplify.m:
compiler/unify_proc.m:
	Use goal_util__generate_simple_call to call builtins,
	rather than duplicating the code.

tests/valid/Mmakefile:
tests/valid/nested_module_bug.m:
tests/valid/intermod_bug_nested.m:
	Test cases.
2003-02-22 13:18:34 +00:00
Fergus Henderson
4ac56ddf67 Fix a bug where the stub code generated with `--allow-stubs'
Estimated hours taken: 0.5
Branches: main

Fix a bug where the stub code generated with `--allow-stubs'
was violating an invariant that polymorphism pass was relying on.

compiler/polymorphism.m:
	Allow unifications whose kind (construction, deconstruction,
	simple_test, etc.) has already been determined.
2003-02-22 08:15:55 +00:00
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