Commit Graph

124 Commits

Author SHA1 Message Date
Fergus Henderson
40dcaf4f4f For calls to class methods, if the particular class instance is
Estimated hours taken: 3 (plus 1 from dgj)

compiler/polymorphism.m:
	For calls to class methods, if the particular class instance is
	known at the call site, then specialize the code by generating
	a direct call to the method for that instance.

tests/invalid/Mmakefile:
tests/invalid/typeclass_test_{1,2,3,4}.m:
tests/invalid/typeclass_test_{1,2,3,4}.err_exp:
tests/hard_coded/Mmakefile:
tests/hard_coded/typeclass_test_{5,6}.m:
tests/hard_coded/typeclass_test_{5,6}.exp:
	Some test cases for type classes, including one for the above change.
1998-01-29 08:39:56 +00:00
Fergus Henderson
803fb1c727 Remove the last vestiges of support for type_info representations
Estimated hours taken: 0.5

compiler/options.m:
compiler/handle_options.m:
compiler/globals.m:
compiler/polymorphism.m:
runtime/mercury_type_info.h:
	Remove the last vestiges of support for type_info representations
	other than "shared-one-or-two-cell".
1998-01-23 12:12:05 +00:00
Zoltan Somogyi
5013dd9c76 Implement nondet pragma C codes.
Estimated hours taken: 40

Implement nondet pragma C codes.

runtime/mercury_stacks.h:
	Define a new macro, mkpragmaframe, for use in the implementation
	of nondet pragma C codes. This new macro includes space for a
	struct with a given sruct tag in the nondet stack frame being created.

compiler/{prog_data.m,hlds_goal.m}:
	Revise the representation of pragma C codes, both as the item and
	in the HLDS.

compiler/prog_io_pragma.m:
	Parse nondet pragma C declarations.

	Fix the indentation in some places.

compiler/llds.m:
	Include an extra argument in mkframe instructions. This extra argument
	gives the details of the C structure (if any) to be included in the
	nondet stack frame to be created.

	Generalize the LLDS representation of pragma C codes. Instead of a
	fixed sequence of <assign from inputs, user c code, assign to outputs>,
	let the sequence contain these elements, as well as arbitrary
	compiler-generated C code, in any order and possibly with repetitions.
	This flexibility is needed for nondet pragma C codes.

	Add a field to pragma C codes to say whether they can call Mercury.
	Some optimizations can do a better job if they know that a pragma C
	code cannot call Mercury.

	Add another field to pragma C codes to give the name of the label
	they refer to (if any). This is needed to prevent labelopt from
	incorrectly optimizing away the label definition.

	Add a new alternative to the type pragma_c_decl, to describe the
	declaration of the local variable that points to the save struct.

compiler/llds_out.m:
	Output mkframe instructions that specify a struct as invoking the new
	mkpragmaframe macro, and make sure that the struct is declared just
	before the procedure that uses it.

	Other minor changes to keep up with the changes to the representation
	of pragma C code in the LLDS, and to make the output look a bit nicer.

compiler/pragma_c_gen.m:
	Add code to generate code for nondet pragma C codes. Revise the utility
	predicates and their data structures a bit to make this possible.

compiler/code_gen.m:
	Add code for the necessary special handling of prologs and epilogs
	of procedures defined by nondet pragma C codes. The prologs need
	to be modified to include a programmer-defined C structure in the
	nondet stack frame and to communicate the location of this structure
	to the pragma C code, whereas the functionality of the epilog is
	taken care of by the pragma C code itself.

compiler/make_hlds.m:
	When creating a proc_info for a procedure defined by a pragma C code,
	we used to insert unifications between the headvars and the vars of
	the pragma C code into the body goal. We now perform substitutions
	instead. This removes a factor that would complicate the generation
	of code for nondet pragma C codes.

	Pass a moduleinfo down the procedures that warn about singletons
	(and other basic scope errors). When checking whether to warn about
	an argument of a pragma C code not being mentioned in the C code
	fragment, we need to know whether the argument is input or output,
	since input variables should appear in some code fragments in a
	nondet pragma C code and must not appear in others. The
	mode_is_{in,out}put checks need the moduleinfo.

	(We do not need to check for any variables being mentioned where
	they shouldn't be. The C compiler will fail in the presence of any
	errors of that type, and since those variables could be referred
	to via macros whose definitions we do not see, we couldn't implement
	a reliable test anyway.)

compiler/opt_util.m:
	Recognize that some sorts of pragma_c codes cannot affect the data
	structures that control backtracking. This allows peepholing to
	do a better job on code sequences produced for nondet pragma C codes.

	Recognize that the C code strings inside some pragma_c codes refer to
	other labels in the procedure. This prevents labelopt from incorrectly
	optimizing away these labels.

compiler/dupelim.m:
	If a label is referred to from within a C code string, then do not
	attempt to optimize it away.

compiler/det_analysis.m:
	Remove a now incorrect part of an error message.

