Commit Graph

249 Commits

Author SHA1 Message Date
Julien Fischer
f3ecb78195 Remove supported for deprecated syntax. The syntax removed is:
Estimated hours taken: 0.5
Branches: main

Remove supported for deprecated syntax.  The syntax removed is:

	- ':' as a module qualifier.
	- '::' and '->' for mode definitions.
	- the old-style pragma syntax.

The 0.12 release issues warnings for uses of this syntax.

XXX This also needs to be mentioned in the news file, but since I need to
clean up the main branch news file I'll do that as a separate change.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
compiler/prog_io_util.m:
	Remove support for the syntax mentioned above.

	Break up an overlong line.

doc_reference_manual.texi:
	Remove the documentation for the above syntax.

compiler/recompilation.m:
compiler/rl_info.m:
compiler/fact_table.m:
	Remove deprecated syntax from these modules.
2005-09-12 08:20:27 +00:00
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
Julien Fischer
a25ba19ea0 Improve the error checking for mutable declarations.
Estimated hours taken: 12
Branches: main

Improve the error checking for mutable declarations.

Fix a bug with solver types and sub-modules reported by Peter Hawkins.

Workaround a bug with mutable declarations and sub-modules.  Currently,
the compiler aborts if there is a mutable declaration in the parent module.
With this change mutable declarations will not be visible in child modules.

XXX This is not correct since they should be visible, but this can be fixed
as a separate change.

compiler/prog_data.m:
	Extend the item_origin type with information about what
	source-to-source transformations are responsible for compiler
	introduced items.  We need this information for error checking mutable
	declarations.  It also provides an additional layer of sanity checking
	in the parse tree.

	Add origin fields to the clause and initialise items, since they can
	both now be introduced by source-to-source transformations.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_typeclass.m:
	Conform to the above change.

compiler/make_hlds_passes.m:
	Don't issue spurious errors about initialise declarations that were
	introduced by the transformation for mutable declarations.  Abort if
	invalid initialise declarations were introduced by other compiler
	passes since this indicates a bug in the compiler.

	Check if mutable declarations occur in the interface of a module and
	emit an error if they do.

	Don't generate initialise items and foreign code from a mutable
	declaration unless we are in the defining module for the mutable
	declaration.

	Don't generate foreign_procs for solver types *unless* we are in the
	defining module.  Doing otherwise breaks the compiler when using
	solver types and sub-modules.

	Fix the formatting of an error message concerning initialise decls.
	s/foreign_code/foreign_proc/ in a spot.

compiler/add_solver.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/add_class.m:
compiler/add_pragma.m:
compiler/state_var.m:
	Conform to the above changes.

compiler/modules.m:
	Handle mutable declarations in private interfaces.

	Clean up some code related to foreign_import_module decls.

	Conform to the changes in prog_data.m.

compiler/prog_util.m:
	Shift the functions for mutable access predicates and variables to
	this module.  The code that generates interface files also needs to be
	able to access them.

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

	Fix a bug where the context in the mq_info structure was not being
	updated.  This caused error messages for mutable declarations that
	contain undefined types or insts to have the wrong context.

compiler/hlds_data.m:
	Fix a typo.

vim/syntax/mercury.vim:
	Highlight `mutable' and `untrailed' appropriately.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/ts.m:
tests/hard_coded/sub-modules/ts.tsub.m:
tests/hard_coded/sub-modules/ts.exp:
	Add Peter Hawkin's test case for the bug with solver
	types and sub-modules.

tests/invalid/Mmakefile:
tests/invalid/bad_mutable.m:
tests/invalid/bad_mutable.err_exp:
	Add a test for the various sorts of errors that can occur with mutable
	declarations.
2005-09-12 03:05:51 +00:00
Julien Fischer
68d2c2e1e1 Improve error reporting for initialise declarations.
Estimated hours taken: 2
Branches: main

Improve error reporting for initialise declarations.

Make clauses in module interfaces an error rather than a warning.
Do the same for pragmas that should not occur in a module interface.

compiler/make_hlds_error.m:
	Add two new predicates that handle error reporting for items that
	should not occur in module interfaces.

compiler/make_hlds_warn.m:
	Remove the predicate for warning about items that should not occur in
	module interfaces.  It is now unused.

compiler/make_hlds_passes.m:
	Do not emit an error for export declarations that have ended up in the
	interface of a module as a result of the source-to-source
	transformation used to implement initialise declarations.

	Report initialise declarations that refer to predicates that do not
	exist directly rather than reporting that the introduced export
	pragmas are incorrect.  The latter is confusing since the pragmas
	do not appear in the source code

	Delete the XXX comment about the above.  Also fix the description of
	the transformation used to implement initialise declarations.

	Make clauses in a module interface an error rather than a warning.
	When reporting this also print out the name and arity of the predicate
	or function to which the clauses belong.

	Make it an error for pragmas that are not allowed in a module
	interface to occur in a module interface.

compiler/prog_data.m:
	Add a type that allows us to distinguish between items that originated
	with user code and those introduced by source-to-source
	transformations on the parse tree.

compiler/recompilation.version.m:
compiler/recompilation.check.m:
compiler/prog_io_pragam.m:
compiler/prog_io.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/add_pragma.m:
compiler/add_solver.m:
compiler/equiv_type.m:
compiler/intermod.m:
	Conform to the above changes.

tests/invalid/Mmakefile:
tests/invalid/not_in_interface.m:
tests/invalid/not_in_interface.err_exp.m:
	Test cases for the above errors.

tests/invalid/bad_initialise_decl.m:
tests/invalid/bad_initialise_decl.err_exp:
	Update this test case.
2005-09-05 03:45:59 +00:00
Ralph Becket
da2984c507 Add `:- mutable' directives to the language, providing modules with private
Estimated hours taken: 24
Branches: main

Add `:- mutable' directives to the language, providing modules with private
mutable variables.  A directives

:- mutable(x, int, 0, ground, [thread_safe]).

leads to the compiler generating the following:

:- semipure pred get_x(int::out(ground)) is det.
:- impure   pred set_x(int::in(ground)) is det.
:-          pred initialise_mutable_x(io::di, io::uo) is det.
:- initialise initialise_mutable_x/2.

