Commit Graph

163 Commits

Author SHA1 Message Date
Fergus Henderson
b461464647 Delete an obsolete comment.
Estimated hours taken: 0.1.

prog_io.m:
	Delete an obsolete comment.
1997-09-15 18:04:16 +00:00
Andrew Bromage
3d920e328f Fix of some documentation rot: We _do_ know how to do a
Estimated hours taken: 5 mins

modes.m:
	Fix of some documentation rot: We _do_ know how to do a
	deep copy.  We just don't know how to do a partially
	instatiated deep copy.

hlds_module.m:
make_hlds.m:
mercury_to_mercury.m:
prog_io.m:
type_util.m:
typecheck.m:
	Remove some when declarations, since the NU-Prolog version
	of the compiler isn't supported any more.
1997-09-01 04:19:10 +00:00
Fergus Henderson
99184d3578 Implement support for types with user-defined equality predicates.
Estimated hours taken: 30

Implement support for types with user-defined equality predicates.

Types with user-defined equality predicates are called "non-canonical types";
they may have more than one representation for the same abstract value.
That means that any attempt to deconstruct a value of a non-canonical
type, i.e. any attempt to peek at the representation, must be cc_multi.

This also implies that conceptually speaking, non-canonical types are not
members of the type classes `comparable' (compare/3) or `deconstructible'
(index/2, argument/3, functor/3, deconstruct/5).  Since we don't support
type classes yet, that just means that the type-class checking is done
at runtime, i.e. any call to one of those functions for a non-canonical
type will call error/1 or fatal_error().

To make non-canonical types useful, we really need type classes,
so that the user can provide instance definitions for `comparable'
and `deconstructible' for such types.  It might also be a good idea
to have a type-class `canonicalizable' which provides a function
to convert its argument to some canonical type (that would
require existential types to do nicely, but alternatively we could
just use `univ').

Note that currently the only mechanism for promising that things are
unique is via the C interface.

compiler/det_analysis.m:
	Add code to check unifications that examine the
	representation of a type with a user-defined equality predicate.
	Any such unification must occur in a single-solution context and
	must not be able to fail.  Such unifications determinism have
	determinism cc_multi.

compiler/det_report.m:
	Add code to report errors for misuse of types with user-defined
	equality predicates.  (Also some other stylistic improvements:
	split up a complicated predicate into subroutines, and
	avoid some unnecessary code duplication.)

compiler/prog_data.m:
compiler/hlds_data.m:
	Add a new `maybe(sym_name)' field to the du_type/3 constructor
	to hold the name of the user-defined equality pred for the
	type, if any.

compiler/prog_io.m:
	Add code to parse the new `... where equality is <name>.' syntax.
	Delete the old support for `... where <condition>'.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/mercury_to_goedel.m:
	Print out the new field.

compiler/base_type_layout.m:
compiler/code_util.m:
compiler/dense_switch.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/make_hlds.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/switch_detection.m:
compiler/tag_switch.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Trivial changes to ignore (or leave unchanged)
	the new field in `du_type'.

compiler/modecheck_unify.m:
	Pass the term__context to unify_proc__request_unify.

compiler/typecheck.m:
	Typecheck the compiler-generated unify predicates for types
	with user-defined equality preds.

compiler/unify_proc.m:
	For d.u. types, if the type has a user-defined equality predicate
	then generate code for the compiler-generated unify predicate
	that just calls the specified predicate, and generate
	code for the compiler-generated compare and index predicates
	that just calls some procedures in mercury_builtin.m that
	report appropriate error messages.
	Ensure that the automatically-generated predicates
	have appropriate term__contexts everywhere, so that if
	the user-defined equality predicate name is ambiguous,
	non-existent, or has the wrong type, mode, or determinism,
	then the error messages from type checking, mode checking,
	or determinism checking refer to the type declaration.

library/mercury_builtin.m:
	Add predicates builtin_index_non_canonical_type/2
	and builtin_compare_non_canonical_type/2, used by
	the code generated by compiler/unify_proc.m.

doc/reference_manual.texi:
	Document the support for user-defined equality predicates.

library/std_util.m:
	Change ML_expand() to return an indication of whether or not
	the type is a non-canonical type (one with a user-defined
	equality predicate).  Change argument/2, functor/2, and
	deconstruct/4 to abort if called for a non-canonical type.
1997-08-22 13:57:43 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Andrew Bromage
9b7f11c6dd Reorganisation of modules to do with the inst data type.
Estimated hours taken: 20

Reorganisation of modules to do with the inst data type.

This is actually the first installment of the alias tracking mode
checker in disguise.  A very good disguise.  The rationale for
this reorganisation is to reduce coupling in the part of the mode
checker which is _not_ in this change (ie most of it).

Alias tracking requires a new kind of inst, alias(inst_key), where
an inst_key is a handle on some other sub-inst.  With it goes a
data structure in which to store dereferenced insts and all the
operations which go with it.  This code will go in the new module
inst.m so that it doesn't have to go in prog_data.m.  (I briefly
considered putting it in instmap.m however this introduces some
bad coupling since instmap.m imports hlds_module.m.  Putting it
in prog_data.m would cause hlds_*.m to depend on prog_data.m,
but we have designed things so that the dependencies go in the
other direction.)

The remainder of the reorganisation is a general cleanup: the
inst testing predicates (inst_is_*) have been moved out of
mode_util because they are not actually operations on modes at
all, and have been moved into inst_match.  inst_match has then
been split because otherwise it would be 2000 lines long and
will get significantly bigger when aliasing is added.  Roughly
speaking, any operations which create new insts from old ones
have been moved into a new module, inst_util while any operations
which test the values of insts remain in inst_match.

Also included are the removal of some NU-Prologisms since the
NU-Prolog version of the compiler is no longer supported.  Two
changes here:

	- Removal of some when declarations.
	- A gross hack in inst_is_*_2, where two copies of
	  the same inst were passed into the predicate so that
	  one could be switched on.  Thank NU-Prolog's lack of
	  common subexpression elimination.

compiler/inst.m:
	New module which contains the data types inst, uniqueness,
	pred_inst_info, bound_inst.

compiler/inst_util.m:
	New module which contains predicates which perform mode
	checking-like operations on insts.

	Moved in:
		abstractly_unify_inst, abstractly_unify_inst_functor,
		inst_merge, make_mostly_uniq_inst (from inst_match.m)

compiler/inst_match.m:
	Moved out:
		inst_merge, make_mostly_uniq_inst,
		abstractly_unify_inst, abstractly_unify_inst_functor
			(to inst_util.m)

	Moved in:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(from mode_util.m)

	Now exported:
		unique_matches_initial/2, unique_matches_final/2
		inst_contains_instname/3, pred_inst_matches/3
		(They are required by inst_util.m, and they are
		useful in their own right.)

compiler/instmap.m:
	instmap_delta_lookup_var/3 reincarnated as
	instmap_delta_search_var/3.  The reason for this change is
	that previously, instmap_delta_lookup_var simply returned
	`free' if the searched-for var did not occur in the
	instmap_delta.  This is somewhat non-obvious behaviour.
	instmap_delta_search_var/3 fails in such a situation.

compiler/mode_util.m:
	Moved out:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(to inst_match.m)
		(These are not really operations on modes.)

compiler/modecheck_call.m:
	Moved in modecheck_higher_order_func_call/5, from modecheck_unify.m

compiler/modecheck_unify.m:
	Moved out modecheck_higher_order_func_call/5, to modecheck_call.m
	where it should have been all along.

compiler/prog_data.m:
	Moved out the types inst, uniqueness, pred_inst_info,
	bound_inst (to inst.m).

compiler/common.m:
compiler/cse_detection.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/liveness.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
	Miscellaneous minor changes to cope with the above changes.

compiler/notes/compiler_design.html:
	Document the new modules.
1997-07-24 01:27:21 +00:00
Fergus Henderson
9b5428d0f5 Fix some bugs where the compiler was silently ignoring certain errors.
Estimated hours taken: 1.5

Fix some bugs where the compiler was silently ignoring certain errors.

compiler/prog_io.m:
	Check for some possible errors in function declarations that
	were previously being silently ignored.  Specifically, we
	now catch cases where a function type declaration includes
	modes for some but not all of its arguments or return value,
	or where it includes a determinism but no modes.

tests/invalid/Mmake:
tests/invalid/func_errors.m:
tests/invalid/func_errors.err_exp:
	Test case for the above change.
1997-07-23 21:03:13 +00:00
Fergus Henderson
3abef80dc1 Trivial aesthetic change: when calling parse_qualified_term,
Estimated hours taken: 0.25

compiler/prog_io.m:
compiler/prog_io_util.m:
	Trivial aesthetic change: when calling parse_qualified_term,
	pass a reasonable human-readable string for the context, even
	in cases where the context won't be used.
1997-07-08 05:49:46 +00:00
Simon Taylor
27d156bbb5 Implemented a :- use_module directive. This is the same as
Estimated hours taken: 14

Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.

:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.

Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.

compiler/module_qual.m
	Keep two sets of type, mode and inst ids, those which can
	be used without qualifiers and those which can't.

	Renamed some predicates which no longer have unique names since
	'__' became a synonym for ':'.

	Made mq_info_set_module_used check whether the current item is in
	the interface, rather than relying on its caller to do the check.

	Removed init_mq_info_module, since make_hlds.m now uses the
	mq_info built during the module qualification pass.

compiler/prog_data.m
	Added a pseudo-declaration `used', same as `imported' except uses of
	the following items must be module qualified.

	Added a type need_qualifier to describe whether uses of an item
	need to be module qualified.

