Commit Graph

153 Commits

Author SHA1 Message Date
Mark Brown
3fc6b3f128 Change the representation of types in the compiler.
Estimated hours taken: 30
Branches: main

Change the representation of types in the compiler.

We also add some support for handling kinds, which will be used later when we
have a kind system.  There are a number of places where kinds are not yet
handled correctly -- we assume that all kinds will be `star'.  Each of these
locations is flagged with a comment that contains "XXX kind inference:".


compiler/prog_data.m:
	Implement the new version of type (type).

	Change the definition of type_param to be a variable instead of a
	term, since all parameters must be variables anyway.

	Implement versions of varset.merge_* which work with tvarsets and
	produce renamings instead of substitutions.  Renamings are more
	convenient than substitutions because we don't need to know the
	kinds of type variables in order to build the renaming, and in any
	case the substitutions shouldn't have anything other than variables
	in the range so renamings will be more efficient and safe.

	Define the type of kinds, and provide a couple of utility predicates
	to operate on them.

compiler/prog_io.m:
	Parse type definition heads as a sym_name and list of type_params,
	rather than a functor.  Handle this change in other predicates.

	Allow parse errors to be returned by get_with_type/3, and handle
	these errors.

	Remove parse_type/2.  This predicate didn't do any processing, it
	just forwarded handling to convert_type/2.

compiler/prog_io_typeclass.m:
	Change type_is_functor_and_vars to handle the new representation
	of types.  In doing so, we retain the old behaviour that pure
	predicates pass this test, but no other pred or func types.  This
	behaviour is arguably incorrect, but there is little point changing
	the behaviour at the moment.  Instead we should remove these kind of
	restrictions entirely, but that should be done later.

compiler/prog_io_util.m:
	Provide predicates to both parse and unparse types.  We need to
	unparse types before printing them out, since we do a lot of special
	case handling when printing out terms and we don't want to duplicate
	this functionality for types.

compiler/module_qual.m:
	Remove report_invalid_type.  We now report ill-formed types during
	parsing.

compiler/superhomogeneous.m:
	Handle errors from the parsing of type expressions.

compiler/prog_out.m:
	Provide a predicate to convert builtin_types to their string names,
	and vice-versa.

compiler/prog_type.m:
	Add a bunch of simple tests to use on types which may have kind
	annotations present.  In such cases, types do not have a canonical
	representation so the simple handling of these tests is not what we
	want.  (Note that these are only required in early phases.  The kind
	annotations -- when they are implemented -- will be removed before
	type checking.)

	Consistently handle the application of renamings, substitutions and
	recursive substitutions to various data structures.

compiler/mercury_to_mercury.m:
	Implement mercury_output_type, mercury_format_type and
	mercury_type_to_string.  These convert the type to a term before
	formatting -- the reason for this is so that appropriate parentheses
	are used when formatting operators.  This results in some slight
	changes to error messages, which are reflected in changes to the
	expected output files in the tests.

	Remove the old version of mercury_type_to_string.

	Change the argument ordering of mercury_format_var to be consistent
	with mercury_format_type.  (Other predicates in this module should
	probably be changed in a similar way, since this argument ordering
	is more amenable to higher-order programming.  But that can be left
	for another change.)

compiler/type_util.m:
	Implement type unification.  The behaviour is much the same as the
	previous behaviour, except that we now handle apply/N types properly,
	and we also allow for kind annotations.

	Implement an occurs check for types.

	Remove the example definition of replace_eqv_type.  It isn't used and
	would no longer work anyway even if it would have worked before.

	Add a tvar_kind_map field to ctor_defn.

	The functions type_info_type and type_ctor_info_type now return
	types with `void' as their argument, rather than the type that the
	type_info or type_ctor_info was for.

	Remove type_util.real_vars/2, since it no longer does anything
	different from prog_type.vars/2.

	Remove the commented out implementation of type_to_ctor_and_args/3.
	Its implementation is in prog_type.m, and has changed significantly
	in any case.

compiler/add_clause.m:
	Move parse_purity_annotation/3 to prog_io_util.m.

compiler/check_typeclass.m:
	Remove apply_substitution_to_var_list/3, since we now have predicates
	in prog_type.m to handle such things.

compiler/continuation_info.m:
compiler/trace.m:
	Use prog_type.vars/2 instead of type_util.real_vars/2.  The two
	predicates have the same meaning now since type_infos don't contain
	any type variables.

compiler/hlds_data.m:
	Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn.

compiler/hlds_pred.m:
	Add a tvar_kind_map field to pred_info.

compiler/polymorphism.m:
	Add a tvar_kind_map field to poly_info.

	Remove unify_corresponding_types, which is no longer used.

compiler/hlds_out.m:
	Use mercury_output_type/5 instead of term_io__write_term/4 and
	mercury_output_term/5.

compiler/post_typecheck.m:
	Build the void substitution directly rather than building intermediate
	lists.

compiler/recompilation.version.m:
	Use term__list_subsumes instead of type_list_subsumes, which now
	operates only on types.  This follows up on what was suggested in
	an XXX comment.

compiler/typecheck_errors.m:
	Use unparse_type/2 to format error messages.

compiler/typecheck_info.m:
	Don't export write_type_with_bindings/5.  It is no longer used
	outside of this module.

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

library/rtti_implementation.m:
	Fix a syntax error that went undetected in our previous
	implementation, and amazingly enough was compiled correctly anyway.

library/term.m:
	Move the versions of term__unify, term__unify_list and
	term__list_subsumes that were implemented specifically for types
	to here.  The version of term_unify that takes a list of bound
	variables (i.e., variables that should not be bound any further)
	is used by the subsumption check, which in turn is used by
	recompilation.version.m.

tests/invalid/kind.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/misc_tests/pretty_print_test.exp:
	Update the expected output of these tests to match what we now do.
2005-09-12 05:25:01 +00:00
Zoltan Somogyi
10536c5ee0 Divide make_hlds.m into submodules of manageable size.
Estimated hours taken: 12
Branches: main

Divide make_hlds.m into submodules of manageable size.

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

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

compiler/add_class.m:
	Submodule for handling typeclasses.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

compiler/notes/compiler_design.html:
	Describe the new modules.
2005-07-26 01:56:30 +00:00
Mark Brown
38d9ef3479 Package the type_info_varmap and typeclass_info_varmap types into an ADT
Estimated hours taken: 25
Branches: main

Package the type_info_varmap and typeclass_info_varmap types into an ADT
called rtti_varmaps.  There are two main purposes for this:

	- We wish to extend this set of maps with new maps.  Doing this
	will be a lot easier and less error prone if all of the maps are
	packaged in a single data structure.

	- Any new maps that we add may contain redundant information that
	just makes searching the maps more efficient.  Therefore they must
	be kept consistent with the existing maps.  Having all the maps
	inside an ADT makes it easier to ensure this.

This change also includes two extensions to the maps.  First, the
typeclass_info_map is made reversible so that it is possible to efficiently
look up the constraint for a given typeclass_info variable.  Second, a new
map from prog_vars to types makes it possible to efficiently look up the
type that a given type_info variable is for.  These two changes mean that
it is no longer necessary to consult the argument of type_info/1 or
typeclass_info/1 to find this information.  (We still do put that information
there, though; changing the RTTI is left for a separate change.)