initialise_mutable_x(!IO) :-
	promise_pure(
		impure set_x(0)
	).

:- pragma foreign_decl("C", "MR_Word mutable_variable_x;").

:- pragma foreign_proc("C", get_x(X::out(ground)),
[thread_safe, promise_semipure],
"MR_trail_current_value(&mutable_variable_x); X = mutable_variable_x;").

:- pragma foreign_proc("C", set_x(X::in(ground)),
[thread_safe],
"mutable_variable_x = X;").

Possible attributes for a mutable variable are `thread_safe' and
`untrailed'.



NEWS:
	Mention the new language feature.

compiler/make_hlds_passes.m:
	Handle the new mutable/5 item.

	Pass 1 expands a mutable directives into the pred
	declaration items.

	Pass 2 expands a mutable directives into the initialise
	and foreign_decl declaration items.

	Pass 3 expands a mutable directives into the initialise
	declaration and the clauses for the preds.

compiler/mercury_to_mercury.m:
compiler/mercury_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Cover the new mutable/5 item.

compiler/prog_data.m:
	Add a new mutable/5 program item.

compiler/prog_io.m:
	Parse `:- mutable' directives.

compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
	Move list_term_to_term_list from prog_io_typeclass to prog_io_util
	(it's a generally useful predicate).

doc/reference_manual.texi:
	Document the new `:- mutable' directive.

tests/hard_coded/Mmakefile:
tests/hard_coded/mutable_decl.m:
tests/hard_coded/mutable_decl.exp:
	Added a test case that only runs in trailing grades.
2005-09-05 02:29:59 +00:00
Ralph Becket
88b75863dc Add support for initialisation predicates to be called before main/2 is
Estimated hours taken: 16
Branches: main

Add support for initialisation predicates to be called before main/2 is
invoked.  The new directive is `:- initialise initpredname.'

NEWS:
	Mention the new functionality.

compiler/export.m:
	`:- pragma export' also adds a C function declaration in the
	generated C wrapper code to avoid C compiler warnings about
	missing declarations.

compiler/hlds_module.m:
	Added a new user_init_preds field to the module_info to
	record the preds named in `initialise' directives.
	Added predicates to access and update the new field.
	The exported names are generated automatically.

compiler/llds.m:
	Added a new field cfile_num_user_inits to c_file structure.

compiler/llds_out.m:
	Add code to include the `REQUIRED_INIT initpredexportname' lines
	in the comment section of the generated C that is recognised
	by mkinit.

compiler/make_hlds_passes.m:
	Handle the new `initialise' directives.

compiler/mercury_compile.m:
	Make sure the list of user defined init pred export names is passed to
	the C code construction preds.

compiler/mercury_to_mercury.m:
	Handle the output of `initialise' directives.

compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Handle the new `initialise' item.

compiler/prog_data.m:
	Add a new `initialise(sym_name)' item.

compiler/prog_io.m:
	Add code to parse `initialise' directives.

compiler/prog_mode.m:
	Add di_mode pred and func.

compiler/transform_llds.m:
	Handle the extra field in c_file.

doc/reference_manual.texi:
	Update the operator table in the reference manual.
	Document the new `initialise' directive.

library/list.m:
	Added index[01]_of_first_occurrence preds and
	det_index[01]_of_first_occurrence funcs.  I've often
	had a need for these and they are used in looking up
	initprednames in the new module_info field.

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

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
	Add a new exported variable, MR_address_of_init_modules_required.
	Call the function pointed to by this variable at the right point
	during module initialisation.

test/hard_coded/Mmakefile:
test/hard_coded/initialise_decl.exp:
test/hard_coded/initialise_decl.m:
test/invalid/Mmakefile:
test/invalid/bad_initialise_decl.err_exp:
test/invalid/bad_initialise_decl.m:
	Added test cases.

util/mkinit.c:
	Now always checks C files for extra inits (previously you had to
	explicitly supply the -x flag).
2005-08-29 03:22:32 +00:00
Mark Brown
943f590bfb Relax the restriction on the constraints on existentially quantified data
Estimated hours taken: 1.5
Branches: main

Relax the restriction on the constraints on existentially quantified data
structures.  The type variables in constraints must be determined by the
constructor arguments and functional dependencies, but don't necessarily
have to appear directly in the constructor arguments.

compiler/check_typeclass.m:
	Implement a check for type declarations which is analogous to the
	existing check for pred/func declarations.

compiler/prog_io.m:
	Relax the existing restriction, which was applied at parse-time.
	Now we just check that all existentially quantified type vars appear
	somewhere, either in the arguments or in the constraints.

	Remove an XXX comment that asked whether the check that all
	constrained variables were existentially quantified was overly
	restrictive.  The answer is no: we don't support existential
	constraints with universal arguments, and we won't support it in
	the foreseeable future.

tests/invalid/Mmakefile:
tests/invalid/fundeps_unbound_in_ctor.err_exp:
tests/invalid/fundeps_unbound_in_ctor.m:
	New test case for the new and changed error messages.

tests/invalid/type_vars.err_exp:
	Updated test case.

tests/valid/Mmakefile:
tests/valid/fundeps.m:
	New test case.
2005-05-13 02:24:20 +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
Mark Brown
47b6f6b200 Fix a buglet that was stopping the compiler from being compiled.
Estimated hours taken: 0
Branches: main

compiler/prog_io.m:
	Fix a buglet that was stopping the compiler from being compiled.
2005-03-18 05:59:17 +00:00
Ralph Becket
ef63c04c2d Fix typo.
Estimated hours taken: 0.5
Branches: main, release

compiler/prog_io.m:
	Fix typo.
2005-03-18 01:02:01 +00:00
Ralph Becket
8eedd4b80b Make the ground is ...' and any is ...' attributes optional in solver
Estimated hours taken: 0.5
Branches: main, release