compiler/make_hlds.m
	Keep with the import_status whether current item was imported
	using a :- use_module directive.

	Use the mq_info structure passed in instead of building a new one.

	Ensure unqualified versions of constructors only get added to the
	cons_table if they can be used without qualification.

compiler/hlds_module.m
	Added an extra argument to predicate_table_insert of type
	need_qualifier.

	Only add predicates to the name and name-arity indices if they
	can be used without qualifiers.

	Changed the structure of the module-name-arity index, so that
	lookups can be made without an arity, such as when type-checking
	module qualified higher-order predicate constants. This does not
	change the interface to the module_name_arity index.

	Factored out some common code in predicate_table_insert which
	applies to both predicates and functions.

compiler/hlds_pred.m
	Removed the opt_decl import_status. It isn't needed any more
	since all uses of items declared in .opt files must now be
	module qualified.

	Added some documentation about when the clauses_info is valid.

compiler/intermod.m
	Ensure that predicate and function calls in the `.opt' file are
	module qualified. Use use_module instead of import_module in
	`.opt' files.

compiler/modules.m
	Handle use_module directives.

	Report a warning if both use_module and import_module declarations
	exist for the same module.

compiler/mercury_compile.m
	Collect inter-module optimization information before module
	qualification, since it can't cause conflicts any more. This means
	that the mq_info structure built in module_qual.m can be reused in
	make_hlds.m, instead of building a new one.

compiler/prog_out.m
	Add a predicate prog_out__write_module_list, which was moved
	here from module_qual.m.

compiler/typecheck.m
	Removed code to check that predicates declared in `.opt' files
	were being used appropriately, since this is now handled by
	use_module.

compiler/*.m
	Added missing imports, mostly for prog_data and term.

NEWS
compiler/notes/todo.html
doc/reference_manual.texi
	Document `:- use_module'.

tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
	Test cases.
1997-06-29 23:11:42 +00:00
Tyson Dowd
cbcb23d17b Enable --warn-interface-imports by default.
Estimated hours taken: 3

Enable --warn-interface-imports by default. This was turned off while
list and term were defined in mercury_builtin.m, since it caused many
warnings.

Fix all the unused interface imports that have been added since then.

compiler/options.m:
	Enable --warn-interface-imports by default.

compiler/module_qual.m:
	Fix formatting inconsistencies with module names in warning
	messages. (".m" was not appended to module names if there was
	only one module).