compiler/hlds_pred.m:
	Move items relating to type_infos and typeclass_infos into a section
	of their own.

	Add a type `rtti_var_info' to hold information about the contents
	of a type_info or typeclass_info variable.

	Define the rtti_varmaps abstract data type.  This data structure
	consists of the type_info_varmap and the typeclass_info_varmap.
	Add a new map, type_info_type_map, which is like the inverse
	to the type_info_varmap.  The difference is that the latter can
	point to locations that are inside a typeclass_info variable,
	whereas the former only refers to type_info variables.  Note that
	the combined maps do not form a bijection, or even an injection,
	since it is possible for two different type variables to point to
	the same location (that is, if they are aliased).

	Make the typeclass_info_varmap reversible, by using the new module
	injection.m.  Unlike the type_info_varmap, this map is always
	injective since the same typeclass_info cannot be used for two
	different constraints.

	The predicates rtti_det_insert_type_info_locn and set_type_info_locn,
	which update the type_info_varmap, contain sanity checks to ensure
	that only type variables that have already been registered with
	the type_info_type_map are used, and that the information in both
	maps is consistent.

	Use the rtti_varmaps structure in proc_info and clauses_info, in
	place of type_info_varmap and typeclass_info_varmap.

compiler/polymorphism.m:
	Remove polymorphism__type_info_or_ctor_type/2 and
	polymorphism__typeclass_info_class_constraint/2, to ensure that
	nobody tries to use the information in the type argument.  Replace
	them with two similar predicates that test if a type is type_info
	or typeclass_info, but that don't return the argument.

	Ensure that the new type_info_type_map in the rtti_varmaps is kept
	up to date by threading the rtti_varmaps through a few more places.
	Some of these places are exported, so this part of the change
	affects other modules as well.

	Fix a comment that referred to a non-existent predicate.

compiler/type_util.m:
	Remove the predicates apply_substitutions_to_var_map/5 and
	apply_substitutions_to_typeclass_var_map/5.  The functionality
	is now provided by the new ADT.

compiler/cse_detection.m:
	Rewrite update_existential_data_structures/4 to use the interface
	provided by rtti_varmaps.  The algorithm for doing this has changed
	in the following ways:

		- The first pass, which builds a map from changed locations
		in the first branch to the tvars concerned, is modified
		slightly to traverse over the keys instead of over key-value
		pairs.

		- The second pass, which previously calculated the induced
		type substitution and reconstructed the type_info_varmap
		now only does the former.

		- Applying the prog_var transformation and the induced type
		substitution is done at the end, using the interface to
		rtti_varmaps.

compiler/goal_util.m:
	Rewrite goal_util__extra_nonlocal_typeinfos/6 to avoid the need
	for using map__member/3 on the typeclass_info_varmap (about which
	the existing comments say "this is probably not very efficient..."),
	and to be more efficient in general.

	Previously, we nondeterministically generated non-local type vars
	and then tested each constraint to see if it had the type var in it.
	Now, we go through each constraint one at a time and check if any of
	the type variables in it are non-local.  This is more efficient
	because we only need to find one non-local type in order to include
	the typeclass_info in the non-locals -- the remaining (duplicate)
	solutions are pruned away.

compiler/higher_order.m:
	Use the new maps instead of looking at the arguments of type_info/1
	and typeclass_info/1 types.  We plan to remove this information
	from type_info and typeclass_info types in future.

	Previously, this module used the type argument in order to update
	the varmaps when the curried arguments of a higher order call are
	added as arguments to the procedure in which the call occurs.
	We now look up this information at the point where the curried arg
	variables are known, and store this information in higher_order_arg
	alongside the types where it used to be stored.  This structure is
	threaded through to the place where the information is needed.

	Fix a cut and paste bug in higher_order_arg_depth/1.  It was
	previously calling higher_order_args_size/1 in the recursive
	call, instead of calling higher_order_args_depth/1.

compiler/inlining.m:
	In inlining__do_inline_call, apply the substitutions to the entire
	rtti_varmaps structure, not just to the type_info_varmap.  (XXX Is
	there a good reason why the substitution should _not_ be applied
	to the typeclass_info varmap?)

compiler/magic_util.m:
	Avoid using polymorphism__type_info_or_ctor_type/2 and
	polymorphism__typeclass_info_class_constraint/2, as these are
	no longer supported.

compiler/*.m:
	Straightforward changes to use the new ADT.

library/injection.m:
	New library module.  This provides an `injection' type which is
	similar to the existing `bimap' type in that it implements
	back-to-back maps, but doesn't have such stringent invariants
	imposed.  In particular, the reverse map is not required to be
	injective.

	This type is used to model the relationship between prog_constraints
	and program variables that hold typeclass_infos for them.  Namely,
	the typeclass_info for a constraint can be held in two different
	variables, but one variable can never hold the typeclass_info for
	two distinct constraints.

library/library.m:
	Add the new library module.

library/list.m:
	Add list__foldl_corresponding and list__foldl2_corresponding, which
	traverse two lists in parallel, which one or two accumulators, and
	abort if there is a length mismatch.

NEWS:
	Mention the changes to the standard library.
2005-07-22 12:32:07 +00:00
Mark Brown
d075d35702 Implement functional dependencies for the typeclass system.
Estimated hours taken: 240
Branches: main

Implement functional dependencies for the typeclass system.  The implementation
has two major parts.  First, some of the basic checks of constraints are
relaxed.  These used to occur in make_hlds but that functionality has now been
moved to check_typeclass.  We also add a range of new tests to ensure that
the FDs are used correctly.  Second, an "improvement" pass to context
reduction is added.  This looks for constraints which match certain rules,
and when it finds them updates the current bindings.  The general rule is
that type variables become more instantiated, but only in a way which provably
does not affect the satisfiability of the constraints.

XXX The plan for this change is to put the context reduction into a new
module check_hlds.typeclasses.m, but I have left the code in typecheck.m
for the moment because the diff will be easier to review that way.  Moving
to the new module will also remove the problem of one particular function
being implemented in both typecheck and hlds_data, which is flagged by an XXX
in the code.

XXX the check for consistency of instances is not yet complete.  We check all
visible instances, but not instances that are only present at link time.  We
could check these in a similar way to the check for overlapping instances
(that is, by defining a symbol that will conflict and cause a link error
if there are overlapping instances), but in the long run a better solution
will be required.  Producing this is left for a later change.

compiler/check_typeclass.m:
	Check for ambiguities in typeclass constraints here, rather than
	make_hlds.  We check by calculating the closure of the bound type
	variables under the induced functional dependencies.  This pass
	is merged in with the already existing pass that checks the
	quantifiers on constrained type variables.

	Check instances for range-restrictedness and for consistency.

	When checking for cycles in the typeclass hierarchy, build up the
	set of ancestors of a class which have FDs on them.  This set is
	used when searching for opportunities to apply improvement rules
	during type checking.

compiler/hlds_data.m:
	Define hlds_class_fundeps and add it to to hlds_class_defn.

	Add a field to hlds_class_defn to store the ancestors which have
	functional dependencies.

	Define the type 'instance_id', which is just an integer.  This is
	what is used in proofs to identify instances.

	In hlds_constraints and in constraint_ids, use the terms 'assumed'
	and 'unproven' rather than 'existential' and 'universal'.  The latter
	are confusing to use since the treatment of constraints differs
	depending on whether the constraint is on the head or the body of a
	clause.

	Add a field to the hlds_constraints for redundant constraints.  These
	are constraints that have either already been reduced or don't need to
	be reduced, which may contribute to improvement of types.

	Define some new predicates for initialising and updating the
	hlds_constraints.

compiler/type_util.m:
	Accommodate the change to hlds_constraints.

compiler/hlds_out.m:
	Output the functional dependencies.

compiler/intermod.m:
	Reconstruct a functional dependency from the HLDS, for outputting.

compiler/make_hlds.m:
	Convert functional dependencies from parse tree form and add them
	to the HLDS.

	Check that functional dependencies are identical in subsequent
	definitions of the same typeclass.

	Don't check for ambiguity here.  That is now done in check_typeclass.

compiler/mercury_to_mercury.m:
	Output functional dependencies in typeclass declarations.

compiler/prog_data.m:
	Define prog_fundeps and add them to the parse tree.

compiler/prog_io_typeclass.m:
	Parse functional dependencies on typeclass declarations.

compiler/typecheck.m:
	Require the class_table to be passed to
	reduce_context_by_rule_application, since the functional dependencies
	are stored here.  Also thread the bindings argument through, since the
	bindings may be improved by context reduction.  Save the resulting
	bindings in the type_assign.

	Instead of passing a list of assumed constraints and threading the
	unproven constraints through context reduction, thread through a
	hlds_constraints structure.  This contains more information about
	redundant constraints than just the two lists.

	Extend context reduction with two new passes.  The first applies the
	"class" FD rule, which tries to find two constraints which are
	identical on the domain of some FD, and then unifies the range
	arguments.  The pair of constraints are either both redundant
	constraints, or one redundant constraint and one assumed constraint.
	The second applies the "instance" FD rule, which for each constraint
	tries to find an instance which is more general on the domain
	arguments.  It then binds the instance arguments and unifies the
	range arguments of the instance with those of the constraint.

	When calculating the head_type_params for a predicate, include all
	variables that occur in universal constraints, since these may not
	necessarily occur in the arguments.

	Rename some variables: use variable prefixes "Pred" and "Parent" for
	types that are from the callee or that have been renamed apart
	respectively.  This follows the same naming scheme used in
	polymorphism.

	Remove the headtypes/0 type, and use head_type_params/0 throughout.

	Add a new kind of cons_error for using "new" on a constructor that is
	not existentially typed.  We check for this situation in
	convert_cons_defn, and report it in report_cons_error.

	Pass a value to convert_cons_defn indicating whether the constraints
	should be flipped or not, and whether the context is a constructor
	that uses 'new'.  We flip the constraints here rather than after the
	fact, since creating the constraints now requires some extra
	processing to be done, and we don't want to have to redo that
	processing.

	Add a constant function that specifies whether variable numbers should
	be displayed as part of the debugging output.  This is currently set
	to 'yes' but the previous behaviour can be achieved by changing the
	value to 'no'.

doc/reference_manual.texi:
	Document the new feature.

NEWS:
	Announce the new feature.

tests/*:
	New test cases.

compler/*.m:
	Minor changes related to the above.

compiler/error_util.m:
	Fix comment grammar.

compiler/prog_type.m:
	Fix an incorrect comment.
2005-04-20 12:57:59 +00:00
Mark Brown
4427723508 Remove the assumption made by polymorphism.m that all type variables
Estimated hours taken: 240
Branches: main

Remove the assumption made by polymorphism.m that all type variables
appearing in class constraints also appear in the type being constrained.
This is a first step towards adding functional dependencies, since in the
presence of functional dependencies (or "improvement" in general) this
assumption no longer holds.

The assumption made by polymorphism manifests itself in the fact that
constraints on atomic goals are reconstructed by unifying the types of
formal parameters with the types of actual arguments, and then applying
the resulting substitution to the constraints.  Any type variables in
constraints that don't appear in the formal parameters will therefore
remain unbound.

This change overcomes the assumption by building up a map from constraint
identifiers to constraints during typechecking, and then looking up this
map in order to reconstruct the constraint during the polymorphism
transformation.

To support this, the type 'class_constraint' has been removed and replaced
by two distinct types, 'prog_constraint' and 'hlds_constraint'.  The former
is part of the parse tree and holds the same information as the old
class_constraint.  The latter is part of the HLDS, and is used during
typechecking; in addition to the information in prog_constraints, it also
stores a set of identifiers that represent where the constraint came from.
These identifiers are used as the keys in the aforementioned map.

At this stage the constraint identifiers are only used by typechecking to
build the constraint map.  Other passes use either prog_constraints or
hlds_constraints with an empty set of identifiers.

compiler/hlds_data.m:
	Define the constraint_id type, which is used to uniquely identify
	class constraints.  A better scheme than this one has been suggested,
	but that will be left to a later change.  An XXX comment to that
	effect has been added.

	Define the hlds_constraint type, which is like prog_constraint but
	it also includes a set of constraint_ids.  Define a set of predicates
	to initialise and manipulate these.

	Define the constraint_map type here.  Move the definition of
	constraint_proof_map to here, where it more sensibly belongs.

	Update the comments in hlds_instance_defn slightly, with information
	that I found I needed to know when making this change.

compiler/hlds_pred.m:
	Add a field to the pred_info to store the constraint_map.

	Move the definition of constraint_proof_map from here.

compiler/hlds_out.m:
	Print out a representation of the constraint map if it isn't empty.

compiler/type_util.m:
	Change the predicates that used to operate on class_constraints so
	that they now operate on hlds_constraints.  The old versions of these
	predicates have now moved to prog_util.

	Add some utility predicates to manipulate constraint_maps.

	Add a predicate to apply a variable renaming to constraint_proof_maps.

compiler/prog_data.m:
	Rename class_constraint(s) to prog_constraint(s).

compiler/prog_util.m:
	Provide a set of predicates for manipulating prog_constraints.

compiler/typecheck.m:
	Ensure that goal_paths are filled in before the first iteration
	of typechecking.

	Pass the hlds_goal_info down through typecheck_goal_2 so that the
	goal_path can be retrieved when needed to assign identifiers to
	constraints.  Thread the goal_path through to wherever it is needed.

	Store hlds_constraints in the args_type_assign rather than
	prog_constraints, so that the required information is available
	when creating the new set of type_assigns.  Do likewise for the
	cons_type_info type.  Don't pass the module_info through
	make_pred_cons_info*, since it isn't used.  Do pass the goal_path,
	though, so that constraints in cons_type_infos can be given the
	correct identifier.

	Add a constraint_map field to the typecheck_info, initialised to empty.

	When retrieving the final information from a typecheck_info, return
	the resulting constraint_map, after applying any type bindings.
	Ensure that any constraints that may not have been entered into the
	constraint_map are put there now.  Call the new predicate in type_util
	to rename the constraint_proof_map, rather than doing it longhand
	here.

	Make the following changes to context reduction:

		- Thread the constraint_map through, so that it can be updated
		as constraints are eliminated.

		- Instead of simply calling sort_and_remove_dups on the
		set of constraints remaining after one iteration, merge the
		constraints in such a way that the complete set of
		constraint_ids is retained.

		- Disregard the constraint_ids when deleting newly introduced
		constraints that are equivalent to constraints that have
		already been seen.

		- Simplify the code of find_matching_instance_rule_2 by
		moving the deterministic code out of the condition of the
		if-then-else.

	Move find_first_map into the library.

compiler/polymorphism.m:
	Ensure that the goal_path is set when constructing lambda goals.

	In process_call, look up the constraints in the constraint_map
	using the goal_path as part of the key, rather than calculating
	the constraints by applying the ParentToActual type substitution.
	Rearrange this code so that it is divided into easier to understand
	blocks.

	Add a field to the poly_info to store the constraint_map, and
	initialise it from the pred_info.

compiler/goal_path.m:
	Fill slots in lambda_goals, since constraints inside these will
	otherwise not be identified properly.  The goal_paths inside here
	do not entirely make sense, since there is no goal_path_step for
	the lambda_goal itself.  However, there is enough information
	retained to distinguish these goal_paths from any other possible
	goal_path, which is all that we require to identify constraints.

	Add a warning not to fill in the goal slots between the typechecking
	and polymorphism passes, since doing so could potentially render the
	constraint_maps incorrect.

compiler/make_hlds.m:
	Initialise the constraint_map to empty in pred_infos.

	Move the code for updating the superclass_table into a separate
	predicate.  Initially this change was made because, in an earlier
	version of the change, the superclass_table had some extra
	information that needed to be filled in.  That part of the change
	is not needed in this diff, but the new predicate simplifies the
	code a bit so I've left it there.

compiler/check_typeclass.m:
	Convert the prog_constraints into hlds_constraints before passing
	them to typecheck.reduce_context_by_rule_application.  They are
	assigned no identifiers, since these constraints are not required
	to be put into the constraint map.

	Change the name of the function get_constraint_id to
	get_constraint_class_id, since it would now be ambiguous otherwise.

compiler/cse_detection.m:
	Import parse_tree__prog_util, since that is where renamings of
	prog_constraints are now defined.

compiler/higher_order.m:
	Initialise pred_infos here with an empty constraint_map.

compiler/post_typecheck.m:
	When binding type vars to void, apply the void substitution to the
	constraint_map.

compiler/table_gen.m:
	Pass the constraint_map when creating a new pred_info.

compiler/unused_args.m:
	Create the pred_info with an empty constraint_map.  The constraint_map
	won't be used by this stage anyway.

compiler/*.m:
	Update to use the new type names.  Also update to use the existing
	type synonyms typeclass_info_varmap and constraint_proof_map.

	Change names of predicates and functions to use prog_constraint
	instead of class_constraint, where applicable.

library/list.m:
	Add find_first_map from typecheck.  Also add find_first_map{2,3},
	since at one stage during development I needed find_first_map3, and,
	although it's not used in the current diff, there is little point
	removing it now.
2005-04-01 14:29:19 +00:00
Zoltan Somogyi
3c60c0e485 Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Change a bunch of modules to import only one module per line, even
	from the library.

compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
	Convert these modules to our current coding style. Use state variables
	where appropriate. Use predmode declarations where possible.
2005-03-22 06:40:32 +00:00
Julien Fischer
a3352a6e5d Do not include :- import_module' and :- use_module' declarations
Estimated hours taken: 22
Branches: main

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

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

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

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

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

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

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

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

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

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

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

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

compiler/parse_tree.m:
	Include the new module.

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

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

compiler/notes/compiler_design.html:
	Mention the new module.
2005-01-21 03:27:58 +00:00
Peter Wang
59d2d4a573 This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17
Branches: main

This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.

As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module.  This required bringing some types from the
compiler into a new module within mdbcomp.

browser/trace_counts.m:
	New module for reading execution trace summaries.

browser/prim_data.m:
	New module holding types and predicates moved in from the compiler.
	Types:
		pred_or_func, sym_name, module_name, proc_label,
		special_pred_id, trace_port
	Predicates:
		string_to_sym_name, insert_module_qualifier

	The mode field of proc_label is now an int instead of a proc_id
	to avoid pulling proc_id into mdbcomp.

browser/mdbcomp.m:
	Add trace_counts and prim_data to the mdbcomp module.

browser/declarative_execution.m:
	Renamed mdb's definition of module_name to flat_module_name
	to avoid conflicts with the definition in mdbcomp__prim_data.

runtime/mercury_trace_base.c:
	In the format of .mercury_trace_counts, write module and predicate
	names now use quoted atom syntax so that names with spaces and
	non-printable characters can be machine-parsed.

browser/:
compiler/:
	Many changes to account for movement of types, and the change to
	proc_label.
2005-01-19 03:11:22 +00:00
Ralph Becket
1067d612d2 Extend the solver types implementation to handle abstract equivalence solver
Estimated hours taken: 180
Branches: main

Extend the solver types implementation to handle abstract equivalence solver
types.

Fix the automatic initialisation of variables with solver types in atomic
goals not in conjunctions.

Fix the automatic initialisation of variables with solver types with type
parameters (previously we were not inserting the necessary type_info
arguments.)

Add the modes ia and oa for in(any) and out(any) as built-ins.

Correct the solver types documentation to reflect the fact that any \= ground
for non-solver types.

doc/reference_manual.texi:
	Previously the documentation stated that inst any was equivalent to
	inst ground for non-solver types.  This is not correct: an (ordinary)
	list of inst any solver type values, for example, may not be
	semantically ground and therefore must have any as (some component of)
	its inst.

	Document the addition of built-in modes ia and oa.

library/builtin.m:
	Added modes ia and oa as synonyms for in(any) and out(any),
	respectively.

compiler/goal_util.m:
	Add a version of goal_util__generate_unsafe_cast with two
	extra inst parameters (needed because solver types
	typically have inst any rather than ground).

compiler/make_hlds.m:
	Fix a bug whereby the declarations for the initialisation special
	preds for imported types were being module qualified using the name of
	the *importing* module.  This turns out to be correct for unification
	and comparison predicates because they are duplicated in every module
	that needs them, but not for solver type initialisation predicates.

compiler/modes.m:
	Export modes__construct_initialisation_call which is now
	also called from unify_proc.m.

	Fix a misleading compiler error message.

	Rearrange some comments for accuracy.

	Scheduling of conjunctions now handles the mode_info flag
	may_initialise_solver_vars slightly differently to support the
	initialisation of free solver vars in atomic goals not appearing
	in conjunctions.

	construct_initialisation_call(s) and prepend_initialisation_call now
	change the mode_info (and thus does not need the module_info).

	construct_initialisation_call and build_call are now much more
	careful about setting up goal_infos, vartypes and instmap_deltas
	correctly.

compiler/modecheck_call.m:
	Ensure that modecheck_end_of_call properly restores the
	mode_info may_initialise_solver_vars flag before returning.

compiler/modecheck_unify.m:
	Arrange for one of the solver vars to be initialised in free/free
	unifications if mode_info_may_initialise_solver_vars is set.

	XXX Var/functor unification still needs fixing.

compiler/mode_info.m:
	Added mode_info_get_may_initialise_solver_vars.
	mode_infos are now initialised to have the may_initialise_solver_vars
	flag set to yes in order to allow the initialisation of solver type
	goals not appearing in conjunctions.  Conjunctions temporarily set
	this flag to no to try scheduling without inserting initialisation
	calls.

compiler/polymorphism.m:
	Add new exported pred, process_new_call.  This predicate takes
	the details about a call to be inserted somewhere after the
	usual polymorphism pass has been run and extends the call with
	the goals and extra arguments to construct and pass any
	required type_infos.

	XXX This predicate does not yet handle calls whose arguments include
	existentially quantified types or type class constraints.

compiler/type_util.m:
	A type that is equivalent to a solver type is now also considered
	a solver type.

compiler/unify_proc.m:
	The compiler generated initialisation predicate for an abstract
	equivalence solver type first calls the initialisation predicate
	for the RHS of the type equivalence, then casts the result back
	into the type on the LHS of the type equivalence.
2004-12-23 04:52:30 +00:00
Julien Fischer
980afa90c5 Add an analysis that tries to identify those procedures
Estimated hours taken: 70
Branches: main

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

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

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

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

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

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

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

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

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

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

compiler/exception_analysis.m:
	The new analysis.

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

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

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

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

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

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

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

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

tests/term/Mercury.options:
tests/term/Mmakefile:
tests/term/exception_analysis_test.m:
tests/term/exception_analysis_test.trans_opt_exp:
	Add a test for the new analysis.
2004-10-16 15:08:55 +00:00
Ralph Becket
f8312974e4 Bugfixes (mostly) related to the recent solver types changes.
Estimated hours taken: 3
Branches: main

Bugfixes (mostly) related to the recent solver types changes.

compiler/type_util.m:
	Having the compiler assume that type variables denote solver types
	causes the compiler to throw an exception when it tries to compile the
	initialisation forwarding predicate for exported abstract type foo(T)
	defined as foo(T) == T.

	The right solution at some point is to introduce a solver type class.

	type_util__is_solver_type no longer assumes that type variables
	denote solver types.

compiler/prog_io.m:
	Fixed a bug in make_maybe_where_details where a solver type without
	user defined equality or comparison would get a
	`yes(unify_compare(no, no))' result rather than just `no'.