compiler/prog_io.m:
doc/reference_manual.texi:
	Make the `ground is ...' and `any is ...' attributes optional in solver
	type definitions, defaulting to `ground' if absent.

	Reflect this change in the documentation.
2005-03-18 00:58:15 +00:00
Zoltan Somogyi
99af5e671a Provide a mechanism to allow a predicate to be defined as a foreign_proc for
Estimated hours taken: 10
Branches: main

Provide a mechanism to allow a predicate to be defined as a foreign_proc for
one backend and as external for another backend. The intended use is to
implement builtin_catch in exception.m, which cannot be implemented as a
foreign_proc for hlc grades, but whose implementation as external for the
LLDS grades requires handwriting extremely error-prone code and data structures
that the compiler could generate reliably.

The mechanism is two language extensions. One allows :- external declarations
such as

	:- external(high_level_backend, p/3).

The second allows foreign_procs such as

	:- pragma foreign_proc("C",
	       p(N::in, IO0::di, IO::uo),
	       [will_not_call_mercury, promise_pure, low_level_backend],
	       ...

compiler/prog_data.m:
	Add an extra field to the items for `:- external' declarations to
	allow hold the optional backend designation.

	Add an extra optional attribute to foreign_procs to handle the
	backend designation.

compiler/prog_io_pragma.m:
	Change the code for reading external declarations to handle the new
	attribute.

compiler/prog_io_pragma.m:
	Change the code for reading foreign_proc attributes to handle the new
	attribute.

compiler/make_hlds.m:
	Ignore external declarations and foreign_proc definitions if they are
	for the wrong backend.

	Use state variables in a place that can benefit from it.

compiler/hlds_module.m:
	Clean up some formatting.

compiler/equiv_type.m:
compiler/ml_code_gen.m:
compiler/module_qual.m:
compiler/modules.m:
	Conform to the changed data structures in prog_data.

doc/reference_manual.texi:
	Add commented-out documentation of the extension to foreign_procs.
	There is no existing documentation of :- external to update.

tests/hard_coded/backend_external.{m,exp,exp2}:
	New test case for the new language extensions.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2005-03-10 02:36:04 +00:00
Julien Fischer
4aa7104e19 Replace deprecated mode and inst syntax.
Estimated hours taken: 0.1
Branches: main, release

browser/declarative_execution.m:
browser/declarative_tree.m:
compiler/mode_constraints.m:
compiler/prog_io.m:
compiler/rl_file.pp:
	Replace deprecated mode and inst syntax.
2005-02-07 11:41:05 +00:00
Ian MacLarty
4970242093 Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id
Estimated hours taken: 4
Branches: main

Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id
defined in mdb.declarative_execution and delete proc_id, since these data
structures are almost identical.

browser/declarative_execution.m
	Remove proc_id and flat_module_name types.  Use
	mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name instead.

browser/declarative_debugger.m
browser/declarative_oracle.m
browser/declarative_tree.m
browser/declarative_user.m
	Use mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name
	instead of mdb.declarative_execution.proc_id and
	mdb.declarative_execution.module_name.

mdbcomp/prim_data.m
compiler/prog_out.m
	Move sym_name_to_string from prog_out to prim_data.
	Fix comment for prog_out.sym_name_and_arity_to_string.

compiler/bytecode.m
compiler/check_typeclass.m
compiler/code_gen.m
compiler/deforest.m
compiler/higher_order.m
compiler/hlds_code_util.m
compiler/hlds_error_util.m
compiler/hlds_module.m
compiler/hlds_out.m
compiler/intermod.m
compiler/layout_out.m
compiler/make.module_target.m
compiler/make_hlds.m
compiler/mercury_compile.m
compiler/mercury_to_mercury.m
compiler/ml_elim_nested.m
compiler/mlds_to_c.m
compiler/mlds_to_gcc.m
compiler/mlds_to_il.m
compiler/mlds_to_java.m
compiler/mlds_to_managed.m
compiler/modes.m
compiler/modules.m
compiler/opt_debug.m
compiler/options_file.m
compiler/polymorphism.m
compiler/prog_io.m
compiler/prog_rep.m
compiler/rl.m
compiler/rl_exprn.m
compiler/rl_gen.m
compiler/rl_info.m
compiler/rl_out.pp
compiler/rtti.m
compiler/rtti_out.m
compiler/rtti_to_mlds.m
compiler/source_file_map.m
compiler/table_gen.m
compiler/trans_opt.m
compiler/unify_gen.m
compiler/unique_modes.m
compiler/unused_args.m
	Use mdbcomp.prim_data.sym_name_to_string instead of
	prog_out.sym_name_to_string.
2005-02-01 07:11:42 +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
Zoltan Somogyi
20cd51e70a This is a cleanup diff; there are no changes in algorithms.
Estimated hours taken: 8
Branches: main

This is a cleanup diff; there are no changes in algorithms.

compiler/delay_info.m:
compiler/instmap.m:
compiler/inst_match.m:
compiler/inst_util.m:
compiler/make.module_target.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/mode_util.m:
compiler/process_util.m:
compiler/prog_io_goal.m:
compiler/prog_io.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/unique_modes.m:
	Bring these modules up to date with our current style guidelines.
	Switch to predmode syntax and state variable notation where
	appropriate. Switch argument orders where this makes it possible
	to use state variable notation. Use the svmap and svset modules
	where appropriate. Fix inconsistent indentation; in some places,
	fix inconsistent placement of comments.

compiler/passes_aux.m:
compiler/modecheck_unify.m:
compiler/mercury_compile.m:
compiler/post_typecheck.m:
compiler/prog_io_dcg.m:
compiler/mode_ordering.m:
compiler/inst_graph.m:
compiler/polymorphism.m:
compiler/prog_io_util.m:
compiler/mode_debug.m:
compiler/mode_robdd.check.m:
compiler/transform.m:
	Minor changes to conform to the changed argument orders of some
	predicates in the cleaned up modules. Also, some minor cleanups.
2004-12-23 06:49:21 +00:00
Julien Fischer
d721ca08de Remove support for NU-Prolog style `when' declarations.
Estimated hours taken: 0.5
Branches: main

Remove support for NU-Prolog style `when' declarations.
These have been deprecated for some time.

NEWS
	Mention this change.

compiler/prog_data.m:
compiler/prog_io.m:
	Remove remaining support for when declarations.

tests/general/interpreter.m:
tests/valid/lazy_list.m:
	Remove some old when declarations.