compiler/*.m:
library/*.m:
tests/invalid/type_loop.m:
tests/warnings/*.m:
	Remove usused interface imports, or move them into
	implementation (mostly bool, list and std_util).
1997-05-21 02:16:53 +00:00
Fergus Henderson
3ec8a17ffc Enable the code to treat `__' as an alternative syntax for module
Estimated hours taken: 8

Enable the code to treat `__' as an alternative syntax for module
qualification, after fixing various places in the compiler where
we use `__' in ways that are incompatible with this.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Uncomment the code to handle `__' as module qualification.

compiler/intermod.m:
compiler/hlds_module.m:
compiler/modecheck_unify.m:
	Fix bugs in the handling of module qualified higher-order terms.

compiler/*.m:
	s/hlds__/hlds_/g

compiler/passes_aux.m:
	s/process__/process_/g

compiler/pragma_c_gen.m:
compiler/code_gen.m:
	s/code_gen__/pragma_c_gen__/ for the predicates defined in
	pragma_c_gen.m (this ought to have been done when the code
	was first moved from code_gen.m to pragma_c_gen.m).

compiler/llds.m:
	s/llds__proc_id/llds_proc_id/g
	The reason for this was to avoid ambiguity between proc_id
	in hlds_pred.m and llds__proc_id in llds.m.

compiler/quantification.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
	s/goal_vars/quantification__goal_vars/g
	The reason for this was to avoid ambiguity between goal_vars
	in quantification.m and goal_util__goal_vars in goal_util.m.

compiler/dupelim.m:
compiler/optimize.m:
	s/dupelim__main/dupelim_main/g
	The reason for this change is that a program can only
	have one main/2 predicate.

compiler/prog_io_dcg.m:
	Remove the old "temporary hack" to strip off and ignore
	io__gc_call/1, since the new handling of `__' broke it.
	It was only useful for optimizing NU-Prolog performance,
	which we don't care about anymore.

compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
compiler/prog_io.m:
	Remove occurrences of io__gc_call.

compiler/llds_out.m:
compiler/base_type_info.m:
	Ensure that we properly handle the special hacks in mercury_builtin
	where predicates from other modules (e.g. term__context_init)
	are defined in mercury_builtin because they are needed for
	type_to_term and term_to_type.  llds_out.m: don't put
	`mercury_builtin' in the mangled names for those symbols.
	base_type_info.m: handle types whose status is "imported"
	in their own module.
1997-02-23 06:08:34 +00:00
Fergus Henderson
f12d206b57 Add code to treat `__' as an alternative syntax for module
Estimated hours taken: 4

Add code to treat `__' as an alternative syntax for module
qualification.  The code is currently commented out, because at the
time this change was made, we don't yet support module qualification of
data constructors.  Now that we do, it should be re-enabled as soon as
it has been tested.

Also avoid some code duplication.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Add (commented out) code to handle `__'.

compiler/prog_io_dcg.m:
compiler/type_util.m:
	Avoid code duplication: use sym_name_and_args from prog_io_goal.m
	for parsing possibly qualified terms.
1997-02-22 08:26:42 +00:00
Simon Taylor
1839ebb663 Module qualification of constructors.
Estimated hours taken: 15

Module qualification of constructors.

compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/modecheck_call.m
	Enable propagate_type_info_into_modes.
	Use type information to module qualify cons_ids.

compiler/mode_util.m
	Use propagate_type_information_into_modes to module qualify cons_ids
	in bound insts.
	typed_ground/2 and free/1 insts are not yet generated, since they
	are not yet used anywhere.
	Avoid expanding insts when propagating type information, since
	that is not yet useful.
	I still need to fix the handling of
		inst_matches_{initial, final, binding}(
			ground(_, _), bound(_, [all_functors_in_the_type]))

compiler/typecheck.m
	Don't assume a module qualified cons_id is a function call
	or higher-order pred constant.

compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/instmap.m
compiler/inst_match.m
	Remove some unnecessary conversion between cons_ids and consts.

compiler/typecheck.m
compiler/mode_errors.m
	Strip builtin qualifiers from cons_ids.

compiler/mercury_to_mercury.m
	Output module qualified cons_ids.

compiler/prog_io.m
compiler/prog_io_util.m
	Module qualify constructors in type definitions.
	Parse qualified cons_ids in bound insts.

compiler/hlds_data.m
	Remove cons_id_to_const/3, since it doesn't make much sense any more.
	Add cons_id_arity/2 and cons_id_and_args_to_term/3.

compiler/make_hlds.m
	Add both qualified and unqualified versions of each cons_id to
	the cons_table.

compiler/det_util.m
	Handle module qualified cons_ids in det_util__interpret_unify.

compiler/code_util.m
	Remove some dead code in code_util__cons_id_to_tag to do with
	tags for higher-order terms. Don't assume module qualified
	cons_ids are higher-order pred constants.

compiler/polymorphism.m
	Module qualify type_info cons_ids.
1997-02-17 01:27:10 +00:00
Zoltan Somogyi
91c4330db7 The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12

The first half of a change to introduce nondet pragma C goals.
This half makes the necessary modifications to the HLDS; the next
half will modify the LLDS and emit it.

prog_data:
	Add a new pragma type for nondet pragma c_codes; these specify
	the names of a a bunch of variables to save across backtracking,
	and a list of label names to which backtracking may take place.

	Rename is_recursive to may_call_mercury, since this is a more
	direct expression of the meaning.

prog_io:
	Move much of the functionality to new files.

prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util:
	New files, made up of pieces of prog_io.

hlds_goal:
	Add an extra argument to the pragma_c_goals to store the extra
	information present in the new type of pragma c_codes.

det_analysis:
	Take into account that the new type of pragma_c goal may have
	more than one solution.

goal_util:
	Rename variables in the new field of pragma_cs.

live_vars:
	Allocate stack slots to the saved variables in the new type of pragma_c
	goals.

make_hlds:
	Handle the new type of pragma_c goals.

mercury_output, hlds_out:
	Output the new type of pragma_c goals.

garbage_out:
	Rename type "det" to "frame_type".

others:
	Ignore one more arg of pragma_c goals or import prog_io_util.
1997-01-27 07:45:40 +00:00
Simon Taylor
bb2b816787 * Inter-module unused argument removal.
Estimated hours taken: 100

* Inter-module unused argument removal.

* Allow the user to specify which directories should be searched
for .opt files.

* Enhancements to simplify.m and common.m which will be useful for
partial deduction.

compiler/options.m
	Added and documented options:
	--intermod-unused-args to enable inter-module unused argument removal.
	--intermod-directory <dir>, same as --search-directory except used
		to locate .opt files.
	--use-search-directories-for-intermod - use the search directories
		for .opt files as well.
	--warn-simple-code - a flag to control the warnings produced by
		simplify.m so that they respect --inhibit-warnings.

compiler/unused_args.m
	Use the unused argument info from the .opt file.
	Clobber the dependency_info if any new preds were added.

compiler/hlds_module.m
	Added a field to the module_info to store unused argument
	information from .opt files.

compiler/prog_data.m
	Add :- pragma unused_args to hold unused argument information.
	This should only be used in .opt files.

compiler/make_hlds.m
	Build the unused_arg_info field in the module_info.
	Check that pragma unused_args only appears in .opt files.
	Fill in the non-locals field in the goal_info for the builtin
	stubs so that mode analysis computes the correct instmap delta.

compiler/intermod.m
	Read in the unused argument information for the current module when
	compiling to C. This is used to ensure that clauses are produced with
	the correct number of removed arguments (it may be possible to remove
	more arguments with the information from other modules).
	Fix a bug in the handling of module qualified function calls and
	higher-order predicate constants.

compiler/handle_options.m
	Handle --intermod-unused-args and
	--use-search-directories-for-intermod.

compiler/mercury_compile.m
	Run the entire front end and polymorphism (not just up to
	typechecking) when building the .opt file with
	--intermod-unused-args.
	Use the new interface to simplify.m, remove calls to excess.m
	and common.m.

compiler/code_util.m
compiler/llds_out.m
	When generating local code for a specialized version of a predicate
	from another module, put this module's name on the label to avoid
	link errors.

compiler/higher_order.m
	Don't add the originating module name to the name of the specialized
	version, since that is now done in code_util.m.
	Clobber the dependency graph so that inlining will work on the
	specialized versions in profiling grades (this will cause slightly
	slower compilation in profiling grades, something I need to fix).

compiler/simplify.m
	Merge a branching goal and an adjacent switch where the branches
	of the first goal contain extra information about the switched
	on variable of the second goal.
	Merge the excess assignments and common subexpression elimination
	passes into simplify.m.

compiler/excess.m
	The functionality of this module is now in simplify.m, but I'll
	leave it here for now.

compiler/instmap.m
	Added predicates instmap__bind_var_to_functor and
	instmap_delta_bind_var_functor to which take a var, cons_id
	and an instmap and adjust the inst of the var. This is used to
	update the instmap at the beginning of each case in a switch.
	Fix a bug in merge_instmap_delta where variables whose inst had
	information added in one branch of a switch, disj, or ite had that
	changed inst included in the instmap_delta for the entire
	branched goal.

compiler/mode_util.m
	Use instmap_delta_bind_var_to_functor in recompute_instmap_delta.
	Added predicate bind_inst_to_functor which takes a ground or bound
	inst and a cons_id and adjusts the top level of the inst to be bound
	to that cons_id. Other types of inst are left unchanged.
	Change recompute_instmap_delta so that the switched on variable of
	a switch is bound to the functor in each case even if the binding
	unification has been removed. Added a boolean argument to request
	recomputation of instmap_deltas for atomic goals.

compiler/modes.m
compiler/unique_modes.m
	Make sure that the instmap_delta for each branch of a switch
	includes the extra information added by the functor test.

compiler/common.m
	Removed the goal traversal. Leave preds to be called by simplify.m
	to optimise common unifications and calls.
	Warn about and eliminate multiple calls to a predicate with the same
	input arguments.
	Replace deconstructions of known terms with assignments to the output
	variables where this would not make more variables live at stack
	flushes.

compiler/follow_code.m
	Exported move_follow_code_select.
	Don't move follow code into erroneous branches.

library/string.nu.nl
	Added string__contains_char/2.

compiler/base_type_layout.m
compiler/special_pred.m
compiler/vn_order.m
library/mercury_builtin.m
	Removed duplicate calls.

doc/user_guide.texi
	Documented options.

tests/warnings/duplicate_call.m
tests/warnings/duplicate_call.exp
	Test duplicate call warning.
1997-01-20 03:27:59 +00:00
Fergus Henderson
d0e054223a Allow `pragma export' for semidet predicates and for det/semidet functions.
Estimated hours taken: 4

Allow `pragma export' for semidet predicates and for det/semidet functions.
(Previously it only worked for det predicates.)

prog_data.m:
	Add a pred_or_func field to the pragma_export struct.

prog_io.m:
	Add code to parse `pragma export' declarations for functions,
	e.g. `pragma export(foo(in) = out, "foo")'.

mercury_to_mercury.m:
	Add code to print out `pragma export' declarations for functions.

module_qual.m:
	Change export/3 to export/4.

export.m:
	Handle semidet procedures -- the C function returns TRUE/FALSE
	depending on whether the Mercury procedure succeeded or failed.

	Handle functions -- for det functions whose return value has
	mode `out', the Mercury function return value is returned as the C
	function return value.

	Don't call save_registers() after returning from call_engine(),
	since call_engine() now saves them itself.

	When generating header files, don't make up argument names
	for the function prototypes, instead just leave the arguments
	unnamed.  Also, make sure the `#ifndef HEADER_NAME_H' comes
	at the very start of the file, before #include "imp.h".
1996-12-20 17:34:22 +00:00
David Overton
37c5340f1c Added code to various sections of the compiler to parse
Estimated hours taken: 80

Added code to various sections of the compiler to parse
`pragma fact_table' declarations and add them to the HLDS.

Added output of fact_table dependencies to .d and .dep files.

Added a new module fact_table.m for parsing the actual fact tables and
generating code.  This is not finished yet.

Added ability to have `pragma c_code' declarations for Mercury
functions.

Modified Files:
   compiler/hlds_module.m
	Added predicate `module_info_set_pred_info' to add a `pred_info'
	entry to `module_info' given a `pred_id'.

   compiler/make_hlds.m
	Added code to handle new `pragma fact_table' declarations.
	New predicate `module_add_pragma_fact_table' which calls the
	fact compiler in fact_table.m to compile the fact table and
	generate C code to access it.  Then add the C code to the HLDS
	as a `pragma c_code'.

	Mercury functions can now have `pragma c_code' declarations.

   compiler/intermod.m
   	Included PredOrFunc argument in call to mercury_output_pragma_c_code.

   compiler/mercury_compile.m
	Added parameters to some predicates to allow fact table
	dependency information to be passed around.

   compiler/mercury_to_mercury.m
   	Handle output of `pragma fact_table' declarations.
	Handle output of `pragma c_code' declarations for functions.

   compiler/module_qual.m
   	Handle module qualification of `pragma fact_table'
	declarations.

   compiler/modules.m
   	New predicate `get_fact_table_dependencies' to work out which
	fact tables a module depends on.
	Changes to `write_dependency_file' to write out fact table
	dependencies.
	Changes to some other predicates to allow fact table
	dependencies to be passed around the module.

   compiler/prog_data.m
   	Added new functor `fact_table(sym_name, arity, string)'
	to the `pragma_type' type.
	Added a `pred_or_func' field to the `c_code' functor of the
	`pragma_type' type.

   compiler/prog_io.m
   	Added code to `parse_pragma_type' to parse `:- pragma fact_table'.
	Here is a sample declaration.  The facts are in a file called
	"factfile":

	:- pred facts(string, int, float).
	:- mode facts(out, out, out) is multidet.
	:- pragma fact_table(facts/3, "factfile").

	Mercury functions can now have `pragma c_code' declarations.
	Here is a sample declaration:

	:- func c_add(int, int) = int.
	:- pragma c_code(non_recursive, c_add(A::in, B::in) = (C::out), "
		C = A + B;
		").


Added Files:
   compiler/fact_table.m
   	Module not yet finished, but it compiles correctly and doesn't
	interfere with the rest of the compiler.

	Main purposes of the module are to parse the fact table
	file, perform type, mode and determinism checks and generate C
	code for the fact table.

	Completed so far:  parsing, type and mode checking,
	determinism inference.  A C array is output to represent the
	table, but no functions are produced yet to access it.
1996-12-17 23:40:31 +00:00
Fergus Henderson
4c3bbe13e2 Add some comments.
Estimated hours taken: 0.5

compiler/prog_io.m:
compiler/prog_data.m:
	Add some comments.
1996-12-14 20:27:25 +00:00
Fergus Henderson
fd6f3e028f Report an error for attempts to redefine builtin insts.
Estimated hours taken: 1

compiler/prog_io.m:
	Report an error for attempts to redefine builtin insts.

	This change is in response to a bug report by Steve Spagnolo.
	It will do for now.  In the long term, however, the ideal
	solution would be for builtin insts to be treated as being
	defined in module `mercury_builtin'; attempting to redefine
	a builtin inst should elicit at worst a warning, since if
	you refer to it in module qualified form things should
	work OK.
1996-12-12 14:49:08 +00:00
Zoltan Somogyi
5d64b759db The main changes are
Estimated hours taken: 12

The main changes are

1	associating a name with the arguments of constructors

2	removing the follow_vars field from calls, higher-order calls
	and complicated unifications, since they are not used

3	merging the follow_vars and store_alloc passes, since they logically
	belong together

4	add a new module, lco, for detecting opportunities for last
	call optimization modulo constructor application; it won't
	actually apply the optimization until the mode system becomes
	expressive enough to handle it (this module detects 529 opportunities
	in the compiler and library)

5	make "-O3 --optimize-value-number" do the right thing; previously,
	it used not to apply value numbering because the vnrepeat option
	defaulted to zero

6	don't refer to .err2 files anymore; use .err instead.

prog_data:
	The list associated with each value of type "constructor" now
	contains not only the types of the arguments but their names as well.

equiv_type, hlds_data, hlds_out, make_hlds, mercury_to_{goedel,mercury},
mode_util, module_qual, shapes, type_util, unify_proc:
	Modify the traversal of type definitions to account for the names
	in the lists inside values of type "constructor".

prog_io:
	Parse argument names. An unrelated change is that we now
	check whether :- pred declarations give modes to some of their
	arguments but not to all, in which case we return an error.

hlds_goal:
	Remove the follow_vars field from calls, higher-order calls
	and complicated unifications.

*.m:
	Handle the new arities of calls, higher order calls and complicated
	unifications.

mercury_compile:
	Don't call follow_vars directly anymore, but do call lco if its option
	is set. Also flush the main output before a call to maybe_report_stats
	to prevent ugly output.

store_alloc:
	Call follow_vars directly.

follow_vars:
	Expose the initialization and traversal predicates for store_alloc.

lco:
	Find opportunities for last call optimization modulo constructor
	application.

passes_aux:
	Add a HLDS traversal type for lco.

optimize:
	Consider the vnrepeat count to be zero unless value numbering is on.

options:
	Set the default value of vnrepeat to 1.

modules:
	Don't refer to .err2 files.
1996-11-04 06:26:51 +00:00
Fergus Henderson
d0f5aada77 Fix bugs in the parsing of variables as goals, e.g.
Estimated hours taken: 1

compiler/prog_io.m:
	Fix bugs in the parsing of variables as goals, e.g.
		p(X) :- X.	% same as p(X) :- call(X).
		q(X) --> X.	% same as p(X, A0, A) :- call(X, A0, A).
	It seems that Dylan managed to break the parsing of goals
	such as that during his changes to introduce module qualification.
1996-11-02 19:43:54 +00:00
Simon Taylor
9205a7e445 Module qualification of function calls and higher-order predicate constants.
Estimated hours taken: 6

Module qualification of function calls and higher-order predicate constants.

compiler/hlds_data.m
	Changed the cons(string, arity) constructor of cons_id to
	cons(sym_name, arity). A module qualified cons_id is assumed to
	be a function or higher-order pred constant, since we don't
	yet support module qualification of constructors (Explicit
	type qualification is much more useful anyway, but that doesn't
	work yet either).

compiler/hlds_goal.m
	Changed the functor(const, list(var)) constructor of unify_rhs
	to functor(cons_id, list(var)) to allow the storing of a module
	qualifier.

compiler/make_hlds.m
	Parse qualified function calls and higher-order pred constants.

compiler/modes.m
compiler/intermod.m
	Take module qualifiers into account when resolving function
	overloading.

compiler/*.m
	Updated unify_rhs's and cons_id's everywhere.
1996-10-02 06:08:07 +00:00
Simon Taylor
5d3fc10571 - Inter-module optimization.
Estimated hours taken: 50

- Inter-module optimization.
Allows inlining and higher-order specialization across module boundaries.
Gives ~10% speed-up on the compiler compiling to C.

- The code to handle explicit type qualification.
The test to recognise a type qualification is semidet_fail'ed
until we work out which operator to use.

- Improved data structures in module_qual.m.
Also, module qualification of the modes of lambda expressions is now
done in make_hlds.m, since it is more convenient now that type
qualifications are module qualified there also.

* Type qualification and module qualifiers on higher-order predicate
constants and function calls still need to be implemented before this
will work on all programs.

* To create a version of a program using this optimization method,
add --intermodule-optimization to MCFLAGS, mmake change_clean,
mmake depend, then make as normal.

* mmake change_clean removes the executable, the .dep file and all
.cs and .os.

compiler/intermod.m
	Handle input and output of .opt files.

compiler/modules.m
	Added some new dependencies in the .d files for
	the .c and .opt files if inter-module optimization
	is being used.
	Also added .opt and .optdate to the list of things for
	mmake realclean to remove.
	Added a target, change_clean, which removes only those files
	necessary to force a rebuild using --intermodule-optimization.
	These are <module>, <module>.dep and all the .c, .o and .s files.

compiler/options.m
	Added options:
		--make-optimization-interface - make the .opt file.
		--intermodule-optimization - puts extra dependencies
			into .d files and turns on input of .opt files.

compiler/make_hlds.m
	Changes to give items from .opt files the correct import_status.
	Also, when matching pragma_c_code clauses to the declared modes
	of the predicates, expand and match on the initial and final insts
	of the argument modes, not the modes themselves, since items in
	.opt files have the modes expanded.
	Module qualify the modes of lambda expressions in unravel_unification
	rather than during mode analysis.
	Parse explicit type qualifications, and add these to the vartypes.
	At the moment this is disabled.

compiler/typecheck.m
	Get the head type params from the tvarset, not from the arg types,
	so that tvars in type qualifications are included.
	Added checks to prevent matching of predicates, functions and
	constructors which should not be visible to a clause.

compiler/module_qual.m
	Module qualify explicit type qualifications.
	More efficient data structures.

compiler/mercury_to_mercury.m
	Export some predicates. Make sure C code strings are properly
	quoted in the .opt files.

compiler/hlds_out.m
	Output function calls correctly. Alter hlds_out__write_goal to write
	out type qualifications on all functors if writing a .opt file.

compiler/hlds_pred.m
	Added a new import_status opt_imported for clauses and declarations
	read from a .opt file. Pred and func declarations read from a .opt
	file get an `opt_decl' import_status so that the compiler doesn't
	expect clauses for them and local preds can't use them.
	Also added import_status abstract_imported and abstract_exported
	to describe types which have only an abstract definition imported
	or exported.
	Added a field to clauses_info to store the map(var, type) from
	explicit type qualifications.
	Renamed pred_info_set_status/3 to pred_info_set_import_status/3 to
	be consistent with pred_info_import_status/2.

compiler/hlds_data.m
	Added an import_status field to the hlds__mode_defn and
	hlds__inst_defn so that intermod.m knows what has already
	been exported.

compiler/equiv_type.m
	Pass out the equiv_map and export a predicate used to
	expand type qualifications.

compiler/dead_proc_elim.m
	Remove non-optimized versions of opt_imported preds. All
	optimizations must give the optimized version an import_status
	of local.

compiler/code_util.m
	Changed code_util__make_local_entry_label so that `localcall's
	are used for recursive calls in exported predicates.

compiler/code_aux.m
	Changed code_aux__contains_only_builtins_2 so that it doesn't
	check for complicated unifies, since any time this is called,
	complicated unifies have either not been created (when called
	when writing the .opt files) or have been converted to calls
	(when called during inlining).

compiler/higher_order.m
	Make sure that the specialized versions get unique names.

compiler/mercury_compile.pp
	Add calls to intermod.m predicates.

compiler/bytecode_gen.m
	Bracketed some '->'/2 insts so that they can be parsed by SICStus.

compiler/peephole.m
	Replace computed_gotos where all the targets are the same with
	an unconditional goto.

compiler/notes/COMPILER_DESIGN
	Documented intermod.m.

library/list.m
	Added list__all_same/1, which is true if all elements of a list are
	identical. Also added list__last/2, which returns the final element
	of a list, failing on the empty list.

library/io.m
	Change the format specifier for io__write_float so that the decimal
	point is always output. Without this, the result may not be a valid
	Mercury floating point constant.

library/varset.m
	Add predicate varset__create_name_var_map/2 to create a mapping
	from variable name to variable id given a varset. This is used
	in processing type qualifications.

scripts/Mmake.rules
scripts/Mmake.vars.in
	Add suffixes, rules and options for .opt and .optdate.

scripts/mercury_update_interface.in
	Work-around for a problem with parallel gmake. mc --make-interface
	was being run twice in a row on the same module. The first call
	mercury_update_interface moves module.int.tmp to module.int,
	then the second can't find module.int.tmp. The work-around is to
	ignore the exit status of the mv.

Some cleaning up:

compiler/*.m
	Fixed some out of date comments about the handling of
	complicated_unify. Also commented some dead code to do
	with generation of code for complicated_unify.

compiler/modes.m
compiler/mode_info.m
	Moved code to module qualify modes of lambda expressions into
	make_hlds.
	Moved predicates resolve_pred_overloading and find_matching_pred_id
	into typecheck, renaming with a typecheck__ prefix, so that these
	can be called from intermod.m.

compiler/undef_modes.m
compiler/undef_types.m
	Removed - their functionality is now in module_qual.m, except
	for checking for looping equivalence types.

compiler/no_builtin.m
compiler/nit_builtin.m
	Removed - they were made useless (if they weren't already) by
	the removal of the --builtin-module option.

compiler/notes/AUTHORS
	Updated student email addresses.
1996-09-11 08:56:25 +00:00
Zoltan Somogyi
a15c032df7 Flesh out the code already here for traversing module_infos,
Estimated hours taken: 4

passes_aux:
	Flesh out the code already here for traversing module_infos,
	making it suitable to handle all the passes of the back end.

mercury_compile:
	Use the traversal code in passes_aux to invoke the back end passes
	over each procvedure in turn. Print a one-line message for each
	predicate if -v is given (this fixes a long-standing bug).

excess.m, follow_code.m, follow_vars.m, live_vars.m, lveness.m, store_alloc.m:
	Remove the code to traverse module_infos, since it is now unnecessary.

export.m:
	Remove an unused argument from export__produce_header_file_2.

others:
	Move imports from interfaces to implementations, or in some cases
	remove them altogether.
1996-08-03 12:06:26 +00:00
Fergus Henderson
cf2e95c28b Fix the capitalization of some more error messages.
Estimated hours taken: 0.1

compiler/prog_io.m:
	Fix the capitalization of some more error messages.
1996-07-04 08:44:19 +00:00
Fergus Henderson
6ebe46c20a Implement a new `:- pragma source_file("<source file name>").' declaration,
Estimated hours taken: 3

Implement a new `:- pragma source_file("<source file name>").' declaration,
and a `#<line number>' directive, to make it more convenient to use
preprocessors or to use Mercury as a target language.

prog_data.m:
	Add `source_file' pragma.

make_hlds.m, module_qual.m:
	Ignore `pragma source_file' declarations.

mercury_to_mercury.m:
	Print `pragma source_file' declarations.
	Simplify a couple of unnecessarily complicated bits of code.

prog_io.m:
	Parse `source_file' pragmas.  When parsing items, check for them;
	handle `pragma source_file' declarations by keeping track of the
	source file name, and passing it to parser__parse_term/4.

	Also, change the "Error: module should start with a `:- module'
	declaration" message from an error to a warning.

	Also, fix the capitalization in a bunch of error messages:
	change from "Error: Blah" to "Error: blah".
1996-07-03 13:22:54 +00:00
Tyson Dowd
03d1f75c7e These changes comprise
Estimated hours taken: 40
	(including testing)

These changes comprise
	* some configuration changes for accurate GC (setting -DNATIVE_GC,
	  working out dependencies for accurate GC, new .agc grade)
	* liveness changes for supporting polymorphism in accurate GC
	* some support of polymorphism for GC (mostly consisting of keeping
	  the typevar -> typinfo_var mappings (eg T in list(T) is
	  stored in TypeInfo_For_T) and corresponing mappings into
	  lvals at continuation labels.
	* changes required to data structures so that above changes could
	  work.
	* cut down on the number of abstract exports handled by checking
	  types to see whether they are imported (duh...)
	* don't use '-I' directories when searching for '.m' files.
	  (since this will wrecks dependency generation in some situations).
	* don't lookup and create shape information when not doing accurate
	  GC. (instead we just give back dummy values).
1996-06-12 07:42:09 +00:00
Simon Taylor
5d9e4158f7 Module qualification of types, insts and modes.
Estimated hours taken: 45

Module qualification of types, insts and modes.

Added a new interface file - <module>.int3. This contains the
short interface qualified as much as possible given the information
in the current module.

When producing the .int and .int2 files for a module, the compiler uses
the information in the .int3 files of modules imported in the interface
to fully module qualify all items. The .int2 file is just a fully
qualified version of the .int3 file. The .int3 file cannot be overwritten
by the fully qualified version in the .int2 file because then mmake would
not be able to tell when the interface files that depend on that .int3
file really need updating.

The --warn-interface-imports option can be used to check whether
a module imported in the interface really needs to be imported in
the interface.


compiler/module_qual.m
Module qualify all types, insts and modes. Also checks for modules
imported in the interface of a module that do not need to be.

compiler/modules.m
The .int file for a module now depends on the .int3 files of imported
modules. Added code to generate the make rule for the .int file in the
.d file. There is now a file .date2 which records the last time the
.int2 file was updated.
The .int3 files are made using the --make-short-interface option
introduced a few weeks ago.

compiler/options.m
Added option --warn-interface-imports to enable warning about interface
imports which need not be in the interface. This is off by default
because a lot of modules in the library import list.m when they only
need the type list, which is defined in mercury_builtin.m.
Removed option --builtin-module, since the mercury_builtin name is wired
into the compiler in a large number of places.

compiler/prog_util.m
Added a predicates construct_qualified_term/3 and construct_qualfied_term/4
which take a sym_name, a list of argument term and a context for the /4
version and give a :/2 term.

compiler/type_util.m
Modified type_to_type_id to handle qualified types. Also added predicates
construct_type/3 and construct_type/4 which take a sym_name and a list of
types and return a type by calling prog_util:construct_qualified_term.

compiler/modes.m
On the first iteration of mode analysis, module qualify the modes of
lambda expressions.

compiler/mode_info.m
Added field to mode_info used to decide whether or not to module qualify
lambda expressions.

compiler/mode_errors.m
Added dummy mode error for when module qualification fails so that mode
analysis will stop.
Added code to strip mercury_builtin qualifiers from error messages to
improve readability.

compiler/typecheck.m
Strip builtin qualifiers from error messages.

compiler/llds.m
compiler/llds_out.m
compiler/opt_util.m
compiler/opt_debug.m
Change the format of labels produced for the predicates to use the
qualified version of the type name.

compiler/mercury_compile.pp
Call module_qual__module_qualify_items and make_short_interface.
Remove references to undef_modes.m and undef_types.m

compiler/undef_modes.m
compiler/undef_types.m
Removed, since their functionality is now in module_qual.m.

compiler/prog_io.m
Changed to qualify the subjects of type, mode and inst declarations.

compiler/*.m
Changes to stop various parts of the compiler from throwing away
module qualifiers.
Qualified various mercury_builtin builtins, e.g. in, out, term etc.
where they are wired in to the compiler.

compiler/hlds_data.m
The mode_table and user_inst_table are now abstract types each
storing the {mode | inst}_id to hlds__{mode | inst}_defn maps
and a list of mode_ids or inst_ids. This was done to improve the
efficiency of module qualifying the modes of lambda expressions
during mode analysis.
module_info_optimize/2 now sorts the lists of ids.
The hlds_module interface to the mode and inst tables has not changed.

compiler/hlds_module.m
Added yet another predicate to search the predicate table.
predicate_table_search_pf_sym_arity searches for predicates or
functions matching the given sym_name, arity and pred_or_func.

compiler/higher_order.m
Changed calls to solutions/2 to list__filter/3. Eliminated unnecessary
requantification of goals.

compiler/unused_args.m
Improved abstraction slightly.
1996-06-11 06:30:10 +00:00
Fergus Henderson
0e1e0b0b91 Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4

Implement `recursive' and `non_recursive' pragma c_code declarations.
This allows the compiler to optimize cases when the C code
is known to not call Mercury code.  It's also necessary
to allow C code which modifies the hp register to work
(such code must be declared `non_recursive', otherwise
the registers will be saved and restored over it).
To make things bootstrap OK, the old pragma c_code declarations
default to `non_recursive'.

prog_data.m, hlds_goal.m:
	Add new field c_is_recursive to pragma c_code goals.

prog_io.m:
	Parse the new `recursive' and `non_recursive' pragma c_code
	declarations.

make_hlds.m:
	Pass the c_is_recursive field from the parse tree to the HLDS.

live_vars.m:
	For non-recursive C code, don't save variables on the stack.

code_gen.pp:
	For non-recursive C code, don't save variables on the stack,
	don't mark the succip as needing to be saved, and don't
	call save_registers() and restore_registers().

*.m:
	Change c_code/5 to c_code/6.
1996-06-10 17:18:50 +00:00
Zoltan Somogyi
cb41c485ef Update a comment.
Estimated hours taken: 2

code_util:
	Update a comment.

dead_proc_elim:
	Fix a progress message.

hlds_out:
	Put a comment sign before each switch arm's "X has functor f"
	output, since this is not proper Prolog or Mercury syntax.

make_hlds:
	Temporarily allow the definition of builtins, to permit bootchecking
	while unary builtins are added.

prog_io:
	Improve the handling of DCG variables in if-then-elses the same way
	I recently improved disjunctions. Also factor out a bit of common
	code.
1996-05-31 01:16:43 +00:00
Zoltan Somogyi
c588526f03 Add a predicate to rename variables in the kinds of goals we have in
Estimated hours taken: 1

prog_util:
	Add a predicate to rename variables in the kinds of goals we have in
	items. (We already have similar predicates for terms and for
	hlds_goals).

prog_io:
	We used to expand ( p ; q ) in DCG clauses to become
	( p(DCG1, DCG2) ; q(DCG1, DCG3), DCG2 = DCG3 ). These extra
	unifications can pile up rather badly; in the new version of lexer.m,
	two 128-way switches each ended up with 90 unifications in the last
	arm. This is very bad for performance. Instead of adding unifications
	to make sure that both arms of a disjunction put the final stream value
	in the same variable, we now use renaming when possible.
1996-05-27 23:33:51 +00:00
Fergus Henderson
b4cf70fccc Rename the pragma' type as pragma_type', to avoid bootstrapping
Estimated hours taken: 0.25

prog_data.m, prog_io.m:
	Rename the `pragma' type as `pragma_type', to avoid bootstrapping
	problems caused by my change to make `pragma' an operator.
1996-05-25 04:10:49 +00:00
Fergus Henderson
a8acf00f9d Add a new pragma `:- pragma obsolete(Name/Arity).';
Estimated hours taken: 3

Add a new pragma `:- pragma obsolete(Name/Arity).';
the effect of this pragma is that we issue a warning for
any call to the specified predicate(s) or function(s).

prog_data.m:
	Add new pragma type `obsolete'.
prog_io.m:
	Parse pragma `obsolete'.
hlds_pred.m, hlds_out.m:
	Add new pred_marker `obsolete'
make_hlds.m:
	When we encounter a pragma `obsolete', insert `request(obsolete)'
	in the pred_marker list for the specified predicate(s) and function(s).
simplify.m:
	For each predicate call, check if the called predicate has been
	marked as obsolete.  If so, return a `warn_obsolete' warning.
det_report.m:
	Add a new warning type `warn_obsolete', and add code to print
	the warning for this warning type.
det_analysis.m:
	Add a comment.
1996-05-21 19:09:28 +00:00
Fergus Henderson
2a1d24f62e Make `pragma' a prefix operator, and change the syntax for
Estimated hours taken: 1

Make `pragma' a prefix operator, and change the syntax for
pragmas from `:- pragma(name, args)' to `pragma name(args)'.
(For backwards compatibility the old syntax is still allowed.)

mercury_to_mercury.m:
	Add `pragma' to the list of operators.
prog_io.m:
	Clean up the code for parsing pragmas: avoid overly deep
	nesting of if-then-elses over pages of code, and avoid
	some code duplication.
	Parse new pragma syntax.
1996-05-21 19:07:47 +00:00
Fergus Henderson
60b9fa83b6 Implement higher-order functions.
Estimated hours taken: 12

Implement higher-order functions.

Add higher-order function terms
(function lambda expressions, e.g. `Func = (func(X) = Y :- Y is 2 * X)'
and higher-order function calls (apply/N, e.g. `Z = apply(Func, 42)').
Add higher-order function insts and modes.

hlds_goal.m:
	Add a new field pred_or_func to lambda_goal.

prog_data.m:
	Add a new field pred_or_func to pred_inst_info.

prog_io.m:
	Add support for parsing higher-order function terms and
	higher-order function insts and modes.

make_hlds.m:
	Add support for parsing higher-order function terms.

typecheck.m:
	Add support for type-checking higher-order function calls
	and higher-order function terms.

modes.m, mode_errors.m:
	Add support for mode-checking higher-order function calls
	and higher-order function terms.

higher_order.m:
	Handle higher-order function types and insts.

hlds_pred.m:
	Add new predicate pred_args_to_func_args, for extracting the
	function arguments and function return from the arguments
	of a predicate that is really a function.

*.m:
	Minor changes to handle new pred_or_func field in lambda_goals
	and pred_inst_infos.
1996-05-14 10:07:46 +00:00
Fergus Henderson
e98fdf8fab Export parse_some_vars_goal, for use by make_hlds.m, for
Estimated hours taken: 0.25

compiler/prog_io.m:
	Export parse_some_vars_goal, for use by make_hlds.m, for
	my recent change to support if-then-else expressions.
1996-04-25 02:43:10 +00:00
Zoltan Somogyi
649b6908c3 Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8

options.m:
	Rename branch_delay_slot to have_delay_slot.
	Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
	This is possible now because the default optimization level is now
	set in mc.

mercury_compile:
	Change verbose output a bit to be more consistent.

dead_proc_elim:
	Export the predicates that will eventually be needed by inlining.m.

inlining.m:
	Use the information about the number of times each procedure is called
	to inline local nonrecursive procedures that are called exactly once.
	EXCEPT that this is turned off at the moment, since the inlining of
	parse_dcg_goal_2 in prog_io, which this change enables, causes the
	compiler to emit incorrect code.

prog_io:
	Moved the data type definitions to prog_data. (Even though prog_io.m
	is ten times the size of prog_data.m, the sizes of the .c files are
	not too dissimilar.)
1996-04-24 01:00:23 +00:00
David Jeffery
de1bce000c Its...
Estimated hours taken: 30 (?)

Its...

The C to Mercury Interface.

The following changes provide a C to Mercury interface. By making a declaration
such as

:- pragma(export, foo(in, in, out), "FunctionName").

you will be able to call the C function "FunctionName" from C. The arguments
are the same as the Mercury arguments, with outputs passed as pointers.

XXX We don't handle floats or strings properly.

A function prototype is output into <modulename>.h

Execution still has to start in Mercury.

Something went wrong with CVS when I tried to abort a commit just then, and it
thinks I've already commited some files... but here's a description of all
my changes anyway:

compiler/garbage_out.m:
	Ignore c_export c_modules.
compiler/hlds_module.m:
	Add an annotation to the hlds, indicating which procs are exported
	to C.
compiler/llds.m:
	Change the way labels are emitted - instead of emitting the label
	directly, it first generates a string and then prints the string. This
	is useful because I only want the string (to print later). The
	preds which return a string are now part of the interface.
compiler/make_hlds.:
	Take note of which procs are to be exported to C.
compiler/mercury_compile.pp:
	Generate a <module>.h file if necessary.
compiler/mercury_to_mercury.m:
	Spit out :- pragma(export, ...) decs.
compiler/prog_io.m:
	Read in :- pragma(export, ...) decs.

compiler/export.m:
	Handle the outputting of C exports. This includes the generation of
	the .h files and the generation of the C functions.
1996-04-22 19:28:36 +00:00
Fergus Henderson
b10f96b2c7 Remove most of the old hack which expanded calls to is/2 in the
Estimated hours taken: 0.25

compiler/prog_io.m:
	Remove most of the old hack which expanded calls to is/2 in the
	parser, since we now use functions instead.
1996-04-07 14:47:45 +00:00
Zoltan Somogyi
2833bfffb7 Divided the old hlds.m into four files:
Estimated hours taken: 10

hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
	Divided the old hlds.m into four files:

	hlds_module.m defines the data structures that deal with issues
	that are wider than a single predicate. These data structures are
	the module_info structure, dependency_info, the predicate table
	and the shape table.

	hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.

	hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
	other parts of goal structures.

	hlsd_data.m defines the HLDS types that deal with issues related
	to data and its representation: function symbols, types, insts, modes.
	It also defines the types related to determinism.

	hlds.m is now an empty module. I have not removed it from CVS
	because we may need the name hlds.m again, and CVS does not like
	the reuse of a name once removed.

other modules:
	Import the necessary part of hlds.

det_analysis:
	Define a type that was up to now improperly defined in hlds.m.

prog_io:
	Move the definition of type determinism to hlds_data. This decision
	may need to be revisited when prog_io is broken up.

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

mercury_compile:
	If the option -d all is given, dump all HLDS stages.

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00
Fergus Henderson
3b36da6e77 Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12

Implement functional syntax.  You can now use `:- func' in a similar manner
to `:- pred'.  For example, `:- func foo(int, int) = int.' declares a function,
and `:- mode foo(in, in) = out.' defines a mode for it.  You can write clauses
for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.'  Any term in the
head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'.

Until we have implemented a proper Mercury debugger, this syntax
should not be used (except that I might reimplement the functions
provided by Prolog's is/2 predicate using this syntax, rather than
the current special-case hack in the parser).

prog_io.m:
	Add syntax for declaring and defining functions.
	Disallow the use of `=' to define modes, as in `:- mode foo = bar.'
	(Instead, you should use `::'.  `==' is also allowed.)
	Also, use higher-order predicates to simplify some of the rather
	repetitious parsing code.

mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m:
	Handle new functional syntax.

typecheck.m:
	Add support for functions, function types such as `func(int) = int',
	and currying.  (But there's currently no equivalent to call/N for
	functions, so function types and currying aren't very useful yet.)

undef_types.m:
	Add support for function types.

modes.m:
	Convert function calls into predicate calls.
	(This must be done after typechecking is complete,
	so I put it in mode analysis.)

hlds.m:
	Add new field `pred_or_func' to the pred_info.

hlds_out.m:
	Print out the `pred_or_func' field.

higher_order.m, unused_args.m, lambda.m, dnf.m:
	Pass extra pred_or_func argument to pred_info_init to specify that
	the thing being created is a predicate, not a function.

constraint.m, dependency_graph.m, hlds_out.m:
	`mercury_output_mode_subdecl' has been renamed
	`mercury_output_pred_mode_subdecl'.

prog_util.m:
	Add new predicate split_type_and_mode/3.

llds.m:
	Print out
		/* code for predicate '*'/3 in mode 0 */
	rather than
		/* code for predicate */3 in mode 0 */
	to avoid a syntax error in the generated C code.