tests/invalid/partial_implied_mode.err_exp2:
	Copy of partial_implied_mode.err_exp, but with different temporary
	variable names in the expected compiler errors.

tests/invalid/any_mode.m:
tests/invalid/any_mode.err_exp:
tests/invalid/any_should_not_match_bound.m:
tests/invalid/any_should_not_match_bound.err_exp:
	Updated code and expected error.

tests/misc_tests/pretty_print_test.exp:
	Corrected expected error.
2004-09-10 03:50:30 +00:00
Ralph Becket
bf2e37d199 Implemented the solver types design.
Estimated hours taken: 100s
Branches: main

Implemented the solver types design.

Solver types provide the means for adding constrained types to Mercury
programs.  A variable of a constrained type may have constraints placed
on it, limiting the values it may be bound to, *before* the variable is
actually bound to a particular value (cf. CLP(Z), CLP(R), CLP(FD) etc.)

Improve the scheduling of solver type goals by preferring deconstructions
over constructions followed by unifications.  This is arranged by allowing
solver type initialisation calls to be inserted only when all else fails.
(XXX This implementation is O(n^2).  I will fix things if this becomes an
issue in practice.)

I have also made some small, opportunistic cosmetic changes.  This
implementation has evolved through several design changes, during which some
functionality was added then later removed - I elected to preserve any
cleaned-up replacement code if removing the no-longer-needed-by-the-
solver-types-design functionality was easy to do.

doc/reference_manual.texi:
	Document solver types.

compiler/hlds_data.m:
	Changed the du_type and foreign_type constructors appropriately
	and added a new solver_type constructor.

compiler/hlds_out.m:
	Improved the code to write out the `where ...' part of
	a type definition and moved it to mercury_output.m.

compiler/inst_match.m:
	Added the pred inst_is_any/1.

compiler/inst_util.m:
	Added the pred inst_contains_unconstrained_var/1.

compiler/make_hlds.m:
	Added processing for solver types, in particular adding the
	compiler generated declarations and implementations of the
	conversion functions.

compiler/mercury_to_mercury.m:
	Added predicate mercury_output_where_attributes.

compiler/mode_info.m:
	Added a new field to mode_info to indicate whether solver type
	initialisation calls can be inserted by modecheck_conj_list_2.

compiler/mode_errors.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
	The compiler now inserts calls to initialisation preds, where
	necessary, before calls and at the end of procedures.  It does
	not yet do this at the end of disjuncts and its scheduling
	policy is naive (i.e. it performs terribly.)

	Added modecheck_conj_list_3 which allows modecheck_conj_list_2
	to insert initialisation calls for a single goal, then repeats
	if this succeeded in scheduling some delayed goals.

compiler/modules.m:
	XXX Reviewers: please look at the `rafe: XXX' comments and
	advise!

compiler/prog_data.m:
	Added the solver_type constructor and the special_type_details
	and solver_type_details types.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Parse the new syntax.
	Replaced get_maybe_equality_compare_preds with
	parse_type_decl_where_part_if_present.

compiler/prog_mode.m:
	Added funcs in_mode/1, out_mode/1, in_any_mode/0,
	out_any_mode/0, and any_inst/0.

compiler/special_pred.m:
	Added `initialise' constructor to special_pred_id.
	Changed special_pred_name to include the type name and arity
	with `__Unify__', `__Inex__' etc.

compiler/type_util.m:
	Added some more utility funcs/preds.

compiler/unify_proc.m:
	Generate the forwarding predicates for initialisation preds.

compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/rl_key.m:
compiler/table_gen.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
	Propagate the changes to hlds_goal_expr.
2004-09-05 23:52:54 +00:00
Zoltan Somogyi
b816836f02 Optimize away stack slots storing dummy values; values of the io__state and
Estimated hours taken: 8
Branches: main

Optimize away stack slots storing dummy values; values of the io__state and
store__store types.

compiler/stack_alloc.m:
	Allocate distinct negative stack slot numbers to values of dummy types.
	We need

compiler/hlds_pred.m:
	Add a predicate for testing whether a value is of a dummy type.

compiler/code_into.m:
	When constructing the list of live locations after a call, do not
	include the negative stack slots containing dummy values. The list
	of live locations is used by the (future) native collector, which
	should ignore dummy types, and by the debugger. The debugger can't
	do anything with these dummy values on the stack except tell the
	user about their existence, which doesn't do the debugger user any
	good.

	We still keep liveness information about dummy values in registers
	at calls and returns, since both the procedural and declarative
	debuggers need to know procedures' full argument lists.

	With respect to the list of live locations before the call, which
	was used only by the (now extinct) value numbering optimization,
	filter out all dummy types, since their values need not be preserved.

compiler/trace.m:
	Do not ask the code generator to preserve values of dummy types,
	since doing so would require referring to negative stack slots.

compiler/unify_gen.m:
compiler/var_locn.m:
	Fix a couple of situations in which we could refer to the negative
	stack slots we now allocate to dummy values.

compiler/call_gen.m:
	Reorder some code to make the source match what happens at runtime.

compiler/llds_out.m:
	Fix the formatting of the sanity check for negative stack slots.

