Commit Graph

6 Commits

Author SHA1 Message Date
Zoltan Somogyi
b2012c0c0e Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8
Branches: main

compiler/*.m:
	Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
	and 'mer_mode'. This is to avoid the need to parenthesize these type
	names in some contexts, and to prepare for the possibility of a parser
	that considers those words to be reserved words.

	Rename some other uses of those names (e.g. as item types in
	recompilation.m).

	Delete some redundant synonyms (prog_type, mercury_type) for mer_type.

	Change some type names (e.g. mlds__type) and predicate names (e.g.
	deforest__goal) to make them unique even without module qualification.

	Rename the function symbols (e.g. pure, &) that need to be renamed
	to avoid the need to parenthesize them. Make their replacement names
	more expressive.

	Convert some more modules to four space indentation.

	Avoid excessively long lines, such as those resulting from the
	automatic substitution of 'mer_type' for 'type'.
2005-10-24 04:14:34 +00:00
Zoltan Somogyi
b54ab42d70 A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5
Branches: main

tools/subst:
	A simple tool for performing substitutions on the source files of the
	compiler.

compiler/*.m:
	Change the names of the get predicates operating on module_infos to
	include "get" in the name, for uniformity. This was done mostly by
	the following sed script, with some manual cleanup afterwards to reduce
	excessive line lengths.

s/module_info_types/module_info_get_type_table/
s/module_info_set_types/module_info_set_type_table/
s/module_info_insts/module_info_get_inst_table/
s/module_info_set_insts/module_info_set_inst_table/
s/module_info_modes/module_info_get_mode_table/
s/module_info_set_modes/module_info_set_mode_table/
s/module_info_ctors/module_info_get_cons_table/
s/module_info_set_ctors/module_info_set_cons_table/
s/module_info_classes/module_info_get_class_table/
s/module_info_set_classes/module_info_set_class_table/
s/module_info_instances/module_info_get_instance_table/
s/module_info_set_instances/module_info_set_instance_table/
s/module_info_superclasses/module_info_get_superclass_table/
s/module_info_set_superclasses/module_info_set_superclass_table/
s/module_info_assertion_table/module_info_get_assertion_table/
s/module_info_exclusive_table/module_info_get_exclusive_table/
s/module_info_ctor_field_table/module_info_get_ctor_field_table/
s/module_info_name/module_info_get_name/
s/module_info_globals/module_info_get_globals/
s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/
s/module_info_num_errors/module_info_get_num_errors/
s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/
s/module_info_stratified_preds/module_info_get_stratified_preds/
s/module_info_unused_arg_info/module_info_get_unused_arg_info/
s/module_info_exception_info/module_info_get_exception_info/
s/module_info_type_spec_info/module_info_get_type_spec_info/
s/module_info_no_tag_types/module_info_get_no_tag_types/
s/module_info_analysis_info/module_info_get_analysis_info/
s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/
2005-09-30 08:08:49 +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
Zoltan Somogyi
6df9a05856 This diff cleans up a bunch of modules. It has no algorithmic changes
Estimated hours taken: 10
Branches: main

This diff cleans up a bunch of modules. It has no algorithmic changes
other than in the formatting of error messages.

compiler/error_util.m:
	Delete the obsolete predicate append_punctuation, since the suffix
	format component can now do more, and do it more easily.

compiler/goal_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/instmap.m:
compiler/const_prop.m:
	Change the argument order of some the predicates exported by these
	modules to make them easier to use with state variable syntax.

compiler/*.m:
	Convert a bunch of these modules to four space indentation, and fix
	departures from our coding style.

	Conform to the changed argument order above.

	Use suffixes instead of append_punctuation.

library/string.m:
	Add string.foldl2.

tests/invalid/circ_*.err_exp:
tests/warnings/unused_args_*.exp:
	Expect the updated error messages, which format sym_names consistently
	the same way as other messages.
2005-08-30 04:12:17 +00:00
Zoltan Somogyi
10536c5ee0 Divide make_hlds.m into submodules of manageable size.
Estimated hours taken: 12
Branches: main

Divide make_hlds.m into submodules of manageable size.

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

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

compiler/add_class.m:
	Submodule for handling typeclasses.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

compiler/notes/compiler_design.html:
	Describe the new modules.
2005-07-26 01:56:30 +00:00