1996-03-25 07:41:54 +00:00
Zoltan Somogyi
3e4a019dcc Fix the pass structure, and start using a loose sequence of stage
Estimated hours taken: 8

mercury_compile:
	Fix the pass structure, and start using a loose sequence of stage
	numbers, to make it easier to add new stages without having to fiddle
	stage numbers.

	THIS DOES MEAN THAT ALL STAGE NUMBERS HAVE CHANGED NOW.

	The stage number assignment scheme assigns 1 to 25 to the front end,
	26 to 50 to the middle passes, and 51 to 99 to the back end.

hlds:
	We had two types that combined a pred_id and a proc_id. One,
	pred_proc_id, used a simple pair; the other, procedure_id, had a better
	definition using a specific function symbol but was not used
	anywhere else. I standardized on the name pred_proc_id, but using the
	definition with a dedicated function symbol (proc).

	I also defined a type pred_proc_list as a list of pred_proc_id.

	To prepare for memoing, I added a new field to pred_info, which is
	a list of markers, each requesting a specific transformation on the
	predicate or indicating that the transformation has been done.
	The inline request is now represented using such a marker. However,
	the interface is backwards compatible.

constraint, dead_proc_elim, dependency_graph, det_analysis, det_report,
higher_order, unused_args:
	Changes to conform to the new definition of pred_proc_id.
	In two places removed definitions of predproclist, whose
	equivalent pred_proc_list is now defined in hlds.m.