2004-09-29 04:36:28 +00:00
Julien Fischer
211a93a278 Fix some compilation errors in Ralph's
Estimated hours taken: 0.5
Branches: main

compiler/prog_io.m:
	Fix some compilation errors in Ralph's
	bug fixes for the solver types code.
2004-09-10 08:01:33 +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
d332038ee1 Bring these modules up to date with our coding guidelines.
Estimated hours taken: 16
Branches: main

compiler/aditi_builtin_ops.m:
compiler/bytecode.m:
compiler/bytecode_backend.m:
compiler/bytecode_gen.m:
compiler/c_util.m:
compiler/code_gen.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dependency_graph.m:
compiler/fact_table.m:
compiler/follow_code.m:
compiler/handle_options.m:
compiler/hlds_out.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/java_util.m:
compiler/liveness.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/matching.m:
compiler/name_mangle.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/options.m:
compiler/options_file.m:
compiler/prog_io.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/source_file_map.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_errors.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
	Bring these modules up to date with our coding guidelines. Use predmode
	syntax for declarations. Use state variable syntax where appropriate,
	and reorder arguments where this is needed for the use of state
	variable syntax. Remove module qualification from the names of defined
	predicates when the module qualification was used inconsistently
	(causing problems for the use of tags) or was causing problems with
	indentation.

	There are no changes in algorithms.
2004-06-30 02:48:20 +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
b39a3d855f This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6
Branches: main

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

compiler/hlds_module.m:
	Bring (most of) this module into line with our current coding
	standards. Use predmode declarations, functions, and state variable
	syntax when appropriate. (The 'most of' is because I left the part of
	the module dealing with predicate tables alone, not wishing to cause
	a conflict for Pete.)

	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.