compiler/handle_options.m:
	Since the --debug-opt-pred-id option is useless without --debug-opt,
	make --debug-opt-pred-id option imply --debug-opt. This was useful
	in debugging this diff.

trace/mercury_trace.c:
	Adapt the test for whether a retry is across I/O. We used to base the
	test on whether the retried predicate has any I/O state arguments,
	and if so, whether the original I/O state variable is still around
	on the stack. After this change, the answer to the second half of
	that question would always be "no", so we now use only the first half:
	whether the retried predicate has any I/O state arguments. This
	requires us to consider more retries to be retries across I/O, but
	from the point of view of a user who may not remember whether the I/O
	predicate has done any I/O so far or not, is arguably more consistent
	than our previous policy.

	Allow retries even if a value of type store.store is missing, since
	store.store is a dummy type just as io.state is.

trace/mercury_trace.c:
compiler/type_util.m:
	Document the fact that you need to update both these files if you
	want to modify the set of dummy types.

tests/debugger/retry.{inp,exp,exp2}:
	Due to the change in mercury_trace.c, one retry in this test case
	changes to being retry over I/O. Update the test input to force this
	retry over I/O, and expect the expanded input to be echoed in the
	output.

tests/debugger/nondet_stack.{exp,exp2}:
	Update these expected outputs to account for the fact that we now need
	fewer stack slots to hold old I/O states when debugging is enabled.
2004-09-02 04:31:42 +00:00
Zoltan Somogyi
90cdc14ef9 Optimize away instructions that move around dummy values; values of the
Estimated hours taken: 3
Branches: main

Optimize away instructions that move around dummy values; values of the
io__state and store__store types. (We still reserve stack slots for them;
getting rid of that is future work.)

compiler/var_locn.m:
	When moving values around, do not emit assignments that move around
	dummy values.

	Delete an unused predicate.

compiler/code_info.m:
	Pass to var_locn.m the extra information it now needs.

compiler/llds_out.m:
	Do not emit assignments for dummy arguments of foreign_procs.

compiler/type_util.m:
	Make the code for checking whether a type is a dummy type use the
	existing predicate for finding the type constructor of a type.
2004-08-30 05:44:39 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

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

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

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

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

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

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

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

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

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

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

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

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

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
ff60134ee9 Bring these modules up to our current coding standards.
Estimated hours taken: 8
Branches: main

analysis/analysis.m:
browser/browse.m:
compiler/accumulator.m:
compiler/assertion.m:
compiler/atsort.m:
compiler/c_util.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_model.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/dead_proc_elim.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/export.m:
compiler/fact_table.m:
compiler/follow_code.m:
compiler/graph_colour.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
compiler/mmc_analysis.m:
compiler/mode_errors.m:
compiler/passes_aux.m:
compiler/post_typecheck.m:
compiler/size_prof.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_errors.m:
compiler/transform_llds.m:
compiler/type_util.m:
compiler/unify_gen.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Bring these modules up to our current coding standards. Use predmode
	declarations and state variable syntax where relevant. Reorder
	arguments where this is needed for the use state variables. Make the
	orders of predicate definitions correspond to the order of their
	declarations. Replace some overly large lambda expressions with named
	predicates. Convert some predicates to functions where this makes
	their use more convenient. Use field access notation where convenient.
	Fix any inconsistent indentation. Remove module prefixes on predicate
	names where this is necessary to allow sane indentation.

	In several places, use predicates from error_util.m to print error
	messages. Apart from this, there are no changes in algorithms.

	In some places, conform to the changes below.

compiler/error_util.m:
compiler/hlds_error_util.m:
	Add new variants of existing predicates for use in some of the
	changed modules above.

compiler/hlds_out.m:
	Add some functions to convert values of some HLDS types as strings,
	for use in preparing the arguments of the new calls to predicates in
	error_util.m. Change the implementations of the predicates that print
	values of those types to call those functions instead of allowing
	code duplication.

compiler/llds.m:
	Add some field names to allow use of field updates where relevant.

tests/invalid/assert_in_interface.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/tricky_assert1.err_exp:
	Update the expected outputs of these test cases to allow for them being
	generated by error_util.m, and hence being better formatted than
	before.
2004-04-05 05:07:49 +00:00
Zoltan Somogyi
5d6fd3bd6f Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4
Branches: main

Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.

There are no changes in algorithms, only functionality being moved around.

compiler/code_model.m:
	Change this module from being a submodule of backend_libs.m to being a
	submodule of hlds.m, since nothing in it is dependent on any backend.

compiler/arg_info.m:
compiler/code_util.m:
	Change arg_info.m from being a submodule of ll_backend.m to being a
	submodule of hlds.m, since most of it is applicable to all current
	and foreseeable backends. Move the one exported predicate that is
	ll_backend dependent, and its support predicates, to code_util.m.

compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
	Update include_module declarations in accordance with the above.

compiler/prog_data.m:
compiler/term_util.m:
	Instead of defining two separate types for holding argument size and
	termination information, one including HLDS-specific information (in
	term_util.m) and one not (in prog_data.m), use a polymorphic type
	defined in prog_data.m and two monomorphic instances.

compiler/termination.m:
compiler/mercury_to_mercury.m:
	Change the predicates for writing out argument size and termination
	information to handle the polymorphic type (we don't need special
	handling of the monomorphic versions), and move them from termination.m
	to mercury_to_mercury.m, since this allows us to avoid some
	undesirable dependencies.

compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
	Move the predicate make_instance_string from base_typeclass_info.m
	to hlds_code_util.m, again because it allows us to remove some
	undesirable dependencies.

compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
	Delete some import_module declarations of other top level modules
	in these top level modules. Some imports were totally unnecessary.
	Some imports were useful in only a small minority of submodules;
	those submodules now import the necessary top level modules directly.

	Move remaining import_module declarations to the implementation section
	where this is feasible.

	Where we still need to import modules we ideally shouldn't, note why.