hlds_out, make_hlds, mercury_to_mercury, prog_io:
	Add code to handle memo pragma declarations, using whenever possible
	a version of the existing code for handling inline requests, but
	generalized for handling any pragma that sets a marker.

switch_detection:
	Rename the type cases_list to sorted_cases_list. This avoids a
	name clash that creates a duplicate label and therefore screws up
	the profiler, and is a better name anyway.

options:
	Add a new option, --opt-space, that turns on optimizations that save
	space and turns off optimizations that squander space.

handle_options:
	Pass the special option handler to getopt.

frameopt:
	For each labelled code sequence that tears down the stack frame but
	does not use it, we used to create a parallel code sequence that omits
	the teardown code, for use by gotos from locations that did not have
	a stack frame. However, peepholing may discover that it is better
	not to tear down the stack frame at the site of the goto after all,
	so we need the original code sequence as well.

	The current change fixes a bug that occurs if the original code
	sequence is modified by another part of frameopt to omit teardown
	code. In such cases, which are produced by --pred-value-number,
	peepholing redirects a goto to a code sequence that it thinks tears
	down the stack frame, but actually doesn't.

	With this change, --pred-value-number now works.

llds:
	Fix typos in a comment.
1996-03-24 06:39:33 +00:00
Zoltan Somogyi
c70dbe9e2b When we are processing the flushing of create expressions, make sure
Estimated hours taken: 2