compiler/*.m:
	Conform to the changes in hlds_module.m. This mostly means using the
	new argument orders of predicates exported by hlds_module.m, and
	switching to state variable notation.

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

	Replace unnecessary occurrences of four-space indentation with
	standard indentation in updated code.

library/list.m:
library/map.m:
library/tree234.m:
	Add list__foldl4 and map__foldl3, since in some compiler modules,
	state variable notation is more convenient (and the code more
	efficient) if we don't have to bundle up several data structures
	into a tuple just to iterate over them.

	Change the fold predicates to use state variable notation.

NEWS:
	Mention the new library functions.
2003-10-31 03:27:39 +00:00
Simon Taylor
404a95cdd7 Remove Unix dependencies in the compiler.
Estimated hours taken: 50
Branches: main

Remove Unix dependencies in the compiler.

Avoid calling passes_aux.invoke_shell_command, which
requires the presence of a Unix shell.

The implementation of fact tables still has dependencies
on Unix utilities (e.g. sort).

aclocal.m4:
	Don't pass Unix style paths to MSVC.

configure.in:
	Use `cygpath -m' rather than `cygpath -w'.
	`cygpath -m' uses '/' as the directory separator,
	so it doesn't cause quoting problems in shell
	scripts.

	Apply $CYGPATH to $PREFIX, $LIBDIR, $CONFIG_PREFIX
	and $CONFIG_LIBDIR.

	Don't pass `-lm' when linking with MSVC.

configure.in:
compiler/options.m:
scripts/Mercury.config.in:
	Add extra configuration options to deal with differences
	between linking with gcc and MSVC:
		--linker-opt-separator
		--linker-link-lib-flag
		--linker-link-lib-suffix
		--shlib-linker-link-lib-flag
		--shlib-linker-link-lib-suffix
		--linker-path-flag

NEWS:
doc/user_guide.texi:
compiler/options.m:
compiler/compile_target_code.m:
compiler/make.program_target.m:
	Instead of substituting in an arbitrary shell script when
	processing `--pre-link-command' and `--extra-init-command',
	require that these options specify a command which will
	be passed the name of the source file containing the main
	module as the first argument, with the source files containing
	the remaining modules following. This is simpler and avoids
	dependencies on a shell.

	Fix quote_arg to handle Windows paths better.

compiler/handle_options.m:
	Don't attempt to use symlinks if they're not available.

compiler/compile_target_code.m:
	Be more careful about quoting.

	Don't call invoke_shell_command where invoke_system_command
	would do.

	Allow linking using MSVC.

compiler/modules.m:
	Remove make_directory, which is now implemented by dir.m.

	Use io.make_symlink rather than shell scripts.

	Implement mercury_update_interface in Mercury.

compiler/llds_out.m:
compiler/make.program_target.m:
	Use dir.make_directory, not modules.make_directory,
	which has been removed.

compiler/make.module_target.m:
	Invoke mercury_compiler directly, not through the
	mmc script to avoid shell dependencies.

	If we can't fork() child `mmc --make' processes,
	pass the arguments to the child process using a
	file to avoid overflowing system limits on Windows.

compiler/mercury_compile.m:
compiler/options_file.m:
	Read argument files.

	Handle backslash-newline in options files correctly.

compiler/passes_aux.m:
	invoke_system_command shouldn't set the exit status --
	the caller may be able to try something else.

compiler/process_util.m:
	Export can_fork for use by make.module_target.m.

	Remove hacks to work around bugs in the implementation
	of zero-arity foreign procs.

compiler/prog_io.m:
	Handle bizarre file names without aborting.

library/Mmakefile:
library/print_extra_inits:
	Move code to find extra initialization functions into
	print_extra_inits, due to the change to the handling
	of the --extra-init-command option described above.

scripts/mmc.in:
	Set the MERCURY_COMPILER environment variable if it is
	not already set, so that the mercury_compile executable
	knows where to find itself.

scripts/mercury.bat.in:
	Make this actually work.

tools/bootcheck:
	Set ANALYSIS_LIB_NAME.

	Apply cygpath (-m not -w) to $root.

	Link print_extra_inits into the stage2 and stage3
	library directories.

util/mkinit.c:
	Handle '\\' in path names.
2003-08-06 12:38:14 +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
Simon Taylor
89a4d190c5 Library changes required to make the compiler work on Windows
Estimated hours taken: 120
Branches: main

Library changes required to make the compiler work on Windows
without Cygwin.  (Compiler changes to come separately).

library/dir.m:
	Handle Windows-style paths.

	Change the determinism of dir.basename and dir.split_name.
	dir.basename now fails for root directories (a new function
	dir.basename_det calls error/1 rather than failing).
	dir.split_name fails for root directories or if the pathname
	passed doesn't contain a directory separator.

	Add predicates dir.make_directory, dir.path_name_is_absolute
	and dir.path_name_is_root_directory.

	Add a multi predicate dir.is_directory separator which
	returns all separators for the platform (including '/' on
	Windows), not just the standard one.

	Add a function dir.parent_directory (returns "..").

	Add dir.foldl2 and dir.recursive_foldl2, to iterate through
	the entries in a directory (and maybe its subdirectories).

	Change '/' to correctly handle Windows paths of the form
	"C:"/"foo" and "\"/"foo".

	Don't add repeated directory separators in '/'.

library/io.m:
	Add io.file_type and io.check_file_accessibility.

	Add predicates to deal with symlinks -- io.have_symlinks,
	io.make_symlink and io.follow_symlink.

	Add io.file_id for use by dir.foldl2 to detect
	symlink loops. This is a bit low level, so it's
	not included in the user documentation.

	Add io.(binary_)input_stream_foldl2_io_maybe_stop, which
	is like io.(binary_)input_stream_foldl2_io, but allows
	stopping part of the way through. This is useful for
	implementing `diff'-like functionality to replace
	mercury_update_interface.

	Use Windows-style paths when generating temporary file
	names on Windows.

	Add versions of the predicates to generate error messages
	to handle Win32 errors.

	Add versions of the predicates to generate error messages
	which take a system error code, rather than looking up
	errno. This simplifies things where the error we
	are interested in was not from the last system call.

library/exception.m:
	Add a predicate finally/6 which performs the same function
	as the `finally' clause in languages such as C# and Java.

	Add predicates try_det, try_io_det and try_store_det,
	which only have one mode so they are more convenient
	to pass to promise_only solution.

library/Mmakefile:
	Add dependencies on runtime/mercury_conf.h for files which
	use the MR_HAVE_* macros.

library/string.m:
	Add a function version of string__index.

NEWS:
	Document the new predicates and functions and the change
	of determinism of dir.split_name and dir.basename.

configure.in:
runtime/mercury_conf.h.in:
	Test for lstat, mkdir, symlink and readlink.

runtime/mercury_conf_param.h:
	Add a macro MR_BROKEN_ST_INO, which is true if the st_ino
	field of `struct stat' is garbage. Currently defined iff
	MR_WIN32 is defined.

compiler/compile_target_code.m:
compiler/modules.m:
compiler/options_file.m:
compiler/prog_io.m:
compiler/source_file_map.m:
	Changes required by the change of determinism of
	dir.split_name and dir.basename.

tests/hard_coded/Mmakefile:
tests/hard_coded/dir_test.{m,exp,exp2}:
	Test case.
2003-07-21 14:08:42 +00:00
Simon Taylor
b9f9de8ed2 The compiler was not module qualifying the `where equality is ...'
Estimated hours taken: 4
Branches: main, release

The compiler was not module qualifying the `where equality is ...'
part of type declarations in interface files. This could cause the
compiler to use the wrong predicate in importing modules if the
user-defined equality predicate was not exported.

To avoid this problem we now require user-defined equality or
comparison predicates for a type to be defined in the same module
as the type. This is the only simple way to module qualify the
unification predicates in interface files without running
typechecking.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Require user-defined equality or comparison predicates for a
	type to be defined in the same module as the type.

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

compiler/typecheck.m:
compiler/post_typecheck.m:
compiler/hlds_pred.m:
compiler/make_hlds.m:
compiler/*.m:
	Calls in the compiler generated unification predicates are
	now guaranteed to be fully qualified, so don't attempt
	to search for more qualified predicates.

	Add a new pred_marker 'calls_are_fully_qualifed' to
	identify predicates whose bodies contain only fully
	qualified calls, rather than testing the import_status.

tests/invalid/Mmakefile:
tests/invalid/exported_unify.m:
tests/invalid/exported_unify2.m:
tests/invalid/exported_unify2.err_exp:
tests/invalid/exported_unify3.m:
tests/invalid/exported_unify3.err_exp:
	Test cases.
2003-05-19 14:24:36 +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
660a24a7ad Fix a bug reported by Michael Day which caused spurious
Estimated hours taken: 8
Branches: main, release

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

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

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

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

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

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

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

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

	Use `lookup_builtin_pred_proc_id' rather than
	`predicate_table_search_*'.

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

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

tests/valid/Mmakefile:
tests/valid/nested_module_bug.m:
tests/valid/intermod_bug_nested.m:
	Test cases.
2003-02-22 13:18:34 +00:00
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
Simon Taylor
04ca8ecfbf Fix a double full stop in an error message.
Estimated hours taken: 0.1
Branches: main, release

compiler/prog_io.m:
	Fix a double full stop in an error message.
2003-01-24 07:44:44 +00:00
Simon Taylor
886d2ae474 Make it easier to use shared libraries on x86 with
Estimated hours taken: 20
Branches: main

Make it easier to use shared libraries on x86 with
`mmc --make'.

There is now a third kind of object file, `.lpic_o'.
These files are compiled with `--pic-reg' but not with
CFLAGS_FOR_PIC, so they can be linked with shared Mercury
libraries.

On x86, executables which are linked with shared Mercury
libraries now depend on $(main_module.lpic_os), not
$(main_module.os).

This doesn't work with Mmake because ml doesn't know
which libraries are Mercury libraries, so it can't
link with the static versions of those libraries if
MERCURY_LINKAGE is set to "static".

configure.in:
bindist/bindist.configure.in:
bindist/bindist.build_vars.in:
	Work out whether `.lpic_o' files are needed.

compiler/modules.m:
	Add `.lpic_o' to the list of grade or architecture
	dependent files.

NEWS:
README.Linux:
compiler/options.m:
doc/user_guide.texi:
	Document MERCURY_LINKAGE, LINKAGE, --linkage,
	--mercury-linkage and -R.

compiler/options_file.m:
compiler/make.program_target.m:
	Handle LINKAGE and MERCURY_LINKAGE variables.

	Allow LIBGRADES, LINKAGE and MERCURY_LINKAGE to be target-specific.

scripts/mmc.in:
	Set up the default linkage using the MERCURY_LINKAGE
	variable.

compiler/compile_target_code.m:
	Build `.lpic_o' files.

	Work out which type of object files to link with.

	When linking statically with Mercury libraries,
	find the absolute pathname for the `.a' file
	for each Mercury library, and pass that to ml,
	rather than just using `-lname'.

	Pass `-R' options to ml for each `-R' option to mmc.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
	Specify which type of object files to build.

compiler/make.program_target.m:
compiler/make.module_target.m:
	Make sure all generated object files are cleaned up.

compiler/prog_io.m:
	Add a better message for files which can't be found.

compiler/make.util.m:
	Add `.lpic_o' to the list of extensions.

compiler/Mmakefile:
profiler/Mmakefile:
deep_profiler/Mmakefile:
	Pass `--linkage shared' to mmc (`--shared' is in MLFLAGS).

tests/Mmakefile:
tests/mmc_make/Mmakefile:
tests/mmc_make/Mercury.options:
tests/mmc_make/complex_test.{m,exp}:
tests/mmc_make/hello.{m,exp}:
	Test `mmc --make'.

tests/lib/complex*.m:
	The complex numbers library from the extras distribution,
	for use in the mmc_make tests.
2003-01-23 00:24:20 +00:00
Ralph Becket
6dd11c5583 Allow field access syntax at the top-level of func and mode declarations and
Estimated hours taken: 3
Branches: main

Allow field access syntax at the top-level of func and mode declarations and
in function clause heads.

NEWS:
	Report the new feature.

doc/reference_manual.texi:
	Document the new feature.

compiler/prog_io.m:
	Implement the new feature.

tests/hard_coded/Mmakefile:
tests/hard_coded/field_syntax.exp:
tests/hard_coded/field_syntax.m:
	Added a test case.
2003-01-16 02:34:35 +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
afffc4bdac Mostly minor fixes to make test cases pass after the state variable
Estimated hours taken: 6
Branches: main

Mostly minor fixes to make test cases pass after the state variable
transformation was introduced.

compiler/make_hlds.m:
	Reversed previous changes that accidentally undid prior work.
	Added state variable transformation to previously missed aditi cases.

tests/invalid/Mmakefile:
	Removed entry for state_vars_test5.m

tests/invalid/state_vars_test3.m:
tests/invalid/state_vars_test3.err_exp:
	Moved this test to tests/warning as state_vars_test.

tests/invalid/state_vars_test4.m:
tests/invalid/state_vars_test4.err_exp:
tests/invalid/state_vars_test5.m:
tests/invalid/state_vars_test5.err_exp:
	Renamed 4->3 and 5->4.

tests/invalid/aditi_update_errors.err_exp:
	The state variable transformation considers conjuncts in reverse
	order w.r.t. before, changing the expected order of these error
	messages.

tests/invalid/overloading.err_exp:
tests/invalid/record_syntax_errors.err_exp:
	Some variable numbers changed after introduction of the state
	variable transformation.

tests/warnings/Mmakefile:
tests/warnings/state_vars_test.m:
tests/warnings/state_vars_test.exp:
	This was tests/invalid/state_vars_test3.{m,exp}.
2002-08-01 00:41:40 +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
Simon Taylor
fc8725fc3c Allow arbitrary mappings from source file name to module name.
Estimated hours taken: 8
Branches: main

Allow arbitrary mappings from source file name to module name.
The mapping is created using the command `mmc -f *.m', which must
be run before `mmake depend'.

compiler/parse_tree.m:
compiler/source_file_map.m:
compiler/notes/compiler_design.html:
	Add a new module to read, write and search the mapping.

compiler/modules.m:
	Use the source file map when searching for source files.

	Export `make_directory' for use by source_file_map.m.

	Use the module name rather than the source file name to
	generate the executable name. This matches the documentation
	in the User's Guide, and it's needed to make the tests work.

compiler/prog_io.m:
	Separate out the code to read the first item in a module to
	find the module name into a new predicate, `find_module_name'.

compiler/handle_options.m:
	Don't complain about the module name not matching the file
	name when generating the Mercury.modules file -- the file
	only needs to be generated when the module name doesn't
	match the file name.

compiler/llds_out.m:
	Remove a duplicate copy of `make_directory'.

compiler/options.m:
compiler/mercury_compile.m:
doc/user_guide.texi:
	Add the `--generate-source-file-mapping' (-f) option
	to generate the mapping.

NEWS:
	Document the change.

tests/hard_coded/Mmakefile:
tests/hard_coded/source_file_map.m:
tests/hard_coded/mapped_module.exp:
	Test case.
2002-04-15 05:04:23 +00:00
Simon Taylor
b98d3d5a0e Fix bugs in the handling of predicate and function
Estimated hours taken: 1.5
Branches: main

Fix bugs in the handling of predicate and function
declarations using `with_type`.

compiler/prog_io.m:
	Fix spurious errors for `with_type` and determinism
	in the one declaration. Function declarations with
	the default modes can use this form of declaration.

compiler/mercury_to_mercury.m:
	Fix the order of `with_type` annotations and class constraints.

tests/recompilation/unchanged_with_type*:
	Test case.
2002-04-09 09:00:33 +00:00
Simon Taylor
811c0af920 Make inter-module optimization work properly with sub-modules.
Estimated hours taken: 15
Branches: main

Make inter-module optimization work properly with sub-modules.

compiler/intermod.m:
	Write `exported_to_submodules' predicates to the `.opt' file.

	Read `.int0' files needed by the `.opt' files.

compiler/make.dependencies.m:
compiler/modules.m:
	Handle dependencies on the extra `.int0' files when compiling
	with `--intermodule-optimization'.

compiler/modules.m:
compiler/prog_io.m:
compiler/*.m:
	Handle partially qualified file names when searching for
	the `.m' file for a module when checking whether there
	should be a dependency on the `.opt' file for the module.

	Separate out the code to find for the source file for a module
	from the code to read the source file for a module.

	Remove an unnecessary argument from prog_io__read_opt_file
	(`.opt' files are always searched for).

compiler/modules.m:
	Export process_module_private_interfaces, for use by intermod.m.

	Remove process_module_indirect_imports, which isn't used anywhere.

	Change get_ancestors from a predicate to a function.

compiler/make_hlds.m:
	Don't report duplicate declaration errors for items imported
	for inter-module optimization. Sometimes both the `.int' and
	`.int0' file for a module are read, and the `.int0' file contains
	everything in the `.int' file..

compiler/modes.m:
compiler/post_typecheck.m:
	Don't report errors for duplicate mode declarations for imported
	predicates when performing inter-module optimization. If the
	`.int' and `.int0' files for a module are both read, the mode
	declarations for a predicate can be read twice.

	Where there are duplicate mode declarations, remove the
	duplicate procedures.

	Move the code to check for indistinguishable modes into
	post_typecheck.m. It only needs to be done once, not
	on every iteration of mode inference.

compiler/hlds_pred.m:
	Add a predicate pred_info_remove_procid, for use by post_typecheck.m.

compiler/mercury_to_mercury.m:
	Improve the comment generated for module_defn items which shouldn't
	appear in Mercury source.

compiler/notes/compiler_design.html:
	Improve the documentation of post_typecheck.m.

tests/invalid/qualified_cons_id2.err_exp:
	Update expected output.
2002-04-07 10:23:06 +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
Simon Taylor
d96f7a9bd5 Allow declarations of the form
Estimated hours taken: 40
Branches: main

Allow declarations of the form
:- pred p `with_type` higher_order_type `with_inst` higher_order_inst.

XXX We should allow `with_inst` annotations on higher-order terms.

compiler/prog_data.m:
	Add fields to `pred_or_func' and `pred_or_func_mode'
	items to hold the `with_type` and `with_inst` annotations.

compiler/prog_io.m:
compiler/prog_io_typeclass.m:
	Parse the annotations.

compiler/module_qual.m:
	Module qualify the annotations.

compiler/equiv_type.m:
	Expand away `with_type` and `with_inst`. Report errors.

	Strip items containing errors from the item list.

	Record smart recompilation dependencies on the types and
	modes expanded. Also record a dependency on the arity of
	predicate and function declarations before expansion.

	Use error_util for error messages.

compiler/mercury_to_mercury.m:
	Write `with_type` and `with_inst` annotations to interface files.

compiler/make_hlds.m:
	Ignore `with_type` and `with_inst` fields in predicate and
	function declarations.

compiler/recompilation.m:
	Changes to allow equiv_type.m to record dependencies on
	arbitrary items, not just types.

compiler/recompilation_usage.m:
compiler/recompilation_check.m:
	Allow searches in the sets of used predicates and functions using
	name, not name and arity, as the key. This is needed because
	the actual arity of a predicate defined using `with_type` is
	not known when writing the interface files.

compiler/recompilation_version.m:
	Handle `with_inst` and `with_type`.

	Pragmas now need to be recorded in the version_numbers even
	if there is no matching `:- pred' or `:- func' declaration --
	the pragma may apply to a predicate or function declared using
	`with_type`.

compiler/mode_util.m:
	Export inst_subsitute_arg_list for use by equiv_type.m.

compiler/error_util.m:
	Add predicate `pred_or_func_to_string'.

library/std_util.m:
	Add std_util__map_foldl_maybe and std_util__map_foldl2_maybe,
	which are like list__map_foldl and list__map_foldl2, but
	apply to the item stored in a value of type std_util__maybe.

NEWS:
doc/reference_manual.texi:
	Document the new syntax and library predicates.

tests/invalid/Mmakefile:
tests/invalid/with_type.m:
tests/invalid/with_type.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/recompilation/TESTS:
tests/recompilation/unchanged_with_type_nr*:
tests/recompilation/with_type_re*:
	Test cases.

tests/invalid/errors1.err_exp:
tests/invalid/type_loop.err_exp:
tests/invalid/vars_in_wrong_places.err_exp:
	Update expected output.
2002-03-15 07:32:27 +00:00
David Overton
da2ed598e0 Extend constrained polymorphic modes to allow inst parameters to be
Estimated hours taken: 80
Branches: main

Extend constrained polymorphic modes to allow inst parameters to be
constrained to insts other than `ground'.  The main motivation for this
is that for HAL we want inst parameters constrained to `any', however
this change is more general and allows inst parameters to be constrained
to any valid inst.

Introduce the syntax `InstParam =< Inst' to constrain an inst parameter
`InstParam' to an inst `Inst' in a predicate or function mode
declaration.

compiler/inst.m:
	Add a new alternative `constrained_inst_var(inst_var, inst)' to
	the `inst' type.
	Remove `constrained_inst_var(inst_var)' alternative from the
	`ground_inst_info' type.

compiler/inst_match.m:
compiler/inst_util.m:
compiler/modecheck_unify.m:
	Make changes required to the core mode checking algorithms to
	handle the change.

compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/make_hlds.m:
	Add support for `=<'/2 insts, but only when parsing predicate
	and function mode declarations, lambda argument modes, and
	pragmas.
	Also add support for specifying inst constraints in the constraints list
	for a declaration.
	Make sure any unconstrained inst parameters in these
	declarations are constrained to be `ground'.
	Check that all constraints for a declaration are consistent,
	i.e. the same constraint for every occurrence of an inst
	parameter.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
	Support printing of `=<'/2 insts.

compiler/mode_util.m:
compiler/module_qual.m:
compiler/pd_util.m:
compiler/recompilation_usage.m:
	Handle the changes to the definition of the `inst' type.

doc/reference_manual.texi:
	Document the change.

tests/valid/Mmakefile:
tests/valid/constrained_poly_insts.m:
tests/invalid/Mmakefile:
tests/invalid/constrained_poly_insts.m:
	Add some test cases.
2002-03-14 01:10:44 +00:00
Simon Taylor
9c9601808d Add an alternative implementation of Mmake as part of the compiler.
Estimated hours taken: 500

Add an alternative implementation of Mmake as part of the compiler.
The advantages of this are
	- more accurate dependencies
	- no `mmake depend' step
	- less process creation (no processes are created to
		build interface files).

Still to do:
	- handle --split-c-files
	- handle the IL backend properly
	- library installation
	- allow the compiler to be built and the nightly tests
	  to be run with `mmc --make'

compiler/make.m:
	Control the build process.

compiler/make.program_target.m:
	Build executables and libraries.

compiler/make.module_target.m:
	Build C files, object files, interface files etc.

compiler/make.dependencies.m:
	Work out the depenendencies between targets.

compiler/make.module_dep_file.m:
	Record the inter-module dependencies between invocations of mmc.

compiler/make.util.m:
	Utility predicates used by `mmc --make'.

compiler/compile_target_code.m:
	This module will eventually contain the predicates used
	to compile the target code files generated by the compiler
	which are now in mercury_compile.m. (That will be done
	as a separate change for ease of reviewing).

	For now compile_target_code.m

compiler/mercury_compile.m:
	Export the predicates used to compile target code.

	Call make.m.

	Pass the name of the top-level module in the source file to modules.m.
	It is needed when generating the `.module_dep' files.

	Lookup the option defaults (which will eventually be stored in
	DEFAULT_MCFLAGS by the mmc script) before compiling. Up until now
	the option defaults have been passed on the command line by the
	mmc script, but with `mmc --make' the default options need
	to be overridden by the value of the MCFLAGS make variable, but
	the MCFLAGS make variable is overridden by command line options.

	Pass the value of `--link-flags' to c2init.

	Remove some uninformative messages printed when a C, IL, etc.
	compilation fails.

compiler/options_file.m:
	Read files containing Make style variable assignments.

compiler/options.m:
doc/user_guide.texi:
	Add a new options category: build system options.

	Add some extra options:
	--warn-undefined-options-variables - like mmake --warn-undefined-vars
	--verbose-commands - print commands that the user might be
		interested in, like C compilation, but not things
		like mercury_update_interface.
	--output-compile-error-lines - print the first n lines
		of the error file generated by a command.
	--generate-mmc-make-modules-dependencies - generate dependencies
		for use by `mmc --make' even when using Mmake.

	--il-assembler, --ilasm-flags, --mcpp-compiler, --mcpp-flags,
	--csharp-compiler, --csharp-flags, --install-prefix,
	--install-command, --libgrades, --options-files,
	--options-search-directories.

compiler/modules.m:
	Add fields to the `module_imports' type for use by make.*m.

	Don't try to fill in fields of the module_imports structure
	lazily. It's error prone, and probably doesn't save much
	anyway.

	Clean up the code to compute what foreign languages
	are used by a list of item.

	Simplify the handling of fact tables by recording that a module
	containing fact tables has foreign code to implement them,
	rather than requiring separate checks everywhere.

	Generalise predicates like get_interface so that they
	work even after the imported items have been read.

	Fix the handling of header files with the LLDS backend.

	Install the `.module_dep' files created for use by
	`mmc --make'.

compiler/*.m:
	Use record syntax rather than explicit deconstruction to
	refer to fields of the `module_imports' type.

compiler/*.m:
	Be more careful about where output goes.
	mercury_compile.m sets the output stream to be io__stderr_stream
	at the start of compilation, so remove all explicit writes to
	io__stderr_stream (with `--make' the error output stream may be
	a `.err' file, not io__stderr_stream).

	Change all occurrences of io__tell/io__told to use
	io__open_output/io__close_output (io__told restores the current
	output stream to io__stdout_stream, not the previous value).

compiler/passes_aux.m:
	Make the output from system commands go to the current
	output stream, not C stdout and stderr.

	Allow commands to be printed with `--verbose-commands'.

	Remove uninformative error messages when a command fails.

compiler/timestamp.m:
	Add functions oldest_timestamp and newest_timestamp.

compiler/llds_out.m:
	Record the number of C files written with `--split-c-files'
	in <module>.num_split.

compiler/prog_io.m:
compiler/*.m:
	`search_for_file' now returns the directory in which the
	file was found.

compiler/foreign.m:
	Use sub-typing to make some calls to predicates in this
	module `det' rather than `semidet'.

compiler/handle_options.m:
	Return the option arguments.

compiler/Mmakefile:
	make.util.m refers to kill() and `struct sigaction' which
	are not exported from <signal.h> unless `--no-ansi' is
	passed to gcc.

compiler/notes/compiler_design.html:
	Document the new modules.

runtime/mercury_signal.h:
runtime/mercury_signal.c:
	Add a function MR_signal_should_restart() which alters
	whether a signal restarts or interrupts system calls.
	In general restarting is the preferred behaviour, but
	the wait() for a child process needs to be interruptible.

scripts/Mmake.vars.in:
	Add subdirs for `.module_dep', `.err_date'
	and `.num_split' files.

library/io.m:
	Add a version of io_call_system which returns the signal
	that killed the command rather than converting it into
	an error message.

	Add a predicate to interpret the result of system() or wait().

library/list.m:
	Add list__map_foldl2 and a unique mode for list__foldl3.

NEWS:
	Document the new library predicates.

configure.in:
runtime/mercury_conf.h.in:
	Check for siginterrupt().

doc/user_guide.texi:
	Document the new options.

	Add a description of `mmc --make' to the "Using Mmake" chapter.
2002-03-12 16:33:37 +00:00
Zoltan Somogyi
7fbb09dc04 Delete the code "handling" undiscrimited unions.
Estimated hours taken: 1
Branches: main

compiler/*.m:
	Delete the code "handling" undiscrimited unions. Their presence
	slows things down, the error messages they lead to can confuse
	users, and we are unlikely to ever implement them in the form
	now assumed by the code.

tests/invalid/bigtest.err_exp:
tests/invalid/uu_type.err_exp:
	Update these expected error messages.
2002-02-26 02:46:05 +00:00
Lars Yencken
443ef48532 Fixed the bug where universally quantification was parsed improperly
Estimated hours taken: 6
Branches: main

Fixed the bug where universally quantification was parsed improperly
for assertions.

compiler/prog_io.m:
	Fixed the way universal quantificaton is parsed.
2002-02-12 04:59:01 +00:00