compiler/*.m:
	Minor changes to conform to changes to the HLDS and LLDS data
	structures.
1998-01-13 10:14:23 +00:00
Fergus Henderson
239e96ec59 Clean up the handling of unbound type variables.
Estimated hours taken: 8

Clean up the handling of unbound type variables.
Fix a bug with unbound type variables in lambda expressions.
Run purity analysis, modechecking etc. even if there were type errors.

compiler/mercury_compile.m:
	Run purity analysis, modechecking etc. even if there were type
	errors.  This fixes a bug (inconsistency between the code and
	the comments) that seems to have been introduced in stayl's
	change to mercury_compile.m (revision 1.25) to add intermodule
	unused argument elimination: the comment said "continue,
	even if type checking found errors", but the code did not
	continue.

	This change was needed to ensure that we still report a warning
	message about unused type variables for tests/invalid/error2.m;
	without it, we stop after type checking and don't do purity
	analysis, and so don't report the warning.

compiler/typecheck.m:
compiler/purity.m:
	Move the code for checking for unbound type variables
	from typecheck.m to purity.m.  It needs to be done
	*after* type inference has been completed, so it
	can't be done in the ordinary type checking/inference
	passes.  Add code to purity.m to bind the
	unbound type variables to the builtin type `void'.

compiler/polymorphism.m:
	Comment out old code to bind unbound type variables
	to `void'; the old code was incomplete, and this
	is now done in purity.m.

compiler/notes/compiler_design.html:
	Document the above changes.

tests/valid/Mmakefile:
tests/valid/unbound_tvar_in_lambda.m:
	Regression test for the above-mentioned bug with unbound type
	variables in lambda expressions.

tests/warnings/singleton_test.exp:
tests/invalid/errors2.err_exp:
	Change the expected warning message for unbound type variables.
	The error context is not as precise as it used to be, I'm afraid:
	we only know which function/predicate the error occurred in,
	not which clause.  Also it now comes out in a different order
	relative to the other error messages.

tests/invalid/errors2.err_exp:
tests/invalid/funcs_as_preds.err_exp:
	Add some new error/warning messages that are output now that
	we run mode and determinism analysis even if there are type errors.
1998-01-02 00:11:41 +00:00
Zoltan Somogyi
b4813457c9 A rewrite of termination analysis to make it significantly easier to modify,
Estimated hours taken: 60

A rewrite of termination analysis to make it significantly easier to modify,
and to extend its capabilities.

compiler/error_util.m:
	A new file containing code that makes it easier to generate
	nicely formatted error messages.

compiler/termination.m:
	Updates to reflect the changes to the representation of termination
	information.

	Instead of doing pass 1 on all SCCs and then pass 2 on all SCCs,
	we now do both pass 1 and 2 on an SCC before moving on to the next.

	Do not insist that either all procedures in an SCC are
	compiler-generated or all are user-written, since this need not be
	true in the presence of user-defined equality predicates.

	Clarify the structure of the code that handles builtins and compiler
	generated predicates.

	Concentrate all the code for updating module_infos in this module.
	Previously it was scattered in several places in several files.

	Put all the code for writing out termination information at the
	end of the module in a logical order.

compiler/term_traversal.m:
	A new file containing code used by both pass 1 and pass 2 to
	traverse procedure bodies.

compiler/term_pass1.m:
	Use the new traversal module.

	Clarify the fixpoint computation on the set of output supplier
	arguments.

	Remove duplicates from the list of equations given to the solver.
	This avoids a det stack overflow in lp.m when doing termination
	analysis on options.m.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_pass2.m:
	Use the new traversal module. Unlike the previous code, this allows us
	to ignore recursive calls with input arguments bigger than the head
	if those calls occur after goals that cannot succeed (since those
	calls will never be reached).

	Implement a better way of doing single argument analysis, which
	(unlike the previous version) works in the presence of mutual recursion
	and other calls between the recursive call and the start of the clause.

	Implement a more precise way of checking for recursions that don't
	cause termination problems. We now allow calls from p to q in which
	the recursive input supplier arguments can grow, provided that on
	any path on which q can call p, directly or indirectly, the recursive
	input supplier arguments shrink by a greater amount.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_util.m:
	Updates to reflect the changes to the representation of termination
	information.

	Reorder to put related code together.

	Change the interface of several predicates to better reflect the
	way they are used.

	Add some more utility predicates.

compiler/term_errors.m:
	Small changes to the set of possible errors, and major changes in
	the way the messages are printed out (we now use error_util).

compiler/options.m:
	Change --term-single-arg from being a bool to an int option,
	whose value indicates the maximum size of an SCC in which we try
	single argument analysis. (Large SCCs can cause single-arg analysis
	to require a lot of iterations.)

	Add an (int) option that controls the max number of paths
	that we are willing to analyze (analyzing too many paths can cause
	det stack overflow).

	Add an (int) option that controls the max number of causes of
	nontermination that we print out.

compiler/hlds_pred.m:
	Use two separate slots in the proc_info to hold argument size data
	and termination info, instead of the single slot used until now.
	The two kinds of information are produced and used separately.

	Make the layout of the get and set procedures for proc_infos more
	regular, to facilitate later updates.

	The procedures proc_info_{,set_}variables did the same work as
	proc_info_{,set_}varset. To eliminate potential confusion, I
	removed the first set.

compiler/*.m:
	Change proc_info_{,set_}variables to proc_info_{,set_}varset.

compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Change the code to handle the arg size data and the termination
	info separately.

compiler/prog_data.m:
	Change the internal representation of termination_info pragmas to
	hold the arg size data and the termination info separately.

compiler/prog_io_pragma.m:
	Change the external representation of termination_info pragmas to
	group the arg size data together with the output supplier data,
	to which it is logically connected.

compiler/module_qual.m:
compiler/modules.m:
	Change the code to accommodate the change to the internal
	representation of termination_info pragmas.

compiler/notes/compiler_design.html:
	Fix some documentation rot, and clarify some points.

	Document termination analysis.

doc/user_guide.texi:
	Document --term-single-arg and the new options.

	Remove spaces from the ends of lines.

library/bag.m:
	Add a new predicate, bag__least_upper_bound.

	Fix code that would do the wrong thing if executed by Prolog.

	Remove spaces from the ends of lines.

library/list.m:
	Add a new predicate, list__take_upto.

library/set{,_ordlist}.m:
	Add a new predicate, set{,_ordlist}__count.

tests/term/*:
	A bunch of new test cases to test the behaviour of termination
	analysis. They are the small benchmark suite from our paper.

tests/Mmakefile:
	Enable the new test case directory.
1997-12-22 10:01:33 +00:00
David Jeffery
7406335105 This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so

This change implements typeclasses. Included are the necessary changes to
the compiler, runtime and library.

compiler/typecheck.m:
	Typecheck the constraints on a pred by adding constraints for each
	call to a pred/func with constraints, and eliminating constraints
	by applying context reduction.

	While reducing the constraints, keep track of the proofs so that
	polymorphism can produce the tyepclass_infos for eliminated
	constraints.

compiler/polymorphism.m:
	Perform the source-to-source transformation which turns code with
	typeclass constraints into code without constraints, but with extra
	"typeclass_info", or "dictionary" parameters.

	Also, rather than always having a type_info directly for each type
	variable, sometimes the type_info is hidden inside a typeclass_info.

compiler/bytecode*.m:
	Insert some code to abort if bytecode generation is used when
	typeclasses are used.
compiler/call_gen.m:
	Generate code for a class_method_call, which forms the body of a class
	method (by selecting the appropriate proc from the typeclass_info).
compiler/dead_proc_elim.m:
	Don't eliminate class methods if they are potentially used outside
	the module
compiler/hlds_data.m:
	Define data types to store:
		- the typeclass definitions
		- the instances of a class
		- "constraint_proof". ie. the proofs of redundancy of a
		  constraint. This info is used by polymorphism to construct the
		  typeclass_infos for a constraint.
		- the "base_tyepclass_info_constant", which is analagous the
		  the base_type_info_constant
compiler/hlds_data.m:
	Define the class_method_call goal. This goal is inserted into the
	body of class method procs, and is responsible for selecting the
	appropriate part of the typeclass_info to call.
compiler/hlds_data.m:
	Add the class table and instance table to the module_info.
compiler/hlds_out.m:
	Output info about base_typeclass_infos and class_method_calls
compiler/hlds_pred.m:
	Change the representation of the locations of type_infos from "var"
	to type_info_locn, which is either a var, or part of a typeclass_info,
	since now the typeclass_infos contain the type_infos for the type that
	they constrain.

	Add constraints to the pred_info.

	Add constraint_proofs to the pred_info (so that typeclass.m can
	annotate the pred_info with the reasons that constraints were
	eliminated, so that polymorphism.m can in turn generate the
	typeclass_infos for the constraints).

	Add the "class_method" marker.

compiler/lambda.m:
	A feable attempt at adding class ontexts to lambda expressions,
	untested and almost certainly not working.
compiler/llds_out.m:
	Output the code addresses for do_*det_class_method, and output
	appropriately mangled symbol names for base_typeclass_infos.
compiler/make_hlds.m:
	Add constraints to the types on pred and func decls, and add
	class and instance declarations to the class_table and instance_table
	respectively.
compiler/mercury_compile.m:
	Add the check_typeclass pass.
compiler/mercury_to_mercury.m:
	Output constraints of pred and funcs, and output typeclass and instance
	declarations.
compiler/module_qual.m:
	Module qualify typeclass names in pred class contexts, and qualify the
	typeclass and instance decls themselves.
compiler/modules.m:
	Output typeclass declarations in the short interface too.
compiler/prog_data.m:
	Add the "typeclass" and "instance" items. Define the types to store
	information about the declarations, including class contexts on pred
	and func decls.
compiler/prog_io.m:
	Parse constraints on pred and func declarations.
compiler/prod_out.m:
	Output class contexts on pred and func decls.
compiler/type_util.m:
	Add preds to apply a substitution to a class_constraint, and to
	a list of class constraints. Add type_list_matches_exactly/2. Also
	add typeclass_info and base_typeclass_info as types which should not
	be optimised as no_tag types (seeing that we cheat a bit about their
	representation).
compiler/notes/compiler_design.html:
	Add notes on module qualification of class contexts. Needs expansion
	to include more stuff on typeclasses.
compiler/*.m:
	Various minor changes.

New Files:
compiler/base_typeclass_info.m:
	Produce one base_typeclass_info for each instance declaration.
compiler/prog_io_typeclass.m:
	Parse typeclass and instance declarations.
compiler/check_typeclass.m:
	Check the conformance of an instance declaration to the typeclass
	declaration, including building up a proof of how superclass
	constraints are satisfied so that polymorphism.m is able to construct
	the typeclass_info, including the superclass typeclass_infos.

library/mercury_builtin.m:
	Implement that base_typeclass_info and typeclass_info types, as
	well as the predicates type_info_from_typeclass_info/3 to extract
	a type_info from a typeclass_info, and superclass_from_typeclass_info/3
	for extracting superclasses.
library/ops.m:
	Add "typeclass" and "instance" as operators.
library/string.m:
	Add a (in, uo) mode for string__length/3.

runtime/mercury_ho_call.c:
	Implement do_call_*det_class_method, which are the pieces of code
	responsible for extracting the correct code address from the
	typeclass_info, setting up the arguments correctly, then executing
	the code.
runtime/mercury_type_info.h:
	Macros for accessing the typeclass_info structure.
1997-12-19 03:10:47 +00:00
Fergus Henderson
d7da60dabf Minor efficiency improvment.
Estimated hours: 0.5

Minor efficiency improvment.

compiler/type_util.m:
compiler/polymorphism.m:
compiler/switch_gen.m:
	Change the type category `user_type(Type)' to just `user_type';
	pass the type as well as the type category, if needed.
1997-10-14 09:27:58 +00:00
Fergus Henderson
5976f769f7 Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1

Fix a bug for the case of a higher-order function call in code
with common sub-expression; mercury 0.7 failed this test, reporting
"Software Error: modecheck fails when repeated", due to confusion
between h.o. _function_ call and h.o. _predicate_ call.

compiler/hlds_goal.m:
	Add `pred_or_func' field to HLDS higher_order_calls.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/hlds_out.m:
compiler/*.m:
	Add code to handle new field for higher_order_call goals.

tests/valid/Mmake:
tests/valid/ho_func_call.m:
	Regression test for the above-mentioned bug.
1997-09-01 14:05:44 +00:00
Thomas Conway
2980b59474 Profiling code with lots of lambda goals was painful, because the names
Estimated hours taken: 1.5

Profiling code with lots of lambda goals was painful, because the names
of the predicates contained no information about which piece of the source
they correspond to. This change corrects this problem by enabling the
profiler to produce output such as:

... 0.00     0.00 <pred/func goal from lp:'pivot', line 362> [10]
... 0.00     0.00 <pred/func goal from lp:'pivot', line 356> [11]
... 0.00     0.00 <pred/func goal from lp:'simplex', line 262> [12]

compiler/lambda.m:
compiler/polymorphism.m:
	construct more meaningful predicate names for lambda predicates.
	this required adding the name of the predicate that contained the
	lambda goal to the info structures that gets threaded through
	these modules.

profiler/demangle.m:
util/mdemangle.c:
	demangle the names for lambda goals.
1997-08-27 03:36:04 +00:00
Fergus Henderson
0a3bcc07b6 Fix another bug in the recalculation of the non-local variables:
Estimated hours taken: 2

compiler/polymorphism.m:
	Fix another bug in the recalculation of the non-local variables:
	we need to requantify if we have added any type variables,
	not just if we have added type variables that are non-local
	at the top level.
1997-08-09 05:01:28 +00:00
Tyson Dowd
f4fc0d86dc Add module qualifiers to names generated by the function
std_util:type_name/1.

compiler/base_type_info.m:
compiler/polymorphism.m:
library/mercury_builtin.m:
	Add module names to base_type_infos.

library/io.m:
library/term.m:
	Check module names as well as type names for special cases.
	Add module qualifiers to terms that represent types
	(That is, when converting type_infos to terms).

library/std_util.m:
	Add type_ctor_module_name/1, add an argument to
	type_ctor_name_and_arity for the module name.
	Add module qualifiers to the name returned by type_name.

runtime/type_info.h:
	Define the offset fo type module names, add
	MR_TYPECTOR_GET_HOT_MODULE_NAME and
	MR_BASE_TYPEINFO_GET_TYPE_MODULE_NAME

tests/hard_coded/higher_order_type_manip.exp:
tests/hard_coded/write.exp:
tests/hard_coded/write_.exp:
	Update test case expected output with module qualifiers where needed.
1997-08-05 04:37:35 +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
Fergus Henderson
20d9e9131a Fix a bug in my previous bug fix: it was calling
Estimated hours taken: 0.5

compiler/polymorphism.m:
	Fix a bug in my previous bug fix: it was calling
	map__apply_to_list to apply the type-info variable map to a
	list of type variables, but not every type variable has a type
	info.
1997-07-25 03:27:53 +00:00
Simon Taylor
138852a198 Commit the correct version of polymorphism.m.
Estimated hours taken: 0.001

compiler/polymorphism.m
	Commit the correct version of polymorphism.m.
1997-07-25 03:18:36 +00:00
Simon Taylor
7974b579ef Fix some places where goal_info fields were not being filled
Estimated hours taken: 1

compiler/simplify.m
compiler/higher_order.m
	Fix some places where goal_info fields were not being filled
	in correctly.

compiler/hlds_goal.m
	Added goal_info_init/4 which takes the nonlocals, instmap_delta
	and determinism of the goal. All goal_info_inits after determinism
	analysis should probably use this version.

compiler/common.m
compiler/polymorphism.m
	Use goal_info_init/4.

tests/general/prune_switch.m
	Test case.
1997-07-25 02:38:44 +00:00
Fergus Henderson
e383d4fa52 Fix a bug: it was over-approximating the non-locals, which
Estimated hours taken: 0.5

compiler/polymorphism.m:
	Fix a bug: it was over-approximating the non-locals, which
	caused the generated HLDS to be mode-incorrect, because it
	could contain a construction for a type_info variable which was
	(spuriously) non-local to the condition of the if-then-else in
	which it occurred.  That's not legal because you can't bind
	non-local variables in the condition of an if-then-else.
1997-07-24 08:04:31 +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
Tyson Dowd
56979ec94c Allow the names of higher order types to be generated.
Estimated hours taken: 5

Allow the names of higher order types to be generated.

LIMITATIONS:
	Document limitations introduced by this change.

compiler/polymorphism.m:
	Map higher order predicates to pred/0 and functions to func/0.

library/mercury_builtin.m:
	Move base_type_* for pred/0 out of library (into runtime).

library/std_util.m:
	Check for pred/0 and func/0 when comparing type infos.
	Create different ctor_infos for higher order preds, decode them
	correctly for args and functors when needed.
	Print functions nicely (eg func(foo) = bar).
	Fix ML_create_type_info so it works correctly with higher order
	types.

runtime/type_info.h:
	Define macros to deal with new representation of higher order
	ctor_infos.

runtime/deep_copy.c:
	Fix make_type_info so it works correctly with higher order
	types.

runtime/Mmakefile:
runtime/type_info.mod:
	Add definitions for pred/0 and func/0 in runtime, they are
	needed by deep copy.

tests/hard_coded/Mmake:
tests/hard_coded/higher_order_type_manip.exp:
tests/hard_coded/higher_order_type_manip.m:
	Test case for this change.
1997-07-16 15:57:00 +00:00
Fergus Henderson
a5cdb73216 Fix a bug in polymorphism__fixup_preds: in the case of a predicate
Estimated hours taken: 1

compiler/polymorphism.m:
	Fix a bug in polymorphism__fixup_preds: in the case of a predicate
	with no modes, it wasn't doing the recursive call to fix up
	the remaining predicates.
1997-06-02 06:36:09 +00:00
Tyson Dowd
327a5131e2 Remove support for term_to_type and type_to_term implemented as special
Estimated hours taken: 5

Remove support for term_to_type and type_to_term implemented as special
preds.  Remove support for one-cell and one-or-two-cell type_infos (now
shared-one-or-two-cell type_infos). Move definitions that were in
mercury_builtin.m back to where they belong.

This code has been removed because it is no longer used, and was no
longer being maintained but was still quite complex.

compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
	Remove one_cell and one_or_two_cell from type_info methods.

compiler/polymorphism.m:
	Remove term_to_type and type_to_term support.
	Remove one_cell and one_or_two_cell from type_info methods.
	Fix documentation to reflect the new situation.

compiler/special_pred.m:
compiler/unify_proc.m:
	Remove term_to_type and type_to_term support.

library/list.m:
	Put the definition of `list' back into list.m

library/mercury_builtin.m:
	Take the definitions of `list', `term', `var', `var__supply',
	etc, out of this module.
	Remove type_to_term, term_to_type, det_term_to_type,
	term__init_var_supply, term__create_var, term__var_to_int
	and term__context_init.
	Remove references to USE_TYPE_TO_TERM and #ifdefs around
	SHARED_ONE_OR_TWO_CELL_TYPE_INFO.

library/std_util.m:
	Remove references ONE_OR_TWO_CELL_TYPE_INFO, and code that
	handles one-cell typeinfo comparisons.

library/term.m:
	Add type_to_term, term_to_type, det_term_to_type,
	term__init_var_supply, term__create_var, term__var_to_int
	and term__context_init back to term.m.
	Add new implementation of type_to_term/2.

library/uniq_array.m:
	Fix a typo in a comment - term_to_type/3 instead of term_to_type/2.

runtime/call.mod:
	Remove special case code for unify, compare, index for
	one-cell typeinfos.
	Remove code for type_to_term/2.

runtime/type_info.h:
	Remove references to ONE_CELL_TYPE_INFO or ONE_OR_TWO_CELL_TYPE_INFO.
	Make sure only SHARED_ONE_OR_TWO_CELL_TYPE_INFO.
	Remove references to USE_TYPE_TO_TERM.

compiler/base_type_layout.m:
compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/delay_slot.m:
compiler/det_util.m:
compiler/fact_table.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/mode_debug.m:
compiler/tree.m:
library/bag.m:
library/queue.m:
	Import module `list' or `term' (or both).
1997-05-20 01:52:55 +00:00
Tyson Dowd
13e61738a8 Fix a bug in compilation in accurate GC grades.
Estimated hours taken: 10

Fix a bug in compilation in accurate GC grades.

compiler/polymorphism.m:
	Add any introduced typeinfo variables to the typevar map.
	Without this unbound type variables won't not occur in the
	typevar map, and the liveness calculations won't be able to
	make sure the typeinfos for the unbound type variables are
	kept live when they should be. (that is, the map lookups would
	fail looking in the typevar map).
1997-05-12 08:18:09 +00:00
Fergus Henderson
e3471f333f Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3

Fix a bug in inlining of polymorphic pragma c_code procedures.

The bug was that if the actual argument type has a specific type
of say `float', then the C variable for the corresponding formal
parameter will be declared to have type `Float', whereas without
inlining the argument type would have been polymorphic and so
the C variable would have been declared to have type `Word'.
Hence we need to keep track of the original argument types,
before any inlining or specialization has occurred, and use
these original argument types to determine how to declare
the C variables, rather than using the actual argument types
for this particular specialization.

compiler/hlds_goal.m:
	Add a new field to pragma_c_code goals, holding the
	original argument types (before any inlining or specialization)
	of the pragma_c_code procedure.

compiler/make_hlds.m:
	Initialize this field with the declared argument types for
	the pragma c_code procedure.

compiler/polymorphism.m:
	Update this field to account for the inserted type_info variables.

compiler/code_gen.m:
	Pass this field to pragma_c_gen.m.

compiler/pragma_c_gen.m:
	Use the original argument types field for the pragma variable
	declarations, rather than looking up the actual types of the
	arguments.

compiler/*.m:
	Trivial changes to handle new field.

compiler/live_vars.m:
	Comment out some code to avoid a warning about `fail'
	in the condition of an if-then-else.
1997-05-05 11:17:40 +00:00
Tyson Dowd
c4dec06196 Fix the (long-time) temporary hack to generate NULL pointers as
Estimated hours taken: 1.5

Fix the (long-time) temporary hack to generate NULL pointers as
type_infos for unbound type variables.

compiler/polymorphism.m:
	- Generate references to void directly, rather than generating
	  NULL pointers.

library/std_util.m:
	- Remove special case code in mercury_compare_type_info, and
	  create_type_info to handle unbound type variables represented
	  as NULLs. Since they are now represented as a normal
	  type_info, there doesn't need to be any special code.
1997-04-30 02:36:30 +00:00
Zoltan Somogyi
4c3b0ecb09 Replace calls to map__set with calls to either map__det_insert or
Estimated hours taken: 3

Replace calls to map__set with calls to either map__det_insert or
map__det_update. In some cases this required a small amount of code
reorganization.
1997-04-07 05:39:59 +00:00
Andrew Bromage
d7319104f9 Making the types pred_id and proc_id (almost) abstract.
Estimated hours taken: 7

Making the types pred_id and proc_id (almost) abstract.

compiler/code_util.m:
        Changed the type of several predicates:
                code_util__make_uni_label/4 (arg 3 was int, now proc_id)
                code_util__inline_builtin/4 (arg 3 was proc_id, now int)
        Added predicate code_util__translate_builtin_2/6.

compiler/hlds_module.m:
        Moved invalid_pred_id/1 to hlds_pred.m

compiler/hlds_pred.m:
        Types pred_id/0 and proc_id are now abstract.
        Added predicates:
                hlds_pred__initial_pred_id/1, hlds_pred__initial_proc_id/1,
                hlds_pred__next_pred_id/2, hlds_pred__next_proc_id/2,
                pred_id_to_int/2, proc_id_to_int/2,
                hlds_pred__in_in_unification_proc_id/1
        Moved predicate invalid_pred_id/1 (from hlds_module.m).

compiler/*.m:
        Miscellaneous minor changes to cast pred/proc_ids to ints
        where appropriate.
1997-03-06 05:09:54 +00:00
Fergus Henderson
620b84e278 Add a reminder to change run the #defines in runtime/type_info.h
Estimated hours taken: 0.25

compiler/polymorphism.m:
	Add a reminder to change run the #defines in runtime/type_info.h
	if the documentation here is changed, and vice versa.
	Also a few other minor improvements to the documentation.
1997-03-04 04:20:33 +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
Tyson Dowd
f3a88df216 Update and improve documentation of polymorphism.
Estimated hours taken: 0.5

Update and improve documentation of polymorphism.

compiler/polymorphism.m:
	- Update documentation and examples to talk about
	  base_type_functors
	- Add some missing documentation of type names
	- Remove some incorrect references to base_type_layouts in
	  one-cell type_infos.
	- Add information about runtime initialization of shared
	  base_type_infos.
	- Give subsections of the documentation headings.
1997-02-23 03:31:20 +00:00
Oliver Hutchison
554cd6376b Added code to store type names in the base type info.
Estimated hours taken: 0.3

Added code to store type names in the base type info.
By storing type names in the base type info we can now give more
helpfull debugging messages. i.e. we can actualy say what type the
error etc... happend in.

compiler/base_type_info.m :
        Added code to place the type name at the end of base type
        info's.

compiler/polymorphism.m :
        Documented change to base type info structure.
1997-02-18 02:50:55 +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
Tyson Dowd
1a2e04a068 Implement shared-one-or-two-cell type_infos for grades without static
Estimated hours taken: 25

Implement shared-one-or-two-cell type_infos for grades without static
code addresses. This allows us to use functor, arg, expand, deep_copy,
etc without changes in all grades.

compiler/base_type_info.m:
	- If static code addresses are not available, eliminate the
	  special procedures, and output the constant 0 instead of a
	  code address.
	- We now keep the `eliminated' predicates in the base_gen_info
	  structure, so that dead_proc_elim knows they are referenced
	  from the base_type_info.

compiler/dead_proc_elim.m:
	- For the moment, don't eliminate any special preds - the
	  analysis to so this safely is quite complex so we take a
	  conservative approach - base_type_infos are always needed, and
	  hence the special preds are always referenced.
	- Also, fix a bug in the handling of eliminated procs - if they
	  are eliminated elsewhere, any eliminated here should be added
	  find the total number. (this bug doesn't occur presently due
	  to the conservative approach we now make).

compiler/globals.m:
compiler/handle_options.m:
	- Change the handling of type_info_method option - we no longer
	  need static addresses to do shared-one-or-two-cell.
	- Add predicate globals__have_static_code_addresses/2 to check
	  for this feature.
	- Make shared-one-or-two-cell the default type_info method.

compiler/llds_out.m:
	- Output initialisation code for the base_type_infos in this
	  module as part of the module initialisation.
	- Don't declare base_type_infos as const if the don't have
	  static code addresses, because we'll have to initialise them
	  at runtime.
	- Don't make decls of base_type_infos `const' if we don't have
	  static code addresses.

compiler/polymorphism.m:
	- Update examples of transformed code to include
	  base_type_layouts, clarify difference between shared and
	  non-shared one-or-two-cell.

library/mercury_builtin.m:
	- Conditionally reference entry labels of builtin special preds,
	  using `MR_MAYBE_STATIC_CODE()' macro.
	- Replace `const' in handwritten base_type_info structs with
	  `MR_STATIC_CODE_CONST'.
	- Add initialisation code to fill in the code addresses.

runtime/type_info.h:
	- Conditionally define MR_STATIC_CODE_ADDRESSES.
	- Define macros to initialise base_type_infos:
	  mercury_init_builtin_base_type_info, and
	  mercury_init_base_type_info
	- Define `MR_STATIC_CODE_CONST' (which is `const' if static code
	  addresses are available, and blank otherwise).
	_ Define MR_MAYBE_STATIC_CODE(X) which is X if static code
	  addresses are available, and 0 otherwise.
	- Make shared-one-or-two-cell the default setting, don't require
	  static code addresses for one-or-two-cell.
	- Create versions of make_typelayout_for_all_tags for 0, 1, 2
	  and 3 tagbits, so as to save space, add error message if we
	  try to use more than 3 tagbits.
	- Improve layout and commenting, break file up into sections.
	- Fix typos.
1997-02-14 05:54:34 +00:00
Tyson Dowd
a28e9f8fa7 Confirm, and fix an XXX in polymorphism.
Estimated hours taken: 4

Confirm, and fix an XXX in polymorphism.

univ_to_type couldn't check the arguments of higher order
types correctly, so one could circumvent the run-time type
check.

compiler/polymorphism.m:
compiler/base_type_layout.m:
	Add the real arity into type_info (and pseudo-type-infos) for
	higher order preds.
	Also, document recent changes to the structure of type_infos,
	fix a typo, and remove the XXX.

library/std_util.m:
	Fix the implementation of mercury_compare_type_info so that the
	arity and argument type_infos of higher-order types are checked.

runtime/deep_copy.c:
	Update offset of the arguments of higher-order type_infos
	as they have been shifted along one.

runtime/type_info.h:
	Add new #defines for the offset of the arity and arguments for
	higher order types, to avoid magic numbers in future.

tests/hard_coded/Mmake:
tests/hard_coded/.cvsignore:
tests/hard_coded/ho_univ_to_type.m:
tests/hard_coded/ho_univ_to_type.exp:
	Test case for conversions - tries to do an illegal conversion.
	The runtime type-check now detects this.
1997-02-04 01:25:21 +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
Tyson Dowd
38dde6d046 Implement deep_copy.
Estimated hours taken: 32

Implement deep_copy.
Implement solutions for asm_fast, using deep_copy.

compiler/base_type_layout.m:
	List all uses of handwritten base_type_layouts.
	For higher-order types, construct type_infos without
	arity, but with argument types.

compiler/polymorphism.m:
	For higher-order types, construct type_infos with argument types.

library/std_util.m:
	Move definition of UNIV_OFFSET_FOR_TYPEINFO and UNIV_OFFSET_FOR_DATA
	to runtime.

runtime/Mmake:
	Add deep_copy.h and deep_copy.c to runtime library.

runtime/memory.c:
runtime/memory.h:
runtime/wrapper.mod:
	Add, and initialize solutions_heap_zone, and solutions_heap_pointer.

runtime/solutions.mod:
	Implement solutions in non-conservative gc grades, using deep_copy,
	and a copy twice algorithm.

runtime/type_info.h:
	Add univ definitions, add offset for type_layout simple args.
1997-01-26 00:38:06 +00:00
Zoltan Somogyi
bc97676d98 Change the definition of is_builtin to use less space.
Estimated hours taken: 2

hlds_goal:
	Change the definition of is_builtin to use less space.

bytecode_gen, code_aux, code_gen, code_util, dependency_graph, follow_code,
higher_order, inlining, live_vars, make_hlds, modecheck_unify, modes,
polymorphism, stratify, unused_args:
	Fixes to accommodate the change to is_builtin.
1996-12-24 02:42:21 +00:00
Zoltan Somogyi
0463a3063e Add a unique identifying number to the names of the variables
Estimated hours taken: 0.1

polymorphism:
	Add a unique identifying number to the names of the variables
	holding typeinfos. This makes HLDS dumps easier to read.
1996-12-15 02:05:36 +00:00
Tyson Dowd
6c0d54b600 Fix a bug that caused the test case hard_coded/curry.m to fail when
Estimated hours taken: 0.75

Fix a bug that caused the test case hard_coded/curry.m to fail when
compiling with -O2, because of a link error.

compiler/polymorphism.m:
	Refer to unqualified pred/0 rather than mercury_builtin:pred/0
	since it is the former that is defined in mercury_builtin,
	and other builtins are treated this way.
1996-12-15 00:26:26 +00:00
Fergus Henderson
075f549b3a Add some missing determinism declarations.
Estimated hours taken: 0.25

code_info.m, polymorphism.m, saved_vars.m:
	Add some missing determinism declarations.
1996-12-09 08:01:09 +00:00
Zoltan Somogyi
ee24e66a71 Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5

Switch from using a stack of store_maps in the code_info to govern what
goes where at the end of each branched structure to using the store map
fields of the goal expressions of those structures.

Fix variable names where they resembled the wrong kind of map(var, lval).

code_info:
	Remove the operations on stacks of store maps.
	Modify the generate_forced_saves and remake_with_store_map operations
	to take a store_map parameter.

	When making variables magically live, pick random unused variables
	to hold them, since we can no longer use the guidance of the top
	store map stack entry. This may lead to the generation of some
	excess move instructions at non-reachable points in the code;
	this will be fixed later.

code_gen:
	Remove the store map push and pop invocations.
	Modify the generate_forced_goal operation to take a store_map parameter.

code_exprn:
	Export a predicate for use by code_info.

middle_rec, disj_gen, ite_gen, switch_gen,
dense_switch, lookup_switch, string_switch, tag_switch:
	Pass the store map around to get it to invocations of the primitives
	in code_gen and code_info that now need it.

goal_util:
	Name apart the new follow_vars field in hlds__goal_infos.
	(This should have been in the change that introduced that field.)

common, constraint, cse_detection, det_analysis, dnf, excess, follow_code,
intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism,
quantification, simplify, switch_detection, typecheck, unique_modes,
unused_args:
	Fix variable names.

follow_vars, store_alloc:
	Add comments.
1996-11-23 10:39:02 +00:00
Andrew Bromage
06e05928e1 Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38

Makes instmap and instmap_delta into ADTs.

compiler/code_gen.m:
compiler/code_info.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/dnf.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/store_alloc.m:
compiler/switch_detection.m:
compiler/transform.m:
compiler/uniq_modes.m:
compiler/unused_args.m:
	Miscellaneous minor changes to use the new instmap.m

compiler/constraint.m:
	Removed unnecessary duplication of code in constraint__checkpoint/4
	and constraint__no_output_vars/2.

compiler/det_util.m:
	Changed no_output_vars/4 to det_no_output_vars/4, moved body
	of code to instmap.m.

compiler/instmap.m:
	Added abstract types instmap/0, instmap_delta/0.

	Added predicates:
		instmap__init_reachable/1, instmap__init_unreachable/1,
		instmap_delta_init_reachable/1,
		instmap_delta_init_unreachable/1, instmap__is_reachable/1,
		instmap__is_unreachable/1, instmap_delta_is_reachable/1,
		instmap_delta_is_unreachable/1, instmap__from_assoc_list/2,
		instmap_delta_from_assoc_list/2, instmap__vars/2,
		instmap__vars_list/2, instmap_delta_changed_vars/2,
		instmap_delta_lookup_var/3, instmap__set/3,
		instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3,
		instmap_delta_restrict/3, instmap_delta_delete_vars/3,
		instmap__no_output_vars/4, instmap_delta_apply_sub/4,
		instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2.

	Renamed predicates:
		instmap__lookup_var/3 (was instmap_lookup_var/3)
		instmap__lookup_vars/3 (was instmap_lookup_vars/3)
		instmap__apply_instmap_delta/3 (was apply_instmap_delta/3)
		instmap__merge/5 (was instmap_merge/5)
		instmap__restrict/3 (was instmap_restrict/3)

	Moved predicates:
		merge_instmap_delta/5 (from mode_util.m)

	Removed predicates:
		instmapping_lookup_var/3

compiler/mode_util.m:
	Moved merge_instmap_delta/5 to instmap.m
1996-11-19 01:18:24 +00:00
Fergus Henderson
7a94ffc149 Fix some mistakes in the comments in my previous change.
Estimated hours taken: 0.25

compiler/polymorphism.m:
	Fix some mistakes in the comments in my previous change.
1996-11-12 02:06:34 +00:00
Fergus Henderson
c08bef0235 Fix a `map__lookup failed' error in which occurs
Estimated hours taken: 2

Fix a `map__lookup failed' error in which occurs
in polymorphism.m for third-order functions.

compiler/polymorphism.m:
	In polymorphism__make_var, when creating a type_info
	variable, check for higher-order types such as
	`func(...) = ...' and handle them specially, rather
	than attempting to look up the (bogus) type '='/2.
1996-11-11 14:57:11 +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
Zoltan Somogyi
9d14c35534 Since NU-Prolog hasn't been capable of executing the compiler for a long time
Estimated hours taken: 1

Since NU-Prolog hasn't been capable of executing the compiler for a long time
now, I have removed the .pp files and replaced them with .m files.

code_gen, mercury_compile, optimize:
	Remove NU-Prolog specific code.

Mmake:
	Don't refer to the .pp files.

dnf:
	Add the capability of transforming all procedures regardless of
	markers. This will be useful when generating idiomatic Prolog code.

mercury_to_goedel, polymorphism:
	Fix comments.
1996-10-28 02:08:24 +00:00
Zoltan Somogyi
86eec52028 Fix the printing of comments by adding a newline at the end.
Estimated hours taken: 2

llds_out:
	Fix the printing of comments by adding a newline at the end.
	The bug only occurred when --auto-comments was given.

middle_rec:
	Under certain rare circumstances, middle_rec could generate code
	that had two copies of some labels. This fix prevents that problem.

polymorphism:
	Put back part of Simon's last change that I accidentally omitted
	earlier. The symptom fixed by this change is an internal error
	in dumping HLDS after the polymorphism stage due to a qualified
	function symbol the dumping code can't handle.
1996-10-23 13:35:42 +00:00
Zoltan Somogyi
6fab99c179 Depending on option settings, generate code that uses the new
Estimated hours taken: 15

polymorphism.m:
	Depending on option settings, generate code that uses the new
	one-or-two-cell representation of typeinfos.

base_type_info.m:
	Generate the base_type_info structures used by the new representation.

dead_proc_elim.m:
	Handle base_gen_infos (a HLDS-level representation of base_type_info
	structures) the same way as predicates. They may be exported (if their
	type is), so if they point to a procedure that procedure must not be
	eliminated, but base_gen_infos that are not exported or otherwise
	needed should themselves be eliminated.

inlining.m:
	Accommodate the changed data structure used by dead_proc_elim.m.

make_tags.m:
	Avoid applying the no_tag optimization to the functor base_type_info/1
	as well as type_info/1 (since both lie about their arity).

mercury_compile.pp:
	Call base_type_info.m to generate first base_gen_infos and then
	base_type_infos.
1996-10-18 10:04:05 +00:00
Andrew Bromage
5c149e55b2 Mode analyser reorganisation.
Estimated hours taken: 20

Mode analyser reorganisation.

compiler/mode_util.m:
	Removed: instmap_init/1,  apply_instmap_delta/3, instmap_lookup_var/3,
	instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
	moved to instmap.m).

compiler/hlds_goal.m:
	Removed the declarations of instmap_delta, instmap and instmapping.

compiler/mode_errors.m:
	Added report_mode_errors/2 (was modecheck_report_errors, from
	modes.m).

compiler/modes.m:
	Predicates now exported:
		modecheck_goal/4
		modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
		handle_extra_goals/8
		mode_context_to_unify_context/3

	Moved to mode_errors.m:
		modecheck_report_errors/2

	Moved to instmap.m:
		compute_instmap_delta/4
		instmap_merge/3
		instmap_lookup_vars (was instmap_lookup_arg_list/3)
		compute_instmap_delta/4

	Moved to mode_debug.m:
		Type port/0
		mode_checkpoint/4

	Moved to modecheck_call.m:
		modecheck_call_pred/7
		modecheck_higher_order_call/10
		modecheck_higher_order_pred_call/4
		modecheck_higher_order_func_call/7

	Moved to modecheck_unify.m:
		modecheck_unification/9
		categorize_unify_var_var/12
		categorize_unify_var_functor/11
		categorize_unify_var_lambda/9

	Moved to mode_info.m:
		mode_info_error/4
		mode_info_add_error/3

compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
	Imported instmap.m

New files:

compiler/instmap.m:
	Handle operations associated with instmaps.

compiler/modecheck_unify.m:
	Handle mode checking of unifications.

compiler/modecheck_call.m:
	Handle mode checking of calls

compiler/mode_debug.m:
        Code to trace the actions of the mode checker.
1996-10-17 05:28:01 +00:00
Simon Taylor
0d4a24ce0f Some fixes Fergus suggested for my previous sets of changes.
Estimated hours taken: 3

Some fixes Fergus suggested for my previous sets of changes.
Give error messages for circular equivalence types.

compiler/equiv_type.m
	Detect and report circular equivalence types.
	Previously the unification preds for circular equivalence
	types looped.

compiler/typecheck.m
	Fixed printing of constants in write_functor_name
		- foo instead of foo/0

compiler/code_aux.m
	Undid my previous change to code_aux__contains_only_builtins,
	which made the code less general than it could be.

compiler/inlining.m
	Changed inlining__simple_goal to disregard complicated_unify.

compiler/polymorphism.m
	Make sure bound insts are not module qualified.
1996-10-11 04:56:19 +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
Zoltan Somogyi
8bd1aaa9de Rename address_const to code_addr_const, and add base_type_info_const
Estimated hours taken: 15

hlds_data:
	Rename address_const to code_addr_const, and add base_type_info_const
	as a new alternative in cons_id, and make corresponding changes
	to cons_tag.

	Make hlds_type__defn an abstract type.

llds:
	Rename address_const to code_addr_const, and add data_addr_const
	as a new alternative in rval_const.

	Change type "label" to have four alternatives, not three:
	local/2 (for internal labels),  c_local (local to a C module),
	local/1 (local a Mercury module but not necessarily to a C module,
	and exported.

llds_out:
	Keep track of the things declared previously, and don't declare them
	again unnecessarily. Associate indentation with the following item
	rather than the previous item (the influence of 244); this results
	in braces being put in different places than previously, but should be
	easier to maintain. Handle the new forms of addresses and labels.
	Refer to c_local labels as STATIC when not using --split-c-files.

code_info:
	Use a presently junk field to store a cell counter, which is used
	to allocate distinguishing numbers to create'd cells. Previously
	we used the label counter, which meant that label numbers changed
	when we optimized away some creates. Handle the new forms of
	addresses and labels.

exprn_aux:
	Handle the new forms of addresses and labels. We are now more
	precise in figuring out what label address forms will be considered
	constants by the C compilers.

others:
	Changes to handle the new forms of addresses and labels, and/or to
	access hlds_type__defn as an abstract type.
1996-08-05 12:05:14 +00:00