code_exprn:
	When we are processing the flushing of create expressions, make sure
	the Lval we are creating into isn't a field reference. This avoids
	deep field of field of field of ... nesting. It does introduce
	references to high register numbers, but this is a lesser evil,
	and Tom and I plan to fix this anyway.

arg_info, globals, options:
	Change --args old to --args simple.

options:
	Make some help messages more specific.

code_aux, code_exprn, code_info, det_report, make_hlds, mercury_to_goedel,
prog_io, typecheck:
	Changes to accommodate the move from varset__lookup_name
	to varset__search_name.
1996-03-12 03:39:13 +00:00
Fergus Henderson
bd2093d8b4 Fixes for two bugs in mode analysis, and
Estimated hours taken: 12

Fixes for two bugs in mode analysis, and
a first cut at support for `any' insts.
(The support for `any' is very preliminary,
has had only the most minimal of testing, and
doubtless has some bugs.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m undef_modes.m
unique_modes.m prog_io.m:
	Add new type of inst `any(uniqueness)' to prog_io.m, and
	change inst_match.m, mode_util.m, and other places to handle
	handle `any' insts.

inst_match.m:
	Fix bug in inst_merge: when merging `unique(f(ground)) and `unique',
	the result should be `ground', not `unique', since part of the
	data structure may be shared.  (This fix required adding several
	new predicates: `merge_uniq_bound' etc.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m polymorphism.m
prog_io.m switch_detection.m unique_modes.m:
	Fix a design bug: in a `bound' inst, the list of bound_insts
	must be sorted on the name+arity, not on the name+arg_insts.
	To achieve this, I changed the type of the first argument of
	functor/2 in the type bound_inst from `const' (just name) to
	`cons_id' (name+arity).
1996-03-09 16:04:29 +00:00
Zoltan Somogyi
e7054745f2 Wrap parentheses around pred insts, since they are needed.
Estimated hours taken: 6

mercury_to_mercury:
	Wrap parentheses around pred insts, since they are needed.

value_number, vn_verify:
	Value numbering now reapplies itself to both halves of a block if
	it cannot optimize the block as a whole.
	Split the verification code into its own module, and fix line lengths.

vn_order:
	Fix the computation of the label at which blocks should be divided.
	Fix line lengths.

vn_debug:
	Add a message to support the new block dividing capability.

code_exprn:
	Redirect option lookup operations from options to getopt.

passes_aux:
	Prepare for some further changes.

prog_io:
	Formatting changes.
1996-03-05 23:55:48 +00:00
Fergus Henderson
6885f10d1c A bunch of changes to get `--split-c-files' to work better.
Estimated hours taken: 4

A bunch of changes to get `--split-c-files' to work better.

compiler/Mmake:
	Add a rule to create mercury_compile.opt using --split-c-files.
	Add dependency of mercury_compile_init.c on ../util/mkinit.
	Add a couple of things missing from the `mmake realclean' rule.

prog_io.m, hlds.m, make_hlds.m, llds.m, mercury_compile.pp,
mercury_to_mercury.m, garbage_out.m:
	Handle new c_code pragma `pragma(c_code, "...")'.
	This has a similar effect to `pragma(c_header_code, "...")',
	except that the code will only be output once if `--split-c-files'
	is enabled.

mercury_compile.pp:
	If --split-c-files option is enabled, pass -DSPLIT_C_FILES to
	the C compiler.

llds.m:
	Fix a bug which meant that --split-c-files didn't work in some grades:
	use the typedef now defined in goto.h when declaring module
	initialization functions, don't just assume they are `void f(void)'.
1996-03-05 03:56:56 +00:00
Fergus Henderson
6d7f4b9b30 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

Undo dylan's changes in the names of some library entities,
by applying the following sed script

	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_integer/term__integer/g
	s/term_float/term__float/g
	s/term_context/term__context/g
	s/term_functor/term__functor/g
	s/term_variable/term__variable/g
	s/_term__/_term_/g
	s/std_util__bool_/bool__/g

to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).