compiler/*.m:
	Update imports of code_util and arg_info.

	In some cases, import top level modules no longer imported by the
	parent module.

	In some cases, delete unnecessary imports.
2004-03-23 10:52:14 +00:00
Zoltan Somogyi
2a1f091157 Bring a part of this module I previously missed into line with our
Estimated hours taken: 0.2
Branches: main

compiler/type_util.m:
	Bring a part of this module I previously missed into line with our
	current coding standards.

	Use predmode declarations and state variable syntax when appropriate.
2003-12-23 03:11:00 +00:00
Zoltan Somogyi
fa9ca36d03 This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5
Branches: main

This diff makes several files easier to read and to maintain (as well as
more than 400 lines shorter), but contains no changes in algorithms whatsoever.

compiler/deep_profiling.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/post_typecheck.m:
compiler/prog_data.m:
compiler/purity.m:
compiler/type_util.m:
	Bring these modules into line with our current coding standards.

	Use predmode declarations and state variable syntax when appropriate.

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Replace predicates with functions where appropriate.

	Standardize indentation.

compiler/*.m:
	Conform to the changes above.
2003-12-21 05:04:38 +00:00
Simon Taylor
82c6cdb55e Make definitions of abstract types available when generating
Estimated hours taken: 100
Branches: main

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

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

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

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

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

compiler/mercury_compile.m:
	Add the new pass.

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

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

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

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

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

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

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

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

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

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

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
	Test case.
2003-12-01 15:56:15 +00:00
Peter Ross
cea3c7294e Fix a bug where the type_ctor_info for type_info/1 and
Estimated hours taken: 2
Branches: main

Fix a bug where the type_ctor_info for type_info/1 and
type_ctor_info/1 weren't being generated.

compiler/type_ctor_info.m:
	Also have to generate a type_ctor_info for those types which
	have hand defined rtti due to having a fake type body.

compiler/type_util.m:
	Rename builtin_type_ctors_with_no_type_defn as
	builtin_type_ctors_with_no_hlds_type_defn as the former name
	was misleading, and remove an incorrect comment about which
	type_ctors this function returns.

compiler/make_hlds.m:
compiler/typecheck.m:
	Changes due to the renaming of
	builtin_type_ctors_with_no_hlds_type_defn.
2003-11-28 20:40:13 +00:00
Peter Ross
368eaf2d11 Address review comments of fjh about my change to generate type_ctor and
Estimated hours taken: 1.5
Branches: main

Address review comments of fjh about my change to generate type_ctor and
special preds for the builtin types which don't have an abstract type
declaration.

compiler/make_hlds.m:
	Change parse_tree_to_hlds to use the state variable syntax.

compiler/type_util.m:
	s/builtin_type_ctors/builtin_type_ctors_with_no_type_defn/
	which better reflects which type ctors this function returns.

compiler/type_ctor_info.m:
	Improve the documentation of how the code determines whether
	or not a type_ctor_info needs to be generated.

compiler/typecheck.m:
	Use builtin_type_ctors_with_no_type_defn and make the documentation
	more explicit.
2003-11-21 15:21:37 +00:00
Peter Ross
22e4692ac5 Rather than declare the builtin types as abstract types in builtin.m
Estimated hours taken: 4
Branches: main

Rather than declare the builtin types as abstract types in builtin.m
special case their handling in the compiler to ensure that the
special preds and the type_ctor_infos are generated when needed.

compiler/type_util.m:
	Add a utility predicate which returns the list of type_ctors
	which represent types which are special builtins (ie they have no type
	declaration, even an abstract one).

compiler/make_hlds.m:
	Add the special preds for the special builtins if we are generating
	the rtti for the builtins.

compiler/type_ctor_info.m:
	Add type_ctor_infos for the special builtins if we are generating
	the rtti for the builtins.

compiler/typecheck.m:
	The special predicates for the special builtins don't require
	typechecking.

library/builtin.m:
	Remove the special builtins as they are no longer needed for
	generating the type_ctor_infos for a type.
2003-11-20 22:58:58 +00:00
Zoltan Somogyi
a2bf36e49a This diff contains no changes in algorithms whatsoever.
Estimated hours taken: 4
Branches: main

This diff contains no changes in algorithms whatsoever.

browser/*.m:
compiler/*.m:
library/*.m:
	Replace old-style lambdas with new-style lambdas or with named
	procedures.
2003-11-05 03:17:49 +00:00
Zoltan Somogyi
03cbbf4fc0 Improve the clarity of polymorphism.m further.
Estimated hours taken: 2
Branches: main

Improve the clarity of polymorphism.m further.

compiler/polymorphism.m:
	When a data structure involving type variables has several versions
	which differ in which tvarset those type variables come from (the raw
	tvarset of a called predicate's pred_info, the renamed-apart version
	in which those type variables have been lifted into the caller's
	newly expanded tvarset, and the version in which the type variables
	in the types of the formal parameters been replaced with the actual
	(possibly polymorphic) types from the actual arguments), use a
	mnemonic prefix to distinguish them, not a numerical suffix of
	the kind we use for other kinds of transformations.

	Put the code handling foreign_procs into its own predicate, to
	make debugging easier.

compiler/prog_data.m:
	Add field names to the class_constraints type, for use in
	polymorphism.m.

compiler/type_util.m:
	Add a utility predicate, factoring out repeated code from
	polymorphism.m.

library/varset.m:
	Clarify the documentation of varset__merge_subst.
2003-10-27 05:36:53 +00:00
Zoltan Somogyi
8693e293a2 This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4
Branches: main

This diff makes hlds_pred.m and many callers of its predicates easier to read
and to maintain, but contains no changes in algorithms whatsoever.

compiler/hlds_pred.m:
	Bring this module into line with our current coding standards.
	Use predmode declarations, functions, and state variable syntax
	when appropriate.

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Replace old-style lambdas with new-style lambdas or with partially
	applied named procedures.

	Standardize indentation.

compiler/*.m:
	Conform to the changes in hlds_pred.m. This mostly means using the
	new argument orders of predicates exported by hlds_pred.m. Where this
	is now conveniently possible, change predicates to use state
	variable notation.

	In some modules, using state variable notation required changing the
	orders of arguments in the module's top predicate.

compiler/passes_aux.m:
	Change the order of arguments in the calls this module makes to
	allow the callees to use state variable notation.

	Convert this module to state variable notation too.
2003-10-24 06:17:51 +00:00
Zoltan Somogyi
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

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

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

library/library.m:
	Include the new module in the library.

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Simon Taylor
5fa9a4b111 Remove the unimplemented aditi_filter and aditi_modify
Estimated hours taken: 0.5
Branches: main

compiler/*.m:
	Remove the unimplemented aditi_filter and aditi_modify
	goals -- they will never be implemented.

	Remove the `aditi_top_down' lambda_eval_method, which was only
	used for those update goals.  Even if those update goals were
	to be implemented, a special type of lambda expression
	shouldn't actually be needed.

	Use clearer names for the updates in the constructors
	of the aditi_builtin type.
2003-09-19 11:10:04 +00:00
Simon Taylor
ea33d1945c The Aditi API has been re-implemented. This change updates
Estimated hours taken: 40
Branches: main

The Aditi API has been re-implemented. This change updates
the Mercury->Aditi interface to work with the new API.

compiler/aditi_builtin_ops.m:
	Pass aditi__states to the builtin predicates implementing
	calls to Aditi procedures.

compiler/mode_util.m:
	Add a function aditi_ui_mode.

compiler/type_util.m:
	Add a function aditi_state_type.

runtime/mercury_wrapper.{c,h}:
util/mkinit.c:
	Pass the connection and a transaction in which to
	store the Aditi-RL modules.

extras/aditi/aditi.m:
extras/aditi/aditi_private_builtin.m:
util/mkinit.c:
	Use the new API.
2003-08-23 13:31:05 +00:00
Simon Taylor
a8ce49c7a8 Fix a bug reported by Fergus, which caused an abort when a
Estimated hours taken: 5
Branches: main

Fix a bug reported by Fergus, which caused an abort when a
user-defined unification or comparison predicate was ill-typed.

compiler/intermod.m:
	Don't attempt to module qualify the unification
	and comparison routines for type declarations that
	won't be used on the current back-end -- they won't
	have been typechecked. They will be ignored when read
	back in, but we put them in the `.opt' file because
	it is sometimes useful to test compiling a module
	against a workspace using a grade different to that
	used to build the workspace.

compiler/type_util.m:
	Choose the correct unification/comparison predicates for
	the current back-end where there are both Mercury and
	foreign definitions for a type.

compiler/make_hlds.m:
compiler/foreign.m:
	Move have_foreign_type_for_backend to foreign.m, for
	use by intermod.m.

doc/reference_manual.texi:
	Clarify the documentation about user-defined unification and
	comparison predicates for foreign types.

tests/invalid/Mmakefile:
tests/invalid/illtyped_compare.{m,err_exp}:
	Add a test case.

tests/invalid/make_opt_error.{m,err_exp}:
	This change caused the error in this test case to not
	be reported any more (it occurred in code not used
	on the back-end being compiled for). Fix the test
	so an error is reported.
2003-08-21 07:01:18 +00:00
David Overton
2ad2f0a28e Allow types to be declared as "solver" types using the syntax
Estimated hours taken: 120
Branches: main

Allow types to be declared as "solver" types using the syntax
`:- solver type ...'.

For a non-solver type t (i.e. any type declared without using the
`solver' keyword), the inst `any' should be considered to be equivalent
to a bound inst i where i contains all the functors of the type t and
each argument has inst `any'.  For solver types, `any' retains its
previous meaning.

This is required to allow us to represent HAL's `old' inst using `any'.
In HAL, `old' is like `any' if the type is an instance of a particular
type class (`solver/1').  However, for types that are not instances of
`solver/1', `old' needs to be treated as though it is `bound'.

library/ops.m:
	Add `solver' as a unary prefix operator.

compiler/prog_data.m:
	Add a field to the type `type_defn' to record whether or not the
	type is a solver type.

compiler/hlds_data.m:
	Add an equivalent field to the type `hlds_type_body'.

compiler/prog_io.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Handle the new ":- solver type ..." syntax.

compiler/det_report.m:
compiler/equiv_type.m:
compiler/foreign.m:
compiler/hlds_code_util.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/stack_opt.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
	Handle the changes to `type_defn' and `hlds_type_body'.

compiler/type_util.m:
	Add predicates `type_util__is_solver_type' and
	`type_body_is_solver_type'.

compiler/inst_match.m:
compiler/inst_util.m:
	In inst_matches_{initial,final,binding} and
	abstractly_unify_inst_functor, when we are comparing `any' insts, check
	whether or not the type is a solver type and treat it appropriately.

compiler/instmap.m:
compiler/modecheck_unify.m:
	Pass type information to abstractly_unify_inst_functor.

compiler/mode_util.m:
	Add a predicate `constructors_to_bound_any_insts' which is the same as
	`constructors_to_bound_insts' except that it makes the arguments of the
	bound inst `any' instead of `ground'.

tests/invalid/any_mode.m:
tests/invalid/any_mode.err_exp:
tests/hard_coded/any_free_unify.m:
	Modify these test cases to use a "solver" type instead of `int'.

tests/valid/any_matches_bound.m:
tests/valid/Mmakefile:
tests/invalid/Mmakefile:
tests/invalid/any_should_not_match_bound.m:
tests/invalid/any_should_not_match_bound.err_exp:
	Add new test cases.

extras/trailed_update/var.m:
clpr/cfloat.m:
	Modify to use the new `:- solver type' syntax.
2003-07-25 02:27:37 +00:00
David Overton
127fe0f85f Fixes to allow testing of ground' matches bound'.
Estimated hours taken: 10
Branches: main

Fixes to allow testing of `ground' matches `bound'.

compiler/modules.m:
	When writing discriminated union types to the .int2 file, write
	out the full type definition rather than an abstract type
	declaration.  This is necessary because a module which
	transitively imports the .int2 file may need to know the
	constructors to allow `ground' to be compared with `bound'
	insts.  See the new test case `transitive_inst_type' for an
	example.  If the type has user-defined equality and/or comparison
	predicates then we write "... where type_is_abstract_noncanonical"
	to the .int2 file instead of giving the predicate names.

compiler/make_hlds.m:
	If a discriminated union type is imported from a .int2 file, mark it
	as `abstract_imported'.

compiler/typecheck.m:
	When type checking var-functor unifications, do not allow functors
	whose types are `abstract_imported', unless we are type checking an
	`opt_imported' predicate.

compiler/prog_data.m:
	Add a new alternative `abstract_noncanonical_type' to the type
	`unify_compare' to represent "where type_is_abstract_noncanonical"
	annotations read from .int2 files.

compiler/prog_io.m:
	Parse "where type_is_abstract_noncanonical" annotations on
	discriminated union types.

compiler/special_pred.m:
compiler/unify_proc.m:
	Avoid creating unification and comparison predicates
	for types with `type_is_abstract_noncanonical' annotations.

compiler/intermod.m:
	Handle the change to the `unify_compare' type.

compiler/type_util.m:
	Do not remove module qualifiers from constructors before looking
	them up in the cons table.  Some cons ids only have the
	qualified version in the table.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/transitive_inst_type.exp:
tests/hard_coded/transitive_inst_type.m:
tests/hard_coded/transitive_inst_type2.m:
tests/hard_coded/transitive_inst_type3.m:
tests/hard_coded/trans_intermod_user_equality.exp:
tests/hard_coded/trans_intermod_user_equality.m:
tests/hard_coded/trans_intermod_user_equality2.m:
tests/hard_coded/trans_intermod_user_equality3.m:
	Add some test cases.
2003-07-22 07:04:26 +00:00
Zoltan Somogyi
a25b2c0507 Prepare to make type_info and typeclass_info foreign types by allowing
Estimated hours taken: 2
Branches: main

Prepare to make type_info and typeclass_info foreign types by allowing
the compiler to generate type_ctor_infos for them, and allow them to be
passed to foreign code without warnings.

compiler/type_util.m:
	Make the predicate type_ctor_has_hand_defined_rtti return true
	only if the relevant type is not declared as a foreign type.
	This is needed to allow the compiler to bootstrap across the change
	that makes type_info and typeclass_info foreign types. This required
	passing the type definition to the predicate.

compiler/special_pred.m:
compiler/unify_proc.m:
	Pass the extra argument to type_ctor_has_hand_defined_rtti.

compiler/type_ctor_info.m:
	Pass the extra argument to type_ctor_has_hand_defined_rtti.

	Set the required flags on any compiler-generated type_ctor_info
	structures for the builtin types with fake arities.

compiler/llds_out.m:
	Fix an old bug: ensure that the second argument of the
	MR_MAYBE_UNBOX_FOREIGN_TYPE macro is of type MR_Word, because the
	macro insists on this. If applied to e.g. type_ctor_info constants,
	the old code would have generated C compiler warnings, because
	their type is not MR_Word.

	Special case the most frequently passed foreign types to avoid the
	memcpy overhead in MR_MAYBE_UNBOX_FOREIGN_TYPE.

compiler/export.m:
	Add a utility predicate to help llds_out.m. In the future,
	the MLDS C backend may want to use it too.
2003-07-03 12:11:18 +00:00
Zoltan Somogyi
d6f05747a2 Prepare to make type_info and typeclass_info foreign types by eliminating the
Estimated hours taken: 4
Branches: main

Prepare to make type_info and typeclass_info foreign types by eliminating the
compiler's dependence on their function symbols. At the moment, the compiler
generates type_intos and typeclass_infos by using the function symbols of these
types as cons_ids. However, the function symbols have fake arities, which
demanded special treatment in many places. This change makes the compiler use
the cons_ids type_into_cell_constructor and typeclass_into_cell_constructor
instead, except in insts, which need to know the arity of the constructor.

compiler/hlds_data.m:
	Add the two new cons_ids.

compiler/polymorphism.m:
	Use the two new cons_ids instead of the function symbols of the
	type_info and typeclass_info types, since those function symbols
	will soon be deleted.

compiler/type_util.m:
	Add a type and some predicates to control the representation of
	type_info and typeclass_info cells in one place.

	Since we no longer depend on the representations of the function
	symbols of the type_info and typeclass_info types, do not special
	case their representation.

compiler/hlds_code_util.m:
	Implement the representation of the two new function symbols.

compiler/bytecode.m:
	Add two new cons_ids to parallel the ones in hlds_data.m.

compiler/higher_order.m:
	Look for the two new cons_ids, instead of the old ones.

	Make the code more maintainable.

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

library/private_builtin.m:
	Delete the statement that the compiler depends on the functors of the
	type_info and type_ctor_info types.

bytecode/mb_bytecode.h:
	Document that some bytecodes generated by the compiler are not yet
	implemented by the bytecode interpreter.
2003-06-24 14:20:59 +00:00
Zoltan Somogyi
aa478cb237 Take a piece of code in modecheck_unify and make it a predicate in
Estimated hours taken: 0.2
Branches: main

compiler/type_util.m:
compiler/modecheck_unify.m:
	Take a piece of code in modecheck_unify and make it a predicate in
	type_util, without any logic changes. In an upcoming diff, another
	module will need the same code.
2003-05-30 14:43:45 +00:00
Zoltan Somogyi
4f42c8e2b1 Improve the documentation of predicates checking for user-defined
Estimated hours taken: 0.2
Branches: main

compiler/type_util.m:
compiler/det_analysis.m:
	Improve the documentation of predicates checking for user-defined
	equality.
2003-05-29 09:19:44 +00:00
Zoltan Somogyi
6554ef7daa Replace "is" with "=".
Estimated hours taken: 2
Branches: main

Replace "is" with "=".
Add field names where relevant.
Replace integers with counters where relevant.
2003-05-26 09:01:46 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

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

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Simon Taylor
482105e074 Allow user-defined comparison functions using the syntax
Estimated hours taken: 10
Branches: main

Allow user-defined comparison functions using the syntax
:- type t ---> t where equality is t_equal, comparison is t_compare.
.
Allow user-defined equality and comparison for foreign types using the syntax
:- pragma foreign_type(c, t, "c_t") where
		equality is t_equal, comparison is t_compare.

compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
compiler/*.m:
	Allow comparison predicates in `type' and `pragma foreign_type'
	declarations

compiler/hlds_data.m:
compiler/*.m:
	Allow equality and comparison predicates to be attached
	to foreign types.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Parse the new syntax.

compiler/make_hlds.m:
	Don't add the types to the HLDS or do typechecking if
	there are errors in the type declarations.
	Test case: tests/invalid/foreign_type_visibility.m.

compiler/foreign.m:
compiler/special_pred.m:
compiler/type_util.m:
	Check whether foreign types have user-defined equality.

compiler/unify_proc.m:
	Generate clauses for user-defined comparison,
	and clauses for unification for foreign types.

compiler/intermod.m:
	Resolve overloading before writing the `.opt' files.

library/builtin.m:
	Add `uo' modes for promise_only_solution, for use in
	user-defined comparison predicates.

	Add types and insts to allow declaration of user-defined
	comparison predicates using `with_type` and `with_inst`.
	We already have types and insts `builtin__comparison_pred',
	but they have a different argument ordering to `compare/3'.

NEWS:
doc/reference_manual.texi:
	Document the change.

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

tests/invalid/Mmakefile:
tests/invalid/typeclass_test_{9,10}.{m,err_exp}:
tests/invalid/purity/purity_nonsense{,2}.{m,err_exp}:
	The change to error-checking in make_hlds.m meant that
	the compilation stopped before some errors in
	typeclass_test_9.m were detected. The code which
	tests for those errors is now in typeclass_test_10.m.
2003-02-12 22:58:20 +00:00
Fergus Henderson
ef7ed9c2f5 Support impurity declarations for higher-order code.
Estimated hours taken: 24
Branches: main

Support impurity declarations for higher-order code.

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

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

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

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

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

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

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

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

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

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

tests/invalid/purity/.cvsignore:
	New file, copied from tests/invalid/.cvsignore.
2003-01-27 09:21:03 +00:00
Fergus Henderson
17f53149a4 Implement `:- pragma reserve_tag(<TypeName>/<Arity>).'.
Estimated hours taken: 6
Branches: main

Implement `:- pragma reserve_tag(<TypeName>/<Arity>).'.
This has the same effect as the `--reserve-tag' option,
except that it only applies to specified type, rather than
to all types.

doc/reference_manual.texi:
	Document the new feature.
	(However, the documentation is currently commented out.)

compiler/prog_data.m:
	Add `reserve_tag(sym_name, arity)' to the `pragma_type' type.

compiler/hlds_data.m:
	Add a new boolean field to the representation of discriminated union
	type bodies to record whether or not the type has a reserved tag.

compiler/prog_io_pragma.m:
	Add code to parse the new pragma.

compiler/make_hlds.m:
	Add code to process the new pragma:
	- check all the appropriate semantic restrictions:
		- the pragma must have the same visibility as the type
		- the type must be defined
		- the type must be a discriminated union type
	- warn if there are multiple such pragmas for the same type
	- call make_tags.m to recompute the tags used for the constructor.
	- record the presence of the reserve_tag pragma in the HLDS type
	  definition body

compiler/make_tags.m:
compiler/type_util.m:
	Add an extra argument to assign_constructor_tags (in make_tags.m)
	and type_constructors_should_be_no_tag (in type_util.m)
	to specify whether or not there was a `reserve_tag' pragma.
	Reserve a tag if either this argument or the global `reserve_tag'
	option is set.

compiler/intermod.m:
	Output a `:- reserve_tag' pragma whenever outputting a type
	to which such a pragma applies.

compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
	Ignore the reserved_tag field.
	XXX This means that the `reserve_tag' pragma (or the compiler
	    option) won't have much effect if --high-level-data is set.

compiler/code_util.m:
compiler/det_report.m:
compiler/hlds_out.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/post_typecheck.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/stack_opt.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
	Trivial changes to handle the new reserved_tag field of
	hlds_type_defn_body.

tests/valid/Mmakefile:
tests/valid/reserve_tag.m:
tests/invalid/Mmakefile:
tests/invalid/reserve_tag.m:
tests/invalid/reserve_tag.err_exp:
	Some tests of the new feature.
2003-01-14 16:42:44 +00:00
Ralph Becket
3607da6191 Added infix `.' as a module separator. This is paving the way to phasing
Estimated hours taken: 3
Branches: main

Added infix `.' as a module separator.  This is paving the way to phasing
out `:' as a module separator in order to use it as a synonym for `with_type`
instead.

NEWS:
	Report the change.

compiler/prog_io.m:
compiler/type_util.m:
	Changed so that `.'/2 is recognised as a module separator.

library/ops.m:
	Change associativity of `.'/2 from xfy to yfx.
2002-12-05 03:52:30 +00:00
Ralph Becket
1cdfefc8ae Backed out last change due to wrong log message 2002-12-05 03:51:26 +00:00
Ralph Becket
bfd2905743 NEWS for Mercury release 0.12:
------------------------------

HIGHLIGHTS
==========

Changes to the Mercury language:
* Infix `.' is now accepted as a module name separator.

Changes to the Mercury compiler:
* Nothing yet.

Portability improvements:
* Nothing yet.

Changes to the Mercury debugger:
* Nothing yet.

Changes to the compiler back-ends:
* Nothing yet.

Numerous minor improvements to the Mercury standard library.

DETAILED LISTING
================

Changes to the Mercury language:

* Infix `.' is now accepted as a module name separator.  Hence it is
  now possible to write io.write_string and list.member to mean the
  same thing as io__write_string and list__member, for instance.  This
  has required changing the associativity of `.' from xfy to yfx and
  from precedence 600 to 10.

Changes to the Mercury standard library:

* We've added the three predicates, `is_nan/1', `is_inf/1' and
  `is_nan_or_inf/1' to float.m.  These predicates are for use only on
  systems which support IEEE floating point arithmetic.

* The determinisms of the following predicates in the `std_util'
  module have been changed from cc_nondet to cc_multi: arg_cc/3 and
  limited_deconstruct_cc/3 (formerly limited_deconstruct_cc/5).  The
  success or failure of these predicates is now encoded in a maybe
  type.

* The incorrect cc_nondet modes of the following predicates in
  the `deconstruct' module have been removed: arg/4, limited_deconstruct/6.
  cc_multi version of the predicates have been introduced where the
  success or failure of the predicate has been encoded into a maybe
  type.

Changes to the extras distribution:

* Nothing yet.

Changes to the Mercury compiler:

* Nothing yet.

Portability improvements:

* Nothing yet.

Changes to the Mercury debugger:

* Nothing yet.

Changes to the compiler back-ends:

* Nothing yet.


NEWS for Mercury 0.11
---------------------

HIGHLIGHTS
==========

Changes to the Mercury language:
* Support for constrained polymorphic modes.
* Addition of state variable syntax.
* Improved support for higher-order functions.
* Predicate and function equivalence type and mode declarations.
* Support for defining predicates or functions
  using different clauses for different modes.
* Support for Haskell-like "@" expressions.
* Generalized foreign language interface.

Changes to the Mercury compiler:
* A new `--make' option, for simpler building of programs.
* A new `--smart-recompilation' option, for fine-grained dependency tracking.
* A new optional warning: `--warn-non-tail-recursion'.
* A new optimization: `--constraint-propagation'.
* A new optimization: `--loop-invariants'.
* Support for arbitrary mappings from module name to source file name.

Portability improvements:
* Mac OS X is now supported "out-of-the-box".
* On Windows we now support generating non-Cygwin executables.
* Better conformance to ANSI/ISO C.

Changes to the compiler back-ends:
* The native code Linux/x86 back-end is now "release quality".
* The .NET CLR back-end is much improved.

Major improvements to the Mercury debugger, including:
* Support for source-linked debugging using vim (rather than emacs).
* Command-line completion.
* Ability to display values of higher-order terms.
* Declarative debugging.
* Support for transparent retries across I/O.

A new profiler, which we call the Mercury deep profiler or mdprof:
* Supports both time and memory profiling.
* Gathers information about individual call sites as well as procedures.
* Eliminates the assumption that all calls to a procedure have equal cost.
* Allows users to explore the gathered data interactively with a web browser.

Numerous minor improvements to the Mercury standard library.

A new testing tool in the extras distribution.
A new regex module for string matching and search-and-replace in the
extras distribution.

DETAILED LISTING
================

Changes to the Mercury language:

* We have added support for constrained polymorphic modes.  See the section on
  Constrained Polymorphic Modes in the Modes chapter of the Mercury Language
  Reference Manual.

* A more general alternative to DCG syntax has been added to the language
  to simplify the manipulation of threaded state.  See the section on State
  Variables in the Syntax chapter in the Mercury Language Reference Manual.

* If a higher-order function term has inst 'ground' it is now assumed to have
  the standard higher-order function inst 'func(in, .., in) = out is det'.
  This makes higher-order functional programming much easier, particularly when
  passing functions to polymorphic predicates.

  This change is not completely backwards compatible since, for safety,
  we must now disallow calls that would cause a variable that has a
  nonstandard function inst to become 'ground'.

* Predicate and function type and mode declarations can now be expressed
  in terms of higher-order predicate and function types and insts, rather
  than explicitly listing the argument types and modes.  This is useful
  where several predicates or functions must have the the same type and
  mode signature.

  For example:
	:- type foldl_pred(T, U) == pred(T, U, U).
	:- inst foldl_pred == (pred(in, in, out) is det).
	:- pred p `with_type` foldl_pred(T, U) `with_inst` foldl_pred.

  For more information see the "Predicate and function type declarations"
  section of the "Types" chapter and the "Predicate and function mode
  declarations" section of the "Modes chapter" of the Mercury Language
  Reference Manual.

* The constructor for lists is now called '[|]' rather than '.'.
  `./2' will eventually become the module qualification operator.
  This change only affects programs which use `./2' explicitly.
  Programs which only use the `[H | T]' syntax will be unaffected.

* We've added a new kind of expression to the language.
  A unification expression, written `X @ Y', unifies X and Y
  and returns the result.

  Unification expressions are most useful when writing switches:
	p(X, X) :- X = f(_, _).
  can now be written as
	p(X @ f(_, _), X).

  See the "Data-terms" section of the "Syntax" chapter of the
  Mercury Language Reference Manual for more details.

* We've extended the language to allow you to specify different clauses
  for different modes of a predicate or function.  This is done by
  putting mode annotations in the head of each clause.
  For example, you can write

	:- mode p(in).
	:- mode p(out).
	p(X::in) :- ... /* clause for the `in' mode */
	p(X::out) :- ... /* clause for the `out' mode */

  For predicates or functions which have different clauses for different
  modes, you need to either (1) add a `pragma promise_pure' declaration
  for the predicate or function, and ensure that the declarative semantics
  remains the same in each mode, or (2) declare the predicate as impure.

* We now allow `:- pragma promise_semipure' declarations. For more
  information, see the "Impurity" chapter of the Mercury Language
  Reference Manual.