I also moved `bool' to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)

compiler/*.m:
	Apply sed script above;
	where appropriate, add `bool' to the list of imported modules.
1996-02-03 17:30:14 +00:00
Fergus Henderson
4414b6c975 Print line numbers in "%03d" format, so that columns in the
Estimated hours taken: 0.5

prog_io.m, prog_out.m:
	Print line numbers in "%03d" format, so that columns in the
	error messages line up nicely.
1996-01-21 14:26:10 +00:00
Fergus Henderson
2fbdac6996 Implemented committed choice nondeterminism.
Estimated hours taken: 8

Implemented committed choice nondeterminism.

I have added new determisms `cc_nondet' and `cc_multi'.
These determinisms have the existing code model `model_semi',
so the only major changes I had to make were to determinism
analysis (and even that wasn't too hard).  Code generation
was pretty much unchanged, except that I had to add back
model_semi disjunctions again.

The one desireable part that won't work yet is overloading a
predicate to have both `nondet' and `cc_nondet' modes.
(Mode analysis will always pick the `cc_nondet' mode, and then if it
occurs in an all_soln context, determinism analysis will unfortunately
report an error rather than substituting the `nondet' mode.)

prog_io.m, hlds.m, hlds_out.m, mercury_to_mercury.m, prog_io.m:
	Add new determisms `cc_nondet' and `cc_multi'.
	Add new soln_count `at_most_many_cc'.

det_analysis.m, det_report.m:
	Changed determinism analysis to handle them, by traversing goals
	right-to-left and propagating a `call_context' down as we go.
	The call_context specifies whether we want `all_solns' to a goal,
	or just the `first_soln'.  Disjunctions which occur in a `first_soln'
	context will get inferred as `cc_nondet' or `cc_multi'.
	Determinism analysis will also check that any calls to predicates
	with a `cc_nondet' or `cc_multi' mode occur only in a `first_soln'
	context.

	(Also another minor improvement: warn if the condition of an
	if-then-else cannot fail.)

disj_gen.m:
	Put back the code to handle semidet disjunctions.
	It had suffered from a fair bit of software rot;
	I hope my fixes were correct.  (Tom, can you please
	have a look at the code and check that it looks OK?)
1996-01-15 16:42:09 +00:00
Fergus Henderson
ebe792f1d8 A large bunch of changes to improve unique mode checking.
Estimated hours taken: 18

---------------------------------------------------------
A large bunch of changes to improve unique mode checking.
---------------------------------------------------------

Unique mode checking is now quite similar to redoing mode checking,
except that as it goes along it changes the insts of variables which
may be used again on backtracking from `unique' to `mostly_unique',
and except that it doesn't do any rescheduling.

(This contrasts with my original very simple approach which just kept track
of which variables were nondet-live - that approach only works
for the top-level of the inst.  The new approach handles insts
such a list whose skeleton is unique and whose elements are mostly_unique.)

Another improvement is that we now also detect errors resulting from
shallow (semidet) backtracking in if-then-elses and negations, which
previously we missed.

Also, fix a bug in the handling of `X = f(_)' when X is unique:
it was inferring the delta instmap `X -> unique(f(ground))'
rather than `X -> unique(f(unique))'.

unique_modes.m:
	Major rewrite.

inst_match.m:
	Add new predicate `make_mostly_uniq_inst' which replaces
	every occurence of `unique' in an inst with `mostly_uniq'.
	Fix bug in abstractly_unify_inst_functor_3 which caused
	above-mentioned problem with `X = f(_)' when X is unique.

hlds.m, prog_io.m, mercury_to_mercury.m, mode_util.m, undef_modes.m:
	Add a new inst_name `mostly_unique(inst)'; the inst
	`defined_inst(mostly_unique(X))' is identical to the
	inst X with every occurrence of `unique' replaced with
	`mostly_unique'.  This change was required in order to
	implement the `make_mostly_uniq_inst' predicate for recursive
	insts.

mode_info.m:
	Add a new field holding the nondet-live variables,
	for use by unique_modes.m.

modes.m:
	Export a whole bunch of previously private predicates,
	for use by unique_modes.m.

det_analysis.m, det_report.m, make_hlds.m, mercury_compile.pp, prog_io.m,
value_number.m:
	Fix unique mode errors resulting from I/O operations (calls
	to io__lookup_bool_opt) in the conditions of if-then-elses.
1996-01-14 15:16:30 +00:00
Fergus Henderson
e2d7877b0f Improve error message for one of the internal errors.
code_exprn.m:
	Improve error message for one of the internal errors.

det_analysis.m:
	Make sure we don't generated unnecessary nested `some' goals.

prog_io.m, inst_match.m, mode_util.m, mercury_to_mercury.m:
	Add new insts `mostly_unique' and `mostly_clobbered', with
	semantics similar to `unique' and `clobbered', except that
	mostly-unique variables might be needed on backtracking.

unique_modes.m:
	A good start on the code to check that `unique' modes
	are not used for nondet live variables.  Still incomplete,
	but just about all the code is there except the code to
	actually compute the set of nondet live variables as you
	traverse the goal.
1996-01-01 13:19:22 +00:00