* We've added `:- pragma c_import_module' declarations, which are
  used to make the C declarations for predicates and functions with
  `:- pragma export' declarations in the imported module visible
  to any C code in the importing module. `mmake' uses
  `:- pragma c_import_module' declarations to make sure that the
  header file for the imported module is built before it is needed,
  which it can't do if the header file is explicitly #included.

* The foreign language interface has been generalized to support
  interfacing with languages other than C.

  In particular, the Mercury compiler's .NET back-end now supports
  interfacing with C#, IL, and "Managed C++" (C++ with Microsoft's
  extensions for the .NET CLR).  Mercury procedures can be defined
  using inline code fragments written in any of these languages.

  For details, see the new "Foreign language interface" chapter of
  the Mercury Language Reference Manual.

* We've removed the undocumented operators `export_adt', `export_cons',
  `export_module', `export_op', `export_pred', `export_sym', `export_type',
  `import_adt', `import_cons', `import_op', `import_pred', `import_sym',
  `import_type' `use_adt', `use_cons', `use_op', `use_pred', `use_sym'
  and `use_type'. These operators were reserved for module system
  extensions which are unlikely to be implemented.

Changes to the Mercury standard library:

* The Prolog-style term comparison operators @<, @=<, @>, @>= are now
  builtin.

* A new builtin function ordering/2 has been added.

* We've added a function to io.m to construct io__error codes from error
  messages: `io__make_io_error'.

* The assumptions that we make about user supplied comparison predicates and
  functions have been relaxed to allow more general orderings.  The new
  assumptions are documented in builtin.m.

* The builtin predicates !/0 and !/2 from Mercury's Prolog heritage have been
  removed (`!' is now a prefix operator used in the state variable syntax).

* We have added the type class `pprint__doc/1' and a new concatenation
  operator, `++/2', which should make it easier to construct doc values.
* Performance bugs in `pprint__to_doc' have now been fixed.  Even
  very large terms can now be converted to docs and pretty printed without
  causing a machine to thrash or run out of memory.

* `io__read_file' and `io__read_file_as_string' now have better error
  handling. The result types have changed, so code using these predicates
  will need minor modifications.
* We've added predicates `io__input_stream_foldl', `io__input_stream_foldl_io'
  and `io__input_stream_foldl2_io', which apply a predicate to each character
  of an input stream in turn.
* We've added predicates `io__binary_input_stream_foldl',
  `io__binary_input_stream_foldl_io' and `io__binary_input_stream_foldl2_io',
  which apply a predicate to each byte of a binary input stream in turn.
* We've added versions of `io__print', `io__write' and `io__write_univ'
  that allow the caller to specify how they should treat values of noncanonical
  types, e.g. types in which a single semantic value may have more than one
  syntactic expression.
* We've added four new predicates to allow programs to retrieve current
  streams: `io__current_input_stream', `io__current_output_stream',
  `io__current_binary_input_stream', and `io__current_binary_output_stream'.
* We've added a predicate to io.m to return the last modification time
  of a file: `io__file_modification_time'.
* We've added cc_multi modes to io__write_list/5 and io__write_list/6.
* You can now close stdin, stdout and stderr.

* We've added four functions to list.m for mapping functions over
  corresponding members of lists: list__map_corresponding/3,
  list__map_corresponding3/4, list__filter_map_corresponding/3
  and list__filter_map_corresponding3/4.
* We've added some other new functions to list.m, namely
  list__last_det/2, list__split_last/3 and list__split_last_det/3.
* We've added cc_multi modes to list__foldl/4 and list__foldr/4.
* We've added a predicate list__map_foldl2.
* As mentioned above, the constructor for lists has changed from './2'
  to `[|]/2'. This change affects the behaviour of the term manipulation
  predicates in the standard library when dealing with values of
  type `term__term/1' representing lists. The affected predicates are
  parser__read_term, parser__read_term_from_string, term__type_to_term,
  term__term_to_type, term_io__read_term and term_io__write_term.
  Also beware that std_util__functor and std_util__deconstruct now
  return `[|]' rather than `.' for lists, and calls to std_util__construct
  which construct lists may need to be updated.
* We've added the predicate list__is_empty/1 and list__is_not_empty/1.
* We've added the predicate list__remove_adjacent_dups/3.

* We've added a function version of error/1, called func_error/1, to require.m.

* ops.m now defines a typeclass which can be used to define operator
  precedence tables for use by parser.m and term_io.m. See
  samples/calculator2.m for an example program.

  The `ops__table' type has been renamed `ops__mercury_op_table'.
  `ops__init_op_table' has been renamed `ops__init_mercury_op_table'.
  `ops__max_priority' is now a function taking an operator table argument.

* The predicates and functions in int.m, float.m, math.m and array.m now
  generate exceptions rather than program aborts on domain errors and
  out-of-bounds array accesses. There are new functions
  `float__unchecked_quotient/2', `int__unchecked_quotient/2' and
  `int__unchecked_rem/2' for which no checking is performed and the
  behaviour if the right operand is zero is undefined.

* We've removed the reverse modes of the arithmetic functions in
  float.m and extras/complex_numbers.  (Because of rounding errors,
  the functions aren't actually reversible.)

* float__pow now works for negative exponents, and runs much faster
  for large exponents.

* We've removed the destructive update modes of string__set_char,
  string__set_char_det and string__unsafe_set_char. The compiler
  currently always stores constant strings in static data, even
  if they are passed to procedures with mode `di', so any attempt
  to update a constant string will cause a crash. Fixing this properly
  will be a lot of work, so for now we have just removed the modes.

* We've added string__suffix, string__words/1, string__foldr,
  string__foldl_substring and string__foldr_substring.

* The exception module has a new predicate `try_store', which is
  like `try_io', but which works with stores rather than io__states.

* We've fixed a bug in time.m. Type `tm' didn't store the day of the month,
  which meant that the functions which required that field (e.g. time__asctime,
  time__mktime) did not work.

  The order of the fields of type `time__tm' has been changed so that
  comparison of values of type `tm' whose `tm_dst' fields are identical
  is equivalent to comparison of the times those values represent.

* std_util.m now contains predicates and functions `map_maybe',
  `fold_maybe', `map_fold_maybe' and `map_fold2_maybe', which are
  analogues of `list__map', `list__foldl', `list__map_foldl' and
  `list__map_foldl2' operating on values of type `maybe' instead
  of `list'.

* We've added a predicate to io.m to return the last modification time
  of a file (io__file_modification_time).

* There is a variant of io__call_system, io__call_system_return_signal
  which on interrupt returns the number of the signal which interrupted
  the command rather than just an error message.

* We've added added several new predicates for deconstructing terms to
  std_util.m. `named_argument' and `det_named_argument' are analogous
  to `argument' and `det_argument' respectively, but specify the desired
  argument by its name, not its position. We have also added committed choice
  version of all the predicates that deconstruct terms. These differ from the
  existing versions in that they do not abort when called upon to deconstruct
  non-canonical terms, such as values of types with user-defined equality.

* We've added a new predicate `intersect_list' in each of the modules
  implementing sets in the Mercury standard library.

* We've added a predicate version of `set__fold'.

* We've added function versions of `builtin__unsafe_promise_unique',
  `ops__init_op_table' and `ops__max_priority'.

* We've added a version of `getopt__process_options' which returns
  the option arguments.

* `getopt__process_options' has been modified to allow negation of
  accumulating options. Negating an accumulating option empties
  the accumulated list of strings.

* We've added some functions to the term_io module to return printable
  representations of term components as strings.

* We've made the outputs of the string concatenation primitives unique.

* New convenience/readability predicates `int__even/1' and `int__odd/1'.

* New predicate benchmark_det_io for benchmarking code that performs I/O.

* We've removed the long obsolete `int__builtin_*' and
  `float__builtin_float_*' predicates, which were synonyms
  for the arithmetic functions dating from when Mercury didn't
  have functions.

* We've added int:'/'/2 as a synonym for int:'//'/2 and false/0 as a
  built-in synonym for fail/0 (both left-overs from Mercury's Prolog
  heritage.)

* dir:'/'/2 is now a synonym for `dir__make_path_name'.

* We've removed the long obsolete predicates `io__read_anything',
  `io__write_anything', and `io__print_anything', which were long ago
  renamed as `io__read', `io__write', and `io__print' respectively.

* We've added random__random/5, which produces a random integer in a
  given range, and random__randcount/3, which returns the number of
  distinct random numbers that can be generated.

Changes to the extras distribution:

* The lex subdirectory now contains a new module, regex, which provides
  for more traditional string-based ways of defining regular expressions
  and provides string matching and search-and-replace functionality.

* There's a new testing tool called "quickcheck", which is similar to
  Haskell's "QuickCheck".  See quickcheck/tutes/index.html.

* The interface to Moose has been changed in a non-backwards compatible
  way to support user-defined modes for the parser state and integrate
  better with lex.

Changes to the Mercury compiler:

* There is a new `--make' option which performs most of the functions
  of Mmake.  The advantages of `mmc --make' are that no `mmake depend'
  step is necessary and the dependencies are more accurate.  Parallel
  builds are not yet supported.  See the "Using Mmake" chapter of the
  "Mercury User's Guide" for details.

* The Mercury compiler can now perform smart recompilation, enabled by the
  `--smart-recompilation' option. With smart recompilation, when the
  interface of a module changes, only modules which use the changed
  declarations are recompiled. Smart recompilation does not yet work
  with `--intermodule-optimization'.

* The Mercury compiler can now handle arbitrary mappings from source files
  to module names.  If the program contains modules for which the source
  file name does not match the module name, before generating the
  dependencies the command `mmc -f SOURCES' must be run, where `SOURCES'
  is a list of the names of all of the source files.  If the names of the
  source files all match the contained module names, `mmc -f' need not be run.

* There is a new `--use-grade-subdirs' option which is similar to
  `--use-subdirs', but allows multiple grades to be built in a
  directory at the same time.  `--use-grade-subdirs' does not
  work with Mmake (it does work with `mmc --make').

* The compiler and scripts accept a `--mercury-stdlib-dir' option,
  which overrides the configured location of the Mercury standard
  library.  There is also an environment variable MERCURY_STDLIB_DIR
  which has the same effect.  The environment variables which were
  previously used to override the location of the standard library
  (MERCURY_ALL_C_INCL_DIRS, MERCURY_ALL_MC_C_INCL_DIRS, MERCURY_INT_DIR,
  MERCURY_C_LIB_DIR, MERCURY_MOD_LIB_MODS, MERCURY_TRACE_LIB_MODS) are
  now deprecated, and will be removed in a future release.
  MERCURY_C_INCL_DIR has already been removed.

* We've added a new compiler option `--warn-non-tail-recursion', which
  causes the compiler to issue a warning about any directly recursive
  call that is not a tail call.

* The automatically generated header files for modules containing
  `pragma export' declarations are now named `<module>.mh', not
  `<module>.h'. This avoids conflicts with system header files.

* We've fixed a long-standing bug in the handling of module imports.
  Previously, if `module1' imported `module2' which imported `module3' in
  its interface section, then any types, insts, modes and typeclasses defined
  in the interface of `module3' could be used in `module1' even
  if `module1' did not import `module3' directly.

  This change will break some existing programs, but that is easily fixed
  by adding any necessary `:- import_module' or `:- use_module' declarations.

* Options for the Mercury runtime can now be set at compile time using
  the new `--runtime-flags' option of ml and c2init.

* We've added a new optimization pass -- constraint propagation.

  Constraint propagation attempts to transform the code so
  that goals which can fail are executed as early as possible.
  It is enabled with the `--constraint-propagation' option
  (or `--local-constraint-propagation' for a more restricted
  version of the transformation).

* The Mercury compiler can now perform inter-module optimization using
  information from transitively imported modules. This is especially
  useful for back-ends which do not support abstract equivalence types
  properly (for example the .NET backend). To disable this behaviour and
  only optimize using information from directly imported modules, use the
  option `--no-read-opt-files-transitively'.

* For each `--Xflags' option there is now a `--Xflag' option which allows a
  single quoted argument to be passed to the invoked program.  This is useful
  where the argument is a directory name containing spaces.

* The `--convert-to-goedel' option has been removed.
  It never really worked anyway.

Portability improvements:

* Mac OS X is now supported "out-of-the-box".

  See README.MacOSX for details.

* On Windows we now support generating non-Cygwin executables.

  The Mercury compiler source distribution can be configured using
  `configure --with-cc="gcc -mno-cygwin"'.  This option ensures
  that the Mercury libraries are only linked with the standard
  Windows libraries, not the Cygwin Unix emulation library,
  so Mercury programs don't need Cygwin, and use DOS/Windows-style
  path names rather than Cygwin's Unix-style path names.

  Note that you still need Cygwin to install and use Mercury.
  The change is that the programs which you build using Mercury
  don't need Cygwin anymore.

* Better conformance to ANSI/ISO C.

  We now pass all the tests in the Mercury test suite
  when the compiler is built with the "lcc" C compiler,
  which is more strict about ANSI/ISO C conformance than GNU C.
  This should also make it easier to port to other C compilers.

Changes to the Mercury debugger:

* The debugger can now print goals just as Prolog debuggers do. At an exit
  port of e.g. append, the command "print goal" will print the current goal
  in a form such as "append([1], [2], [1, 2])".

* You can now navigate terms in the debugger by argument name as well as by
  argument number.

* The debugger can now print higher order values.

* The debugger can now print type_info structures. However, since such
  structures are normally of interest to implementors only, the debugger
  will print such values only if the user gives the command "print_optionals
  on".

* The debugger can now perform command line completion when compiled
  with GNU Readline support enabled.

* We've added a 'view' command to `mdb', which opens a `vim' window and
  in it displays the current source location, updated at each event.  This
  requires X11 and a version of `vim' with the `clientserver' feature
  enabled.

* The `--window' mdb option now creates a window for mdb, not
  the program.  The main advantage of the new behaviour is that
  redirection of the program's input and output works.  The old
  behaviour is still available with `mdb --program-in-window'.

* The debugger now includes support for declarative debugging.  The `dd'
  command starts diagnosis at any exit, fail or exception port in mdb.  See
  the Mercury User's Guide for more details.

* When a program is compiled in a debugging grade, the debugger can be
  asked, via the command `table_io start', to make I/O primitives (such as
  io__open_file, io__write_string etc) idempotent. This means that a given
  call to e.g. io__open_file will open the specified file only once,
  even if retry commands cause the call to be executed more than once.

A new profiler, which we call the Mercury deep profiler or mdprof:

* The old Mercury profiler is based on the technology of the standard Unix
  profiler gprof. This technology makes the assumption that all calls to a
  given C function (in Mercury, a given function or predicate in a given mode)
  have the same cost, whether the cost being measured is CPU time, memory cells
  allocated, memory words allocated etc. In C programs, this assumption is
  usually close enough to correct for the output of gprof to be useful. In
  Mercury, due to the presence of parametric polymorphism and the significantly
  higher frequency of higher order code, different call sites are far more
  likely to have distinct performance characteristics than in C, so the output
  of a gprof-style profiler is usually not accurate enough to be useful.

  The new profiler records, for each of its measurements, not just the current
  predicate/function and its caller, but the entire chain of ancestors. This
  "deep context" is what gives the profiler its name. Actually, to keep
  overheads down, we don't walk the stack at every measurement; we just
  associate the current context with each measurement, and update the current
  context when it changes. Given this fact, it costs very little extra to
  record measurements on every aspect of performance (counts of calls, exits,
  fails and redos, counts of memory cells and memory words allocated, and time
  spent). We thus have only one deep profiling grade component, .profdeep,
  as opposed to the old profiler which has several grade components
  for different subsets of these measurements.

* The deep context recorded by the deep profiler records the identities of
  the call sites as well as the identities of predicates and functions
  in the list of ancestors. If a predicate p contains two calls to predicate q,
  this allows the deep profiler to report that one call to q costs next to
  nothing while the other one is a major performance problem.

* The deep profiler gathers so much data that giving it to the user all at once
  would swamp the user with too much information. We therefore implemented the
  deep profiler as a CGI program. Users can use thus use a web browser to
  explore the information contained in profiling data files.

* The deep profiler currently does not handle programs that catch exceptions.

* Further information about the deep profiler is available in the paper
  "Deep profiling: engineering a profiler for a declarative programming
  language" by Thomas C. Conway and Zoltan Somogyi, available from our web
  site at <http://www.cs.mu.oz.au/mercury/information/papers.html#mu_01_24>.

Changes to the compiler back-ends:

* The native code Linux/x86 back-end is now "release quality".

  The native code back-end, which was first released in Mercury 0.10,
  compiles directly to assembler, rather than than going via C.
  This back-end is enabled using the `--target asm' option.  It is
  implemented by linking the Mercury compiler with the (relatively)
  language independent GNU Compiler Collection back-end.  In other words,
  it is a Mercury front-end for GCC.

  This release is the first to be based on an officially released
  version of GCC (it is based on GCC 3.2).  In this release, the native
  code back-end now passes all of the applicable tests in the Mercury test
  suite, including bootstraping the Mercury compiler.  Currently it is only
  supported on i*86-pc-linux-gnu (Intel x86-based PCs running Linux).

  For details see <http://www.cs.mu.oz.au/mercury/download/gcc-backend.html>.

* .NET CLR back-end much improved.

  The .NET CLR back-end, which generates MSIL code for Microsoft's new
  .NET Common Language Runtime, has been substantially improved.
  Mercury data structures are mapped to .NET CLR data types in a more
  natural and more efficient manner.  A lot more of the standard library
  is now supported.  Text files on Windows are now output with proper
  Windows CR-LF line endings.  Many bugs have been fixed.

  This back-end supports the whole of the Mercury language, but the
  Mercury standard library implementation for the .NET CLR is still
  not yet complete.  The .NET CLR back-end now passes about half of
  the tests in the Mercury test suite.

  This back-end is selected when you use the `--grade il' option.

  See <http://www.cs.mu.oz.au/mercury/dotnet.html> and/or
  <http://www.cs.mu.oz.au/mercury/information/dotnet/mercury_and_dotnet.html>.

For news about earlier versions, see the HISTORY file.
2002-12-05 03:47:48 +00:00
Ralph Becket
54255f93e7 Make the Prolog term comparison operators (@<, @=<, @>, @>=)
Estimated hours taken: 32
Branches: main

Make the Prolog term comparison operators (@<, @=<, @>, @>=)
builtin since they're often useful and calling compare/3
can look a little awkward.

Simplification now applies the following transformations on the
new builtin operators:

	X  @< Y    --->    some [R] (compare(R, X, Y), R  = (<))
	X @=< Y    --->    some [R] (compare(R, X, Y), R \= (>))
	X @>  Y    --->    some [R] (compare(R, X, Y), R  = (>))
	X @>= Y    --->    some [R] (compare(R, X, Y), R \= (<))

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/table_gen.m:
	Added `only_mode' argument to calls to
	goal_util__generate_simple_call which now has an extra parameter.

compiler/goal_util.m:
	Added a new parameter, ModeNo, to goal_util__generate_simple_call.
	ModeNo is either
	- `only_mode' in which case the predicate in question is expected to
	  have exactly one mode or
	- `mode_no(N)' in which case mode number N (counting from 0) is
	  used.
	The inequality transformation uses this to handle calls to compare/3
	with unique arguments (even though the builtin inequality modes don't
	yet handle ui arguments...)

compiler/simplify.m:
	simplify__goal_2 for calls now makes a decision as to whether to
	call simplify__call_goal or simplify__inequality_goal.  The bulk
	of simplify__goal_2 is now in simplify__call_goal.  The
	inequality transformation is handled in simplify__inequality_goal.

compiler/type_util.m:
	Added comparison_result_type constant.

compiler/NEWS:
	Mention these changes.

library/builtin.m:
	Added the inequalities as built-ins.
	Added the function ordering/2.

library/prolog.m:
	Removed the definitions for @< etc.
2002-11-01 07:07:01 +00:00
Simon Taylor
0387a6e9c2 Improvements for `:- pragma foreign_type'.
Estimated hours taken: 10
Branches: main

Improvements for `:- pragma foreign_type'.
- Allow default Mercury definitions. The Mercury definition must define
  a discriminated union type. The constructors of the Mercury type are
  only visible in predicates which have implementations for all the
  foreign languages the type has implementations for. In all other
  predicates the type is treated as an abstract type (the check for
  this isn't quite right).
- Allow polymorphic foreign types.
- Don't require the `:- pragma foreign_type' for exported foreign types
  to be in the interface. We now only require that all definitions
  have the same visibility.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
	Allow polymorphic foreign types.

compiler/prog_io.m:
	Export code to parse the type name in a type definition for
	use by prog_io_pragma.m.

compiler/make_hlds.m:
	Handle Mercury definitions for foreign types.

	Separate out the code to add constructors and special predicates
	to the HLDS into a separate pass. For foreign types, we don't know
	what to add until all type definitions have been seen.

	Use the C definition for foreign types with `--target asm'.

compiler/modules.m:
	Distinguish properly between `exported' and `exported_to_submodules'.
	Previously, if a module had sub-modules, all declarations,
	including those in the interface, had import_status
	`exported_to_submodules'. Now, the declarations in the
	interface have status `exported' or `abstract_exported'.
	This is needed to check that the visibility of all the
	definitions of a type is the same.

compiler/hlds_pred.m:
	Add a predicate status_is_exported_to_non_submodules, which
	fails if an item is local to the module and its sub-modules.

compiler/hlds_data.m:
compiler/*.m:
	Record whether a du type has foreign definitions as well.

	Also record whether uses of the type or its constructors
	need to be qualified (this is needed now that adding
	the constructors to the HLDS is a separate pass).

compiler/typecheck.m:
	Check that a predicate or function has foreign clauses before
	allowing the use of a constructor of a type which also has
	foreign definitions.

compiler/hlds_pred.m:
compiler/make_hlds.m:
	Simplify the code to work out the goal_type for a predicate.

compiler/hlds_out.m:
	Don't abort on foreign types.

	Print the goal type for each predicate.

compiler/error_util.m:
	Handle the case where the message being written is a
	continuation of an existing message, so the first line
	should be indented.

compiler/module_qual.m:
	Remove unnecessary processing of foreign types.

doc/reference_manual.tex:
	Document the change.

	Update the documentation for mixing Mercury and foreign clauses.
	The Mercury clauses no longer need to be mode-specific.

tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_type2.{m,exp}:
tests/hard_coded/foreign_type.m:
tests/hard_coded/intermod_foreign_type.{m,exp}:
tests/hard_coded/intermod_foreign_type2.m:
tests/invalid/Mmakefile:
tests/invalid/foreign_type_2.{m,err_exp}:
tests/invalid/foreign_type_visibility.{m,err_exp}:
	Test cases.

tests/invalid/record_syntax.err_exp:
	Update expected output.
2002-06-30 17:07:20 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

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

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

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

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

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

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

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

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

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

compiler/*.m:
	Change type_id to the more descriptive type_ctor everywhere.
2002-03-07 08:30:28 +00:00
Fergus Henderson
ceae383ec2 Fix some bugs with the hlc.agc grade where the compiler was generating
Estimated hours taken: 2
Branches: main

Fix some bugs with the hlc.agc grade where the compiler was generating
references to type_info variables that were not in scope.

compiler/hlds_pred.m:
	Document the invariant that type_info arguments must precede
	non-type_info arguments, since MLDS->C accurate GC relies on this.

compiler/type_util.m:
	Add new function put_typeinfo_vars_first, for use by lamdbda.m
	and ml_code_gen.m.

compiler/lambda.m:
	Call put_typeinfo_vars_first on the arguments of the introduced
	procedures, to ensure that invariant documented in hlds_pred.m holds.

compiler/ml_code_gen.m:
	Call put_typeinfo_vars_first on the list of local variables
	that we generate for each subgoal, to avoid referring to type_info
	variables that are not in scope in the GC tracing code.
2002-03-05 10:59:23 +00:00
Fergus Henderson
7622e889e0 Define the `heap_pointer' type in private_builtin.m as a new builtin
Estimated hours taken: 2
Branches: main

Define the `heap_pointer' type in private_builtin.m as a new builtin
type with representation MR_TYPECTOR_REP_HP, rather than as equivalent
to `c_pointer'.  This is needed so that the accurate garbage collector
can tell saved heap pointer values apart from other c_pointer values,
which it needs to do in order to handle saved heap pointer values.

library/private_builtin.m:
runtime/mercury.h:
runtime/mercury.c:
	Define the type_ctor_info etc. for the heap_pointer type.

compiler/type_util.m:
	Add a new function `heap_pointer_type'.

compiler/add_heap_ops.m:
	Use `heap_pointer_type' from type_util.m.
2002-02-05 09:14:55 +00:00